1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright 2013-2016 Freescale Semiconductor, Inc.
4  * Copyright 2017, 2023 NXP
5  */
6 
7 #ifndef _FSL_DPIO_H
8 #define _FSL_DPIO_H
9 
10 /* DPIO Version */
11 #define DPIO_VER_MAJOR				4
12 #define DPIO_VER_MINOR				2
13 
14 /* Command IDs */
15 #define DPIO_CMDID_CLOSE					0x8001
16 #define DPIO_CMDID_OPEN						0x8031
17 #define DPIO_CMDID_CREATE					0x9031
18 #define DPIO_CMDID_DESTROY					0x9831
19 #define DPIO_CMDID_GET_API_VERSION				0xa031
20 
21 #define DPIO_CMDID_ENABLE					0x0021
22 #define DPIO_CMDID_DISABLE					0x0031
23 #define DPIO_CMDID_GET_ATTR					0x0041
24 
25 /* Macros for accessing command fields smaller than 1byte */
26 #define DPIO_MASK(field)        \
27 	GENMASK(DPIO_##field##_SHIFT + DPIO_##field##_SIZE - 1, \
28 		DPIO_##field##_SHIFT)
29 #define dpio_set_field(var, field, val) \
30 	((var) |= (((val) << DPIO_##field##_SHIFT) & DPIO_MASK(field)))
31 #define dpio_get_field(var, field)      \
32 	(((var) & DPIO_MASK(field)) >> DPIO_##field##_SHIFT)
33 
34 #pragma pack(push, 1)
35 struct dpio_cmd_open {
36 	__le32 dpio_id;
37 };
38 
39 #define DPIO_CHANNEL_MODE_SHIFT		0
40 #define DPIO_CHANNEL_MODE_SIZE		2
41 
42 struct dpio_cmd_create {
43 	__le16 pad1;
44 	/* from LSB: channel_mode:2 */
45 	u8 channel_mode;
46 	u8 pad2;
47 	u8 num_priorities;
48 };
49 
50 struct dpio_cmd_destroy {
51 	__le32 dpio_id;
52 };
53 
54 #define DPIO_ATTR_CHANNEL_MODE_SHIFT	0
55 #define DPIO_ATTR_CHANNEL_MODE_SIZE	4
56 
57 struct dpio_rsp_get_attr {
58 	__le32 id;
59 	__le16 qbman_portal_id;
60 	u8 num_priorities;
61 	/* from LSB: channel_mode:4 */
62 	u8 channel_mode;
63 	__le64 qbman_portal_ce_offset;
64 	__le64 qbman_portal_ci_offset;
65 	__le32 qbman_version;
66 	__le32 pad;
67 	__le32 clk;
68 };
69 
70 #pragma pack(pop)
71 
72 /* Data Path I/O Portal API
73  * Contains initialization APIs and runtime control APIs for DPIO
74  */
75 
76 struct fsl_mc_io;
77 
78 int dpio_open(struct fsl_mc_io *mc_io, u32 cmd_flags, int dpio_id,
79 	      u16 *token);
80 
81 int dpio_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
82 
83 /**
84  * enum dpio_channel_mode - DPIO notification channel mode
85  * @DPIO_NO_CHANNEL:	No support for notification channel
86  * @DPIO_LOCAL_CHANNEL:	Notifications on data availability can be received by a
87  *	dedicated channel in the DPIO; user should point the queue's
88  *	destination in the relevant interface to this DPIO
89  */
90 enum dpio_channel_mode {
91 	DPIO_NO_CHANNEL = 0,
92 	DPIO_LOCAL_CHANNEL = 1,
93 };
94 
95 /**
96  * struct dpio_cfg - Structure representing DPIO configuration
97  * @channel_mode:	Notification channel mode
98  * @num_priorities:	Number of priorities for the notification channel (1-8);
99  *			relevant only if 'channel_mode = DPIO_LOCAL_CHANNEL'
100  */
101 struct dpio_cfg {
102 	enum dpio_channel_mode channel_mode;
103 	u8 num_priorities;
104 };
105 
106 int dpio_create(struct fsl_mc_io *mc_io, u16 dprc_token, u32 cmd_flags,
107 		const struct dpio_cfg *cfg, u32 *obj_id);
108 
109 int dpio_destroy(struct fsl_mc_io *mc_io, u16 dprc_token, u32 cmd_flags,
110 		 u32 object_id);
111 
112 int dpio_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
113 
114 int dpio_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token);
115 
116 /**
117  * struct dpio_attr - Structure representing DPIO attributes
118  * @id:				DPIO object ID
119  * @qbman_portal_ce_offset:	Offset of the software portal cache-enabled area
120  * @qbman_portal_ci_offset:	Offset of the software portal
121  *				cache-inhibited area
122  * @qbman_portal_id:		Software portal ID
123  * @channel_mode:		Notification channel mode
124  * @num_priorities:		Number of priorities for the notification
125  *				channel (1-8); relevant only if
126  *				'channel_mode = DPIO_LOCAL_CHANNEL'
127  * @qbman_version:		QBMAN version
128  */
129 struct dpio_attr {
130 	int id;
131 	u64 qbman_portal_ce_offset;
132 	u64 qbman_portal_ci_offset;
133 	u16 qbman_portal_id;
134 	enum dpio_channel_mode channel_mode;
135 	u8 num_priorities;
136 	u32 qbman_version;
137 	u32 clk;
138 };
139 
140 int dpio_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
141 			struct dpio_attr *attr);
142 
143 int dpio_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags,
144 			 u16 *major_ver, u16 *minor_ver);
145 #endif /* _FSL_DPIO_H */
146