1
2
3
4
5
6
7
8#include <linux/fsl/mc.h>
9#include "dpsw.h"
10#include "dpsw-cmd.h"
11
12static void build_if_id_bitmap(__le64 *bmap, const u16 *id, const u16 num_ifs)
13{
14 int i;
15
16 for (i = 0; (i < num_ifs) && (i < DPSW_MAX_IF); i++) {
17 if (id[i] < DPSW_MAX_IF)
18 bmap[id[i] / 64] |= cpu_to_le64(BIT_MASK(id[i] % 64));
19 }
20}
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39int dpsw_open(struct fsl_mc_io *mc_io, u32 cmd_flags, int dpsw_id, u16 *token)
40{
41 struct fsl_mc_command cmd = { 0 };
42 struct dpsw_cmd_open *cmd_params;
43 int err;
44
45
46 cmd.header = mc_encode_cmd_header(DPSW_CMDID_OPEN,
47 cmd_flags,
48 0);
49 cmd_params = (struct dpsw_cmd_open *)cmd.params;
50 cmd_params->dpsw_id = cpu_to_le32(dpsw_id);
51
52
53 err = mc_send_command(mc_io, &cmd);
54 if (err)
55 return err;
56
57
58 *token = mc_cmd_hdr_read_token(&cmd);
59
60 return 0;
61}
62
63
64
65
66
67
68
69
70
71
72
73
74int dpsw_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
75{
76 struct fsl_mc_command cmd = { 0 };
77
78
79 cmd.header = mc_encode_cmd_header(DPSW_CMDID_CLOSE,
80 cmd_flags,
81 token);
82
83
84 return mc_send_command(mc_io, &cmd);
85}
86
87
88
89
90
91
92
93
94
95int dpsw_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
96{
97 struct fsl_mc_command cmd = { 0 };
98
99
100 cmd.header = mc_encode_cmd_header(DPSW_CMDID_ENABLE,
101 cmd_flags,
102 token);
103
104
105 return mc_send_command(mc_io, &cmd);
106}
107
108
109
110
111
112
113
114
115
116int dpsw_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
117{
118 struct fsl_mc_command cmd = { 0 };
119
120
121 cmd.header = mc_encode_cmd_header(DPSW_CMDID_DISABLE,
122 cmd_flags,
123 token);
124
125
126 return mc_send_command(mc_io, &cmd);
127}
128
129
130
131
132
133
134
135
136
137int dpsw_reset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
138{
139 struct fsl_mc_command cmd = { 0 };
140
141
142 cmd.header = mc_encode_cmd_header(DPSW_CMDID_RESET,
143 cmd_flags,
144 token);
145
146
147 return mc_send_command(mc_io, &cmd);
148}
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165int dpsw_set_irq_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
166 u8 irq_index, u8 en)
167{
168 struct fsl_mc_command cmd = { 0 };
169 struct dpsw_cmd_set_irq_enable *cmd_params;
170
171
172 cmd.header = mc_encode_cmd_header(DPSW_CMDID_SET_IRQ_ENABLE,
173 cmd_flags,
174 token);
175 cmd_params = (struct dpsw_cmd_set_irq_enable *)cmd.params;
176 dpsw_set_field(cmd_params->enable_state, ENABLE, en);
177 cmd_params->irq_index = irq_index;
178
179
180 return mc_send_command(mc_io, &cmd);
181}
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199int dpsw_set_irq_mask(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
200 u8 irq_index, u32 mask)
201{
202 struct fsl_mc_command cmd = { 0 };
203 struct dpsw_cmd_set_irq_mask *cmd_params;
204
205
206 cmd.header = mc_encode_cmd_header(DPSW_CMDID_SET_IRQ_MASK,
207 cmd_flags,
208 token);
209 cmd_params = (struct dpsw_cmd_set_irq_mask *)cmd.params;
210 cmd_params->mask = cpu_to_le32(mask);
211 cmd_params->irq_index = irq_index;
212
213
214 return mc_send_command(mc_io, &cmd);
215}
216
217
218
219
220
221
222
223
224
225
226
227
228
229int dpsw_get_irq_status(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
230 u8 irq_index, u32 *status)
231{
232 struct fsl_mc_command cmd = { 0 };
233 struct dpsw_cmd_get_irq_status *cmd_params;
234 struct dpsw_rsp_get_irq_status *rsp_params;
235 int err;
236
237
238 cmd.header = mc_encode_cmd_header(DPSW_CMDID_GET_IRQ_STATUS,
239 cmd_flags,
240 token);
241 cmd_params = (struct dpsw_cmd_get_irq_status *)cmd.params;
242 cmd_params->status = cpu_to_le32(*status);
243 cmd_params->irq_index = irq_index;
244
245
246 err = mc_send_command(mc_io, &cmd);
247 if (err)
248 return err;
249
250
251 rsp_params = (struct dpsw_rsp_get_irq_status *)cmd.params;
252 *status = le32_to_cpu(rsp_params->status);
253
254 return 0;
255}
256
257
258
259
260
261
262
263
264
265
266
267
268
269int dpsw_clear_irq_status(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
270 u8 irq_index, u32 status)
271{
272 struct fsl_mc_command cmd = { 0 };
273 struct dpsw_cmd_clear_irq_status *cmd_params;
274
275
276 cmd.header = mc_encode_cmd_header(DPSW_CMDID_CLEAR_IRQ_STATUS,
277 cmd_flags,
278 token);
279 cmd_params = (struct dpsw_cmd_clear_irq_status *)cmd.params;
280 cmd_params->status = cpu_to_le32(status);
281 cmd_params->irq_index = irq_index;
282
283
284 return mc_send_command(mc_io, &cmd);
285}
286
287
288
289
290
291
292
293
294
295
296int dpsw_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
297 struct dpsw_attr *attr)
298{
299 struct fsl_mc_command cmd = { 0 };
300 struct dpsw_rsp_get_attr *rsp_params;
301 int err;
302
303
304 cmd.header = mc_encode_cmd_header(DPSW_CMDID_GET_ATTR,
305 cmd_flags,
306 token);
307
308
309 err = mc_send_command(mc_io, &cmd);
310 if (err)
311 return err;
312
313
314 rsp_params = (struct dpsw_rsp_get_attr *)cmd.params;
315 attr->num_ifs = le16_to_cpu(rsp_params->num_ifs);
316 attr->max_fdbs = rsp_params->max_fdbs;
317 attr->num_fdbs = rsp_params->num_fdbs;
318 attr->max_vlans = le16_to_cpu(rsp_params->max_vlans);
319 attr->num_vlans = le16_to_cpu(rsp_params->num_vlans);
320 attr->max_fdb_entries = le16_to_cpu(rsp_params->max_fdb_entries);
321 attr->fdb_aging_time = le16_to_cpu(rsp_params->fdb_aging_time);
322 attr->id = le32_to_cpu(rsp_params->dpsw_id);
323 attr->mem_size = le16_to_cpu(rsp_params->mem_size);
324 attr->max_fdb_mc_groups = le16_to_cpu(rsp_params->max_fdb_mc_groups);
325 attr->max_meters_per_if = rsp_params->max_meters_per_if;
326 attr->options = le64_to_cpu(rsp_params->options);
327 attr->component_type = dpsw_get_field(rsp_params->component_type, COMPONENT_TYPE);
328 attr->flooding_cfg = dpsw_get_field(rsp_params->repl_cfg, FLOODING_CFG);
329 attr->broadcast_cfg = dpsw_get_field(rsp_params->repl_cfg, BROADCAST_CFG);
330 return 0;
331}
332
333
334
335
336
337
338
339
340
341
342
343int dpsw_if_set_link_cfg(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id,
344 struct dpsw_link_cfg *cfg)
345{
346 struct fsl_mc_command cmd = { 0 };
347 struct dpsw_cmd_if_set_link_cfg *cmd_params;
348
349
350 cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_SET_LINK_CFG,
351 cmd_flags,
352 token);
353 cmd_params = (struct dpsw_cmd_if_set_link_cfg *)cmd.params;
354 cmd_params->if_id = cpu_to_le16(if_id);
355 cmd_params->rate = cpu_to_le32(cfg->rate);
356 cmd_params->options = cpu_to_le64(cfg->options);
357
358
359 return mc_send_command(mc_io, &cmd);
360}
361
362
363
364
365
366
367
368
369
370
371
372int dpsw_if_get_link_state(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
373 u16 if_id, struct dpsw_link_state *state)
374{
375 struct fsl_mc_command cmd = { 0 };
376 struct dpsw_cmd_if_get_link_state *cmd_params;
377 struct dpsw_rsp_if_get_link_state *rsp_params;
378 int err;
379
380
381 cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_GET_LINK_STATE,
382 cmd_flags,
383 token);
384 cmd_params = (struct dpsw_cmd_if_get_link_state *)cmd.params;
385 cmd_params->if_id = cpu_to_le16(if_id);
386
387
388 err = mc_send_command(mc_io, &cmd);
389 if (err)
390 return err;
391
392
393 rsp_params = (struct dpsw_rsp_if_get_link_state *)cmd.params;
394 state->rate = le32_to_cpu(rsp_params->rate);
395 state->options = le64_to_cpu(rsp_params->options);
396 state->up = dpsw_get_field(rsp_params->up, UP);
397
398 return 0;
399}
400
401
402
403
404
405
406
407
408
409
410
411int dpsw_if_set_tci(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id,
412 const struct dpsw_tci_cfg *cfg)
413{
414 struct fsl_mc_command cmd = { 0 };
415 struct dpsw_cmd_if_set_tci *cmd_params;
416 u16 tmp_conf = 0;
417
418
419 cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_SET_TCI,
420 cmd_flags,
421 token);
422 cmd_params = (struct dpsw_cmd_if_set_tci *)cmd.params;
423 cmd_params->if_id = cpu_to_le16(if_id);
424 dpsw_set_field(tmp_conf, VLAN_ID, cfg->vlan_id);
425 dpsw_set_field(tmp_conf, DEI, cfg->dei);
426 dpsw_set_field(tmp_conf, PCP, cfg->pcp);
427 cmd_params->conf = cpu_to_le16(tmp_conf);
428
429
430 return mc_send_command(mc_io, &cmd);
431}
432
433
434
435
436
437
438
439
440
441
442
443int dpsw_if_get_tci(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id,
444 struct dpsw_tci_cfg *cfg)
445{
446 struct fsl_mc_command cmd = { 0 };
447 struct dpsw_cmd_if_get_tci *cmd_params;
448 struct dpsw_rsp_if_get_tci *rsp_params;
449 int err;
450
451
452 cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_GET_TCI,
453 cmd_flags,
454 token);
455 cmd_params = (struct dpsw_cmd_if_get_tci *)cmd.params;
456 cmd_params->if_id = cpu_to_le16(if_id);
457
458
459 err = mc_send_command(mc_io, &cmd);
460 if (err)
461 return err;
462
463
464 rsp_params = (struct dpsw_rsp_if_get_tci *)cmd.params;
465 cfg->pcp = rsp_params->pcp;
466 cfg->dei = rsp_params->dei;
467 cfg->vlan_id = le16_to_cpu(rsp_params->vlan_id);
468
469 return 0;
470}
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485int dpsw_if_set_stp(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id,
486 const struct dpsw_stp_cfg *cfg)
487{
488 struct fsl_mc_command cmd = { 0 };
489 struct dpsw_cmd_if_set_stp *cmd_params;
490
491
492 cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_SET_STP,
493 cmd_flags,
494 token);
495 cmd_params = (struct dpsw_cmd_if_set_stp *)cmd.params;
496 cmd_params->if_id = cpu_to_le16(if_id);
497 cmd_params->vlan_id = cpu_to_le16(cfg->vlan_id);
498 dpsw_set_field(cmd_params->state, STATE, cfg->state);
499
500
501 return mc_send_command(mc_io, &cmd);
502}
503
504
505
506
507
508
509
510
511
512
513
514
515int dpsw_if_get_counter(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
516 u16 if_id, enum dpsw_counter type, u64 *counter)
517{
518 struct fsl_mc_command cmd = { 0 };
519 struct dpsw_cmd_if_get_counter *cmd_params;
520 struct dpsw_rsp_if_get_counter *rsp_params;
521 int err;
522
523
524 cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_GET_COUNTER,
525 cmd_flags,
526 token);
527 cmd_params = (struct dpsw_cmd_if_get_counter *)cmd.params;
528 cmd_params->if_id = cpu_to_le16(if_id);
529 dpsw_set_field(cmd_params->type, COUNTER_TYPE, type);
530
531
532 err = mc_send_command(mc_io, &cmd);
533 if (err)
534 return err;
535
536
537 rsp_params = (struct dpsw_rsp_if_get_counter *)cmd.params;
538 *counter = le64_to_cpu(rsp_params->counter);
539
540 return 0;
541}
542
543
544
545
546
547
548
549
550
551
552int dpsw_if_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id)
553{
554 struct fsl_mc_command cmd = { 0 };
555 struct dpsw_cmd_if *cmd_params;
556
557
558 cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_ENABLE,
559 cmd_flags,
560 token);
561 cmd_params = (struct dpsw_cmd_if *)cmd.params;
562 cmd_params->if_id = cpu_to_le16(if_id);
563
564
565 return mc_send_command(mc_io, &cmd);
566}
567
568
569
570
571
572
573
574
575
576
577int dpsw_if_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id)
578{
579 struct fsl_mc_command cmd = { 0 };
580 struct dpsw_cmd_if *cmd_params;
581
582
583 cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_DISABLE,
584 cmd_flags,
585 token);
586 cmd_params = (struct dpsw_cmd_if *)cmd.params;
587 cmd_params->if_id = cpu_to_le16(if_id);
588
589
590 return mc_send_command(mc_io, &cmd);
591}
592
593
594
595
596
597
598
599
600
601
602
603int dpsw_if_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
604 u16 if_id, struct dpsw_if_attr *attr)
605{
606 struct dpsw_rsp_if_get_attr *rsp_params;
607 struct fsl_mc_command cmd = { 0 };
608 struct dpsw_cmd_if *cmd_params;
609 int err;
610
611 cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_GET_ATTR, cmd_flags,
612 token);
613 cmd_params = (struct dpsw_cmd_if *)cmd.params;
614 cmd_params->if_id = cpu_to_le16(if_id);
615
616 err = mc_send_command(mc_io, &cmd);
617 if (err)
618 return err;
619
620 rsp_params = (struct dpsw_rsp_if_get_attr *)cmd.params;
621 attr->num_tcs = rsp_params->num_tcs;
622 attr->rate = le32_to_cpu(rsp_params->rate);
623 attr->options = le32_to_cpu(rsp_params->options);
624 attr->qdid = le16_to_cpu(rsp_params->qdid);
625 attr->enabled = dpsw_get_field(rsp_params->conf, ENABLED);
626 attr->accept_all_vlan = dpsw_get_field(rsp_params->conf,
627 ACCEPT_ALL_VLAN);
628 attr->admit_untagged = dpsw_get_field(rsp_params->conf,
629 ADMIT_UNTAGGED);
630
631 return 0;
632}
633
634
635
636
637
638
639
640
641
642
643
644int dpsw_if_set_max_frame_length(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
645 u16 if_id, u16 frame_length)
646{
647 struct fsl_mc_command cmd = { 0 };
648 struct dpsw_cmd_if_set_max_frame_length *cmd_params;
649
650
651 cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_SET_MAX_FRAME_LENGTH,
652 cmd_flags,
653 token);
654 cmd_params = (struct dpsw_cmd_if_set_max_frame_length *)cmd.params;
655 cmd_params->if_id = cpu_to_le16(if_id);
656 cmd_params->frame_length = cpu_to_le16(frame_length);
657
658
659 return mc_send_command(mc_io, &cmd);
660}
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679int dpsw_vlan_add(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
680 u16 vlan_id, const struct dpsw_vlan_cfg *cfg)
681{
682 struct fsl_mc_command cmd = { 0 };
683 struct dpsw_vlan_add *cmd_params;
684
685
686 cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_ADD,
687 cmd_flags,
688 token);
689 cmd_params = (struct dpsw_vlan_add *)cmd.params;
690 cmd_params->fdb_id = cpu_to_le16(cfg->fdb_id);
691 cmd_params->vlan_id = cpu_to_le16(vlan_id);
692
693
694 return mc_send_command(mc_io, &cmd);
695}
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712int dpsw_vlan_add_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
713 u16 vlan_id, const struct dpsw_vlan_if_cfg *cfg)
714{
715 struct dpsw_cmd_vlan_add_if *cmd_params;
716 struct fsl_mc_command cmd = { 0 };
717
718
719 cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_ADD_IF,
720 cmd_flags,
721 token);
722 cmd_params = (struct dpsw_cmd_vlan_add_if *)cmd.params;
723 cmd_params->vlan_id = cpu_to_le16(vlan_id);
724 cmd_params->options = cpu_to_le16(cfg->options);
725 cmd_params->fdb_id = cpu_to_le16(cfg->fdb_id);
726 build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
727
728
729 return mc_send_command(mc_io, &cmd);
730}
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749int dpsw_vlan_add_if_untagged(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
750 u16 vlan_id, const struct dpsw_vlan_if_cfg *cfg)
751{
752 struct fsl_mc_command cmd = { 0 };
753 struct dpsw_cmd_vlan_manage_if *cmd_params;
754
755
756 cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_ADD_IF_UNTAGGED,
757 cmd_flags,
758 token);
759 cmd_params = (struct dpsw_cmd_vlan_manage_if *)cmd.params;
760 cmd_params->vlan_id = cpu_to_le16(vlan_id);
761 build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
762
763
764 return mc_send_command(mc_io, &cmd);
765}
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780int dpsw_vlan_remove_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
781 u16 vlan_id, const struct dpsw_vlan_if_cfg *cfg)
782{
783 struct fsl_mc_command cmd = { 0 };
784 struct dpsw_cmd_vlan_manage_if *cmd_params;
785
786
787 cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_REMOVE_IF,
788 cmd_flags,
789 token);
790 cmd_params = (struct dpsw_cmd_vlan_manage_if *)cmd.params;
791 cmd_params->vlan_id = cpu_to_le16(vlan_id);
792 build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
793
794
795 return mc_send_command(mc_io, &cmd);
796}
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813int dpsw_vlan_remove_if_untagged(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
814 u16 vlan_id, const struct dpsw_vlan_if_cfg *cfg)
815{
816 struct fsl_mc_command cmd = { 0 };
817 struct dpsw_cmd_vlan_manage_if *cmd_params;
818
819
820 cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_REMOVE_IF_UNTAGGED,
821 cmd_flags,
822 token);
823 cmd_params = (struct dpsw_cmd_vlan_manage_if *)cmd.params;
824 cmd_params->vlan_id = cpu_to_le16(vlan_id);
825 build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
826
827
828 return mc_send_command(mc_io, &cmd);
829}
830
831
832
833
834
835
836
837
838
839
840int dpsw_vlan_remove(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
841 u16 vlan_id)
842{
843 struct fsl_mc_command cmd = { 0 };
844 struct dpsw_cmd_vlan_remove *cmd_params;
845
846
847 cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_REMOVE,
848 cmd_flags,
849 token);
850 cmd_params = (struct dpsw_cmd_vlan_remove *)cmd.params;
851 cmd_params->vlan_id = cpu_to_le16(vlan_id);
852
853
854 return mc_send_command(mc_io, &cmd);
855}
856
857
858
859
860
861
862
863
864
865
866
867
868int dpsw_fdb_add(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 *fdb_id,
869 const struct dpsw_fdb_cfg *cfg)
870{
871 struct dpsw_cmd_fdb_add *cmd_params;
872 struct dpsw_rsp_fdb_add *rsp_params;
873 struct fsl_mc_command cmd = { 0 };
874 int err;
875
876 cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_ADD,
877 cmd_flags,
878 token);
879 cmd_params = (struct dpsw_cmd_fdb_add *)cmd.params;
880 cmd_params->fdb_ageing_time = cpu_to_le16(cfg->fdb_ageing_time);
881 cmd_params->num_fdb_entries = cpu_to_le16(cfg->num_fdb_entries);
882
883 err = mc_send_command(mc_io, &cmd);
884 if (err)
885 return err;
886
887 rsp_params = (struct dpsw_rsp_fdb_add *)cmd.params;
888 *fdb_id = le16_to_cpu(rsp_params->fdb_id);
889
890 return 0;
891}
892
893
894
895
896
897
898
899
900
901
902int dpsw_fdb_remove(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 fdb_id)
903{
904 struct dpsw_cmd_fdb_remove *cmd_params;
905 struct fsl_mc_command cmd = { 0 };
906
907
908 cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_REMOVE,
909 cmd_flags,
910 token);
911 cmd_params = (struct dpsw_cmd_fdb_remove *)cmd.params;
912 cmd_params->fdb_id = cpu_to_le16(fdb_id);
913
914 return mc_send_command(mc_io, &cmd);
915}
916
917
918
919
920
921
922
923
924
925
926
927int dpsw_fdb_add_unicast(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
928 u16 fdb_id, const struct dpsw_fdb_unicast_cfg *cfg)
929{
930 struct fsl_mc_command cmd = { 0 };
931 struct dpsw_cmd_fdb_unicast_op *cmd_params;
932 int i;
933
934
935 cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_ADD_UNICAST,
936 cmd_flags,
937 token);
938 cmd_params = (struct dpsw_cmd_fdb_unicast_op *)cmd.params;
939 cmd_params->fdb_id = cpu_to_le16(fdb_id);
940 cmd_params->if_egress = cpu_to_le16(cfg->if_egress);
941 for (i = 0; i < 6; i++)
942 cmd_params->mac_addr[i] = cfg->mac_addr[5 - i];
943 dpsw_set_field(cmd_params->type, ENTRY_TYPE, cfg->type);
944
945
946 return mc_send_command(mc_io, &cmd);
947}
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967int dpsw_fdb_dump(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 fdb_id,
968 u64 iova_addr, u32 iova_size, u16 *num_entries)
969{
970 struct dpsw_cmd_fdb_dump *cmd_params;
971 struct dpsw_rsp_fdb_dump *rsp_params;
972 struct fsl_mc_command cmd = { 0 };
973 int err;
974
975
976 cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_DUMP,
977 cmd_flags,
978 token);
979 cmd_params = (struct dpsw_cmd_fdb_dump *)cmd.params;
980 cmd_params->fdb_id = cpu_to_le16(fdb_id);
981 cmd_params->iova_addr = cpu_to_le64(iova_addr);
982 cmd_params->iova_size = cpu_to_le32(iova_size);
983
984
985 err = mc_send_command(mc_io, &cmd);
986 if (err)
987 return err;
988
989 rsp_params = (struct dpsw_rsp_fdb_dump *)cmd.params;
990 *num_entries = le16_to_cpu(rsp_params->num_entries);
991
992 return 0;
993}
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005int dpsw_fdb_remove_unicast(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1006 u16 fdb_id, const struct dpsw_fdb_unicast_cfg *cfg)
1007{
1008 struct fsl_mc_command cmd = { 0 };
1009 struct dpsw_cmd_fdb_unicast_op *cmd_params;
1010 int i;
1011
1012
1013 cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_REMOVE_UNICAST,
1014 cmd_flags,
1015 token);
1016 cmd_params = (struct dpsw_cmd_fdb_unicast_op *)cmd.params;
1017 cmd_params->fdb_id = cpu_to_le16(fdb_id);
1018 for (i = 0; i < 6; i++)
1019 cmd_params->mac_addr[i] = cfg->mac_addr[5 - i];
1020 cmd_params->if_egress = cpu_to_le16(cfg->if_egress);
1021 dpsw_set_field(cmd_params->type, ENTRY_TYPE, cfg->type);
1022
1023
1024 return mc_send_command(mc_io, &cmd);
1025}
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044int dpsw_fdb_add_multicast(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1045 u16 fdb_id, const struct dpsw_fdb_multicast_cfg *cfg)
1046{
1047 struct fsl_mc_command cmd = { 0 };
1048 struct dpsw_cmd_fdb_multicast_op *cmd_params;
1049 int i;
1050
1051
1052 cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_ADD_MULTICAST,
1053 cmd_flags,
1054 token);
1055 cmd_params = (struct dpsw_cmd_fdb_multicast_op *)cmd.params;
1056 cmd_params->fdb_id = cpu_to_le16(fdb_id);
1057 cmd_params->num_ifs = cpu_to_le16(cfg->num_ifs);
1058 dpsw_set_field(cmd_params->type, ENTRY_TYPE, cfg->type);
1059 build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
1060 for (i = 0; i < 6; i++)
1061 cmd_params->mac_addr[i] = cfg->mac_addr[5 - i];
1062
1063
1064 return mc_send_command(mc_io, &cmd);
1065}
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083int dpsw_fdb_remove_multicast(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1084 u16 fdb_id, const struct dpsw_fdb_multicast_cfg *cfg)
1085{
1086 struct fsl_mc_command cmd = { 0 };
1087 struct dpsw_cmd_fdb_multicast_op *cmd_params;
1088 int i;
1089
1090
1091 cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_REMOVE_MULTICAST,
1092 cmd_flags,
1093 token);
1094 cmd_params = (struct dpsw_cmd_fdb_multicast_op *)cmd.params;
1095 cmd_params->fdb_id = cpu_to_le16(fdb_id);
1096 cmd_params->num_ifs = cpu_to_le16(cfg->num_ifs);
1097 dpsw_set_field(cmd_params->type, ENTRY_TYPE, cfg->type);
1098 build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
1099 for (i = 0; i < 6; i++)
1100 cmd_params->mac_addr[i] = cfg->mac_addr[5 - i];
1101
1102
1103 return mc_send_command(mc_io, &cmd);
1104}
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115int dpsw_ctrl_if_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags,
1116 u16 token, struct dpsw_ctrl_if_attr *attr)
1117{
1118 struct dpsw_rsp_ctrl_if_get_attr *rsp_params;
1119 struct fsl_mc_command cmd = { 0 };
1120 int err;
1121
1122 cmd.header = mc_encode_cmd_header(DPSW_CMDID_CTRL_IF_GET_ATTR,
1123 cmd_flags, token);
1124
1125 err = mc_send_command(mc_io, &cmd);
1126 if (err)
1127 return err;
1128
1129 rsp_params = (struct dpsw_rsp_ctrl_if_get_attr *)cmd.params;
1130 attr->rx_fqid = le32_to_cpu(rsp_params->rx_fqid);
1131 attr->rx_err_fqid = le32_to_cpu(rsp_params->rx_err_fqid);
1132 attr->tx_err_conf_fqid = le32_to_cpu(rsp_params->tx_err_conf_fqid);
1133
1134 return 0;
1135}
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146int dpsw_ctrl_if_set_pools(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1147 const struct dpsw_ctrl_if_pools_cfg *cfg)
1148{
1149 struct dpsw_cmd_ctrl_if_set_pools *cmd_params;
1150 struct fsl_mc_command cmd = { 0 };
1151 int i;
1152
1153 cmd.header = mc_encode_cmd_header(DPSW_CMDID_CTRL_IF_SET_POOLS,
1154 cmd_flags, token);
1155 cmd_params = (struct dpsw_cmd_ctrl_if_set_pools *)cmd.params;
1156 cmd_params->num_dpbp = cfg->num_dpbp;
1157 for (i = 0; i < DPSW_MAX_DPBP; i++) {
1158 cmd_params->dpbp_id[i] = cpu_to_le32(cfg->pools[i].dpbp_id);
1159 cmd_params->buffer_size[i] =
1160 cpu_to_le16(cfg->pools[i].buffer_size);
1161 cmd_params->backup_pool_mask |=
1162 DPSW_BACKUP_POOL(cfg->pools[i].backup_pool, i);
1163 }
1164
1165 return mc_send_command(mc_io, &cmd);
1166}
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178int dpsw_ctrl_if_set_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1179 enum dpsw_queue_type qtype,
1180 const struct dpsw_ctrl_if_queue_cfg *cfg)
1181{
1182 struct dpsw_cmd_ctrl_if_set_queue *cmd_params;
1183 struct fsl_mc_command cmd = { 0 };
1184
1185 cmd.header = mc_encode_cmd_header(DPSW_CMDID_CTRL_IF_SET_QUEUE,
1186 cmd_flags,
1187 token);
1188 cmd_params = (struct dpsw_cmd_ctrl_if_set_queue *)cmd.params;
1189 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
1190 cmd_params->dest_priority = cfg->dest_cfg.priority;
1191 cmd_params->qtype = qtype;
1192 cmd_params->user_ctx = cpu_to_le64(cfg->user_ctx);
1193 cmd_params->options = cpu_to_le32(cfg->options);
1194 dpsw_set_field(cmd_params->dest_type,
1195 DEST_TYPE,
1196 cfg->dest_cfg.dest_type);
1197
1198 return mc_send_command(mc_io, &cmd);
1199}
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210int dpsw_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags,
1211 u16 *major_ver, u16 *minor_ver)
1212{
1213 struct fsl_mc_command cmd = { 0 };
1214 struct dpsw_rsp_get_api_version *rsp_params;
1215 int err;
1216
1217 cmd.header = mc_encode_cmd_header(DPSW_CMDID_GET_API_VERSION,
1218 cmd_flags,
1219 0);
1220
1221 err = mc_send_command(mc_io, &cmd);
1222 if (err)
1223 return err;
1224
1225 rsp_params = (struct dpsw_rsp_get_api_version *)cmd.params;
1226 *major_ver = le16_to_cpu(rsp_params->version_major);
1227 *minor_ver = le16_to_cpu(rsp_params->version_minor);
1228
1229 return 0;
1230}
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242int dpsw_if_get_port_mac_addr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1243 u16 if_id, u8 mac_addr[6])
1244{
1245 struct dpsw_rsp_if_get_mac_addr *rsp_params;
1246 struct fsl_mc_command cmd = { 0 };
1247 struct dpsw_cmd_if *cmd_params;
1248 int err, i;
1249
1250
1251 cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_GET_PORT_MAC_ADDR,
1252 cmd_flags,
1253 token);
1254 cmd_params = (struct dpsw_cmd_if *)cmd.params;
1255 cmd_params->if_id = cpu_to_le16(if_id);
1256
1257
1258 err = mc_send_command(mc_io, &cmd);
1259 if (err)
1260 return err;
1261
1262
1263 rsp_params = (struct dpsw_rsp_if_get_mac_addr *)cmd.params;
1264 for (i = 0; i < 6; i++)
1265 mac_addr[5 - i] = rsp_params->mac_addr[i];
1266
1267 return 0;
1268}
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278int dpsw_ctrl_if_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
1279{
1280 struct fsl_mc_command cmd = { 0 };
1281
1282 cmd.header = mc_encode_cmd_header(DPSW_CMDID_CTRL_IF_ENABLE, cmd_flags,
1283 token);
1284
1285 return mc_send_command(mc_io, &cmd);
1286}
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296int dpsw_ctrl_if_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
1297{
1298 struct fsl_mc_command cmd = { 0 };
1299
1300 cmd.header = mc_encode_cmd_header(DPSW_CMDID_CTRL_IF_DISABLE,
1301 cmd_flags,
1302 token);
1303
1304 return mc_send_command(mc_io, &cmd);
1305}
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316int dpsw_set_egress_flood(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1317 const struct dpsw_egress_flood_cfg *cfg)
1318{
1319 struct dpsw_cmd_set_egress_flood *cmd_params;
1320 struct fsl_mc_command cmd = { 0 };
1321
1322 cmd.header = mc_encode_cmd_header(DPSW_CMDID_SET_EGRESS_FLOOD, cmd_flags, token);
1323 cmd_params = (struct dpsw_cmd_set_egress_flood *)cmd.params;
1324 cmd_params->fdb_id = cpu_to_le16(cfg->fdb_id);
1325 cmd_params->flood_type = cfg->flood_type;
1326 build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
1327
1328 return mc_send_command(mc_io, &cmd);
1329}
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342int dpsw_if_set_learning_mode(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1343 u16 if_id, enum dpsw_learning_mode mode)
1344{
1345 struct dpsw_cmd_if_set_learning_mode *cmd_params;
1346 struct fsl_mc_command cmd = { 0 };
1347
1348 cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_SET_LEARNING_MODE,
1349 cmd_flags,
1350 token);
1351 cmd_params = (struct dpsw_cmd_if_set_learning_mode *)cmd.params;
1352 cmd_params->if_id = cpu_to_le16(if_id);
1353 dpsw_set_field(cmd_params->mode, LEARNING_MODE, mode);
1354
1355 return mc_send_command(mc_io, &cmd);
1356}
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371int dpsw_acl_add(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 *acl_id,
1372 const struct dpsw_acl_cfg *cfg)
1373{
1374 struct dpsw_cmd_acl_add *cmd_params;
1375 struct dpsw_rsp_acl_add *rsp_params;
1376 struct fsl_mc_command cmd = { 0 };
1377 int err;
1378
1379 cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_ADD, cmd_flags, token);
1380 cmd_params = (struct dpsw_cmd_acl_add *)cmd.params;
1381 cmd_params->max_entries = cpu_to_le16(cfg->max_entries);
1382
1383 err = mc_send_command(mc_io, &cmd);
1384 if (err)
1385 return err;
1386
1387 rsp_params = (struct dpsw_rsp_acl_add *)cmd.params;
1388 *acl_id = le16_to_cpu(rsp_params->acl_id);
1389
1390 return 0;
1391}
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402int dpsw_acl_remove(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1403 u16 acl_id)
1404{
1405 struct dpsw_cmd_acl_remove *cmd_params;
1406 struct fsl_mc_command cmd = { 0 };
1407
1408 cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_REMOVE, cmd_flags,
1409 token);
1410 cmd_params = (struct dpsw_cmd_acl_remove *)cmd.params;
1411 cmd_params->acl_id = cpu_to_le16(acl_id);
1412
1413 return mc_send_command(mc_io, &cmd);
1414}
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426int dpsw_acl_add_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1427 u16 acl_id, const struct dpsw_acl_if_cfg *cfg)
1428{
1429 struct dpsw_cmd_acl_if *cmd_params;
1430 struct fsl_mc_command cmd = { 0 };
1431
1432 cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_ADD_IF, cmd_flags,
1433 token);
1434 cmd_params = (struct dpsw_cmd_acl_if *)cmd.params;
1435 cmd_params->acl_id = cpu_to_le16(acl_id);
1436 cmd_params->num_ifs = cpu_to_le16(cfg->num_ifs);
1437 build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
1438
1439 return mc_send_command(mc_io, &cmd);
1440}
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452int dpsw_acl_remove_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1453 u16 acl_id, const struct dpsw_acl_if_cfg *cfg)
1454{
1455 struct dpsw_cmd_acl_if *cmd_params;
1456 struct fsl_mc_command cmd = { 0 };
1457
1458
1459 cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_REMOVE_IF, cmd_flags,
1460 token);
1461 cmd_params = (struct dpsw_cmd_acl_if *)cmd.params;
1462 cmd_params->acl_id = cpu_to_le16(acl_id);
1463 cmd_params->num_ifs = cpu_to_le16(cfg->num_ifs);
1464 build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
1465
1466
1467 return mc_send_command(mc_io, &cmd);
1468}
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478void dpsw_acl_prepare_entry_cfg(const struct dpsw_acl_key *key,
1479 u8 *entry_cfg_buf)
1480{
1481 struct dpsw_prep_acl_entry *ext_params;
1482 int i;
1483
1484 ext_params = (struct dpsw_prep_acl_entry *)entry_cfg_buf;
1485
1486 for (i = 0; i < 6; i++) {
1487 ext_params->match_l2_dest_mac[i] = key->match.l2_dest_mac[5 - i];
1488 ext_params->match_l2_source_mac[i] = key->match.l2_source_mac[5 - i];
1489 ext_params->mask_l2_dest_mac[i] = key->mask.l2_dest_mac[5 - i];
1490 ext_params->mask_l2_source_mac[i] = key->mask.l2_source_mac[5 - i];
1491 }
1492
1493 ext_params->match_l2_tpid = cpu_to_le16(key->match.l2_tpid);
1494 ext_params->match_l2_vlan_id = cpu_to_le16(key->match.l2_vlan_id);
1495 ext_params->match_l3_dest_ip = cpu_to_le32(key->match.l3_dest_ip);
1496 ext_params->match_l3_source_ip = cpu_to_le32(key->match.l3_source_ip);
1497 ext_params->match_l4_dest_port = cpu_to_le16(key->match.l4_dest_port);
1498 ext_params->match_l4_source_port = cpu_to_le16(key->match.l4_source_port);
1499 ext_params->match_l2_ether_type = cpu_to_le16(key->match.l2_ether_type);
1500 ext_params->match_l2_pcp_dei = key->match.l2_pcp_dei;
1501 ext_params->match_l3_dscp = key->match.l3_dscp;
1502
1503 ext_params->mask_l2_tpid = cpu_to_le16(key->mask.l2_tpid);
1504 ext_params->mask_l2_vlan_id = cpu_to_le16(key->mask.l2_vlan_id);
1505 ext_params->mask_l3_dest_ip = cpu_to_le32(key->mask.l3_dest_ip);
1506 ext_params->mask_l3_source_ip = cpu_to_le32(key->mask.l3_source_ip);
1507 ext_params->mask_l4_dest_port = cpu_to_le16(key->mask.l4_dest_port);
1508 ext_params->mask_l4_source_port = cpu_to_le16(key->mask.l4_source_port);
1509 ext_params->mask_l2_ether_type = cpu_to_le16(key->mask.l2_ether_type);
1510 ext_params->mask_l2_pcp_dei = key->mask.l2_pcp_dei;
1511 ext_params->mask_l3_dscp = key->mask.l3_dscp;
1512 ext_params->match_l3_protocol = key->match.l3_protocol;
1513 ext_params->mask_l3_protocol = key->mask.l3_protocol;
1514}
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528int dpsw_acl_add_entry(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1529 u16 acl_id, const struct dpsw_acl_entry_cfg *cfg)
1530{
1531 struct dpsw_cmd_acl_entry *cmd_params;
1532 struct fsl_mc_command cmd = { 0 };
1533
1534 cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_ADD_ENTRY, cmd_flags,
1535 token);
1536 cmd_params = (struct dpsw_cmd_acl_entry *)cmd.params;
1537 cmd_params->acl_id = cpu_to_le16(acl_id);
1538 cmd_params->result_if_id = cpu_to_le16(cfg->result.if_id);
1539 cmd_params->precedence = cpu_to_le32(cfg->precedence);
1540 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1541 dpsw_set_field(cmd_params->result_action,
1542 RESULT_ACTION,
1543 cfg->result.action);
1544
1545 return mc_send_command(mc_io, &cmd);
1546}
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560int dpsw_acl_remove_entry(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1561 u16 acl_id, const struct dpsw_acl_entry_cfg *cfg)
1562{
1563 struct dpsw_cmd_acl_entry *cmd_params;
1564 struct fsl_mc_command cmd = { 0 };
1565
1566
1567 cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_REMOVE_ENTRY,
1568 cmd_flags,
1569 token);
1570 cmd_params = (struct dpsw_cmd_acl_entry *)cmd.params;
1571 cmd_params->acl_id = cpu_to_le16(acl_id);
1572 cmd_params->result_if_id = cpu_to_le16(cfg->result.if_id);
1573 cmd_params->precedence = cpu_to_le32(cfg->precedence);
1574 cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1575 dpsw_set_field(cmd_params->result_action,
1576 RESULT_ACTION,
1577 cfg->result.action);
1578
1579
1580 return mc_send_command(mc_io, &cmd);
1581}
1582