wl12xx.h 11.8 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

L
Luciano Coelho 已提交
38 39 40
#define DRIVER_NAME "wl1271"
#define DRIVER_PREFIX DRIVER_NAME ": "

L
Levi, Shahar 已提交
41 42 43 44 45 46 47
/*
 * FW versions support BA 11n
 * versions marks x.x.x.50-60.x
 */
#define WL12XX_BA_SUPPORT_FW_COST_VER2_START    50
#define WL12XX_BA_SUPPORT_FW_COST_VER2_END      60

L
Luciano Coelho 已提交
48 49 50 51 52 53
enum {
	DEBUG_NONE	= 0,
	DEBUG_IRQ	= BIT(0),
	DEBUG_SPI	= BIT(1),
	DEBUG_BOOT	= BIT(2),
	DEBUG_MAILBOX	= BIT(3),
K
Kalle Valo 已提交
54
	DEBUG_TESTMODE	= BIT(4),
L
Luciano Coelho 已提交
55 56 57 58 59 60 61 62 63
	DEBUG_EVENT	= BIT(5),
	DEBUG_TX	= BIT(6),
	DEBUG_RX	= BIT(7),
	DEBUG_SCAN	= BIT(8),
	DEBUG_CRYPT	= BIT(9),
	DEBUG_PSM	= BIT(10),
	DEBUG_MAC80211	= BIT(11),
	DEBUG_CMD	= BIT(12),
	DEBUG_ACX	= BIT(13),
T
Teemu Paasikivi 已提交
64
	DEBUG_SDIO	= BIT(14),
65
	DEBUG_FILTERS   = BIT(15),
66
	DEBUG_ADHOC     = BIT(16),
67 68
	DEBUG_AP	= BIT(17),
	DEBUG_MASTER	= (DEBUG_ADHOC | DEBUG_AP),
L
Luciano Coelho 已提交
69 70 71
	DEBUG_ALL	= ~0,
};

72
extern u32 wl12xx_debug_level;
L
Luciano Coelho 已提交
73 74 75 76

#define DEBUG_DUMP_LIMIT 1024

#define wl1271_error(fmt, arg...) \
77
	pr_err(DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
L
Luciano Coelho 已提交
78 79

#define wl1271_warning(fmt, arg...) \
80
	pr_warning(DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
L
Luciano Coelho 已提交
81 82

#define wl1271_notice(fmt, arg...) \
83
	pr_info(DRIVER_PREFIX fmt "\n", ##arg)
L
Luciano Coelho 已提交
84 85

#define wl1271_info(fmt, arg...) \
86
	pr_info(DRIVER_PREFIX fmt "\n", ##arg)
L
Luciano Coelho 已提交
87 88 89

#define wl1271_debug(level, fmt, arg...) \
	do { \
90 91
		if (level & wl12xx_debug_level) \
			pr_debug(DRIVER_PREFIX fmt "\n", ##arg); \
L
Luciano Coelho 已提交
92 93
	} while (0)

94
/* TODO: use pr_debug_hex_dump when it will be available */
L
Luciano Coelho 已提交
95 96
#define wl1271_dump(level, prefix, buf, len)	\
	do { \
97
		if (level & wl12xx_debug_level) \
L
Luciano Coelho 已提交
98 99 100 101 102 103 104 105 106
			print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
				       DUMP_PREFIX_OFFSET, 16, 1,	\
				       buf,				\
				       min_t(size_t, len, DEBUG_DUMP_LIMIT), \
				       0);				\
	} while (0)

#define wl1271_dump_ascii(level, prefix, buf, len)	\
	do { \
107
		if (level & wl12xx_debug_level) \
L
Luciano Coelho 已提交
108 109 110 111 112 113 114
			print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
				       DUMP_PREFIX_OFFSET, 16, 1,	\
				       buf,				\
				       min_t(size_t, len, DEBUG_DUMP_LIMIT), \
				       true);				\
	} while (0)

115
#define WL1271_DEFAULT_STA_RX_CONFIG (CFG_UNI_FILTER_EN |	\
116 117
				  CFG_BSSID_FILTER_EN | \
				  CFG_MC_FILTER_EN)
L
Luciano Coelho 已提交
118

119
#define WL1271_DEFAULT_STA_RX_FILTER (CFG_RX_RCTS_ACK | CFG_RX_PRSP_EN |  \
L
Luciano Coelho 已提交
120 121 122 123
				  CFG_RX_MGMT_EN | CFG_RX_DATA_EN |   \
				  CFG_RX_CTL_EN | CFG_RX_BCN_EN |     \
				  CFG_RX_AUTH_EN | CFG_RX_ASSOC_EN)

124 125 126 127 128 129 130 131 132
#define WL1271_DEFAULT_AP_RX_CONFIG  0

#define WL1271_DEFAULT_AP_RX_FILTER  (CFG_RX_RCTS_ACK | CFG_RX_PREQ_EN | \
				  CFG_RX_MGMT_EN | CFG_RX_DATA_EN | \
				  CFG_RX_CTL_EN | CFG_RX_AUTH_EN | \
				  CFG_RX_ASSOC_EN)



