blob: f843c6a10cf362742c25eaaf00168f9fde1c55f6 [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 *
Olivier Deprez157378f2022-04-04 15:47:50 +020021 * SVC_STATUS_OK:
22 * Secure firmware accepts the request issued by one of service clients.
David Brazdil0f672f62019-12-10 10:32:29 +000023 *
Olivier Deprez157378f2022-04-04 15:47:50 +020024 * SVC_STATUS_BUFFER_SUBMITTED:
25 * Service client successfully submits data buffer to secure firmware.
David Brazdil0f672f62019-12-10 10:32:29 +000026 *
Olivier Deprez157378f2022-04-04 15:47:50 +020027 * SVC_STATUS_BUFFER_DONE:
David Brazdil0f672f62019-12-10 10:32:29 +000028 * Secure firmware completes data process, ready to accept the
29 * next WRITE transaction.
30 *
Olivier Deprez157378f2022-04-04 15:47:50 +020031 * SVC_STATUS_COMPLETED:
32 * Secure firmware completes service request successfully. In case of
33 * FPGA configuration, FPGA should be in user mode.
David Brazdil0f672f62019-12-10 10:32:29 +000034 *
Olivier Deprez157378f2022-04-04 15:47:50 +020035 * SVC_COMMAND_STATUS_BUSY:
36 * Service request is still in process.
David Brazdil0f672f62019-12-10 10:32:29 +000037 *
Olivier Deprez157378f2022-04-04 15:47:50 +020038 * SVC_COMMAND_STATUS_ERROR:
39 * Error encountered during the process of the service request.
David Brazdil0f672f62019-12-10 10:32:29 +000040 *
Olivier Deprez157378f2022-04-04 15:47:50 +020041 * SVC_STATUS_NO_SUPPORT:
42 * Secure firmware doesn't support requested features such as RSU retry
43 * or RSU notify.
David Brazdil0f672f62019-12-10 10:32:29 +000044 */
Olivier Deprez157378f2022-04-04 15:47:50 +020045#define SVC_STATUS_OK 0
46#define SVC_STATUS_BUFFER_SUBMITTED 1
47#define SVC_STATUS_BUFFER_DONE 2
48#define SVC_STATUS_COMPLETED 3
49#define SVC_STATUS_BUSY 4
50#define SVC_STATUS_ERROR 5
51#define SVC_STATUS_NO_SUPPORT 6
52
David Brazdil0f672f62019-12-10 10:32:29 +000053/**
54 * Flag bit for COMMAND_RECONFIG
55 *
56 * COMMAND_RECONFIG_FLAG_PARTIAL:
Olivier Deprez157378f2022-04-04 15:47:50 +020057 * Set to FPGA configuration type (full or partial).
David Brazdil0f672f62019-12-10 10:32:29 +000058 */
59#define COMMAND_RECONFIG_FLAG_PARTIAL 0
60
61/**
62 * Timeout settings for service clients:
63 * timeout value used in Stratix10 FPGA manager driver.
64 * timeout value used in RSU driver
65 */
Olivier Deprez157378f2022-04-04 15:47:50 +020066#define SVC_RECONFIG_REQUEST_TIMEOUT_MS 300
67#define SVC_RECONFIG_BUFFER_TIMEOUT_MS 720
David Brazdil0f672f62019-12-10 10:32:29 +000068#define SVC_RSU_REQUEST_TIMEOUT_MS 300
69
70struct stratix10_svc_chan;
71
72/**
73 * enum stratix10_svc_command_code - supported service commands
74 *
75 * @COMMAND_NOOP: do 'dummy' request for integration/debug/trouble-shooting
76 *
77 * @COMMAND_RECONFIG: ask for FPGA configuration preparation, return status
Olivier Deprez157378f2022-04-04 15:47:50 +020078 * is SVC_STATUS_OK
David Brazdil0f672f62019-12-10 10:32:29 +000079 *
80 * @COMMAND_RECONFIG_DATA_SUBMIT: submit buffer(s) of bit-stream data for the
Olivier Deprez157378f2022-04-04 15:47:50 +020081 * FPGA configuration, return status is SVC_STATUS_SUBMITTED or SVC_STATUS_ERROR
David Brazdil0f672f62019-12-10 10:32:29 +000082 *
83 * @COMMAND_RECONFIG_DATA_CLAIM: check the status of the configuration, return
Olivier Deprez157378f2022-04-04 15:47:50 +020084 * status is SVC_STATUS_COMPLETED, or SVC_STATUS_BUSY, or SVC_STATUS_ERROR
David Brazdil0f672f62019-12-10 10:32:29 +000085 *
86 * @COMMAND_RECONFIG_STATUS: check the status of the configuration, return
Olivier Deprez157378f2022-04-04 15:47:50 +020087 * status is SVC_STATUS_COMPLETED, or SVC_STATUS_BUSY, or SVC_STATUS_ERROR
David Brazdil0f672f62019-12-10 10:32:29 +000088 *
89 * @COMMAND_RSU_STATUS: request remote system update boot log, return status
90 * is log data or SVC_STATUS_RSU_ERROR
91 *
92 * @COMMAND_RSU_UPDATE: set the offset of the bitstream to boot after reboot,
Olivier Deprez157378f2022-04-04 15:47:50 +020093 * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
David Brazdil0f672f62019-12-10 10:32:29 +000094 *
95 * @COMMAND_RSU_NOTIFY: report the status of hard processor system
Olivier Deprez157378f2022-04-04 15:47:50 +020096 * software to firmware, return status is SVC_STATUS_OK or
97 * SVC_STATUS_ERROR
David Brazdil0f672f62019-12-10 10:32:29 +000098 *
99 * @COMMAND_RSU_RETRY: query firmware for the current image's retry counter,
Olivier Deprez157378f2022-04-04 15:47:50 +0200100 * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
101 *
102 * @COMMAND_RSU_MAX_RETRY: query firmware for the max retry value,
103 * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
104 *
105 * @COMMAND_RSU_DCMF_VERSION: query firmware for the DCMF version, return status
106 * is SVC_STATUS_OK or SVC_STATUS_ERROR
David Brazdil0f672f62019-12-10 10:32:29 +0000107 */
108enum stratix10_svc_command_code {
109 COMMAND_NOOP = 0,
110 COMMAND_RECONFIG,
111 COMMAND_RECONFIG_DATA_SUBMIT,
112 COMMAND_RECONFIG_DATA_CLAIM,
113 COMMAND_RECONFIG_STATUS,
114 COMMAND_RSU_STATUS,
115 COMMAND_RSU_UPDATE,
116 COMMAND_RSU_NOTIFY,
117 COMMAND_RSU_RETRY,
Olivier Deprez157378f2022-04-04 15:47:50 +0200118 COMMAND_RSU_MAX_RETRY,
119 COMMAND_RSU_DCMF_VERSION,
David Brazdil0f672f62019-12-10 10:32:29 +0000120};
121
122/**
123 * struct stratix10_svc_client_msg - message sent by client to service
124 * @payload: starting address of data need be processed
125 * @payload_length: data size in bytes
126 * @command: service command
127 * @arg: args to be passed via registers and not physically mapped buffers
128 */
129struct stratix10_svc_client_msg {
130 void *payload;
131 size_t payload_length;
132 enum stratix10_svc_command_code command;
133 u64 arg[3];
134};
135
136/**
137 * struct stratix10_svc_command_config_type - config type
138 * @flags: flag bit for the type of FPGA configuration
139 */
140struct stratix10_svc_command_config_type {
141 u32 flags;
142};
143
144/**
145 * struct stratix10_svc_cb_data - callback data structure from service layer
146 * @status: the status of sent command
147 * @kaddr1: address of 1st completed data block
148 * @kaddr2: address of 2nd completed data block
149 * @kaddr3: address of 3rd completed data block
150 */
151struct stratix10_svc_cb_data {
152 u32 status;
153 void *kaddr1;
154 void *kaddr2;
155 void *kaddr3;
156};
157
158/**
159 * struct stratix10_svc_client - service client structure
160 * @dev: the client device
161 * @receive_cb: callback to provide service client the received data
162 * @priv: client private data
163 */
164struct stratix10_svc_client {
165 struct device *dev;
166 void (*receive_cb)(struct stratix10_svc_client *client,
167 struct stratix10_svc_cb_data *cb_data);
168 void *priv;
169};
170
171/**
172 * stratix10_svc_request_channel_byname() - request service channel
173 * @client: identity of the client requesting the channel
174 * @name: supporting client name defined above
175 *
176 * Return: a pointer to channel assigned to the client on success,
177 * or ERR_PTR() on error.
178 */
179struct stratix10_svc_chan
180*stratix10_svc_request_channel_byname(struct stratix10_svc_client *client,
181 const char *name);
182
183/**
184 * stratix10_svc_free_channel() - free service channel.
185 * @chan: service channel to be freed
186 */
187void stratix10_svc_free_channel(struct stratix10_svc_chan *chan);
188
189/**
190 * stratix10_svc_allocate_memory() - allocate the momory
191 * @chan: service channel assigned to the client
192 * @size: number of bytes client requests
193 *
194 * Service layer allocates the requested number of bytes from the memory
195 * pool for the client.
196 *
197 * Return: the starting address of allocated memory on success, or
198 * ERR_PTR() on error.
199 */
200void *stratix10_svc_allocate_memory(struct stratix10_svc_chan *chan,
201 size_t size);
202
203/**
204 * stratix10_svc_free_memory() - free allocated memory
205 * @chan: service channel assigned to the client
206 * @kaddr: starting address of memory to be free back to pool
207 */
208void stratix10_svc_free_memory(struct stratix10_svc_chan *chan, void *kaddr);
209
210/**
211 * stratix10_svc_send() - send a message to the remote
212 * @chan: service channel assigned to the client
213 * @msg: message data to be sent, in the format of
214 * struct stratix10_svc_client_msg
215 *
216 * Return: 0 for success, -ENOMEM or -ENOBUFS on error.
217 */
218int stratix10_svc_send(struct stratix10_svc_chan *chan, void *msg);
219
220/**
221 * intel_svc_done() - complete service request
222 * @chan: service channel assigned to the client
223 *
224 * This function is used by service client to inform service layer that
225 * client's service requests are completed, or there is an error in the
226 * request process.
227 */
228void stratix10_svc_done(struct stratix10_svc_chan *chan);
229#endif
230