iosm_ipc_protocol_ops.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. /* SPDX-License-Identifier: GPL-2.0-only
  2. *
  3. * Copyright (C) 2020-21 Intel Corporation.
  4. */
  5. #ifndef IOSM_IPC_PROTOCOL_OPS_H
  6. #define IOSM_IPC_PROTOCOL_OPS_H
  7. #define SIZE_MASK 0x00FFFFFF
  8. #define COMPLETION_STATUS 24
  9. #define RESET_BIT 7
  10. /**
  11. * enum ipc_mem_td_cs - Completion status of a TD
  12. * @IPC_MEM_TD_CS_INVALID: Initial status - td not yet used.
  13. * @IPC_MEM_TD_CS_PARTIAL_TRANSFER: More data pending -> next TD used for this
  14. * @IPC_MEM_TD_CS_END_TRANSFER: IO transfer is complete.
  15. * @IPC_MEM_TD_CS_OVERFLOW: IO transfer to small for the buff to write
  16. * @IPC_MEM_TD_CS_ABORT: TD marked as abort and shall be discarded
  17. * by AP.
  18. * @IPC_MEM_TD_CS_ERROR: General error.
  19. */
  20. enum ipc_mem_td_cs {
  21. IPC_MEM_TD_CS_INVALID,
  22. IPC_MEM_TD_CS_PARTIAL_TRANSFER,
  23. IPC_MEM_TD_CS_END_TRANSFER,
  24. IPC_MEM_TD_CS_OVERFLOW,
  25. IPC_MEM_TD_CS_ABORT,
  26. IPC_MEM_TD_CS_ERROR,
  27. };
  28. /**
  29. * enum ipc_mem_msg_cs - Completion status of IPC Message
  30. * @IPC_MEM_MSG_CS_INVALID: Initial status.
  31. * @IPC_MEM_MSG_CS_SUCCESS: IPC Message completion success.
  32. * @IPC_MEM_MSG_CS_ERROR: Message send error.
  33. */
  34. enum ipc_mem_msg_cs {
  35. IPC_MEM_MSG_CS_INVALID,
  36. IPC_MEM_MSG_CS_SUCCESS,
  37. IPC_MEM_MSG_CS_ERROR,
  38. };
  39. /**
  40. * struct ipc_msg_prep_args_pipe - struct for pipe args for message preparation
  41. * @pipe: Pipe to open/close
  42. */
  43. struct ipc_msg_prep_args_pipe {
  44. struct ipc_pipe *pipe;
  45. };
  46. /**
  47. * struct ipc_msg_prep_args_sleep - struct for sleep args for message
  48. * preparation
  49. * @target: 0=host, 1=device
  50. * @state: 0=enter sleep, 1=exit sleep
  51. */
  52. struct ipc_msg_prep_args_sleep {
  53. unsigned int target;
  54. unsigned int state;
  55. };
  56. /**
  57. * struct ipc_msg_prep_feature_set - struct for feature set argument for
  58. * message preparation
  59. * @reset_enable: 0=out-of-band, 1=in-band-crash notification
  60. */
  61. struct ipc_msg_prep_feature_set {
  62. u8 reset_enable;
  63. };
  64. /**
  65. * struct ipc_msg_prep_map - struct for map argument for message preparation
  66. * @region_id: Region to map
  67. * @addr: Pcie addr of region to map
  68. * @size: Size of the region to map
  69. */
  70. struct ipc_msg_prep_map {
  71. unsigned int region_id;
  72. unsigned long addr;
  73. size_t size;
  74. };
  75. /**
  76. * struct ipc_msg_prep_unmap - struct for unmap argument for message preparation
  77. * @region_id: Region to unmap
  78. */
  79. struct ipc_msg_prep_unmap {
  80. unsigned int region_id;
  81. };
  82. /**
  83. * struct ipc_msg_prep_args - Union to handle different message types
  84. * @pipe_open: Pipe open message preparation struct
  85. * @pipe_close: Pipe close message preparation struct
  86. * @sleep: Sleep message preparation struct
  87. * @feature_set: Feature set message preparation struct
  88. * @map: Memory map message preparation struct
  89. * @unmap: Memory unmap message preparation struct
  90. */
  91. union ipc_msg_prep_args {
  92. struct ipc_msg_prep_args_pipe pipe_open;
  93. struct ipc_msg_prep_args_pipe pipe_close;
  94. struct ipc_msg_prep_args_sleep sleep;
  95. struct ipc_msg_prep_feature_set feature_set;
  96. struct ipc_msg_prep_map map;
  97. struct ipc_msg_prep_unmap unmap;
  98. };
  99. /**
  100. * enum ipc_msg_prep_type - Enum for message prepare actions
  101. * @IPC_MSG_PREP_SLEEP: Sleep message preparation type
  102. * @IPC_MSG_PREP_PIPE_OPEN: Pipe open message preparation type
  103. * @IPC_MSG_PREP_PIPE_CLOSE: Pipe close message preparation type
  104. * @IPC_MSG_PREP_FEATURE_SET: Feature set message preparation type
  105. * @IPC_MSG_PREP_MAP: Memory map message preparation type
  106. * @IPC_MSG_PREP_UNMAP: Memory unmap message preparation type
  107. */
  108. enum ipc_msg_prep_type {
  109. IPC_MSG_PREP_SLEEP,
  110. IPC_MSG_PREP_PIPE_OPEN,
  111. IPC_MSG_PREP_PIPE_CLOSE,
  112. IPC_MSG_PREP_FEATURE_SET,
  113. IPC_MSG_PREP_MAP,
  114. IPC_MSG_PREP_UNMAP,
  115. };
  116. /**
  117. * struct ipc_rsp - Response to sent message
  118. * @completion: For waking up requestor
  119. * @status: Completion status
  120. */
  121. struct ipc_rsp {
  122. struct completion completion;
  123. enum ipc_mem_msg_cs status;
  124. };
  125. /**
  126. * enum ipc_mem_msg - Type-definition of the messages.
  127. * @IPC_MEM_MSG_OPEN_PIPE: AP ->CP: Open a pipe
  128. * @IPC_MEM_MSG_CLOSE_PIPE: AP ->CP: Close a pipe
  129. * @IPC_MEM_MSG_ABORT_PIPE: AP ->CP: wait for completion of the
  130. * running transfer and abort all pending
  131. * IO-transfers for the pipe
  132. * @IPC_MEM_MSG_SLEEP: AP ->CP: host enter or exit sleep
  133. * @IPC_MEM_MSG_FEATURE_SET: AP ->CP: Intel feature configuration
  134. */
  135. enum ipc_mem_msg {
  136. IPC_MEM_MSG_OPEN_PIPE = 0x01,
  137. IPC_MEM_MSG_CLOSE_PIPE = 0x02,
  138. IPC_MEM_MSG_ABORT_PIPE = 0x03,
  139. IPC_MEM_MSG_SLEEP = 0x04,
  140. IPC_MEM_MSG_FEATURE_SET = 0xF0,
  141. };
  142. /**
  143. * struct ipc_mem_msg_open_pipe - Message structure for open pipe
  144. * @tdr_addr: Tdr address
  145. * @tdr_entries: Tdr entries
  146. * @pipe_nr: Pipe number
  147. * @type_of_message: Message type
  148. * @irq_vector: MSI vector number
  149. * @accumulation_backoff: Time in usec for data accumalation
  150. * @completion_status: Message Completion Status
  151. */
  152. struct ipc_mem_msg_open_pipe {
  153. __le64 tdr_addr;
  154. __le16 tdr_entries;
  155. u8 pipe_nr;
  156. u8 type_of_message;
  157. __le32 irq_vector;
  158. __le32 accumulation_backoff;
  159. __le32 completion_status;
  160. };
  161. /**
  162. * struct ipc_mem_msg_close_pipe - Message structure for close pipe
  163. * @reserved1: Reserved
  164. * @reserved2: Reserved
  165. * @pipe_nr: Pipe number
  166. * @type_of_message: Message type
  167. * @reserved3: Reserved
  168. * @reserved4: Reserved
  169. * @completion_status: Message Completion Status
  170. */
  171. struct ipc_mem_msg_close_pipe {
  172. __le32 reserved1[2];
  173. __le16 reserved2;
  174. u8 pipe_nr;
  175. u8 type_of_message;
  176. __le32 reserved3;
  177. __le32 reserved4;
  178. __le32 completion_status;
  179. };
  180. /**
  181. * struct ipc_mem_msg_abort_pipe - Message structure for abort pipe
  182. * @reserved1: Reserved
  183. * @reserved2: Reserved
  184. * @pipe_nr: Pipe number
  185. * @type_of_message: Message type
  186. * @reserved3: Reserved
  187. * @reserved4: Reserved
  188. * @completion_status: Message Completion Status
  189. */
  190. struct ipc_mem_msg_abort_pipe {
  191. __le32 reserved1[2];
  192. __le16 reserved2;
  193. u8 pipe_nr;
  194. u8 type_of_message;
  195. __le32 reserved3;
  196. __le32 reserved4;
  197. __le32 completion_status;
  198. };
  199. /**
  200. * struct ipc_mem_msg_host_sleep - Message structure for sleep message.
  201. * @reserved1: Reserved
  202. * @target: 0=host, 1=device, host or EP devie
  203. * is the message target
  204. * @state: 0=enter sleep, 1=exit sleep,
  205. * 2=enter sleep no protocol
  206. * @reserved2: Reserved
  207. * @type_of_message: Message type
  208. * @reserved3: Reserved
  209. * @reserved4: Reserved
  210. * @completion_status: Message Completion Status
  211. */
  212. struct ipc_mem_msg_host_sleep {
  213. __le32 reserved1[2];
  214. u8 target;
  215. u8 state;
  216. u8 reserved2;
  217. u8 type_of_message;
  218. __le32 reserved3;
  219. __le32 reserved4;
  220. __le32 completion_status;
  221. };
  222. /**
  223. * struct ipc_mem_msg_feature_set - Message structure for feature_set message
  224. * @reserved1: Reserved
  225. * @reserved2: Reserved
  226. * @reset_enable: 0=out-of-band, 1=in-band-crash notification
  227. * @type_of_message: Message type
  228. * @reserved3: Reserved
  229. * @reserved4: Reserved
  230. * @completion_status: Message Completion Status
  231. */
  232. struct ipc_mem_msg_feature_set {
  233. __le32 reserved1[2];
  234. __le16 reserved2;
  235. u8 reset_enable;
  236. u8 type_of_message;
  237. __le32 reserved3;
  238. __le32 reserved4;
  239. __le32 completion_status;
  240. };
  241. /**
  242. * struct ipc_mem_msg_common - Message structure for completion status update.
  243. * @reserved1: Reserved
  244. * @reserved2: Reserved
  245. * @type_of_message: Message type
  246. * @reserved3: Reserved
  247. * @reserved4: Reserved
  248. * @completion_status: Message Completion Status
  249. */
  250. struct ipc_mem_msg_common {
  251. __le32 reserved1[2];
  252. u8 reserved2[3];
  253. u8 type_of_message;
  254. __le32 reserved3;
  255. __le32 reserved4;
  256. __le32 completion_status;
  257. };
  258. /**
  259. * union ipc_mem_msg_entry - Union with all possible messages.
  260. * @open_pipe: Open pipe message struct
  261. * @close_pipe: Close pipe message struct
  262. * @abort_pipe: Abort pipe message struct
  263. * @host_sleep: Host sleep message struct
  264. * @feature_set: Featuer set message struct
  265. * @common: Used to access msg_type and to set the completion status
  266. */
  267. union ipc_mem_msg_entry {
  268. struct ipc_mem_msg_open_pipe open_pipe;
  269. struct ipc_mem_msg_close_pipe close_pipe;
  270. struct ipc_mem_msg_abort_pipe abort_pipe;
  271. struct ipc_mem_msg_host_sleep host_sleep;
  272. struct ipc_mem_msg_feature_set feature_set;
  273. struct ipc_mem_msg_common common;
  274. };
  275. /* Transfer descriptor definition. */
  276. struct ipc_protocol_td {
  277. union {
  278. /* 0 : 63 - 64-bit address of a buffer in host memory. */
  279. dma_addr_t address;
  280. struct {
  281. /* 0 : 31 - 32 bit address */
  282. __le32 address;
  283. /* 32 : 63 - corresponding descriptor */
  284. __le32 desc;
  285. } __packed shm;
  286. } buffer;
  287. /* 0 - 2nd byte - Size of the buffer.
  288. * The host provides the size of the buffer queued.
  289. * The EP device reads this value and shall update
  290. * it for downlink transfers to indicate the
  291. * amount of data written in buffer.
  292. * 3rd byte - This field provides the completion status
  293. * of the TD. When queuing the TD, the host sets
  294. * the status to 0. The EP device updates this
  295. * field when completing the TD.
  296. */
  297. __le32 scs;
  298. /* 0th - nr of following descriptors
  299. * 1 - 3rd byte - reserved
  300. */
  301. __le32 next;
  302. } __packed;
  303. /**
  304. * ipc_protocol_msg_prep - Prepare message based upon message type
  305. * @ipc_imem: iosm_protocol instance
  306. * @msg_type: message prepare type
  307. * @args: message arguments
  308. *
  309. * Return: 0 on success and failure value on error
  310. */
  311. int ipc_protocol_msg_prep(struct iosm_imem *ipc_imem,
  312. enum ipc_msg_prep_type msg_type,
  313. union ipc_msg_prep_args *args);
  314. /**
  315. * ipc_protocol_msg_hp_update - Function for head pointer update
  316. * of message ring
  317. * @ipc_imem: iosm_protocol instance
  318. */
  319. void ipc_protocol_msg_hp_update(struct iosm_imem *ipc_imem);
  320. /**
  321. * ipc_protocol_msg_process - Function for processing responses
  322. * to IPC messages
  323. * @ipc_imem: iosm_protocol instance
  324. * @irq: IRQ vector
  325. *
  326. * Return: True on success, false if error
  327. */
  328. bool ipc_protocol_msg_process(struct iosm_imem *ipc_imem, int irq);
  329. /**
  330. * ipc_protocol_ul_td_send - Function for sending the data to CP
  331. * @ipc_protocol: iosm_protocol instance
  332. * @pipe: Pipe instance
  333. * @p_ul_list: uplink sk_buff list
  334. *
  335. * Return: true in success, false in case of error
  336. */
  337. bool ipc_protocol_ul_td_send(struct iosm_protocol *ipc_protocol,
  338. struct ipc_pipe *pipe,
  339. struct sk_buff_head *p_ul_list);
  340. /**
  341. * ipc_protocol_ul_td_process - Function for processing the sent data
  342. * @ipc_protocol: iosm_protocol instance
  343. * @pipe: Pipe instance
  344. *
  345. * Return: sk_buff instance
  346. */
  347. struct sk_buff *ipc_protocol_ul_td_process(struct iosm_protocol *ipc_protocol,
  348. struct ipc_pipe *pipe);
  349. /**
  350. * ipc_protocol_dl_td_prepare - Function for providing DL TDs to CP
  351. * @ipc_protocol: iosm_protocol instance
  352. * @pipe: Pipe instance
  353. *
  354. * Return: true in success, false in case of error
  355. */
  356. bool ipc_protocol_dl_td_prepare(struct iosm_protocol *ipc_protocol,
  357. struct ipc_pipe *pipe);
  358. /**
  359. * ipc_protocol_dl_td_process - Function for processing the DL data
  360. * @ipc_protocol: iosm_protocol instance
  361. * @pipe: Pipe instance
  362. *
  363. * Return: sk_buff instance
  364. */
  365. struct sk_buff *ipc_protocol_dl_td_process(struct iosm_protocol *ipc_protocol,
  366. struct ipc_pipe *pipe);
  367. /**
  368. * ipc_protocol_get_head_tail_index - Function for getting Head and Tail
  369. * pointer index of given pipe
  370. * @ipc_protocol: iosm_protocol instance
  371. * @pipe: Pipe Instance
  372. * @head: head pointer index of the given pipe
  373. * @tail: tail pointer index of the given pipe
  374. */
  375. void ipc_protocol_get_head_tail_index(struct iosm_protocol *ipc_protocol,
  376. struct ipc_pipe *pipe, u32 *head,
  377. u32 *tail);
  378. /**
  379. * ipc_protocol_get_ipc_status - Function for getting the IPC Status
  380. * @ipc_protocol: iosm_protocol instance
  381. *
  382. * Return: Returns IPC State
  383. */
  384. enum ipc_mem_device_ipc_state ipc_protocol_get_ipc_status(struct iosm_protocol
  385. *ipc_protocol);
  386. /**
  387. * ipc_protocol_pipe_cleanup - Function to cleanup pipe resources
  388. * @ipc_protocol: iosm_protocol instance
  389. * @pipe: Pipe instance
  390. */
  391. void ipc_protocol_pipe_cleanup(struct iosm_protocol *ipc_protocol,
  392. struct ipc_pipe *pipe);
  393. /**
  394. * ipc_protocol_get_ap_exec_stage - Function for getting AP Exec Stage
  395. * @ipc_protocol: pointer to struct iosm protocol
  396. *
  397. * Return: returns BOOT Stages
  398. */
  399. enum ipc_mem_exec_stage
  400. ipc_protocol_get_ap_exec_stage(struct iosm_protocol *ipc_protocol);
  401. /**
  402. * ipc_protocol_pm_dev_get_sleep_notification - Function for getting Dev Sleep
  403. * notification
  404. * @ipc_protocol: iosm_protocol instance
  405. *
  406. * Return: Returns dev PM State
  407. */
  408. u32 ipc_protocol_pm_dev_get_sleep_notification(struct iosm_protocol
  409. *ipc_protocol);
  410. #endif