133
#define WL1271_FW_NAME "wl1271-fw-2.bin"
134 135
#define WL1271_AP_FW_NAME "wl1271-fw-ap.bin"

L
Luciano Coelho 已提交
136
#define WL1271_NVS_NAME "wl1271-nvs.bin"
137

138 139 140
#define WL1271_TX_SECURITY_LO16(s) ((u16)((s) & 0xffff))
#define WL1271_TX_SECURITY_HI32(s) ((u32)(((s) >> 16) & 0xffffffff))

141 142
#define WL1271_CIPHER_SUITE_GEM 0x00147201

143
#define WL1271_BUSY_WORD_CNT 1
144
#define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32))
L
Luciano Coelho 已提交
145 146 147 148

#define WL1271_ELP_HW_STATE_ASLEEP 0
#define WL1271_ELP_HW_STATE_IRQ    1

J
Juuso Oikarinen 已提交
149 150 151
#define WL1271_DEFAULT_BEACON_INT  100
#define WL1271_DEFAULT_DTIM_PERIOD 1

152 153 154 155 156 157 158 159
#define WL1271_AP_GLOBAL_HLID      0
#define WL1271_AP_BROADCAST_HLID   1
#define WL1271_AP_STA_HLID_START   2

#define WL1271_AP_BSS_INDEX        0
#define WL1271_AP_DEF_INACTIV_SEC  300
#define WL1271_AP_DEF_BEACON_EXP   20

160
#define ACX_TX_DESCRIPTORS         32
J
Juuso Oikarinen 已提交
161

162 163
#define WL1271_AGGR_BUFFER_SIZE (4 * PAGE_SIZE)

L
Luciano Coelho 已提交
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
enum wl1271_state {
	WL1271_STATE_OFF,
	WL1271_STATE_ON,
	WL1271_STATE_PLT,
};

enum wl1271_partition_type {
	PART_DOWN,
	PART_WORK,
	PART_DRPW,

	PART_TABLE_LEN
};

struct wl1271_partition {
	u32 size;
	u32 start;
};

struct wl1271_partition_set {
	struct wl1271_partition mem;
	struct wl1271_partition reg;
186 187
	struct wl1271_partition mem2;
	struct wl1271_partition mem3;
L
Luciano Coelho 已提交
188 189 190 191
};

struct wl1271;

L
Levi, Shahar 已提交
192 193
#define WL12XX_NUM_FW_VER 5

L
Luciano Coelho 已提交
194 195 196
/* FIXME: I'm not sure about this structure name */
struct wl1271_chip {
	u32 id;
L
Levi, Shahar 已提交
197 198
	char fw_ver_str[ETHTOOL_BUSINFO_LEN];
	unsigned int fw_ver[WL12XX_NUM_FW_VER];
L
Luciano Coelho 已提交
199 200 201 202 203 204 205 206 207 208 209 210 211
};

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

