hbm.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * ISHTP bus layer messages handling
  4. *
  5. * Copyright (c) 2003-2016, Intel Corporation.
  6. */
  7. #ifndef _ISHTP_HBM_H_
  8. #define _ISHTP_HBM_H_
  9. #include <linux/uuid.h>
  10. struct ishtp_device;
  11. struct ishtp_msg_hdr;
  12. struct ishtp_cl;
  13. /*
  14. * Timeouts in Seconds
  15. */
  16. #define ISHTP_INTEROP_TIMEOUT 7 /* Timeout on ready message */
  17. #define ISHTP_CL_CONNECT_TIMEOUT 15 /* HPS: Client Connect Timeout */
  18. /*
  19. * ISHTP Version
  20. */
  21. #define HBM_MINOR_VERSION 0
  22. #define HBM_MAJOR_VERSION 1
  23. /* Host bus message command opcode */
  24. #define ISHTP_HBM_CMD_OP_MSK 0x7f
  25. /* Host bus message command RESPONSE */
  26. #define ISHTP_HBM_CMD_RES_MSK 0x80
  27. /*
  28. * ISHTP Bus Message Command IDs
  29. */
  30. #define HOST_START_REQ_CMD 0x01
  31. #define HOST_START_RES_CMD 0x81
  32. #define HOST_STOP_REQ_CMD 0x02
  33. #define HOST_STOP_RES_CMD 0x82
  34. #define FW_STOP_REQ_CMD 0x03
  35. #define HOST_ENUM_REQ_CMD 0x04
  36. #define HOST_ENUM_RES_CMD 0x84
  37. #define HOST_CLIENT_PROPERTIES_REQ_CMD 0x05
  38. #define HOST_CLIENT_PROPERTIES_RES_CMD 0x85
  39. #define CLIENT_CONNECT_REQ_CMD 0x06
  40. #define CLIENT_CONNECT_RES_CMD 0x86
  41. #define CLIENT_DISCONNECT_REQ_CMD 0x07
  42. #define CLIENT_DISCONNECT_RES_CMD 0x87
  43. #define ISHTP_FLOW_CONTROL_CMD 0x08
  44. #define DMA_BUFFER_ALLOC_NOTIFY 0x11
  45. #define DMA_BUFFER_ALLOC_RESPONSE 0x91
  46. #define DMA_XFER 0x12
  47. #define DMA_XFER_ACK 0x92
  48. /*
  49. * ISHTP Stop Reason
  50. * used by hbm_host_stop_request.reason
  51. */
  52. #define DRIVER_STOP_REQUEST 0x00
  53. /*
  54. * ISHTP BUS Interface Section
  55. */
  56. struct ishtp_msg_hdr {
  57. uint32_t fw_addr:8;
  58. uint32_t host_addr:8;
  59. uint32_t length:9;
  60. uint32_t reserved:6;
  61. uint32_t msg_complete:1;
  62. } __packed;
  63. struct ishtp_bus_message {
  64. uint8_t hbm_cmd;
  65. uint8_t data[];
  66. } __packed;
  67. /**
  68. * struct hbm_cl_cmd - client specific host bus command
  69. * CONNECT, DISCONNECT, and FlOW CONTROL
  70. *
  71. * @hbm_cmd - bus message command header
  72. * @fw_addr - address of the fw client
  73. * @host_addr - address of the client in the driver
  74. * @data
  75. */
  76. struct ishtp_hbm_cl_cmd {
  77. uint8_t hbm_cmd;
  78. uint8_t fw_addr;
  79. uint8_t host_addr;
  80. uint8_t data;
  81. };
  82. struct hbm_version {
  83. uint8_t minor_version;
  84. uint8_t major_version;
  85. } __packed;
  86. struct hbm_host_version_request {
  87. uint8_t hbm_cmd;
  88. uint8_t reserved;
  89. struct hbm_version host_version;
  90. } __packed;
  91. struct hbm_host_version_response {
  92. uint8_t hbm_cmd;
  93. uint8_t host_version_supported;
  94. struct hbm_version fw_max_version;
  95. } __packed;
  96. struct hbm_host_stop_request {
  97. uint8_t hbm_cmd;
  98. uint8_t reason;
  99. uint8_t reserved[2];
  100. } __packed;
  101. struct hbm_host_stop_response {
  102. uint8_t hbm_cmd;
  103. uint8_t reserved[3];
  104. } __packed;
  105. struct hbm_host_enum_request {
  106. uint8_t hbm_cmd;
  107. uint8_t reserved[3];
  108. } __packed;
  109. struct hbm_host_enum_response {
  110. uint8_t hbm_cmd;
  111. uint8_t reserved[3];
  112. uint8_t valid_addresses[32];
  113. } __packed;
  114. struct ishtp_client_properties {
  115. guid_t protocol_name;
  116. uint8_t protocol_version;
  117. uint8_t max_number_of_connections;
  118. uint8_t fixed_address;
  119. uint8_t single_recv_buf;
  120. uint32_t max_msg_length;
  121. uint8_t dma_hdr_len;
  122. #define ISHTP_CLIENT_DMA_ENABLED 0x80
  123. uint8_t reserved4;
  124. uint8_t reserved5;
  125. uint8_t reserved6;
  126. } __packed;
  127. struct hbm_props_request {
  128. uint8_t hbm_cmd;
  129. uint8_t address;
  130. uint8_t reserved[2];
  131. } __packed;
  132. struct hbm_props_response {
  133. uint8_t hbm_cmd;
  134. uint8_t address;
  135. uint8_t status;
  136. uint8_t reserved[1];
  137. struct ishtp_client_properties client_properties;
  138. } __packed;
  139. /**
  140. * struct hbm_client_connect_request - connect/disconnect request
  141. *
  142. * @hbm_cmd - bus message command header
  143. * @fw_addr - address of the fw client
  144. * @host_addr - address of the client in the driver
  145. * @reserved
  146. */
  147. struct hbm_client_connect_request {
  148. uint8_t hbm_cmd;
  149. uint8_t fw_addr;
  150. uint8_t host_addr;
  151. uint8_t reserved;
  152. } __packed;
  153. /**
  154. * struct hbm_client_connect_response - connect/disconnect response
  155. *
  156. * @hbm_cmd - bus message command header
  157. * @fw_addr - address of the fw client
  158. * @host_addr - address of the client in the driver
  159. * @status - status of the request
  160. */
  161. struct hbm_client_connect_response {
  162. uint8_t hbm_cmd;
  163. uint8_t fw_addr;
  164. uint8_t host_addr;
  165. uint8_t status;
  166. } __packed;
  167. #define ISHTP_FC_MESSAGE_RESERVED_LENGTH 5
  168. struct hbm_flow_control {
  169. uint8_t hbm_cmd;
  170. uint8_t fw_addr;
  171. uint8_t host_addr;
  172. uint8_t reserved[ISHTP_FC_MESSAGE_RESERVED_LENGTH];
  173. } __packed;
  174. struct dma_alloc_notify {
  175. uint8_t hbm;
  176. uint8_t status;
  177. uint8_t reserved[2];
  178. uint32_t buf_size;
  179. uint64_t buf_address;
  180. /* [...] May come more size/address pairs */
  181. } __packed;
  182. struct dma_xfer_hbm {
  183. uint8_t hbm;
  184. uint8_t fw_client_id;
  185. uint8_t host_client_id;
  186. uint8_t reserved;
  187. uint64_t msg_addr;
  188. uint32_t msg_length;
  189. uint32_t reserved2;
  190. } __packed;
  191. /* System state */
  192. #define ISHTP_SYSTEM_STATE_CLIENT_ADDR 13
  193. #define SYSTEM_STATE_SUBSCRIBE 0x1
  194. #define SYSTEM_STATE_STATUS 0x2
  195. #define SYSTEM_STATE_QUERY_SUBSCRIBERS 0x3
  196. #define SYSTEM_STATE_STATE_CHANGE_REQ 0x4
  197. /*indicates suspend and resume states*/
  198. #define CONNECTED_STANDBY_STATE_BIT (1<<0)
  199. #define SUSPEND_STATE_BIT (1<<1)
  200. struct ish_system_states_header {
  201. uint32_t cmd;
  202. uint32_t cmd_status; /*responses will have this set*/
  203. } __packed;
  204. struct ish_system_states_subscribe {
  205. struct ish_system_states_header hdr;
  206. uint32_t states;
  207. } __packed;
  208. struct ish_system_states_status {
  209. struct ish_system_states_header hdr;
  210. uint32_t supported_states;
  211. uint32_t states_status;
  212. } __packed;
  213. struct ish_system_states_query_subscribers {
  214. struct ish_system_states_header hdr;
  215. } __packed;
  216. struct ish_system_states_state_change_req {
  217. struct ish_system_states_header hdr;
  218. uint32_t requested_states;
  219. uint32_t states_status;
  220. } __packed;
  221. /**
  222. * enum ishtp_hbm_state - host bus message protocol state
  223. *
  224. * @ISHTP_HBM_IDLE : protocol not started
  225. * @ISHTP_HBM_START : start request message was sent
  226. * @ISHTP_HBM_ENUM_CLIENTS : enumeration request was sent
  227. * @ISHTP_HBM_CLIENT_PROPERTIES : acquiring clients properties
  228. */
  229. enum ishtp_hbm_state {
  230. ISHTP_HBM_IDLE = 0,
  231. ISHTP_HBM_START,
  232. ISHTP_HBM_STARTED,
  233. ISHTP_HBM_ENUM_CLIENTS,
  234. ISHTP_HBM_CLIENT_PROPERTIES,
  235. ISHTP_HBM_WORKING,
  236. ISHTP_HBM_STOPPED,
  237. };
  238. static inline void ishtp_hbm_hdr(struct ishtp_msg_hdr *hdr, size_t length)
  239. {
  240. hdr->host_addr = 0;
  241. hdr->fw_addr = 0;
  242. hdr->length = length;
  243. hdr->msg_complete = 1;
  244. hdr->reserved = 0;
  245. }
  246. int ishtp_hbm_start_req(struct ishtp_device *dev);
  247. int ishtp_hbm_start_wait(struct ishtp_device *dev);
  248. int ishtp_hbm_cl_flow_control_req(struct ishtp_device *dev,
  249. struct ishtp_cl *cl);
  250. int ishtp_hbm_cl_disconnect_req(struct ishtp_device *dev, struct ishtp_cl *cl);
  251. int ishtp_hbm_cl_connect_req(struct ishtp_device *dev, struct ishtp_cl *cl);
  252. void ishtp_hbm_enum_clients_req(struct ishtp_device *dev);
  253. void bh_hbm_work_fn(struct work_struct *work);
  254. void recv_hbm(struct ishtp_device *dev, struct ishtp_msg_hdr *ishtp_hdr);
  255. void recv_fixed_cl_msg(struct ishtp_device *dev,
  256. struct ishtp_msg_hdr *ishtp_hdr);
  257. void ishtp_hbm_dispatch(struct ishtp_device *dev,
  258. struct ishtp_bus_message *hdr);
  259. void ishtp_query_subscribers(struct ishtp_device *dev);
  260. /* Exported I/F */
  261. void ishtp_send_suspend(struct ishtp_device *dev);
  262. void ishtp_send_resume(struct ishtp_device *dev);
  263. #endif /* _ISHTP_HBM_H_ */