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