net/dpaa2: add support for multicast promiscuous mode
[dpdk.git] / drivers / net / dpaa2 / mc / dpni.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  * Copyright (c) 2016 NXP.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  * * Neither the name of the above-listed copyright holders nor the
18  * names of any contributors may be used to endorse or promote products
19  * derived from this software without specific prior written permission.
20  *
21  *   GPL LICENSE SUMMARY
22  *
23  * ALTERNATIVELY, this software may be distributed under the terms of the
24  * GNU General Public License ("GPL") as published by the Free Software
25  * Foundation, either version 2 of that License or (at your option) any
26  * later version.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
32  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  */
40 #include <fsl_mc_sys.h>
41 #include <fsl_mc_cmd.h>
42 #include <fsl_dpni.h>
43 #include <fsl_dpni_cmd.h>
44
45 int dpni_prepare_key_cfg(const struct dpkg_profile_cfg *cfg,
46                          uint8_t *key_cfg_buf)
47 {
48         int i, j;
49         int offset = 0;
50         int param = 1;
51         uint64_t *params = (uint64_t *)key_cfg_buf;
52
53         if (!key_cfg_buf || !cfg)
54                 return -EINVAL;
55
56         params[0] |= mc_enc(0, 8, cfg->num_extracts);
57         params[0] = cpu_to_le64(params[0]);
58
59         if (cfg->num_extracts >= DPKG_MAX_NUM_OF_EXTRACTS)
60                 return -EINVAL;
61
62         for (i = 0; i < cfg->num_extracts; i++) {
63                 switch (cfg->extracts[i].type) {
64                 case DPKG_EXTRACT_FROM_HDR:
65                         params[param] |= mc_enc(0, 8,
66                                         cfg->extracts[i].extract.from_hdr.prot);
67                         params[param] |= mc_enc(8, 4,
68                                         cfg->extracts[i].extract.from_hdr.type);
69                         params[param] |= mc_enc(16, 8,
70                                         cfg->extracts[i].extract.from_hdr.size);
71                         params[param] |= mc_enc(24, 8,
72                                         cfg->extracts[i].extract.
73                                         from_hdr.offset);
74                         params[param] |= mc_enc(32, 32,
75                                         cfg->extracts[i].extract.
76                                         from_hdr.field);
77                         params[param] = cpu_to_le64(params[param]);
78                         param++;
79                         params[param] |= mc_enc(0, 8,
80                                         cfg->extracts[i].extract.
81                                         from_hdr.hdr_index);
82                         break;
83                 case DPKG_EXTRACT_FROM_DATA:
84                         params[param] |= mc_enc(16, 8,
85                                         cfg->extracts[i].extract.
86                                         from_data.size);
87                         params[param] |= mc_enc(24, 8,
88                                         cfg->extracts[i].extract.
89                                         from_data.offset);
90                         params[param] = cpu_to_le64(params[param]);
91                         param++;
92                         break;
93                 case DPKG_EXTRACT_FROM_PARSE:
94                         params[param] |= mc_enc(16, 8,
95                                         cfg->extracts[i].extract.
96                                         from_parse.size);
97                         params[param] |= mc_enc(24, 8,
98                                         cfg->extracts[i].extract.
99                                         from_parse.offset);
100                         params[param] = cpu_to_le64(params[param]);
101                         param++;
102                         break;
103                 default:
104                         return -EINVAL;
105                 }
106                 params[param] |= mc_enc(
107                         24, 8, cfg->extracts[i].num_of_byte_masks);
108                 params[param] |= mc_enc(32, 4, cfg->extracts[i].type);
109                 params[param] = cpu_to_le64(params[param]);
110                 param++;
111                 for (offset = 0, j = 0;
112                         j < DPKG_NUM_OF_MASKS;
113                         offset += 16, j++) {
114                         params[param] |= mc_enc(
115                                 (offset), 8, cfg->extracts[i].masks[j].mask);
116                         params[param] |= mc_enc(
117                                 (offset + 8), 8,
118                                 cfg->extracts[i].masks[j].offset);
119                 }
120                 params[param] = cpu_to_le64(params[param]);
121                 param++;
122         }
123         return 0;
124 }
125
126 int dpni_open(struct fsl_mc_io *mc_io,
127               uint32_t cmd_flags,
128               int dpni_id,
129               uint16_t *token)
130 {
131         struct mc_command cmd = { 0 };
132         int err;
133
134         /* prepare command */
135         cmd.header = mc_encode_cmd_header(DPNI_CMDID_OPEN,
136                                           cmd_flags,
137                                           0);
138         DPNI_CMD_OPEN(cmd, dpni_id);
139
140         /* send command to mc*/
141         err = mc_send_command(mc_io, &cmd);
142         if (err)
143                 return err;
144
145         /* retrieve response parameters */
146         *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
147
148         return 0;
149 }
150
151 int dpni_close(struct fsl_mc_io *mc_io,
152                uint32_t cmd_flags,
153                uint16_t token)
154 {
155         struct mc_command cmd = { 0 };
156
157         /* prepare command */
158         cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLOSE,
159                                           cmd_flags,
160                                           token);
161
162         /* send command to mc*/
163         return mc_send_command(mc_io, &cmd);
164 }
165
166 int dpni_create(struct fsl_mc_io        *mc_io,
167                 uint16_t        dprc_token,
168                 uint32_t        cmd_flags,
169                 const struct dpni_cfg   *cfg,
170                 uint32_t        *obj_id)
171 {
172         struct mc_command cmd = { 0 };
173         int err;
174
175         /* prepare command */
176         cmd.header = mc_encode_cmd_header(DPNI_CMDID_CREATE,
177                                           cmd_flags,
178                                           dprc_token);
179         DPNI_CMD_CREATE(cmd, cfg);
180
181         /* send command to mc*/
182         err = mc_send_command(mc_io, &cmd);
183         if (err)
184                 return err;
185
186         /* retrieve response parameters */
187         CMD_CREATE_RSP_GET_OBJ_ID_PARAM0(cmd, *obj_id);
188
189         return 0;
190 }
191
192 int dpni_destroy(struct fsl_mc_io       *mc_io,
193                  uint16_t       dprc_token,
194                 uint32_t        cmd_flags,
195                 uint32_t        object_id)
196 {
197         struct mc_command cmd = { 0 };
198
199         /* prepare command */
200         cmd.header = mc_encode_cmd_header(DPNI_CMDID_DESTROY,
201                                           cmd_flags,
202                                           dprc_token);
203         /* set object id to destroy */
204         CMD_DESTROY_SET_OBJ_ID_PARAM0(cmd, object_id);
205         /* send command to mc*/
206         return mc_send_command(mc_io, &cmd);
207 }
208
209 int dpni_set_pools(struct fsl_mc_io *mc_io,
210                    uint32_t cmd_flags,
211                    uint16_t token,
212                    const struct dpni_pools_cfg *cfg)
213 {
214         struct mc_command cmd = { 0 };
215
216         /* prepare command */
217         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS,
218                                           cmd_flags,
219                                           token);
220         DPNI_CMD_SET_POOLS(cmd, cfg);
221
222         /* send command to mc*/
223         return mc_send_command(mc_io, &cmd);
224 }
225
226 int dpni_enable(struct fsl_mc_io *mc_io,
227                 uint32_t cmd_flags,
228                 uint16_t token)
229 {
230         struct mc_command cmd = { 0 };
231
232         /* prepare command */
233         cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
234                                           cmd_flags,
235                                           token);
236
237         /* send command to mc*/
238         return mc_send_command(mc_io, &cmd);
239 }
240
241 int dpni_disable(struct fsl_mc_io *mc_io,
242                  uint32_t cmd_flags,
243                  uint16_t token)
244 {
245         struct mc_command cmd = { 0 };
246
247         /* prepare command */
248         cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
249                                           cmd_flags,
250                                           token);
251
252         /* send command to mc*/
253         return mc_send_command(mc_io, &cmd);
254 }
255
256 int dpni_is_enabled(struct fsl_mc_io *mc_io,
257                     uint32_t cmd_flags,
258                     uint16_t token,
259                     int *en)
260 {
261         struct mc_command cmd = { 0 };
262         int err;
263         /* prepare command */
264         cmd.header = mc_encode_cmd_header(DPNI_CMDID_IS_ENABLED, cmd_flags,
265                                           token);
266
267         /* send command to mc*/
268         err = mc_send_command(mc_io, &cmd);
269         if (err)
270                 return err;
271
272         /* retrieve response parameters */
273         DPNI_RSP_IS_ENABLED(cmd, *en);
274
275         return 0;
276 }
277
278 int dpni_reset(struct fsl_mc_io *mc_io,
279                uint32_t cmd_flags,
280                uint16_t token)
281 {
282         struct mc_command cmd = { 0 };
283
284         /* prepare command */
285         cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
286                                           cmd_flags,
287                                           token);
288
289         /* send command to mc*/
290         return mc_send_command(mc_io, &cmd);
291 }
292
293 int dpni_get_attributes(struct fsl_mc_io *mc_io,
294                         uint32_t cmd_flags,
295                         uint16_t token,
296                         struct dpni_attr *attr)
297 {
298         struct mc_command cmd = { 0 };
299         int err;
300
301         /* prepare command */
302         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
303                                           cmd_flags,
304                                           token);
305
306         /* send command to mc*/
307         err = mc_send_command(mc_io, &cmd);
308         if (err)
309                 return err;
310
311         /* retrieve response parameters */
312         DPNI_RSP_GET_ATTR(cmd, attr);
313
314         return 0;
315 }
316
317 int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
318                              uint32_t cmd_flags,
319                              uint16_t token,
320                               struct dpni_error_cfg *cfg)
321 {
322         struct mc_command cmd = { 0 };
323
324         /* prepare command */
325         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_ERRORS_BEHAVIOR,
326                                           cmd_flags,
327                                           token);
328         DPNI_CMD_SET_ERRORS_BEHAVIOR(cmd, cfg);
329
330         /* send command to mc*/
331         return mc_send_command(mc_io, &cmd);
332 }
333
334 int dpni_get_buffer_layout(struct fsl_mc_io *mc_io,
335                            uint32_t cmd_flags,
336                            uint16_t token,
337                            enum dpni_queue_type qtype,
338                            struct dpni_buffer_layout *layout)
339 {
340         struct mc_command cmd = { 0 };
341         int err;
342
343         /* prepare command */
344         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_BUFFER_LAYOUT,
345                                           cmd_flags,
346                                           token);
347         DPNI_CMD_GET_BUFFER_LAYOUT(cmd, qtype);
348
349         /* send command to mc*/
350         err = mc_send_command(mc_io, &cmd);
351         if (err)
352                 return err;
353
354         /* retrieve response parameters */
355         DPNI_RSP_GET_BUFFER_LAYOUT(cmd, layout);
356
357         return 0;
358 }
359
360 int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
361                            uint32_t cmd_flags,
362                               uint16_t token,
363                               enum dpni_queue_type qtype,
364                               const struct dpni_buffer_layout *layout)
365 {
366         struct mc_command cmd = { 0 };
367
368         /* prepare command */
369         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT,
370                                           cmd_flags,
371                                           token);
372         DPNI_CMD_SET_BUFFER_LAYOUT(cmd, qtype, layout);
373
374         /* send command to mc*/
375         return mc_send_command(mc_io, &cmd);
376 }
377
378 int dpni_set_offload(struct fsl_mc_io *mc_io,
379                      uint32_t cmd_flags,
380                      uint16_t token,
381                      enum dpni_offload type,
382                      uint32_t config)
383 {
384         struct mc_command cmd = { 0 };
385
386         /* prepare command */
387         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_OFFLOAD,
388                                           cmd_flags,
389                                           token);
390         DPNI_CMD_SET_OFFLOAD(cmd, type, config);
391
392         /* send command to mc*/
393         return mc_send_command(mc_io, &cmd);
394 }
395
396 int dpni_get_offload(struct fsl_mc_io *mc_io,
397                      uint32_t cmd_flags,
398                      uint16_t token,
399                      enum dpni_offload type,
400                      uint32_t *config)
401 {
402         struct mc_command cmd = { 0 };
403         int err;
404
405         /* prepare command */
406         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OFFLOAD,
407                                           cmd_flags,
408                                           token);
409         DPNI_CMD_GET_OFFLOAD(cmd, type);
410
411         /* send command to mc*/
412         err = mc_send_command(mc_io, &cmd);
413         if (err)
414                 return err;
415
416         /* retrieve response parameters */
417         DPNI_RSP_GET_OFFLOAD(cmd, *config);
418
419         return 0;
420 }
421
422 int dpni_get_qdid(struct fsl_mc_io *mc_io,
423                   uint32_t cmd_flags,
424                   uint16_t token,
425                   enum dpni_queue_type qtype,
426                   uint16_t *qdid)
427 {
428         struct mc_command cmd = { 0 };
429         int err;
430
431         /* prepare command */
432         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
433                                           cmd_flags,
434                                           token);
435         DPNI_CMD_GET_QDID(cmd, qtype);
436
437         /* send command to mc*/
438         err = mc_send_command(mc_io, &cmd);
439         if (err)
440                 return err;
441
442         /* retrieve response parameters */
443         DPNI_RSP_GET_QDID(cmd, *qdid);
444
445         return 0;
446 }
447 int dpni_get_link_state(struct fsl_mc_io *mc_io,
448                         uint32_t cmd_flags,
449                         uint16_t token,
450                         struct dpni_link_state *state)
451 {
452         struct mc_command cmd = { 0 };
453         int err;
454
455         /* prepare command */
456         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
457                                           cmd_flags,
458                                           token);
459
460         /* send command to mc*/
461         err = mc_send_command(mc_io, &cmd);
462         if (err)
463                 return err;
464
465         /* retrieve response parameters */
466         DPNI_RSP_GET_LINK_STATE(cmd, state);
467
468         return 0;
469 }
470
471 int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
472                               uint32_t cmd_flags,
473                               uint16_t token,
474                               uint16_t max_frame_length)
475 {
476         struct mc_command cmd = { 0 };
477
478         /* prepare command */
479         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MAX_FRAME_LENGTH,
480                                           cmd_flags,
481                                           token);
482         DPNI_CMD_SET_MAX_FRAME_LENGTH(cmd, max_frame_length);
483
484         /* send command to mc*/
485         return mc_send_command(mc_io, &cmd);
486 }
487
488 int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
489                               uint32_t cmd_flags,
490                               uint16_t token,
491                               uint16_t *max_frame_length)
492 {
493         struct mc_command cmd = { 0 };
494         int err;
495
496         /* prepare command */
497         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MAX_FRAME_LENGTH,
498                                           cmd_flags,
499                                           token);
500
501         /* send command to mc*/
502         err = mc_send_command(mc_io, &cmd);
503         if (err)
504                 return err;
505
506         /* retrieve response parameters */
507         DPNI_RSP_GET_MAX_FRAME_LENGTH(cmd, *max_frame_length);
508
509         return 0;
510 }
511
512 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
513                                uint32_t cmd_flags,
514                                uint16_t token,
515                                int en)
516 {
517         struct mc_command cmd = { 0 };
518
519         /* prepare command */
520         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MCAST_PROMISC,
521                                           cmd_flags,
522                                           token);
523         DPNI_CMD_SET_MULTICAST_PROMISC(cmd, en);
524
525         /* send command to mc*/
526         return mc_send_command(mc_io, &cmd);
527 }
528
529 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
530                                uint32_t cmd_flags,
531                                uint16_t token,
532                                int *en)
533 {
534         struct mc_command cmd = { 0 };
535         int err;
536
537         /* prepare command */
538         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MCAST_PROMISC,
539                                           cmd_flags,
540                                           token);
541
542         /* send command to mc*/
543         err = mc_send_command(mc_io, &cmd);
544         if (err)
545                 return err;
546
547         /* retrieve response parameters */
548         DPNI_RSP_GET_MULTICAST_PROMISC(cmd, *en);
549
550         return 0;
551 }
552
553 int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io,
554                              uint32_t cmd_flags,
555                              uint16_t token,
556                              int en)
557 {
558         struct mc_command cmd = { 0 };
559
560         /* prepare command */
561         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_UNICAST_PROMISC,
562                                           cmd_flags,
563                                           token);
564         DPNI_CMD_SET_UNICAST_PROMISC(cmd, en);
565
566         /* send command to mc*/
567         return mc_send_command(mc_io, &cmd);
568 }
569
570 int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io,
571                              uint32_t cmd_flags,
572                              uint16_t token,
573                              int *en)
574 {
575         struct mc_command cmd = { 0 };
576         int err;
577
578         /* prepare command */
579         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_UNICAST_PROMISC,
580                                           cmd_flags,
581                                           token);
582
583         /* send command to mc*/
584         err = mc_send_command(mc_io, &cmd);
585         if (err)
586                 return err;
587
588         /* retrieve response parameters */
589         DPNI_RSP_GET_UNICAST_PROMISC(cmd, *en);
590
591         return 0;
592 }
593
594 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
595                               uint32_t cmd_flags,
596                               uint16_t token,
597                               const uint8_t mac_addr[6])
598 {
599         struct mc_command cmd = { 0 };
600
601         /* prepare command */
602         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
603                                           cmd_flags,
604                                           token);
605         DPNI_CMD_SET_PRIMARY_MAC_ADDR(cmd, mac_addr);
606
607         /* send command to mc*/
608         return mc_send_command(mc_io, &cmd);
609 }
610
611 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
612                               uint32_t cmd_flags,
613                               uint16_t token,
614                               uint8_t mac_addr[6])
615 {
616         struct mc_command cmd = { 0 };
617         int err;
618
619         /* prepare command */
620         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
621                                           cmd_flags,
622                                           token);
623
624         /* send command to mc*/
625         err = mc_send_command(mc_io, &cmd);
626         if (err)
627                 return err;
628
629         /* retrieve response parameters */
630         DPNI_RSP_GET_PRIMARY_MAC_ADDR(cmd, mac_addr);
631
632         return 0;
633 }
634
635 int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
636                       uint32_t cmd_flags,
637                       uint16_t token,
638                       const uint8_t mac_addr[6])
639 {
640         struct mc_command cmd = { 0 };
641
642         /* prepare command */
643         cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
644                                           cmd_flags,
645                                           token);
646         DPNI_CMD_ADD_MAC_ADDR(cmd, mac_addr);
647
648         /* send command to mc*/
649         return mc_send_command(mc_io, &cmd);
650 }
651
652 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
653                          uint32_t cmd_flags,
654                          uint16_t token,
655                          const uint8_t mac_addr[6])
656 {
657         struct mc_command cmd = { 0 };
658
659         /* prepare command */
660         cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
661                                           cmd_flags,
662                                           token);
663         DPNI_CMD_REMOVE_MAC_ADDR(cmd, mac_addr);
664
665         /* send command to mc*/
666         return mc_send_command(mc_io, &cmd);
667 }
668
669 int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
670                            uint32_t cmd_flags,
671                            uint16_t token,
672                            int unicast,
673                            int multicast)
674 {
675         struct mc_command cmd = { 0 };
676
677         /* prepare command */
678         cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_MAC_FILTERS,
679                                           cmd_flags,
680                                           token);
681         DPNI_CMD_CLEAR_MAC_FILTERS(cmd, unicast, multicast);
682
683         /* send command to mc*/
684         return mc_send_command(mc_io, &cmd);
685 }
686
687 int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
688                            uint32_t cmd_flags,
689                            uint16_t token,
690                            uint8_t mac_addr[6])
691 {
692         struct mc_command cmd = { 0 };
693         int err;
694
695         /* prepare command */
696         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PORT_MAC_ADDR,
697                                           cmd_flags,
698                                           token);
699
700         /* send command to mc*/
701         err = mc_send_command(mc_io, &cmd);
702         if (err)
703                 return err;
704
705         /* retrieve response parameters */
706         DPNI_RSP_GET_PORT_MAC_ADDR(cmd, mac_addr);
707
708         return 0;
709 }
710
711 int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
712                         uint32_t cmd_flags,
713                         uint16_t token,
714                         uint8_t tc_id,
715                         const struct dpni_rx_tc_dist_cfg *cfg)
716 {
717         struct mc_command cmd = { 0 };
718
719         /* prepare command */
720         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_DIST,
721                                           cmd_flags,
722                                           token);
723         DPNI_CMD_SET_RX_TC_DIST(cmd, tc_id, cfg);
724
725         /* send command to mc*/
726         return mc_send_command(mc_io, &cmd);
727 }
728
729 int dpni_set_tx_confirmation_mode(struct fsl_mc_io      *mc_io,
730                                   uint32_t              cmd_flags,
731                             uint16_t            token,
732                             enum dpni_confirmation_mode mode)
733 {
734         struct mc_command cmd = { 0 };
735
736         /* prepare command */
737         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONFIRMATION_MODE,
738                                           cmd_flags,
739                                           token);
740         DPNI_CMD_SET_TX_CONFIRMATION_MODE(cmd, mode);
741
742         /* send command to mc*/
743         return mc_send_command(mc_io, &cmd);
744 }
745
746 int dpni_set_congestion_notification(
747                         struct fsl_mc_io        *mc_io,
748                         uint32_t                cmd_flags,
749                         uint16_t                token,
750                         enum dpni_queue_type qtype,
751                         uint8_t         tc_id,
752                         const struct dpni_congestion_notification_cfg *cfg)
753 {
754         struct mc_command cmd = { 0 };
755
756         /* prepare command */
757         cmd.header = mc_encode_cmd_header(
758                         DPNI_CMDID_SET_CONGESTION_NOTIFICATION,
759                         cmd_flags,
760                         token);
761         DPNI_CMD_SET_CONGESTION_NOTIFICATION(cmd, qtype, tc_id, cfg);
762
763         /* send command to mc*/
764         return mc_send_command(mc_io, &cmd);
765 }
766
767 int dpni_get_congestion_notification(struct fsl_mc_io   *mc_io,
768                                      uint32_t           cmd_flags,
769                                            uint16_t             token,
770                                      enum dpni_queue_type qtype,
771                                            uint8_t              tc_id,
772                                 struct dpni_congestion_notification_cfg *cfg)
773 {
774         struct mc_command cmd = { 0 };
775         int err;
776
777         /* prepare command */
778         cmd.header = mc_encode_cmd_header(
779                         DPNI_CMDID_GET_CONGESTION_NOTIFICATION,
780                         cmd_flags,
781                         token);
782         DPNI_CMD_GET_CONGESTION_NOTIFICATION(cmd, qtype, tc_id);
783
784         /* send command to mc*/
785         err = mc_send_command(mc_io, &cmd);
786         if (err)
787                 return err;
788
789         DPNI_RSP_GET_CONGESTION_NOTIFICATION(cmd, cfg);
790
791         return 0;
792 }
793
794 int dpni_get_api_version(struct fsl_mc_io *mc_io,
795                          uint32_t cmd_flags,
796                            uint16_t *major_ver,
797                            uint16_t *minor_ver)
798 {
799         struct mc_command cmd = { 0 };
800         int err;
801
802         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION,
803                                         cmd_flags,
804                                         0);
805
806         err = mc_send_command(mc_io, &cmd);
807         if (err)
808                 return err;
809
810         DPNI_RSP_GET_API_VERSION(cmd, *major_ver, *minor_ver);
811
812         return 0;
813 }
814
815 int dpni_set_queue(struct fsl_mc_io *mc_io,
816                    uint32_t cmd_flags,
817                      uint16_t token,
818                    enum dpni_queue_type qtype,
819                          uint8_t tc,
820                          uint8_t index,
821                    uint8_t options,
822                      const struct dpni_queue *queue)
823 {
824         struct mc_command cmd = { 0 };
825
826         /* prepare command */
827         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE,
828                                           cmd_flags,
829                                           token);
830         DPNI_CMD_SET_QUEUE(cmd, qtype, tc, index, options, queue);
831
832         /* send command to mc*/
833         return mc_send_command(mc_io, &cmd);
834 }
835
836 int dpni_get_queue(struct fsl_mc_io *mc_io,
837                    uint32_t cmd_flags,
838                      uint16_t token,
839                    enum dpni_queue_type qtype,
840                          uint8_t tc,
841                          uint8_t index,
842                    struct dpni_queue *queue,
843                    struct dpni_queue_id *qid)
844 {
845         struct mc_command cmd = { 0 };
846         int err;
847
848         /* prepare command */
849         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE,
850                                           cmd_flags,
851                                           token);
852         DPNI_CMD_GET_QUEUE(cmd, qtype, tc, index);
853
854         /* send command to mc*/
855         err = mc_send_command(mc_io, &cmd);
856         if (err)
857                 return err;
858
859         /* retrieve response parameters */
860         DPNI_RSP_GET_QUEUE(cmd, queue, qid);
861
862         return 0;
863 }
864
865 int dpni_get_statistics(struct fsl_mc_io *mc_io,
866                         uint32_t cmd_flags,
867                         uint16_t token,
868                         uint8_t page,
869                         union dpni_statistics *stat)
870 {
871         struct mc_command cmd = { 0 };
872         int err;
873
874         /* prepare command */
875         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS,
876                                           cmd_flags,
877                                           token);
878         DPNI_CMD_GET_STATISTICS(cmd, page);
879
880         /* send command to mc*/
881         err = mc_send_command(mc_io, &cmd);
882         if (err)
883                 return err;
884
885         /* retrieve response parameters */
886         DPNI_RSP_GET_STATISTICS(cmd, stat);
887
888         return 0;
889 }
890
891 int dpni_reset_statistics(struct fsl_mc_io *mc_io,
892                           uint32_t cmd_flags,
893                      uint16_t token)
894 {
895         struct mc_command cmd = { 0 };
896
897         /* prepare command */
898         cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET_STATISTICS,
899                                           cmd_flags,
900                                           token);
901
902         /* send command to mc*/
903         return mc_send_command(mc_io, &cmd);
904 }
905
906 int dpni_set_taildrop(struct fsl_mc_io *mc_io,
907                       uint32_t cmd_flags,
908                       uint16_t token,
909                       enum dpni_congestion_point cg_point,
910                       enum dpni_queue_type q_type,
911                       uint8_t tc,
912                       uint8_t q_index,
913                       struct dpni_taildrop *taildrop)
914 {
915         struct mc_command cmd = { 0 };
916
917         /* prepare command */
918         cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TAILDROP,
919                                           cmd_flags,
920                                           token);
921         DPNI_CMD_SET_TAILDROP(cmd, cg_point, q_type, tc, q_index, taildrop);
922
923         /* send command to mc*/
924         return mc_send_command(mc_io, &cmd);
925 }
926
927 int dpni_get_taildrop(struct fsl_mc_io *mc_io,
928                       uint32_t cmd_flags,
929                      uint16_t token,
930                          enum dpni_congestion_point cg_point,
931                          enum dpni_queue_type q_type,
932                          uint8_t tc,
933                          uint8_t q_index,
934                          struct dpni_taildrop *taildrop)
935 {
936         struct mc_command cmd = { 0 };
937         int err;
938
939         /* prepare command */
940         cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TAILDROP,
941                                           cmd_flags,
942                                           token);
943         DPNI_CMD_GET_TAILDROP(cmd, cg_point, q_type, tc, q_index);
944
945         /* send command to mc*/
946         err = mc_send_command(mc_io, &cmd);
947         if (err)
948                 return err;
949
950         /* retrieve response parameters */
951         DPNI_RSP_GET_TAILDROP(cmd, taildrop);
952
953         return 0;
954 }