-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtcam_write.c
1216 lines (1011 loc) · 27.4 KB
/
tcam_write.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "tcam_write.h"
uint16 g_sys_humber_acl_reorder_ratio = 100;
#define DO_REORDER(move_num, all) ((move_num) >= ((all)/g_sys_humber_acl_reorder_ratio))
static sys_aclqos_entry_ctl_t sys_aclqos_entry_ctl;
static cm_hash_t *p_sys_acl_redirect_hash[MAX_LOCAL_CHIP_NUM];
static sys_aclqos_entry_ctl_t *acl_master = &sys_aclqos_entry_ctl;
static sys_chip_master_t *p_chip_master = NULL;
#define CM_PTR_VALID_CHECK(p) \
do{ \
if( (p) == NULL ) \
return CM_E_PTR_INVALID; \
}while(0)
/*TDB*/
#define CM_ERROR_RETURN(ret) \
do{ \
if( (ret) == CM_E_ERR_RET) \
return CM_E_ERR_RET; \
}while(0)
#define CM_NOT_ZERO_CHECK(a) \
do{ \
if( (a) == 0 ) \
return CM_E_ZERO; \
}while(0)
#define CTC_MAX_VALUE_CHECK(num, max) \
do{ \
if( (num) >= (max) ) \
return CM_E_ERR; \
else \
return CM_E_NONE; \
}while(0)
#define CTC_MIN_VALUE_CHECK(num, min) \
do{ \
if( (num) <= (min) ) \
return CM_E_ERR; \
else \
return CM_E_NONE; \
}while(0)
#define IS_ACL_LABEL(type) \
do{ \
if( (type) == ACL_LABEL ) \
return CM_E_NONE; \
else \
return CM_E_ERR; \
}while(0)
#define IS_QOS_LABEL(type) \
do{ \
if( (type) == QOS_LABEL ) \
return CM_E_NONE; \
else \
return CM_E_ERR; \
}while(0)
/*get sys entry node by entry id*/
static uint32
_sys_acl_get_sys_entry_by_eid(uint32 eid, sys_acl_entry_t **sys_entry_out)
{
sys_acl_entry_t* p_sys_entry_lkup = NULL;
sys_acl_entry_t sys_entry;
CM_PTR_VALID_CHECK(sys_entry_out);
memset(&sys_entry, 0, sizeof(sys_acl_entry_t));
sys_entry.entry_id = eid;
p_sys_entry_lkup = cm_hash_lookup(acl_master->entry, &sys_entry);
*sys_entry_out = p_sys_entry_lkup;
return CM_E_NONE;
}
/*move entry in hardware table to an new index*/
static int32
_sys_humber_acl_entry_move_hw(sys_acl_entry_t *pe, int32 tcam_idx_new)
{
int32 tcam_idx_old = pe->block_index;
sys_aclqos_sub_entry_info_t sub_info;
CM_PTR_VALID_CHECK(pe);
/*add first*/
memset(&sub_info, 0, sizeof(sub_info));
sub_info.offset = tcam_idx_new;
CM_ERROR_RETURN(_sys_humber_aclqos_write_entry_to_chip(0, pe->p_label, pe, &sub_info));
/*then delete*/
CM_ERROR_RETURN(_sys_humber_aclqos_delete_entry_from_chip(0, pe->p_label, pe->key.type, tcam_idx_old));
pe->block_index = tcam_idx_new;
return CM_E_NONE;
}
/*move entry to a new place with amount steps*/
static int32
_sys_humber_acl_entry_move(sys_acl_entry_t* pe, int32 amount)
{
int32 tcam_idx_old = 0;/*original entry tcam index*/
int32 tcam_idx_new = 0;/*next tcam index for the entry*/
sys_acl_block_t* pb;/*field slice control*/
uint8 asic_type;
CM_PTR_VALID_CHECK(pe);
asic_type = acl_master->asic_type[pe->key.type];
pb = &acl_master->block[asic_type];
if(amount == 0)
{
return(CM_E_NONE);
}
tcam_idx_old = pe->block_index;
tcam_idx_new = tcam_idx_old + amount;
/*move the hardware entry*/
CM_ERROR_RETURN(_sys_humber_acl_entry_move_hw(pe, tcam_idx_new));
/*move the software entry*/
pb->entries[tcam_idx_old];
pb->entries[tcam_idx_new] = pe;
pb->block_index = tcam_idx_new;
return CM_E_NONE;
}
/*shift up entries from target entry to prev null entry*/
static int32
_sys_humber_acl_entry_shift_up(sys_acl_block_t* pb, int32 target_index, int32 prev_null_index)
{
int32 temp;
CM_PTR_VALID_CHECK(pb);
temp = prev_null_index;
/*start from prev - 1
* prev+1 --> prev
* prev+2 --> prev + 1
* ..
*target --> target - 1
*/
while((temp < target_index))
{
CM_ERROR_RETURN(_sys_humber_acl_entry_move(pb->entries[temp+1], -1));
temp++;
}
return CM_E_NONE;
}
/*shift down entries from target entry to next null entry*/
static int32
_sys_humber_acl_entry_shift_down(sys_acl_entry_t* pb, int32 target_index, int32 next_null_index)
{
int32 temp;
CM_PTR_VALID_CHECK(pb);
SYS_ACL_DBG_FUNC();
temp = next_null_index;
while((temp > target_index))
{
CM_ERROR_RETURN(_sys_humber_acl_entry_move(pb->entries[temp-1], 1));
temp--;
}
return CM_E_NONE;
}
static int32
_sys_humber_acl_reorder(sys_acl_block_t* pb, int32 bottom_index, uint8 extra_num)
{
int32 idx;
int32 t_idx;
int32 o_idx;
_fpa_target_t *target_a = NULL;
int32 ret = 0;
uint8 move_ok;
//static double time;
//clock_t begin, end;
uint32 full_num;
uint32 free_num;
uint32 real_num;
uint32 left_num;
//begin = clock();
CM_PTR_VALID_CHECK(pb);
extra_num = extra_num ? 1 : 0;/*extra num is 1 for new entry*/
/*malloc a new array based on new exist entry*/
full_num = pb->entry_count - extra_num;/* if extra_num == 1, reserve last*/
free_num = pb->free_count;
real_num = pb->entry_count - pb->free_count;
target_a = (_fpa_target_t*)mem_malloc(MEM_ACLQOS_MODULE, real_num * sizeof(_fpa_target_t));
if(!target_a)
{
return CM_E_NO_MEMORY;
}
memset(target_a, 0, sizeof(real_num * sizeof(_fpa_target_t)));
/*save target idx to array*/
for(t_idx = 0; t_idx < real_num; t_idx++)
{
target_a[t_idx].t_idx = (full_num * t_idx)/real_num;
}
/*save old idx to array*/
o_idx = 0;
for(idx = 0; t_idx < real_num; t_idx++)
{
if(pb->entries[idx])
{
target_a[o_idx].o_idx = idx;
o_idx++;
}
}
left_num = real_num;
/*move num*/
while(left_num)
{
SYS_ACL_DBG_INFO("");
for(idx = 0; idx < left_num; idx++)
{
move_ok = 0;
if(target_a[idx].o_idx == target_a[idx].t_idx)/* stay */
{
SYS_ACL_DBG_INFO("stay\n");
kal_memmove(&target_a[idx], &target_a[idx+1], (left_num - idx -1)*sizeof(_fpa_target_t));
left_num--;
idx--;
}else{
if(target-a[idx].o_idx < target_a[idx].t_idx)/* move down */
{
if((idx == left_num - 1)||(target_a[idx+1].o_idx > target_a[idx].t_idx))
{
move_ok = 1;
}
}else{/* move up */
if((idx == 0)||(target_a[idx-1].o_idx > target_a[idx].t_idx))
{
move_ok = 1;
}
}
if(move_ok)
{
CM_ERROR_RETURN(_sys_humber_acl_entry_move(pb->entries[target_a[idx].o_idx], (target_a[idx].t_idx - target_a[idx].o_idx)), ret, cleanup);
kal_memmove(&target_a[idx], &target_a[idx+1], (left_num - idx -1)*sizeof(_fpa_target_a));
left_num--;
idx--;
}
}
}
}
mem_free(target_a);
//end = clock();
//time = time + (double)end - begin)/CLOCKS_PER_SEC;
return CM_E_NONE;
cleanup:
mem_free(target_a);
return ret;
}
static int32
_sys_humber_acl_lookup_block_index(uint16 entry_id, uint16* block_index)
{
sys_acl_entry_t *pe = NULL;
*block_index = SYS_ACL_INVALID_INDEX;// SYS_ACL_INVALID_INDEX = -1
_sys_acl_get_sys_entry_by_eid(entry_id, &pe);
if(pe)
{
*block_index = pe->block_index;
}
return CM_E_NONE;
}
static int32
_sys_humber_acl_shift_all_entries_down(sys_acl_block_t* pb)
{
int32 prev_entry_idx = 0;
int32 left_num;
int32 idx;
int32 null_idx = 0;
left_num = pb->entry_count - pb->free_count;
idx = pb->entry_count - 1;
while(left_num)
{
if(pb->entries[idx])
{
idx--;
left_num--;
countinue;
}
null_idx = idx;
for(prev_entry_idx = null_idx; prev_entry_idx >= 0; prev_entry_idx--)
{
if(pb->entries[prev_entry_idx])
{
_sys_humber_acl_entry_move(pb->entries[prev_entry_idx], null_idx - prev_entry_idx);
break;
}
}
if(prev_entry_idx < 0)
{
break;
}
}
return CM_E_NONE;
}
staitc int32
_sys_humber_acl_shift_all_entries_up(sys_acl_block_t* pb)
{
int32 next_entry_idx = 0;
int32 left_num;
int32 idx;
int32 null_idx = 0;
left_num = pb->entry_count - pb->free_count;
idx = 0;
while(left_num)
{
if(pb->entries[idx])
{
idx++;
left_num--;
continue;
}
null_idx = idx;
for(next_entry_idx = null_idx; next_entry_idx < pb->entry_count; next_entry_idx++)
{
if(pb->entries[next_entry_idx])
{
_sys_humber_acl_entry_move(pb->entries[next_entry_idx], null_idx - next_enrty_idx);
break;
}
}
if(next_entry_idx >= pb->entry_count)
{
break;
}
}
return CM_E_NONE;
}
/*worst is bset*/
static int32
_sys_humber_acl_magic_reorder(sys_acl_block_t* pb, uint32 after_entry_id)
{
if((pb->entry_count - pb->free_count) > SYS_ACL_REMEMBER_BASE;//SYS_ACL_REMEMBER_BASE = 10
{
return CM_E_NONE;
}
if(after_entry_id == CM_ACLQOS_ENTRY_ID_HEAD)
{
pb->after_0_cnt++;
}
else if(after_entry_id < CM_ACLQOS_ENTRY_ID_TAIL)
{
pb->after_1_cnt++;
}
if((pb->entry_count - pb->free_count) == SYS_ACL_REMEMBER_BASE)
{
if(pb->after_0_cnt >= 4 + pb->after_1_cnt)
{
_sys_humber_acl_shift_all_entries_down(pb);
}
else if(pb->after_1_cnt >= 4 + pb->after_0_cnt)
{
_sys_humber_acl_shift_all_entries_up(pb);
}
}
return CM_E_NONE;
}
static int32
_sys_humber_acl_get_block_index(sys_acl_block_t *pb, uint32 after_entry_id, uint16* block_index, uint16* shift_amount)
{
int32 bottom_idx = 0;
int32 target_idx = 0;
int32 first_entry_idx = 0;
int32 idx;
int32 prev_null_idx = 0;
int32 next_null_idx = 0;
int32 shift_up_amount = 0;
int32 shift_down_amount = 0;
int16 after_idx = 0;
CM_PTR_VALID_CHECK(pb);
CM_PTR_VALID_CHECK(block_index);
if(pb->free_count < 1)
{
return CM_E_ACL_GET_BLOCK_INDEX_FAILED;
}
*shift_amount = 0;
_sys_humber_acl_magic_reorder(pb, after_entry_id);
if(after_entry_id == CM_ACLQOS_ENTRY_ID_TAIL)
{
next_null_idx = SYS_ACL_INVALID_INDEX;
bottom_idx = pb->entry_count + pb->entry_dft_max - 1;
for(idx = pb->entry_count; idx <= bottom_idx; idx++)
{
if(pb->entries[idx] == NULL)
{
next_null_idx = idx;
break;
}
}
target_idx = next_null_idx;
pb->entry_dft_cnt++;
}else if(pb->entry_count == pb->free_count){
target_idx = pb->entry_count - 1;
}
else if(after_entry_id == CM_ACLQOS_ENTRY_ID_HEAD)
{
/*get last not null index*/
first_entry_idx = SYS_ACL_INVALID_INDEX;
for( idx = 0; idx < pb->entry_count; idx++)
{
if(pb->entries[idx] != NULL)
{
first_entry_idx = idx;
break;
}
}
if(first_entry_idx == 0)
{
next_null_idx = SYS_ACL_INVALID_INDEX;
target_idx = 0;
/*search first next null entry from top down*/
for(idx = target_idx; idx < pb->entry_count; idx++)
{
if(pb->entries[idx] == NULL)
{
next_null_idx = idx;
break;
}
}
shift_down_amount = next_null_idx - target_idx - 1;
CM_ERROR_RETURN(_sys_humber_acl_entry_shift_down(pb, target_idx, next_null_idx));
*shift_amount = shift_down_amount;
}else{
target_idx = first_entry_idx - 1;
}
}else{
CM_ERROR_RETURN(_sys_humber_acl_lookup_block_index(after_entry_id, &after_idx));
next_null_idx = SYS_ACL_INVALID_INDEX;
prev_null_idx = SYS_ACL_INVALID_INDEX;
for(idx = after_idx; idx >= 0; idx--)
{
if(pb->entries[idx] == NULL)
{
prev_null_idx = idx;
break;
}
}
for(idx = after_idx; idx < pb->entry_count; idx++)
{
if(pb->entries[idx] == NULL)
{
next_null_idx = idx;
break;
}
}
if(prev_null_idx == SYS_ACL_INVALID_INDEX)
{
shift_up_amount = pb->entry_count;
}else{
shift_up_amount = after_idx - prev_null_idx;
}
if(next_null_idx == SYS_ACL_INVALID_INDEX)
{
shift_down_amount = pb->entry_count;
}else{
shift_down_amount = next_null_idx - (after_idx + 1);
}
if(shift_down_amount <= shift_up_amount)
{
/*shift dowm*/
target_idx = after_idx + 1;
*shift_amount = shift_down_amount;
CM_ERROR_RETURN(_sys_humber_acl_entry_shift_down(pb, target_idx, prev_null_idx));
}else{
/*shift up*/
target_idx = after_idx;
*shift_amount = shift_up_amount;
CM_ERROR_RETURN(_sys_humber_acl_entry_shift_up(pb, target_idx, next_null_idx)
}
}
*block_index = target_idx;
return CM_E_NONE;
}
void*
cm_hash_lookup(cm_hash_t* hash, void *data)
{
uint32 key = 0;
uint32 index = 0;
uint32 hash_size = 0;
uint16 idx_1d = 0;
uint16 idx_2d = 0;
cm_hash_backet_t *backet = NULL;
if(!hash)
return NULL;
hash_size = hash->block_size * hash->block_num;
key = (*hash->hash_key)(data);
index = key % hash_size;
idx_1d = index / hash->block_size;
idx_2d = index % hash->block_size;
if(!hash->index[idx_1d])
{
return NULL;
}
for(backet = hash->index[idx_1d][idx_2d]; backet != NULL; backet = backet->next)
{
if(backet->key == key && (*hash->hash_cmp)(backet->data, data) == TRUE)
{
return backet->data;
}
}
return NULL;
}
int32
sys_humber_aclqos_label_lookup(uint32 lable_id, uint8 is_service_label, sys_aclqos_label_t** pp_label)
{
sys_aclqos_label_t label;
CM_NOT_ZERO_CHECK(lable_id);
CM_PTR_VALID_CHECK(pp_label);
label.id = lable_id;
if(is_service_label)
{
*pp_label = cm_hash_lookup(p_service_label_hash, &label);
}else{
*pp_label = cm_hash_lookup(p_aclqos_label_hash, &label);
}
return CM_E_NONE;
}
uint8
sys_humber_get_local_chip_num(void)
{
if( NULL == p_chip_master)
return 0;
return p_chip_master->lchip_num;
}
static int32
_sys_humber_aclqos_map_action(uint8 lchip, sys_aclqos_label_t* p_label, cm_aclqos_action_t *p_cm_action, sys_aclqos_action_t *p_sys_action)
{
cm_direction_t dir;
sys_nh_offset_array_t offset_array;
sys_humber_opf_t opf;
uint32 ds_fwd_offset = 0;
uint32 ds_fwd_base = 0;
sys_nh_info_ecmp_t* p_nhinfo = 0;
sys_acl_redirect_t acl_redirect;
sys_acl_redirect_t *p_acl_redirect = 0;
uint32 ret = 0;
CM_PTR_VALID_CHECK(pp_label);
CM_PTR_VALID_CHECK(p_cm_action);
CM_PTR_VALID_CHECK(p_sys_action);
kal_memset(&opf, 0, sizeof(opf));
kal_memset(&ad_redirect, 0, sizeof(acl_redirect));
dir = p_label->dir;
/*deny*/
if(p_cm_action->flag & CTC_ACLQOS_ACTION_DISCARD_FLAG)
{
p_sys_action->flag.discard = 1;
}
//deny bridging
if(p_cm_action->flag & CTC_ACLQOS_ACTION_DENY_BRIDGE_FLAG)
{
p_sys_action->flag.deny_bridge = 1;
}
//deny learning
if(p_cm_action->flag & CTC_ACLQOS_ACTION_DENY_LEARN_FLAG)
{
p_sys_action->flag.deny_learning = 1;
}
//deny route
if(p_cm_action->flag & CTC_ACLQOS_ACTION_DENY_ROUTE_FLAG)
{
p_sys_action->flag.deny_route = 1;
}
//deny replace cos
if(p_cm_action->flag & CTC_ACLQOS_ACTION_DENY_REPLACE_COS_FLAG)
{
p_sys_action->flag.deny_replace_cos = 1;
}
//deny replace dscp
if(p_cm_action->flag & CTC_ACLQOS_ACTION_DENY_REPLACE_DSCP_FLAG)
{
p_sys_action->flag.deny_replace_dscp = 1;
}
//stats
if(p_cm_action->flag & CTC_ACLQOS_ACTION_STATS_FLAG)
{
if(p_cm_action->flags & CTC_ACLQOS_ACTION_FLOW_ID_FLAGS)
{
return CTC_E_ACLQOS_COLLISION_FIELD;
}
p_sys_action->flag.stats = 1;
p_sys_action->stats_or_flowid.stats_ptr = SPECIAL_STATS_PTR;
if(p_cm_action->stats_ptr >= 4096)
{
return CTC_E_INVALID_FARAM;
}
p_sys_action->stats_or_flowid.stats_ptr = p_cm_action->stats_ptr;
}
//flow id
if(p_cm_action->flag & CTC_ACLQOS_ACTION_FLOW_ID_FLAG)
{
CTC_MAX_VALUE_CHECK(p_cm_action->flow_id, 254);
p_sys_action->flag.flow_id = 1;
p_sys_action->stats_or_flowid.flow_id = 255 - p_cm_action->flow_id;
}
//flow policer
if(p_cm_action->flag & CTC_ACLQOS_ACTION_FLOW_POLICER_FLAG)
{
p_sys_action->flag.flow_policer = 1;
p_sys_action->policer_id = p_cm_action->policer_id;
}
//copy to cpu
if(p_cm_action->flag & CTC_ACLQOS_ACTION_COPY_TO_CPU_FLAG)
{
CTC_MAX_VALUE_CHECK(p_cm_action->log_weight, 0xF);
p_cm_action->log_weight = p_cm_action->log_weight ? p_cm_action->log_weight : OxF;
p_sys_action->flag.copy_to_cpu = 1;
p_sys_action->acl_log_id = CTC_ACLQOS_LOG_SESSION_3;
p_sys_action->random_threshold_shift = p_cm_action->log_weight;
}
//invalid
if(p_cm_action->flag & CTC_ACLQOS_ACTION_INVALID_FLAG)
{
p_sys_action->flag.invalid = 1;
}
return CM_E_NONE;
}
static int32
_sys_humber_aclqos_map_key(uint8 lchip, sys_aclqos_label_t *p_label, cm_aclqos_key_t *p_cm_key, sys_aclqos_key_t *p_sys_key)
{
sys_aclqos_label_index_t *p_label_index;
CM_PTR_VALID_CHECK(pp_label);
CM_PTR_VALID_CHECK(p_cm_key);
CM_PTR_VALID_CHECK(p_sys_key);
p_label_index = p_label->p_index[lchip];
CM_PTR_VALID_CHECK(p_label_index);
p_sys_key->type = p_cm_key->type;
if(SYS_PBR_ACL_LABEL != p_label->tyoe)
{
switch(p_sys_key->type)
{
case: CTC_ACLQOS_MAC_KEY:
CM_ERROR_RETURN(
_sys_humber_aclqos_map_mac_key(lchip, p_label, &p_cm_key->key_info.mac_key, &p_sys_key->key_info.mac_key));
break;
case: CTC_ACLQOS_IPV4_KEY:
CM_ERROR_RETURN(
_sys_humber_aclqos_map_ipv4_key(lchip, p_label, &p_cm_key->key_info.ipv4_key, &p_sys_key->key_info.ipv4_key));
break;
case: CTC_ACLQOS_MPLS_KEY:
CM_ERROR_RETURN(
_sys_humber_aclqos_map_mpls_key(lchip, p_label, &p_cm_key->key_info.mpls_key, &p_sys_key->key_info.mpls_key));
break;
case: CTC_ACLQOS_IPV6_KEY:
CM_ERROR_RETURN(
_sys_humber_aclqos_map_ipv6_key(lchip, p_label, &p_cm_key->key_info.ipv6_key, &p_sys_key->key_info.ipv6_key));
break;
default:
return CM_E_ACLQOS_INVALID_KEY_TYPE;
}
}else{
/*NULL*/
return CM_E_ACLQOS_INVALID_KEY_TYPE;
}
return CM_E_NONE;
}
void
cm_list_pointer_insert_tail(cm_list_pointer_t *p_list, cm_list_pointer_node_t *p_node)
{
p_node->p_next = NULL;
p_node->p_prev = _CTC_LTAIL(p_list);
}
static int32
_sys_humber_aclqos_add_entry_to_db(sys_acl_block_t *pb, sys_aclqos_entry_t *p_entry)
{
sys_aclqos_label_index_t *p_index = NULL;
cm_list_pointer_t *p_list = NULL;
sys_aclqos_label_t *p_label;
p_label = p_entry->p_label;
p_index = p_label->p_index[0];
p_list = &p_index->entry_list[p_entry->key.type];
cm_list_pointer_insert_tail(p_list, &p_entry->head);
//add to hash
cm_hash_insert(acl_master->entry, p_entry);
//add to block
pb->entries[p_entry->block_index] = p_entry;
//free count
//ignore the default entry
if(p_entry->block_index < pb->entry_count)
{
(pb->free_count)--;
}
return CM_E_NONE;
}
static int32
_sys_humber_aclqos_remove_entry_from_db(sys_acl_block_t *pb, sys_aclqos_entry_t *p_entry)
{
sys_aclqos_label_index_t *p_index = NULL;
cm_list_pointer_t *p_list = NULL;
sys_aclqos_label_t *p_label;
sys_humber_opf_t opf;
uint32 ds_fwd_offset = 0;
sys_acl_redirect_t acl_redirect;
sys_acl_redirect_t *p_acL_redirect = 0;
p_label = p_entry->p_label;
p_index = p_label->p_index[0];
p_list = &p_index->entry_list[p_entry->key.type];
//unbind flow policer
if(p_entry->action.flag.flow_policer)
{
sys_humber_qos_flow_policer_unbind(p_sys_acl_redirect_hash[pb->lchip], &acl_redirect);
if(p_acl_redirect)
{
p_acl_redirect->ref--;
if(p_acl_redirect->ref == 0)
{
opf.pool_type = OPF_ACL_FWD_SRAM;
opf.pool_index = pb->lchip;
ds_fwd_offset = p_entry->action.ds_fwd_ptr;
CM_ERROR_RETURN(sys_humber_opf_free_offset9&opf, 1, ds_fwd_offset));
cm_hash_remove(p_sys_acl_redirect_hash[pb->lchip], p_acl_redirect);
mem_free(p_acl_redirect);
}
}else{
return CM_E_ACLQOS_INVALID_ACTION;
}
}
//remove from hash
cm_hash_remove(acl_master->entry, p_entry);
//removr from block
pb->entries[p_entry->block_index] = NULL;
//free count++
//ignore the default entry
if(p_entry->block_index < pb->entry_count)
{
(pb->free_count)++;
}
if(p_entry->head.p_prev)
{
cm_list_pointer_delete(p_list, &p_entry->head);
}
mem_free(p_entry);
return CM_E_NONE;
}
static int32
_sys_humber_aclqos_entry_write(sys_acl_block_t *pb, sys_aclqos_entry_t *p_entry)
{
sys_aclqos_sub_entry_info_t info;
CM_PTR_VALID_CHECK(p_entry);
memset(&info, 0, sizeof(info));
info.offset = p_entry->block_index;
CM_ERROR_RETURN(
_sys_humber_aclqos_write_entry_to_chip(0, p_entry->p_label, p_entry, &info));
//add to database
CM_ERROR_RETURN(
_sys_humber_aclqos_add_entry_to_db(pb, p_entry));
return CM_E_NONE;
}
static int32
_sys_humber_aclqos_entry_remove(sys_acl_block_t *pb, sys_aclqos_entry_t* p_entry)
{
CM_PTR_VALID_CHECK(p_entry);
//remove all sub entries from tcam and db
CM_ERROR_RETURN(
_sys_humber_aclqos_remove_sub_entry(0, p_entry->p_label, p_entry);
CM_ERROR_RETURN(
_sys_humber_aclqos_remove_entry_from_db(pb, p_entry));
return CM_E_NONE;
}
int32
sys_humber_aclqos_entry_insert(uint32 label_id, cm_aclqos_label_type_t label_type, uint32 entry_id, cm_aclqos_entry_t *p_cm_entry)
{
sys_aclqos_entry_t *p_sys_entry[MAX_LOCAL_CHIP_NUM];
sys_aclqos_action_t *p_sys_action;
sys_aclqos_key_t *p_sys_key;
sys_aclqos_label_t *p_label = NULL;
uint8 lchip, lchip_num;
int32 ret;
uint8 is_service_label = 0;
uint16 block_index = 0;
sys_aclqos_block_t *pb = NULL;
uint8 asic_type;
uint16 shift_amount = 0;
CM_PTR_VALID_CHECK(p_cm_entry);
CTC_MIN_VALUE_CHECK(p_cm_entry->entry_id, 1);
if(SERVICE_LABEL == label_type)
{
is_service_label = 1;
}
CM_ERROR_RETURN(sys_humber_aclqos_label_lookup(label_id, is_service_label, &p_label));
if(!p_label)
{
return CM_E_ACLQOS_LABEL_NOT_EXIST;
}
if(QOS_LABEL == label_type)
{
if(IS_ACL_LABEL(p_label->type))
return CM_E_ACLQOS_DIFFERENT_TYPE;
}else if(ACL_LABEL == label_type)
{
if(IS_QOS_LABEL(p_label->type))
return CM_E_ACLQOS_DIFFERENT_TYPE;
}
kal_memset(p_sys_entry, 0, sizeof(p_sys_entry));
asic_type = acl_master->asic_type[p_cm_entry->key.type];
pb = &acl_master->block[asic_type];
//add entry
lchip_num = sys_humber_get_local_chip_num();
for(lchip = 0, lchip < lchip_num; lchip++)
{
if(!p_label->p_label[lchip])
{
continue;
}
_sys_acl_get_sys_entry_by_eid(p_cm_entry->entry_id, &p_sys_entry[lchip]);
if(p_sys_entry[lchip])
{
ret = CM_E_ACLQOS_ENTRY_EXIST;
p_sys_entry[lchip] = NULL;
goto ERR;
}
p_sys_entry[lchip] = (sys_aclqos_entry_t *)mem_malloc(MEM_ACLQOS_MODELE, sizeof(sys_aclqos_entry_t));
if(!p_sys_entry[lchip])
{
ret = CM_E_NO_MEMORY;
goto ERR;
}
kal_memset(p_sys_entry[lchip], 0, sizeof(sys_aclqos_entry_t));
p_sys_entry[lchip]->entry_id = p_cm_entry->entry_id;
p_sys_action = &p_sys_entry[lchip]->action;
p_sys_key = &p_sys_entry[lchip]->key;
p_sys_entry[lchip]->p_label = p_label;
//map acl/qos action
ret = _sys_humber_aclqos_map_action(lchip, p_label, &p_cm_entry->action, p_sys_action);
if(ret)
{
goto ERR;
}
//map acl/qos key
ret = _sys_humber_aclqos_map_key(lchip, p_label, &p_cm_entry->key, p_sys_key);
if(ret)
{
goto ERR;
}
//get entry offset
ret = _sys_humber_acl_get_block_index(pb, entry_id, &block_index, &shift_amount);
if(ret)
{
goto ERR;
}
p_sys_entry[lchip]->block_index = block_index;
//write entries
ret = _sys_humber_aclqos_entry_write(pb, p_sys_entry[lchip]);
if(ret)
{
goto ERR;
}
if(DO_REORDER(shift_amount, pb->entry_count))
{
_sys_humber_acl_reorder(pb, pb->entry_count - 1, 0);
}
}