Merge tag '6.6-rc-smb3-client-fixes-part2' of git://git.samba.org/sfrench/cifs-2.6
[sfrench/cifs-2.6.git] / include / linux / firmware / intel / stratix10-svc-client.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2017-2018, Intel Corporation
4  */
5
6 #ifndef __STRATIX10_SVC_CLIENT_H
7 #define __STRATIX10_SVC_CLIENT_H
8
9 /*
10  * Service layer driver supports client names
11  *
12  * fpga: for FPGA configuration
13  * rsu: for remote status update
14  */
15 #define SVC_CLIENT_FPGA                 "fpga"
16 #define SVC_CLIENT_RSU                  "rsu"
17 #define SVC_CLIENT_FCS                  "fcs"
18
19 /*
20  * Status of the sent command, in bit number
21  *
22  * SVC_STATUS_OK:
23  * Secure firmware accepts the request issued by one of service clients.
24  *
25  * SVC_STATUS_BUFFER_SUBMITTED:
26  * Service client successfully submits data buffer to secure firmware.
27  *
28  * SVC_STATUS_BUFFER_DONE:
29  * Secure firmware completes data process, ready to accept the
30  * next WRITE transaction.
31  *
32  * SVC_STATUS_COMPLETED:
33  * Secure firmware completes service request successfully. In case of
34  * FPGA configuration, FPGA should be in user mode.
35  *
36  * SVC_COMMAND_STATUS_BUSY:
37  * Service request is still in process.
38  *
39  * SVC_COMMAND_STATUS_ERROR:
40  * Error encountered during the process of the service request.
41  *
42  * SVC_STATUS_NO_SUPPORT:
43  * Secure firmware doesn't support requested features such as RSU retry
44  * or RSU notify.
45  */
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
54
55 /*
56  * Flag bit for COMMAND_RECONFIG
57  *
58  * COMMAND_RECONFIG_FLAG_PARTIAL:
59  * Set to FPGA configuration type (full or partial).
60  */
61 #define COMMAND_RECONFIG_FLAG_PARTIAL   0
62
63 /*
64  * Timeout settings for service clients:
65  * timeout value used in Stratix10 FPGA manager driver.
66  * timeout value used in RSU driver
67  */
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
73
74 struct stratix10_svc_chan;
75
76 /**
77  * enum stratix10_svc_command_code - supported service commands
78  *
79  * @COMMAND_NOOP: do 'dummy' request for integration/debug/trouble-shooting
80  *
81  * @COMMAND_RECONFIG: ask for FPGA configuration preparation, return status
82  * is SVC_STATUS_OK
83  *
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
86  *
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
89  *
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
92  *
93  * @COMMAND_RSU_STATUS: request remote system update boot log, return status
94  * is log data or SVC_STATUS_RSU_ERROR
95  *
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
98  *
99  * @COMMAND_RSU_NOTIFY: report the status of hard processor system
100  * software to firmware, return status is SVC_STATUS_OK or
101  * SVC_STATUS_ERROR
102  *
103  * @COMMAND_RSU_RETRY: query firmware for the current image's retry counter,
104  * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
105  *
106  * @COMMAND_RSU_MAX_RETRY: query firmware for the max retry value,
107  * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
108  *
109  * @COMMAND_RSU_DCMF_VERSION: query firmware for the DCMF version, return status
110  * is SVC_STATUS_OK or SVC_STATUS_ERROR
111  *
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
114  *
115  * @COMMAND_FIRMWARE_VERSION: query running firmware version, return status
116  * is SVC_STATUS_OK or SVC_STATUS_ERROR
117  *
118  * @COMMAND_SMC_SVC_VERSION: Non-mailbox SMC SVC API Version,
119  * return status is SVC_STATUS_OK
120  *
121  * @COMMAND_MBOX_SEND_CMD: send generic mailbox command, return status is
122  * SVC_STATUS_OK or SVC_STATUS_ERROR
123  *
124  * @COMMAND_RSU_DCMF_STATUS: query firmware for the DCMF status
125  * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
126  *
127  * @COMMAND_FCS_REQUEST_SERVICE: request validation of image from firmware,
128  * return status is SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM
129  *
130  * @COMMAND_FCS_SEND_CERTIFICATE: send a certificate, return status is
131  * SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM, SVC_STATUS_ERROR
132  *
133  * @COMMAND_FCS_GET_PROVISION_DATA: read the provisioning data, return status is
134  * SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM, SVC_STATUS_ERROR
135  *
136  * @COMMAND_FCS_DATA_ENCRYPTION: encrypt the data, return status is
137  * SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM, SVC_STATUS_ERROR
138  *
139  * @COMMAND_FCS_DATA_DECRYPTION: decrypt the data, return status is
140  * SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM, SVC_STATUS_ERROR
141  *
142  * @COMMAND_FCS_RANDOM_NUMBER_GEN: generate a random number, return status
143  * is SVC_STATUS_OK, SVC_STATUS_ERROR
144  */
145 enum stratix10_svc_command_code {
146         /* for FPGA */
147         COMMAND_NOOP = 0,
148         COMMAND_RECONFIG,
149         COMMAND_RECONFIG_DATA_SUBMIT,
150         COMMAND_RECONFIG_DATA_CLAIM,
151         COMMAND_RECONFIG_STATUS,
152         /* for RSU */
153         COMMAND_RSU_STATUS = 10,
154         COMMAND_RSU_UPDATE,
155         COMMAND_RSU_NOTIFY,
156         COMMAND_RSU_RETRY,
157         COMMAND_RSU_MAX_RETRY,
158         COMMAND_RSU_DCMF_VERSION,
159         COMMAND_RSU_DCMF_STATUS,
160         COMMAND_FIRMWARE_VERSION,
161         /* for FCS */
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,
174 };
175
176 /**
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
184  */
185 struct stratix10_svc_client_msg {
186         void *payload;
187         size_t payload_length;
188         void *payload_output;
189         size_t payload_length_output;
190         enum stratix10_svc_command_code command;
191         u64 arg[3];
192 };
193
194 /**
195  * struct stratix10_svc_command_config_type - config type
196  * @flags: flag bit for the type of FPGA configuration
197  */
198 struct stratix10_svc_command_config_type {
199         u32 flags;
200 };
201
202 /**
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
208  */
209 struct stratix10_svc_cb_data {
210         u32 status;
211         void *kaddr1;
212         void *kaddr2;
213         void *kaddr3;
214 };
215
216 /**
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
221  */
222 struct stratix10_svc_client {
223         struct device *dev;
224         void (*receive_cb)(struct stratix10_svc_client *client,
225                            struct stratix10_svc_cb_data *cb_data);
226         void *priv;
227 };
228
229 /**
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
233  *
234  * Return: a pointer to channel assigned to the client on success,
235  * or ERR_PTR() on error.
236  */
237 struct stratix10_svc_chan
238 *stratix10_svc_request_channel_byname(struct stratix10_svc_client *client,
239         const char *name);
240
241 /**
242  * stratix10_svc_free_channel() - free service channel.
243  * @chan: service channel to be freed
244  */
245 void stratix10_svc_free_channel(struct stratix10_svc_chan *chan);
246
247 /**
248  * stratix10_svc_allocate_memory() - allocate the momory
249  * @chan: service channel assigned to the client
250  * @size: number of bytes client requests
251  *
252  * Service layer allocates the requested number of bytes from the memory
253  * pool for the client.
254  *
255  * Return: the starting address of allocated memory on success, or
256  * ERR_PTR() on error.
257  */
258 void *stratix10_svc_allocate_memory(struct stratix10_svc_chan *chan,
259                                     size_t size);
260
261 /**
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
265  */
266 void stratix10_svc_free_memory(struct stratix10_svc_chan *chan, void *kaddr);
267
268 /**
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
273  *
274  * Return: 0 for success, -ENOMEM or -ENOBUFS on error.
275  */
276 int stratix10_svc_send(struct stratix10_svc_chan *chan, void *msg);
277
278 /**
279  * stratix10_svc_done() - complete service request
280  * @chan: service channel assigned to the client
281  *
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
284  * request process.
285  */
286 void stratix10_svc_done(struct stratix10_svc_chan *chan);
287 #endif
288