xref: /dpdk/drivers/crypto/dpaa2_sec/mc/fsl_dpseci.h (revision 4562de32)
1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2  *
3  * Copyright 2013-2016 Freescale Semiconductor Inc.
4  * Copyright 2016-2020 NXP
5  *
6  */
7 #ifndef __FSL_DPSECI_H
8 #define __FSL_DPSECI_H
9 
10 /* Data Path SEC Interface API
11  * Contains initialization APIs and runtime control APIs for DPSECI
12  */
13 
14 #include <fsl_dpopr.h>
15 
16 struct fsl_mc_io;
17 
18 /**
19  * General DPSECI macros
20  */
21 
22 /**
23  * Maximum number of Tx/Rx priorities per DPSECI object
24  */
25 #define DPSECI_MAX_QUEUE_NUM		16
26 
27 /**
28  * All queues considered; see dpseci_set_rx_queue()
29  */
30 #define DPSECI_ALL_QUEUES	(uint8_t)(-1)
31 
32 int dpseci_open(struct fsl_mc_io *mc_io,
33 		uint32_t cmd_flags,
34 		int dpseci_id,
35 		uint16_t *token);
36 
37 int dpseci_close(struct fsl_mc_io *mc_io,
38 		 uint32_t cmd_flags,
39 		 uint16_t token);
40 
41 /**
42  * Enable the Congestion Group support
43  */
44 #define DPSECI_OPT_HAS_CG				0x000020
45 
46 /**
47  * Enable the Order Restoration support
48  */
49 #define DPSECI_OPT_HAS_OPR				0x000040
50 
51 /**
52  * Order Point Records are shared for the entire DPSECI
53  */
54 #define DPSECI_OPT_OPR_SHARED				0x000080
55 
56 /**
57  * struct dpseci_cfg - Structure representing DPSECI configuration
58  * @options: Any combination of the following options:
59  *		DPSECI_OPT_HAS_CG
60  *		DPSECI_OPT_HAS_OPR
61  *		DPSECI_OPT_OPR_SHARED
62  * @num_tx_queues: num of queues towards the SEC
63  * @num_rx_queues: num of queues back from the SEC
64  * @priorities: Priorities for the SEC hardware processing;
65  *		each place in the array is the priority of the tx queue
66  *		towards the SEC,
67  *		valid priorities are configured with values 1-8;
68  */
69 struct dpseci_cfg {
70 	uint32_t options;
71 	uint8_t num_tx_queues;
72 	uint8_t num_rx_queues;
73 	uint8_t priorities[DPSECI_MAX_QUEUE_NUM];
74 };
75 
76 int dpseci_create(struct fsl_mc_io *mc_io,
77 		  uint16_t dprc_token,
78 		  uint32_t cmd_flags,
79 		  const struct dpseci_cfg *cfg,
80 		  uint32_t *obj_id);
81 
82 int dpseci_destroy(struct fsl_mc_io *mc_io,
83 		   uint16_t dprc_token,
84 		   uint32_t cmd_flags,
85 		   uint32_t object_id);
86 
87 int dpseci_enable(struct fsl_mc_io *mc_io,
88 		  uint32_t cmd_flags,
89 		  uint16_t token);
90 
91 int dpseci_disable(struct fsl_mc_io *mc_io,
92 		   uint32_t cmd_flags,
93 		   uint16_t token);
94 
95 int dpseci_is_enabled(struct fsl_mc_io *mc_io,
96 		      uint32_t cmd_flags,
97 		      uint16_t token,
98 		      int *en);
99 
100 int dpseci_reset(struct fsl_mc_io *mc_io,
101 		 uint32_t cmd_flags,
102 		 uint16_t token);
103 
104 /**
105  * struct dpseci_attr - Structure representing DPSECI attributes
106  * @id: DPSECI object ID
107  * @num_tx_queues: number of queues towards the SEC
108  * @num_rx_queues: number of queues back from the SEC
109  * @options: Any combination of the following options:
110  *		DPSECI_OPT_HAS_CG
111  *		DPSECI_OPT_HAS_OPR
112  *		DPSECI_OPT_OPR_SHARED
113  */
114 struct dpseci_attr {
115 	int id;
116 	uint8_t num_tx_queues;
117 	uint8_t num_rx_queues;
118 	uint32_t options;
119 };
120 
121 int dpseci_get_attributes(struct fsl_mc_io *mc_io,
122 			  uint32_t cmd_flags,
123 			  uint16_t token,
124 			  struct dpseci_attr *attr);
125 
126 /**
127  * enum dpseci_dest - DPSECI destination types
128  * @DPSECI_DEST_NONE: Unassigned destination; The queue is set in parked mode
129  *		and does not generate FQDAN notifications; user is expected to
130  *		dequeue from the queue based on polling or other user-defined
131  *		method
132  * @DPSECI_DEST_DPIO: The queue is set in schedule mode and generates FQDAN
133  *		notifications to the specified DPIO; user is expected to dequeue
134  *		from the queue only after notification is received
135  * @DPSECI_DEST_DPCON: The queue is set in schedule mode and does not generate
136  *		FQDAN notifications, but is connected to the specified DPCON
137  *		object; user is expected to dequeue from the DPCON channel
138  */
139 enum dpseci_dest {
140 	DPSECI_DEST_NONE = 0,
141 	DPSECI_DEST_DPIO = 1,
142 	DPSECI_DEST_DPCON = 2
143 };
144 
145 /**
146  * struct dpseci_dest_cfg - Structure representing DPSECI destination parameters
147  * @dest_type: Destination type
148  * @dest_id: Either DPIO ID or DPCON ID, depending on the destination type
149  * @priority: Priority selection within the DPIO or DPCON channel; valid values
150  *	are 0-1 or 0-7, depending on the number of priorities in that
151  *	channel; not relevant for 'DPSECI_DEST_NONE' option
152  */
153 struct dpseci_dest_cfg {
154 	enum dpseci_dest dest_type;
155 	int dest_id;
156 	uint8_t priority;
157 };
158 
159 /**
160  * DPSECI queue modification options
161  */
162 
163 /**
164  * Select to modify the user's context associated with the queue
165  */
166 #define DPSECI_QUEUE_OPT_USER_CTX		0x00000001
167 
168 /**
169  * Select to modify the queue's destination
170  */
171 #define DPSECI_QUEUE_OPT_DEST			0x00000002
172 
173 /**
174  * Select to modify the queue's order preservation
175  */
176 #define DPSECI_QUEUE_OPT_ORDER_PRESERVATION	0x00000004
177 
178 /**
179  * struct dpseci_rx_queue_cfg - DPSECI RX queue configuration
180  * @options: Flags representing the suggested modifications to the queue;
181  *	Use any combination of 'DPSECI_QUEUE_OPT_<X>' flags
182  * @order_preservation_en: order preservation configuration for the rx queue
183  * valid only if 'DPSECI_QUEUE_OPT_ORDER_PRESERVATION' is contained in 'options'
184  * @user_ctx: User context value provided in the frame descriptor of each
185  *	dequeued frame;
186  *	valid only if 'DPSECI_QUEUE_OPT_USER_CTX' is contained in 'options'
187  * @dest_cfg: Queue destination parameters;
188  *	valid only if 'DPSECI_QUEUE_OPT_DEST' is contained in 'options'
189  */
190 struct dpseci_rx_queue_cfg {
191 	uint32_t options;
192 	int order_preservation_en;
193 	uint64_t user_ctx;
194 	struct dpseci_dest_cfg dest_cfg;
195 };
196 
197 int dpseci_set_rx_queue(struct fsl_mc_io *mc_io,
198 			uint32_t cmd_flags,
199 			uint16_t token,
200 			uint8_t queue,
201 			const struct dpseci_rx_queue_cfg *cfg);
202 
203 /**
204  * struct dpseci_rx_queue_attr - Structure representing attributes of Rx queues
205  * @user_ctx: User context value provided in the frame descriptor of each
206  *	dequeued frame
207  * @order_preservation_en: Status of the order preservation configuration
208  *				on the queue
209  * @dest_cfg: Queue destination configuration
210  * @fqid: Virtual FQID value to be used for dequeue operations
211  */
212 struct dpseci_rx_queue_attr {
213 	uint64_t user_ctx;
214 	int order_preservation_en;
215 	struct dpseci_dest_cfg dest_cfg;
216 	uint32_t fqid;
217 };
218 
219 int dpseci_get_rx_queue(struct fsl_mc_io *mc_io,
220 			uint32_t cmd_flags,
221 			uint16_t token,
222 			uint8_t queue,
223 			struct dpseci_rx_queue_attr *attr);
224 
225 /**
226  * struct dpseci_tx_queue_attr - Structure representing attributes of Tx queues
227  * @fqid: Virtual FQID to be used for sending frames to SEC hardware
228  * @priority: SEC hardware processing priority for the queue
229  */
230 struct dpseci_tx_queue_attr {
231 	uint32_t fqid;
232 	uint8_t priority;
233 };
234 
235 int dpseci_get_tx_queue(struct fsl_mc_io *mc_io,
236 			uint32_t cmd_flags,
237 			uint16_t token,
238 			uint8_t queue,
239 			struct dpseci_tx_queue_attr *attr);
240 
241 /**
242  * struct dpseci_sec_attr - Structure representing attributes of the SEC
243  *				hardware accelerator
244  * @ip_id:		ID for SEC.
245  * @major_rev:		Major revision number for SEC.
246  * @minor_rev:		Minor revision number for SEC.
247  * @era:		SEC Era.
248  * @deco_num:		The number of copies of the DECO that are implemented
249  *			in this version of SEC.
250  * @zuc_auth_acc_num:	The number of copies of ZUCA that are implemented
251  *			in this version of SEC.
252  * @zuc_enc_acc_num:	The number of copies of ZUCE that are implemented
253  *			in this version of SEC.
254  * @snow_f8_acc_num:	The number of copies of the SNOW-f8 module that are
255  *			implemented in this version of SEC.
256  * @snow_f9_acc_num:	The number of copies of the SNOW-f9 module that are
257  *			implemented in this version of SEC.
258  * @crc_acc_num:	The number of copies of the CRC module that are
259  *			implemented in this version of SEC.
260  * @pk_acc_num:		The number of copies of the Public Key module that are
261  *			implemented in this version of SEC.
262  * @kasumi_acc_num:	The number of copies of the Kasumi module that are
263  *			implemented in this version of SEC.
264  * @rng_acc_num:	The number of copies of the Random Number Generator that
265  *			are implemented in this version of SEC.
266  * @md_acc_num:		The number of copies of the MDHA (Hashing module) that
267  *			are implemented in this version of SEC.
268  * @arc4_acc_num:	The number of copies of the ARC4 module that are
269  *			implemented in this version of SEC.
270  * @des_acc_num:	The number of copies of the DES module that are
271  *			implemented in this version of SEC.
272  * @aes_acc_num:	The number of copies of the AES module that are
273  *			implemented in this version of SEC.
274  * @ccha_acc_num:	The number of copies of the ChaCha20 module that are
275  *			implemented in this version of SEC.
276  * @ptha_acc_num:	The number of copies of the Poly1305 module that are
277  *			implemented in this version of SEC.
278  **/
279 
280 struct dpseci_sec_attr {
281 	uint16_t ip_id;
282 	uint8_t major_rev;
283 	uint8_t minor_rev;
284 	uint8_t era;
285 	uint8_t deco_num;
286 	uint8_t zuc_auth_acc_num;
287 	uint8_t zuc_enc_acc_num;
288 	uint8_t snow_f8_acc_num;
289 	uint8_t snow_f9_acc_num;
290 	uint8_t crc_acc_num;
291 	uint8_t pk_acc_num;
292 	uint8_t kasumi_acc_num;
293 	uint8_t rng_acc_num;
294 	uint8_t md_acc_num;
295 	uint8_t arc4_acc_num;
296 	uint8_t des_acc_num;
297 	uint8_t aes_acc_num;
298 	uint8_t ccha_acc_num;
299 	uint8_t ptha_acc_num;
300 };
301 
302 int dpseci_get_sec_attr(struct fsl_mc_io *mc_io,
303 			uint32_t cmd_flags,
304 			uint16_t token,
305 			struct dpseci_sec_attr *attr);
306 
307 /**
308  * struct dpseci_sec_counters - Structure representing global SEC counters and
309  *				not per dpseci counters
310  * @dequeued_requests:	Number of Requests Dequeued
311  * @ob_enc_requests:	Number of Outbound Encrypt Requests
312  * @ib_dec_requests:	Number of Inbound Decrypt Requests
313  * @ob_enc_bytes:	Number of Outbound Bytes Encrypted
314  * @ob_prot_bytes:	Number of Outbound Bytes Protected
315  * @ib_dec_bytes:	Number of Inbound Bytes Decrypted
316  * @ib_valid_bytes:	Number of Inbound Bytes Validated
317  */
318 struct dpseci_sec_counters {
319 	uint64_t dequeued_requests;
320 	uint64_t ob_enc_requests;
321 	uint64_t ib_dec_requests;
322 	uint64_t ob_enc_bytes;
323 	uint64_t ob_prot_bytes;
324 	uint64_t ib_dec_bytes;
325 	uint64_t ib_valid_bytes;
326 };
327 
328 int dpseci_get_sec_counters(struct fsl_mc_io *mc_io,
329 			    uint32_t cmd_flags,
330 			    uint16_t token,
331 			    struct dpseci_sec_counters *counters);
332 
333 int dpseci_get_api_version(struct fsl_mc_io *mc_io,
334 			   uint32_t cmd_flags,
335 			   uint16_t *major_ver,
336 			   uint16_t *minor_ver);
337 
338 int dpseci_set_opr(struct fsl_mc_io *mc_io,
339 		   uint32_t cmd_flags,
340 		   uint16_t token,
341 		   uint8_t index,
342 		   uint8_t options,
343 		   struct opr_cfg *cfg);
344 
345 int dpseci_get_opr(struct fsl_mc_io *mc_io,
346 		   uint32_t cmd_flags,
347 		   uint16_t token,
348 		   uint8_t index,
349 		   struct opr_cfg *cfg,
350 		   struct opr_qry *qry);
351 
352 /**
353  * enum dpseci_congestion_unit - DPSECI congestion units
354  * @DPSECI_CONGESTION_UNIT_BYTES: bytes units
355  * @DPSECI_CONGESTION_UNIT_FRAMES: frames units
356  */
357 enum dpseci_congestion_unit {
358 	DPSECI_CONGESTION_UNIT_BYTES = 0,
359 	DPSECI_CONGESTION_UNIT_FRAMES
360 };
361 
362 /**
363  * CSCN message is written to message_iova once entering a
364  * congestion state (see 'threshold_entry')
365  */
366 #define DPSECI_CGN_MODE_WRITE_MEM_ON_ENTER		0x00000001
367 /**
368  * CSCN message is written to message_iova once exiting a
369  * congestion state (see 'threshold_exit')
370  */
371 #define DPSECI_CGN_MODE_WRITE_MEM_ON_EXIT		0x00000002
372 /**
373  * CSCN write will attempt to allocate into a cache (coherent write);
374  * valid only if 'DPSECI_CGN_MODE_WRITE_MEM_<X>' is selected
375  */
376 #define DPSECI_CGN_MODE_COHERENT_WRITE			0x00000004
377 /**
378  * if 'dpseci_dest_cfg.dest_type != DPSECI_DEST_NONE' CSCN message is sent to
379  * DPIO/DPCON's WQ channel once entering a congestion state
380  * (see 'threshold_entry')
381  */
382 #define DPSECI_CGN_MODE_NOTIFY_DEST_ON_ENTER		0x00000008
383 /**
384  * if 'dpseci_dest_cfg.dest_type != DPSECI_DEST_NONE' CSCN message is sent to
385  * DPIO/DPCON's WQ channel once exiting a congestion state
386  * (see 'threshold_exit')
387  */
388 #define DPSECI_CGN_MODE_NOTIFY_DEST_ON_EXIT		0x00000010
389 /**
390  * if 'dpseci_dest_cfg.dest_type != DPSECI_DEST_NONE' when the CSCN is written
391  * to the sw-portal's DQRR, the DQRI interrupt is asserted immediately
392  * (if enabled)
393  */
394 #define DPSECI_CGN_MODE_INTR_COALESCING_DISABLED	0x00000020
395 
396 /**
397  * struct dpseci_congestion_notification_cfg - congestion notification
398  *		configuration
399  * @units: units type
400  * @threshold_entry: above this threshold we enter a congestion state.
401  *		set it to '0' to disable it
402  * @threshold_exit: below this threshold we exit the congestion state.
403  * @message_ctx: The context that will be part of the CSCN message
404  * @message_iova: I/O virtual address (must be in DMA-able memory),
405  *		must be 16B aligned;
406  * @dest_cfg: CSCN can be send to either DPIO or DPCON WQ channel
407  * @notification_mode: Mask of available options; use 'DPSECI_CGN_MODE_<X>'
408  *		values
409  */
410 struct dpseci_congestion_notification_cfg {
411 	enum dpseci_congestion_unit units;
412 	uint32_t threshold_entry;
413 	uint32_t threshold_exit;
414 	uint64_t message_ctx;
415 	uint64_t message_iova;
416 	struct dpseci_dest_cfg dest_cfg;
417 	uint16_t notification_mode;
418 };
419 
420 int dpseci_set_congestion_notification(
421 			struct fsl_mc_io *mc_io,
422 			uint32_t cmd_flags,
423 			uint16_t token,
424 			const struct dpseci_congestion_notification_cfg *cfg);
425 
426 int dpseci_get_congestion_notification(
427 			struct fsl_mc_io *mc_io,
428 			uint32_t cmd_flags,
429 			uint16_t token,
430 			struct dpseci_congestion_notification_cfg *cfg);
431 
432 #endif /* __FSL_DPSECI_H */
433