xref: /linux/drivers/net/wireless/intel/iwlegacy/commands.h (revision 91a4855d6c03e770e42f17c798a36a3c46e63de2) !
1 /******************************************************************************
2  *
3  * This file is provided under a dual BSD/GPLv2 license.  When using or
4  * redistributing this file, you may do so under either license.
5  *
6  * GPL LICENSE SUMMARY
7  *
8  * Copyright(c) 2005 - 2011 Intel Corporation. All rights reserved.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of version 2 of the GNU General Public License as
12  * published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22  * USA
23  *
24  * The full GNU General Public License is included in this distribution
25  * in the file called LICENSE.GPL.
26  *
27  * Contact Information:
28  *  Intel Linux Wireless <ilw@linux.intel.com>
29  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30  *
31  * BSD LICENSE
32  *
33  * Copyright(c) 2005 - 2011 Intel Corporation. All rights reserved.
34  * All rights reserved.
35  *
36  * Redistribution and use in source and binary forms, with or without
37  * modification, are permitted provided that the following conditions
38  * are met:
39  *
40  *  * Redistributions of source code must retain the above copyright
41  *    notice, this list of conditions and the following disclaimer.
42  *  * Redistributions in binary form must reproduce the above copyright
43  *    notice, this list of conditions and the following disclaimer in
44  *    the documentation and/or other materials provided with the
45  *    distribution.
46  *  * Neither the name Intel Corporation nor the names of its
47  *    contributors may be used to endorse or promote products derived
48  *    from this software without specific prior written permission.
49  *
50  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61  *
62  *****************************************************************************/
63 
64 #ifndef __il_commands_h__
65 #define __il_commands_h__
66 
67 #include <linux/ieee80211.h>
68 
69 struct il_priv;
70 
71 /* uCode version contains 4 values: Major/Minor/API/Serial */
72 #define IL_UCODE_MAJOR(ver)	(((ver) & 0xFF000000) >> 24)
73 #define IL_UCODE_MINOR(ver)	(((ver) & 0x00FF0000) >> 16)
74 #define IL_UCODE_API(ver)	(((ver) & 0x0000FF00) >> 8)
75 #define IL_UCODE_SERIAL(ver)	((ver) & 0x000000FF)
76 
77 /* Tx rates */
78 #define IL_CCK_RATES	4
79 #define IL_OFDM_RATES	8
80 #define IL_MAX_RATES	(IL_CCK_RATES + IL_OFDM_RATES)
81 
82 enum {
83 	N_ALIVE = 0x1,
84 	N_ERROR = 0x2,
85 
86 	/* RXON and QOS commands */
87 	C_RXON = 0x10,
88 	C_RXON_ASSOC = 0x11,
89 	C_QOS_PARAM = 0x13,
90 	C_RXON_TIMING = 0x14,
91 
92 	/* Multi-Station support */
93 	C_ADD_STA = 0x18,
94 	C_REM_STA = 0x19,
95 
96 	/* Security */
97 	C_WEPKEY = 0x20,
98 
99 	/* RX, TX, LEDs */
100 	N_3945_RX = 0x1b,	/* 3945 only */
101 	C_TX = 0x1c,
102 	C_RATE_SCALE = 0x47,	/* 3945 only */
103 	C_LEDS = 0x48,
104 	C_TX_LINK_QUALITY_CMD = 0x4e,	/* for 4965 */
105 
106 	/* 802.11h related */
107 	C_CHANNEL_SWITCH = 0x72,
108 	N_CHANNEL_SWITCH = 0x73,
109 	C_SPECTRUM_MEASUREMENT = 0x74,
110 	N_SPECTRUM_MEASUREMENT = 0x75,
111 
112 	/* Power Management */
113 	C_POWER_TBL = 0x77,
114 	N_PM_SLEEP = 0x7A,
115 	N_PM_DEBUG_STATS = 0x7B,
116 
117 	/* Scan commands and notifications */
118 	C_SCAN = 0x80,
119 	C_SCAN_ABORT = 0x81,
120 	N_SCAN_START = 0x82,
121 	N_SCAN_RESULTS = 0x83,
122 	N_SCAN_COMPLETE = 0x84,
123 
124 	/* IBSS/AP commands */
125 	N_BEACON = 0x90,
126 	C_TX_BEACON = 0x91,
127 
128 	/* Miscellaneous commands */
129 	C_TX_PWR_TBL = 0x97,
130 
131 	/* Bluetooth device coexistence config command */
132 	C_BT_CONFIG = 0x9b,
133 
134 	/* Statistics */
135 	C_STATS = 0x9c,
136 	N_STATS = 0x9d,
137 
138 	/* RF-KILL commands and notifications */
139 	N_CARD_STATE = 0xa1,
140 
141 	/* Missed beacons notification */
142 	N_MISSED_BEACONS = 0xa2,
143 
144 	C_CT_KILL_CONFIG = 0xa4,
145 	C_SENSITIVITY = 0xa8,
146 	C_PHY_CALIBRATION = 0xb0,
147 	N_RX_PHY = 0xc0,
148 	N_RX_MPDU = 0xc1,
149 	N_RX = 0xc3,
150 	N_COMPRESSED_BA = 0xc5,
151 
152 	IL_CN_MAX = 0xff
153 };
154 
155 /******************************************************************************
156  * (0)
157  * Commonly used structures and definitions:
158  * Command header, rate_n_flags, txpower
159  *
160  *****************************************************************************/
161 
162 /* il_cmd_header flags value */
163 #define IL_CMD_FAILED_MSK 0x40
164 
165 #define SEQ_TO_QUEUE(s)	(((s) >> 8) & 0x1f)
166 #define QUEUE_TO_SEQ(q)	(((q) & 0x1f) << 8)
167 #define SEQ_TO_IDX(s)	((s) & 0xff)
168 #define IDX_TO_SEQ(i)	((i) & 0xff)
169 #define SEQ_HUGE_FRAME	cpu_to_le16(0x4000)
170 #define SEQ_RX_FRAME	cpu_to_le16(0x8000)
171 
172 /**
173  * struct il_cmd_header
174  *
175  * This header format appears in the beginning of each command sent from the
176  * driver, and each response/notification received from uCode.
177  */
178 struct il_cmd_header {
179 	u8 cmd;			/* Command ID:  C_RXON, etc. */
180 	u8 flags;		/* 0:5 reserved, 6 abort, 7 internal */
181 	/*
182 	 * The driver sets up the sequence number to values of its choosing.
183 	 * uCode does not use this value, but passes it back to the driver
184 	 * when sending the response to each driver-originated command, so
185 	 * the driver can match the response to the command.  Since the values
186 	 * don't get used by uCode, the driver may set up an arbitrary format.
187 	 *
188 	 * There is one exception:  uCode sets bit 15 when it originates
189 	 * the response/notification, i.e. when the response/notification
190 	 * is not a direct response to a command sent by the driver.  For
191 	 * example, uCode issues N_3945_RX when it sends a received frame
192 	 * to the driver; it is not a direct response to any driver command.
193 	 *
194 	 * The Linux driver uses the following format:
195 	 *
196 	 *  0:7         tfd idx - position within TX queue
197 	 *  8:12        TX queue id
198 	 *  13          reserved
199 	 *  14          huge - driver sets this to indicate command is in the
200 	 *              'huge' storage at the end of the command buffers
201 	 *  15          unsolicited RX or uCode-originated notification
202 	 */
203 	__le16 sequence;
204 } __packed;
205 
206 /**
207  * struct il3945_tx_power
208  *
209  * Used in C_TX_PWR_TBL, C_SCAN, C_CHANNEL_SWITCH
210  *
211  * Each entry contains two values:
212  * 1)  DSP gain (or sometimes called DSP attenuation).  This is a fine-grained
213  *     linear value that multiplies the output of the digital signal processor,
214  *     before being sent to the analog radio.
215  * 2)  Radio gain.  This sets the analog gain of the radio Tx path.
216  *     It is a coarser setting, and behaves in a logarithmic (dB) fashion.
217  *
218  * Driver obtains values from struct il3945_tx_power power_gain_table[][].
219  */
220 struct il3945_tx_power {
221 	u8 tx_gain;		/* gain for analog radio */
222 	u8 dsp_atten;		/* gain for DSP */
223 } __packed;
224 
225 /**
226  * struct il3945_power_per_rate
227  *
228  * Used in C_TX_PWR_TBL, C_CHANNEL_SWITCH
229  */
230 struct il3945_power_per_rate {
231 	u8 rate;		/* plcp */
232 	struct il3945_tx_power tpc;
233 	u8 reserved;
234 } __packed;
235 
236 /**
237  * iwl4965 rate_n_flags bit fields
238  *
239  * rate_n_flags format is used in following iwl4965 commands:
240  *  N_RX (response only)
241  *  N_RX_MPDU (response only)
242  *  C_TX (both command and response)
243  *  C_TX_LINK_QUALITY_CMD
244  *
245  * High-throughput (HT) rate format for bits 7:0 (bit 8 must be "1"):
246  *  2-0:  0)   6 Mbps
247  *        1)  12 Mbps
248  *        2)  18 Mbps
249  *        3)  24 Mbps
250  *        4)  36 Mbps
251  *        5)  48 Mbps
252  *        6)  54 Mbps
253  *        7)  60 Mbps
254  *
255  *  4-3:  0)  Single stream (SISO)
256  *        1)  Dual stream (MIMO)
257  *        2)  Triple stream (MIMO)
258  *
259  *    5:  Value of 0x20 in bits 7:0 indicates 6 Mbps HT40 duplicate data
260  *
261  * Legacy OFDM rate format for bits 7:0 (bit 8 must be "0", bit 9 "0"):
262  *  3-0:  0xD)   6 Mbps
263  *        0xF)   9 Mbps
264  *        0x5)  12 Mbps
265  *        0x7)  18 Mbps
266  *        0x9)  24 Mbps
267  *        0xB)  36 Mbps
268  *        0x1)  48 Mbps
269  *        0x3)  54 Mbps
270  *
271  * Legacy CCK rate format for bits 7:0 (bit 8 must be "0", bit 9 "1"):
272  *  6-0:   10)  1 Mbps
273  *         20)  2 Mbps
274  *         55)  5.5 Mbps
275  *        110)  11 Mbps
276  */
277 #define RATE_MCS_CODE_MSK 0x7
278 #define RATE_MCS_SPATIAL_POS 3
279 #define RATE_MCS_SPATIAL_MSK 0x18
280 #define RATE_MCS_HT_DUP_POS 5
281 #define RATE_MCS_HT_DUP_MSK 0x20
282 
283 /* Bit 8: (1) HT format, (0) legacy format in bits 7:0 */
284 #define RATE_MCS_FLAGS_POS 8
285 #define RATE_MCS_HT_POS 8
286 #define RATE_MCS_HT_MSK 0x100
287 
288 /* Bit 9: (1) CCK, (0) OFDM.  HT (bit 8) must be "0" for this bit to be valid */
289 #define RATE_MCS_CCK_POS 9
290 #define RATE_MCS_CCK_MSK 0x200
291 
292 /* Bit 10: (1) Use Green Field preamble */
293 #define RATE_MCS_GF_POS 10
294 #define RATE_MCS_GF_MSK 0x400
295 
296 /* Bit 11: (1) Use 40Mhz HT40 chnl width, (0) use 20 MHz legacy chnl width */
297 #define RATE_MCS_HT40_POS 11
298 #define RATE_MCS_HT40_MSK 0x800
299 
300 /* Bit 12: (1) Duplicate data on both 20MHz chnls. HT40 (bit 11) must be set. */
301 #define RATE_MCS_DUP_POS 12
302 #define RATE_MCS_DUP_MSK 0x1000
303 
304 /* Bit 13: (1) Short guard interval (0.4 usec), (0) normal GI (0.8 usec) */
305 #define RATE_MCS_SGI_POS 13
306 #define RATE_MCS_SGI_MSK 0x2000
307 
308 /**
309  * rate_n_flags Tx antenna masks
310  * 4965 has 2 transmitters
311  * bit14:16
312  */
313 #define RATE_MCS_ANT_POS	14
314 #define RATE_MCS_ANT_A_MSK	0x04000
315 #define RATE_MCS_ANT_B_MSK	0x08000
316 #define RATE_MCS_ANT_C_MSK	0x10000
317 #define RATE_MCS_ANT_AB_MSK	(RATE_MCS_ANT_A_MSK | RATE_MCS_ANT_B_MSK)
318 #define RATE_MCS_ANT_ABC_MSK	(RATE_MCS_ANT_AB_MSK | RATE_MCS_ANT_C_MSK)
319 #define RATE_ANT_NUM 3
320 
321 #define POWER_TBL_NUM_ENTRIES			33
322 #define POWER_TBL_NUM_HT_OFDM_ENTRIES		32
323 #define POWER_TBL_CCK_ENTRY			32
324 
325 #define IL_PWR_NUM_HT_OFDM_ENTRIES		24
326 #define IL_PWR_CCK_ENTRIES			2
327 
328 /**
329  * union il4965_tx_power_dual_stream
330  *
331  * Host format used for C_TX_PWR_TBL, C_CHANNEL_SWITCH
332  * Use __le32 version (struct tx_power_dual_stream) when building command.
333  *
334  * Driver provides radio gain and DSP attenuation settings to device in pairs,
335  * one value for each transmitter chain.  The first value is for transmitter A,
336  * second for transmitter B.
337  *
338  * For SISO bit rates, both values in a pair should be identical.
339  * For MIMO rates, one value may be different from the other,
340  * in order to balance the Tx output between the two transmitters.
341  *
342  * See more details in doc for TXPOWER in 4965.h.
343  */
344 union il4965_tx_power_dual_stream {
345 	struct {
346 		u8 radio_tx_gain[2];
347 		u8 dsp_predis_atten[2];
348 	} s;
349 	u32 dw;
350 };
351 
352 /**
353  * struct tx_power_dual_stream
354  *
355  * Table entries in C_TX_PWR_TBL, C_CHANNEL_SWITCH
356  *
357  * Same format as il_tx_power_dual_stream, but __le32
358  */
359 struct tx_power_dual_stream {
360 	__le32 dw;
361 } __packed;
362 
363 /**
364  * struct il4965_tx_power_db
365  *
366  * Entire table within C_TX_PWR_TBL, C_CHANNEL_SWITCH
367  */
368 struct il4965_tx_power_db {
369 	struct tx_power_dual_stream power_tbl[POWER_TBL_NUM_ENTRIES];
370 } __packed;
371 
372 /******************************************************************************
373  * (0a)
374  * Alive and Error Commands & Responses:
375  *
376  *****************************************************************************/
377 
378 #define UCODE_VALID_OK	cpu_to_le32(0x1)
379 #define INITIALIZE_SUBTYPE    (9)
380 
381 /*
382  * ("Initialize") N_ALIVE = 0x1 (response only, not a command)
383  *
384  * uCode issues this "initialize alive" notification once the initialization
385  * uCode image has completed its work, and is ready to load the runtime image.
386  * This is the *first* "alive" notification that the driver will receive after
387  * rebooting uCode; the "initialize" alive is indicated by subtype field == 9.
388  *
389  * See comments documenting "BSM" (bootstrap state machine).
390  *
391  * For 4965, this notification contains important calibration data for
392  * calculating txpower settings:
393  *
394  * 1)  Power supply voltage indication.  The voltage sensor outputs higher
395  *     values for lower voltage, and vice verse.
396  *
397  * 2)  Temperature measurement parameters, for each of two channel widths
398  *     (20 MHz and 40 MHz) supported by the radios.  Temperature sensing
399  *     is done via one of the receiver chains, and channel width influences
400  *     the results.
401  *
402  * 3)  Tx gain compensation to balance 4965's 2 Tx chains for MIMO operation,
403  *     for each of 5 frequency ranges.
404  */
405 struct il_init_alive_resp {
406 	u8 ucode_minor;
407 	u8 ucode_major;
408 	__le16 reserved1;
409 	u8 sw_rev[8];
410 	u8 ver_type;
411 	u8 ver_subtype;		/* "9" for initialize alive */
412 	__le16 reserved2;
413 	__le32 log_event_table_ptr;
414 	__le32 error_event_table_ptr;
415 	__le32 timestamp;
416 	__le32 is_valid;
417 
418 	/* calibration values from "initialize" uCode */
419 	__le32 voltage;		/* signed, higher value is lower voltage */
420 	__le32 therm_r1[2];	/* signed, 1st for normal, 2nd for HT40 */
421 	__le32 therm_r2[2];	/* signed */
422 	__le32 therm_r3[2];	/* signed */
423 	__le32 therm_r4[2];	/* signed */
424 	__le32 tx_atten[5][2];	/* signed MIMO gain comp, 5 freq groups,
425 				 * 2 Tx chains */
426 } __packed;
427 
428 /**
429  * N_ALIVE = 0x1 (response only, not a command)
430  *
431  * uCode issues this "alive" notification once the runtime image is ready
432  * to receive commands from the driver.  This is the *second* "alive"
433  * notification that the driver will receive after rebooting uCode;
434  * this "alive" is indicated by subtype field != 9.
435  *
436  * See comments documenting "BSM" (bootstrap state machine).
437  *
438  * This response includes two pointers to structures within the device's
439  * data SRAM (access via HBUS_TARG_MEM_* regs) that are useful for debugging:
440  *
441  * 1)  log_event_table_ptr indicates base of the event log.  This traces
442  *     a 256-entry history of uCode execution within a circular buffer.
443  *     Its header format is:
444  *
445  *	__le32 log_size;     log capacity (in number of entries)
446  *	__le32 type;         (1) timestamp with each entry, (0) no timestamp
447  *	__le32 wraps;        # times uCode has wrapped to top of circular buffer
448  *      __le32 write_idx;  next circular buffer entry that uCode would fill
449  *
450  *     The header is followed by the circular buffer of log entries.  Entries
451  *     with timestamps have the following format:
452  *
453  *	__le32 event_id;     range 0 - 1500
454  *	__le32 timestamp;    low 32 bits of TSF (of network, if associated)
455  *	__le32 data;         event_id-specific data value
456  *
457  *     Entries without timestamps contain only event_id and data.
458  *
459  *
460  * 2)  error_event_table_ptr indicates base of the error log.  This contains
461  *     information about any uCode error that occurs.  For 4965, the format
462  *     of the error log is:
463  *
464  *	__le32 valid;        (nonzero) valid, (0) log is empty
465  *	__le32 error_id;     type of error
466  *	__le32 pc;           program counter
467  *	__le32 blink1;       branch link
468  *	__le32 blink2;       branch link
469  *	__le32 ilink1;       interrupt link
470  *	__le32 ilink2;       interrupt link
471  *	__le32 data1;        error-specific data
472  *	__le32 data2;        error-specific data
473  *	__le32 line;         source code line of error
474  *	__le32 bcon_time;    beacon timer
475  *	__le32 tsf_low;      network timestamp function timer
476  *	__le32 tsf_hi;       network timestamp function timer
477  *	__le32 gp1;          GP1 timer register
478  *	__le32 gp2;          GP2 timer register
479  *	__le32 gp3;          GP3 timer register
480  *	__le32 ucode_ver;    uCode version
481  *	__le32 hw_ver;       HW Silicon version
482  *	__le32 brd_ver;      HW board version
483  *	__le32 log_pc;       log program counter
484  *	__le32 frame_ptr;    frame pointer
485  *	__le32 stack_ptr;    stack pointer
486  *	__le32 hcmd;         last host command
487  *	__le32 isr0;         isr status register LMPM_NIC_ISR0: rxtx_flag
488  *	__le32 isr1;         isr status register LMPM_NIC_ISR1: host_flag
489  *	__le32 isr2;         isr status register LMPM_NIC_ISR2: enc_flag
490  *	__le32 isr3;         isr status register LMPM_NIC_ISR3: time_flag
491  *	__le32 isr4;         isr status register LMPM_NIC_ISR4: wico interrupt
492  *	__le32 isr_pref;     isr status register LMPM_NIC_PREF_STAT
493  *	__le32 wait_event;   wait event() caller address
494  *	__le32 l2p_control;  L2pControlField
495  *	__le32 l2p_duration; L2pDurationField
496  *	__le32 l2p_mhvalid;  L2pMhValidBits
497  *	__le32 l2p_addr_match; L2pAddrMatchStat
498  *	__le32 lmpm_pmg_sel; indicate which clocks are turned on (LMPM_PMG_SEL)
499  *	__le32 u_timestamp;  indicate when the date and time of the compilation
500  *	__le32 reserved;
501  *
502  * The Linux driver can print both logs to the system log when a uCode error
503  * occurs.
504  */
505 struct il_alive_resp {
506 	u8 ucode_minor;
507 	u8 ucode_major;
508 	__le16 reserved1;
509 	u8 sw_rev[8];
510 	u8 ver_type;
511 	u8 ver_subtype;		/* not "9" for runtime alive */
512 	__le16 reserved2;
513 	__le32 log_event_table_ptr;	/* SRAM address for event log */
514 	__le32 error_event_table_ptr;	/* SRAM address for error log */
515 	__le32 timestamp;
516 	__le32 is_valid;
517 } __packed;
518 
519 /*
520  * N_ERROR = 0x2 (response only, not a command)
521  */
522 struct il_error_resp {
523 	__le32 error_type;
524 	u8 cmd_id;
525 	u8 reserved1;
526 	__le16 bad_cmd_seq_num;
527 	__le32 error_info;
528 	__le64 timestamp;
529 } __packed;
530 
531 /******************************************************************************
532  * (1)
533  * RXON Commands & Responses:
534  *
535  *****************************************************************************/
536 
537 /*
538  * Rx config defines & structure
539  */
540 /* rx_config device types  */
541 enum {
542 	RXON_DEV_TYPE_AP = 1,
543 	RXON_DEV_TYPE_ESS = 3,
544 	RXON_DEV_TYPE_IBSS = 4,
545 	RXON_DEV_TYPE_SNIFFER = 6,
546 };
547 
548 #define RXON_RX_CHAIN_DRIVER_FORCE_MSK		cpu_to_le16(0x1 << 0)
549 #define RXON_RX_CHAIN_DRIVER_FORCE_POS		(0)
550 #define RXON_RX_CHAIN_VALID_MSK			cpu_to_le16(0x7 << 1)
551 #define RXON_RX_CHAIN_VALID_POS			(1)
552 #define RXON_RX_CHAIN_FORCE_SEL_MSK		cpu_to_le16(0x7 << 4)
553 #define RXON_RX_CHAIN_FORCE_SEL_POS		(4)
554 #define RXON_RX_CHAIN_FORCE_MIMO_SEL_MSK	cpu_to_le16(0x7 << 7)
555 #define RXON_RX_CHAIN_FORCE_MIMO_SEL_POS	(7)
556 #define RXON_RX_CHAIN_CNT_MSK			cpu_to_le16(0x3 << 10)
557 #define RXON_RX_CHAIN_CNT_POS			(10)
558 #define RXON_RX_CHAIN_MIMO_CNT_MSK		cpu_to_le16(0x3 << 12)
559 #define RXON_RX_CHAIN_MIMO_CNT_POS		(12)
560 #define RXON_RX_CHAIN_MIMO_FORCE_MSK		cpu_to_le16(0x1 << 14)
561 #define RXON_RX_CHAIN_MIMO_FORCE_POS		(14)
562 
563 /* rx_config flags */
564 /* band & modulation selection */
565 #define RXON_FLG_BAND_24G_MSK           cpu_to_le32(1 << 0)
566 #define RXON_FLG_CCK_MSK                cpu_to_le32(1 << 1)
567 /* auto detection enable */
568 #define RXON_FLG_AUTO_DETECT_MSK        cpu_to_le32(1 << 2)
569 /* TGg protection when tx */
570 #define RXON_FLG_TGG_PROTECT_MSK        cpu_to_le32(1 << 3)
571 /* cck short slot & preamble */
572 #define RXON_FLG_SHORT_SLOT_MSK          cpu_to_le32(1 << 4)
573 #define RXON_FLG_SHORT_PREAMBLE_MSK     cpu_to_le32(1 << 5)
574 /* antenna selection */
575 #define RXON_FLG_DIS_DIV_MSK            cpu_to_le32(1 << 7)
576 #define RXON_FLG_ANT_SEL_MSK            cpu_to_le32(0x0f00)
577 #define RXON_FLG_ANT_A_MSK              cpu_to_le32(1 << 8)
578 #define RXON_FLG_ANT_B_MSK              cpu_to_le32(1 << 9)
579 /* radar detection enable */
580 #define RXON_FLG_RADAR_DETECT_MSK       cpu_to_le32(1 << 12)
581 #define RXON_FLG_TGJ_NARROW_BAND_MSK    cpu_to_le32(1 << 13)
582 /* rx response to host with 8-byte TSF
583 * (according to ON_AIR deassertion) */
584 #define RXON_FLG_TSF2HOST_MSK           cpu_to_le32(1 << 15)
585 
586 /* HT flags */
587 #define RXON_FLG_CTRL_CHANNEL_LOC_POS		(22)
588 #define RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK	cpu_to_le32(0x1 << 22)
589 
590 #define RXON_FLG_HT_OPERATING_MODE_POS		(23)
591 
592 #define RXON_FLG_HT_PROT_MSK			cpu_to_le32(0x1 << 23)
593 #define RXON_FLG_HT40_PROT_MSK			cpu_to_le32(0x2 << 23)
594 
595 #define RXON_FLG_CHANNEL_MODE_POS		(25)
596 #define RXON_FLG_CHANNEL_MODE_MSK		cpu_to_le32(0x3 << 25)
597 
598 /* channel mode */
599 enum {
600 	CHANNEL_MODE_LEGACY = 0,
601 	CHANNEL_MODE_PURE_40 = 1,
602 	CHANNEL_MODE_MIXED = 2,
603 	CHANNEL_MODE_RESERVED = 3,
604 };
605 #define RXON_FLG_CHANNEL_MODE_LEGACY			\
606 	cpu_to_le32(CHANNEL_MODE_LEGACY << RXON_FLG_CHANNEL_MODE_POS)
607 #define RXON_FLG_CHANNEL_MODE_PURE_40			\
608 	cpu_to_le32(CHANNEL_MODE_PURE_40 << RXON_FLG_CHANNEL_MODE_POS)
609 #define RXON_FLG_CHANNEL_MODE_MIXED			\
610 	cpu_to_le32(CHANNEL_MODE_MIXED << RXON_FLG_CHANNEL_MODE_POS)
611 
612 /* CTS to self (if spec allows) flag */
613 #define RXON_FLG_SELF_CTS_EN			cpu_to_le32(0x1<<30)
614 
615 /* rx_config filter flags */
616 /* accept all data frames */
617 #define RXON_FILTER_PROMISC_MSK         cpu_to_le32(1 << 0)
618 /* pass control & management to host */
619 #define RXON_FILTER_CTL2HOST_MSK        cpu_to_le32(1 << 1)
620 /* accept multi-cast */
621 #define RXON_FILTER_ACCEPT_GRP_MSK      cpu_to_le32(1 << 2)
622 /* don't decrypt uni-cast frames */
623 #define RXON_FILTER_DIS_DECRYPT_MSK     cpu_to_le32(1 << 3)
624 /* don't decrypt multi-cast frames */
625 #define RXON_FILTER_DIS_GRP_DECRYPT_MSK cpu_to_le32(1 << 4)
626 /* STA is associated */
627 #define RXON_FILTER_ASSOC_MSK           cpu_to_le32(1 << 5)
628 /* transfer to host non bssid beacons in associated state */
629 #define RXON_FILTER_BCON_AWARE_MSK      cpu_to_le32(1 << 6)
630 
631 /**
632  * C_RXON = 0x10 (command, has simple generic response)
633  *
634  * RXON tunes the radio tuner to a service channel, and sets up a number
635  * of parameters that are used primarily for Rx, but also for Tx operations.
636  *
637  * NOTE:  When tuning to a new channel, driver must set the
638  *        RXON_FILTER_ASSOC_MSK to 0.  This will clear station-dependent
639  *        info within the device, including the station tables, tx retry
640  *        rate tables, and txpower tables.  Driver must build a new station
641  *        table and txpower table before transmitting anything on the RXON
642  *        channel.
643  *
644  * NOTE:  All RXONs wipe clean the internal txpower table.  Driver must
645  *        issue a new C_TX_PWR_TBL after each C_RXON (0x10),
646  *        regardless of whether RXON_FILTER_ASSOC_MSK is set.
647  */
648 
649 struct il3945_rxon_cmd {
650 	u8 node_addr[6];
651 	__le16 reserved1;
652 	u8 bssid_addr[6];
653 	__le16 reserved2;
654 	u8 wlap_bssid_addr[6];
655 	__le16 reserved3;
656 	u8 dev_type;
657 	u8 air_propagation;
658 	__le16 reserved4;
659 	u8 ofdm_basic_rates;
660 	u8 cck_basic_rates;
661 	__le16 assoc_id;
662 	__le32 flags;
663 	__le32 filter_flags;
664 	__le16 channel;
665 	__le16 reserved5;
666 } __packed;
667 
668 struct il4965_rxon_cmd {
669 	u8 node_addr[6];
670 	__le16 reserved1;
671 	u8 bssid_addr[6];
672 	__le16 reserved2;
673 	u8 wlap_bssid_addr[6];
674 	__le16 reserved3;
675 	u8 dev_type;
676 	u8 air_propagation;
677 	__le16 rx_chain;
678 	u8 ofdm_basic_rates;
679 	u8 cck_basic_rates;
680 	__le16 assoc_id;
681 	__le32 flags;
682 	__le32 filter_flags;
683 	__le16 channel;
684 	u8 ofdm_ht_single_stream_basic_rates;
685 	u8 ofdm_ht_dual_stream_basic_rates;
686 } __packed;
687 
688 /* Create a common rxon cmd which will be typecast into the 3945 or 4965
689  * specific rxon cmd, depending on where it is called from.
690  */
691 struct il_rxon_cmd {
692 	u8 node_addr[6];
693 	__le16 reserved1;
694 	u8 bssid_addr[6];
695 	__le16 reserved2;
696 	u8 wlap_bssid_addr[6];
697 	__le16 reserved3;
698 	u8 dev_type;
699 	u8 air_propagation;
700 	__le16 rx_chain;
701 	u8 ofdm_basic_rates;
702 	u8 cck_basic_rates;
703 	__le16 assoc_id;
704 	__le32 flags;
705 	__le32 filter_flags;
706 	__le16 channel;
707 	u8 ofdm_ht_single_stream_basic_rates;
708 	u8 ofdm_ht_dual_stream_basic_rates;
709 	u8 reserved4;
710 	u8 reserved5;
711 } __packed;
712 
713 /*
714  * C_RXON_ASSOC = 0x11 (command, has simple generic response)
715  */
716 struct il3945_rxon_assoc_cmd {
717 	__le32 flags;
718 	__le32 filter_flags;
719 	u8 ofdm_basic_rates;
720 	u8 cck_basic_rates;
721 	__le16 reserved;
722 } __packed;
723 
724 struct il4965_rxon_assoc_cmd {
725 	__le32 flags;
726 	__le32 filter_flags;
727 	u8 ofdm_basic_rates;
728 	u8 cck_basic_rates;
729 	u8 ofdm_ht_single_stream_basic_rates;
730 	u8 ofdm_ht_dual_stream_basic_rates;
731 	__le16 rx_chain_select_flags;
732 	__le16 reserved;
733 } __packed;
734 
735 #define IL_CONN_MAX_LISTEN_INTERVAL	10
736 #define IL_MAX_UCODE_BEACON_INTERVAL	4	/* 4096 */
737 #define IL39_MAX_UCODE_BEACON_INTERVAL	1	/* 1024 */
738 
739 /*
740  * C_RXON_TIMING = 0x14 (command, has simple generic response)
741  */
742 struct il_rxon_time_cmd {
743 	__le64 timestamp;
744 	__le16 beacon_interval;
745 	__le16 atim_win;
746 	__le32 beacon_init_val;
747 	__le16 listen_interval;
748 	u8 dtim_period;
749 	u8 delta_cp_bss_tbtts;
750 } __packed;
751 
752 /*
753  * C_CHANNEL_SWITCH = 0x72 (command, has simple generic response)
754  */
755 struct il3945_channel_switch_cmd {
756 	u8 band;
757 	u8 expect_beacon;
758 	__le16 channel;
759 	__le32 rxon_flags;
760 	__le32 rxon_filter_flags;
761 	__le32 switch_time;
762 	struct il3945_power_per_rate power[IL_MAX_RATES];
763 } __packed;
764 
765 struct il4965_channel_switch_cmd {
766 	u8 band;
767 	u8 expect_beacon;
768 	__le16 channel;
769 	__le32 rxon_flags;
770 	__le32 rxon_filter_flags;
771 	__le32 switch_time;
772 	struct il4965_tx_power_db tx_power;
773 } __packed;
774 
775 /*
776  * N_CHANNEL_SWITCH = 0x73 (notification only, not a command)
777  */
778 struct il_csa_notification {
779 	__le16 band;
780 	__le16 channel;
781 	__le32 status;		/* 0 - OK, 1 - fail */
782 } __packed;
783 
784 /******************************************************************************
785  * (2)
786  * Quality-of-Service (QOS) Commands & Responses:
787  *
788  *****************************************************************************/
789 
790 /**
791  * struct il_ac_qos -- QOS timing params for C_QOS_PARAM
792  * One for each of 4 EDCA access categories in struct il_qosparam_cmd
793  *
794  * @cw_min: Contention win, start value in numbers of slots.
795  *          Should be a power-of-2, minus 1.  Device's default is 0x0f.
796  * @cw_max: Contention win, max value in numbers of slots.
797  *          Should be a power-of-2, minus 1.  Device's default is 0x3f.
798  * @aifsn:  Number of slots in Arbitration Interframe Space (before
799  *          performing random backoff timing prior to Tx).  Device default 1.
800  * @edca_txop:  Length of Tx opportunity, in uSecs.  Device default is 0.
801  *
802  * Device will automatically increase contention win by (2*CW) + 1 for each
803  * transmission retry.  Device uses cw_max as a bit mask, ANDed with new CW
804  * value, to cap the CW value.
805  */
806 struct il_ac_qos {
807 	__le16 cw_min;
808 	__le16 cw_max;
809 	u8 aifsn;
810 	u8 reserved1;
811 	__le16 edca_txop;
812 } __packed;
813 
814 /* QoS flags defines */
815 #define QOS_PARAM_FLG_UPDATE_EDCA_MSK	cpu_to_le32(0x01)
816 #define QOS_PARAM_FLG_TGN_MSK		cpu_to_le32(0x02)
817 #define QOS_PARAM_FLG_TXOP_TYPE_MSK	cpu_to_le32(0x10)
818 
819 /* Number of Access Categories (AC) (EDCA), queues 0..3 */
820 #define AC_NUM                4
821 
822 /*
823  * C_QOS_PARAM = 0x13 (command, has simple generic response)
824  *
825  * This command sets up timings for each of the 4 prioritized EDCA Tx FIFOs
826  * 0: Background, 1: Best Effort, 2: Video, 3: Voice.
827  */
828 struct il_qosparam_cmd {
829 	__le32 qos_flags;
830 	struct il_ac_qos ac[AC_NUM];
831 } __packed;
832 
833 /******************************************************************************
834  * (3)
835  * Add/Modify Stations Commands & Responses:
836  *
837  *****************************************************************************/
838 /*
839  * Multi station support
840  */
841 
842 /* Special, dedicated locations within device's station table */
843 #define	IL_AP_ID		0
844 #define	IL_STA_ID		2
845 #define	IL3945_BROADCAST_ID	24
846 #define IL3945_STATION_COUNT	25
847 #define IL4965_BROADCAST_ID	31
848 #define	IL4965_STATION_COUNT	32
849 
850 #define	IL_STATION_COUNT	32	/* MAX(3945,4965) */
851 #define	IL_INVALID_STATION	255
852 
853 #define STA_FLG_TX_RATE_MSK		cpu_to_le32(1 << 2)
854 #define STA_FLG_PWR_SAVE_MSK		cpu_to_le32(1 << 8)
855 #define STA_FLG_RTS_MIMO_PROT_MSK	cpu_to_le32(1 << 17)
856 #define STA_FLG_AGG_MPDU_8US_MSK	cpu_to_le32(1 << 18)
857 #define STA_FLG_MAX_AGG_SIZE_POS	(19)
858 #define STA_FLG_MAX_AGG_SIZE_MSK	cpu_to_le32(3 << 19)
859 #define STA_FLG_HT40_EN_MSK		cpu_to_le32(1 << 21)
860 #define STA_FLG_MIMO_DIS_MSK		cpu_to_le32(1 << 22)
861 #define STA_FLG_AGG_MPDU_DENSITY_POS	(23)
862 #define STA_FLG_AGG_MPDU_DENSITY_MSK	cpu_to_le32(7 << 23)
863 
864 /* Use in mode field.  1: modify existing entry, 0: add new station entry */
865 #define STA_CONTROL_MODIFY_MSK		0x01
866 
867 /* key flags __le16*/
868 #define STA_KEY_FLG_ENCRYPT_MSK	cpu_to_le16(0x0007)
869 #define STA_KEY_FLG_NO_ENC	cpu_to_le16(0x0000)
870 #define STA_KEY_FLG_WEP		cpu_to_le16(0x0001)
871 #define STA_KEY_FLG_CCMP	cpu_to_le16(0x0002)
872 #define STA_KEY_FLG_TKIP	cpu_to_le16(0x0003)
873 
874 #define STA_KEY_FLG_KEYID_POS	8
875 #define STA_KEY_FLG_INVALID	cpu_to_le16(0x0800)
876 /* wep key is either from global key (0) or from station info array (1) */
877 #define STA_KEY_FLG_MAP_KEY_MSK	cpu_to_le16(0x0008)
878 
879 /* wep key in STA: 5-bytes (0) or 13-bytes (1) */
880 #define STA_KEY_FLG_KEY_SIZE_MSK	cpu_to_le16(0x1000)
881 #define STA_KEY_MULTICAST_MSK		cpu_to_le16(0x4000)
882 #define STA_KEY_MAX_NUM		8
883 
884 /* Flags indicate whether to modify vs. don't change various station params */
885 #define	STA_MODIFY_KEY_MASK		0x01
886 #define	STA_MODIFY_TID_DISABLE_TX	0x02
887 #define	STA_MODIFY_TX_RATE_MSK		0x04
888 #define STA_MODIFY_ADDBA_TID_MSK	0x08
889 #define STA_MODIFY_DELBA_TID_MSK	0x10
890 #define STA_MODIFY_SLEEP_TX_COUNT_MSK	0x20
891 
892 /* Receiver address (actually, Rx station's idx into station table),
893  * combined with Traffic ID (QOS priority), in format used by Tx Scheduler */
894 #define BUILD_RAxTID(sta_id, tid)	(((sta_id) << 4) + (tid))
895 
896 struct il4965_keyinfo {
897 	__le16 key_flags;
898 	u8 tkip_rx_tsc_byte2;	/* TSC[2] for key mix ph1 detection */
899 	u8 reserved1;
900 	__le16 tkip_rx_ttak[5];	/* 10-byte unicast TKIP TTAK */
901 	u8 key_offset;
902 	u8 reserved2;
903 	u8 key[16];		/* 16-byte unicast decryption key */
904 } __packed;
905 
906 /**
907  * struct sta_id_modify
908  * @addr[ETH_ALEN]: station's MAC address
909  * @sta_id: idx of station in uCode's station table
910  * @modify_mask: STA_MODIFY_*, 1: modify, 0: don't change
911  *
912  * Driver selects unused table idx when adding new station,
913  * or the idx to a pre-existing station entry when modifying that station.
914  * Some idxes have special purposes (IL_AP_ID, idx 0, is for AP).
915  *
916  * modify_mask flags select which parameters to modify vs. leave alone.
917  */
918 struct sta_id_modify {
919 	u8 addr[ETH_ALEN];
920 	__le16 reserved1;
921 	u8 sta_id;
922 	u8 modify_mask;
923 	__le16 reserved2;
924 } __packed;
925 
926 /*
927  * C_ADD_STA = 0x18 (command)
928  *
929  * The device contains an internal table of per-station information,
930  * with info on security keys, aggregation parameters, and Tx rates for
931  * initial Tx attempt and any retries (4965 devices uses
932  * C_TX_LINK_QUALITY_CMD,
933  * 3945 uses C_RATE_SCALE to set up rate tables).
934  *
935  * C_ADD_STA sets up the table entry for one station, either creating
936  * a new entry, or modifying a pre-existing one.
937  *
938  * NOTE:  RXON command (without "associated" bit set) wipes the station table
939  *        clean.  Moving into RF_KILL state does this also.  Driver must set up
940  *        new station table before transmitting anything on the RXON channel
941  *        (except active scans or active measurements; those commands carry
942  *        their own txpower/rate setup data).
943  *
944  *        When getting started on a new channel, driver must set up the
945  *        IL_BROADCAST_ID entry (last entry in the table).  For a client
946  *        station in a BSS, once an AP is selected, driver sets up the AP STA
947  *        in the IL_AP_ID entry (1st entry in the table).  BROADCAST and AP
948  *        are all that are needed for a BSS client station.  If the device is
949  *        used as AP, or in an IBSS network, driver must set up station table
950  *        entries for all STAs in network, starting with idx IL_STA_ID.
951  */
952 
953 struct il3945_addsta_cmd {
954 	u8 mode;		/* 1: modify existing, 0: add new station */
955 	u8 reserved[3];
956 	struct sta_id_modify sta;
957 	struct il4965_keyinfo key;
958 	__le32 station_flags;	/* STA_FLG_* */
959 	__le32 station_flags_msk;	/* STA_FLG_* */
960 
961 	/* bit field to disable (1) or enable (0) Tx for Traffic ID (TID)
962 	 * corresponding to bit (e.g. bit 5 controls TID 5).
963 	 * Set modify_mask bit STA_MODIFY_TID_DISABLE_TX to use this field. */
964 	__le16 tid_disable_tx;
965 
966 	__le16 rate_n_flags;
967 
968 	/* TID for which to add block-ack support.
969 	 * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */
970 	u8 add_immediate_ba_tid;
971 
972 	/* TID for which to remove block-ack support.
973 	 * Set modify_mask bit STA_MODIFY_DELBA_TID_MSK to use this field. */
974 	u8 remove_immediate_ba_tid;
975 
976 	/* Starting Sequence Number for added block-ack support.
977 	 * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */
978 	__le16 add_immediate_ba_ssn;
979 } __packed;
980 
981 struct il4965_addsta_cmd {
982 	u8 mode;		/* 1: modify existing, 0: add new station */
983 	u8 reserved[3];
984 	struct sta_id_modify sta;
985 	struct il4965_keyinfo key;
986 	__le32 station_flags;	/* STA_FLG_* */
987 	__le32 station_flags_msk;	/* STA_FLG_* */
988 
989 	/* bit field to disable (1) or enable (0) Tx for Traffic ID (TID)
990 	 * corresponding to bit (e.g. bit 5 controls TID 5).
991 	 * Set modify_mask bit STA_MODIFY_TID_DISABLE_TX to use this field. */
992 	__le16 tid_disable_tx;
993 
994 	__le16 reserved1;
995 
996 	/* TID for which to add block-ack support.
997 	 * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */
998 	u8 add_immediate_ba_tid;
999 
1000 	/* TID for which to remove block-ack support.
1001 	 * Set modify_mask bit STA_MODIFY_DELBA_TID_MSK to use this field. */
1002 	u8 remove_immediate_ba_tid;
1003 
1004 	/* Starting Sequence Number for added block-ack support.
1005 	 * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */
1006 	__le16 add_immediate_ba_ssn;
1007 
1008 	/*
1009 	 * Number of packets OK to transmit to station even though
1010 	 * it is asleep -- used to synchronise PS-poll and u-APSD
1011 	 * responses while ucode keeps track of STA sleep state.
1012 	 */
1013 	__le16 sleep_tx_count;
1014 
1015 	__le16 reserved2;
1016 } __packed;
1017 
1018 /* Wrapper struct for 3945 and 4965 addsta_cmd structures */
1019 struct il_addsta_cmd {
1020 	u8 mode;		/* 1: modify existing, 0: add new station */
1021 	u8 reserved[3];
1022 	struct sta_id_modify sta;
1023 	struct il4965_keyinfo key;
1024 	__le32 station_flags;	/* STA_FLG_* */
1025 	__le32 station_flags_msk;	/* STA_FLG_* */
1026 
1027 	/* bit field to disable (1) or enable (0) Tx for Traffic ID (TID)
1028 	 * corresponding to bit (e.g. bit 5 controls TID 5).
1029 	 * Set modify_mask bit STA_MODIFY_TID_DISABLE_TX to use this field. */
1030 	__le16 tid_disable_tx;
1031 
1032 	__le16 rate_n_flags;	/* 3945 only */
1033 
1034 	/* TID for which to add block-ack support.
1035 	 * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */
1036 	u8 add_immediate_ba_tid;
1037 
1038 	/* TID for which to remove block-ack support.
1039 	 * Set modify_mask bit STA_MODIFY_DELBA_TID_MSK to use this field. */
1040 	u8 remove_immediate_ba_tid;
1041 
1042 	/* Starting Sequence Number for added block-ack support.
1043 	 * Set modify_mask bit STA_MODIFY_ADDBA_TID_MSK to use this field. */
1044 	__le16 add_immediate_ba_ssn;
1045 
1046 	/*
1047 	 * Number of packets OK to transmit to station even though
1048 	 * it is asleep -- used to synchronise PS-poll and u-APSD
1049 	 * responses while ucode keeps track of STA sleep state.
1050 	 */
1051 	__le16 sleep_tx_count;
1052 
1053 	__le16 reserved2;
1054 } __packed;
1055 
1056 #define ADD_STA_SUCCESS_MSK		0x1
1057 #define ADD_STA_NO_ROOM_IN_TBL	0x2
1058 #define ADD_STA_NO_BLOCK_ACK_RESOURCE	0x4
1059 #define ADD_STA_MODIFY_NON_EXIST_STA	0x8
1060 /*
1061  * C_ADD_STA = 0x18 (response)
1062  */
1063 struct il_add_sta_resp {
1064 	u8 status;		/* ADD_STA_* */
1065 } __packed;
1066 
1067 #define REM_STA_SUCCESS_MSK              0x1
1068 /*
1069  *  C_REM_STA = 0x19 (response)
1070  */
1071 struct il_rem_sta_resp {
1072 	u8 status;
1073 } __packed;
1074 
1075 /*
1076  *  C_REM_STA = 0x19 (command)
1077  */
1078 struct il_rem_sta_cmd {
1079 	u8 num_sta;		/* number of removed stations */
1080 	u8 reserved[3];
1081 	u8 addr[ETH_ALEN];	/* MAC addr of the first station */
1082 	u8 reserved2[2];
1083 } __packed;
1084 
1085 #define IL_TX_FIFO_BK_MSK		cpu_to_le32(BIT(0))
1086 #define IL_TX_FIFO_BE_MSK		cpu_to_le32(BIT(1))
1087 #define IL_TX_FIFO_VI_MSK		cpu_to_le32(BIT(2))
1088 #define IL_TX_FIFO_VO_MSK		cpu_to_le32(BIT(3))
1089 #define IL_AGG_TX_QUEUE_MSK		cpu_to_le32(0xffc00)
1090 
1091 #define IL_DROP_SINGLE		0
1092 #define IL_DROP_SELECTED	1
1093 #define IL_DROP_ALL		2
1094 
1095 /*
1096  * REPLY_WEP_KEY = 0x20
1097  */
1098 struct il_wep_key {
1099 	u8 key_idx;
1100 	u8 key_offset;
1101 	u8 reserved1[2];
1102 	u8 key_size;
1103 	u8 reserved2[3];
1104 	u8 key[16];
1105 } __packed;
1106 
1107 struct il_wep_cmd {
1108 	u8 num_keys;
1109 	u8 global_key_type;
1110 	u8 flags;
1111 	u8 reserved;
1112 	struct il_wep_key key[];
1113 } __packed;
1114 
1115 #define WEP_KEY_WEP_TYPE 1
1116 #define WEP_KEYS_MAX 4
1117 #define WEP_INVALID_OFFSET 0xff
1118 #define WEP_KEY_LEN_64 5
1119 #define WEP_KEY_LEN_128 13
1120 
1121 /******************************************************************************
1122  * (4)
1123  * Rx Responses:
1124  *
1125  *****************************************************************************/
1126 
1127 #define RX_RES_STATUS_NO_CRC32_ERROR	cpu_to_le32(1 << 0)
1128 #define RX_RES_STATUS_NO_RXE_OVERFLOW	cpu_to_le32(1 << 1)
1129 
1130 #define RX_RES_PHY_FLAGS_BAND_24_MSK	cpu_to_le16(1 << 0)
1131 #define RX_RES_PHY_FLAGS_MOD_CCK_MSK		cpu_to_le16(1 << 1)
1132 #define RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK	cpu_to_le16(1 << 2)
1133 #define RX_RES_PHY_FLAGS_NARROW_BAND_MSK	cpu_to_le16(1 << 3)
1134 #define RX_RES_PHY_FLAGS_ANTENNA_MSK		0x70
1135 #define RX_RES_PHY_FLAGS_ANTENNA_POS		4
1136 #define RX_RES_PHY_FLAGS_AGG_MSK	cpu_to_le16(1 << 7)
1137 
1138 #define RX_RES_STATUS_SEC_TYPE_MSK	(0x7 << 8)
1139 #define RX_RES_STATUS_SEC_TYPE_NONE	(0x0 << 8)
1140 #define RX_RES_STATUS_SEC_TYPE_WEP	(0x1 << 8)
1141 #define RX_RES_STATUS_SEC_TYPE_CCMP	(0x2 << 8)
1142 #define RX_RES_STATUS_SEC_TYPE_TKIP	(0x3 << 8)
1143 #define	RX_RES_STATUS_SEC_TYPE_ERR	(0x7 << 8)
1144 
1145 #define RX_RES_STATUS_STATION_FOUND	(1<<6)
1146 #define RX_RES_STATUS_NO_STATION_INFO_MISMATCH	(1<<7)
1147 
1148 #define RX_RES_STATUS_DECRYPT_TYPE_MSK	(0x3 << 11)
1149 #define RX_RES_STATUS_NOT_DECRYPT	(0x0 << 11)
1150 #define RX_RES_STATUS_DECRYPT_OK	(0x3 << 11)
1151 #define RX_RES_STATUS_BAD_ICV_MIC	(0x1 << 11)
1152 #define RX_RES_STATUS_BAD_KEY_TTAK	(0x2 << 11)
1153 
1154 #define RX_MPDU_RES_STATUS_ICV_OK	(0x20)
1155 #define RX_MPDU_RES_STATUS_MIC_OK	(0x40)
1156 #define RX_MPDU_RES_STATUS_TTAK_OK	(1 << 7)
1157 #define RX_MPDU_RES_STATUS_DEC_DONE_MSK	(0x800)
1158 
1159 struct il3945_rx_frame_stats {
1160 	/* New members MUST be added within the __struct_group() macro below. */
1161 	__struct_group(il3945_rx_frame_stats_hdr, hdr, __packed,
1162 		u8 phy_count;
1163 		u8 id;
1164 		u8 rssi;
1165 		u8 agc;
1166 		__le16 sig_avg;
1167 		__le16 noise_diff;
1168 	);
1169 	u8 payload[];
1170 } __packed;
1171 static_assert(offsetof(struct il3945_rx_frame_stats, payload) == sizeof(struct il3945_rx_frame_stats_hdr),
1172 	      "struct member likely outside of __struct_group()");
1173 
1174 struct il3945_rx_frame_hdr {
1175 	/* New members MUST be added within the __struct_group() macro below. */
1176 	__struct_group(il3945_rx_frame_hdr_hdr, hdr, __packed,
1177 		__le16 channel;
1178 		__le16 phy_flags;
1179 		u8 reserved1;
1180 		u8 rate;
1181 		__le16 len;
1182 	);
1183 	u8 payload[];
1184 } __packed;
1185 static_assert(offsetof(struct il3945_rx_frame_hdr, payload) == sizeof(struct il3945_rx_frame_hdr_hdr),
1186 	      "struct member likely outside of __struct_group()");
1187 
1188 struct il3945_rx_frame_end {
1189 	__le32 status;
1190 	__le64 timestamp;
1191 	__le32 beacon_timestamp;
1192 } __packed;
1193 
1194 /*
1195  * N_3945_RX = 0x1b (response only, not a command)
1196  *
1197  * NOTE:  DO NOT dereference from casts to this structure
1198  * It is provided only for calculating minimum data set size.
1199  * The actual offsets of the hdr and end are dynamic based on
1200  * stats.phy_count
1201  */
1202 struct il3945_rx_frame {
1203 	struct il3945_rx_frame_stats_hdr stats;
1204 	struct il3945_rx_frame_hdr_hdr hdr;
1205 	struct il3945_rx_frame_end end;
1206 } __packed;
1207 
1208 #define IL39_RX_FRAME_SIZE	(4 + sizeof(struct il3945_rx_frame))
1209 
1210 /* Fixed (non-configurable) rx data from phy */
1211 
1212 #define IL49_RX_RES_PHY_CNT 14
1213 #define IL49_RX_PHY_FLAGS_ANTENNAE_OFFSET	(4)
1214 #define IL49_RX_PHY_FLAGS_ANTENNAE_MASK	(0x70)
1215 #define IL49_AGC_DB_MASK			(0x3f80)	/* MASK(7,13) */
1216 #define IL49_AGC_DB_POS			(7)
1217 struct il4965_rx_non_cfg_phy {
1218 	__le16 ant_selection;	/* ant A bit 4, ant B bit 5, ant C bit 6 */
1219 	__le16 agc_info;	/* agc code 0:6, agc dB 7:13, reserved 14:15 */
1220 	u8 rssi_info[6];	/* we use even entries, 0/2/4 for A/B/C rssi */
1221 	u8 pad[];
1222 } __packed;
1223 
1224 /*
1225  * N_RX = 0xc3 (response only, not a command)
1226  * Used only for legacy (non 11n) frames.
1227  */
1228 struct il_rx_phy_res {
1229 	u8 non_cfg_phy_cnt;	/* non configurable DSP phy data byte count */
1230 	u8 cfg_phy_cnt;		/* configurable DSP phy data byte count */
1231 	u8 stat_id;		/* configurable DSP phy data set ID */
1232 	u8 reserved1;
1233 	__le64 timestamp;	/* TSF at on air rise */
1234 	__le32 beacon_time_stamp;	/* beacon at on-air rise */
1235 	__le16 phy_flags;	/* general phy flags: band, modulation, ... */
1236 	__le16 channel;		/* channel number */
1237 	u8 non_cfg_phy_buf[32];	/* for various implementations of non_cfg_phy */
1238 	__le32 rate_n_flags;	/* RATE_MCS_* */
1239 	__le16 byte_count;	/* frame's byte-count */
1240 	__le16 frame_time;	/* frame's time on the air */
1241 } __packed;
1242 
1243 struct il_rx_mpdu_res_start {
1244 	__le16 byte_count;
1245 	__le16 reserved;
1246 } __packed;
1247 
1248 /******************************************************************************
1249  * (5)
1250  * Tx Commands & Responses:
1251  *
1252  * Driver must place each C_TX command into one of the prioritized Tx
1253  * queues in host DRAM, shared between driver and device (see comments for
1254  * SCD registers and Tx/Rx Queues).  When the device's Tx scheduler and uCode
1255  * are preparing to transmit, the device pulls the Tx command over the PCI
1256  * bus via one of the device's Tx DMA channels, to fill an internal FIFO
1257  * from which data will be transmitted.
1258  *
1259  * uCode handles all timing and protocol related to control frames
1260  * (RTS/CTS/ACK), based on flags in the Tx command.  uCode and Tx scheduler
1261  * handle reception of block-acks; uCode updates the host driver via
1262  * N_COMPRESSED_BA.
1263  *
1264  * uCode handles retrying Tx when an ACK is expected but not received.
1265  * This includes trying lower data rates than the one requested in the Tx
1266  * command, as set up by the C_RATE_SCALE (for 3945) or
1267  * C_TX_LINK_QUALITY_CMD (4965).
1268  *
1269  * Driver sets up transmit power for various rates via C_TX_PWR_TBL.
1270  * This command must be executed after every RXON command, before Tx can occur.
1271  *****************************************************************************/
1272 
1273 /* C_TX Tx flags field */
1274 
1275 /*
1276  * 1: Use Request-To-Send protocol before this frame.
1277  * Mutually exclusive vs. TX_CMD_FLG_CTS_MSK.
1278  */
1279 #define TX_CMD_FLG_RTS_MSK cpu_to_le32(1 << 1)
1280 
1281 /*
1282  * 1: Transmit Clear-To-Send to self before this frame.
1283  * Driver should set this for AUTH/DEAUTH/ASSOC-REQ/REASSOC mgmnt frames.
1284  * Mutually exclusive vs. TX_CMD_FLG_RTS_MSK.
1285  */
1286 #define TX_CMD_FLG_CTS_MSK cpu_to_le32(1 << 2)
1287 
1288 /* 1: Expect ACK from receiving station
1289  * 0: Don't expect ACK (MAC header's duration field s/b 0)
1290  * Set this for unicast frames, but not broadcast/multicast. */
1291 #define TX_CMD_FLG_ACK_MSK cpu_to_le32(1 << 3)
1292 
1293 /* For 4965 devices:
1294  * 1: Use rate scale table (see C_TX_LINK_QUALITY_CMD).
1295  *    Tx command's initial_rate_idx indicates first rate to try;
1296  *    uCode walks through table for additional Tx attempts.
1297  * 0: Use Tx rate/MCS from Tx command's rate_n_flags field.
1298  *    This rate will be used for all Tx attempts; it will not be scaled. */
1299 #define TX_CMD_FLG_STA_RATE_MSK cpu_to_le32(1 << 4)
1300 
1301 /* 1: Expect immediate block-ack.
1302  * Set when Txing a block-ack request frame.  Also set TX_CMD_FLG_ACK_MSK. */
1303 #define TX_CMD_FLG_IMM_BA_RSP_MASK  cpu_to_le32(1 << 6)
1304 
1305 /*
1306  * 1: Frame requires full Tx-Op protection.
1307  * Set this if either RTS or CTS Tx Flag gets set.
1308  */
1309 #define TX_CMD_FLG_FULL_TXOP_PROT_MSK cpu_to_le32(1 << 7)
1310 
1311 /* Tx antenna selection field; used only for 3945, reserved (0) for 4965 devices.
1312  * Set field to "0" to allow 3945 uCode to select antenna (normal usage). */
1313 #define TX_CMD_FLG_ANT_SEL_MSK cpu_to_le32(0xf00)
1314 #define TX_CMD_FLG_ANT_A_MSK cpu_to_le32(1 << 8)
1315 #define TX_CMD_FLG_ANT_B_MSK cpu_to_le32(1 << 9)
1316 
1317 /* 1: uCode overrides sequence control field in MAC header.
1318  * 0: Driver provides sequence control field in MAC header.
1319  * Set this for management frames, non-QOS data frames, non-unicast frames,
1320  * and also in Tx command embedded in C_SCAN for active scans. */
1321 #define TX_CMD_FLG_SEQ_CTL_MSK cpu_to_le32(1 << 13)
1322 
1323 /* 1: This frame is non-last MPDU; more fragments are coming.
1324  * 0: Last fragment, or not using fragmentation. */
1325 #define TX_CMD_FLG_MORE_FRAG_MSK cpu_to_le32(1 << 14)
1326 
1327 /* 1: uCode calculates and inserts Timestamp Function (TSF) in outgoing frame.
1328  * 0: No TSF required in outgoing frame.
1329  * Set this for transmitting beacons and probe responses. */
1330 #define TX_CMD_FLG_TSF_MSK cpu_to_le32(1 << 16)
1331 
1332 /* 1: Driver inserted 2 bytes pad after the MAC header, for (required) dword
1333  *    alignment of frame's payload data field.
1334  * 0: No pad
1335  * Set this for MAC headers with 26 or 30 bytes, i.e. those with QOS or ADDR4
1336  * field (but not both).  Driver must align frame data (i.e. data following
1337  * MAC header) to DWORD boundary. */
1338 #define TX_CMD_FLG_MH_PAD_MSK cpu_to_le32(1 << 20)
1339 
1340 /* accelerate aggregation support
1341  * 0 - no CCMP encryption; 1 - CCMP encryption */
1342 #define TX_CMD_FLG_AGG_CCMP_MSK cpu_to_le32(1 << 22)
1343 
1344 /* HCCA-AP - disable duration overwriting. */
1345 #define TX_CMD_FLG_DUR_MSK cpu_to_le32(1 << 25)
1346 
1347 /*
1348  * TX command security control
1349  */
1350 #define TX_CMD_SEC_WEP		0x01
1351 #define TX_CMD_SEC_CCM		0x02
1352 #define TX_CMD_SEC_TKIP		0x03
1353 #define TX_CMD_SEC_MSK		0x03
1354 #define TX_CMD_SEC_SHIFT	6
1355 #define TX_CMD_SEC_KEY128	0x08
1356 
1357 /*
1358  * C_TX = 0x1c (command)
1359  */
1360 
1361 struct il3945_tx_cmd {
1362 	/* New members MUST be added within the __struct_group() macro below. */
1363 	__struct_group(il3945_tx_cmd_hdr, __hdr, __packed,
1364 		/*
1365 		 * MPDU byte count:
1366 		 * MAC header (24/26/30/32 bytes) + 2 bytes pad if 26/30 header size,
1367 		 * + 8 byte IV for CCM or TKIP (not used for WEP)
1368 		 * + Data payload
1369 		 * + 8-byte MIC (not used for CCM/WEP)
1370 		 * NOTE:  Does not include Tx command bytes, post-MAC pad bytes,
1371 		 *        MIC (CCM) 8 bytes, ICV (WEP/TKIP/CKIP) 4 bytes, CRC 4 bytes.i
1372 		 * Range: 14-2342 bytes.
1373 		 */
1374 		__le16 len;
1375 
1376 		/*
1377 		 * MPDU or MSDU byte count for next frame.
1378 		 * Used for fragmentation and bursting, but not 11n aggregation.
1379 		 * Same as "len", but for next frame.  Set to 0 if not applicable.
1380 		 */
1381 		__le16 next_frame_len;
1382 
1383 		__le32 tx_flags;	/* TX_CMD_FLG_* */
1384 
1385 		u8 rate;
1386 
1387 		/* Index of recipient station in uCode's station table */
1388 		u8 sta_id;
1389 		u8 tid_tspec;
1390 		u8 sec_ctl;
1391 		u8 key[16];
1392 		union {
1393 			u8 byte[8];
1394 			__le16 word[4];
1395 			__le32 dw[2];
1396 		} tkip_mic;
1397 		__le32 next_frame_info;
1398 		union {
1399 			__le32 life_time;
1400 			__le32 attempt;
1401 		} stop_time;
1402 		u8 supp_rates[2];
1403 		u8 rts_retry_limit;	/*byte 50 */
1404 		u8 data_retry_limit;	/*byte 51 */
1405 		union {
1406 			__le16 pm_frame_timeout;
1407 			__le16 attempt_duration;
1408 		} timeout;
1409 
1410 		/*
1411 		 * Duration of EDCA burst Tx Opportunity, in 32-usec units.
1412 		 * Set this if txop time is not specified by HCCA protocol (e.g. by AP).
1413 		 */
1414 		__le16 driver_txop;
1415 	);
1416 
1417 	/*
1418 	 * MAC header goes here, followed by 2 bytes padding if MAC header
1419 	 * length is 26 or 30 bytes, followed by payload data
1420 	 */
1421 	struct ieee80211_hdr hdr[];
1422 } __packed;
1423 static_assert(offsetof(struct il3945_tx_cmd, hdr) == sizeof(struct il3945_tx_cmd_hdr),
1424 	      "struct member likely outside of __struct_group()");
1425 
1426 /*
1427  * C_TX = 0x1c (response)
1428  */
1429 struct il3945_tx_resp {
1430 	u8 failure_rts;
1431 	u8 failure_frame;
1432 	u8 bt_kill_count;
1433 	u8 rate;
1434 	__le32 wireless_media_time;
1435 	__le32 status;		/* TX status */
1436 } __packed;
1437 
1438 /*
1439  * 4965 uCode updates these Tx attempt count values in host DRAM.
1440  * Used for managing Tx retries when expecting block-acks.
1441  * Driver should set these fields to 0.
1442  */
1443 struct il_dram_scratch {
1444 	u8 try_cnt;		/* Tx attempts */
1445 	u8 bt_kill_cnt;		/* Tx attempts blocked by Bluetooth device */
1446 	__le16 reserved;
1447 } __packed;
1448 
1449 struct il_tx_cmd {
1450 	/* New members MUST be added within the __struct_group() macro below. */
1451 	__struct_group(il_tx_cmd_hdr, __hdr, __packed,
1452 		/*
1453 		 * MPDU byte count:
1454 		 * MAC header (24/26/30/32 bytes) + 2 bytes pad if 26/30 header size,
1455 		 * + 8 byte IV for CCM or TKIP (not used for WEP)
1456 		 * + Data payload
1457 		 * + 8-byte MIC (not used for CCM/WEP)
1458 		 * NOTE:  Does not include Tx command bytes, post-MAC pad bytes,
1459 		 *        MIC (CCM) 8 bytes, ICV (WEP/TKIP/CKIP) 4 bytes, CRC 4 bytes.i
1460 		 * Range: 14-2342 bytes.
1461 		 */
1462 		__le16 len;
1463 
1464 		/*
1465 		 * MPDU or MSDU byte count for next frame.
1466 		 * Used for fragmentation and bursting, but not 11n aggregation.
1467 		 * Same as "len", but for next frame.  Set to 0 if not applicable.
1468 		 */
1469 		__le16 next_frame_len;
1470 
1471 		__le32 tx_flags;	/* TX_CMD_FLG_* */
1472 
1473 		/* uCode may modify this field of the Tx command (in host DRAM!).
1474 		 * Driver must also set dram_lsb_ptr and dram_msb_ptr in this cmd. */
1475 		struct il_dram_scratch scratch;
1476 
1477 		/* Rate for *all* Tx attempts, if TX_CMD_FLG_STA_RATE_MSK is cleared. */
1478 		__le32 rate_n_flags;	/* RATE_MCS_* */
1479 
1480 		/* Index of destination station in uCode's station table */
1481 		u8 sta_id;
1482 
1483 		/* Type of security encryption:  CCM or TKIP */
1484 		u8 sec_ctl;		/* TX_CMD_SEC_* */
1485 
1486 		/*
1487 		 * Index into rate table (see C_TX_LINK_QUALITY_CMD) for initial
1488 		 * Tx attempt, if TX_CMD_FLG_STA_RATE_MSK is set.  Normally "0" for
1489 		 * data frames, this field may be used to selectively reduce initial
1490 		 * rate (via non-0 value) for special frames (e.g. management), while
1491 		 * still supporting rate scaling for all frames.
1492 		 */
1493 		u8 initial_rate_idx;
1494 		u8 reserved;
1495 		u8 key[16];
1496 		__le16 next_frame_flags;
1497 		__le16 reserved2;
1498 		union {
1499 			__le32 life_time;
1500 			__le32 attempt;
1501 		} stop_time;
1502 
1503 		/* Host DRAM physical address pointer to "scratch" in this command.
1504 		 * Must be dword aligned.  "0" in dram_lsb_ptr disables usage. */
1505 		__le32 dram_lsb_ptr;
1506 		u8 dram_msb_ptr;
1507 
1508 		u8 rts_retry_limit;	/*byte 50 */
1509 		u8 data_retry_limit;	/*byte 51 */
1510 		u8 tid_tspec;
1511 		union {
1512 			__le16 pm_frame_timeout;
1513 			__le16 attempt_duration;
1514 		} timeout;
1515 
1516 		/*
1517 		 * Duration of EDCA burst Tx Opportunity, in 32-usec units.
1518 		 * Set this if txop time is not specified by HCCA protocol (e.g. by AP).
1519 		 */
1520 		__le16 driver_txop;
1521 	);
1522 
1523 	/*
1524 	 * MAC header goes here, followed by 2 bytes padding if MAC header
1525 	 * length is 26 or 30 bytes, followed by payload data
1526 	 */
1527 	struct ieee80211_hdr hdr[];
1528 } __packed;
1529 static_assert(offsetof(struct il_tx_cmd, hdr) == sizeof(struct il_tx_cmd_hdr),
1530 	      "struct member likely outside of __struct_group()");
1531 
1532 /* TX command response is sent after *3945* transmission attempts.
1533  *
1534  * NOTES:
1535  *
1536  * TX_STATUS_FAIL_NEXT_FRAG
1537  *
1538  * If the fragment flag in the MAC header for the frame being transmitted
1539  * is set and there is insufficient time to transmit the next frame, the
1540  * TX status will be returned with 'TX_STATUS_FAIL_NEXT_FRAG'.
1541  *
1542  * TX_STATUS_FIFO_UNDERRUN
1543  *
1544  * Indicates the host did not provide bytes to the FIFO fast enough while
1545  * a TX was in progress.
1546  *
1547  * TX_STATUS_FAIL_MGMNT_ABORT
1548  *
1549  * This status is only possible if the ABORT ON MGMT RX parameter was
1550  * set to true with the TX command.
1551  *
1552  * If the MSB of the status parameter is set then an abort sequence is
1553  * required.  This sequence consists of the host activating the TX Abort
1554  * control line, and then waiting for the TX Abort command response.  This
1555  * indicates that a the device is no longer in a transmit state, and that the
1556  * command FIFO has been cleared.  The host must then deactivate the TX Abort
1557  * control line.  Receiving is still allowed in this case.
1558  */
1559 enum {
1560 	TX_3945_STATUS_SUCCESS = 0x01,
1561 	TX_3945_STATUS_DIRECT_DONE = 0x02,
1562 	TX_3945_STATUS_FAIL_SHORT_LIMIT = 0x82,
1563 	TX_3945_STATUS_FAIL_LONG_LIMIT = 0x83,
1564 	TX_3945_STATUS_FAIL_FIFO_UNDERRUN = 0x84,
1565 	TX_3945_STATUS_FAIL_MGMNT_ABORT = 0x85,
1566 	TX_3945_STATUS_FAIL_NEXT_FRAG = 0x86,
1567 	TX_3945_STATUS_FAIL_LIFE_EXPIRE = 0x87,
1568 	TX_3945_STATUS_FAIL_DEST_PS = 0x88,
1569 	TX_3945_STATUS_FAIL_ABORTED = 0x89,
1570 	TX_3945_STATUS_FAIL_BT_RETRY = 0x8a,
1571 	TX_3945_STATUS_FAIL_STA_INVALID = 0x8b,
1572 	TX_3945_STATUS_FAIL_FRAG_DROPPED = 0x8c,
1573 	TX_3945_STATUS_FAIL_TID_DISABLE = 0x8d,
1574 	TX_3945_STATUS_FAIL_FRAME_FLUSHED = 0x8e,
1575 	TX_3945_STATUS_FAIL_INSUFFICIENT_CF_POLL = 0x8f,
1576 	TX_3945_STATUS_FAIL_TX_LOCKED = 0x90,
1577 	TX_3945_STATUS_FAIL_NO_BEACON_ON_RADAR = 0x91,
1578 };
1579 
1580 /*
1581  * TX command response is sent after *4965* transmission attempts.
1582  *
1583  * both postpone and abort status are expected behavior from uCode. there is
1584  * no special operation required from driver; except for RFKILL_FLUSH,
1585  * which required tx flush host command to flush all the tx frames in queues
1586  */
1587 enum {
1588 	TX_STATUS_SUCCESS = 0x01,
1589 	TX_STATUS_DIRECT_DONE = 0x02,
1590 	/* postpone TX */
1591 	TX_STATUS_POSTPONE_DELAY = 0x40,
1592 	TX_STATUS_POSTPONE_FEW_BYTES = 0x41,
1593 	TX_STATUS_POSTPONE_QUIET_PERIOD = 0x43,
1594 	TX_STATUS_POSTPONE_CALC_TTAK = 0x44,
1595 	/* abort TX */
1596 	TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY = 0x81,
1597 	TX_STATUS_FAIL_SHORT_LIMIT = 0x82,
1598 	TX_STATUS_FAIL_LONG_LIMIT = 0x83,
1599 	TX_STATUS_FAIL_FIFO_UNDERRUN = 0x84,
1600 	TX_STATUS_FAIL_DRAIN_FLOW = 0x85,
1601 	TX_STATUS_FAIL_RFKILL_FLUSH = 0x86,
1602 	TX_STATUS_FAIL_LIFE_EXPIRE = 0x87,
1603 	TX_STATUS_FAIL_DEST_PS = 0x88,
1604 	TX_STATUS_FAIL_HOST_ABORTED = 0x89,
1605 	TX_STATUS_FAIL_BT_RETRY = 0x8a,
1606 	TX_STATUS_FAIL_STA_INVALID = 0x8b,
1607 	TX_STATUS_FAIL_FRAG_DROPPED = 0x8c,
1608 	TX_STATUS_FAIL_TID_DISABLE = 0x8d,
1609 	TX_STATUS_FAIL_FIFO_FLUSHED = 0x8e,
1610 	TX_STATUS_FAIL_INSUFFICIENT_CF_POLL = 0x8f,
1611 	TX_STATUS_FAIL_PASSIVE_NO_RX = 0x90,
1612 	TX_STATUS_FAIL_NO_BEACON_ON_RADAR = 0x91,
1613 };
1614 
1615 #define	TX_PACKET_MODE_REGULAR		0x0000
1616 #define	TX_PACKET_MODE_BURST_SEQ	0x0100
1617 #define	TX_PACKET_MODE_BURST_FIRST	0x0200
1618 
1619 enum {
1620 	TX_POWER_PA_NOT_ACTIVE = 0x0,
1621 };
1622 
1623 enum {
1624 	TX_STATUS_MSK = 0x000000ff,	/* bits 0:7 */
1625 	TX_STATUS_DELAY_MSK = 0x00000040,
1626 	TX_STATUS_ABORT_MSK = 0x00000080,
1627 	TX_PACKET_MODE_MSK = 0x0000ff00,	/* bits 8:15 */
1628 	TX_FIFO_NUMBER_MSK = 0x00070000,	/* bits 16:18 */
1629 	TX_RESERVED = 0x00780000,	/* bits 19:22 */
1630 	TX_POWER_PA_DETECT_MSK = 0x7f800000,	/* bits 23:30 */
1631 	TX_ABORT_REQUIRED_MSK = 0x80000000,	/* bits 31:31 */
1632 };
1633 
1634 /* *******************************
1635  * TX aggregation status
1636  ******************************* */
1637 
1638 enum {
1639 	AGG_TX_STATE_TRANSMITTED = 0x00,
1640 	AGG_TX_STATE_UNDERRUN_MSK = 0x01,
1641 	AGG_TX_STATE_FEW_BYTES_MSK = 0x04,
1642 	AGG_TX_STATE_ABORT_MSK = 0x08,
1643 	AGG_TX_STATE_LAST_SENT_TTL_MSK = 0x10,
1644 	AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK = 0x20,
1645 	AGG_TX_STATE_SCD_QUERY_MSK = 0x80,
1646 	AGG_TX_STATE_TEST_BAD_CRC32_MSK = 0x100,
1647 	AGG_TX_STATE_RESPONSE_MSK = 0x1ff,
1648 	AGG_TX_STATE_DUMP_TX_MSK = 0x200,
1649 	AGG_TX_STATE_DELAY_TX_MSK = 0x400
1650 };
1651 
1652 #define AGG_TX_STATUS_MSK	0x00000fff	/* bits 0:11 */
1653 #define AGG_TX_TRY_MSK		0x0000f000	/* bits 12:15 */
1654 
1655 #define AGG_TX_STATE_LAST_SENT_MSK  (AGG_TX_STATE_LAST_SENT_TTL_MSK | \
1656 				     AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK)
1657 
1658 /* # tx attempts for first frame in aggregation */
1659 #define AGG_TX_STATE_TRY_CNT_POS 12
1660 #define AGG_TX_STATE_TRY_CNT_MSK 0xf000
1661 
1662 /* Command ID and sequence number of Tx command for this frame */
1663 #define AGG_TX_STATE_SEQ_NUM_POS 16
1664 #define AGG_TX_STATE_SEQ_NUM_MSK 0xffff0000
1665 
1666 /*
1667  * C_TX = 0x1c (response)
1668  *
1669  * This response may be in one of two slightly different formats, indicated
1670  * by the frame_count field:
1671  *
1672  * 1)  No aggregation (frame_count == 1).  This reports Tx results for
1673  *     a single frame.  Multiple attempts, at various bit rates, may have
1674  *     been made for this frame.
1675  *
1676  * 2)  Aggregation (frame_count > 1).  This reports Tx results for
1677  *     2 or more frames that used block-acknowledge.  All frames were
1678  *     transmitted at same rate.  Rate scaling may have been used if first
1679  *     frame in this new agg block failed in previous agg block(s).
1680  *
1681  *     Note that, for aggregation, ACK (block-ack) status is not delivered here;
1682  *     block-ack has not been received by the time the 4965 device records
1683  *     this status.
1684  *     This status relates to reasons the tx might have been blocked or aborted
1685  *     within the sending station (this 4965 device), rather than whether it was
1686  *     received successfully by the destination station.
1687  */
1688 struct agg_tx_status {
1689 	__le16 status;
1690 	__le16 sequence;
1691 } __packed;
1692 
1693 struct il4965_tx_resp_hdr {
1694 	u8 frame_count;		/* 1 no aggregation, >1 aggregation */
1695 	u8 bt_kill_count;	/* # blocked by bluetooth (unused for agg) */
1696 	u8 failure_rts;		/* # failures due to unsuccessful RTS */
1697 	u8 failure_frame;	/* # failures due to no ACK (unused for agg) */
1698 
1699 	/* For non-agg:  Rate at which frame was successful.
1700 	 * For agg:  Rate at which all frames were transmitted. */
1701 	__le32 rate_n_flags;	/* RATE_MCS_*  */
1702 
1703 	/* For non-agg:  RTS + CTS + frame tx attempts time + ACK.
1704 	 * For agg:  RTS + CTS + aggregation tx time + block-ack time. */
1705 	__le16 wireless_media_time;	/* uSecs */
1706 
1707 	__le16 reserved;
1708 	__le32 pa_power1;	/* RF power amplifier measurement (not used) */
1709 	__le32 pa_power2;
1710 } __packed;
1711 
1712 struct il4965_tx_resp {
1713 	struct il4965_tx_resp_hdr;
1714 
1715 	/*
1716 	 * For non-agg:  frame status TX_STATUS_*
1717 	 * For agg:  status of 1st frame, AGG_TX_STATE_*; other frame status
1718 	 *           fields follow this one, up to frame_count.
1719 	 *           Bit fields:
1720 	 *           11- 0:  AGG_TX_STATE_* status code
1721 	 *           15-12:  Retry count for 1st frame in aggregation (retries
1722 	 *                   occur if tx failed for this frame when it was a
1723 	 *                   member of a previous aggregation block).  If rate
1724 	 *                   scaling is used, retry count indicates the rate
1725 	 *                   table entry used for all frames in the new agg.
1726 	 *           31-16:  Sequence # for this frame's Tx cmd (not SSN!)
1727 	 */
1728 	union {
1729 		__le32 status;
1730 		DECLARE_FLEX_ARRAY(struct agg_tx_status, agg_status);	/* for each agg frame */
1731 	} u;
1732 } __packed;
1733 
1734 /*
1735  * N_COMPRESSED_BA = 0xc5 (response only, not a command)
1736  *
1737  * Reports Block-Acknowledge from recipient station
1738  */
1739 struct il_compressed_ba_resp {
1740 	__le32 sta_addr_lo32;
1741 	__le16 sta_addr_hi16;
1742 	__le16 reserved;
1743 
1744 	/* Index of recipient (BA-sending) station in uCode's station table */
1745 	u8 sta_id;
1746 	u8 tid;
1747 	__le16 seq_ctl;
1748 	__le64 bitmap;
1749 	__le16 scd_flow;
1750 	__le16 scd_ssn;
1751 } __packed;
1752 
1753 /*
1754  * C_TX_PWR_TBL = 0x97 (command, has simple generic response)
1755  *
1756  * See details under "TXPOWER" in 4965.h.
1757  */
1758 
1759 struct il3945_txpowertable_cmd {
1760 	u8 band;		/* 0: 5 GHz, 1: 2.4 GHz */
1761 	u8 reserved;
1762 	__le16 channel;
1763 	struct il3945_power_per_rate power[IL_MAX_RATES];
1764 } __packed;
1765 
1766 struct il4965_txpowertable_cmd {
1767 	u8 band;		/* 0: 5 GHz, 1: 2.4 GHz */
1768 	u8 reserved;
1769 	__le16 channel;
1770 	struct il4965_tx_power_db tx_power;
1771 } __packed;
1772 
1773 /**
1774  * struct il3945_rate_scaling_cmd - Rate Scaling Command & Response
1775  *
1776  * C_RATE_SCALE = 0x47 (command, has simple generic response)
1777  *
1778  * NOTE: The table of rates passed to the uCode via the
1779  * RATE_SCALE command sets up the corresponding order of
1780  * rates used for all related commands, including rate
1781  * masks, etc.
1782  *
1783  * For example, if you set 9MB (PLCP 0x0f) as the first
1784  * rate in the rate table, the bit mask for that rate
1785  * when passed through ofdm_basic_rates on the C_RXON
1786  * command would be bit 0 (1 << 0)
1787  */
1788 struct il3945_rate_scaling_info {
1789 	__le16 rate_n_flags;
1790 	u8 try_cnt;
1791 	u8 next_rate_idx;
1792 } __packed;
1793 
1794 struct il3945_rate_scaling_cmd {
1795 	u8 table_id;
1796 	u8 reserved[3];
1797 	struct il3945_rate_scaling_info table[IL_MAX_RATES];
1798 } __packed;
1799 
1800 /*RS_NEW_API: only TLC_RTS remains and moved to bit 0 */
1801 #define  LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK	(1 << 0)
1802 
1803 /* # of EDCA prioritized tx fifos */
1804 #define  LINK_QUAL_AC_NUM AC_NUM
1805 
1806 /* # entries in rate scale table to support Tx retries */
1807 #define  LINK_QUAL_MAX_RETRY_NUM 16
1808 
1809 /* Tx antenna selection values */
1810 #define  LINK_QUAL_ANT_A_MSK (1 << 0)
1811 #define  LINK_QUAL_ANT_B_MSK (1 << 1)
1812 #define  LINK_QUAL_ANT_MSK   (LINK_QUAL_ANT_A_MSK|LINK_QUAL_ANT_B_MSK)
1813 
1814 /**
1815  * struct il_link_qual_general_params
1816  *
1817  * Used in C_TX_LINK_QUALITY_CMD
1818  */
1819 struct il_link_qual_general_params {
1820 	u8 flags;
1821 
1822 	/* No entries at or above this (driver chosen) idx contain MIMO */
1823 	u8 mimo_delimiter;
1824 
1825 	/* Best single antenna to use for single stream (legacy, SISO). */
1826 	u8 single_stream_ant_msk;	/* LINK_QUAL_ANT_* */
1827 
1828 	/* Best antennas to use for MIMO (unused for 4965, assumes both). */
1829 	u8 dual_stream_ant_msk;	/* LINK_QUAL_ANT_* */
1830 
1831 	/*
1832 	 * If driver needs to use different initial rates for different
1833 	 * EDCA QOS access categories (as implemented by tx fifos 0-3),
1834 	 * this table will set that up, by indicating the idxes in the
1835 	 * rs_table[LINK_QUAL_MAX_RETRY_NUM] rate table at which to start.
1836 	 * Otherwise, driver should set all entries to 0.
1837 	 *
1838 	 * Entry usage:
1839 	 * 0 = Background, 1 = Best Effort (normal), 2 = Video, 3 = Voice
1840 	 * TX FIFOs above 3 use same value (typically 0) as TX FIFO 3.
1841 	 */
1842 	u8 start_rate_idx[LINK_QUAL_AC_NUM];
1843 } __packed;
1844 
1845 #define LINK_QUAL_AGG_TIME_LIMIT_DEF	(4000)	/* 4 milliseconds */
1846 #define LINK_QUAL_AGG_TIME_LIMIT_MAX	(8000)
1847 #define LINK_QUAL_AGG_TIME_LIMIT_MIN	(100)
1848 
1849 #define LINK_QUAL_AGG_DISABLE_START_DEF	(3)
1850 #define LINK_QUAL_AGG_DISABLE_START_MAX	(255)
1851 #define LINK_QUAL_AGG_DISABLE_START_MIN	(0)
1852 
1853 #define LINK_QUAL_AGG_FRAME_LIMIT_DEF	(31)
1854 #define LINK_QUAL_AGG_FRAME_LIMIT_MAX	(63)
1855 #define LINK_QUAL_AGG_FRAME_LIMIT_MIN	(0)
1856 
1857 /**
1858  * struct il_link_qual_agg_params
1859  *
1860  * Used in C_TX_LINK_QUALITY_CMD
1861  */
1862 struct il_link_qual_agg_params {
1863 
1864 	/*
1865 	 *Maximum number of uSec in aggregation.
1866 	 * default set to 4000 (4 milliseconds) if not configured in .cfg
1867 	 */
1868 	__le16 agg_time_limit;
1869 
1870 	/*
1871 	 * Number of Tx retries allowed for a frame, before that frame will
1872 	 * no longer be considered for the start of an aggregation sequence
1873 	 * (scheduler will then try to tx it as single frame).
1874 	 * Driver should set this to 3.
1875 	 */
1876 	u8 agg_dis_start_th;
1877 
1878 	/*
1879 	 * Maximum number of frames in aggregation.
1880 	 * 0 = no limit (default).  1 = no aggregation.
1881 	 * Other values = max # frames in aggregation.
1882 	 */
1883 	u8 agg_frame_cnt_limit;
1884 
1885 	__le32 reserved;
1886 } __packed;
1887 
1888 /*
1889  * C_TX_LINK_QUALITY_CMD = 0x4e (command, has simple generic response)
1890  *
1891  * For 4965 devices only; 3945 uses C_RATE_SCALE.
1892  *
1893  * Each station in the 4965 device's internal station table has its own table
1894  * of 16
1895  * Tx rates and modulation modes (e.g. legacy/SISO/MIMO) for retrying Tx when
1896  * an ACK is not received.  This command replaces the entire table for
1897  * one station.
1898  *
1899  * NOTE:  Station must already be in 4965 device's station table.
1900  *	  Use C_ADD_STA.
1901  *
1902  * The rate scaling procedures described below work well.  Of course, other
1903  * procedures are possible, and may work better for particular environments.
1904  *
1905  *
1906  * FILLING THE RATE TBL
1907  *
1908  * Given a particular initial rate and mode, as determined by the rate
1909  * scaling algorithm described below, the Linux driver uses the following
1910  * formula to fill the rs_table[LINK_QUAL_MAX_RETRY_NUM] rate table in the
1911  * Link Quality command:
1912  *
1913  *
1914  * 1)  If using High-throughput (HT) (SISO or MIMO) initial rate:
1915  *     a) Use this same initial rate for first 3 entries.
1916  *     b) Find next lower available rate using same mode (SISO or MIMO),
1917  *        use for next 3 entries.  If no lower rate available, switch to
1918  *        legacy mode (no HT40 channel, no MIMO, no short guard interval).
1919  *     c) If using MIMO, set command's mimo_delimiter to number of entries
1920  *        using MIMO (3 or 6).
1921  *     d) After trying 2 HT rates, switch to legacy mode (no HT40 channel,
1922  *        no MIMO, no short guard interval), at the next lower bit rate
1923  *        (e.g. if second HT bit rate was 54, try 48 legacy), and follow
1924  *        legacy procedure for remaining table entries.
1925  *
1926  * 2)  If using legacy initial rate:
1927  *     a) Use the initial rate for only one entry.
1928  *     b) For each following entry, reduce the rate to next lower available
1929  *        rate, until reaching the lowest available rate.
1930  *     c) When reducing rate, also switch antenna selection.
1931  *     d) Once lowest available rate is reached, repeat this rate until
1932  *        rate table is filled (16 entries), switching antenna each entry.
1933  *
1934  *
1935  * ACCUMULATING HISTORY
1936  *
1937  * The rate scaling algorithm for 4965 devices, as implemented in Linux driver,
1938  * uses two sets of frame Tx success history:  One for the current/active
1939  * modulation mode, and one for a speculative/search mode that is being
1940  * attempted. If the speculative mode turns out to be more effective (i.e.
1941  * actual transfer rate is better), then the driver continues to use the
1942  * speculative mode as the new current active mode.
1943  *
1944  * Each history set contains, separately for each possible rate, data for a
1945  * sliding win of the 62 most recent tx attempts at that rate.  The data
1946  * includes a shifting bitmap of success(1)/failure(0), and sums of successful
1947  * and attempted frames, from which the driver can additionally calculate a
1948  * success ratio (success / attempted) and number of failures
1949  * (attempted - success), and control the size of the win (attempted).
1950  * The driver uses the bit map to remove successes from the success sum, as
1951  * the oldest tx attempts fall out of the win.
1952  *
1953  * When the 4965 device makes multiple tx attempts for a given frame, each
1954  * attempt might be at a different rate, and have different modulation
1955  * characteristics (e.g. antenna, fat channel, short guard interval), as set
1956  * up in the rate scaling table in the Link Quality command.  The driver must
1957  * determine which rate table entry was used for each tx attempt, to determine
1958  * which rate-specific history to update, and record only those attempts that
1959  * match the modulation characteristics of the history set.
1960  *
1961  * When using block-ack (aggregation), all frames are transmitted at the same
1962  * rate, since there is no per-attempt acknowledgment from the destination
1963  * station.  The Tx response struct il_tx_resp indicates the Tx rate in
1964  * rate_n_flags field.  After receiving a block-ack, the driver can update
1965  * history for the entire block all at once.
1966  *
1967  *
1968  * FINDING BEST STARTING RATE:
1969  *
1970  * When working with a selected initial modulation mode (see below), the
1971  * driver attempts to find a best initial rate.  The initial rate is the
1972  * first entry in the Link Quality command's rate table.
1973  *
1974  * 1)  Calculate actual throughput (success ratio * expected throughput, see
1975  *     table below) for current initial rate.  Do this only if enough frames
1976  *     have been attempted to make the value meaningful:  at least 6 failed
1977  *     tx attempts, or at least 8 successes.  If not enough, don't try rate
1978  *     scaling yet.
1979  *
1980  * 2)  Find available rates adjacent to current initial rate.  Available means:
1981  *     a)  supported by hardware &&
1982  *     b)  supported by association &&
1983  *     c)  within any constraints selected by user
1984  *
1985  * 3)  Gather measured throughputs for adjacent rates.  These might not have
1986  *     enough history to calculate a throughput.  That's okay, we might try
1987  *     using one of them anyway!
1988  *
1989  * 4)  Try decreasing rate if, for current rate:
1990  *     a)  success ratio is < 15% ||
1991  *     b)  lower adjacent rate has better measured throughput ||
1992  *     c)  higher adjacent rate has worse throughput, and lower is unmeasured
1993  *
1994  *     As a sanity check, if decrease was determined above, leave rate
1995  *     unchanged if:
1996  *     a)  lower rate unavailable
1997  *     b)  success ratio at current rate > 85% (very good)
1998  *     c)  current measured throughput is better than expected throughput
1999  *         of lower rate (under perfect 100% tx conditions, see table below)
2000  *
2001  * 5)  Try increasing rate if, for current rate:
2002  *     a)  success ratio is < 15% ||
2003  *     b)  both adjacent rates' throughputs are unmeasured (try it!) ||
2004  *     b)  higher adjacent rate has better measured throughput ||
2005  *     c)  lower adjacent rate has worse throughput, and higher is unmeasured
2006  *
2007  *     As a sanity check, if increase was determined above, leave rate
2008  *     unchanged if:
2009  *     a)  success ratio at current rate < 70%.  This is not particularly
2010  *         good performance; higher rate is sure to have poorer success.
2011  *
2012  * 6)  Re-evaluate the rate after each tx frame.  If working with block-
2013  *     acknowledge, history and stats may be calculated for the entire
2014  *     block (including prior history that fits within the history wins),
2015  *     before re-evaluation.
2016  *
2017  * FINDING BEST STARTING MODULATION MODE:
2018  *
2019  * After working with a modulation mode for a "while" (and doing rate scaling),
2020  * the driver searches for a new initial mode in an attempt to improve
2021  * throughput.  The "while" is measured by numbers of attempted frames:
2022  *
2023  * For legacy mode, search for new mode after:
2024  *   480 successful frames, or 160 failed frames
2025  * For high-throughput modes (SISO or MIMO), search for new mode after:
2026  *   4500 successful frames, or 400 failed frames
2027  *
2028  * Mode switch possibilities are (3 for each mode):
2029  *
2030  * For legacy:
2031  *   Change antenna, try SISO (if HT association), try MIMO (if HT association)
2032  * For SISO:
2033  *   Change antenna, try MIMO, try shortened guard interval (SGI)
2034  * For MIMO:
2035  *   Try SISO antenna A, SISO antenna B, try shortened guard interval (SGI)
2036  *
2037  * When trying a new mode, use the same bit rate as the old/current mode when
2038  * trying antenna switches and shortened guard interval.  When switching to
2039  * SISO from MIMO or legacy, or to MIMO from SISO or legacy, use a rate
2040  * for which the expected throughput (under perfect conditions) is about the
2041  * same or slightly better than the actual measured throughput delivered by
2042  * the old/current mode.
2043  *
2044  * Actual throughput can be estimated by multiplying the expected throughput
2045  * by the success ratio (successful / attempted tx frames).  Frame size is
2046  * not considered in this calculation; it assumes that frame size will average
2047  * out to be fairly consistent over several samples.  The following are
2048  * metric values for expected throughput assuming 100% success ratio.
2049  * Only G band has support for CCK rates:
2050  *
2051  *           RATE:  1    2    5   11    6   9   12   18   24   36   48   54   60
2052  *
2053  *              G:  7   13   35   58   40  57   72   98  121  154  177  186  186
2054  *              A:  0    0    0    0   40  57   72   98  121  154  177  186  186
2055  *     SISO 20MHz:  0    0    0    0   42  42   76  102  124  159  183  193  202
2056  * SGI SISO 20MHz:  0    0    0    0   46  46   82  110  132  168  192  202  211
2057  *     MIMO 20MHz:  0    0    0    0   74  74  123  155  179  214  236  244  251
2058  * SGI MIMO 20MHz:  0    0    0    0   81  81  131  164  188  222  243  251  257
2059  *     SISO 40MHz:  0    0    0    0   77  77  127  160  184  220  242  250  257
2060  * SGI SISO 40MHz:  0    0    0    0   83  83  135  169  193  229  250  257  264
2061  *     MIMO 40MHz:  0    0    0    0  123 123  182  214  235  264  279  285  289
2062  * SGI MIMO 40MHz:  0    0    0    0  131 131  191  222  242  270  284  289  293
2063  *
2064  * After the new mode has been tried for a short while (minimum of 6 failed
2065  * frames or 8 successful frames), compare success ratio and actual throughput
2066  * estimate of the new mode with the old.  If either is better with the new
2067  * mode, continue to use the new mode.
2068  *
2069  * Continue comparing modes until all 3 possibilities have been tried.
2070  * If moving from legacy to HT, try all 3 possibilities from the new HT
2071  * mode.  After trying all 3, a best mode is found.  Continue to use this mode
2072  * for the longer "while" described above (e.g. 480 successful frames for
2073  * legacy), and then repeat the search process.
2074  *
2075  */
2076 struct il_link_quality_cmd {
2077 
2078 	/* Index of destination/recipient station in uCode's station table */
2079 	u8 sta_id;
2080 	u8 reserved1;
2081 	__le16 control;		/* not used */
2082 	struct il_link_qual_general_params general_params;
2083 	struct il_link_qual_agg_params agg_params;
2084 
2085 	/*
2086 	 * Rate info; when using rate-scaling, Tx command's initial_rate_idx
2087 	 * specifies 1st Tx rate attempted, via idx into this table.
2088 	 * 4965 devices works its way through table when retrying Tx.
2089 	 */
2090 	struct {
2091 		__le32 rate_n_flags;	/* RATE_MCS_*, RATE_* */
2092 	} rs_table[LINK_QUAL_MAX_RETRY_NUM];
2093 	__le32 reserved2;
2094 } __packed;
2095 
2096 /*
2097  * BT configuration enable flags:
2098  *   bit 0 - 1: BT channel announcement enabled
2099  *           0: disable
2100  *   bit 1 - 1: priority of BT device enabled
2101  *           0: disable
2102  */
2103 #define BT_COEX_DISABLE (0x0)
2104 #define BT_ENABLE_CHANNEL_ANNOUNCE BIT(0)
2105 #define BT_ENABLE_PRIORITY	   BIT(1)
2106 
2107 #define BT_COEX_ENABLE  (BT_ENABLE_CHANNEL_ANNOUNCE | BT_ENABLE_PRIORITY)
2108 
2109 #define BT_LEAD_TIME_DEF (0x1E)
2110 
2111 #define BT_MAX_KILL_DEF (0x5)
2112 
2113 /*
2114  * C_BT_CONFIG = 0x9b (command, has simple generic response)
2115  *
2116  * 3945 and 4965 devices support hardware handshake with Bluetooth device on
2117  * same platform.  Bluetooth device alerts wireless device when it will Tx;
2118  * wireless device can delay or kill its own Tx to accommodate.
2119  */
2120 struct il_bt_cmd {
2121 	u8 flags;
2122 	u8 lead_time;
2123 	u8 max_kill;
2124 	u8 reserved;
2125 	__le32 kill_ack_mask;
2126 	__le32 kill_cts_mask;
2127 } __packed;
2128 
2129 /******************************************************************************
2130  * (6)
2131  * Spectrum Management (802.11h) Commands, Responses, Notifications:
2132  *
2133  *****************************************************************************/
2134 
2135 /*
2136  * Spectrum Management
2137  */
2138 #define MEASUREMENT_FILTER_FLAG (RXON_FILTER_PROMISC_MSK         | \
2139 				 RXON_FILTER_CTL2HOST_MSK        | \
2140 				 RXON_FILTER_ACCEPT_GRP_MSK      | \
2141 				 RXON_FILTER_DIS_DECRYPT_MSK     | \
2142 				 RXON_FILTER_DIS_GRP_DECRYPT_MSK | \
2143 				 RXON_FILTER_ASSOC_MSK           | \
2144 				 RXON_FILTER_BCON_AWARE_MSK)
2145 
2146 struct il_measure_channel {
2147 	__le32 duration;	/* measurement duration in extended beacon
2148 				 * format */
2149 	u8 channel;		/* channel to measure */
2150 	u8 type;		/* see enum il_measure_type */
2151 	__le16 reserved;
2152 } __packed;
2153 
2154 /*
2155  * C_SPECTRUM_MEASUREMENT = 0x74 (command)
2156  */
2157 struct il_spectrum_cmd {
2158 	__le16 len;		/* number of bytes starting from token */
2159 	u8 token;		/* token id */
2160 	u8 id;			/* measurement id -- 0 or 1 */
2161 	u8 origin;		/* 0 = TGh, 1 = other, 2 = TGk */
2162 	u8 periodic;		/* 1 = periodic */
2163 	__le16 path_loss_timeout;
2164 	__le32 start_time;	/* start time in extended beacon format */
2165 	__le32 reserved2;
2166 	__le32 flags;		/* rxon flags */
2167 	__le32 filter_flags;	/* rxon filter flags */
2168 	__le16 channel_count;	/* minimum 1, maximum 10 */
2169 	__le16 reserved3;
2170 	struct il_measure_channel channels[10];
2171 } __packed;
2172 
2173 /*
2174  * C_SPECTRUM_MEASUREMENT = 0x74 (response)
2175  */
2176 struct il_spectrum_resp {
2177 	u8 token;
2178 	u8 id;			/* id of the prior command replaced, or 0xff */
2179 	__le16 status;		/* 0 - command will be handled
2180 				 * 1 - cannot handle (conflicts with another
2181 				 *     measurement) */
2182 } __packed;
2183 
2184 enum il_measurement_state {
2185 	IL_MEASUREMENT_START = 0,
2186 	IL_MEASUREMENT_STOP = 1,
2187 };
2188 
2189 enum il_measurement_status {
2190 	IL_MEASUREMENT_OK = 0,
2191 	IL_MEASUREMENT_CONCURRENT = 1,
2192 	IL_MEASUREMENT_CSA_CONFLICT = 2,
2193 	IL_MEASUREMENT_TGH_CONFLICT = 3,
2194 	/* 4-5 reserved */
2195 	IL_MEASUREMENT_STOPPED = 6,
2196 	IL_MEASUREMENT_TIMEOUT = 7,
2197 	IL_MEASUREMENT_PERIODIC_FAILED = 8,
2198 };
2199 
2200 #define NUM_ELEMENTS_IN_HISTOGRAM 8
2201 
2202 struct il_measurement_histogram {
2203 	__le32 ofdm[NUM_ELEMENTS_IN_HISTOGRAM];	/* in 0.8usec counts */
2204 	__le32 cck[NUM_ELEMENTS_IN_HISTOGRAM];	/* in 1usec counts */
2205 } __packed;
2206 
2207 /* clear channel availability counters */
2208 struct il_measurement_cca_counters {
2209 	__le32 ofdm;
2210 	__le32 cck;
2211 } __packed;
2212 
2213 enum il_measure_type {
2214 	IL_MEASURE_BASIC = (1 << 0),
2215 	IL_MEASURE_CHANNEL_LOAD = (1 << 1),
2216 	IL_MEASURE_HISTOGRAM_RPI = (1 << 2),
2217 	IL_MEASURE_HISTOGRAM_NOISE = (1 << 3),
2218 	IL_MEASURE_FRAME = (1 << 4),
2219 	/* bits 5:6 are reserved */
2220 	IL_MEASURE_IDLE = (1 << 7),
2221 };
2222 
2223 /*
2224  * N_SPECTRUM_MEASUREMENT = 0x75 (notification only, not a command)
2225  */
2226 struct il_spectrum_notification {
2227 	u8 id;			/* measurement id -- 0 or 1 */
2228 	u8 token;
2229 	u8 channel_idx;		/* idx in measurement channel list */
2230 	u8 state;		/* 0 - start, 1 - stop */
2231 	__le32 start_time;	/* lower 32-bits of TSF */
2232 	u8 band;		/* 0 - 5.2GHz, 1 - 2.4GHz */
2233 	u8 channel;
2234 	u8 type;		/* see enum il_measurement_type */
2235 	u8 reserved1;
2236 	/* NOTE:  cca_ofdm, cca_cck, basic_type, and histogram are only
2237 	 * valid if applicable for measurement type requested. */
2238 	__le32 cca_ofdm;	/* cca fraction time in 40Mhz clock periods */
2239 	__le32 cca_cck;		/* cca fraction time in 44Mhz clock periods */
2240 	__le32 cca_time;	/* channel load time in usecs */
2241 	u8 basic_type;		/* 0 - bss, 1 - ofdm preamble, 2 -
2242 				 * unidentified */
2243 	u8 reserved2[3];
2244 	struct il_measurement_histogram histogram;
2245 	__le32 stop_time;	/* lower 32-bits of TSF */
2246 	__le32 status;		/* see il_measurement_status */
2247 } __packed;
2248 
2249 /******************************************************************************
2250  * (7)
2251  * Power Management Commands, Responses, Notifications:
2252  *
2253  *****************************************************************************/
2254 
2255 /**
2256  * struct il_powertable_cmd - Power Table Command
2257  * @flags: See below:
2258  *
2259  * C_POWER_TBL = 0x77 (command, has simple generic response)
2260  *
2261  * PM allow:
2262  *   bit 0 - '0' Driver not allow power management
2263  *           '1' Driver allow PM (use rest of parameters)
2264  *
2265  * uCode send sleep notifications:
2266  *   bit 1 - '0' Don't send sleep notification
2267  *           '1' send sleep notification (SEND_PM_NOTIFICATION)
2268  *
2269  * Sleep over DTIM
2270  *   bit 2 - '0' PM have to walk up every DTIM
2271  *           '1' PM could sleep over DTIM till listen Interval.
2272  *
2273  * PCI power managed
2274  *   bit 3 - '0' (PCI_CFG_LINK_CTRL & 0x1)
2275  *           '1' !(PCI_CFG_LINK_CTRL & 0x1)
2276  *
2277  * Fast PD
2278  *   bit 4 - '1' Put radio to sleep when receiving frame for others
2279  *
2280  * Force sleep Modes
2281  *   bit 31/30- '00' use both mac/xtal sleeps
2282  *              '01' force Mac sleep
2283  *              '10' force xtal sleep
2284  *              '11' Illegal set
2285  *
2286  * NOTE: if sleep_interval[SLEEP_INTRVL_TBL_SIZE-1] > DTIM period then
2287  * ucode assume sleep over DTIM is allowed and we don't need to wake up
2288  * for every DTIM.
2289  */
2290 #define IL_POWER_VEC_SIZE 5
2291 
2292 #define IL_POWER_DRIVER_ALLOW_SLEEP_MSK		cpu_to_le16(BIT(0))
2293 #define IL_POWER_SLEEP_OVER_DTIM_MSK		cpu_to_le16(BIT(2))
2294 #define IL_POWER_PCI_PM_MSK			cpu_to_le16(BIT(3))
2295 
2296 struct il3945_powertable_cmd {
2297 	__le16 flags;
2298 	u8 reserved[2];
2299 	__le32 rx_data_timeout;
2300 	__le32 tx_data_timeout;
2301 	__le32 sleep_interval[IL_POWER_VEC_SIZE];
2302 } __packed;
2303 
2304 struct il_powertable_cmd {
2305 	__le16 flags;
2306 	u8 keep_alive_seconds;	/* 3945 reserved */
2307 	u8 debug_flags;		/* 3945 reserved */
2308 	__le32 rx_data_timeout;
2309 	__le32 tx_data_timeout;
2310 	__le32 sleep_interval[IL_POWER_VEC_SIZE];
2311 	__le32 keep_alive_beacons;
2312 } __packed;
2313 
2314 /*
2315  * N_PM_SLEEP = 0x7A (notification only, not a command)
2316  * all devices identical.
2317  */
2318 struct il_sleep_notification {
2319 	u8 pm_sleep_mode;
2320 	u8 pm_wakeup_src;
2321 	__le16 reserved;
2322 	__le32 sleep_time;
2323 	__le32 tsf_low;
2324 	__le32 bcon_timer;
2325 } __packed;
2326 
2327 /* Sleep states.  all devices identical. */
2328 enum {
2329 	IL_PM_NO_SLEEP = 0,
2330 	IL_PM_SLP_MAC = 1,
2331 	IL_PM_SLP_FULL_MAC_UNASSOCIATE = 2,
2332 	IL_PM_SLP_FULL_MAC_CARD_STATE = 3,
2333 	IL_PM_SLP_PHY = 4,
2334 	IL_PM_SLP_REPENT = 5,
2335 	IL_PM_WAKEUP_BY_TIMER = 6,
2336 	IL_PM_WAKEUP_BY_DRIVER = 7,
2337 	IL_PM_WAKEUP_BY_RFKILL = 8,
2338 	/* 3 reserved */
2339 	IL_PM_NUM_OF_MODES = 12,
2340 };
2341 
2342 /*
2343  * N_CARD_STATE = 0xa1 (notification only, not a command)
2344  */
2345 struct il_card_state_notif {
2346 	__le32 flags;
2347 } __packed;
2348 
2349 #define HW_CARD_DISABLED   0x01
2350 #define SW_CARD_DISABLED   0x02
2351 #define CT_CARD_DISABLED   0x04
2352 #define RXON_CARD_DISABLED 0x10
2353 
2354 struct il_ct_kill_config {
2355 	__le32 reserved;
2356 	__le32 critical_temperature_M;
2357 	__le32 critical_temperature_R;
2358 } __packed;
2359 
2360 /******************************************************************************
2361  * (8)
2362  * Scan Commands, Responses, Notifications:
2363  *
2364  *****************************************************************************/
2365 
2366 #define SCAN_CHANNEL_TYPE_PASSIVE cpu_to_le32(0)
2367 #define SCAN_CHANNEL_TYPE_ACTIVE  cpu_to_le32(1)
2368 
2369 /**
2370  * struct il_scan_channel - entry in C_SCAN channel table
2371  *
2372  * One for each channel in the scan list.
2373  * Each channel can independently select:
2374  * 1)  SSID for directed active scans
2375  * 2)  Txpower setting (for rate specified within Tx command)
2376  * 3)  How long to stay on-channel (behavior may be modified by quiet_time,
2377  *     quiet_plcp_th, good_CRC_th)
2378  *
2379  * To avoid uCode errors, make sure the following are true (see comments
2380  * under struct il_scan_cmd about max_out_time and quiet_time):
2381  * 1)  If using passive_dwell (i.e. passive_dwell != 0):
2382  *     active_dwell <= passive_dwell (< max_out_time if max_out_time != 0)
2383  * 2)  quiet_time <= active_dwell
2384  * 3)  If restricting off-channel time (i.e. max_out_time !=0):
2385  *     passive_dwell < max_out_time
2386  *     active_dwell < max_out_time
2387  */
2388 struct il3945_scan_channel {
2389 	/*
2390 	 * type is defined as:
2391 	 * 0:0 1 = active, 0 = passive
2392 	 * 1:4 SSID direct bit map; if a bit is set, then corresponding
2393 	 *     SSID IE is transmitted in probe request.
2394 	 * 5:7 reserved
2395 	 */
2396 	u8 type;
2397 	u8 channel;		/* band is selected by il3945_scan_cmd "flags" field */
2398 	struct il3945_tx_power tpc;
2399 	__le16 active_dwell;	/* in 1024-uSec TU (time units), typ 5-50 */
2400 	__le16 passive_dwell;	/* in 1024-uSec TU (time units), typ 20-500 */
2401 } __packed;
2402 
2403 /* set number of direct probes u8 type */
2404 #define IL39_SCAN_PROBE_MASK(n) ((BIT(n) | (BIT(n) - BIT(1))))
2405 
2406 struct il_scan_channel {
2407 	/*
2408 	 * type is defined as:
2409 	 * 0:0 1 = active, 0 = passive
2410 	 * 1:20 SSID direct bit map; if a bit is set, then corresponding
2411 	 *     SSID IE is transmitted in probe request.
2412 	 * 21:31 reserved
2413 	 */
2414 	__le32 type;
2415 	__le16 channel;		/* band is selected by il_scan_cmd "flags" field */
2416 	u8 tx_gain;		/* gain for analog radio */
2417 	u8 dsp_atten;		/* gain for DSP */
2418 	__le16 active_dwell;	/* in 1024-uSec TU (time units), typ 5-50 */
2419 	__le16 passive_dwell;	/* in 1024-uSec TU (time units), typ 20-500 */
2420 } __packed;
2421 
2422 /* set number of direct probes __le32 type */
2423 #define IL_SCAN_PROBE_MASK(n)	cpu_to_le32((BIT(n) | (BIT(n) - BIT(1))))
2424 
2425 /**
2426  * struct il_ssid_ie - directed scan network information element
2427  *
2428  * Up to 20 of these may appear in C_SCAN (Note: Only 4 are in
2429  * 3945 SCAN api), selected by "type" bit field in struct il_scan_channel;
2430  * each channel may select different ssids from among the 20 (4) entries.
2431  * SSID IEs get transmitted in reverse order of entry.
2432  */
2433 struct il_ssid_ie {
2434 	u8 id;
2435 	u8 len;
2436 	u8 ssid[32];
2437 } __packed;
2438 
2439 #define PROBE_OPTION_MAX_3945		4
2440 #define PROBE_OPTION_MAX		20
2441 #define TX_CMD_LIFE_TIME_INFINITE	cpu_to_le32(0xFFFFFFFF)
2442 #define IL_GOOD_CRC_TH_DISABLED	0
2443 #define IL_GOOD_CRC_TH_DEFAULT		cpu_to_le16(1)
2444 #define IL_GOOD_CRC_TH_NEVER		cpu_to_le16(0xffff)
2445 #define IL_MAX_SCAN_SIZE 1024
2446 #define IL_MAX_CMD_SIZE 4096
2447 
2448 /*
2449  * C_SCAN = 0x80 (command)
2450  *
2451  * The hardware scan command is very powerful; the driver can set it up to
2452  * maintain (relatively) normal network traffic while doing a scan in the
2453  * background.  The max_out_time and suspend_time control the ratio of how
2454  * long the device stays on an associated network channel ("service channel")
2455  * vs. how long it's away from the service channel, i.e. tuned to other channels
2456  * for scanning.
2457  *
2458  * max_out_time is the max time off-channel (in usec), and suspend_time
2459  * is how long (in "extended beacon" format) that the scan is "suspended"
2460  * after returning to the service channel.  That is, suspend_time is the
2461  * time that we stay on the service channel, doing normal work, between
2462  * scan segments.  The driver may set these parameters differently to support
2463  * scanning when associated vs. not associated, and light vs. heavy traffic
2464  * loads when associated.
2465  *
2466  * After receiving this command, the device's scan engine does the following;
2467  *
2468  * 1)  Sends SCAN_START notification to driver
2469  * 2)  Checks to see if it has time to do scan for one channel
2470  * 3)  Sends NULL packet, with power-save (PS) bit set to 1,
2471  *     to tell AP that we're going off-channel
2472  * 4)  Tunes to first channel in scan list, does active or passive scan
2473  * 5)  Sends SCAN_RESULT notification to driver
2474  * 6)  Checks to see if it has time to do scan on *next* channel in list
2475  * 7)  Repeats 4-6 until it no longer has time to scan the next channel
2476  *     before max_out_time expires
2477  * 8)  Returns to service channel
2478  * 9)  Sends NULL packet with PS=0 to tell AP that we're back
2479  * 10) Stays on service channel until suspend_time expires
2480  * 11) Repeats entire process 2-10 until list is complete
2481  * 12) Sends SCAN_COMPLETE notification
2482  *
2483  * For fast, efficient scans, the scan command also has support for staying on
2484  * a channel for just a short time, if doing active scanning and getting no
2485  * responses to the transmitted probe request.  This time is controlled by
2486  * quiet_time, and the number of received packets below which a channel is
2487  * considered "quiet" is controlled by quiet_plcp_threshold.
2488  *
2489  * For active scanning on channels that have regulatory restrictions against
2490  * blindly transmitting, the scan can listen before transmitting, to make sure
2491  * that there is already legitimate activity on the channel.  If enough
2492  * packets are cleanly received on the channel (controlled by good_CRC_th,
2493  * typical value 1), the scan engine starts transmitting probe requests.
2494  *
2495  * Driver must use separate scan commands for 2.4 vs. 5 GHz bands.
2496  *
2497  * To avoid uCode errors, see timing restrictions described under
2498  * struct il_scan_channel.
2499  */
2500 
2501 struct il3945_scan_cmd {
2502 	__le16 len;
2503 	u8 reserved0;
2504 	u8 channel_count;	/* # channels in channel list */
2505 	__le16 quiet_time;	/* dwell only this # millisecs on quiet channel
2506 				 * (only for active scan) */
2507 	__le16 quiet_plcp_th;	/* quiet chnl is < this # pkts (typ. 1) */
2508 	__le16 good_CRC_th;	/* passive -> active promotion threshold */
2509 	__le16 reserved1;
2510 	__le32 max_out_time;	/* max usec to be away from associated (service)
2511 				 * channel */
2512 	__le32 suspend_time;	/* pause scan this long (in "extended beacon
2513 				 * format") when returning to service channel:
2514 				 * 3945; 31:24 # beacons, 19:0 additional usec,
2515 				 * 4965; 31:22 # beacons, 21:0 additional usec.
2516 				 */
2517 	__le32 flags;		/* RXON_FLG_* */
2518 	__le32 filter_flags;	/* RXON_FILTER_* */
2519 
2520 	/* For active scans (set to all-0s for passive scans).
2521 	 * Does not include payload.  Must specify Tx rate; no rate scaling. */
2522 	struct il3945_tx_cmd_hdr tx_cmd;
2523 
2524 	/* For directed active scans (set to all-0s otherwise) */
2525 	struct il_ssid_ie direct_scan[PROBE_OPTION_MAX_3945];
2526 
2527 	/*
2528 	 * Probe request frame, followed by channel list.
2529 	 *
2530 	 * Size of probe request frame is specified by byte count in tx_cmd.
2531 	 * Channel list follows immediately after probe request frame.
2532 	 * Number of channels in list is specified by channel_count.
2533 	 * Each channel in list is of type:
2534 	 *
2535 	 * struct il3945_scan_channel channels[0];
2536 	 *
2537 	 * NOTE:  Only one band of channels can be scanned per pass.  You
2538 	 * must not mix 2.4GHz channels and 5.2GHz channels, and you must wait
2539 	 * for one scan to complete (i.e. receive N_SCAN_COMPLETE)
2540 	 * before requesting another scan.
2541 	 */
2542 	u8 data[];
2543 } __packed;
2544 
2545 struct il_scan_cmd {
2546 	__le16 len;
2547 	u8 reserved0;
2548 	u8 channel_count;	/* # channels in channel list */
2549 	__le16 quiet_time;	/* dwell only this # millisecs on quiet channel
2550 				 * (only for active scan) */
2551 	__le16 quiet_plcp_th;	/* quiet chnl is < this # pkts (typ. 1) */
2552 	__le16 good_CRC_th;	/* passive -> active promotion threshold */
2553 	__le16 rx_chain;	/* RXON_RX_CHAIN_* */
2554 	__le32 max_out_time;	/* max usec to be away from associated (service)
2555 				 * channel */
2556 	__le32 suspend_time;	/* pause scan this long (in "extended beacon
2557 				 * format") when returning to service chnl:
2558 				 * 3945; 31:24 # beacons, 19:0 additional usec,
2559 				 * 4965; 31:22 # beacons, 21:0 additional usec.
2560 				 */
2561 	__le32 flags;		/* RXON_FLG_* */
2562 	__le32 filter_flags;	/* RXON_FILTER_* */
2563 
2564 	/* For active scans (set to all-0s for passive scans).
2565 	 * Does not include payload.  Must specify Tx rate; no rate scaling. */
2566 	struct il_tx_cmd_hdr tx_cmd;
2567 
2568 	/* For directed active scans (set to all-0s otherwise) */
2569 	struct il_ssid_ie direct_scan[PROBE_OPTION_MAX];
2570 
2571 	/*
2572 	 * Probe request frame, followed by channel list.
2573 	 *
2574 	 * Size of probe request frame is specified by byte count in tx_cmd.
2575 	 * Channel list follows immediately after probe request frame.
2576 	 * Number of channels in list is specified by channel_count.
2577 	 * Each channel in list is of type:
2578 	 *
2579 	 * struct il_scan_channel channels[0];
2580 	 *
2581 	 * NOTE:  Only one band of channels can be scanned per pass.  You
2582 	 * must not mix 2.4GHz channels and 5.2GHz channels, and you must wait
2583 	 * for one scan to complete (i.e. receive N_SCAN_COMPLETE)
2584 	 * before requesting another scan.
2585 	 */
2586 	u8 data[];
2587 } __packed;
2588 
2589 /* Can abort will notify by complete notification with abort status. */
2590 #define CAN_ABORT_STATUS	cpu_to_le32(0x1)
2591 /* complete notification statuses */
2592 #define ABORT_STATUS            0x2
2593 
2594 /*
2595  * C_SCAN = 0x80 (response)
2596  */
2597 struct il_scanreq_notification {
2598 	__le32 status;		/* 1: okay, 2: cannot fulfill request */
2599 } __packed;
2600 
2601 /*
2602  * N_SCAN_START = 0x82 (notification only, not a command)
2603  */
2604 struct il_scanstart_notification {
2605 	__le32 tsf_low;
2606 	__le32 tsf_high;
2607 	__le32 beacon_timer;
2608 	u8 channel;
2609 	u8 band;
2610 	u8 reserved[2];
2611 	__le32 status;
2612 } __packed;
2613 
2614 #define  SCAN_OWNER_STATUS 0x1
2615 #define  MEASURE_OWNER_STATUS 0x2
2616 
2617 #define IL_PROBE_STATUS_OK		0
2618 #define IL_PROBE_STATUS_TX_FAILED	BIT(0)
2619 /* error statuses combined with TX_FAILED */
2620 #define IL_PROBE_STATUS_FAIL_TTL	BIT(1)
2621 #define IL_PROBE_STATUS_FAIL_BT	BIT(2)
2622 
2623 #define NUMBER_OF_STATS 1	/* first __le32 is good CRC */
2624 /*
2625  * N_SCAN_RESULTS = 0x83 (notification only, not a command)
2626  */
2627 struct il_scanresults_notification {
2628 	u8 channel;
2629 	u8 band;
2630 	u8 probe_status;
2631 	u8 num_probe_not_sent;	/* not enough time to send */
2632 	__le32 tsf_low;
2633 	__le32 tsf_high;
2634 	__le32 stats[NUMBER_OF_STATS];
2635 } __packed;
2636 
2637 /*
2638  * N_SCAN_COMPLETE = 0x84 (notification only, not a command)
2639  */
2640 struct il_scancomplete_notification {
2641 	u8 scanned_channels;
2642 	u8 status;
2643 	u8 last_channel;
2644 	__le32 tsf_low;
2645 	__le32 tsf_high;
2646 } __packed;
2647 
2648 /******************************************************************************
2649  * (9)
2650  * IBSS/AP Commands and Notifications:
2651  *
2652  *****************************************************************************/
2653 
2654 enum il_ibss_manager {
2655 	IL_NOT_IBSS_MANAGER = 0,
2656 	IL_IBSS_MANAGER = 1,
2657 };
2658 
2659 /*
2660  * N_BEACON = 0x90 (notification only, not a command)
2661  */
2662 
2663 struct il3945_beacon_notif {
2664 	struct il3945_tx_resp beacon_notify_hdr;
2665 	__le32 low_tsf;
2666 	__le32 high_tsf;
2667 	__le32 ibss_mgr_status;
2668 } __packed;
2669 
2670 struct il4965_beacon_notif {
2671 	struct il4965_tx_resp_hdr beacon_notify_hdr;
2672 	__le32 beacon_tx_status;
2673 	__le32 low_tsf;
2674 	__le32 high_tsf;
2675 	__le32 ibss_mgr_status;
2676 } __packed;
2677 
2678 /*
2679  * C_TX_BEACON= 0x91 (command, has simple generic response)
2680  */
2681 
2682 struct il3945_tx_beacon_cmd {
2683 	struct il3945_tx_cmd_hdr tx;
2684 	__le16 tim_idx;
2685 	u8 tim_size;
2686 	u8 reserved1;
2687 	struct ieee80211_hdr frame[];	/* beacon frame */
2688 } __packed;
2689 
2690 struct il_tx_beacon_cmd {
2691 	struct il_tx_cmd_hdr tx;
2692 	__le16 tim_idx;
2693 	u8 tim_size;
2694 	u8 reserved1;
2695 	struct ieee80211_hdr frame[];	/* beacon frame */
2696 } __packed;
2697 
2698 /******************************************************************************
2699  * (10)
2700  * Statistics Commands and Notifications:
2701  *
2702  *****************************************************************************/
2703 
2704 #define IL_TEMP_CONVERT 260
2705 
2706 #define SUP_RATE_11A_MAX_NUM_CHANNELS  8
2707 #define SUP_RATE_11B_MAX_NUM_CHANNELS  4
2708 #define SUP_RATE_11G_MAX_NUM_CHANNELS  12
2709 
2710 /* Used for passing to driver number of successes and failures per rate */
2711 struct rate_histogram {
2712 	union {
2713 		__le32 a[SUP_RATE_11A_MAX_NUM_CHANNELS];
2714 		__le32 b[SUP_RATE_11B_MAX_NUM_CHANNELS];
2715 		__le32 g[SUP_RATE_11G_MAX_NUM_CHANNELS];
2716 	} success;
2717 	union {
2718 		__le32 a[SUP_RATE_11A_MAX_NUM_CHANNELS];
2719 		__le32 b[SUP_RATE_11B_MAX_NUM_CHANNELS];
2720 		__le32 g[SUP_RATE_11G_MAX_NUM_CHANNELS];
2721 	} failed;
2722 } __packed;
2723 
2724 /* stats command response */
2725 
2726 struct iwl39_stats_rx_phy {
2727 	__le32 ina_cnt;
2728 	__le32 fina_cnt;
2729 	__le32 plcp_err;
2730 	__le32 crc32_err;
2731 	__le32 overrun_err;
2732 	__le32 early_overrun_err;
2733 	__le32 crc32_good;
2734 	__le32 false_alarm_cnt;
2735 	__le32 fina_sync_err_cnt;
2736 	__le32 sfd_timeout;
2737 	__le32 fina_timeout;
2738 	__le32 unresponded_rts;
2739 	__le32 rxe_frame_limit_overrun;
2740 	__le32 sent_ack_cnt;
2741 	__le32 sent_cts_cnt;
2742 } __packed;
2743 
2744 struct iwl39_stats_rx_non_phy {
2745 	__le32 bogus_cts;	/* CTS received when not expecting CTS */
2746 	__le32 bogus_ack;	/* ACK received when not expecting ACK */
2747 	__le32 non_bssid_frames;	/* number of frames with BSSID that
2748 					 * doesn't belong to the STA BSSID */
2749 	__le32 filtered_frames;	/* count frames that were dumped in the
2750 				 * filtering process */
2751 	__le32 non_channel_beacons;	/* beacons with our bss id but not on
2752 					 * our serving channel */
2753 } __packed;
2754 
2755 struct iwl39_stats_rx {
2756 	struct iwl39_stats_rx_phy ofdm;
2757 	struct iwl39_stats_rx_phy cck;
2758 	struct iwl39_stats_rx_non_phy general;
2759 } __packed;
2760 
2761 struct iwl39_stats_tx {
2762 	__le32 preamble_cnt;
2763 	__le32 rx_detected_cnt;
2764 	__le32 bt_prio_defer_cnt;
2765 	__le32 bt_prio_kill_cnt;
2766 	__le32 few_bytes_cnt;
2767 	__le32 cts_timeout;
2768 	__le32 ack_timeout;
2769 	__le32 expected_ack_cnt;
2770 	__le32 actual_ack_cnt;
2771 } __packed;
2772 
2773 struct stats_dbg {
2774 	__le32 burst_check;
2775 	__le32 burst_count;
2776 	__le32 wait_for_silence_timeout_cnt;
2777 	__le32 reserved[3];
2778 } __packed;
2779 
2780 struct iwl39_stats_div {
2781 	__le32 tx_on_a;
2782 	__le32 tx_on_b;
2783 	__le32 exec_time;
2784 	__le32 probe_time;
2785 } __packed;
2786 
2787 struct iwl39_stats_general {
2788 	__le32 temperature;
2789 	struct stats_dbg dbg;
2790 	__le32 sleep_time;
2791 	__le32 slots_out;
2792 	__le32 slots_idle;
2793 	__le32 ttl_timestamp;
2794 	struct iwl39_stats_div div;
2795 } __packed;
2796 
2797 struct stats_rx_phy {
2798 	__le32 ina_cnt;
2799 	__le32 fina_cnt;
2800 	__le32 plcp_err;
2801 	__le32 crc32_err;
2802 	__le32 overrun_err;
2803 	__le32 early_overrun_err;
2804 	__le32 crc32_good;
2805 	__le32 false_alarm_cnt;
2806 	__le32 fina_sync_err_cnt;
2807 	__le32 sfd_timeout;
2808 	__le32 fina_timeout;
2809 	__le32 unresponded_rts;
2810 	__le32 rxe_frame_limit_overrun;
2811 	__le32 sent_ack_cnt;
2812 	__le32 sent_cts_cnt;
2813 	__le32 sent_ba_rsp_cnt;
2814 	__le32 dsp_self_kill;
2815 	__le32 mh_format_err;
2816 	__le32 re_acq_main_rssi_sum;
2817 	__le32 reserved3;
2818 } __packed;
2819 
2820 struct stats_rx_ht_phy {
2821 	__le32 plcp_err;
2822 	__le32 overrun_err;
2823 	__le32 early_overrun_err;
2824 	__le32 crc32_good;
2825 	__le32 crc32_err;
2826 	__le32 mh_format_err;
2827 	__le32 agg_crc32_good;
2828 	__le32 agg_mpdu_cnt;
2829 	__le32 agg_cnt;
2830 	__le32 unsupport_mcs;
2831 } __packed;
2832 
2833 #define INTERFERENCE_DATA_AVAILABLE      cpu_to_le32(1)
2834 
2835 struct stats_rx_non_phy {
2836 	__le32 bogus_cts;	/* CTS received when not expecting CTS */
2837 	__le32 bogus_ack;	/* ACK received when not expecting ACK */
2838 	__le32 non_bssid_frames;	/* number of frames with BSSID that
2839 					 * doesn't belong to the STA BSSID */
2840 	__le32 filtered_frames;	/* count frames that were dumped in the
2841 				 * filtering process */
2842 	__le32 non_channel_beacons;	/* beacons with our bss id but not on
2843 					 * our serving channel */
2844 	__le32 channel_beacons;	/* beacons with our bss id and in our
2845 				 * serving channel */
2846 	__le32 num_missed_bcon;	/* number of missed beacons */
2847 	__le32 adc_rx_saturation_time;	/* count in 0.8us units the time the
2848 					 * ADC was in saturation */
2849 	__le32 ina_detection_search_time;	/* total time (in 0.8us) searched
2850 						 * for INA */
2851 	__le32 beacon_silence_rssi_a;	/* RSSI silence after beacon frame */
2852 	__le32 beacon_silence_rssi_b;	/* RSSI silence after beacon frame */
2853 	__le32 beacon_silence_rssi_c;	/* RSSI silence after beacon frame */
2854 	__le32 interference_data_flag;	/* flag for interference data
2855 					 * availability. 1 when data is
2856 					 * available. */
2857 	__le32 channel_load;	/* counts RX Enable time in uSec */
2858 	__le32 dsp_false_alarms;	/* DSP false alarm (both OFDM
2859 					 * and CCK) counter */
2860 	__le32 beacon_rssi_a;
2861 	__le32 beacon_rssi_b;
2862 	__le32 beacon_rssi_c;
2863 	__le32 beacon_energy_a;
2864 	__le32 beacon_energy_b;
2865 	__le32 beacon_energy_c;
2866 } __packed;
2867 
2868 struct stats_rx {
2869 	struct stats_rx_phy ofdm;
2870 	struct stats_rx_phy cck;
2871 	struct stats_rx_non_phy general;
2872 	struct stats_rx_ht_phy ofdm_ht;
2873 } __packed;
2874 
2875 /**
2876  * struct stats_tx_power - current tx power
2877  *
2878  * @ant_a: current tx power on chain a in 1/2 dB step
2879  * @ant_b: current tx power on chain b in 1/2 dB step
2880  * @ant_c: current tx power on chain c in 1/2 dB step
2881  */
2882 struct stats_tx_power {
2883 	u8 ant_a;
2884 	u8 ant_b;
2885 	u8 ant_c;
2886 	u8 reserved;
2887 } __packed;
2888 
2889 struct stats_tx_non_phy_agg {
2890 	__le32 ba_timeout;
2891 	__le32 ba_reschedule_frames;
2892 	__le32 scd_query_agg_frame_cnt;
2893 	__le32 scd_query_no_agg;
2894 	__le32 scd_query_agg;
2895 	__le32 scd_query_mismatch;
2896 	__le32 frame_not_ready;
2897 	__le32 underrun;
2898 	__le32 bt_prio_kill;
2899 	__le32 rx_ba_rsp_cnt;
2900 } __packed;
2901 
2902 struct stats_tx {
2903 	__le32 preamble_cnt;
2904 	__le32 rx_detected_cnt;
2905 	__le32 bt_prio_defer_cnt;
2906 	__le32 bt_prio_kill_cnt;
2907 	__le32 few_bytes_cnt;
2908 	__le32 cts_timeout;
2909 	__le32 ack_timeout;
2910 	__le32 expected_ack_cnt;
2911 	__le32 actual_ack_cnt;
2912 	__le32 dump_msdu_cnt;
2913 	__le32 burst_abort_next_frame_mismatch_cnt;
2914 	__le32 burst_abort_missing_next_frame_cnt;
2915 	__le32 cts_timeout_collision;
2916 	__le32 ack_or_ba_timeout_collision;
2917 	struct stats_tx_non_phy_agg agg;
2918 
2919 	__le32 reserved1;
2920 } __packed;
2921 
2922 struct stats_div {
2923 	__le32 tx_on_a;
2924 	__le32 tx_on_b;
2925 	__le32 exec_time;
2926 	__le32 probe_time;
2927 	__le32 reserved1;
2928 	__le32 reserved2;
2929 } __packed;
2930 
2931 struct stats_general_common {
2932 	__le32 temperature;	/* radio temperature */
2933 	struct stats_dbg dbg;
2934 	__le32 sleep_time;
2935 	__le32 slots_out;
2936 	__le32 slots_idle;
2937 	__le32 ttl_timestamp;
2938 	struct stats_div div;
2939 	__le32 rx_enable_counter;
2940 	/*
2941 	 * num_of_sos_states:
2942 	 *  count the number of times we have to re-tune
2943 	 *  in order to get out of bad PHY status
2944 	 */
2945 	__le32 num_of_sos_states;
2946 } __packed;
2947 
2948 struct stats_general {
2949 	struct stats_general_common common;
2950 	__le32 reserved2;
2951 	__le32 reserved3;
2952 } __packed;
2953 
2954 #define UCODE_STATS_CLEAR_MSK		(0x1 << 0)
2955 #define UCODE_STATS_FREQUENCY_MSK		(0x1 << 1)
2956 #define UCODE_STATS_NARROW_BAND_MSK	(0x1 << 2)
2957 
2958 /*
2959  * C_STATS = 0x9c,
2960  * all devices identical.
2961  *
2962  * This command triggers an immediate response containing uCode stats.
2963  * The response is in the same format as N_STATS 0x9d, below.
2964  *
2965  * If the CLEAR_STATS configuration flag is set, uCode will clear its
2966  * internal copy of the stats (counters) after issuing the response.
2967  * This flag does not affect N_STATSs after beacons (see below).
2968  *
2969  * If the DISABLE_NOTIF configuration flag is set, uCode will not issue
2970  * N_STATSs after received beacons (see below).  This flag
2971  * does not affect the response to the C_STATS 0x9c itself.
2972  */
2973 #define IL_STATS_CONF_CLEAR_STATS cpu_to_le32(0x1)	/* see above */
2974 #define IL_STATS_CONF_DISABLE_NOTIF cpu_to_le32(0x2)	/* see above */
2975 struct il_stats_cmd {
2976 	__le32 configuration_flags;	/* IL_STATS_CONF_* */
2977 } __packed;
2978 
2979 /*
2980  * N_STATS = 0x9d (notification only, not a command)
2981  *
2982  * By default, uCode issues this notification after receiving a beacon
2983  * while associated.  To disable this behavior, set DISABLE_NOTIF flag in the
2984  * C_STATS 0x9c, above.
2985  *
2986  * Statistics counters continue to increment beacon after beacon, but are
2987  * cleared when changing channels or when driver issues C_STATS
2988  * 0x9c with CLEAR_STATS bit set (see above).
2989  *
2990  * uCode also issues this notification during scans.  uCode clears stats
2991  * appropriately so that each notification contains stats for only the
2992  * one channel that has just been scanned.
2993  */
2994 #define STATS_REPLY_FLG_BAND_24G_MSK         cpu_to_le32(0x2)
2995 #define STATS_REPLY_FLG_HT40_MODE_MSK        cpu_to_le32(0x8)
2996 
2997 struct il3945_notif_stats {
2998 	__le32 flag;
2999 	struct iwl39_stats_rx rx;
3000 	struct iwl39_stats_tx tx;
3001 	struct iwl39_stats_general general;
3002 } __packed;
3003 
3004 struct il_notif_stats {
3005 	__le32 flag;
3006 	struct stats_rx rx;
3007 	struct stats_tx tx;
3008 	struct stats_general general;
3009 } __packed;
3010 
3011 /*
3012  * N_MISSED_BEACONS = 0xa2 (notification only, not a command)
3013  *
3014  * uCode send N_MISSED_BEACONS to driver when detect beacon missed
3015  * in regardless of how many missed beacons, which mean when driver receive the
3016  * notification, inside the command, it can find all the beacons information
3017  * which include number of total missed beacons, number of consecutive missed
3018  * beacons, number of beacons received and number of beacons expected to
3019  * receive.
3020  *
3021  * If uCode detected consecutive_missed_beacons > 5, it will reset the radio
3022  * in order to bring the radio/PHY back to working state; which has no relation
3023  * to when driver will perform sensitivity calibration.
3024  *
3025  * Driver should set it own missed_beacon_threshold to decide when to perform
3026  * sensitivity calibration based on number of consecutive missed beacons in
3027  * order to improve overall performance, especially in noisy environment.
3028  *
3029  */
3030 
3031 #define IL_MISSED_BEACON_THRESHOLD_MIN	(1)
3032 #define IL_MISSED_BEACON_THRESHOLD_DEF	(5)
3033 #define IL_MISSED_BEACON_THRESHOLD_MAX	IL_MISSED_BEACON_THRESHOLD_DEF
3034 
3035 struct il_missed_beacon_notif {
3036 	__le32 consecutive_missed_beacons;
3037 	__le32 total_missed_becons;
3038 	__le32 num_expected_beacons;
3039 	__le32 num_recvd_beacons;
3040 } __packed;
3041 
3042 /******************************************************************************
3043  * (11)
3044  * Rx Calibration Commands:
3045  *
3046  * With the uCode used for open source drivers, most Tx calibration (except
3047  * for Tx Power) and most Rx calibration is done by uCode during the
3048  * "initialize" phase of uCode boot.  Driver must calibrate only:
3049  *
3050  * 1)  Tx power (depends on temperature), described elsewhere
3051  * 2)  Receiver gain balance (optimize MIMO, and detect disconnected antennas)
3052  * 3)  Receiver sensitivity (to optimize signal detection)
3053  *
3054  *****************************************************************************/
3055 
3056 /**
3057  * C_SENSITIVITY = 0xa8 (command, has simple generic response)
3058  *
3059  * This command sets up the Rx signal detector for a sensitivity level that
3060  * is high enough to lock onto all signals within the associated network,
3061  * but low enough to ignore signals that are below a certain threshold, so as
3062  * not to have too many "false alarms".  False alarms are signals that the
3063  * Rx DSP tries to lock onto, but then discards after determining that they
3064  * are noise.
3065  *
3066  * The optimum number of false alarms is between 5 and 50 per 200 TUs
3067  * (200 * 1024 uSecs, i.e. 204.8 milliseconds) of actual Rx time (i.e.
3068  * time listening, not transmitting).  Driver must adjust sensitivity so that
3069  * the ratio of actual false alarms to actual Rx time falls within this range.
3070  *
3071  * While associated, uCode delivers N_STATSs after each
3072  * received beacon.  These provide information to the driver to analyze the
3073  * sensitivity.  Don't analyze stats that come in from scanning, or any
3074  * other non-associated-network source.  Pertinent stats include:
3075  *
3076  * From "general" stats (struct stats_rx_non_phy):
3077  *
3078  * (beacon_energy_[abc] & 0x0FF00) >> 8 (unsigned, higher value is lower level)
3079  *   Measure of energy of desired signal.  Used for establishing a level
3080  *   below which the device does not detect signals.
3081  *
3082  * (beacon_silence_rssi_[abc] & 0x0FF00) >> 8 (unsigned, units in dB)
3083  *   Measure of background noise in silent period after beacon.
3084  *
3085  * channel_load
3086  *   uSecs of actual Rx time during beacon period (varies according to
3087  *   how much time was spent transmitting).
3088  *
3089  * From "cck" and "ofdm" stats (struct stats_rx_phy), separately:
3090  *
3091  * false_alarm_cnt
3092  *   Signal locks abandoned early (before phy-level header).
3093  *
3094  * plcp_err
3095  *   Signal locks abandoned late (during phy-level header).
3096  *
3097  * NOTE:  Both false_alarm_cnt and plcp_err increment monotonically from
3098  *        beacon to beacon, i.e. each value is an accumulation of all errors
3099  *        before and including the latest beacon.  Values will wrap around to 0
3100  *        after counting up to 2^32 - 1.  Driver must differentiate vs.
3101  *        previous beacon's values to determine # false alarms in the current
3102  *        beacon period.
3103  *
3104  * Total number of false alarms = false_alarms + plcp_errs
3105  *
3106  * For OFDM, adjust the following table entries in struct il_sensitivity_cmd
3107  * (notice that the start points for OFDM are at or close to settings for
3108  * maximum sensitivity):
3109  *
3110  *                                             START  /  MIN  /  MAX
3111  *   HD_AUTO_CORR32_X1_TH_ADD_MIN_IDX          90   /   85  /  120
3112  *   HD_AUTO_CORR32_X1_TH_ADD_MIN_MRC_IDX     170   /  170  /  210
3113  *   HD_AUTO_CORR32_X4_TH_ADD_MIN_IDX         105   /  105  /  140
3114  *   HD_AUTO_CORR32_X4_TH_ADD_MIN_MRC_IDX     220   /  220  /  270
3115  *
3116  *   If actual rate of OFDM false alarms (+ plcp_errors) is too high
3117  *   (greater than 50 for each 204.8 msecs listening), reduce sensitivity
3118  *   by *adding* 1 to all 4 of the table entries above, up to the max for
3119  *   each entry.  Conversely, if false alarm rate is too low (less than 5
3120  *   for each 204.8 msecs listening), *subtract* 1 from each entry to
3121  *   increase sensitivity.
3122  *
3123  * For CCK sensitivity, keep track of the following:
3124  *
3125  *   1).  20-beacon history of maximum background noise, indicated by
3126  *        (beacon_silence_rssi_[abc] & 0x0FF00), units in dB, across the
3127  *        3 receivers.  For any given beacon, the "silence reference" is
3128  *        the maximum of last 60 samples (20 beacons * 3 receivers).
3129  *
3130  *   2).  10-beacon history of strongest signal level, as indicated
3131  *        by (beacon_energy_[abc] & 0x0FF00) >> 8, across the 3 receivers,
3132  *        i.e. the strength of the signal through the best receiver at the
3133  *        moment.  These measurements are "upside down", with lower values
3134  *        for stronger signals, so max energy will be *minimum* value.
3135  *
3136  *        Then for any given beacon, the driver must determine the *weakest*
3137  *        of the strongest signals; this is the minimum level that needs to be
3138  *        successfully detected, when using the best receiver at the moment.
3139  *        "Max cck energy" is the maximum (higher value means lower energy!)
3140  *        of the last 10 minima.  Once this is determined, driver must add
3141  *        a little margin by adding "6" to it.
3142  *
3143  *   3).  Number of consecutive beacon periods with too few false alarms.
3144  *        Reset this to 0 at the first beacon period that falls within the
3145  *        "good" range (5 to 50 false alarms per 204.8 milliseconds rx).
3146  *
3147  * Then, adjust the following CCK table entries in struct il_sensitivity_cmd
3148  * (notice that the start points for CCK are at maximum sensitivity):
3149  *
3150  *                                             START  /  MIN  /  MAX
3151  *   HD_AUTO_CORR40_X4_TH_ADD_MIN_IDX         125   /  125  /  200
3152  *   HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_IDX     200   /  200  /  400
3153  *   HD_MIN_ENERGY_CCK_DET_IDX                100   /    0  /  100
3154  *
3155  *   If actual rate of CCK false alarms (+ plcp_errors) is too high
3156  *   (greater than 50 for each 204.8 msecs listening), method for reducing
3157  *   sensitivity is:
3158  *
3159  *   1)  *Add* 3 to value in HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_IDX,
3160  *       up to max 400.
3161  *
3162  *   2)  If current value in HD_AUTO_CORR40_X4_TH_ADD_MIN_IDX is < 160,
3163  *       sensitivity has been reduced a significant amount; bring it up to
3164  *       a moderate 161.  Otherwise, *add* 3, up to max 200.
3165  *
3166  *   3)  a)  If current value in HD_AUTO_CORR40_X4_TH_ADD_MIN_IDX is > 160,
3167  *       sensitivity has been reduced only a moderate or small amount;
3168  *       *subtract* 2 from value in HD_MIN_ENERGY_CCK_DET_IDX,
3169  *       down to min 0.  Otherwise (if gain has been significantly reduced),
3170  *       don't change the HD_MIN_ENERGY_CCK_DET_IDX value.
3171  *
3172  *       b)  Save a snapshot of the "silence reference".
3173  *
3174  *   If actual rate of CCK false alarms (+ plcp_errors) is too low
3175  *   (less than 5 for each 204.8 msecs listening), method for increasing
3176  *   sensitivity is used only if:
3177  *
3178  *   1a)  Previous beacon did not have too many false alarms
3179  *   1b)  AND difference between previous "silence reference" and current
3180  *        "silence reference" (prev - current) is 2 or more,
3181  *   OR 2)  100 or more consecutive beacon periods have had rate of
3182  *          less than 5 false alarms per 204.8 milliseconds rx time.
3183  *
3184  *   Method for increasing sensitivity:
3185  *
3186  *   1)  *Subtract* 3 from value in HD_AUTO_CORR40_X4_TH_ADD_MIN_IDX,
3187  *       down to min 125.
3188  *
3189  *   2)  *Subtract* 3 from value in HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_IDX,
3190  *       down to min 200.
3191  *
3192  *   3)  *Add* 2 to value in HD_MIN_ENERGY_CCK_DET_IDX, up to max 100.
3193  *
3194  *   If actual rate of CCK false alarms (+ plcp_errors) is within good range
3195  *   (between 5 and 50 for each 204.8 msecs listening):
3196  *
3197  *   1)  Save a snapshot of the silence reference.
3198  *
3199  *   2)  If previous beacon had too many CCK false alarms (+ plcp_errors),
3200  *       give some extra margin to energy threshold by *subtracting* 8
3201  *       from value in HD_MIN_ENERGY_CCK_DET_IDX.
3202  *
3203  *   For all cases (too few, too many, good range), make sure that the CCK
3204  *   detection threshold (energy) is below the energy level for robust
3205  *   detection over the past 10 beacon periods, the "Max cck energy".
3206  *   Lower values mean higher energy; this means making sure that the value
3207  *   in HD_MIN_ENERGY_CCK_DET_IDX is at or *above* "Max cck energy".
3208  *
3209  */
3210 
3211 /*
3212  * Table entries in C_SENSITIVITY (struct il_sensitivity_cmd)
3213  */
3214 #define HD_TBL_SIZE  (11)	/* number of entries */
3215 #define HD_MIN_ENERGY_CCK_DET_IDX                 (0)	/* table idxes */
3216 #define HD_MIN_ENERGY_OFDM_DET_IDX                (1)
3217 #define HD_AUTO_CORR32_X1_TH_ADD_MIN_IDX          (2)
3218 #define HD_AUTO_CORR32_X1_TH_ADD_MIN_MRC_IDX      (3)
3219 #define HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_IDX      (4)
3220 #define HD_AUTO_CORR32_X4_TH_ADD_MIN_IDX          (5)
3221 #define HD_AUTO_CORR32_X4_TH_ADD_MIN_MRC_IDX      (6)
3222 #define HD_BARKER_CORR_TH_ADD_MIN_IDX             (7)
3223 #define HD_BARKER_CORR_TH_ADD_MIN_MRC_IDX         (8)
3224 #define HD_AUTO_CORR40_X4_TH_ADD_MIN_IDX          (9)
3225 #define HD_OFDM_ENERGY_TH_IN_IDX                  (10)
3226 
3227 /* Control field in struct il_sensitivity_cmd */
3228 #define C_SENSITIVITY_CONTROL_DEFAULT_TBL	cpu_to_le16(0)
3229 #define C_SENSITIVITY_CONTROL_WORK_TBL	cpu_to_le16(1)
3230 
3231 /**
3232  * struct il_sensitivity_cmd
3233  * @control:  (1) updates working table, (0) updates default table
3234  * @table:  energy threshold values, use HD_* as idx into table
3235  *
3236  * Always use "1" in "control" to update uCode's working table and DSP.
3237  */
3238 struct il_sensitivity_cmd {
3239 	__le16 control;		/* always use "1" */
3240 	__le16 table[HD_TBL_SIZE];	/* use HD_* as idx */
3241 } __packed;
3242 
3243 /**
3244  * C_PHY_CALIBRATION = 0xb0 (command, has simple generic response)
3245  *
3246  * This command sets the relative gains of 4965 device's 3 radio receiver chains.
3247  *
3248  * After the first association, driver should accumulate signal and noise
3249  * stats from the N_STATSs that follow the first 20
3250  * beacons from the associated network (don't collect stats that come
3251  * in from scanning, or any other non-network source).
3252  *
3253  * DISCONNECTED ANTENNA:
3254  *
3255  * Driver should determine which antennas are actually connected, by comparing
3256  * average beacon signal levels for the 3 Rx chains.  Accumulate (add) the
3257  * following values over 20 beacons, one accumulator for each of the chains
3258  * a/b/c, from struct stats_rx_non_phy:
3259  *
3260  * beacon_rssi_[abc] & 0x0FF (unsigned, units in dB)
3261  *
3262  * Find the strongest signal from among a/b/c.  Compare the other two to the
3263  * strongest.  If any signal is more than 15 dB (times 20, unless you
3264  * divide the accumulated values by 20) below the strongest, the driver
3265  * considers that antenna to be disconnected, and should not try to use that
3266  * antenna/chain for Rx or Tx.  If both A and B seem to be disconnected,
3267  * driver should declare the stronger one as connected, and attempt to use it
3268  * (A and B are the only 2 Tx chains!).
3269  *
3270  *
3271  * RX BALANCE:
3272  *
3273  * Driver should balance the 3 receivers (but just the ones that are connected
3274  * to antennas, see above) for gain, by comparing the average signal levels
3275  * detected during the silence after each beacon (background noise).
3276  * Accumulate (add) the following values over 20 beacons, one accumulator for
3277  * each of the chains a/b/c, from struct stats_rx_non_phy:
3278  *
3279  * beacon_silence_rssi_[abc] & 0x0FF (unsigned, units in dB)
3280  *
3281  * Find the weakest background noise level from among a/b/c.  This Rx chain
3282  * will be the reference, with 0 gain adjustment.  Attenuate other channels by
3283  * finding noise difference:
3284  *
3285  * (accum_noise[i] - accum_noise[reference]) / 30
3286  *
3287  * The "30" adjusts the dB in the 20 accumulated samples to units of 1.5 dB.
3288  * For use in diff_gain_[abc] fields of struct il_calibration_cmd, the
3289  * driver should limit the difference results to a range of 0-3 (0-4.5 dB),
3290  * and set bit 2 to indicate "reduce gain".  The value for the reference
3291  * (weakest) chain should be "0".
3292  *
3293  * diff_gain_[abc] bit fields:
3294  *   2: (1) reduce gain, (0) increase gain
3295  * 1-0: amount of gain, units of 1.5 dB
3296  */
3297 
3298 /* Phy calibration command for series */
3299 /* The default calibrate table size if not specified by firmware */
3300 #define IL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE	18
3301 enum {
3302 	IL_PHY_CALIBRATE_DIFF_GAIN_CMD = 7,
3303 	IL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE = 19,
3304 };
3305 
3306 #define IL_MAX_PHY_CALIBRATE_TBL_SIZE		(253)
3307 
3308 struct il_calib_hdr {
3309 	u8 op_code;
3310 	u8 first_group;
3311 	u8 groups_num;
3312 	u8 data_valid;
3313 } __packed;
3314 
3315 /* IL_PHY_CALIBRATE_DIFF_GAIN_CMD (7) */
3316 struct il_calib_diff_gain_cmd {
3317 	struct il_calib_hdr hdr;
3318 	s8 diff_gain_a;		/* see above */
3319 	s8 diff_gain_b;
3320 	s8 diff_gain_c;
3321 	u8 reserved1;
3322 } __packed;
3323 
3324 /******************************************************************************
3325  * (12)
3326  * Miscellaneous Commands:
3327  *
3328  *****************************************************************************/
3329 
3330 /*
3331  * LEDs Command & Response
3332  * C_LEDS = 0x48 (command, has simple generic response)
3333  *
3334  * For each of 3 possible LEDs (Activity/Link/Tech, selected by "id" field),
3335  * this command turns it on or off, or sets up a periodic blinking cycle.
3336  */
3337 struct il_led_cmd {
3338 	__le32 interval;	/* "interval" in uSec */
3339 	u8 id;			/* 1: Activity, 2: Link, 3: Tech */
3340 	u8 off;			/* # intervals off while blinking;
3341 				 * "0", with >0 "on" value, turns LED on */
3342 	u8 on;			/* # intervals on while blinking;
3343 				 * "0", regardless of "off", turns LED off */
3344 	u8 reserved;
3345 } __packed;
3346 
3347 /******************************************************************************
3348  * (13)
3349  * Union of all expected notifications/responses:
3350  *
3351  *****************************************************************************/
3352 
3353 #define IL_RX_FRAME_SIZE_MSK	0x00003fff
3354 
3355 struct il_rx_pkt {
3356 	/*
3357 	 * The first 4 bytes of the RX frame header contain both the RX frame
3358 	 * size and some flags.
3359 	 * Bit fields:
3360 	 * 31:    flag flush RB request
3361 	 * 30:    flag ignore TC (terminal counter) request
3362 	 * 29:    flag fast IRQ request
3363 	 * 28-14: Reserved
3364 	 * 13-00: RX frame size
3365 	 */
3366 	__le32 len_n_flags;
3367 	struct il_cmd_header hdr;
3368 	union {
3369 		struct il3945_rx_frame rx_frame;
3370 		struct il3945_tx_resp tx_resp;
3371 		struct il3945_beacon_notif beacon_status;
3372 
3373 		struct il_alive_resp alive_frame;
3374 		struct il_spectrum_notification spectrum_notif;
3375 		struct il_csa_notification csa_notif;
3376 		struct il_error_resp err_resp;
3377 		struct il_card_state_notif card_state_notif;
3378 		struct il_add_sta_resp add_sta;
3379 		struct il_rem_sta_resp rem_sta;
3380 		struct il_sleep_notification sleep_notif;
3381 		struct il_spectrum_resp spectrum;
3382 		struct il_notif_stats stats;
3383 		struct il_compressed_ba_resp compressed_ba;
3384 		struct il_missed_beacon_notif missed_beacon;
3385 		__le32 status;
3386 		DECLARE_FLEX_ARRAY(u8, raw);
3387 	} u;
3388 } __packed;
3389 
3390 #endif /* __il_commands_h__ */
3391