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) 2007 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * The full GNU General Public License is included in this distribution
22 * in the file called COPYING.
23 *
24 * Contact Information:
25 * Intel Linux Wireless <linuxwifi@intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 * BSD LICENSE
29 *
30 * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
31 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
32 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
33 * All rights reserved.
34 *
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
37 * are met:
38 *
39 * * Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * * Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in
43 * the documentation and/or other materials provided with the
44 * distribution.
45 * * Neither the name Intel Corporation nor the names of its
46 * contributors may be used to endorse or promote products derived
47 * from this software without specific prior written permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
50 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
51 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
52 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
53 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
57 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
59 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 *
61 *****************************************************************************/
62 #ifndef __iwl_fw_api_cmdhdr_h__
63 #define __iwl_fw_api_cmdhdr_h__
64
65 /**
66 * DOC: Host command section
67 *
68 * A host command is a command issued by the upper layer to the fw. There are
69 * several versions of fw that have several APIs. The transport layer is
70 * completely agnostic to these differences.
71 * The transport does provide helper functionality (i.e. SYNC / ASYNC mode),
72 */
73 #define SEQ_TO_QUEUE(s) (((s) >> 8) & 0x1f)
74 #define QUEUE_TO_SEQ(q) (((q) & 0x1f) << 8)
75 #define SEQ_TO_INDEX(s) ((s) & 0xff)
76 #define INDEX_TO_SEQ(i) ((i) & 0xff)
77 #define SEQ_RX_FRAME cpu_to_le16(0x8000)
78
79 /*
80 * those functions retrieve specific information from
81 * the id field in the iwl_host_cmd struct which contains
82 * the command id, the group id and the version of the command
83 * and vice versa
84 */
iwl_cmd_opcode(u32 cmdid)85 static inline u8 iwl_cmd_opcode(u32 cmdid)
86 {
87 return cmdid & 0xFF;
88 }
89
iwl_cmd_groupid(u32 cmdid)90 static inline u8 iwl_cmd_groupid(u32 cmdid)
91 {
92 return ((cmdid & 0xFF00) >> 8);
93 }
94
iwl_cmd_version(u32 cmdid)95 static inline u8 iwl_cmd_version(u32 cmdid)
96 {
97 return ((cmdid & 0xFF0000) >> 16);
98 }
99
iwl_cmd_id(u8 opcode,u8 groupid,u8 version)100 static inline u32 iwl_cmd_id(u8 opcode, u8 groupid, u8 version)
101 {
102 return opcode + (groupid << 8) + (version << 16);
103 }
104
105 /* make u16 wide id out of u8 group and opcode */
106 #define WIDE_ID(grp, opcode) (((grp) << 8) | (opcode))
107 #define DEF_ID(opcode) ((1 << 8) | (opcode))
108
109 /* due to the conversion, this group is special; new groups
110 * should be defined in the appropriate fw-api header files
111 */
112 #define IWL_ALWAYS_LONG_GROUP 1
113
114 /**
115 * struct iwl_cmd_header - (short) command header format
116 *
117 * This header format appears in the beginning of each command sent from the
118 * driver, and each response/notification received from uCode.
119 */
120 struct iwl_cmd_header {
121 /**
122 * @cmd: Command ID: REPLY_RXON, etc.
123 */
124 u8 cmd;
125 /**
126 * @group_id: group ID, for commands with groups
127 */
128 u8 group_id;
129 /**
130 * @sequence:
131 * Sequence number for the command.
132 *
133 * The driver sets up the sequence number to values of its choosing.
134 * uCode does not use this value, but passes it back to the driver
135 * when sending the response to each driver-originated command, so
136 * the driver can match the response to the command. Since the values
137 * don't get used by uCode, the driver may set up an arbitrary format.
138 *
139 * There is one exception: uCode sets bit 15 when it originates
140 * the response/notification, i.e. when the response/notification
141 * is not a direct response to a command sent by the driver. For
142 * example, uCode issues REPLY_RX when it sends a received frame
143 * to the driver; it is not a direct response to any driver command.
144 *
145 * The Linux driver uses the following format:
146 *
147 * 0:7 tfd index - position within TX queue
148 * 8:12 TX queue id
149 * 13:14 reserved
150 * 15 unsolicited RX or uCode-originated notification
151 */
152 __le16 sequence;
153 } __packed;
154
155 /**
156 * struct iwl_cmd_header_wide
157 *
158 * This header format appears in the beginning of each command sent from the
159 * driver, and each response/notification received from uCode.
160 * this is the wide version that contains more information about the command
161 * like length, version and command type
162 *
163 * @cmd: command ID, like in &struct iwl_cmd_header
164 * @group_id: group ID, like in &struct iwl_cmd_header
165 * @sequence: sequence, like in &struct iwl_cmd_header
166 * @length: length of the command
167 * @reserved: reserved
168 * @version: command version
169 */
170 struct iwl_cmd_header_wide {
171 u8 cmd;
172 u8 group_id;
173 __le16 sequence;
174 __le16 length;
175 u8 reserved;
176 u8 version;
177 } __packed;
178
179 /**
180 * struct iwl_calib_res_notif_phy_db - Receive phy db chunk after calibrations
181 * @type: type of the result - mostly ignored
182 * @length: length of the data
183 * @data: data, length in @length
184 */
185 struct iwl_calib_res_notif_phy_db {
186 __le16 type;
187 __le16 length;
188 u8 data[];
189 } __packed;
190
191 /**
192 * struct iwl_phy_db_cmd - configure operational ucode
193 * @type: type of the data
194 * @length: length of the data
195 * @data: data, length in @length
196 */
197 struct iwl_phy_db_cmd {
198 __le16 type;
199 __le16 length;
200 u8 data[];
201 } __packed;
202
203 /**
204 * struct iwl_cmd_response - generic response struct for most commands
205 * @status: status of the command asked, changes for each one
206 */
207 struct iwl_cmd_response {
208 __le32 status;
209 };
210
211 #endif /* __iwl_fw_api_cmdhdr_h__ */
212