iwlagn: clean up & autodetect statistics
[linux-block.git] / drivers / net / wireless / iwlwifi / iwl-commands.h
1 /******************************************************************************
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) 2005 - 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 /*
64  * Please use this file (iwl-commands.h) only for uCode API definitions.
65  * Please use iwl-xxxx-hw.h for hardware-related definitions.
66  * Please use iwl-dev.h for driver implementation definitions.
67  */
68
69 #ifndef __iwl_commands_h__
70 #define __iwl_commands_h__
71
72 struct iwl_priv;
73
74 /* uCode version contains 4 values: Major/Minor/API/Serial */
75 #define IWL_UCODE_MAJOR(ver)    (((ver) & 0xFF000000) >> 24)
76 #define IWL_UCODE_MINOR(ver)    (((ver) & 0x00FF0000) >> 16)
77 #define IWL_UCODE_API(ver)      (((ver) & 0x0000FF00) >> 8)
78 #define IWL_UCODE_SERIAL(ver)   ((ver) & 0x000000FF)
79
80
81 /* Tx rates */
82 #define IWL_CCK_RATES   4
83 #define IWL_OFDM_RATES  8
84 #define IWL_MAX_RATES   (IWL_CCK_RATES + IWL_OFDM_RATES)
85
86 enum {
87         REPLY_ALIVE = 0x1,
88         REPLY_ERROR = 0x2,
89
90         /* RXON and QOS commands */
91         REPLY_RXON = 0x10,
92         REPLY_RXON_ASSOC = 0x11,
93         REPLY_QOS_PARAM = 0x13,
94         REPLY_RXON_TIMING = 0x14,
95
96         /* Multi-Station support */
97         REPLY_ADD_STA = 0x18,
98         REPLY_REMOVE_STA = 0x19,
99         REPLY_REMOVE_ALL_STA = 0x1a,    /* not used */
100         REPLY_TXFIFO_FLUSH = 0x1e,
101
102         /* Security */
103         REPLY_WEPKEY = 0x20,
104
105         /* RX, TX, LEDs */
106         REPLY_TX = 0x1c,
107         REPLY_LEDS_CMD = 0x48,
108         REPLY_TX_LINK_QUALITY_CMD = 0x4e, /* for 4965 and up */
109
110         /* WiMAX coexistence */
111         COEX_PRIORITY_TABLE_CMD = 0x5a, /* for 5000 series and up */
112         COEX_MEDIUM_NOTIFICATION = 0x5b,
113         COEX_EVENT_CMD = 0x5c,
114
115         /* Calibration */
116         TEMPERATURE_NOTIFICATION = 0x62,
117         CALIBRATION_CFG_CMD = 0x65,
118         CALIBRATION_RES_NOTIFICATION = 0x66,
119         CALIBRATION_COMPLETE_NOTIFICATION = 0x67,
120
121         /* 802.11h related */
122         REPLY_QUIET_CMD = 0x71,         /* not used */
123         REPLY_CHANNEL_SWITCH = 0x72,
124         CHANNEL_SWITCH_NOTIFICATION = 0x73,
125         REPLY_SPECTRUM_MEASUREMENT_CMD = 0x74,
126         SPECTRUM_MEASURE_NOTIFICATION = 0x75,
127
128         /* Power Management */
129         POWER_TABLE_CMD = 0x77,
130         PM_SLEEP_NOTIFICATION = 0x7A,
131         PM_DEBUG_STATISTIC_NOTIFIC = 0x7B,
132
133         /* Scan commands and notifications */
134         REPLY_SCAN_CMD = 0x80,
135         REPLY_SCAN_ABORT_CMD = 0x81,
136         SCAN_START_NOTIFICATION = 0x82,
137         SCAN_RESULTS_NOTIFICATION = 0x83,
138         SCAN_COMPLETE_NOTIFICATION = 0x84,
139
140         /* IBSS/AP commands */
141         BEACON_NOTIFICATION = 0x90,
142         REPLY_TX_BEACON = 0x91,
143         WHO_IS_AWAKE_NOTIFICATION = 0x94,       /* not used */
144
145         /* Miscellaneous commands */
146         REPLY_TX_POWER_DBM_CMD = 0x95,
147         QUIET_NOTIFICATION = 0x96,              /* not used */
148         REPLY_TX_PWR_TABLE_CMD = 0x97,
149         REPLY_TX_POWER_DBM_CMD_V1 = 0x98,       /* old version of API */
150         TX_ANT_CONFIGURATION_CMD = 0x98,
151         MEASURE_ABORT_NOTIFICATION = 0x99,      /* not used */
152
153         /* Bluetooth device coexistence config command */
154         REPLY_BT_CONFIG = 0x9b,
155
156         /* Statistics */
157         REPLY_STATISTICS_CMD = 0x9c,
158         STATISTICS_NOTIFICATION = 0x9d,
159
160         /* RF-KILL commands and notifications */
161         REPLY_CARD_STATE_CMD = 0xa0,
162         CARD_STATE_NOTIFICATION = 0xa1,
163
164         /* Missed beacons notification */
165         MISSED_BEACONS_NOTIFICATION = 0xa2,
166
167         REPLY_CT_KILL_CONFIG_CMD = 0xa4,
168         SENSITIVITY_CMD = 0xa8,
169         REPLY_PHY_CALIBRATION_CMD = 0xb0,
170         REPLY_RX_PHY_CMD = 0xc0,
171         REPLY_RX_MPDU_CMD = 0xc1,
172         REPLY_RX = 0xc3,
173         REPLY_COMPRESSED_BA = 0xc5,
174
175         /* BT Coex */
176         REPLY_BT_COEX_PRIO_TABLE = 0xcc,
177         REPLY_BT_COEX_PROT_ENV = 0xcd,
178         REPLY_BT_COEX_PROFILE_NOTIF = 0xce,
179
180         /* PAN commands */
181         REPLY_WIPAN_PARAMS = 0xb2,
182         REPLY_WIPAN_RXON = 0xb3,        /* use REPLY_RXON structure */
183         REPLY_WIPAN_RXON_TIMING = 0xb4, /* use REPLY_RXON_TIMING structure */
184         REPLY_WIPAN_RXON_ASSOC = 0xb6,  /* use REPLY_RXON_ASSOC structure */
185         REPLY_WIPAN_QOS_PARAM = 0xb7,   /* use REPLY_QOS_PARAM structure */
186         REPLY_WIPAN_WEPKEY = 0xb8,      /* use REPLY_WEPKEY structure */
187         REPLY_WIPAN_P2P_CHANNEL_SWITCH = 0xb9,
188         REPLY_WIPAN_NOA_NOTIFICATION = 0xbc,
189         REPLY_WIPAN_DEACTIVATION_COMPLETE = 0xbd,
190
191         REPLY_MAX = 0xff
192 };
193
194 /******************************************************************************
195  * (0)
196  * Commonly used structures and definitions:
197  * Command header, rate_n_flags, txpower
198  *
199  *****************************************************************************/
200
201 /* iwl_cmd_header flags value */
202 #define IWL_CMD_FAILED_MSK 0x40
203
204 #define SEQ_TO_QUEUE(s) (((s) >> 8) & 0x1f)
205 #define QUEUE_TO_SEQ(q) (((q) & 0x1f) << 8)
206 #define SEQ_TO_INDEX(s) ((s) & 0xff)
207 #define INDEX_TO_SEQ(i) ((i) & 0xff)
208 #define SEQ_HUGE_FRAME  cpu_to_le16(0x4000)
209 #define SEQ_RX_FRAME    cpu_to_le16(0x8000)
210
211 /**
212  * struct iwl_cmd_header
213  *
214  * This header format appears in the beginning of each command sent from the
215  * driver, and each response/notification received from uCode.
216  */
217 struct iwl_cmd_header {
218         u8 cmd;         /* Command ID:  REPLY_RXON, etc. */
219         u8 flags;       /* 0:5 reserved, 6 abort, 7 internal */
220         /*
221          * The driver sets up the sequence number to values of its choosing.
222          * uCode does not use this value, but passes it back to the driver
223          * when sending the response to each driver-originated command, so
224          * the driver can match the response to the command.  Since the values
225          * don't get used by uCode, the driver may set up an arbitrary format.
226          *
227          * There is one exception:  uCode sets bit 15 when it originates
228          * the response/notification, i.e. when the response/notification
229          * is not a direct response to a command sent by the driver.  For
230          * example, uCode issues REPLY_RX when it sends a received frame
231          * to the driver; it is not a direct response to any driver command.
232          *
233          * The Linux driver uses the following format:
234          *
235          *  0:7         tfd index - position within TX queue
236          *  8:12        TX queue id
237          *  13          reserved
238          *  14          huge - driver sets this to indicate command is in the
239          *              'huge' storage at the end of the command buffers
240          *  15          unsolicited RX or uCode-originated notification
241          */
242         __le16 sequence;
243
244         /* command or response/notification data follows immediately */
245         u8 data[0];
246 } __packed;
247
248
249 /**
250  * iwlagn rate_n_flags bit fields
251  *
252  * rate_n_flags format is used in following iwlagn commands:
253  *  REPLY_RX (response only)
254  *  REPLY_RX_MPDU (response only)
255  *  REPLY_TX (both command and response)
256  *  REPLY_TX_LINK_QUALITY_CMD
257  *
258  * High-throughput (HT) rate format for bits 7:0 (bit 8 must be "1"):
259  *  2-0:  0)   6 Mbps
260  *        1)  12 Mbps
261  *        2)  18 Mbps
262  *        3)  24 Mbps
263  *        4)  36 Mbps
264  *        5)  48 Mbps
265  *        6)  54 Mbps
266  *        7)  60 Mbps
267  *
268  *  4-3:  0)  Single stream (SISO)
269  *        1)  Dual stream (MIMO)
270  *        2)  Triple stream (MIMO)
271  *
272  *    5:  Value of 0x20 in bits 7:0 indicates 6 Mbps HT40 duplicate data
273  *
274  * Legacy OFDM rate format for bits 7:0 (bit 8 must be "0", bit 9 "0"):
275  *  3-0:  0xD)   6 Mbps
276  *        0xF)   9 Mbps
277  *        0x5)  12 Mbps
278  *        0x7)  18 Mbps
279  *        0x9)  24 Mbps
280  *        0xB)  36 Mbps
281  *        0x1)  48 Mbps
282  *        0x3)  54 Mbps
283  *
284  * Legacy CCK rate format for bits 7:0 (bit 8 must be "0", bit 9 "1"):
285  *  6-0:   10)  1 Mbps
286  *         20)  2 Mbps
287  *         55)  5.5 Mbps
288  *        110)  11 Mbps
289  */
290 #define RATE_MCS_CODE_MSK 0x7
291 #define RATE_MCS_SPATIAL_POS 3
292 #define RATE_MCS_SPATIAL_MSK 0x18
293 #define RATE_MCS_HT_DUP_POS 5
294 #define RATE_MCS_HT_DUP_MSK 0x20
295 /* Both legacy and HT use bits 7:0 as the CCK/OFDM rate or HT MCS */
296 #define RATE_MCS_RATE_MSK 0xff
297
298 /* Bit 8: (1) HT format, (0) legacy format in bits 7:0 */
299 #define RATE_MCS_FLAGS_POS 8
300 #define RATE_MCS_HT_POS 8
301 #define RATE_MCS_HT_MSK 0x100
302
303 /* Bit 9: (1) CCK, (0) OFDM.  HT (bit 8) must be "0" for this bit to be valid */
304 #define RATE_MCS_CCK_POS 9
305 #define RATE_MCS_CCK_MSK 0x200
306
307 /* Bit 10: (1) Use Green Field preamble */
308 #define RATE_MCS_GF_POS 10
309 #define RATE_MCS_GF_MSK 0x400
310
311 /* Bit 11: (1) Use 40Mhz HT40 chnl width, (0) use 20 MHz legacy chnl width */
312 #define RATE_MCS_HT40_POS 11
313 #define RATE_MCS_HT40_MSK 0x800
314
315 /* Bit 12: (1) Duplicate data on both 20MHz chnls. HT40 (bit 11) must be set. */
316 #define RATE_MCS_DUP_POS 12
317 #define RATE_MCS_DUP_MSK 0x1000
318
319 /* Bit 13: (1) Short guard interval (0.4 usec), (0) normal GI (0.8 usec) */
320 #define RATE_MCS_SGI_POS 13
321 #define RATE_MCS_SGI_MSK 0x2000
322
323 /**
324  * rate_n_flags Tx antenna masks
325  * 4965 has 2 transmitters
326  * 5100 has 1 transmitter B
327  * 5150 has 1 transmitter A
328  * 5300 has 3 transmitters
329  * 5350 has 3 transmitters
330  * bit14:16
331  */
332 #define RATE_MCS_ANT_POS        14
333 #define RATE_MCS_ANT_A_MSK      0x04000
334 #define RATE_MCS_ANT_B_MSK      0x08000
335 #define RATE_MCS_ANT_C_MSK      0x10000
336 #define RATE_MCS_ANT_AB_MSK     (RATE_MCS_ANT_A_MSK | RATE_MCS_ANT_B_MSK)
337 #define RATE_MCS_ANT_ABC_MSK    (RATE_MCS_ANT_AB_MSK | RATE_MCS_ANT_C_MSK)
338 #define RATE_ANT_NUM 3
339
340 #define POWER_TABLE_NUM_ENTRIES                 33
341 #define POWER_TABLE_NUM_HT_OFDM_ENTRIES         32
342 #define POWER_TABLE_CCK_ENTRY                   32
343
344 #define IWL_PWR_NUM_HT_OFDM_ENTRIES             24
345 #define IWL_PWR_CCK_ENTRIES                     2
346
347 /**
348  * struct tx_power_dual_stream
349  *
350  * Table entries in REPLY_TX_PWR_TABLE_CMD, REPLY_CHANNEL_SWITCH
351  *
352  * Same format as iwl_tx_power_dual_stream, but __le32
353  */
354 struct tx_power_dual_stream {
355         __le32 dw;
356 } __packed;
357
358 /**
359  * Command REPLY_TX_POWER_DBM_CMD = 0x98
360  * struct iwlagn_tx_power_dbm_cmd
361  */
362 #define IWLAGN_TX_POWER_AUTO 0x7f
363 #define IWLAGN_TX_POWER_NO_CLOSED (0x1 << 6)
364
365 struct iwlagn_tx_power_dbm_cmd {
366         s8 global_lmt; /*in half-dBm (e.g. 30 = 15 dBm) */
367         u8 flags;
368         s8 srv_chan_lmt; /*in half-dBm (e.g. 30 = 15 dBm) */
369         u8 reserved;
370 } __packed;
371
372 /**
373  * Command TX_ANT_CONFIGURATION_CMD = 0x98
374  * This command is used to configure valid Tx antenna.
375  * By default uCode concludes the valid antenna according to the radio flavor.
376  * This command enables the driver to override/modify this conclusion.
377  */
378 struct iwl_tx_ant_config_cmd {
379         __le32 valid;
380 } __packed;
381
382 /******************************************************************************
383  * (0a)
384  * Alive and Error Commands & Responses:
385  *
386  *****************************************************************************/
387
388 #define UCODE_VALID_OK  cpu_to_le32(0x1)
389 #define INITIALIZE_SUBTYPE    (9)
390
391 /**
392  * REPLY_ALIVE = 0x1 (response only, not a command)
393  *
394  * uCode issues this "alive" notification once the runtime image is ready
395  * to receive commands from the driver.  This is the *second* "alive"
396  * notification that the driver will receive after rebooting uCode;
397  * this "alive" is indicated by subtype field != 9.
398  *
399  * See comments documenting "BSM" (bootstrap state machine).
400  *
401  * This response includes two pointers to structures within the device's
402  * data SRAM (access via HBUS_TARG_MEM_* regs) that are useful for debugging:
403  *
404  * 1)  log_event_table_ptr indicates base of the event log.  This traces
405  *     a 256-entry history of uCode execution within a circular buffer.
406  *     Its header format is:
407  *
408  *      __le32 log_size;     log capacity (in number of entries)
409  *      __le32 type;         (1) timestamp with each entry, (0) no timestamp
410  *      __le32 wraps;        # times uCode has wrapped to top of circular buffer
411  *      __le32 write_index;  next circular buffer entry that uCode would fill
412  *
413  *     The header is followed by the circular buffer of log entries.  Entries
414  *     with timestamps have the following format:
415  *
416  *      __le32 event_id;     range 0 - 1500
417  *      __le32 timestamp;    low 32 bits of TSF (of network, if associated)
418  *      __le32 data;         event_id-specific data value
419  *
420  *     Entries without timestamps contain only event_id and data.
421  *
422  *
423  * 2)  error_event_table_ptr indicates base of the error log.  This contains
424  *     information about any uCode error that occurs.  For agn, the format
425  *     of the error log is:
426  *
427  *      __le32 valid;        (nonzero) valid, (0) log is empty
428  *      __le32 error_id;     type of error
429  *      __le32 pc;           program counter
430  *      __le32 blink1;       branch link
431  *      __le32 blink2;       branch link
432  *      __le32 ilink1;       interrupt link
433  *      __le32 ilink2;       interrupt link
434  *      __le32 data1;        error-specific data
435  *      __le32 data2;        error-specific data
436  *      __le32 line;         source code line of error
437  *      __le32 bcon_time;    beacon timer
438  *      __le32 tsf_low;      network timestamp function timer
439  *      __le32 tsf_hi;       network timestamp function timer
440  *      __le32 gp1;          GP1 timer register
441  *      __le32 gp2;          GP2 timer register
442  *      __le32 gp3;          GP3 timer register
443  *      __le32 ucode_ver;    uCode version
444  *      __le32 hw_ver;       HW Silicon version
445  *      __le32 brd_ver;      HW board version
446  *      __le32 log_pc;       log program counter
447  *      __le32 frame_ptr;    frame pointer
448  *      __le32 stack_ptr;    stack pointer
449  *      __le32 hcmd;         last host command
450  *      __le32 isr0;         isr status register LMPM_NIC_ISR0: rxtx_flag
451  *      __le32 isr1;         isr status register LMPM_NIC_ISR1: host_flag
452  *      __le32 isr2;         isr status register LMPM_NIC_ISR2: enc_flag
453  *      __le32 isr3;         isr status register LMPM_NIC_ISR3: time_flag
454  *      __le32 isr4;         isr status register LMPM_NIC_ISR4: wico interrupt
455  *      __le32 isr_pref;     isr status register LMPM_NIC_PREF_STAT
456  *      __le32 wait_event;   wait event() caller address
457  *      __le32 l2p_control;  L2pControlField
458  *      __le32 l2p_duration; L2pDurationField
459  *      __le32 l2p_mhvalid;  L2pMhValidBits
460  *      __le32 l2p_addr_match; L2pAddrMatchStat
461  *      __le32 lmpm_pmg_sel; indicate which clocks are turned on (LMPM_PMG_SEL)
462  *      __le32 u_timestamp;  indicate when the date and time of the compilation
463  *      __le32 reserved;
464  *
465  * The Linux driver can print both logs to the system log when a uCode error
466  * occurs.
467  */
468 struct iwl_alive_resp {
469         u8 ucode_minor;
470         u8 ucode_major;
471         __le16 reserved1;
472         u8 sw_rev[8];
473         u8 ver_type;
474         u8 ver_subtype;                 /* not "9" for runtime alive */
475         __le16 reserved2;
476         __le32 log_event_table_ptr;     /* SRAM address for event log */
477         __le32 error_event_table_ptr;   /* SRAM address for error log */
478         __le32 timestamp;
479         __le32 is_valid;
480 } __packed;
481
482 /*
483  * REPLY_ERROR = 0x2 (response only, not a command)
484  */
485 struct iwl_error_resp {
486         __le32 error_type;
487         u8 cmd_id;
488         u8 reserved1;
489         __le16 bad_cmd_seq_num;
490         __le32 error_info;
491         __le64 timestamp;
492 } __packed;
493
494 /******************************************************************************
495  * (1)
496  * RXON Commands & Responses:
497  *
498  *****************************************************************************/
499
500 /*
501  * Rx config defines & structure
502  */
503 /* rx_config device types  */
504 enum {
505         RXON_DEV_TYPE_AP = 1,
506         RXON_DEV_TYPE_ESS = 3,
507         RXON_DEV_TYPE_IBSS = 4,
508         RXON_DEV_TYPE_SNIFFER = 6,
509         RXON_DEV_TYPE_CP = 7,
510         RXON_DEV_TYPE_2STA = 8,
511         RXON_DEV_TYPE_P2P = 9,
512 };
513
514
515 #define RXON_RX_CHAIN_DRIVER_FORCE_MSK          cpu_to_le16(0x1 << 0)
516 #define RXON_RX_CHAIN_DRIVER_FORCE_POS          (0)
517 #define RXON_RX_CHAIN_VALID_MSK                 cpu_to_le16(0x7 << 1)
518 #define RXON_RX_CHAIN_VALID_POS                 (1)
519 #define RXON_RX_CHAIN_FORCE_SEL_MSK             cpu_to_le16(0x7 << 4)
520 #define RXON_RX_CHAIN_FORCE_SEL_POS             (4)
521 #define RXON_RX_CHAIN_FORCE_MIMO_SEL_MSK        cpu_to_le16(0x7 << 7)
522 #define RXON_RX_CHAIN_FORCE_MIMO_SEL_POS        (7)
523 #define RXON_RX_CHAIN_CNT_MSK                   cpu_to_le16(0x3 << 10)
524 #define RXON_RX_CHAIN_CNT_POS                   (10)
525 #define RXON_RX_CHAIN_MIMO_CNT_MSK              cpu_to_le16(0x3 << 12)
526 #define RXON_RX_CHAIN_MIMO_CNT_POS              (12)
527 #define RXON_RX_CHAIN_MIMO_FORCE_MSK            cpu_to_le16(0x1 << 14)
528 #define RXON_RX_CHAIN_MIMO_FORCE_POS            (14)
529
530 /* rx_config flags */
531 /* band & modulation selection */
532 #define RXON_FLG_BAND_24G_MSK           cpu_to_le32(1 << 0)
533 #define RXON_FLG_CCK_MSK                cpu_to_le32(1 << 1)
534 /* auto detection enable */
535 #define RXON_FLG_AUTO_DETECT_MSK        cpu_to_le32(1 << 2)
536 /* TGg protection when tx */
537 #define RXON_FLG_TGG_PROTECT_MSK        cpu_to_le32(1 << 3)
538 /* cck short slot & preamble */
539 #define RXON_FLG_SHORT_SLOT_MSK          cpu_to_le32(1 << 4)
540 #define RXON_FLG_SHORT_PREAMBLE_MSK     cpu_to_le32(1 << 5)
541 /* antenna selection */
542 #define RXON_FLG_DIS_DIV_MSK            cpu_to_le32(1 << 7)
543 #define RXON_FLG_ANT_SEL_MSK            cpu_to_le32(0x0f00)
544 #define RXON_FLG_ANT_A_MSK              cpu_to_le32(1 << 8)
545 #define RXON_FLG_ANT_B_MSK              cpu_to_le32(1 << 9)
546 /* radar detection enable */
547 #define RXON_FLG_RADAR_DETECT_MSK       cpu_to_le32(1 << 12)
548 #define RXON_FLG_TGJ_NARROW_BAND_MSK    cpu_to_le32(1 << 13)
549 /* rx response to host with 8-byte TSF
550 * (according to ON_AIR deassertion) */
551 #define RXON_FLG_TSF2HOST_MSK           cpu_to_le32(1 << 15)
552
553
554 /* HT flags */
555 #define RXON_FLG_CTRL_CHANNEL_LOC_POS           (22)
556 #define RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK        cpu_to_le32(0x1 << 22)
557
558 #define RXON_FLG_HT_OPERATING_MODE_POS          (23)
559
560 #define RXON_FLG_HT_PROT_MSK                    cpu_to_le32(0x1 << 23)
561 #define RXON_FLG_HT40_PROT_MSK                  cpu_to_le32(0x2 << 23)
562
563 #define RXON_FLG_CHANNEL_MODE_POS               (25)
564 #define RXON_FLG_CHANNEL_MODE_MSK               cpu_to_le32(0x3 << 25)
565
566 /* channel mode */
567 enum {
568         CHANNEL_MODE_LEGACY = 0,
569         CHANNEL_MODE_PURE_40 = 1,
570         CHANNEL_MODE_MIXED = 2,
571         CHANNEL_MODE_RESERVED = 3,
572 };
573 #define RXON_FLG_CHANNEL_MODE_LEGACY    cpu_to_le32(CHANNEL_MODE_LEGACY << RXON_FLG_CHANNEL_MODE_POS)
574 #define RXON_FLG_CHANNEL_MODE_PURE_40   cpu_to_le32(CHANNEL_MODE_PURE_40 << RXON_FLG_CHANNEL_MODE_POS)
575 #define RXON_FLG_CHANNEL_MODE_MIXED     cpu_to_le32(CHANNEL_MODE_MIXED << RXON_FLG_CHANNEL_MODE_POS)
576
577 /* CTS to self (if spec allows) flag */
578 #define RXON_FLG_SELF_CTS_EN                    cpu_to_le32(0x1<<30)
579
580 /* rx_config filter flags */
581 /* accept all data frames */
582 #define RXON_FILTER_PROMISC_MSK         cpu_to_le32(1 << 0)
583 /* pass control & management to host */
584 #define RXON_FILTER_CTL2HOST_MSK        cpu_to_le32(1 << 1)
585 /* accept multi-cast */
586 #define RXON_FILTER_ACCEPT_GRP_MSK      cpu_to_le32(1 << 2)
587 /* don't decrypt uni-cast frames */
588 #define RXON_FILTER_DIS_DECRYPT_MSK     cpu_to_le32(1 << 3)
589 /* don't decrypt multi-cast frames */
590 #define RXON_FILTER_DIS_GRP_DECRYPT_MSK cpu_to_le32(1 << 4)
591 /* STA is associated */
592 #define RXON_FILTER_ASSOC_MSK           cpu_to_le32(1 << 5)
593 /* transfer to host non bssid beacons in associated state */
594 #define RXON_FILTER_BCON_AWARE_MSK      cpu_to_le32(1 << 6)
595
596 /**
597  * REPLY_RXON = 0x10 (command, has simple generic response)
598  *
599  * RXON tunes the radio tuner to a service channel, and sets up a number
600  * of parameters that are used primarily for Rx, but also for Tx operations.
601  *
602  * NOTE:  When tuning to a new channel, driver must set the
603  *        RXON_FILTER_ASSOC_MSK to 0.  This will clear station-dependent
604  *        info within the device, including the station tables, tx retry
605  *        rate tables, and txpower tables.  Driver must build a new station
606  *        table and txpower table before transmitting anything on the RXON
607  *        channel.
608  *
609  * NOTE:  All RXONs wipe clean the internal txpower table.  Driver must
610  *        issue a new REPLY_TX_PWR_TABLE_CMD after each REPLY_RXON (0x10),
611  *        regardless of whether RXON_FILTER_ASSOC_MSK is set.
612  */
613
614 struct iwl_rxon_cmd {
615         u8 node_addr[6];
616         __le16 reserved1;
617         u8 bssid_addr[6];
618         __le16 reserved2;
619         u8 wlap_bssid_addr[6];
620         __le16 reserved3;
621         u8 dev_type;
622         u8 air_propagation;
623         __le16 rx_chain;
624         u8 ofdm_basic_rates;
625         u8 cck_basic_rates;
626         __le16 assoc_id;
627         __le32 flags;
628         __le32 filter_flags;
629         __le16 channel;
630         u8 ofdm_ht_single_stream_basic_rates;
631         u8 ofdm_ht_dual_stream_basic_rates;
632         u8 ofdm_ht_triple_stream_basic_rates;
633         u8 reserved5;
634         __le16 acquisition_data;
635         __le16 reserved6;
636 } __packed;
637
638 /*
639  * REPLY_RXON_ASSOC = 0x11 (command, has simple generic response)
640  */
641 struct iwl5000_rxon_assoc_cmd {
642         __le32 flags;
643         __le32 filter_flags;
644         u8 ofdm_basic_rates;
645         u8 cck_basic_rates;
646         __le16 reserved1;
647         u8 ofdm_ht_single_stream_basic_rates;
648         u8 ofdm_ht_dual_stream_basic_rates;
649         u8 ofdm_ht_triple_stream_basic_rates;
650         u8 reserved2;
651         __le16 rx_chain_select_flags;
652         __le16 acquisition_data;
653         __le32 reserved3;
654 } __packed;
655
656 #define IWL_CONN_MAX_LISTEN_INTERVAL    10
657 #define IWL_MAX_UCODE_BEACON_INTERVAL   4 /* 4096 */
658 #define IWL39_MAX_UCODE_BEACON_INTERVAL 1 /* 1024 */
659
660 /*
661  * REPLY_RXON_TIMING = 0x14 (command, has simple generic response)
662  */
663 struct iwl_rxon_time_cmd {
664         __le64 timestamp;
665         __le16 beacon_interval;
666         __le16 atim_window;
667         __le32 beacon_init_val;
668         __le16 listen_interval;
669         u8 dtim_period;
670         u8 delta_cp_bss_tbtts;
671 } __packed;
672
673 /*
674  * REPLY_CHANNEL_SWITCH = 0x72 (command, has simple generic response)
675  */
676 /**
677  * struct iwl5000_channel_switch_cmd
678  * @band: 0- 5.2GHz, 1- 2.4GHz
679  * @expect_beacon: 0- resume transmits after channel switch
680  *                 1- wait for beacon to resume transmits
681  * @channel: new channel number
682  * @rxon_flags: Rx on flags
683  * @rxon_filter_flags: filtering parameters
684  * @switch_time: switch time in extended beacon format
685  * @reserved: reserved bytes
686  */
687 struct iwl5000_channel_switch_cmd {
688         u8 band;
689         u8 expect_beacon;
690         __le16 channel;
691         __le32 rxon_flags;
692         __le32 rxon_filter_flags;
693         __le32 switch_time;
694         __le32 reserved[2][IWL_PWR_NUM_HT_OFDM_ENTRIES + IWL_PWR_CCK_ENTRIES];
695 } __packed;
696
697 /**
698  * struct iwl6000_channel_switch_cmd
699  * @band: 0- 5.2GHz, 1- 2.4GHz
700  * @expect_beacon: 0- resume transmits after channel switch
701  *                 1- wait for beacon to resume transmits
702  * @channel: new channel number
703  * @rxon_flags: Rx on flags
704  * @rxon_filter_flags: filtering parameters
705  * @switch_time: switch time in extended beacon format
706  * @reserved: reserved bytes
707  */
708 struct iwl6000_channel_switch_cmd {
709         u8 band;
710         u8 expect_beacon;
711         __le16 channel;
712         __le32 rxon_flags;
713         __le32 rxon_filter_flags;
714         __le32 switch_time;
715         __le32 reserved[3][IWL_PWR_NUM_HT_OFDM_ENTRIES + IWL_PWR_CCK_ENTRIES];
716 } __packed;
717
718 /*
719  * CHANNEL_SWITCH_NOTIFICATION = 0x73 (notification only, not a command)
720  */
721 struct iwl_csa_notification {
722         __le16 band;
723         __le16 channel;
724         __le32 status;          /* 0 - OK, 1 - fail */
725 } __packed;
726
727 /******************************************************************************
728  * (2)
729  * Quality-of-Service (QOS) Commands & Responses:
730  *
731  *****************************************************************************/
732
733 /**
734  * struct iwl_ac_qos -- QOS timing params for REPLY_QOS_PARAM
735  * One for each of 4 EDCA access categories in struct iwl_qosparam_cmd
736  *
737  * @cw_min: Contention window, start value in numbers of slots.
738  *          Should be a power-of-2, minus 1.  Device's default is 0x0f.
739  * @cw_max: Contention window, max value in numbers of slots.
740  *          Should be a power-of-2, minus 1.  Device's default is 0x3f.
741  * @aifsn:  Number of slots in Arbitration Interframe Space (before
742  *          performing random backoff timing prior to Tx).  Device default 1.
743  * @edca_txop:  Length of Tx opportunity, in uSecs.  Device default is 0.
744  *
745  * Device will automatically increase contention window by (2*CW) + 1 for each
746  * transmission retry.  Device uses cw_max as a bit mask, ANDed with new CW
747  * value, to cap the CW value.
748  */
749 struct iwl_ac_qos {
750         __le16 cw_min;
751         __le16 cw_max;
752         u8 aifsn;
753         u8 reserved1;
754         __le16 edca_txop;
755 } __packed;
756
757 /* QoS flags defines */
758 #define QOS_PARAM_FLG_UPDATE_EDCA_MSK   cpu_to_le32(0x01)
759 #define QOS_PARAM_FLG_TGN_MSK           cpu_to_le32(0x02)
760 #define QOS_PARAM_FLG_TXOP_TYPE_MSK     cpu_to_le32(0x10)
761
762 /* Number of Access Categories (AC) (EDCA), queues 0..3 */
763 #define AC_NUM                4
764
765 /*
766  * REPLY_QOS_PARAM = 0x13 (command, has simple generic response)
767  *
768  * This command sets up timings for each of the 4 prioritized EDCA Tx FIFOs
769  * 0: Background, 1: Best Effort, 2: Video, 3: Voice.
770  */
771 struct iwl_qosparam_cmd {
772         __le32 qos_flags;
773         struct iwl_ac_qos ac[AC_NUM];
774 } __packed;
775
776 /******************************************************************************
777  * (3)
778  * Add/Modify Stations Commands & Responses:
779  *
780  *****************************************************************************/
781 /*
782  * Multi station support
783  */
784
785 /* Special, dedicated locations within device's station table */
786 #define IWL_AP_ID               0
787 #define IWL_AP_ID_PAN           1
788 #define IWL_STA_ID              2
789 #define IWLAGN_PAN_BCAST_ID     14
790 #define IWLAGN_BROADCAST_ID     15
791 #define IWLAGN_STATION_COUNT    16
792
793 #define IWL_INVALID_STATION     255
794
795 #define STA_FLG_TX_RATE_MSK             cpu_to_le32(1 << 2)
796 #define STA_FLG_PWR_SAVE_MSK            cpu_to_le32(1 << 8)
797 #define STA_FLG_PAN_STATION             cpu_to_le32(1 << 13)
798 #define STA_FLG_RTS_MIMO_PROT_MSK       cpu_to_le32(1 << 17)
799 #define STA_FLG_AGG_MPDU_8US_MSK        cpu_to_le32(1 << 18)
800 #define STA_FLG_MAX_AGG_SIZE_POS        (19)
801 #define STA_FLG_MAX_AGG_SIZE_MSK        cpu_to_le32(3 << 19)
802 #define STA_FLG_HT40_EN_MSK             cpu_to_le32(1 << 21)
803 #define STA_FLG_MIMO_DIS_MSK            cpu_to_le32(1 << 22)
804 #define STA_FLG_AGG_MPDU_DENSITY_POS    (23)
805 #define STA_FLG_AGG_MPDU_DENSITY_MSK    cpu_to_le32(7 << 23)
806
807 /* Use in mode field.  1: modify existing entry, 0: add new station entry */
808 #define STA_CONTROL_MODIFY_MSK          0x01
809
810 /* key flags __le16*/
811 #define STA_KEY_FLG_ENCRYPT_MSK cpu_to_le16(0x0007)
812 #define STA_KEY_FLG_NO_ENC      cpu_to_le16(0x0000)
813 #define STA_KEY_FLG_WEP         cpu_to_le16(0x0001)
814 #define STA_KEY_FLG_CCMP        cpu_to_le16(0x0002)
815 #define STA_KEY_FLG_TKIP        cpu_to_le16(0x0003)
816
817 #define STA_KEY_FLG_KEYID_POS   8
818 #define STA_KEY_FLG_INVALID     cpu_to_le16(0x0800)
819 /* wep key is either from global key (0) or from station info array (1) */
820 #define STA_KEY_FLG_MAP_KEY_MSK cpu_to_le16(0x0008)
821
822 /* wep key in STA: 5-bytes (0) or 13-bytes (1) */
823 #define STA_KEY_FLG_KEY_SIZE_MSK     cpu_to_le16(0x1000)
824 #define STA_KEY_MULTICAST_MSK        cpu_to_le16(0x4000)
825 #define STA_KEY_MAX_NUM         8
826 #define STA_KEY_MAX_NUM_PAN     16
827
828 /* Flags indicate whether to modify vs. don't change various station params */
829 #define STA_MODIFY_KEY_MASK             0x01
830 #define STA_MODIFY_TID_DISABLE_TX       0x02
831 #define STA_MODIFY_TX_RATE_MSK          0x04
832 #define STA_MODIFY_ADDBA_TID_MSK        0x08
833 #define STA_MODIFY_DELBA_TID_MSK        0x10
834 #define STA_MODIFY_SLEEP_TX_COUNT_MSK   0x20
835
836 /* Receiver address (actually, Rx station's index into station table),
837  * combined with Traffic ID (QOS priority), in format used by Tx Scheduler */
838 #define BUILD_RAxTID(sta_id, tid)       (((sta_id) << 4) + (tid))
839
840 /* agn */
841 struct iwl_keyinfo {
842         __le16 key_flags;
843         u8 tkip_rx_tsc_byte2;   /* TSC[2] for key mix ph1 detection */
844         u8 reserved1;
845         __le16 tkip_rx_ttak[5]; /* 10-byte unicast TKIP TTAK */
846         u8 key_offset;
847         u8 reserved2;
848         u8 key[16];             /* 16-byte unicast decryption key */
849         __le64 tx_secur_seq_cnt;
850         __le64 hw_tkip_mic_rx_key;
851         __le64 hw_tkip_mic_tx_key;
852 } __packed;
853
854 /**
855  * struct sta_id_modify
856  * @addr[ETH_ALEN]: station's MAC address
857  * @sta_id: index of station in uCode's station table
858  * @modify_mask: STA_MODIFY_*, 1: modify, 0: don't change
859  *
860  * Driver selects unused table index when adding new station,
861  * or the index to a pre-existing station entry when modifying that station.
862  * Some indexes have special purposes (IWL_AP_ID, index 0, is for AP).
863  *
864  * modify_mask flags select which parameters to modify vs. leave alone.
865  */
866 struct sta_id_modify {
867         u8 addr[ETH_ALEN];
868         __le16 reserved1;
869         u8 sta_id;
870         u8 modify_mask;
871         __le16 reserved2;
872 } __packed;
873
874 /*
875  * REPLY_ADD_STA = 0x18 (command)
876  *
877  * The device contains an internal table of per-station information,
878  * with info on security keys, aggregation parameters, and Tx rates for
879  * initial Tx attempt and any retries (agn devices uses
880  * REPLY_TX_LINK_QUALITY_CMD,
881  *
882  * REPLY_ADD_STA sets up the table entry for one station, either creating
883  * a new entry, or modifying a pre-existing one.
884  *
885  * NOTE:  RXON command (without "associated" bit set) wipes the station table
886  *        clean.  Moving into RF_KILL state does this also.  Driver must set up
887  *        new station table before transmitting anything on the RXON channel
888  *        (except active scans or active measurements; those commands carry
889  *        their own txpower/rate setup data).
890  *
891  *        When getting started on a new channel, driver must set up the
892  *        IWL_BROADCAST_ID entry (last entry in the table).  For a client
893  *        station in a BSS, once an AP is selected, driver sets up the AP STA
894  *        in the IWL_AP_ID entry (1st entry in the table).  BROADCAST and AP
895  *        are all that are needed for a BSS client station.  If the device is
896  *        used as AP, or in an IBSS network, driver must set up station table
897  *        entries for all STAs in network, starting with index IWL_STA_ID.
898  */
899
900 struct iwl_addsta_cmd {
901         u8 mode;                /* 1: modify existing, 0: add new station */
902         u8 reserved[3];
903         struct sta_id_modify sta;
904         struct iwl_keyinfo key;
905         __le32 station_flags;           /* STA_FLG_* */
906         __le32 station_flags_msk;       /* STA_FLG_* */
907
908         /* bit field to disable (1) or enable (0) Tx for Traffic ID (TID)
909          * corresponding to bit (e.g. bit 5 controls TID 5).
910          * Set modify_mask bit STA_MODIFY_TID_DISABLE_TX to use this field. */
911         __le16 tid_disable_tx;
912
913         __le16  rate_n_flags;           /* 3945 only */
914
915         /* TID for which to add block-ack support.
916          * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */
917         u8 add_immediate_ba_tid;
918
919         /* TID for which to remove block-ack support.
920          * Set modify_mask bit STA_MODIFY_DELBA_TID_MSK to use this field. */
921         u8 remove_immediate_ba_tid;
922
923         /* Starting Sequence Number for added block-ack support.
924          * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */
925         __le16 add_immediate_ba_ssn;
926
927         /*
928          * Number of packets OK to transmit to station even though
929          * it is asleep -- used to synchronise PS-poll and u-APSD
930          * responses while ucode keeps track of STA sleep state.
931          */
932         __le16 sleep_tx_count;
933
934         __le16 reserved2;
935 } __packed;
936
937
938 #define ADD_STA_SUCCESS_MSK             0x1
939 #define ADD_STA_NO_ROOM_IN_TABLE        0x2
940 #define ADD_STA_NO_BLOCK_ACK_RESOURCE   0x4
941 #define ADD_STA_MODIFY_NON_EXIST_STA    0x8
942 /*
943  * REPLY_ADD_STA = 0x18 (response)
944  */
945 struct iwl_add_sta_resp {
946         u8 status;      /* ADD_STA_* */
947 } __packed;
948
949 #define REM_STA_SUCCESS_MSK              0x1
950 /*
951  *  REPLY_REM_STA = 0x19 (response)
952  */
953 struct iwl_rem_sta_resp {
954         u8 status;
955 } __packed;
956
957 /*
958  *  REPLY_REM_STA = 0x19 (command)
959  */
960 struct iwl_rem_sta_cmd {
961         u8 num_sta;     /* number of removed stations */
962         u8 reserved[3];
963         u8 addr[ETH_ALEN]; /* MAC addr of the first station */
964         u8 reserved2[2];
965 } __packed;
966
967 #define IWL_TX_FIFO_BK_MSK              cpu_to_le32(BIT(0))
968 #define IWL_TX_FIFO_BE_MSK              cpu_to_le32(BIT(1))
969 #define IWL_TX_FIFO_VI_MSK              cpu_to_le32(BIT(2))
970 #define IWL_TX_FIFO_VO_MSK              cpu_to_le32(BIT(3))
971 #define IWL_AGG_TX_QUEUE_MSK            cpu_to_le32(0xffc00)
972
973 #define IWL_DROP_SINGLE         0
974 #define IWL_DROP_SELECTED       1
975 #define IWL_DROP_ALL            2
976
977 /*
978  * REPLY_TXFIFO_FLUSH = 0x1e(command and response)
979  *
980  * When using full FIFO flush this command checks the scheduler HW block WR/RD
981  * pointers to check if all the frames were transferred by DMA into the
982  * relevant TX FIFO queue. Only when the DMA is finished and the queue is
983  * empty the command can finish.
984  * This command is used to flush the TXFIFO from transmit commands, it may
985  * operate on single or multiple queues, the command queue can't be flushed by
986  * this command. The command response is returned when all the queue flush
987  * operations are done. Each TX command flushed return response with the FLUSH
988  * status set in the TX response status. When FIFO flush operation is used,
989  * the flush operation ends when both the scheduler DMA done and TXFIFO empty
990  * are set.
991  *
992  * @fifo_control: bit mask for which queues to flush
993  * @flush_control: flush controls
994  *      0: Dump single MSDU
995  *      1: Dump multiple MSDU according to PS, INVALID STA, TTL, TID disable.
996  *      2: Dump all FIFO
997  */
998 struct iwl_txfifo_flush_cmd {
999         __le32 fifo_control;
1000         __le16 flush_control;
1001         __le16 reserved;
1002 } __packed;
1003
1004 /*
1005  * REPLY_WEP_KEY = 0x20
1006  */
1007 struct iwl_wep_key {
1008         u8 key_index;
1009         u8 key_offset;
1010         u8 reserved1[2];
1011         u8 key_size;
1012         u8 reserved2[3];
1013         u8 key[16];
1014 } __packed;
1015
1016 struct iwl_wep_cmd {
1017         u8 num_keys;
1018         u8 global_key_type;
1019         u8 flags;
1020         u8 reserved;
1021         struct iwl_wep_key key[0];
1022 } __packed;
1023
1024 #define WEP_KEY_WEP_TYPE 1
1025 #define WEP_KEYS_MAX 4
1026 #define WEP_INVALID_OFFSET 0xff
1027 #define WEP_KEY_LEN_64 5
1028 #define WEP_KEY_LEN_128 13
1029
1030 /******************************************************************************
1031  * (4)
1032  * Rx Responses:
1033  *
1034  *****************************************************************************/
1035
1036 #define RX_RES_STATUS_NO_CRC32_ERROR    cpu_to_le32(1 << 0)
1037 #define RX_RES_STATUS_NO_RXE_OVERFLOW   cpu_to_le32(1 << 1)
1038
1039 #define RX_RES_PHY_FLAGS_BAND_24_MSK    cpu_to_le16(1 << 0)
1040 #define RX_RES_PHY_FLAGS_MOD_CCK_MSK            cpu_to_le16(1 << 1)
1041 #define RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK     cpu_to_le16(1 << 2)
1042 #define RX_RES_PHY_FLAGS_NARROW_BAND_MSK        cpu_to_le16(1 << 3)
1043 #define RX_RES_PHY_FLAGS_ANTENNA_MSK            0xf0
1044 #define RX_RES_PHY_FLAGS_ANTENNA_POS            4
1045
1046 #define RX_RES_STATUS_SEC_TYPE_MSK      (0x7 << 8)
1047 #define RX_RES_STATUS_SEC_TYPE_NONE     (0x0 << 8)
1048 #define RX_RES_STATUS_SEC_TYPE_WEP      (0x1 << 8)
1049 #define RX_RES_STATUS_SEC_TYPE_CCMP     (0x2 << 8)
1050 #define RX_RES_STATUS_SEC_TYPE_TKIP     (0x3 << 8)
1051 #define RX_RES_STATUS_SEC_TYPE_ERR      (0x7 << 8)
1052
1053 #define RX_RES_STATUS_STATION_FOUND     (1<<6)
1054 #define RX_RES_STATUS_NO_STATION_INFO_MISMATCH  (1<<7)
1055
1056 #define RX_RES_STATUS_DECRYPT_TYPE_MSK  (0x3 << 11)
1057 #define RX_RES_STATUS_NOT_DECRYPT       (0x0 << 11)
1058 #define RX_RES_STATUS_DECRYPT_OK        (0x3 << 11)
1059 #define RX_RES_STATUS_BAD_ICV_MIC       (0x1 << 11)
1060 #define RX_RES_STATUS_BAD_KEY_TTAK      (0x2 << 11)
1061
1062 #define RX_MPDU_RES_STATUS_ICV_OK       (0x20)
1063 #define RX_MPDU_RES_STATUS_MIC_OK       (0x40)
1064 #define RX_MPDU_RES_STATUS_TTAK_OK      (1 << 7)
1065 #define RX_MPDU_RES_STATUS_DEC_DONE_MSK (0x800)
1066
1067
1068 #define IWLAGN_RX_RES_PHY_CNT 8
1069 #define IWLAGN_RX_RES_AGC_IDX     1
1070 #define IWLAGN_RX_RES_RSSI_AB_IDX 2
1071 #define IWLAGN_RX_RES_RSSI_C_IDX  3
1072 #define IWLAGN_OFDM_AGC_MSK 0xfe00
1073 #define IWLAGN_OFDM_AGC_BIT_POS 9
1074 #define IWLAGN_OFDM_RSSI_INBAND_A_BITMSK 0x00ff
1075 #define IWLAGN_OFDM_RSSI_ALLBAND_A_BITMSK 0xff00
1076 #define IWLAGN_OFDM_RSSI_A_BIT_POS 0
1077 #define IWLAGN_OFDM_RSSI_INBAND_B_BITMSK 0xff0000
1078 #define IWLAGN_OFDM_RSSI_ALLBAND_B_BITMSK 0xff000000
1079 #define IWLAGN_OFDM_RSSI_B_BIT_POS 16
1080 #define IWLAGN_OFDM_RSSI_INBAND_C_BITMSK 0x00ff
1081 #define IWLAGN_OFDM_RSSI_ALLBAND_C_BITMSK 0xff00
1082 #define IWLAGN_OFDM_RSSI_C_BIT_POS 0
1083
1084 struct iwlagn_non_cfg_phy {
1085         __le32 non_cfg_phy[IWLAGN_RX_RES_PHY_CNT];  /* up to 8 phy entries */
1086 } __packed;
1087
1088
1089 /*
1090  * REPLY_RX = 0xc3 (response only, not a command)
1091  * Used only for legacy (non 11n) frames.
1092  */
1093 struct iwl_rx_phy_res {
1094         u8 non_cfg_phy_cnt;     /* non configurable DSP phy data byte count */
1095         u8 cfg_phy_cnt;         /* configurable DSP phy data byte count */
1096         u8 stat_id;             /* configurable DSP phy data set ID */
1097         u8 reserved1;
1098         __le64 timestamp;       /* TSF at on air rise */
1099         __le32 beacon_time_stamp; /* beacon at on-air rise */
1100         __le16 phy_flags;       /* general phy flags: band, modulation, ... */
1101         __le16 channel;         /* channel number */
1102         u8 non_cfg_phy_buf[32]; /* for various implementations of non_cfg_phy */
1103         __le32 rate_n_flags;    /* RATE_MCS_* */
1104         __le16 byte_count;      /* frame's byte-count */
1105         __le16 frame_time;      /* frame's time on the air */
1106 } __packed;
1107
1108 struct iwl_rx_mpdu_res_start {
1109         __le16 byte_count;
1110         __le16 reserved;
1111 } __packed;
1112
1113
1114 /******************************************************************************
1115  * (5)
1116  * Tx Commands & Responses:
1117  *
1118  * Driver must place each REPLY_TX command into one of the prioritized Tx
1119  * queues in host DRAM, shared between driver and device (see comments for
1120  * SCD registers and Tx/Rx Queues).  When the device's Tx scheduler and uCode
1121  * are preparing to transmit, the device pulls the Tx command over the PCI
1122  * bus via one of the device's Tx DMA channels, to fill an internal FIFO
1123  * from which data will be transmitted.
1124  *
1125  * uCode handles all timing and protocol related to control frames
1126  * (RTS/CTS/ACK), based on flags in the Tx command.  uCode and Tx scheduler
1127  * handle reception of block-acks; uCode updates the host driver via
1128  * REPLY_COMPRESSED_BA.
1129  *
1130  * uCode handles retrying Tx when an ACK is expected but not received.
1131  * This includes trying lower data rates than the one requested in the Tx
1132  * command, as set up by the REPLY_RATE_SCALE (for 3945) or
1133  * REPLY_TX_LINK_QUALITY_CMD (agn).
1134  *
1135  * Driver sets up transmit power for various rates via REPLY_TX_PWR_TABLE_CMD.
1136  * This command must be executed after every RXON command, before Tx can occur.
1137  *****************************************************************************/
1138
1139 /* REPLY_TX Tx flags field */
1140
1141 /*
1142  * 1: Use RTS/CTS protocol or CTS-to-self if spec allows it
1143  * before this frame. if CTS-to-self required check
1144  * RXON_FLG_SELF_CTS_EN status.
1145  * unused in 3945/4965, used in 5000 series and after
1146  */
1147 #define TX_CMD_FLG_PROT_REQUIRE_MSK cpu_to_le32(1 << 0)
1148
1149 /*
1150  * 1: Use Request-To-Send protocol before this frame.
1151  * Mutually exclusive vs. TX_CMD_FLG_CTS_MSK.
1152  * used in 3945/4965, unused in 5000 series and after
1153  */
1154 #define TX_CMD_FLG_RTS_MSK cpu_to_le32(1 << 1)
1155
1156 /*
1157  * 1: Transmit Clear-To-Send to self before this frame.
1158  * Driver should set this for AUTH/DEAUTH/ASSOC-REQ/REASSOC mgmnt frames.
1159  * Mutually exclusive vs. TX_CMD_FLG_RTS_MSK.
1160  * used in 3945/4965, unused in 5000 series and after
1161  */
1162 #define TX_CMD_FLG_CTS_MSK cpu_to_le32(1 << 2)
1163
1164 /* 1: Expect ACK from receiving station
1165  * 0: Don't expect ACK (MAC header's duration field s/b 0)
1166  * Set this for unicast frames, but not broadcast/multicast. */
1167 #define TX_CMD_FLG_ACK_MSK cpu_to_le32(1 << 3)
1168
1169 /* For agn devices:
1170  * 1: Use rate scale table (see REPLY_TX_LINK_QUALITY_CMD).
1171  *    Tx command's initial_rate_index indicates first rate to try;
1172  *    uCode walks through table for additional Tx attempts.
1173  * 0: Use Tx rate/MCS from Tx command's rate_n_flags field.
1174  *    This rate will be used for all Tx attempts; it will not be scaled. */
1175 #define TX_CMD_FLG_STA_RATE_MSK cpu_to_le32(1 << 4)
1176
1177 /* 1: Expect immediate block-ack.
1178  * Set when Txing a block-ack request frame.  Also set TX_CMD_FLG_ACK_MSK. */
1179 #define TX_CMD_FLG_IMM_BA_RSP_MASK  cpu_to_le32(1 << 6)
1180
1181 /*
1182  * 1: Frame requires full Tx-Op protection.
1183  * Set this if either RTS or CTS Tx Flag gets set.
1184  * used in 3945/4965, unused in 5000 series and after
1185  */
1186 #define TX_CMD_FLG_FULL_TXOP_PROT_MSK cpu_to_le32(1 << 7)
1187
1188 /* Tx antenna selection field; used only for 3945, reserved (0) for agn devices.
1189  * Set field to "0" to allow 3945 uCode to select antenna (normal usage). */
1190 #define TX_CMD_FLG_ANT_SEL_MSK cpu_to_le32(0xf00)
1191 #define TX_CMD_FLG_ANT_A_MSK cpu_to_le32(1 << 8)
1192 #define TX_CMD_FLG_ANT_B_MSK cpu_to_le32(1 << 9)
1193
1194 /* 1: Ignore Bluetooth priority for this frame.
1195  * 0: Delay Tx until Bluetooth device is done (normal usage). */
1196 #define TX_CMD_FLG_IGNORE_BT cpu_to_le32(1 << 12)
1197
1198 /* 1: uCode overrides sequence control field in MAC header.
1199  * 0: Driver provides sequence control field in MAC header.
1200  * Set this for management frames, non-QOS data frames, non-unicast frames,
1201  * and also in Tx command embedded in REPLY_SCAN_CMD for active scans. */
1202 #define TX_CMD_FLG_SEQ_CTL_MSK cpu_to_le32(1 << 13)
1203
1204 /* 1: This frame is non-last MPDU; more fragments are coming.
1205  * 0: Last fragment, or not using fragmentation. */
1206 #define TX_CMD_FLG_MORE_FRAG_MSK cpu_to_le32(1 << 14)
1207
1208 /* 1: uCode calculates and inserts Timestamp Function (TSF) in outgoing frame.
1209  * 0: No TSF required in outgoing frame.
1210  * Set this for transmitting beacons and probe responses. */
1211 #define TX_CMD_FLG_TSF_MSK cpu_to_le32(1 << 16)
1212
1213 /* 1: Driver inserted 2 bytes pad after the MAC header, for (required) dword
1214  *    alignment of frame's payload data field.
1215  * 0: No pad
1216  * Set this for MAC headers with 26 or 30 bytes, i.e. those with QOS or ADDR4
1217  * field (but not both).  Driver must align frame data (i.e. data following
1218  * MAC header) to DWORD boundary. */
1219 #define TX_CMD_FLG_MH_PAD_MSK cpu_to_le32(1 << 20)
1220
1221 /* accelerate aggregation support
1222  * 0 - no CCMP encryption; 1 - CCMP encryption */
1223 #define TX_CMD_FLG_AGG_CCMP_MSK cpu_to_le32(1 << 22)
1224
1225 /* HCCA-AP - disable duration overwriting. */
1226 #define TX_CMD_FLG_DUR_MSK cpu_to_le32(1 << 25)
1227
1228
1229 /*
1230  * TX command security control
1231  */
1232 #define TX_CMD_SEC_WEP          0x01
1233 #define TX_CMD_SEC_CCM          0x02
1234 #define TX_CMD_SEC_TKIP         0x03
1235 #define TX_CMD_SEC_MSK          0x03
1236 #define TX_CMD_SEC_SHIFT        6
1237 #define TX_CMD_SEC_KEY128       0x08
1238
1239 /*
1240  * security overhead sizes
1241  */
1242 #define WEP_IV_LEN 4
1243 #define WEP_ICV_LEN 4
1244 #define CCMP_MIC_LEN 8
1245 #define TKIP_ICV_LEN 4
1246
1247 /*
1248  * REPLY_TX = 0x1c (command)
1249  */
1250
1251 /*
1252  * 4965 uCode updates these Tx attempt count values in host DRAM.
1253  * Used for managing Tx retries when expecting block-acks.
1254  * Driver should set these fields to 0.
1255  */
1256 struct iwl_dram_scratch {
1257         u8 try_cnt;             /* Tx attempts */
1258         u8 bt_kill_cnt;         /* Tx attempts blocked by Bluetooth device */
1259         __le16 reserved;
1260 } __packed;
1261
1262 struct iwl_tx_cmd {
1263         /*
1264          * MPDU byte count:
1265          * MAC header (24/26/30/32 bytes) + 2 bytes pad if 26/30 header size,
1266          * + 8 byte IV for CCM or TKIP (not used for WEP)
1267          * + Data payload
1268          * + 8-byte MIC (not used for CCM/WEP)
1269          * NOTE:  Does not include Tx command bytes, post-MAC pad bytes,
1270          *        MIC (CCM) 8 bytes, ICV (WEP/TKIP/CKIP) 4 bytes, CRC 4 bytes.i
1271          * Range: 14-2342 bytes.
1272          */
1273         __le16 len;
1274
1275         /*
1276          * MPDU or MSDU byte count for next frame.
1277          * Used for fragmentation and bursting, but not 11n aggregation.
1278          * Same as "len", but for next frame.  Set to 0 if not applicable.
1279          */
1280         __le16 next_frame_len;
1281
1282         __le32 tx_flags;        /* TX_CMD_FLG_* */
1283
1284         /* uCode may modify this field of the Tx command (in host DRAM!).
1285          * Driver must also set dram_lsb_ptr and dram_msb_ptr in this cmd. */
1286         struct iwl_dram_scratch scratch;
1287
1288         /* Rate for *all* Tx attempts, if TX_CMD_FLG_STA_RATE_MSK is cleared. */
1289         __le32 rate_n_flags;    /* RATE_MCS_* */
1290
1291         /* Index of destination station in uCode's station table */
1292         u8 sta_id;
1293
1294         /* Type of security encryption:  CCM or TKIP */
1295         u8 sec_ctl;             /* TX_CMD_SEC_* */
1296
1297         /*
1298          * Index into rate table (see REPLY_TX_LINK_QUALITY_CMD) for initial
1299          * Tx attempt, if TX_CMD_FLG_STA_RATE_MSK is set.  Normally "0" for
1300          * data frames, this field may be used to selectively reduce initial
1301          * rate (via non-0 value) for special frames (e.g. management), while
1302          * still supporting rate scaling for all frames.
1303          */
1304         u8 initial_rate_index;
1305         u8 reserved;
1306         u8 key[16];
1307         __le16 next_frame_flags;
1308         __le16 reserved2;
1309         union {
1310                 __le32 life_time;
1311                 __le32 attempt;
1312         } stop_time;
1313
1314         /* Host DRAM physical address pointer to "scratch" in this command.
1315          * Must be dword aligned.  "0" in dram_lsb_ptr disables usage. */
1316         __le32 dram_lsb_ptr;
1317         u8 dram_msb_ptr;
1318
1319         u8 rts_retry_limit;     /*byte 50 */
1320         u8 data_retry_limit;    /*byte 51 */
1321         u8 tid_tspec;
1322         union {
1323                 __le16 pm_frame_timeout;
1324                 __le16 attempt_duration;
1325         } timeout;
1326
1327         /*
1328          * Duration of EDCA burst Tx Opportunity, in 32-usec units.
1329          * Set this if txop time is not specified by HCCA protocol (e.g. by AP).
1330          */
1331         __le16 driver_txop;
1332
1333         /*
1334          * MAC header goes here, followed by 2 bytes padding if MAC header
1335          * length is 26 or 30 bytes, followed by payload data
1336          */
1337         u8 payload[0];
1338         struct ieee80211_hdr hdr[0];
1339 } __packed;
1340
1341 /*
1342  * TX command response is sent after *agn* transmission attempts.
1343  *
1344  * both postpone and abort status are expected behavior from uCode. there is
1345  * no special operation required from driver; except for RFKILL_FLUSH,
1346  * which required tx flush host command to flush all the tx frames in queues
1347  */
1348 enum {
1349         TX_STATUS_SUCCESS = 0x01,
1350         TX_STATUS_DIRECT_DONE = 0x02,
1351         /* postpone TX */
1352         TX_STATUS_POSTPONE_DELAY = 0x40,
1353         TX_STATUS_POSTPONE_FEW_BYTES = 0x41,
1354         TX_STATUS_POSTPONE_BT_PRIO = 0x42,
1355         TX_STATUS_POSTPONE_QUIET_PERIOD = 0x43,
1356         TX_STATUS_POSTPONE_CALC_TTAK = 0x44,
1357         /* abort TX */
1358         TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY = 0x81,
1359         TX_STATUS_FAIL_SHORT_LIMIT = 0x82,
1360         TX_STATUS_FAIL_LONG_LIMIT = 0x83,
1361         TX_STATUS_FAIL_FIFO_UNDERRUN = 0x84,
1362         TX_STATUS_FAIL_DRAIN_FLOW = 0x85,
1363         TX_STATUS_FAIL_RFKILL_FLUSH = 0x86,
1364         TX_STATUS_FAIL_LIFE_EXPIRE = 0x87,
1365         TX_STATUS_FAIL_DEST_PS = 0x88,
1366         TX_STATUS_FAIL_HOST_ABORTED = 0x89,
1367         TX_STATUS_FAIL_BT_RETRY = 0x8a,
1368         TX_STATUS_FAIL_STA_INVALID = 0x8b,
1369         TX_STATUS_FAIL_FRAG_DROPPED = 0x8c,
1370         TX_STATUS_FAIL_TID_DISABLE = 0x8d,
1371         TX_STATUS_FAIL_FIFO_FLUSHED = 0x8e,
1372         TX_STATUS_FAIL_INSUFFICIENT_CF_POLL = 0x8f,
1373         TX_STATUS_FAIL_PASSIVE_NO_RX = 0x90,
1374         TX_STATUS_FAIL_NO_BEACON_ON_RADAR = 0x91,
1375 };
1376
1377 #define TX_PACKET_MODE_REGULAR          0x0000
1378 #define TX_PACKET_MODE_BURST_SEQ        0x0100
1379 #define TX_PACKET_MODE_BURST_FIRST      0x0200
1380
1381 enum {
1382         TX_POWER_PA_NOT_ACTIVE = 0x0,
1383 };
1384
1385 enum {
1386         TX_STATUS_MSK = 0x000000ff,             /* bits 0:7 */
1387         TX_STATUS_DELAY_MSK = 0x00000040,
1388         TX_STATUS_ABORT_MSK = 0x00000080,
1389         TX_PACKET_MODE_MSK = 0x0000ff00,        /* bits 8:15 */
1390         TX_FIFO_NUMBER_MSK = 0x00070000,        /* bits 16:18 */
1391         TX_RESERVED = 0x00780000,               /* bits 19:22 */
1392         TX_POWER_PA_DETECT_MSK = 0x7f800000,    /* bits 23:30 */
1393         TX_ABORT_REQUIRED_MSK = 0x80000000,     /* bits 31:31 */
1394 };
1395
1396 /* *******************************
1397  * TX aggregation status
1398  ******************************* */
1399
1400 enum {
1401         AGG_TX_STATE_TRANSMITTED = 0x00,
1402         AGG_TX_STATE_UNDERRUN_MSK = 0x01,
1403         AGG_TX_STATE_BT_PRIO_MSK = 0x02,
1404         AGG_TX_STATE_FEW_BYTES_MSK = 0x04,
1405         AGG_TX_STATE_ABORT_MSK = 0x08,
1406         AGG_TX_STATE_LAST_SENT_TTL_MSK = 0x10,
1407         AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK = 0x20,
1408         AGG_TX_STATE_LAST_SENT_BT_KILL_MSK = 0x40,
1409         AGG_TX_STATE_SCD_QUERY_MSK = 0x80,
1410         AGG_TX_STATE_TEST_BAD_CRC32_MSK = 0x100,
1411         AGG_TX_STATE_RESPONSE_MSK = 0x1ff,
1412         AGG_TX_STATE_DUMP_TX_MSK = 0x200,
1413         AGG_TX_STATE_DELAY_TX_MSK = 0x400
1414 };
1415
1416 #define AGG_TX_STATUS_MSK       0x00000fff      /* bits 0:11 */
1417 #define AGG_TX_TRY_MSK          0x0000f000      /* bits 12:15 */
1418
1419 #define AGG_TX_STATE_LAST_SENT_MSK  (AGG_TX_STATE_LAST_SENT_TTL_MSK | \
1420                                      AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK | \
1421                                      AGG_TX_STATE_LAST_SENT_BT_KILL_MSK)
1422
1423 /* # tx attempts for first frame in aggregation */
1424 #define AGG_TX_STATE_TRY_CNT_POS 12
1425 #define AGG_TX_STATE_TRY_CNT_MSK 0xf000
1426
1427 /* Command ID and sequence number of Tx command for this frame */
1428 #define AGG_TX_STATE_SEQ_NUM_POS 16
1429 #define AGG_TX_STATE_SEQ_NUM_MSK 0xffff0000
1430
1431 /*
1432  * REPLY_TX = 0x1c (response)
1433  *
1434  * This response may be in one of two slightly different formats, indicated
1435  * by the frame_count field:
1436  *
1437  * 1)  No aggregation (frame_count == 1).  This reports Tx results for
1438  *     a single frame.  Multiple attempts, at various bit rates, may have
1439  *     been made for this frame.
1440  *
1441  * 2)  Aggregation (frame_count > 1).  This reports Tx results for
1442  *     2 or more frames that used block-acknowledge.  All frames were
1443  *     transmitted at same rate.  Rate scaling may have been used if first
1444  *     frame in this new agg block failed in previous agg block(s).
1445  *
1446  *     Note that, for aggregation, ACK (block-ack) status is not delivered here;
1447  *     block-ack has not been received by the time the agn device records
1448  *     this status.
1449  *     This status relates to reasons the tx might have been blocked or aborted
1450  *     within the sending station (this agn device), rather than whether it was
1451  *     received successfully by the destination station.
1452  */
1453 struct agg_tx_status {
1454         __le16 status;
1455         __le16 sequence;
1456 } __packed;
1457
1458 /*
1459  * definitions for initial rate index field
1460  * bits [3:0] initial rate index
1461  * bits [6:4] rate table color, used for the initial rate
1462  * bit-7 invalid rate indication
1463  *   i.e. rate was not chosen from rate table
1464  *   or rate table color was changed during frame retries
1465  * refer tlc rate info
1466  */
1467
1468 #define IWL50_TX_RES_INIT_RATE_INDEX_POS        0
1469 #define IWL50_TX_RES_INIT_RATE_INDEX_MSK        0x0f
1470 #define IWL50_TX_RES_RATE_TABLE_COLOR_POS       4
1471 #define IWL50_TX_RES_RATE_TABLE_COLOR_MSK       0x70
1472 #define IWL50_TX_RES_INV_RATE_INDEX_MSK 0x80
1473
1474 /* refer to ra_tid */
1475 #define IWLAGN_TX_RES_TID_POS   0
1476 #define IWLAGN_TX_RES_TID_MSK   0x0f
1477 #define IWLAGN_TX_RES_RA_POS    4
1478 #define IWLAGN_TX_RES_RA_MSK    0xf0
1479
1480 struct iwlagn_tx_resp {
1481         u8 frame_count;         /* 1 no aggregation, >1 aggregation */
1482         u8 bt_kill_count;       /* # blocked by bluetooth (unused for agg) */
1483         u8 failure_rts;         /* # failures due to unsuccessful RTS */
1484         u8 failure_frame;       /* # failures due to no ACK (unused for agg) */
1485
1486         /* For non-agg:  Rate at which frame was successful.
1487          * For agg:  Rate at which all frames were transmitted. */
1488         __le32 rate_n_flags;    /* RATE_MCS_*  */
1489
1490         /* For non-agg:  RTS + CTS + frame tx attempts time + ACK.
1491          * For agg:  RTS + CTS + aggregation tx time + block-ack time. */
1492         __le16 wireless_media_time;     /* uSecs */
1493
1494         u8 pa_status;           /* RF power amplifier measurement (not used) */
1495         u8 pa_integ_res_a[3];
1496         u8 pa_integ_res_b[3];
1497         u8 pa_integ_res_C[3];
1498
1499         __le32 tfd_info;
1500         __le16 seq_ctl;
1501         __le16 byte_cnt;
1502         u8 tlc_info;
1503         u8 ra_tid;              /* tid (0:3), sta_id (4:7) */
1504         __le16 frame_ctrl;
1505         /*
1506          * For non-agg:  frame status TX_STATUS_*
1507          * For agg:  status of 1st frame, AGG_TX_STATE_*; other frame status
1508          *           fields follow this one, up to frame_count.
1509          *           Bit fields:
1510          *           11- 0:  AGG_TX_STATE_* status code
1511          *           15-12:  Retry count for 1st frame in aggregation (retries
1512          *                   occur if tx failed for this frame when it was a
1513          *                   member of a previous aggregation block).  If rate
1514          *                   scaling is used, retry count indicates the rate
1515          *                   table entry used for all frames in the new agg.
1516          *           31-16:  Sequence # for this frame's Tx cmd (not SSN!)
1517          */
1518         struct agg_tx_status status;    /* TX status (in aggregation -
1519                                          * status of 1st frame) */
1520 } __packed;
1521 /*
1522  * REPLY_COMPRESSED_BA = 0xc5 (response only, not a command)
1523  *
1524  * Reports Block-Acknowledge from recipient station
1525  */
1526 struct iwl_compressed_ba_resp {
1527         __le32 sta_addr_lo32;
1528         __le16 sta_addr_hi16;
1529         __le16 reserved;
1530
1531         /* Index of recipient (BA-sending) station in uCode's station table */
1532         u8 sta_id;
1533         u8 tid;
1534         __le16 seq_ctl;
1535         __le64 bitmap;
1536         __le16 scd_flow;
1537         __le16 scd_ssn;
1538         /* following only for 5000 series and up */
1539         u8 txed;        /* number of frames sent */
1540         u8 txed_2_done; /* number of frames acked */
1541 } __packed;
1542
1543 /*
1544  * REPLY_TX_PWR_TABLE_CMD = 0x97 (command, has simple generic response)
1545  *
1546  */
1547
1548 /*RS_NEW_API: only TLC_RTS remains and moved to bit 0 */
1549 #define  LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK    (1 << 0)
1550
1551 /* # of EDCA prioritized tx fifos */
1552 #define  LINK_QUAL_AC_NUM AC_NUM
1553
1554 /* # entries in rate scale table to support Tx retries */
1555 #define  LINK_QUAL_MAX_RETRY_NUM 16
1556
1557 /* Tx antenna selection values */
1558 #define  LINK_QUAL_ANT_A_MSK (1 << 0)
1559 #define  LINK_QUAL_ANT_B_MSK (1 << 1)
1560 #define  LINK_QUAL_ANT_MSK   (LINK_QUAL_ANT_A_MSK|LINK_QUAL_ANT_B_MSK)
1561
1562
1563 /**
1564  * struct iwl_link_qual_general_params
1565  *
1566  * Used in REPLY_TX_LINK_QUALITY_CMD
1567  */
1568 struct iwl_link_qual_general_params {
1569         u8 flags;
1570
1571         /* No entries at or above this (driver chosen) index contain MIMO */
1572         u8 mimo_delimiter;
1573
1574         /* Best single antenna to use for single stream (legacy, SISO). */
1575         u8 single_stream_ant_msk;       /* LINK_QUAL_ANT_* */
1576
1577         /* Best antennas to use for MIMO (unused for 4965, assumes both). */
1578         u8 dual_stream_ant_msk;         /* LINK_QUAL_ANT_* */
1579
1580         /*
1581          * If driver needs to use different initial rates for different
1582          * EDCA QOS access categories (as implemented by tx fifos 0-3),
1583          * this table will set that up, by indicating the indexes in the
1584          * rs_table[LINK_QUAL_MAX_RETRY_NUM] rate table at which to start.
1585          * Otherwise, driver should set all entries to 0.
1586          *
1587          * Entry usage:
1588          * 0 = Background, 1 = Best Effort (normal), 2 = Video, 3 = Voice
1589          * TX FIFOs above 3 use same value (typically 0) as TX FIFO 3.
1590          */
1591         u8 start_rate_index[LINK_QUAL_AC_NUM];
1592 } __packed;
1593
1594 #define LINK_QUAL_AGG_TIME_LIMIT_DEF    (4000) /* 4 milliseconds */
1595 #define LINK_QUAL_AGG_TIME_LIMIT_MAX    (8000)
1596 #define LINK_QUAL_AGG_TIME_LIMIT_MIN    (100)
1597
1598 #define LINK_QUAL_AGG_DISABLE_START_DEF (3)
1599 #define LINK_QUAL_AGG_DISABLE_START_MAX (255)
1600 #define LINK_QUAL_AGG_DISABLE_START_MIN (0)
1601
1602 #define LINK_QUAL_AGG_FRAME_LIMIT_DEF   (63)
1603 #define LINK_QUAL_AGG_FRAME_LIMIT_MAX   (63)
1604 #define LINK_QUAL_AGG_FRAME_LIMIT_MIN   (0)
1605
1606 /**
1607  * struct iwl_link_qual_agg_params
1608  *
1609  * Used in REPLY_TX_LINK_QUALITY_CMD
1610  */
1611 struct iwl_link_qual_agg_params {
1612
1613         /*
1614          *Maximum number of uSec in aggregation.
1615          * default set to 4000 (4 milliseconds) if not configured in .cfg
1616          */
1617         __le16 agg_time_limit;
1618
1619         /*
1620          * Number of Tx retries allowed for a frame, before that frame will
1621          * no longer be considered for the start of an aggregation sequence
1622          * (scheduler will then try to tx it as single frame).
1623          * Driver should set this to 3.
1624          */
1625         u8 agg_dis_start_th;
1626
1627         /*
1628          * Maximum number of frames in aggregation.
1629          * 0 = no limit (default).  1 = no aggregation.
1630          * Other values = max # frames in aggregation.
1631          */
1632         u8 agg_frame_cnt_limit;
1633
1634         __le32 reserved;
1635 } __packed;
1636
1637 /*
1638  * REPLY_TX_LINK_QUALITY_CMD = 0x4e (command, has simple generic response)
1639  *
1640  * For agn devices only; 3945 uses REPLY_RATE_SCALE.
1641  *
1642  * Each station in the agn device's internal station table has its own table
1643  * of 16
1644  * Tx rates and modulation modes (e.g. legacy/SISO/MIMO) for retrying Tx when
1645  * an ACK is not received.  This command replaces the entire table for
1646  * one station.
1647  *
1648  * NOTE:  Station must already be in agn device's station table.
1649  *        Use REPLY_ADD_STA.
1650  *
1651  * The rate scaling procedures described below work well.  Of course, other
1652  * procedures are possible, and may work better for particular environments.
1653  *
1654  *
1655  * FILLING THE RATE TABLE
1656  *
1657  * Given a particular initial rate and mode, as determined by the rate
1658  * scaling algorithm described below, the Linux driver uses the following
1659  * formula to fill the rs_table[LINK_QUAL_MAX_RETRY_NUM] rate table in the
1660  * Link Quality command:
1661  *
1662  *
1663  * 1)  If using High-throughput (HT) (SISO or MIMO) initial rate:
1664  *     a) Use this same initial rate for first 3 entries.
1665  *     b) Find next lower available rate using same mode (SISO or MIMO),
1666  *        use for next 3 entries.  If no lower rate available, switch to
1667  *        legacy mode (no HT40 channel, no MIMO, no short guard interval).
1668  *     c) If using MIMO, set command's mimo_delimiter to number of entries
1669  *        using MIMO (3 or 6).
1670  *     d) After trying 2 HT rates, switch to legacy mode (no HT40 channel,
1671  *        no MIMO, no short guard interval), at the next lower bit rate
1672  *        (e.g. if second HT bit rate was 54, try 48 legacy), and follow
1673  *        legacy procedure for remaining table entries.
1674  *
1675  * 2)  If using legacy initial rate:
1676  *     a) Use the initial rate for only one entry.
1677  *     b) For each following entry, reduce the rate to next lower available
1678  *        rate, until reaching the lowest available rate.
1679  *     c) When reducing rate, also switch antenna selection.
1680  *     d) Once lowest available rate is reached, repeat this rate until
1681  *        rate table is filled (16 entries), switching antenna each entry.
1682  *
1683  *
1684  * ACCUMULATING HISTORY
1685  *
1686  * The rate scaling algorithm for agn devices, as implemented in Linux driver,
1687  * uses two sets of frame Tx success history:  One for the current/active
1688  * modulation mode, and one for a speculative/search mode that is being
1689  * attempted. If the speculative mode turns out to be more effective (i.e.
1690  * actual transfer rate is better), then the driver continues to use the
1691  * speculative mode as the new current active mode.
1692  *
1693  * Each history set contains, separately for each possible rate, data for a
1694  * sliding window of the 62 most recent tx attempts at that rate.  The data
1695  * includes a shifting bitmap of success(1)/failure(0), and sums of successful
1696  * and attempted frames, from which the driver can additionally calculate a
1697  * success ratio (success / attempted) and number of failures
1698  * (attempted - success), and control the size of the window (attempted).
1699  * The driver uses the bit map to remove successes from the success sum, as
1700  * the oldest tx attempts fall out of the window.
1701  *
1702  * When the agn device makes multiple tx attempts for a given frame, each
1703  * attempt might be at a different rate, and have different modulation
1704  * characteristics (e.g. antenna, fat channel, short guard interval), as set
1705  * up in the rate scaling table in the Link Quality command.  The driver must
1706  * determine which rate table entry was used for each tx attempt, to determine
1707  * which rate-specific history to update, and record only those attempts that
1708  * match the modulation characteristics of the history set.
1709  *
1710  * When using block-ack (aggregation), all frames are transmitted at the same
1711  * rate, since there is no per-attempt acknowledgment from the destination
1712  * station.  The Tx response struct iwl_tx_resp indicates the Tx rate in
1713  * rate_n_flags field.  After receiving a block-ack, the driver can update
1714  * history for the entire block all at once.
1715  *
1716  *
1717  * FINDING BEST STARTING RATE:
1718  *
1719  * When working with a selected initial modulation mode (see below), the
1720  * driver attempts to find a best initial rate.  The initial rate is the
1721  * first entry in the Link Quality command's rate table.
1722  *
1723  * 1)  Calculate actual throughput (success ratio * expected throughput, see
1724  *     table below) for current initial rate.  Do this only if enough frames
1725  *     have been attempted to make the value meaningful:  at least 6 failed
1726  *     tx attempts, or at least 8 successes.  If not enough, don't try rate
1727  *     scaling yet.
1728  *
1729  * 2)  Find available rates adjacent to current initial rate.  Available means:
1730  *     a)  supported by hardware &&
1731  *     b)  supported by association &&
1732  *     c)  within any constraints selected by user
1733  *
1734  * 3)  Gather measured throughputs for adjacent rates.  These might not have
1735  *     enough history to calculate a throughput.  That's okay, we might try
1736  *     using one of them anyway!
1737  *
1738  * 4)  Try decreasing rate if, for current rate:
1739  *     a)  success ratio is < 15% ||
1740  *     b)  lower adjacent rate has better measured throughput ||
1741  *     c)  higher adjacent rate has worse throughput, and lower is unmeasured
1742  *
1743  *     As a sanity check, if decrease was determined above, leave rate
1744  *     unchanged if:
1745  *     a)  lower rate unavailable
1746  *     b)  success ratio at current rate > 85% (very good)
1747  *     c)  current measured throughput is better than expected throughput
1748  *         of lower rate (under perfect 100% tx conditions, see table below)
1749  *
1750  * 5)  Try increasing rate if, for current rate:
1751  *     a)  success ratio is < 15% ||
1752  *     b)  both adjacent rates' throughputs are unmeasured (try it!) ||
1753  *     b)  higher adjacent rate has better measured throughput ||
1754  *     c)  lower adjacent rate has worse throughput, and higher is unmeasured
1755  *
1756  *     As a sanity check, if increase was determined above, leave rate
1757  *     unchanged if:
1758  *     a)  success ratio at current rate < 70%.  This is not particularly
1759  *         good performance; higher rate is sure to have poorer success.
1760  *
1761  * 6)  Re-evaluate the rate after each tx frame.  If working with block-
1762  *     acknowledge, history and statistics may be calculated for the entire
1763  *     block (including prior history that fits within the history windows),
1764  *     before re-evaluation.
1765  *
1766  * FINDING BEST STARTING MODULATION MODE:
1767  *
1768  * After working with a modulation mode for a "while" (and doing rate scaling),
1769  * the driver searches for a new initial mode in an attempt to improve
1770  * throughput.  The "while" is measured by numbers of attempted frames:
1771  *
1772  * For legacy mode, search for new mode after:
1773  *   480 successful frames, or 160 failed frames
1774  * For high-throughput modes (SISO or MIMO), search for new mode after:
1775  *   4500 successful frames, or 400 failed frames
1776  *
1777  * Mode switch possibilities are (3 for each mode):
1778  *
1779  * For legacy:
1780  *   Change antenna, try SISO (if HT association), try MIMO (if HT association)
1781  * For SISO:
1782  *   Change antenna, try MIMO, try shortened guard interval (SGI)
1783  * For MIMO:
1784  *   Try SISO antenna A, SISO antenna B, try shortened guard interval (SGI)
1785  *
1786  * When trying a new mode, use the same bit rate as the old/current mode when
1787  * trying antenna switches and shortened guard interval.  When switching to
1788  * SISO from MIMO or legacy, or to MIMO from SISO or legacy, use a rate
1789  * for which the expected throughput (under perfect conditions) is about the
1790  * same or slightly better than the actual measured throughput delivered by
1791  * the old/current mode.
1792  *
1793  * Actual throughput can be estimated by multiplying the expected throughput
1794  * by the success ratio (successful / attempted tx frames).  Frame size is
1795  * not considered in this calculation; it assumes that frame size will average
1796  * out to be fairly consistent over several samples.  The following are
1797  * metric values for expected throughput assuming 100% success ratio.
1798  * Only G band has support for CCK rates:
1799  *
1800  *           RATE:  1    2    5   11    6   9   12   18   24   36   48   54   60
1801  *
1802  *              G:  7   13   35   58   40  57   72   98  121  154  177  186  186
1803  *              A:  0    0    0    0   40  57   72   98  121  154  177  186  186
1804  *     SISO 20MHz:  0    0    0    0   42  42   76  102  124  159  183  193  202
1805  * SGI SISO 20MHz:  0    0    0    0   46  46   82  110  132  168  192  202  211
1806  *     MIMO 20MHz:  0    0    0    0   74  74  123  155  179  214  236  244  251
1807  * SGI MIMO 20MHz:  0    0    0    0   81  81  131  164  188  222  243  251  257
1808  *     SISO 40MHz:  0    0    0    0   77  77  127  160  184  220  242  250  257
1809  * SGI SISO 40MHz:  0    0    0    0   83  83  135  169  193  229  250  257  264
1810  *     MIMO 40MHz:  0    0    0    0  123 123  182  214  235  264  279  285  289
1811  * SGI MIMO 40MHz:  0    0    0    0  131 131  191  222  242  270  284  289  293
1812  *
1813  * After the new mode has been tried for a short while (minimum of 6 failed
1814  * frames or 8 successful frames), compare success ratio and actual throughput
1815  * estimate of the new mode with the old.  If either is better with the new
1816  * mode, continue to use the new mode.
1817  *
1818  * Continue comparing modes until all 3 possibilities have been tried.
1819  * If moving from legacy to HT, try all 3 possibilities from the new HT
1820  * mode.  After trying all 3, a best mode is found.  Continue to use this mode
1821  * for the longer "while" described above (e.g. 480 successful frames for
1822  * legacy), and then repeat the search process.
1823  *
1824  */
1825 struct iwl_link_quality_cmd {
1826
1827         /* Index of destination/recipient station in uCode's station table */
1828         u8 sta_id;
1829         u8 reserved1;
1830         __le16 control;         /* not used */
1831         struct iwl_link_qual_general_params general_params;
1832         struct iwl_link_qual_agg_params agg_params;
1833
1834         /*
1835          * Rate info; when using rate-scaling, Tx command's initial_rate_index
1836          * specifies 1st Tx rate attempted, via index into this table.
1837          * agn devices works its way through table when retrying Tx.
1838          */
1839         struct {
1840                 __le32 rate_n_flags;    /* RATE_MCS_*, IWL_RATE_* */
1841         } rs_table[LINK_QUAL_MAX_RETRY_NUM];
1842         __le32 reserved2;
1843 } __packed;
1844
1845 /*
1846  * BT configuration enable flags:
1847  *   bit 0 - 1: BT channel announcement enabled
1848  *           0: disable
1849  *   bit 1 - 1: priority of BT device enabled
1850  *           0: disable
1851  *   bit 2 - 1: BT 2 wire support enabled
1852  *           0: disable
1853  */
1854 #define BT_COEX_DISABLE (0x0)
1855 #define BT_ENABLE_CHANNEL_ANNOUNCE BIT(0)
1856 #define BT_ENABLE_PRIORITY         BIT(1)
1857 #define BT_ENABLE_2_WIRE           BIT(2)
1858
1859 #define BT_COEX_DISABLE (0x0)
1860 #define BT_COEX_ENABLE  (BT_ENABLE_CHANNEL_ANNOUNCE | BT_ENABLE_PRIORITY)
1861
1862 #define BT_LEAD_TIME_MIN (0x0)
1863 #define BT_LEAD_TIME_DEF (0x1E)
1864 #define BT_LEAD_TIME_MAX (0xFF)
1865
1866 #define BT_MAX_KILL_MIN (0x1)
1867 #define BT_MAX_KILL_DEF (0x5)
1868 #define BT_MAX_KILL_MAX (0xFF)
1869
1870 #define BT_DURATION_LIMIT_DEF   625
1871 #define BT_DURATION_LIMIT_MAX   1250
1872 #define BT_DURATION_LIMIT_MIN   625
1873
1874 #define BT_ON_THRESHOLD_DEF     4
1875 #define BT_ON_THRESHOLD_MAX     1000
1876 #define BT_ON_THRESHOLD_MIN     1
1877
1878 #define BT_FRAG_THRESHOLD_DEF   0
1879 #define BT_FRAG_THRESHOLD_MAX   0
1880 #define BT_FRAG_THRESHOLD_MIN   0
1881
1882 #define BT_AGG_THRESHOLD_DEF    1200
1883 #define BT_AGG_THRESHOLD_MAX    8000
1884 #define BT_AGG_THRESHOLD_MIN    400
1885
1886 /*
1887  * REPLY_BT_CONFIG = 0x9b (command, has simple generic response)
1888  *
1889  * 3945 and agn devices support hardware handshake with Bluetooth device on
1890  * same platform.  Bluetooth device alerts wireless device when it will Tx;
1891  * wireless device can delay or kill its own Tx to accommodate.
1892  */
1893 struct iwl_bt_cmd {
1894         u8 flags;
1895         u8 lead_time;
1896         u8 max_kill;
1897         u8 reserved;
1898         __le32 kill_ack_mask;
1899         __le32 kill_cts_mask;
1900 } __packed;
1901
1902 #define IWLAGN_BT_FLAG_CHANNEL_INHIBITION       BIT(0)
1903
1904 #define IWLAGN_BT_FLAG_COEX_MODE_MASK           (BIT(3)|BIT(4)|BIT(5))
1905 #define IWLAGN_BT_FLAG_COEX_MODE_SHIFT          3
1906 #define IWLAGN_BT_FLAG_COEX_MODE_DISABLED       0
1907 #define IWLAGN_BT_FLAG_COEX_MODE_LEGACY_2W      1
1908 #define IWLAGN_BT_FLAG_COEX_MODE_3W             2
1909 #define IWLAGN_BT_FLAG_COEX_MODE_4W             3
1910
1911 #define IWLAGN_BT_FLAG_UCODE_DEFAULT            BIT(6)
1912 /* Disable Sync PSPoll on SCO/eSCO */
1913 #define IWLAGN_BT_FLAG_SYNC_2_BT_DISABLE        BIT(7)
1914
1915 #define IWLAGN_BT_PRIO_BOOST_MAX        0xFF
1916 #define IWLAGN_BT_PRIO_BOOST_MIN        0x00
1917 #define IWLAGN_BT_PRIO_BOOST_DEFAULT    0xF0
1918
1919 #define IWLAGN_BT_MAX_KILL_DEFAULT      5
1920
1921 #define IWLAGN_BT3_T7_DEFAULT           1
1922
1923 #define IWLAGN_BT_KILL_ACK_MASK_DEFAULT cpu_to_le32(0xffff0000)
1924 #define IWLAGN_BT_KILL_CTS_MASK_DEFAULT cpu_to_le32(0xffff0000)
1925 #define IWLAGN_BT_KILL_ACK_CTS_MASK_SCO cpu_to_le32(0xffffffff)
1926
1927 #define IWLAGN_BT3_PRIO_SAMPLE_DEFAULT  2
1928
1929 #define IWLAGN_BT3_T2_DEFAULT           0xc
1930
1931 #define IWLAGN_BT_VALID_ENABLE_FLAGS    cpu_to_le16(BIT(0))
1932 #define IWLAGN_BT_VALID_BOOST           cpu_to_le16(BIT(1))
1933 #define IWLAGN_BT_VALID_MAX_KILL        cpu_to_le16(BIT(2))
1934 #define IWLAGN_BT_VALID_3W_TIMERS       cpu_to_le16(BIT(3))
1935 #define IWLAGN_BT_VALID_KILL_ACK_MASK   cpu_to_le16(BIT(4))
1936 #define IWLAGN_BT_VALID_KILL_CTS_MASK   cpu_to_le16(BIT(5))
1937 #define IWLAGN_BT_VALID_BT4_TIMES       cpu_to_le16(BIT(6))
1938 #define IWLAGN_BT_VALID_3W_LUT          cpu_to_le16(BIT(7))
1939
1940 #define IWLAGN_BT_ALL_VALID_MSK         (IWLAGN_BT_VALID_ENABLE_FLAGS | \
1941                                         IWLAGN_BT_VALID_BOOST | \
1942                                         IWLAGN_BT_VALID_MAX_KILL | \
1943                                         IWLAGN_BT_VALID_3W_TIMERS | \
1944                                         IWLAGN_BT_VALID_KILL_ACK_MASK | \
1945                                         IWLAGN_BT_VALID_KILL_CTS_MASK | \
1946                                         IWLAGN_BT_VALID_BT4_TIMES | \
1947                                         IWLAGN_BT_VALID_3W_LUT)
1948
1949 struct iwl_basic_bt_cmd {
1950         u8 flags;
1951         u8 ledtime; /* unused */
1952         u8 max_kill;
1953         u8 bt3_timer_t7_value;
1954         __le32 kill_ack_mask;
1955         __le32 kill_cts_mask;
1956         u8 bt3_prio_sample_time;
1957         u8 bt3_timer_t2_value;
1958         __le16 bt4_reaction_time; /* unused */
1959         __le32 bt3_lookup_table[12];
1960         __le16 bt4_decision_time; /* unused */
1961         __le16 valid;
1962 };
1963
1964 struct iwl6000_bt_cmd {
1965         struct iwl_basic_bt_cmd basic;
1966         u8 prio_boost;
1967         /*
1968          * set IWLAGN_BT_VALID_BOOST to "1" in "valid" bitmask
1969          * if configure the following patterns
1970          */
1971         u8 tx_prio_boost;       /* SW boost of WiFi tx priority */
1972         __le16 rx_prio_boost;   /* SW boost of WiFi rx priority */
1973 };
1974
1975 struct iwl2000_bt_cmd {
1976         struct iwl_basic_bt_cmd basic;
1977         __le32 prio_boost;
1978         /*
1979          * set IWLAGN_BT_VALID_BOOST to "1" in "valid" bitmask
1980          * if configure the following patterns
1981          */
1982         u8 reserved;
1983         u8 tx_prio_boost;       /* SW boost of WiFi tx priority */
1984         __le16 rx_prio_boost;   /* SW boost of WiFi rx priority */
1985 };
1986
1987 #define IWLAGN_BT_SCO_ACTIVE    cpu_to_le32(BIT(0))
1988
1989 struct iwlagn_bt_sco_cmd {
1990         __le32 flags;
1991 };
1992
1993 /******************************************************************************
1994  * (6)
1995  * Spectrum Management (802.11h) Commands, Responses, Notifications:
1996  *
1997  *****************************************************************************/
1998
1999 /*
2000  * Spectrum Management
2001  */
2002 #define MEASUREMENT_FILTER_FLAG (RXON_FILTER_PROMISC_MSK         | \
2003                                  RXON_FILTER_CTL2HOST_MSK        | \
2004                                  RXON_FILTER_ACCEPT_GRP_MSK      | \
2005                                  RXON_FILTER_DIS_DECRYPT_MSK     | \
2006                                  RXON_FILTER_DIS_GRP_DECRYPT_MSK | \
2007                                  RXON_FILTER_ASSOC_MSK           | \
2008                                  RXON_FILTER_BCON_AWARE_MSK)
2009
2010 struct iwl_measure_channel {
2011         __le32 duration;        /* measurement duration in extended beacon
2012                                  * format */
2013         u8 channel;             /* channel to measure */
2014         u8 type;                /* see enum iwl_measure_type */
2015         __le16 reserved;
2016 } __packed;
2017
2018 /*
2019  * REPLY_SPECTRUM_MEASUREMENT_CMD = 0x74 (command)
2020  */
2021 struct iwl_spectrum_cmd {
2022         __le16 len;             /* number of bytes starting from token */
2023         u8 token;               /* token id */
2024         u8 id;                  /* measurement id -- 0 or 1 */
2025         u8 origin;              /* 0 = TGh, 1 = other, 2 = TGk */
2026         u8 periodic;            /* 1 = periodic */
2027         __le16 path_loss_timeout;
2028         __le32 start_time;      /* start time in extended beacon format */
2029         __le32 reserved2;
2030         __le32 flags;           /* rxon flags */
2031         __le32 filter_flags;    /* rxon filter flags */
2032         __le16 channel_count;   /* minimum 1, maximum 10 */
2033         __le16 reserved3;
2034         struct iwl_measure_channel channels[10];
2035 } __packed;
2036
2037 /*
2038  * REPLY_SPECTRUM_MEASUREMENT_CMD = 0x74 (response)
2039  */
2040 struct iwl_spectrum_resp {
2041         u8 token;
2042         u8 id;                  /* id of the prior command replaced, or 0xff */
2043         __le16 status;          /* 0 - command will be handled
2044                                  * 1 - cannot handle (conflicts with another
2045                                  *     measurement) */
2046 } __packed;
2047
2048 enum iwl_measurement_state {
2049         IWL_MEASUREMENT_START = 0,
2050         IWL_MEASUREMENT_STOP = 1,
2051 };
2052
2053 enum iwl_measurement_status {
2054         IWL_MEASUREMENT_OK = 0,
2055         IWL_MEASUREMENT_CONCURRENT = 1,
2056         IWL_MEASUREMENT_CSA_CONFLICT = 2,
2057         IWL_MEASUREMENT_TGH_CONFLICT = 3,
2058         /* 4-5 reserved */
2059         IWL_MEASUREMENT_STOPPED = 6,
2060         IWL_MEASUREMENT_TIMEOUT = 7,
2061         IWL_MEASUREMENT_PERIODIC_FAILED = 8,
2062 };
2063
2064 #define NUM_ELEMENTS_IN_HISTOGRAM 8
2065
2066 struct iwl_measurement_histogram {
2067         __le32 ofdm[NUM_ELEMENTS_IN_HISTOGRAM]; /* in 0.8usec counts */
2068         __le32 cck[NUM_ELEMENTS_IN_HISTOGRAM];  /* in 1usec counts */
2069 } __packed;
2070
2071 /* clear channel availability counters */
2072 struct iwl_measurement_cca_counters {
2073         __le32 ofdm;
2074         __le32 cck;
2075 } __packed;
2076
2077 enum iwl_measure_type {
2078         IWL_MEASURE_BASIC = (1 << 0),
2079         IWL_MEASURE_CHANNEL_LOAD = (1 << 1),
2080         IWL_MEASURE_HISTOGRAM_RPI = (1 << 2),
2081         IWL_MEASURE_HISTOGRAM_NOISE = (1 << 3),
2082         IWL_MEASURE_FRAME = (1 << 4),
2083         /* bits 5:6 are reserved */
2084         IWL_MEASURE_IDLE = (1 << 7),
2085 };
2086
2087 /*
2088  * SPECTRUM_MEASURE_NOTIFICATION = 0x75 (notification only, not a command)
2089  */
2090 struct iwl_spectrum_notification {
2091         u8 id;                  /* measurement id -- 0 or 1 */
2092         u8 token;
2093         u8 channel_index;       /* index in measurement channel list */
2094         u8 state;               /* 0 - start, 1 - stop */
2095         __le32 start_time;      /* lower 32-bits of TSF */
2096         u8 band;                /* 0 - 5.2GHz, 1 - 2.4GHz */
2097         u8 channel;
2098         u8 type;                /* see enum iwl_measurement_type */
2099         u8 reserved1;
2100         /* NOTE:  cca_ofdm, cca_cck, basic_type, and histogram are only only
2101          * valid if applicable for measurement type requested. */
2102         __le32 cca_ofdm;        /* cca fraction time in 40Mhz clock periods */
2103         __le32 cca_cck;         /* cca fraction time in 44Mhz clock periods */
2104         __le32 cca_time;        /* channel load time in usecs */
2105         u8 basic_type;          /* 0 - bss, 1 - ofdm preamble, 2 -
2106                                  * unidentified */
2107         u8 reserved2[3];
2108         struct iwl_measurement_histogram histogram;
2109         __le32 stop_time;       /* lower 32-bits of TSF */
2110         __le32 status;          /* see iwl_measurement_status */
2111 } __packed;
2112
2113 /******************************************************************************
2114  * (7)
2115  * Power Management Commands, Responses, Notifications:
2116  *
2117  *****************************************************************************/
2118
2119 /**
2120  * struct iwl_powertable_cmd - Power Table Command
2121  * @flags: See below:
2122  *
2123  * POWER_TABLE_CMD = 0x77 (command, has simple generic response)
2124  *
2125  * PM allow:
2126  *   bit 0 - '0' Driver not allow power management
2127  *           '1' Driver allow PM (use rest of parameters)
2128  *
2129  * uCode send sleep notifications:
2130  *   bit 1 - '0' Don't send sleep notification
2131  *           '1' send sleep notification (SEND_PM_NOTIFICATION)
2132  *
2133  * Sleep over DTIM
2134  *   bit 2 - '0' PM have to walk up every DTIM
2135  *           '1' PM could sleep over DTIM till listen Interval.
2136  *
2137  * PCI power managed
2138  *   bit 3 - '0' (PCI_CFG_LINK_CTRL & 0x1)
2139  *           '1' !(PCI_CFG_LINK_CTRL & 0x1)
2140  *
2141  * Fast PD
2142  *   bit 4 - '1' Put radio to sleep when receiving frame for others
2143  *
2144  * Force sleep Modes
2145  *   bit 31/30- '00' use both mac/xtal sleeps
2146  *              '01' force Mac sleep
2147  *              '10' force xtal sleep
2148  *              '11' Illegal set
2149  *
2150  * NOTE: if sleep_interval[SLEEP_INTRVL_TABLE_SIZE-1] > DTIM period then
2151  * ucode assume sleep over DTIM is allowed and we don't need to wake up
2152  * for every DTIM.
2153  */
2154 #define IWL_POWER_VEC_SIZE 5
2155
2156 #define IWL_POWER_DRIVER_ALLOW_SLEEP_MSK        cpu_to_le16(BIT(0))
2157 #define IWL_POWER_POWER_SAVE_ENA_MSK            cpu_to_le16(BIT(0))
2158 #define IWL_POWER_POWER_MANAGEMENT_ENA_MSK      cpu_to_le16(BIT(1))
2159 #define IWL_POWER_SLEEP_OVER_DTIM_MSK           cpu_to_le16(BIT(2))
2160 #define IWL_POWER_PCI_PM_MSK                    cpu_to_le16(BIT(3))
2161 #define IWL_POWER_FAST_PD                       cpu_to_le16(BIT(4))
2162 #define IWL_POWER_BEACON_FILTERING              cpu_to_le16(BIT(5))
2163 #define IWL_POWER_SHADOW_REG_ENA                cpu_to_le16(BIT(6))
2164 #define IWL_POWER_CT_KILL_SET                   cpu_to_le16(BIT(7))
2165 #define IWL_POWER_BT_SCO_ENA                    cpu_to_le16(BIT(8))
2166 #define IWL_POWER_ADVANCE_PM_ENA_MSK            cpu_to_le16(BIT(9))
2167
2168 struct iwl_powertable_cmd {
2169         __le16 flags;
2170         u8 keep_alive_seconds;          /* 3945 reserved */
2171         u8 debug_flags;                 /* 3945 reserved */
2172         __le32 rx_data_timeout;
2173         __le32 tx_data_timeout;
2174         __le32 sleep_interval[IWL_POWER_VEC_SIZE];
2175         __le32 keep_alive_beacons;
2176 } __packed;
2177
2178 /*
2179  * PM_SLEEP_NOTIFICATION = 0x7A (notification only, not a command)
2180  * all devices identical.
2181  */
2182 struct iwl_sleep_notification {
2183         u8 pm_sleep_mode;
2184         u8 pm_wakeup_src;
2185         __le16 reserved;
2186         __le32 sleep_time;
2187         __le32 tsf_low;
2188         __le32 bcon_timer;
2189 } __packed;
2190
2191 /* Sleep states.  all devices identical. */
2192 enum {
2193         IWL_PM_NO_SLEEP = 0,
2194         IWL_PM_SLP_MAC = 1,
2195         IWL_PM_SLP_FULL_MAC_UNASSOCIATE = 2,
2196         IWL_PM_SLP_FULL_MAC_CARD_STATE = 3,
2197         IWL_PM_SLP_PHY = 4,
2198         IWL_PM_SLP_REPENT = 5,
2199         IWL_PM_WAKEUP_BY_TIMER = 6,
2200         IWL_PM_WAKEUP_BY_DRIVER = 7,
2201         IWL_PM_WAKEUP_BY_RFKILL = 8,
2202         /* 3 reserved */
2203         IWL_PM_NUM_OF_MODES = 12,
2204 };
2205
2206 /*
2207  * REPLY_CARD_STATE_CMD = 0xa0 (command, has simple generic response)
2208  */
2209 #define CARD_STATE_CMD_DISABLE 0x00     /* Put card to sleep */
2210 #define CARD_STATE_CMD_ENABLE  0x01     /* Wake up card */
2211 #define CARD_STATE_CMD_HALT    0x02     /* Power down permanently */
2212 struct iwl_card_state_cmd {
2213         __le32 status;          /* CARD_STATE_CMD_* request new power state */
2214 } __packed;
2215
2216 /*
2217  * CARD_STATE_NOTIFICATION = 0xa1 (notification only, not a command)
2218  */
2219 struct iwl_card_state_notif {
2220         __le32 flags;
2221 } __packed;
2222
2223 #define HW_CARD_DISABLED   0x01
2224 #define SW_CARD_DISABLED   0x02
2225 #define CT_CARD_DISABLED   0x04
2226 #define RXON_CARD_DISABLED 0x10
2227
2228 struct iwl_ct_kill_config {
2229         __le32   reserved;
2230         __le32   critical_temperature_M;
2231         __le32   critical_temperature_R;
2232 }  __packed;
2233
2234 /* 1000, and 6x00 */
2235 struct iwl_ct_kill_throttling_config {
2236         __le32   critical_temperature_exit;
2237         __le32   reserved;
2238         __le32   critical_temperature_enter;
2239 }  __packed;
2240
2241 /******************************************************************************
2242  * (8)
2243  * Scan Commands, Responses, Notifications:
2244  *
2245  *****************************************************************************/
2246
2247 #define SCAN_CHANNEL_TYPE_PASSIVE cpu_to_le32(0)
2248 #define SCAN_CHANNEL_TYPE_ACTIVE  cpu_to_le32(1)
2249
2250 /**
2251  * struct iwl_scan_channel - entry in REPLY_SCAN_CMD channel table
2252  *
2253  * One for each channel in the scan list.
2254  * Each channel can independently select:
2255  * 1)  SSID for directed active scans
2256  * 2)  Txpower setting (for rate specified within Tx command)
2257  * 3)  How long to stay on-channel (behavior may be modified by quiet_time,
2258  *     quiet_plcp_th, good_CRC_th)
2259  *
2260  * To avoid uCode errors, make sure the following are true (see comments
2261  * under struct iwl_scan_cmd about max_out_time and quiet_time):
2262  * 1)  If using passive_dwell (i.e. passive_dwell != 0):
2263  *     active_dwell <= passive_dwell (< max_out_time if max_out_time != 0)
2264  * 2)  quiet_time <= active_dwell
2265  * 3)  If restricting off-channel time (i.e. max_out_time !=0):
2266  *     passive_dwell < max_out_time
2267  *     active_dwell < max_out_time
2268  */
2269
2270 struct iwl_scan_channel {
2271         /*
2272          * type is defined as:
2273          * 0:0 1 = active, 0 = passive
2274          * 1:20 SSID direct bit map; if a bit is set, then corresponding
2275          *     SSID IE is transmitted in probe request.
2276          * 21:31 reserved
2277          */
2278         __le32 type;
2279         __le16 channel; /* band is selected by iwl_scan_cmd "flags" field */
2280         u8 tx_gain;             /* gain for analog radio */
2281         u8 dsp_atten;           /* gain for DSP */
2282         __le16 active_dwell;    /* in 1024-uSec TU (time units), typ 5-50 */
2283         __le16 passive_dwell;   /* in 1024-uSec TU (time units), typ 20-500 */
2284 } __packed;
2285
2286 /* set number of direct probes __le32 type */
2287 #define IWL_SCAN_PROBE_MASK(n)  cpu_to_le32((BIT(n) | (BIT(n) - BIT(1))))
2288
2289 /**
2290  * struct iwl_ssid_ie - directed scan network information element
2291  *
2292  * Up to 20 of these may appear in REPLY_SCAN_CMD (Note: Only 4 are in
2293  * 3945 SCAN api), selected by "type" bit field in struct iwl_scan_channel;
2294  * each channel may select different ssids from among the 20 (4) entries.
2295  * SSID IEs get transmitted in reverse order of entry.
2296  */
2297 struct iwl_ssid_ie {
2298         u8 id;
2299         u8 len;
2300         u8 ssid[32];
2301 } __packed;
2302
2303 #define PROBE_OPTION_MAX_3945           4
2304 #define PROBE_OPTION_MAX                20
2305 #define TX_CMD_LIFE_TIME_INFINITE       cpu_to_le32(0xFFFFFFFF)
2306 #define IWL_GOOD_CRC_TH_DISABLED        0
2307 #define IWL_GOOD_CRC_TH_DEFAULT         cpu_to_le16(1)
2308 #define IWL_GOOD_CRC_TH_NEVER           cpu_to_le16(0xffff)
2309 #define IWL_MAX_SCAN_SIZE 1024
2310 #define IWL_MAX_CMD_SIZE 4096
2311
2312 /*
2313  * REPLY_SCAN_CMD = 0x80 (command)
2314  *
2315  * The hardware scan command is very powerful; the driver can set it up to
2316  * maintain (relatively) normal network traffic while doing a scan in the
2317  * background.  The max_out_time and suspend_time control the ratio of how
2318  * long the device stays on an associated network channel ("service channel")
2319  * vs. how long it's away from the service channel, i.e. tuned to other channels
2320  * for scanning.
2321  *
2322  * max_out_time is the max time off-channel (in usec), and suspend_time
2323  * is how long (in "extended beacon" format) that the scan is "suspended"
2324  * after returning to the service channel.  That is, suspend_time is the
2325  * time that we stay on the service channel, doing normal work, between
2326  * scan segments.  The driver may set these parameters differently to support
2327  * scanning when associated vs. not associated, and light vs. heavy traffic
2328  * loads when associated.
2329  *
2330  * After receiving this command, the device's scan engine does the following;
2331  *
2332  * 1)  Sends SCAN_START notification to driver
2333  * 2)  Checks to see if it has time to do scan for one channel
2334  * 3)  Sends NULL packet, with power-save (PS) bit set to 1,
2335  *     to tell AP that we're going off-channel
2336  * 4)  Tunes to first channel in scan list, does active or passive scan
2337  * 5)  Sends SCAN_RESULT notification to driver
2338  * 6)  Checks to see if it has time to do scan on *next* channel in list
2339  * 7)  Repeats 4-6 until it no longer has time to scan the next channel
2340  *     before max_out_time expires
2341  * 8)  Returns to service channel
2342  * 9)  Sends NULL packet with PS=0 to tell AP that we're back
2343  * 10) Stays on service channel until suspend_time expires
2344  * 11) Repeats entire process 2-10 until list is complete
2345  * 12) Sends SCAN_COMPLETE notification
2346  *
2347  * For fast, efficient scans, the scan command also has support for staying on
2348  * a channel for just a short time, if doing active scanning and getting no
2349  * responses to the transmitted probe request.  This time is controlled by
2350  * quiet_time, and the number of received packets below which a channel is
2351  * considered "quiet" is controlled by quiet_plcp_threshold.
2352  *
2353  * For active scanning on channels that have regulatory restrictions against
2354  * blindly transmitting, the scan can listen before transmitting, to make sure
2355  * that there is already legitimate activity on the channel.  If enough
2356  * packets are cleanly received on the channel (controlled by good_CRC_th,
2357  * typical value 1), the scan engine starts transmitting probe requests.
2358  *
2359  * Driver must use separate scan commands for 2.4 vs. 5 GHz bands.
2360  *
2361  * To avoid uCode errors, see timing restrictions described under
2362  * struct iwl_scan_channel.
2363  */
2364
2365 enum iwl_scan_flags {
2366         /* BIT(0) currently unused */
2367         IWL_SCAN_FLAGS_ACTION_FRAME_TX  = BIT(1),
2368         /* bits 2-7 reserved */
2369 };
2370
2371 struct iwl_scan_cmd {
2372         __le16 len;
2373         u8 scan_flags;          /* scan flags: see enum iwl_scan_flags */
2374         u8 channel_count;       /* # channels in channel list */
2375         __le16 quiet_time;      /* dwell only this # millisecs on quiet channel
2376                                  * (only for active scan) */
2377         __le16 quiet_plcp_th;   /* quiet chnl is < this # pkts (typ. 1) */
2378         __le16 good_CRC_th;     /* passive -> active promotion threshold */
2379         __le16 rx_chain;        /* RXON_RX_CHAIN_* */
2380         __le32 max_out_time;    /* max usec to be away from associated (service)
2381                                  * channel */
2382         __le32 suspend_time;    /* pause scan this long (in "extended beacon
2383                                  * format") when returning to service chnl:
2384                                  * 3945; 31:24 # beacons, 19:0 additional usec,
2385                                  * 4965; 31:22 # beacons, 21:0 additional usec.
2386                                  */
2387         __le32 flags;           /* RXON_FLG_* */
2388         __le32 filter_flags;    /* RXON_FILTER_* */
2389
2390         /* For active scans (set to all-0s for passive scans).
2391          * Does not include payload.  Must specify Tx rate; no rate scaling. */
2392         struct iwl_tx_cmd tx_cmd;
2393
2394         /* For directed active scans (set to all-0s otherwise) */
2395         struct iwl_ssid_ie direct_scan[PROBE_OPTION_MAX];
2396
2397         /*
2398          * Probe request frame, followed by channel list.
2399          *
2400          * Size of probe request frame is specified by byte count in tx_cmd.
2401          * Channel list follows immediately after probe request frame.
2402          * Number of channels in list is specified by channel_count.
2403          * Each channel in list is of type:
2404          *
2405          * struct iwl_scan_channel channels[0];
2406          *
2407          * NOTE:  Only one band of channels can be scanned per pass.  You
2408          * must not mix 2.4GHz channels and 5.2GHz channels, and you must wait
2409          * for one scan to complete (i.e. receive SCAN_COMPLETE_NOTIFICATION)
2410          * before requesting another scan.
2411          */
2412         u8 data[0];
2413 } __packed;
2414
2415 /* Can abort will notify by complete notification with abort status. */
2416 #define CAN_ABORT_STATUS        cpu_to_le32(0x1)
2417 /* complete notification statuses */
2418 #define ABORT_STATUS            0x2
2419
2420 /*
2421  * REPLY_SCAN_CMD = 0x80 (response)
2422  */
2423 struct iwl_scanreq_notification {
2424         __le32 status;          /* 1: okay, 2: cannot fulfill request */
2425 } __packed;
2426
2427 /*
2428  * SCAN_START_NOTIFICATION = 0x82 (notification only, not a command)
2429  */
2430 struct iwl_scanstart_notification {
2431         __le32 tsf_low;
2432         __le32 tsf_high;
2433         __le32 beacon_timer;
2434         u8 channel;
2435         u8 band;
2436         u8 reserved[2];
2437         __le32 status;
2438 } __packed;
2439
2440 #define  SCAN_OWNER_STATUS 0x1;
2441 #define  MEASURE_OWNER_STATUS 0x2;
2442
2443 #define IWL_PROBE_STATUS_OK             0
2444 #define IWL_PROBE_STATUS_TX_FAILED      BIT(0)
2445 /* error statuses combined with TX_FAILED */
2446 #define IWL_PROBE_STATUS_FAIL_TTL       BIT(1)
2447 #define IWL_PROBE_STATUS_FAIL_BT        BIT(2)
2448
2449 #define NUMBER_OF_STATISTICS 1  /* first __le32 is good CRC */
2450 /*
2451  * SCAN_RESULTS_NOTIFICATION = 0x83 (notification only, not a command)
2452  */
2453 struct iwl_scanresults_notification {
2454         u8 channel;
2455         u8 band;
2456         u8 probe_status;
2457         u8 num_probe_not_sent; /* not enough time to send */
2458         __le32 tsf_low;
2459         __le32 tsf_high;
2460         __le32 statistics[NUMBER_OF_STATISTICS];
2461 } __packed;
2462
2463 /*
2464  * SCAN_COMPLETE_NOTIFICATION = 0x84 (notification only, not a command)
2465  */
2466 struct iwl_scancomplete_notification {
2467         u8 scanned_channels;
2468         u8 status;
2469         u8 bt_status;   /* BT On/Off status */
2470         u8 last_channel;
2471         __le32 tsf_low;
2472         __le32 tsf_high;
2473 } __packed;
2474
2475
2476 /******************************************************************************
2477  * (9)
2478  * IBSS/AP Commands and Notifications:
2479  *
2480  *****************************************************************************/
2481
2482 enum iwl_ibss_manager {
2483         IWL_NOT_IBSS_MANAGER = 0,
2484         IWL_IBSS_MANAGER = 1,
2485 };
2486
2487 /*
2488  * BEACON_NOTIFICATION = 0x90 (notification only, not a command)
2489  */
2490
2491 struct iwlagn_beacon_notif {
2492         struct iwlagn_tx_resp beacon_notify_hdr;
2493         __le32 low_tsf;
2494         __le32 high_tsf;
2495         __le32 ibss_mgr_status;
2496 } __packed;
2497
2498 /*
2499  * REPLY_TX_BEACON = 0x91 (command, has simple generic response)
2500  */
2501
2502 struct iwl_tx_beacon_cmd {
2503         struct iwl_tx_cmd tx;
2504         __le16 tim_idx;
2505         u8 tim_size;
2506         u8 reserved1;
2507         struct ieee80211_hdr frame[0];  /* beacon frame */
2508 } __packed;
2509
2510 /******************************************************************************
2511  * (10)
2512  * Statistics Commands and Notifications:
2513  *
2514  *****************************************************************************/
2515
2516 #define IWL_TEMP_CONVERT 260
2517
2518 #define SUP_RATE_11A_MAX_NUM_CHANNELS  8
2519 #define SUP_RATE_11B_MAX_NUM_CHANNELS  4
2520 #define SUP_RATE_11G_MAX_NUM_CHANNELS  12
2521
2522 /* Used for passing to driver number of successes and failures per rate */
2523 struct rate_histogram {
2524         union {
2525                 __le32 a[SUP_RATE_11A_MAX_NUM_CHANNELS];
2526                 __le32 b[SUP_RATE_11B_MAX_NUM_CHANNELS];
2527                 __le32 g[SUP_RATE_11G_MAX_NUM_CHANNELS];
2528         } success;
2529         union {
2530                 __le32 a[SUP_RATE_11A_MAX_NUM_CHANNELS];
2531                 __le32 b[SUP_RATE_11B_MAX_NUM_CHANNELS];
2532                 __le32 g[SUP_RATE_11G_MAX_NUM_CHANNELS];
2533         } failed;
2534 } __packed;
2535
2536 /* statistics command response */
2537
2538 struct statistics_dbg {
2539         __le32 burst_check;
2540         __le32 burst_count;
2541         __le32 wait_for_silence_timeout_cnt;
2542         __le32 reserved[3];
2543 } __packed;
2544
2545 struct statistics_rx_phy {
2546         __le32 ina_cnt;
2547         __le32 fina_cnt;
2548         __le32 plcp_err;
2549         __le32 crc32_err;
2550         __le32 overrun_err;
2551         __le32 early_overrun_err;
2552         __le32 crc32_good;
2553         __le32 false_alarm_cnt;
2554         __le32 fina_sync_err_cnt;
2555         __le32 sfd_timeout;
2556         __le32 fina_timeout;
2557         __le32 unresponded_rts;
2558         __le32 rxe_frame_limit_overrun;
2559         __le32 sent_ack_cnt;
2560         __le32 sent_cts_cnt;
2561         __le32 sent_ba_rsp_cnt;
2562         __le32 dsp_self_kill;
2563         __le32 mh_format_err;
2564         __le32 re_acq_main_rssi_sum;
2565         __le32 reserved3;
2566 } __packed;
2567
2568 struct statistics_rx_ht_phy {
2569         __le32 plcp_err;
2570         __le32 overrun_err;
2571         __le32 early_overrun_err;
2572         __le32 crc32_good;
2573         __le32 crc32_err;
2574         __le32 mh_format_err;
2575         __le32 agg_crc32_good;
2576         __le32 agg_mpdu_cnt;
2577         __le32 agg_cnt;
2578         __le32 unsupport_mcs;
2579 } __packed;
2580
2581 #define INTERFERENCE_DATA_AVAILABLE      cpu_to_le32(1)
2582
2583 struct statistics_rx_non_phy {
2584         __le32 bogus_cts;       /* CTS received when not expecting CTS */
2585         __le32 bogus_ack;       /* ACK received when not expecting ACK */
2586         __le32 non_bssid_frames;        /* number of frames with BSSID that
2587                                          * doesn't belong to the STA BSSID */
2588         __le32 filtered_frames; /* count frames that were dumped in the
2589                                  * filtering process */
2590         __le32 non_channel_beacons;     /* beacons with our bss id but not on
2591                                          * our serving channel */
2592         __le32 channel_beacons; /* beacons with our bss id and in our
2593                                  * serving channel */
2594         __le32 num_missed_bcon; /* number of missed beacons */
2595         __le32 adc_rx_saturation_time;  /* count in 0.8us units the time the
2596                                          * ADC was in saturation */
2597         __le32 ina_detection_search_time;/* total time (in 0.8us) searched
2598                                           * for INA */
2599         __le32 beacon_silence_rssi_a;   /* RSSI silence after beacon frame */
2600         __le32 beacon_silence_rssi_b;   /* RSSI silence after beacon frame */
2601         __le32 beacon_silence_rssi_c;   /* RSSI silence after beacon frame */
2602         __le32 interference_data_flag;  /* flag for interference data
2603                                          * availability. 1 when data is
2604                                          * available. */
2605         __le32 channel_load;            /* counts RX Enable time in uSec */
2606         __le32 dsp_false_alarms;        /* DSP false alarm (both OFDM
2607                                          * and CCK) counter */
2608         __le32 beacon_rssi_a;
2609         __le32 beacon_rssi_b;
2610         __le32 beacon_rssi_c;
2611         __le32 beacon_energy_a;
2612         __le32 beacon_energy_b;
2613         __le32 beacon_energy_c;
2614 } __packed;
2615
2616 struct statistics_rx_non_phy_bt {
2617         struct statistics_rx_non_phy common;
2618         /* additional stats for bt */
2619         __le32 num_bt_kills;
2620         __le32 reserved[2];
2621 } __packed;
2622
2623 struct statistics_rx {
2624         struct statistics_rx_phy ofdm;
2625         struct statistics_rx_phy cck;
2626         struct statistics_rx_non_phy general;
2627         struct statistics_rx_ht_phy ofdm_ht;
2628 } __packed;
2629
2630 struct statistics_rx_bt {
2631         struct statistics_rx_phy ofdm;
2632         struct statistics_rx_phy cck;
2633         struct statistics_rx_non_phy_bt general;
2634         struct statistics_rx_ht_phy ofdm_ht;
2635 } __packed;
2636
2637 /**
2638  * struct statistics_tx_power - current tx power
2639  *
2640  * @ant_a: current tx power on chain a in 1/2 dB step
2641  * @ant_b: current tx power on chain b in 1/2 dB step
2642  * @ant_c: current tx power on chain c in 1/2 dB step
2643  */
2644 struct statistics_tx_power {
2645         u8 ant_a;
2646         u8 ant_b;
2647         u8 ant_c;
2648         u8 reserved;
2649 } __packed;
2650
2651 struct statistics_tx_non_phy_agg {
2652         __le32 ba_timeout;
2653         __le32 ba_reschedule_frames;
2654         __le32 scd_query_agg_frame_cnt;
2655         __le32 scd_query_no_agg;
2656         __le32 scd_query_agg;
2657         __le32 scd_query_mismatch;
2658         __le32 frame_not_ready;
2659         __le32 underrun;
2660         __le32 bt_prio_kill;
2661         __le32 rx_ba_rsp_cnt;
2662 } __packed;
2663
2664 struct statistics_tx {
2665         __le32 preamble_cnt;
2666         __le32 rx_detected_cnt;
2667         __le32 bt_prio_defer_cnt;
2668         __le32 bt_prio_kill_cnt;
2669         __le32 few_bytes_cnt;
2670         __le32 cts_timeout;
2671         __le32 ack_timeout;
2672         __le32 expected_ack_cnt;
2673         __le32 actual_ack_cnt;
2674         __le32 dump_msdu_cnt;
2675         __le32 burst_abort_next_frame_mismatch_cnt;
2676         __le32 burst_abort_missing_next_frame_cnt;
2677         __le32 cts_timeout_collision;
2678         __le32 ack_or_ba_timeout_collision;
2679         struct statistics_tx_non_phy_agg agg;
2680         /*
2681          * "tx_power" are optional parameters provided by uCode,
2682          * 6000 series is the only device provide the information,
2683          * Those are reserved fields for all the other devices
2684          */
2685         struct statistics_tx_power tx_power;
2686         __le32 reserved1;
2687 } __packed;
2688
2689
2690 struct statistics_div {
2691         __le32 tx_on_a;
2692         __le32 tx_on_b;
2693         __le32 exec_time;
2694         __le32 probe_time;
2695         __le32 reserved1;
2696         __le32 reserved2;
2697 } __packed;
2698
2699 struct statistics_general_common {
2700         __le32 temperature;   /* radio temperature */
2701         __le32 temperature_m; /* for 5000 and up, this is radio voltage */
2702         struct statistics_dbg dbg;
2703         __le32 sleep_time;
2704         __le32 slots_out;
2705         __le32 slots_idle;
2706         __le32 ttl_timestamp;
2707         struct statistics_div div;
2708         __le32 rx_enable_counter;
2709         /*
2710          * num_of_sos_states:
2711          *  count the number of times we have to re-tune
2712          *  in order to get out of bad PHY status
2713          */
2714         __le32 num_of_sos_states;
2715 } __packed;
2716
2717 struct statistics_bt_activity {
2718         /* Tx statistics */
2719         __le32 hi_priority_tx_req_cnt;
2720         __le32 hi_priority_tx_denied_cnt;
2721         __le32 lo_priority_tx_req_cnt;
2722         __le32 lo_priority_tx_denied_cnt;
2723         /* Rx statistics */
2724         __le32 hi_priority_rx_req_cnt;
2725         __le32 hi_priority_rx_denied_cnt;
2726         __le32 lo_priority_rx_req_cnt;
2727         __le32 lo_priority_rx_denied_cnt;
2728 } __packed;
2729
2730 struct statistics_general {
2731         struct statistics_general_common common;
2732         __le32 reserved2;
2733         __le32 reserved3;
2734 } __packed;
2735
2736 struct statistics_general_bt {
2737         struct statistics_general_common common;
2738         struct statistics_bt_activity activity;
2739         __le32 reserved2;
2740         __le32 reserved3;
2741 } __packed;
2742
2743 #define UCODE_STATISTICS_CLEAR_MSK              (0x1 << 0)
2744 #define UCODE_STATISTICS_FREQUENCY_MSK          (0x1 << 1)
2745 #define UCODE_STATISTICS_NARROW_BAND_MSK        (0x1 << 2)
2746
2747 /*
2748  * REPLY_STATISTICS_CMD = 0x9c,
2749  * all devices identical.
2750  *
2751  * This command triggers an immediate response containing uCode statistics.
2752  * The response is in the same format as STATISTICS_NOTIFICATION 0x9d, below.
2753  *
2754  * If the CLEAR_STATS configuration flag is set, uCode will clear its
2755  * internal copy of the statistics (counters) after issuing the response.
2756  * This flag does not affect STATISTICS_NOTIFICATIONs after beacons (see below).
2757  *
2758  * If the DISABLE_NOTIF configuration flag is set, uCode will not issue
2759  * STATISTICS_NOTIFICATIONs after received beacons (see below).  This flag
2760  * does not affect the response to the REPLY_STATISTICS_CMD 0x9c itself.
2761  */
2762 #define IWL_STATS_CONF_CLEAR_STATS cpu_to_le32(0x1)     /* see above */
2763 #define IWL_STATS_CONF_DISABLE_NOTIF cpu_to_le32(0x2)/* see above */
2764 struct iwl_statistics_cmd {
2765         __le32 configuration_flags;     /* IWL_STATS_CONF_* */
2766 } __packed;
2767
2768 /*
2769  * STATISTICS_NOTIFICATION = 0x9d (notification only, not a command)
2770  *
2771  * By default, uCode issues this notification after receiving a beacon
2772  * while associated.  To disable this behavior, set DISABLE_NOTIF flag in the
2773  * REPLY_STATISTICS_CMD 0x9c, above.
2774  *
2775  * Statistics counters continue to increment beacon after beacon, but are
2776  * cleared when changing channels or when driver issues REPLY_STATISTICS_CMD
2777  * 0x9c with CLEAR_STATS bit set (see above).
2778  *
2779  * uCode also issues this notification during scans.  uCode clears statistics
2780  * appropriately so that each notification contains statistics for only the
2781  * one channel that has just been scanned.
2782  */
2783 #define STATISTICS_REPLY_FLG_BAND_24G_MSK         cpu_to_le32(0x2)
2784 #define STATISTICS_REPLY_FLG_HT40_MODE_MSK        cpu_to_le32(0x8)
2785
2786 struct iwl_notif_statistics {
2787         __le32 flag;
2788         struct statistics_rx rx;
2789         struct statistics_tx tx;
2790         struct statistics_general general;
2791 } __packed;
2792
2793 struct iwl_bt_notif_statistics {
2794         __le32 flag;
2795         struct statistics_rx_bt rx;
2796         struct statistics_tx tx;
2797         struct statistics_general_bt general;
2798 } __packed;
2799
2800 /*
2801  * MISSED_BEACONS_NOTIFICATION = 0xa2 (notification only, not a command)
2802  *
2803  * uCode send MISSED_BEACONS_NOTIFICATION to driver when detect beacon missed
2804  * in regardless of how many missed beacons, which mean when driver receive the
2805  * notification, inside the command, it can find all the beacons information
2806  * which include number of total missed beacons, number of consecutive missed
2807  * beacons, number of beacons received and number of beacons expected to
2808  * receive.
2809  *
2810  * If uCode detected consecutive_missed_beacons > 5, it will reset the radio
2811  * in order to bring the radio/PHY back to working state; which has no relation
2812  * to when driver will perform sensitivity calibration.
2813  *
2814  * Driver should set it own missed_beacon_threshold to decide when to perform
2815  * sensitivity calibration based on number of consecutive missed beacons in
2816  * order to improve overall performance, especially in noisy environment.
2817  *
2818  */
2819
2820 #define IWL_MISSED_BEACON_THRESHOLD_MIN (1)
2821 #define IWL_MISSED_BEACON_THRESHOLD_DEF (5)
2822 #define IWL_MISSED_BEACON_THRESHOLD_MAX IWL_MISSED_BEACON_THRESHOLD_DEF
2823
2824 struct iwl_missed_beacon_notif {
2825         __le32 consecutive_missed_beacons;
2826         __le32 total_missed_becons;
2827         __le32 num_expected_beacons;
2828         __le32 num_recvd_beacons;
2829 } __packed;
2830
2831
2832 /******************************************************************************
2833  * (11)
2834  * Rx Calibration Commands:
2835  *
2836  * With the uCode used for open source drivers, most Tx calibration (except
2837  * for Tx Power) and most Rx calibration is done by uCode during the
2838  * "initialize" phase of uCode boot.  Driver must calibrate only:
2839  *
2840  * 1)  Tx power (depends on temperature), described elsewhere
2841  * 2)  Receiver gain balance (optimize MIMO, and detect disconnected antennas)
2842  * 3)  Receiver sensitivity (to optimize signal detection)
2843  *
2844  *****************************************************************************/
2845
2846 /**
2847  * SENSITIVITY_CMD = 0xa8 (command, has simple generic response)
2848  *
2849  * This command sets up the Rx signal detector for a sensitivity level that
2850  * is high enough to lock onto all signals within the associated network,
2851  * but low enough to ignore signals that are below a certain threshold, so as
2852  * not to have too many "false alarms".  False alarms are signals that the
2853  * Rx DSP tries to lock onto, but then discards after determining that they
2854  * are noise.
2855  *
2856  * The optimum number of false alarms is between 5 and 50 per 200 TUs
2857  * (200 * 1024 uSecs, i.e. 204.8 milliseconds) of actual Rx time (i.e.
2858  * time listening, not transmitting).  Driver must adjust sensitivity so that
2859  * the ratio of actual false alarms to actual Rx time falls within this range.
2860  *
2861  * While associated, uCode delivers STATISTICS_NOTIFICATIONs after each
2862  * received beacon.  These provide information to the driver to analyze the
2863  * sensitivity.  Don't analyze statistics that come in from scanning, or any
2864  * other non-associated-network source.  Pertinent statistics include:
2865  *
2866  * From "general" statistics (struct statistics_rx_non_phy):
2867  *
2868  * (beacon_energy_[abc] & 0x0FF00) >> 8 (unsigned, higher value is lower level)
2869  *   Measure of energy of desired signal.  Used for establishing a level
2870  *   below which the device does not detect signals.
2871  *
2872  * (beacon_silence_rssi_[abc] & 0x0FF00) >> 8 (unsigned, units in dB)
2873  *   Measure of background noise in silent period after beacon.
2874  *
2875  * channel_load
2876  *   uSecs of actual Rx time during beacon period (varies according to
2877  *   how much time was spent transmitting).
2878  *
2879  * From "cck" and "ofdm" statistics (struct statistics_rx_phy), separately:
2880  *
2881  * false_alarm_cnt
2882  *   Signal locks abandoned early (before phy-level header).
2883  *
2884  * plcp_err
2885  *   Signal locks abandoned late (during phy-level header).
2886  *
2887  * NOTE:  Both false_alarm_cnt and plcp_err increment monotonically from
2888  *        beacon to beacon, i.e. each value is an accumulation of all errors
2889  *        before and including the latest beacon.  Values will wrap around to 0
2890  *        after counting up to 2^32 - 1.  Driver must differentiate vs.
2891  *        previous beacon's values to determine # false alarms in the current
2892  *        beacon period.
2893  *
2894  * Total number of false alarms = false_alarms + plcp_errs
2895  *
2896  * For OFDM, adjust the following table entries in struct iwl_sensitivity_cmd
2897  * (notice that the start points for OFDM are at or close to settings for
2898  * maximum sensitivity):
2899  *
2900  *                                             START  /  MIN  /  MAX
2901  *   HD_AUTO_CORR32_X1_TH_ADD_MIN_INDEX          90   /   85  /  120
2902  *   HD_AUTO_CORR32_X1_TH_ADD_MIN_MRC_INDEX     170   /  170  /  210
2903  *   HD_AUTO_CORR32_X4_TH_ADD_MIN_INDEX         105   /  105  /  140
2904  *   HD_AUTO_CORR32_X4_TH_ADD_MIN_MRC_INDEX     220   /  220  /  270
2905  *
2906  *   If actual rate of OFDM false alarms (+ plcp_errors) is too high
2907  *   (greater than 50 for each 204.8 msecs listening), reduce sensitivity
2908  *   by *adding* 1 to all 4 of the table entries above, up to the max for
2909  *   each entry.  Conversely, if false alarm rate is too low (less than 5
2910  *   for each 204.8 msecs listening), *subtract* 1 from each entry to
2911  *   increase sensitivity.
2912  *
2913  * For CCK sensitivity, keep track of the following:
2914  *
2915  *   1).  20-beacon history of maximum background noise, indicated by
2916  *        (beacon_silence_rssi_[abc] & 0x0FF00), units in dB, across the
2917  *        3 receivers.  For any given beacon, the "silence reference" is
2918  *        the maximum of last 60 samples (20 beacons * 3 receivers).
2919  *
2920  *   2).  10-beacon history of strongest signal level, as indicated
2921  *        by (beacon_energy_[abc] & 0x0FF00) >> 8, across the 3 receivers,
2922  *        i.e. the strength of the signal through the best receiver at the
2923  *        moment.  These measurements are "upside down", with lower values
2924  *        for stronger signals, so max energy will be *minimum* value.
2925  *
2926  *        Then for any given beacon, the driver must determine the *weakest*
2927  *        of the strongest signals; this is the minimum level that needs to be
2928  *        successfully detected, when using the best receiver at the moment.
2929  *        "Max cck energy" is the maximum (higher value means lower energy!)
2930  *        of the last 10 minima.  Once this is determined, driver must add
2931  *        a little margin by adding "6" to it.
2932  *
2933  *   3).  Number of consecutive beacon periods with too few false alarms.
2934  *        Reset this to 0 at the first beacon period that falls within the
2935  *        "good" range (5 to 50 false alarms per 204.8 milliseconds rx).
2936  *
2937  * Then, adjust the following CCK table entries in struct iwl_sensitivity_cmd
2938  * (notice that the start points for CCK are at maximum sensitivity):
2939  *
2940  *                                             START  /  MIN  /  MAX
2941  *   HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX         125   /  125  /  200
2942  *   HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX     200   /  200  /  400
2943  *   HD_MIN_ENERGY_CCK_DET_INDEX                100   /    0  /  100
2944  *
2945  *   If actual rate of CCK false alarms (+ plcp_errors) is too high
2946  *   (greater than 50 for each 204.8 msecs listening), method for reducing
2947  *   sensitivity is:
2948  *
2949  *   1)  *Add* 3 to value in HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX,
2950  *       up to max 400.
2951  *
2952  *   2)  If current value in HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX is < 160,
2953  *       sensitivity has been reduced a significant amount; bring it up to
2954  *       a moderate 161.  Otherwise, *add* 3, up to max 200.
2955  *
2956  *   3)  a)  If current value in HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX is > 160,
2957  *       sensitivity has been reduced only a moderate or small amount;
2958  *       *subtract* 2 from value in HD_MIN_ENERGY_CCK_DET_INDEX,
2959  *       down to min 0.  Otherwise (if gain has been significantly reduced),
2960  *       don't change the HD_MIN_ENERGY_CCK_DET_INDEX value.
2961  *
2962  *       b)  Save a snapshot of the "silence reference".
2963  *
2964  *   If actual rate of CCK false alarms (+ plcp_errors) is too low
2965  *   (less than 5 for each 204.8 msecs listening), method for increasing
2966  *   sensitivity is used only if:
2967  *
2968  *   1a)  Previous beacon did not have too many false alarms
2969  *   1b)  AND difference between previous "silence reference" and current
2970  *        "silence reference" (prev - current) is 2 or more,
2971  *   OR 2)  100 or more consecutive beacon periods have had rate of
2972  *          less than 5 false alarms per 204.8 milliseconds rx time.
2973  *
2974  *   Method for increasing sensitivity:
2975  *
2976  *   1)  *Subtract* 3 from value in HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX,
2977  *       down to min 125.
2978  *
2979  *   2)  *Subtract* 3 from value in HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX,
2980  *       down to min 200.
2981  *
2982  *   3)  *Add* 2 to value in HD_MIN_ENERGY_CCK_DET_INDEX, up to max 100.
2983  *
2984  *   If actual rate of CCK false alarms (+ plcp_errors) is within good range
2985  *   (between 5 and 50 for each 204.8 msecs listening):
2986  *
2987  *   1)  Save a snapshot of the silence reference.
2988  *
2989  *   2)  If previous beacon had too many CCK false alarms (+ plcp_errors),
2990  *       give some extra margin to energy threshold by *subtracting* 8
2991  *       from value in HD_MIN_ENERGY_CCK_DET_INDEX.
2992  *
2993  *   For all cases (too few, too many, good range), make sure that the CCK
2994  *   detection threshold (energy) is below the energy level for robust
2995  *   detection over the past 10 beacon periods, the "Max cck energy".
2996  *   Lower values mean higher energy; this means making sure that the value
2997  *   in HD_MIN_ENERGY_CCK_DET_INDEX is at or *above* "Max cck energy".
2998  *
2999  */
3000
3001 /*
3002  * Table entries in SENSITIVITY_CMD (struct iwl_sensitivity_cmd)
3003  */
3004 #define HD_TABLE_SIZE  (11)     /* number of entries */
3005 #define HD_MIN_ENERGY_CCK_DET_INDEX                 (0) /* table indexes */
3006 #define HD_MIN_ENERGY_OFDM_DET_INDEX                (1)
3007 #define HD_AUTO_CORR32_X1_TH_ADD_MIN_INDEX          (2)
3008 #define HD_AUTO_CORR32_X1_TH_ADD_MIN_MRC_INDEX      (3)
3009 #define HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX      (4)
3010 #define HD_AUTO_CORR32_X4_TH_ADD_MIN_INDEX          (5)
3011 #define HD_AUTO_CORR32_X4_TH_ADD_MIN_MRC_INDEX      (6)
3012 #define HD_BARKER_CORR_TH_ADD_MIN_INDEX             (7)
3013 #define HD_BARKER_CORR_TH_ADD_MIN_MRC_INDEX         (8)
3014 #define HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX          (9)
3015 #define HD_OFDM_ENERGY_TH_IN_INDEX                  (10)
3016
3017 /*
3018  * Additional table entries in enhance SENSITIVITY_CMD
3019  */
3020 #define HD_INA_NON_SQUARE_DET_OFDM_INDEX                (11)
3021 #define HD_INA_NON_SQUARE_DET_CCK_INDEX                 (12)
3022 #define HD_CORR_11_INSTEAD_OF_CORR_9_EN_INDEX           (13)
3023 #define HD_OFDM_NON_SQUARE_DET_SLOPE_MRC_INDEX          (14)
3024 #define HD_OFDM_NON_SQUARE_DET_INTERCEPT_MRC_INDEX      (15)
3025 #define HD_OFDM_NON_SQUARE_DET_SLOPE_INDEX              (16)
3026 #define HD_OFDM_NON_SQUARE_DET_INTERCEPT_INDEX          (17)
3027 #define HD_CCK_NON_SQUARE_DET_SLOPE_MRC_INDEX           (18)
3028 #define HD_CCK_NON_SQUARE_DET_INTERCEPT_MRC_INDEX       (19)
3029 #define HD_CCK_NON_SQUARE_DET_SLOPE_INDEX               (20)
3030 #define HD_CCK_NON_SQUARE_DET_INTERCEPT_INDEX           (21)
3031 #define HD_RESERVED                                     (22)
3032
3033 /* number of entries for enhanced tbl */
3034 #define ENHANCE_HD_TABLE_SIZE  (23)
3035
3036 /* number of additional entries for enhanced tbl */
3037 #define ENHANCE_HD_TABLE_ENTRIES  (ENHANCE_HD_TABLE_SIZE - HD_TABLE_SIZE)
3038
3039 #define HD_INA_NON_SQUARE_DET_OFDM_DATA                 cpu_to_le16(0)
3040 #define HD_INA_NON_SQUARE_DET_CCK_DATA                  cpu_to_le16(0)
3041 #define HD_CORR_11_INSTEAD_OF_CORR_9_EN_DATA            cpu_to_le16(0)
3042 #define HD_OFDM_NON_SQUARE_DET_SLOPE_MRC_DATA           cpu_to_le16(668)
3043 #define HD_OFDM_NON_SQUARE_DET_INTERCEPT_MRC_DATA       cpu_to_le16(4)
3044 #define HD_OFDM_NON_SQUARE_DET_SLOPE_DATA               cpu_to_le16(486)
3045 #define HD_OFDM_NON_SQUARE_DET_INTERCEPT_DATA           cpu_to_le16(37)
3046 #define HD_CCK_NON_SQUARE_DET_SLOPE_MRC_DATA            cpu_to_le16(853)
3047 #define HD_CCK_NON_SQUARE_DET_INTERCEPT_MRC_DATA        cpu_to_le16(4)
3048 #define HD_CCK_NON_SQUARE_DET_SLOPE_DATA                cpu_to_le16(476)
3049 #define HD_CCK_NON_SQUARE_DET_INTERCEPT_DATA            cpu_to_le16(99)
3050
3051
3052 /* Control field in struct iwl_sensitivity_cmd */
3053 #define SENSITIVITY_CMD_CONTROL_DEFAULT_TABLE   cpu_to_le16(0)
3054 #define SENSITIVITY_CMD_CONTROL_WORK_TABLE      cpu_to_le16(1)
3055
3056 /**
3057  * struct iwl_sensitivity_cmd
3058  * @control:  (1) updates working table, (0) updates default table
3059  * @table:  energy threshold values, use HD_* as index into table
3060  *
3061  * Always use "1" in "control" to update uCode's working table and DSP.
3062  */
3063 struct iwl_sensitivity_cmd {
3064         __le16 control;                 /* always use "1" */
3065         __le16 table[HD_TABLE_SIZE];    /* use HD_* as index */
3066 } __packed;
3067
3068 /*
3069  *
3070  */
3071 struct iwl_enhance_sensitivity_cmd {
3072         __le16 control;                 /* always use "1" */
3073         __le16 enhance_table[ENHANCE_HD_TABLE_SIZE];    /* use HD_* as index */
3074 } __packed;
3075
3076
3077 /**
3078  * REPLY_PHY_CALIBRATION_CMD = 0xb0 (command, has simple generic response)
3079  *
3080  * This command sets the relative gains of agn device's 3 radio receiver chains.
3081  *
3082  * After the first association, driver should accumulate signal and noise
3083  * statistics from the STATISTICS_NOTIFICATIONs that follow the first 20
3084  * beacons from the associated network (don't collect statistics that come
3085  * in from scanning, or any other non-network source).
3086  *
3087  * DISCONNECTED ANTENNA:
3088  *
3089  * Driver should determine which antennas are actually connected, by comparing
3090  * average beacon signal levels for the 3 Rx chains.  Accumulate (add) the
3091  * following values over 20 beacons, one accumulator for each of the chains
3092  * a/b/c, from struct statistics_rx_non_phy:
3093  *
3094  * beacon_rssi_[abc] & 0x0FF (unsigned, units in dB)
3095  *
3096  * Find the strongest signal from among a/b/c.  Compare the other two to the
3097  * strongest.  If any signal is more than 15 dB (times 20, unless you
3098  * divide the accumulated values by 20) below the strongest, the driver
3099  * considers that antenna to be disconnected, and should not try to use that
3100  * antenna/chain for Rx or Tx.  If both A and B seem to be disconnected,
3101  * driver should declare the stronger one as connected, and attempt to use it
3102  * (A and B are the only 2 Tx chains!).
3103  *
3104  *
3105  * RX BALANCE:
3106  *
3107  * Driver should balance the 3 receivers (but just the ones that are connected
3108  * to antennas, see above) for gain, by comparing the average signal levels
3109  * detected during the silence after each beacon (background noise).
3110  * Accumulate (add) the following values over 20 beacons, one accumulator for
3111  * each of the chains a/b/c, from struct statistics_rx_non_phy:
3112  *
3113  * beacon_silence_rssi_[abc] & 0x0FF (unsigned, units in dB)
3114  *
3115  * Find the weakest background noise level from among a/b/c.  This Rx chain
3116  * will be the reference, with 0 gain adjustment.  Attenuate other channels by
3117  * finding noise difference:
3118  *
3119  * (accum_noise[i] - accum_noise[reference]) / 30
3120  *
3121  * The "30" adjusts the dB in the 20 accumulated samples to units of 1.5 dB.
3122  * For use in diff_gain_[abc] fields of struct iwl_calibration_cmd, the
3123  * driver should limit the difference results to a range of 0-3 (0-4.5 dB),
3124  * and set bit 2 to indicate "reduce gain".  The value for the reference
3125  * (weakest) chain should be "0".
3126  *
3127  * diff_gain_[abc] bit fields:
3128  *   2: (1) reduce gain, (0) increase gain
3129  * 1-0: amount of gain, units of 1.5 dB
3130  */
3131
3132 /* Phy calibration command for series */
3133 /* The default calibrate table size if not specified by firmware */
3134 #define IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE     18
3135 enum {
3136         IWL_PHY_CALIBRATE_DIFF_GAIN_CMD         = 7,
3137         IWL_PHY_CALIBRATE_DC_CMD                = 8,
3138         IWL_PHY_CALIBRATE_LO_CMD                = 9,
3139         IWL_PHY_CALIBRATE_TX_IQ_CMD             = 11,
3140         IWL_PHY_CALIBRATE_CRYSTAL_FRQ_CMD       = 15,
3141         IWL_PHY_CALIBRATE_BASE_BAND_CMD         = 16,
3142         IWL_PHY_CALIBRATE_TX_IQ_PERD_CMD        = 17,
3143         IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD       = 18,
3144         IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE = 19,
3145 };
3146
3147 #define IWL_MAX_PHY_CALIBRATE_TBL_SIZE          (253)
3148
3149 #define IWL_CALIB_INIT_CFG_ALL  cpu_to_le32(0xffffffff)
3150
3151 /* This enum defines the bitmap of various calibrations to enable in both
3152  * init ucode and runtime ucode through CALIBRATION_CFG_CMD.
3153  */
3154 enum iwl_ucode_calib_cfg {
3155         IWL_CALIB_CFG_RX_BB_IDX,
3156         IWL_CALIB_CFG_DC_IDX,
3157         IWL_CALIB_CFG_TX_IQ_IDX,
3158         IWL_CALIB_CFG_RX_IQ_IDX,
3159         IWL_CALIB_CFG_NOISE_IDX,
3160         IWL_CALIB_CFG_CRYSTAL_IDX,
3161         IWL_CALIB_CFG_TEMPERATURE_IDX,
3162         IWL_CALIB_CFG_PAPD_IDX,
3163 };
3164
3165
3166 struct iwl_calib_cfg_elmnt_s {
3167         __le32 is_enable;
3168         __le32 start;
3169         __le32 send_res;
3170         __le32 apply_res;
3171         __le32 reserved;
3172 } __packed;
3173
3174 struct iwl_calib_cfg_status_s {
3175         struct iwl_calib_cfg_elmnt_s once;
3176         struct iwl_calib_cfg_elmnt_s perd;
3177         __le32 flags;
3178 } __packed;
3179
3180 struct iwl_calib_cfg_cmd {
3181         struct iwl_calib_cfg_status_s ucd_calib_cfg;
3182         struct iwl_calib_cfg_status_s drv_calib_cfg;
3183         __le32 reserved1;
3184 } __packed;
3185
3186 struct iwl_calib_hdr {
3187         u8 op_code;
3188         u8 first_group;
3189         u8 groups_num;
3190         u8 data_valid;
3191 } __packed;
3192
3193 struct iwl_calib_cmd {
3194         struct iwl_calib_hdr hdr;
3195         u8 data[0];
3196 } __packed;
3197
3198 /* IWL_PHY_CALIBRATE_DIFF_GAIN_CMD (7) */
3199 struct iwl_calib_diff_gain_cmd {
3200         struct iwl_calib_hdr hdr;
3201         s8 diff_gain_a;         /* see above */
3202         s8 diff_gain_b;
3203         s8 diff_gain_c;
3204         u8 reserved1;
3205 } __packed;
3206
3207 struct iwl_calib_xtal_freq_cmd {
3208         struct iwl_calib_hdr hdr;
3209         u8 cap_pin1;
3210         u8 cap_pin2;
3211         u8 pad[2];
3212 } __packed;
3213
3214 #define DEFAULT_RADIO_SENSOR_OFFSET    2700
3215 struct iwl_calib_temperature_offset_cmd {
3216         struct iwl_calib_hdr hdr;
3217         s16 radio_sensor_offset;
3218         s16 reserved;
3219 } __packed;
3220
3221 /* IWL_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD */
3222 struct iwl_calib_chain_noise_reset_cmd {
3223         struct iwl_calib_hdr hdr;
3224         u8 data[0];
3225 };
3226
3227 /* IWL_PHY_CALIBRATE_CHAIN_NOISE_GAIN_CMD */
3228 struct iwl_calib_chain_noise_gain_cmd {
3229         struct iwl_calib_hdr hdr;
3230         u8 delta_gain_1;
3231         u8 delta_gain_2;
3232         u8 pad[2];
3233 } __packed;
3234
3235 /******************************************************************************
3236  * (12)
3237  * Miscellaneous Commands:
3238  *
3239  *****************************************************************************/
3240
3241 /*
3242  * LEDs Command & Response
3243  * REPLY_LEDS_CMD = 0x48 (command, has simple generic response)
3244  *
3245  * For each of 3 possible LEDs (Activity/Link/Tech, selected by "id" field),
3246  * this command turns it on or off, or sets up a periodic blinking cycle.
3247  */
3248 struct iwl_led_cmd {
3249         __le32 interval;        /* "interval" in uSec */
3250         u8 id;                  /* 1: Activity, 2: Link, 3: Tech */
3251         u8 off;                 /* # intervals off while blinking;
3252                                  * "0", with >0 "on" value, turns LED on */
3253         u8 on;                  /* # intervals on while blinking;
3254                                  * "0", regardless of "off", turns LED off */
3255         u8 reserved;
3256 } __packed;
3257
3258 /*
3259  * station priority table entries
3260  * also used as potential "events" value for both
3261  * COEX_MEDIUM_NOTIFICATION and COEX_EVENT_CMD
3262  */
3263
3264 /*
3265  * COEX events entry flag masks
3266  * RP - Requested Priority
3267  * WP - Win Medium Priority: priority assigned when the contention has been won
3268  */
3269 #define COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG        (0x1)
3270 #define COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG        (0x2)
3271 #define COEX_EVT_FLAG_DELAY_MEDIUM_FREE_NTFY_FLG  (0x4)
3272
3273 #define COEX_CU_UNASSOC_IDLE_RP               4
3274 #define COEX_CU_UNASSOC_MANUAL_SCAN_RP        4
3275 #define COEX_CU_UNASSOC_AUTO_SCAN_RP          4
3276 #define COEX_CU_CALIBRATION_RP                4
3277 #define COEX_CU_PERIODIC_CALIBRATION_RP       4
3278 #define COEX_CU_CONNECTION_ESTAB_RP           4
3279 #define COEX_CU_ASSOCIATED_IDLE_RP            4
3280 #define COEX_CU_ASSOC_MANUAL_SCAN_RP          4
3281 #define COEX_CU_ASSOC_AUTO_SCAN_RP            4
3282 #define COEX_CU_ASSOC_ACTIVE_LEVEL_RP         4
3283 #define COEX_CU_RF_ON_RP                      6
3284 #define COEX_CU_RF_OFF_RP                     4
3285 #define COEX_CU_STAND_ALONE_DEBUG_RP          6
3286 #define COEX_CU_IPAN_ASSOC_LEVEL_RP           4
3287 #define COEX_CU_RSRVD1_RP                     4
3288 #define COEX_CU_RSRVD2_RP                     4
3289
3290 #define COEX_CU_UNASSOC_IDLE_WP               3
3291 #define COEX_CU_UNASSOC_MANUAL_SCAN_WP        3
3292 #define COEX_CU_UNASSOC_AUTO_SCAN_WP          3
3293 #define COEX_CU_CALIBRATION_WP                3
3294 #define COEX_CU_PERIODIC_CALIBRATION_WP       3
3295 #define COEX_CU_CONNECTION_ESTAB_WP           3
3296 #define COEX_CU_ASSOCIATED_IDLE_WP            3
3297 #define COEX_CU_ASSOC_MANUAL_SCAN_WP          3
3298 #define COEX_CU_ASSOC_AUTO_SCAN_WP            3
3299 #define COEX_CU_ASSOC_ACTIVE_LEVEL_WP         3
3300 #define COEX_CU_RF_ON_WP                      3
3301 #define COEX_CU_RF_OFF_WP                     3
3302 #define COEX_CU_STAND_ALONE_DEBUG_WP          6
3303 #define COEX_CU_IPAN_ASSOC_LEVEL_WP           3
3304 #define COEX_CU_RSRVD1_WP                     3
3305 #define COEX_CU_RSRVD2_WP                     3
3306
3307 #define COEX_UNASSOC_IDLE_FLAGS                     0
3308 #define COEX_UNASSOC_MANUAL_SCAN_FLAGS          \
3309         (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG |   \
3310         COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG)
3311 #define COEX_UNASSOC_AUTO_SCAN_FLAGS            \
3312         (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG |   \
3313         COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG)
3314 #define COEX_CALIBRATION_FLAGS                  \
3315         (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG |   \
3316         COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG)
3317 #define COEX_PERIODIC_CALIBRATION_FLAGS             0
3318 /*
3319  * COEX_CONNECTION_ESTAB:
3320  * we need DELAY_MEDIUM_FREE_NTFY to let WiMAX disconnect from network.
3321  */
3322 #define COEX_CONNECTION_ESTAB_FLAGS             \
3323         (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG |   \
3324         COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG |    \
3325         COEX_EVT_FLAG_DELAY_MEDIUM_FREE_NTFY_FLG)
3326 #define COEX_ASSOCIATED_IDLE_FLAGS                  0
3327 #define COEX_ASSOC_MANUAL_SCAN_FLAGS            \
3328         (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG |   \
3329         COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG)
3330 #define COEX_ASSOC_AUTO_SCAN_FLAGS              \
3331         (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG |   \
3332          COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG)
3333 #define COEX_ASSOC_ACTIVE_LEVEL_FLAGS               0
3334 #define COEX_RF_ON_FLAGS                            0
3335 #define COEX_RF_OFF_FLAGS                           0
3336 #define COEX_STAND_ALONE_DEBUG_FLAGS            \
3337         (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG |   \
3338          COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG)
3339 #define COEX_IPAN_ASSOC_LEVEL_FLAGS             \
3340         (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG |   \
3341          COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG |   \
3342          COEX_EVT_FLAG_DELAY_MEDIUM_FREE_NTFY_FLG)
3343 #define COEX_RSRVD1_FLAGS                           0
3344 #define COEX_RSRVD2_FLAGS                           0
3345 /*
3346  * COEX_CU_RF_ON is the event wrapping all radio ownership.
3347  * We need DELAY_MEDIUM_FREE_NTFY to let WiMAX disconnect from network.
3348  */
3349 #define COEX_CU_RF_ON_FLAGS                     \
3350         (COEX_EVT_FLAG_MEDIUM_FREE_NTFY_FLG |   \
3351          COEX_EVT_FLAG_MEDIUM_ACTV_NTFY_FLG |   \
3352          COEX_EVT_FLAG_DELAY_MEDIUM_FREE_NTFY_FLG)
3353
3354
3355 enum {
3356         /* un-association part */
3357         COEX_UNASSOC_IDLE               = 0,
3358         COEX_UNASSOC_MANUAL_SCAN        = 1,
3359         COEX_UNASSOC_AUTO_SCAN          = 2,
3360         /* calibration */
3361         COEX_CALIBRATION                = 3,
3362         COEX_PERIODIC_CALIBRATION       = 4,
3363         /* connection */
3364         COEX_CONNECTION_ESTAB           = 5,
3365         /* association part */
3366         COEX_ASSOCIATED_IDLE            = 6,
3367         COEX_ASSOC_MANUAL_SCAN          = 7,
3368         COEX_ASSOC_AUTO_SCAN            = 8,
3369         COEX_ASSOC_ACTIVE_LEVEL         = 9,
3370         /* RF ON/OFF */
3371         COEX_RF_ON                      = 10,
3372         COEX_RF_OFF                     = 11,
3373         COEX_STAND_ALONE_DEBUG          = 12,
3374         /* IPAN */
3375         COEX_IPAN_ASSOC_LEVEL           = 13,
3376         /* reserved */
3377         COEX_RSRVD1                     = 14,
3378         COEX_RSRVD2                     = 15,
3379         COEX_NUM_OF_EVENTS              = 16
3380 };
3381
3382 /*
3383  * Coexistence WIFI/WIMAX  Command
3384  * COEX_PRIORITY_TABLE_CMD = 0x5a
3385  *
3386  */
3387 struct iwl_wimax_coex_event_entry {
3388         u8 request_prio;
3389         u8 win_medium_prio;
3390         u8 reserved;
3391         u8 flags;
3392 } __packed;
3393
3394 /* COEX flag masks */
3395
3396 /* Station table is valid */
3397 #define COEX_FLAGS_STA_TABLE_VALID_MSK      (0x1)
3398 /* UnMask wake up src at unassociated sleep */
3399 #define COEX_FLAGS_UNASSOC_WA_UNMASK_MSK    (0x4)
3400 /* UnMask wake up src at associated sleep */
3401 #define COEX_FLAGS_ASSOC_WA_UNMASK_MSK      (0x8)
3402 /* Enable CoEx feature. */
3403 #define COEX_FLAGS_COEX_ENABLE_MSK          (0x80)
3404
3405 struct iwl_wimax_coex_cmd {
3406         u8 flags;
3407         u8 reserved[3];
3408         struct iwl_wimax_coex_event_entry sta_prio[COEX_NUM_OF_EVENTS];
3409 } __packed;
3410
3411 /*
3412  * Coexistence MEDIUM NOTIFICATION
3413  * COEX_MEDIUM_NOTIFICATION = 0x5b
3414  *
3415  * notification from uCode to host to indicate medium changes
3416  *
3417  */
3418 /*
3419  * status field
3420  * bit 0 - 2: medium status
3421  * bit 3: medium change indication
3422  * bit 4 - 31: reserved
3423  */
3424 /* status option values, (0 - 2 bits) */
3425 #define COEX_MEDIUM_BUSY        (0x0) /* radio belongs to WiMAX */
3426 #define COEX_MEDIUM_ACTIVE      (0x1) /* radio belongs to WiFi */
3427 #define COEX_MEDIUM_PRE_RELEASE (0x2) /* received radio release */
3428 #define COEX_MEDIUM_MSK         (0x7)
3429
3430 /* send notification status (1 bit) */
3431 #define COEX_MEDIUM_CHANGED     (0x8)
3432 #define COEX_MEDIUM_CHANGED_MSK (0x8)
3433 #define COEX_MEDIUM_SHIFT       (3)
3434
3435 struct iwl_coex_medium_notification {
3436         __le32 status;
3437         __le32 events;
3438 } __packed;
3439
3440 /*
3441  * Coexistence EVENT  Command
3442  * COEX_EVENT_CMD = 0x5c
3443  *
3444  * send from host to uCode for coex event request.
3445  */
3446 /* flags options */
3447 #define COEX_EVENT_REQUEST_MSK  (0x1)
3448
3449 struct iwl_coex_event_cmd {
3450         u8 flags;
3451         u8 event;
3452         __le16 reserved;
3453 } __packed;
3454
3455 struct iwl_coex_event_resp {
3456         __le32 status;
3457 } __packed;
3458
3459
3460 /******************************************************************************
3461  * Bluetooth Coexistence commands
3462  *
3463  *****************************************************************************/
3464
3465 /*
3466  * BT Status notification
3467  * REPLY_BT_COEX_PROFILE_NOTIF = 0xce
3468  */
3469 enum iwl_bt_coex_profile_traffic_load {
3470         IWL_BT_COEX_TRAFFIC_LOAD_NONE =         0,
3471         IWL_BT_COEX_TRAFFIC_LOAD_LOW =          1,
3472         IWL_BT_COEX_TRAFFIC_LOAD_HIGH =         2,
3473         IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS =   3,
3474 /*
3475  * There are no more even though below is a u8, the
3476  * indication from the BT device only has two bits.
3477  */
3478 };
3479
3480 #define BT_SESSION_ACTIVITY_1_UART_MSG          0x1
3481 #define BT_SESSION_ACTIVITY_2_UART_MSG          0x2
3482
3483 /* BT UART message - Share Part (BT -> WiFi) */
3484 #define BT_UART_MSG_FRAME1MSGTYPE_POS           (0)
3485 #define BT_UART_MSG_FRAME1MSGTYPE_MSK           \
3486                 (0x7 << BT_UART_MSG_FRAME1MSGTYPE_POS)
3487 #define BT_UART_MSG_FRAME1SSN_POS               (3)
3488 #define BT_UART_MSG_FRAME1SSN_MSK               \
3489                 (0x3 << BT_UART_MSG_FRAME1SSN_POS)
3490 #define BT_UART_MSG_FRAME1UPDATEREQ_POS         (5)
3491 #define BT_UART_MSG_FRAME1UPDATEREQ_MSK         \
3492                 (0x1 << BT_UART_MSG_FRAME1UPDATEREQ_POS)
3493 #define BT_UART_MSG_FRAME1RESERVED_POS          (6)
3494 #define BT_UART_MSG_FRAME1RESERVED_MSK          \
3495                 (0x3 << BT_UART_MSG_FRAME1RESERVED_POS)
3496
3497 #define BT_UART_MSG_FRAME2OPENCONNECTIONS_POS   (0)
3498 #define BT_UART_MSG_FRAME2OPENCONNECTIONS_MSK   \
3499                 (0x3 << BT_UART_MSG_FRAME2OPENCONNECTIONS_POS)
3500 #define BT_UART_MSG_FRAME2TRAFFICLOAD_POS       (2)
3501 #define BT_UART_MSG_FRAME2TRAFFICLOAD_MSK       \
3502                 (0x3 << BT_UART_MSG_FRAME2TRAFFICLOAD_POS)
3503 #define BT_UART_MSG_FRAME2CHLSEQN_POS           (4)
3504 #define BT_UART_MSG_FRAME2CHLSEQN_MSK           \
3505                 (0x1 << BT_UART_MSG_FRAME2CHLSEQN_POS)
3506 #define BT_UART_MSG_FRAME2INBAND_POS            (5)
3507 #define BT_UART_MSG_FRAME2INBAND_MSK            \
3508                 (0x1 << BT_UART_MSG_FRAME2INBAND_POS)
3509 #define BT_UART_MSG_FRAME2RESERVED_POS          (6)
3510 #define BT_UART_MSG_FRAME2RESERVED_MSK          \
3511                 (0x3 << BT_UART_MSG_FRAME2RESERVED_POS)
3512
3513 #define BT_UART_MSG_FRAME3SCOESCO_POS           (0)
3514 #define BT_UART_MSG_FRAME3SCOESCO_MSK           \
3515                 (0x1 << BT_UART_MSG_FRAME3SCOESCO_POS)
3516 #define BT_UART_MSG_FRAME3SNIFF_POS             (1)
3517 #define BT_UART_MSG_FRAME3SNIFF_MSK             \
3518                 (0x1 << BT_UART_MSG_FRAME3SNIFF_POS)
3519 #define BT_UART_MSG_FRAME3A2DP_POS              (2)
3520 #define BT_UART_MSG_FRAME3A2DP_MSK              \
3521                 (0x1 << BT_UART_MSG_FRAME3A2DP_POS)
3522 #define BT_UART_MSG_FRAME3ACL_POS               (3)
3523 #define BT_UART_MSG_FRAME3ACL_MSK               \
3524                 (0x1 << BT_UART_MSG_FRAME3ACL_POS)
3525 #define BT_UART_MSG_FRAME3MASTER_POS            (4)
3526 #define BT_UART_MSG_FRAME3MASTER_MSK            \
3527                 (0x1 << BT_UART_MSG_FRAME3MASTER_POS)
3528 #define BT_UART_MSG_FRAME3OBEX_POS              (5)
3529 #define BT_UART_MSG_FRAME3OBEX_MSK              \
3530                 (0x1 << BT_UART_MSG_FRAME3OBEX_POS)
3531 #define BT_UART_MSG_FRAME3RESERVED_POS          (6)
3532 #define BT_UART_MSG_FRAME3RESERVED_MSK          \
3533                 (0x3 << BT_UART_MSG_FRAME3RESERVED_POS)
3534
3535 #define BT_UART_MSG_FRAME4IDLEDURATION_POS      (0)
3536 #define BT_UART_MSG_FRAME4IDLEDURATION_MSK      \
3537                 (0x3F << BT_UART_MSG_FRAME4IDLEDURATION_POS)
3538 #define BT_UART_MSG_FRAME4RESERVED_POS          (6)
3539 #define BT_UART_MSG_FRAME4RESERVED_MSK          \
3540                 (0x3 << BT_UART_MSG_FRAME4RESERVED_POS)
3541
3542 #define BT_UART_MSG_FRAME5TXACTIVITY_POS        (0)
3543 #define BT_UART_MSG_FRAME5TXACTIVITY_MSK        \
3544                 (0x3 << BT_UART_MSG_FRAME5TXACTIVITY_POS)
3545 #define BT_UART_MSG_FRAME5RXACTIVITY_POS        (2)
3546 #define BT_UART_MSG_FRAME5RXACTIVITY_MSK        \
3547                 (0x3 << BT_UART_MSG_FRAME5RXACTIVITY_POS)
3548 #define BT_UART_MSG_FRAME5ESCORETRANSMIT_POS    (4)
3549 #define BT_UART_MSG_FRAME5ESCORETRANSMIT_MSK    \
3550                 (0x3 << BT_UART_MSG_FRAME5ESCORETRANSMIT_POS)
3551 #define BT_UART_MSG_FRAME5RESERVED_POS          (6)
3552 #define BT_UART_MSG_FRAME5RESERVED_MSK          \
3553                 (0x3 << BT_UART_MSG_FRAME5RESERVED_POS)
3554
3555 #define BT_UART_MSG_FRAME6SNIFFINTERVAL_POS     (0)
3556 #define BT_UART_MSG_FRAME6SNIFFINTERVAL_MSK     \
3557                 (0x1F << BT_UART_MSG_FRAME6SNIFFINTERVAL_POS)
3558 #define BT_UART_MSG_FRAME6DISCOVERABLE_POS      (5)
3559 #define BT_UART_MSG_FRAME6DISCOVERABLE_MSK      \
3560                 (0x1 << BT_UART_MSG_FRAME6DISCOVERABLE_POS)
3561 #define BT_UART_MSG_FRAME6RESERVED_POS          (6)
3562 #define BT_UART_MSG_FRAME6RESERVED_MSK          \
3563                 (0x3 << BT_UART_MSG_FRAME6RESERVED_POS)
3564
3565 #define BT_UART_MSG_FRAME7SNIFFACTIVITY_POS     (0)
3566 #define BT_UART_MSG_FRAME7SNIFFACTIVITY_MSK     \
3567                 (0x7 << BT_UART_MSG_FRAME7SNIFFACTIVITY_POS)
3568 #define BT_UART_MSG_FRAME7PAGE_POS              (3)
3569 #define BT_UART_MSG_FRAME7PAGE_MSK              \
3570                 (0x1 << BT_UART_MSG_FRAME7PAGE_POS)
3571 #define BT_UART_MSG_FRAME7INQUIRY_POS           (4)
3572 #define BT_UART_MSG_FRAME7INQUIRY_MSK           \
3573                 (0x1 << BT_UART_MSG_FRAME7INQUIRY_POS)
3574 #define BT_UART_MSG_FRAME7CONNECTABLE_POS       (5)
3575 #define BT_UART_MSG_FRAME7CONNECTABLE_MSK       \
3576                 (0x1 << BT_UART_MSG_FRAME7CONNECTABLE_POS)
3577 #define BT_UART_MSG_FRAME7RESERVED_POS          (6)
3578 #define BT_UART_MSG_FRAME7RESERVED_MSK          \
3579                 (0x3 << BT_UART_MSG_FRAME7RESERVED_POS)
3580
3581 /* BT Session Activity 2 UART message (BT -> WiFi) */
3582 #define BT_UART_MSG_2_FRAME1RESERVED1_POS       (5)
3583 #define BT_UART_MSG_2_FRAME1RESERVED1_MSK       \
3584                 (0x1<<BT_UART_MSG_2_FRAME1RESERVED1_POS)
3585 #define BT_UART_MSG_2_FRAME1RESERVED2_POS       (6)
3586 #define BT_UART_MSG_2_FRAME1RESERVED2_MSK       \
3587                 (0x3<<BT_UART_MSG_2_FRAME1RESERVED2_POS)
3588
3589 #define BT_UART_MSG_2_FRAME2AGGTRAFFICLOAD_POS  (0)
3590 #define BT_UART_MSG_2_FRAME2AGGTRAFFICLOAD_MSK  \
3591                 (0x3F<<BT_UART_MSG_2_FRAME2AGGTRAFFICLOAD_POS)
3592 #define BT_UART_MSG_2_FRAME2RESERVED_POS        (6)
3593 #define BT_UART_MSG_2_FRAME2RESERVED_MSK        \
3594                 (0x3<<BT_UART_MSG_2_FRAME2RESERVED_POS)
3595
3596 #define BT_UART_MSG_2_FRAME3BRLASTTXPOWER_POS   (0)
3597 #define BT_UART_MSG_2_FRAME3BRLASTTXPOWER_MSK   \
3598                 (0xF<<BT_UART_MSG_2_FRAME3BRLASTTXPOWER_POS)
3599 #define BT_UART_MSG_2_FRAME3INQPAGESRMODE_POS   (4)
3600 #define BT_UART_MSG_2_FRAME3INQPAGESRMODE_MSK   \
3601                 (0x1<<BT_UART_MSG_2_FRAME3INQPAGESRMODE_POS)
3602 #define BT_UART_MSG_2_FRAME3LEMASTER_POS        (5)
3603 #define BT_UART_MSG_2_FRAME3LEMASTER_MSK        \
3604                 (0x1<<BT_UART_MSG_2_FRAME3LEMASTER_POS)
3605 #define BT_UART_MSG_2_FRAME3RESERVED_POS        (6)
3606 #define BT_UART_MSG_2_FRAME3RESERVED_MSK        \
3607                 (0x3<<BT_UART_MSG_2_FRAME3RESERVED_POS)
3608
3609 #define BT_UART_MSG_2_FRAME4LELASTTXPOWER_POS   (0)
3610 #define BT_UART_MSG_2_FRAME4LELASTTXPOWER_MSK   \
3611                 (0xF<<BT_UART_MSG_2_FRAME4LELASTTXPOWER_POS)
3612 #define BT_UART_MSG_2_FRAME4NUMLECONN_POS       (4)
3613 #define BT_UART_MSG_2_FRAME4NUMLECONN_MSK       \
3614                 (0x3<<BT_UART_MSG_2_FRAME4NUMLECONN_POS)
3615 #define BT_UART_MSG_2_FRAME4RESERVED_POS        (6)
3616 #define BT_UART_MSG_2_FRAME4RESERVED_MSK        \
3617                 (0x3<<BT_UART_MSG_2_FRAME4RESERVED_POS)
3618
3619 #define BT_UART_MSG_2_FRAME5BTMINRSSI_POS       (0)
3620 #define BT_UART_MSG_2_FRAME5BTMINRSSI_MSK       \
3621                 (0xF<<BT_UART_MSG_2_FRAME5BTMINRSSI_POS)
3622 #define BT_UART_MSG_2_FRAME5LESCANINITMODE_POS  (4)
3623 #define BT_UART_MSG_2_FRAME5LESCANINITMODE_MSK  \
3624                 (0x1<<BT_UART_MSG_2_FRAME5LESCANINITMODE_POS)
3625 #define BT_UART_MSG_2_FRAME5LEADVERMODE_POS     (5)
3626 #define BT_UART_MSG_2_FRAME5LEADVERMODE_MSK     \
3627                 (0x1<<BT_UART_MSG_2_FRAME5LEADVERMODE_POS)
3628 #define BT_UART_MSG_2_FRAME5RESERVED_POS        (6)
3629 #define BT_UART_MSG_2_FRAME5RESERVED_MSK        \
3630                 (0x3<<BT_UART_MSG_2_FRAME5RESERVED_POS)
3631
3632 #define BT_UART_MSG_2_FRAME6LECONNINTERVAL_POS  (0)
3633 #define BT_UART_MSG_2_FRAME6LECONNINTERVAL_MSK  \
3634                 (0x1F<<BT_UART_MSG_2_FRAME6LECONNINTERVAL_POS)
3635 #define BT_UART_MSG_2_FRAME6RFU_POS             (5)
3636 #define BT_UART_MSG_2_FRAME6RFU_MSK             \
3637                 (0x1<<BT_UART_MSG_2_FRAME6RFU_POS)
3638 #define BT_UART_MSG_2_FRAME6RESERVED_POS        (6)
3639 #define BT_UART_MSG_2_FRAME6RESERVED_MSK        \
3640                 (0x3<<BT_UART_MSG_2_FRAME6RESERVED_POS)
3641
3642 #define BT_UART_MSG_2_FRAME7LECONNSLAVELAT_POS  (0)
3643 #define BT_UART_MSG_2_FRAME7LECONNSLAVELAT_MSK  \
3644                 (0x7<<BT_UART_MSG_2_FRAME7LECONNSLAVELAT_POS)
3645 #define BT_UART_MSG_2_FRAME7LEPROFILE1_POS      (3)
3646 #define BT_UART_MSG_2_FRAME7LEPROFILE1_MSK      \
3647                 (0x1<<BT_UART_MSG_2_FRAME7LEPROFILE1_POS)
3648 #define BT_UART_MSG_2_FRAME7LEPROFILE2_POS      (4)
3649 #define BT_UART_MSG_2_FRAME7LEPROFILE2_MSK      \
3650                 (0x1<<BT_UART_MSG_2_FRAME7LEPROFILE2_POS)
3651 #define BT_UART_MSG_2_FRAME7LEPROFILEOTHER_POS  (5)
3652 #define BT_UART_MSG_2_FRAME7LEPROFILEOTHER_MSK  \
3653                 (0x1<<BT_UART_MSG_2_FRAME7LEPROFILEOTHER_POS)
3654 #define BT_UART_MSG_2_FRAME7RESERVED_POS        (6)
3655 #define BT_UART_MSG_2_FRAME7RESERVED_MSK        \
3656                 (0x3<<BT_UART_MSG_2_FRAME7RESERVED_POS)
3657
3658
3659 struct iwl_bt_uart_msg {
3660         u8 header;
3661         u8 frame1;
3662         u8 frame2;
3663         u8 frame3;
3664         u8 frame4;
3665         u8 frame5;
3666         u8 frame6;
3667         u8 frame7;
3668 } __attribute__((packed));
3669
3670 struct iwl_bt_coex_profile_notif {
3671         struct iwl_bt_uart_msg last_bt_uart_msg;
3672         u8 bt_status; /* 0 - off, 1 - on */
3673         u8 bt_traffic_load; /* 0 .. 3? */
3674         u8 bt_ci_compliance; /* 0 - not complied, 1 - complied */
3675         u8 reserved;
3676 } __attribute__((packed));
3677
3678 #define IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS 0
3679 #define IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_MSK 0x1
3680 #define IWL_BT_COEX_PRIO_TBL_PRIO_POS           1
3681 #define IWL_BT_COEX_PRIO_TBL_PRIO_MASK          0x0e
3682 #define IWL_BT_COEX_PRIO_TBL_RESERVED_POS       4
3683 #define IWL_BT_COEX_PRIO_TBL_RESERVED_MASK      0xf0
3684 #define IWL_BT_COEX_PRIO_TBL_PRIO_SHIFT         1
3685
3686 /*
3687  * BT Coexistence Priority table
3688  * REPLY_BT_COEX_PRIO_TABLE = 0xcc
3689  */
3690 enum bt_coex_prio_table_events {
3691         BT_COEX_PRIO_TBL_EVT_INIT_CALIB1 = 0,
3692         BT_COEX_PRIO_TBL_EVT_INIT_CALIB2 = 1,
3693         BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_LOW1 = 2,
3694         BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_LOW2 = 3, /* DC calib */
3695         BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_HIGH1 = 4,
3696         BT_COEX_PRIO_TBL_EVT_PERIODIC_CALIB_HIGH2 = 5,
3697         BT_COEX_PRIO_TBL_EVT_DTIM = 6,
3698         BT_COEX_PRIO_TBL_EVT_SCAN52 = 7,
3699         BT_COEX_PRIO_TBL_EVT_SCAN24 = 8,
3700         BT_COEX_PRIO_TBL_EVT_RESERVED0 = 9,
3701         BT_COEX_PRIO_TBL_EVT_RESERVED1 = 10,
3702         BT_COEX_PRIO_TBL_EVT_RESERVED2 = 11,
3703         BT_COEX_PRIO_TBL_EVT_RESERVED3 = 12,
3704         BT_COEX_PRIO_TBL_EVT_RESERVED4 = 13,
3705         BT_COEX_PRIO_TBL_EVT_RESERVED5 = 14,
3706         BT_COEX_PRIO_TBL_EVT_RESERVED6 = 15,
3707         /* BT_COEX_PRIO_TBL_EVT_MAX should always be last */
3708         BT_COEX_PRIO_TBL_EVT_MAX,
3709 };
3710
3711 enum bt_coex_prio_table_priorities {
3712         BT_COEX_PRIO_TBL_DISABLED = 0,
3713         BT_COEX_PRIO_TBL_PRIO_LOW = 1,
3714         BT_COEX_PRIO_TBL_PRIO_HIGH = 2,
3715         BT_COEX_PRIO_TBL_PRIO_BYPASS = 3,
3716         BT_COEX_PRIO_TBL_PRIO_COEX_OFF = 4,
3717         BT_COEX_PRIO_TBL_PRIO_COEX_ON = 5,
3718         BT_COEX_PRIO_TBL_PRIO_RSRVD1 = 6,
3719         BT_COEX_PRIO_TBL_PRIO_RSRVD2 = 7,
3720         BT_COEX_PRIO_TBL_MAX,
3721 };
3722
3723 struct iwl_bt_coex_prio_table_cmd {
3724         u8 prio_tbl[BT_COEX_PRIO_TBL_EVT_MAX];
3725 } __attribute__((packed));
3726
3727 #define IWL_BT_COEX_ENV_CLOSE   0
3728 #define IWL_BT_COEX_ENV_OPEN    1
3729 /*
3730  * BT Protection Envelope
3731  * REPLY_BT_COEX_PROT_ENV = 0xcd
3732  */
3733 struct iwl_bt_coex_prot_env_cmd {
3734         u8 action; /* 0 = closed, 1 = open */
3735         u8 type; /* 0 .. 15 */
3736         u8 reserved[2];
3737 } __attribute__((packed));
3738
3739 /******************************************************************************
3740  * (13)
3741  * Union of all expected notifications/responses:
3742  *
3743  *****************************************************************************/
3744
3745 struct iwl_rx_packet {
3746         /*
3747          * The first 4 bytes of the RX frame header contain both the RX frame
3748          * size and some flags.
3749          * Bit fields:
3750          * 31:    flag flush RB request
3751          * 30:    flag ignore TC (terminal counter) request
3752          * 29:    flag fast IRQ request
3753          * 28-14: Reserved
3754          * 13-00: RX frame size
3755          */
3756         __le32 len_n_flags;
3757         struct iwl_cmd_header hdr;
3758         union {
3759                 struct iwl_alive_resp alive_frame;
3760                 struct iwl_spectrum_notification spectrum_notif;
3761                 struct iwl_csa_notification csa_notif;
3762                 struct iwl_error_resp err_resp;
3763                 struct iwl_card_state_notif card_state_notif;
3764                 struct iwl_add_sta_resp add_sta;
3765                 struct iwl_rem_sta_resp rem_sta;
3766                 struct iwl_sleep_notification sleep_notif;
3767                 struct iwl_spectrum_resp spectrum;
3768                 struct iwl_notif_statistics stats;
3769                 struct iwl_bt_notif_statistics stats_bt;
3770                 struct iwl_compressed_ba_resp compressed_ba;
3771                 struct iwl_missed_beacon_notif missed_beacon;
3772                 struct iwl_coex_medium_notification coex_medium_notif;
3773                 struct iwl_coex_event_resp coex_event;
3774                 struct iwl_bt_coex_profile_notif bt_coex_profile_notif;
3775                 __le32 status;
3776                 u8 raw[0];
3777         } u;
3778 } __packed;
3779
3780 int iwl_agn_check_rxon_cmd(struct iwl_priv *priv);
3781
3782 /*
3783  * REPLY_WIPAN_PARAMS = 0xb2 (Commands and Notification)
3784  */
3785
3786 /*
3787  * Minimum slot time in TU
3788  */
3789 #define IWL_MIN_SLOT_TIME       20
3790
3791 /**
3792  * struct iwl_wipan_slot
3793  * @width: Time in TU
3794  * @type:
3795  *   0 - BSS
3796  *   1 - PAN
3797  */
3798 struct iwl_wipan_slot {
3799         __le16 width;
3800         u8 type;
3801         u8 reserved;
3802 } __packed;
3803
3804 #define IWL_WIPAN_PARAMS_FLG_LEAVE_CHANNEL_CTS          BIT(1)  /* reserved */
3805 #define IWL_WIPAN_PARAMS_FLG_LEAVE_CHANNEL_QUIET        BIT(2)  /* reserved */
3806 #define IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE               BIT(3)  /* reserved */
3807 #define IWL_WIPAN_PARAMS_FLG_FILTER_BEACON_NOTIF        BIT(4)
3808 #define IWL_WIPAN_PARAMS_FLG_FULL_SLOTTED_MODE          BIT(5)
3809
3810 /**
3811  * struct iwl_wipan_params_cmd
3812  * @flags:
3813  *   bit0: reserved
3814  *   bit1: CP leave channel with CTS
3815  *   bit2: CP leave channel qith Quiet
3816  *   bit3: slotted mode
3817  *     1 - work in slotted mode
3818  *     0 - work in non slotted mode
3819  *   bit4: filter beacon notification
3820  *   bit5: full tx slotted mode. if this flag is set,
3821  *         uCode will perform leaving channel methods in context switch
3822  *         also when working in same channel mode
3823  * @num_slots: 1 - 10
3824  */
3825 struct iwl_wipan_params_cmd {
3826         __le16 flags;
3827         u8 reserved;
3828         u8 num_slots;
3829         struct iwl_wipan_slot slots[10];
3830 } __packed;
3831
3832 /*
3833  * REPLY_WIPAN_P2P_CHANNEL_SWITCH = 0xb9
3834  *
3835  * TODO: Figure out what this is used for,
3836  *       it can only switch between 2.4 GHz
3837  *       channels!!
3838  */
3839
3840 struct iwl_wipan_p2p_channel_switch_cmd {
3841         __le16 channel;
3842         __le16 reserved;
3843 };
3844
3845 /*
3846  * REPLY_WIPAN_NOA_NOTIFICATION = 0xbc
3847  *
3848  * This is used by the device to notify us of the
3849  * NoA schedule it determined so we can forward it
3850  * to userspace for inclusion in probe responses.
3851  *
3852  * In beacons, the NoA schedule is simply appended
3853  * to the frame we give the device.
3854  */
3855
3856 struct iwl_wipan_noa_descriptor {
3857         u8 count;
3858         __le32 duration;
3859         __le32 interval;
3860         __le32 starttime;
3861 } __packed;
3862
3863 struct iwl_wipan_noa_attribute {
3864         u8 id;
3865         __le16 length;
3866         u8 index;
3867         u8 ct_window;
3868         struct iwl_wipan_noa_descriptor descr0, descr1;
3869         u8 reserved;
3870 } __packed;
3871
3872 struct iwl_wipan_noa_notification {
3873         u32 noa_active;
3874         struct iwl_wipan_noa_attribute noa_attribute;
3875 } __packed;
3876
3877 #endif                          /* __iwl_commands_h__ */