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