staging: fsl-mc: fix a few implicit includes
[linux-block.git] / drivers / staging / fsl-mc / bus / dpcon.c
CommitLineData
24999f33
IR
1/* Copyright 2013-2016 Freescale Semiconductor Inc.
2 *
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.
13 *
14 *
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
18 * later version.
19 *
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.
31 */
409acdd0 32#include <linux/kernel.h>
c409c18b 33#include "../include/mc-sys.h"
57ebab2d 34#include "../include/mc-cmd.h"
24999f33
IR
35#include "../include/dpcon.h"
36
37#include "dpcon-cmd.h"
38
39/**
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
45 *
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.
53 *
54 * Return: '0' on Success; Error code otherwise.
55 */
56int dpcon_open(struct fsl_mc_io *mc_io,
57 u32 cmd_flags,
58 int dpcon_id,
59 u16 *token)
60{
61 struct mc_command cmd = { 0 };
62 struct dpcon_cmd_open *dpcon_cmd;
63 int err;
64
65 /* prepare command */
66 cmd.header = mc_encode_cmd_header(DPCON_CMDID_OPEN,
67 cmd_flags,
68 0);
69 dpcon_cmd = (struct dpcon_cmd_open *)cmd.params;
70 dpcon_cmd->dpcon_id = cpu_to_le32(dpcon_id);
71
72 /* send command to mc*/
73 err = mc_send_command(mc_io, &cmd);
74 if (err)
75 return err;
76
77 /* retrieve response parameters */
78 *token = mc_cmd_hdr_read_token(&cmd);
79
80 return 0;
81}
82EXPORT_SYMBOL(dpcon_open);
83
84/**
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
89 *
90 * After this function is called, no further operations are
91 * allowed on the object without opening a new control session.
92 *
93 * Return: '0' on Success; Error code otherwise.
94 */
95int dpcon_close(struct fsl_mc_io *mc_io,
96 u32 cmd_flags,
97 u16 token)
98{
99 struct mc_command cmd = { 0 };
100
101 /* prepare command */
102 cmd.header = mc_encode_cmd_header(DPCON_CMDID_CLOSE,
103 cmd_flags,
104 token);
105
106 /* send command to mc*/
107 return mc_send_command(mc_io, &cmd);
108}
109EXPORT_SYMBOL(dpcon_close);
110
111/**
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
116 *
117 * Return: '0' on Success; Error code otherwise
118 */
119int dpcon_enable(struct fsl_mc_io *mc_io,
120 u32 cmd_flags,
121 u16 token)
122{
123 struct mc_command cmd = { 0 };
124
125 /* prepare command */
126 cmd.header = mc_encode_cmd_header(DPCON_CMDID_ENABLE,
127 cmd_flags,
128 token);
129
130 /* send command to mc*/
131 return mc_send_command(mc_io, &cmd);
132}
133EXPORT_SYMBOL(dpcon_enable);
134
135/**
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
140 *
141 * Return: '0' on Success; Error code otherwise
142 */
143int dpcon_disable(struct fsl_mc_io *mc_io,
144 u32 cmd_flags,
145 u16 token)
146{
147 struct mc_command cmd = { 0 };
148
149 /* prepare command */
150 cmd.header = mc_encode_cmd_header(DPCON_CMDID_DISABLE,
151 cmd_flags,
152 token);
153
154 /* send command to mc*/
155 return mc_send_command(mc_io, &cmd);
156}
157EXPORT_SYMBOL(dpcon_disable);
158
159/**
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
165 *
166 * Return: '0' on Success; Error code otherwise.
167 */
168int dpcon_is_enabled(struct fsl_mc_io *mc_io,
169 u32 cmd_flags,
170 u16 token,
171 int *en)
172{
173 struct mc_command cmd = { 0 };
174 struct dpcon_rsp_is_enabled *dpcon_rsp;
175 int err;
176
177 /* prepare command */
178 cmd.header = mc_encode_cmd_header(DPCON_CMDID_IS_ENABLED,
179 cmd_flags,
180 token);
181
182 /* send command to mc*/
183 err = mc_send_command(mc_io, &cmd);
184 if (err)
185 return err;
186
187 /* retrieve response parameters */
188 dpcon_rsp = (struct dpcon_rsp_is_enabled *)cmd.params;
189 *en = dpcon_rsp->enabled & DPCON_ENABLE;
190
191 return 0;
192}
193EXPORT_SYMBOL(dpcon_is_enabled);
194
195/**
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
200 *
201 * Return: '0' on Success; Error code otherwise.
202 */
203int dpcon_reset(struct fsl_mc_io *mc_io,
204 u32 cmd_flags,
205 u16 token)
206{
207 struct mc_command cmd = { 0 };
208
209 /* prepare command */
210 cmd.header = mc_encode_cmd_header(DPCON_CMDID_RESET,
211 cmd_flags, token);
212
213 /* send command to mc*/
214 return mc_send_command(mc_io, &cmd);
215}
216EXPORT_SYMBOL(dpcon_reset);
217
218/**
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
224 *
225 * Return: '0' on Success; Error code otherwise.
226 */
227int dpcon_get_attributes(struct fsl_mc_io *mc_io,
228 u32 cmd_flags,
229 u16 token,
230 struct dpcon_attr *attr)
231{
232 struct mc_command cmd = { 0 };
233 struct dpcon_rsp_get_attr *dpcon_rsp;
234 int err;
235
236 /* prepare command */
237 cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_ATTR,
238 cmd_flags,
239 token);
240
241 /* send command to mc*/
242 err = mc_send_command(mc_io, &cmd);
243 if (err)
244 return err;
245
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;
251
252 return 0;
253}
254EXPORT_SYMBOL(dpcon_get_attributes);
255
256/**
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
262 *
263 * Return: '0' on Success; Error code otherwise
264 */
265int dpcon_set_notification(struct fsl_mc_io *mc_io,
266 u32 cmd_flags,
267 u16 token,
268 struct dpcon_notification_cfg *cfg)
269{
270 struct mc_command cmd = { 0 };
271 struct dpcon_cmd_set_notification *dpcon_cmd;
272
273 /* prepare command */
274 cmd.header = mc_encode_cmd_header(DPCON_CMDID_SET_NOTIFICATION,
275 cmd_flags,
276 token);
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);
281
282 /* send command to mc*/
283 return mc_send_command(mc_io, &cmd);
284}
285EXPORT_SYMBOL(dpcon_set_notification);
286
287/**
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
293 *
294 * Return: '0' on Success; Error code otherwise
295 */
296int dpcon_get_api_version(struct fsl_mc_io *mc_io,
297 u32 cmd_flags,
298 u16 *major_ver,
299 u16 *minor_ver)
300{
301 struct mc_command cmd = { 0 };
302 int err;
303
304 /* prepare command */
305 cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_API_VERSION,
306 cmd_flags, 0);
307
308 /* send command to mc */
309 err = mc_send_command(mc_io, &cmd);
310 if (err)
311 return err;
312
313 /* retrieve response parameters */
314 mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
315
316 return 0;
317}
318EXPORT_SYMBOL(dpcon_get_api_version);