162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/* Copyright 2019 NXP */
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci#ifndef __FSL_DPDMAI_H
562306a36Sopenharmony_ci#define __FSL_DPDMAI_H
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci/* DPDMAI Version */
862306a36Sopenharmony_ci#define DPDMAI_VER_MAJOR	2
962306a36Sopenharmony_ci#define DPDMAI_VER_MINOR	2
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#define DPDMAI_CMD_BASE_VERSION	0
1262306a36Sopenharmony_ci#define DPDMAI_CMD_ID_OFFSET	4
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#define DPDMAI_CMDID_FORMAT(x)	(((x) << DPDMAI_CMD_ID_OFFSET) | \
1562306a36Sopenharmony_ci				DPDMAI_CMD_BASE_VERSION)
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci/* Command IDs */
1862306a36Sopenharmony_ci#define DPDMAI_CMDID_CLOSE		DPDMAI_CMDID_FORMAT(0x800)
1962306a36Sopenharmony_ci#define DPDMAI_CMDID_OPEN               DPDMAI_CMDID_FORMAT(0x80E)
2062306a36Sopenharmony_ci#define DPDMAI_CMDID_CREATE             DPDMAI_CMDID_FORMAT(0x90E)
2162306a36Sopenharmony_ci#define DPDMAI_CMDID_DESTROY            DPDMAI_CMDID_FORMAT(0x900)
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci#define DPDMAI_CMDID_ENABLE             DPDMAI_CMDID_FORMAT(0x002)
2462306a36Sopenharmony_ci#define DPDMAI_CMDID_DISABLE            DPDMAI_CMDID_FORMAT(0x003)
2562306a36Sopenharmony_ci#define DPDMAI_CMDID_GET_ATTR           DPDMAI_CMDID_FORMAT(0x004)
2662306a36Sopenharmony_ci#define DPDMAI_CMDID_RESET              DPDMAI_CMDID_FORMAT(0x005)
2762306a36Sopenharmony_ci#define DPDMAI_CMDID_IS_ENABLED         DPDMAI_CMDID_FORMAT(0x006)
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci#define DPDMAI_CMDID_SET_IRQ            DPDMAI_CMDID_FORMAT(0x010)
3062306a36Sopenharmony_ci#define DPDMAI_CMDID_GET_IRQ            DPDMAI_CMDID_FORMAT(0x011)
3162306a36Sopenharmony_ci#define DPDMAI_CMDID_SET_IRQ_ENABLE     DPDMAI_CMDID_FORMAT(0x012)
3262306a36Sopenharmony_ci#define DPDMAI_CMDID_GET_IRQ_ENABLE     DPDMAI_CMDID_FORMAT(0x013)
3362306a36Sopenharmony_ci#define DPDMAI_CMDID_SET_IRQ_MASK       DPDMAI_CMDID_FORMAT(0x014)
3462306a36Sopenharmony_ci#define DPDMAI_CMDID_GET_IRQ_MASK       DPDMAI_CMDID_FORMAT(0x015)
3562306a36Sopenharmony_ci#define DPDMAI_CMDID_GET_IRQ_STATUS     DPDMAI_CMDID_FORMAT(0x016)
3662306a36Sopenharmony_ci#define DPDMAI_CMDID_CLEAR_IRQ_STATUS	DPDMAI_CMDID_FORMAT(0x017)
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#define DPDMAI_CMDID_SET_RX_QUEUE	DPDMAI_CMDID_FORMAT(0x1A0)
3962306a36Sopenharmony_ci#define DPDMAI_CMDID_GET_RX_QUEUE       DPDMAI_CMDID_FORMAT(0x1A1)
4062306a36Sopenharmony_ci#define DPDMAI_CMDID_GET_TX_QUEUE       DPDMAI_CMDID_FORMAT(0x1A2)
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci#define MC_CMD_HDR_TOKEN_O 32  /* Token field offset */
4362306a36Sopenharmony_ci#define MC_CMD_HDR_TOKEN_S 16  /* Token field size */
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci#define MAKE_UMASK64(_width) \
4662306a36Sopenharmony_ci	((u64)((_width) < 64 ? ((u64)1 << (_width)) - 1 : (u64)-1))
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci/* Data Path DMA Interface API
4962306a36Sopenharmony_ci * Contains initialization APIs and runtime control APIs for DPDMAI
5062306a36Sopenharmony_ci */
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci/**
5362306a36Sopenharmony_ci * Maximum number of Tx/Rx priorities per DPDMAI object
5462306a36Sopenharmony_ci */
5562306a36Sopenharmony_ci#define DPDMAI_PRIO_NUM		2
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci/* DPDMAI queue modification options */
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci/**
6062306a36Sopenharmony_ci * Select to modify the user's context associated with the queue
6162306a36Sopenharmony_ci */
6262306a36Sopenharmony_ci#define DPDMAI_QUEUE_OPT_USER_CTX	0x1
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci/**
6562306a36Sopenharmony_ci * Select to modify the queue's destination
6662306a36Sopenharmony_ci */
6762306a36Sopenharmony_ci#define DPDMAI_QUEUE_OPT_DEST		0x2
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci/**
7062306a36Sopenharmony_ci * struct dpdmai_cfg - Structure representing DPDMAI configuration
7162306a36Sopenharmony_ci * @priorities: Priorities for the DMA hardware processing; valid priorities are
7262306a36Sopenharmony_ci *	configured with values 1-8; the entry following last valid entry
7362306a36Sopenharmony_ci *	should be configured with 0
7462306a36Sopenharmony_ci */
7562306a36Sopenharmony_cistruct dpdmai_cfg {
7662306a36Sopenharmony_ci	u8 priorities[DPDMAI_PRIO_NUM];
7762306a36Sopenharmony_ci};
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci/**
8062306a36Sopenharmony_ci * struct dpdmai_attr - Structure representing DPDMAI attributes
8162306a36Sopenharmony_ci * @id: DPDMAI object ID
8262306a36Sopenharmony_ci * @version: DPDMAI version
8362306a36Sopenharmony_ci * @num_of_priorities: number of priorities
8462306a36Sopenharmony_ci */
8562306a36Sopenharmony_cistruct dpdmai_attr {
8662306a36Sopenharmony_ci	int	id;
8762306a36Sopenharmony_ci	/**
8862306a36Sopenharmony_ci	 * struct version - DPDMAI version
8962306a36Sopenharmony_ci	 * @major: DPDMAI major version
9062306a36Sopenharmony_ci	 * @minor: DPDMAI minor version
9162306a36Sopenharmony_ci	 */
9262306a36Sopenharmony_ci	struct {
9362306a36Sopenharmony_ci		u16 major;
9462306a36Sopenharmony_ci		u16 minor;
9562306a36Sopenharmony_ci	} version;
9662306a36Sopenharmony_ci	u8 num_of_priorities;
9762306a36Sopenharmony_ci};
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci/**
10062306a36Sopenharmony_ci * enum dpdmai_dest - DPDMAI destination types
10162306a36Sopenharmony_ci * @DPDMAI_DEST_NONE: Unassigned destination; The queue is set in parked mode
10262306a36Sopenharmony_ci *	and does not generate FQDAN notifications; user is expected to dequeue
10362306a36Sopenharmony_ci *	from the queue based on polling or other user-defined method
10462306a36Sopenharmony_ci * @DPDMAI_DEST_DPIO: The queue is set in schedule mode and generates FQDAN
10562306a36Sopenharmony_ci *	notifications to the specified DPIO; user is expected to dequeue
10662306a36Sopenharmony_ci *	from the queue only after notification is received
10762306a36Sopenharmony_ci * @DPDMAI_DEST_DPCON: The queue is set in schedule mode and does not generate
10862306a36Sopenharmony_ci *	FQDAN notifications, but is connected to the specified DPCON object;
10962306a36Sopenharmony_ci *	user is expected to dequeue from the DPCON channel
11062306a36Sopenharmony_ci */
11162306a36Sopenharmony_cienum dpdmai_dest {
11262306a36Sopenharmony_ci	DPDMAI_DEST_NONE = 0,
11362306a36Sopenharmony_ci	DPDMAI_DEST_DPIO = 1,
11462306a36Sopenharmony_ci	DPDMAI_DEST_DPCON = 2
11562306a36Sopenharmony_ci};
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci/**
11862306a36Sopenharmony_ci * struct dpdmai_dest_cfg - Structure representing DPDMAI destination parameters
11962306a36Sopenharmony_ci * @dest_type: Destination type
12062306a36Sopenharmony_ci * @dest_id: Either DPIO ID or DPCON ID, depending on the destination type
12162306a36Sopenharmony_ci * @priority: Priority selection within the DPIO or DPCON channel; valid values
12262306a36Sopenharmony_ci *	are 0-1 or 0-7, depending on the number of priorities in that
12362306a36Sopenharmony_ci *	channel; not relevant for 'DPDMAI_DEST_NONE' option
12462306a36Sopenharmony_ci */
12562306a36Sopenharmony_cistruct dpdmai_dest_cfg {
12662306a36Sopenharmony_ci	enum dpdmai_dest dest_type;
12762306a36Sopenharmony_ci	int dest_id;
12862306a36Sopenharmony_ci	u8 priority;
12962306a36Sopenharmony_ci};
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci/**
13262306a36Sopenharmony_ci * struct dpdmai_rx_queue_cfg - DPDMAI RX queue configuration
13362306a36Sopenharmony_ci * @options: Flags representing the suggested modifications to the queue;
13462306a36Sopenharmony_ci *	Use any combination of 'DPDMAI_QUEUE_OPT_<X>' flags
13562306a36Sopenharmony_ci * @user_ctx: User context value provided in the frame descriptor of each
13662306a36Sopenharmony_ci *	dequeued frame;
13762306a36Sopenharmony_ci *	valid only if 'DPDMAI_QUEUE_OPT_USER_CTX' is contained in 'options'
13862306a36Sopenharmony_ci * @dest_cfg: Queue destination parameters;
13962306a36Sopenharmony_ci *	valid only if 'DPDMAI_QUEUE_OPT_DEST' is contained in 'options'
14062306a36Sopenharmony_ci */
14162306a36Sopenharmony_cistruct dpdmai_rx_queue_cfg {
14262306a36Sopenharmony_ci	struct dpdmai_dest_cfg dest_cfg;
14362306a36Sopenharmony_ci	u32 options;
14462306a36Sopenharmony_ci	u64 user_ctx;
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ci};
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci/**
14962306a36Sopenharmony_ci * struct dpdmai_rx_queue_attr - Structure representing attributes of Rx queues
15062306a36Sopenharmony_ci * @user_ctx:  User context value provided in the frame descriptor of each
15162306a36Sopenharmony_ci *	 dequeued frame
15262306a36Sopenharmony_ci * @dest_cfg: Queue destination configuration
15362306a36Sopenharmony_ci * @fqid: Virtual FQID value to be used for dequeue operations
15462306a36Sopenharmony_ci */
15562306a36Sopenharmony_cistruct dpdmai_rx_queue_attr {
15662306a36Sopenharmony_ci	struct dpdmai_dest_cfg	dest_cfg;
15762306a36Sopenharmony_ci	u64 user_ctx;
15862306a36Sopenharmony_ci	u32 fqid;
15962306a36Sopenharmony_ci};
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ciint dpdmai_open(struct fsl_mc_io *mc_io, u32 cmd_flags,
16262306a36Sopenharmony_ci		int dpdmai_id, u16 *token);
16362306a36Sopenharmony_ciint dpdmai_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
16462306a36Sopenharmony_ciint dpdmai_destroy(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
16562306a36Sopenharmony_ciint dpdmai_create(struct fsl_mc_io *mc_io, u32 cmd_flags,
16662306a36Sopenharmony_ci		  const struct dpdmai_cfg *cfg, u16 *token);
16762306a36Sopenharmony_ciint dpdmai_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
16862306a36Sopenharmony_ciint dpdmai_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
16962306a36Sopenharmony_ciint dpdmai_reset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
17062306a36Sopenharmony_ciint dpdmai_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags,
17162306a36Sopenharmony_ci			  u16 token, struct dpdmai_attr	*attr);
17262306a36Sopenharmony_ciint dpdmai_set_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
17362306a36Sopenharmony_ci			u8 priority, const struct dpdmai_rx_queue_cfg *cfg);
17462306a36Sopenharmony_ciint dpdmai_get_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
17562306a36Sopenharmony_ci			u8 priority, struct dpdmai_rx_queue_attr *attr);
17662306a36Sopenharmony_ciint dpdmai_get_tx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags,
17762306a36Sopenharmony_ci			u16 token, u8 priority, u32 *fqid);
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci#endif /* __FSL_DPDMAI_H */
180