0ea78379778df1ec26685ed7d50a47605c400421
[deb_dpdk.git] / drivers / bus / fslmc / mc / dpci.c
1 /*-
2  * This file is provided under a dual BSD/GPLv2 license. When using or
3  * redistributing this file, you may do so under either license.
4  *
5  *   BSD LICENSE
6  *
7  * Copyright 2013-2016 Freescale Semiconductor Inc.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  * * Neither the name of the above-listed copyright holders nor the
17  * names of any contributors may be used to endorse or promote products
18  * derived from this software without specific prior written permission.
19  *
20  *   GPL LICENSE SUMMARY
21  *
22  * ALTERNATIVELY, this software may be distributed under the terms of the
23  * GNU General Public License ("GPL") as published by the Free Software
24  * Foundation, either version 2 of that License or (at your option) any
25  * later version.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
31  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39 #include <fsl_mc_sys.h>
40 #include <fsl_mc_cmd.h>
41 #include <fsl_dpci.h>
42 #include <fsl_dpci_cmd.h>
43
44 int dpci_open(struct fsl_mc_io *mc_io,
45               uint32_t cmd_flags,
46               int dpci_id,
47               uint16_t *token)
48 {
49         struct mc_command cmd = { 0 };
50         int err;
51
52         /* prepare command */
53         cmd.header = mc_encode_cmd_header(DPCI_CMDID_OPEN,
54                                           cmd_flags,
55                                           0);
56         DPCI_CMD_OPEN(cmd, dpci_id);
57
58         /* send command to mc*/
59         err = mc_send_command(mc_io, &cmd);
60         if (err)
61                 return err;
62
63         /* retrieve response parameters */
64         *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
65
66         return 0;
67 }
68
69 int dpci_close(struct fsl_mc_io *mc_io,
70                uint32_t cmd_flags,
71                uint16_t token)
72 {
73         struct mc_command cmd = { 0 };
74
75         /* prepare command */
76         cmd.header = mc_encode_cmd_header(DPCI_CMDID_CLOSE,
77                                           cmd_flags,
78                                           token);
79
80         /* send command to mc*/
81         return mc_send_command(mc_io, &cmd);
82 }
83
84 int dpci_create(struct fsl_mc_io *mc_io,
85                 uint16_t dprc_token,
86                 uint32_t cmd_flags,
87                 const struct dpci_cfg *cfg,
88                 uint32_t *obj_id)
89 {
90         struct mc_command cmd = { 0 };
91         int err;
92
93         /* prepare command */
94         cmd.header = mc_encode_cmd_header(DPCI_CMDID_CREATE,
95                                           cmd_flags,
96                                           dprc_token);
97         DPCI_CMD_CREATE(cmd, cfg);
98
99         /* send command to mc*/
100         err = mc_send_command(mc_io, &cmd);
101         if (err)
102                 return err;
103
104         /* retrieve response parameters */
105         CMD_CREATE_RSP_GET_OBJ_ID_PARAM0(cmd, *obj_id);
106
107         return 0;
108 }
109
110 int dpci_destroy(struct fsl_mc_io *mc_io,
111                  uint16_t dprc_token,
112                 uint32_t cmd_flags,
113                 uint32_t object_id)
114 {
115         struct mc_command cmd = { 0 };
116
117         /* prepare command */
118         cmd.header = mc_encode_cmd_header(DPCI_CMDID_DESTROY,
119                                           cmd_flags,
120                                           dprc_token);
121         /* set object id to destroy */
122         CMD_DESTROY_SET_OBJ_ID_PARAM0(cmd, object_id);
123         /* send command to mc*/
124         return mc_send_command(mc_io, &cmd);
125 }
126
127 int dpci_enable(struct fsl_mc_io *mc_io,
128                 uint32_t cmd_flags,
129                 uint16_t token)
130 {
131         struct mc_command cmd = { 0 };
132
133         /* prepare command */
134         cmd.header = mc_encode_cmd_header(DPCI_CMDID_ENABLE,
135                                           cmd_flags,
136                                           token);
137
138         /* send command to mc*/
139         return mc_send_command(mc_io, &cmd);
140 }
141
142 int dpci_disable(struct fsl_mc_io *mc_io,
143                  uint32_t cmd_flags,
144                  uint16_t token)
145 {
146         struct mc_command cmd = { 0 };
147
148         /* prepare command */
149         cmd.header = mc_encode_cmd_header(DPCI_CMDID_DISABLE,
150                                           cmd_flags,
151                                           token);
152
153         /* send command to mc*/
154         return mc_send_command(mc_io, &cmd);
155 }
156
157 int dpci_is_enabled(struct fsl_mc_io *mc_io,
158                     uint32_t cmd_flags,
159                     uint16_t token,
160                     int *en)
161 {
162         struct mc_command cmd = { 0 };
163         int err;
164         /* prepare command */
165         cmd.header = mc_encode_cmd_header(DPCI_CMDID_IS_ENABLED, cmd_flags,
166                                           token);
167
168         /* send command to mc*/
169         err = mc_send_command(mc_io, &cmd);
170         if (err)
171                 return err;
172
173         /* retrieve response parameters */
174         DPCI_RSP_IS_ENABLED(cmd, *en);
175
176         return 0;
177 }
178
179 int dpci_reset(struct fsl_mc_io *mc_io,
180                uint32_t cmd_flags,
181                uint16_t token)
182 {
183         struct mc_command cmd = { 0 };
184
185         /* prepare command */
186         cmd.header = mc_encode_cmd_header(DPCI_CMDID_RESET,
187                                           cmd_flags,
188                                           token);
189
190         /* send command to mc*/
191         return mc_send_command(mc_io, &cmd);
192 }
193
194 int dpci_get_attributes(struct fsl_mc_io *mc_io,
195                         uint32_t cmd_flags,
196                         uint16_t token,
197                         struct dpci_attr *attr)
198 {
199         struct mc_command cmd = { 0 };
200         int err;
201
202         /* prepare command */
203         cmd.header = mc_encode_cmd_header(DPCI_CMDID_GET_ATTR,
204                                           cmd_flags,
205                                           token);
206
207         /* send command to mc*/
208         err = mc_send_command(mc_io, &cmd);
209         if (err)
210                 return err;
211
212         /* retrieve response parameters */
213         DPCI_RSP_GET_ATTRIBUTES(cmd, attr);
214
215         return 0;
216 }
217
218 int dpci_set_rx_queue(struct fsl_mc_io *mc_io,
219                       uint32_t cmd_flags,
220                       uint16_t token,
221                       uint8_t priority,
222                       const struct dpci_rx_queue_cfg *cfg)
223 {
224         struct mc_command cmd = { 0 };
225
226         /* prepare command */
227         cmd.header = mc_encode_cmd_header(DPCI_CMDID_SET_RX_QUEUE,
228                                           cmd_flags,
229                                           token);
230         DPCI_CMD_SET_RX_QUEUE(cmd, priority, cfg);
231
232         /* send command to mc*/
233         return mc_send_command(mc_io, &cmd);
234 }
235
236 int dpci_get_rx_queue(struct fsl_mc_io *mc_io,
237                       uint32_t cmd_flags,
238                       uint16_t token,
239                       uint8_t priority,
240                       struct dpci_rx_queue_attr *attr)
241 {
242         struct mc_command cmd = { 0 };
243         int err;
244
245         /* prepare command */
246         cmd.header = mc_encode_cmd_header(DPCI_CMDID_GET_RX_QUEUE,
247                                           cmd_flags,
248                                           token);
249         DPCI_CMD_GET_RX_QUEUE(cmd, priority);
250
251         /* send command to mc*/
252         err = mc_send_command(mc_io, &cmd);
253         if (err)
254                 return err;
255
256         /* retrieve response parameters */
257         DPCI_RSP_GET_RX_QUEUE(cmd, attr);
258
259         return 0;
260 }
261
262 int dpci_get_tx_queue(struct fsl_mc_io *mc_io,
263                       uint32_t cmd_flags,
264                       uint16_t token,
265                       uint8_t priority,
266                       struct dpci_tx_queue_attr *attr)
267 {
268         struct mc_command cmd = { 0 };
269         int err;
270
271         /* prepare command */
272         cmd.header = mc_encode_cmd_header(DPCI_CMDID_GET_TX_QUEUE,
273                                           cmd_flags,
274                                           token);
275         DPCI_CMD_GET_TX_QUEUE(cmd, priority);
276
277         /* send command to mc*/
278         err = mc_send_command(mc_io, &cmd);
279         if (err)
280                 return err;
281
282         /* retrieve response parameters */
283         DPCI_RSP_GET_TX_QUEUE(cmd, attr);
284
285         return 0;
286 }
287
288 int dpci_get_api_version(struct fsl_mc_io *mc_io,
289                          uint32_t cmd_flags,
290                            uint16_t *major_ver,
291                            uint16_t *minor_ver)
292 {
293         struct mc_command cmd = { 0 };
294         int err;
295
296         cmd.header = mc_encode_cmd_header(DPCI_CMDID_GET_API_VERSION,
297                                         cmd_flags,
298                                         0);
299
300         err = mc_send_command(mc_io, &cmd);
301         if (err)
302                 return err;
303
304         DPCI_RSP_GET_API_VERSION(cmd, *major_ver, *minor_ver);
305
306         return 0;
307 }