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