1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * This file is part of wl1271
5 * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
6 * Copyright (C) 2008-2009 Nokia Corporation
8 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
11 #ifndef __WLCORE_I_H__
12 #define __WLCORE_I_H__
14 #include <linux/mutex.h>
15 #include <linux/completion.h>
16 #include <linux/spinlock.h>
17 #include <linux/list.h>
18 #include <linux/bitops.h>
19 #include <net/mac80211.h>
24 struct wilink_family_data {
26 const char *nvs_name; /* wl12xx nvs file */
27 const char *cfg_name; /* wl18xx cfg file */
30 #define WL1271_TX_SECURITY_LO16(s) ((u16)((s) & 0xffff))
31 #define WL1271_TX_SECURITY_HI32(s) ((u32)(((s) >> 16) & 0xffffffff))
32 #define WL1271_TX_SQN_POST_RECOVERY_PADDING 0xff
33 /* Use smaller padding for GEM, as some APs have issues when it's too big */
34 #define WL1271_TX_SQN_POST_RECOVERY_PADDING_GEM 0x20
37 #define WL1271_CIPHER_SUITE_GEM 0x00147201
39 #define WL1271_BUSY_WORD_CNT 1
40 #define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32))
42 #define WL1271_ELP_HW_STATE_ASLEEP 0
43 #define WL1271_ELP_HW_STATE_IRQ 1
45 #define WL1271_DEFAULT_BEACON_INT 100
46 #define WL1271_DEFAULT_DTIM_PERIOD 1
48 #define WL12XX_MAX_ROLES 4
49 #define WL12XX_INVALID_ROLE_ID 0xff
50 #define WL12XX_INVALID_LINK_ID 0xff
53 * max number of links allowed by all HWs.
54 * this is NOT the actual max links supported by the current hw.
56 #define WLCORE_MAX_LINKS 16
58 /* the driver supports the 2.4Ghz and 5Ghz bands */
59 #define WLCORE_NUM_BANDS 2
61 #define WL12XX_MAX_RATE_POLICIES 16
62 #define WLCORE_MAX_KLV_TEMPLATES 4
64 /* Defined by FW as 0. Will not be freed or allocated. */
65 #define WL12XX_SYSTEM_HLID 0
68 * When in AP-mode, we allow (at least) this number of packets
69 * to be transmitted to FW for a STA in PS-mode. Only when packets are
70 * present in the FW buffers it will wake the sleeping STA. We want to put
71 * enough packets for the driver to transmit all of its buffered data before
72 * the STA goes to sleep again. But we don't want to take too much memory
73 * as it might hurt the throughput of active STAs.
75 #define WL1271_PS_STA_MAX_PACKETS 2
77 #define WL1271_AP_BSS_INDEX 0
78 #define WL1271_AP_DEF_BEACON_EXP 20
82 WLCORE_STATE_RESTARTING,
88 WL12XX_FW_TYPE_NORMAL,
107 char fw_ver_str[ETHTOOL_FWVERS_LEN];
108 unsigned int fw_ver[NUM_FW_VER];
109 char phy_fw_ver_str[ETHTOOL_FWVERS_LEN];
112 #define NUM_TX_QUEUES 4
114 struct wl_fw_status {
118 u8 tx_results_counter;
119 __le32 *rx_pkt_descs;
124 * A bitmap (where each bit represents a single HLID)
125 * to indicate if the station is in PS mode.
130 * A bitmap (where each bit represents a single HLID) to indicate
131 * if the station is in Fast mode
133 u32 link_fast_bitmap;
135 /* Cumulative counter of total released mem blocks since FW-reset */
136 u32 total_released_blks;
138 /* Size (in Memory Blocks) of TX pool */
143 * Cumulative counter of released packets per AC
144 * (length of the array is NUM_TX_QUEUES)
146 u8 *tx_released_pkts;
149 * Cumulative counter of freed packets per HLID
150 * (length of the array is wl->num_links)
152 u8 *tx_lnk_free_pkts;
154 /* Cumulative counter of released Voice memory blocks */
155 u8 tx_voice_released_blks;
157 /* Tx rate of the last transmitted packet */
160 /* Tx rate or Tx rate estimate pre calculated by fw in mbps */
161 u8 tx_last_rate_mbps;
163 /* hlid for which the rates were reported */
169 /* Private status to be used by the lower drivers */
173 #define WL1271_MAX_CHANNELS 64
175 struct cfg80211_scan_request *req;
176 unsigned long scanned_ch[BITS_TO_LONGS(WL1271_MAX_CHANNELS)];
179 u8 ssid[IEEE80211_MAX_SSID_LEN+1];
183 struct wl1271_if_operations {
184 int __must_check (*read)(struct device *child, int addr, void *buf,
185 size_t len, bool fixed);
186 int __must_check (*write)(struct device *child, int addr, void *buf,
187 size_t len, bool fixed);
188 void (*reset)(struct device *child);
189 void (*init)(struct device *child);
190 int (*power)(struct device *child, bool enable);
191 void (*set_block_size) (struct device *child, unsigned int blksz);
194 struct wlcore_platdev_data {
195 struct wl1271_if_operations *if_ops;
196 const struct wilink_family_data *family;
198 bool ref_clock_xtal; /* specify whether the clock is XTAL or not */
199 u32 ref_clock_freq; /* in Hertz */
200 u32 tcxo_clock_freq; /* in Hertz, tcxo is always XTAL */
204 #define MAX_NUM_KEYS 14
205 #define MAX_KEY_SIZE 32
207 struct wl1271_ap_key {
211 u8 key[MAX_KEY_SIZE];
219 WL1271_FLAG_GPIO_POWER,
220 WL1271_FLAG_TX_QUEUE_STOPPED,
221 WL1271_FLAG_TX_PENDING,
223 WL1271_FLAG_IRQ_RUNNING,
224 WL1271_FLAG_FW_TX_BUSY,
225 WL1271_FLAG_DUMMY_PACKET_PENDING,
226 WL1271_FLAG_SUSPENDED,
227 WL1271_FLAG_PENDING_WORK,
228 WL1271_FLAG_SOFT_GEMINI,
229 WL1271_FLAG_RECOVERY_IN_PROGRESS,
230 WL1271_FLAG_VIF_CHANGE_IN_PROGRESS,
231 WL1271_FLAG_INTENDED_FW_RECOVERY,
232 WL1271_FLAG_IO_FAILED,
233 WL1271_FLAG_REINIT_TX_WDOG,
236 enum wl12xx_vif_flags {
237 WLVIF_FLAG_INITIALIZED,
238 WLVIF_FLAG_STA_ASSOCIATED,
239 WLVIF_FLAG_STA_AUTHORIZED,
240 WLVIF_FLAG_IBSS_JOINED,
241 WLVIF_FLAG_AP_STARTED,
243 WLVIF_FLAG_STA_STATE_SENT,
244 WLVIF_FLAG_RX_STREAMING_STARTED,
245 WLVIF_FLAG_PSPOLL_FAILURE,
246 WLVIF_FLAG_CS_PROGRESS,
247 WLVIF_FLAG_AP_PROBE_RESP_SET,
250 WLVIF_FLAG_BEACON_DISABLED,
256 /* AP-mode - TX queue per AC in link */
257 struct sk_buff_head tx_queue[NUM_TX_QUEUES];
259 /* accounting for allocated / freed packets in FW */
265 /* bitmap of TIDs where RX BA sessions are active for this link */
268 /* the last fw rate index we used for this link */
271 /* the last fw rate [Mbps] we used for this link */
274 /* The wlvif this link belongs to. Might be null for global links */
275 struct wl12xx_vif *wlvif;
278 * total freed FW packets on the link - used for tracking the
279 * AES/TKIP PN across recoveries. Re-initialized each time
280 * from the wl1271_station structure.
282 u64 total_freed_pkts;
285 #define WL1271_MAX_RX_FILTERS 5
286 #define WL1271_RX_FILTER_MAX_FIELDS 8
288 #define WL1271_RX_FILTER_ETH_HEADER_SIZE 14
289 #define WL1271_RX_FILTER_MAX_FIELDS_SIZE 95
290 #define RX_FILTER_FIELD_OVERHEAD \
291 (sizeof(struct wl12xx_rx_filter_field) - sizeof(u8 *))
292 #define WL1271_RX_FILTER_MAX_PATTERN_SIZE \
293 (WL1271_RX_FILTER_MAX_FIELDS_SIZE - RX_FILTER_FIELD_OVERHEAD)
295 #define WL1271_RX_FILTER_FLAG_MASK BIT(0)
296 #define WL1271_RX_FILTER_FLAG_IP_HEADER 0
297 #define WL1271_RX_FILTER_FLAG_ETHERNET_HEADER BIT(1)
299 enum rx_filter_action {
312 struct wl12xx_rx_filter_field {
319 struct wl12xx_rx_filter {
322 struct wl12xx_rx_filter_field fields[WL1271_RX_FILTER_MAX_FIELDS];
325 struct wl1271_station {
330 * total freed FW packets on the link to the STA - used for tracking the
331 * AES/TKIP PN across recoveries. Re-initialized each time from the
332 * wl1271_station structure.
333 * Used in both AP and STA mode.
335 u64 total_freed_pkts;
340 struct list_head list;
343 u8 p2p; /* we are using p2p role */
346 /* sta/ibss specific */
361 /* channel type we started the STA role with */
362 enum nl80211_channel_type role_chan_type;
368 /* HLIDs bitmap of associated stations */
369 unsigned long sta_hlid_map[BITS_TO_LONGS(
372 /* recoreded keys - set here before AP startup */
373 struct wl1271_ap_key *recorded_keys[MAX_NUM_KEYS];
377 u8 ucast_rate_idx[CONF_TX_MAX_AC_COUNT];
381 /* the hlid of the last transmitted skb */
384 /* counters of packets per AC, across all links in the vif */
385 int tx_queue_count[NUM_TX_QUEUES];
387 unsigned long links_map[BITS_TO_LONGS(WLCORE_MAX_LINKS)];
389 u8 ssid[IEEE80211_MAX_SSID_LEN + 1];
392 /* The current band */
393 enum nl80211_band band;
395 enum nl80211_channel_type channel_type;
397 u32 bitrate_masks[WLCORE_NUM_BANDS];
401 * currently configured rate set:
402 * bits 0-15 - 802.11abg rates
403 * bits 16-23 - 802.11n MCS index mask
404 * support only 1 stream, thus only 8 bits for the MCS rates (0-7).
409 /* probe-req template for the current AP */
410 struct sk_buff *probereq;
412 /* Beaconing interval (needed for ad-hoc) */
415 /* Default key (for WEP) */
418 /* Our association ID */
421 /* retry counter for PSM entries */
430 /* save the current encryption type for auto-arp config */
434 /* RX BA constraint value */
443 struct work_struct rx_streaming_enable_work;
444 struct work_struct rx_streaming_disable_work;
445 struct timer_list rx_streaming_timer;
447 struct delayed_work channel_switch_work;
448 struct delayed_work connection_loss_work;
450 /* number of in connection stations */
454 * This vif's queues are mapped to mac80211 HW queues as:
456 * VI - hw_queue_base + 1
457 * BE - hw_queue_base + 2
458 * BK - hw_queue_base + 3
462 /* do we have a pending auth reply? (and ROC) */
463 bool ap_pending_auth_reply;
465 /* time when we sent the pending auth reply */
466 unsigned long pending_auth_reply_time;
468 /* work for canceling ROC after pending auth reply */
469 struct delayed_work pending_auth_complete_work;
471 /* update rate conrol */
472 enum ieee80211_sta_rx_bandwidth rc_update_bw;
473 struct ieee80211_sta_ht_cap rc_ht_cap;
474 struct work_struct rc_update_work;
477 * total freed FW packets on the link.
478 * For STA this holds the PN of the link to the AP.
479 * For AP this holds the PN of the broadcast link.
481 u64 total_freed_pkts;
484 * This struct must be last!
485 * data that has to be saved acrossed reconfigs (e.g. recovery)
486 * should be declared in this struct.
493 static inline struct wl12xx_vif *wl12xx_vif_to_data(struct ieee80211_vif *vif)
496 return (struct wl12xx_vif *)vif->drv_priv;
500 struct ieee80211_vif *wl12xx_wlvif_to_vif(struct wl12xx_vif *wlvif)
502 return container_of((void *)wlvif, struct ieee80211_vif, drv_priv);
505 static inline bool wlcore_is_p2p_mgmt(struct wl12xx_vif *wlvif)
507 return wl12xx_wlvif_to_vif(wlvif)->type == NL80211_IFTYPE_P2P_DEVICE;
510 #define wl12xx_for_each_wlvif(wl, wlvif) \
511 list_for_each_entry(wlvif, &wl->wlvif_list, list)
513 #define wl12xx_for_each_wlvif_continue(wl, wlvif) \
514 list_for_each_entry_continue(wlvif, &wl->wlvif_list, list)
516 #define wl12xx_for_each_wlvif_bss_type(wl, wlvif, _bss_type) \
517 wl12xx_for_each_wlvif(wl, wlvif) \
518 if (wlvif->bss_type == _bss_type)
520 #define wl12xx_for_each_wlvif_sta(wl, wlvif) \
521 wl12xx_for_each_wlvif_bss_type(wl, wlvif, BSS_TYPE_STA_BSS)
523 #define wl12xx_for_each_wlvif_ap(wl, wlvif) \
524 wl12xx_for_each_wlvif_bss_type(wl, wlvif, BSS_TYPE_AP_BSS)
526 int wl1271_plt_start(struct wl1271 *wl, const enum plt_mode plt_mode);
527 int wl1271_plt_stop(struct wl1271 *wl);
528 int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif);
529 void wl12xx_queue_recovery_work(struct wl1271 *wl);
530 size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen);
531 int wl1271_rx_filter_alloc_field(struct wl12xx_rx_filter *filter,
532 u16 offset, u8 flags,
533 const u8 *pattern, u8 len);
534 void wl1271_rx_filter_free(struct wl12xx_rx_filter *filter);
535 struct wl12xx_rx_filter *wl1271_rx_filter_alloc(void);
536 int wl1271_rx_filter_get_fields_size(struct wl12xx_rx_filter *filter);
537 void wl1271_rx_filter_flatten_fields(struct wl12xx_rx_filter *filter,
540 #define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
542 #define SESSION_COUNTER_MAX 6 /* maximum value for the session counter */
543 #define SESSION_COUNTER_INVALID 7 /* used with dummy_packet */
545 #define WL1271_DEFAULT_POWER_LEVEL 0
547 #define WL1271_TX_QUEUE_LOW_WATERMARK 32
548 #define WL1271_TX_QUEUE_HIGH_WATERMARK 256
550 #define WL1271_DEFERRED_QUEUE_LIMIT 64
552 /* WL1271 needs a 200ms sleep after power on, and a 20ms sleep before power
553 on in case is has been shut down shortly before */
554 #define WL1271_PRE_POWER_ON_SLEEP 20 /* in milliseconds */
555 #define WL1271_POWER_ON_SLEEP 200 /* in milliseconds */
557 /* Macros to handle wl1271.sta_rate_set */
558 #define HW_BG_RATES_MASK 0xffff
559 #define HW_HT_RATES_OFFSET 16
560 #define HW_MIMO_RATES_OFFSET 24
562 #endif /* __WLCORE_I_H__ */