hbm.h 7.3 KB

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