2 * Copyright 2013-2016 Freescale Semiconductor Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the above-listed copyright holders nor the
13 * names of any contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * ALTERNATIVELY, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL") as published by the Free Software
18 * Foundation, either version 2 of that License or (at your option) any
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
33 #include <linux/kernel.h>
34 #include "../../include/mc-sys.h"
35 #include "../../include/mc-cmd.h"
41 * Data Path I/O Portal API
42 * Contains initialization APIs and runtime control APIs for DPIO
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 the specific MC
57 * portal; this token must be used in all subsequent commands for
58 * this specific object.
60 * Return: '0' on Success; Error code otherwise.
62 int dpio_open(struct fsl_mc_io *mc_io,
67 struct mc_command cmd = { 0 };
68 struct dpio_cmd_open *dpio_cmd;
72 cmd.header = mc_encode_cmd_header(DPIO_CMDID_OPEN,
75 dpio_cmd = (struct dpio_cmd_open *)cmd.params;
76 dpio_cmd->dpio_id = cpu_to_le32(dpio_id);
78 err = mc_send_command(mc_io, &cmd);
82 /* retrieve response parameters */
83 *token = mc_cmd_hdr_read_token(&cmd);
89 * dpio_close() - Close the control session of the object
90 * @mc_io: Pointer to MC portal's I/O object
91 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
92 * @token: Token of DPIO object
94 * Return: '0' on Success; Error code otherwise.
96 int dpio_close(struct fsl_mc_io *mc_io,
100 struct mc_command cmd = { 0 };
102 /* prepare command */
103 cmd.header = mc_encode_cmd_header(DPIO_CMDID_CLOSE,
107 return mc_send_command(mc_io, &cmd);
111 * dpio_enable() - Enable the DPIO, allow I/O portal operations.
112 * @mc_io: Pointer to MC portal's I/O object
113 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
114 * @token: Token of DPIO object
116 * Return: '0' on Success; Error code otherwise
118 int dpio_enable(struct fsl_mc_io *mc_io,
122 struct mc_command cmd = { 0 };
124 /* prepare command */
125 cmd.header = mc_encode_cmd_header(DPIO_CMDID_ENABLE,
129 return mc_send_command(mc_io, &cmd);
133 * dpio_disable() - Disable the DPIO, stop any I/O portal operation.
134 * @mc_io: Pointer to MC portal's I/O object
135 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
136 * @token: Token of DPIO object
138 * Return: '0' on Success; Error code otherwise
140 int dpio_disable(struct fsl_mc_io *mc_io,
144 struct mc_command cmd = { 0 };
146 /* prepare command */
147 cmd.header = mc_encode_cmd_header(DPIO_CMDID_DISABLE,
151 return mc_send_command(mc_io, &cmd);
155 * dpio_get_attributes() - Retrieve DPIO attributes
156 * @mc_io: Pointer to MC portal's I/O object
157 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
158 * @token: Token of DPIO object
159 * @attr: Returned object's attributes
161 * Return: '0' on Success; Error code otherwise
163 int dpio_get_attributes(struct fsl_mc_io *mc_io,
166 struct dpio_attr *attr)
168 struct mc_command cmd = { 0 };
169 struct dpio_rsp_get_attr *dpio_rsp;
172 /* prepare command */
173 cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR,
177 err = mc_send_command(mc_io, &cmd);
181 /* retrieve response parameters */
182 dpio_rsp = (struct dpio_rsp_get_attr *)cmd.params;
183 attr->id = le32_to_cpu(dpio_rsp->id);
184 attr->qbman_portal_id = le16_to_cpu(dpio_rsp->qbman_portal_id);
185 attr->num_priorities = dpio_rsp->num_priorities;
186 attr->channel_mode = dpio_rsp->channel_mode & DPIO_CHANNEL_MODE_MASK;
187 attr->qbman_portal_ce_offset =
188 le64_to_cpu(dpio_rsp->qbman_portal_ce_addr);
189 attr->qbman_portal_ci_offset =
190 le64_to_cpu(dpio_rsp->qbman_portal_ci_addr);
191 attr->qbman_version = le32_to_cpu(dpio_rsp->qbman_version);
197 * dpio_get_api_version - Get Data Path I/O API version
198 * @mc_io: Pointer to MC portal's DPIO object
199 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
200 * @major_ver: Major version of DPIO API
201 * @minor_ver: Minor version of DPIO API
203 * Return: '0' on Success; Error code otherwise
205 int dpio_get_api_version(struct fsl_mc_io *mc_io,
210 struct mc_command cmd = { 0 };
213 /* prepare command */
214 cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_API_VERSION,
217 err = mc_send_command(mc_io, &cmd);
221 /* retrieve response parameters */
222 mc_cmd_read_api_version(&cmd, major_ver, minor_ver);