1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
6 #include <fsl_mc_sys.h>
7 #include <fsl_mc_cmd.h>
9 #include <fsl_dpcon_cmd.h>
12 * dpcon_open() - Open a control session for the specified object
13 * @mc_io: Pointer to MC portal's I/O object
14 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
15 * @dpcon_id: DPCON unique ID
16 * @token: Returned token; use in subsequent API calls
18 * This function can be used to open a control session for an
19 * already created object; an object may have been declared in
20 * the DPL or by calling the dpcon_create() function.
21 * This function returns a unique authentication token,
22 * associated with the specific object ID and the specific MC
23 * portal; this token must be used in all subsequent commands for
24 * this specific object.
26 * Return: '0' on Success; Error code otherwise.
28 int dpcon_open(struct fsl_mc_io *mc_io,
33 struct mc_command cmd = { 0 };
34 struct dpcon_cmd_open *dpcon_cmd;
38 cmd.header = mc_encode_cmd_header(DPCON_CMDID_OPEN,
41 dpcon_cmd = (struct dpcon_cmd_open *)cmd.params;
42 dpcon_cmd->dpcon_id = cpu_to_le32(dpcon_id);
44 /* send command to mc*/
45 err = mc_send_command(mc_io, &cmd);
49 /* retrieve response parameters */
50 *token = mc_cmd_hdr_read_token(&cmd);
56 * dpcon_close() - Close the control session of the object
57 * @mc_io: Pointer to MC portal's I/O object
58 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
59 * @token: Token of DPCON object
61 * After this function is called, no further operations are
62 * allowed on the object without opening a new control session.
64 * Return: '0' on Success; Error code otherwise.
66 int dpcon_close(struct fsl_mc_io *mc_io,
70 struct mc_command cmd = { 0 };
73 cmd.header = mc_encode_cmd_header(DPCON_CMDID_CLOSE,
77 /* send command to mc*/
78 return mc_send_command(mc_io, &cmd);
82 * dpcon_create() - Create the DPCON object.
83 * @mc_io: Pointer to MC portal's I/O object
84 * @dprc_token: Parent container token; '0' for default container
85 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
86 * @cfg: Configuration structure
87 * @obj_id: Returned object id; use in subsequent API calls
89 * Create the DPCON object, allocate required resources and
90 * perform required initialization.
92 * The object can be created either by declaring it in the
93 * DPL file, or by calling this function.
95 * This function accepts an authentication token of a parent
96 * container that this object should be assigned to and returns
97 * an object id. This object_id will be used in all subsequent calls to
98 * this specific object.
100 * Return: '0' on Success; Error code otherwise.
102 int dpcon_create(struct fsl_mc_io *mc_io,
105 const struct dpcon_cfg *cfg,
108 struct dpcon_cmd_create *dpcon_cmd;
109 struct mc_command cmd = { 0 };
112 /* prepare command */
113 cmd.header = mc_encode_cmd_header(DPCON_CMDID_CREATE,
116 dpcon_cmd = (struct dpcon_cmd_create *)cmd.params;
117 dpcon_cmd->num_priorities = cfg->num_priorities;
119 /* send command to mc*/
120 err = mc_send_command(mc_io, &cmd);
124 /* retrieve response parameters */
125 *obj_id = mc_cmd_read_object_id(&cmd);
131 * dpcon_destroy() - Destroy the DPCON object and release all its resources.
132 * @mc_io: Pointer to MC portal's I/O object
133 * @dprc_token: Parent container token; '0' for default container
134 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
135 * @obj_id: ID of DPCON object
137 * Return: '0' on Success; error code otherwise.
139 int dpcon_destroy(struct fsl_mc_io *mc_io,
144 struct dpcon_cmd_destroy *cmd_params;
145 struct mc_command cmd = { 0 };
147 /* prepare command */
148 cmd.header = mc_encode_cmd_header(DPCON_CMDID_DESTROY,
151 cmd_params = (struct dpcon_cmd_destroy *)cmd.params;
152 cmd_params->object_id = cpu_to_le32(obj_id);
154 /* send command to mc*/
155 return mc_send_command(mc_io, &cmd);
159 * dpcon_enable() - Enable the DPCON
160 * @mc_io: Pointer to MC portal's I/O object
161 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
162 * @token: Token of DPCON object
164 * Return: '0' on Success; Error code otherwise
166 int dpcon_enable(struct fsl_mc_io *mc_io,
170 struct mc_command cmd = { 0 };
172 /* prepare command */
173 cmd.header = mc_encode_cmd_header(DPCON_CMDID_ENABLE,
177 /* send command to mc*/
178 return mc_send_command(mc_io, &cmd);
182 * dpcon_disable() - Disable the DPCON
183 * @mc_io: Pointer to MC portal's I/O object
184 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
185 * @token: Token of DPCON object
187 * Return: '0' on Success; Error code otherwise
189 int dpcon_disable(struct fsl_mc_io *mc_io,
193 struct mc_command cmd = { 0 };
195 /* prepare command */
196 cmd.header = mc_encode_cmd_header(DPCON_CMDID_DISABLE,
200 /* send command to mc*/
201 return mc_send_command(mc_io, &cmd);
205 * dpcon_is_enabled() - Check if the DPCON is enabled.
206 * @mc_io: Pointer to MC portal's I/O object
207 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
208 * @token: Token of DPCON object
209 * @en: Returns '1' if object is enabled; '0' otherwise
211 * Return: '0' on Success; Error code otherwise.
213 int dpcon_is_enabled(struct fsl_mc_io *mc_io,
218 struct dpcon_rsp_is_enabled *dpcon_rsp;
219 struct mc_command cmd = { 0 };
222 /* prepare command */
223 cmd.header = mc_encode_cmd_header(DPCON_CMDID_IS_ENABLED,
227 /* send command to mc*/
228 err = mc_send_command(mc_io, &cmd);
232 /* retrieve response parameters */
233 dpcon_rsp = (struct dpcon_rsp_is_enabled *)cmd.params;
234 *en = dpcon_rsp->enabled & DPCON_ENABLE;
240 * dpcon_reset() - Reset the DPCON, returns the object to initial state.
241 * @mc_io: Pointer to MC portal's I/O object
242 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
243 * @token: Token of DPCON object
245 * Return: '0' on Success; Error code otherwise.
247 int dpcon_reset(struct fsl_mc_io *mc_io,
251 struct mc_command cmd = { 0 };
253 /* prepare command */
254 cmd.header = mc_encode_cmd_header(DPCON_CMDID_RESET,
257 /* send command to mc*/
258 return mc_send_command(mc_io, &cmd);
262 * dpcon_get_attributes() - Retrieve DPCON attributes.
263 * @mc_io: Pointer to MC portal's I/O object
264 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
265 * @token: Token of DPCON object
266 * @attr: Object's attributes
268 * Return: '0' on Success; Error code otherwise.
270 int dpcon_get_attributes(struct fsl_mc_io *mc_io,
273 struct dpcon_attr *attr)
275 struct dpcon_rsp_get_attr *dpcon_rsp;
276 struct mc_command cmd = { 0 };
279 /* prepare command */
280 cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_ATTR,
284 /* send command to mc*/
285 err = mc_send_command(mc_io, &cmd);
289 /* retrieve response parameters */
290 dpcon_rsp = (struct dpcon_rsp_get_attr *)cmd.params;
291 attr->id = le32_to_cpu(dpcon_rsp->id);
292 attr->qbman_ch_id = le16_to_cpu(dpcon_rsp->qbman_ch_id);
293 attr->num_priorities = dpcon_rsp->num_priorities;
299 * dpcon_get_api_version - Get Data Path Concentrator API version
300 * @mc_io: Pointer to MC portal's DPCON object
301 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
302 * @major_ver: Major version of DPCON API
303 * @minor_ver: Minor version of DPCON API
305 * Return: '0' on Success; Error code otherwise
307 int dpcon_get_api_version(struct fsl_mc_io *mc_io,
312 struct dpcon_rsp_get_api_version *rsp_params;
313 struct mc_command cmd = { 0 };
316 /* prepare command */
317 cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_API_VERSION,
320 /* send command to mc */
321 err = mc_send_command(mc_io, &cmd);
325 /* retrieve response parameters */
326 rsp_params = (struct dpcon_rsp_get_api_version *)cmd.params;
327 *major_ver = le16_to_cpu(rsp_params->major);
328 *minor_ver = le16_to_cpu(rsp_params->minor);