stratix10-svc-client.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2017-2018, Intel Corporation
  4. */
  5. #ifndef __STRATIX10_SVC_CLIENT_H
  6. #define __STRATIX10_SVC_CLIENT_H
  7. /**
  8. * Service layer driver supports client names
  9. *
  10. * fpga: for FPGA configuration
  11. * rsu: for remote status update
  12. */
  13. #define SVC_CLIENT_FPGA "fpga"
  14. #define SVC_CLIENT_RSU "rsu"
  15. /**
  16. * Status of the sent command, in bit number
  17. *
  18. * SVC_STATUS_OK:
  19. * Secure firmware accepts the request issued by one of service clients.
  20. *
  21. * SVC_STATUS_BUFFER_SUBMITTED:
  22. * Service client successfully submits data buffer to secure firmware.
  23. *
  24. * SVC_STATUS_BUFFER_DONE:
  25. * Secure firmware completes data process, ready to accept the
  26. * next WRITE transaction.
  27. *
  28. * SVC_STATUS_COMPLETED:
  29. * Secure firmware completes service request successfully. In case of
  30. * FPGA configuration, FPGA should be in user mode.
  31. *
  32. * SVC_COMMAND_STATUS_BUSY:
  33. * Service request is still in process.
  34. *
  35. * SVC_COMMAND_STATUS_ERROR:
  36. * Error encountered during the process of the service request.
  37. *
  38. * SVC_STATUS_NO_SUPPORT:
  39. * Secure firmware doesn't support requested features such as RSU retry
  40. * or RSU notify.
  41. */
  42. #define SVC_STATUS_OK 0
  43. #define SVC_STATUS_BUFFER_SUBMITTED 1
  44. #define SVC_STATUS_BUFFER_DONE 2
  45. #define SVC_STATUS_COMPLETED 3
  46. #define SVC_STATUS_BUSY 4
  47. #define SVC_STATUS_ERROR 5
  48. #define SVC_STATUS_NO_SUPPORT 6
  49. /**
  50. * Flag bit for COMMAND_RECONFIG
  51. *
  52. * COMMAND_RECONFIG_FLAG_PARTIAL:
  53. * Set to FPGA configuration type (full or partial).
  54. */
  55. #define COMMAND_RECONFIG_FLAG_PARTIAL 0
  56. /**
  57. * Timeout settings for service clients:
  58. * timeout value used in Stratix10 FPGA manager driver.
  59. * timeout value used in RSU driver
  60. */
  61. #define SVC_RECONFIG_REQUEST_TIMEOUT_MS 300
  62. #define SVC_RECONFIG_BUFFER_TIMEOUT_MS 720
  63. #define SVC_RSU_REQUEST_TIMEOUT_MS 300
  64. struct stratix10_svc_chan;
  65. /**
  66. * enum stratix10_svc_command_code - supported service commands
  67. *
  68. * @COMMAND_NOOP: do 'dummy' request for integration/debug/trouble-shooting
  69. *
  70. * @COMMAND_RECONFIG: ask for FPGA configuration preparation, return status
  71. * is SVC_STATUS_OK
  72. *
  73. * @COMMAND_RECONFIG_DATA_SUBMIT: submit buffer(s) of bit-stream data for the
  74. * FPGA configuration, return status is SVC_STATUS_SUBMITTED or SVC_STATUS_ERROR
  75. *
  76. * @COMMAND_RECONFIG_DATA_CLAIM: check the status of the configuration, return
  77. * status is SVC_STATUS_COMPLETED, or SVC_STATUS_BUSY, or SVC_STATUS_ERROR
  78. *
  79. * @COMMAND_RECONFIG_STATUS: check the status of the configuration, return
  80. * status is SVC_STATUS_COMPLETED, or SVC_STATUS_BUSY, or SVC_STATUS_ERROR
  81. *
  82. * @COMMAND_RSU_STATUS: request remote system update boot log, return status
  83. * is log data or SVC_STATUS_RSU_ERROR
  84. *
  85. * @COMMAND_RSU_UPDATE: set the offset of the bitstream to boot after reboot,
  86. * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
  87. *
  88. * @COMMAND_RSU_NOTIFY: report the status of hard processor system
  89. * software to firmware, return status is SVC_STATUS_OK or
  90. * SVC_STATUS_ERROR
  91. *
  92. * @COMMAND_RSU_RETRY: query firmware for the current image's retry counter,
  93. * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
  94. *
  95. * @COMMAND_RSU_MAX_RETRY: query firmware for the max retry value,
  96. * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
  97. *
  98. * @COMMAND_RSU_DCMF_VERSION: query firmware for the DCMF version, return status
  99. * is SVC_STATUS_OK or SVC_STATUS_ERROR
  100. */
  101. enum stratix10_svc_command_code {
  102. COMMAND_NOOP = 0,
  103. COMMAND_RECONFIG,
  104. COMMAND_RECONFIG_DATA_SUBMIT,
  105. COMMAND_RECONFIG_DATA_CLAIM,
  106. COMMAND_RECONFIG_STATUS,
  107. COMMAND_RSU_STATUS,
  108. COMMAND_RSU_UPDATE,
  109. COMMAND_RSU_NOTIFY,
  110. COMMAND_RSU_RETRY,
  111. COMMAND_RSU_MAX_RETRY,
  112. COMMAND_RSU_DCMF_VERSION,
  113. };
  114. /**
  115. * struct stratix10_svc_client_msg - message sent by client to service
  116. * @payload: starting address of data need be processed
  117. * @payload_length: data size in bytes
  118. * @command: service command
  119. * @arg: args to be passed via registers and not physically mapped buffers
  120. */
  121. struct stratix10_svc_client_msg {
  122. void *payload;
  123. size_t payload_length;
  124. enum stratix10_svc_command_code command;
  125. u64 arg[3];
  126. };
  127. /**
  128. * struct stratix10_svc_command_config_type - config type
  129. * @flags: flag bit for the type of FPGA configuration
  130. */
  131. struct stratix10_svc_command_config_type {
  132. u32 flags;
  133. };
  134. /**
  135. * struct stratix10_svc_cb_data - callback data structure from service layer
  136. * @status: the status of sent command
  137. * @kaddr1: address of 1st completed data block
  138. * @kaddr2: address of 2nd completed data block
  139. * @kaddr3: address of 3rd completed data block
  140. */
  141. struct stratix10_svc_cb_data {
  142. u32 status;
  143. void *kaddr1;
  144. void *kaddr2;
  145. void *kaddr3;
  146. };
  147. /**
  148. * struct stratix10_svc_client - service client structure
  149. * @dev: the client device
  150. * @receive_cb: callback to provide service client the received data
  151. * @priv: client private data
  152. */
  153. struct stratix10_svc_client {
  154. struct device *dev;
  155. void (*receive_cb)(struct stratix10_svc_client *client,
  156. struct stratix10_svc_cb_data *cb_data);
  157. void *priv;
  158. };
  159. /**
  160. * stratix10_svc_request_channel_byname() - request service channel
  161. * @client: identity of the client requesting the channel
  162. * @name: supporting client name defined above
  163. *
  164. * Return: a pointer to channel assigned to the client on success,
  165. * or ERR_PTR() on error.
  166. */
  167. struct stratix10_svc_chan
  168. *stratix10_svc_request_channel_byname(struct stratix10_svc_client *client,
  169. const char *name);
  170. /**
  171. * stratix10_svc_free_channel() - free service channel.
  172. * @chan: service channel to be freed
  173. */
  174. void stratix10_svc_free_channel(struct stratix10_svc_chan *chan);
  175. /**
  176. * stratix10_svc_allocate_memory() - allocate the momory
  177. * @chan: service channel assigned to the client
  178. * @size: number of bytes client requests
  179. *
  180. * Service layer allocates the requested number of bytes from the memory
  181. * pool for the client.
  182. *
  183. * Return: the starting address of allocated memory on success, or
  184. * ERR_PTR() on error.
  185. */
  186. void *stratix10_svc_allocate_memory(struct stratix10_svc_chan *chan,
  187. size_t size);
  188. /**
  189. * stratix10_svc_free_memory() - free allocated memory
  190. * @chan: service channel assigned to the client
  191. * @kaddr: starting address of memory to be free back to pool
  192. */
  193. void stratix10_svc_free_memory(struct stratix10_svc_chan *chan, void *kaddr);
  194. /**
  195. * stratix10_svc_send() - send a message to the remote
  196. * @chan: service channel assigned to the client
  197. * @msg: message data to be sent, in the format of
  198. * struct stratix10_svc_client_msg
  199. *
  200. * Return: 0 for success, -ENOMEM or -ENOBUFS on error.
  201. */
  202. int stratix10_svc_send(struct stratix10_svc_chan *chan, void *msg);
  203. /**
  204. * intel_svc_done() - complete service request
  205. * @chan: service channel assigned to the client
  206. *
  207. * This function is used by service client to inform service layer that
  208. * client's service requests are completed, or there is an error in the
  209. * request process.
  210. */
  211. void stratix10_svc_done(struct stratix10_svc_chan *chan);
  212. #endif