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 <linux/kernel.h>
33 #include "../include/mc-sys.h"
34 #include "../include/mc-cmd.h"
35 #include "../include/dpcon.h"
37 #include "dpcon-cmd.h"
40 * dpcon_open() - Open a control session for the specified object
41 * @mc_io: Pointer to MC portal's I/O object
42 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
43 * @dpcon_id: DPCON unique ID
44 * @token: Returned token; use in subsequent API calls
46 * This function can be used to open a control session for an
47 * already created object; an object may have been declared in
48 * the DPL or by calling the dpcon_create() function.
49 * This function returns a unique authentication token,
50 * associated with the specific object ID and the specific MC
51 * portal; this token must be used in all subsequent commands for
52 * this specific object.
54 * Return: '0' on Success; Error code otherwise.
56 int dpcon_open(struct fsl_mc_io *mc_io,
61 struct mc_command cmd = { 0 };
62 struct dpcon_cmd_open *dpcon_cmd;
66 cmd.header = mc_encode_cmd_header(DPCON_CMDID_OPEN,
69 dpcon_cmd = (struct dpcon_cmd_open *)cmd.params;
70 dpcon_cmd->dpcon_id = cpu_to_le32(dpcon_id);
72 /* send command to mc*/
73 err = mc_send_command(mc_io, &cmd);
77 /* retrieve response parameters */
78 *token = mc_cmd_hdr_read_token(&cmd);
82 EXPORT_SYMBOL(dpcon_open);
85 * dpcon_close() - Close the control session of the object
86 * @mc_io: Pointer to MC portal's I/O object
87 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
88 * @token: Token of DPCON object
90 * After this function is called, no further operations are
91 * allowed on the object without opening a new control session.
93 * Return: '0' on Success; Error code otherwise.
95 int dpcon_close(struct fsl_mc_io *mc_io,
99 struct mc_command cmd = { 0 };
101 /* prepare command */
102 cmd.header = mc_encode_cmd_header(DPCON_CMDID_CLOSE,
106 /* send command to mc*/
107 return mc_send_command(mc_io, &cmd);
109 EXPORT_SYMBOL(dpcon_close);
112 * dpcon_enable() - Enable the DPCON
113 * @mc_io: Pointer to MC portal's I/O object
114 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
115 * @token: Token of DPCON object
117 * Return: '0' on Success; Error code otherwise
119 int dpcon_enable(struct fsl_mc_io *mc_io,
123 struct mc_command cmd = { 0 };
125 /* prepare command */
126 cmd.header = mc_encode_cmd_header(DPCON_CMDID_ENABLE,
130 /* send command to mc*/
131 return mc_send_command(mc_io, &cmd);
133 EXPORT_SYMBOL(dpcon_enable);
136 * dpcon_disable() - Disable the DPCON
137 * @mc_io: Pointer to MC portal's I/O object
138 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
139 * @token: Token of DPCON object
141 * Return: '0' on Success; Error code otherwise
143 int dpcon_disable(struct fsl_mc_io *mc_io,
147 struct mc_command cmd = { 0 };
149 /* prepare command */
150 cmd.header = mc_encode_cmd_header(DPCON_CMDID_DISABLE,
154 /* send command to mc*/
155 return mc_send_command(mc_io, &cmd);
157 EXPORT_SYMBOL(dpcon_disable);
160 * dpcon_is_enabled() - Check if the DPCON is enabled.
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
164 * @en: Returns '1' if object is enabled; '0' otherwise
166 * Return: '0' on Success; Error code otherwise.
168 int dpcon_is_enabled(struct fsl_mc_io *mc_io,
173 struct mc_command cmd = { 0 };
174 struct dpcon_rsp_is_enabled *dpcon_rsp;
177 /* prepare command */
178 cmd.header = mc_encode_cmd_header(DPCON_CMDID_IS_ENABLED,
182 /* send command to mc*/
183 err = mc_send_command(mc_io, &cmd);
187 /* retrieve response parameters */
188 dpcon_rsp = (struct dpcon_rsp_is_enabled *)cmd.params;
189 *en = dpcon_rsp->enabled & DPCON_ENABLE;
193 EXPORT_SYMBOL(dpcon_is_enabled);
196 * dpcon_reset() - Reset the DPCON, returns the object to initial state.
197 * @mc_io: Pointer to MC portal's I/O object
198 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
199 * @token: Token of DPCON object
201 * Return: '0' on Success; Error code otherwise.
203 int dpcon_reset(struct fsl_mc_io *mc_io,
207 struct mc_command cmd = { 0 };
209 /* prepare command */
210 cmd.header = mc_encode_cmd_header(DPCON_CMDID_RESET,
213 /* send command to mc*/
214 return mc_send_command(mc_io, &cmd);
216 EXPORT_SYMBOL(dpcon_reset);
219 * dpcon_get_attributes() - Retrieve DPCON attributes.
220 * @mc_io: Pointer to MC portal's I/O object
221 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
222 * @token: Token of DPCON object
223 * @attr: Object's attributes
225 * Return: '0' on Success; Error code otherwise.
227 int dpcon_get_attributes(struct fsl_mc_io *mc_io,
230 struct dpcon_attr *attr)
232 struct mc_command cmd = { 0 };
233 struct dpcon_rsp_get_attr *dpcon_rsp;
236 /* prepare command */
237 cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_ATTR,
241 /* send command to mc*/
242 err = mc_send_command(mc_io, &cmd);
246 /* retrieve response parameters */
247 dpcon_rsp = (struct dpcon_rsp_get_attr *)cmd.params;
248 attr->id = le32_to_cpu(dpcon_rsp->id);
249 attr->qbman_ch_id = le16_to_cpu(dpcon_rsp->qbman_ch_id);
250 attr->num_priorities = dpcon_rsp->num_priorities;
254 EXPORT_SYMBOL(dpcon_get_attributes);
257 * dpcon_set_notification() - Set DPCON notification destination
258 * @mc_io: Pointer to MC portal's I/O object
259 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
260 * @token: Token of DPCON object
261 * @cfg: Notification parameters
263 * Return: '0' on Success; Error code otherwise
265 int dpcon_set_notification(struct fsl_mc_io *mc_io,
268 struct dpcon_notification_cfg *cfg)
270 struct mc_command cmd = { 0 };
271 struct dpcon_cmd_set_notification *dpcon_cmd;
273 /* prepare command */
274 cmd.header = mc_encode_cmd_header(DPCON_CMDID_SET_NOTIFICATION,
277 dpcon_cmd = (struct dpcon_cmd_set_notification *)cmd.params;
278 dpcon_cmd->dpio_id = cpu_to_le32(cfg->dpio_id);
279 dpcon_cmd->priority = cfg->priority;
280 dpcon_cmd->user_ctx = cpu_to_le64(cfg->user_ctx);
282 /* send command to mc*/
283 return mc_send_command(mc_io, &cmd);
285 EXPORT_SYMBOL(dpcon_set_notification);
288 * dpcon_get_api_version - Get Data Path Concentrator API version
289 * @mc_io: Pointer to MC portal's DPCON object
290 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
291 * @major_ver: Major version of DPCON API
292 * @minor_ver: Minor version of DPCON API
294 * Return: '0' on Success; Error code otherwise
296 int dpcon_get_api_version(struct fsl_mc_io *mc_io,
301 struct mc_command cmd = { 0 };
304 /* prepare command */
305 cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_API_VERSION,
308 /* send command to mc */
309 err = mc_send_command(mc_io, &cmd);
313 /* retrieve response parameters */
314 mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
318 EXPORT_SYMBOL(dpcon_get_api_version);