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