staging: fsl-mc: fix a few implicit includes
[linux-block.git] / drivers / staging / fsl-mc / bus / dpio / dpio.c
1 /*
2  * Copyright 2013-2016 Freescale Semiconductor Inc.
3  * Copyright 2016 NXP
4  *
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.
15  *
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
19  * later version.
20  *
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.
32  */
33 #include <linux/kernel.h>
34 #include "../../include/mc-sys.h"
35 #include "../../include/mc-cmd.h"
36
37 #include "dpio.h"
38 #include "dpio-cmd.h"
39
40 /*
41  * Data Path I/O Portal API
42  * Contains initialization APIs and runtime control APIs for DPIO
43  */
44
45 /**
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
51  *
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.
59  *
60  * Return:      '0' on Success; Error code otherwise.
61  */
62 int dpio_open(struct fsl_mc_io *mc_io,
63               u32 cmd_flags,
64               int dpio_id,
65               u16 *token)
66 {
67         struct mc_command cmd = { 0 };
68         struct dpio_cmd_open *dpio_cmd;
69         int err;
70
71         /* prepare command */
72         cmd.header = mc_encode_cmd_header(DPIO_CMDID_OPEN,
73                                           cmd_flags,
74                                           0);
75         dpio_cmd = (struct dpio_cmd_open *)cmd.params;
76         dpio_cmd->dpio_id = cpu_to_le32(dpio_id);
77
78         err = mc_send_command(mc_io, &cmd);
79         if (err)
80                 return err;
81
82         /* retrieve response parameters */
83         *token = mc_cmd_hdr_read_token(&cmd);
84
85         return 0;
86 }
87
88 /**
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
93  *
94  * Return:      '0' on Success; Error code otherwise.
95  */
96 int dpio_close(struct fsl_mc_io *mc_io,
97                u32 cmd_flags,
98                u16 token)
99 {
100         struct mc_command cmd = { 0 };
101
102         /* prepare command */
103         cmd.header = mc_encode_cmd_header(DPIO_CMDID_CLOSE,
104                                           cmd_flags,
105                                           token);
106
107         return mc_send_command(mc_io, &cmd);
108 }
109
110 /**
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
115  *
116  * Return:      '0' on Success; Error code otherwise
117  */
118 int dpio_enable(struct fsl_mc_io *mc_io,
119                 u32 cmd_flags,
120                 u16 token)
121 {
122         struct mc_command cmd = { 0 };
123
124         /* prepare command */
125         cmd.header = mc_encode_cmd_header(DPIO_CMDID_ENABLE,
126                                           cmd_flags,
127                                           token);
128
129         return mc_send_command(mc_io, &cmd);
130 }
131
132 /**
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
137  *
138  * Return:      '0' on Success; Error code otherwise
139  */
140 int dpio_disable(struct fsl_mc_io *mc_io,
141                  u32 cmd_flags,
142                  u16 token)
143 {
144         struct mc_command cmd = { 0 };
145
146         /* prepare command */
147         cmd.header = mc_encode_cmd_header(DPIO_CMDID_DISABLE,
148                                           cmd_flags,
149                                           token);
150
151         return mc_send_command(mc_io, &cmd);
152 }
153
154 /**
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
160  *
161  * Return:      '0' on Success; Error code otherwise
162  */
163 int dpio_get_attributes(struct fsl_mc_io *mc_io,
164                         u32 cmd_flags,
165                         u16 token,
166                         struct dpio_attr *attr)
167 {
168         struct mc_command cmd = { 0 };
169         struct dpio_rsp_get_attr *dpio_rsp;
170         int err;
171
172         /* prepare command */
173         cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR,
174                                           cmd_flags,
175                                           token);
176
177         err = mc_send_command(mc_io, &cmd);
178         if (err)
179                 return err;
180
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);
192
193         return 0;
194 }
195
196 /**
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
202  *
203  * Return:      '0' on Success; Error code otherwise
204  */
205 int dpio_get_api_version(struct fsl_mc_io *mc_io,
206                          u32 cmd_flags,
207                          u16 *major_ver,
208                          u16 *minor_ver)
209 {
210         struct mc_command cmd = { 0 };
211         int err;
212
213         /* prepare command */
214         cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_API_VERSION,
215                                           cmd_flags, 0);
216
217         err = mc_send_command(mc_io, &cmd);
218         if (err)
219                 return err;
220
221         /* retrieve response parameters */
222         mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
223
224         return 0;
225 }