212 213 214 215 216
#define AP_MAX_STATIONS            5

/* Broadcast and Global links + links to stations */
#define AP_MAX_LINKS               (AP_MAX_STATIONS + 2)

217 218
/* FW status registers common for AP/STA */
struct wl1271_fw_common_status {
L
Luciano Coelho 已提交
219
	__le32 intr;
L
Luciano Coelho 已提交
220 221 222 223
	u8  fw_rx_counter;
	u8  drv_rx_counter;
	u8  reserved;
	u8  tx_results_counter;
L
Luciano Coelho 已提交
224 225 226
	__le32 rx_pkt_descs[NUM_RX_PKT_DESC];
	__le32 tx_released_blks[NUM_TX_QUEUES];
	__le32 fw_localtime;
227 228 229 230 231
} __packed;

/* FW status registers for AP */
struct wl1271_fw_ap_status {
	struct wl1271_fw_common_status common;
232 233 234 235 236 237 238 239 240 241 242 243

	/* Next fields valid only in AP FW */

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

	/* Number of freed MBs per HLID */
	u8 tx_lnk_free_blks[AP_MAX_LINKS];
	u8 padding_1[1];
244
} __packed;
L
Luciano Coelho 已提交
245

246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
/* FW status registers for STA */
struct wl1271_fw_sta_status {
	struct wl1271_fw_common_status common;

	u8  tx_total;
	u8  reserved1;
	__le16 reserved2;
} __packed;

struct wl1271_fw_full_status {
	union {
		struct wl1271_fw_common_status common;
		struct wl1271_fw_sta_status sta;
		struct wl1271_fw_ap_status ap;
	};
} __packed;


L
Luciano Coelho 已提交
264 265 266 267 268
struct wl1271_rx_mem_pool_addr {
	u32 addr;
	u32 addr_extra;
};

269
struct wl1271_scan {
270
	struct cfg80211_scan_request *req;
L
Luciano Coelho 已提交
271
	bool *scanned_ch;
272
	bool failed;
273 274 275 276 277
	u8 state;
	u8 ssid[IW_ESSID_MAX_SIZE+1];
	size_t ssid_len;
};

278 279 280 281 282 283 284
struct wl1271_if_operations {
	void (*read)(struct wl1271 *wl, int addr, void *buf, size_t len,
		     bool fixed);
	void (*write)(struct wl1271 *wl, int addr, void *buf, size_t len,
		     bool fixed);
	void (*reset)(struct wl1271 *wl);
	void (*init)(struct wl1271 *wl);
285
	int (*power)(struct wl1271 *wl, bool enable);
286 287 288 289 290
	struct device* (*dev)(struct wl1271 *wl);
	void (*enable_irq)(struct wl1271 *wl);
	void (*disable_irq)(struct wl1271 *wl);
};

291 292 293 294 295 296 297 298 299 300 301 302 303
#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;
};

304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
enum wl12xx_flags {
	WL1271_FLAG_STA_ASSOCIATED,
	WL1271_FLAG_JOINED,
	WL1271_FLAG_GPIO_POWER,
	WL1271_FLAG_TX_QUEUE_STOPPED,
	WL1271_FLAG_IN_ELP,
	WL1271_FLAG_PSM,
	WL1271_FLAG_PSM_REQUESTED,
	WL1271_FLAG_IRQ_PENDING,
	WL1271_FLAG_IRQ_RUNNING,
	WL1271_FLAG_IDLE,
	WL1271_FLAG_IDLE_REQUESTED,
	WL1271_FLAG_PSPOLL_FAILURE,
	WL1271_FLAG_STA_STATE_SENT,
	WL1271_FLAG_FW_TX_BUSY,
	WL1271_FLAG_AP_STARTED
};

