]> git.ipfire.org Git - people/ms/u-boot.git/blame - drivers/net/fsl-mc/dpni.c
drivers/fsl-mc: flib changes for mc 8.0.0
[people/ms/u-boot.git] / drivers / net / fsl-mc / dpni.c
CommitLineData
a2a55e51
PK
1/*
2 * Copyright (C) 2013-2015 Freescale Semiconductor
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <fsl-mc/fsl_mc_sys.h>
8#include <fsl-mc/fsl_mc_cmd.h>
9#include <fsl-mc/fsl_dpni.h>
10
87457d11
PK
11int dpni_open(struct fsl_mc_io *mc_io,
12 uint32_t cmd_flags,
13 int dpni_id,
14 uint16_t *token)
a2a55e51
PK
15{
16 struct mc_command cmd = { 0 };
17 int err;
18
19 /* prepare command */
20 cmd.header = mc_encode_cmd_header(DPNI_CMDID_OPEN,
87457d11
PK
21 cmd_flags,
22 0);
a2a55e51
PK
23 DPNI_CMD_OPEN(cmd, dpni_id);
24
25 /* send command to mc*/
26 err = mc_send_command(mc_io, &cmd);
27 if (err)
28 return err;
29
30 /* retrieve response parameters */
31 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
32
33 return 0;
34}
35
87457d11
PK
36int dpni_close(struct fsl_mc_io *mc_io,
37 uint32_t cmd_flags,
38 uint16_t token)
a2a55e51
PK
39{
40 struct mc_command cmd = { 0 };
41
42 /* prepare command */
43 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLOSE,
87457d11
PK
44 cmd_flags,
45 token);
a2a55e51
PK
46
47 /* send command to mc*/
48 return mc_send_command(mc_io, &cmd);
49}
50
51int dpni_set_pools(struct fsl_mc_io *mc_io,
87457d11 52 uint32_t cmd_flags,
a2a55e51
PK
53 uint16_t token,
54 const struct dpni_pools_cfg *cfg)
55{
56 struct mc_command cmd = { 0 };
57
58 /* prepare command */
59 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS,
87457d11 60 cmd_flags,
a2a55e51
PK
61 token);
62 DPNI_CMD_SET_POOLS(cmd, cfg);
63
64 /* send command to mc*/
65 return mc_send_command(mc_io, &cmd);
66}
67
87457d11
PK
68int dpni_enable(struct fsl_mc_io *mc_io,
69 uint32_t cmd_flags,
70 uint16_t token)
a2a55e51
PK
71{
72 struct mc_command cmd = { 0 };
73
74 /* prepare command */
75 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
87457d11
PK
76 cmd_flags,
77 token);
a2a55e51
PK
78
79 /* send command to mc*/
80 return mc_send_command(mc_io, &cmd);
81}
82
87457d11
PK
83int dpni_disable(struct fsl_mc_io *mc_io,
84 uint32_t cmd_flags,
85 uint16_t token)
a2a55e51
PK
86{
87 struct mc_command cmd = { 0 };
88
89 /* prepare command */
90 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
87457d11 91 cmd_flags,
a2a55e51
PK
92 token);
93
94 /* send command to mc*/
95 return mc_send_command(mc_io, &cmd);
96}
97
87457d11
PK
98int dpni_reset(struct fsl_mc_io *mc_io,
99 uint32_t cmd_flags,
100 uint16_t token)
a2a55e51
PK
101{
102 struct mc_command cmd = { 0 };
103
104 /* prepare command */
105 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
87457d11
PK
106 cmd_flags,
107 token);
a2a55e51
PK
108
109 /* send command to mc*/
110 return mc_send_command(mc_io, &cmd);
111}
112
113int dpni_get_attributes(struct fsl_mc_io *mc_io,
87457d11 114 uint32_t cmd_flags,
a2a55e51
PK
115 uint16_t token,
116 struct dpni_attr *attr)
117{
118 struct mc_command cmd = { 0 };
119 int err;
120
121 /* prepare command */
122 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
87457d11 123 cmd_flags,
a2a55e51
PK
124 token);
125
126 /* send command to mc*/
127 err = mc_send_command(mc_io, &cmd);
128 if (err)
129 return err;
130
131 /* retrieve response parameters */
132 DPNI_RSP_GET_ATTR(cmd, attr);
133
134 return 0;
135}
136
137int dpni_get_rx_buffer_layout(struct fsl_mc_io *mc_io,
87457d11 138 uint32_t cmd_flags,
a2a55e51
PK
139 uint16_t token,
140 struct dpni_buffer_layout *layout)
141{
142 struct mc_command cmd = { 0 };
143 int err;
144
145 /* prepare command */
146 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_RX_BUFFER_LAYOUT,
87457d11
PK
147 cmd_flags,
148 token);
a2a55e51
PK
149
150 /* send command to mc*/
151 err = mc_send_command(mc_io, &cmd);
152 if (err)
153 return err;
154
155 /* retrieve response parameters */
156 DPNI_RSP_GET_RX_BUFFER_LAYOUT(cmd, layout);
157
158 return 0;
159}
160
161int dpni_set_rx_buffer_layout(struct fsl_mc_io *mc_io,
87457d11 162 uint32_t cmd_flags,
a2a55e51
PK
163 uint16_t token,
164 const struct dpni_buffer_layout *layout)
165{
166 struct mc_command cmd = { 0 };
167
168 /* prepare command */
169 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_BUFFER_LAYOUT,
87457d11
PK
170 cmd_flags,
171 token);
a2a55e51
PK
172 DPNI_CMD_SET_RX_BUFFER_LAYOUT(cmd, layout);
173
174 /* send command to mc*/
175 return mc_send_command(mc_io, &cmd);
176}
177
178int dpni_get_tx_buffer_layout(struct fsl_mc_io *mc_io,
87457d11 179 uint32_t cmd_flags,
a2a55e51
PK
180 uint16_t token,
181 struct dpni_buffer_layout *layout)
182{
183 struct mc_command cmd = { 0 };
184 int err;
185
186 /* prepare command */
187 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_BUFFER_LAYOUT,
87457d11
PK
188 cmd_flags,
189 token);
a2a55e51
PK
190
191 /* send command to mc*/
192 err = mc_send_command(mc_io, &cmd);
193 if (err)
194 return err;
195
196 /* retrieve response parameters */
197 DPNI_RSP_GET_TX_BUFFER_LAYOUT(cmd, layout);
198
199 return 0;
200}
201
202int dpni_set_tx_buffer_layout(struct fsl_mc_io *mc_io,
87457d11 203 uint32_t cmd_flags,
a2a55e51
PK
204 uint16_t token,
205 const struct dpni_buffer_layout *layout)
206{
207 struct mc_command cmd = { 0 };
208
209 /* prepare command */
210 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_BUFFER_LAYOUT,
87457d11
PK
211 cmd_flags,
212 token);
a2a55e51
PK
213 DPNI_CMD_SET_TX_BUFFER_LAYOUT(cmd, layout);
214
215 /* send command to mc*/
216 return mc_send_command(mc_io, &cmd);
217}
218
219int dpni_get_tx_conf_buffer_layout(struct fsl_mc_io *mc_io,
87457d11 220 uint32_t cmd_flags,
a2a55e51
PK
221 uint16_t token,
222 struct dpni_buffer_layout *layout)
223{
224 struct mc_command cmd = { 0 };
225 int err;
226
227 /* prepare command */
228 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_CONF_BUFFER_LAYOUT,
87457d11
PK
229 cmd_flags,
230 token);
a2a55e51
PK
231
232 /* send command to mc*/
233 err = mc_send_command(mc_io, &cmd);
234 if (err)
235 return err;
236
237 /* retrieve response parameters */
238 DPNI_RSP_GET_TX_CONF_BUFFER_LAYOUT(cmd, layout);
239
240 return 0;
241}
242
243int dpni_set_tx_conf_buffer_layout(struct fsl_mc_io *mc_io,
87457d11 244 uint32_t cmd_flags,
a2a55e51
PK
245 uint16_t token,
246 const struct dpni_buffer_layout *layout)
247{
248 struct mc_command cmd = { 0 };
249
250 /* prepare command */
251 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONF_BUFFER_LAYOUT,
87457d11
PK
252 cmd_flags,
253 token);
a2a55e51
PK
254 DPNI_CMD_SET_TX_CONF_BUFFER_LAYOUT(cmd, layout);
255
256 /* send command to mc*/
257 return mc_send_command(mc_io, &cmd);
258}
259
87457d11
PK
260int dpni_get_qdid(struct fsl_mc_io *mc_io,
261 uint32_t cmd_flags,
262 uint16_t token,
263 uint16_t *qdid)
a2a55e51
PK
264{
265 struct mc_command cmd = { 0 };
266 int err;
267
268 /* prepare command */
269 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
87457d11 270 cmd_flags,
a2a55e51
PK
271 token);
272
273 /* send command to mc*/
274 err = mc_send_command(mc_io, &cmd);
275 if (err)
276 return err;
277
278 /* retrieve response parameters */
279 DPNI_RSP_GET_QDID(cmd, *qdid);
280
281 return 0;
282}
283
284int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
87457d11 285 uint32_t cmd_flags,
a2a55e51
PK
286 uint16_t token,
287 uint16_t *data_offset)
288{
289 struct mc_command cmd = { 0 };
290 int err;
291
292 /* prepare command */
293 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
87457d11
PK
294 cmd_flags,
295 token);
a2a55e51
PK
296
297 /* send command to mc*/
298 err = mc_send_command(mc_io, &cmd);
299 if (err)
300 return err;
301
302 /* retrieve response parameters */
303 DPNI_RSP_GET_TX_DATA_OFFSET(cmd, *data_offset);
304
305 return 0;
306}
307
308int dpni_get_counter(struct fsl_mc_io *mc_io,
87457d11 309 uint32_t cmd_flags,
a2a55e51
PK
310 uint16_t token,
311 enum dpni_counter counter,
312 uint64_t *value)
313{
314 struct mc_command cmd = { 0 };
315 int err;
316
317 /* prepare command */
318 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_COUNTER,
87457d11
PK
319 cmd_flags,
320 token);
a2a55e51
PK
321 DPNI_CMD_GET_COUNTER(cmd, counter);
322
323 /* send command to mc*/
324 err = mc_send_command(mc_io, &cmd);
325 if (err)
326 return err;
327
328 /* retrieve response parameters */
329 DPNI_RSP_GET_COUNTER(cmd, *value);
330
331 return 0;
332}
333
334int dpni_set_counter(struct fsl_mc_io *mc_io,
87457d11 335 uint32_t cmd_flags,
a2a55e51
PK
336 uint16_t token,
337 enum dpni_counter counter,
338 uint64_t value)
339{
340 struct mc_command cmd = { 0 };
341
342 /* prepare command */
343 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_COUNTER,
87457d11
PK
344 cmd_flags,
345 token);
a2a55e51
PK
346 DPNI_CMD_SET_COUNTER(cmd, counter, value);
347
348 /* send command to mc*/
349 return mc_send_command(mc_io, &cmd);
350}
351
352int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
87457d11 353 uint32_t cmd_flags,
a2a55e51 354 uint16_t token,
87457d11 355 const struct dpni_link_cfg *cfg)
a2a55e51
PK
356{
357 struct mc_command cmd = { 0 };
358
359 /* prepare command */
360 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
87457d11
PK
361 cmd_flags,
362 token);
a2a55e51
PK
363 DPNI_CMD_SET_LINK_CFG(cmd, cfg);
364
365 /* send command to mc*/
366 return mc_send_command(mc_io, &cmd);
367}
368
369int dpni_get_link_state(struct fsl_mc_io *mc_io,
87457d11 370 uint32_t cmd_flags,
a2a55e51
PK
371 uint16_t token,
372 struct dpni_link_state *state)
373{
374 struct mc_command cmd = { 0 };
375 int err;
376
377 /* prepare command */
378 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
87457d11
PK
379 cmd_flags,
380 token);
a2a55e51
PK
381
382 /* send command to mc*/
383 err = mc_send_command(mc_io, &cmd);
384 if (err)
385 return err;
386
387 /* retrieve response parameters */
388 DPNI_RSP_GET_LINK_STATE(cmd, state);
389
390 return 0;
391}
392
393
394int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
87457d11 395 uint32_t cmd_flags,
a2a55e51
PK
396 uint16_t token,
397 const uint8_t mac_addr[6])
398{
399 struct mc_command cmd = { 0 };
400
401 /* prepare command */
402 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
87457d11
PK
403 cmd_flags,
404 token);
a2a55e51
PK
405 DPNI_CMD_SET_PRIMARY_MAC_ADDR(cmd, mac_addr);
406
407 /* send command to mc*/
408 return mc_send_command(mc_io, &cmd);
409}
410
411int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
87457d11 412 uint32_t cmd_flags,
a2a55e51
PK
413 uint16_t token,
414 uint8_t mac_addr[6])
415{
416 struct mc_command cmd = { 0 };
417 int err;
418
419 /* prepare command */
420 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
87457d11
PK
421 cmd_flags,
422 token);
a2a55e51
PK
423
424 /* send command to mc*/
425 err = mc_send_command(mc_io, &cmd);
426 if (err)
427 return err;
428
429 /* retrieve response parameters */
430 DPNI_RSP_GET_PRIMARY_MAC_ADDR(cmd, mac_addr);
431
432 return 0;
433}
434
435int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
87457d11 436 uint32_t cmd_flags,
a2a55e51
PK
437 uint16_t token,
438 const uint8_t mac_addr[6])
439{
440 struct mc_command cmd = { 0 };
441
442 /* prepare command */
443 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
87457d11
PK
444 cmd_flags,
445 token);
a2a55e51
PK
446 DPNI_CMD_ADD_MAC_ADDR(cmd, mac_addr);
447
448 /* send command to mc*/
449 return mc_send_command(mc_io, &cmd);
450}
451
452int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
87457d11 453 uint32_t cmd_flags,
a2a55e51
PK
454 uint16_t token,
455 const uint8_t mac_addr[6])
456{
457 struct mc_command cmd = { 0 };
458
459 /* prepare command */
460 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
87457d11
PK
461 cmd_flags,
462 token);
a2a55e51
PK
463 DPNI_CMD_REMOVE_MAC_ADDR(cmd, mac_addr);
464
465 /* send command to mc*/
466 return mc_send_command(mc_io, &cmd);
467}
468
469int dpni_set_tx_flow(struct fsl_mc_io *mc_io,
87457d11 470 uint32_t cmd_flags,
a2a55e51
PK
471 uint16_t token,
472 uint16_t *flow_id,
473 const struct dpni_tx_flow_cfg *cfg)
474{
475 struct mc_command cmd = { 0 };
476 int err;
477
478 /* prepare command */
479 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_FLOW,
87457d11
PK
480 cmd_flags,
481 token);
a2a55e51
PK
482 DPNI_CMD_SET_TX_FLOW(cmd, *flow_id, cfg);
483
484 /* send command to mc*/
485 err = mc_send_command(mc_io, &cmd);
486 if (err)
487 return err;
488
489 /* retrieve response parameters */
490 DPNI_RSP_SET_TX_FLOW(cmd, *flow_id);
491
492 return 0;
493}
494
495int dpni_get_tx_flow(struct fsl_mc_io *mc_io,
87457d11 496 uint32_t cmd_flags,
a2a55e51
PK
497 uint16_t token,
498 uint16_t flow_id,
499 struct dpni_tx_flow_attr *attr)
500{
501 struct mc_command cmd = { 0 };
502 int err;
503
504 /* prepare command */
505 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_FLOW,
87457d11
PK
506 cmd_flags,
507 token);
a2a55e51
PK
508 DPNI_CMD_GET_TX_FLOW(cmd, flow_id);
509
510 /* send command to mc*/
511 err = mc_send_command(mc_io, &cmd);
512 if (err)
513 return err;
514
515 /* retrieve response parameters */
516 DPNI_RSP_GET_TX_FLOW(cmd, attr);
517
518 return 0;
519}
520
521int dpni_set_rx_flow(struct fsl_mc_io *mc_io,
87457d11 522 uint32_t cmd_flags,
a2a55e51
PK
523 uint16_t token,
524 uint8_t tc_id,
525 uint16_t flow_id,
526 const struct dpni_queue_cfg *cfg)
527{
528 struct mc_command cmd = { 0 };
529
530 /* prepare command */
531 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_FLOW,
87457d11
PK
532 cmd_flags,
533 token);
a2a55e51
PK
534 DPNI_CMD_SET_RX_FLOW(cmd, tc_id, flow_id, cfg);
535
536 /* send command to mc*/
537 return mc_send_command(mc_io, &cmd);
538}
539
540int dpni_get_rx_flow(struct fsl_mc_io *mc_io,
87457d11 541 uint32_t cmd_flags,
a2a55e51
PK
542 uint16_t token,
543 uint8_t tc_id,
544 uint16_t flow_id,
545 struct dpni_queue_attr *attr)
546{
547 struct mc_command cmd = { 0 };
548 int err;
549 /* prepare command */
550 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_RX_FLOW,
87457d11
PK
551 cmd_flags,
552 token);
a2a55e51
PK
553 DPNI_CMD_GET_RX_FLOW(cmd, tc_id, flow_id);
554
555 /* send command to mc*/
556 err = mc_send_command(mc_io, &cmd);
557 if (err)
558 return err;
559
560 /* retrieve response parameters */
561 DPNI_RSP_GET_RX_FLOW(cmd, attr);
562
563 return 0;
564}