2 * This file is part of wl1271
4 * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
5 * Copyright (C) 2008-2009 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
28 #include <linux/mutex.h>
29 #include <linux/completion.h>
30 #include <linux/spinlock.h>
31 #include <linux/list.h>
32 #include <linux/bitops.h>
33 #include <net/mac80211.h>
39 * FW versions support BA 11n
40 * versions marks x.x.x.50-60.x
42 #define WL12XX_BA_SUPPORT_FW_COST_VER2_START 50
43 #define WL12XX_BA_SUPPORT_FW_COST_VER2_END 60
45 #define WL127X_FW_NAME "ti-connectivity/wl127x-fw-3.bin"
46 #define WL128X_FW_NAME "ti-connectivity/wl128x-fw-3.bin"
49 * wl127x and wl128x are using the same NVS file name. However, the
50 * ini parameters between them are different. The driver validates
51 * the correct NVS size in wl1271_boot_upload_nvs().
53 #define WL12XX_NVS_NAME "ti-connectivity/wl1271-nvs.bin"
55 #define WL1271_TX_SECURITY_LO16(s) ((u16)((s) & 0xffff))
56 #define WL1271_TX_SECURITY_HI32(s) ((u32)(((s) >> 16) & 0xffffffff))
57 #define WL1271_TX_SQN_POST_RECOVERY_PADDING 0xff
59 #define WL1271_CIPHER_SUITE_GEM 0x00147201
61 #define WL1271_BUSY_WORD_CNT 1
62 #define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32))
64 #define WL1271_ELP_HW_STATE_ASLEEP 0
65 #define WL1271_ELP_HW_STATE_IRQ 1
67 #define WL1271_DEFAULT_BEACON_INT 100
68 #define WL1271_DEFAULT_DTIM_PERIOD 1
70 #define WL12XX_MAX_ROLES 4
71 #define WL12XX_MAX_LINKS 12
72 #define WL12XX_INVALID_ROLE_ID 0xff
73 #define WL12XX_INVALID_LINK_ID 0xff
75 #define WL12XX_MAX_RATE_POLICIES 16
77 /* Defined by FW as 0. Will not be freed or allocated. */
78 #define WL12XX_SYSTEM_HLID 0
81 * When in AP-mode, we allow (at least) this number of packets
82 * to be transmitted to FW for a STA in PS-mode. Only when packets are
83 * present in the FW buffers it will wake the sleeping STA. We want to put
84 * enough packets for the driver to transmit all of its buffered data before
85 * the STA goes to sleep again. But we don't want to take too much memory
86 * as it might hurt the throughput of active STAs.
88 #define WL1271_PS_STA_MAX_PACKETS 2
90 #define WL1271_AP_BSS_INDEX 0
91 #define WL1271_AP_DEF_BEACON_EXP 20
93 #define ACX_TX_DESCRIPTORS 16
95 #define WL1271_AGGR_BUFFER_SIZE (4 * PAGE_SIZE)
103 enum wl1271_partition_type
{
111 struct wl1271_partition
{
116 struct wl1271_partition_set
{
117 struct wl1271_partition mem
;
118 struct wl1271_partition reg
;
119 struct wl1271_partition mem2
;
120 struct wl1271_partition mem3
;
135 #define FW_VER_CHIP_WL127X 6
136 #define FW_VER_CHIP_WL128X 7
138 #define FW_VER_IF_TYPE_STA 1
139 #define FW_VER_IF_TYPE_AP 2
141 #define FW_VER_MINOR_1_SPARE_STA_MIN 58
142 #define FW_VER_MINOR_1_SPARE_AP_MIN 47
144 #define FW_VER_MINOR_FWLOG_STA_MIN 70
148 char fw_ver_str
[ETHTOOL_BUSINFO_LEN
];
149 unsigned int fw_ver
[NUM_FW_VER
];
152 struct wl1271_stats
{
153 struct acx_statistics
*fw_stats
;
154 unsigned long fw_stats_update
;
156 unsigned int retry_count
;
157 unsigned int excessive_retries
;
160 #define NUM_TX_QUEUES 4
161 #define NUM_RX_PKT_DESC 8
163 #define AP_MAX_STATIONS 8
165 /* FW status registers */
166 struct wl12xx_fw_status
{
171 u8 tx_results_counter
;
172 __le32 rx_pkt_descs
[NUM_RX_PKT_DESC
];
176 * A bitmap (where each bit represents a single HLID)
177 * to indicate if the station is in PS mode.
179 __le32 link_ps_bitmap
;
182 * A bitmap (where each bit represents a single HLID) to indicate
183 * if the station is in Fast mode
185 __le32 link_fast_bitmap
;
187 /* Cumulative counter of total released mem blocks since FW-reset */
188 __le32 total_released_blks
;
190 /* Size (in Memory Blocks) of TX pool */
193 /* Cumulative counter of released packets per AC */
194 u8 tx_released_pkts
[NUM_TX_QUEUES
];
196 /* Cumulative counter of freed packets per HLID */
197 u8 tx_lnk_free_pkts
[WL12XX_MAX_LINKS
];
199 /* Cumulative counter of released Voice memory blocks */
200 u8 tx_voice_released_blks
;
202 __le32 log_start_addr
;
205 struct wl1271_rx_mem_pool_addr
{
210 #define WL1271_MAX_CHANNELS 64
212 struct cfg80211_scan_request
*req
;
213 unsigned long scanned_ch
[BITS_TO_LONGS(WL1271_MAX_CHANNELS
)];
216 u8 ssid
[IEEE80211_MAX_SSID_LEN
+1];
220 struct wl1271_if_operations
{
221 void (*read
)(struct device
*child
, int addr
, void *buf
, size_t len
,
223 void (*write
)(struct device
*child
, int addr
, void *buf
, size_t len
,
225 void (*reset
)(struct device
*child
);
226 void (*init
)(struct device
*child
);
227 int (*power
)(struct device
*child
, bool enable
);
228 void (*set_block_size
) (struct device
*child
, unsigned int blksz
);
231 #define MAX_NUM_KEYS 14
232 #define MAX_KEY_SIZE 32
234 struct wl1271_ap_key
{
238 u8 key
[MAX_KEY_SIZE
];
245 WL1271_FLAG_GPIO_POWER
,
246 WL1271_FLAG_TX_QUEUE_STOPPED
,
247 WL1271_FLAG_TX_PENDING
,
249 WL1271_FLAG_ELP_REQUESTED
,
250 WL1271_FLAG_IRQ_RUNNING
,
252 WL1271_FLAG_FW_TX_BUSY
,
253 WL1271_FLAG_DUMMY_PACKET_PENDING
,
254 WL1271_FLAG_SUSPENDED
,
255 WL1271_FLAG_PENDING_WORK
,
256 WL1271_FLAG_SOFT_GEMINI
,
257 WL1271_FLAG_RECOVERY_IN_PROGRESS
,
260 enum wl12xx_vif_flags
{
261 WLVIF_FLAG_INITIALIZED
,
262 WLVIF_FLAG_STA_ASSOCIATED
,
263 WLVIF_FLAG_IBSS_JOINED
,
264 WLVIF_FLAG_AP_STARTED
,
266 WLVIF_FLAG_PSM_REQUESTED
,
267 WLVIF_FLAG_STA_STATE_SENT
,
268 WLVIF_FLAG_RX_STREAMING_STARTED
,
269 WLVIF_FLAG_PSPOLL_FAILURE
,
270 WLVIF_FLAG_CS_PROGRESS
,
274 /* AP-mode - TX queue per AC in link */
275 struct sk_buff_head tx_queue
[NUM_TX_QUEUES
];
277 /* accounting for allocated / freed packets in FW */
283 /* bitmap of TIDs where RX BA sessions are active for this link */
288 struct ieee80211_hw
*hw
;
289 bool mac80211_registered
;
295 struct wl1271_if_operations
*if_ops
;
297 void (*set_power
)(bool enable
);
303 enum wl1271_state state
;
308 struct wl1271_partition_set part
;
310 struct wl1271_chip chip
;
322 u8 mac_addr
[ETH_ALEN
];
326 unsigned long links_map
[BITS_TO_LONGS(WL12XX_MAX_LINKS
)];
327 unsigned long roles_map
[BITS_TO_LONGS(WL12XX_MAX_ROLES
)];
328 unsigned long roc_map
[BITS_TO_LONGS(WL12XX_MAX_ROLES
)];
329 unsigned long rate_policies_map
[
330 BITS_TO_LONGS(WL12XX_MAX_RATE_POLICIES
)];
332 struct list_head wlvif_list
;
337 struct wl1271_acx_mem_map
*target_mem_map
;
339 /* Accounting for allocated / available TX blocks on HW */
341 u32 tx_blocks_available
;
342 u32 tx_allocated_blocks
;
343 u32 tx_results_count
;
345 /* amount of spare TX blocks to use */
348 /* Accounting for allocated / available Tx packets in HW */
349 u32 tx_pkts_freed
[NUM_TX_QUEUES
];
350 u32 tx_allocated_pkts
[NUM_TX_QUEUES
];
352 /* Transmitted TX packets counter for chipset interface */
353 u32 tx_packets_count
;
355 /* Time-offset between host and chipset clocks */
358 /* Frames scheduled for transmission, not handled yet */
359 int tx_queue_count
[NUM_TX_QUEUES
];
360 long stopped_queues_map
;
362 /* Frames received, not handled yet by mac80211 */
363 struct sk_buff_head deferred_rx_queue
;
365 /* Frames sent, not returned yet to mac80211 */
366 struct sk_buff_head deferred_tx_queue
;
368 struct work_struct tx_work
;
369 struct workqueue_struct
*freezable_wq
;
371 /* Pending TX frames */
372 unsigned long tx_frames_map
[BITS_TO_LONGS(ACX_TX_DESCRIPTORS
)];
373 struct sk_buff
*tx_frames
[ACX_TX_DESCRIPTORS
];
379 /* Rx memory pool address */
380 struct wl1271_rx_mem_pool_addr rx_mem_pool_addr
;
382 /* Intermediate buffer, used for packet aggregation */
385 /* Reusable dummy packet template */
386 struct sk_buff
*dummy_packet
;
388 /* Network stack work */
389 struct work_struct netstack_work
;
394 /* Number of valid bytes in the FW log buffer */
397 /* Sysfs FW log entry readers wait queue */
398 wait_queue_head_t fwlog_waitq
;
400 /* Hardware recovery work */
401 struct work_struct recovery_work
;
403 /* The mbox event mask */
406 /* Mailbox pointers */
409 /* Are we currently scanning */
410 struct ieee80211_vif
*scan_vif
;
411 struct wl1271_scan scan
;
412 struct delayed_work scan_complete_work
;
416 /* The current band */
417 enum ieee80211_band band
;
419 struct completion
*elp_compl
;
420 struct delayed_work elp_work
;
425 struct wl1271_stats stats
;
429 u32 buffer_busyword
[WL1271_BUSY_WORD_CNT
];
431 struct wl12xx_fw_status
*fw_status
;
432 struct wl1271_tx_hw_res_if
*tx_res_if
;
434 struct ieee80211_vif
*vif
;
436 /* Current chipset configuration */
437 struct conf_drv_settings conf
;
443 struct list_head list
;
445 /* Most recently reported noise in dBm */
448 /* bands supported by this instance of wl12xx */
449 struct ieee80211_supported_band bands
[IEEE80211_NUM_BANDS
];
454 * wowlan trigger was configured during suspend.
455 * (currently, only "ANY" trigger is supported)
458 bool irq_wake_enabled
;
461 * AP-mode - links indexed by HLID. The global and broadcast links
464 struct wl1271_link links
[WL12XX_MAX_LINKS
];
466 /* AP-mode - a bitmap of links currently in PS mode according to FW */
469 /* AP-mode - a bitmap of links currently in PS mode in mac80211 */
470 unsigned long ap_ps_map
;
472 /* Quirks of specific hardware revisions */
475 /* Platform limitations */
476 unsigned int platform_quirks
;
478 /* number of currently active RX BA sessions */
479 int ba_rx_session_count
;
481 /* AP-mode - number of currently connected stations */
482 int active_sta_count
;
484 /* last wlvif we transmitted from */
485 struct wl12xx_vif
*last_wlvif
;
488 struct wl1271_station
{
494 struct list_head list
;
497 u8 p2p
; /* we are using p2p role */
500 /* sta/ibss specific */
517 /* HLIDs bitmap of associated stations */
518 unsigned long sta_hlid_map
[BITS_TO_LONGS(
521 /* recoreded keys - set here before AP startup */
522 struct wl1271_ap_key
*recorded_keys
[MAX_NUM_KEYS
];
526 u8 ucast_rate_idx
[CONF_TX_MAX_AC_COUNT
];
530 /* the hlid of the last transmitted skb */
533 unsigned long links_map
[BITS_TO_LONGS(WL12XX_MAX_LINKS
)];
535 u8 ssid
[IEEE80211_MAX_SSID_LEN
+ 1];
538 /* The current band */
539 enum ieee80211_band band
;
542 u32 bitrate_masks
[IEEE80211_NUM_BANDS
];
546 * currently configured rate set:
547 * bits 0-15 - 802.11abg rates
548 * bits 16-23 - 802.11n MCS index mask
549 * support only 1 stream, thus only 8 bits for the MCS rates (0-7).
554 /* probe-req template for the current AP */
555 struct sk_buff
*probereq
;
557 /* Beaconing interval (needed for ad-hoc) */
560 /* Default key (for WEP) */
563 /* Our association ID */
566 /* Session counter for the chipset */
569 struct completion
*ps_compl
;
570 struct delayed_work pspoll_work
;
572 /* counter for ps-poll delivery failures */
573 int ps_poll_failures
;
575 /* retry counter for PSM entries */
584 /* RX BA constraint value */
589 struct work_struct rx_streaming_enable_work
;
590 struct work_struct rx_streaming_disable_work
;
591 struct timer_list rx_streaming_timer
;
594 * This struct must be last!
595 * data that has to be saved acrossed reconfigs (e.g. recovery)
596 * should be declared in this struct.
601 * Security sequence number
602 * bits 0-15: lower 16 bits part of sequence number
603 * bits 16-47: higher 32 bits part of sequence number
604 * bits 48-63: not in use
608 /* 8 bits of the last sequence number in use */
609 u8 tx_security_last_seq_lsb
;
613 static inline struct wl12xx_vif
*wl12xx_vif_to_data(struct ieee80211_vif
*vif
)
615 return (struct wl12xx_vif
*)vif
->drv_priv
;
619 struct ieee80211_vif
*wl12xx_wlvif_to_vif(struct wl12xx_vif
*wlvif
)
621 return container_of((void *)wlvif
, struct ieee80211_vif
, drv_priv
);
624 #define wl12xx_for_each_wlvif(wl, wlvif) \
625 list_for_each_entry(wlvif, &wl->wlvif_list, list)
627 #define wl12xx_for_each_wlvif_continue(wl, wlvif) \
628 list_for_each_entry_continue(wlvif, &wl->wlvif_list, list)
630 #define wl12xx_for_each_wlvif_bss_type(wl, wlvif, _bss_type) \
631 wl12xx_for_each_wlvif(wl, wlvif) \
632 if (wlvif->bss_type == _bss_type)
634 #define wl12xx_for_each_wlvif_sta(wl, wlvif) \
635 wl12xx_for_each_wlvif_bss_type(wl, wlvif, BSS_TYPE_STA_BSS)
637 #define wl12xx_for_each_wlvif_ap(wl, wlvif) \
638 wl12xx_for_each_wlvif_bss_type(wl, wlvif, BSS_TYPE_AP_BSS)
640 int wl1271_plt_start(struct wl1271
*wl
);
641 int wl1271_plt_stop(struct wl1271
*wl
);
642 int wl1271_recalc_rx_streaming(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
);
643 void wl12xx_queue_recovery_work(struct wl1271
*wl
);
644 size_t wl12xx_copy_fwlog(struct wl1271
*wl
, u8
*memblock
, size_t maxlen
);
646 #define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
648 #define SESSION_COUNTER_MAX 6 /* maximum value for the session counter */
649 #define SESSION_COUNTER_INVALID 7 /* used with dummy_packet */
651 #define WL1271_DEFAULT_POWER_LEVEL 0
653 #define WL1271_TX_QUEUE_LOW_WATERMARK 32
654 #define WL1271_TX_QUEUE_HIGH_WATERMARK 256
656 #define WL1271_DEFERRED_QUEUE_LIMIT 64
658 /* WL1271 needs a 200ms sleep after power on, and a 20ms sleep before power
659 on in case is has been shut down shortly before */
660 #define WL1271_PRE_POWER_ON_SLEEP 20 /* in milliseconds */
661 #define WL1271_POWER_ON_SLEEP 200 /* in milliseconds */
663 /* Macros to handle wl1271.sta_rate_set */
664 #define HW_BG_RATES_MASK 0xffff
665 #define HW_HT_RATES_OFFSET 16
669 /* Each RX/TX transaction requires an end-of-transaction transfer */
670 #define WL12XX_QUIRK_END_OF_TRANSACTION BIT(0)
672 /* wl127x and SPI don't support SDIO block size alignment */
673 #define WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT BIT(2)
675 /* Older firmwares did not implement the FW logger over bus feature */
676 #define WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED BIT(4)
678 #define WL12XX_HW_BLOCK_SIZE 256