blob: b6c4302a39e00d3d6ec280cfff9738dfdb1a5091 [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001/* 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
18/**
19 * Status of the sent command, in bit number
20 *
21 * SVC_COMMAND_STATUS_RECONFIG_REQUEST_OK:
22 * Secure firmware accepts the request of FPGA reconfiguration.
23 *
24 * SVC_STATUS_RECONFIG_BUFFER_SUBMITTED:
25 * Service client successfully submits FPGA configuration
26 * data buffer to secure firmware.
27 *
28 * SVC_COMMAND_STATUS_RECONFIG_BUFFER_DONE:
29 * Secure firmware completes data process, ready to accept the
30 * next WRITE transaction.
31 *
32 * SVC_COMMAND_STATUS_RECONFIG_COMPLETED:
33 * Secure firmware completes FPGA configuration successfully, FPGA should
34 * be in user mode.
35 *
36 * SVC_COMMAND_STATUS_RECONFIG_BUSY:
37 * FPGA configuration is still in process.
38 *
39 * SVC_COMMAND_STATUS_RECONFIG_ERROR:
40 * Error encountered during FPGA configuration.
41 *
42 * SVC_STATUS_RSU_OK:
43 * Secure firmware accepts the request of remote status update (RSU).
44 */
45#define SVC_STATUS_RECONFIG_REQUEST_OK 0
46#define SVC_STATUS_RECONFIG_BUFFER_SUBMITTED 1
47#define SVC_STATUS_RECONFIG_BUFFER_DONE 2
48#define SVC_STATUS_RECONFIG_COMPLETED 3
49#define SVC_STATUS_RECONFIG_BUSY 4
50#define SVC_STATUS_RECONFIG_ERROR 5
51#define SVC_STATUS_RSU_OK 6
52#define SVC_STATUS_RSU_ERROR 7
53/**
54 * Flag bit for COMMAND_RECONFIG
55 *
56 * COMMAND_RECONFIG_FLAG_PARTIAL:
57 * Set to FPGA configuration type (full or partial), the default
58 * is full reconfig.
59 */
60#define COMMAND_RECONFIG_FLAG_PARTIAL 0
61
62/**
63 * Timeout settings for service clients:
64 * timeout value used in Stratix10 FPGA manager driver.
65 * timeout value used in RSU driver
66 */
67#define SVC_RECONFIG_REQUEST_TIMEOUT_MS 100
68#define SVC_RECONFIG_BUFFER_TIMEOUT_MS 240
69#define SVC_RSU_REQUEST_TIMEOUT_MS 300
70
71struct stratix10_svc_chan;
72
73/**
74 * enum stratix10_svc_command_code - supported service commands
75 *
76 * @COMMAND_NOOP: do 'dummy' request for integration/debug/trouble-shooting
77 *
78 * @COMMAND_RECONFIG: ask for FPGA configuration preparation, return status
79 * is SVC_STATUS_RECONFIG_REQUEST_OK
80 *
81 * @COMMAND_RECONFIG_DATA_SUBMIT: submit buffer(s) of bit-stream data for the
82 * FPGA configuration, return status is SVC_STATUS_RECONFIG_BUFFER_SUBMITTED,
83 * or SVC_STATUS_RECONFIG_ERROR
84 *
85 * @COMMAND_RECONFIG_DATA_CLAIM: check the status of the configuration, return
86 * status is SVC_STATUS_RECONFIG_COMPLETED, or SVC_STATUS_RECONFIG_BUSY, or
87 * SVC_STATUS_RECONFIG_ERROR
88 *
89 * @COMMAND_RECONFIG_STATUS: check the status of the configuration, return
90 * status is SVC_STATUS_RECONFIG_COMPLETED, or SVC_STATUS_RECONFIG_BUSY, or
91 * SVC_STATUS_RECONFIG_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_RSU_OK or SVC_STATUS_RSU_ERROR
98 *
99 * @COMMAND_RSU_NOTIFY: report the status of hard processor system
100 * software to firmware, return status is SVC_STATUS_RSU_OK or
101 * SVC_STATUS_RSU_ERROR
102 *
103 * @COMMAND_RSU_RETRY: query firmware for the current image's retry counter,
104 * return status is SVC_STATUS_RSU_OK or SVC_STATUS_RSU_ERROR
105 */
106enum stratix10_svc_command_code {
107 COMMAND_NOOP = 0,
108 COMMAND_RECONFIG,
109 COMMAND_RECONFIG_DATA_SUBMIT,
110 COMMAND_RECONFIG_DATA_CLAIM,
111 COMMAND_RECONFIG_STATUS,
112 COMMAND_RSU_STATUS,
113 COMMAND_RSU_UPDATE,
114 COMMAND_RSU_NOTIFY,
115 COMMAND_RSU_RETRY,
116};
117
118/**
119 * struct stratix10_svc_client_msg - message sent by client to service
120 * @payload: starting address of data need be processed
121 * @payload_length: data size in bytes
122 * @command: service command
123 * @arg: args to be passed via registers and not physically mapped buffers
124 */
125struct stratix10_svc_client_msg {
126 void *payload;
127 size_t payload_length;
128 enum stratix10_svc_command_code command;
129 u64 arg[3];
130};
131
132/**
133 * struct stratix10_svc_command_config_type - config type
134 * @flags: flag bit for the type of FPGA configuration
135 */
136struct stratix10_svc_command_config_type {
137 u32 flags;
138};
139
140/**
141 * struct stratix10_svc_cb_data - callback data structure from service layer
142 * @status: the status of sent command
143 * @kaddr1: address of 1st completed data block
144 * @kaddr2: address of 2nd completed data block
145 * @kaddr3: address of 3rd completed data block
146 */
147struct stratix10_svc_cb_data {
148 u32 status;
149 void *kaddr1;
150 void *kaddr2;
151 void *kaddr3;
152};
153
154/**
155 * struct stratix10_svc_client - service client structure
156 * @dev: the client device
157 * @receive_cb: callback to provide service client the received data
158 * @priv: client private data
159 */
160struct stratix10_svc_client {
161 struct device *dev;
162 void (*receive_cb)(struct stratix10_svc_client *client,
163 struct stratix10_svc_cb_data *cb_data);
164 void *priv;
165};
166
167/**
168 * stratix10_svc_request_channel_byname() - request service channel
169 * @client: identity of the client requesting the channel
170 * @name: supporting client name defined above
171 *
172 * Return: a pointer to channel assigned to the client on success,
173 * or ERR_PTR() on error.
174 */
175struct stratix10_svc_chan
176*stratix10_svc_request_channel_byname(struct stratix10_svc_client *client,
177 const char *name);
178
179/**
180 * stratix10_svc_free_channel() - free service channel.
181 * @chan: service channel to be freed
182 */
183void stratix10_svc_free_channel(struct stratix10_svc_chan *chan);
184
185/**
186 * stratix10_svc_allocate_memory() - allocate the momory
187 * @chan: service channel assigned to the client
188 * @size: number of bytes client requests
189 *
190 * Service layer allocates the requested number of bytes from the memory
191 * pool for the client.
192 *
193 * Return: the starting address of allocated memory on success, or
194 * ERR_PTR() on error.
195 */
196void *stratix10_svc_allocate_memory(struct stratix10_svc_chan *chan,
197 size_t size);
198
199/**
200 * stratix10_svc_free_memory() - free allocated memory
201 * @chan: service channel assigned to the client
202 * @kaddr: starting address of memory to be free back to pool
203 */
204void stratix10_svc_free_memory(struct stratix10_svc_chan *chan, void *kaddr);
205
206/**
207 * stratix10_svc_send() - send a message to the remote
208 * @chan: service channel assigned to the client
209 * @msg: message data to be sent, in the format of
210 * struct stratix10_svc_client_msg
211 *
212 * Return: 0 for success, -ENOMEM or -ENOBUFS on error.
213 */
214int stratix10_svc_send(struct stratix10_svc_chan *chan, void *msg);
215
216/**
217 * intel_svc_done() - complete service request
218 * @chan: service channel assigned to the client
219 *
220 * This function is used by service client to inform service layer that
221 * client's service requests are completed, or there is an error in the
222 * request process.
223 */
224void stratix10_svc_done(struct stratix10_svc_chan *chan);
225#endif
226