blob: bb61c13d49987c546f3feea765e910ef4ff84ee4 [file] [log] [blame]
Emmanuel Grumbach48f20d32011-08-25 23:10:36 -07001/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2007 - 2011 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
26 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2005 - 2011 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63#ifndef __iwl_shared_h__
64#define __iwl_shared_h__
65
Emmanuel Grumbacha72b8b02011-08-25 23:11:13 -070066#include <linux/types.h>
67#include <linux/spinlock.h>
68#include <linux/mutex.h>
69#include <linux/gfp.h>
70
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -070071#include "iwl-commands.h"
72
Emmanuel Grumbache6bb4c92011-08-25 23:10:48 -070073/*This files includes all the types / functions that are exported by the
74 * upper layer to the bus and transport layer */
75
Emmanuel Grumbach48f20d32011-08-25 23:10:36 -070076struct iwl_cfg;
Emmanuel Grumbachcac988a2011-08-25 23:10:37 -070077struct iwl_bus;
Emmanuel Grumbach48f20d32011-08-25 23:10:36 -070078struct iwl_priv;
Emmanuel Grumbachd6189122011-08-25 23:10:39 -070079struct iwl_sensitivity_ranges;
Emmanuel Grumbache6bb4c92011-08-25 23:10:48 -070080struct iwl_trans_ops;
Emmanuel Grumbach48f20d32011-08-25 23:10:36 -070081
Emmanuel Grumbach332a4ba2011-08-25 23:11:16 -070082#define DRV_NAME "iwlagn"
83#define IWLWIFI_VERSION "in-tree:"
84#define DRV_COPYRIGHT "Copyright(c) 2003-2011 Intel Corporation"
85#define DRV_AUTHOR "<ilw@linux.intel.com>"
86
Emmanuel Grumbach48f20d32011-08-25 23:10:36 -070087extern struct iwl_mod_params iwlagn_mod_params;
88
Wey-Yi Guye4ef84d2011-08-25 23:10:58 -070089/**
90 * struct iwl_mod_params
91 * @sw_crypto: using hardware encryption, default = 0
92 * @num_of_queues: number of tx queue, HW dependent
93 * @disable_11n: 11n capabilities enabled, default = 0
94 * @amsdu_size_8K: enable 8K amsdu size, default = 1
95 * @antenna: both antennas (use diversity), default = 0
96 * @restart_fw: restart firmware, default = 1
97 * @plcp_check: enable plcp health check, default = true
98 * @ack_check: disable ack health check, default = false
99 * @wd_disable: enable stuck queue check, default = false
100 * @bt_coex_active: enable bt coex, default = true
101 * @led_mode: system default, default = 0
102 * @no_sleep_autoadjust: disable autoadjust, default = true
103 * @power_save: disable power save, default = false
104 * @power_level: power level, default = 1
105 * @debug_level: levels are IWL_DL_*
106 * @ant_coupling: antenna coupling in dB, default = 0
107 * @bt_ch_announce: BT channel inhibition, default = enable
108 * @wanted_ucode_alternative: ucode alternative to use, default = 1
109 * @auto_agg: enable agg. without check, default = true
110 */
Emmanuel Grumbach48f20d32011-08-25 23:10:36 -0700111struct iwl_mod_params {
Wey-Yi Guye4ef84d2011-08-25 23:10:58 -0700112 int sw_crypto;
113 int num_of_queues;
114 int disable_11n;
115 int amsdu_size_8K;
116 int antenna;
117 int restart_fw;
118 bool plcp_check;
119 bool ack_check;
120 bool wd_disable;
121 bool bt_coex_active;
122 int led_mode;
123 bool no_sleep_autoadjust;
124 bool power_save;
125 int power_level;
126 u32 debug_level;
Emmanuel Grumbach48f20d32011-08-25 23:10:36 -0700127 int ant_coupling;
Wey-Yi Guye4ef84d2011-08-25 23:10:58 -0700128 bool bt_ch_announce;
Emmanuel Grumbach48f20d32011-08-25 23:10:36 -0700129 int wanted_ucode_alternative;
Wey-Yi Guye4ef84d2011-08-25 23:10:58 -0700130 bool auto_agg;
Emmanuel Grumbach48f20d32011-08-25 23:10:36 -0700131};
132
Emmanuel Grumbachcac988a2011-08-25 23:10:37 -0700133/**
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700134 * struct iwl_hw_params
135 * @max_txq_num: Max # Tx queues supported
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700136 * @tx/rx_chains_num: Number of TX/RX chains
137 * @valid_tx/rx_ant: usable antennas
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700138 * @rx_page_order: Rx buffer page order
139 * @rx_wrt_ptr_reg: FH{39}_RSCSR_CHNL0_WPTR
140 * @max_stations:
141 * @ht40_channel: is 40MHz width possible in band 2.4
142 * BIT(IEEE80211_BAND_5GHZ) BIT(IEEE80211_BAND_5GHZ)
143 * @sw_crypto: 0 for hw, 1 for sw
144 * @max_xxx_size: for ucode uses
145 * @ct_kill_threshold: temperature threshold
146 * @beacon_time_tsf_bits: number of valid tsf bits for beacon time
147 * @calib_init_cfg: setup initial calibrations for the hw
148 * @calib_rt_cfg: setup runtime calibrations for the hw
149 * @struct iwl_sensitivity_ranges: range of sensitivity values
150 */
151struct iwl_hw_params {
152 u8 max_txq_num;
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700153 u8 tx_chains_num;
154 u8 rx_chains_num;
155 u8 valid_tx_ant;
156 u8 valid_rx_ant;
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700157 u32 rx_page_order;
158 u8 max_stations;
159 u8 ht40_channel;
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700160 u32 max_inst_size;
161 u32 max_data_size;
162 u32 ct_kill_threshold; /* value in hw-dependent units */
163 u32 ct_kill_exit_threshold; /* value in hw-dependent units */
164 /* for 1000, 6000 series and up */
165 u16 beacon_time_tsf_bits;
166 u32 calib_init_cfg;
167 u32 calib_rt_cfg;
168 const struct iwl_sensitivity_ranges *sens;
169};
170
171/**
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700172 * struct iwl_ht_agg - aggregation status while waiting for block-ack
173 * @txq_id: Tx queue used for Tx attempt
174 * @wait_for_ba: Expect block-ack before next Tx reply
175 * @rate_n_flags: Rate at which Tx was attempted
176 *
177 * If REPLY_TX indicates that aggregation was attempted, driver must wait
178 * for block ack (REPLY_COMPRESSED_BA). This struct stores tx reply info
179 * until block ack arrives.
180 */
181struct iwl_ht_agg {
182 u16 txq_id;
183 u16 wait_for_ba;
184 u32 rate_n_flags;
185#define IWL_AGG_OFF 0
186#define IWL_AGG_ON 1
187#define IWL_EMPTYING_HW_QUEUE_ADDBA 2
188#define IWL_EMPTYING_HW_QUEUE_DELBA 3
189 u8 state;
190 u8 tx_fifo;
191};
192
193struct iwl_tid_data {
194 u16 seq_number; /* agn only */
195 u16 tfds_in_queue;
196 struct iwl_ht_agg agg;
197};
198
199/**
Emmanuel Grumbachcac988a2011-08-25 23:10:37 -0700200 * struct iwl_shared - shared fields for all the layers of the driver
201 *
Emmanuel Grumbach8f470ce2011-08-25 23:10:38 -0700202 * @dbg_level_dev: dbg level set per device. Prevails on
203 * iwlagn_mod_params.debug_level if set (!= 0)
Emmanuel Grumbachcefeaa52011-08-25 23:10:40 -0700204 * @cmd_queue: command queue number
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700205 * @status: STATUS_*
Emmanuel Grumbachcac988a2011-08-25 23:10:37 -0700206 * @bus: pointer to the bus layer data
207 * @priv: pointer to the upper layer data
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700208 * @hw_params: see struct iwl_hw_params
Emmanuel Grumbach74e28e42011-08-25 23:10:41 -0700209 * @workqueue: the workqueue used by all the layers of the driver
Emmanuel Grumbach10b15e62011-08-25 23:10:43 -0700210 * @lock: protect general shared data
Emmanuel Grumbachf39c95e2011-08-25 23:10:47 -0700211 * @sta_lock: protects the station table.
212 * If lock and sta_lock are needed, lock must be acquired first.
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -0700213 * @mutex:
Emmanuel Grumbachcac988a2011-08-25 23:10:37 -0700214 */
215struct iwl_shared {
Emmanuel Grumbach8f470ce2011-08-25 23:10:38 -0700216#ifdef CONFIG_IWLWIFI_DEBUG
217 u32 dbg_level_dev;
218#endif /* CONFIG_IWLWIFI_DEBUG */
219
Emmanuel Grumbachcefeaa52011-08-25 23:10:40 -0700220 u8 cmd_queue;
Emmanuel Grumbach63013ae2011-08-25 23:10:42 -0700221 unsigned long status;
Emmanuel Grumbach57210f72011-08-25 23:10:52 -0700222 bool wowlan;
Emmanuel Grumbachcefeaa52011-08-25 23:10:40 -0700223
Emmanuel Grumbachcac988a2011-08-25 23:10:37 -0700224 struct iwl_bus *bus;
225 struct iwl_priv *priv;
Emmanuel Grumbache6bb4c92011-08-25 23:10:48 -0700226 struct iwl_trans *trans;
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700227 struct iwl_hw_params hw_params;
Emmanuel Grumbach74e28e42011-08-25 23:10:41 -0700228
229 struct workqueue_struct *workqueue;
Emmanuel Grumbach10b15e62011-08-25 23:10:43 -0700230 spinlock_t lock;
Emmanuel Grumbachf39c95e2011-08-25 23:10:47 -0700231 spinlock_t sta_lock;
Emmanuel Grumbach6ac2f832011-08-25 23:10:44 -0700232 struct mutex mutex;
Emmanuel Grumbach5f85a782011-08-25 23:11:18 -0700233
234 struct iwl_tid_data tid_data[IWLAGN_STATION_COUNT][IWL_MAX_TID_COUNT];
Emmanuel Grumbachcac988a2011-08-25 23:10:37 -0700235};
236
237/*Whatever _m is (iwl_trans, iwl_priv, iwl_bus, these macros will work */
238#define priv(_m) ((_m)->shrd->priv)
239#define bus(_m) ((_m)->shrd->bus)
Emmanuel Grumbache6bb4c92011-08-25 23:10:48 -0700240#define trans(_m) ((_m)->shrd->trans)
Emmanuel Grumbachd6189122011-08-25 23:10:39 -0700241#define hw_params(_m) ((_m)->shrd->hw_params)
Emmanuel Grumbachcac988a2011-08-25 23:10:37 -0700242
Emmanuel Grumbach8f470ce2011-08-25 23:10:38 -0700243#ifdef CONFIG_IWLWIFI_DEBUG
244/*
245 * iwl_get_debug_level: Return active debug level for device
246 *
247 * Using sysfs it is possible to set per device debug level. This debug
248 * level will be used if set, otherwise the global debug level which can be
249 * set via module parameter is used.
250 */
251static inline u32 iwl_get_debug_level(struct iwl_shared *shrd)
252{
253 if (shrd->dbg_level_dev)
254 return shrd->dbg_level_dev;
255 else
256 return iwlagn_mod_params.debug_level;
257}
258#else
259static inline u32 iwl_get_debug_level(struct iwl_shared *shrd)
260{
261 return iwlagn_mod_params.debug_level;
262}
263#endif
264
Emmanuel Grumbach790428b2011-08-25 23:11:05 -0700265static inline void iwl_free_pages(struct iwl_shared *shrd, unsigned long page)
266{
267 free_pages(page, shrd->hw_params.rx_page_order);
268}
269
Emmanuel Grumbach5a878bf2011-08-25 23:10:51 -0700270struct iwl_rx_mem_buffer {
271 dma_addr_t page_dma;
272 struct page *page;
273 struct list_head list;
274};
275
276#define rxb_addr(r) page_address(r->page)
277
Emmanuel Grumbach48f20d32011-08-25 23:10:36 -0700278#ifdef CONFIG_PM
279int iwl_suspend(struct iwl_priv *priv);
280int iwl_resume(struct iwl_priv *priv);
281#endif /* !CONFIG_PM */
282
Emmanuel Grumbache6bb4c92011-08-25 23:10:48 -0700283int iwl_probe(struct iwl_bus *bus, const struct iwl_trans_ops *trans_ops,
284 struct iwl_cfg *cfg);
Emmanuel Grumbach48f20d32011-08-25 23:10:36 -0700285void __devexit iwl_remove(struct iwl_priv * priv);
286
Emmanuel Grumbach845a9c02011-08-25 23:11:04 -0700287/*****************************************************
288* DRIVER STATUS FUNCTIONS
289******************************************************/
290#define STATUS_HCMD_ACTIVE 0 /* host command in progress */
291/* 1 is unused (used to be STATUS_HCMD_SYNC_ACTIVE) */
292#define STATUS_INT_ENABLED 2
293#define STATUS_RF_KILL_HW 3
294#define STATUS_CT_KILL 4
295#define STATUS_INIT 5
296#define STATUS_ALIVE 6
297#define STATUS_READY 7
298#define STATUS_TEMPERATURE 8
299#define STATUS_GEO_CONFIGURED 9
300#define STATUS_EXIT_PENDING 10
301#define STATUS_STATISTICS 12
302#define STATUS_SCANNING 13
303#define STATUS_SCAN_ABORTING 14
304#define STATUS_SCAN_HW 15
305#define STATUS_POWER_PMI 16
306#define STATUS_FW_ERROR 17
307#define STATUS_DEVICE_ENABLED 18
308#define STATUS_CHANNEL_SWITCH_PENDING 19
309
310static inline int iwl_is_ready(struct iwl_shared *shrd)
311{
312 /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are
313 * set but EXIT_PENDING is not */
314 return test_bit(STATUS_READY, &shrd->status) &&
315 test_bit(STATUS_GEO_CONFIGURED, &shrd->status) &&
316 !test_bit(STATUS_EXIT_PENDING, &shrd->status);
317}
318
319static inline int iwl_is_alive(struct iwl_shared *shrd)
320{
321 return test_bit(STATUS_ALIVE, &shrd->status);
322}
323
324static inline int iwl_is_init(struct iwl_shared *shrd)
325{
326 return test_bit(STATUS_INIT, &shrd->status);
327}
328
329static inline int iwl_is_rfkill_hw(struct iwl_shared *shrd)
330{
331 return test_bit(STATUS_RF_KILL_HW, &shrd->status);
332}
333
334static inline int iwl_is_rfkill(struct iwl_shared *shrd)
335{
336 return iwl_is_rfkill_hw(shrd);
337}
338
339static inline int iwl_is_ctkill(struct iwl_shared *shrd)
340{
341 return test_bit(STATUS_CT_KILL, &shrd->status);
342}
343
344static inline int iwl_is_ready_rf(struct iwl_shared *shrd)
345{
346 if (iwl_is_rfkill(shrd))
347 return 0;
348
349 return iwl_is_ready(shrd);
350}
351
Emmanuel Grumbach48f20d32011-08-25 23:10:36 -0700352#endif /* #__iwl_shared_h__ */