wl12xx.h 11.1 KB
Newer Older
L
Luciano Coelho 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * This file is part of wl1271
 *
 * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
 * Copyright (C) 2008-2009 Nokia Corporation
 *
 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

S
Shahar Levi 已提交
25 26
#ifndef __WL12XX_H__
#define __WL12XX_H__
L
Luciano Coelho 已提交
27 28 29 30 31 32 33 34

#include <linux/mutex.h>
#include <linux/completion.h>
#include <linux/spinlock.h>
#include <linux/list.h>
#include <linux/bitops.h>
#include <net/mac80211.h>

S
Shahar Levi 已提交
35 36
#include "conf.h"
#include "ini.h"
37

38 39 40 41 42 43
#define WL127X_FW_NAME_MULTI "ti-connectivity/wl127x-fw-4-mr.bin"
#define WL127X_FW_NAME_SINGLE "ti-connectivity/wl127x-fw-4-sr.bin"

#define WL128X_FW_NAME_MULTI "ti-connectivity/wl128x-fw-4-mr.bin"
#define WL128X_FW_NAME_SINGLE "ti-connectivity/wl128x-fw-4-sr.bin"

44 45
#define WL127X_PLT_FW_NAME "ti-connectivity/wl127x-fw-4-plt.bin"
#define WL128X_PLT_FW_NAME "ti-connectivity/wl128x-fw-4-plt.bin"
46

47 48 49 50 51 52
/*
 * wl127x and wl128x are using the same NVS file name. However, the
 * ini parameters between them are different.  The driver validates
 * the correct NVS size in wl1271_boot_upload_nvs().
 */
#define WL12XX_NVS_NAME "ti-connectivity/wl1271-nvs.bin"
53

54 55
#define WL1271_TX_SECURITY_LO16(s) ((u16)((s) & 0xffff))
#define WL1271_TX_SECURITY_HI32(s) ((u32)(((s) >> 16) & 0xffffffff))
56
#define WL1271_TX_SQN_POST_RECOVERY_PADDING 0xff
57

58 59
#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))
L
Luciano Coelho 已提交
62 63 64 65

#define WL1271_ELP_HW_STATE_ASLEEP 0
#define WL1271_ELP_HW_STATE_IRQ    1

J
Juuso Oikarinen 已提交
66 67 68
#define WL1271_DEFAULT_BEACON_INT  100
#define WL1271_DEFAULT_DTIM_PERIOD 1

E
Eliad Peller 已提交
69
#define WL12XX_MAX_ROLES           4
70
#define WL12XX_MAX_LINKS           12
E
Eliad Peller 已提交
71 72
#define WL12XX_INVALID_ROLE_ID     0xff
#define WL12XX_INVALID_LINK_ID     0xff
73

E
Eliad Peller 已提交
74 75
#define WL12XX_MAX_RATE_POLICIES 16

76
/* Defined by FW as 0. Will not be freed or allocated. */
E
Eliad Peller 已提交
77
#define WL12XX_SYSTEM_HLID         0
78

79
/*
80
 * When in AP-mode, we allow (at least) this number of packets
81 82 83
 * to be transmitted to FW for a STA in PS-mode. Only when packets are
 * present in the FW buffers it will wake the sleeping STA. We want to put
 * 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 86
 * as it might hurt the throughput of active STAs.
 */
87
#define WL1271_PS_STA_MAX_PACKETS  2
88

89 90 91
#define WL1271_AP_BSS_INDEX        0
#define WL1271_AP_DEF_BEACON_EXP   20

92 93
#define WL1271_AGGR_BUFFER_SIZE (4 * PAGE_SIZE)

L
Luciano Coelho 已提交
94 95 96
enum wl1271_state {
	WL1271_STATE_OFF,
	WL1271_STATE_ON,
97 98 99 100 101
};

