1
2
3
4
5#include <linux/kernel.h>
6#include <linux/errno.h>
7#include <linux/fsl/mc.h>
8#include "dpni.h"
9#include "dpni-cmd.h"
10
11
12
13
14
15
16
17
18
19
20int dpni_prepare_key_cfg(const struct dpkg_profile_cfg *cfg, u8 *key_cfg_buf)
21{
22 int i, j;
23 struct dpni_ext_set_rx_tc_dist *dpni_ext;
24 struct dpni_dist_extract *extr;
25
26 if (cfg->num_extracts > DPKG_MAX_NUM_OF_EXTRACTS)
27 return -EINVAL;
28
29 dpni_ext = (struct dpni_ext_set_rx_tc_dist *)key_cfg_buf;
30 dpni_ext->num_extracts = cfg->num_extracts;
31
32 for (i = 0; i < cfg->num_extracts; i++) {
33 extr = &dpni_ext->extracts[i];
34
35 switch (cfg->extracts[i].type) {
36 case DPKG_EXTRACT_FROM_HDR:
37 extr->prot = cfg->extracts[i].extract.from_hdr.prot;
38 dpni_set_field(extr->efh_type, EFH_TYPE,
39 cfg->extracts[i].extract.from_hdr.type);
40 extr->size = cfg->extracts[i].extract.from_hdr.size;
41 extr->offset = cfg->extracts[i].extract.from_hdr.offset;
42 extr->field = cpu_to_le32(
43 cfg->extracts[i].extract.from_hdr.field);
44 extr->hdr_index =
45 cfg->extracts[i].extract.from_hdr.hdr_index;
46 break;
47 case DPKG_EXTRACT_FROM_DATA:
48 extr->size = cfg->extracts[i].extract.from_data.size;
49 extr->offset =
50 cfg->extracts[i].extract.from_data.offset;
51 break;
52 case DPKG_EXTRACT_FROM_PARSE:
53 extr->size = cfg->extracts[i].extract.from_parse.size;
54 extr->offset =
55 cfg->extracts[i].extract.from_parse.offset;
56 break;
57 default:
58 return -EINVAL;
59 }
60
61 extr->num_of_byte_masks = cfg->extracts[i].num_of_byte_masks;
62 dpni_set_field(extr->extract_type, EXTRACT_TYPE,
63 cfg->extracts[i].type);
64
65 for (j = 0; j < DPKG_NUM_OF_MASKS; j++) {
66 extr->masks[j].mask = cfg->extracts[i].masks[j].mask;
67 extr->masks[j].offset =
68 cfg->extracts[i].masks[j].offset;
69 }
70 }
71
72 return 0;
73}
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92int dpni_open(struct fsl_mc_io *mc_io,
93 u32 cmd_flags,
94 int dpni_id,
95 u16 *token)
96{
97 struct fsl_mc_command cmd = { 0 };
98 struct dpni_cmd_open *cmd_params;
99
100 int err;
101
102
103 cmd.header = mc_encode_cmd_header(DPNI_CMDID_OPEN,
104 cmd_flags,
105 0);
106 cmd_params = (struct dpni_cmd_open *)cmd.params;
107 cmd_params->dpni_id = cpu_to_le32(dpni_id);
108
109
110 err = mc_send_command(mc_io, &cmd);
111 if (err)
112 return err;
113
114
115 *token = mc_cmd_hdr_read_token(&cmd);
116
117 return 0;
118}
119
120
121
122
123
124
125
126
127
128
129
130
131int dpni_close(struct fsl_mc_io *mc_io,
132 u32 cmd_flags,
133 u16 token)
134{
135 struct fsl_mc_command cmd = { 0 };
136
137
138 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLOSE,
139 cmd_flags,
140 token);
141
142
143 return mc_send_command(mc_io, &cmd);
144}
145
146
147
148
149
150
151
152
153
154
155
156
157
158int dpni_set_pools(struct fsl_mc_io *mc_io,
159 u32 cmd_flags,
160 u16 token,
161 const struct dpni_pools_cfg *cfg)
162{
163 struct fsl_mc_command cmd = { 0 };
164 struct dpni_cmd_set_pools *cmd_params;
165 int i;
166
167
168 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS,
169 cmd_flags,
170 token);
171 cmd_params = (struct dpni_cmd_set_pools *)cmd.params;
172 cmd_params->num_dpbp = cfg->num_dpbp;
173 for (i = 0; i < DPNI_MAX_DPBP; i++) {
174 cmd_params->dpbp_id[i] = cpu_to_le32(cfg->pools[i].dpbp_id);
175 cmd_params->buffer_size[i] =
176 cpu_to_le16(cfg->pools[i].buffer_size);
177 cmd_params->backup_pool_mask |=
178 DPNI_BACKUP_POOL(cfg->pools[i].backup_pool, i);
179 }
180
181
182 return mc_send_command(mc_io, &cmd);
183}
184
185
186
187
188
189
190
191
192
193int dpni_enable(struct fsl_mc_io *mc_io,
194 u32 cmd_flags,
195 u16 token)
196{
197 struct fsl_mc_command cmd = { 0 };
198
199
200 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
201 cmd_flags,
202 token);
203
204
205 return mc_send_command(mc_io, &cmd);
206}
207
208
209
210
211
212
213
214
215
216int dpni_disable(struct fsl_mc_io *mc_io,
217 u32 cmd_flags,
218 u16 token)
219{
220 struct fsl_mc_command cmd = { 0 };
221
222
223 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
224 cmd_flags,
225 token);
226
227
228 return mc_send_command(mc_io, &cmd);
229}
230
231
232
233
234
235
236
237
238
239
240int dpni_is_enabled(struct fsl_mc_io *mc_io,
241 u32 cmd_flags,
242 u16 token,
243 int *en)
244{
245 struct fsl_mc_command cmd = { 0 };
246 struct dpni_rsp_is_enabled *rsp_params;
247 int err;
248
249
250 cmd.header = mc_encode_cmd_header(DPNI_CMDID_IS_ENABLED,
251 cmd_flags,
252 token);
253
254
255 err = mc_send_command(mc_io, &cmd);
256 if (err)
257 return err;
258
259
260 rsp_params = (struct dpni_rsp_is_enabled *)cmd.params;
261 *en = dpni_get_field(rsp_params->enabled, ENABLE);
262
263 return 0;
264}
265
266
267
268
269
270
271
272
273
274int dpni_reset(struct fsl_mc_io *mc_io,
275 u32 cmd_flags,
276 u16 token)
277{
278 struct fsl_mc_command cmd = { 0 };
279
280
281 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
282 cmd_flags,
283 token);
284
285
286 return mc_send_command(mc_io, &cmd);
287}
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304int dpni_set_irq_enable(struct fsl_mc_io *mc_io,
305 u32 cmd_flags,
306 u16 token,
307 u8 irq_index,
308 u8 en)
309{
310 struct fsl_mc_command cmd = { 0 };
311 struct dpni_cmd_set_irq_enable *cmd_params;
312
313
314 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_ENABLE,
315 cmd_flags,
316 token);
317 cmd_params = (struct dpni_cmd_set_irq_enable *)cmd.params;
318 dpni_set_field(cmd_params->enable, ENABLE, en);
319 cmd_params->irq_index = irq_index;
320
321
322 return mc_send_command(mc_io, &cmd);
323}
324
325
326
327
328
329
330
331
332
333
334
335int dpni_get_irq_enable(struct fsl_mc_io *mc_io,
336 u32 cmd_flags,
337 u16 token,
338 u8 irq_index,
339 u8 *en)
340{
341 struct fsl_mc_command cmd = { 0 };
342 struct dpni_cmd_get_irq_enable *cmd_params;
343 struct dpni_rsp_get_irq_enable *rsp_params;
344
345 int err;
346
347
348 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_ENABLE,
349 cmd_flags,
350 token);
351 cmd_params = (struct dpni_cmd_get_irq_enable *)cmd.params;
352 cmd_params->irq_index = irq_index;
353
354
355 err = mc_send_command(mc_io, &cmd);
356 if (err)
357 return err;
358
359
360 rsp_params = (struct dpni_rsp_get_irq_enable *)cmd.params;
361 *en = dpni_get_field(rsp_params->enabled, ENABLE);
362
363 return 0;
364}
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382int dpni_set_irq_mask(struct fsl_mc_io *mc_io,
383 u32 cmd_flags,
384 u16 token,
385 u8 irq_index,
386 u32 mask)
387{
388 struct fsl_mc_command cmd = { 0 };
389 struct dpni_cmd_set_irq_mask *cmd_params;
390
391
392 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_MASK,
393 cmd_flags,
394 token);
395 cmd_params = (struct dpni_cmd_set_irq_mask *)cmd.params;
396 cmd_params->mask = cpu_to_le32(mask);
397 cmd_params->irq_index = irq_index;
398
399
400 return mc_send_command(mc_io, &cmd);
401}
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416int dpni_get_irq_mask(struct fsl_mc_io *mc_io,
417 u32 cmd_flags,
418 u16 token,
419 u8 irq_index,
420 u32 *mask)
421{
422 struct fsl_mc_command cmd = { 0 };
423 struct dpni_cmd_get_irq_mask *cmd_params;
424 struct dpni_rsp_get_irq_mask *rsp_params;
425 int err;
426
427
428 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_MASK,
429 cmd_flags,
430 token);
431 cmd_params = (struct dpni_cmd_get_irq_mask *)cmd.params;
432 cmd_params->irq_index = irq_index;
433
434
435 err = mc_send_command(mc_io, &cmd);
436 if (err)
437 return err;
438
439
440 rsp_params = (struct dpni_rsp_get_irq_mask *)cmd.params;
441 *mask = le32_to_cpu(rsp_params->mask);
442
443 return 0;
444}
445
446
447
448
449
450
451
452
453
454
455
456
457
458int dpni_get_irq_status(struct fsl_mc_io *mc_io,
459 u32 cmd_flags,
460 u16 token,
461 u8 irq_index,
462 u32 *status)
463{
464 struct fsl_mc_command cmd = { 0 };
465 struct dpni_cmd_get_irq_status *cmd_params;
466 struct dpni_rsp_get_irq_status *rsp_params;
467 int err;
468
469
470 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_STATUS,
471 cmd_flags,
472 token);
473 cmd_params = (struct dpni_cmd_get_irq_status *)cmd.params;
474 cmd_params->status = cpu_to_le32(*status);
475 cmd_params->irq_index = irq_index;
476
477
478 err = mc_send_command(mc_io, &cmd);
479 if (err)
480 return err;
481
482
483 rsp_params = (struct dpni_rsp_get_irq_status *)cmd.params;
484 *status = le32_to_cpu(rsp_params->status);
485
486 return 0;
487}
488
489
490
491
492
493
494
495
496
497
498
499
500
501int dpni_clear_irq_status(struct fsl_mc_io *mc_io,
502 u32 cmd_flags,
503 u16 token,
504 u8 irq_index,
505 u32 status)
506{
507 struct fsl_mc_command cmd = { 0 };
508 struct dpni_cmd_clear_irq_status *cmd_params;
509
510
511 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLEAR_IRQ_STATUS,
512 cmd_flags,
513 token);
514 cmd_params = (struct dpni_cmd_clear_irq_status *)cmd.params;
515 cmd_params->irq_index = irq_index;
516 cmd_params->status = cpu_to_le32(status);
517
518
519 return mc_send_command(mc_io, &cmd);
520}
521
522
523
524
525
526
527
528
529
530
531int dpni_get_attributes(struct fsl_mc_io *mc_io,
532 u32 cmd_flags,
533 u16 token,
534 struct dpni_attr *attr)
535{
536 struct fsl_mc_command cmd = { 0 };
537 struct dpni_rsp_get_attr *rsp_params;
538
539 int err;
540
541
542 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
543 cmd_flags,
544 token);
545
546
547 err = mc_send_command(mc_io, &cmd);
548 if (err)
549 return err;
550
551
552 rsp_params = (struct dpni_rsp_get_attr *)cmd.params;
553 attr->options = le32_to_cpu(rsp_params->options);
554 attr->num_queues = rsp_params->num_queues;
555 attr->num_tcs = rsp_params->num_tcs;
556 attr->mac_filter_entries = rsp_params->mac_filter_entries;
557 attr->vlan_filter_entries = rsp_params->vlan_filter_entries;
558 attr->qos_entries = rsp_params->qos_entries;
559 attr->fs_entries = le16_to_cpu(rsp_params->fs_entries);
560 attr->qos_key_size = rsp_params->qos_key_size;
561 attr->fs_key_size = rsp_params->fs_key_size;
562 attr->wriop_version = le16_to_cpu(rsp_params->wriop_version);
563
564 return 0;
565}
566
567
568
569
570
571
572
573
574
575
576
577
578
579int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
580 u32 cmd_flags,
581 u16 token,
582 struct dpni_error_cfg *cfg)
583{
584 struct fsl_mc_command cmd = { 0 };
585 struct dpni_cmd_set_errors_behavior *cmd_params;
586
587
588 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_ERRORS_BEHAVIOR,
589 cmd_flags,
590 token);
591 cmd_params = (struct dpni_cmd_set_errors_behavior *)cmd.params;
592 cmd_params->errors = cpu_to_le32(cfg->errors);
593 dpni_set_field(cmd_params->flags, ERROR_ACTION, cfg->error_action);
594 dpni_set_field(cmd_params->flags, FRAME_ANN, cfg->set_frame_annotation);
595
596
597 return mc_send_command(mc_io, &cmd);
598}
599
600
601
602
603
604
605
606
607
608
609
610int dpni_get_buffer_layout(struct fsl_mc_io *mc_io,
611 u32 cmd_flags,
612 u16 token,
613 enum dpni_queue_type qtype,
614 struct dpni_buffer_layout *layout)
615{
616 struct fsl_mc_command cmd = { 0 };
617 struct dpni_cmd_get_buffer_layout *cmd_params;
618 struct dpni_rsp_get_buffer_layout *rsp_params;
619 int err;
620
621
622 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_BUFFER_LAYOUT,
623 cmd_flags,
624 token);
625 cmd_params = (struct dpni_cmd_get_buffer_layout *)cmd.params;
626 cmd_params->qtype = qtype;
627
628
629 err = mc_send_command(mc_io, &cmd);
630 if (err)
631 return err;
632
633
634 rsp_params = (struct dpni_rsp_get_buffer_layout *)cmd.params;
635 layout->pass_timestamp = dpni_get_field(rsp_params->flags, PASS_TS);
636 layout->pass_parser_result = dpni_get_field(rsp_params->flags, PASS_PR);
637 layout->pass_frame_status = dpni_get_field(rsp_params->flags, PASS_FS);
638 layout->private_data_size = le16_to_cpu(rsp_params->private_data_size);
639 layout->data_align = le16_to_cpu(rsp_params->data_align);
640 layout->data_head_room = le16_to_cpu(rsp_params->head_room);
641 layout->data_tail_room = le16_to_cpu(rsp_params->tail_room);
642
643 return 0;
644}
645
646
647
648
649
650
651
652
653
654
655
656
657
658int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
659 u32 cmd_flags,
660 u16 token,
661 enum dpni_queue_type qtype,
662 const struct dpni_buffer_layout *layout)
663{
664 struct fsl_mc_command cmd = { 0 };
665 struct dpni_cmd_set_buffer_layout *cmd_params;
666
667
668 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT,
669 cmd_flags,
670 token);
671 cmd_params = (struct dpni_cmd_set_buffer_layout *)cmd.params;
672 cmd_params->qtype = qtype;
673 cmd_params->options = cpu_to_le16(layout->options);
674 dpni_set_field(cmd_params->flags, PASS_TS, layout->pass_timestamp);
675 dpni_set_field(cmd_params->flags, PASS_PR, layout->pass_parser_result);
676 dpni_set_field(cmd_params->flags, PASS_FS, layout->pass_frame_status);
677 cmd_params->private_data_size = cpu_to_le16(layout->private_data_size);
678 cmd_params->data_align = cpu_to_le16(layout->data_align);
679 cmd_params->head_room = cpu_to_le16(layout->data_head_room);
680 cmd_params->tail_room = cpu_to_le16(layout->data_tail_room);
681
682
683 return mc_send_command(mc_io, &cmd);
684}
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700int dpni_set_offload(struct fsl_mc_io *mc_io,
701 u32 cmd_flags,
702 u16 token,
703 enum dpni_offload type,
704 u32 config)
705{
706 struct fsl_mc_command cmd = { 0 };
707 struct dpni_cmd_set_offload *cmd_params;
708
709 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_OFFLOAD,
710 cmd_flags,
711 token);
712 cmd_params = (struct dpni_cmd_set_offload *)cmd.params;
713 cmd_params->dpni_offload = type;
714 cmd_params->config = cpu_to_le32(config);
715
716 return mc_send_command(mc_io, &cmd);
717}
718
719int dpni_get_offload(struct fsl_mc_io *mc_io,
720 u32 cmd_flags,
721 u16 token,
722 enum dpni_offload type,
723 u32 *config)
724{
725 struct fsl_mc_command cmd = { 0 };
726 struct dpni_cmd_get_offload *cmd_params;
727 struct dpni_rsp_get_offload *rsp_params;
728 int err;
729
730
731 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OFFLOAD,
732 cmd_flags,
733 token);
734 cmd_params = (struct dpni_cmd_get_offload *)cmd.params;
735 cmd_params->dpni_offload = type;
736
737
738 err = mc_send_command(mc_io, &cmd);
739 if (err)
740 return err;
741
742
743 rsp_params = (struct dpni_rsp_get_offload *)cmd.params;
744 *config = le32_to_cpu(rsp_params->config);
745
746 return 0;
747}
748
749
750
751
752
753
754
755
756
757
758
759
760
761int dpni_get_qdid(struct fsl_mc_io *mc_io,
762 u32 cmd_flags,
763 u16 token,
764 enum dpni_queue_type qtype,
765 u16 *qdid)
766{
767 struct fsl_mc_command cmd = { 0 };
768 struct dpni_cmd_get_qdid *cmd_params;
769 struct dpni_rsp_get_qdid *rsp_params;
770 int err;
771
772
773 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
774 cmd_flags,
775 token);
776 cmd_params = (struct dpni_cmd_get_qdid *)cmd.params;
777 cmd_params->qtype = qtype;
778
779
780 err = mc_send_command(mc_io, &cmd);
781 if (err)
782 return err;
783
784
785 rsp_params = (struct dpni_rsp_get_qdid *)cmd.params;
786 *qdid = le16_to_cpu(rsp_params->qdid);
787
788 return 0;
789}
790
791
792
793
794
795
796
797
798
799
800int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
801 u32 cmd_flags,
802 u16 token,
803 u16 *data_offset)
804{
805 struct fsl_mc_command cmd = { 0 };
806 struct dpni_rsp_get_tx_data_offset *rsp_params;
807 int err;
808
809
810 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
811 cmd_flags,
812 token);
813
814
815 err = mc_send_command(mc_io, &cmd);
816 if (err)
817 return err;
818
819
820 rsp_params = (struct dpni_rsp_get_tx_data_offset *)cmd.params;
821 *data_offset = le16_to_cpu(rsp_params->data_offset);
822
823 return 0;
824}
825
826
827
828
829
830
831
832
833
834
835int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
836 u32 cmd_flags,
837 u16 token,
838 const struct dpni_link_cfg *cfg)
839{
840 struct fsl_mc_command cmd = { 0 };
841 struct dpni_cmd_set_link_cfg *cmd_params;
842
843
844 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
845 cmd_flags,
846 token);
847 cmd_params = (struct dpni_cmd_set_link_cfg *)cmd.params;
848 cmd_params->rate = cpu_to_le32(cfg->rate);
849 cmd_params->options = cpu_to_le64(cfg->options);
850
851
852 return mc_send_command(mc_io, &cmd);
853}
854
855
856
857
858
859
860
861
862
863
864int dpni_get_link_state(struct fsl_mc_io *mc_io,
865 u32 cmd_flags,
866 u16 token,
867 struct dpni_link_state *state)
868{
869 struct fsl_mc_command cmd = { 0 };
870 struct dpni_rsp_get_link_state *rsp_params;
871 int err;
872
873
874 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
875 cmd_flags,
876 token);
877
878
879 err = mc_send_command(mc_io, &cmd);
880 if (err)
881 return err;
882
883
884 rsp_params = (struct dpni_rsp_get_link_state *)cmd.params;
885 state->up = dpni_get_field(rsp_params->flags, LINK_STATE);
886 state->rate = le32_to_cpu(rsp_params->rate);
887 state->options = le64_to_cpu(rsp_params->options);
888
889 return 0;
890}
891
892
893
894
895
896
897
898
899
900
901
902
903int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
904 u32 cmd_flags,
905 u16 token,
906 u16 max_frame_length)
907{
908 struct fsl_mc_command cmd = { 0 };
909 struct dpni_cmd_set_max_frame_length *cmd_params;
910
911
912 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MAX_FRAME_LENGTH,
913 cmd_flags,
914 token);
915 cmd_params = (struct dpni_cmd_set_max_frame_length *)cmd.params;
916 cmd_params->max_frame_length = cpu_to_le16(max_frame_length);
917
918
919 return mc_send_command(mc_io, &cmd);
920}
921
922
923
924
925
926
927
928
929
930
931
932
933int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
934 u32 cmd_flags,
935 u16 token,
936 u16 *max_frame_length)
937{
938 struct fsl_mc_command cmd = { 0 };
939 struct dpni_rsp_get_max_frame_length *rsp_params;
940 int err;
941
942
943 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MAX_FRAME_LENGTH,
944 cmd_flags,
945 token);
946
947
948 err = mc_send_command(mc_io, &cmd);
949 if (err)
950 return err;
951
952
953 rsp_params = (struct dpni_rsp_get_max_frame_length *)cmd.params;
954 *max_frame_length = le16_to_cpu(rsp_params->max_frame_length);
955
956 return 0;
957}
958
959
960
961
962
963
964
965
966
967
968int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
969 u32 cmd_flags,
970 u16 token,
971 int en)
972{
973 struct fsl_mc_command cmd = { 0 };
974 struct dpni_cmd_set_multicast_promisc *cmd_params;
975
976
977 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MCAST_PROMISC,
978 cmd_flags,
979 token);
980 cmd_params = (struct dpni_cmd_set_multicast_promisc *)cmd.params;
981 dpni_set_field(cmd_params->enable, ENABLE, en);
982
983
984 return mc_send_command(mc_io, &cmd);
985}
986
987
988
989
990
991
992
993
994
995
996int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
997 u32 cmd_flags,
998 u16 token,
999 int *en)
1000{
1001 struct fsl_mc_command cmd = { 0 };
1002 struct dpni_rsp_get_multicast_promisc *rsp_params;
1003 int err;
1004
1005
1006 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MCAST_PROMISC,
1007 cmd_flags,
1008 token);
1009
1010
1011 err = mc_send_command(mc_io, &cmd);
1012 if (err)
1013 return err;
1014
1015
1016 rsp_params = (struct dpni_rsp_get_multicast_promisc *)cmd.params;
1017 *en = dpni_get_field(rsp_params->enabled, ENABLE);
1018
1019 return 0;
1020}
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io,
1032 u32 cmd_flags,
1033 u16 token,
1034 int en)
1035{
1036 struct fsl_mc_command cmd = { 0 };
1037 struct dpni_cmd_set_unicast_promisc *cmd_params;
1038
1039
1040 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_UNICAST_PROMISC,
1041 cmd_flags,
1042 token);
1043 cmd_params = (struct dpni_cmd_set_unicast_promisc *)cmd.params;
1044 dpni_set_field(cmd_params->enable, ENABLE, en);
1045
1046
1047 return mc_send_command(mc_io, &cmd);
1048}
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io,
1060 u32 cmd_flags,
1061 u16 token,
1062 int *en)
1063{
1064 struct fsl_mc_command cmd = { 0 };
1065 struct dpni_rsp_get_unicast_promisc *rsp_params;
1066 int err;
1067
1068
1069 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_UNICAST_PROMISC,
1070 cmd_flags,
1071 token);
1072
1073
1074 err = mc_send_command(mc_io, &cmd);
1075 if (err)
1076 return err;
1077
1078
1079 rsp_params = (struct dpni_rsp_get_unicast_promisc *)cmd.params;
1080 *en = dpni_get_field(rsp_params->enabled, ENABLE);
1081
1082 return 0;
1083}
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
1095 u32 cmd_flags,
1096 u16 token,
1097 const u8 mac_addr[6])
1098{
1099 struct fsl_mc_command cmd = { 0 };
1100 struct dpni_cmd_set_primary_mac_addr *cmd_params;
1101 int i;
1102
1103
1104 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
1105 cmd_flags,
1106 token);
1107 cmd_params = (struct dpni_cmd_set_primary_mac_addr *)cmd.params;
1108 for (i = 0; i < 6; i++)
1109 cmd_params->mac_addr[i] = mac_addr[5 - i];
1110
1111
1112 return mc_send_command(mc_io, &cmd);
1113}
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
1125 u32 cmd_flags,
1126 u16 token,
1127 u8 mac_addr[6])
1128{
1129 struct fsl_mc_command cmd = { 0 };
1130 struct dpni_rsp_get_primary_mac_addr *rsp_params;
1131 int i, err;
1132
1133
1134 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
1135 cmd_flags,
1136 token);
1137
1138
1139 err = mc_send_command(mc_io, &cmd);
1140 if (err)
1141 return err;
1142
1143
1144 rsp_params = (struct dpni_rsp_get_primary_mac_addr *)cmd.params;
1145 for (i = 0; i < 6; i++)
1146 mac_addr[5 - i] = rsp_params->mac_addr[i];
1147
1148 return 0;
1149}
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
1164 u32 cmd_flags,
1165 u16 token,
1166 u8 mac_addr[6])
1167{
1168 struct fsl_mc_command cmd = { 0 };
1169 struct dpni_rsp_get_port_mac_addr *rsp_params;
1170 int i, err;
1171
1172
1173 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PORT_MAC_ADDR,
1174 cmd_flags,
1175 token);
1176
1177
1178 err = mc_send_command(mc_io, &cmd);
1179 if (err)
1180 return err;
1181
1182
1183 rsp_params = (struct dpni_rsp_get_port_mac_addr *)cmd.params;
1184 for (i = 0; i < 6; i++)
1185 mac_addr[5 - i] = rsp_params->mac_addr[i];
1186
1187 return 0;
1188}
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
1200 u32 cmd_flags,
1201 u16 token,
1202 const u8 mac_addr[6])
1203{
1204 struct fsl_mc_command cmd = { 0 };
1205 struct dpni_cmd_add_mac_addr *cmd_params;
1206 int i;
1207
1208
1209 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
1210 cmd_flags,
1211 token);
1212 cmd_params = (struct dpni_cmd_add_mac_addr *)cmd.params;
1213 for (i = 0; i < 6; i++)
1214 cmd_params->mac_addr[i] = mac_addr[5 - i];
1215
1216
1217 return mc_send_command(mc_io, &cmd);
1218}
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
1230 u32 cmd_flags,
1231 u16 token,
1232 const u8 mac_addr[6])
1233{
1234 struct fsl_mc_command cmd = { 0 };
1235 struct dpni_cmd_remove_mac_addr *cmd_params;
1236 int i;
1237
1238
1239 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
1240 cmd_flags,
1241 token);
1242 cmd_params = (struct dpni_cmd_remove_mac_addr *)cmd.params;
1243 for (i = 0; i < 6; i++)
1244 cmd_params->mac_addr[i] = mac_addr[5 - i];
1245
1246
1247 return mc_send_command(mc_io, &cmd);
1248}
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
1263 u32 cmd_flags,
1264 u16 token,
1265 int unicast,
1266 int multicast)
1267{
1268 struct fsl_mc_command cmd = { 0 };
1269 struct dpni_cmd_clear_mac_filters *cmd_params;
1270
1271
1272 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_MAC_FILTERS,
1273 cmd_flags,
1274 token);
1275 cmd_params = (struct dpni_cmd_clear_mac_filters *)cmd.params;
1276 dpni_set_field(cmd_params->flags, UNICAST_FILTERS, unicast);
1277 dpni_set_field(cmd_params->flags, MULTICAST_FILTERS, multicast);
1278
1279
1280 return mc_send_command(mc_io, &cmd);
1281}
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
1297 u32 cmd_flags,
1298 u16 token,
1299 u8 tc_id,
1300 const struct dpni_rx_tc_dist_cfg *cfg)
1301{
1302 struct fsl_mc_command cmd = { 0 };
1303 struct dpni_cmd_set_rx_tc_dist *cmd_params;
1304
1305
1306 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_DIST,
1307 cmd_flags,
1308 token);
1309 cmd_params = (struct dpni_cmd_set_rx_tc_dist *)cmd.params;
1310 cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
1311 cmd_params->tc_id = tc_id;
1312 dpni_set_field(cmd_params->flags, DIST_MODE, cfg->dist_mode);
1313 dpni_set_field(cmd_params->flags, MISS_ACTION, cfg->fs_cfg.miss_action);
1314 cmd_params->default_flow_id = cpu_to_le16(cfg->fs_cfg.default_flow_id);
1315 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1316
1317
1318 return mc_send_command(mc_io, &cmd);
1319}
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337int dpni_set_queue(struct fsl_mc_io *mc_io,
1338 u32 cmd_flags,
1339 u16 token,
1340 enum dpni_queue_type qtype,
1341 u8 tc,
1342 u8 index,
1343 u8 options,
1344 const struct dpni_queue *queue)
1345{
1346 struct fsl_mc_command cmd = { 0 };
1347 struct dpni_cmd_set_queue *cmd_params;
1348
1349
1350 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE,
1351 cmd_flags,
1352 token);
1353 cmd_params = (struct dpni_cmd_set_queue *)cmd.params;
1354 cmd_params->qtype = qtype;
1355 cmd_params->tc = tc;
1356 cmd_params->index = index;
1357 cmd_params->options = options;
1358 cmd_params->dest_id = cpu_to_le32(queue->destination.id);
1359 cmd_params->dest_prio = queue->destination.priority;
1360 dpni_set_field(cmd_params->flags, DEST_TYPE, queue->destination.type);
1361 dpni_set_field(cmd_params->flags, STASH_CTRL, queue->flc.stash_control);
1362 dpni_set_field(cmd_params->flags, HOLD_ACTIVE,
1363 queue->destination.hold_active);
1364 cmd_params->flc = cpu_to_le64(queue->flc.value);
1365 cmd_params->user_context = cpu_to_le64(queue->user_context);
1366
1367
1368 return mc_send_command(mc_io, &cmd);
1369}
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385int dpni_get_queue(struct fsl_mc_io *mc_io,
1386 u32 cmd_flags,
1387 u16 token,
1388 enum dpni_queue_type qtype,
1389 u8 tc,
1390 u8 index,
1391 struct dpni_queue *queue,
1392 struct dpni_queue_id *qid)
1393{
1394 struct fsl_mc_command cmd = { 0 };
1395 struct dpni_cmd_get_queue *cmd_params;
1396 struct dpni_rsp_get_queue *rsp_params;
1397 int err;
1398
1399
1400 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE,
1401 cmd_flags,
1402 token);
1403 cmd_params = (struct dpni_cmd_get_queue *)cmd.params;
1404 cmd_params->qtype = qtype;
1405 cmd_params->tc = tc;
1406 cmd_params->index = index;
1407
1408
1409 err = mc_send_command(mc_io, &cmd);
1410 if (err)
1411 return err;
1412
1413
1414 rsp_params = (struct dpni_rsp_get_queue *)cmd.params;
1415 queue->destination.id = le32_to_cpu(rsp_params->dest_id);
1416 queue->destination.priority = rsp_params->dest_prio;
1417 queue->destination.type = dpni_get_field(rsp_params->flags,
1418 DEST_TYPE);
1419 queue->flc.stash_control = dpni_get_field(rsp_params->flags,
1420 STASH_CTRL);
1421 queue->destination.hold_active = dpni_get_field(rsp_params->flags,
1422 HOLD_ACTIVE);
1423 queue->flc.value = le64_to_cpu(rsp_params->flc);
1424 queue->user_context = le64_to_cpu(rsp_params->user_context);
1425 qid->fqid = le32_to_cpu(rsp_params->fqid);
1426 qid->qdbin = le16_to_cpu(rsp_params->qdbin);
1427
1428 return 0;
1429}
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442int dpni_get_statistics(struct fsl_mc_io *mc_io,
1443 u32 cmd_flags,
1444 u16 token,
1445 u8 page,
1446 union dpni_statistics *stat)
1447{
1448 struct fsl_mc_command cmd = { 0 };
1449 struct dpni_cmd_get_statistics *cmd_params;
1450 struct dpni_rsp_get_statistics *rsp_params;
1451 int i, err;
1452
1453
1454 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS,
1455 cmd_flags,
1456 token);
1457 cmd_params = (struct dpni_cmd_get_statistics *)cmd.params;
1458 cmd_params->page_number = page;
1459
1460
1461 err = mc_send_command(mc_io, &cmd);
1462 if (err)
1463 return err;
1464
1465
1466 rsp_params = (struct dpni_rsp_get_statistics *)cmd.params;
1467 for (i = 0; i < DPNI_STATISTICS_CNT; i++)
1468 stat->raw.counter[i] = le64_to_cpu(rsp_params->counter[i]);
1469
1470 return 0;
1471}
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488int dpni_set_taildrop(struct fsl_mc_io *mc_io,
1489 u32 cmd_flags,
1490 u16 token,
1491 enum dpni_congestion_point cg_point,
1492 enum dpni_queue_type qtype,
1493 u8 tc,
1494 u8 index,
1495 struct dpni_taildrop *taildrop)
1496{
1497 struct fsl_mc_command cmd = { 0 };
1498 struct dpni_cmd_set_taildrop *cmd_params;
1499
1500
1501 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TAILDROP,
1502 cmd_flags,
1503 token);
1504 cmd_params = (struct dpni_cmd_set_taildrop *)cmd.params;
1505 cmd_params->congestion_point = cg_point;
1506 cmd_params->qtype = qtype;
1507 cmd_params->tc = tc;
1508 cmd_params->index = index;
1509 dpni_set_field(cmd_params->enable, ENABLE, taildrop->enable);
1510 cmd_params->units = taildrop->units;
1511 cmd_params->threshold = cpu_to_le32(taildrop->threshold);
1512
1513
1514 return mc_send_command(mc_io, &cmd);
1515}
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532int dpni_get_taildrop(struct fsl_mc_io *mc_io,
1533 u32 cmd_flags,
1534 u16 token,
1535 enum dpni_congestion_point cg_point,
1536 enum dpni_queue_type qtype,
1537 u8 tc,
1538 u8 index,
1539 struct dpni_taildrop *taildrop)
1540{
1541 struct fsl_mc_command cmd = { 0 };
1542 struct dpni_cmd_get_taildrop *cmd_params;
1543 struct dpni_rsp_get_taildrop *rsp_params;
1544 int err;
1545
1546
1547 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TAILDROP,
1548 cmd_flags,
1549 token);
1550 cmd_params = (struct dpni_cmd_get_taildrop *)cmd.params;
1551 cmd_params->congestion_point = cg_point;
1552 cmd_params->qtype = qtype;
1553 cmd_params->tc = tc;
1554 cmd_params->index = index;
1555
1556
1557 err = mc_send_command(mc_io, &cmd);
1558 if (err)
1559 return err;
1560
1561
1562 rsp_params = (struct dpni_rsp_get_taildrop *)cmd.params;
1563 taildrop->enable = dpni_get_field(rsp_params->enable, ENABLE);
1564 taildrop->units = rsp_params->units;
1565 taildrop->threshold = le32_to_cpu(rsp_params->threshold);
1566
1567 return 0;
1568}
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579int dpni_get_api_version(struct fsl_mc_io *mc_io,
1580 u32 cmd_flags,
1581 u16 *major_ver,
1582 u16 *minor_ver)
1583{
1584 struct dpni_rsp_get_api_version *rsp_params;
1585 struct fsl_mc_command cmd = { 0 };
1586 int err;
1587
1588 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION,
1589 cmd_flags, 0);
1590
1591 err = mc_send_command(mc_io, &cmd);
1592 if (err)
1593 return err;
1594
1595 rsp_params = (struct dpni_rsp_get_api_version *)cmd.params;
1596 *major_ver = le16_to_cpu(rsp_params->major);
1597 *minor_ver = le16_to_cpu(rsp_params->minor);
1598
1599 return 0;
1600}
1601