Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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
18/**
19 * Status of the sent command, in bit number
20 *
21 * SVC_STATUS_OK:
22 * Secure firmware accepts the request issued by one of service clients.
23 *
24 * SVC_STATUS_BUFFER_SUBMITTED:
25 * Service client successfully submits data buffer to secure firmware.
26 *
27 * SVC_STATUS_BUFFER_DONE:
28 * Secure firmware completes data process, ready to accept the
29 * next WRITE transaction.
30 *
31 * SVC_STATUS_COMPLETED:
32 * Secure firmware completes service request successfully. In case of
33 * FPGA configuration, FPGA should be in user mode.
34 *
35 * SVC_COMMAND_STATUS_BUSY:
36 * Service request is still in process.
37 *
38 * SVC_COMMAND_STATUS_ERROR:
39 * Error encountered during the process of the service request.
40 *
41 * SVC_STATUS_NO_SUPPORT:
42 * Secure firmware doesn't support requested features such as RSU retry
43 * or RSU notify.
44 */
45#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
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_OK
80 *
81 * @COMMAND_RECONFIG_DATA_SUBMIT: submit buffer(s) of bit-stream data for the
82 * FPGA configuration, return status is SVC_STATUS_SUBMITTED or SVC_STATUS_ERROR
83 *
84 * @COMMAND_RECONFIG_DATA_CLAIM: check the status of the configuration, return
85 * status is SVC_STATUS_COMPLETED, or SVC_STATUS_BUSY, or SVC_STATUS_ERROR
86 *
87 * @COMMAND_RECONFIG_STATUS: check the status of the configuration, return
88 * status is SVC_STATUS_COMPLETED, or SVC_STATUS_BUSY, or SVC_STATUS_ERROR
89 *
90 * @COMMAND_RSU_STATUS: request remote system update boot log, return status
91 * is log data or SVC_STATUS_RSU_ERROR
92 *
93 * @COMMAND_RSU_UPDATE: set the offset of the bitstream to boot after reboot,
94 * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
95 *
96 * @COMMAND_RSU_NOTIFY: report the status of hard processor system
97 * software to firmware, return status is SVC_STATUS_OK or
98 * SVC_STATUS_ERROR
99 *
100 * @COMMAND_RSU_RETRY: query firmware for the current image's retry counter,
101 * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
102 */
103enum stratix10_svc_command_code {
104 COMMAND_NOOP = 0,
105 COMMAND_RECONFIG,
106 COMMAND_RECONFIG_DATA_SUBMIT,
107 COMMAND_RECONFIG_DATA_CLAIM,
108 COMMAND_RECONFIG_STATUS,
109 COMMAND_RSU_STATUS,
110 COMMAND_RSU_UPDATE,
111 COMMAND_RSU_NOTIFY,
112 COMMAND_RSU_RETRY,
113};
114
115/**
116 * struct stratix10_svc_client_msg - message sent by client to service
117 * @payload: starting address of data need be processed
118 * @payload_length: data size in bytes
119 * @command: service command
120 * @arg: args to be passed via registers and not physically mapped buffers
121 */
122struct stratix10_svc_client_msg {
123 void *payload;
124 size_t payload_length;
125 enum stratix10_svc_command_code command;
126 u64 arg[3];
127};
128
129/**
130 * struct stratix10_svc_command_config_type - config type
131 * @flags: flag bit for the type of FPGA configuration
132 */
133struct stratix10_svc_command_config_type {
134 u32 flags;
135};
136
137/**
138 * struct stratix10_svc_cb_data - callback data structure from service layer
139 * @status: the status of sent command
140 * @kaddr1: address of 1st completed data block
141 * @kaddr2: address of 2nd completed data block
142 * @kaddr3: address of 3rd completed data block
143 */
144struct stratix10_svc_cb_data {
145 u32 status;
146 void *kaddr1;
147 void *kaddr2;
148 void *kaddr3;
149};
150
151/**
152 * struct stratix10_svc_client - service client structure
153 * @dev: the client device
154 * @receive_cb: callback to provide service client the received data
155 * @priv: client private data
156 */
157struct stratix10_svc_client {
158 struct device *dev;
159 void (*receive_cb)(struct stratix10_svc_client *client,
160 struct stratix10_svc_cb_data *cb_data);
161 void *priv;
162};
163
164/**
165 * stratix10_svc_request_channel_byname() - request service channel
166 * @client: identity of the client requesting the channel
167 * @name: supporting client name defined above
168 *
169 * Return: a pointer to channel assigned to the client on success,
170 * or ERR_PTR() on error.
171 */
172struct stratix10_svc_chan
173*stratix10_svc_request_channel_byname(struct stratix10_svc_client *client,
174 const char *name);
175
176/**
177 * stratix10_svc_free_channel() - free service channel.
178 * @chan: service channel to be freed
179 */
180void stratix10_svc_free_channel(struct stratix10_svc_chan *chan);
181
182/**
183 * stratix10_svc_allocate_memory() - allocate the momory
184 * @chan: service channel assigned to the client
185 * @size: number of bytes client requests
186 *
187 * Service layer allocates the requested number of bytes from the memory
188 * pool for the client.
189 *
190 * Return: the starting address of allocated memory on success, or
191 * ERR_PTR() on error.
192 */
193void *stratix10_svc_allocate_memory(struct stratix10_svc_chan *chan,
194 size_t size);
195
196/**
197 * stratix10_svc_free_memory() - free allocated memory
198 * @chan: service channel assigned to the client
199 * @kaddr: starting address of memory to be free back to pool
200 */
201void stratix10_svc_free_memory(struct stratix10_svc_chan *chan, void *kaddr);
202
203/**
204 * stratix10_svc_send() - send a message to the remote
205 * @chan: service channel assigned to the client
206 * @msg: message data to be sent, in the format of
207 * struct stratix10_svc_client_msg
208 *
209 * Return: 0 for success, -ENOMEM or -ENOBUFS on error.
210 */
211int stratix10_svc_send(struct stratix10_svc_chan *chan, void *msg);
212
213/**
214 * intel_svc_done() - complete service request
215 * @chan: service channel assigned to the client
216 *
217 * This function is used by service client to inform service layer that
218 * client's service requests are completed, or there is an error in the
219 * request process.
220 */
221void stratix10_svc_done(struct stratix10_svc_chan *chan);
222#endif
223