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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
|
/*-
* Copyright 2007-2009 Solarflare Communications Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include "efsys.h"
#include "efx.h"
#include "efx_types.h"
#include "efx_regs.h"
#include "efx_impl.h"
#if EFSYS_OPT_FILTER
/* "Fudge factors" - difference between programmed value and actual depth.
* Due to pipelined implementation we need to program H/W with a value that
* is larger than the hop limit we want.
*/
#define FILTER_CTL_SRCH_FUDGE_WILD 3
#define FILTER_CTL_SRCH_FUDGE_FULL 1
/* Hard maximum hop limit. Hardware will time-out beyond 200-something.
* We also need to avoid infinite loops in efx_filter_search() when the
* table is full.
*/
#define FILTER_CTL_SRCH_MAX 200
/* The filter hash function is LFSR polynomial x^16 + x^3 + 1 of a 32-bit
* key derived from the n-tuple. */
static uint16_t
efx_filter_tbl_hash(
__in uint32_t key)
{
uint16_t tmp;
/* First 16 rounds */
tmp = 0x1fff ^ (uint16_t)(key >> 16);
tmp = tmp ^ tmp >> 3 ^ tmp >> 6;
tmp = tmp ^ tmp >> 9;
/* Last 16 rounds */
tmp = tmp ^ tmp << 13 ^ (uint16_t)(key & 0xffff);
tmp = tmp ^ tmp >> 3 ^ tmp >> 6;
tmp = tmp ^ tmp >> 9;
return (tmp);
}
/* To allow for hash collisions, filter search continues at these
* increments from the first possible entry selected by the hash. */
static uint16_t
efx_filter_tbl_increment(
__in uint32_t key)
{
return ((uint16_t)(key * 2 - 1));
}
static __checkReturn boolean_t
efx_filter_test_used(
__in efx_filter_tbl_t *eftp,
__in unsigned int index)
{
EFSYS_ASSERT3P(eftp->eft_bitmap, !=, NULL);
return ((eftp->eft_bitmap[index / 32] & (1 << (index % 32))) != 0);
}
static void
efx_filter_set_used(
__in efx_filter_tbl_t *eftp,
__in unsigned int index)
{
EFSYS_ASSERT3P(eftp->eft_bitmap, !=, NULL);
eftp->eft_bitmap[index / 32] |= (1 << (index % 32));
++eftp->eft_used;
}
static void
efx_filter_clear_used(
__in efx_filter_tbl_t *eftp,
__in unsigned int index)
{
EFSYS_ASSERT3P(eftp->eft_bitmap, !=, NULL);
eftp->eft_bitmap[index / 32] &= ~(1 << (index % 32));
--eftp->eft_used;
EFSYS_ASSERT3U(eftp->eft_used, >=, 0);
}
static efx_filter_tbl_id_t
efx_filter_tbl_id(
__in efx_filter_type_t type)
{
efx_filter_tbl_id_t tbl_id;
switch (type)
{
case EFX_FILTER_RX_TCP_FULL:
case EFX_FILTER_RX_TCP_WILD:
case EFX_FILTER_RX_UDP_FULL:
case EFX_FILTER_RX_UDP_WILD:
tbl_id = EFX_FILTER_TBL_RX_IP;
break;
#if EFSYS_OPT_SIENA
case EFX_FILTER_RX_MAC_FULL:
case EFX_FILTER_RX_MAC_WILD:
tbl_id = EFX_FILTER_TBL_RX_MAC;
break;
case EFX_FILTER_TX_TCP_FULL:
case EFX_FILTER_TX_TCP_WILD:
case EFX_FILTER_TX_UDP_FULL:
case EFX_FILTER_TX_UDP_WILD:
tbl_id = EFX_FILTER_TBL_TX_IP;
break;
case EFX_FILTER_TX_MAC_FULL:
case EFX_FILTER_TX_MAC_WILD:
tbl_id = EFX_FILTER_TBL_RX_MAC;
break;
#endif /* EFSYS_OPT_SIENA */
default:
EFSYS_ASSERT(B_FALSE);
break;
}
return (tbl_id);
}
static void
efx_filter_reset_search_depth(
__inout efx_filter_t *efp,
__in efx_filter_tbl_id_t tbl_id)
{
switch (tbl_id)
{
case EFX_FILTER_TBL_RX_IP:
efp->ef_depth[EFX_FILTER_RX_TCP_FULL] = 0;
efp->ef_depth[EFX_FILTER_RX_TCP_WILD] = 0;
efp->ef_depth[EFX_FILTER_RX_UDP_FULL] = 0;
efp->ef_depth[EFX_FILTER_RX_UDP_WILD] = 0;
break;
#if EFSYS_OPT_SIENA
case EFX_FILTER_TBL_RX_MAC:
efp->ef_depth[EFX_FILTER_RX_MAC_FULL] = 0;
efp->ef_depth[EFX_FILTER_RX_MAC_WILD] = 0;
break;
case EFX_FILTER_TBL_TX_IP:
efp->ef_depth[EFX_FILTER_TX_TCP_FULL] = 0;
efp->ef_depth[EFX_FILTER_TX_TCP_WILD] = 0;
efp->ef_depth[EFX_FILTER_TX_UDP_FULL] = 0;
efp->ef_depth[EFX_FILTER_TX_UDP_WILD] = 0;
break;
case EFX_FILTER_TBL_TX_MAC:
efp->ef_depth[EFX_FILTER_TX_MAC_FULL] = 0;
efp->ef_depth[EFX_FILTER_TX_MAC_WILD] = 0;
break;
#endif /* EFSYS_OPT_SIENA */
default:
EFSYS_ASSERT(B_FALSE);
break;
}
}
static void
efx_filter_push_rx_limits(
__in efx_nic_t *enp)
{
efx_filter_t *efp = &enp->en_filter;
efx_oword_t oword;
EFX_BAR_READO(enp, FR_AZ_RX_FILTER_CTL_REG, &oword);
EFX_SET_OWORD_FIELD(oword, FRF_AZ_TCP_FULL_SRCH_LIMIT,
efp->ef_depth[EFX_FILTER_RX_TCP_FULL] +
FILTER_CTL_SRCH_FUDGE_FULL);
EFX_SET_OWORD_FIELD(oword, FRF_AZ_TCP_WILD_SRCH_LIMIT,
efp->ef_depth[EFX_FILTER_RX_TCP_WILD] +
FILTER_CTL_SRCH_FUDGE_WILD);
EFX_SET_OWORD_FIELD(oword, FRF_AZ_UDP_FULL_SRCH_LIMIT,
efp->ef_depth[EFX_FILTER_RX_UDP_FULL] +
FILTER_CTL_SRCH_FUDGE_FULL);
EFX_SET_OWORD_FIELD(oword, FRF_AZ_UDP_WILD_SRCH_LIMIT,
efp->ef_depth[EFX_FILTER_RX_UDP_WILD] +
FILTER_CTL_SRCH_FUDGE_WILD);
#if EFSYS_OPT_SIENA
if (efp->ef_tbl[EFX_FILTER_TBL_RX_MAC].eft_size) {
EFX_SET_OWORD_FIELD(oword,
FRF_CZ_ETHERNET_FULL_SEARCH_LIMIT,
efp->ef_depth[EFX_FILTER_RX_MAC_FULL] +
FILTER_CTL_SRCH_FUDGE_FULL);
EFX_SET_OWORD_FIELD(oword,
FRF_CZ_ETHERNET_WILDCARD_SEARCH_LIMIT,
efp->ef_depth[EFX_FILTER_RX_MAC_WILD] +
FILTER_CTL_SRCH_FUDGE_WILD);
}
#endif /* EFSYS_OPT_SIENA */
EFX_BAR_WRITEO(enp, FR_AZ_RX_FILTER_CTL_REG, &oword);
}
static void
efx_filter_push_tx_limits(
__in efx_nic_t *enp)
{
efx_filter_t *efp = &enp->en_filter;
efx_oword_t oword;
if (efp->ef_tbl[EFX_FILTER_TBL_TX_IP].eft_size == 0)
return;
EFX_BAR_READO(enp, FR_AZ_TX_CFG_REG, &oword);
EFX_SET_OWORD_FIELD(oword, FRF_CZ_TX_TCPIP_FILTER_FULL_SEARCH_RANGE,
efp->ef_depth[EFX_FILTER_TX_TCP_FULL] +
FILTER_CTL_SRCH_FUDGE_FULL);
EFX_SET_OWORD_FIELD(oword, FRF_CZ_TX_TCPIP_FILTER_WILD_SEARCH_RANGE,
efp->ef_depth[EFX_FILTER_TX_TCP_WILD] +
FILTER_CTL_SRCH_FUDGE_WILD);
EFX_SET_OWORD_FIELD(oword, FRF_CZ_TX_UDPIP_FILTER_FULL_SEARCH_RANGE,
efp->ef_depth[EFX_FILTER_TX_UDP_FULL] +
FILTER_CTL_SRCH_FUDGE_FULL);
EFX_SET_OWORD_FIELD(oword, FRF_CZ_TX_UDPIP_FILTER_WILD_SEARCH_RANGE,
efp->ef_depth[EFX_FILTER_TX_UDP_WILD] +
FILTER_CTL_SRCH_FUDGE_WILD);
EFX_BAR_WRITEO(enp, FR_AZ_TX_CFG_REG, &oword);
}
/* Build a filter entry and return its n-tuple key. */
static __checkReturn uint32_t
efx_filter_build(
__out efx_oword_t *filter,
__in efx_filter_spec_t *spec)
{
uint32_t dword3;
uint32_t key;
uint8_t type = spec->efs_type;
uint8_t flags = spec->efs_flags;
switch (efx_filter_tbl_id(type)) {
case EFX_FILTER_TBL_RX_IP: {
boolean_t is_udp = (type == EFX_FILTER_RX_UDP_FULL ||
type == EFX_FILTER_RX_UDP_WILD);
EFX_POPULATE_OWORD_7(*filter,
FRF_BZ_RSS_EN, (flags & EFX_FILTER_FLAG_RX_RSS) ? 1 : 0,
FRF_BZ_SCATTER_EN, (flags & EFX_FILTER_FLAG_RX_SCATTER) ? 1 : 0,
FRF_AZ_TCP_UDP, is_udp,
FRF_AZ_RXQ_ID, spec->efs_dmaq_id,
EFX_DWORD_2, spec->efs_dword[2],
EFX_DWORD_1, spec->efs_dword[1],
EFX_DWORD_0, spec->efs_dword[0]);
dword3 = is_udp;
break;
}
#if EFSYS_OPT_SIENA
case EFX_FILTER_TBL_RX_MAC: {
boolean_t is_wild = (type == EFX_FILTER_RX_MAC_WILD);
EFX_POPULATE_OWORD_8(*filter,
FRF_CZ_RMFT_RSS_EN, (flags & EFX_FILTER_FLAG_RX_RSS) ? 1 : 0,
FRF_CZ_RMFT_SCATTER_EN, (flags & EFX_FILTER_FLAG_RX_SCATTER) ? 1 : 0,
FRF_CZ_RMFT_IP_OVERRIDE, (flags & EFX_FILTER_FLAG_RX_OVERRIDE_IP) ? 1 : 0,
FRF_CZ_RMFT_RXQ_ID, spec->efs_dmaq_id,
FRF_CZ_RMFT_WILDCARD_MATCH, is_wild,
FRF_CZ_RMFT_DEST_MAC_DW1, spec->efs_dword[2],
FRF_CZ_RMFT_DEST_MAC_DW0, spec->efs_dword[1],
FRF_CZ_RMFT_VLAN_ID, spec->efs_dword[0]);
dword3 = is_wild;
break;
}
#endif /* EFSYS_OPT_SIENA */
case EFX_FILTER_TBL_TX_IP: {
boolean_t is_udp = (type == EFX_FILTER_TX_UDP_FULL ||
type == EFX_FILTER_TX_UDP_WILD);
EFX_POPULATE_OWORD_5(*filter,
FRF_CZ_TIFT_TCP_UDP, is_udp,
FRF_CZ_TIFT_TXQ_ID, spec->efs_dmaq_id,
EFX_DWORD_2, spec->efs_dword[2],
EFX_DWORD_1, spec->efs_dword[1],
EFX_DWORD_0, spec->efs_dword[0]);
dword3 = is_udp | spec->efs_dmaq_id << 1;
break;
}
#if EFSYS_OPT_SIENA
case EFX_FILTER_TBL_TX_MAC: {
boolean_t is_wild = (type == EFX_FILTER_TX_MAC_WILD);
EFX_POPULATE_OWORD_5(*filter,
FRF_CZ_TMFT_TXQ_ID, spec->efs_dmaq_id,
FRF_CZ_TMFT_WILDCARD_MATCH, is_wild,
FRF_CZ_TMFT_SRC_MAC_DW1, spec->efs_dword[2],
FRF_CZ_TMFT_SRC_MAC_DW0, spec->efs_dword[1],
FRF_CZ_TMFT_VLAN_ID, spec->efs_dword[0]);
dword3 = is_wild | spec->efs_dmaq_id << 1;
break;
}
#endif /* EFSYS_OPT_SIENA */
default:
EFSYS_ASSERT(B_FALSE);
}
key = spec->efs_dword[0] ^ spec->efs_dword[1] ^ spec->efs_dword[2] ^ dword3;
return (key);
}
static __checkReturn int
efx_filter_push_entry(
__inout efx_nic_t *enp,
__in efx_filter_type_t type,
__in int index,
__in efx_oword_t *eop)
{
int rc;
switch (type)
{
case EFX_FILTER_RX_TCP_FULL:
case EFX_FILTER_RX_TCP_WILD:
case EFX_FILTER_RX_UDP_FULL:
case EFX_FILTER_RX_UDP_WILD:
EFX_BAR_TBL_WRITEO(enp, FR_AZ_RX_FILTER_TBL0, index, eop);
break;
#if EFSYS_OPT_SIENA
case EFX_FILTER_RX_MAC_FULL:
case EFX_FILTER_RX_MAC_WILD:
EFX_BAR_TBL_WRITEO(enp, FR_CZ_RX_MAC_FILTER_TBL0, index, eop);
break;
case EFX_FILTER_TX_TCP_FULL:
case EFX_FILTER_TX_TCP_WILD:
case EFX_FILTER_TX_UDP_FULL:
case EFX_FILTER_TX_UDP_WILD:
EFX_BAR_TBL_WRITEO(enp, FR_CZ_TX_FILTER_TBL0, index, eop);
break;
case EFX_FILTER_TX_MAC_FULL:
case EFX_FILTER_TX_MAC_WILD:
EFX_BAR_TBL_WRITEO(enp, FR_CZ_TX_MAC_FILTER_TBL0, index, eop);
break;
#endif /* EFSYS_OPT_SIENA */
default:
rc = ENOTSUP;
goto fail1;
}
return (0);
fail1:
return (rc);
}
static __checkReturn boolean_t
efx_filter_equal(
__in const efx_filter_spec_t *left,
__in const efx_filter_spec_t *right)
{
efx_filter_tbl_id_t tbl_id = efx_filter_tbl_id(left->efs_type);
if (left->efs_type != right->efs_type)
return (B_FALSE);
if (memcmp(left->efs_dword, right->efs_dword, sizeof(left->efs_dword)))
return (B_FALSE);
if ((tbl_id == EFX_FILTER_TBL_TX_IP ||
tbl_id == EFX_FILTER_TBL_TX_MAC) &&
left->efs_dmaq_id != right->efs_dmaq_id)
return (B_FALSE);
return (B_TRUE);
}
static __checkReturn int
efx_filter_search(
__in efx_filter_tbl_t *eftp,
__in efx_filter_spec_t *spec,
__in uint32_t key,
__in boolean_t for_insert,
__out int *filter_index,
__out unsigned int *depth_required)
{
unsigned hash, incr, filter_idx, depth;
hash = efx_filter_tbl_hash(key);
incr = efx_filter_tbl_increment(key);
filter_idx = hash & (eftp->eft_size - 1);
depth = 1;
for (;;) {
/* Return success if entry is used and matches this spec
* or entry is unused and we are trying to insert.
*/
if (efx_filter_test_used(eftp, filter_idx) ?
efx_filter_equal(spec, &eftp->eft_spec[filter_idx]) :
for_insert) {
*filter_index = filter_idx;
*depth_required = depth;
return (0);
}
/* Return failure if we reached the maximum search depth */
if (depth == FILTER_CTL_SRCH_MAX)
return for_insert ? EBUSY : ENOENT;
filter_idx = (filter_idx + incr) & (eftp->eft_size - 1);
++depth;
}
}
__checkReturn int
efx_filter_insert_filter(
__in efx_nic_t *enp,
__in efx_filter_spec_t *spec,
__in boolean_t replace)
{
efx_filter_t *efp = &enp->en_filter;
efx_filter_tbl_id_t tbl_id = efx_filter_tbl_id(spec->efs_type);
efx_filter_tbl_t *eftp = &efp->ef_tbl[tbl_id];
efx_filter_spec_t *saved_spec;
efx_oword_t filter;
int filter_idx;
unsigned int depth;
int state;
uint32_t key;
int rc;
if (eftp->eft_size == 0)
return (EINVAL);
key = efx_filter_build(&filter, spec);
EFSYS_LOCK(enp->en_eslp, state);
rc = efx_filter_search(eftp, spec, key, B_TRUE, &filter_idx, &depth);
if (rc != 0)
goto done;
EFSYS_ASSERT3U(filter_idx, <, eftp->eft_size);
saved_spec = &eftp->eft_spec[filter_idx];
if (efx_filter_test_used(eftp, filter_idx)) {
if (replace == B_FALSE) {
rc = EEXIST;
goto done;
}
}
efx_filter_set_used(eftp, filter_idx);
*saved_spec = *spec;
if (efp->ef_depth[spec->efs_type] < depth) {
efp->ef_depth[spec->efs_type] = depth;
if (tbl_id == EFX_FILTER_TBL_TX_IP ||
tbl_id == EFX_FILTER_TBL_TX_MAC)
efx_filter_push_tx_limits(enp);
else
efx_filter_push_rx_limits(enp);
}
efx_filter_push_entry(enp, spec->efs_type, filter_idx, &filter);
done:
EFSYS_UNLOCK(enp->en_eslp, state);
return (rc);
}
static void
efx_filter_clear_entry(
__in efx_nic_t *enp,
__in efx_filter_tbl_t *eftp,
__in int index)
{
efx_oword_t filter;
if (efx_filter_test_used(eftp, index)) {
efx_filter_clear_used(eftp, index);
EFX_ZERO_OWORD(filter);
efx_filter_push_entry(enp, eftp->eft_spec[index].efs_type,
index, &filter);
memset(&eftp->eft_spec[index], 0, sizeof(eftp->eft_spec[0]));
}
}
__checkReturn int
efx_filter_remove_filter(
__in efx_nic_t *enp,
__in efx_filter_spec_t *spec)
{
efx_filter_t *efp = &enp->en_filter;
efx_filter_tbl_id_t tbl_id = efx_filter_tbl_id(spec->efs_type);
efx_filter_tbl_t *eftp = &efp->ef_tbl[tbl_id];
efx_filter_spec_t *saved_spec;
efx_oword_t filter;
int filter_idx;
unsigned int depth;
int state;
uint32_t key;
int rc;
key = efx_filter_build(&filter, spec);
EFSYS_LOCK(enp->en_eslp, state);
rc = efx_filter_search(eftp, spec, key, B_FALSE, &filter_idx, &depth);
if (rc != 0)
goto out;
saved_spec = &eftp->eft_spec[filter_idx];
efx_filter_clear_entry(enp, eftp, filter_idx);
if (eftp->eft_used == 0)
efx_filter_reset_search_depth(efp, tbl_id);
rc = 0;
out:
EFSYS_UNLOCK(enp->en_eslp, state);
return (rc);
}
void
efx_filter_remove_index(
__inout efx_nic_t *enp,
__in efx_filter_type_t type,
__in int index)
{
efx_filter_t *efp = &enp->en_filter;
efx_filter_tbl_id_t tbl_id = efx_filter_tbl_id(type);
efx_filter_tbl_t *eftp = &efp->ef_tbl[tbl_id];
int state;
if (index < 0)
return;
EFSYS_LOCK(enp->en_eslp, state);
efx_filter_clear_entry(enp, eftp, index);
if (eftp->eft_used == 0)
efx_filter_reset_search_depth(efp, tbl_id);
EFSYS_UNLOCK(enp->en_eslp, state);
}
void
efx_filter_tbl_clear(
__inout efx_nic_t *enp,
__in efx_filter_tbl_id_t tbl_id)
{
efx_filter_t *efp = &enp->en_filter;
efx_filter_tbl_t *eftp = &efp->ef_tbl[tbl_id];
int index;
int state;
EFSYS_LOCK(enp->en_eslp, state);
for (index = 0; index < eftp->eft_size; ++index) {
efx_filter_clear_entry(enp, eftp, index);
}
if (eftp->eft_used == 0)
efx_filter_reset_search_depth(efp, tbl_id);
EFSYS_UNLOCK(enp->en_eslp, state);
}
/* Restore filter state after a reset */
void
efx_filter_restore(
__in efx_nic_t *enp)
{
efx_filter_t *efp = &enp->en_filter;
efx_filter_tbl_id_t tbl_id;
efx_filter_tbl_t *eftp;
efx_filter_spec_t *spec;
efx_oword_t filter;
int filter_idx;
int state;
EFSYS_LOCK(enp->en_eslp, state);
for (tbl_id = 0; tbl_id < EFX_FILTER_NTBLS; tbl_id++) {
eftp = &efp->ef_tbl[tbl_id];
for (filter_idx = 0; filter_idx < eftp->eft_size; filter_idx++) {
if (!efx_filter_test_used(eftp, filter_idx))
continue;
spec = &eftp->eft_spec[filter_idx];
efx_filter_build(&filter, spec);
efx_filter_push_entry(enp, spec->efs_type,
filter_idx, &filter);
}
}
efx_filter_push_rx_limits(enp);
efx_filter_push_tx_limits(enp);
EFSYS_UNLOCK(enp->en_eslp, state);
}
void
efx_filter_redirect_index(
__inout efx_nic_t *enp,
__in efx_filter_type_t type,
__in int filter_index,
__in int rxq_index)
{
efx_filter_t *efp = &enp->en_filter;
efx_filter_tbl_t *eftp =
&efp->ef_tbl[efx_filter_tbl_id(type)];
efx_filter_spec_t *spec;
efx_oword_t filter;
int state;
EFSYS_LOCK(enp->en_eslp, state);
spec = &eftp->eft_spec[filter_index];
spec->efs_dmaq_id = (uint16_t)rxq_index;
efx_filter_build(&filter, spec);
efx_filter_push_entry(enp, spec->efs_type, filter_index, &filter);
EFSYS_UNLOCK(enp->en_eslp, state);
}
__checkReturn int
efx_filter_init(
__in efx_nic_t *enp)
{
efx_filter_t *efp = &enp->en_filter;
efx_filter_tbl_t *eftp;
int tbl_id;
int rc;
EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
EFSYS_ASSERT(!(enp->en_mod_flags & EFX_MOD_FILTER));
switch (enp->en_family)
{
#if EFSYS_OPT_FALCON
case EFX_FAMILY_FALCON:
eftp = &efp->ef_tbl[EFX_FILTER_TBL_RX_IP];
eftp->eft_size = FR_AZ_RX_FILTER_TBL0_ROWS;
break;
#endif /* EFSYS_OPT_FALCON */
#if EFSYS_OPT_SIENA
case EFX_FAMILY_SIENA:
eftp = &efp->ef_tbl[EFX_FILTER_TBL_RX_IP];
eftp->eft_size = FR_AZ_RX_FILTER_TBL0_ROWS;
eftp = &efp->ef_tbl[EFX_FILTER_TBL_RX_MAC];
eftp->eft_size = FR_CZ_RX_MAC_FILTER_TBL0_ROWS;
eftp = &efp->ef_tbl[EFX_FILTER_TBL_TX_IP];
eftp->eft_size = FR_CZ_TX_FILTER_TBL0_ROWS;
eftp = &efp->ef_tbl[EFX_FILTER_TBL_TX_MAC];
eftp->eft_size = FR_CZ_TX_MAC_FILTER_TBL0_ROWS;
break;
#endif /* EFSYS_OPT_SIENA */
default:
rc = ENOTSUP;
goto fail1;
}
for (tbl_id = 0; tbl_id < EFX_FILTER_NTBLS; tbl_id++) {
unsigned int bitmap_size;
eftp = &efp->ef_tbl[tbl_id];
if (eftp->eft_size == 0)
continue;
EFX_STATIC_ASSERT(sizeof(eftp->eft_bitmap[0]) == sizeof(uint32_t));
bitmap_size = (eftp->eft_size + (sizeof(uint32_t) * 8) - 1) / 8;
EFSYS_KMEM_ALLOC(enp->en_esip, bitmap_size, eftp->eft_bitmap);
if (!eftp->eft_bitmap) {
rc = ENOMEM;
goto fail2;
}
EFSYS_KMEM_ALLOC(enp->en_esip, eftp->eft_size * sizeof(*eftp->eft_spec),
eftp->eft_spec);
if (!eftp->eft_spec) {
rc = ENOMEM;
goto fail3;
}
memset(eftp->eft_spec, 0, eftp->eft_size * sizeof(*eftp->eft_spec));
}
enp->en_mod_flags |= EFX_MOD_FILTER;
return (0);
fail3:
EFSYS_PROBE(fail3);
fail2:
EFSYS_PROBE(fail2);
efx_filter_fini(enp);
fail1:
EFSYS_PROBE1(fail1, int, rc);
return (rc);
}
void
efx_filter_fini(
__in efx_nic_t *enp)
{
efx_filter_t *efp = &enp->en_filter;
efx_filter_tbl_id_t tbl_id;
EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
for (tbl_id = 0; tbl_id < EFX_FILTER_NTBLS; tbl_id++) {
efx_filter_tbl_t *eftp = &efp->ef_tbl[tbl_id];
unsigned int bitmap_size;
EFX_STATIC_ASSERT(sizeof(eftp->eft_bitmap[0]) == sizeof(uint32_t));
bitmap_size = (eftp->eft_size + (sizeof(uint32_t) * 8) - 1) / 8;
if (eftp->eft_bitmap != NULL) {
EFSYS_KMEM_FREE(enp->en_esip, bitmap_size,
eftp->eft_bitmap);
eftp->eft_bitmap = NULL;
}
if (eftp->eft_spec != NULL) {
EFSYS_KMEM_FREE(enp->en_esip, eftp->eft_size *
sizeof(*eftp->eft_spec), eftp->eft_spec);
eftp->eft_spec = NULL;
}
}
enp->en_mod_flags &= ~EFX_MOD_FILTER;
}
extern void
efx_filter_spec_rx_ipv4_tcp_full(
__inout efx_filter_spec_t *spec,
__in unsigned int flags,
__in uint32_t src_ip,
__in uint16_t src_tcp,
__in uint32_t dest_ip,
__in uint16_t dest_tcp)
{
EFSYS_ASSERT3P(spec, !=, NULL);
EFSYS_ASSERT((flags & ~(EFX_FILTER_FLAG_RX_RSS |
EFX_FILTER_FLAG_RX_SCATTER)) == 0);
spec->efs_type = EFX_FILTER_RX_TCP_FULL;
spec->efs_flags = (uint8_t)flags;
spec->efs_dword[0] = src_tcp | src_ip << 16;
spec->efs_dword[1] = dest_tcp << 16 | src_ip >> 16;
spec->efs_dword[2] = dest_ip;
}
extern void
efx_filter_spec_rx_ipv4_tcp_wild(
__inout efx_filter_spec_t *spec,
__in unsigned int flags,
__in uint32_t dest_ip,
__in uint16_t dest_tcp)
{
EFSYS_ASSERT3P(spec, !=, NULL);
EFSYS_ASSERT((flags & ~(EFX_FILTER_FLAG_RX_RSS |
EFX_FILTER_FLAG_RX_SCATTER)) == 0);
spec->efs_type = EFX_FILTER_RX_TCP_WILD;
spec->efs_flags = (uint8_t)flags;
spec->efs_dword[0] = 0;
spec->efs_dword[1] = dest_tcp << 16;
spec->efs_dword[2] = dest_ip;
}
extern void
efx_filter_spec_rx_ipv4_udp_full(
__inout efx_filter_spec_t *spec,
__in unsigned int flags,
__in uint32_t src_ip,
__in uint16_t src_udp,
__in uint32_t dest_ip,
__in uint16_t dest_udp)
{
EFSYS_ASSERT3P(spec, !=, NULL);
EFSYS_ASSERT((flags & ~(EFX_FILTER_FLAG_RX_RSS |
EFX_FILTER_FLAG_RX_SCATTER)) == 0);
spec->efs_type = EFX_FILTER_RX_UDP_FULL;
spec->efs_flags = (uint8_t)flags;
spec->efs_dword[0] = src_udp | src_ip << 16;
spec->efs_dword[1] = dest_udp << 16 | src_ip >> 16;
spec->efs_dword[2] = dest_ip;
}
extern void
efx_filter_spec_rx_ipv4_udp_wild(
__inout efx_filter_spec_t *spec,
__in unsigned int flags,
__in uint32_t dest_ip,
__in uint16_t dest_udp)
{
EFSYS_ASSERT3P(spec, !=, NULL);
EFSYS_ASSERT((flags & ~(EFX_FILTER_FLAG_RX_RSS |
EFX_FILTER_FLAG_RX_SCATTER)) == 0);
spec->efs_type = EFX_FILTER_RX_UDP_WILD;
spec->efs_flags = (uint8_t)flags;
spec->efs_dword[0] = dest_udp;
spec->efs_dword[1] = 0;
spec->efs_dword[2] = dest_ip;
}
#if EFSYS_OPT_SIENA
extern void
efx_filter_spec_rx_mac_full(
__inout efx_filter_spec_t *spec,
__in unsigned int flags,
__in uint16_t vlan_id,
__in uint8_t *dest_mac)
{
EFSYS_ASSERT3P(spec, !=, NULL);
EFSYS_ASSERT3P(dest_mac, !=, NULL);
EFSYS_ASSERT((flags & ~(EFX_FILTER_FLAG_RX_RSS |
EFX_FILTER_FLAG_RX_SCATTER |
EFX_FILTER_FLAG_RX_OVERRIDE_IP)) == 0);
spec->efs_type = EFX_FILTER_RX_MAC_FULL;
spec->efs_flags = (uint8_t)flags;
spec->efs_dword[0] = vlan_id;
spec->efs_dword[1] =
dest_mac[2] << 24 |
dest_mac[3] << 16 |
dest_mac[4] << 8 |
dest_mac[5];
spec->efs_dword[2] =
dest_mac[0] << 8 |
dest_mac[1];
}
#endif /* EFSYS_OPT_SIENA */
#if EFSYS_OPT_SIENA
extern void
efx_filter_spec_rx_mac_wild(
__inout efx_filter_spec_t *spec,
__in unsigned int flags,
__in uint8_t *dest_mac)
{
EFSYS_ASSERT3P(spec, !=, NULL);
EFSYS_ASSERT3P(dest_mac, !=, NULL);
EFSYS_ASSERT((flags & ~(EFX_FILTER_FLAG_RX_RSS |
EFX_FILTER_FLAG_RX_SCATTER |
EFX_FILTER_FLAG_RX_OVERRIDE_IP)) == 0);
spec->efs_type = EFX_FILTER_RX_MAC_WILD;
spec->efs_flags = (uint8_t)flags;
spec->efs_dword[0] = 0;
spec->efs_dword[1] =
dest_mac[2] << 24 |
dest_mac[3] << 16 |
dest_mac[4] << 8 |
dest_mac[5];
spec->efs_dword[2] =
dest_mac[0] << 8 |
dest_mac[1];
}
#endif /* EFSYS_OPT_SIENA */
#if EFSYS_OPT_SIENA
extern void
efx_filter_spec_tx_ipv4_tcp_full(
__inout efx_filter_spec_t *spec,
__in uint32_t src_ip,
__in uint16_t src_tcp,
__in uint32_t dest_ip,
__in uint16_t dest_tcp)
{
EFSYS_ASSERT3P(spec, !=, NULL);
spec->efs_type = EFX_FILTER_TX_TCP_FULL;
spec->efs_flags = 0;
spec->efs_dword[0] = src_tcp | src_ip << 16;
spec->efs_dword[1] = dest_tcp << 16 | src_ip >> 16;
spec->efs_dword[2] = dest_ip;
}
#endif /* EFSYS_OPT_SIENA */
#if EFSYS_OPT_SIENA
extern void
efx_filter_spec_tx_ipv4_tcp_wild(
__inout efx_filter_spec_t *spec,
__in uint32_t src_ip,
__in uint16_t src_tcp)
{
EFSYS_ASSERT3P(spec, !=, NULL);
spec->efs_type = EFX_FILTER_TX_TCP_WILD;
spec->efs_flags = 0;
spec->efs_dword[0] = 0;
spec->efs_dword[1] = src_tcp << 16;
spec->efs_dword[2] = src_ip;
}
#endif /* EFSYS_OPT_SIENA */
#if EFSYS_OPT_SIENA
extern void
efx_filter_spec_tx_ipv4_udp_full(
__inout efx_filter_spec_t *spec,
__in uint32_t src_ip,
__in uint16_t src_udp,
__in uint32_t dest_ip,
__in uint16_t dest_udp)
{
EFSYS_ASSERT3P(spec, !=, NULL);
spec->efs_type = EFX_FILTER_TX_UDP_FULL;
spec->efs_flags = 0;
spec->efs_dword[0] = src_udp | src_ip << 16;
spec->efs_dword[1] = dest_udp << 16 | src_ip >> 16;
spec->efs_dword[2] = dest_ip;
}
#endif /* EFSYS_OPT_SIENA */
#if EFSYS_OPT_SIENA
extern void
efx_filter_spec_tx_ipv4_udp_wild(
__inout efx_filter_spec_t *spec,
__in uint32_t src_ip,
__in uint16_t src_udp)
{
EFSYS_ASSERT3P(spec, !=, NULL);
spec->efs_type = EFX_FILTER_TX_UDP_WILD;
spec->efs_flags = 0;
spec->efs_dword[0] = src_udp;
spec->efs_dword[1] = 0;
spec->efs_dword[2] = src_ip;
}
#endif /* EFSYS_OPT_SIENA */
#if EFSYS_OPT_SIENA
extern void
efx_filter_spec_tx_mac_full(
__inout efx_filter_spec_t *spec,
__in uint16_t vlan_id,
__in uint8_t *src_mac)
{
EFSYS_ASSERT3P(spec, !=, NULL);
EFSYS_ASSERT3P(src_mac, !=, NULL);
spec->efs_type = EFX_FILTER_TX_MAC_FULL;
spec->efs_flags = 0;
spec->efs_dword[0] = vlan_id;
spec->efs_dword[1] =
src_mac[2] << 24 |
src_mac[3] << 16 |
src_mac[4] << 8 |
src_mac[5];
spec->efs_dword[2] =
src_mac[0] << 8 |
src_mac[1];
}
#endif /* EFSYS_OPT_SIENA */
#if EFSYS_OPT_SIENA
extern void
efx_filter_spec_tx_mac_wild(
__inout efx_filter_spec_t *spec,
__in uint8_t *src_mac)
{
EFSYS_ASSERT3P(spec, !=, NULL);
EFSYS_ASSERT3P(src_mac, !=, NULL);
spec->efs_type = EFX_FILTER_TX_MAC_WILD;
spec->efs_flags = 0;
spec->efs_dword[0] = 0;
spec->efs_dword[1] =
src_mac[2] << 24 |
src_mac[3] << 16 |
src_mac[4] << 8 |
src_mac[5];
spec->efs_dword[2] =
src_mac[0] << 8 |
src_mac[1];
}
#endif /* EFSYS_OPT_SIENA */
#endif /* EFSYS_OPT_FILTER */
|