1 /*-
2  * This file is provided under a dual BSD/GPLv2 license. When using or
3  * redistributing this file, you may do so under either license.
4  *
5  *   BSD LICENSE
6  *
7  * Copyright 2013-2016 Freescale Semiconductor Inc.
8  * Copyright 2016-2017 NXP.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  * * Neither the name of the above-listed copyright holders nor the
18  * names of any contributors may be used to endorse or promote products
19  * derived from this software without specific prior written permission.
20  *
21  *   GPL LICENSE SUMMARY
22  *
23  * ALTERNATIVELY, this software may be distributed under the terms of the
24  * GNU General Public License ("GPL") as published by the Free Software
25  * Foundation, either version 2 of that License or (at your option) any
26  * later version.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
32  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  */
40 #ifndef __FSL_DPSECI_H
41 #define __FSL_DPSECI_H
42 
43 /* Data Path SEC Interface API
44  * Contains initialization APIs and runtime control APIs for DPSECI
45  */
46 
47 struct fsl_mc_io;
48 
49 /**
50  * General DPSECI macros
51  */
52 
53 /**
54  * Maximum number of Tx/Rx priorities per DPSECI object
55  */
56 #define DPSECI_PRIO_NUM		8
57 
58 /**
59  * All queues considered; see dpseci_set_rx_queue()
60  */
61 #define DPSECI_ALL_QUEUES	(uint8_t)(-1)
62 
63 int dpseci_open(struct fsl_mc_io *mc_io,
64 		uint32_t cmd_flags,
65 		int dpseci_id,
66 		uint16_t *token);
67 
68 int dpseci_close(struct fsl_mc_io *mc_io,
69 		 uint32_t cmd_flags,
70 		 uint16_t token);
71 
72 /**
73  * Enable the Congestion Group support
74  */
75 #define DPSECI_OPT_HAS_CG				0x000020
76 
77 /**
78  * struct dpseci_cfg - Structure representing DPSECI configuration
79  * @options: Any combination of the following options:
80  *		DPSECI_OPT_HAS_CG
81  *		DPSECI_OPT_HAS_OPR
82  *		DPSECI_OPT_OPR_SHARED
83  * @num_tx_queues: num of queues towards the SEC
84  * @num_rx_queues: num of queues back from the SEC
85  * @priorities: Priorities for the SEC hardware processing;
86  *		each place in the array is the priority of the tx queue
87  *		towards the SEC,
88  *		valid priorities are configured with values 1-8;
89  */
90 struct dpseci_cfg {
91 	uint32_t options;
92 	uint8_t num_tx_queues;
93 	uint8_t num_rx_queues;
94 	uint8_t priorities[DPSECI_PRIO_NUM];
95 };
96 
97 int dpseci_create(struct fsl_mc_io *mc_io,
98 		  uint16_t dprc_token,
99 		  uint32_t cmd_flags,
100 		  const struct dpseci_cfg *cfg,
101 		  uint32_t *obj_id);
102 
103 int dpseci_destroy(struct fsl_mc_io *mc_io,
104 		   uint16_t dprc_token,
105 		   uint32_t cmd_flags,
106 		   uint32_t object_id);
107 
108 int dpseci_enable(struct fsl_mc_io *mc_io,
109 		  uint32_t cmd_flags,
110 		  uint16_t token);
111 
112 int dpseci_disable(struct fsl_mc_io *mc_io,
113 		   uint32_t cmd_flags,
114 		   uint16_t token);
115 
116 int dpseci_is_enabled(struct fsl_mc_io *mc_io,
117 		      uint32_t cmd_flags,
118 		      uint16_t token,
119 		      int *en);
120 
121 int dpseci_reset(struct fsl_mc_io *mc_io,
122 		 uint32_t cmd_flags,
123 		 uint16_t token);
124 
125 /**
126  * struct dpseci_attr - Structure representing DPSECI attributes
127  * @id: DPSECI object ID
128  * @num_tx_queues: number of queues towards the SEC
129  * @num_rx_queues: number of queues back from the SEC
130  * @options: Any combination of the following options:
131  *		DPSECI_OPT_HAS_CG
132  *		DPSECI_OPT_HAS_OPR
133  *		DPSECI_OPT_OPR_SHARED
134  */
135 struct dpseci_attr {
136 	int id;
137 	uint8_t num_tx_queues;
138 	uint8_t num_rx_queues;
139 	uint32_t options;
140 };
141 
142 int dpseci_get_attributes(struct fsl_mc_io *mc_io,
143 			  uint32_t cmd_flags,
144 			  uint16_t token,
145 			  struct dpseci_attr *attr);
146 
147 /**
148  * enum dpseci_dest - DPSECI destination types
149  * @DPSECI_DEST_NONE: Unassigned destination; The queue is set in parked mode
150  *		and does not generate FQDAN notifications; user is expected to
151  *		dequeue from the queue based on polling or other user-defined
152  *		method
153  * @DPSECI_DEST_DPIO: The queue is set in schedule mode and generates FQDAN
154  *		notifications to the specified DPIO; user is expected to dequeue
155  *		from the queue only after notification is received
156  * @DPSECI_DEST_DPCON: The queue is set in schedule mode and does not generate
157  *		FQDAN notifications, but is connected to the specified DPCON
158  *		object; user is expected to dequeue from the DPCON channel
159  */
160 enum dpseci_dest {
161 	DPSECI_DEST_NONE = 0,
162 	DPSECI_DEST_DPIO = 1,
163 	DPSECI_DEST_DPCON = 2
164 };
165 
166 /**
167  * struct dpseci_dest_cfg - Structure representing DPSECI destination parameters
168  * @dest_type: Destination type
169  * @dest_id: Either DPIO ID or DPCON ID, depending on the destination type
170  * @priority: Priority selection within the DPIO or DPCON channel; valid values
171  *	are 0-1 or 0-7, depending on the number of priorities in that
172  *	channel; not relevant for 'DPSECI_DEST_NONE' option
173  */
174 struct dpseci_dest_cfg {
175 	enum dpseci_dest dest_type;
176 	int dest_id;
177 	uint8_t priority;
178 };
179 
180 /**
181  * DPSECI queue modification options
182  */
183 
184 /**
185  * Select to modify the user's context associated with the queue
186  */
187 #define DPSECI_QUEUE_OPT_USER_CTX		0x00000001
188 
189 /**
190  * Select to modify the queue's destination
191  */
192 #define DPSECI_QUEUE_OPT_DEST			0x00000002
193 
194 /**
195  * Select to modify the queue's order preservation
196  */
197 #define DPSECI_QUEUE_OPT_ORDER_PRESERVATION	0x00000004
198 
199 /**
200  * struct dpseci_rx_queue_cfg - DPSECI RX queue configuration
201  * @options: Flags representing the suggested modifications to the queue;
202  *	Use any combination of 'DPSECI_QUEUE_OPT_<X>' flags
203  * @order_preservation_en: order preservation configuration for the rx queue
204  * valid only if 'DPSECI_QUEUE_OPT_ORDER_PRESERVATION' is contained in 'options'
205  * @user_ctx: User context value provided in the frame descriptor of each
206  *	dequeued frame;
207  *	valid only if 'DPSECI_QUEUE_OPT_USER_CTX' is contained in 'options'
208  * @dest_cfg: Queue destination parameters;
209  *	valid only if 'DPSECI_QUEUE_OPT_DEST' is contained in 'options'
210  */
211 struct dpseci_rx_queue_cfg {
212 	uint32_t options;
213 	int order_preservation_en;
214 	uint64_t user_ctx;
215 	struct dpseci_dest_cfg dest_cfg;
216 };
217 
218 int dpseci_set_rx_queue(struct fsl_mc_io *mc_io,
219 			uint32_t cmd_flags,
220 			uint16_t token,
221 			uint8_t queue,
222 			const struct dpseci_rx_queue_cfg *cfg);
223 
224 /**
225  * struct dpseci_rx_queue_attr - Structure representing attributes of Rx queues
226  * @user_ctx: User context value provided in the frame descriptor of each
227  *	dequeued frame
228  * @order_preservation_en: Status of the order preservation configuration
229  *				on the queue
230  * @dest_cfg: Queue destination configuration
231  * @fqid: Virtual FQID value to be used for dequeue operations
232  */
233 struct dpseci_rx_queue_attr {
234 	uint64_t user_ctx;
235 	int order_preservation_en;
236 	struct dpseci_dest_cfg dest_cfg;
237 	uint32_t fqid;
238 };
239 
240 int dpseci_get_rx_queue(struct fsl_mc_io *mc_io,
241 			uint32_t cmd_flags,
242 			uint16_t token,
243 			uint8_t queue,
244 			struct dpseci_rx_queue_attr *attr);
245 
246 /**
247  * struct dpseci_tx_queue_attr - Structure representing attributes of Tx queues
248  * @fqid: Virtual FQID to be used for sending frames to SEC hardware
249  * @priority: SEC hardware processing priority for the queue
250  */
251 struct dpseci_tx_queue_attr {
252 	uint32_t fqid;
253 	uint8_t priority;
254 };
255 
256 int dpseci_get_tx_queue(struct fsl_mc_io *mc_io,
257 			uint32_t cmd_flags,
258 			uint16_t token,
259 			uint8_t queue,
260 			struct dpseci_tx_queue_attr *attr);
261 
262 /**
263  * struct dpseci_sec_attr - Structure representing attributes of the SEC
264  *				hardware accelerator
265  * @ip_id:		ID for SEC.
266  * @major_rev:		Major revision number for SEC.
267  * @minor_rev:		Minor revision number for SEC.
268  * @era:		SEC Era.
269  * @deco_num:		The number of copies of the DECO that are implemented
270  *			in this version of SEC.
271  * @zuc_auth_acc_num:	The number of copies of ZUCA that are implemented
272  *			in this version of SEC.
273  * @zuc_enc_acc_num:	The number of copies of ZUCE that are implemented
274  *			in this version of SEC.
275  * @snow_f8_acc_num:	The number of copies of the SNOW-f8 module that are
276  *			implemented in this version of SEC.
277  * @snow_f9_acc_num:	The number of copies of the SNOW-f9 module that are
278  *			implemented in this version of SEC.
279  * @crc_acc_num:	The number of copies of the CRC module that are
280  *			implemented in this version of SEC.
281  * @pk_acc_num:		The number of copies of the Public Key module that are
282  *			implemented in this version of SEC.
283  * @kasumi_acc_num:	The number of copies of the Kasumi module that are
284  *			implemented in this version of SEC.
285  * @rng_acc_num:	The number of copies of the Random Number Generator that
286  *			are implemented in this version of SEC.
287  * @md_acc_num:		The number of copies of the MDHA (Hashing module) that
288  *			are implemented in this version of SEC.
289  * @arc4_acc_num:	The number of copies of the ARC4 module that are
290  *			implemented in this version of SEC.
291  * @des_acc_num:	The number of copies of the DES module that are
292  *			implemented in this version of SEC.
293  * @aes_acc_num:	The number of copies of the AES module that are
294  *			implemented in this version of SEC.
295  **/
296 
297 struct dpseci_sec_attr {
298 	uint16_t ip_id;
299 	uint8_t major_rev;
300 	uint8_t minor_rev;
301 	uint8_t era;
302 	uint8_t deco_num;
303 	uint8_t zuc_auth_acc_num;
304 	uint8_t zuc_enc_acc_num;
305 	uint8_t snow_f8_acc_num;
306 	uint8_t snow_f9_acc_num;
307 	uint8_t crc_acc_num;
308 	uint8_t pk_acc_num;
309 	uint8_t kasumi_acc_num;
310 	uint8_t rng_acc_num;
311 	uint8_t md_acc_num;
312 	uint8_t arc4_acc_num;
313 	uint8_t des_acc_num;
314 	uint8_t aes_acc_num;
315 };
316 
317 int dpseci_get_sec_attr(struct fsl_mc_io *mc_io,
318 			uint32_t cmd_flags,
319 			uint16_t token,
320 			struct dpseci_sec_attr *attr);
321 
322 /**
323  * struct dpseci_sec_counters - Structure representing global SEC counters and
324  *				not per dpseci counters
325  * @dequeued_requests:	Number of Requests Dequeued
326  * @ob_enc_requests:	Number of Outbound Encrypt Requests
327  * @ib_dec_requests:	Number of Inbound Decrypt Requests
328  * @ob_enc_bytes:	Number of Outbound Bytes Encrypted
329  * @ob_prot_bytes:	Number of Outbound Bytes Protected
330  * @ib_dec_bytes:	Number of Inbound Bytes Decrypted
331  * @ib_valid_bytes:	Number of Inbound Bytes Validated
332  */
333 struct dpseci_sec_counters {
334 	uint64_t dequeued_requests;
335 	uint64_t ob_enc_requests;
336 	uint64_t ib_dec_requests;
337 	uint64_t ob_enc_bytes;
338 	uint64_t ob_prot_bytes;
339 	uint64_t ib_dec_bytes;
340 	uint64_t ib_valid_bytes;
341 };
342 
343 int dpseci_get_sec_counters(struct fsl_mc_io *mc_io,
344 			    uint32_t cmd_flags,
345 			    uint16_t token,
346 			    struct dpseci_sec_counters *counters);
347 
348 int dpseci_get_api_version(struct fsl_mc_io *mc_io,
349 			   uint32_t cmd_flags,
350 			   uint16_t *major_ver,
351 			   uint16_t *minor_ver);
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