1 /* Copyright 2013-2016 Freescale Semiconductor Inc.
2 * Copyright (c) 2016 NXP.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the above-listed copyright holders nor the
12 * names of any contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
16 * ALTERNATIVELY, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL") as published by the Free Software
18 * Foundation, either version 2 of that License or (at your option) any
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
34 #ifndef __FSL_DPSECI_H
35 #define __FSL_DPSECI_H
37 /* Data Path SEC Interface API
38 * Contains initialization APIs and runtime control APIs for DPSECI
44 * General DPSECI macros
48 * Maximum number of Tx/Rx priorities per DPSECI object
50 #define DPSECI_PRIO_NUM 8
53 * All queues considered; see dpseci_set_rx_queue()
55 #define DPSECI_ALL_QUEUES (uint8_t)(-1)
58 * dpseci_open() - Open a control session for the specified object
59 * This function can be used to open a control session for an
60 * already created object; an object may have been declared in
61 * the DPL or by calling the dpseci_create() function.
62 * This function returns a unique authentication token,
63 * associated with the specific object ID and the specific MC
64 * portal; this token must be used in all subsequent commands for
65 * this specific object.
67 * @param mc_io Pointer to MC portal's I/O object
68 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
69 * @param dpseci_id DPSECI unique ID
70 * @param token Returned token; use in subsequent API calls
73 * - Return '0' on Success.
74 * - Return Error code otherwise.
77 dpseci_open(struct fsl_mc_io *mc_io,
83 * dpseci_close() - Close the control session of the object
84 * After this function is called, no further operations are
85 * allowed on the object without opening a new control session.
87 * @param mc_io Pointer to MC portal's I/O object
88 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
89 * @param token Token of DPSECI object
92 * - Return '0' on Success.
93 * - Return Error code otherwise.
96 dpseci_close(struct fsl_mc_io *mc_io,
101 * struct dpseci_cfg - Structure representing DPSECI configuration
104 uint8_t num_tx_queues; /* num of queues towards the SEC */
105 uint8_t num_rx_queues; /* num of queues back from the SEC */
106 uint8_t priorities[DPSECI_PRIO_NUM];
107 /**< Priorities for the SEC hardware processing;
108 * each place in the array is the priority of the tx queue
110 * valid priorities are configured with values 1-8;
115 * dpseci_create() - Create the DPSECI object
116 * Create the DPSECI object, allocate required resources and
117 * perform required initialization.
119 * The object can be created either by declaring it in the
120 * DPL file, or by calling this function.
122 * The function accepts an authentication token of a parent
123 * container that this object should be assigned to. The token
124 * can be '0' so the object will be assigned to the default container.
125 * The newly created object can be opened with the returned
126 * object id and using the container's associated tokens and MC portals.
128 * @param mc_io Pointer to MC portal's I/O object
129 * @param dprc_token Parent container token; '0' for default container
130 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
131 * @param cfg Configuration structure
132 * @param obj_id returned object id
135 * - Return '0' on Success.
136 * - Return Error code otherwise.
139 dpseci_create(struct fsl_mc_io *mc_io,
142 const struct dpseci_cfg *cfg,
146 * dpseci_destroy() - Destroy the DPSECI object and release all its resources.
147 * The function accepts the authentication token of the parent container that
148 * created the object (not the one that currently owns the object). The object
149 * is searched within parent using the provided 'object_id'.
150 * All tokens to the object must be closed before calling destroy.
152 * @param mc_io Pointer to MC portal's I/O object
153 * @param dprc_token Parent container token; '0' for default container
154 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
155 * @param object_id The object id; it must be a valid id within the
156 * container that created this object;
159 * - Return '0' on Success.
160 * - Return Error code otherwise.
163 dpseci_destroy(struct fsl_mc_io *mc_io,
169 * dpseci_enable() - Enable the DPSECI, allow sending and receiving frames.
170 * @param mc_io Pointer to MC portal's I/O object
171 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
172 * @param token Token of DPSECI object
175 * - Return '0' on Success.
176 * - Return Error code otherwise.
179 dpseci_enable(struct fsl_mc_io *mc_io,
184 * dpseci_disable() - Disable the DPSECI, stop sending and receiving frames.
185 * @param mc_io Pointer to MC portal's I/O object
186 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
187 * @param token Token of DPSECI object
190 * - Return '0' on Success.
191 * - Return Error code otherwise.
194 dpseci_disable(struct fsl_mc_io *mc_io,
199 * dpseci_is_enabled() - Check if the DPSECI is enabled.
200 * @param mc_io Pointer to MC portal's I/O object
201 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
202 * @param token Token of DPSECI object
203 * @param en Returns '1' if object is enabled; '0' otherwise
206 * - Return '0' on Success.
207 * - Return Error code otherwise.
210 dpseci_is_enabled(struct fsl_mc_io *mc_io,
216 * dpseci_reset() - Reset the DPSECI, returns the object to initial state.
217 * @param mc_io Pointer to MC portal's I/O object
218 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
219 * @param token Token of DPSECI object
222 * - Return '0' on Success.
223 * - Return Error code otherwise.
226 dpseci_reset(struct fsl_mc_io *mc_io,
231 * struct dpseci_irq_cfg - IRQ configuration
233 struct dpseci_irq_cfg {
235 /* Address that must be written to signal a message-based interrupt */
237 /* Value to write into irq_addr address */
239 /* A user defined number associated with this IRQ */
243 * dpseci_set_irq() - Set IRQ information for the DPSECI to trigger an interrupt
244 * @param mc_io Pointer to MC portal's I/O object
245 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
246 * @param token Token of DPSECI object
247 * @param irq_index Identifies the interrupt index to configure
248 * @param irq_cfg IRQ configuration
251 * - Return '0' on Success.
252 * - Return Error code otherwise.
255 dpseci_set_irq(struct fsl_mc_io *mc_io,
259 struct dpseci_irq_cfg *irq_cfg);
262 * dpseci_get_irq() - Get IRQ information from the DPSECI
264 * @param mc_io Pointer to MC portal's I/O object
265 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
266 * @param token Token of DPSECI object
267 * @param irq_index The interrupt index to configure
268 * @param type Interrupt type: 0 represents message interrupt
269 * type (both irq_addr and irq_val are valid)
270 * @param irq_cfg IRQ attributes
273 * - Return '0' on Success.
274 * - Return Error code otherwise.
277 dpseci_get_irq(struct fsl_mc_io *mc_io,
282 struct dpseci_irq_cfg *irq_cfg);
285 * dpseci_set_irq_enable() - Set overall interrupt state.
286 * Allows GPP software to control when interrupts are generated.
287 * Each interrupt can have up to 32 causes. The enable/disable control's the
288 * overall interrupt state. if the interrupt is disabled no causes will cause
291 * @param mc_io Pointer to MC portal's I/O object
292 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
293 * @param token Token of DPSECI object
294 * @param irq_index The interrupt index to configure
295 * @param en Interrupt state - enable = 1, disable = 0
298 * - Return '0' on Success.
299 * - Return Error code otherwise.
302 dpseci_set_irq_enable(struct fsl_mc_io *mc_io,
309 * dpseci_get_irq_enable() - Get overall interrupt state
310 * @param mc_io Pointer to MC portal's I/O object
311 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
312 * @param token Token of DPSECI object
313 * @param irq_index The interrupt index to configure
314 * @param en Returned Interrupt state - enable = 1,
318 * - Return '0' on Success.
319 * - Return Error code otherwise.
322 dpseci_get_irq_enable(struct fsl_mc_io *mc_io,
329 * dpseci_set_irq_mask() - Set interrupt mask.
330 * Every interrupt can have up to 32 causes and the interrupt model supports
331 * masking/unmasking each cause independently
333 * @param mc_io Pointer to MC portal's I/O object
334 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
335 * @param token Token of DPSECI object
336 * @param irq_index The interrupt index to configure
337 * @param mask event mask to trigger interrupt;
340 * 1 = consider event for asserting IRQ
343 * - Return '0' on Success.
344 * - Return Error code otherwise.
347 dpseci_set_irq_mask(struct fsl_mc_io *mc_io,
354 * dpseci_get_irq_mask() - Get interrupt mask.
355 * Every interrupt can have up to 32 causes and the interrupt model supports
356 * masking/unmasking each cause independently
358 * @param mc_io Pointer to MC portal's I/O object
359 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
360 * @param token Token of DPSECI object
361 * @param irq_index The interrupt index to configure
362 * @param mask Returned event mask to trigger interrupt
365 * - Return '0' on Success.
366 * - Return Error code otherwise.
369 dpseci_get_irq_mask(struct fsl_mc_io *mc_io,
376 * dpseci_get_irq_status() - Get the current status of any pending interrupts
377 * @param mc_io Pointer to MC portal's I/O object
378 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
379 * @param token Token of DPSECI object
380 * @param irq_index The interrupt index to configure
381 * @param status Returned interrupts status - one bit per cause:
382 * 0 = no interrupt pending
383 * 1 = interrupt pending
386 * - Return '0' on Success.
387 * - Return Error code otherwise.
390 dpseci_get_irq_status(struct fsl_mc_io *mc_io,
397 * dpseci_clear_irq_status() - Clear a pending interrupt's status
398 * @param mc_io Pointer to MC portal's I/O object
399 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
400 * @param token Token of DPSECI object
401 * @param irq_index The interrupt index to configure
402 * @param status bits to clear (W1C) - one bit per cause:
404 * 1 = clear status bit
407 * - Return '0' on Success.
408 * - Return Error code otherwise.
411 dpseci_clear_irq_status(struct fsl_mc_io *mc_io,
418 * struct dpseci_attr - Structure representing DPSECI attributes
419 * @param id: DPSECI object ID
420 * @param num_tx_queues: number of queues towards the SEC
421 * @param num_rx_queues: number of queues back from the SEC
424 int id; /* DPSECI object ID */
425 uint8_t num_tx_queues; /* number of queues towards the SEC */
426 uint8_t num_rx_queues; /* number of queues back from the SEC */
430 * dpseci_get_attributes() - Retrieve DPSECI attributes.
431 * @param mc_io Pointer to MC portal's I/O object
432 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
433 * @param token Token of DPSECI object
434 * @param attr Returned object's attributes
437 * - Return '0' on Success.
438 * - Return Error code otherwise.
441 dpseci_get_attributes(struct fsl_mc_io *mc_io,
444 struct dpseci_attr *attr);
447 * enum dpseci_dest - DPSECI destination types
448 * @DPSECI_DEST_NONE: Unassigned destination; The queue is set in parked mode
449 * and does not generate FQDAN notifications; user is expected to
450 * dequeue from the queue based on polling or other user-defined
452 * @DPSECI_DEST_DPIO: The queue is set in schedule mode and generates FQDAN
453 * notifications to the specified DPIO; user is expected to dequeue
454 * from the queue only after notification is received
455 * @DPSECI_DEST_DPCON: The queue is set in schedule mode and does not generate
456 * FQDAN notifications, but is connected to the specified DPCON
457 * object; user is expected to dequeue from the DPCON channel
460 DPSECI_DEST_NONE = 0,
461 DPSECI_DEST_DPIO = 1,
462 DPSECI_DEST_DPCON = 2
466 * struct dpseci_dest_cfg - Structure representing DPSECI destination parameters
468 struct dpseci_dest_cfg {
469 enum dpseci_dest dest_type; /* Destination type */
471 /* Either DPIO ID or DPCON ID, depending on the destination type */
473 /* Priority selection within the DPIO or DPCON channel; valid values
474 * are 0-1 or 0-7, depending on the number of priorities in that
475 * channel; not relevant for 'DPSECI_DEST_NONE' option
480 * DPSECI queue modification options
484 * Select to modify the user's context associated with the queue
486 #define DPSECI_QUEUE_OPT_USER_CTX 0x00000001
489 * Select to modify the queue's destination
491 #define DPSECI_QUEUE_OPT_DEST 0x00000002
494 * Select to modify the queue's order preservation
496 #define DPSECI_QUEUE_OPT_ORDER_PRESERVATION 0x00000004
499 * struct dpseci_rx_queue_cfg - DPSECI RX queue configuration
501 struct dpseci_rx_queue_cfg {
503 /* Flags representing the suggested modifications to the queue;
504 * Use any combination of 'DPSECI_QUEUE_OPT_<X>' flags
506 int order_preservation_en;
507 /* order preservation configuration for the rx queue
508 * valid only if 'DPSECI_QUEUE_OPT_ORDER_PRESERVATION' is contained in
512 /* User context value provided in the frame descriptor of each
514 * valid only if 'DPSECI_QUEUE_OPT_USER_CTX' is contained in 'options'
516 struct dpseci_dest_cfg dest_cfg;
517 /* Queue destination parameters;
518 * valid only if 'DPSECI_QUEUE_OPT_DEST' is contained in 'options'
523 * dpseci_set_rx_queue() - Set Rx queue configuration
524 * @param mc_io Pointer to MC portal's I/O object
525 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
526 * @param token Token of DPSECI object
527 * @param queue Select the queue relative to number of
528 * priorities configured at DPSECI creation; use
529 * DPSECI_ALL_QUEUES to configure all Rx queues
531 * @param cfg Rx queue configuration
534 * - Return '0' on Success.
535 * - Return Error code otherwise.
538 dpseci_set_rx_queue(struct fsl_mc_io *mc_io,
542 const struct dpseci_rx_queue_cfg *cfg);
545 * struct dpseci_rx_queue_attr - Structure representing attributes of Rx queues
547 struct dpseci_rx_queue_attr {
549 /* User context value provided in the frame descriptor of
550 * each dequeued frame
552 int order_preservation_en;
553 /* Status of the order preservation configuration on the queue */
554 struct dpseci_dest_cfg dest_cfg;
555 /* Queue destination configuration */
557 /* Virtual FQID value to be used for dequeue operations */
561 * dpseci_get_rx_queue() - Retrieve Rx queue attributes.
562 * @param mc_io Pointer to MC portal's I/O object
563 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
564 * @param token Token of DPSECI object
565 * @param queue Select the queue relative to number of
566 * priorities configured at DPSECI creation
567 * @param attr Returned Rx queue attributes
570 * - Return '0' on Success.
571 * - Return Error code otherwise.
574 dpseci_get_rx_queue(struct fsl_mc_io *mc_io,
578 struct dpseci_rx_queue_attr *attr);
581 * struct dpseci_tx_queue_attr - Structure representing attributes of Tx queues
583 struct dpseci_tx_queue_attr {
585 /* Virtual FQID to be used for sending frames to SEC hardware */
587 /* SEC hardware processing priority for the queue */
591 * dpseci_get_tx_queue() - Retrieve Tx queue attributes.
592 * @param mc_io Pointer to MC portal's I/O object
593 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
594 * @param token Token of DPSECI object
595 * @param queue Select the queue relative to number of
596 * priorities configured at DPSECI creation
597 * @param attr Returned Tx queue attributes
600 * - Return '0' on Success.
601 * - Return Error code otherwise.
604 dpseci_get_tx_queue(struct fsl_mc_io *mc_io,
608 struct dpseci_tx_queue_attr *attr);
611 * struct dpseci_sec_attr - Structure representing attributes of the SEC
612 * hardware accelerator
615 struct dpseci_sec_attr {
616 uint16_t ip_id; /* ID for SEC */
617 uint8_t major_rev; /* Major revision number for SEC */
618 uint8_t minor_rev; /* Minor revision number for SEC */
619 uint8_t era; /* SEC Era */
621 /* The number of copies of the DECO that are implemented in
622 * this version of SEC
624 uint8_t zuc_auth_acc_num;
625 /* The number of copies of ZUCA that are implemented in this
628 uint8_t zuc_enc_acc_num;
629 /* The number of copies of ZUCE that are implemented in this
632 uint8_t snow_f8_acc_num;
633 /* The number of copies of the SNOW-f8 module that are
634 * implemented in this version of SEC
636 uint8_t snow_f9_acc_num;
637 /* The number of copies of the SNOW-f9 module that are
638 * implemented in this version of SEC
641 /* The number of copies of the CRC module that are implemented
642 * in this version of SEC
645 /* The number of copies of the Public Key module that are
646 * implemented in this version of SEC
648 uint8_t kasumi_acc_num;
649 /* The number of copies of the Kasumi module that are
650 * implemented in this version of SEC
653 /* The number of copies of the Random Number Generator that are
654 * implemented in this version of SEC
657 /* The number of copies of the MDHA (Hashing module) that are
658 * implemented in this version of SEC
660 uint8_t arc4_acc_num;
661 /* The number of copies of the ARC4 module that are implemented
662 * in this version of SEC
665 /* The number of copies of the DES module that are implemented
666 * in this version of SEC
669 /* The number of copies of the AES module that are implemented
670 * in this version of SEC
675 * dpseci_get_sec_attr() - Retrieve SEC accelerator attributes.
676 * @param mc_io Pointer to MC portal's I/O object
677 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
678 * @param token Token of DPSECI object
679 * @param attr Returned SEC attributes
682 * - Return '0' on Success.
683 * - Return Error code otherwise.
686 dpseci_get_sec_attr(struct fsl_mc_io *mc_io,
689 struct dpseci_sec_attr *attr);
692 * struct dpseci_sec_counters - Structure representing global SEC counters and
693 * not per dpseci counters
695 struct dpseci_sec_counters {
696 uint64_t dequeued_requests; /* Number of Requests Dequeued */
697 uint64_t ob_enc_requests; /* Number of Outbound Encrypt Requests */
698 uint64_t ib_dec_requests; /* Number of Inbound Decrypt Requests */
699 uint64_t ob_enc_bytes; /* Number of Outbound Bytes Encrypted */
700 uint64_t ob_prot_bytes; /* Number of Outbound Bytes Protected */
701 uint64_t ib_dec_bytes; /* Number of Inbound Bytes Decrypted */
702 uint64_t ib_valid_bytes; /* Number of Inbound Bytes Validated */
706 * dpseci_get_sec_counters() - Retrieve SEC accelerator counters.
707 * @param mc_io Pointer to MC portal's I/O object
708 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
709 * @param token Token of DPSECI object
710 * @param counters Returned SEC counters
713 * - Return '0' on Success.
714 * - Return Error code otherwise.
717 dpseci_get_sec_counters(struct fsl_mc_io *mc_io,
720 struct dpseci_sec_counters *counters);
723 * dpseci_get_api_version() - Get Data Path SEC Interface API version
724 * @param mc_io Pointer to MC portal's I/O object
725 * @param cmd_flags Command flags; one or more of 'MC_CMD_FLAG_'
726 * @param major_ver Major version of data path sec API
727 * @param minor_ver Minor version of data path sec API
730 * - Return '0' on Success.
731 * - Return Error code otherwise.
734 dpseci_get_api_version(struct fsl_mc_io *mc_io,
737 uint16_t *minor_ver);
739 #endif /* __FSL_DPSECI_H */