cmdhdr.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. * DOC: Host command section
  66. *
  67. * A host command is a command issued by the upper layer to the fw. There are
  68. * several versions of fw that have several APIs. The transport layer is
  69. * completely agnostic to these differences.
  70. * The transport does provide helper functionality (i.e. SYNC / ASYNC mode),
  71. */
  72. #define SEQ_TO_QUEUE(s) (((s) >> 8) & 0x1f)
  73. #define QUEUE_TO_SEQ(q) (((q) & 0x1f) << 8)
  74. #define SEQ_TO_INDEX(s) ((s) & 0xff)
  75. #define INDEX_TO_SEQ(i) ((i) & 0xff)
  76. #define SEQ_RX_FRAME cpu_to_le16(0x8000)
  77. /*
  78. * those functions retrieve specific information from
  79. * the id field in the iwl_host_cmd struct which contains
  80. * the command id, the group id and the version of the command
  81. * and vice versa
  82. */
  83. static inline u8 iwl_cmd_opcode(u32 cmdid)
  84. {
  85. return cmdid & 0xFF;
  86. }
  87. static inline u8 iwl_cmd_groupid(u32 cmdid)
  88. {
  89. return ((cmdid & 0xFF00) >> 8);
  90. }
  91. static inline u8 iwl_cmd_version(u32 cmdid)
  92. {
  93. return ((cmdid & 0xFF0000) >> 16);
  94. }
  95. static inline u32 iwl_cmd_id(u8 opcode, u8 groupid, u8 version)
  96. {
  97. return opcode + (groupid << 8) + (version << 16);
  98. }
  99. /* make u16 wide id out of u8 group and opcode */
  100. #define WIDE_ID(grp, opcode) (((grp) << 8) | (opcode))
  101. #define DEF_ID(opcode) ((1 << 8) | (opcode))
  102. /* due to the conversion, this group is special; new groups
  103. * should be defined in the appropriate fw-api header files
  104. */
  105. #define IWL_ALWAYS_LONG_GROUP 1
  106. /**
  107. * struct iwl_cmd_header - (short) command header format
  108. *
  109. * This header format appears in the beginning of each command sent from the
  110. * driver, and each response/notification received from uCode.
  111. */
  112. struct iwl_cmd_header {
  113. /**
  114. * @cmd: Command ID: REPLY_RXON, etc.
  115. */
  116. u8 cmd;
  117. /**
  118. * @group_id: group ID, for commands with groups
  119. */
  120. u8 group_id;
  121. /**
  122. * @sequence:
  123. * Sequence number for the command.
  124. *
  125. * The driver sets up the sequence number to values of its choosing.
  126. * uCode does not use this value, but passes it back to the driver
  127. * when sending the response to each driver-originated command, so
  128. * the driver can match the response to the command. Since the values
  129. * don't get used by uCode, the driver may set up an arbitrary format.
  130. *
  131. * There is one exception: uCode sets bit 15 when it originates
  132. * the response/notification, i.e. when the response/notification
  133. * is not a direct response to a command sent by the driver. For
  134. * example, uCode issues REPLY_RX when it sends a received frame
  135. * to the driver; it is not a direct response to any driver command.
  136. *
  137. * The Linux driver uses the following format:
  138. *
  139. * 0:7 tfd index - position within TX queue
  140. * 8:12 TX queue id
  141. * 13:14 reserved
  142. * 15 unsolicited RX or uCode-originated notification
  143. */
  144. __le16 sequence;
  145. } __packed;
  146. /**
  147. * struct iwl_cmd_header_wide
  148. *
  149. * This header format appears in the beginning of each command sent from the
  150. * driver, and each response/notification received from uCode.
  151. * this is the wide version that contains more information about the command
  152. * like length, version and command type
  153. *
  154. * @cmd: command ID, like in &struct iwl_cmd_header
  155. * @group_id: group ID, like in &struct iwl_cmd_header
  156. * @sequence: sequence, like in &struct iwl_cmd_header
  157. * @length: length of the command
  158. * @reserved: reserved
  159. * @version: command version
  160. */
  161. struct iwl_cmd_header_wide {
  162. u8 cmd;
  163. u8 group_id;
  164. __le16 sequence;
  165. __le16 length;
  166. u8 reserved;
  167. u8 version;
  168. } __packed;
  169. /**
  170. * struct iwl_calib_res_notif_phy_db - Receive phy db chunk after calibrations
  171. * @type: type of the result - mostly ignored
  172. * @length: length of the data
  173. * @data: data, length in @length
  174. */
  175. struct iwl_calib_res_notif_phy_db {
  176. __le16 type;
  177. __le16 length;
  178. u8 data[];
  179. } __packed;
  180. /**
  181. * struct iwl_phy_db_cmd - configure operational ucode
  182. * @type: type of the data
  183. * @length: length of the data
  184. * @data: data, length in @length
  185. */
  186. struct iwl_phy_db_cmd {
  187. __le16 type;
  188. __le16 length;
  189. u8 data[];
  190. } __packed;
  191. /**
  192. * struct iwl_cmd_response - generic response struct for most commands
  193. * @status: status of the command asked, changes for each one
  194. */
  195. struct iwl_cmd_response {
  196. __le32 status;
  197. };
  198. #endif /* __iwl_fw_api_cmdhdr_h__ */