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.
7 * Copyright 2013-2016 Freescale Semiconductor Inc.
8 * Copyright (c) 2016 NXP.
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.
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
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.
41 #ifndef __FSL_DPSECI_H
42 #define __FSL_DPSECI_H
44 /* Data Path SEC Interface API
45 * Contains initialization APIs and runtime control APIs for DPSECI
51 * General DPSECI macros
55 * Maximum number of Tx/Rx priorities per DPSECI object
57 #define DPSECI_PRIO_NUM 8
60 * All queues considered; see dpseci_set_rx_queue()
62 #define DPSECI_ALL_QUEUES (uint8_t)(-1)
65 * dpseci_open() - Open a control session for the specified object
66 * This function can be used to open a control session for an
67 * already created object; an object may have been declared in
68 * the DPL or by calling the dpseci_create() function.
69 * This function returns a unique authentication token,
70 * associated with the specific object ID and the specific MC
71 * portal; this token must be used in all subsequent commands for
72 * this specific object.
74 * @param mc_io Pointer to MC portal's I/O object
75 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
76 * @param dpseci_id DPSECI unique ID
77 * @param token Returned token; use in subsequent API calls
80 * - Return '0' on Success.
81 * - Return Error code otherwise.
84 dpseci_open(struct fsl_mc_io *mc_io,
90 * dpseci_close() - Close the control session of the object
91 * After this function is called, no further operations are
92 * allowed on the object without opening a new control session.
94 * @param mc_io Pointer to MC portal's I/O object
95 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
96 * @param token Token of DPSECI object
99 * - Return '0' on Success.
100 * - Return Error code otherwise.
103 dpseci_close(struct fsl_mc_io *mc_io,
108 * struct dpseci_cfg - Structure representing DPSECI configuration
111 uint8_t num_tx_queues; /* num of queues towards the SEC */
112 uint8_t num_rx_queues; /* num of queues back from the SEC */
113 uint8_t priorities[DPSECI_PRIO_NUM];
114 /**< Priorities for the SEC hardware processing;
115 * each place in the array is the priority of the tx queue
117 * valid priorities are configured with values 1-8;
122 * dpseci_create() - Create the DPSECI object
123 * Create the DPSECI object, allocate required resources and
124 * perform required initialization.
126 * The object can be created either by declaring it in the
127 * DPL file, or by calling this function.
129 * The function accepts an authentication token of a parent
130 * container that this object should be assigned to. The token
131 * can be '0' so the object will be assigned to the default container.
132 * The newly created object can be opened with the returned
133 * object id and using the container's associated tokens and MC portals.
135 * @param mc_io Pointer to MC portal's I/O object
136 * @param dprc_token Parent container token; '0' for default container
137 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
138 * @param cfg Configuration structure
139 * @param obj_id returned object id
142 * - Return '0' on Success.
143 * - Return Error code otherwise.
146 dpseci_create(struct fsl_mc_io *mc_io,
149 const struct dpseci_cfg *cfg,
153 * dpseci_destroy() - Destroy the DPSECI object and release all its resources.
154 * The function accepts the authentication token of the parent container that
155 * created the object (not the one that currently owns the object). The object
156 * is searched within parent using the provided 'object_id'.
157 * All tokens to the object must be closed before calling destroy.
159 * @param mc_io Pointer to MC portal's I/O object
160 * @param dprc_token Parent container token; '0' for default container
161 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
162 * @param object_id The object id; it must be a valid id within the
163 * container that created this object;
166 * - Return '0' on Success.
167 * - Return Error code otherwise.
170 dpseci_destroy(struct fsl_mc_io *mc_io,
176 * dpseci_enable() - Enable the DPSECI, allow sending and receiving frames.
177 * @param mc_io Pointer to MC portal's I/O object
178 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
179 * @param token Token of DPSECI object
182 * - Return '0' on Success.
183 * - Return Error code otherwise.
186 dpseci_enable(struct fsl_mc_io *mc_io,
191 * dpseci_disable() - Disable the DPSECI, stop sending and receiving frames.
192 * @param mc_io Pointer to MC portal's I/O object
193 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
194 * @param token Token of DPSECI object
197 * - Return '0' on Success.
198 * - Return Error code otherwise.
201 dpseci_disable(struct fsl_mc_io *mc_io,
206 * dpseci_is_enabled() - Check if the DPSECI is enabled.
207 * @param mc_io Pointer to MC portal's I/O object
208 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
209 * @param token Token of DPSECI object
210 * @param en Returns '1' if object is enabled; '0' otherwise
213 * - Return '0' on Success.
214 * - Return Error code otherwise.
217 dpseci_is_enabled(struct fsl_mc_io *mc_io,
223 * dpseci_reset() - Reset the DPSECI, returns the object to initial state.
224 * @param mc_io Pointer to MC portal's I/O object
225 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
226 * @param token Token of DPSECI object
229 * - Return '0' on Success.
230 * - Return Error code otherwise.
233 dpseci_reset(struct fsl_mc_io *mc_io,
238 * struct dpseci_irq_cfg - IRQ configuration
240 struct dpseci_irq_cfg {
242 /* Address that must be written to signal a message-based interrupt */
244 /* Value to write into irq_addr address */
246 /* A user defined number associated with this IRQ */
250 * dpseci_set_irq() - Set IRQ information for the DPSECI to trigger an interrupt
251 * @param mc_io Pointer to MC portal's I/O object
252 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
253 * @param token Token of DPSECI object
254 * @param irq_index Identifies the interrupt index to configure
255 * @param irq_cfg IRQ configuration
258 * - Return '0' on Success.
259 * - Return Error code otherwise.
262 dpseci_set_irq(struct fsl_mc_io *mc_io,
266 struct dpseci_irq_cfg *irq_cfg);
269 * dpseci_get_irq() - Get IRQ information from the DPSECI
271 * @param mc_io Pointer to MC portal's I/O object
272 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
273 * @param token Token of DPSECI object
274 * @param irq_index The interrupt index to configure
275 * @param type Interrupt type: 0 represents message interrupt
276 * type (both irq_addr and irq_val are valid)
277 * @param irq_cfg IRQ attributes
280 * - Return '0' on Success.
281 * - Return Error code otherwise.
284 dpseci_get_irq(struct fsl_mc_io *mc_io,
289 struct dpseci_irq_cfg *irq_cfg);
292 * dpseci_set_irq_enable() - Set overall interrupt state.
293 * Allows GPP software to control when interrupts are generated.
294 * Each interrupt can have up to 32 causes. The enable/disable control's the
295 * overall interrupt state. if the interrupt is disabled no causes will cause
298 * @param mc_io Pointer to MC portal's I/O object
299 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
300 * @param token Token of DPSECI object
301 * @param irq_index The interrupt index to configure
302 * @param en Interrupt state - enable = 1, disable = 0
305 * - Return '0' on Success.
306 * - Return Error code otherwise.
309 dpseci_set_irq_enable(struct fsl_mc_io *mc_io,
316 * dpseci_get_irq_enable() - Get overall interrupt state
317 * @param mc_io Pointer to MC portal's I/O object
318 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
319 * @param token Token of DPSECI object
320 * @param irq_index The interrupt index to configure
321 * @param en Returned Interrupt state - enable = 1,
325 * - Return '0' on Success.
326 * - Return Error code otherwise.
329 dpseci_get_irq_enable(struct fsl_mc_io *mc_io,
336 * dpseci_set_irq_mask() - Set interrupt mask.
337 * Every interrupt can have up to 32 causes and the interrupt model supports
338 * masking/unmasking each cause independently
340 * @param mc_io Pointer to MC portal's I/O object
341 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
342 * @param token Token of DPSECI object
343 * @param irq_index The interrupt index to configure
344 * @param mask event mask to trigger interrupt;
347 * 1 = consider event for asserting IRQ
350 * - Return '0' on Success.
351 * - Return Error code otherwise.
354 dpseci_set_irq_mask(struct fsl_mc_io *mc_io,
361 * dpseci_get_irq_mask() - Get interrupt mask.
362 * Every interrupt can have up to 32 causes and the interrupt model supports
363 * masking/unmasking each cause independently
365 * @param mc_io Pointer to MC portal's I/O object
366 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
367 * @param token Token of DPSECI object
368 * @param irq_index The interrupt index to configure
369 * @param mask Returned event mask to trigger interrupt
372 * - Return '0' on Success.
373 * - Return Error code otherwise.
376 dpseci_get_irq_mask(struct fsl_mc_io *mc_io,
383 * dpseci_get_irq_status() - Get the current status of any pending interrupts
384 * @param mc_io Pointer to MC portal's I/O object
385 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
386 * @param token Token of DPSECI object
387 * @param irq_index The interrupt index to configure
388 * @param status Returned interrupts status - one bit per cause:
389 * 0 = no interrupt pending
390 * 1 = interrupt pending
393 * - Return '0' on Success.
394 * - Return Error code otherwise.
397 dpseci_get_irq_status(struct fsl_mc_io *mc_io,
404 * dpseci_clear_irq_status() - Clear a pending interrupt's status
405 * @param mc_io Pointer to MC portal's I/O object
406 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
407 * @param token Token of DPSECI object
408 * @param irq_index The interrupt index to configure
409 * @param status bits to clear (W1C) - one bit per cause:
411 * 1 = clear status bit
414 * - Return '0' on Success.
415 * - Return Error code otherwise.
418 dpseci_clear_irq_status(struct fsl_mc_io *mc_io,
425 * struct dpseci_attr - Structure representing DPSECI attributes
426 * @param id: DPSECI object ID
427 * @param num_tx_queues: number of queues towards the SEC
428 * @param num_rx_queues: number of queues back from the SEC
431 int id; /* DPSECI object ID */
432 uint8_t num_tx_queues; /* number of queues towards the SEC */
433 uint8_t num_rx_queues; /* number of queues back from the SEC */
437 * dpseci_get_attributes() - Retrieve DPSECI attributes.
438 * @param mc_io Pointer to MC portal's I/O object
439 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
440 * @param token Token of DPSECI object
441 * @param attr Returned object's attributes
444 * - Return '0' on Success.
445 * - Return Error code otherwise.
448 dpseci_get_attributes(struct fsl_mc_io *mc_io,
451 struct dpseci_attr *attr);
454 * enum dpseci_dest - DPSECI destination types
455 * @DPSECI_DEST_NONE: Unassigned destination; The queue is set in parked mode
456 * and does not generate FQDAN notifications; user is expected to
457 * dequeue from the queue based on polling or other user-defined
459 * @DPSECI_DEST_DPIO: The queue is set in schedule mode and generates FQDAN
460 * notifications to the specified DPIO; user is expected to dequeue
461 * from the queue only after notification is received
462 * @DPSECI_DEST_DPCON: The queue is set in schedule mode and does not generate
463 * FQDAN notifications, but is connected to the specified DPCON
464 * object; user is expected to dequeue from the DPCON channel
467 DPSECI_DEST_NONE = 0,
468 DPSECI_DEST_DPIO = 1,
469 DPSECI_DEST_DPCON = 2
473 * struct dpseci_dest_cfg - Structure representing DPSECI destination parameters
475 struct dpseci_dest_cfg {
476 enum dpseci_dest dest_type; /* Destination type */
478 /* Either DPIO ID or DPCON ID, depending on the destination type */
480 /* Priority selection within the DPIO or DPCON channel; valid values
481 * are 0-1 or 0-7, depending on the number of priorities in that
482 * channel; not relevant for 'DPSECI_DEST_NONE' option
487 * DPSECI queue modification options
491 * Select to modify the user's context associated with the queue
493 #define DPSECI_QUEUE_OPT_USER_CTX 0x00000001
496 * Select to modify the queue's destination
498 #define DPSECI_QUEUE_OPT_DEST 0x00000002
501 * Select to modify the queue's order preservation
503 #define DPSECI_QUEUE_OPT_ORDER_PRESERVATION 0x00000004
506 * struct dpseci_rx_queue_cfg - DPSECI RX queue configuration
508 struct dpseci_rx_queue_cfg {
510 /* Flags representing the suggested modifications to the queue;
511 * Use any combination of 'DPSECI_QUEUE_OPT_<X>' flags
513 int order_preservation_en;
514 /* order preservation configuration for the rx queue
515 * valid only if 'DPSECI_QUEUE_OPT_ORDER_PRESERVATION' is contained in
519 /* User context value provided in the frame descriptor of each
521 * valid only if 'DPSECI_QUEUE_OPT_USER_CTX' is contained in 'options'
523 struct dpseci_dest_cfg dest_cfg;
524 /* Queue destination parameters;
525 * valid only if 'DPSECI_QUEUE_OPT_DEST' is contained in 'options'
530 * dpseci_set_rx_queue() - Set Rx queue configuration
531 * @param mc_io Pointer to MC portal's I/O object
532 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
533 * @param token Token of DPSECI object
534 * @param queue Select the queue relative to number of
535 * priorities configured at DPSECI creation; use
536 * DPSECI_ALL_QUEUES to configure all Rx queues
538 * @param cfg Rx queue configuration
541 * - Return '0' on Success.
542 * - Return Error code otherwise.
545 dpseci_set_rx_queue(struct fsl_mc_io *mc_io,
549 const struct dpseci_rx_queue_cfg *cfg);
552 * struct dpseci_rx_queue_attr - Structure representing attributes of Rx queues
554 struct dpseci_rx_queue_attr {
556 /* User context value provided in the frame descriptor of
557 * each dequeued frame
559 int order_preservation_en;
560 /* Status of the order preservation configuration on the queue */
561 struct dpseci_dest_cfg dest_cfg;
562 /* Queue destination configuration */
564 /* Virtual FQID value to be used for dequeue operations */
568 * dpseci_get_rx_queue() - Retrieve Rx queue attributes.
569 * @param mc_io Pointer to MC portal's I/O object
570 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
571 * @param token Token of DPSECI object
572 * @param queue Select the queue relative to number of
573 * priorities configured at DPSECI creation
574 * @param attr Returned Rx queue attributes
577 * - Return '0' on Success.
578 * - Return Error code otherwise.
581 dpseci_get_rx_queue(struct fsl_mc_io *mc_io,
585 struct dpseci_rx_queue_attr *attr);
588 * struct dpseci_tx_queue_attr - Structure representing attributes of Tx queues
590 struct dpseci_tx_queue_attr {
592 /* Virtual FQID to be used for sending frames to SEC hardware */
594 /* SEC hardware processing priority for the queue */
598 * dpseci_get_tx_queue() - Retrieve Tx queue attributes.
599 * @param mc_io Pointer to MC portal's I/O object
600 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
601 * @param token Token of DPSECI object
602 * @param queue Select the queue relative to number of
603 * priorities configured at DPSECI creation
604 * @param attr Returned Tx queue attributes
607 * - Return '0' on Success.
608 * - Return Error code otherwise.
611 dpseci_get_tx_queue(struct fsl_mc_io *mc_io,
615 struct dpseci_tx_queue_attr *attr);
618 * struct dpseci_sec_attr - Structure representing attributes of the SEC
619 * hardware accelerator
622 struct dpseci_sec_attr {
623 uint16_t ip_id; /* ID for SEC */
624 uint8_t major_rev; /* Major revision number for SEC */
625 uint8_t minor_rev; /* Minor revision number for SEC */
626 uint8_t era; /* SEC Era */
628 /* The number of copies of the DECO that are implemented in
629 * this version of SEC
631 uint8_t zuc_auth_acc_num;
632 /* The number of copies of ZUCA that are implemented in this
635 uint8_t zuc_enc_acc_num;
636 /* The number of copies of ZUCE that are implemented in this
639 uint8_t snow_f8_acc_num;
640 /* The number of copies of the SNOW-f8 module that are
641 * implemented in this version of SEC
643 uint8_t snow_f9_acc_num;
644 /* The number of copies of the SNOW-f9 module that are
645 * implemented in this version of SEC
648 /* The number of copies of the CRC module that are implemented
649 * in this version of SEC
652 /* The number of copies of the Public Key module that are
653 * implemented in this version of SEC
655 uint8_t kasumi_acc_num;
656 /* The number of copies of the Kasumi module that are
657 * implemented in this version of SEC
660 /* The number of copies of the Random Number Generator that are
661 * implemented in this version of SEC
664 /* The number of copies of the MDHA (Hashing module) that are
665 * implemented in this version of SEC
667 uint8_t arc4_acc_num;
668 /* The number of copies of the ARC4 module that are implemented
669 * in this version of SEC
672 /* The number of copies of the DES module that are implemented
673 * in this version of SEC
676 /* The number of copies of the AES module that are implemented
677 * in this version of SEC
682 * dpseci_get_sec_attr() - Retrieve SEC accelerator attributes.
683 * @param mc_io Pointer to MC portal's I/O object
684 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
685 * @param token Token of DPSECI object
686 * @param attr Returned SEC attributes
689 * - Return '0' on Success.
690 * - Return Error code otherwise.
693 dpseci_get_sec_attr(struct fsl_mc_io *mc_io,
696 struct dpseci_sec_attr *attr);
699 * struct dpseci_sec_counters - Structure representing global SEC counters and
700 * not per dpseci counters
702 struct dpseci_sec_counters {
703 uint64_t dequeued_requests; /* Number of Requests Dequeued */
704 uint64_t ob_enc_requests; /* Number of Outbound Encrypt Requests */
705 uint64_t ib_dec_requests; /* Number of Inbound Decrypt Requests */
706 uint64_t ob_enc_bytes; /* Number of Outbound Bytes Encrypted */
707 uint64_t ob_prot_bytes; /* Number of Outbound Bytes Protected */
708 uint64_t ib_dec_bytes; /* Number of Inbound Bytes Decrypted */
709 uint64_t ib_valid_bytes; /* Number of Inbound Bytes Validated */
713 * dpseci_get_sec_counters() - Retrieve SEC accelerator counters.
714 * @param mc_io Pointer to MC portal's I/O object
715 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
716 * @param token Token of DPSECI object
717 * @param counters Returned SEC counters
720 * - Return '0' on Success.
721 * - Return Error code otherwise.
724 dpseci_get_sec_counters(struct fsl_mc_io *mc_io,
727 struct dpseci_sec_counters *counters);
730 * dpseci_get_api_version() - Get Data Path SEC Interface API version
731 * @param mc_io Pointer to MC portal's I/O object
732 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
733 * @param major_ver Major version of data path sec API
734 * @param minor_ver Minor version of data path sec API
737 * - Return '0' on Success.
738 * - Return Error code otherwise.
741 dpseci_get_api_version(struct fsl_mc_io *mc_io,
744 uint16_t *minor_ver);
746 #endif /* __FSL_DPSECI_H */