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