enum wl12xx_fw_type {
	WL12XX_FW_TYPE_NONE,
	WL12XX_FW_TYPE_NORMAL,
102
	WL12XX_FW_TYPE_MULTI,
103
	WL12XX_FW_TYPE_PLT,
L
Luciano Coelho 已提交
104 105 106 107
};

struct wl1271;

108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
enum {
	FW_VER_CHIP,
	FW_VER_IF_TYPE,
	FW_VER_MAJOR,
	FW_VER_SUBTYPE,
	FW_VER_MINOR,

	NUM_FW_VER
};

#define FW_VER_CHIP_WL127X 6
#define FW_VER_CHIP_WL128X 7

#define FW_VER_IF_TYPE_STA 1
#define FW_VER_IF_TYPE_AP  2

#define FW_VER_MINOR_1_SPARE_STA_MIN 58
#define FW_VER_MINOR_1_SPARE_AP_MIN  47
L
Levi, Shahar 已提交
126

127 128
#define FW_VER_MINOR_FWLOG_STA_MIN 70

L
Luciano Coelho 已提交
129 130
struct wl1271_chip {
	u32 id;
L
Levi, Shahar 已提交
131
	char fw_ver_str[ETHTOOL_BUSINFO_LEN];
132
	unsigned int fw_ver[NUM_FW_VER];
L
Luciano Coelho 已提交
133 134 135 136 137 138 139 140 141 142 143 144 145
};

struct wl1271_stats {
	struct acx_statistics *fw_stats;
	unsigned long fw_stats_update;

	unsigned int retry_count;
	unsigned int excessive_retries;
};

#define NUM_TX_QUEUES              4
#define NUM_RX_PKT_DESC            8

146
#define AP_MAX_STATIONS            8
147

E
Eliad Peller 已提交
148 149
/* FW status registers */
struct wl12xx_fw_status {
L
Luciano Coelho 已提交
150
	__le32 intr;
L
Luciano Coelho 已提交
151 152 153 154
	u8  fw_rx_counter;
	u8  drv_rx_counter;
	u8  reserved;
	u8  tx_results_counter;
L
Luciano Coelho 已提交
155 156
	__le32 rx_pkt_descs[NUM_RX_PKT_DESC];
	__le32 fw_localtime;
157 158 159 160 161 162 163

	/*
	 * A bitmap (where each bit represents a single HLID)
	 * to indicate if the station is in PS mode.
	 */
	__le32 link_ps_bitmap;

E
Eliad Peller 已提交
164 165 166 167 168
	/*
	 * A bitmap (where each bit represents a single HLID) to indicate
	 * if the station is in Fast mode
	 */
	__le32 link_fast_bitmap;
L
Luciano Coelho 已提交
169

E
Eliad Peller 已提交
170 171
	/* Cumulative counter of total released mem blocks since FW-reset */
	__le32 total_released_blks;
172

E
Eliad Peller 已提交
173 174
	/* Size (in Memory Blocks) of TX pool */
	__le32 tx_total;
175

176 177
	/* Cumulative counter of released packets per AC */
	u8 tx_released_pkts[NUM_TX_QUEUES];
178

179 180
	/* Cumulative counter of freed packets per HLID */
	u8 tx_lnk_free_pkts[WL12XX_MAX_LINKS];
E
Eliad Peller 已提交
181 182 183

	/* Cumulative counter of released Voice memory blocks */
	u8 tx_voice_released_blks;
184
	u8 padding_1[3];
E
Eliad Peller 已提交
185 186
	__le32 log_start_addr;
} __packed;
187

L
Luciano Coelho 已提交
188 189 190 191 192
struct wl1271_rx_mem_pool_addr {
	u32 addr;
	u32 addr_extra;
};

193
#define WL1271_MAX_CHANNELS 64
194
struct wl1271_scan {
195
	struct cfg80211_scan_request *req;
196
	unsigned long scanned_ch[BITS_TO_LONGS(WL1271_MAX_CHANNELS)];
197
	bool failed;
198
	u8 state;
J
Johannes Berg 已提交
199
	u8 ssid[IEEE80211_MAX_SSID_LEN+1];
200 201 202
	size_t ssid_len;
};

