1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2017-2018, Intel Corporation
6 #ifndef __STRATIX10_SVC_CLIENT_H
7 #define __STRATIX10_SVC_CLIENT_H
10 * Service layer driver supports client names
12 * fpga: for FPGA configuration
13 * rsu: for remote status update
15 #define SVC_CLIENT_FPGA "fpga"
16 #define SVC_CLIENT_RSU "rsu"
17 #define SVC_CLIENT_FCS "fcs"
20 * Status of the sent command, in bit number
23 * Secure firmware accepts the request issued by one of service clients.
25 * SVC_STATUS_BUFFER_SUBMITTED:
26 * Service client successfully submits data buffer to secure firmware.
28 * SVC_STATUS_BUFFER_DONE:
29 * Secure firmware completes data process, ready to accept the
30 * next WRITE transaction.
32 * SVC_STATUS_COMPLETED:
33 * Secure firmware completes service request successfully. In case of
34 * FPGA configuration, FPGA should be in user mode.
36 * SVC_COMMAND_STATUS_BUSY:
37 * Service request is still in process.
39 * SVC_COMMAND_STATUS_ERROR:
40 * Error encountered during the process of the service request.
42 * SVC_STATUS_NO_SUPPORT:
43 * Secure firmware doesn't support requested features such as RSU retry
46 #define SVC_STATUS_OK 0
47 #define SVC_STATUS_BUFFER_SUBMITTED 1
48 #define SVC_STATUS_BUFFER_DONE 2
49 #define SVC_STATUS_COMPLETED 3
50 #define SVC_STATUS_BUSY 4
51 #define SVC_STATUS_ERROR 5
52 #define SVC_STATUS_NO_SUPPORT 6
53 #define SVC_STATUS_INVALID_PARAM 7
56 * Flag bit for COMMAND_RECONFIG
58 * COMMAND_RECONFIG_FLAG_PARTIAL:
59 * Set to FPGA configuration type (full or partial).
61 #define COMMAND_RECONFIG_FLAG_PARTIAL 0
64 * Timeout settings for service clients:
65 * timeout value used in Stratix10 FPGA manager driver.
66 * timeout value used in RSU driver
68 #define SVC_RECONFIG_REQUEST_TIMEOUT_MS 300
69 #define SVC_RECONFIG_BUFFER_TIMEOUT_MS 720
70 #define SVC_RSU_REQUEST_TIMEOUT_MS 300
71 #define SVC_FCS_REQUEST_TIMEOUT_MS 2000
72 #define SVC_COMPLETED_TIMEOUT_MS 30000
74 struct stratix10_svc_chan;
77 * enum stratix10_svc_command_code - supported service commands
79 * @COMMAND_NOOP: do 'dummy' request for integration/debug/trouble-shooting
81 * @COMMAND_RECONFIG: ask for FPGA configuration preparation, return status
84 * @COMMAND_RECONFIG_DATA_SUBMIT: submit buffer(s) of bit-stream data for the
85 * FPGA configuration, return status is SVC_STATUS_SUBMITTED or SVC_STATUS_ERROR
87 * @COMMAND_RECONFIG_DATA_CLAIM: check the status of the configuration, return
88 * status is SVC_STATUS_COMPLETED, or SVC_STATUS_BUSY, or SVC_STATUS_ERROR
90 * @COMMAND_RECONFIG_STATUS: check the status of the configuration, return
91 * status is SVC_STATUS_COMPLETED, or SVC_STATUS_BUSY, or SVC_STATUS_ERROR
93 * @COMMAND_RSU_STATUS: request remote system update boot log, return status
94 * is log data or SVC_STATUS_RSU_ERROR
96 * @COMMAND_RSU_UPDATE: set the offset of the bitstream to boot after reboot,
97 * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
99 * @COMMAND_RSU_NOTIFY: report the status of hard processor system
100 * software to firmware, return status is SVC_STATUS_OK or
103 * @COMMAND_RSU_RETRY: query firmware for the current image's retry counter,
104 * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
106 * @COMMAND_RSU_MAX_RETRY: query firmware for the max retry value,
107 * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
109 * @COMMAND_RSU_DCMF_VERSION: query firmware for the DCMF version, return status
110 * is SVC_STATUS_OK or SVC_STATUS_ERROR
112 * @COMMAND_POLL_SERVICE_STATUS: poll if the service request is complete,
113 * return statis is SVC_STATUS_OK, SVC_STATUS_ERROR or SVC_STATUS_BUSY
115 * @COMMAND_FIRMWARE_VERSION: query running firmware version, return status
116 * is SVC_STATUS_OK or SVC_STATUS_ERROR
118 * @COMMAND_SMC_SVC_VERSION: Non-mailbox SMC SVC API Version,
119 * return status is SVC_STATUS_OK
121 * @COMMAND_MBOX_SEND_CMD: send generic mailbox command, return status is
122 * SVC_STATUS_OK or SVC_STATUS_ERROR
124 * @COMMAND_RSU_DCMF_STATUS: query firmware for the DCMF status
125 * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
127 * @COMMAND_FCS_REQUEST_SERVICE: request validation of image from firmware,
128 * return status is SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM
130 * @COMMAND_FCS_SEND_CERTIFICATE: send a certificate, return status is
131 * SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM, SVC_STATUS_ERROR
133 * @COMMAND_FCS_GET_PROVISION_DATA: read the provisioning data, return status is
134 * SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM, SVC_STATUS_ERROR
136 * @COMMAND_FCS_DATA_ENCRYPTION: encrypt the data, return status is
137 * SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM, SVC_STATUS_ERROR
139 * @COMMAND_FCS_DATA_DECRYPTION: decrypt the data, return status is
140 * SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM, SVC_STATUS_ERROR
142 * @COMMAND_FCS_RANDOM_NUMBER_GEN: generate a random number, return status
143 * is SVC_STATUS_OK, SVC_STATUS_ERROR
145 enum stratix10_svc_command_code {
149 COMMAND_RECONFIG_DATA_SUBMIT,
150 COMMAND_RECONFIG_DATA_CLAIM,
151 COMMAND_RECONFIG_STATUS,
153 COMMAND_RSU_STATUS = 10,
157 COMMAND_RSU_MAX_RETRY,
158 COMMAND_RSU_DCMF_VERSION,
159 COMMAND_RSU_DCMF_STATUS,
160 COMMAND_FIRMWARE_VERSION,
162 COMMAND_FCS_REQUEST_SERVICE = 20,
163 COMMAND_FCS_SEND_CERTIFICATE,
164 COMMAND_FCS_GET_PROVISION_DATA,
165 COMMAND_FCS_DATA_ENCRYPTION,
166 COMMAND_FCS_DATA_DECRYPTION,
167 COMMAND_FCS_RANDOM_NUMBER_GEN,
168 /* for general status poll */
169 COMMAND_POLL_SERVICE_STATUS = 40,
170 /* for generic mailbox send command */
171 COMMAND_MBOX_SEND_CMD = 100,
172 /* Non-mailbox SMC Call */
173 COMMAND_SMC_SVC_VERSION = 200,
177 * struct stratix10_svc_client_msg - message sent by client to service
178 * @payload: starting address of data need be processed
179 * @payload_length: to be processed data size in bytes
180 * @payload_output: starting address of processed data
181 * @payload_length_output: processed data size in bytes
182 * @command: service command
183 * @arg: args to be passed via registers and not physically mapped buffers
185 struct stratix10_svc_client_msg {
187 size_t payload_length;
188 void *payload_output;
189 size_t payload_length_output;
190 enum stratix10_svc_command_code command;
195 * struct stratix10_svc_command_config_type - config type
196 * @flags: flag bit for the type of FPGA configuration
198 struct stratix10_svc_command_config_type {
203 * struct stratix10_svc_cb_data - callback data structure from service layer
204 * @status: the status of sent command
205 * @kaddr1: address of 1st completed data block
206 * @kaddr2: address of 2nd completed data block
207 * @kaddr3: address of 3rd completed data block
209 struct stratix10_svc_cb_data {
217 * struct stratix10_svc_client - service client structure
218 * @dev: the client device
219 * @receive_cb: callback to provide service client the received data
220 * @priv: client private data
222 struct stratix10_svc_client {
224 void (*receive_cb)(struct stratix10_svc_client *client,
225 struct stratix10_svc_cb_data *cb_data);
230 * stratix10_svc_request_channel_byname() - request service channel
231 * @client: identity of the client requesting the channel
232 * @name: supporting client name defined above
234 * Return: a pointer to channel assigned to the client on success,
235 * or ERR_PTR() on error.
237 struct stratix10_svc_chan
238 *stratix10_svc_request_channel_byname(struct stratix10_svc_client *client,
242 * stratix10_svc_free_channel() - free service channel.
243 * @chan: service channel to be freed
245 void stratix10_svc_free_channel(struct stratix10_svc_chan *chan);
248 * stratix10_svc_allocate_memory() - allocate the momory
249 * @chan: service channel assigned to the client
250 * @size: number of bytes client requests
252 * Service layer allocates the requested number of bytes from the memory
253 * pool for the client.
255 * Return: the starting address of allocated memory on success, or
256 * ERR_PTR() on error.
258 void *stratix10_svc_allocate_memory(struct stratix10_svc_chan *chan,
262 * stratix10_svc_free_memory() - free allocated memory
263 * @chan: service channel assigned to the client
264 * @kaddr: starting address of memory to be free back to pool
266 void stratix10_svc_free_memory(struct stratix10_svc_chan *chan, void *kaddr);
269 * stratix10_svc_send() - send a message to the remote
270 * @chan: service channel assigned to the client
271 * @msg: message data to be sent, in the format of
272 * struct stratix10_svc_client_msg
274 * Return: 0 for success, -ENOMEM or -ENOBUFS on error.
276 int stratix10_svc_send(struct stratix10_svc_chan *chan, void *msg);
279 * stratix10_svc_done() - complete service request
280 * @chan: service channel assigned to the client
282 * This function is used by service client to inform service layer that
283 * client's service requests are completed, or there is an error in the
286 void stratix10_svc_done(struct stratix10_svc_chan *chan);