GNU Linux-libre 4.14.290-gnu1
[releases.git] / drivers / staging / fsl-mc / bus / dpbp.c
1 /*
2  * Copyright 2013-2016 Freescale Semiconductor Inc.
3  *
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.
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  */
32 #include <linux/kernel.h>
33 #include "../include/mc.h"
34 #include "../include/dpbp.h"
35
36 #include "dpbp-cmd.h"
37
38 /**
39  * dpbp_open() - Open a control session for the specified object.
40  * @mc_io:      Pointer to MC portal's I/O object
41  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
42  * @dpbp_id:    DPBP unique ID
43  * @token:      Returned token; use in subsequent API calls
44  *
45  * This function can be used to open a control session for an
46  * already created object; an object may have been declared in
47  * the DPL or by calling the dpbp_create function.
48  * This function returns a unique authentication token,
49  * associated with the specific object ID and the specific MC
50  * portal; this token must be used in all subsequent commands for
51  * this specific object
52  *
53  * Return:      '0' on Success; Error code otherwise.
54  */
55 int dpbp_open(struct fsl_mc_io *mc_io,
56               u32 cmd_flags,
57               int dpbp_id,
58               u16 *token)
59 {
60         struct mc_command cmd = { 0 };
61         struct dpbp_cmd_open *cmd_params;
62         int err;
63
64         /* prepare command */
65         cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
66                                           cmd_flags, 0);
67         cmd_params = (struct dpbp_cmd_open *)cmd.params;
68         cmd_params->dpbp_id = cpu_to_le32(dpbp_id);
69
70         /* send command to mc*/
71         err = mc_send_command(mc_io, &cmd);
72         if (err)
73                 return err;
74
75         /* retrieve response parameters */
76         *token = mc_cmd_hdr_read_token(&cmd);
77
78         return err;
79 }
80 EXPORT_SYMBOL(dpbp_open);
81
82 /**
83  * dpbp_close() - Close the control session of the object
84  * @mc_io:      Pointer to MC portal's I/O object
85  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
86  * @token:      Token of DPBP object
87  *
88  * After this function is called, no further operations are
89  * allowed on the object without opening a new control session.
90  *
91  * Return:      '0' on Success; Error code otherwise.
92  */
93 int dpbp_close(struct fsl_mc_io *mc_io,
94                u32 cmd_flags,
95                u16 token)
96 {
97         struct mc_command cmd = { 0 };
98
99         /* prepare command */
100         cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
101                                           token);
102
103         /* send command to mc*/
104         return mc_send_command(mc_io, &cmd);
105 }
106 EXPORT_SYMBOL(dpbp_close);
107
108 /**
109  * dpbp_enable() - Enable the DPBP.
110  * @mc_io:      Pointer to MC portal's I/O object
111  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
112  * @token:      Token of DPBP object
113  *
114  * Return:      '0' on Success; Error code otherwise.
115  */
116 int dpbp_enable(struct fsl_mc_io *mc_io,
117                 u32 cmd_flags,
118                 u16 token)
119 {
120         struct mc_command cmd = { 0 };
121
122         /* prepare command */
123         cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
124                                           token);
125
126         /* send command to mc*/
127         return mc_send_command(mc_io, &cmd);
128 }
129 EXPORT_SYMBOL(dpbp_enable);
130
131 /**
132  * dpbp_disable() - Disable the DPBP.
133  * @mc_io:      Pointer to MC portal's I/O object
134  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
135  * @token:      Token of DPBP object
136  *
137  * Return:      '0' on Success; Error code otherwise.
138  */
139 int dpbp_disable(struct fsl_mc_io *mc_io,
140                  u32 cmd_flags,
141                  u16 token)
142 {
143         struct mc_command cmd = { 0 };
144
145         /* prepare command */
146         cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
147                                           cmd_flags, token);
148
149         /* send command to mc*/
150         return mc_send_command(mc_io, &cmd);
151 }
152 EXPORT_SYMBOL(dpbp_disable);
153
154 /**
155  * dpbp_is_enabled() - Check if the DPBP is enabled.
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 DPBP object
159  * @en:         Returns '1' if object is enabled; '0' otherwise
160  *
161  * Return:      '0' on Success; Error code otherwise.
162  */
163 int dpbp_is_enabled(struct fsl_mc_io *mc_io,
164                     u32 cmd_flags,
165                     u16 token,
166                     int *en)
167 {
168         struct mc_command cmd = { 0 };
169         struct dpbp_rsp_is_enabled *rsp_params;
170         int err;
171         /* prepare command */
172         cmd.header = mc_encode_cmd_header(DPBP_CMDID_IS_ENABLED, cmd_flags,
173                                           token);
174
175         /* send command to mc*/
176         err = mc_send_command(mc_io, &cmd);
177         if (err)
178                 return err;
179
180         /* retrieve response parameters */
181         rsp_params = (struct dpbp_rsp_is_enabled *)cmd.params;
182         *en = rsp_params->enabled & DPBP_ENABLE;
183
184         return 0;
185 }
186 EXPORT_SYMBOL(dpbp_is_enabled);
187
188 /**
189  * dpbp_reset() - Reset the DPBP, returns the object to initial state.
190  * @mc_io:      Pointer to MC portal's I/O object
191  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
192  * @token:      Token of DPBP object
193  *
194  * Return:      '0' on Success; Error code otherwise.
195  */
196 int dpbp_reset(struct fsl_mc_io *mc_io,
197                u32 cmd_flags,
198                u16 token)
199 {
200         struct mc_command cmd = { 0 };
201
202         /* prepare command */
203         cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
204                                           cmd_flags, token);
205
206         /* send command to mc*/
207         return mc_send_command(mc_io, &cmd);
208 }
209 EXPORT_SYMBOL(dpbp_reset);
210
211 /**
212  * dpbp_get_attributes - Retrieve DPBP attributes.
213  *
214  * @mc_io:      Pointer to MC portal's I/O object
215  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
216  * @token:      Token of DPBP object
217  * @attr:       Returned object's attributes
218  *
219  * Return:      '0' on Success; Error code otherwise.
220  */
221 int dpbp_get_attributes(struct fsl_mc_io *mc_io,
222                         u32 cmd_flags,
223                         u16 token,
224                         struct dpbp_attr *attr)
225 {
226         struct mc_command cmd = { 0 };
227         struct dpbp_rsp_get_attributes *rsp_params;
228         int err;
229
230         /* prepare command */
231         cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
232                                           cmd_flags, token);
233
234         /* send command to mc*/
235         err = mc_send_command(mc_io, &cmd);
236         if (err)
237                 return err;
238
239         /* retrieve response parameters */
240         rsp_params = (struct dpbp_rsp_get_attributes *)cmd.params;
241         attr->bpid = le16_to_cpu(rsp_params->bpid);
242         attr->id = le32_to_cpu(rsp_params->id);
243
244         return 0;
245 }
246 EXPORT_SYMBOL(dpbp_get_attributes);
247
248 /**
249  * dpbp_get_api_version - Get Data Path Buffer Pool API version
250  * @mc_io:      Pointer to Mc portal's I/O object
251  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
252  * @major_ver:  Major version of Buffer Pool API
253  * @minor_ver:  Minor version of Buffer Pool API
254  *
255  * Return:      '0' on Success; Error code otherwise.
256  */
257 int dpbp_get_api_version(struct fsl_mc_io *mc_io,
258                          u32 cmd_flags,
259                          u16 *major_ver,
260                          u16 *minor_ver)
261 {
262         struct mc_command cmd = { 0 };
263         int err;
264
265         /* prepare command */
266         cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_API_VERSION,
267                                           cmd_flags, 0);
268
269         /* send command to mc */
270         err = mc_send_command(mc_io, &cmd);
271         if (err)
272                 return err;
273
274         /* retrieve response parameters */
275         mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
276
277         return 0;
278 }
279 EXPORT_SYMBOL(dpbp_get_api_version);