New upstream version 18.11-rc1
[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_MAX_QUEUE_NUM            16
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_MAX_QUEUE_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  * @ccha_acc_num:       The number of copies of the ChaCha20 module that are
263  *                      implemented in this version of SEC.
264  * @ptha_acc_num:       The number of copies of the Poly1305 module that are
265  *                      implemented in this version of SEC.
266  **/
267
268 struct dpseci_sec_attr {
269         uint16_t ip_id;
270         uint8_t major_rev;
271         uint8_t minor_rev;
272         uint8_t era;
273         uint8_t deco_num;
274         uint8_t zuc_auth_acc_num;
275         uint8_t zuc_enc_acc_num;
276         uint8_t snow_f8_acc_num;
277         uint8_t snow_f9_acc_num;
278         uint8_t crc_acc_num;
279         uint8_t pk_acc_num;
280         uint8_t kasumi_acc_num;
281         uint8_t rng_acc_num;
282         uint8_t md_acc_num;
283         uint8_t arc4_acc_num;
284         uint8_t des_acc_num;
285         uint8_t aes_acc_num;
286         uint8_t ccha_acc_num;
287         uint8_t ptha_acc_num;
288 };
289
290 int dpseci_get_sec_attr(struct fsl_mc_io *mc_io,
291                         uint32_t cmd_flags,
292                         uint16_t token,
293                         struct dpseci_sec_attr *attr);
294
295 /**
296  * struct dpseci_sec_counters - Structure representing global SEC counters and
297  *                              not per dpseci counters
298  * @dequeued_requests:  Number of Requests Dequeued
299  * @ob_enc_requests:    Number of Outbound Encrypt Requests
300  * @ib_dec_requests:    Number of Inbound Decrypt Requests
301  * @ob_enc_bytes:       Number of Outbound Bytes Encrypted
302  * @ob_prot_bytes:      Number of Outbound Bytes Protected
303  * @ib_dec_bytes:       Number of Inbound Bytes Decrypted
304  * @ib_valid_bytes:     Number of Inbound Bytes Validated
305  */
306 struct dpseci_sec_counters {
307         uint64_t dequeued_requests;
308         uint64_t ob_enc_requests;
309         uint64_t ib_dec_requests;
310         uint64_t ob_enc_bytes;
311         uint64_t ob_prot_bytes;
312         uint64_t ib_dec_bytes;
313         uint64_t ib_valid_bytes;
314 };
315
316 int dpseci_get_sec_counters(struct fsl_mc_io *mc_io,
317                             uint32_t cmd_flags,
318                             uint16_t token,
319                             struct dpseci_sec_counters *counters);
320
321 int dpseci_get_api_version(struct fsl_mc_io *mc_io,
322                            uint32_t cmd_flags,
323                            uint16_t *major_ver,
324                            uint16_t *minor_ver);
325
326 int dpseci_set_opr(struct fsl_mc_io *mc_io,
327                    uint32_t cmd_flags,
328                    uint16_t token,
329                    uint8_t index,
330                    uint8_t options,
331                    struct opr_cfg *cfg);
332
333 int dpseci_get_opr(struct fsl_mc_io *mc_io,
334                    uint32_t cmd_flags,
335                    uint16_t token,
336                    uint8_t index,
337                    struct opr_cfg *cfg,
338                    struct opr_qry *qry);
339
340 /**
341  * enum dpseci_congestion_unit - DPSECI congestion units
342  * @DPSECI_CONGESTION_UNIT_BYTES: bytes units
343  * @DPSECI_CONGESTION_UNIT_FRAMES: frames units
344  */
345 enum dpseci_congestion_unit {
346         DPSECI_CONGESTION_UNIT_BYTES = 0,
347         DPSECI_CONGESTION_UNIT_FRAMES
348 };
349
350 /**
351  * CSCN message is written to message_iova once entering a
352  * congestion state (see 'threshold_entry')
353  */
354 #define DPSECI_CGN_MODE_WRITE_MEM_ON_ENTER              0x00000001
355 /**
356  * CSCN message is written to message_iova once exiting a
357  * congestion state (see 'threshold_exit')
358  */
359 #define DPSECI_CGN_MODE_WRITE_MEM_ON_EXIT               0x00000002
360 /**
361  * CSCN write will attempt to allocate into a cache (coherent write);
362  * valid only if 'DPSECI_CGN_MODE_WRITE_MEM_<X>' is selected
363  */
364 #define DPSECI_CGN_MODE_COHERENT_WRITE                  0x00000004
365 /**
366  * if 'dpseci_dest_cfg.dest_type != DPSECI_DEST_NONE' CSCN message is sent to
367  * DPIO/DPCON's WQ channel once entering a congestion state
368  * (see 'threshold_entry')
369  */
370 #define DPSECI_CGN_MODE_NOTIFY_DEST_ON_ENTER            0x00000008
371 /**
372  * if 'dpseci_dest_cfg.dest_type != DPSECI_DEST_NONE' CSCN message is sent to
373  * DPIO/DPCON's WQ channel once exiting a congestion state
374  * (see 'threshold_exit')
375  */
376 #define DPSECI_CGN_MODE_NOTIFY_DEST_ON_EXIT             0x00000010
377 /**
378  * if 'dpseci_dest_cfg.dest_type != DPSECI_DEST_NONE' when the CSCN is written
379  * to the sw-portal's DQRR, the DQRI interrupt is asserted immediately
380  * (if enabled)
381  */
382 #define DPSECI_CGN_MODE_INTR_COALESCING_DISABLED        0x00000020
383
384 /**
385  * struct dpseci_congestion_notification_cfg - congestion notification
386  *              configuration
387  * @units: units type
388  * @threshold_entry: above this threshold we enter a congestion state.
389  *              set it to '0' to disable it
390  * @threshold_exit: below this threshold we exit the congestion state.
391  * @message_ctx: The context that will be part of the CSCN message
392  * @message_iova: I/O virtual address (must be in DMA-able memory),
393  *              must be 16B aligned;
394  * @dest_cfg: CSCN can be send to either DPIO or DPCON WQ channel
395  * @notification_mode: Mask of available options; use 'DPSECI_CGN_MODE_<X>'
396  *              values
397  */
398 struct dpseci_congestion_notification_cfg {
399         enum dpseci_congestion_unit units;
400         uint32_t threshold_entry;
401         uint32_t threshold_exit;
402         uint64_t message_ctx;
403         uint64_t message_iova;
404         struct dpseci_dest_cfg dest_cfg;
405         uint16_t notification_mode;
406 };
407
408 int dpseci_set_congestion_notification(
409                         struct fsl_mc_io *mc_io,
410                         uint32_t cmd_flags,
411                         uint16_t token,
412                         const struct dpseci_congestion_notification_cfg *cfg);
413
414 int dpseci_get_congestion_notification(
415                         struct fsl_mc_io *mc_io,
416                         uint32_t cmd_flags,
417                         uint16_t token,
418                         struct dpseci_congestion_notification_cfg *cfg);
419
420 #endif /* __FSL_DPSECI_H */