L
Luciano Coelho 已提交
322
struct wl1271 {
323
	struct platform_device *plat_dev;
L
Luciano Coelho 已提交
324 325 326
	struct ieee80211_hw *hw;
	bool mac80211_registered;

327 328 329
	void *if_priv;

	struct wl1271_if_operations *if_ops;
L
Luciano Coelho 已提交
330 331 332

	void (*set_power)(bool enable);
	int irq;
333
	int ref_clock;
L
Luciano Coelho 已提交
334 335 336 337 338 339

	spinlock_t wl_lock;

	enum wl1271_state state;
	struct mutex mutex;

340 341
	unsigned long flags;

342
	struct wl1271_partition_set part;
L
Luciano Coelho 已提交
343 344 345 346 347 348 349 350

	struct wl1271_chip chip;

	int cmd_box_addr;
	int event_box_addr;

	u8 *fw;
	size_t fw_len;
351
	u8 fw_bss_type;
352
	struct wl1271_nvs_file *nvs;
353
	size_t nvs_len;
L
Luciano Coelho 已提交
354

355 356
	s8 hw_pg_ver;

L
Luciano Coelho 已提交
357 358 359
	u8 bssid[ETH_ALEN];
	u8 mac_addr[ETH_ALEN];
	u8 bss_type;
360
	u8 set_bss_type;
L
Luciano Coelho 已提交
361 362 363 364 365 366 367 368 369
	u8 ssid[IW_ESSID_MAX_SIZE + 1];
	u8 ssid_len;
	int channel;

	struct wl1271_acx_mem_map *target_mem_map;

	/* Accounting for allocated / available TX blocks on HW */
	u32 tx_blocks_freed[NUM_TX_QUEUES];
	u32 tx_blocks_available;
370
	u32 tx_results_count;
L
Luciano Coelho 已提交
371 372

	/* Transmitted TX packets counter for chipset interface */
373
	u32 tx_packets_count;
L
Luciano Coelho 已提交
374 375

	/* Time-offset between host and chipset clocks */
376
	s64 time_offset;
L
Luciano Coelho 已提交
377 378 379 380 381

	/* Session counter for the chipset */
	int session_counter;

	/* Frames scheduled for transmission, not handled yet */
382 383
	struct sk_buff_head tx_queue[NUM_TX_QUEUES];
	int tx_queue_count;
L
Luciano Coelho 已提交
384 385

	struct work_struct tx_work;
386

L
Luciano Coelho 已提交
387
	/* Pending TX frames */
388
	unsigned long tx_frames_map[BITS_TO_LONGS(ACX_TX_DESCRIPTORS)];
J
Juuso Oikarinen 已提交
389
	struct sk_buff *tx_frames[ACX_TX_DESCRIPTORS];
390
	int tx_frames_cnt;
L
Luciano Coelho 已提交
391

392 393
	/* Security sequence number counters */
	u8 tx_security_last_seq;
394
	s64 tx_security_seq;
395

L
Luciano Coelho 已提交
396 397 398 399 400 401
	/* FW Rx counter */
	u32 rx_counter;

	/* Rx memory pool address */
	struct wl1271_rx_mem_pool_addr rx_mem_pool_addr;

402 403 404
	/* Intermediate buffer, used for packet aggregation */
	u8 *aggr_buf;

L
Luciano Coelho 已提交
405 406 407
	/* The target interrupt mask */
	struct work_struct irq_work;

408 409 410
	/* Hardware recovery work */
	struct work_struct recovery_work;

L
Luciano Coelho 已提交
411 412 413 414 415 416 417
	/* The mbox event mask */
	u32 event_mask;

	/* Mailbox pointers */
	u32 mbox_ptr[2];

