1*91f16700Schasinglulu /* 2*91f16700Schasinglulu * Copyright 2017-2021 NXP 3*91f16700Schasinglulu * 4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause 5*91f16700Schasinglulu * 6*91f16700Schasinglulu */ 7*91f16700Schasinglulu 8*91f16700Schasinglulu #ifndef _JR_DRIVER_H_ 9*91f16700Schasinglulu #define _JR_DRIVER_H_ 10*91f16700Schasinglulu 11*91f16700Schasinglulu #include "jr_driver_config.h" 12*91f16700Schasinglulu 13*91f16700Schasinglulu /* The maximum size of a SEC descriptor, in WORDs (32 bits). */ 14*91f16700Schasinglulu #define MAX_DESC_SIZE_WORDS 64 15*91f16700Schasinglulu 16*91f16700Schasinglulu #define CAAM_TIMEOUT 200000 /* ms */ 17*91f16700Schasinglulu 18*91f16700Schasinglulu /* Return codes for JR user space driver APIs */ 19*91f16700Schasinglulu typedef enum sec_return_code_e { 20*91f16700Schasinglulu SEC_SUCCESS = 0, 21*91f16700Schasinglulu SEC_INVALID_INPUT_PARAM, 22*91f16700Schasinglulu SEC_OUT_OF_MEMORY, 23*91f16700Schasinglulu SEC_DESCRIPTOR_IN_FLIGHT, 24*91f16700Schasinglulu SEC_LAST_DESCRIPTOR_IN_FLIGHT, 25*91f16700Schasinglulu SEC_PROCESSING_ERROR, 26*91f16700Schasinglulu SEC_DESC_PROCESSING_ERROR, 27*91f16700Schasinglulu SEC_JR_IS_FULL, 28*91f16700Schasinglulu SEC_DRIVER_RELEASE_IN_PROGRESS, 29*91f16700Schasinglulu SEC_DRIVER_ALREADY_INITIALIZED, 30*91f16700Schasinglulu SEC_DRIVER_NOT_INITIALIZED, 31*91f16700Schasinglulu SEC_JOB_RING_RESET_IN_PROGRESS, 32*91f16700Schasinglulu SEC_RESET_ENGINE_FAILED, 33*91f16700Schasinglulu SEC_ENABLE_IRQS_FAILED, 34*91f16700Schasinglulu SEC_DISABLE_IRQS_FAILED, 35*91f16700Schasinglulu SEC_RETURN_CODE_MAX_VALUE, 36*91f16700Schasinglulu } sec_return_code_t; 37*91f16700Schasinglulu 38*91f16700Schasinglulu /* STRUCTURES AND OTHER TYPEDEFS */ 39*91f16700Schasinglulu 40*91f16700Schasinglulu /* 41*91f16700Schasinglulu * @brief Function called by JR User Space driver to notify every processed 42*91f16700Schasinglulu * descriptor. 43*91f16700Schasinglulu * 44*91f16700Schasinglulu * Callback provided by the User Application. 45*91f16700Schasinglulu * Callback is invoked by JR User Space driver for each descriptor processed by 46*91f16700Schasinglulu * SEC 47*91f16700Schasinglulu * @param [in] status Status word indicating processing result for 48*91f16700Schasinglulu * this descriptor. 49*91f16700Schasinglulu * @param [in] arg Opaque data passed by User Application 50*91f16700Schasinglulu * It is opaque from JR driver's point of view. 51*91f16700Schasinglulu * @param [in] job_ring The job ring handle on which the processed 52*91f16700Schasinglulu * descriptor word was enqueued 53*91f16700Schasinglulu */ 54*91f16700Schasinglulu typedef void (*user_callback) (uint32_t *desc, uint32_t status, 55*91f16700Schasinglulu void *arg, void *job_ring); 56*91f16700Schasinglulu 57*91f16700Schasinglulu /* 58*91f16700Schasinglulu * Structure encompassing a job descriptor which is to be processed 59*91f16700Schasinglulu * by SEC. User should also initialise this structure with the callback 60*91f16700Schasinglulu * function pointer which will be called by driver after receiving proccessed 61*91f16700Schasinglulu * descriptor from SEC. User data is also passed in this data structure which 62*91f16700Schasinglulu * will be sent as an argument to the user callback function. 63*91f16700Schasinglulu */ 64*91f16700Schasinglulu struct job_descriptor { 65*91f16700Schasinglulu uint32_t desc[MAX_DESC_SIZE_WORDS]; 66*91f16700Schasinglulu void *arg; 67*91f16700Schasinglulu user_callback callback; 68*91f16700Schasinglulu }; 69*91f16700Schasinglulu 70*91f16700Schasinglulu /* 71*91f16700Schasinglulu * @brief Initialize the JR User Space driver. 72*91f16700Schasinglulu * This function will handle initialization of sec library 73*91f16700Schasinglulu * along with registering platform specific callbacks, 74*91f16700Schasinglulu * as well as local data initialization. 75*91f16700Schasinglulu * Call once during application startup. 76*91f16700Schasinglulu * @note Global SEC initialization is done in SEC kernel driver. 77*91f16700Schasinglulu * @note The hardware IDs of the initialized Job Rings are opaque to the UA. 78*91f16700Schasinglulu * The exact Job Rings used by this library are decided between SEC user 79*91f16700Schasinglulu * space driver and SEC kernel driver. A static partitioning of Job Rings is 80*91f16700Schasinglulu * assumed, configured in DTS(device tree specification) file. 81*91f16700Schasinglulu * @param [in] platform_cb Registering the platform specific 82*91f16700Schasinglulu * callbacks with driver 83*91f16700Schasinglulu * @retval ::0 for successful execution 84*91f16700Schasinglulu * @retval ::-1 failure 85*91f16700Schasinglulu */ 86*91f16700Schasinglulu int sec_jr_lib_init(void); 87*91f16700Schasinglulu 88*91f16700Schasinglulu /* 89*91f16700Schasinglulu * @brief Initialize the software and hardware resources tied to a job ring. 90*91f16700Schasinglulu * @param [in] jr_mode; Model to be used by SEC Driver to receive 91*91f16700Schasinglulu * notifications from SEC. Can be either 92*91f16700Schasinglulu * SEC_NOTIFICATION_TYPE_IRQ or 93*91f16700Schasinglulu * SEC_NOTIFICATION_TYPE_POLL 94*91f16700Schasinglulu * @param [in] irq_coalescing_timer This value determines the maximum 95*91f16700Schasinglulu * amount of time after processing a 96*91f16700Schasinglulu * descriptor before raising an interrupt. 97*91f16700Schasinglulu * @param [in] irq_coalescing_count This value determines how many 98*91f16700Schasinglulu * descriptors are completed before 99*91f16700Schasinglulu * raising an interrupt. 100*91f16700Schasinglulu * @param [in] reg_base_addr The job ring base address register 101*91f16700Schasinglulu * @param [in] irq_id The job ring interrupt identification number. 102*91f16700Schasinglulu * @retval job_ring_handle for successful job ring configuration 103*91f16700Schasinglulu * @retval NULL on error 104*91f16700Schasinglulu */ 105*91f16700Schasinglulu void *init_job_ring(uint8_t jr_mode, 106*91f16700Schasinglulu uint16_t irq_coalescing_timer, 107*91f16700Schasinglulu uint8_t irq_coalescing_count, 108*91f16700Schasinglulu void *reg_base_addr, uint32_t irq_id); 109*91f16700Schasinglulu 110*91f16700Schasinglulu /* 111*91f16700Schasinglulu * @brief Release the resources used by the JR User Space driver. 112*91f16700Schasinglulu * Reset and release SEC's job rings indicated by the User Application at 113*91f16700Schasinglulu * init_job_ring() and free any memory allocated internally. 114*91f16700Schasinglulu * Call once during application tear down. 115*91f16700Schasinglulu * @note In case there are any descriptors in-flight (descriptors received by 116*91f16700Schasinglulu * JR driver for processing and for which no response was yet provided to UA), 117*91f16700Schasinglulu * the descriptors are discarded without any notifications to User Application. 118*91f16700Schasinglulu * @retval ::0 is returned for a successful execution 119*91f16700Schasinglulu * @retval ::-1 is returned if JR driver release is in progress 120*91f16700Schasinglulu */ 121*91f16700Schasinglulu int sec_release(void); 122*91f16700Schasinglulu 123*91f16700Schasinglulu /* 124*91f16700Schasinglulu * @brief Submit a descriptor for SEC processing. 125*91f16700Schasinglulu * This function creates a "job" which is meant to instruct SEC HW 126*91f16700Schasinglulu * to perform the processing on the input buffer. The "job" is enqueued 127*91f16700Schasinglulu * in the Job Ring associated. The function will return after the "job" 128*91f16700Schasinglulu * enqueue is finished. The function will not wait for SEC to 129*91f16700Schasinglulu * start or/and finish the "job" processing. 130*91f16700Schasinglulu * After the processing is finished the SEC HW writes the processing result 131*91f16700Schasinglulu * to the provided output buffer. 132*91f16700Schasinglulu * The Caller must poll JR driver using jr_dequeue() 133*91f16700Schasinglulu * to receive notifications of the processing completion 134*91f16700Schasinglulu * status. The notifications are received by caller by means of callback 135*91f16700Schasinglulu * (see ::user_callback). 136*91f16700Schasinglulu * @param [in] job_ring_handle The handle of the job ring on which 137*91f16700Schasinglulu * descriptor is to be enqueued 138*91f16700Schasinglulu * @param [in] job_descriptor The job descriptor structure of type 139*91f16700Schasinglulu * struct job_descriptor. This structure 140*91f16700Schasinglulu * should be filled with job descriptor along 141*91f16700Schasinglulu * with callback function to be called after 142*91f16700Schasinglulu * processing of descriptor and some 143*91f16700Schasinglulu * opaque data passed to be passed to the 144*91f16700Schasinglulu * callback function 145*91f16700Schasinglulu * 146*91f16700Schasinglulu * @retval ::0 is returned for successful execution 147*91f16700Schasinglulu * @retval ::-1 is returned if there is some enqueue failure 148*91f16700Schasinglulu */ 149*91f16700Schasinglulu int enq_jr_desc(void *job_ring_handle, struct job_descriptor *jobdescr); 150*91f16700Schasinglulu 151*91f16700Schasinglulu /* 152*91f16700Schasinglulu * @brief Polls for available descriptors processed by SEC on a specific 153*91f16700Schasinglulu * Job Ring 154*91f16700Schasinglulu * This function polls the SEC Job Rings and delivers processed descriptors 155*91f16700Schasinglulu * Each processed descriptor has a user_callback registered. 156*91f16700Schasinglulu * This user_callback is invoked for each processed descriptor. 157*91f16700Schasinglulu * The polling is stopped when "limit" descriptors are notified or when 158*91f16700Schasinglulu * there are no more descriptors to notify. 159*91f16700Schasinglulu * @note The dequeue_jr() API cannot be called from within a user_callback 160*91f16700Schasinglulu * function 161*91f16700Schasinglulu * @param [in] job_ring_handle The Job Ring handle. 162*91f16700Schasinglulu * @param [in] limit This value represents the maximum number 163*91f16700Schasinglulu * of processed descriptors that can be 164*91f16700Schasinglulu * notified API call on this Job Ring. 165*91f16700Schasinglulu * Note that fewer descriptors may be notified 166*91f16700Schasinglulu * if enough processed descriptors are not 167*91f16700Schasinglulu * available. 168*91f16700Schasinglulu * If limit has a negative value, then all 169*91f16700Schasinglulu * ready descriptors will be notified. 170*91f16700Schasinglulu * 171*91f16700Schasinglulu * @retval :: >=0 is returned where retval is the total 172*91f16700Schasinglulu * Number of descriptors notified 173*91f16700Schasinglulu * during this function call. 174*91f16700Schasinglulu * @retval :: -1 is returned in case of some error 175*91f16700Schasinglulu */ 176*91f16700Schasinglulu int dequeue_jr(void *job_ring_handle, int32_t limit); 177*91f16700Schasinglulu 178*91f16700Schasinglulu #endif /* _JR_DRIVER_H_ */ 179