203
struct wl1271_if_operations {
204
	void (*read)(struct device *child, int addr, void *buf, size_t len,
205
		     bool fixed);
206
	void (*write)(struct device *child, int addr, void *buf, size_t len,
207
		     bool fixed);
208 209 210 211
	void (*reset)(struct device *child);
	void (*init)(struct device *child);
	int (*power)(struct device *child, bool enable);
	void (*set_block_size) (struct device *child, unsigned int blksz);
212 213
};

214 215 216 217 218 219 220 221 222 223 224 225 226
#define MAX_NUM_KEYS 14
#define MAX_KEY_SIZE 32

struct wl1271_ap_key {
	u8 id;
	u8 key_type;
	u8 key_size;
	u8 key[MAX_KEY_SIZE];
	u8 hlid;
	u32 tx_seq_32;
	u16 tx_seq_16;
};

227 228 229
enum wl12xx_flags {
	WL1271_FLAG_GPIO_POWER,
	WL1271_FLAG_TX_QUEUE_STOPPED,
I
Ido Yariv 已提交
230
	WL1271_FLAG_TX_PENDING,
231
	WL1271_FLAG_IN_ELP,
232
	WL1271_FLAG_ELP_REQUESTED,
233 234
	WL1271_FLAG_IRQ_RUNNING,
	WL1271_FLAG_FW_TX_BUSY,
235
	WL1271_FLAG_DUMMY_PACKET_PENDING,
236 237
	WL1271_FLAG_SUSPENDED,
	WL1271_FLAG_PENDING_WORK,
238
	WL1271_FLAG_SOFT_GEMINI,
239
	WL1271_FLAG_RECOVERY_IN_PROGRESS,
240
	WL1271_FLAG_VIF_CHANGE_IN_PROGRESS,
241
	WL1271_FLAG_INTENDED_FW_RECOVERY,
242 243
};

244
enum wl12xx_vif_flags {
245
	WLVIF_FLAG_INITIALIZED,
246
	WLVIF_FLAG_STA_ASSOCIATED,
247
	WLVIF_FLAG_STA_AUTHORIZED,
248
	WLVIF_FLAG_IBSS_JOINED,
249
	WLVIF_FLAG_AP_STARTED,
E
Eyal Shapira 已提交
250
	WLVIF_FLAG_IN_PS,
251
	WLVIF_FLAG_STA_STATE_SENT,
252
	WLVIF_FLAG_RX_STREAMING_STARTED,
253
	WLVIF_FLAG_PSPOLL_FAILURE,
254
	WLVIF_FLAG_CS_PROGRESS,
255
	WLVIF_FLAG_AP_PROBE_RESP_SET,
256
	WLVIF_FLAG_IN_USE,
257 258
};

259 260 261
struct wl1271_link {
	/* AP-mode - TX queue per AC in link */
	struct sk_buff_head tx_queue[NUM_TX_QUEUES];
262

263 264 265
	/* accounting for allocated / freed packets in FW */
	u8 allocated_pkts;
	u8 prev_freed_pkts;
266 267

	u8 addr[ETH_ALEN];
268 269 270

	/* bitmap of TIDs where RX BA sessions are active for this link */
	u8 ba_bitmap;
271 272
};

273 274
struct wl1271_station {
	u8 hlid;
L
Luciano Coelho 已提交
275 276
};

