xref: /openbmc/u-boot/include/fsl-mc/fsl_dpio.h (revision 0a61ee88)
1 /*
2  * Copyright (C) 2013-2015 Freescale Semiconductor
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 
7 #ifndef _FSL_DPIO_H
8 #define _FSL_DPIO_H
9 
10 /* DPIO Version */
11 #define DPIO_VER_MAJOR				3
12 #define DPIO_VER_MINOR				1
13 
14 /* Command IDs */
15 #define DPIO_CMDID_CLOSE					0x800
16 #define DPIO_CMDID_OPEN						0x803
17 #define DPIO_CMDID_CREATE					0x903
18 #define DPIO_CMDID_DESTROY					0x900
19 
20 #define DPIO_CMDID_ENABLE					0x002
21 #define DPIO_CMDID_DISABLE					0x003
22 #define DPIO_CMDID_GET_ATTR					0x004
23 #define DPIO_CMDID_RESET					0x005
24 
25 /*                cmd, param, offset, width, type, arg_name */
26 #define DPIO_CMD_OPEN(cmd, dpio_id) \
27 	MC_CMD_OP(cmd, 0, 0,  32, int,     dpio_id)
28 
29 /*                cmd, param, offset, width, type, arg_name */
30 #define DPIO_CMD_CREATE(cmd, cfg) \
31 do { \
32 	MC_CMD_OP(cmd, 0, 16, 2,  enum dpio_channel_mode,	\
33 					   cfg->channel_mode);\
34 	MC_CMD_OP(cmd, 0, 32, 8,  uint8_t, cfg->num_priorities);\
35 } while (0)
36 
37 /*                cmd, param, offset, width, type, arg_name */
38 #define DPIO_RSP_GET_ATTR(cmd, attr) \
39 do { \
40 	MC_RSP_OP(cmd, 0, 0,  32, int,	    attr->id);\
41 	MC_RSP_OP(cmd, 0, 32, 16, uint16_t, attr->qbman_portal_id);\
42 	MC_RSP_OP(cmd, 0, 48, 8,  uint8_t,  attr->num_priorities);\
43 	MC_RSP_OP(cmd, 0, 56, 4,  enum dpio_channel_mode, attr->channel_mode);\
44 	MC_RSP_OP(cmd, 1, 0,  64, uint64_t, attr->qbman_portal_ce_offset);\
45 	MC_RSP_OP(cmd, 2, 0,  64, uint64_t, attr->qbman_portal_ci_offset);\
46 	MC_RSP_OP(cmd, 3, 0,  16, uint16_t, attr->version.major);\
47 	MC_RSP_OP(cmd, 3, 16, 16, uint16_t, attr->version.minor);\
48 } while (0)
49 
50 /* Data Path I/O Portal API
51  * Contains initialization APIs and runtime control APIs for DPIO
52  */
53 
54 struct fsl_mc_io;
55 
56 /**
57  * dpio_open() - Open a control session for the specified object
58  * @mc_io:	Pointer to MC portal's I/O object
59  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
60  * @dpio_id:	DPIO unique ID
61  * @token:	Returned token; use in subsequent API calls
62  *
63  * This function can be used to open a control session for an
64  * already created object; an object may have been declared in
65  * the DPL or by calling the dpio_create() function.
66  * This function returns a unique authentication token,
67  * associated with the specific object ID and the specific MC
68  * portal; this token must be used in all subsequent commands for
69  * this specific object.
70  *
71  * Return:	'0' on Success; Error code otherwise.
72  */
73 int dpio_open(struct fsl_mc_io	*mc_io,
74 	      uint32_t		cmd_flags,
75 	      int		dpio_id,
76 	      uint16_t		*token);
77 
78 /**
79  * dpio_close() - Close the control session of the object
80  * @mc_io:	Pointer to MC portal's I/O object
81  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
82  * @token:	Token of DPIO object
83  *
84  * Return:	'0' on Success; Error code otherwise.
85  */
86 int dpio_close(struct fsl_mc_io	*mc_io,
87 	       uint32_t		cmd_flags,
88 	       uint16_t		token);
89 
90 /**
91  * enum dpio_channel_mode - DPIO notification channel mode
92  * @DPIO_NO_CHANNEL: No support for notification channel
93  * @DPIO_LOCAL_CHANNEL: Notifications on data availability can be received by a
94  *	dedicated channel in the DPIO; user should point the queue's
95  *	destination in the relevant interface to this DPIO
96  */
97 enum dpio_channel_mode {
98 	DPIO_NO_CHANNEL = 0,
99 	DPIO_LOCAL_CHANNEL = 1,
100 };
101 
102 /**
103  * struct dpio_cfg - Structure representing DPIO configuration
104  * @channel_mode: Notification channel mode
105  * @num_priorities: Number of priorities for the notification channel (1-8);
106  *			relevant only if 'channel_mode = DPIO_LOCAL_CHANNEL'
107  */
108 struct dpio_cfg {
109 	enum dpio_channel_mode	channel_mode;
110 	uint8_t		num_priorities;
111 };
112 
113 /**
114  * dpio_create() - Create the DPIO object.
115  * @mc_io:	Pointer to MC portal's I/O object
116  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
117  * @cfg:	Configuration structure
118  * @token:	Returned token; use in subsequent API calls
119  *
120  * Create the DPIO object, allocate required resources and
121  * perform required initialization.
122  *
123  * The object can be created either by declaring it in the
124  * DPL file, or by calling this function.
125  *
126  * This function returns a unique authentication token,
127  * associated with the specific object ID and the specific MC
128  * portal; this token must be used in all subsequent calls to
129  * this specific object. For objects that are created using the
130  * DPL file, call dpio_open() function to get an authentication
131  * token first.
132  *
133  * Return:	'0' on Success; Error code otherwise.
134  */
135 int dpio_create(struct fsl_mc_io	*mc_io,
136 		uint32_t		cmd_flags,
137 		const struct dpio_cfg	*cfg,
138 		uint16_t		*token);
139 
140 /**
141  * dpio_destroy() - Destroy the DPIO object and release all its resources.
142  * @mc_io:	Pointer to MC portal's I/O object
143  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
144  * @token:	Token of DPIO object
145  *
146  * Return:	'0' on Success; Error code otherwise
147  */
148 int dpio_destroy(struct fsl_mc_io	*mc_io,
149 		 uint32_t		cmd_flags,
150 		 uint16_t		token);
151 
152 /**
153  * dpio_enable() - Enable the DPIO, allow I/O portal operations.
154  * @mc_io:	Pointer to MC portal's I/O object
155  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
156  * @token:	Token of DPIO object
157  *
158  * Return:	'0' on Success; Error code otherwise
159  */
160 int dpio_enable(struct fsl_mc_io	*mc_io,
161 		uint32_t		cmd_flags,
162 		uint16_t		token);
163 
164 /**
165  * dpio_disable() - Disable the DPIO, stop any I/O portal operation.
166  * @mc_io:	Pointer to MC portal's I/O object
167  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
168  * @token:	Token of DPIO object
169  *
170  * Return:	'0' on Success; Error code otherwise
171  */
172 int dpio_disable(struct fsl_mc_io	*mc_io,
173 		 uint32_t		cmd_flags,
174 		 uint16_t		token);
175 
176 /**
177  * dpio_reset() - Reset the DPIO, returns the object to initial state.
178  * @mc_io:	Pointer to MC portal's I/O object
179  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
180  * @token:	Token of DPIO object
181  *
182  * Return:	'0' on Success; Error code otherwise.
183  */
184 int dpio_reset(struct fsl_mc_io	*mc_io,
185 	       uint32_t			cmd_flags,
186 	       uint16_t		token);
187 
188 /**
189  * struct dpio_attr - Structure representing DPIO attributes
190  * @id: DPIO object ID
191  * @version: DPIO version
192  * @qbman_portal_ce_offset: offset of the software portal cache-enabled area
193  * @qbman_portal_ci_offset: offset of the software portal cache-inhibited area
194  * @qbman_portal_id: Software portal ID
195  * @channel_mode: Notification channel mode
196  * @num_priorities: Number of priorities for the notification channel (1-8);
197  *			relevant only if 'channel_mode = DPIO_LOCAL_CHANNEL'
198  */
199 struct dpio_attr {
200 	int id;
201 	/**
202 	 * struct version - DPIO version
203 	 * @major: DPIO major version
204 	 * @minor: DPIO minor version
205 	 */
206 	struct {
207 		uint16_t major;
208 		uint16_t minor;
209 	} version;
210 	uint64_t qbman_portal_ce_offset;
211 	uint64_t qbman_portal_ci_offset;
212 	uint16_t qbman_portal_id;
213 	enum dpio_channel_mode channel_mode;
214 	uint8_t num_priorities;
215 };
216 
217 /**
218  * dpio_get_attributes() - Retrieve DPIO attributes
219  * @mc_io:	Pointer to MC portal's I/O object
220  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
221  * @token:	Token of DPIO object
222  * @attr:	Returned object's attributes
223  *
224  * Return:	'0' on Success; Error code otherwise
225  */
226 int dpio_get_attributes(struct fsl_mc_io	*mc_io,
227 			uint32_t		cmd_flags,
228 			uint16_t		token,
229 			struct dpio_attr	*attr);
230 
231 #endif /* _FSL_DPIO_H */
232