1*050a99a6SPankaj Gupta /* 2*050a99a6SPankaj Gupta * Copyright 2017-2021 NXP 3*050a99a6SPankaj Gupta * 4*050a99a6SPankaj Gupta * SPDX-License-Identifier: BSD-3-Clause 5*050a99a6SPankaj Gupta * 6*050a99a6SPankaj Gupta */ 7*050a99a6SPankaj Gupta 8*050a99a6SPankaj Gupta #ifndef _JR_DRIVER_CONFIG_H_ 9*050a99a6SPankaj Gupta #define _JR_DRIVER_CONFIG_H_ 10*050a99a6SPankaj Gupta 11*050a99a6SPankaj Gupta /* Helper defines */ 12*050a99a6SPankaj Gupta 13*050a99a6SPankaj Gupta /* Define used for setting a flag on */ 14*050a99a6SPankaj Gupta #define ON 1 15*050a99a6SPankaj Gupta /* Define used for setting a flag off */ 16*050a99a6SPankaj Gupta #define OFF 0 17*050a99a6SPankaj Gupta 18*050a99a6SPankaj Gupta /* SEC is configured to start work in polling mode, */ 19*050a99a6SPankaj Gupta #define SEC_STARTUP_POLLING_MODE 0 20*050a99a6SPankaj Gupta /* 21*050a99a6SPankaj Gupta * SEC is configured to start work in interrupt mode, 22*050a99a6SPankaj Gupta * when configured for NAPI notification style. 23*050a99a6SPankaj Gupta */ 24*050a99a6SPankaj Gupta #define SEC_STARTUP_INTERRUPT_MODE 1 25*050a99a6SPankaj Gupta 26*050a99a6SPankaj Gupta /* 27*050a99a6SPankaj Gupta * SEC driver will use ONLY interrupts to receive notifications 28*050a99a6SPankaj Gupta * for processed packets from SEC engine hardware. 29*050a99a6SPankaj Gupta */ 30*050a99a6SPankaj Gupta #define SEC_NOTIFICATION_TYPE_IRQ 1 31*050a99a6SPankaj Gupta /* 32*050a99a6SPankaj Gupta * SEC driver will use ONLY polling to receive notifications 33*050a99a6SPankaj Gupta * for processed packets from SEC engine hardware. 34*050a99a6SPankaj Gupta */ 35*050a99a6SPankaj Gupta #define SEC_NOTIFICATION_TYPE_POLL 2 36*050a99a6SPankaj Gupta 37*050a99a6SPankaj Gupta /* 38*050a99a6SPankaj Gupta * Determines how SEC user space driver will receive notifications 39*050a99a6SPankaj Gupta * for processed packets from SEC engine. 40*050a99a6SPankaj Gupta * Valid values are: #SEC_NOTIFICATION_TYPE_POLL, #SEC_NOTIFICATION_TYPE_IRQ 41*050a99a6SPankaj Gupta */ 42*050a99a6SPankaj Gupta #define SEC_NOTIFICATION_TYPE SEC_NOTIFICATION_TYPE_POLL 43*050a99a6SPankaj Gupta 44*050a99a6SPankaj Gupta /* Maximum number of job rings supported by SEC hardware */ 45*050a99a6SPankaj Gupta #define MAX_SEC_JOB_RINGS 1 46*050a99a6SPankaj Gupta 47*050a99a6SPankaj Gupta /* 48*050a99a6SPankaj Gupta * Size of cryptographic context that is used directly in communicating 49*050a99a6SPankaj Gupta * with SEC device. 50*050a99a6SPankaj Gupta * SEC device works only with physical addresses. This is the maximum size 51*050a99a6SPankaj Gupta * for a SEC descriptor ( = 64 words). 52*050a99a6SPankaj Gupta */ 53*050a99a6SPankaj Gupta 54*050a99a6SPankaj Gupta #define SEC_CRYPTO_DESCRIPTOR_SIZE 256 55*050a99a6SPankaj Gupta 56*050a99a6SPankaj Gupta /* 57*050a99a6SPankaj Gupta * Size of job descriptor submitted to SEC device for each packet to be 58*050a99a6SPankaj Gupta * processed. 59*050a99a6SPankaj Gupta * Job descriptor contains 3 DMA address pointers: 60*050a99a6SPankaj Gupta * - to shared descriptor, to input buffer and to output buffer. 61*050a99a6SPankaj Gupta * The job descriptor contains other SEC specific commands as well: 62*050a99a6SPankaj Gupta * - HEADER command, SEQ IN PTR command SEQ OUT PTR command and opaque 63*050a99a6SPankaj Gupta * data, each measuring 4 bytes. 64*050a99a6SPankaj Gupta * Job descriptor size, depending on physical address representation: 65*050a99a6SPankaj Gupta * - 32 bit - size is 28 bytes - cacheline-aligned size is 64 bytes 66*050a99a6SPankaj Gupta * - 36 bit - size is 40 bytes - cacheline-aligned size is 64 bytes 67*050a99a6SPankaj Gupta * @note: Job descriptor must be cacheline-aligned to ensure efficient memory 68*050a99a6SPankaj Gupta * access. 69*050a99a6SPankaj Gupta * @note: If other format is used for job descriptor, then the size must be 70*050a99a6SPankaj Gupta * revised. 71*050a99a6SPankaj Gupta */ 72*050a99a6SPankaj Gupta 73*050a99a6SPankaj Gupta #define SEC_JOB_DESCRIPTOR_SIZE 64 74*050a99a6SPankaj Gupta 75*050a99a6SPankaj Gupta /* 76*050a99a6SPankaj Gupta * Size of one entry in the input ring of a job ring. 77*050a99a6SPankaj Gupta * Input ring contains pointers to job descriptors. 78*050a99a6SPankaj Gupta * The memory used for an input ring and output ring must be physically 79*050a99a6SPankaj Gupta * contiguous. 80*050a99a6SPankaj Gupta */ 81*050a99a6SPankaj Gupta 82*050a99a6SPankaj Gupta #define SEC_JOB_INPUT_RING_ENTRY_SIZE sizeof(phys_addr_t) 83*050a99a6SPankaj Gupta 84*050a99a6SPankaj Gupta /* 85*050a99a6SPankaj Gupta * Size of one entry in the output ring of a job ring. 86*050a99a6SPankaj Gupta * Output ring entry is a pointer to a job descriptor followed by a 4 byte 87*050a99a6SPankaj Gupta * status word. 88*050a99a6SPankaj Gupta * The memory used for an input ring and output ring must be physically 89*050a99a6SPankaj Gupta * contiguous. 90*050a99a6SPankaj Gupta * @note If desired to use also the optional SEQ OUT indication in output 91*050a99a6SPankaj Gupta * ring entries, then 4 more bytes must be added to the size. 92*050a99a6SPankaj Gupta */ 93*050a99a6SPankaj Gupta 94*050a99a6SPankaj Gupta #define SEC_JOB_OUTPUT_RING_ENTRY_SIZE (SEC_JOB_INPUT_RING_ENTRY_SIZE + 4) 95*050a99a6SPankaj Gupta 96*050a99a6SPankaj Gupta /* DMA memory required for an input ring of a job ring. */ 97*050a99a6SPankaj Gupta #define SEC_DMA_MEM_INPUT_RING_SIZE \ 98*050a99a6SPankaj Gupta ((SEC_JOB_INPUT_RING_ENTRY_SIZE) * (SEC_JOB_RING_SIZE)) 99*050a99a6SPankaj Gupta 100*050a99a6SPankaj Gupta /* 101*050a99a6SPankaj Gupta * DMA memory required for an output ring of a job ring. 102*050a99a6SPankaj Gupta * Required extra 4 byte for status word per each entry. 103*050a99a6SPankaj Gupta */ 104*050a99a6SPankaj Gupta #define SEC_DMA_MEM_OUTPUT_RING_SIZE \ 105*050a99a6SPankaj Gupta ((SEC_JOB_OUTPUT_RING_ENTRY_SIZE) * (SEC_JOB_RING_SIZE)) 106*050a99a6SPankaj Gupta 107*050a99a6SPankaj Gupta /* DMA memory required for descriptors of a job ring. */ 108*050a99a6SPankaj Gupta #define SEC_DMA_MEM_DESCRIPTORS \ 109*050a99a6SPankaj Gupta ((SEC_CRYPTO_DESCRIPTOR_SIZE)*(SEC_JOB_RING_SIZE)) 110*050a99a6SPankaj Gupta 111*050a99a6SPankaj Gupta /* DMA memory required for a job ring, including both input output rings. */ 112*050a99a6SPankaj Gupta #define SEC_DMA_MEM_JOB_RING_SIZE \ 113*050a99a6SPankaj Gupta ((SEC_DMA_MEM_INPUT_RING_SIZE) + \ 114*050a99a6SPankaj Gupta (SEC_DMA_MEM_OUTPUT_RING_SIZE)) 115*050a99a6SPankaj Gupta 116*050a99a6SPankaj Gupta /* 117*050a99a6SPankaj Gupta * When calling sec_init() UA will provide an area of virtual memory 118*050a99a6SPankaj Gupta * of size #SEC_DMA_MEMORY_SIZE to be used internally by the driver 119*050a99a6SPankaj Gupta * to allocate data (like SEC descriptors) that needs to be passed to 120*050a99a6SPankaj Gupta * SEC device in physical addressing and later on retrieved from SEC device. 121*050a99a6SPankaj Gupta * At initialization the UA provides specialized ptov/vtop functions/macros to 122*050a99a6SPankaj Gupta * translate addresses allocated from this memory area. 123*050a99a6SPankaj Gupta */ 124*050a99a6SPankaj Gupta #define SEC_DMA_MEMORY_SIZE \ 125*050a99a6SPankaj Gupta ((SEC_DMA_MEM_JOB_RING_SIZE) * (MAX_SEC_JOB_RINGS)) 126*050a99a6SPankaj Gupta 127*050a99a6SPankaj Gupta /* 128*050a99a6SPankaj Gupta * SEC DEVICE related configuration. 129*050a99a6SPankaj Gupta 130*050a99a6SPankaj Gupta * Enable/Disable logging support at compile time. 131*050a99a6SPankaj Gupta * Valid values: 132*050a99a6SPankaj Gupta * ON - enable logging 133*050a99a6SPankaj Gupta * OFF - disable logging 134*050a99a6SPankaj Gupta * The messages are logged at stdout. 135*050a99a6SPankaj Gupta */ 136*050a99a6SPankaj Gupta 137*050a99a6SPankaj Gupta #define SEC_DRIVER_LOGGING OFF 138*050a99a6SPankaj Gupta 139*050a99a6SPankaj Gupta /* 140*050a99a6SPankaj Gupta * Configure logging level at compile time. 141*050a99a6SPankaj Gupta * Valid values: 142*050a99a6SPankaj Gupta * SEC_DRIVER_LOG_ERROR - log only errors 143*050a99a6SPankaj Gupta * SEC_DRIVER_LOG_INFO - log errors and info messages 144*050a99a6SPankaj Gupta * SEC_DRIVER_LOG_DEBUG - log errors, info and debug messages 145*050a99a6SPankaj Gupta */ 146*050a99a6SPankaj Gupta 147*050a99a6SPankaj Gupta #define SEC_DRIVER_LOGGING_LEVEL SEC_DRIVER_LOG_DEBUG 148*050a99a6SPankaj Gupta 149*050a99a6SPankaj Gupta /* 150*050a99a6SPankaj Gupta * SEC JOB RING related configuration. 151*050a99a6SPankaj Gupta 152*050a99a6SPankaj Gupta * Configure the size of the JOB RING. 153*050a99a6SPankaj Gupta * The maximum size of the ring is hardware limited to 1024. 154*050a99a6SPankaj Gupta * However the number of packets in flight in a time interval of 155*050a99a6SPankaj Gupta * 1ms can be calculated 156*050a99a6SPankaj Gupta * from the traffic rate (Mbps) and packet size. 157*050a99a6SPankaj Gupta * Here it was considered a packet size of 40 bytes. 158*050a99a6SPankaj Gupta * @note Round up to nearest power of 2 for optimized update 159*050a99a6SPankaj Gupta * of producer/consumer indexes of each job ring 160*050a99a6SPankaj Gupta * \todo Should set to 750, according to the calculation above, but 161*050a99a6SPankaj Gupta * the JR size must be power of 2, thus the next closest value must 162*050a99a6SPankaj Gupta * be chosen (i.e. 512 since 1024 is not available) 163*050a99a6SPankaj Gupta * For firmware choose this to be 16 164*050a99a6SPankaj Gupta */ 165*050a99a6SPankaj Gupta 166*050a99a6SPankaj Gupta #define SEC_JOB_RING_SIZE 16 167*050a99a6SPankaj Gupta 168*050a99a6SPankaj Gupta /* 169*050a99a6SPankaj Gupta * Interrupt coalescing related configuration. 170*050a99a6SPankaj Gupta * NOTE: SEC hardware enabled interrupt 171*050a99a6SPankaj Gupta * coalescing is not supported on SEC version 3.1! 172*050a99a6SPankaj Gupta * SEC version 4.4 has support for interrupt 173*050a99a6SPankaj Gupta * coalescing. 174*050a99a6SPankaj Gupta */ 175*050a99a6SPankaj Gupta 176*050a99a6SPankaj Gupta #if SEC_NOTIFICATION_TYPE != SEC_NOTIFICATION_TYPE_POLL 177*050a99a6SPankaj Gupta 178*050a99a6SPankaj Gupta #define SEC_INT_COALESCING_ENABLE ON 179*050a99a6SPankaj Gupta /* 180*050a99a6SPankaj Gupta * Interrupt Coalescing Descriptor Count Threshold. 181*050a99a6SPankaj Gupta * While interrupt coalescing is enabled (ICEN=1), this value determines 182*050a99a6SPankaj Gupta * how many Descriptors are completed before raising an interrupt. 183*050a99a6SPankaj Gupta * Valid values for this field are from 0 to 255. 184*050a99a6SPankaj Gupta * Note that a value of 1 functionally defeats the advantages of interrupt 185*050a99a6SPankaj Gupta * coalescing since the threshold value is reached each time that a 186*050a99a6SPankaj Gupta * Job Descriptor is completed. A value of 0 is treated in the same 187*050a99a6SPankaj Gupta * manner as a value of 1. 188*050a99a6SPankaj Gupta * 189*050a99a6SPankaj Gupta */ 190*050a99a6SPankaj Gupta #define SEC_INTERRUPT_COALESCING_DESCRIPTOR_COUNT_THRESH 10 191*050a99a6SPankaj Gupta 192*050a99a6SPankaj Gupta /* 193*050a99a6SPankaj Gupta * Interrupt Coalescing Timer Threshold. 194*050a99a6SPankaj Gupta * While interrupt coalescing is enabled (ICEN=1), this value determines the 195*050a99a6SPankaj Gupta * maximum amount of time after processing a Descriptor before raising an 196*050a99a6SPankaj Gupta * interrupt. 197*050a99a6SPankaj Gupta * The threshold value is represented in units equal to 64 CAAM interface 198*050a99a6SPankaj Gupta * clocks. Valid values for this field are from 1 to 65535. 199*050a99a6SPankaj Gupta * A value of 0 results in behavior identical to that when interrupt 200*050a99a6SPankaj Gupta * coalescing is disabled. 201*050a99a6SPankaj Gupta */ 202*050a99a6SPankaj Gupta #define SEC_INTERRUPT_COALESCING_TIMER_THRESH 100 203*050a99a6SPankaj Gupta #endif /* SEC_NOTIFICATION_TYPE_POLL */ 204*050a99a6SPankaj Gupta 205*050a99a6SPankaj Gupta #endif /* _JR_DRIVER_CONFIG_H_ */ 206