E
Eliad Peller 已提交
277
struct wl12xx_vif {
E
Eliad Peller 已提交
278
	struct wl1271 *wl;
E
Eliad Peller 已提交
279
	struct list_head list;
280
	unsigned long flags;
E
Eliad Peller 已提交
281
	u8 bss_type;
E
Eliad Peller 已提交
282
	u8 p2p; /* we are using p2p role */
E
Eliad Peller 已提交
283
	u8 role_id;
E
Eliad Peller 已提交
284

E
Eliad Peller 已提交
285 286
	/* sta/ibss specific */
	u8 dev_role_id;
E
Eliad Peller 已提交
287
	u8 dev_hlid;
E
Eliad Peller 已提交
288

E
Eliad Peller 已提交
289 290 291
	union {
		struct {
			u8 hlid;
E
Eliad Peller 已提交
292
			u8 ba_rx_bitmap;
E
Eliad Peller 已提交
293 294 295 296

			u8 basic_rate_idx;
			u8 ap_rate_idx;
			u8 p2p_rate_idx;
297 298

			bool qos;
E
Eliad Peller 已提交
299
		} sta;
300 301 302
		struct {
			u8 global_hlid;
			u8 bcast_hlid;
303 304 305 306

			/* HLIDs bitmap of associated stations */
			unsigned long sta_hlid_map[BITS_TO_LONGS(
							WL12XX_MAX_LINKS)];
307 308 309

			/* recoreded keys - set here before AP startup */
			struct wl1271_ap_key *recorded_keys[MAX_NUM_KEYS];
E
Eliad Peller 已提交
310 311 312 313

			u8 mgmt_rate_idx;
			u8 bcast_rate_idx;
			u8 ucast_rate_idx[CONF_TX_MAX_AC_COUNT];
314
		} ap;
E
Eliad Peller 已提交
315 316
	};

317 318 319
	/* the hlid of the last transmitted skb */
	int last_tx_hlid;

320 321
	unsigned long links_map[BITS_TO_LONGS(WL12XX_MAX_LINKS)];

322 323 324
	u8 ssid[IEEE80211_MAX_SSID_LEN + 1];
	u8 ssid_len;

E
Eliad Peller 已提交
325 326
	/* The current band */
	enum ieee80211_band band;
E
Eliad Peller 已提交
327
	int channel;
E
Eliad Peller 已提交
328

329
	u32 bitrate_masks[IEEE80211_NUM_BANDS];
E
Eliad Peller 已提交
330
	u32 basic_rate_set;
E
Eliad Peller 已提交
331 332 333 334 335 336 337

	/*
	 * currently configured rate set:
	 *	bits  0-15 - 802.11abg rates
	 *	bits 16-23 - 802.11n   MCS index mask
	 * support only 1 stream, thus only 8 bits for the MCS rates (0-7).
	 */
E
Eliad Peller 已提交
338
	u32 basic_rate;
E
Eliad Peller 已提交
339
	u32 rate_set;
E
Eliad Peller 已提交
340 341 342

	/* probe-req template for the current AP */
	struct sk_buff *probereq;
E
Eliad Peller 已提交
343

E
Eliad Peller 已提交
344 345 346
	/* Beaconing interval (needed for ad-hoc) */
	u32 beacon_int;

E
Eliad Peller 已提交
347 348 349
	/* Default key (for WEP) */
	u32 default_key;

E
Eliad Peller 已提交
350 351
	/* Our association ID */
	u16 aid;
352 353 354

	/* Session counter for the chipset */
	int session_counter;
E
Eliad Peller 已提交
355

356 357
	/* retry counter for PSM entries */
	u8 psm_entry_retry;
358

359 360 361
	/* in dBm */
	int power_level;

362 363
	int rssi_thold;
	int last_rssi_event;
E
Eliad Peller 已提交
364

365 366 367 368
	/* save the current encryption type for auto-arp config */
	u8 encryption_type;
	__be32 ip_addr;

E
Eliad Peller 已提交
369 370 371
	/* RX BA constraint value */
	bool ba_support;
	bool ba_allowed;
372

E
Eliad Peller 已提交
373 374 375 376 377
	/* Rx Streaming */
	struct work_struct rx_streaming_enable_work;
	struct work_struct rx_streaming_disable_work;
	struct timer_list rx_streaming_timer;

378 379 380
	/* does the current role use GEM for encryption (AP or STA) */
	bool is_gem;

381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
	/*
	 * This struct must be last!
	 * data that has to be saved acrossed reconfigs (e.g. recovery)
	 * should be declared in this struct.
	 */
	struct {
		u8 persistent[0];
		/*
		 * Security sequence number
		 *     bits 0-15: lower 16 bits part of sequence number
		 *     bits 16-47: higher 32 bits part of sequence number
		 *     bits 48-63: not in use
		 */
		u64 tx_security_seq;

