1050a99a6SPankaj Gupta /* 2050a99a6SPankaj Gupta * Copyright 2017-2021 NXP 3050a99a6SPankaj Gupta * 4050a99a6SPankaj Gupta * SPDX-License-Identifier: BSD-3-Clause 5050a99a6SPankaj Gupta * 6050a99a6SPankaj Gupta */ 7050a99a6SPankaj Gupta 8050a99a6SPankaj Gupta #ifndef _JR_DRIVER_H_ 9050a99a6SPankaj Gupta #define _JR_DRIVER_H_ 10050a99a6SPankaj Gupta 11050a99a6SPankaj Gupta #include "jr_driver_config.h" 12050a99a6SPankaj Gupta 13050a99a6SPankaj Gupta /* The maximum size of a SEC descriptor, in WORDs (32 bits). */ 14050a99a6SPankaj Gupta #define MAX_DESC_SIZE_WORDS 64 15050a99a6SPankaj Gupta 16050a99a6SPankaj Gupta #define CAAM_TIMEOUT 200000 /* ms */ 17050a99a6SPankaj Gupta 18050a99a6SPankaj Gupta /* Return codes for JR user space driver APIs */ 19050a99a6SPankaj Gupta typedef enum sec_return_code_e { 20050a99a6SPankaj Gupta SEC_SUCCESS = 0, 21050a99a6SPankaj Gupta SEC_INVALID_INPUT_PARAM, 22050a99a6SPankaj Gupta SEC_OUT_OF_MEMORY, 23050a99a6SPankaj Gupta SEC_DESCRIPTOR_IN_FLIGHT, 24050a99a6SPankaj Gupta SEC_LAST_DESCRIPTOR_IN_FLIGHT, 25050a99a6SPankaj Gupta SEC_PROCESSING_ERROR, 26050a99a6SPankaj Gupta SEC_DESC_PROCESSING_ERROR, 27050a99a6SPankaj Gupta SEC_JR_IS_FULL, 28050a99a6SPankaj Gupta SEC_DRIVER_RELEASE_IN_PROGRESS, 29050a99a6SPankaj Gupta SEC_DRIVER_ALREADY_INITIALIZED, 30050a99a6SPankaj Gupta SEC_DRIVER_NOT_INITIALIZED, 31050a99a6SPankaj Gupta SEC_JOB_RING_RESET_IN_PROGRESS, 32050a99a6SPankaj Gupta SEC_RESET_ENGINE_FAILED, 33050a99a6SPankaj Gupta SEC_ENABLE_IRQS_FAILED, 34050a99a6SPankaj Gupta SEC_DISABLE_IRQS_FAILED, 35050a99a6SPankaj Gupta SEC_RETURN_CODE_MAX_VALUE, 36050a99a6SPankaj Gupta } sec_return_code_t; 37050a99a6SPankaj Gupta 38050a99a6SPankaj Gupta /* STRUCTURES AND OTHER TYPEDEFS */ 39050a99a6SPankaj Gupta 40050a99a6SPankaj Gupta /* 41050a99a6SPankaj Gupta * @brief Function called by JR User Space driver to notify every processed 42050a99a6SPankaj Gupta * descriptor. 43050a99a6SPankaj Gupta * 44050a99a6SPankaj Gupta * Callback provided by the User Application. 45050a99a6SPankaj Gupta * Callback is invoked by JR User Space driver for each descriptor processed by 46050a99a6SPankaj Gupta * SEC 47050a99a6SPankaj Gupta * @param [in] status Status word indicating processing result for 48050a99a6SPankaj Gupta * this descriptor. 49050a99a6SPankaj Gupta * @param [in] arg Opaque data passed by User Application 50050a99a6SPankaj Gupta * It is opaque from JR driver's point of view. 51050a99a6SPankaj Gupta * @param [in] job_ring The job ring handle on which the processed 52050a99a6SPankaj Gupta * descriptor word was enqueued 53050a99a6SPankaj Gupta */ 54050a99a6SPankaj Gupta typedef void (*user_callback) (uint32_t *desc, uint32_t status, 55050a99a6SPankaj Gupta void *arg, void *job_ring); 56050a99a6SPankaj Gupta 57050a99a6SPankaj Gupta /* 58050a99a6SPankaj Gupta * Structure encompassing a job descriptor which is to be processed 59050a99a6SPankaj Gupta * by SEC. User should also initialise this structure with the callback 60*1b491eeaSElyes Haouas * function pointer which will be called by driver after receiving proccessed 61050a99a6SPankaj Gupta * descriptor from SEC. User data is also passed in this data structure which 62050a99a6SPankaj Gupta * will be sent as an argument to the user callback function. 63050a99a6SPankaj Gupta */ 64050a99a6SPankaj Gupta struct job_descriptor { 65050a99a6SPankaj Gupta uint32_t desc[MAX_DESC_SIZE_WORDS]; 66050a99a6SPankaj Gupta void *arg; 67050a99a6SPankaj Gupta user_callback callback; 68050a99a6SPankaj Gupta }; 69050a99a6SPankaj Gupta 70050a99a6SPankaj Gupta /* 71050a99a6SPankaj Gupta * @brief Initialize the JR User Space driver. 72050a99a6SPankaj Gupta * This function will handle initialization of sec library 73050a99a6SPankaj Gupta * along with registering platform specific callbacks, 74050a99a6SPankaj Gupta * as well as local data initialization. 75050a99a6SPankaj Gupta * Call once during application startup. 76050a99a6SPankaj Gupta * @note Global SEC initialization is done in SEC kernel driver. 77050a99a6SPankaj Gupta * @note The hardware IDs of the initialized Job Rings are opaque to the UA. 78050a99a6SPankaj Gupta * The exact Job Rings used by this library are decided between SEC user 79050a99a6SPankaj Gupta * space driver and SEC kernel driver. A static partitioning of Job Rings is 80050a99a6SPankaj Gupta * assumed, configured in DTS(device tree specification) file. 81050a99a6SPankaj Gupta * @param [in] platform_cb Registering the platform specific 82050a99a6SPankaj Gupta * callbacks with driver 83050a99a6SPankaj Gupta * @retval ::0 for successful execution 84050a99a6SPankaj Gupta * @retval ::-1 failure 85050a99a6SPankaj Gupta */ 86050a99a6SPankaj Gupta int sec_jr_lib_init(void); 87050a99a6SPankaj Gupta 88050a99a6SPankaj Gupta /* 89050a99a6SPankaj Gupta * @brief Initialize the software and hardware resources tied to a job ring. 90050a99a6SPankaj Gupta * @param [in] jr_mode; Model to be used by SEC Driver to receive 91050a99a6SPankaj Gupta * notifications from SEC. Can be either 92050a99a6SPankaj Gupta * SEC_NOTIFICATION_TYPE_IRQ or 93050a99a6SPankaj Gupta * SEC_NOTIFICATION_TYPE_POLL 94050a99a6SPankaj Gupta * @param [in] irq_coalescing_timer This value determines the maximum 95050a99a6SPankaj Gupta * amount of time after processing a 96050a99a6SPankaj Gupta * descriptor before raising an interrupt. 97050a99a6SPankaj Gupta * @param [in] irq_coalescing_count This value determines how many 98050a99a6SPankaj Gupta * descriptors are completed before 99050a99a6SPankaj Gupta * raising an interrupt. 100050a99a6SPankaj Gupta * @param [in] reg_base_addr The job ring base address register 101050a99a6SPankaj Gupta * @param [in] irq_id The job ring interrupt identification number. 102050a99a6SPankaj Gupta * @retval job_ring_handle for successful job ring configuration 103050a99a6SPankaj Gupta * @retval NULL on error 104050a99a6SPankaj Gupta */ 105050a99a6SPankaj Gupta void *init_job_ring(uint8_t jr_mode, 106050a99a6SPankaj Gupta uint16_t irq_coalescing_timer, 107050a99a6SPankaj Gupta uint8_t irq_coalescing_count, 108050a99a6SPankaj Gupta void *reg_base_addr, uint32_t irq_id); 109050a99a6SPankaj Gupta 110050a99a6SPankaj Gupta /* 111050a99a6SPankaj Gupta * @brief Release the resources used by the JR User Space driver. 112050a99a6SPankaj Gupta * Reset and release SEC's job rings indicated by the User Application at 113050a99a6SPankaj Gupta * init_job_ring() and free any memory allocated internally. 114050a99a6SPankaj Gupta * Call once during application tear down. 115050a99a6SPankaj Gupta * @note In case there are any descriptors in-flight (descriptors received by 116050a99a6SPankaj Gupta * JR driver for processing and for which no response was yet provided to UA), 117050a99a6SPankaj Gupta * the descriptors are discarded without any notifications to User Application. 118050a99a6SPankaj Gupta * @retval ::0 is returned for a successful execution 119050a99a6SPankaj Gupta * @retval ::-1 is returned if JR driver release is in progress 120050a99a6SPankaj Gupta */ 121050a99a6SPankaj Gupta int sec_release(void); 122050a99a6SPankaj Gupta 123050a99a6SPankaj Gupta /* 124050a99a6SPankaj Gupta * @brief Submit a descriptor for SEC processing. 125050a99a6SPankaj Gupta * This function creates a "job" which is meant to instruct SEC HW 126050a99a6SPankaj Gupta * to perform the processing on the input buffer. The "job" is enqueued 127050a99a6SPankaj Gupta * in the Job Ring associated. The function will return after the "job" 128050a99a6SPankaj Gupta * enqueue is finished. The function will not wait for SEC to 129050a99a6SPankaj Gupta * start or/and finish the "job" processing. 130050a99a6SPankaj Gupta * After the processing is finished the SEC HW writes the processing result 131050a99a6SPankaj Gupta * to the provided output buffer. 132050a99a6SPankaj Gupta * The Caller must poll JR driver using jr_dequeue() 133050a99a6SPankaj Gupta * to receive notifications of the processing completion 134050a99a6SPankaj Gupta * status. The notifications are received by caller by means of callback 135050a99a6SPankaj Gupta * (see ::user_callback). 136050a99a6SPankaj Gupta * @param [in] job_ring_handle The handle of the job ring on which 137050a99a6SPankaj Gupta * descriptor is to be enqueued 138050a99a6SPankaj Gupta * @param [in] job_descriptor The job descriptor structure of type 139050a99a6SPankaj Gupta * struct job_descriptor. This structure 140050a99a6SPankaj Gupta * should be filled with job descriptor along 141050a99a6SPankaj Gupta * with callback function to be called after 142050a99a6SPankaj Gupta * processing of descriptor and some 143050a99a6SPankaj Gupta * opaque data passed to be passed to the 144050a99a6SPankaj Gupta * callback function 145050a99a6SPankaj Gupta * 146050a99a6SPankaj Gupta * @retval ::0 is returned for successful execution 147050a99a6SPankaj Gupta * @retval ::-1 is returned if there is some enqueue failure 148050a99a6SPankaj Gupta */ 149050a99a6SPankaj Gupta int enq_jr_desc(void *job_ring_handle, struct job_descriptor *jobdescr); 150050a99a6SPankaj Gupta 151050a99a6SPankaj Gupta /* 152050a99a6SPankaj Gupta * @brief Polls for available descriptors processed by SEC on a specific 153050a99a6SPankaj Gupta * Job Ring 154050a99a6SPankaj Gupta * This function polls the SEC Job Rings and delivers processed descriptors 155050a99a6SPankaj Gupta * Each processed descriptor has a user_callback registered. 156050a99a6SPankaj Gupta * This user_callback is invoked for each processed descriptor. 157050a99a6SPankaj Gupta * The polling is stopped when "limit" descriptors are notified or when 158050a99a6SPankaj Gupta * there are no more descriptors to notify. 159050a99a6SPankaj Gupta * @note The dequeue_jr() API cannot be called from within a user_callback 160050a99a6SPankaj Gupta * function 161050a99a6SPankaj Gupta * @param [in] job_ring_handle The Job Ring handle. 162050a99a6SPankaj Gupta * @param [in] limit This value represents the maximum number 163050a99a6SPankaj Gupta * of processed descriptors that can be 164050a99a6SPankaj Gupta * notified API call on this Job Ring. 165050a99a6SPankaj Gupta * Note that fewer descriptors may be notified 166050a99a6SPankaj Gupta * if enough processed descriptors are not 167050a99a6SPankaj Gupta * available. 168050a99a6SPankaj Gupta * If limit has a negative value, then all 169050a99a6SPankaj Gupta * ready descriptors will be notified. 170050a99a6SPankaj Gupta * 171050a99a6SPankaj Gupta * @retval :: >=0 is returned where retval is the total 172050a99a6SPankaj Gupta * Number of descriptors notified 173050a99a6SPankaj Gupta * during this function call. 174050a99a6SPankaj Gupta * @retval :: -1 is returned in case of some error 175050a99a6SPankaj Gupta */ 176050a99a6SPankaj Gupta int dequeue_jr(void *job_ring_handle, int32_t limit); 177050a99a6SPankaj Gupta 178050a99a6SPankaj Gupta #endif /* _JR_DRIVER_H_ */ 179