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>
38 #define WL127X_FW_NAME_MULTI "ti-connectivity/wl127x-fw-4-mr.bin"
39 #define WL127X_FW_NAME_SINGLE "ti-connectivity/wl127x-fw-4-sr.bin"
41 #define WL128X_FW_NAME_MULTI "ti-connectivity/wl128x-fw-4-mr.bin"
42 #define WL128X_FW_NAME_SINGLE "ti-connectivity/wl128x-fw-4-sr.bin"
44 #define WL127X_PLT_FW_NAME "ti-connectivity/wl127x-fw-4-plt.bin"
45 #define WL128X_PLT_FW_NAME "ti-connectivity/wl128x-fw-4-plt.bin"
48 * wl127x and wl128x are using the same NVS file name. However, the
49 * ini parameters between them are different. The driver validates
50 * the correct NVS size in wl1271_boot_upload_nvs().
52 #define WL12XX_NVS_NAME "ti-connectivity/wl1271-nvs.bin"
54 #define WL1271_TX_SECURITY_LO16(s) ((u16)((s) & 0xffff))
55 #define WL1271_TX_SECURITY_HI32(s) ((u32)(((s) >> 16) & 0xffffffff))
56 #define WL1271_TX_SQN_POST_RECOVERY_PADDING 0xff
58 #define WL1271_CIPHER_SUITE_GEM 0x00147201
60 #define WL1271_BUSY_WORD_CNT 1
61 #define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32))
63 #define WL1271_ELP_HW_STATE_ASLEEP 0
64 #define WL1271_ELP_HW_STATE_IRQ 1
66 #define WL1271_DEFAULT_BEACON_INT 100
67 #define WL1271_DEFAULT_DTIM_PERIOD 1
69 #define WL12XX_MAX_ROLES 4
70 #define WL12XX_MAX_LINKS 12
71 #define WL12XX_INVALID_ROLE_ID 0xff
72 #define WL12XX_INVALID_LINK_ID 0xff
74 #define WL12XX_MAX_RATE_POLICIES 16
76 /* Defined by FW as 0. Will not be freed or allocated. */
77 #define WL12XX_SYSTEM_HLID 0
80 * When in AP-mode, we allow (at least) this number of packets
81 * to be transmitted to FW for a STA in PS-mode. Only when packets are
82 * present in the FW buffers it will wake the sleeping STA. We want to put
83 * enough packets for the driver to transmit all of its buffered data before
84 * the STA goes to sleep again. But we don't want to take too much memory
85 * as it might hurt the throughput of active STAs.
87 #define WL1271_PS_STA_MAX_PACKETS 2
89 #define WL1271_AP_BSS_INDEX 0
90 #define WL1271_AP_DEF_BEACON_EXP 20
92 #define ACX_TX_DESCRIPTORS 16
94 #define WL1271_AGGR_BUFFER_SIZE (4 * PAGE_SIZE)
101 enum wl12xx_fw_type {
103 WL12XX_FW_TYPE_NORMAL,
104 WL12XX_FW_TYPE_MULTI,
108 enum wl1271_partition_type {
116 struct wl1271_partition {
121 struct wl1271_partition_set {
122 struct wl1271_partition mem;
123 struct wl1271_partition reg;
124 struct wl1271_partition mem2;
125 struct wl1271_partition mem3;
140 #define FW_VER_CHIP_WL127X 6
141 #define FW_VER_CHIP_WL128X 7
143 #define FW_VER_IF_TYPE_STA 1
144 #define FW_VER_IF_TYPE_AP 2
146 #define FW_VER_MINOR_1_SPARE_STA_MIN 58
147 #define FW_VER_MINOR_1_SPARE_AP_MIN 47
149 #define FW_VER_MINOR_FWLOG_STA_MIN 70
153 char fw_ver_str[ETHTOOL_BUSINFO_LEN];
154 unsigned int fw_ver[NUM_FW_VER];
157 struct wl1271_stats {
158 struct acx_statistics *fw_stats;
159 unsigned long fw_stats_update;
161 unsigned int retry_count;
162 unsigned int excessive_retries;
165 #define NUM_TX_QUEUES 4
166 #define NUM_RX_PKT_DESC 8
168 #define AP_MAX_STATIONS 8
170 /* FW status registers */
171 struct wl12xx_fw_status {
176 u8 tx_results_counter;
177 __le32 rx_pkt_descs[NUM_RX_PKT_DESC];
181 * A bitmap (where each bit represents a single HLID)
182 * to indicate if the station is in PS mode.
184 __le32 link_ps_bitmap;
187 * A bitmap (where each bit represents a single HLID) to indicate
188 * if the station is in Fast mode
190 __le32 link_fast_bitmap;
192 /* Cumulative counter of total released mem blocks since FW-reset */
193 __le32 total_released_blks;
195 /* Size (in Memory Blocks) of TX pool */
198 /* Cumulative counter of released packets per AC */
199 u8 tx_released_pkts[NUM_TX_QUEUES];
201 /* Cumulative counter of freed packets per HLID */
202 u8 tx_lnk_free_pkts[WL12XX_MAX_LINKS];
204 /* Cumulative counter of released Voice memory blocks */
205 u8 tx_voice_released_blks;
207 __le32 log_start_addr;
210 struct wl1271_rx_mem_pool_addr {
215 #define WL1271_MAX_CHANNELS 64
217 struct cfg80211_scan_request *req;
218 unsigned long scanned_ch[BITS_TO_LONGS(WL1271_MAX_CHANNELS)];
221 u8 ssid[IEEE80211_MAX_SSID_LEN+1];
225 struct wl1271_if_operations {
226 void (*read)(struct device *child, int addr, void *buf, size_t len,
228 void (*write)(struct device *child, int addr, void *buf, size_t len,
230 void (*reset)(struct device *child);
231 void (*init)(struct device *child);
232 int (*power)(struct device *child, bool enable);
233 void (*set_block_size) (struct device *child, unsigned int blksz);
236 #define MAX_NUM_KEYS 14
237 #define MAX_KEY_SIZE 32
239 struct wl1271_ap_key {
243 u8 key[MAX_KEY_SIZE];
250 WL1271_FLAG_GPIO_POWER,
251 WL1271_FLAG_TX_QUEUE_STOPPED,
252 WL1271_FLAG_TX_PENDING,
254 WL1271_FLAG_ELP_REQUESTED,
255 WL1271_FLAG_IRQ_RUNNING,
256 WL1271_FLAG_FW_TX_BUSY,
257 WL1271_FLAG_DUMMY_PACKET_PENDING,
258 WL1271_FLAG_SUSPENDED,
259 WL1271_FLAG_PENDING_WORK,
260 WL1271_FLAG_SOFT_GEMINI,
261 WL1271_FLAG_RECOVERY_IN_PROGRESS,
262 WL1271_FLAG_VIF_CHANGE_IN_PROGRESS,
263 WL1271_FLAG_INTENDED_FW_RECOVERY,
266 enum wl12xx_vif_flags {
267 WLVIF_FLAG_INITIALIZED,
268 WLVIF_FLAG_STA_ASSOCIATED,
269 WLVIF_FLAG_STA_AUTHORIZED,
270 WLVIF_FLAG_IBSS_JOINED,
271 WLVIF_FLAG_AP_STARTED,
273 WLVIF_FLAG_STA_STATE_SENT,
274 WLVIF_FLAG_RX_STREAMING_STARTED,
275 WLVIF_FLAG_PSPOLL_FAILURE,
276 WLVIF_FLAG_CS_PROGRESS,
277 WLVIF_FLAG_AP_PROBE_RESP_SET,
282 /* AP-mode - TX queue per AC in link */
283 struct sk_buff_head tx_queue[NUM_TX_QUEUES];
285 /* accounting for allocated / freed packets in FW */
291 /* bitmap of TIDs where RX BA sessions are active for this link */
296 struct ieee80211_hw *hw;
297 bool mac80211_registered;
303 struct wl1271_if_operations *if_ops;
305 void (*set_power)(bool enable);
311 enum wl1271_state state;
312 enum wl12xx_fw_type fw_type;
319 struct wl1271_partition_set part;
321 struct wl1271_chip chip;
333 /* address read from the fuse ROM */
337 /* we have up to 2 MAC addresses */
338 struct mac_address addresses[2];
342 unsigned long links_map[BITS_TO_LONGS(WL12XX_MAX_LINKS)];
343 unsigned long roles_map[BITS_TO_LONGS(WL12XX_MAX_ROLES)];
344 unsigned long roc_map[BITS_TO_LONGS(WL12XX_MAX_ROLES)];
345 unsigned long rate_policies_map[
346 BITS_TO_LONGS(WL12XX_MAX_RATE_POLICIES)];
348 struct list_head wlvif_list;
353 struct wl1271_acx_mem_map *target_mem_map;
355 /* Accounting for allocated / available TX blocks on HW */
357 u32 tx_blocks_available;
358 u32 tx_allocated_blocks;
359 u32 tx_results_count;
361 /* amount of spare TX blocks to use */
364 /* Accounting for allocated / available Tx packets in HW */
365 u32 tx_pkts_freed[NUM_TX_QUEUES];
366 u32 tx_allocated_pkts[NUM_TX_QUEUES];
368 /* Transmitted TX packets counter for chipset interface */
369 u32 tx_packets_count;
371 /* Time-offset between host and chipset clocks */
374 /* Frames scheduled for transmission, not handled yet */
375 int tx_queue_count[NUM_TX_QUEUES];
376 long stopped_queues_map;
378 /* Frames received, not handled yet by mac80211 */
379 struct sk_buff_head deferred_rx_queue;
381 /* Frames sent, not returned yet to mac80211 */
382 struct sk_buff_head deferred_tx_queue;
384 struct work_struct tx_work;
385 struct workqueue_struct *freezable_wq;
387 /* Pending TX frames */
388 unsigned long tx_frames_map[BITS_TO_LONGS(ACX_TX_DESCRIPTORS)];
389 struct sk_buff *tx_frames[ACX_TX_DESCRIPTORS];
395 /* Rx memory pool address */
396 struct wl1271_rx_mem_pool_addr rx_mem_pool_addr;
398 /* Intermediate buffer, used for packet aggregation */
401 /* Reusable dummy packet template */
402 struct sk_buff *dummy_packet;
404 /* Network stack work */
405 struct work_struct netstack_work;
410 /* Number of valid bytes in the FW log buffer */
413 /* Sysfs FW log entry readers wait queue */
414 wait_queue_head_t fwlog_waitq;
416 /* Hardware recovery work */
417 struct work_struct recovery_work;
419 /* The mbox event mask */
422 /* Mailbox pointers */
425 /* Are we currently scanning */
426 struct ieee80211_vif *scan_vif;
427 struct wl1271_scan scan;
428 struct delayed_work scan_complete_work;
432 /* The current band */
433 enum ieee80211_band band;
435 struct completion *elp_compl;
436 struct delayed_work elp_work;
441 struct wl1271_stats stats;
445 u32 buffer_busyword[WL1271_BUSY_WORD_CNT];
447 struct wl12xx_fw_status *fw_status;
448 struct wl1271_tx_hw_res_if *tx_res_if;
450 /* Current chipset configuration */
451 struct conf_drv_settings conf;
457 /* Most recently reported noise in dBm */
460 /* bands supported by this instance of wl12xx */
461 struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
466 * wowlan trigger was configured during suspend.
467 * (currently, only "ANY" trigger is supported)
470 bool irq_wake_enabled;
473 * AP-mode - links indexed by HLID. The global and broadcast links
476 struct wl1271_link links[WL12XX_MAX_LINKS];
478 /* AP-mode - a bitmap of links currently in PS mode according to FW */
481 /* AP-mode - a bitmap of links currently in PS mode in mac80211 */
482 unsigned long ap_ps_map;
484 /* Quirks of specific hardware revisions */
487 /* Platform limitations */
488 unsigned int platform_quirks;
490 /* number of currently active RX BA sessions */
491 int ba_rx_session_count;
493 /* AP-mode - number of currently connected stations */
494 int active_sta_count;
496 /* last wlvif we transmitted from */
497 struct wl12xx_vif *last_wlvif;
499 /* work to fire when Tx is stuck */
500 struct delayed_work tx_watchdog_work;
503 struct wl1271_station {
509 struct list_head list;
512 u8 p2p; /* we are using p2p role */
515 /* sta/ibss specific */
534 /* HLIDs bitmap of associated stations */
535 unsigned long sta_hlid_map[BITS_TO_LONGS(
538 /* recoreded keys - set here before AP startup */
539 struct wl1271_ap_key *recorded_keys[MAX_NUM_KEYS];
543 u8 ucast_rate_idx[CONF_TX_MAX_AC_COUNT];
547 /* the hlid of the last transmitted skb */
550 unsigned long links_map[BITS_TO_LONGS(WL12XX_MAX_LINKS)];
552 u8 ssid[IEEE80211_MAX_SSID_LEN + 1];
555 /* The current band */
556 enum ieee80211_band band;
559 u32 bitrate_masks[IEEE80211_NUM_BANDS];
563 * currently configured rate set:
564 * bits 0-15 - 802.11abg rates
565 * bits 16-23 - 802.11n MCS index mask
566 * support only 1 stream, thus only 8 bits for the MCS rates (0-7).
571 /* probe-req template for the current AP */
572 struct sk_buff *probereq;
574 /* Beaconing interval (needed for ad-hoc) */
577 /* Default key (for WEP) */
580 /* Our association ID */
583 /* Session counter for the chipset */
586 /* retry counter for PSM entries */
595 /* save the current encryption type for auto-arp config */
599 /* RX BA constraint value */
604 struct work_struct rx_streaming_enable_work;
605 struct work_struct rx_streaming_disable_work;
606 struct timer_list rx_streaming_timer;
609 * This struct must be last!
610 * data that has to be saved acrossed reconfigs (e.g. recovery)
611 * should be declared in this struct.
616 * Security sequence number
617 * bits 0-15: lower 16 bits part of sequence number
618 * bits 16-47: higher 32 bits part of sequence number
619 * bits 48-63: not in use
623 /* 8 bits of the last sequence number in use */
624 u8 tx_security_last_seq_lsb;
628 static inline struct wl12xx_vif *wl12xx_vif_to_data(struct ieee80211_vif *vif)
630 return (struct wl12xx_vif *)vif->drv_priv;
634 struct ieee80211_vif *wl12xx_wlvif_to_vif(struct wl12xx_vif *wlvif)
636 return container_of((void *)wlvif, struct ieee80211_vif, drv_priv);
639 #define wl12xx_for_each_wlvif(wl, wlvif) \
640 list_for_each_entry(wlvif, &wl->wlvif_list, list)
642 #define wl12xx_for_each_wlvif_continue(wl, wlvif) \
643 list_for_each_entry_continue(wlvif, &wl->wlvif_list, list)
645 #define wl12xx_for_each_wlvif_bss_type(wl, wlvif, _bss_type) \
646 wl12xx_for_each_wlvif(wl, wlvif) \
647 if (wlvif->bss_type == _bss_type)
649 #define wl12xx_for_each_wlvif_sta(wl, wlvif) \
650 wl12xx_for_each_wlvif_bss_type(wl, wlvif, BSS_TYPE_STA_BSS)
652 #define wl12xx_for_each_wlvif_ap(wl, wlvif) \
653 wl12xx_for_each_wlvif_bss_type(wl, wlvif, BSS_TYPE_AP_BSS)
655 int wl1271_plt_start(struct wl1271 *wl);
656 int wl1271_plt_stop(struct wl1271 *wl);
657 int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif);
658 void wl12xx_queue_recovery_work(struct wl1271 *wl);
659 size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen);
661 #define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
663 #define SESSION_COUNTER_MAX 6 /* maximum value for the session counter */
664 #define SESSION_COUNTER_INVALID 7 /* used with dummy_packet */
666 #define WL1271_DEFAULT_POWER_LEVEL 0
668 #define WL1271_TX_QUEUE_LOW_WATERMARK 32
669 #define WL1271_TX_QUEUE_HIGH_WATERMARK 256
671 #define WL1271_DEFERRED_QUEUE_LIMIT 64
673 /* WL1271 needs a 200ms sleep after power on, and a 20ms sleep before power
674 on in case is has been shut down shortly before */
675 #define WL1271_PRE_POWER_ON_SLEEP 20 /* in milliseconds */
676 #define WL1271_POWER_ON_SLEEP 200 /* in milliseconds */
678 /* Macros to handle wl1271.sta_rate_set */
679 #define HW_BG_RATES_MASK 0xffff
680 #define HW_HT_RATES_OFFSET 16
684 /* Each RX/TX transaction requires an end-of-transaction transfer */
685 #define WL12XX_QUIRK_END_OF_TRANSACTION BIT(0)
687 /* wl127x and SPI don't support SDIO block size alignment */
688 #define WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT BIT(2)
690 /* Older firmwares did not implement the FW logger over bus feature */
691 #define WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED BIT(4)
693 #define WL12XX_HW_BLOCK_SIZE 256