		/* 8 bits of the last sequence number in use */
		u8 tx_security_last_seq_lsb;
	};
E
Eliad Peller 已提交
399 400 401 402 403 404 405 406 407 408 409 410 411
};

static inline struct wl12xx_vif *wl12xx_vif_to_data(struct ieee80211_vif *vif)
{
	return (struct wl12xx_vif *)vif->drv_priv;
}

static inline
struct ieee80211_vif *wl12xx_wlvif_to_vif(struct wl12xx_vif *wlvif)
{
	return container_of((void *)wlvif, struct ieee80211_vif, drv_priv);
}

E
Eliad Peller 已提交
412 413 414
#define wl12xx_for_each_wlvif(wl, wlvif) \
		list_for_each_entry(wlvif, &wl->wlvif_list, list)

415 416 417
#define wl12xx_for_each_wlvif_continue(wl, wlvif) \
		list_for_each_entry_continue(wlvif, &wl->wlvif_list, list)

418 419 420 421 422 423 424 425 426 427
#define wl12xx_for_each_wlvif_bss_type(wl, wlvif, _bss_type)	\
		wl12xx_for_each_wlvif(wl, wlvif)		\
			if (wlvif->bss_type == _bss_type)

#define wl12xx_for_each_wlvif_sta(wl, wlvif)	\
		wl12xx_for_each_wlvif_bss_type(wl, wlvif, BSS_TYPE_STA_BSS)

#define wl12xx_for_each_wlvif_ap(wl, wlvif)	\
		wl12xx_for_each_wlvif_bss_type(wl, wlvif, BSS_TYPE_AP_BSS)

L
Luciano Coelho 已提交
428 429
int wl1271_plt_start(struct wl1271 *wl);
int wl1271_plt_stop(struct wl1271 *wl);
E
Eliad Peller 已提交
430
int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif);
431
void wl12xx_queue_recovery_work(struct wl1271 *wl);
432
size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen);
L
Luciano Coelho 已提交
433 434 435

#define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */

436 437
#define SESSION_COUNTER_MAX 6 /* maximum value for the session counter */
#define SESSION_COUNTER_INVALID 7 /* used with dummy_packet */
L
Luciano Coelho 已提交
438 439 440

#define WL1271_DEFAULT_POWER_LEVEL 0

441 442
#define WL1271_TX_QUEUE_LOW_WATERMARK  32
#define WL1271_TX_QUEUE_HIGH_WATERMARK 256
L
Luciano Coelho 已提交
443

444 445
#define WL1271_DEFERRED_QUEUE_LIMIT    64

J
Juuso Oikarinen 已提交
446 447
/* WL1271 needs a 200ms sleep after power on, and a 20ms sleep before power
   on in case is has been shut down shortly before */
S
Stefan Weil 已提交
448 449
#define WL1271_PRE_POWER_ON_SLEEP 20 /* in milliseconds */
#define WL1271_POWER_ON_SLEEP 200 /* in milliseconds */
L
Luciano Coelho 已提交
450

S
Shahar Levi 已提交
451 452 453 454
/* Macros to handle wl1271.sta_rate_set */
#define HW_BG_RATES_MASK	0xffff
#define HW_HT_RATES_OFFSET	16

455 456
#define WL12XX_HW_BLOCK_SIZE	256

L
Luciano Coelho 已提交
457
#endif