xref: /freebsd/sys/contrib/dev/iwlwifi/fw/api/cmdhdr.h (revision bfcc09ddd422c95a1a2e4e794b63ee54c4902398)
1*bfcc09ddSBjoern A. Zeeb /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2*bfcc09ddSBjoern A. Zeeb /*
3*bfcc09ddSBjoern A. Zeeb  * Copyright (C) 2005-2014 Intel Corporation
4*bfcc09ddSBjoern A. Zeeb  * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
5*bfcc09ddSBjoern A. Zeeb  * Copyright (C) 2016-2017 Intel Deutschland GmbH
6*bfcc09ddSBjoern A. Zeeb  */
7*bfcc09ddSBjoern A. Zeeb #ifndef __iwl_fw_api_cmdhdr_h__
8*bfcc09ddSBjoern A. Zeeb #define __iwl_fw_api_cmdhdr_h__
9*bfcc09ddSBjoern A. Zeeb 
10*bfcc09ddSBjoern A. Zeeb /**
11*bfcc09ddSBjoern A. Zeeb  * DOC: Host command section
12*bfcc09ddSBjoern A. Zeeb  *
13*bfcc09ddSBjoern A. Zeeb  * A host command is a command issued by the upper layer to the fw. There are
14*bfcc09ddSBjoern A. Zeeb  * several versions of fw that have several APIs. The transport layer is
15*bfcc09ddSBjoern A. Zeeb  * completely agnostic to these differences.
16*bfcc09ddSBjoern A. Zeeb  * The transport does provide helper functionality (i.e. SYNC / ASYNC mode),
17*bfcc09ddSBjoern A. Zeeb  */
18*bfcc09ddSBjoern A. Zeeb #define SEQ_TO_QUEUE(s)	(((s) >> 8) & 0x1f)
19*bfcc09ddSBjoern A. Zeeb #define QUEUE_TO_SEQ(q)	(((q) & 0x1f) << 8)
20*bfcc09ddSBjoern A. Zeeb #define SEQ_TO_INDEX(s)	((s) & 0xff)
21*bfcc09ddSBjoern A. Zeeb #define INDEX_TO_SEQ(i)	((i) & 0xff)
22*bfcc09ddSBjoern A. Zeeb #define SEQ_RX_FRAME	cpu_to_le16(0x8000)
23*bfcc09ddSBjoern A. Zeeb 
24*bfcc09ddSBjoern A. Zeeb /*
25*bfcc09ddSBjoern A. Zeeb  * those functions retrieve specific information from
26*bfcc09ddSBjoern A. Zeeb  * the id field in the iwl_host_cmd struct which contains
27*bfcc09ddSBjoern A. Zeeb  * the command id, the group id and the version of the command
28*bfcc09ddSBjoern A. Zeeb  * and vice versa
29*bfcc09ddSBjoern A. Zeeb */
iwl_cmd_opcode(u32 cmdid)30*bfcc09ddSBjoern A. Zeeb static inline u8 iwl_cmd_opcode(u32 cmdid)
31*bfcc09ddSBjoern A. Zeeb {
32*bfcc09ddSBjoern A. Zeeb 	return cmdid & 0xFF;
33*bfcc09ddSBjoern A. Zeeb }
34*bfcc09ddSBjoern A. Zeeb 
iwl_cmd_groupid(u32 cmdid)35*bfcc09ddSBjoern A. Zeeb static inline u8 iwl_cmd_groupid(u32 cmdid)
36*bfcc09ddSBjoern A. Zeeb {
37*bfcc09ddSBjoern A. Zeeb 	return ((cmdid & 0xFF00) >> 8);
38*bfcc09ddSBjoern A. Zeeb }
39*bfcc09ddSBjoern A. Zeeb 
iwl_cmd_version(u32 cmdid)40*bfcc09ddSBjoern A. Zeeb static inline u8 iwl_cmd_version(u32 cmdid)
41*bfcc09ddSBjoern A. Zeeb {
42*bfcc09ddSBjoern A. Zeeb 	return ((cmdid & 0xFF0000) >> 16);
43*bfcc09ddSBjoern A. Zeeb }
44*bfcc09ddSBjoern A. Zeeb 
iwl_cmd_id(u8 opcode,u8 groupid,u8 version)45*bfcc09ddSBjoern A. Zeeb static inline u32 iwl_cmd_id(u8 opcode, u8 groupid, u8 version)
46*bfcc09ddSBjoern A. Zeeb {
47*bfcc09ddSBjoern A. Zeeb 	return opcode + (groupid << 8) + (version << 16);
48*bfcc09ddSBjoern A. Zeeb }
49*bfcc09ddSBjoern A. Zeeb 
50*bfcc09ddSBjoern A. Zeeb /* make u16 wide id out of u8 group and opcode */
51*bfcc09ddSBjoern A. Zeeb #define WIDE_ID(grp, opcode) (((grp) << 8) | (opcode))
52*bfcc09ddSBjoern A. Zeeb #define DEF_ID(opcode) ((1 << 8) | (opcode))
53*bfcc09ddSBjoern A. Zeeb 
54*bfcc09ddSBjoern A. Zeeb /* due to the conversion, this group is special; new groups
55*bfcc09ddSBjoern A. Zeeb  * should be defined in the appropriate fw-api header files
56*bfcc09ddSBjoern A. Zeeb  */
57*bfcc09ddSBjoern A. Zeeb #define IWL_ALWAYS_LONG_GROUP	1
58*bfcc09ddSBjoern A. Zeeb 
59*bfcc09ddSBjoern A. Zeeb /**
60*bfcc09ddSBjoern A. Zeeb  * struct iwl_cmd_header - (short) command header format
61*bfcc09ddSBjoern A. Zeeb  *
62*bfcc09ddSBjoern A. Zeeb  * This header format appears in the beginning of each command sent from the
63*bfcc09ddSBjoern A. Zeeb  * driver, and each response/notification received from uCode.
64*bfcc09ddSBjoern A. Zeeb  */
65*bfcc09ddSBjoern A. Zeeb struct iwl_cmd_header {
66*bfcc09ddSBjoern A. Zeeb 	/**
67*bfcc09ddSBjoern A. Zeeb 	 * @cmd: Command ID: REPLY_RXON, etc.
68*bfcc09ddSBjoern A. Zeeb 	 */
69*bfcc09ddSBjoern A. Zeeb 	u8 cmd;
70*bfcc09ddSBjoern A. Zeeb 	/**
71*bfcc09ddSBjoern A. Zeeb 	 * @group_id: group ID, for commands with groups
72*bfcc09ddSBjoern A. Zeeb 	 */
73*bfcc09ddSBjoern A. Zeeb 	u8 group_id;
74*bfcc09ddSBjoern A. Zeeb 	/**
75*bfcc09ddSBjoern A. Zeeb 	 * @sequence:
76*bfcc09ddSBjoern A. Zeeb 	 * Sequence number for the command.
77*bfcc09ddSBjoern A. Zeeb 	 *
78*bfcc09ddSBjoern A. Zeeb 	 * The driver sets up the sequence number to values of its choosing.
79*bfcc09ddSBjoern A. Zeeb 	 * uCode does not use this value, but passes it back to the driver
80*bfcc09ddSBjoern A. Zeeb 	 * when sending the response to each driver-originated command, so
81*bfcc09ddSBjoern A. Zeeb 	 * the driver can match the response to the command.  Since the values
82*bfcc09ddSBjoern A. Zeeb 	 * don't get used by uCode, the driver may set up an arbitrary format.
83*bfcc09ddSBjoern A. Zeeb 	 *
84*bfcc09ddSBjoern A. Zeeb 	 * There is one exception:  uCode sets bit 15 when it originates
85*bfcc09ddSBjoern A. Zeeb 	 * the response/notification, i.e. when the response/notification
86*bfcc09ddSBjoern A. Zeeb 	 * is not a direct response to a command sent by the driver.  For
87*bfcc09ddSBjoern A. Zeeb 	 * example, uCode issues REPLY_RX when it sends a received frame
88*bfcc09ddSBjoern A. Zeeb 	 * to the driver; it is not a direct response to any driver command.
89*bfcc09ddSBjoern A. Zeeb 	 *
90*bfcc09ddSBjoern A. Zeeb 	 * The Linux driver uses the following format:
91*bfcc09ddSBjoern A. Zeeb 	 *
92*bfcc09ddSBjoern A. Zeeb 	 *  0:7		tfd index - position within TX queue
93*bfcc09ddSBjoern A. Zeeb 	 *  8:12	TX queue id
94*bfcc09ddSBjoern A. Zeeb 	 *  13:14	reserved
95*bfcc09ddSBjoern A. Zeeb 	 *  15		unsolicited RX or uCode-originated notification
96*bfcc09ddSBjoern A. Zeeb 	 */
97*bfcc09ddSBjoern A. Zeeb 	__le16 sequence;
98*bfcc09ddSBjoern A. Zeeb } __packed;
99*bfcc09ddSBjoern A. Zeeb 
100*bfcc09ddSBjoern A. Zeeb /**
101*bfcc09ddSBjoern A. Zeeb  * struct iwl_cmd_header_wide
102*bfcc09ddSBjoern A. Zeeb  *
103*bfcc09ddSBjoern A. Zeeb  * This header format appears in the beginning of each command sent from the
104*bfcc09ddSBjoern A. Zeeb  * driver, and each response/notification received from uCode.
105*bfcc09ddSBjoern A. Zeeb  * this is the wide version that contains more information about the command
106*bfcc09ddSBjoern A. Zeeb  * like length, version and command type
107*bfcc09ddSBjoern A. Zeeb  *
108*bfcc09ddSBjoern A. Zeeb  * @cmd: command ID, like in &struct iwl_cmd_header
109*bfcc09ddSBjoern A. Zeeb  * @group_id: group ID, like in &struct iwl_cmd_header
110*bfcc09ddSBjoern A. Zeeb  * @sequence: sequence, like in &struct iwl_cmd_header
111*bfcc09ddSBjoern A. Zeeb  * @length: length of the command
112*bfcc09ddSBjoern A. Zeeb  * @reserved: reserved
113*bfcc09ddSBjoern A. Zeeb  * @version: command version
114*bfcc09ddSBjoern A. Zeeb  */
115*bfcc09ddSBjoern A. Zeeb struct iwl_cmd_header_wide {
116*bfcc09ddSBjoern A. Zeeb 	u8 cmd;
117*bfcc09ddSBjoern A. Zeeb 	u8 group_id;
118*bfcc09ddSBjoern A. Zeeb 	__le16 sequence;
119*bfcc09ddSBjoern A. Zeeb 	__le16 length;
120*bfcc09ddSBjoern A. Zeeb 	u8 reserved;
121*bfcc09ddSBjoern A. Zeeb 	u8 version;
122*bfcc09ddSBjoern A. Zeeb } __packed;
123*bfcc09ddSBjoern A. Zeeb 
124*bfcc09ddSBjoern A. Zeeb /**
125*bfcc09ddSBjoern A. Zeeb  * struct iwl_calib_res_notif_phy_db - Receive phy db chunk after calibrations
126*bfcc09ddSBjoern A. Zeeb  * @type: type of the result - mostly ignored
127*bfcc09ddSBjoern A. Zeeb  * @length: length of the data
128*bfcc09ddSBjoern A. Zeeb  * @data: data, length in @length
129*bfcc09ddSBjoern A. Zeeb  */
130*bfcc09ddSBjoern A. Zeeb struct iwl_calib_res_notif_phy_db {
131*bfcc09ddSBjoern A. Zeeb 	__le16 type;
132*bfcc09ddSBjoern A. Zeeb 	__le16 length;
133*bfcc09ddSBjoern A. Zeeb 	u8 data[];
134*bfcc09ddSBjoern A. Zeeb } __packed;
135*bfcc09ddSBjoern A. Zeeb 
136*bfcc09ddSBjoern A. Zeeb /**
137*bfcc09ddSBjoern A. Zeeb  * struct iwl_phy_db_cmd - configure operational ucode
138*bfcc09ddSBjoern A. Zeeb  * @type: type of the data
139*bfcc09ddSBjoern A. Zeeb  * @length: length of the data
140*bfcc09ddSBjoern A. Zeeb  * @data: data, length in @length
141*bfcc09ddSBjoern A. Zeeb  */
142*bfcc09ddSBjoern A. Zeeb struct iwl_phy_db_cmd {
143*bfcc09ddSBjoern A. Zeeb 	__le16 type;
144*bfcc09ddSBjoern A. Zeeb 	__le16 length;
145*bfcc09ddSBjoern A. Zeeb 	u8 data[];
146*bfcc09ddSBjoern A. Zeeb } __packed;
147*bfcc09ddSBjoern A. Zeeb 
148*bfcc09ddSBjoern A. Zeeb /**
149*bfcc09ddSBjoern A. Zeeb  * struct iwl_cmd_response - generic response struct for most commands
150*bfcc09ddSBjoern A. Zeeb  * @status: status of the command asked, changes for each one
151*bfcc09ddSBjoern A. Zeeb  */
152*bfcc09ddSBjoern A. Zeeb struct iwl_cmd_response {
153*bfcc09ddSBjoern A. Zeeb 	__le32 status;
154*bfcc09ddSBjoern A. Zeeb };
155*bfcc09ddSBjoern A. Zeeb 
156*bfcc09ddSBjoern A. Zeeb #endif /* __iwl_fw_api_cmdhdr_h__ */
157