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