staging: fsl-mc: fix a few implicit includes
[linux-2.6/btrfs-unstable.git] / drivers / staging / fsl-mc / bus / dpbp.c
blobe92d887de716dcd00d671e1906d52ea37f76a84c
1 /*
2 * Copyright 2013-2016 Freescale Semiconductor Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the above-listed copyright holders nor the
12 * names of any contributors may be used to endorse or promote products
13 * 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
18 * later version.
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/dpbp.h"
37 #include "dpbp-cmd.h"
39 /**
40 * dpbp_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 * @dpbp_id: DPBP 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 dpbp_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 dpbp_open(struct fsl_mc_io *mc_io,
57 u32 cmd_flags,
58 int dpbp_id,
59 u16 *token)
61 struct mc_command cmd = { 0 };
62 struct dpbp_cmd_open *cmd_params;
63 int err;
65 /* prepare command */
66 cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
67 cmd_flags, 0);
68 cmd_params = (struct dpbp_cmd_open *)cmd.params;
69 cmd_params->dpbp_id = cpu_to_le32(dpbp_id);
71 /* send command to mc*/
72 err = mc_send_command(mc_io, &cmd);
73 if (err)
74 return err;
76 /* retrieve response parameters */
77 *token = mc_cmd_hdr_read_token(&cmd);
79 return err;
81 EXPORT_SYMBOL(dpbp_open);
83 /**
84 * dpbp_close() - Close the control session of the object
85 * @mc_io: Pointer to MC portal's I/O object
86 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
87 * @token: Token of DPBP object
89 * After this function is called, no further operations are
90 * allowed on the object without opening a new control session.
92 * Return: '0' on Success; Error code otherwise.
94 int dpbp_close(struct fsl_mc_io *mc_io,
95 u32 cmd_flags,
96 u16 token)
98 struct mc_command cmd = { 0 };
100 /* prepare command */
101 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
102 token);
104 /* send command to mc*/
105 return mc_send_command(mc_io, &cmd);
107 EXPORT_SYMBOL(dpbp_close);
110 * dpbp_enable() - Enable the DPBP.
111 * @mc_io: Pointer to MC portal's I/O object
112 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
113 * @token: Token of DPBP object
115 * Return: '0' on Success; Error code otherwise.
117 int dpbp_enable(struct fsl_mc_io *mc_io,
118 u32 cmd_flags,
119 u16 token)
121 struct mc_command cmd = { 0 };
123 /* prepare command */
124 cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
125 token);
127 /* send command to mc*/
128 return mc_send_command(mc_io, &cmd);
130 EXPORT_SYMBOL(dpbp_enable);
133 * dpbp_disable() - Disable the DPBP.
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 DPBP object
138 * Return: '0' on Success; Error code otherwise.
140 int dpbp_disable(struct fsl_mc_io *mc_io,
141 u32 cmd_flags,
142 u16 token)
144 struct mc_command cmd = { 0 };
146 /* prepare command */
147 cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
148 cmd_flags, token);
150 /* send command to mc*/
151 return mc_send_command(mc_io, &cmd);
153 EXPORT_SYMBOL(dpbp_disable);
156 * dpbp_is_enabled() - Check if the DPBP is enabled.
157 * @mc_io: Pointer to MC portal's I/O object
158 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
159 * @token: Token of DPBP object
160 * @en: Returns '1' if object is enabled; '0' otherwise
162 * Return: '0' on Success; Error code otherwise.
164 int dpbp_is_enabled(struct fsl_mc_io *mc_io,
165 u32 cmd_flags,
166 u16 token,
167 int *en)
169 struct mc_command cmd = { 0 };
170 struct dpbp_rsp_is_enabled *rsp_params;
171 int err;
172 /* prepare command */
173 cmd.header = mc_encode_cmd_header(DPBP_CMDID_IS_ENABLED, cmd_flags,
174 token);
176 /* send command to mc*/
177 err = mc_send_command(mc_io, &cmd);
178 if (err)
179 return err;
181 /* retrieve response parameters */
182 rsp_params = (struct dpbp_rsp_is_enabled *)cmd.params;
183 *en = rsp_params->enabled & DPBP_ENABLE;
185 return 0;
187 EXPORT_SYMBOL(dpbp_is_enabled);
190 * dpbp_reset() - Reset the DPBP, returns the object to initial state.
191 * @mc_io: Pointer to MC portal's I/O object
192 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
193 * @token: Token of DPBP object
195 * Return: '0' on Success; Error code otherwise.
197 int dpbp_reset(struct fsl_mc_io *mc_io,
198 u32 cmd_flags,
199 u16 token)
201 struct mc_command cmd = { 0 };
203 /* prepare command */
204 cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
205 cmd_flags, token);
207 /* send command to mc*/
208 return mc_send_command(mc_io, &cmd);
210 EXPORT_SYMBOL(dpbp_reset);
213 * dpbp_get_attributes - Retrieve DPBP attributes.
215 * @mc_io: Pointer to MC portal's I/O object
216 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
217 * @token: Token of DPBP object
218 * @attr: Returned object's attributes
220 * Return: '0' on Success; Error code otherwise.
222 int dpbp_get_attributes(struct fsl_mc_io *mc_io,
223 u32 cmd_flags,
224 u16 token,
225 struct dpbp_attr *attr)
227 struct mc_command cmd = { 0 };
228 struct dpbp_rsp_get_attributes *rsp_params;
229 int err;
231 /* prepare command */
232 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
233 cmd_flags, token);
235 /* send command to mc*/
236 err = mc_send_command(mc_io, &cmd);
237 if (err)
238 return err;
240 /* retrieve response parameters */
241 rsp_params = (struct dpbp_rsp_get_attributes *)cmd.params;
242 attr->bpid = le16_to_cpu(rsp_params->bpid);
243 attr->id = le32_to_cpu(rsp_params->id);
245 return 0;
247 EXPORT_SYMBOL(dpbp_get_attributes);
250 * dpbp_get_api_version - Get Data Path Buffer Pool API version
251 * @mc_io: Pointer to Mc portal's I/O object
252 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
253 * @major_ver: Major version of Buffer Pool API
254 * @minor_ver: Minor version of Buffer Pool API
256 * Return: '0' on Success; Error code otherwise.
258 int dpbp_get_api_version(struct fsl_mc_io *mc_io,
259 u32 cmd_flags,
260 u16 *major_ver,
261 u16 *minor_ver)
263 struct mc_command cmd = { 0 };
264 int err;
266 /* prepare command */
267 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_API_VERSION,
268 cmd_flags, 0);
270 /* send command to mc */
271 err = mc_send_command(mc_io, &cmd);
272 if (err)
273 return err;
275 /* retrieve response parameters */
276 mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
278 return 0;
280 EXPORT_SYMBOL(dpbp_get_api_version);