162306a36Sopenharmony_ci/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright 2013-2016 Freescale Semiconductor Inc.
462306a36Sopenharmony_ci * Copyright 2017-2018 NXP
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci#ifndef _DPSECI_H_
762306a36Sopenharmony_ci#define _DPSECI_H_
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci/*
1062306a36Sopenharmony_ci * Data Path SEC Interface API
1162306a36Sopenharmony_ci * Contains initialization APIs and runtime control APIs for DPSECI
1262306a36Sopenharmony_ci */
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_cistruct fsl_mc_io;
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci/**
1762306a36Sopenharmony_ci * General DPSECI macros
1862306a36Sopenharmony_ci */
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci/**
2162306a36Sopenharmony_ci * Maximum number of Tx/Rx queues per DPSECI object
2262306a36Sopenharmony_ci */
2362306a36Sopenharmony_ci#define DPSECI_MAX_QUEUE_NUM		16
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci/**
2662306a36Sopenharmony_ci * All queues considered; see dpseci_set_rx_queue()
2762306a36Sopenharmony_ci */
2862306a36Sopenharmony_ci#define DPSECI_ALL_QUEUES	(u8)(-1)
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ciint dpseci_open(struct fsl_mc_io *mc_io, u32 cmd_flags, int dpseci_id,
3162306a36Sopenharmony_ci		u16 *token);
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ciint dpseci_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci/**
3662306a36Sopenharmony_ci * Enable the Congestion Group support
3762306a36Sopenharmony_ci */
3862306a36Sopenharmony_ci#define DPSECI_OPT_HAS_CG		0x000020
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci/**
4162306a36Sopenharmony_ci * struct dpseci_cfg - Structure representing DPSECI configuration
4262306a36Sopenharmony_ci * @options: Any combination of the following flags:
4362306a36Sopenharmony_ci *		DPSECI_OPT_HAS_CG
4462306a36Sopenharmony_ci * @num_tx_queues: num of queues towards the SEC
4562306a36Sopenharmony_ci * @num_rx_queues: num of queues back from the SEC
4662306a36Sopenharmony_ci * @priorities: Priorities for the SEC hardware processing;
4762306a36Sopenharmony_ci *		each place in the array is the priority of the tx queue
4862306a36Sopenharmony_ci *		towards the SEC;
4962306a36Sopenharmony_ci *		valid priorities are configured with values 1-8;
5062306a36Sopenharmony_ci */
5162306a36Sopenharmony_cistruct dpseci_cfg {
5262306a36Sopenharmony_ci	u32 options;
5362306a36Sopenharmony_ci	u8 num_tx_queues;
5462306a36Sopenharmony_ci	u8 num_rx_queues;
5562306a36Sopenharmony_ci	u8 priorities[DPSECI_MAX_QUEUE_NUM];
5662306a36Sopenharmony_ci};
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ciint dpseci_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ciint dpseci_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ciint dpseci_reset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ciint dpseci_is_enabled(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
6562306a36Sopenharmony_ci		      int *en);
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci/**
6862306a36Sopenharmony_ci * struct dpseci_attr - Structure representing DPSECI attributes
6962306a36Sopenharmony_ci * @id: DPSECI object ID
7062306a36Sopenharmony_ci * @num_tx_queues: number of queues towards the SEC
7162306a36Sopenharmony_ci * @num_rx_queues: number of queues back from the SEC
7262306a36Sopenharmony_ci * @options: any combination of the following flags:
7362306a36Sopenharmony_ci *		DPSECI_OPT_HAS_CG
7462306a36Sopenharmony_ci */
7562306a36Sopenharmony_cistruct dpseci_attr {
7662306a36Sopenharmony_ci	int id;
7762306a36Sopenharmony_ci	u8 num_tx_queues;
7862306a36Sopenharmony_ci	u8 num_rx_queues;
7962306a36Sopenharmony_ci	u32 options;
8062306a36Sopenharmony_ci};
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ciint dpseci_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
8362306a36Sopenharmony_ci			  struct dpseci_attr *attr);
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci/**
8662306a36Sopenharmony_ci * enum dpseci_dest - DPSECI destination types
8762306a36Sopenharmony_ci * @DPSECI_DEST_NONE: Unassigned destination; The queue is set in parked mode
8862306a36Sopenharmony_ci *	and does not generate FQDAN notifications; user is expected to dequeue
8962306a36Sopenharmony_ci *	from the queue based on polling or other user-defined method
9062306a36Sopenharmony_ci * @DPSECI_DEST_DPIO: The queue is set in schedule mode and generates FQDAN
9162306a36Sopenharmony_ci *	notifications to the specified DPIO; user is expected to dequeue from
9262306a36Sopenharmony_ci *	the queue only after notification is received
9362306a36Sopenharmony_ci * @DPSECI_DEST_DPCON: The queue is set in schedule mode and does not generate
9462306a36Sopenharmony_ci *	FQDAN notifications, but is connected to the specified DPCON object;
9562306a36Sopenharmony_ci *	user is expected to dequeue from the DPCON channel
9662306a36Sopenharmony_ci */
9762306a36Sopenharmony_cienum dpseci_dest {
9862306a36Sopenharmony_ci	DPSECI_DEST_NONE = 0,
9962306a36Sopenharmony_ci	DPSECI_DEST_DPIO,
10062306a36Sopenharmony_ci	DPSECI_DEST_DPCON
10162306a36Sopenharmony_ci};
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci/**
10462306a36Sopenharmony_ci * struct dpseci_dest_cfg - Structure representing DPSECI destination parameters
10562306a36Sopenharmony_ci * @dest_type: Destination type
10662306a36Sopenharmony_ci * @dest_id: Either DPIO ID or DPCON ID, depending on the destination type
10762306a36Sopenharmony_ci * @priority: Priority selection within the DPIO or DPCON channel; valid values
10862306a36Sopenharmony_ci *	are 0-1 or 0-7, depending on the number of priorities in that channel;
10962306a36Sopenharmony_ci *	not relevant for 'DPSECI_DEST_NONE' option
11062306a36Sopenharmony_ci */
11162306a36Sopenharmony_cistruct dpseci_dest_cfg {
11262306a36Sopenharmony_ci	enum dpseci_dest dest_type;
11362306a36Sopenharmony_ci	int dest_id;
11462306a36Sopenharmony_ci	u8 priority;
11562306a36Sopenharmony_ci};
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci/**
11862306a36Sopenharmony_ci * DPSECI queue modification options
11962306a36Sopenharmony_ci */
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci/**
12262306a36Sopenharmony_ci * Select to modify the user's context associated with the queue
12362306a36Sopenharmony_ci */
12462306a36Sopenharmony_ci#define DPSECI_QUEUE_OPT_USER_CTX		0x00000001
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ci/**
12762306a36Sopenharmony_ci * Select to modify the queue's destination
12862306a36Sopenharmony_ci */
12962306a36Sopenharmony_ci#define DPSECI_QUEUE_OPT_DEST			0x00000002
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci/**
13262306a36Sopenharmony_ci * Select to modify the queue's order preservation
13362306a36Sopenharmony_ci */
13462306a36Sopenharmony_ci#define DPSECI_QUEUE_OPT_ORDER_PRESERVATION	0x00000004
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci/**
13762306a36Sopenharmony_ci * struct dpseci_rx_queue_cfg - DPSECI RX queue configuration
13862306a36Sopenharmony_ci * @options: Flags representing the suggested modifications to the queue;
13962306a36Sopenharmony_ci *	Use any combination of 'DPSECI_QUEUE_OPT_<X>' flags
14062306a36Sopenharmony_ci * @order_preservation_en: order preservation configuration for the rx queue
14162306a36Sopenharmony_ci * valid only if 'DPSECI_QUEUE_OPT_ORDER_PRESERVATION' is contained in 'options'
14262306a36Sopenharmony_ci * @user_ctx: User context value provided in the frame descriptor of each
14362306a36Sopenharmony_ci *	dequeued frame;	valid only if 'DPSECI_QUEUE_OPT_USER_CTX' is contained
14462306a36Sopenharmony_ci *	in 'options'
14562306a36Sopenharmony_ci * @dest_cfg: Queue destination parameters; valid only if
14662306a36Sopenharmony_ci *	'DPSECI_QUEUE_OPT_DEST' is contained in 'options'
14762306a36Sopenharmony_ci */
14862306a36Sopenharmony_cistruct dpseci_rx_queue_cfg {
14962306a36Sopenharmony_ci	u32 options;
15062306a36Sopenharmony_ci	int order_preservation_en;
15162306a36Sopenharmony_ci	u64 user_ctx;
15262306a36Sopenharmony_ci	struct dpseci_dest_cfg dest_cfg;
15362306a36Sopenharmony_ci};
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ciint dpseci_set_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
15662306a36Sopenharmony_ci			u8 queue, const struct dpseci_rx_queue_cfg *cfg);
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ci/**
15962306a36Sopenharmony_ci * struct dpseci_rx_queue_attr - Structure representing attributes of Rx queues
16062306a36Sopenharmony_ci * @user_ctx: User context value provided in the frame descriptor of each
16162306a36Sopenharmony_ci *	dequeued frame
16262306a36Sopenharmony_ci * @order_preservation_en: Status of the order preservation configuration on the
16362306a36Sopenharmony_ci *	queue
16462306a36Sopenharmony_ci * @dest_cfg: Queue destination configuration
16562306a36Sopenharmony_ci * @fqid: Virtual FQID value to be used for dequeue operations
16662306a36Sopenharmony_ci */
16762306a36Sopenharmony_cistruct dpseci_rx_queue_attr {
16862306a36Sopenharmony_ci	u64 user_ctx;
16962306a36Sopenharmony_ci	int order_preservation_en;
17062306a36Sopenharmony_ci	struct dpseci_dest_cfg dest_cfg;
17162306a36Sopenharmony_ci	u32 fqid;
17262306a36Sopenharmony_ci};
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_ciint dpseci_get_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
17562306a36Sopenharmony_ci			u8 queue, struct dpseci_rx_queue_attr *attr);
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ci/**
17862306a36Sopenharmony_ci * struct dpseci_tx_queue_attr - Structure representing attributes of Tx queues
17962306a36Sopenharmony_ci * @fqid: Virtual FQID to be used for sending frames to SEC hardware
18062306a36Sopenharmony_ci * @priority: SEC hardware processing priority for the queue
18162306a36Sopenharmony_ci */
18262306a36Sopenharmony_cistruct dpseci_tx_queue_attr {
18362306a36Sopenharmony_ci	u32 fqid;
18462306a36Sopenharmony_ci	u8 priority;
18562306a36Sopenharmony_ci};
18662306a36Sopenharmony_ci
18762306a36Sopenharmony_ciint dpseci_get_tx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
18862306a36Sopenharmony_ci			u8 queue, struct dpseci_tx_queue_attr *attr);
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci/**
19162306a36Sopenharmony_ci * struct dpseci_sec_attr - Structure representing attributes of the SEC
19262306a36Sopenharmony_ci *	hardware accelerator
19362306a36Sopenharmony_ci * @ip_id: ID for SEC
19462306a36Sopenharmony_ci * @major_rev: Major revision number for SEC
19562306a36Sopenharmony_ci * @minor_rev: Minor revision number for SEC
19662306a36Sopenharmony_ci * @era: SEC Era
19762306a36Sopenharmony_ci * @deco_num: The number of copies of the DECO that are implemented in this
19862306a36Sopenharmony_ci *	version of SEC
19962306a36Sopenharmony_ci * @zuc_auth_acc_num: The number of copies of ZUCA that are implemented in this
20062306a36Sopenharmony_ci *	version of SEC
20162306a36Sopenharmony_ci * @zuc_enc_acc_num: The number of copies of ZUCE that are implemented in this
20262306a36Sopenharmony_ci *	version of SEC
20362306a36Sopenharmony_ci * @snow_f8_acc_num: The number of copies of the SNOW-f8 module that are
20462306a36Sopenharmony_ci *	implemented in this version of SEC
20562306a36Sopenharmony_ci * @snow_f9_acc_num: The number of copies of the SNOW-f9 module that are
20662306a36Sopenharmony_ci *	implemented in this version of SEC
20762306a36Sopenharmony_ci * @crc_acc_num: The number of copies of the CRC module that are implemented in
20862306a36Sopenharmony_ci *	this version of SEC
20962306a36Sopenharmony_ci * @pk_acc_num:  The number of copies of the Public Key module that are
21062306a36Sopenharmony_ci *	implemented in this version of SEC
21162306a36Sopenharmony_ci * @kasumi_acc_num: The number of copies of the Kasumi module that are
21262306a36Sopenharmony_ci *	implemented in this version of SEC
21362306a36Sopenharmony_ci * @rng_acc_num: The number of copies of the Random Number Generator that are
21462306a36Sopenharmony_ci *	implemented in this version of SEC
21562306a36Sopenharmony_ci * @md_acc_num: The number of copies of the MDHA (Hashing module) that are
21662306a36Sopenharmony_ci *	implemented in this version of SEC
21762306a36Sopenharmony_ci * @arc4_acc_num: The number of copies of the ARC4 module that are implemented
21862306a36Sopenharmony_ci *	in this version of SEC
21962306a36Sopenharmony_ci * @des_acc_num: The number of copies of the DES module that are implemented in
22062306a36Sopenharmony_ci *	this version of SEC
22162306a36Sopenharmony_ci * @aes_acc_num: The number of copies of the AES module that are implemented in
22262306a36Sopenharmony_ci *	this version of SEC
22362306a36Sopenharmony_ci * @ccha_acc_num: The number of copies of the ChaCha20 module that are
22462306a36Sopenharmony_ci *	implemented in this version of SEC.
22562306a36Sopenharmony_ci * @ptha_acc_num: The number of copies of the Poly1305 module that are
22662306a36Sopenharmony_ci *	implemented in this version of SEC.
22762306a36Sopenharmony_ci **/
22862306a36Sopenharmony_cistruct dpseci_sec_attr {
22962306a36Sopenharmony_ci	u16 ip_id;
23062306a36Sopenharmony_ci	u8 major_rev;
23162306a36Sopenharmony_ci	u8 minor_rev;
23262306a36Sopenharmony_ci	u8 era;
23362306a36Sopenharmony_ci	u8 deco_num;
23462306a36Sopenharmony_ci	u8 zuc_auth_acc_num;
23562306a36Sopenharmony_ci	u8 zuc_enc_acc_num;
23662306a36Sopenharmony_ci	u8 snow_f8_acc_num;
23762306a36Sopenharmony_ci	u8 snow_f9_acc_num;
23862306a36Sopenharmony_ci	u8 crc_acc_num;
23962306a36Sopenharmony_ci	u8 pk_acc_num;
24062306a36Sopenharmony_ci	u8 kasumi_acc_num;
24162306a36Sopenharmony_ci	u8 rng_acc_num;
24262306a36Sopenharmony_ci	u8 md_acc_num;
24362306a36Sopenharmony_ci	u8 arc4_acc_num;
24462306a36Sopenharmony_ci	u8 des_acc_num;
24562306a36Sopenharmony_ci	u8 aes_acc_num;
24662306a36Sopenharmony_ci	u8 ccha_acc_num;
24762306a36Sopenharmony_ci	u8 ptha_acc_num;
24862306a36Sopenharmony_ci};
24962306a36Sopenharmony_ci
25062306a36Sopenharmony_ciint dpseci_get_sec_attr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
25162306a36Sopenharmony_ci			struct dpseci_sec_attr *attr);
25262306a36Sopenharmony_ci
25362306a36Sopenharmony_ciint dpseci_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags,
25462306a36Sopenharmony_ci			   u16 *major_ver, u16 *minor_ver);
25562306a36Sopenharmony_ci
25662306a36Sopenharmony_ci/**
25762306a36Sopenharmony_ci * enum dpseci_congestion_unit - DPSECI congestion units
25862306a36Sopenharmony_ci * @DPSECI_CONGESTION_UNIT_BYTES: bytes units
25962306a36Sopenharmony_ci * @DPSECI_CONGESTION_UNIT_FRAMES: frames units
26062306a36Sopenharmony_ci */
26162306a36Sopenharmony_cienum dpseci_congestion_unit {
26262306a36Sopenharmony_ci	DPSECI_CONGESTION_UNIT_BYTES = 0,
26362306a36Sopenharmony_ci	DPSECI_CONGESTION_UNIT_FRAMES
26462306a36Sopenharmony_ci};
26562306a36Sopenharmony_ci
26662306a36Sopenharmony_ci/**
26762306a36Sopenharmony_ci * CSCN message is written to message_iova once entering a
26862306a36Sopenharmony_ci * congestion state (see 'threshold_entry')
26962306a36Sopenharmony_ci */
27062306a36Sopenharmony_ci#define DPSECI_CGN_MODE_WRITE_MEM_ON_ENTER		0x00000001
27162306a36Sopenharmony_ci
27262306a36Sopenharmony_ci/**
27362306a36Sopenharmony_ci * CSCN message is written to message_iova once exiting a
27462306a36Sopenharmony_ci * congestion state (see 'threshold_exit')
27562306a36Sopenharmony_ci */
27662306a36Sopenharmony_ci#define DPSECI_CGN_MODE_WRITE_MEM_ON_EXIT		0x00000002
27762306a36Sopenharmony_ci
27862306a36Sopenharmony_ci/**
27962306a36Sopenharmony_ci * CSCN write will attempt to allocate into a cache (coherent write);
28062306a36Sopenharmony_ci * valid only if 'DPSECI_CGN_MODE_WRITE_MEM_<X>' is selected
28162306a36Sopenharmony_ci */
28262306a36Sopenharmony_ci#define DPSECI_CGN_MODE_COHERENT_WRITE			0x00000004
28362306a36Sopenharmony_ci
28462306a36Sopenharmony_ci/**
28562306a36Sopenharmony_ci * if 'dpseci_dest_cfg.dest_type != DPSECI_DEST_NONE' CSCN message is sent to
28662306a36Sopenharmony_ci * DPIO/DPCON's WQ channel once entering a congestion state
28762306a36Sopenharmony_ci * (see 'threshold_entry')
28862306a36Sopenharmony_ci */
28962306a36Sopenharmony_ci#define DPSECI_CGN_MODE_NOTIFY_DEST_ON_ENTER		0x00000008
29062306a36Sopenharmony_ci
29162306a36Sopenharmony_ci/**
29262306a36Sopenharmony_ci * if 'dpseci_dest_cfg.dest_type != DPSECI_DEST_NONE' CSCN message is sent to
29362306a36Sopenharmony_ci * DPIO/DPCON's WQ channel once exiting a congestion state
29462306a36Sopenharmony_ci * (see 'threshold_exit')
29562306a36Sopenharmony_ci */
29662306a36Sopenharmony_ci#define DPSECI_CGN_MODE_NOTIFY_DEST_ON_EXIT		0x00000010
29762306a36Sopenharmony_ci
29862306a36Sopenharmony_ci/**
29962306a36Sopenharmony_ci * if 'dpseci_dest_cfg.dest_type != DPSECI_DEST_NONE' when the CSCN is written
30062306a36Sopenharmony_ci * to the sw-portal's DQRR, the DQRI interrupt is asserted immediately
30162306a36Sopenharmony_ci * (if enabled)
30262306a36Sopenharmony_ci */
30362306a36Sopenharmony_ci#define DPSECI_CGN_MODE_INTR_COALESCING_DISABLED	0x00000020
30462306a36Sopenharmony_ci
30562306a36Sopenharmony_ci/**
30662306a36Sopenharmony_ci * struct dpseci_congestion_notification_cfg - congestion notification
30762306a36Sopenharmony_ci *	configuration
30862306a36Sopenharmony_ci * @units: units type
30962306a36Sopenharmony_ci * @threshold_entry: above this threshold we enter a congestion state.
31062306a36Sopenharmony_ci *	set it to '0' to disable it
31162306a36Sopenharmony_ci * @threshold_exit: below this threshold we exit the congestion state.
31262306a36Sopenharmony_ci * @message_ctx: The context that will be part of the CSCN message
31362306a36Sopenharmony_ci * @message_iova: I/O virtual address (must be in DMA-able memory),
31462306a36Sopenharmony_ci *	must be 16B aligned;
31562306a36Sopenharmony_ci * @dest_cfg: CSCN can be send to either DPIO or DPCON WQ channel
31662306a36Sopenharmony_ci * @notification_mode: Mask of available options; use 'DPSECI_CGN_MODE_<X>'
31762306a36Sopenharmony_ci *	values
31862306a36Sopenharmony_ci */
31962306a36Sopenharmony_cistruct dpseci_congestion_notification_cfg {
32062306a36Sopenharmony_ci	enum dpseci_congestion_unit units;
32162306a36Sopenharmony_ci	u32 threshold_entry;
32262306a36Sopenharmony_ci	u32 threshold_exit;
32362306a36Sopenharmony_ci	u64 message_ctx;
32462306a36Sopenharmony_ci	u64 message_iova;
32562306a36Sopenharmony_ci	struct dpseci_dest_cfg dest_cfg;
32662306a36Sopenharmony_ci	u16 notification_mode;
32762306a36Sopenharmony_ci};
32862306a36Sopenharmony_ci
32962306a36Sopenharmony_ciint dpseci_set_congestion_notification(struct fsl_mc_io *mc_io, u32 cmd_flags,
33062306a36Sopenharmony_ci	u16 token, const struct dpseci_congestion_notification_cfg *cfg);
33162306a36Sopenharmony_ci
33262306a36Sopenharmony_ciint dpseci_get_congestion_notification(struct fsl_mc_io *mc_io, u32 cmd_flags,
33362306a36Sopenharmony_ci	u16 token, struct dpseci_congestion_notification_cfg *cfg);
33462306a36Sopenharmony_ci
33562306a36Sopenharmony_ci#endif /* _DPSECI_H_ */
336