2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
7 * Copyright 2013-2016 Freescale Semiconductor Inc.
8 * Copyright 2016-2017 NXP.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * * Neither the name of the above-listed copyright holders nor the
18 * names of any contributors may be used to endorse or promote products
19 * derived from this software without specific prior written permission.
23 * ALTERNATIVELY, this software may be distributed under the terms of the
24 * GNU General Public License ("GPL") as published by the Free Software
25 * Foundation, either version 2 of that License or (at your option) any
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
32 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
40 #include <fsl_mc_sys.h>
41 #include <fsl_mc_cmd.h>
43 #include <fsl_dpio_cmd.h>
46 * dpio_open() - Open a control session for the specified object
47 * @mc_io: Pointer to MC portal's I/O object
48 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
49 * @dpio_id: DPIO unique ID
50 * @token: Returned token; use in subsequent API calls
52 * This function can be used to open a control session for an
53 * already created object; an object may have been declared in
54 * the DPL or by calling the dpio_create() function.
55 * This function returns a unique authentication token,
56 * associated with the specific object ID and any MC portals
57 * assigned to the parent container; this token must be used in
58 * all subsequent commands for this specific object.
60 * Return: '0' on Success; Error code otherwise.
62 int dpio_open(struct fsl_mc_io *mc_io,
67 struct dpio_cmd_open *cmd_params;
68 struct mc_command cmd = { 0 };
72 cmd.header = mc_encode_cmd_header(DPIO_CMDID_OPEN,
75 cmd_params = (struct dpio_cmd_open *)cmd.params;
76 cmd_params->dpio_id = cpu_to_le32(dpio_id);
78 /* send command to mc*/
79 err = mc_send_command(mc_io, &cmd);
83 /* retrieve response parameters */
84 *token = mc_cmd_hdr_read_token(&cmd);
90 * dpio_close() - Close the control session of the object
91 * @mc_io: Pointer to MC portal's I/O object
92 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
93 * @token: Token of DPIO object
95 * Return: '0' on Success; Error code otherwise.
97 int dpio_close(struct fsl_mc_io *mc_io,
101 struct mc_command cmd = { 0 };
103 /* prepare command */
104 cmd.header = mc_encode_cmd_header(DPIO_CMDID_CLOSE,
108 /* send command to mc*/
109 return mc_send_command(mc_io, &cmd);
113 * dpio_create() - Create the DPIO object.
114 * @mc_io: Pointer to MC portal's I/O object
115 * @dprc_token: Parent container token; '0' for default container
116 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
117 * @cfg: Configuration structure
118 * @obj_id: Returned object id
120 * Create the DPIO object, allocate required resources and
121 * perform required initialization.
123 * The object can be created either by declaring it in the
124 * DPL file, or by calling this function.
126 * The function accepts an authentication token of a parent
127 * container that this object should be assigned to. The token
128 * can be '0' so the object will be assigned to the default container.
129 * The newly created object can be opened with the returned
130 * object id and using the container's associated tokens and MC portals.
132 * Return: '0' on Success; Error code otherwise.
134 int dpio_create(struct fsl_mc_io *mc_io,
137 const struct dpio_cfg *cfg,
140 struct dpio_cmd_create *cmd_params;
141 struct mc_command cmd = { 0 };
144 /* prepare command */
145 cmd.header = mc_encode_cmd_header(DPIO_CMDID_CREATE,
148 cmd_params = (struct dpio_cmd_create *)cmd.params;
149 cmd_params->num_priorities = cfg->num_priorities;
150 dpio_set_field(cmd_params->channel_mode,
154 /* send command to mc*/
155 err = mc_send_command(mc_io, &cmd);
159 /* retrieve response parameters */
160 *obj_id = mc_cmd_read_object_id(&cmd);
166 * dpio_destroy() - Destroy the DPIO object and release all its resources.
167 * @mc_io: Pointer to MC portal's I/O object
168 * @dprc_token: Parent container token; '0' for default container
169 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
170 * @object_id: The object id; it must be a valid id within the container that
171 * created this object;
173 * The function accepts the authentication token of the parent container that
174 * created the object (not the one that currently owns the object). The object
175 * is searched within parent using the provided 'object_id'.
176 * All tokens to the object must be closed before calling destroy.
178 * Return: '0' on Success; Error code otherwise
180 int dpio_destroy(struct fsl_mc_io *mc_io,
185 struct dpio_cmd_destroy *cmd_params;
186 struct mc_command cmd = { 0 };
188 /* prepare command */
189 cmd.header = mc_encode_cmd_header(DPIO_CMDID_DESTROY,
193 /* set object id to destroy */
194 cmd_params = (struct dpio_cmd_destroy *)cmd.params;
195 cmd_params->dpio_id = cpu_to_le32(object_id);
197 /* send command to mc*/
198 return mc_send_command(mc_io, &cmd);
202 * dpio_enable() - Enable the DPIO, allow I/O portal operations.
203 * @mc_io: Pointer to MC portal's I/O object
204 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
205 * @token: Token of DPIO object
207 * Return: '0' on Success; Error code otherwise
209 int dpio_enable(struct fsl_mc_io *mc_io,
213 struct mc_command cmd = { 0 };
215 /* prepare command */
216 cmd.header = mc_encode_cmd_header(DPIO_CMDID_ENABLE,
220 /* send command to mc*/
221 return mc_send_command(mc_io, &cmd);
225 * dpio_disable() - Disable the DPIO, stop any I/O portal operation.
226 * @mc_io: Pointer to MC portal's I/O object
227 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
228 * @token: Token of DPIO object
230 * Return: '0' on Success; Error code otherwise
232 int dpio_disable(struct fsl_mc_io *mc_io,
236 struct mc_command cmd = { 0 };
238 /* prepare command */
239 cmd.header = mc_encode_cmd_header(DPIO_CMDID_DISABLE,
243 /* send command to mc*/
244 return mc_send_command(mc_io, &cmd);
248 * dpio_is_enabled() - Check if the DPIO is enabled.
249 * @mc_io: Pointer to MC portal's I/O object
250 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
251 * @token: Token of DPIO object
252 * @en: Returns '1' if object is enabled; '0' otherwise
254 * Return: '0' on Success; Error code otherwise.
256 int dpio_is_enabled(struct fsl_mc_io *mc_io,
261 struct dpio_rsp_is_enabled *rsp_params;
262 struct mc_command cmd = { 0 };
265 /* prepare command */
266 cmd.header = mc_encode_cmd_header(DPIO_CMDID_IS_ENABLED, cmd_flags,
269 /* send command to mc*/
270 err = mc_send_command(mc_io, &cmd);
274 /* retrieve response parameters */
275 rsp_params = (struct dpio_rsp_is_enabled *)cmd.params;
276 *en = dpio_get_field(rsp_params->en, ENABLE);
282 * dpio_reset() - Reset the DPIO, returns the object to initial state.
283 * @mc_io: Pointer to MC portal's I/O object
284 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
285 * @token: Token of DPIO object
287 * Return: '0' on Success; Error code otherwise.
289 int dpio_reset(struct fsl_mc_io *mc_io,
293 struct mc_command cmd = { 0 };
295 /* prepare command */
296 cmd.header = mc_encode_cmd_header(DPIO_CMDID_RESET,
300 /* send command to mc*/
301 return mc_send_command(mc_io, &cmd);
304 int dpio_get_attributes(struct fsl_mc_io *mc_io,
307 struct dpio_attr *attr)
309 struct dpio_rsp_get_attr *rsp_params;
310 struct mc_command cmd = { 0 };
313 /* prepare command */
314 cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR,
318 /* send command to mc*/
319 err = mc_send_command(mc_io, &cmd);
323 /* retrieve response parameters */
324 rsp_params = (struct dpio_rsp_get_attr *)cmd.params;
325 attr->id = le32_to_cpu(rsp_params->id);
326 attr->qbman_portal_id = le16_to_cpu(rsp_params->qbman_portal_id);
327 attr->num_priorities = rsp_params->num_priorities;
328 attr->qbman_portal_ce_offset =
329 le64_to_cpu(rsp_params->qbman_portal_ce_offset);
330 attr->qbman_portal_ci_offset =
331 le64_to_cpu(rsp_params->qbman_portal_ci_offset);
332 attr->qbman_version = le32_to_cpu(rsp_params->qbman_version);
333 attr->clk = le32_to_cpu(rsp_params->clk);
334 attr->channel_mode = dpio_get_field(rsp_params->channel_mode,
341 * dpio_set_stashing_destination() - Set the stashing destination.
342 * @mc_io: Pointer to MC portal's I/O object
343 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
344 * @token: Token of DPIO object
345 * @sdest: Stashing destination value
347 * Return: '0' on Success; Error code otherwise.
349 int dpio_set_stashing_destination(struct fsl_mc_io *mc_io,
354 struct dpio_stashing_dest *cmd_params;
355 struct mc_command cmd = { 0 };
357 /* prepare command */
358 cmd.header = mc_encode_cmd_header(DPIO_CMDID_SET_STASHING_DEST,
361 cmd_params = (struct dpio_stashing_dest *)cmd.params;
362 cmd_params->sdest = sdest;
364 /* send command to mc*/
365 return mc_send_command(mc_io, &cmd);
369 * dpio_get_stashing_destination() - Get the stashing destination..
370 * @mc_io: Pointer to MC portal's I/O object
371 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
372 * @token: Token of DPIO object
373 * @sdest: Returns the stashing destination value
375 * Return: '0' on Success; Error code otherwise.
377 int dpio_get_stashing_destination(struct fsl_mc_io *mc_io,
382 struct dpio_stashing_dest *rsp_params;
383 struct mc_command cmd = { 0 };
386 /* prepare command */
387 cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_STASHING_DEST,
391 /* send command to mc*/
392 err = mc_send_command(mc_io, &cmd);
396 /* retrieve response parameters */
397 rsp_params = (struct dpio_stashing_dest *)cmd.params;
398 *sdest = rsp_params->sdest;
404 * dpio_add_static_dequeue_channel() - Add a static dequeue channel.
405 * @mc_io: Pointer to MC portal's I/O object
406 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
407 * @token: Token of DPIO object
408 * @dpcon_id: DPCON object ID
409 * @channel_index: Returned channel index to be used in qbman API
411 * Return: '0' on Success; Error code otherwise.
413 int dpio_add_static_dequeue_channel(struct fsl_mc_io *mc_io,
417 uint8_t *channel_index)
419 struct dpio_rsp_add_static_dequeue_channel *rsp_params;
420 struct dpio_cmd_static_dequeue_channel *cmd_params;
421 struct mc_command cmd = { 0 };
424 /* prepare command */
425 cmd.header = mc_encode_cmd_header(DPIO_CMDID_ADD_STATIC_DEQUEUE_CHANNEL,
428 cmd_params = (struct dpio_cmd_static_dequeue_channel *)cmd.params;
429 cmd_params->dpcon_id = cpu_to_le32(dpcon_id);
431 /* send command to mc*/
432 err = mc_send_command(mc_io, &cmd);
436 /* retrieve response parameters */
437 rsp_params = (struct dpio_rsp_add_static_dequeue_channel *)cmd.params;
438 *channel_index = rsp_params->channel_index;
444 * dpio_remove_static_dequeue_channel() - Remove a static dequeue channel.
445 * @mc_io: Pointer to MC portal's I/O object
446 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
447 * @token: Token of DPIO object
448 * @dpcon_id: DPCON object ID
450 * Return: '0' on Success; Error code otherwise.
452 int dpio_remove_static_dequeue_channel(struct fsl_mc_io *mc_io,
457 struct dpio_cmd_static_dequeue_channel *cmd_params;
458 struct mc_command cmd = { 0 };
460 /* prepare command */
461 cmd.header = mc_encode_cmd_header(
462 DPIO_CMDID_REMOVE_STATIC_DEQUEUE_CHANNEL,
465 cmd_params = (struct dpio_cmd_static_dequeue_channel *)cmd.params;
466 cmd_params->dpcon_id = cpu_to_le32(dpcon_id);
468 /* send command to mc*/
469 return mc_send_command(mc_io, &cmd);
473 * dpio_get_api_version() - Get Data Path I/O API version
474 * @mc_io: Pointer to MC portal's I/O object
475 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
476 * @major_ver: Major version of data path i/o API
477 * @minor_ver: Minor version of data path i/o API
479 * Return: '0' on Success; Error code otherwise.
481 int dpio_get_api_version(struct fsl_mc_io *mc_io,
486 struct dpio_rsp_get_api_version *rsp_params;
487 struct mc_command cmd = { 0 };
490 cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_API_VERSION,
494 err = mc_send_command(mc_io, &cmd);
498 rsp_params = (struct dpio_rsp_get_api_version *)cmd.params;
499 *major_ver = le16_to_cpu(rsp_params->major);
500 *minor_ver = le16_to_cpu(rsp_params->minor);