1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
4 * Copyright 2017-2019 NXP
7 #include <fsl_mc_sys.h>
8 #include <fsl_mc_cmd.h>
10 #include <fsl_dpcon_cmd.h>
13 * dpcon_open() - Open a control session for the specified object
14 * @mc_io: Pointer to MC portal's I/O object
15 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
16 * @dpcon_id: DPCON unique ID
17 * @token: Returned token; use in subsequent API calls
19 * This function can be used to open a control session for an
20 * already created object; an object may have been declared in
21 * the DPL or by calling the dpcon_create() function.
22 * This function returns a unique authentication token,
23 * associated with the specific object ID and the specific MC
24 * portal; this token must be used in all subsequent commands for
25 * this specific object.
27 * Return: '0' on Success; Error code otherwise.
29 int dpcon_open(struct fsl_mc_io *mc_io,
34 struct mc_command cmd = { 0 };
35 struct dpcon_cmd_open *dpcon_cmd;
39 cmd.header = mc_encode_cmd_header(DPCON_CMDID_OPEN,
42 dpcon_cmd = (struct dpcon_cmd_open *)cmd.params;
43 dpcon_cmd->dpcon_id = cpu_to_le32(dpcon_id);
45 /* send command to mc*/
46 err = mc_send_command(mc_io, &cmd);
50 /* retrieve response parameters */
51 *token = mc_cmd_hdr_read_token(&cmd);
57 * dpcon_close() - Close the control session of the 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 * @token: Token of DPCON object
62 * After this function is called, no further operations are
63 * allowed on the object without opening a new control session.
65 * Return: '0' on Success; Error code otherwise.
67 int dpcon_close(struct fsl_mc_io *mc_io,
71 struct mc_command cmd = { 0 };
74 cmd.header = mc_encode_cmd_header(DPCON_CMDID_CLOSE,
78 /* send command to mc*/
79 return mc_send_command(mc_io, &cmd);
83 * dpcon_create() - Create the DPCON object.
84 * @mc_io: Pointer to MC portal's I/O object
85 * @dprc_token: Parent container token; '0' for default container
86 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
87 * @cfg: Configuration structure
88 * @obj_id: Returned object id; use in subsequent API calls
90 * Create the DPCON object, allocate required resources and
91 * perform required initialization.
93 * The object can be created either by declaring it in the
94 * DPL file, or by calling this function.
96 * This function accepts an authentication token of a parent
97 * container that this object should be assigned to and returns
98 * an object id. This object_id will be used in all subsequent calls to
99 * this specific object.
101 * Return: '0' on Success; Error code otherwise.
103 int dpcon_create(struct fsl_mc_io *mc_io,
106 const struct dpcon_cfg *cfg,
109 struct dpcon_cmd_create *dpcon_cmd;
110 struct mc_command cmd = { 0 };
113 /* prepare command */
114 cmd.header = mc_encode_cmd_header(DPCON_CMDID_CREATE,
117 dpcon_cmd = (struct dpcon_cmd_create *)cmd.params;
118 dpcon_cmd->num_priorities = cfg->num_priorities;
120 /* send command to mc*/
121 err = mc_send_command(mc_io, &cmd);
125 /* retrieve response parameters */
126 *obj_id = mc_cmd_read_object_id(&cmd);
132 * dpcon_destroy() - Destroy the DPCON object and release all its resources.
133 * @mc_io: Pointer to MC portal's I/O object
134 * @dprc_token: Parent container token; '0' for default container
135 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
136 * @obj_id: ID of DPCON object
138 * Return: '0' on Success; error code otherwise.
140 int dpcon_destroy(struct fsl_mc_io *mc_io,
145 struct dpcon_cmd_destroy *cmd_params;
146 struct mc_command cmd = { 0 };
148 /* prepare command */
149 cmd.header = mc_encode_cmd_header(DPCON_CMDID_DESTROY,
152 cmd_params = (struct dpcon_cmd_destroy *)cmd.params;
153 cmd_params->object_id = cpu_to_le32(obj_id);
155 /* send command to mc*/
156 return mc_send_command(mc_io, &cmd);
160 * dpcon_enable() - Enable the DPCON
161 * @mc_io: Pointer to MC portal's I/O object
162 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
163 * @token: Token of DPCON object
165 * Return: '0' on Success; Error code otherwise
167 int dpcon_enable(struct fsl_mc_io *mc_io,
171 struct mc_command cmd = { 0 };
173 /* prepare command */
174 cmd.header = mc_encode_cmd_header(DPCON_CMDID_ENABLE,
178 /* send command to mc*/
179 return mc_send_command(mc_io, &cmd);
183 * dpcon_disable() - Disable the DPCON
184 * @mc_io: Pointer to MC portal's I/O object
185 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
186 * @token: Token of DPCON object
188 * Return: '0' on Success; Error code otherwise
190 int dpcon_disable(struct fsl_mc_io *mc_io,
194 struct mc_command cmd = { 0 };
196 /* prepare command */
197 cmd.header = mc_encode_cmd_header(DPCON_CMDID_DISABLE,
201 /* send command to mc*/
202 return mc_send_command(mc_io, &cmd);
206 * dpcon_is_enabled() - Check if the DPCON is enabled.
207 * @mc_io: Pointer to MC portal's I/O object
208 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
209 * @token: Token of DPCON object
210 * @en: Returns '1' if object is enabled; '0' otherwise
212 * Return: '0' on Success; Error code otherwise.
214 int dpcon_is_enabled(struct fsl_mc_io *mc_io,
219 struct dpcon_rsp_is_enabled *dpcon_rsp;
220 struct mc_command cmd = { 0 };
223 /* prepare command */
224 cmd.header = mc_encode_cmd_header(DPCON_CMDID_IS_ENABLED,
228 /* send command to mc*/
229 err = mc_send_command(mc_io, &cmd);
233 /* retrieve response parameters */
234 dpcon_rsp = (struct dpcon_rsp_is_enabled *)cmd.params;
235 *en = dpcon_rsp->enabled & DPCON_ENABLE;
241 * dpcon_reset() - Reset the DPCON, returns the object to initial state.
242 * @mc_io: Pointer to MC portal's I/O object
243 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
244 * @token: Token of DPCON object
246 * Return: '0' on Success; Error code otherwise.
248 int dpcon_reset(struct fsl_mc_io *mc_io,
252 struct mc_command cmd = { 0 };
254 /* prepare command */
255 cmd.header = mc_encode_cmd_header(DPCON_CMDID_RESET,
258 /* send command to mc*/
259 return mc_send_command(mc_io, &cmd);
263 * dpcon_get_attributes() - Retrieve DPCON attributes.
264 * @mc_io: Pointer to MC portal's I/O object
265 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
266 * @token: Token of DPCON object
267 * @attr: Object's attributes
269 * Return: '0' on Success; Error code otherwise.
271 int dpcon_get_attributes(struct fsl_mc_io *mc_io,
274 struct dpcon_attr *attr)
276 struct dpcon_rsp_get_attr *dpcon_rsp;
277 struct mc_command cmd = { 0 };
280 /* prepare command */
281 cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_ATTR,
285 /* send command to mc*/
286 err = mc_send_command(mc_io, &cmd);
290 /* retrieve response parameters */
291 dpcon_rsp = (struct dpcon_rsp_get_attr *)cmd.params;
292 attr->id = le32_to_cpu(dpcon_rsp->id);
293 attr->qbman_ch_id = le16_to_cpu(dpcon_rsp->qbman_ch_id);
294 attr->num_priorities = dpcon_rsp->num_priorities;
300 * dpcon_get_api_version - Get Data Path Concentrator API version
301 * @mc_io: Pointer to MC portal's DPCON object
302 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
303 * @major_ver: Major version of DPCON API
304 * @minor_ver: Minor version of DPCON API
306 * Return: '0' on Success; Error code otherwise
308 int dpcon_get_api_version(struct fsl_mc_io *mc_io,
313 struct dpcon_rsp_get_api_version *rsp_params;
314 struct mc_command cmd = { 0 };
317 /* prepare command */
318 cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_API_VERSION,
321 /* send command to mc */
322 err = mc_send_command(mc_io, &cmd);
326 /* retrieve response parameters */
327 rsp_params = (struct dpcon_rsp_get_api_version *)cmd.params;
328 *major_ver = le16_to_cpu(rsp_params->major);
329 *minor_ver = le16_to_cpu(rsp_params->minor);