Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/holtmann/bluet...
[linux-2.6] / 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 - 2008 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  * James P. Ketrenos <ipw2100-admin@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 - 2008 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-4965-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 enum {
73         REPLY_ALIVE = 0x1,
74         REPLY_ERROR = 0x2,
75
76         /* RXON and QOS commands */
77         REPLY_RXON = 0x10,
78         REPLY_RXON_ASSOC = 0x11,
79         REPLY_QOS_PARAM = 0x13,
80         REPLY_RXON_TIMING = 0x14,
81
82         /* Multi-Station support */
83         REPLY_ADD_STA = 0x18,
84         REPLY_REMOVE_STA = 0x19,        /* not used */
85         REPLY_REMOVE_ALL_STA = 0x1a,    /* not used */
86
87         /* Security */
88         REPLY_WEPKEY = 0x20,
89
90         /* RX, TX, LEDs */
91         REPLY_TX = 0x1c,
92         REPLY_RATE_SCALE = 0x47,        /* 3945 only */
93         REPLY_LEDS_CMD = 0x48,
94         REPLY_TX_LINK_QUALITY_CMD = 0x4e, /* 4965 only */
95
96         /* WiMAX coexistence */
97         COEX_PRIORITY_TABLE_CMD = 0x5a, /*5000 only */
98         COEX_MEDIUM_NOTIFICATION = 0x5b,
99         COEX_EVENT_CMD = 0x5c,
100
101         /* Calibration */
102         CALIBRATION_CFG_CMD = 0x65,
103         CALIBRATION_RES_NOTIFICATION = 0x66,
104         CALIBRATION_COMPLETE_NOTIFICATION = 0x67,
105
106         /* 802.11h related */
107         RADAR_NOTIFICATION = 0x70,      /* not used */
108         REPLY_QUIET_CMD = 0x71,         /* not used */
109         REPLY_CHANNEL_SWITCH = 0x72,
110         CHANNEL_SWITCH_NOTIFICATION = 0x73,
111         REPLY_SPECTRUM_MEASUREMENT_CMD = 0x74,
112         SPECTRUM_MEASURE_NOTIFICATION = 0x75,
113
114         /* Power Management */
115         POWER_TABLE_CMD = 0x77,
116         PM_SLEEP_NOTIFICATION = 0x7A,
117         PM_DEBUG_STATISTIC_NOTIFIC = 0x7B,
118
119         /* Scan commands and notifications */
120         REPLY_SCAN_CMD = 0x80,
121         REPLY_SCAN_ABORT_CMD = 0x81,
122         SCAN_START_NOTIFICATION = 0x82,
123         SCAN_RESULTS_NOTIFICATION = 0x83,
124         SCAN_COMPLETE_NOTIFICATION = 0x84,
125
126         /* IBSS/AP commands */
127         BEACON_NOTIFICATION = 0x90,
128         REPLY_TX_BEACON = 0x91,
129         WHO_IS_AWAKE_NOTIFICATION = 0x94,       /* not used */
130
131         /* Miscellaneous commands */
132         QUIET_NOTIFICATION = 0x96,              /* not used */
133         REPLY_TX_PWR_TABLE_CMD = 0x97,
134         REPLY_TX_POWER_DBM_CMD = 0x98,
135         MEASURE_ABORT_NOTIFICATION = 0x99,      /* not used */
136
137         /* Bluetooth device coexistence config command */
138         REPLY_BT_CONFIG = 0x9b,
139
140         /* Statistics */
141         REPLY_STATISTICS_CMD = 0x9c,
142         STATISTICS_NOTIFICATION = 0x9d,
143
144         /* RF-KILL commands and notifications */
145         REPLY_CARD_STATE_CMD = 0xa0,
146         CARD_STATE_NOTIFICATION = 0xa1,
147
148         /* Missed beacons notification */
149         MISSED_BEACONS_NOTIFICATION = 0xa2,
150
151         REPLY_CT_KILL_CONFIG_CMD = 0xa4,
152         SENSITIVITY_CMD = 0xa8,
153         REPLY_PHY_CALIBRATION_CMD = 0xb0,
154         REPLY_RX_PHY_CMD = 0xc0,
155         REPLY_RX_MPDU_CMD = 0xc1,
156         REPLY_RX = 0xc3,
157         REPLY_COMPRESSED_BA = 0xc5,
158         REPLY_MAX = 0xff
159 };
160
161 /******************************************************************************
162  * (0)
163  * Commonly used structures and definitions:
164  * Command header, rate_n_flags, txpower
165  *
166  *****************************************************************************/
167
168 /* iwl_cmd_header flags value */
169 #define IWL_CMD_FAILED_MSK 0x40
170
171 #define SEQ_TO_QUEUE(s) (((s) >> 8) & 0x1f)
172 #define QUEUE_TO_SEQ(q) (((q) & 0x1f) << 8)
173 #define SEQ_TO_INDEX(s) ((s) & 0xff)
174 #define INDEX_TO_SEQ(i) ((i) & 0xff)
175 #define SEQ_HUGE_FRAME  __constant_cpu_to_le16(0x4000)
176 #define SEQ_RX_FRAME    __constant_cpu_to_le16(0x8000)
177
178 /**
179  * struct iwl_cmd_header
180  *
181  * This header format appears in the beginning of each command sent from the
182  * driver, and each response/notification received from uCode.
183  */
184 struct iwl_cmd_header {
185         u8 cmd;         /* Command ID:  REPLY_RXON, etc. */
186         u8 flags;       /* 0:5 reserved, 6 abort, 7 internal */
187         /*
188          * The driver sets up the sequence number to values of its choosing.
189          * uCode does not use this value, but passes it back to the driver
190          * when sending the response to each driver-originated command, so
191          * the driver can match the response to the command.  Since the values
192          * don't get used by uCode, the driver may set up an arbitrary format.
193          *
194          * There is one exception:  uCode sets bit 15 when it originates
195          * the response/notification, i.e. when the response/notification
196          * is not a direct response to a command sent by the driver.  For
197          * example, uCode issues REPLY_3945_RX when it sends a received frame
198          * to the driver; it is not a direct response to any driver command.
199          *
200          * The Linux driver uses the following format:
201          *
202          *  0:7         tfd index - position within TX queue
203          *  8:12        TX queue id
204          *  13          reserved
205          *  14          huge - driver sets this to indicate command is in the
206          *              'huge' storage at the end of the command buffers
207          *  15          unsolicited RX or uCode-originated notification
208          */
209         __le16 sequence;
210
211         /* command or response/notification data follows immediately */
212         u8 data[0];
213 } __attribute__ ((packed));
214
215 /**
216  * iwlagn rate_n_flags bit fields
217  *
218  * rate_n_flags format is used in following iwlagn commands:
219  *  REPLY_RX (response only)
220  *  REPLY_RX_MPDU (response only)
221  *  REPLY_TX (both command and response)
222  *  REPLY_TX_LINK_QUALITY_CMD
223  *
224  * High-throughput (HT) rate format for bits 7:0 (bit 8 must be "1"):
225  *  2-0:  0)   6 Mbps
226  *        1)  12 Mbps
227  *        2)  18 Mbps
228  *        3)  24 Mbps
229  *        4)  36 Mbps
230  *        5)  48 Mbps
231  *        6)  54 Mbps
232  *        7)  60 Mbps
233  *
234  *  4-3:  0)  Single stream (SISO)
235  *        1)  Dual stream (MIMO)
236  *        2)  Triple stream (MIMO)
237  *
238  *    5:  Value of 0x20 in bits 7:0 indicates 6 Mbps FAT duplicate data
239  *
240  * Legacy OFDM rate format for bits 7:0 (bit 8 must be "0", bit 9 "0"):
241  *  3-0:  0xD)   6 Mbps
242  *        0xF)   9 Mbps
243  *        0x5)  12 Mbps
244  *        0x7)  18 Mbps
245  *        0x9)  24 Mbps
246  *        0xB)  36 Mbps
247  *        0x1)  48 Mbps
248  *        0x3)  54 Mbps
249  *
250  * Legacy CCK rate format for bits 7:0 (bit 8 must be "0", bit 9 "1"):
251  *  3-0:   10)  1 Mbps
252  *         20)  2 Mbps
253  *         55)  5.5 Mbps
254  *        110)  11 Mbps
255  */
256 #define RATE_MCS_CODE_MSK 0x7
257 #define RATE_MCS_SPATIAL_POS 3
258 #define RATE_MCS_SPATIAL_MSK 0x18
259 #define RATE_MCS_HT_DUP_POS 5
260 #define RATE_MCS_HT_DUP_MSK 0x20
261
262 /* Bit 8: (1) HT format, (0) legacy format in bits 7:0 */
263 #define RATE_MCS_FLAGS_POS 8
264 #define RATE_MCS_HT_POS 8
265 #define RATE_MCS_HT_MSK 0x100
266
267 /* Bit 9: (1) CCK, (0) OFDM.  HT (bit 8) must be "0" for this bit to be valid */
268 #define RATE_MCS_CCK_POS 9
269 #define RATE_MCS_CCK_MSK 0x200
270
271 /* Bit 10: (1) Use Green Field preamble */
272 #define RATE_MCS_GF_POS 10
273 #define RATE_MCS_GF_MSK 0x400
274
275 /* Bit 11: (1) Use 40Mhz FAT chnl width, (0) use 20 MHz legacy chnl width */
276 #define RATE_MCS_FAT_POS 11
277 #define RATE_MCS_FAT_MSK 0x800
278
279 /* Bit 12: (1) Duplicate data on both 20MHz chnls.  FAT (bit 11) must be set. */
280 #define RATE_MCS_DUP_POS 12
281 #define RATE_MCS_DUP_MSK 0x1000
282
283 /* Bit 13: (1) Short guard interval (0.4 usec), (0) normal GI (0.8 usec) */
284 #define RATE_MCS_SGI_POS 13
285 #define RATE_MCS_SGI_MSK 0x2000
286
287 /**
288  * rate_n_flags Tx antenna masks
289  * 4965 has 2 transmitters
290  * 5100 has 1 transmitter B
291  * 5150 has 1 transmitter A
292  * 5300 has 3 transmitters
293  * 5350 has 3 transmitters
294  * bit14:16
295  */
296 #define RATE_MCS_ANT_POS      14
297 #define RATE_MCS_ANT_A_MSK    0x04000
298 #define RATE_MCS_ANT_B_MSK    0x08000
299 #define RATE_MCS_ANT_C_MSK    0x10000
300 #define RATE_MCS_ANT_ABC_MSK  0x1C000
301 #define RATE_ANT_NUM 3
302
303 #define POWER_TABLE_NUM_ENTRIES                 33
304 #define POWER_TABLE_NUM_HT_OFDM_ENTRIES         32
305 #define POWER_TABLE_CCK_ENTRY                   32
306
307 /**
308  * union iwl4965_tx_power_dual_stream
309  *
310  * Host format used for REPLY_TX_PWR_TABLE_CMD, REPLY_CHANNEL_SWITCH
311  * Use __le32 version (struct tx_power_dual_stream) when building command.
312  *
313  * Driver provides radio gain and DSP attenuation settings to device in pairs,
314  * one value for each transmitter chain.  The first value is for transmitter A,
315  * second for transmitter B.
316  *
317  * For SISO bit rates, both values in a pair should be identical.
318  * For MIMO rates, one value may be different from the other,
319  * in order to balance the Tx output between the two transmitters.
320  *
321  * See more details in doc for TXPOWER in iwl-4965-hw.h.
322  */
323 union iwl4965_tx_power_dual_stream {
324         struct {
325                 u8 radio_tx_gain[2];
326                 u8 dsp_predis_atten[2];
327         } s;
328         u32 dw;
329 };
330
331 /**
332  * struct tx_power_dual_stream
333  *
334  * Table entries in REPLY_TX_PWR_TABLE_CMD, REPLY_CHANNEL_SWITCH
335  *
336  * Same format as iwl_tx_power_dual_stream, but __le32
337  */
338 struct tx_power_dual_stream {
339         __le32 dw;
340 } __attribute__ ((packed));
341
342 /**
343  * struct iwl4965_tx_power_db
344  *
345  * Entire table within REPLY_TX_PWR_TABLE_CMD, REPLY_CHANNEL_SWITCH
346  */
347 struct iwl4965_tx_power_db {
348         struct tx_power_dual_stream power_tbl[POWER_TABLE_NUM_ENTRIES];
349 } __attribute__ ((packed));
350
351 /**
352  * Command REPLY_TX_POWER_DBM_CMD = 0x98
353  * struct iwl5000_tx_power_dbm_cmd
354  */
355 #define IWL50_TX_POWER_AUTO 0x7f
356 #define IWL50_TX_POWER_NO_CLOSED (0x1 << 6)
357
358 struct iwl5000_tx_power_dbm_cmd {
359         s8 global_lmt; /*in half-dBm (e.g. 30 = 15 dBm) */
360         u8 flags;
361         s8 srv_chan_lmt; /*in half-dBm (e.g. 30 = 15 dBm) */
362         u8 reserved;
363 } __attribute__ ((packed));
364
365 /******************************************************************************
366  * (0a)
367  * Alive and Error Commands & Responses:
368  *
369  *****************************************************************************/
370
371 #define UCODE_VALID_OK  __constant_cpu_to_le32(0x1)
372 #define INITIALIZE_SUBTYPE    (9)
373
374 /*
375  * ("Initialize") REPLY_ALIVE = 0x1 (response only, not a command)
376  *
377  * uCode issues this "initialize alive" notification once the initialization
378  * uCode image has completed its work, and is ready to load the runtime image.
379  * This is the *first* "alive" notification that the driver will receive after
380  * rebooting uCode; the "initialize" alive is indicated by subtype field == 9.
381  *
382  * See comments documenting "BSM" (bootstrap state machine).
383  *
384  * For 4965, this notification contains important calibration data for
385  * calculating txpower settings:
386  *
387  * 1)  Power supply voltage indication.  The voltage sensor outputs higher
388  *     values for lower voltage, and vice verse.
389  *
390  * 2)  Temperature measurement parameters, for each of two channel widths
391  *     (20 MHz and 40 MHz) supported by the radios.  Temperature sensing
392  *     is done via one of the receiver chains, and channel width influences
393  *     the results.
394  *
395  * 3)  Tx gain compensation to balance 4965's 2 Tx chains for MIMO operation,
396  *     for each of 5 frequency ranges.
397  */
398 struct iwl_init_alive_resp {
399         u8 ucode_minor;
400         u8 ucode_major;
401         __le16 reserved1;
402         u8 sw_rev[8];
403         u8 ver_type;
404         u8 ver_subtype;         /* "9" for initialize alive */
405         __le16 reserved2;
406         __le32 log_event_table_ptr;
407         __le32 error_event_table_ptr;
408         __le32 timestamp;
409         __le32 is_valid;
410
411         /* calibration values from "initialize" uCode */
412         __le32 voltage;         /* signed, higher value is lower voltage */
413         __le32 therm_r1[2];     /* signed, 1st for normal, 2nd for FAT channel*/
414         __le32 therm_r2[2];     /* signed */
415         __le32 therm_r3[2];     /* signed */
416         __le32 therm_r4[2];     /* signed */
417         __le32 tx_atten[5][2];  /* signed MIMO gain comp, 5 freq groups,
418                                  * 2 Tx chains */
419 } __attribute__ ((packed));
420
421
422 /**
423  * REPLY_ALIVE = 0x1 (response only, not a command)
424  *
425  * uCode issues this "alive" notification once the runtime image is ready
426  * to receive commands from the driver.  This is the *second* "alive"
427  * notification that the driver will receive after rebooting uCode;
428  * this "alive" is indicated by subtype field != 9.
429  *
430  * See comments documenting "BSM" (bootstrap state machine).
431  *
432  * This response includes two pointers to structures within the device's
433  * data SRAM (access via HBUS_TARG_MEM_* regs) that are useful for debugging:
434  *
435  * 1)  log_event_table_ptr indicates base of the event log.  This traces
436  *     a 256-entry history of uCode execution within a circular buffer.
437  *     Its header format is:
438  *
439  *      __le32 log_size;     log capacity (in number of entries)
440  *      __le32 type;         (1) timestamp with each entry, (0) no timestamp
441  *      __le32 wraps;        # times uCode has wrapped to top of circular buffer
442  *      __le32 write_index;  next circular buffer entry that uCode would fill
443  *
444  *     The header is followed by the circular buffer of log entries.  Entries
445  *     with timestamps have the following format:
446  *
447  *      __le32 event_id;     range 0 - 1500
448  *      __le32 timestamp;    low 32 bits of TSF (of network, if associated)
449  *      __le32 data;         event_id-specific data value
450  *
451  *     Entries without timestamps contain only event_id and data.
452  *
453  * 2)  error_event_table_ptr indicates base of the error log.  This contains
454  *     information about any uCode error that occurs.  For 4965, the format
455  *     of the error log is:
456  *
457  *      __le32 valid;        (nonzero) valid, (0) log is empty
458  *      __le32 error_id;     type of error
459  *      __le32 pc;           program counter
460  *      __le32 blink1;       branch link
461  *      __le32 blink2;       branch link
462  *      __le32 ilink1;       interrupt link
463  *      __le32 ilink2;       interrupt link
464  *      __le32 data1;        error-specific data
465  *      __le32 data2;        error-specific data
466  *      __le32 line;         source code line of error
467  *      __le32 bcon_time;    beacon timer
468  *      __le32 tsf_low;      network timestamp function timer
469  *      __le32 tsf_hi;       network timestamp function timer
470  *
471  * The Linux driver can print both logs to the system log when a uCode error
472  * occurs.
473  */
474 struct iwl_alive_resp {
475         u8 ucode_minor;
476         u8 ucode_major;
477         __le16 reserved1;
478         u8 sw_rev[8];
479         u8 ver_type;
480         u8 ver_subtype;                 /* not "9" for runtime alive */
481         __le16 reserved2;
482         __le32 log_event_table_ptr;     /* SRAM address for event log */
483         __le32 error_event_table_ptr;   /* SRAM address for error log */
484         __le32 timestamp;
485         __le32 is_valid;
486 } __attribute__ ((packed));
487
488
489
490 /*
491  * REPLY_ERROR = 0x2 (response only, not a command)
492  */
493 struct iwl_error_resp {
494         __le32 error_type;
495         u8 cmd_id;
496         u8 reserved1;
497         __le16 bad_cmd_seq_num;
498         __le32 error_info;
499         __le64 timestamp;
500 } __attribute__ ((packed));
501
502 /******************************************************************************
503  * (1)
504  * RXON Commands & Responses:
505  *
506  *****************************************************************************/
507
508 /*
509  * Rx config defines & structure
510  */
511 /* rx_config device types  */
512 enum {
513         RXON_DEV_TYPE_AP = 1,
514         RXON_DEV_TYPE_ESS = 3,
515         RXON_DEV_TYPE_IBSS = 4,
516         RXON_DEV_TYPE_SNIFFER = 6,
517 };
518
519
520 #define RXON_RX_CHAIN_DRIVER_FORCE_MSK          __constant_cpu_to_le16(0x1 << 0)
521 #define RXON_RX_CHAIN_VALID_MSK                 __constant_cpu_to_le16(0x7 << 1)
522 #define RXON_RX_CHAIN_VALID_POS                 (1)
523 #define RXON_RX_CHAIN_FORCE_SEL_MSK             __constant_cpu_to_le16(0x7 << 4)
524 #define RXON_RX_CHAIN_FORCE_SEL_POS             (4)
525 #define RXON_RX_CHAIN_FORCE_MIMO_SEL_MSK        __constant_cpu_to_le16(0x7 << 7)
526 #define RXON_RX_CHAIN_FORCE_MIMO_SEL_POS        (7)
527 #define RXON_RX_CHAIN_CNT_MSK                   __constant_cpu_to_le16(0x3 << 10)
528 #define RXON_RX_CHAIN_CNT_POS                   (10)
529 #define RXON_RX_CHAIN_MIMO_CNT_MSK              __constant_cpu_to_le16(0x3 << 12)
530 #define RXON_RX_CHAIN_MIMO_CNT_POS              (12)
531 #define RXON_RX_CHAIN_MIMO_FORCE_MSK            __constant_cpu_to_le16(0x1 << 14)
532 #define RXON_RX_CHAIN_MIMO_FORCE_POS            (14)
533
534 /* rx_config flags */
535 /* band & modulation selection */
536 #define RXON_FLG_BAND_24G_MSK           __constant_cpu_to_le32(1 << 0)
537 #define RXON_FLG_CCK_MSK                __constant_cpu_to_le32(1 << 1)
538 /* auto detection enable */
539 #define RXON_FLG_AUTO_DETECT_MSK        __constant_cpu_to_le32(1 << 2)
540 /* TGg protection when tx */
541 #define RXON_FLG_TGG_PROTECT_MSK        __constant_cpu_to_le32(1 << 3)
542 /* cck short slot & preamble */
543 #define RXON_FLG_SHORT_SLOT_MSK          __constant_cpu_to_le32(1 << 4)
544 #define RXON_FLG_SHORT_PREAMBLE_MSK     __constant_cpu_to_le32(1 << 5)
545 /* antenna selection */
546 #define RXON_FLG_DIS_DIV_MSK            __constant_cpu_to_le32(1 << 7)
547 #define RXON_FLG_ANT_SEL_MSK            __constant_cpu_to_le32(0x0f00)
548 #define RXON_FLG_ANT_A_MSK              __constant_cpu_to_le32(1 << 8)
549 #define RXON_FLG_ANT_B_MSK              __constant_cpu_to_le32(1 << 9)
550 /* radar detection enable */
551 #define RXON_FLG_RADAR_DETECT_MSK       __constant_cpu_to_le32(1 << 12)
552 #define RXON_FLG_TGJ_NARROW_BAND_MSK    __constant_cpu_to_le32(1 << 13)
553 /* rx response to host with 8-byte TSF
554 * (according to ON_AIR deassertion) */
555 #define RXON_FLG_TSF2HOST_MSK           __constant_cpu_to_le32(1 << 15)
556
557
558 /* HT flags */
559 #define RXON_FLG_CTRL_CHANNEL_LOC_POS           (22)
560 #define RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK        __constant_cpu_to_le32(0x1 << 22)
561
562 #define RXON_FLG_HT_OPERATING_MODE_POS          (23)
563
564 #define RXON_FLG_HT_PROT_MSK                    __constant_cpu_to_le32(0x1 << 23)
565 #define RXON_FLG_FAT_PROT_MSK                   __constant_cpu_to_le32(0x2 << 23)
566
567 #define RXON_FLG_CHANNEL_MODE_POS               (25)
568 #define RXON_FLG_CHANNEL_MODE_MSK               __constant_cpu_to_le32(0x3 << 25)
569 #define RXON_FLG_CHANNEL_MODE_PURE_40_MSK       __constant_cpu_to_le32(0x1 << 25)
570 #define RXON_FLG_CHANNEL_MODE_MIXED_MSK         __constant_cpu_to_le32(0x2 << 25)
571 /* CTS to self (if spec allows) flag */
572 #define RXON_FLG_SELF_CTS_EN                    __constant_cpu_to_le32(0x1<<30)
573
574 /* rx_config filter flags */
575 /* accept all data frames */
576 #define RXON_FILTER_PROMISC_MSK         __constant_cpu_to_le32(1 << 0)
577 /* pass control & management to host */
578 #define RXON_FILTER_CTL2HOST_MSK        __constant_cpu_to_le32(1 << 1)
579 /* accept multi-cast */
580 #define RXON_FILTER_ACCEPT_GRP_MSK      __constant_cpu_to_le32(1 << 2)
581 /* don't decrypt uni-cast frames */
582 #define RXON_FILTER_DIS_DECRYPT_MSK     __constant_cpu_to_le32(1 << 3)
583 /* don't decrypt multi-cast frames */
584 #define RXON_FILTER_DIS_GRP_DECRYPT_MSK __constant_cpu_to_le32(1 << 4)
585 /* STA is associated */
586 #define RXON_FILTER_ASSOC_MSK           __constant_cpu_to_le32(1 << 5)
587 /* transfer to host non bssid beacons in associated state */
588 #define RXON_FILTER_BCON_AWARE_MSK      __constant_cpu_to_le32(1 << 6)
589
590 /**
591  * REPLY_RXON = 0x10 (command, has simple generic response)
592  *
593  * RXON tunes the radio tuner to a service channel, and sets up a number
594  * of parameters that are used primarily for Rx, but also for Tx operations.
595  *
596  * NOTE:  When tuning to a new channel, driver must set the
597  *        RXON_FILTER_ASSOC_MSK to 0.  This will clear station-dependent
598  *        info within the device, including the station tables, tx retry
599  *        rate tables, and txpower tables.  Driver must build a new station
600  *        table and txpower table before transmitting anything on the RXON
601  *        channel.
602  *
603  * NOTE:  All RXONs wipe clean the internal txpower table.  Driver must
604  *        issue a new REPLY_TX_PWR_TABLE_CMD after each REPLY_RXON (0x10),
605  *        regardless of whether RXON_FILTER_ASSOC_MSK is set.
606  */
607 struct iwl4965_rxon_cmd {
608         u8 node_addr[6];
609         __le16 reserved1;
610         u8 bssid_addr[6];
611         __le16 reserved2;
612         u8 wlap_bssid_addr[6];
613         __le16 reserved3;
614         u8 dev_type;
615         u8 air_propagation;
616         __le16 rx_chain;
617         u8 ofdm_basic_rates;
618         u8 cck_basic_rates;
619         __le16 assoc_id;
620         __le32 flags;
621         __le32 filter_flags;
622         __le16 channel;
623         u8 ofdm_ht_single_stream_basic_rates;
624         u8 ofdm_ht_dual_stream_basic_rates;
625 } __attribute__ ((packed));
626
627 /* 5000 HW just extend this command */
628 struct iwl_rxon_cmd {
629         u8 node_addr[6];
630         __le16 reserved1;
631         u8 bssid_addr[6];
632         __le16 reserved2;
633         u8 wlap_bssid_addr[6];
634         __le16 reserved3;
635         u8 dev_type;
636         u8 air_propagation;
637         __le16 rx_chain;
638         u8 ofdm_basic_rates;
639         u8 cck_basic_rates;
640         __le16 assoc_id;
641         __le32 flags;
642         __le32 filter_flags;
643         __le16 channel;
644         u8 ofdm_ht_single_stream_basic_rates;
645         u8 ofdm_ht_dual_stream_basic_rates;
646         u8 ofdm_ht_triple_stream_basic_rates;
647         u8 reserved5;
648         __le16 acquisition_data;
649         __le16 reserved6;
650 } __attribute__ ((packed));
651
652 struct iwl5000_rxon_assoc_cmd {
653         __le32 flags;
654         __le32 filter_flags;
655         u8 ofdm_basic_rates;
656         u8 cck_basic_rates;
657         __le16 reserved1;
658         u8 ofdm_ht_single_stream_basic_rates;
659         u8 ofdm_ht_dual_stream_basic_rates;
660         u8 ofdm_ht_triple_stream_basic_rates;
661         u8 reserved2;
662         __le16 rx_chain_select_flags;
663         __le16 acquisition_data;
664         __le32 reserved3;
665 } __attribute__ ((packed));
666
667 /*
668  * REPLY_RXON_ASSOC = 0x11 (command, has simple generic response)
669  */
670 struct iwl4965_rxon_assoc_cmd {
671         __le32 flags;
672         __le32 filter_flags;
673         u8 ofdm_basic_rates;
674         u8 cck_basic_rates;
675         u8 ofdm_ht_single_stream_basic_rates;
676         u8 ofdm_ht_dual_stream_basic_rates;
677         __le16 rx_chain_select_flags;
678         __le16 reserved;
679 } __attribute__ ((packed));
680
681 #define IWL_CONN_MAX_LISTEN_INTERVAL    10
682
683 /*
684  * REPLY_RXON_TIMING = 0x14 (command, has simple generic response)
685  */
686 struct iwl_rxon_time_cmd {
687         __le64 timestamp;
688         __le16 beacon_interval;
689         __le16 atim_window;
690         __le32 beacon_init_val;
691         __le16 listen_interval;
692         __le16 reserved;
693 } __attribute__ ((packed));
694
695 /*
696  * REPLY_CHANNEL_SWITCH = 0x72 (command, has simple generic response)
697  */
698 struct iwl4965_channel_switch_cmd {
699         u8 band;
700         u8 expect_beacon;
701         __le16 channel;
702         __le32 rxon_flags;
703         __le32 rxon_filter_flags;
704         __le32 switch_time;
705         struct iwl4965_tx_power_db tx_power;
706 } __attribute__ ((packed));
707
708 /*
709  * CHANNEL_SWITCH_NOTIFICATION = 0x73 (notification only, not a command)
710  */
711 struct iwl4965_csa_notification {
712         __le16 band;
713         __le16 channel;
714         __le32 status;          /* 0 - OK, 1 - fail */
715 } __attribute__ ((packed));
716
717 /******************************************************************************
718  * (2)
719  * Quality-of-Service (QOS) Commands & Responses:
720  *
721  *****************************************************************************/
722
723 /**
724  * struct iwl_ac_qos -- QOS timing params for REPLY_QOS_PARAM
725  * One for each of 4 EDCA access categories in struct iwl_qosparam_cmd
726  *
727  * @cw_min: Contention window, start value in numbers of slots.
728  *          Should be a power-of-2, minus 1.  Device's default is 0x0f.
729  * @cw_max: Contention window, max value in numbers of slots.
730  *          Should be a power-of-2, minus 1.  Device's default is 0x3f.
731  * @aifsn:  Number of slots in Arbitration Interframe Space (before
732  *          performing random backoff timing prior to Tx).  Device default 1.
733  * @edca_txop:  Length of Tx opportunity, in uSecs.  Device default is 0.
734  *
735  * Device will automatically increase contention window by (2*CW) + 1 for each
736  * transmission retry.  Device uses cw_max as a bit mask, ANDed with new CW
737  * value, to cap the CW value.
738  */
739 struct iwl_ac_qos {
740         __le16 cw_min;
741         __le16 cw_max;
742         u8 aifsn;
743         u8 reserved1;
744         __le16 edca_txop;
745 } __attribute__ ((packed));
746
747 /* QoS flags defines */
748 #define QOS_PARAM_FLG_UPDATE_EDCA_MSK   __constant_cpu_to_le32(0x01)
749 #define QOS_PARAM_FLG_TGN_MSK           __constant_cpu_to_le32(0x02)
750 #define QOS_PARAM_FLG_TXOP_TYPE_MSK     __constant_cpu_to_le32(0x10)
751
752 /* Number of Access Categories (AC) (EDCA), queues 0..3 */
753 #define AC_NUM                4
754
755 /*
756  * REPLY_QOS_PARAM = 0x13 (command, has simple generic response)
757  *
758  * This command sets up timings for each of the 4 prioritized EDCA Tx FIFOs
759  * 0: Background, 1: Best Effort, 2: Video, 3: Voice.
760  */
761 struct iwl_qosparam_cmd {
762         __le32 qos_flags;
763         struct iwl_ac_qos ac[AC_NUM];
764 } __attribute__ ((packed));
765
766 /******************************************************************************
767  * (3)
768  * Add/Modify Stations Commands & Responses:
769  *
770  *****************************************************************************/
771 /*
772  * Multi station support
773  */
774
775 /* Special, dedicated locations within device's station table */
776 #define IWL_AP_ID               0
777 #define IWL_MULTICAST_ID        1
778 #define IWL_STA_ID              2
779 #define IWL4965_BROADCAST_ID    31
780 #define IWL4965_STATION_COUNT   32
781 #define IWL5000_BROADCAST_ID    15
782 #define IWL5000_STATION_COUNT   16
783
784 #define IWL_STATION_COUNT       32      /* MAX(3945,4965)*/
785 #define IWL_INVALID_STATION     255
786
787 #define STA_FLG_PWR_SAVE_MSK            __constant_cpu_to_le32(1 << 8);
788 #define STA_FLG_RTS_MIMO_PROT_MSK       __constant_cpu_to_le32(1 << 17)
789 #define STA_FLG_AGG_MPDU_8US_MSK        __constant_cpu_to_le32(1 << 18)
790 #define STA_FLG_MAX_AGG_SIZE_POS        (19)
791 #define STA_FLG_MAX_AGG_SIZE_MSK        __constant_cpu_to_le32(3 << 19)
792 #define STA_FLG_FAT_EN_MSK              __constant_cpu_to_le32(1 << 21)
793 #define STA_FLG_MIMO_DIS_MSK            __constant_cpu_to_le32(1 << 22)
794 #define STA_FLG_AGG_MPDU_DENSITY_POS    (23)
795 #define STA_FLG_AGG_MPDU_DENSITY_MSK    __constant_cpu_to_le32(7 << 23)
796
797 /* Use in mode field.  1: modify existing entry, 0: add new station entry */
798 #define STA_CONTROL_MODIFY_MSK          0x01
799
800 /* key flags __le16*/
801 #define STA_KEY_FLG_ENCRYPT_MSK __constant_cpu_to_le16(0x0007)
802 #define STA_KEY_FLG_NO_ENC      __constant_cpu_to_le16(0x0000)
803 #define STA_KEY_FLG_WEP         __constant_cpu_to_le16(0x0001)
804 #define STA_KEY_FLG_CCMP        __constant_cpu_to_le16(0x0002)
805 #define STA_KEY_FLG_TKIP        __constant_cpu_to_le16(0x0003)
806
807 #define STA_KEY_FLG_KEYID_POS   8
808 #define STA_KEY_FLG_INVALID     __constant_cpu_to_le16(0x0800)
809 /* wep key is either from global key (0) or from station info array (1) */
810 #define STA_KEY_FLG_MAP_KEY_MSK __constant_cpu_to_le16(0x0008)
811
812 /* wep key in STA: 5-bytes (0) or 13-bytes (1) */
813 #define STA_KEY_FLG_KEY_SIZE_MSK     __constant_cpu_to_le16(0x1000)
814 #define STA_KEY_MULTICAST_MSK        __constant_cpu_to_le16(0x4000)
815 #define STA_KEY_MAX_NUM         8
816
817 /* Flags indicate whether to modify vs. don't change various station params */
818 #define STA_MODIFY_KEY_MASK             0x01
819 #define STA_MODIFY_TID_DISABLE_TX       0x02
820 #define STA_MODIFY_TX_RATE_MSK          0x04
821 #define STA_MODIFY_ADDBA_TID_MSK        0x08
822 #define STA_MODIFY_DELBA_TID_MSK        0x10
823
824 /* Receiver address (actually, Rx station's index into station table),
825  * combined with Traffic ID (QOS priority), in format used by Tx Scheduler */
826 #define BUILD_RAxTID(sta_id, tid)       (((sta_id) << 4) + (tid))
827
828 struct iwl4965_keyinfo {
829         __le16 key_flags;
830         u8 tkip_rx_tsc_byte2;   /* TSC[2] for key mix ph1 detection */
831         u8 reserved1;
832         __le16 tkip_rx_ttak[5]; /* 10-byte unicast TKIP TTAK */
833         u8 key_offset;
834         u8 reserved2;
835         u8 key[16];             /* 16-byte unicast decryption key */
836 } __attribute__ ((packed));
837
838 /* 5000 */
839 struct iwl_keyinfo {
840         __le16 key_flags;
841         u8 tkip_rx_tsc_byte2;   /* TSC[2] for key mix ph1 detection */
842         u8 reserved1;
843         __le16 tkip_rx_ttak[5]; /* 10-byte unicast TKIP TTAK */
844         u8 key_offset;
845         u8 reserved2;
846         u8 key[16];             /* 16-byte unicast decryption key */
847         __le64 tx_secur_seq_cnt;
848         __le64 hw_tkip_mic_rx_key;
849         __le64 hw_tkip_mic_tx_key;
850 } __attribute__ ((packed));
851
852 /**
853  * struct sta_id_modify
854  * @addr[ETH_ALEN]: station's MAC address
855  * @sta_id: index of station in uCode's station table
856  * @modify_mask: STA_MODIFY_*, 1: modify, 0: don't change
857  *
858  * Driver selects unused table index when adding new station,
859  * or the index to a pre-existing station entry when modifying that station.
860  * Some indexes have special purposes (IWL_AP_ID, index 0, is for AP).
861  *
862  * modify_mask flags select which parameters to modify vs. leave alone.
863  */
864 struct sta_id_modify {
865         u8 addr[ETH_ALEN];
866         __le16 reserved1;
867         u8 sta_id;
868         u8 modify_mask;
869         __le16 reserved2;
870 } __attribute__ ((packed));
871
872 /*
873  * REPLY_ADD_STA = 0x18 (command)
874  *
875  * The device contains an internal table of per-station information,
876  * with info on security keys, aggregation parameters, and Tx rates for
877  * initial Tx attempt and any retries (4965 uses REPLY_TX_LINK_QUALITY_CMD,
878  * 3945 uses REPLY_RATE_SCALE to set up rate tables).
879  *
880  * REPLY_ADD_STA sets up the table entry for one station, either creating
881  * a new entry, or modifying a pre-existing one.
882  *
883  * NOTE:  RXON command (without "associated" bit set) wipes the station table
884  *        clean.  Moving into RF_KILL state does this also.  Driver must set up
885  *        new station table before transmitting anything on the RXON channel
886  *        (except active scans or active measurements; those commands carry
887  *        their own txpower/rate setup data).
888  *
889  *        When getting started on a new channel, driver must set up the
890  *        IWL_BROADCAST_ID entry (last entry in the table).  For a client
891  *        station in a BSS, once an AP is selected, driver sets up the AP STA
892  *        in the IWL_AP_ID entry (1st entry in the table).  BROADCAST and AP
893  *        are all that are needed for a BSS client station.  If the device is
894  *        used as AP, or in an IBSS network, driver must set up station table
895  *        entries for all STAs in network, starting with index IWL_STA_ID.
896  */
897 struct iwl4965_addsta_cmd {
898         u8 mode;                /* 1: modify existing, 0: add new station */
899         u8 reserved[3];
900         struct sta_id_modify sta;
901         struct iwl4965_keyinfo key;
902         __le32 station_flags;           /* STA_FLG_* */
903         __le32 station_flags_msk;       /* STA_FLG_* */
904
905         /* bit field to disable (1) or enable (0) Tx for Traffic ID (TID)
906          * corresponding to bit (e.g. bit 5 controls TID 5).
907          * Set modify_mask bit STA_MODIFY_TID_DISABLE_TX to use this field. */
908         __le16 tid_disable_tx;
909
910         __le16  reserved1;
911
912         /* TID for which to add block-ack support.
913          * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */
914         u8 add_immediate_ba_tid;
915
916         /* TID for which to remove block-ack support.
917          * Set modify_mask bit STA_MODIFY_DELBA_TID_MSK to use this field. */
918         u8 remove_immediate_ba_tid;
919
920         /* Starting Sequence Number for added block-ack support.
921          * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */
922         __le16 add_immediate_ba_ssn;
923
924         __le32 reserved2;
925 } __attribute__ ((packed));
926
927 /* 5000 */
928 struct iwl_addsta_cmd {
929         u8 mode;                /* 1: modify existing, 0: add new station */
930         u8 reserved[3];
931         struct sta_id_modify sta;
932         struct iwl_keyinfo key;
933         __le32 station_flags;           /* STA_FLG_* */
934         __le32 station_flags_msk;       /* STA_FLG_* */
935
936         /* bit field to disable (1) or enable (0) Tx for Traffic ID (TID)
937          * corresponding to bit (e.g. bit 5 controls TID 5).
938          * Set modify_mask bit STA_MODIFY_TID_DISABLE_TX to use this field. */
939         __le16 tid_disable_tx;
940
941         __le16  reserved1;
942
943         /* TID for which to add block-ack support.
944          * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */
945         u8 add_immediate_ba_tid;
946
947         /* TID for which to remove block-ack support.
948          * Set modify_mask bit STA_MODIFY_DELBA_TID_MSK to use this field. */
949         u8 remove_immediate_ba_tid;
950
951         /* Starting Sequence Number for added block-ack support.
952          * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */
953         __le16 add_immediate_ba_ssn;
954
955         __le32 reserved2;
956 } __attribute__ ((packed));
957
958
959 #define ADD_STA_SUCCESS_MSK             0x1
960 #define ADD_STA_NO_ROOM_IN_TABLE        0x2
961 #define ADD_STA_NO_BLOCK_ACK_RESOURCE   0x4
962 #define ADD_STA_MODIFY_NON_EXIST_STA    0x8
963 /*
964  * REPLY_ADD_STA = 0x18 (response)
965  */
966 struct iwl_add_sta_resp {
967         u8 status;      /* ADD_STA_* */
968 } __attribute__ ((packed));
969
970 #define REM_STA_SUCCESS_MSK              0x1
971 /*
972  *  REPLY_REM_STA = 0x19 (response)
973  */
974 struct iwl_rem_sta_resp {
975         u8 status;
976 } __attribute__ ((packed));
977
978 /*
979  *  REPLY_REM_STA = 0x19 (command)
980  */
981 struct iwl_rem_sta_cmd {
982         u8 num_sta;     /* number of removed stations */
983         u8 reserved[3];
984         u8 addr[ETH_ALEN]; /* MAC addr of the first station */
985         u8 reserved2[2];
986 } __attribute__ ((packed));
987
988 /*
989  * REPLY_WEP_KEY = 0x20
990  */
991 struct iwl_wep_key {
992         u8 key_index;
993         u8 key_offset;
994         u8 reserved1[2];
995         u8 key_size;
996         u8 reserved2[3];
997         u8 key[16];
998 } __attribute__ ((packed));
999
1000 struct iwl_wep_cmd {
1001         u8 num_keys;
1002         u8 global_key_type;
1003         u8 flags;
1004         u8 reserved;
1005         struct iwl_wep_key key[0];
1006 } __attribute__ ((packed));
1007
1008 #define WEP_KEY_WEP_TYPE 1
1009 #define WEP_KEYS_MAX 4
1010 #define WEP_INVALID_OFFSET 0xff
1011 #define WEP_KEY_LEN_64 5
1012 #define WEP_KEY_LEN_128 13
1013
1014 /******************************************************************************
1015  * (4)
1016  * Rx Responses:
1017  *
1018  *****************************************************************************/
1019
1020 struct iwl4965_rx_frame_stats {
1021         u8 phy_count;
1022         u8 id;
1023         u8 rssi;
1024         u8 agc;
1025         __le16 sig_avg;
1026         __le16 noise_diff;
1027         u8 payload[0];
1028 } __attribute__ ((packed));
1029
1030 struct iwl4965_rx_frame_hdr {
1031         __le16 channel;
1032         __le16 phy_flags;
1033         u8 reserved1;
1034         u8 rate;
1035         __le16 len;
1036         u8 payload[0];
1037 } __attribute__ ((packed));
1038
1039 #define RX_RES_STATUS_NO_CRC32_ERROR    __constant_cpu_to_le32(1 << 0)
1040 #define RX_RES_STATUS_NO_RXE_OVERFLOW   __constant_cpu_to_le32(1 << 1)
1041
1042 #define RX_RES_PHY_FLAGS_BAND_24_MSK    __constant_cpu_to_le16(1 << 0)
1043 #define RX_RES_PHY_FLAGS_MOD_CCK_MSK            __constant_cpu_to_le16(1 << 1)
1044 #define RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK     __constant_cpu_to_le16(1 << 2)
1045 #define RX_RES_PHY_FLAGS_NARROW_BAND_MSK        __constant_cpu_to_le16(1 << 3)
1046 #define RX_RES_PHY_FLAGS_ANTENNA_MSK            __constant_cpu_to_le16(0xf0)
1047
1048 #define RX_RES_STATUS_SEC_TYPE_MSK      (0x7 << 8)
1049 #define RX_RES_STATUS_SEC_TYPE_NONE     (0x0 << 8)
1050 #define RX_RES_STATUS_SEC_TYPE_WEP      (0x1 << 8)
1051 #define RX_RES_STATUS_SEC_TYPE_CCMP     (0x2 << 8)
1052 #define RX_RES_STATUS_SEC_TYPE_TKIP     (0x3 << 8)
1053 #define RX_RES_STATUS_SEC_TYPE_ERR      (0x7 << 8)
1054
1055 #define RX_RES_STATUS_STATION_FOUND     (1<<6)
1056 #define RX_RES_STATUS_NO_STATION_INFO_MISMATCH  (1<<7)
1057
1058 #define RX_RES_STATUS_DECRYPT_TYPE_MSK  (0x3 << 11)
1059 #define RX_RES_STATUS_NOT_DECRYPT       (0x0 << 11)
1060 #define RX_RES_STATUS_DECRYPT_OK        (0x3 << 11)
1061 #define RX_RES_STATUS_BAD_ICV_MIC       (0x1 << 11)
1062 #define RX_RES_STATUS_BAD_KEY_TTAK      (0x2 << 11)
1063
1064 #define RX_MPDU_RES_STATUS_ICV_OK       (0x20)
1065 #define RX_MPDU_RES_STATUS_MIC_OK       (0x40)
1066 #define RX_MPDU_RES_STATUS_TTAK_OK      (1 << 7)
1067 #define RX_MPDU_RES_STATUS_DEC_DONE_MSK (0x800)
1068
1069 struct iwl4965_rx_frame_end {
1070         __le32 status;
1071         __le64 timestamp;
1072         __le32 beacon_timestamp;
1073 } __attribute__ ((packed));
1074
1075 /*
1076  * REPLY_3945_RX = 0x1b (response only, not a command)
1077  *
1078  * NOTE:  DO NOT dereference from casts to this structure
1079  * It is provided only for calculating minimum data set size.
1080  * The actual offsets of the hdr and end are dynamic based on
1081  * stats.phy_count
1082  */
1083 struct iwl4965_rx_frame {
1084         struct iwl4965_rx_frame_stats stats;
1085         struct iwl4965_rx_frame_hdr hdr;
1086         struct iwl4965_rx_frame_end end;
1087 } __attribute__ ((packed));
1088
1089 /* Fixed (non-configurable) rx data from phy */
1090
1091 #define IWL49_RX_RES_PHY_CNT 14
1092 #define IWL49_RX_PHY_FLAGS_ANTENNAE_OFFSET      (4)
1093 #define IWL49_RX_PHY_FLAGS_ANTENNAE_MASK        (0x70)
1094 #define IWL49_AGC_DB_MASK                       (0x3f80)        /* MASK(7,13) */
1095 #define IWL49_AGC_DB_POS                        (7)
1096 struct iwl4965_rx_non_cfg_phy {
1097         __le16 ant_selection;   /* ant A bit 4, ant B bit 5, ant C bit 6 */
1098         __le16 agc_info;        /* agc code 0:6, agc dB 7:13, reserved 14:15 */
1099         u8 rssi_info[6];        /* we use even entries, 0/2/4 for A/B/C rssi */
1100         u8 pad[0];
1101 } __attribute__ ((packed));
1102
1103
1104 #define IWL50_RX_RES_PHY_CNT 8
1105 #define IWL50_RX_RES_AGC_IDX     1
1106 #define IWL50_RX_RES_RSSI_AB_IDX 2
1107 #define IWL50_RX_RES_RSSI_C_IDX  3
1108 #define IWL50_OFDM_AGC_MSK 0xfe00
1109 #define IWL50_OFDM_AGC_BIT_POS 9
1110 #define IWL50_OFDM_RSSI_A_MSK 0x00ff
1111 #define IWL50_OFDM_RSSI_A_BIT_POS 0
1112 #define IWL50_OFDM_RSSI_B_MSK 0xff0000
1113 #define IWL50_OFDM_RSSI_B_BIT_POS 16
1114 #define IWL50_OFDM_RSSI_C_MSK 0x00ff
1115 #define IWL50_OFDM_RSSI_C_BIT_POS 0
1116
1117 struct iwl5000_non_cfg_phy {
1118         __le32 non_cfg_phy[IWL50_RX_RES_PHY_CNT];  /* up to 8 phy entries */
1119 } __attribute__ ((packed));
1120
1121
1122 /*
1123  * REPLY_RX = 0xc3 (response only, not a command)
1124  * Used only for legacy (non 11n) frames.
1125  */
1126 struct iwl_rx_phy_res {
1127         u8 non_cfg_phy_cnt;     /* non configurable DSP phy data byte count */
1128         u8 cfg_phy_cnt;         /* configurable DSP phy data byte count */
1129         u8 stat_id;             /* configurable DSP phy data set ID */
1130         u8 reserved1;
1131         __le64 timestamp;       /* TSF at on air rise */
1132         __le32 beacon_time_stamp; /* beacon at on-air rise */
1133         __le16 phy_flags;       /* general phy flags: band, modulation, ... */
1134         __le16 channel;         /* channel number */
1135         u8 non_cfg_phy_buf[32]; /* for various implementations of non_cfg_phy */
1136         __le32 rate_n_flags;    /* RATE_MCS_* */
1137         __le16 byte_count;      /* frame's byte-count */
1138         __le16 reserved3;
1139 } __attribute__ ((packed));
1140
1141 struct iwl4965_rx_mpdu_res_start {
1142         __le16 byte_count;
1143         __le16 reserved;
1144 } __attribute__ ((packed));
1145
1146
1147 /******************************************************************************
1148  * (5)
1149  * Tx Commands & Responses:
1150  *
1151  * Driver must place each REPLY_TX command into one of the prioritized Tx
1152  * queues in host DRAM, shared between driver and device (see comments for
1153  * SCD registers and Tx/Rx Queues).  When the device's Tx scheduler and uCode
1154  * are preparing to transmit, the device pulls the Tx command over the PCI
1155  * bus via one of the device's Tx DMA channels, to fill an internal FIFO
1156  * from which data will be transmitted.
1157  *
1158  * uCode handles all timing and protocol related to control frames
1159  * (RTS/CTS/ACK), based on flags in the Tx command.  uCode and Tx scheduler
1160  * handle reception of block-acks; uCode updates the host driver via
1161  * REPLY_COMPRESSED_BA (4965).
1162  *
1163  * uCode handles retrying Tx when an ACK is expected but not received.
1164  * This includes trying lower data rates than the one requested in the Tx
1165  * command, as set up by the REPLY_RATE_SCALE (for 3945) or
1166  * REPLY_TX_LINK_QUALITY_CMD (4965).
1167  *
1168  * Driver sets up transmit power for various rates via REPLY_TX_PWR_TABLE_CMD.
1169  * This command must be executed after every RXON command, before Tx can occur.
1170  *****************************************************************************/
1171
1172 /* REPLY_TX Tx flags field */
1173
1174 /* 1: Use RTS/CTS protocol or CTS-to-self if spec allows it
1175  * before this frame. if CTS-to-self required check
1176  * RXON_FLG_SELF_CTS_EN status. */
1177 #define TX_CMD_FLG_RTS_CTS_MSK __constant_cpu_to_le32(1 << 0)
1178
1179 /* 1: Use Request-To-Send protocol before this frame.
1180  * Mutually exclusive vs. TX_CMD_FLG_CTS_MSK. */
1181 #define TX_CMD_FLG_RTS_MSK __constant_cpu_to_le32(1 << 1)
1182
1183 /* 1: Transmit Clear-To-Send to self before this frame.
1184  * Driver should set this for AUTH/DEAUTH/ASSOC-REQ/REASSOC mgmnt frames.
1185  * Mutually exclusive vs. TX_CMD_FLG_RTS_MSK. */
1186 #define TX_CMD_FLG_CTS_MSK __constant_cpu_to_le32(1 << 2)
1187
1188 /* 1: Expect ACK from receiving station
1189  * 0: Don't expect ACK (MAC header's duration field s/b 0)
1190  * Set this for unicast frames, but not broadcast/multicast. */
1191 #define TX_CMD_FLG_ACK_MSK __constant_cpu_to_le32(1 << 3)
1192
1193 /* For 4965:
1194  * 1: Use rate scale table (see REPLY_TX_LINK_QUALITY_CMD).
1195  *    Tx command's initial_rate_index indicates first rate to try;
1196  *    uCode walks through table for additional Tx attempts.
1197  * 0: Use Tx rate/MCS from Tx command's rate_n_flags field.
1198  *    This rate will be used for all Tx attempts; it will not be scaled. */
1199 #define TX_CMD_FLG_STA_RATE_MSK __constant_cpu_to_le32(1 << 4)
1200
1201 /* 1: Expect immediate block-ack.
1202  * Set when Txing a block-ack request frame.  Also set TX_CMD_FLG_ACK_MSK. */
1203 #define TX_CMD_FLG_IMM_BA_RSP_MASK  __constant_cpu_to_le32(1 << 6)
1204
1205 /* 1: Frame requires full Tx-Op protection.
1206  * Set this if either RTS or CTS Tx Flag gets set. */
1207 #define TX_CMD_FLG_FULL_TXOP_PROT_MSK __constant_cpu_to_le32(1 << 7)
1208
1209 /* Tx antenna selection field; used only for 3945, reserved (0) for 4965.
1210  * Set field to "0" to allow 3945 uCode to select antenna (normal usage). */
1211 #define TX_CMD_FLG_ANT_SEL_MSK __constant_cpu_to_le32(0xf00)
1212 #define TX_CMD_FLG_ANT_A_MSK __constant_cpu_to_le32(1 << 8)
1213 #define TX_CMD_FLG_ANT_B_MSK __constant_cpu_to_le32(1 << 9)
1214
1215 /* 1: Ignore Bluetooth priority for this frame.
1216  * 0: Delay Tx until Bluetooth device is done (normal usage). */
1217 #define TX_CMD_FLG_BT_DIS_MSK __constant_cpu_to_le32(1 << 12)
1218
1219 /* 1: uCode overrides sequence control field in MAC header.
1220  * 0: Driver provides sequence control field in MAC header.
1221  * Set this for management frames, non-QOS data frames, non-unicast frames,
1222  * and also in Tx command embedded in REPLY_SCAN_CMD for active scans. */
1223 #define TX_CMD_FLG_SEQ_CTL_MSK __constant_cpu_to_le32(1 << 13)
1224
1225 /* 1: This frame is non-last MPDU; more fragments are coming.
1226  * 0: Last fragment, or not using fragmentation. */
1227 #define TX_CMD_FLG_MORE_FRAG_MSK __constant_cpu_to_le32(1 << 14)
1228
1229 /* 1: uCode calculates and inserts Timestamp Function (TSF) in outgoing frame.
1230  * 0: No TSF required in outgoing frame.
1231  * Set this for transmitting beacons and probe responses. */
1232 #define TX_CMD_FLG_TSF_MSK __constant_cpu_to_le32(1 << 16)
1233
1234 /* 1: Driver inserted 2 bytes pad after the MAC header, for (required) dword
1235  *    alignment of frame's payload data field.
1236  * 0: No pad
1237  * Set this for MAC headers with 26 or 30 bytes, i.e. those with QOS or ADDR4
1238  * field (but not both).  Driver must align frame data (i.e. data following
1239  * MAC header) to DWORD boundary. */
1240 #define TX_CMD_FLG_MH_PAD_MSK __constant_cpu_to_le32(1 << 20)
1241
1242 /* accelerate aggregation support
1243  * 0 - no CCMP encryption; 1 - CCMP encryption */
1244 #define TX_CMD_FLG_AGG_CCMP_MSK __constant_cpu_to_le32(1 << 22)
1245
1246 /* HCCA-AP - disable duration overwriting. */
1247 #define TX_CMD_FLG_DUR_MSK __constant_cpu_to_le32(1 << 25)
1248
1249
1250 /*
1251  * TX command security control
1252  */
1253 #define TX_CMD_SEC_WEP          0x01
1254 #define TX_CMD_SEC_CCM          0x02
1255 #define TX_CMD_SEC_TKIP         0x03
1256 #define TX_CMD_SEC_MSK          0x03
1257 #define TX_CMD_SEC_SHIFT        6
1258 #define TX_CMD_SEC_KEY128       0x08
1259
1260 /*
1261  * security overhead sizes
1262  */
1263 #define WEP_IV_LEN 4
1264 #define WEP_ICV_LEN 4
1265 #define CCMP_MIC_LEN 8
1266 #define TKIP_ICV_LEN 4
1267
1268 /*
1269  * 4965 uCode updates these Tx attempt count values in host DRAM.
1270  * Used for managing Tx retries when expecting block-acks.
1271  * Driver should set these fields to 0.
1272  */
1273 struct iwl4965_dram_scratch {
1274         u8 try_cnt;             /* Tx attempts */
1275         u8 bt_kill_cnt;         /* Tx attempts blocked by Bluetooth device */
1276         __le16 reserved;
1277 } __attribute__ ((packed));
1278
1279 /*
1280  * REPLY_TX = 0x1c (command)
1281  */
1282 struct iwl_tx_cmd {
1283         /*
1284          * MPDU byte count:
1285          * MAC header (24/26/30/32 bytes) + 2 bytes pad if 26/30 header size,
1286          * + 8 byte IV for CCM or TKIP (not used for WEP)
1287          * + Data payload
1288          * + 8-byte MIC (not used for CCM/WEP)
1289          * NOTE:  Does not include Tx command bytes, post-MAC pad bytes,
1290          *        MIC (CCM) 8 bytes, ICV (WEP/TKIP/CKIP) 4 bytes, CRC 4 bytes.i
1291          * Range: 14-2342 bytes.
1292          */
1293         __le16 len;
1294
1295         /*
1296          * MPDU or MSDU byte count for next frame.
1297          * Used for fragmentation and bursting, but not 11n aggregation.
1298          * Same as "len", but for next frame.  Set to 0 if not applicable.
1299          */
1300         __le16 next_frame_len;
1301
1302         __le32 tx_flags;        /* TX_CMD_FLG_* */
1303
1304         /* 4965's uCode may modify this field of the Tx command (in host DRAM!).
1305          * Driver must also set dram_lsb_ptr and dram_msb_ptr in this cmd. */
1306         struct iwl4965_dram_scratch scratch;
1307
1308         /* Rate for *all* Tx attempts, if TX_CMD_FLG_STA_RATE_MSK is cleared. */
1309         __le32 rate_n_flags;    /* RATE_MCS_* */
1310
1311         /* Index of destination station in uCode's station table */
1312         u8 sta_id;
1313
1314         /* Type of security encryption:  CCM or TKIP */
1315         u8 sec_ctl;             /* TX_CMD_SEC_* */
1316
1317         /*
1318          * Index into rate table (see REPLY_TX_LINK_QUALITY_CMD) for initial
1319          * Tx attempt, if TX_CMD_FLG_STA_RATE_MSK is set.  Normally "0" for
1320          * data frames, this field may be used to selectively reduce initial
1321          * rate (via non-0 value) for special frames (e.g. management), while
1322          * still supporting rate scaling for all frames.
1323          */
1324         u8 initial_rate_index;
1325         u8 reserved;
1326         u8 key[16];
1327         __le16 next_frame_flags;
1328         __le16 reserved2;
1329         union {
1330                 __le32 life_time;
1331                 __le32 attempt;
1332         } stop_time;
1333
1334         /* Host DRAM physical address pointer to "scratch" in this command.
1335          * Must be dword aligned.  "0" in dram_lsb_ptr disables usage. */
1336         __le32 dram_lsb_ptr;
1337         u8 dram_msb_ptr;
1338
1339         u8 rts_retry_limit;     /*byte 50 */
1340         u8 data_retry_limit;    /*byte 51 */
1341         u8 tid_tspec;
1342         union {
1343                 __le16 pm_frame_timeout;
1344                 __le16 attempt_duration;
1345         } timeout;
1346
1347         /*
1348          * Duration of EDCA burst Tx Opportunity, in 32-usec units.
1349          * Set this if txop time is not specified by HCCA protocol (e.g. by AP).
1350          */
1351         __le16 driver_txop;
1352
1353         /*
1354          * MAC header goes here, followed by 2 bytes padding if MAC header
1355          * length is 26 or 30 bytes, followed by payload data
1356          */
1357         u8 payload[0];
1358         struct ieee80211_hdr hdr[0];
1359 } __attribute__ ((packed));
1360
1361 /* TX command response is sent after *all* transmission attempts.
1362  *
1363  * NOTES:
1364  *
1365  * TX_STATUS_FAIL_NEXT_FRAG
1366  *
1367  * If the fragment flag in the MAC header for the frame being transmitted
1368  * is set and there is insufficient time to transmit the next frame, the
1369  * TX status will be returned with 'TX_STATUS_FAIL_NEXT_FRAG'.
1370  *
1371  * TX_STATUS_FIFO_UNDERRUN
1372  *
1373  * Indicates the host did not provide bytes to the FIFO fast enough while
1374  * a TX was in progress.
1375  *
1376  * TX_STATUS_FAIL_MGMNT_ABORT
1377  *
1378  * This status is only possible if the ABORT ON MGMT RX parameter was
1379  * set to true with the TX command.
1380  *
1381  * If the MSB of the status parameter is set then an abort sequence is
1382  * required.  This sequence consists of the host activating the TX Abort
1383  * control line, and then waiting for the TX Abort command response.  This
1384  * indicates that a the device is no longer in a transmit state, and that the
1385  * command FIFO has been cleared.  The host must then deactivate the TX Abort
1386  * control line.  Receiving is still allowed in this case.
1387  */
1388 enum {
1389         TX_STATUS_SUCCESS = 0x01,
1390         TX_STATUS_DIRECT_DONE = 0x02,
1391         TX_STATUS_FAIL_SHORT_LIMIT = 0x82,
1392         TX_STATUS_FAIL_LONG_LIMIT = 0x83,
1393         TX_STATUS_FAIL_FIFO_UNDERRUN = 0x84,
1394         TX_STATUS_FAIL_MGMNT_ABORT = 0x85,
1395         TX_STATUS_FAIL_NEXT_FRAG = 0x86,
1396         TX_STATUS_FAIL_LIFE_EXPIRE = 0x87,
1397         TX_STATUS_FAIL_DEST_PS = 0x88,
1398         TX_STATUS_FAIL_ABORTED = 0x89,
1399         TX_STATUS_FAIL_BT_RETRY = 0x8a,
1400         TX_STATUS_FAIL_STA_INVALID = 0x8b,
1401         TX_STATUS_FAIL_FRAG_DROPPED = 0x8c,
1402         TX_STATUS_FAIL_TID_DISABLE = 0x8d,
1403         TX_STATUS_FAIL_FRAME_FLUSHED = 0x8e,
1404         TX_STATUS_FAIL_INSUFFICIENT_CF_POLL = 0x8f,
1405         TX_STATUS_FAIL_TX_LOCKED = 0x90,
1406         TX_STATUS_FAIL_NO_BEACON_ON_RADAR = 0x91,
1407 };
1408
1409 #define TX_PACKET_MODE_REGULAR          0x0000
1410 #define TX_PACKET_MODE_BURST_SEQ        0x0100
1411 #define TX_PACKET_MODE_BURST_FIRST      0x0200
1412
1413 enum {
1414         TX_POWER_PA_NOT_ACTIVE = 0x0,
1415 };
1416
1417 enum {
1418         TX_STATUS_MSK = 0x000000ff,             /* bits 0:7 */
1419         TX_STATUS_DELAY_MSK = 0x00000040,
1420         TX_STATUS_ABORT_MSK = 0x00000080,
1421         TX_PACKET_MODE_MSK = 0x0000ff00,        /* bits 8:15 */
1422         TX_FIFO_NUMBER_MSK = 0x00070000,        /* bits 16:18 */
1423         TX_RESERVED = 0x00780000,               /* bits 19:22 */
1424         TX_POWER_PA_DETECT_MSK = 0x7f800000,    /* bits 23:30 */
1425         TX_ABORT_REQUIRED_MSK = 0x80000000,     /* bits 31:31 */
1426 };
1427
1428 static inline bool iwl_is_tx_success(u32 status)
1429 {
1430         status &= TX_STATUS_MSK;
1431         return (status == TX_STATUS_SUCCESS) ||
1432                (status == TX_STATUS_DIRECT_DONE);
1433 }
1434
1435
1436
1437 /* *******************************
1438  * TX aggregation status
1439  ******************************* */
1440
1441 enum {
1442         AGG_TX_STATE_TRANSMITTED = 0x00,
1443         AGG_TX_STATE_UNDERRUN_MSK = 0x01,
1444         AGG_TX_STATE_BT_PRIO_MSK = 0x02,
1445         AGG_TX_STATE_FEW_BYTES_MSK = 0x04,
1446         AGG_TX_STATE_ABORT_MSK = 0x08,
1447         AGG_TX_STATE_LAST_SENT_TTL_MSK = 0x10,
1448         AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK = 0x20,
1449         AGG_TX_STATE_LAST_SENT_BT_KILL_MSK = 0x40,
1450         AGG_TX_STATE_SCD_QUERY_MSK = 0x80,
1451         AGG_TX_STATE_TEST_BAD_CRC32_MSK = 0x100,
1452         AGG_TX_STATE_RESPONSE_MSK = 0x1ff,
1453         AGG_TX_STATE_DUMP_TX_MSK = 0x200,
1454         AGG_TX_STATE_DELAY_TX_MSK = 0x400
1455 };
1456
1457 #define AGG_TX_STATE_LAST_SENT_MSK  (AGG_TX_STATE_LAST_SENT_TTL_MSK | \
1458                                      AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK | \
1459                                      AGG_TX_STATE_LAST_SENT_BT_KILL_MSK)
1460
1461 /* # tx attempts for first frame in aggregation */
1462 #define AGG_TX_STATE_TRY_CNT_POS 12
1463 #define AGG_TX_STATE_TRY_CNT_MSK 0xf000
1464
1465 /* Command ID and sequence number of Tx command for this frame */
1466 #define AGG_TX_STATE_SEQ_NUM_POS 16
1467 #define AGG_TX_STATE_SEQ_NUM_MSK 0xffff0000
1468
1469 /*
1470  * REPLY_TX = 0x1c (response)
1471  *
1472  * This response may be in one of two slightly different formats, indicated
1473  * by the frame_count field:
1474  *
1475  * 1)  No aggregation (frame_count == 1).  This reports Tx results for
1476  *     a single frame.  Multiple attempts, at various bit rates, may have
1477  *     been made for this frame.
1478  *
1479  * 2)  Aggregation (frame_count > 1).  This reports Tx results for
1480  *     2 or more frames that used block-acknowledge.  All frames were
1481  *     transmitted at same rate.  Rate scaling may have been used if first
1482  *     frame in this new agg block failed in previous agg block(s).
1483  *
1484  *     Note that, for aggregation, ACK (block-ack) status is not delivered here;
1485  *     block-ack has not been received by the time the 4965 records this status.
1486  *     This status relates to reasons the tx might have been blocked or aborted
1487  *     within the sending station (this 4965), rather than whether it was
1488  *     received successfully by the destination station.
1489  */
1490 struct agg_tx_status {
1491         __le16 status;
1492         __le16 sequence;
1493 } __attribute__ ((packed));
1494
1495 struct iwl4965_tx_resp {
1496         u8 frame_count;         /* 1 no aggregation, >1 aggregation */
1497         u8 bt_kill_count;       /* # blocked by bluetooth (unused for agg) */
1498         u8 failure_rts;         /* # failures due to unsuccessful RTS */
1499         u8 failure_frame;       /* # failures due to no ACK (unused for agg) */
1500
1501         /* For non-agg:  Rate at which frame was successful.
1502          * For agg:  Rate at which all frames were transmitted. */
1503         __le32 rate_n_flags;    /* RATE_MCS_*  */
1504
1505         /* For non-agg:  RTS + CTS + frame tx attempts time + ACK.
1506          * For agg:  RTS + CTS + aggregation tx time + block-ack time. */
1507         __le16 wireless_media_time;     /* uSecs */
1508
1509         __le16 reserved;
1510         __le32 pa_power1;       /* RF power amplifier measurement (not used) */
1511         __le32 pa_power2;
1512
1513         /*
1514          * For non-agg:  frame status TX_STATUS_*
1515          * For agg:  status of 1st frame, AGG_TX_STATE_*; other frame status
1516          *           fields follow this one, up to frame_count.
1517          *           Bit fields:
1518          *           11- 0:  AGG_TX_STATE_* status code
1519          *           15-12:  Retry count for 1st frame in aggregation (retries
1520          *                   occur if tx failed for this frame when it was a
1521          *                   member of a previous aggregation block).  If rate
1522          *                   scaling is used, retry count indicates the rate
1523          *                   table entry used for all frames in the new agg.
1524          *           31-16:  Sequence # for this frame's Tx cmd (not SSN!)
1525          */
1526         union {
1527                 __le32 status;
1528                 struct agg_tx_status agg_status[0]; /* for each agg frame */
1529         } u;
1530 } __attribute__ ((packed));
1531
1532 /*
1533  * definitions for initial rate index field
1534  * bits [3:0] initial rate index
1535  * bits [6:4] rate table color, used for the initial rate
1536  * bit-7 invalid rate indication
1537  *   i.e. rate was not chosen from rate table
1538  *   or rate table color was changed during frame retries
1539  * refer tlc rate info
1540  */
1541
1542 #define IWL50_TX_RES_INIT_RATE_INDEX_POS        0
1543 #define IWL50_TX_RES_INIT_RATE_INDEX_MSK        0x0f
1544 #define IWL50_TX_RES_RATE_TABLE_COLOR_POS       4
1545 #define IWL50_TX_RES_RATE_TABLE_COLOR_MSK       0x70
1546 #define IWL50_TX_RES_INV_RATE_INDEX_MSK 0x80
1547
1548 /* refer to ra_tid */
1549 #define IWL50_TX_RES_TID_POS    0
1550 #define IWL50_TX_RES_TID_MSK    0x0f
1551 #define IWL50_TX_RES_RA_POS     4
1552 #define IWL50_TX_RES_RA_MSK     0xf0
1553
1554 struct iwl5000_tx_resp {
1555         u8 frame_count;         /* 1 no aggregation, >1 aggregation */
1556         u8 bt_kill_count;       /* # blocked by bluetooth (unused for agg) */
1557         u8 failure_rts;         /* # failures due to unsuccessful RTS */
1558         u8 failure_frame;       /* # failures due to no ACK (unused for agg) */
1559
1560         /* For non-agg:  Rate at which frame was successful.
1561          * For agg:  Rate at which all frames were transmitted. */
1562         __le32 rate_n_flags;    /* RATE_MCS_*  */
1563
1564         /* For non-agg:  RTS + CTS + frame tx attempts time + ACK.
1565          * For agg:  RTS + CTS + aggregation tx time + block-ack time. */
1566         __le16 wireless_media_time;     /* uSecs */
1567
1568         u8 pa_status;           /* RF power amplifier measurement (not used) */
1569         u8 pa_integ_res_a[3];
1570         u8 pa_integ_res_b[3];
1571         u8 pa_integ_res_C[3];
1572
1573         __le32 tfd_info;
1574         __le16 seq_ctl;
1575         __le16 byte_cnt;
1576         u8 tlc_info;
1577         u8 ra_tid;              /* tid (0:3), sta_id (4:7) */
1578         __le16 frame_ctrl;
1579         /*
1580          * For non-agg:  frame status TX_STATUS_*
1581          * For agg:  status of 1st frame, AGG_TX_STATE_*; other frame status
1582          *           fields follow this one, up to frame_count.
1583          *           Bit fields:
1584          *           11- 0:  AGG_TX_STATE_* status code
1585          *           15-12:  Retry count for 1st frame in aggregation (retries
1586          *                   occur if tx failed for this frame when it was a
1587          *                   member of a previous aggregation block).  If rate
1588          *                   scaling is used, retry count indicates the rate
1589          *                   table entry used for all frames in the new agg.
1590          *           31-16:  Sequence # for this frame's Tx cmd (not SSN!)
1591          */
1592         struct agg_tx_status status;    /* TX status (in aggregation -
1593                                          * status of 1st frame) */
1594 } __attribute__ ((packed));
1595 /*
1596  * REPLY_COMPRESSED_BA = 0xc5 (response only, not a command)
1597  *
1598  * Reports Block-Acknowledge from recipient station
1599  */
1600 struct iwl_compressed_ba_resp {
1601         __le32 sta_addr_lo32;
1602         __le16 sta_addr_hi16;
1603         __le16 reserved;
1604
1605         /* Index of recipient (BA-sending) station in uCode's station table */
1606         u8 sta_id;
1607         u8 tid;
1608         __le16 seq_ctl;
1609         __le64 bitmap;
1610         __le16 scd_flow;
1611         __le16 scd_ssn;
1612 } __attribute__ ((packed));
1613
1614 /*
1615  * REPLY_TX_PWR_TABLE_CMD = 0x97 (command, has simple generic response)
1616  *
1617  * See details under "TXPOWER" in iwl-4965-hw.h.
1618  */
1619 struct iwl4965_txpowertable_cmd {
1620         u8 band;                /* 0: 5 GHz, 1: 2.4 GHz */
1621         u8 reserved;
1622         __le16 channel;
1623         struct iwl4965_tx_power_db tx_power;
1624 } __attribute__ ((packed));
1625
1626 /*RS_NEW_API: only TLC_RTS remains and moved to bit 0 */
1627 #define  LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK    (1 << 0)
1628
1629 /* # of EDCA prioritized tx fifos */
1630 #define  LINK_QUAL_AC_NUM AC_NUM
1631
1632 /* # entries in rate scale table to support Tx retries */
1633 #define  LINK_QUAL_MAX_RETRY_NUM 16
1634
1635 /* Tx antenna selection values */
1636 #define  LINK_QUAL_ANT_A_MSK (1 << 0)
1637 #define  LINK_QUAL_ANT_B_MSK (1 << 1)
1638 #define  LINK_QUAL_ANT_MSK   (LINK_QUAL_ANT_A_MSK|LINK_QUAL_ANT_B_MSK)
1639
1640
1641 /**
1642  * struct iwl_link_qual_general_params
1643  *
1644  * Used in REPLY_TX_LINK_QUALITY_CMD
1645  */
1646 struct iwl_link_qual_general_params {
1647         u8 flags;
1648
1649         /* No entries at or above this (driver chosen) index contain MIMO */
1650         u8 mimo_delimiter;
1651
1652         /* Best single antenna to use for single stream (legacy, SISO). */
1653         u8 single_stream_ant_msk;       /* LINK_QUAL_ANT_* */
1654
1655         /* Best antennas to use for MIMO (unused for 4965, assumes both). */
1656         u8 dual_stream_ant_msk;         /* LINK_QUAL_ANT_* */
1657
1658         /*
1659          * If driver needs to use different initial rates for different
1660          * EDCA QOS access categories (as implemented by tx fifos 0-3),
1661          * this table will set that up, by indicating the indexes in the
1662          * rs_table[LINK_QUAL_MAX_RETRY_NUM] rate table at which to start.
1663          * Otherwise, driver should set all entries to 0.
1664          *
1665          * Entry usage:
1666          * 0 = Background, 1 = Best Effort (normal), 2 = Video, 3 = Voice
1667          * TX FIFOs above 3 use same value (typically 0) as TX FIFO 3.
1668          */
1669         u8 start_rate_index[LINK_QUAL_AC_NUM];
1670 } __attribute__ ((packed));
1671
1672 /**
1673  * struct iwl_link_qual_agg_params
1674  *
1675  * Used in REPLY_TX_LINK_QUALITY_CMD
1676  */
1677 struct iwl_link_qual_agg_params {
1678
1679         /* Maximum number of uSec in aggregation.
1680          * Driver should set this to 4000 (4 milliseconds). */
1681         __le16 agg_time_limit;
1682
1683         /*
1684          * Number of Tx retries allowed for a frame, before that frame will
1685          * no longer be considered for the start of an aggregation sequence
1686          * (scheduler will then try to tx it as single frame).
1687          * Driver should set this to 3.
1688          */
1689         u8 agg_dis_start_th;
1690
1691         /*
1692          * Maximum number of frames in aggregation.
1693          * 0 = no limit (default).  1 = no aggregation.
1694          * Other values = max # frames in aggregation.
1695          */
1696         u8 agg_frame_cnt_limit;
1697
1698         __le32 reserved;
1699 } __attribute__ ((packed));
1700
1701 /*
1702  * REPLY_TX_LINK_QUALITY_CMD = 0x4e (command, has simple generic response)
1703  *
1704  * For 4965 only; 3945 uses REPLY_RATE_SCALE.
1705  *
1706  * Each station in the 4965's internal station table has its own table of 16
1707  * Tx rates and modulation modes (e.g. legacy/SISO/MIMO) for retrying Tx when
1708  * an ACK is not received.  This command replaces the entire table for
1709  * one station.
1710  *
1711  * NOTE:  Station must already be in 4965's station table.  Use REPLY_ADD_STA.
1712  *
1713  * The rate scaling procedures described below work well.  Of course, other
1714  * procedures are possible, and may work better for particular environments.
1715  *
1716  *
1717  * FILLING THE RATE TABLE
1718  *
1719  * Given a particular initial rate and mode, as determined by the rate
1720  * scaling algorithm described below, the Linux driver uses the following
1721  * formula to fill the rs_table[LINK_QUAL_MAX_RETRY_NUM] rate table in the
1722  * Link Quality command:
1723  *
1724  *
1725  * 1)  If using High-throughput (HT) (SISO or MIMO) initial rate:
1726  *     a) Use this same initial rate for first 3 entries.
1727  *     b) Find next lower available rate using same mode (SISO or MIMO),
1728  *        use for next 3 entries.  If no lower rate available, switch to
1729  *        legacy mode (no FAT channel, no MIMO, no short guard interval).
1730  *     c) If using MIMO, set command's mimo_delimiter to number of entries
1731  *        using MIMO (3 or 6).
1732  *     d) After trying 2 HT rates, switch to legacy mode (no FAT channel,
1733  *        no MIMO, no short guard interval), at the next lower bit rate
1734  *        (e.g. if second HT bit rate was 54, try 48 legacy), and follow
1735  *        legacy procedure for remaining table entries.
1736  *
1737  * 2)  If using legacy initial rate:
1738  *     a) Use the initial rate for only one entry.
1739  *     b) For each following entry, reduce the rate to next lower available
1740  *        rate, until reaching the lowest available rate.
1741  *     c) When reducing rate, also switch antenna selection.
1742  *     d) Once lowest available rate is reached, repeat this rate until
1743  *        rate table is filled (16 entries), switching antenna each entry.
1744  *
1745  *
1746  * ACCUMULATING HISTORY
1747  *
1748  * The rate scaling algorithm for 4965, as implemented in Linux driver, uses
1749  * two sets of frame Tx success history:  One for the current/active modulation
1750  * mode, and one for a speculative/search mode that is being attempted.  If the
1751  * speculative mode turns out to be more effective (i.e. actual transfer
1752  * rate is better), then the driver continues to use the speculative mode
1753  * as the new current active mode.
1754  *
1755  * Each history set contains, separately for each possible rate, data for a
1756  * sliding window of the 62 most recent tx attempts at that rate.  The data
1757  * includes a shifting bitmap of success(1)/failure(0), and sums of successful
1758  * and attempted frames, from which the driver can additionally calculate a
1759  * success ratio (success / attempted) and number of failures
1760  * (attempted - success), and control the size of the window (attempted).
1761  * The driver uses the bit map to remove successes from the success sum, as
1762  * the oldest tx attempts fall out of the window.
1763  *
1764  * When the 4965 makes multiple tx attempts for a given frame, each attempt
1765  * might be at a different rate, and have different modulation characteristics
1766  * (e.g. antenna, fat channel, short guard interval), as set up in the rate
1767  * scaling table in the Link Quality command.  The driver must determine
1768  * which rate table entry was used for each tx attempt, to determine which
1769  * rate-specific history to update, and record only those attempts that
1770  * match the modulation characteristics of the history set.
1771  *
1772  * When using block-ack (aggregation), all frames are transmitted at the same
1773  * rate, since there is no per-attempt acknowledgment from the destination
1774  * station.  The Tx response struct iwl_tx_resp indicates the Tx rate in
1775  * rate_n_flags field.  After receiving a block-ack, the driver can update
1776  * history for the entire block all at once.
1777  *
1778  *
1779  * FINDING BEST STARTING RATE:
1780  *
1781  * When working with a selected initial modulation mode (see below), the
1782  * driver attempts to find a best initial rate.  The initial rate is the
1783  * first entry in the Link Quality command's rate table.
1784  *
1785  * 1)  Calculate actual throughput (success ratio * expected throughput, see
1786  *     table below) for current initial rate.  Do this only if enough frames
1787  *     have been attempted to make the value meaningful:  at least 6 failed
1788  *     tx attempts, or at least 8 successes.  If not enough, don't try rate
1789  *     scaling yet.
1790  *
1791  * 2)  Find available rates adjacent to current initial rate.  Available means:
1792  *     a)  supported by hardware &&
1793  *     b)  supported by association &&
1794  *     c)  within any constraints selected by user
1795  *
1796  * 3)  Gather measured throughputs for adjacent rates.  These might not have
1797  *     enough history to calculate a throughput.  That's okay, we might try
1798  *     using one of them anyway!
1799  *
1800  * 4)  Try decreasing rate if, for current rate:
1801  *     a)  success ratio is < 15% ||
1802  *     b)  lower adjacent rate has better measured throughput ||
1803  *     c)  higher adjacent rate has worse throughput, and lower is unmeasured
1804  *
1805  *     As a sanity check, if decrease was determined above, leave rate
1806  *     unchanged if:
1807  *     a)  lower rate unavailable
1808  *     b)  success ratio at current rate > 85% (very good)
1809  *     c)  current measured throughput is better than expected throughput
1810  *         of lower rate (under perfect 100% tx conditions, see table below)
1811  *
1812  * 5)  Try increasing rate if, for current rate:
1813  *     a)  success ratio is < 15% ||
1814  *     b)  both adjacent rates' throughputs are unmeasured (try it!) ||
1815  *     b)  higher adjacent rate has better measured throughput ||
1816  *     c)  lower adjacent rate has worse throughput, and higher is unmeasured
1817  *
1818  *     As a sanity check, if increase was determined above, leave rate
1819  *     unchanged if:
1820  *     a)  success ratio at current rate < 70%.  This is not particularly
1821  *         good performance; higher rate is sure to have poorer success.
1822  *
1823  * 6)  Re-evaluate the rate after each tx frame.  If working with block-
1824  *     acknowledge, history and statistics may be calculated for the entire
1825  *     block (including prior history that fits within the history windows),
1826  *     before re-evaluation.
1827  *
1828  * FINDING BEST STARTING MODULATION MODE:
1829  *
1830  * After working with a modulation mode for a "while" (and doing rate scaling),
1831  * the driver searches for a new initial mode in an attempt to improve
1832  * throughput.  The "while" is measured by numbers of attempted frames:
1833  *
1834  * For legacy mode, search for new mode after:
1835  *   480 successful frames, or 160 failed frames
1836  * For high-throughput modes (SISO or MIMO), search for new mode after:
1837  *   4500 successful frames, or 400 failed frames
1838  *
1839  * Mode switch possibilities are (3 for each mode):
1840  *
1841  * For legacy:
1842  *   Change antenna, try SISO (if HT association), try MIMO (if HT association)
1843  * For SISO:
1844  *   Change antenna, try MIMO, try shortened guard interval (SGI)
1845  * For MIMO:
1846  *   Try SISO antenna A, SISO antenna B, try shortened guard interval (SGI)
1847  *
1848  * When trying a new mode, use the same bit rate as the old/current mode when
1849  * trying antenna switches and shortened guard interval.  When switching to
1850  * SISO from MIMO or legacy, or to MIMO from SISO or legacy, use a rate
1851  * for which the expected throughput (under perfect conditions) is about the
1852  * same or slightly better than the actual measured throughput delivered by
1853  * the old/current mode.
1854  *
1855  * Actual throughput can be estimated by multiplying the expected throughput
1856  * by the success ratio (successful / attempted tx frames).  Frame size is
1857  * not considered in this calculation; it assumes that frame size will average
1858  * out to be fairly consistent over several samples.  The following are
1859  * metric values for expected throughput assuming 100% success ratio.
1860  * Only G band has support for CCK rates:
1861  *
1862  *           RATE:  1    2    5   11    6   9   12   18   24   36   48   54   60
1863  *
1864  *              G:  7   13   35   58   40  57   72   98  121  154  177  186  186
1865  *              A:  0    0    0    0   40  57   72   98  121  154  177  186  186
1866  *     SISO 20MHz:  0    0    0    0   42  42   76  102  124  159  183  193  202
1867  * SGI SISO 20MHz:  0    0    0    0   46  46   82  110  132  168  192  202  211
1868  *     MIMO 20MHz:  0    0    0    0   74  74  123  155  179  214  236  244  251
1869  * SGI MIMO 20MHz:  0    0    0    0   81  81  131  164  188  222  243  251  257
1870  *     SISO 40MHz:  0    0    0    0   77  77  127  160  184  220  242  250  257
1871  * SGI SISO 40MHz:  0    0    0    0   83  83  135  169  193  229  250  257  264
1872  *     MIMO 40MHz:  0    0    0    0  123 123  182  214  235  264  279  285  289
1873  * SGI MIMO 40MHz:  0    0    0    0  131 131  191  222  242  270  284  289  293
1874  *
1875  * After the new mode has been tried for a short while (minimum of 6 failed
1876  * frames or 8 successful frames), compare success ratio and actual throughput
1877  * estimate of the new mode with the old.  If either is better with the new
1878  * mode, continue to use the new mode.
1879  *
1880  * Continue comparing modes until all 3 possibilities have been tried.
1881  * If moving from legacy to HT, try all 3 possibilities from the new HT
1882  * mode.  After trying all 3, a best mode is found.  Continue to use this mode
1883  * for the longer "while" described above (e.g. 480 successful frames for
1884  * legacy), and then repeat the search process.
1885  *
1886  */
1887 struct iwl_link_quality_cmd {
1888
1889         /* Index of destination/recipient station in uCode's station table */
1890         u8 sta_id;
1891         u8 reserved1;
1892         __le16 control;         /* not used */
1893         struct iwl_link_qual_general_params general_params;
1894         struct iwl_link_qual_agg_params agg_params;
1895
1896         /*
1897          * Rate info; when using rate-scaling, Tx command's initial_rate_index
1898          * specifies 1st Tx rate attempted, via index into this table.
1899          * 4965 works its way through table when retrying Tx.
1900          */
1901         struct {
1902                 __le32 rate_n_flags;    /* RATE_MCS_*, IWL_RATE_* */
1903         } rs_table[LINK_QUAL_MAX_RETRY_NUM];
1904         __le32 reserved2;
1905 } __attribute__ ((packed));
1906
1907 /*
1908  * REPLY_BT_CONFIG = 0x9b (command, has simple generic response)
1909  *
1910  * 3945 and 4965 support hardware handshake with Bluetooth device on
1911  * same platform.  Bluetooth device alerts wireless device when it will Tx;
1912  * wireless device can delay or kill its own Tx to accommodate.
1913  */
1914 struct iwl4965_bt_cmd {
1915         u8 flags;
1916         u8 lead_time;
1917         u8 max_kill;
1918         u8 reserved;
1919         __le32 kill_ack_mask;
1920         __le32 kill_cts_mask;
1921 } __attribute__ ((packed));
1922
1923 /******************************************************************************
1924  * (6)
1925  * Spectrum Management (802.11h) Commands, Responses, Notifications:
1926  *
1927  *****************************************************************************/
1928
1929 /*
1930  * Spectrum Management
1931  */
1932 #define MEASUREMENT_FILTER_FLAG (RXON_FILTER_PROMISC_MSK         | \
1933                                  RXON_FILTER_CTL2HOST_MSK        | \
1934                                  RXON_FILTER_ACCEPT_GRP_MSK      | \
1935                                  RXON_FILTER_DIS_DECRYPT_MSK     | \
1936                                  RXON_FILTER_DIS_GRP_DECRYPT_MSK | \
1937                                  RXON_FILTER_ASSOC_MSK           | \
1938                                  RXON_FILTER_BCON_AWARE_MSK)
1939
1940 struct iwl4965_measure_channel {
1941         __le32 duration;        /* measurement duration in extended beacon
1942                                  * format */
1943         u8 channel;             /* channel to measure */
1944         u8 type;                /* see enum iwl4965_measure_type */
1945         __le16 reserved;
1946 } __attribute__ ((packed));
1947
1948 /*
1949  * REPLY_SPECTRUM_MEASUREMENT_CMD = 0x74 (command)
1950  */
1951 struct iwl4965_spectrum_cmd {
1952         __le16 len;             /* number of bytes starting from token */
1953         u8 token;               /* token id */
1954         u8 id;                  /* measurement id -- 0 or 1 */
1955         u8 origin;              /* 0 = TGh, 1 = other, 2 = TGk */
1956         u8 periodic;            /* 1 = periodic */
1957         __le16 path_loss_timeout;
1958         __le32 start_time;      /* start time in extended beacon format */
1959         __le32 reserved2;
1960         __le32 flags;           /* rxon flags */
1961         __le32 filter_flags;    /* rxon filter flags */
1962         __le16 channel_count;   /* minimum 1, maximum 10 */
1963         __le16 reserved3;
1964         struct iwl4965_measure_channel channels[10];
1965 } __attribute__ ((packed));
1966
1967 /*
1968  * REPLY_SPECTRUM_MEASUREMENT_CMD = 0x74 (response)
1969  */
1970 struct iwl4965_spectrum_resp {
1971         u8 token;
1972         u8 id;                  /* id of the prior command replaced, or 0xff */
1973         __le16 status;          /* 0 - command will be handled
1974                                  * 1 - cannot handle (conflicts with another
1975                                  *     measurement) */
1976 } __attribute__ ((packed));
1977
1978 enum iwl4965_measurement_state {
1979         IWL_MEASUREMENT_START = 0,
1980         IWL_MEASUREMENT_STOP = 1,
1981 };
1982
1983 enum iwl4965_measurement_status {
1984         IWL_MEASUREMENT_OK = 0,
1985         IWL_MEASUREMENT_CONCURRENT = 1,
1986         IWL_MEASUREMENT_CSA_CONFLICT = 2,
1987         IWL_MEASUREMENT_TGH_CONFLICT = 3,
1988         /* 4-5 reserved */
1989         IWL_MEASUREMENT_STOPPED = 6,
1990         IWL_MEASUREMENT_TIMEOUT = 7,
1991         IWL_MEASUREMENT_PERIODIC_FAILED = 8,
1992 };
1993
1994 #define NUM_ELEMENTS_IN_HISTOGRAM 8
1995
1996 struct iwl4965_measurement_histogram {
1997         __le32 ofdm[NUM_ELEMENTS_IN_HISTOGRAM]; /* in 0.8usec counts */
1998         __le32 cck[NUM_ELEMENTS_IN_HISTOGRAM];  /* in 1usec counts */
1999 } __attribute__ ((packed));
2000
2001 /* clear channel availability counters */
2002 struct iwl4965_measurement_cca_counters {
2003         __le32 ofdm;
2004         __le32 cck;
2005 } __attribute__ ((packed));
2006
2007 enum iwl4965_measure_type {
2008         IWL_MEASURE_BASIC = (1 << 0),
2009         IWL_MEASURE_CHANNEL_LOAD = (1 << 1),
2010         IWL_MEASURE_HISTOGRAM_RPI = (1 << 2),
2011         IWL_MEASURE_HISTOGRAM_NOISE = (1 << 3),
2012         IWL_MEASURE_FRAME = (1 << 4),
2013         /* bits 5:6 are reserved */
2014         IWL_MEASURE_IDLE = (1 << 7),
2015 };
2016
2017 /*
2018  * SPECTRUM_MEASURE_NOTIFICATION = 0x75 (notification only, not a command)
2019  */
2020 struct iwl4965_spectrum_notification {
2021         u8 id;                  /* measurement id -- 0 or 1 */
2022         u8 token;
2023         u8 channel_index;       /* index in measurement channel list */
2024         u8 state;               /* 0 - start, 1 - stop */
2025         __le32 start_time;      /* lower 32-bits of TSF */
2026         u8 band;                /* 0 - 5.2GHz, 1 - 2.4GHz */
2027         u8 channel;
2028         u8 type;                /* see enum iwl4965_measurement_type */
2029         u8 reserved1;
2030         /* NOTE:  cca_ofdm, cca_cck, basic_type, and histogram are only only
2031          * valid if applicable for measurement type requested. */
2032         __le32 cca_ofdm;        /* cca fraction time in 40Mhz clock periods */
2033         __le32 cca_cck;         /* cca fraction time in 44Mhz clock periods */
2034         __le32 cca_time;        /* channel load time in usecs */
2035         u8 basic_type;          /* 0 - bss, 1 - ofdm preamble, 2 -
2036                                  * unidentified */
2037         u8 reserved2[3];
2038         struct iwl4965_measurement_histogram histogram;
2039         __le32 stop_time;       /* lower 32-bits of TSF */
2040         __le32 status;          /* see iwl4965_measurement_status */
2041 } __attribute__ ((packed));
2042
2043 /******************************************************************************
2044  * (7)
2045  * Power Management Commands, Responses, Notifications:
2046  *
2047  *****************************************************************************/
2048
2049 /**
2050  * struct iwl_powertable_cmd - Power Table Command
2051  * @flags: See below:
2052  *
2053  * POWER_TABLE_CMD = 0x77 (command, has simple generic response)
2054  *
2055  * PM allow:
2056  *   bit 0 - '0' Driver not allow power management
2057  *           '1' Driver allow PM (use rest of parameters)
2058  * uCode send sleep notifications:
2059  *   bit 1 - '0' Don't send sleep notification
2060  *           '1' send sleep notification (SEND_PM_NOTIFICATION)
2061  * Sleep over DTIM
2062  *   bit 2 - '0' PM have to walk up every DTIM
2063  *           '1' PM could sleep over DTIM till listen Interval.
2064  * PCI power managed
2065  *   bit 3 - '0' (PCI_CFG_LINK_CTRL & 0x1)
2066  *           '1' !(PCI_CFG_LINK_CTRL & 0x1)
2067  * Force sleep Modes
2068  *   bit 31/30- '00' use both mac/xtal sleeps
2069  *              '01' force Mac sleep
2070  *              '10' force xtal sleep
2071  *              '11' Illegal set
2072  *
2073  * NOTE: if sleep_interval[SLEEP_INTRVL_TABLE_SIZE-1] > DTIM period then
2074  * ucode assume sleep over DTIM is allowed and we don't need to wake up
2075  * for every DTIM.
2076  */
2077 #define IWL_POWER_VEC_SIZE 5
2078
2079 #define IWL_POWER_DRIVER_ALLOW_SLEEP_MSK        __constant_cpu_to_le16(1 << 0)
2080 #define IWL_POWER_SLEEP_OVER_DTIM_MSK           __constant_cpu_to_le16(1 << 2)
2081 #define IWL_POWER_PCI_PM_MSK                    __constant_cpu_to_le16(1 << 3)
2082 #define IWL_POWER_FAST_PD                       __constant_cpu_to_le16(1 << 4)
2083
2084 struct iwl_powertable_cmd {
2085         __le16 flags;
2086         u8 keep_alive_seconds;
2087         u8 debug_flags;
2088         __le32 rx_data_timeout;
2089         __le32 tx_data_timeout;
2090         __le32 sleep_interval[IWL_POWER_VEC_SIZE];
2091         __le32 keep_alive_beacons;
2092 } __attribute__ ((packed));
2093
2094 /*
2095  * PM_SLEEP_NOTIFICATION = 0x7A (notification only, not a command)
2096  * 3945 and 4965 identical.
2097  */
2098 struct iwl4965_sleep_notification {
2099         u8 pm_sleep_mode;
2100         u8 pm_wakeup_src;
2101         __le16 reserved;
2102         __le32 sleep_time;
2103         __le32 tsf_low;
2104         __le32 bcon_timer;
2105 } __attribute__ ((packed));
2106
2107 /* Sleep states.  3945 and 4965 identical. */
2108 enum {
2109         IWL_PM_NO_SLEEP = 0,
2110         IWL_PM_SLP_MAC = 1,
2111         IWL_PM_SLP_FULL_MAC_UNASSOCIATE = 2,
2112         IWL_PM_SLP_FULL_MAC_CARD_STATE = 3,
2113         IWL_PM_SLP_PHY = 4,
2114         IWL_PM_SLP_REPENT = 5,
2115         IWL_PM_WAKEUP_BY_TIMER = 6,
2116         IWL_PM_WAKEUP_BY_DRIVER = 7,
2117         IWL_PM_WAKEUP_BY_RFKILL = 8,
2118         /* 3 reserved */
2119         IWL_PM_NUM_OF_MODES = 12,
2120 };
2121
2122 /*
2123  * REPLY_CARD_STATE_CMD = 0xa0 (command, has simple generic response)
2124  */
2125 #define CARD_STATE_CMD_DISABLE 0x00     /* Put card to sleep */
2126 #define CARD_STATE_CMD_ENABLE  0x01     /* Wake up card */
2127 #define CARD_STATE_CMD_HALT    0x02     /* Power down permanently */
2128 struct iwl4965_card_state_cmd {
2129         __le32 status;          /* CARD_STATE_CMD_* request new power state */
2130 } __attribute__ ((packed));
2131
2132 /*
2133  * CARD_STATE_NOTIFICATION = 0xa1 (notification only, not a command)
2134  */
2135 struct iwl4965_card_state_notif {
2136         __le32 flags;
2137 } __attribute__ ((packed));
2138
2139 #define HW_CARD_DISABLED   0x01
2140 #define SW_CARD_DISABLED   0x02
2141 #define RF_CARD_DISABLED   0x04
2142 #define RXON_CARD_DISABLED 0x10
2143
2144 struct iwl_ct_kill_config {
2145         __le32   reserved;
2146         __le32   critical_temperature_M;
2147         __le32   critical_temperature_R;
2148 }  __attribute__ ((packed));
2149
2150 /******************************************************************************
2151  * (8)
2152  * Scan Commands, Responses, Notifications:
2153  *
2154  *****************************************************************************/
2155
2156 #define SCAN_CHANNEL_TYPE_PASSIVE __constant_cpu_to_le32(0)
2157 #define SCAN_CHANNEL_TYPE_ACTIVE  __constant_cpu_to_le32(1)
2158
2159 /**
2160  * struct iwl_scan_channel - entry in REPLY_SCAN_CMD channel table
2161  *
2162  * One for each channel in the scan list.
2163  * Each channel can independently select:
2164  * 1)  SSID for directed active scans
2165  * 2)  Txpower setting (for rate specified within Tx command)
2166  * 3)  How long to stay on-channel (behavior may be modified by quiet_time,
2167  *     quiet_plcp_th, good_CRC_th)
2168  *
2169  * To avoid uCode errors, make sure the following are true (see comments
2170  * under struct iwl_scan_cmd about max_out_time and quiet_time):
2171  * 1)  If using passive_dwell (i.e. passive_dwell != 0):
2172  *     active_dwell <= passive_dwell (< max_out_time if max_out_time != 0)
2173  * 2)  quiet_time <= active_dwell
2174  * 3)  If restricting off-channel time (i.e. max_out_time !=0):
2175  *     passive_dwell < max_out_time
2176  *     active_dwell < max_out_time
2177  */
2178 struct iwl_scan_channel {
2179         /*
2180          * type is defined as:
2181          * 0:0 1 = active, 0 = passive
2182          * 1:20 SSID direct bit map; if a bit is set, then corresponding
2183          *     SSID IE is transmitted in probe request.
2184          * 21:31 reserved
2185          */
2186         __le32 type;
2187         __le16 channel; /* band is selected by iwl_scan_cmd "flags" field */
2188         u8 tx_gain;             /* gain for analog radio */
2189         u8 dsp_atten;           /* gain for DSP */
2190         __le16 active_dwell;    /* in 1024-uSec TU (time units), typ 5-50 */
2191         __le16 passive_dwell;   /* in 1024-uSec TU (time units), typ 20-500 */
2192 } __attribute__ ((packed));
2193
2194 /**
2195  * struct iwl_ssid_ie - directed scan network information element
2196  *
2197  * Up to 4 of these may appear in REPLY_SCAN_CMD, selected by "type" field
2198  * in struct iwl4965_scan_channel; each channel may select different ssids from
2199  * among the 4 entries.  SSID IEs get transmitted in reverse order of entry.
2200  */
2201 struct iwl_ssid_ie {
2202         u8 id;
2203         u8 len;
2204         u8 ssid[32];
2205 } __attribute__ ((packed));
2206
2207 #define PROBE_OPTION_MAX                0x14
2208 #define TX_CMD_LIFE_TIME_INFINITE       __constant_cpu_to_le32(0xFFFFFFFF)
2209 #define IWL_GOOD_CRC_TH                 __constant_cpu_to_le16(1)
2210 #define IWL_MAX_SCAN_SIZE 1024
2211
2212 /*
2213  * REPLY_SCAN_CMD = 0x80 (command)
2214  *
2215  * The hardware scan command is very powerful; the driver can set it up to
2216  * maintain (relatively) normal network traffic while doing a scan in the
2217  * background.  The max_out_time and suspend_time control the ratio of how
2218  * long the device stays on an associated network channel ("service channel")
2219  * vs. how long it's away from the service channel, i.e. tuned to other channels
2220  * for scanning.
2221  *
2222  * max_out_time is the max time off-channel (in usec), and suspend_time
2223  * is how long (in "extended beacon" format) that the scan is "suspended"
2224  * after returning to the service channel.  That is, suspend_time is the
2225  * time that we stay on the service channel, doing normal work, between
2226  * scan segments.  The driver may set these parameters differently to support
2227  * scanning when associated vs. not associated, and light vs. heavy traffic
2228  * loads when associated.
2229  *
2230  * After receiving this command, the device's scan engine does the following;
2231  *
2232  * 1)  Sends SCAN_START notification to driver
2233  * 2)  Checks to see if it has time to do scan for one channel
2234  * 3)  Sends NULL packet, with power-save (PS) bit set to 1,
2235  *     to tell AP that we're going off-channel
2236  * 4)  Tunes to first channel in scan list, does active or passive scan
2237  * 5)  Sends SCAN_RESULT notification to driver
2238  * 6)  Checks to see if it has time to do scan on *next* channel in list
2239  * 7)  Repeats 4-6 until it no longer has time to scan the next channel
2240  *     before max_out_time expires
2241  * 8)  Returns to service channel
2242  * 9)  Sends NULL packet with PS=0 to tell AP that we're back
2243  * 10) Stays on service channel until suspend_time expires
2244  * 11) Repeats entire process 2-10 until list is complete
2245  * 12) Sends SCAN_COMPLETE notification
2246  *
2247  * For fast, efficient scans, the scan command also has support for staying on
2248  * a channel for just a short time, if doing active scanning and getting no
2249  * responses to the transmitted probe request.  This time is controlled by
2250  * quiet_time, and the number of received packets below which a channel is
2251  * considered "quiet" is controlled by quiet_plcp_threshold.
2252  *
2253  * For active scanning on channels that have regulatory restrictions against
2254  * blindly transmitting, the scan can listen before transmitting, to make sure
2255  * that there is already legitimate activity on the channel.  If enough
2256  * packets are cleanly received on the channel (controlled by good_CRC_th,
2257  * typical value 1), the scan engine starts transmitting probe requests.
2258  *
2259  * Driver must use separate scan commands for 2.4 vs. 5 GHz bands.
2260  *
2261  * To avoid uCode errors, see timing restrictions described under
2262  * struct iwl_scan_channel.
2263  */
2264 struct iwl_scan_cmd {
2265         __le16 len;
2266         u8 reserved0;
2267         u8 channel_count;       /* # channels in channel list */
2268         __le16 quiet_time;      /* dwell only this # millisecs on quiet channel
2269                                  * (only for active scan) */
2270         __le16 quiet_plcp_th;   /* quiet chnl is < this # pkts (typ. 1) */
2271         __le16 good_CRC_th;     /* passive -> active promotion threshold */
2272         __le16 rx_chain;        /* RXON_RX_CHAIN_* */
2273         __le32 max_out_time;    /* max usec to be away from associated (service)
2274                                  * channel */
2275         __le32 suspend_time;    /* pause scan this long (in "extended beacon
2276                                  * format") when returning to service chnl:
2277                                  * 3945; 31:24 # beacons, 19:0 additional usec,
2278                                  * 4965; 31:22 # beacons, 21:0 additional usec.
2279                                  */
2280         __le32 flags;           /* RXON_FLG_* */
2281         __le32 filter_flags;    /* RXON_FILTER_* */
2282
2283         /* For active scans (set to all-0s for passive scans).
2284          * Does not include payload.  Must specify Tx rate; no rate scaling. */
2285         struct iwl_tx_cmd tx_cmd;
2286
2287         /* For directed active scans (set to all-0s otherwise) */
2288         struct iwl_ssid_ie direct_scan[PROBE_OPTION_MAX];
2289
2290         /*
2291          * Probe request frame, followed by channel list.
2292          *
2293          * Size of probe request frame is specified by byte count in tx_cmd.
2294          * Channel list follows immediately after probe request frame.
2295          * Number of channels in list is specified by channel_count.
2296          * Each channel in list is of type:
2297          *
2298          * struct iwl4965_scan_channel channels[0];
2299          *
2300          * NOTE:  Only one band of channels can be scanned per pass.  You
2301          * must not mix 2.4GHz channels and 5.2GHz channels, and you must wait
2302          * for one scan to complete (i.e. receive SCAN_COMPLETE_NOTIFICATION)
2303          * before requesting another scan.
2304          */
2305         u8 data[0];
2306 } __attribute__ ((packed));
2307
2308 /* Can abort will notify by complete notification with abort status. */
2309 #define CAN_ABORT_STATUS        __constant_cpu_to_le32(0x1)
2310 /* complete notification statuses */
2311 #define ABORT_STATUS            0x2
2312
2313 /*
2314  * REPLY_SCAN_CMD = 0x80 (response)
2315  */
2316 struct iwl_scanreq_notification {
2317         __le32 status;          /* 1: okay, 2: cannot fulfill request */
2318 } __attribute__ ((packed));
2319
2320 /*
2321  * SCAN_START_NOTIFICATION = 0x82 (notification only, not a command)
2322  */
2323 struct iwl_scanstart_notification {
2324         __le32 tsf_low;
2325         __le32 tsf_high;
2326         __le32 beacon_timer;
2327         u8 channel;
2328         u8 band;
2329         u8 reserved[2];
2330         __le32 status;
2331 } __attribute__ ((packed));
2332
2333 #define  SCAN_OWNER_STATUS 0x1;
2334 #define  MEASURE_OWNER_STATUS 0x2;
2335
2336 #define NUMBER_OF_STATISTICS 1  /* first __le32 is good CRC */
2337 /*
2338  * SCAN_RESULTS_NOTIFICATION = 0x83 (notification only, not a command)
2339  */
2340 struct iwl_scanresults_notification {
2341         u8 channel;
2342         u8 band;
2343         u8 reserved[2];
2344         __le32 tsf_low;
2345         __le32 tsf_high;
2346         __le32 statistics[NUMBER_OF_STATISTICS];
2347 } __attribute__ ((packed));
2348
2349 /*
2350  * SCAN_COMPLETE_NOTIFICATION = 0x84 (notification only, not a command)
2351  */
2352 struct iwl_scancomplete_notification {
2353         u8 scanned_channels;
2354         u8 status;
2355         u8 reserved;
2356         u8 last_channel;
2357         __le32 tsf_low;
2358         __le32 tsf_high;
2359 } __attribute__ ((packed));
2360
2361
2362 /******************************************************************************
2363  * (9)
2364  * IBSS/AP Commands and Notifications:
2365  *
2366  *****************************************************************************/
2367
2368 /*
2369  * BEACON_NOTIFICATION = 0x90 (notification only, not a command)
2370  */
2371 struct iwl4965_beacon_notif {
2372         struct iwl4965_tx_resp beacon_notify_hdr;
2373         __le32 low_tsf;
2374         __le32 high_tsf;
2375         __le32 ibss_mgr_status;
2376 } __attribute__ ((packed));
2377
2378 /*
2379  * REPLY_TX_BEACON = 0x91 (command, has simple generic response)
2380  */
2381 struct iwl_tx_beacon_cmd {
2382         struct iwl_tx_cmd tx;
2383         __le16 tim_idx;
2384         u8 tim_size;
2385         u8 reserved1;
2386         struct ieee80211_hdr frame[0];  /* beacon frame */
2387 } __attribute__ ((packed));
2388
2389 /******************************************************************************
2390  * (10)
2391  * Statistics Commands and Notifications:
2392  *
2393  *****************************************************************************/
2394
2395 #define IWL_TEMP_CONVERT 260
2396
2397 #define SUP_RATE_11A_MAX_NUM_CHANNELS  8
2398 #define SUP_RATE_11B_MAX_NUM_CHANNELS  4
2399 #define SUP_RATE_11G_MAX_NUM_CHANNELS  12
2400
2401 /* Used for passing to driver number of successes and failures per rate */
2402 struct rate_histogram {
2403         union {
2404                 __le32 a[SUP_RATE_11A_MAX_NUM_CHANNELS];
2405                 __le32 b[SUP_RATE_11B_MAX_NUM_CHANNELS];
2406                 __le32 g[SUP_RATE_11G_MAX_NUM_CHANNELS];
2407         } success;
2408         union {
2409                 __le32 a[SUP_RATE_11A_MAX_NUM_CHANNELS];
2410                 __le32 b[SUP_RATE_11B_MAX_NUM_CHANNELS];
2411                 __le32 g[SUP_RATE_11G_MAX_NUM_CHANNELS];
2412         } failed;
2413 } __attribute__ ((packed));
2414
2415 /* statistics command response */
2416
2417 struct statistics_rx_phy {
2418         __le32 ina_cnt;
2419         __le32 fina_cnt;
2420         __le32 plcp_err;
2421         __le32 crc32_err;
2422         __le32 overrun_err;
2423         __le32 early_overrun_err;
2424         __le32 crc32_good;
2425         __le32 false_alarm_cnt;
2426         __le32 fina_sync_err_cnt;
2427         __le32 sfd_timeout;
2428         __le32 fina_timeout;
2429         __le32 unresponded_rts;
2430         __le32 rxe_frame_limit_overrun;
2431         __le32 sent_ack_cnt;
2432         __le32 sent_cts_cnt;
2433         __le32 sent_ba_rsp_cnt;
2434         __le32 dsp_self_kill;
2435         __le32 mh_format_err;
2436         __le32 re_acq_main_rssi_sum;
2437         __le32 reserved3;
2438 } __attribute__ ((packed));
2439
2440 struct statistics_rx_ht_phy {
2441         __le32 plcp_err;
2442         __le32 overrun_err;
2443         __le32 early_overrun_err;
2444         __le32 crc32_good;
2445         __le32 crc32_err;
2446         __le32 mh_format_err;
2447         __le32 agg_crc32_good;
2448         __le32 agg_mpdu_cnt;
2449         __le32 agg_cnt;
2450         __le32 reserved2;
2451 } __attribute__ ((packed));
2452
2453 struct statistics_rx_non_phy {
2454         __le32 bogus_cts;       /* CTS received when not expecting CTS */
2455         __le32 bogus_ack;       /* ACK received when not expecting ACK */
2456         __le32 non_bssid_frames;        /* number of frames with BSSID that
2457                                          * doesn't belong to the STA BSSID */
2458         __le32 filtered_frames; /* count frames that were dumped in the
2459                                  * filtering process */
2460         __le32 non_channel_beacons;     /* beacons with our bss id but not on
2461                                          * our serving channel */
2462         __le32 channel_beacons; /* beacons with our bss id and in our
2463                                  * serving channel */
2464         __le32 num_missed_bcon; /* number of missed beacons */
2465         __le32 adc_rx_saturation_time;  /* count in 0.8us units the time the
2466                                          * ADC was in saturation */
2467         __le32 ina_detection_search_time;/* total time (in 0.8us) searched
2468                                           * for INA */
2469         __le32 beacon_silence_rssi_a;   /* RSSI silence after beacon frame */
2470         __le32 beacon_silence_rssi_b;   /* RSSI silence after beacon frame */
2471         __le32 beacon_silence_rssi_c;   /* RSSI silence after beacon frame */
2472         __le32 interference_data_flag;  /* flag for interference data
2473                                          * availability. 1 when data is
2474                                          * available. */
2475         __le32 channel_load;            /* counts RX Enable time in uSec */
2476         __le32 dsp_false_alarms;        /* DSP false alarm (both OFDM
2477                                          * and CCK) counter */
2478         __le32 beacon_rssi_a;
2479         __le32 beacon_rssi_b;
2480         __le32 beacon_rssi_c;
2481         __le32 beacon_energy_a;
2482         __le32 beacon_energy_b;
2483         __le32 beacon_energy_c;
2484 } __attribute__ ((packed));
2485
2486 struct statistics_rx {
2487         struct statistics_rx_phy ofdm;
2488         struct statistics_rx_phy cck;
2489         struct statistics_rx_non_phy general;
2490         struct statistics_rx_ht_phy ofdm_ht;
2491 } __attribute__ ((packed));
2492
2493 struct statistics_tx_non_phy_agg {
2494         __le32 ba_timeout;
2495         __le32 ba_reschedule_frames;
2496         __le32 scd_query_agg_frame_cnt;
2497         __le32 scd_query_no_agg;
2498         __le32 scd_query_agg;
2499         __le32 scd_query_mismatch;
2500         __le32 frame_not_ready;
2501         __le32 underrun;
2502         __le32 bt_prio_kill;
2503         __le32 rx_ba_rsp_cnt;
2504         __le32 reserved2;
2505         __le32 reserved3;
2506 } __attribute__ ((packed));
2507
2508 struct statistics_tx {
2509         __le32 preamble_cnt;
2510         __le32 rx_detected_cnt;
2511         __le32 bt_prio_defer_cnt;
2512         __le32 bt_prio_kill_cnt;
2513         __le32 few_bytes_cnt;
2514         __le32 cts_timeout;
2515         __le32 ack_timeout;
2516         __le32 expected_ack_cnt;
2517         __le32 actual_ack_cnt;
2518         __le32 dump_msdu_cnt;
2519         __le32 burst_abort_next_frame_mismatch_cnt;
2520         __le32 burst_abort_missing_next_frame_cnt;
2521         __le32 cts_timeout_collision;
2522         __le32 ack_or_ba_timeout_collision;
2523         struct statistics_tx_non_phy_agg agg;
2524 } __attribute__ ((packed));
2525
2526 struct statistics_dbg {
2527         __le32 burst_check;
2528         __le32 burst_count;
2529         __le32 reserved[4];
2530 } __attribute__ ((packed));
2531
2532 struct statistics_div {
2533         __le32 tx_on_a;
2534         __le32 tx_on_b;
2535         __le32 exec_time;
2536         __le32 probe_time;
2537         __le32 reserved1;
2538         __le32 reserved2;
2539 } __attribute__ ((packed));
2540
2541 struct statistics_general {
2542         __le32 temperature;
2543         __le32 temperature_m;
2544         struct statistics_dbg dbg;
2545         __le32 sleep_time;
2546         __le32 slots_out;
2547         __le32 slots_idle;
2548         __le32 ttl_timestamp;
2549         struct statistics_div div;
2550         __le32 rx_enable_counter;
2551         __le32 reserved1;
2552         __le32 reserved2;
2553         __le32 reserved3;
2554 } __attribute__ ((packed));
2555
2556 /*
2557  * REPLY_STATISTICS_CMD = 0x9c,
2558  * 3945 and 4965 identical.
2559  *
2560  * This command triggers an immediate response containing uCode statistics.
2561  * The response is in the same format as STATISTICS_NOTIFICATION 0x9d, below.
2562  *
2563  * If the CLEAR_STATS configuration flag is set, uCode will clear its
2564  * internal copy of the statistics (counters) after issuing the response.
2565  * This flag does not affect STATISTICS_NOTIFICATIONs after beacons (see below).
2566  *
2567  * If the DISABLE_NOTIF configuration flag is set, uCode will not issue
2568  * STATISTICS_NOTIFICATIONs after received beacons (see below).  This flag
2569  * does not affect the response to the REPLY_STATISTICS_CMD 0x9c itself.
2570  */
2571 #define IWL_STATS_CONF_CLEAR_STATS __constant_cpu_to_le32(0x1)  /* see above */
2572 #define IWL_STATS_CONF_DISABLE_NOTIF __constant_cpu_to_le32(0x2)/* see above */
2573 struct iwl_statistics_cmd {
2574         __le32 configuration_flags;     /* IWL_STATS_CONF_* */
2575 } __attribute__ ((packed));
2576
2577 /*
2578  * STATISTICS_NOTIFICATION = 0x9d (notification only, not a command)
2579  *
2580  * By default, uCode issues this notification after receiving a beacon
2581  * while associated.  To disable this behavior, set DISABLE_NOTIF flag in the
2582  * REPLY_STATISTICS_CMD 0x9c, above.
2583  *
2584  * Statistics counters continue to increment beacon after beacon, but are
2585  * cleared when changing channels or when driver issues REPLY_STATISTICS_CMD
2586  * 0x9c with CLEAR_STATS bit set (see above).
2587  *
2588  * uCode also issues this notification during scans.  uCode clears statistics
2589  * appropriately so that each notification contains statistics for only the
2590  * one channel that has just been scanned.
2591  */
2592 #define STATISTICS_REPLY_FLG_BAND_24G_MSK         __constant_cpu_to_le32(0x2)
2593 #define STATISTICS_REPLY_FLG_FAT_MODE_MSK         __constant_cpu_to_le32(0x8)
2594 struct iwl_notif_statistics {
2595         __le32 flag;
2596         struct statistics_rx rx;
2597         struct statistics_tx tx;
2598         struct statistics_general general;
2599 } __attribute__ ((packed));
2600
2601
2602 /*
2603  * MISSED_BEACONS_NOTIFICATION = 0xa2 (notification only, not a command)
2604  */
2605 /* if ucode missed CONSECUTIVE_MISSED_BCONS_TH beacons in a row,
2606  * then this notification will be sent. */
2607 #define CONSECUTIVE_MISSED_BCONS_TH 20
2608
2609 struct iwl4965_missed_beacon_notif {
2610         __le32 consequtive_missed_beacons;
2611         __le32 total_missed_becons;
2612         __le32 num_expected_beacons;
2613         __le32 num_recvd_beacons;
2614 } __attribute__ ((packed));
2615
2616
2617 /******************************************************************************
2618  * (11)
2619  * Rx Calibration Commands:
2620  *
2621  * With the uCode used for open source drivers, most Tx calibration (except
2622  * for Tx Power) and most Rx calibration is done by uCode during the
2623  * "initialize" phase of uCode boot.  Driver must calibrate only:
2624  *
2625  * 1)  Tx power (depends on temperature), described elsewhere
2626  * 2)  Receiver gain balance (optimize MIMO, and detect disconnected antennas)
2627  * 3)  Receiver sensitivity (to optimize signal detection)
2628  *
2629  *****************************************************************************/
2630
2631 /**
2632  * SENSITIVITY_CMD = 0xa8 (command, has simple generic response)
2633  *
2634  * This command sets up the Rx signal detector for a sensitivity level that
2635  * is high enough to lock onto all signals within the associated network,
2636  * but low enough to ignore signals that are below a certain threshold, so as
2637  * not to have too many "false alarms".  False alarms are signals that the
2638  * Rx DSP tries to lock onto, but then discards after determining that they
2639  * are noise.
2640  *
2641  * The optimum number of false alarms is between 5 and 50 per 200 TUs
2642  * (200 * 1024 uSecs, i.e. 204.8 milliseconds) of actual Rx time (i.e.
2643  * time listening, not transmitting).  Driver must adjust sensitivity so that
2644  * the ratio of actual false alarms to actual Rx time falls within this range.
2645  *
2646  * While associated, uCode delivers STATISTICS_NOTIFICATIONs after each
2647  * received beacon.  These provide information to the driver to analyze the
2648  * sensitivity.  Don't analyze statistics that come in from scanning, or any
2649  * other non-associated-network source.  Pertinent statistics include:
2650  *
2651  * From "general" statistics (struct statistics_rx_non_phy):
2652  *
2653  * (beacon_energy_[abc] & 0x0FF00) >> 8 (unsigned, higher value is lower level)
2654  *   Measure of energy of desired signal.  Used for establishing a level
2655  *   below which the device does not detect signals.
2656  *
2657  * (beacon_silence_rssi_[abc] & 0x0FF00) >> 8 (unsigned, units in dB)
2658  *   Measure of background noise in silent period after beacon.
2659  *
2660  * channel_load
2661  *   uSecs of actual Rx time during beacon period (varies according to
2662  *   how much time was spent transmitting).
2663  *
2664  * From "cck" and "ofdm" statistics (struct statistics_rx_phy), separately:
2665  *
2666  * false_alarm_cnt
2667  *   Signal locks abandoned early (before phy-level header).
2668  *
2669  * plcp_err
2670  *   Signal locks abandoned late (during phy-level header).
2671  *
2672  * NOTE:  Both false_alarm_cnt and plcp_err increment monotonically from
2673  *        beacon to beacon, i.e. each value is an accumulation of all errors
2674  *        before and including the latest beacon.  Values will wrap around to 0
2675  *        after counting up to 2^32 - 1.  Driver must differentiate vs.
2676  *        previous beacon's values to determine # false alarms in the current
2677  *        beacon period.
2678  *
2679  * Total number of false alarms = false_alarms + plcp_errs
2680  *
2681  * For OFDM, adjust the following table entries in struct iwl_sensitivity_cmd
2682  * (notice that the start points for OFDM are at or close to settings for
2683  * maximum sensitivity):
2684  *
2685  *                                             START  /  MIN  /  MAX
2686  *   HD_AUTO_CORR32_X1_TH_ADD_MIN_INDEX          90   /   85  /  120
2687  *   HD_AUTO_CORR32_X1_TH_ADD_MIN_MRC_INDEX     170   /  170  /  210
2688  *   HD_AUTO_CORR32_X4_TH_ADD_MIN_INDEX         105   /  105  /  140
2689  *   HD_AUTO_CORR32_X4_TH_ADD_MIN_MRC_INDEX     220   /  220  /  270
2690  *
2691  *   If actual rate of OFDM false alarms (+ plcp_errors) is too high
2692  *   (greater than 50 for each 204.8 msecs listening), reduce sensitivity
2693  *   by *adding* 1 to all 4 of the table entries above, up to the max for
2694  *   each entry.  Conversely, if false alarm rate is too low (less than 5
2695  *   for each 204.8 msecs listening), *subtract* 1 from each entry to
2696  *   increase sensitivity.
2697  *
2698  * For CCK sensitivity, keep track of the following:
2699  *
2700  *   1).  20-beacon history of maximum background noise, indicated by
2701  *        (beacon_silence_rssi_[abc] & 0x0FF00), units in dB, across the
2702  *        3 receivers.  For any given beacon, the "silence reference" is
2703  *        the maximum of last 60 samples (20 beacons * 3 receivers).
2704  *
2705  *   2).  10-beacon history of strongest signal level, as indicated
2706  *        by (beacon_energy_[abc] & 0x0FF00) >> 8, across the 3 receivers,
2707  *        i.e. the strength of the signal through the best receiver at the
2708  *        moment.  These measurements are "upside down", with lower values
2709  *        for stronger signals, so max energy will be *minimum* value.
2710  *
2711  *        Then for any given beacon, the driver must determine the *weakest*
2712  *        of the strongest signals; this is the minimum level that needs to be
2713  *        successfully detected, when using the best receiver at the moment.
2714  *        "Max cck energy" is the maximum (higher value means lower energy!)
2715  *        of the last 10 minima.  Once this is determined, driver must add
2716  *        a little margin by adding "6" to it.
2717  *
2718  *   3).  Number of consecutive beacon periods with too few false alarms.
2719  *        Reset this to 0 at the first beacon period that falls within the
2720  *        "good" range (5 to 50 false alarms per 204.8 milliseconds rx).
2721  *
2722  * Then, adjust the following CCK table entries in struct iwl_sensitivity_cmd
2723  * (notice that the start points for CCK are at maximum sensitivity):
2724  *
2725  *                                             START  /  MIN  /  MAX
2726  *   HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX         125   /  125  /  200
2727  *   HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX     200   /  200  /  400
2728  *   HD_MIN_ENERGY_CCK_DET_INDEX                100   /    0  /  100
2729  *
2730  *   If actual rate of CCK false alarms (+ plcp_errors) is too high
2731  *   (greater than 50 for each 204.8 msecs listening), method for reducing
2732  *   sensitivity is:
2733  *
2734  *   1)  *Add* 3 to value in HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX,
2735  *       up to max 400.
2736  *
2737  *   2)  If current value in HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX is < 160,
2738  *       sensitivity has been reduced a significant amount; bring it up to
2739  *       a moderate 161.  Otherwise, *add* 3, up to max 200.
2740  *
2741  *   3)  a)  If current value in HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX is > 160,
2742  *       sensitivity has been reduced only a moderate or small amount;
2743  *       *subtract* 2 from value in HD_MIN_ENERGY_CCK_DET_INDEX,
2744  *       down to min 0.  Otherwise (if gain has been significantly reduced),
2745  *       don't change the HD_MIN_ENERGY_CCK_DET_INDEX value.
2746  *
2747  *       b)  Save a snapshot of the "silence reference".
2748  *
2749  *   If actual rate of CCK false alarms (+ plcp_errors) is too low
2750  *   (less than 5 for each 204.8 msecs listening), method for increasing
2751  *   sensitivity is used only if:
2752  *
2753  *   1a)  Previous beacon did not have too many false alarms
2754  *   1b)  AND difference between previous "silence reference" and current
2755  *        "silence reference" (prev - current) is 2 or more,
2756  *   OR 2)  100 or more consecutive beacon periods have had rate of
2757  *          less than 5 false alarms per 204.8 milliseconds rx time.
2758  *
2759  *   Method for increasing sensitivity:
2760  *
2761  *   1)  *Subtract* 3 from value in HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX,
2762  *       down to min 125.
2763  *
2764  *   2)  *Subtract* 3 from value in HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX,
2765  *       down to min 200.
2766  *
2767  *   3)  *Add* 2 to value in HD_MIN_ENERGY_CCK_DET_INDEX, up to max 100.
2768  *
2769  *   If actual rate of CCK false alarms (+ plcp_errors) is within good range
2770  *   (between 5 and 50 for each 204.8 msecs listening):
2771  *
2772  *   1)  Save a snapshot of the silence reference.
2773  *
2774  *   2)  If previous beacon had too many CCK false alarms (+ plcp_errors),
2775  *       give some extra margin to energy threshold by *subtracting* 8
2776  *       from value in HD_MIN_ENERGY_CCK_DET_INDEX.
2777  *
2778  *   For all cases (too few, too many, good range), make sure that the CCK
2779  *   detection threshold (energy) is below the energy level for robust
2780  *   detection over the past 10 beacon periods, the "Max cck energy".
2781  *   Lower values mean higher energy; this means making sure that the value
2782  *   in HD_MIN_ENERGY_CCK_DET_INDEX is at or *above* "Max cck energy".
2783  *
2784  * Driver should set the following entries to fixed values:
2785  *
2786  *   HD_MIN_ENERGY_OFDM_DET_INDEX               100
2787  *   HD_BARKER_CORR_TH_ADD_MIN_INDEX            190
2788  *   HD_BARKER_CORR_TH_ADD_MIN_MRC_INDEX        390
2789  *   HD_OFDM_ENERGY_TH_IN_INDEX                  62
2790  */
2791
2792 /*
2793  * Table entries in SENSITIVITY_CMD (struct iwl_sensitivity_cmd)
2794  */
2795 #define HD_TABLE_SIZE  (11)     /* number of entries */
2796 #define HD_MIN_ENERGY_CCK_DET_INDEX                 (0) /* table indexes */
2797 #define HD_MIN_ENERGY_OFDM_DET_INDEX                (1)
2798 #define HD_AUTO_CORR32_X1_TH_ADD_MIN_INDEX          (2)
2799 #define HD_AUTO_CORR32_X1_TH_ADD_MIN_MRC_INDEX      (3)
2800 #define HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX      (4)
2801 #define HD_AUTO_CORR32_X4_TH_ADD_MIN_INDEX          (5)
2802 #define HD_AUTO_CORR32_X4_TH_ADD_MIN_MRC_INDEX      (6)
2803 #define HD_BARKER_CORR_TH_ADD_MIN_INDEX             (7)
2804 #define HD_BARKER_CORR_TH_ADD_MIN_MRC_INDEX         (8)
2805 #define HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX          (9)
2806 #define HD_OFDM_ENERGY_TH_IN_INDEX                  (10)
2807
2808 /* Control field in struct iwl_sensitivity_cmd */
2809 #define SENSITIVITY_CMD_CONTROL_DEFAULT_TABLE   __constant_cpu_to_le16(0)
2810 #define SENSITIVITY_CMD_CONTROL_WORK_TABLE      __constant_cpu_to_le16(1)
2811
2812 /**
2813  * struct iwl_sensitivity_cmd
2814  * @control:  (1) updates working table, (0) updates default table
2815  * @table:  energy threshold values, use HD_* as index into table
2816  *
2817  * Always use "1" in "control" to update uCode's working table and DSP.
2818  */
2819 struct iwl_sensitivity_cmd {
2820         __le16 control;                 /* always use "1" */
2821         __le16 table[HD_TABLE_SIZE];    /* use HD_* as index */
2822 } __attribute__ ((packed));
2823
2824
2825 /**
2826  * REPLY_PHY_CALIBRATION_CMD = 0xb0 (command, has simple generic response)
2827  *
2828  * This command sets the relative gains of 4965's 3 radio receiver chains.
2829  *
2830  * After the first association, driver should accumulate signal and noise
2831  * statistics from the STATISTICS_NOTIFICATIONs that follow the first 20
2832  * beacons from the associated network (don't collect statistics that come
2833  * in from scanning, or any other non-network source).
2834  *
2835  * DISCONNECTED ANTENNA:
2836  *
2837  * Driver should determine which antennas are actually connected, by comparing
2838  * average beacon signal levels for the 3 Rx chains.  Accumulate (add) the
2839  * following values over 20 beacons, one accumulator for each of the chains
2840  * a/b/c, from struct statistics_rx_non_phy:
2841  *
2842  * beacon_rssi_[abc] & 0x0FF (unsigned, units in dB)
2843  *
2844  * Find the strongest signal from among a/b/c.  Compare the other two to the
2845  * strongest.  If any signal is more than 15 dB (times 20, unless you
2846  * divide the accumulated values by 20) below the strongest, the driver
2847  * considers that antenna to be disconnected, and should not try to use that
2848  * antenna/chain for Rx or Tx.  If both A and B seem to be disconnected,
2849  * driver should declare the stronger one as connected, and attempt to use it
2850  * (A and B are the only 2 Tx chains!).
2851  *
2852  *
2853  * RX BALANCE:
2854  *
2855  * Driver should balance the 3 receivers (but just the ones that are connected
2856  * to antennas, see above) for gain, by comparing the average signal levels
2857  * detected during the silence after each beacon (background noise).
2858  * Accumulate (add) the following values over 20 beacons, one accumulator for
2859  * each of the chains a/b/c, from struct statistics_rx_non_phy:
2860  *
2861  * beacon_silence_rssi_[abc] & 0x0FF (unsigned, units in dB)
2862  *
2863  * Find the weakest background noise level from among a/b/c.  This Rx chain
2864  * will be the reference, with 0 gain adjustment.  Attenuate other channels by
2865  * finding noise difference:
2866  *
2867  * (accum_noise[i] - accum_noise[reference]) / 30
2868  *
2869  * The "30" adjusts the dB in the 20 accumulated samples to units of 1.5 dB.
2870  * For use in diff_gain_[abc] fields of struct iwl_calibration_cmd, the
2871  * driver should limit the difference results to a range of 0-3 (0-4.5 dB),
2872  * and set bit 2 to indicate "reduce gain".  The value for the reference
2873  * (weakest) chain should be "0".
2874  *
2875  * diff_gain_[abc] bit fields:
2876  *   2: (1) reduce gain, (0) increase gain
2877  * 1-0: amount of gain, units of 1.5 dB
2878  */
2879
2880 /* Phy calibration command for series */
2881
2882 enum {
2883         IWL_PHY_CALIBRATE_DIFF_GAIN_CMD         = 7,
2884         IWL_PHY_CALIBRATE_DC_CMD                = 8,
2885         IWL_PHY_CALIBRATE_LO_CMD                = 9,
2886         IWL_PHY_CALIBRATE_RX_BB_CMD             = 10,
2887         IWL_PHY_CALIBRATE_TX_IQ_CMD             = 11,
2888         IWL_PHY_CALIBRATE_RX_IQ_CMD             = 12,
2889         IWL_PHY_CALIBRATION_NOISE_CMD           = 13,
2890         IWL_PHY_CALIBRATE_AGC_TABLE_CMD         = 14,
2891         IWL_PHY_CALIBRATE_CRYSTAL_FRQ_CMD       = 15,
2892         IWL_PHY_CALIBRATE_BASE_BAND_CMD         = 16,
2893         IWL_PHY_CALIBRATE_TX_IQ_PERD_CMD        = 17,
2894         IWL_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD = 18,
2895         IWL_PHY_CALIBRATE_CHAIN_NOISE_GAIN_CMD  = 19,
2896 };
2897
2898
2899 struct iwl_cal_xtal_freq {
2900         u8 cap_pin1;
2901         u8 cap_pin2;
2902 } __attribute__ ((packed));
2903
2904 #define IWL_CALIB_INIT_CFG_ALL  __constant_cpu_to_le32(0xffffffff)
2905
2906 struct iwl_calib_cfg_elmnt_s {
2907         __le32 is_enable;
2908         __le32 start;
2909         __le32 send_res;
2910         __le32 apply_res;
2911         __le32 reserved;
2912 } __attribute__ ((packed));
2913
2914 struct iwl_calib_cfg_status_s {
2915         struct iwl_calib_cfg_elmnt_s once;
2916         struct iwl_calib_cfg_elmnt_s perd;
2917         __le32 flags;
2918 } __attribute__ ((packed));
2919
2920 struct iwl_calib_cfg_cmd {
2921         struct iwl_calib_cfg_status_s ucd_calib_cfg;
2922         struct iwl_calib_cfg_status_s drv_calib_cfg;
2923         __le32 reserved1;
2924 } __attribute__ ((packed));
2925
2926 struct iwl_calib_hdr {
2927         u8 op_code;
2928         u8 first_group;
2929         u8 groups_num;
2930         u8 data_valid;
2931 } __attribute__ ((packed));
2932
2933 struct iwl_calib_cmd {
2934         struct iwl_calib_hdr hdr;
2935         u8 data[0];
2936 } __attribute__ ((packed));
2937
2938 /* "Differential Gain" opcode used in REPLY_PHY_CALIBRATION_CMD. */
2939
2940 struct iwl_calib_diff_gain_cmd {
2941         u8 opCode;              /* IWL_PHY_CALIBRATE_DIFF_GAIN_CMD (7) */
2942         u8 flags;               /* not used */
2943         __le16 reserved;
2944         s8 diff_gain_a;         /* see above */
2945         s8 diff_gain_b;
2946         s8 diff_gain_c;
2947         u8 reserved1;
2948 } __attribute__ ((packed));
2949
2950 struct iwl_calib_chain_noise_reset_cmd {
2951         u8 op_code;     /* IWL_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD */
2952         u8 flags;       /* not used */
2953         __le16 reserved;
2954 } __attribute__ ((packed));
2955
2956 struct iwl_calib_chain_noise_gain_cmd {
2957         u8 op_code;     /* IWL_PHY_CALIBRATE_CHAIN_NOISE_GAIN_CMD */
2958         u8 flags;       /* not used */
2959         __le16 reserved;
2960         u8 delta_gain_1;
2961         u8 delta_gain_2;
2962         __le16 reserved1;
2963 } __attribute__ ((packed));
2964
2965 /******************************************************************************
2966  * (12)
2967  * Miscellaneous Commands:
2968  *
2969  *****************************************************************************/
2970
2971 /*
2972  * LEDs Command & Response
2973  * REPLY_LEDS_CMD = 0x48 (command, has simple generic response)
2974  *
2975  * For each of 3 possible LEDs (Activity/Link/Tech, selected by "id" field),
2976  * this command turns it on or off, or sets up a periodic blinking cycle.
2977  */
2978 struct iwl_led_cmd {
2979         __le32 interval;        /* "interval" in uSec */
2980         u8 id;                  /* 1: Activity, 2: Link, 3: Tech */
2981         u8 off;                 /* # intervals off while blinking;
2982                                  * "0", with >0 "on" value, turns LED on */
2983         u8 on;                  /* # intervals on while blinking;
2984                                  * "0", regardless of "off", turns LED off */
2985         u8 reserved;
2986 } __attribute__ ((packed));
2987
2988 /*
2989  * Coexistence WIFI/WIMAX  Command
2990  * COEX_PRIORITY_TABLE_CMD = 0x5a
2991  *
2992  */
2993 enum {
2994         COEX_UNASSOC_IDLE               = 0,
2995         COEX_UNASSOC_MANUAL_SCAN        = 1,
2996         COEX_UNASSOC_AUTO_SCAN          = 2,
2997         COEX_CALIBRATION                = 3,
2998         COEX_PERIODIC_CALIBRATION       = 4,
2999         COEX_CONNECTION_ESTAB           = 5,
3000         COEX_ASSOCIATED_IDLE            = 6,
3001         COEX_ASSOC_MANUAL_SCAN          = 7,
3002         COEX_ASSOC_AUTO_SCAN            = 8,
3003         COEX_ASSOC_ACTIVE_LEVEL         = 9,
3004         COEX_RF_ON                      = 10,
3005         COEX_RF_OFF                     = 11,
3006         COEX_STAND_ALONE_DEBUG          = 12,
3007         COEX_IPAN_ASSOC_LEVEL           = 13,
3008         COEX_RSRVD1                     = 14,
3009         COEX_RSRVD2                     = 15,
3010         COEX_NUM_OF_EVENTS              = 16
3011 };
3012
3013 struct iwl_wimax_coex_event_entry {
3014         u8 request_prio;
3015         u8 win_medium_prio;
3016         u8 reserved;
3017         u8 flags;
3018 } __attribute__ ((packed));
3019
3020 /* COEX flag masks */
3021
3022 /* Station table is valid */
3023 #define COEX_FLAGS_STA_TABLE_VALID_MSK      (0x1)
3024 /* UnMask wake up src at unassociated sleep */
3025 #define COEX_FLAGS_UNASSOC_WA_UNMASK_MSK    (0x4)
3026 /* UnMask wake up src at associated sleep */
3027 #define COEX_FLAGS_ASSOC_WA_UNMASK_MSK      (0x8)
3028 /* Enable CoEx feature. */
3029 #define COEX_FLAGS_COEX_ENABLE_MSK          (0x80)
3030
3031 struct iwl_wimax_coex_cmd {
3032         u8 flags;
3033         u8 reserved[3];
3034         struct iwl_wimax_coex_event_entry sta_prio[COEX_NUM_OF_EVENTS];
3035 } __attribute__ ((packed));
3036
3037 /******************************************************************************
3038  * (13)
3039  * Union of all expected notifications/responses:
3040  *
3041  *****************************************************************************/
3042
3043 struct iwl_rx_packet {
3044         __le32 len;
3045         struct iwl_cmd_header hdr;
3046         union {
3047                 struct iwl_alive_resp alive_frame;
3048                 struct iwl4965_rx_frame rx_frame;
3049                 struct iwl4965_tx_resp tx_resp;
3050                 struct iwl4965_spectrum_notification spectrum_notif;
3051                 struct iwl4965_csa_notification csa_notif;
3052                 struct iwl_error_resp err_resp;
3053                 struct iwl4965_card_state_notif card_state_notif;
3054                 struct iwl4965_beacon_notif beacon_status;
3055                 struct iwl_add_sta_resp add_sta;
3056                 struct iwl_rem_sta_resp rem_sta;
3057                 struct iwl4965_sleep_notification sleep_notif;
3058                 struct iwl4965_spectrum_resp spectrum;
3059                 struct iwl_notif_statistics stats;
3060                 struct iwl_compressed_ba_resp compressed_ba;
3061                 struct iwl4965_missed_beacon_notif missed_beacon;
3062                 __le32 status;
3063                 u8 raw[0];
3064         } u;
3065 } __attribute__ ((packed));
3066
3067 #define IWL_RX_FRAME_SIZE        (4 + sizeof(struct iwl4965_rx_frame))
3068
3069 #endif                          /* __iwl_commands_h__ */