1 /* Copyright 2013-2016 Freescale Semiconductor Inc.
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
5 * * Redistributions of source code must retain the above copyright
6 * notice, this list of conditions and the following disclaimer.
7 * * Redistributions in binary form must reproduce the above copyright
8 * notice, this list of conditions and the following disclaimer in the
9 * documentation and/or other materials provided with the distribution.
10 * * Neither the name of the above-listed copyright holders nor the
11 * names of any contributors may be used to endorse or promote products
12 * derived from this software without specific prior written permission.
15 * ALTERNATIVELY, this software may be distributed under the terms of the
16 * GNU General Public License ("GPL") as published by the Free Software
17 * Foundation, either version 2 of that License or (at your option) any
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
32 #include <fsl_mc_sys.h>
33 #include <fsl_mc_cmd.h>
34 #include <fsl_dpcon.h>
35 #include <fsl_dpcon_cmd.h>
38 * dpcon_open() - Open a control session for the specified object
39 * @mc_io: Pointer to MC portal's I/O object
40 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
41 * @dpcon_id: DPCON unique ID
42 * @token: Returned token; use in subsequent API calls
44 * This function can be used to open a control session for an
45 * already created object; an object may have been declared in
46 * the DPL or by calling the dpcon_create() function.
47 * This function returns a unique authentication token,
48 * associated with the specific object ID and the specific MC
49 * portal; this token must be used in all subsequent commands for
50 * this specific object.
52 * Return: '0' on Success; Error code otherwise.
54 int dpcon_open(struct fsl_mc_io *mc_io,
59 struct mc_command cmd = { 0 };
60 struct dpcon_cmd_open *dpcon_cmd;
64 cmd.header = mc_encode_cmd_header(DPCON_CMDID_OPEN,
67 dpcon_cmd = (struct dpcon_cmd_open *)cmd.params;
68 dpcon_cmd->dpcon_id = cpu_to_le32(dpcon_id);
70 /* send command to mc*/
71 err = mc_send_command(mc_io, &cmd);
75 /* retrieve response parameters */
76 *token = mc_cmd_hdr_read_token(&cmd);
82 * dpcon_close() - Close the control session of the object
83 * @mc_io: Pointer to MC portal's I/O object
84 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
85 * @token: Token of DPCON object
87 * After this function is called, no further operations are
88 * allowed on the object without opening a new control session.
90 * Return: '0' on Success; Error code otherwise.
92 int dpcon_close(struct fsl_mc_io *mc_io,
96 struct mc_command cmd = { 0 };
99 cmd.header = mc_encode_cmd_header(DPCON_CMDID_CLOSE,
103 /* send command to mc*/
104 return mc_send_command(mc_io, &cmd);
108 * dpcon_create() - Create the DPCON object.
109 * @mc_io: Pointer to MC portal's I/O object
110 * @dprc_token: Parent container token; '0' for default container
111 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
112 * @cfg: Configuration structure
113 * @obj_id: Returned object id; use in subsequent API calls
115 * Create the DPCON object, allocate required resources and
116 * perform required initialization.
118 * The object can be created either by declaring it in the
119 * DPL file, or by calling this function.
121 * This function accepts an authentication token of a parent
122 * container that this object should be assigned to and returns
123 * an object id. This object_id will be used in all subsequent calls to
124 * this specific object.
126 * Return: '0' on Success; Error code otherwise.
128 int dpcon_create(struct fsl_mc_io *mc_io,
131 const struct dpcon_cfg *cfg,
134 struct dpcon_cmd_create *dpcon_cmd;
135 struct mc_command cmd = { 0 };
138 /* prepare command */
139 cmd.header = mc_encode_cmd_header(DPCON_CMDID_CREATE,
142 dpcon_cmd = (struct dpcon_cmd_create *)cmd.params;
143 dpcon_cmd->num_priorities = cfg->num_priorities;
145 /* send command to mc*/
146 err = mc_send_command(mc_io, &cmd);
150 /* retrieve response parameters */
151 *obj_id = mc_cmd_read_object_id(&cmd);
157 * dpcon_destroy() - Destroy the DPCON object and release all its resources.
158 * @mc_io: Pointer to MC portal's I/O object
159 * @dprc_token: Parent container token; '0' for default container
160 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
161 * @obj_id: ID of DPCON object
163 * Return: '0' on Success; error code otherwise.
165 int dpcon_destroy(struct fsl_mc_io *mc_io,
170 struct dpcon_cmd_destroy *cmd_params;
171 struct mc_command cmd = { 0 };
173 /* prepare command */
174 cmd.header = mc_encode_cmd_header(DPCON_CMDID_DESTROY,
177 cmd_params = (struct dpcon_cmd_destroy *)cmd.params;
178 cmd_params->object_id = cpu_to_le32(obj_id);
180 /* send command to mc*/
181 return mc_send_command(mc_io, &cmd);
185 * dpcon_enable() - Enable the DPCON
186 * @mc_io: Pointer to MC portal's I/O object
187 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
188 * @token: Token of DPCON object
190 * Return: '0' on Success; Error code otherwise
192 int dpcon_enable(struct fsl_mc_io *mc_io,
196 struct mc_command cmd = { 0 };
198 /* prepare command */
199 cmd.header = mc_encode_cmd_header(DPCON_CMDID_ENABLE,
203 /* send command to mc*/
204 return mc_send_command(mc_io, &cmd);
208 * dpcon_disable() - Disable the DPCON
209 * @mc_io: Pointer to MC portal's I/O object
210 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
211 * @token: Token of DPCON object
213 * Return: '0' on Success; Error code otherwise
215 int dpcon_disable(struct fsl_mc_io *mc_io,
219 struct mc_command cmd = { 0 };
221 /* prepare command */
222 cmd.header = mc_encode_cmd_header(DPCON_CMDID_DISABLE,
226 /* send command to mc*/
227 return mc_send_command(mc_io, &cmd);
231 * dpcon_is_enabled() - Check if the DPCON is enabled.
232 * @mc_io: Pointer to MC portal's I/O object
233 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
234 * @token: Token of DPCON object
235 * @en: Returns '1' if object is enabled; '0' otherwise
237 * Return: '0' on Success; Error code otherwise.
239 int dpcon_is_enabled(struct fsl_mc_io *mc_io,
244 struct dpcon_rsp_is_enabled *dpcon_rsp;
245 struct mc_command cmd = { 0 };
248 /* prepare command */
249 cmd.header = mc_encode_cmd_header(DPCON_CMDID_IS_ENABLED,
253 /* send command to mc*/
254 err = mc_send_command(mc_io, &cmd);
258 /* retrieve response parameters */
259 dpcon_rsp = (struct dpcon_rsp_is_enabled *)cmd.params;
260 *en = dpcon_rsp->enabled & DPCON_ENABLE;
266 * dpcon_reset() - Reset the DPCON, returns the object to initial state.
267 * @mc_io: Pointer to MC portal's I/O object
268 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
269 * @token: Token of DPCON object
271 * Return: '0' on Success; Error code otherwise.
273 int dpcon_reset(struct fsl_mc_io *mc_io,
277 struct mc_command cmd = { 0 };
279 /* prepare command */
280 cmd.header = mc_encode_cmd_header(DPCON_CMDID_RESET,
283 /* send command to mc*/
284 return mc_send_command(mc_io, &cmd);
288 * dpcon_get_attributes() - Retrieve DPCON attributes.
289 * @mc_io: Pointer to MC portal's I/O object
290 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
291 * @token: Token of DPCON object
292 * @attr: Object's attributes
294 * Return: '0' on Success; Error code otherwise.
296 int dpcon_get_attributes(struct fsl_mc_io *mc_io,
299 struct dpcon_attr *attr)
301 struct dpcon_rsp_get_attr *dpcon_rsp;
302 struct mc_command cmd = { 0 };
305 /* prepare command */
306 cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_ATTR,
310 /* send command to mc*/
311 err = mc_send_command(mc_io, &cmd);
315 /* retrieve response parameters */
316 dpcon_rsp = (struct dpcon_rsp_get_attr *)cmd.params;
317 attr->id = le32_to_cpu(dpcon_rsp->id);
318 attr->qbman_ch_id = le16_to_cpu(dpcon_rsp->qbman_ch_id);
319 attr->num_priorities = dpcon_rsp->num_priorities;
325 * dpcon_get_api_version - Get Data Path Concentrator API version
326 * @mc_io: Pointer to MC portal's DPCON object
327 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
328 * @major_ver: Major version of DPCON API
329 * @minor_ver: Minor version of DPCON API
331 * Return: '0' on Success; Error code otherwise
333 int dpcon_get_api_version(struct fsl_mc_io *mc_io,
338 struct dpcon_rsp_get_api_version *rsp_params;
339 struct mc_command cmd = { 0 };
342 /* prepare command */
343 cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_API_VERSION,
346 /* send command to mc */
347 err = mc_send_command(mc_io, &cmd);
351 /* retrieve response parameters */
352 rsp_params = (struct dpcon_rsp_get_api_version *)cmd.params;
353 *major_ver = le16_to_cpu(rsp_params->major);
354 *minor_ver = le16_to_cpu(rsp_params->minor);