	/* Are we currently scanning */
418
	struct wl1271_scan scan;
419
	struct delayed_work scan_complete_work;
L
Luciano Coelho 已提交
420

421 422 423
	/* probe-req template for the current AP */
	struct sk_buff *probereq;

L
Luciano Coelho 已提交
424 425 426
	/* Our association ID */
	u16 aid;

S
Shahar Levi 已提交
427 428 429 430 431 432
	/*
	 * 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).
	 */
J
Juuso Oikarinen 已提交
433
	u32 basic_rate_set;
434
	u32 basic_rate;
435
	u32 rate_set;
J
Juuso Oikarinen 已提交
436

437 438 439
	/* The current band */
	enum ieee80211_band band;

440 441 442
	/* Beaconing interval (needed for ad-hoc) */
	u32 beacon_int;

L
Luciano Coelho 已提交
443 444 445
	/* Default key (for WEP) */
	u32 default_key;

446
	unsigned int filters;
L
Luciano Coelho 已提交
447 448 449 450
	unsigned int rx_config;
	unsigned int rx_filter;

	struct completion *elp_compl;
451
	struct delayed_work elp_work;
452 453 454 455
	struct delayed_work pspoll_work;

	/* counter for ps-poll delivery failures */
	int ps_poll_failures;
L
Luciano Coelho 已提交
456

457 458 459
	/* retry counter for PSM entries */
	u8 psm_entry_retry;

L
Luciano Coelho 已提交
460 461 462
	/* in dBm */
	int power_level;

463 464 465
	int rssi_thold;
	int last_rssi_event;

L
Luciano Coelho 已提交
466 467
	struct wl1271_stats stats;

468
	__le32 buffer_32;
L
Luciano Coelho 已提交
469
	u32 buffer_cmd;
470
	u32 buffer_busyword[WL1271_BUSY_WORD_CNT];
L
Luciano Coelho 已提交
471

472
	struct wl1271_fw_full_status *fw_status;
L
Luciano Coelho 已提交
473
	struct wl1271_tx_hw_res_if *tx_res_if;
474 475

	struct ieee80211_vif *vif;
476

477 478
	/* Current chipset configuration */
	struct conf_drv_settings conf;
479

480 481
	bool sg_enabled;

482 483
	bool enable_11a;

484
	struct list_head list;
485 486 487

	/* Most recently reported noise in dBm */
	s8 noise;
488 489 490

	/* map for HLIDs of associated stations - when operating in AP mode */
	unsigned long ap_hlid_map[BITS_TO_LONGS(AP_MAX_STATIONS)];
491 492 493

	/* recoreded keys for AP-mode - set here before AP startup */
	struct wl1271_ap_key *recorded_ap_keys[MAX_NUM_KEYS];
494 495 496

	/* bands supported by this instance of wl12xx */
	struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
L
Levi, Shahar 已提交
497 498 499 500

	/* RX BA constraint value */
	bool ba_support;
	u8 ba_rx_bitmap;
501 502 503 504
};

struct wl1271_station {
	u8 hlid;
L
Luciano Coelho 已提交
505 506 507 508 509 510 511 512 513 514 515
};

int wl1271_plt_start(struct wl1271 *wl);
int wl1271_plt_stop(struct wl1271 *wl);

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

#define SESSION_COUNTER_MAX 7 /* maximum value for the session counter */

#define WL1271_DEFAULT_POWER_LEVEL 0

516 517
#define WL1271_TX_QUEUE_LOW_WATERMARK  10
#define WL1271_TX_QUEUE_HIGH_WATERMARK 25
L
Luciano Coelho 已提交
518

J
Juuso Oikarinen 已提交
519 520
/* 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 已提交
521 522
#define WL1271_PRE_POWER_ON_SLEEP 20 /* in milliseconds */
#define WL1271_POWER_ON_SLEEP 200 /* in milliseconds */
L
Luciano Coelho 已提交
523

S
Shahar Levi 已提交
524 525 526 527
/* Macros to handle wl1271.sta_rate_set */
#define HW_BG_RATES_MASK	0xffff
#define HW_HT_RATES_OFFSET	16

L
Luciano Coelho 已提交
528
#endif