1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * RSS and Classifier helpers for Marvell PPv2 Network Controller
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2014 Marvell
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * Marcin Wojtas <mw@semihalf.com>
8*4882a593Smuzhiyun */
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun #include "mvpp2.h"
11*4882a593Smuzhiyun #include "mvpp2_cls.h"
12*4882a593Smuzhiyun #include "mvpp2_prs.h"
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun #define MVPP2_DEF_FLOW(_type, _id, _opts, _ri, _ri_mask) \
15*4882a593Smuzhiyun { \
16*4882a593Smuzhiyun .flow_type = _type, \
17*4882a593Smuzhiyun .flow_id = _id, \
18*4882a593Smuzhiyun .supported_hash_opts = _opts, \
19*4882a593Smuzhiyun .prs_ri = { \
20*4882a593Smuzhiyun .ri = _ri, \
21*4882a593Smuzhiyun .ri_mask = _ri_mask \
22*4882a593Smuzhiyun } \
23*4882a593Smuzhiyun }
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun static const struct mvpp2_cls_flow cls_flows[MVPP2_N_PRS_FLOWS] = {
26*4882a593Smuzhiyun /* TCP over IPv4 flows, Not fragmented, no vlan tag */
27*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_TCP4, MVPP2_FL_IP4_TCP_NF_UNTAG,
28*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_5T,
29*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP4 |
30*4882a593Smuzhiyun MVPP2_PRS_RI_L4_TCP,
31*4882a593Smuzhiyun MVPP2_PRS_IP_MASK | MVPP2_PRS_RI_VLAN_MASK),
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_TCP4, MVPP2_FL_IP4_TCP_NF_UNTAG,
34*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_5T,
35*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP4_OPT |
36*4882a593Smuzhiyun MVPP2_PRS_RI_L4_TCP,
37*4882a593Smuzhiyun MVPP2_PRS_IP_MASK | MVPP2_PRS_RI_VLAN_MASK),
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_TCP4, MVPP2_FL_IP4_TCP_NF_UNTAG,
40*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_5T,
41*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP4_OTHER |
42*4882a593Smuzhiyun MVPP2_PRS_RI_L4_TCP,
43*4882a593Smuzhiyun MVPP2_PRS_IP_MASK | MVPP2_PRS_RI_VLAN_MASK),
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun /* TCP over IPv4 flows, Not fragmented, with vlan tag */
46*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_TCP4, MVPP2_FL_IP4_TCP_NF_TAG,
47*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_5T | MVPP22_CLS_HEK_TAGGED,
48*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP4 | MVPP2_PRS_RI_L4_TCP,
49*4882a593Smuzhiyun MVPP2_PRS_IP_MASK),
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_TCP4, MVPP2_FL_IP4_TCP_NF_TAG,
52*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_5T | MVPP22_CLS_HEK_TAGGED,
53*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP4_OPT | MVPP2_PRS_RI_L4_TCP,
54*4882a593Smuzhiyun MVPP2_PRS_IP_MASK),
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_TCP4, MVPP2_FL_IP4_TCP_NF_TAG,
57*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_5T | MVPP22_CLS_HEK_TAGGED,
58*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP4_OTHER | MVPP2_PRS_RI_L4_TCP,
59*4882a593Smuzhiyun MVPP2_PRS_IP_MASK),
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun /* TCP over IPv4 flows, fragmented, no vlan tag */
62*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_TCP4, MVPP2_FL_IP4_TCP_FRAG_UNTAG,
63*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_2T,
64*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP4 |
65*4882a593Smuzhiyun MVPP2_PRS_RI_L4_TCP,
66*4882a593Smuzhiyun MVPP2_PRS_IP_MASK | MVPP2_PRS_RI_VLAN_MASK),
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_TCP4, MVPP2_FL_IP4_TCP_FRAG_UNTAG,
69*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_2T,
70*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP4_OPT |
71*4882a593Smuzhiyun MVPP2_PRS_RI_L4_TCP,
72*4882a593Smuzhiyun MVPP2_PRS_IP_MASK | MVPP2_PRS_RI_VLAN_MASK),
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_TCP4, MVPP2_FL_IP4_TCP_FRAG_UNTAG,
75*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_2T,
76*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP4_OTHER |
77*4882a593Smuzhiyun MVPP2_PRS_RI_L4_TCP,
78*4882a593Smuzhiyun MVPP2_PRS_IP_MASK | MVPP2_PRS_RI_VLAN_MASK),
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun /* TCP over IPv4 flows, fragmented, with vlan tag */
81*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_TCP4, MVPP2_FL_IP4_TCP_FRAG_TAG,
82*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_2T | MVPP22_CLS_HEK_TAGGED,
83*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP4 | MVPP2_PRS_RI_L4_TCP,
84*4882a593Smuzhiyun MVPP2_PRS_IP_MASK),
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_TCP4, MVPP2_FL_IP4_TCP_FRAG_TAG,
87*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_2T | MVPP22_CLS_HEK_TAGGED,
88*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP4_OPT | MVPP2_PRS_RI_L4_TCP,
89*4882a593Smuzhiyun MVPP2_PRS_IP_MASK),
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_TCP4, MVPP2_FL_IP4_TCP_FRAG_TAG,
92*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_2T | MVPP22_CLS_HEK_TAGGED,
93*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP4_OTHER | MVPP2_PRS_RI_L4_TCP,
94*4882a593Smuzhiyun MVPP2_PRS_IP_MASK),
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun /* UDP over IPv4 flows, Not fragmented, no vlan tag */
97*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_UDP4, MVPP2_FL_IP4_UDP_NF_UNTAG,
98*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_5T,
99*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP4 |
100*4882a593Smuzhiyun MVPP2_PRS_RI_L4_UDP,
101*4882a593Smuzhiyun MVPP2_PRS_IP_MASK | MVPP2_PRS_RI_VLAN_MASK),
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_UDP4, MVPP2_FL_IP4_UDP_NF_UNTAG,
104*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_5T,
105*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP4_OPT |
106*4882a593Smuzhiyun MVPP2_PRS_RI_L4_UDP,
107*4882a593Smuzhiyun MVPP2_PRS_IP_MASK | MVPP2_PRS_RI_VLAN_MASK),
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_UDP4, MVPP2_FL_IP4_UDP_NF_UNTAG,
110*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_5T,
111*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP4_OTHER |
112*4882a593Smuzhiyun MVPP2_PRS_RI_L4_UDP,
113*4882a593Smuzhiyun MVPP2_PRS_IP_MASK | MVPP2_PRS_RI_VLAN_MASK),
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun /* UDP over IPv4 flows, Not fragmented, with vlan tag */
116*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_UDP4, MVPP2_FL_IP4_UDP_NF_TAG,
117*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_5T | MVPP22_CLS_HEK_TAGGED,
118*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP4 | MVPP2_PRS_RI_L4_UDP,
119*4882a593Smuzhiyun MVPP2_PRS_IP_MASK),
120*4882a593Smuzhiyun
121*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_UDP4, MVPP2_FL_IP4_UDP_NF_TAG,
122*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_5T | MVPP22_CLS_HEK_TAGGED,
123*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP4_OPT | MVPP2_PRS_RI_L4_UDP,
124*4882a593Smuzhiyun MVPP2_PRS_IP_MASK),
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_UDP4, MVPP2_FL_IP4_UDP_NF_TAG,
127*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_5T | MVPP22_CLS_HEK_TAGGED,
128*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP4_OTHER | MVPP2_PRS_RI_L4_UDP,
129*4882a593Smuzhiyun MVPP2_PRS_IP_MASK),
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun /* UDP over IPv4 flows, fragmented, no vlan tag */
132*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_UDP4, MVPP2_FL_IP4_UDP_FRAG_UNTAG,
133*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_2T,
134*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP4 |
135*4882a593Smuzhiyun MVPP2_PRS_RI_L4_UDP,
136*4882a593Smuzhiyun MVPP2_PRS_IP_MASK | MVPP2_PRS_RI_VLAN_MASK),
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_UDP4, MVPP2_FL_IP4_UDP_FRAG_UNTAG,
139*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_2T,
140*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP4_OPT |
141*4882a593Smuzhiyun MVPP2_PRS_RI_L4_UDP,
142*4882a593Smuzhiyun MVPP2_PRS_IP_MASK | MVPP2_PRS_RI_VLAN_MASK),
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_UDP4, MVPP2_FL_IP4_UDP_FRAG_UNTAG,
145*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_2T,
146*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP4_OTHER |
147*4882a593Smuzhiyun MVPP2_PRS_RI_L4_UDP,
148*4882a593Smuzhiyun MVPP2_PRS_IP_MASK | MVPP2_PRS_RI_VLAN_MASK),
149*4882a593Smuzhiyun
150*4882a593Smuzhiyun /* UDP over IPv4 flows, fragmented, with vlan tag */
151*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_UDP4, MVPP2_FL_IP4_UDP_FRAG_TAG,
152*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_2T | MVPP22_CLS_HEK_TAGGED,
153*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP4 | MVPP2_PRS_RI_L4_UDP,
154*4882a593Smuzhiyun MVPP2_PRS_IP_MASK),
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_UDP4, MVPP2_FL_IP4_UDP_FRAG_TAG,
157*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_2T | MVPP22_CLS_HEK_TAGGED,
158*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP4_OPT | MVPP2_PRS_RI_L4_UDP,
159*4882a593Smuzhiyun MVPP2_PRS_IP_MASK),
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_UDP4, MVPP2_FL_IP4_UDP_FRAG_TAG,
162*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_2T | MVPP22_CLS_HEK_TAGGED,
163*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP4_OTHER | MVPP2_PRS_RI_L4_UDP,
164*4882a593Smuzhiyun MVPP2_PRS_IP_MASK),
165*4882a593Smuzhiyun
166*4882a593Smuzhiyun /* TCP over IPv6 flows, not fragmented, no vlan tag */
167*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_TCP6, MVPP2_FL_IP6_TCP_NF_UNTAG,
168*4882a593Smuzhiyun MVPP22_CLS_HEK_IP6_5T,
169*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP6 |
170*4882a593Smuzhiyun MVPP2_PRS_RI_L4_TCP,
171*4882a593Smuzhiyun MVPP2_PRS_IP_MASK | MVPP2_PRS_RI_VLAN_MASK),
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_TCP6, MVPP2_FL_IP6_TCP_NF_UNTAG,
174*4882a593Smuzhiyun MVPP22_CLS_HEK_IP6_5T,
175*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP6_EXT |
176*4882a593Smuzhiyun MVPP2_PRS_RI_L4_TCP,
177*4882a593Smuzhiyun MVPP2_PRS_IP_MASK | MVPP2_PRS_RI_VLAN_MASK),
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun /* TCP over IPv6 flows, not fragmented, with vlan tag */
180*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_TCP6, MVPP2_FL_IP6_TCP_NF_TAG,
181*4882a593Smuzhiyun MVPP22_CLS_HEK_IP6_5T | MVPP22_CLS_HEK_TAGGED,
182*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP6 | MVPP2_PRS_RI_L4_TCP,
183*4882a593Smuzhiyun MVPP2_PRS_IP_MASK),
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_TCP6, MVPP2_FL_IP6_TCP_NF_TAG,
186*4882a593Smuzhiyun MVPP22_CLS_HEK_IP6_5T | MVPP22_CLS_HEK_TAGGED,
187*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP6_EXT | MVPP2_PRS_RI_L4_TCP,
188*4882a593Smuzhiyun MVPP2_PRS_IP_MASK),
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun /* TCP over IPv6 flows, fragmented, no vlan tag */
191*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_TCP6, MVPP2_FL_IP6_TCP_FRAG_UNTAG,
192*4882a593Smuzhiyun MVPP22_CLS_HEK_IP6_2T,
193*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP6 |
194*4882a593Smuzhiyun MVPP2_PRS_RI_IP_FRAG_TRUE | MVPP2_PRS_RI_L4_TCP,
195*4882a593Smuzhiyun MVPP2_PRS_IP_MASK | MVPP2_PRS_RI_VLAN_MASK),
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_TCP6, MVPP2_FL_IP6_TCP_FRAG_UNTAG,
198*4882a593Smuzhiyun MVPP22_CLS_HEK_IP6_2T,
199*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP6_EXT |
200*4882a593Smuzhiyun MVPP2_PRS_RI_IP_FRAG_TRUE | MVPP2_PRS_RI_L4_TCP,
201*4882a593Smuzhiyun MVPP2_PRS_IP_MASK | MVPP2_PRS_RI_VLAN_MASK),
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun /* TCP over IPv6 flows, fragmented, with vlan tag */
204*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_TCP6, MVPP2_FL_IP6_TCP_FRAG_TAG,
205*4882a593Smuzhiyun MVPP22_CLS_HEK_IP6_2T | MVPP22_CLS_HEK_TAGGED,
206*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP6 | MVPP2_PRS_RI_IP_FRAG_TRUE |
207*4882a593Smuzhiyun MVPP2_PRS_RI_L4_TCP,
208*4882a593Smuzhiyun MVPP2_PRS_IP_MASK),
209*4882a593Smuzhiyun
210*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_TCP6, MVPP2_FL_IP6_TCP_FRAG_TAG,
211*4882a593Smuzhiyun MVPP22_CLS_HEK_IP6_2T | MVPP22_CLS_HEK_TAGGED,
212*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP6_EXT | MVPP2_PRS_RI_IP_FRAG_TRUE |
213*4882a593Smuzhiyun MVPP2_PRS_RI_L4_TCP,
214*4882a593Smuzhiyun MVPP2_PRS_IP_MASK),
215*4882a593Smuzhiyun
216*4882a593Smuzhiyun /* UDP over IPv6 flows, not fragmented, no vlan tag */
217*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_UDP6, MVPP2_FL_IP6_UDP_NF_UNTAG,
218*4882a593Smuzhiyun MVPP22_CLS_HEK_IP6_5T,
219*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP6 |
220*4882a593Smuzhiyun MVPP2_PRS_RI_L4_UDP,
221*4882a593Smuzhiyun MVPP2_PRS_IP_MASK | MVPP2_PRS_RI_VLAN_MASK),
222*4882a593Smuzhiyun
223*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_UDP6, MVPP2_FL_IP6_UDP_NF_UNTAG,
224*4882a593Smuzhiyun MVPP22_CLS_HEK_IP6_5T,
225*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP6_EXT |
226*4882a593Smuzhiyun MVPP2_PRS_RI_L4_UDP,
227*4882a593Smuzhiyun MVPP2_PRS_IP_MASK | MVPP2_PRS_RI_VLAN_MASK),
228*4882a593Smuzhiyun
229*4882a593Smuzhiyun /* UDP over IPv6 flows, not fragmented, with vlan tag */
230*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_UDP6, MVPP2_FL_IP6_UDP_NF_TAG,
231*4882a593Smuzhiyun MVPP22_CLS_HEK_IP6_5T | MVPP22_CLS_HEK_TAGGED,
232*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP6 | MVPP2_PRS_RI_L4_UDP,
233*4882a593Smuzhiyun MVPP2_PRS_IP_MASK),
234*4882a593Smuzhiyun
235*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_UDP6, MVPP2_FL_IP6_UDP_NF_TAG,
236*4882a593Smuzhiyun MVPP22_CLS_HEK_IP6_5T | MVPP22_CLS_HEK_TAGGED,
237*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP6_EXT | MVPP2_PRS_RI_L4_UDP,
238*4882a593Smuzhiyun MVPP2_PRS_IP_MASK),
239*4882a593Smuzhiyun
240*4882a593Smuzhiyun /* UDP over IPv6 flows, fragmented, no vlan tag */
241*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_UDP6, MVPP2_FL_IP6_UDP_FRAG_UNTAG,
242*4882a593Smuzhiyun MVPP22_CLS_HEK_IP6_2T,
243*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP6 |
244*4882a593Smuzhiyun MVPP2_PRS_RI_IP_FRAG_TRUE | MVPP2_PRS_RI_L4_UDP,
245*4882a593Smuzhiyun MVPP2_PRS_IP_MASK | MVPP2_PRS_RI_VLAN_MASK),
246*4882a593Smuzhiyun
247*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_UDP6, MVPP2_FL_IP6_UDP_FRAG_UNTAG,
248*4882a593Smuzhiyun MVPP22_CLS_HEK_IP6_2T,
249*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP6_EXT |
250*4882a593Smuzhiyun MVPP2_PRS_RI_IP_FRAG_TRUE | MVPP2_PRS_RI_L4_UDP,
251*4882a593Smuzhiyun MVPP2_PRS_IP_MASK | MVPP2_PRS_RI_VLAN_MASK),
252*4882a593Smuzhiyun
253*4882a593Smuzhiyun /* UDP over IPv6 flows, fragmented, with vlan tag */
254*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_UDP6, MVPP2_FL_IP6_UDP_FRAG_TAG,
255*4882a593Smuzhiyun MVPP22_CLS_HEK_IP6_2T | MVPP22_CLS_HEK_TAGGED,
256*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP6 | MVPP2_PRS_RI_IP_FRAG_TRUE |
257*4882a593Smuzhiyun MVPP2_PRS_RI_L4_UDP,
258*4882a593Smuzhiyun MVPP2_PRS_IP_MASK),
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_UDP6, MVPP2_FL_IP6_UDP_FRAG_TAG,
261*4882a593Smuzhiyun MVPP22_CLS_HEK_IP6_2T | MVPP22_CLS_HEK_TAGGED,
262*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP6_EXT | MVPP2_PRS_RI_IP_FRAG_TRUE |
263*4882a593Smuzhiyun MVPP2_PRS_RI_L4_UDP,
264*4882a593Smuzhiyun MVPP2_PRS_IP_MASK),
265*4882a593Smuzhiyun
266*4882a593Smuzhiyun /* IPv4 flows, no vlan tag */
267*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_IP4, MVPP2_FL_IP4_UNTAG,
268*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_2T,
269*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP4,
270*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_MASK | MVPP2_PRS_RI_L3_PROTO_MASK),
271*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_IP4, MVPP2_FL_IP4_UNTAG,
272*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_2T,
273*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP4_OPT,
274*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_MASK | MVPP2_PRS_RI_L3_PROTO_MASK),
275*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_IP4, MVPP2_FL_IP4_UNTAG,
276*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_2T,
277*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP4_OTHER,
278*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_MASK | MVPP2_PRS_RI_L3_PROTO_MASK),
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun /* IPv4 flows, with vlan tag */
281*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_IP4, MVPP2_FL_IP4_TAG,
282*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_2T | MVPP22_CLS_HEK_TAGGED,
283*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP4,
284*4882a593Smuzhiyun MVPP2_PRS_RI_L3_PROTO_MASK),
285*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_IP4, MVPP2_FL_IP4_TAG,
286*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_2T | MVPP22_CLS_HEK_TAGGED,
287*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP4_OPT,
288*4882a593Smuzhiyun MVPP2_PRS_RI_L3_PROTO_MASK),
289*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_IP4, MVPP2_FL_IP4_TAG,
290*4882a593Smuzhiyun MVPP22_CLS_HEK_IP4_2T | MVPP22_CLS_HEK_TAGGED,
291*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP4_OTHER,
292*4882a593Smuzhiyun MVPP2_PRS_RI_L3_PROTO_MASK),
293*4882a593Smuzhiyun
294*4882a593Smuzhiyun /* IPv6 flows, no vlan tag */
295*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_IP6, MVPP2_FL_IP6_UNTAG,
296*4882a593Smuzhiyun MVPP22_CLS_HEK_IP6_2T,
297*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP6,
298*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_MASK | MVPP2_PRS_RI_L3_PROTO_MASK),
299*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_IP6, MVPP2_FL_IP6_UNTAG,
300*4882a593Smuzhiyun MVPP22_CLS_HEK_IP6_2T,
301*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE | MVPP2_PRS_RI_L3_IP6,
302*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_MASK | MVPP2_PRS_RI_L3_PROTO_MASK),
303*4882a593Smuzhiyun
304*4882a593Smuzhiyun /* IPv6 flows, with vlan tag */
305*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_IP6, MVPP2_FL_IP6_TAG,
306*4882a593Smuzhiyun MVPP22_CLS_HEK_IP6_2T | MVPP22_CLS_HEK_TAGGED,
307*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP6,
308*4882a593Smuzhiyun MVPP2_PRS_RI_L3_PROTO_MASK),
309*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_IP6, MVPP2_FL_IP6_TAG,
310*4882a593Smuzhiyun MVPP22_CLS_HEK_IP6_2T | MVPP22_CLS_HEK_TAGGED,
311*4882a593Smuzhiyun MVPP2_PRS_RI_L3_IP6,
312*4882a593Smuzhiyun MVPP2_PRS_RI_L3_PROTO_MASK),
313*4882a593Smuzhiyun
314*4882a593Smuzhiyun /* Non IP flow, no vlan tag */
315*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_ETHERNET, MVPP2_FL_NON_IP_UNTAG,
316*4882a593Smuzhiyun 0,
317*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_NONE,
318*4882a593Smuzhiyun MVPP2_PRS_RI_VLAN_MASK),
319*4882a593Smuzhiyun /* Non IP flow, with vlan tag */
320*4882a593Smuzhiyun MVPP2_DEF_FLOW(MVPP22_FLOW_ETHERNET, MVPP2_FL_NON_IP_TAG,
321*4882a593Smuzhiyun MVPP22_CLS_HEK_OPT_VLAN,
322*4882a593Smuzhiyun 0, 0),
323*4882a593Smuzhiyun };
324*4882a593Smuzhiyun
mvpp2_cls_flow_hits(struct mvpp2 * priv,int index)325*4882a593Smuzhiyun u32 mvpp2_cls_flow_hits(struct mvpp2 *priv, int index)
326*4882a593Smuzhiyun {
327*4882a593Smuzhiyun mvpp2_write(priv, MVPP2_CTRS_IDX, index);
328*4882a593Smuzhiyun
329*4882a593Smuzhiyun return mvpp2_read(priv, MVPP2_CLS_FLOW_TBL_HIT_CTR);
330*4882a593Smuzhiyun }
331*4882a593Smuzhiyun
mvpp2_cls_flow_read(struct mvpp2 * priv,int index,struct mvpp2_cls_flow_entry * fe)332*4882a593Smuzhiyun void mvpp2_cls_flow_read(struct mvpp2 *priv, int index,
333*4882a593Smuzhiyun struct mvpp2_cls_flow_entry *fe)
334*4882a593Smuzhiyun {
335*4882a593Smuzhiyun fe->index = index;
336*4882a593Smuzhiyun mvpp2_write(priv, MVPP2_CLS_FLOW_INDEX_REG, index);
337*4882a593Smuzhiyun fe->data[0] = mvpp2_read(priv, MVPP2_CLS_FLOW_TBL0_REG);
338*4882a593Smuzhiyun fe->data[1] = mvpp2_read(priv, MVPP2_CLS_FLOW_TBL1_REG);
339*4882a593Smuzhiyun fe->data[2] = mvpp2_read(priv, MVPP2_CLS_FLOW_TBL2_REG);
340*4882a593Smuzhiyun }
341*4882a593Smuzhiyun
342*4882a593Smuzhiyun /* Update classification flow table registers */
mvpp2_cls_flow_write(struct mvpp2 * priv,struct mvpp2_cls_flow_entry * fe)343*4882a593Smuzhiyun static void mvpp2_cls_flow_write(struct mvpp2 *priv,
344*4882a593Smuzhiyun struct mvpp2_cls_flow_entry *fe)
345*4882a593Smuzhiyun {
346*4882a593Smuzhiyun mvpp2_write(priv, MVPP2_CLS_FLOW_INDEX_REG, fe->index);
347*4882a593Smuzhiyun mvpp2_write(priv, MVPP2_CLS_FLOW_TBL0_REG, fe->data[0]);
348*4882a593Smuzhiyun mvpp2_write(priv, MVPP2_CLS_FLOW_TBL1_REG, fe->data[1]);
349*4882a593Smuzhiyun mvpp2_write(priv, MVPP2_CLS_FLOW_TBL2_REG, fe->data[2]);
350*4882a593Smuzhiyun }
351*4882a593Smuzhiyun
mvpp2_cls_lookup_hits(struct mvpp2 * priv,int index)352*4882a593Smuzhiyun u32 mvpp2_cls_lookup_hits(struct mvpp2 *priv, int index)
353*4882a593Smuzhiyun {
354*4882a593Smuzhiyun mvpp2_write(priv, MVPP2_CTRS_IDX, index);
355*4882a593Smuzhiyun
356*4882a593Smuzhiyun return mvpp2_read(priv, MVPP2_CLS_DEC_TBL_HIT_CTR);
357*4882a593Smuzhiyun }
358*4882a593Smuzhiyun
mvpp2_cls_lookup_read(struct mvpp2 * priv,int lkpid,int way,struct mvpp2_cls_lookup_entry * le)359*4882a593Smuzhiyun void mvpp2_cls_lookup_read(struct mvpp2 *priv, int lkpid, int way,
360*4882a593Smuzhiyun struct mvpp2_cls_lookup_entry *le)
361*4882a593Smuzhiyun {
362*4882a593Smuzhiyun u32 val;
363*4882a593Smuzhiyun
364*4882a593Smuzhiyun val = (way << MVPP2_CLS_LKP_INDEX_WAY_OFFS) | lkpid;
365*4882a593Smuzhiyun mvpp2_write(priv, MVPP2_CLS_LKP_INDEX_REG, val);
366*4882a593Smuzhiyun le->way = way;
367*4882a593Smuzhiyun le->lkpid = lkpid;
368*4882a593Smuzhiyun le->data = mvpp2_read(priv, MVPP2_CLS_LKP_TBL_REG);
369*4882a593Smuzhiyun }
370*4882a593Smuzhiyun
371*4882a593Smuzhiyun /* Update classification lookup table register */
mvpp2_cls_lookup_write(struct mvpp2 * priv,struct mvpp2_cls_lookup_entry * le)372*4882a593Smuzhiyun static void mvpp2_cls_lookup_write(struct mvpp2 *priv,
373*4882a593Smuzhiyun struct mvpp2_cls_lookup_entry *le)
374*4882a593Smuzhiyun {
375*4882a593Smuzhiyun u32 val;
376*4882a593Smuzhiyun
377*4882a593Smuzhiyun val = (le->way << MVPP2_CLS_LKP_INDEX_WAY_OFFS) | le->lkpid;
378*4882a593Smuzhiyun mvpp2_write(priv, MVPP2_CLS_LKP_INDEX_REG, val);
379*4882a593Smuzhiyun mvpp2_write(priv, MVPP2_CLS_LKP_TBL_REG, le->data);
380*4882a593Smuzhiyun }
381*4882a593Smuzhiyun
382*4882a593Smuzhiyun /* Operations on flow entry */
mvpp2_cls_flow_hek_num_get(struct mvpp2_cls_flow_entry * fe)383*4882a593Smuzhiyun static int mvpp2_cls_flow_hek_num_get(struct mvpp2_cls_flow_entry *fe)
384*4882a593Smuzhiyun {
385*4882a593Smuzhiyun return fe->data[1] & MVPP2_CLS_FLOW_TBL1_N_FIELDS_MASK;
386*4882a593Smuzhiyun }
387*4882a593Smuzhiyun
mvpp2_cls_flow_hek_num_set(struct mvpp2_cls_flow_entry * fe,int num_of_fields)388*4882a593Smuzhiyun static void mvpp2_cls_flow_hek_num_set(struct mvpp2_cls_flow_entry *fe,
389*4882a593Smuzhiyun int num_of_fields)
390*4882a593Smuzhiyun {
391*4882a593Smuzhiyun fe->data[1] &= ~MVPP2_CLS_FLOW_TBL1_N_FIELDS_MASK;
392*4882a593Smuzhiyun fe->data[1] |= MVPP2_CLS_FLOW_TBL1_N_FIELDS(num_of_fields);
393*4882a593Smuzhiyun }
394*4882a593Smuzhiyun
mvpp2_cls_flow_hek_get(struct mvpp2_cls_flow_entry * fe,int field_index)395*4882a593Smuzhiyun static int mvpp2_cls_flow_hek_get(struct mvpp2_cls_flow_entry *fe,
396*4882a593Smuzhiyun int field_index)
397*4882a593Smuzhiyun {
398*4882a593Smuzhiyun return (fe->data[2] >> MVPP2_CLS_FLOW_TBL2_FLD_OFFS(field_index)) &
399*4882a593Smuzhiyun MVPP2_CLS_FLOW_TBL2_FLD_MASK;
400*4882a593Smuzhiyun }
401*4882a593Smuzhiyun
mvpp2_cls_flow_hek_set(struct mvpp2_cls_flow_entry * fe,int field_index,int field_id)402*4882a593Smuzhiyun static void mvpp2_cls_flow_hek_set(struct mvpp2_cls_flow_entry *fe,
403*4882a593Smuzhiyun int field_index, int field_id)
404*4882a593Smuzhiyun {
405*4882a593Smuzhiyun fe->data[2] &= ~MVPP2_CLS_FLOW_TBL2_FLD(field_index,
406*4882a593Smuzhiyun MVPP2_CLS_FLOW_TBL2_FLD_MASK);
407*4882a593Smuzhiyun fe->data[2] |= MVPP2_CLS_FLOW_TBL2_FLD(field_index, field_id);
408*4882a593Smuzhiyun }
409*4882a593Smuzhiyun
mvpp2_cls_flow_eng_set(struct mvpp2_cls_flow_entry * fe,int engine)410*4882a593Smuzhiyun static void mvpp2_cls_flow_eng_set(struct mvpp2_cls_flow_entry *fe,
411*4882a593Smuzhiyun int engine)
412*4882a593Smuzhiyun {
413*4882a593Smuzhiyun fe->data[0] &= ~MVPP2_CLS_FLOW_TBL0_ENG(MVPP2_CLS_FLOW_TBL0_ENG_MASK);
414*4882a593Smuzhiyun fe->data[0] |= MVPP2_CLS_FLOW_TBL0_ENG(engine);
415*4882a593Smuzhiyun }
416*4882a593Smuzhiyun
mvpp2_cls_flow_eng_get(struct mvpp2_cls_flow_entry * fe)417*4882a593Smuzhiyun int mvpp2_cls_flow_eng_get(struct mvpp2_cls_flow_entry *fe)
418*4882a593Smuzhiyun {
419*4882a593Smuzhiyun return (fe->data[0] >> MVPP2_CLS_FLOW_TBL0_OFFS) &
420*4882a593Smuzhiyun MVPP2_CLS_FLOW_TBL0_ENG_MASK;
421*4882a593Smuzhiyun }
422*4882a593Smuzhiyun
mvpp2_cls_flow_port_id_sel(struct mvpp2_cls_flow_entry * fe,bool from_packet)423*4882a593Smuzhiyun static void mvpp2_cls_flow_port_id_sel(struct mvpp2_cls_flow_entry *fe,
424*4882a593Smuzhiyun bool from_packet)
425*4882a593Smuzhiyun {
426*4882a593Smuzhiyun if (from_packet)
427*4882a593Smuzhiyun fe->data[0] |= MVPP2_CLS_FLOW_TBL0_PORT_ID_SEL;
428*4882a593Smuzhiyun else
429*4882a593Smuzhiyun fe->data[0] &= ~MVPP2_CLS_FLOW_TBL0_PORT_ID_SEL;
430*4882a593Smuzhiyun }
431*4882a593Smuzhiyun
mvpp2_cls_flow_last_set(struct mvpp2_cls_flow_entry * fe,bool is_last)432*4882a593Smuzhiyun static void mvpp2_cls_flow_last_set(struct mvpp2_cls_flow_entry *fe,
433*4882a593Smuzhiyun bool is_last)
434*4882a593Smuzhiyun {
435*4882a593Smuzhiyun fe->data[0] &= ~MVPP2_CLS_FLOW_TBL0_LAST;
436*4882a593Smuzhiyun fe->data[0] |= !!is_last;
437*4882a593Smuzhiyun }
438*4882a593Smuzhiyun
mvpp2_cls_flow_pri_set(struct mvpp2_cls_flow_entry * fe,int prio)439*4882a593Smuzhiyun static void mvpp2_cls_flow_pri_set(struct mvpp2_cls_flow_entry *fe, int prio)
440*4882a593Smuzhiyun {
441*4882a593Smuzhiyun fe->data[1] &= ~MVPP2_CLS_FLOW_TBL1_PRIO(MVPP2_CLS_FLOW_TBL1_PRIO_MASK);
442*4882a593Smuzhiyun fe->data[1] |= MVPP2_CLS_FLOW_TBL1_PRIO(prio);
443*4882a593Smuzhiyun }
444*4882a593Smuzhiyun
mvpp2_cls_flow_port_add(struct mvpp2_cls_flow_entry * fe,u32 port)445*4882a593Smuzhiyun static void mvpp2_cls_flow_port_add(struct mvpp2_cls_flow_entry *fe,
446*4882a593Smuzhiyun u32 port)
447*4882a593Smuzhiyun {
448*4882a593Smuzhiyun fe->data[0] |= MVPP2_CLS_FLOW_TBL0_PORT_ID(port);
449*4882a593Smuzhiyun }
450*4882a593Smuzhiyun
mvpp2_cls_flow_port_remove(struct mvpp2_cls_flow_entry * fe,u32 port)451*4882a593Smuzhiyun static void mvpp2_cls_flow_port_remove(struct mvpp2_cls_flow_entry *fe,
452*4882a593Smuzhiyun u32 port)
453*4882a593Smuzhiyun {
454*4882a593Smuzhiyun fe->data[0] &= ~MVPP2_CLS_FLOW_TBL0_PORT_ID(port);
455*4882a593Smuzhiyun }
456*4882a593Smuzhiyun
mvpp2_cls_flow_lu_type_set(struct mvpp2_cls_flow_entry * fe,u8 lu_type)457*4882a593Smuzhiyun static void mvpp2_cls_flow_lu_type_set(struct mvpp2_cls_flow_entry *fe,
458*4882a593Smuzhiyun u8 lu_type)
459*4882a593Smuzhiyun {
460*4882a593Smuzhiyun fe->data[1] &= ~MVPP2_CLS_FLOW_TBL1_LU_TYPE(MVPP2_CLS_LU_TYPE_MASK);
461*4882a593Smuzhiyun fe->data[1] |= MVPP2_CLS_FLOW_TBL1_LU_TYPE(lu_type);
462*4882a593Smuzhiyun }
463*4882a593Smuzhiyun
464*4882a593Smuzhiyun /* Initialize the parser entry for the given flow */
mvpp2_cls_flow_prs_init(struct mvpp2 * priv,const struct mvpp2_cls_flow * flow)465*4882a593Smuzhiyun static void mvpp2_cls_flow_prs_init(struct mvpp2 *priv,
466*4882a593Smuzhiyun const struct mvpp2_cls_flow *flow)
467*4882a593Smuzhiyun {
468*4882a593Smuzhiyun mvpp2_prs_add_flow(priv, flow->flow_id, flow->prs_ri.ri,
469*4882a593Smuzhiyun flow->prs_ri.ri_mask);
470*4882a593Smuzhiyun }
471*4882a593Smuzhiyun
472*4882a593Smuzhiyun /* Initialize the Lookup Id table entry for the given flow */
mvpp2_cls_flow_lkp_init(struct mvpp2 * priv,const struct mvpp2_cls_flow * flow)473*4882a593Smuzhiyun static void mvpp2_cls_flow_lkp_init(struct mvpp2 *priv,
474*4882a593Smuzhiyun const struct mvpp2_cls_flow *flow)
475*4882a593Smuzhiyun {
476*4882a593Smuzhiyun struct mvpp2_cls_lookup_entry le;
477*4882a593Smuzhiyun
478*4882a593Smuzhiyun le.way = 0;
479*4882a593Smuzhiyun le.lkpid = flow->flow_id;
480*4882a593Smuzhiyun
481*4882a593Smuzhiyun /* The default RxQ for this port is set in the C2 lookup */
482*4882a593Smuzhiyun le.data = 0;
483*4882a593Smuzhiyun
484*4882a593Smuzhiyun /* We point on the first lookup in the sequence for the flow, that is
485*4882a593Smuzhiyun * the C2 lookup.
486*4882a593Smuzhiyun */
487*4882a593Smuzhiyun le.data |= MVPP2_CLS_LKP_FLOW_PTR(MVPP2_CLS_FLT_FIRST(flow->flow_id));
488*4882a593Smuzhiyun
489*4882a593Smuzhiyun /* CLS is always enabled, RSS is enabled/disabled in C2 lookup */
490*4882a593Smuzhiyun le.data |= MVPP2_CLS_LKP_TBL_LOOKUP_EN_MASK;
491*4882a593Smuzhiyun
492*4882a593Smuzhiyun mvpp2_cls_lookup_write(priv, &le);
493*4882a593Smuzhiyun }
494*4882a593Smuzhiyun
mvpp2_cls_c2_write(struct mvpp2 * priv,struct mvpp2_cls_c2_entry * c2)495*4882a593Smuzhiyun static void mvpp2_cls_c2_write(struct mvpp2 *priv,
496*4882a593Smuzhiyun struct mvpp2_cls_c2_entry *c2)
497*4882a593Smuzhiyun {
498*4882a593Smuzhiyun u32 val;
499*4882a593Smuzhiyun mvpp2_write(priv, MVPP22_CLS_C2_TCAM_IDX, c2->index);
500*4882a593Smuzhiyun
501*4882a593Smuzhiyun val = mvpp2_read(priv, MVPP22_CLS_C2_TCAM_INV);
502*4882a593Smuzhiyun if (c2->valid)
503*4882a593Smuzhiyun val &= ~MVPP22_CLS_C2_TCAM_INV_BIT;
504*4882a593Smuzhiyun else
505*4882a593Smuzhiyun val |= MVPP22_CLS_C2_TCAM_INV_BIT;
506*4882a593Smuzhiyun mvpp2_write(priv, MVPP22_CLS_C2_TCAM_INV, val);
507*4882a593Smuzhiyun
508*4882a593Smuzhiyun mvpp2_write(priv, MVPP22_CLS_C2_ACT, c2->act);
509*4882a593Smuzhiyun
510*4882a593Smuzhiyun mvpp2_write(priv, MVPP22_CLS_C2_ATTR0, c2->attr[0]);
511*4882a593Smuzhiyun mvpp2_write(priv, MVPP22_CLS_C2_ATTR1, c2->attr[1]);
512*4882a593Smuzhiyun mvpp2_write(priv, MVPP22_CLS_C2_ATTR2, c2->attr[2]);
513*4882a593Smuzhiyun mvpp2_write(priv, MVPP22_CLS_C2_ATTR3, c2->attr[3]);
514*4882a593Smuzhiyun
515*4882a593Smuzhiyun mvpp2_write(priv, MVPP22_CLS_C2_TCAM_DATA0, c2->tcam[0]);
516*4882a593Smuzhiyun mvpp2_write(priv, MVPP22_CLS_C2_TCAM_DATA1, c2->tcam[1]);
517*4882a593Smuzhiyun mvpp2_write(priv, MVPP22_CLS_C2_TCAM_DATA2, c2->tcam[2]);
518*4882a593Smuzhiyun mvpp2_write(priv, MVPP22_CLS_C2_TCAM_DATA3, c2->tcam[3]);
519*4882a593Smuzhiyun /* Writing TCAM_DATA4 flushes writes to TCAM_DATA0-4 and INV to HW */
520*4882a593Smuzhiyun mvpp2_write(priv, MVPP22_CLS_C2_TCAM_DATA4, c2->tcam[4]);
521*4882a593Smuzhiyun }
522*4882a593Smuzhiyun
mvpp2_cls_c2_read(struct mvpp2 * priv,int index,struct mvpp2_cls_c2_entry * c2)523*4882a593Smuzhiyun void mvpp2_cls_c2_read(struct mvpp2 *priv, int index,
524*4882a593Smuzhiyun struct mvpp2_cls_c2_entry *c2)
525*4882a593Smuzhiyun {
526*4882a593Smuzhiyun u32 val;
527*4882a593Smuzhiyun mvpp2_write(priv, MVPP22_CLS_C2_TCAM_IDX, index);
528*4882a593Smuzhiyun
529*4882a593Smuzhiyun c2->index = index;
530*4882a593Smuzhiyun
531*4882a593Smuzhiyun c2->tcam[0] = mvpp2_read(priv, MVPP22_CLS_C2_TCAM_DATA0);
532*4882a593Smuzhiyun c2->tcam[1] = mvpp2_read(priv, MVPP22_CLS_C2_TCAM_DATA1);
533*4882a593Smuzhiyun c2->tcam[2] = mvpp2_read(priv, MVPP22_CLS_C2_TCAM_DATA2);
534*4882a593Smuzhiyun c2->tcam[3] = mvpp2_read(priv, MVPP22_CLS_C2_TCAM_DATA3);
535*4882a593Smuzhiyun c2->tcam[4] = mvpp2_read(priv, MVPP22_CLS_C2_TCAM_DATA4);
536*4882a593Smuzhiyun
537*4882a593Smuzhiyun c2->act = mvpp2_read(priv, MVPP22_CLS_C2_ACT);
538*4882a593Smuzhiyun
539*4882a593Smuzhiyun c2->attr[0] = mvpp2_read(priv, MVPP22_CLS_C2_ATTR0);
540*4882a593Smuzhiyun c2->attr[1] = mvpp2_read(priv, MVPP22_CLS_C2_ATTR1);
541*4882a593Smuzhiyun c2->attr[2] = mvpp2_read(priv, MVPP22_CLS_C2_ATTR2);
542*4882a593Smuzhiyun c2->attr[3] = mvpp2_read(priv, MVPP22_CLS_C2_ATTR3);
543*4882a593Smuzhiyun
544*4882a593Smuzhiyun val = mvpp2_read(priv, MVPP22_CLS_C2_TCAM_INV);
545*4882a593Smuzhiyun c2->valid = !(val & MVPP22_CLS_C2_TCAM_INV_BIT);
546*4882a593Smuzhiyun }
547*4882a593Smuzhiyun
mvpp2_cls_ethtool_flow_to_type(int flow_type)548*4882a593Smuzhiyun static int mvpp2_cls_ethtool_flow_to_type(int flow_type)
549*4882a593Smuzhiyun {
550*4882a593Smuzhiyun switch (flow_type & ~(FLOW_EXT | FLOW_MAC_EXT | FLOW_RSS)) {
551*4882a593Smuzhiyun case ETHER_FLOW:
552*4882a593Smuzhiyun return MVPP22_FLOW_ETHERNET;
553*4882a593Smuzhiyun case TCP_V4_FLOW:
554*4882a593Smuzhiyun return MVPP22_FLOW_TCP4;
555*4882a593Smuzhiyun case TCP_V6_FLOW:
556*4882a593Smuzhiyun return MVPP22_FLOW_TCP6;
557*4882a593Smuzhiyun case UDP_V4_FLOW:
558*4882a593Smuzhiyun return MVPP22_FLOW_UDP4;
559*4882a593Smuzhiyun case UDP_V6_FLOW:
560*4882a593Smuzhiyun return MVPP22_FLOW_UDP6;
561*4882a593Smuzhiyun case IPV4_FLOW:
562*4882a593Smuzhiyun return MVPP22_FLOW_IP4;
563*4882a593Smuzhiyun case IPV6_FLOW:
564*4882a593Smuzhiyun return MVPP22_FLOW_IP6;
565*4882a593Smuzhiyun default:
566*4882a593Smuzhiyun return -EOPNOTSUPP;
567*4882a593Smuzhiyun }
568*4882a593Smuzhiyun }
569*4882a593Smuzhiyun
mvpp2_cls_c2_port_flow_index(struct mvpp2_port * port,int loc)570*4882a593Smuzhiyun static int mvpp2_cls_c2_port_flow_index(struct mvpp2_port *port, int loc)
571*4882a593Smuzhiyun {
572*4882a593Smuzhiyun return MVPP22_CLS_C2_RFS_LOC(port->id, loc);
573*4882a593Smuzhiyun }
574*4882a593Smuzhiyun
575*4882a593Smuzhiyun /* Initialize the flow table entries for the given flow */
mvpp2_cls_flow_init(struct mvpp2 * priv,const struct mvpp2_cls_flow * flow)576*4882a593Smuzhiyun static void mvpp2_cls_flow_init(struct mvpp2 *priv,
577*4882a593Smuzhiyun const struct mvpp2_cls_flow *flow)
578*4882a593Smuzhiyun {
579*4882a593Smuzhiyun struct mvpp2_cls_flow_entry fe;
580*4882a593Smuzhiyun int i, pri = 0;
581*4882a593Smuzhiyun
582*4882a593Smuzhiyun /* Assign default values to all entries in the flow */
583*4882a593Smuzhiyun for (i = MVPP2_CLS_FLT_FIRST(flow->flow_id);
584*4882a593Smuzhiyun i <= MVPP2_CLS_FLT_LAST(flow->flow_id); i++) {
585*4882a593Smuzhiyun memset(&fe, 0, sizeof(fe));
586*4882a593Smuzhiyun fe.index = i;
587*4882a593Smuzhiyun mvpp2_cls_flow_pri_set(&fe, pri++);
588*4882a593Smuzhiyun
589*4882a593Smuzhiyun if (i == MVPP2_CLS_FLT_LAST(flow->flow_id))
590*4882a593Smuzhiyun mvpp2_cls_flow_last_set(&fe, 1);
591*4882a593Smuzhiyun
592*4882a593Smuzhiyun mvpp2_cls_flow_write(priv, &fe);
593*4882a593Smuzhiyun }
594*4882a593Smuzhiyun
595*4882a593Smuzhiyun /* RSS config C2 lookup */
596*4882a593Smuzhiyun mvpp2_cls_flow_read(priv, MVPP2_CLS_FLT_C2_RSS_ENTRY(flow->flow_id),
597*4882a593Smuzhiyun &fe);
598*4882a593Smuzhiyun
599*4882a593Smuzhiyun mvpp2_cls_flow_eng_set(&fe, MVPP22_CLS_ENGINE_C2);
600*4882a593Smuzhiyun mvpp2_cls_flow_port_id_sel(&fe, true);
601*4882a593Smuzhiyun mvpp2_cls_flow_lu_type_set(&fe, MVPP22_CLS_LU_TYPE_ALL);
602*4882a593Smuzhiyun
603*4882a593Smuzhiyun /* Add all ports */
604*4882a593Smuzhiyun for (i = 0; i < MVPP2_MAX_PORTS; i++)
605*4882a593Smuzhiyun mvpp2_cls_flow_port_add(&fe, BIT(i));
606*4882a593Smuzhiyun
607*4882a593Smuzhiyun mvpp2_cls_flow_write(priv, &fe);
608*4882a593Smuzhiyun
609*4882a593Smuzhiyun /* C3Hx lookups */
610*4882a593Smuzhiyun for (i = 0; i < MVPP2_MAX_PORTS; i++) {
611*4882a593Smuzhiyun mvpp2_cls_flow_read(priv,
612*4882a593Smuzhiyun MVPP2_CLS_FLT_HASH_ENTRY(i, flow->flow_id),
613*4882a593Smuzhiyun &fe);
614*4882a593Smuzhiyun
615*4882a593Smuzhiyun /* Set a default engine. Will be overwritten when setting the
616*4882a593Smuzhiyun * real HEK parameters
617*4882a593Smuzhiyun */
618*4882a593Smuzhiyun mvpp2_cls_flow_eng_set(&fe, MVPP22_CLS_ENGINE_C3HA);
619*4882a593Smuzhiyun mvpp2_cls_flow_port_id_sel(&fe, true);
620*4882a593Smuzhiyun mvpp2_cls_flow_port_add(&fe, BIT(i));
621*4882a593Smuzhiyun
622*4882a593Smuzhiyun mvpp2_cls_flow_write(priv, &fe);
623*4882a593Smuzhiyun }
624*4882a593Smuzhiyun }
625*4882a593Smuzhiyun
626*4882a593Smuzhiyun /* Adds a field to the Header Extracted Key generation parameters*/
mvpp2_flow_add_hek_field(struct mvpp2_cls_flow_entry * fe,u32 field_id)627*4882a593Smuzhiyun static int mvpp2_flow_add_hek_field(struct mvpp2_cls_flow_entry *fe,
628*4882a593Smuzhiyun u32 field_id)
629*4882a593Smuzhiyun {
630*4882a593Smuzhiyun int nb_fields = mvpp2_cls_flow_hek_num_get(fe);
631*4882a593Smuzhiyun
632*4882a593Smuzhiyun if (nb_fields == MVPP2_FLOW_N_FIELDS)
633*4882a593Smuzhiyun return -EINVAL;
634*4882a593Smuzhiyun
635*4882a593Smuzhiyun mvpp2_cls_flow_hek_set(fe, nb_fields, field_id);
636*4882a593Smuzhiyun
637*4882a593Smuzhiyun mvpp2_cls_flow_hek_num_set(fe, nb_fields + 1);
638*4882a593Smuzhiyun
639*4882a593Smuzhiyun return 0;
640*4882a593Smuzhiyun }
641*4882a593Smuzhiyun
mvpp2_flow_set_hek_fields(struct mvpp2_cls_flow_entry * fe,unsigned long hash_opts)642*4882a593Smuzhiyun static int mvpp2_flow_set_hek_fields(struct mvpp2_cls_flow_entry *fe,
643*4882a593Smuzhiyun unsigned long hash_opts)
644*4882a593Smuzhiyun {
645*4882a593Smuzhiyun u32 field_id;
646*4882a593Smuzhiyun int i;
647*4882a593Smuzhiyun
648*4882a593Smuzhiyun /* Clear old fields */
649*4882a593Smuzhiyun mvpp2_cls_flow_hek_num_set(fe, 0);
650*4882a593Smuzhiyun fe->data[2] = 0;
651*4882a593Smuzhiyun
652*4882a593Smuzhiyun for_each_set_bit(i, &hash_opts, MVPP22_CLS_HEK_N_FIELDS) {
653*4882a593Smuzhiyun switch (BIT(i)) {
654*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_MAC_DA:
655*4882a593Smuzhiyun field_id = MVPP22_CLS_FIELD_MAC_DA;
656*4882a593Smuzhiyun break;
657*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_VLAN:
658*4882a593Smuzhiyun field_id = MVPP22_CLS_FIELD_VLAN;
659*4882a593Smuzhiyun break;
660*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_VLAN_PRI:
661*4882a593Smuzhiyun field_id = MVPP22_CLS_FIELD_VLAN_PRI;
662*4882a593Smuzhiyun break;
663*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_IP4SA:
664*4882a593Smuzhiyun field_id = MVPP22_CLS_FIELD_IP4SA;
665*4882a593Smuzhiyun break;
666*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_IP4DA:
667*4882a593Smuzhiyun field_id = MVPP22_CLS_FIELD_IP4DA;
668*4882a593Smuzhiyun break;
669*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_IP6SA:
670*4882a593Smuzhiyun field_id = MVPP22_CLS_FIELD_IP6SA;
671*4882a593Smuzhiyun break;
672*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_IP6DA:
673*4882a593Smuzhiyun field_id = MVPP22_CLS_FIELD_IP6DA;
674*4882a593Smuzhiyun break;
675*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_L4SIP:
676*4882a593Smuzhiyun field_id = MVPP22_CLS_FIELD_L4SIP;
677*4882a593Smuzhiyun break;
678*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_L4DIP:
679*4882a593Smuzhiyun field_id = MVPP22_CLS_FIELD_L4DIP;
680*4882a593Smuzhiyun break;
681*4882a593Smuzhiyun default:
682*4882a593Smuzhiyun return -EINVAL;
683*4882a593Smuzhiyun }
684*4882a593Smuzhiyun if (mvpp2_flow_add_hek_field(fe, field_id))
685*4882a593Smuzhiyun return -EINVAL;
686*4882a593Smuzhiyun }
687*4882a593Smuzhiyun
688*4882a593Smuzhiyun return 0;
689*4882a593Smuzhiyun }
690*4882a593Smuzhiyun
691*4882a593Smuzhiyun /* Returns the size, in bits, of the corresponding HEK field */
mvpp2_cls_hek_field_size(u32 field)692*4882a593Smuzhiyun static int mvpp2_cls_hek_field_size(u32 field)
693*4882a593Smuzhiyun {
694*4882a593Smuzhiyun switch (field) {
695*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_MAC_DA:
696*4882a593Smuzhiyun return 48;
697*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_VLAN:
698*4882a593Smuzhiyun return 12;
699*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_VLAN_PRI:
700*4882a593Smuzhiyun return 3;
701*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_IP4SA:
702*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_IP4DA:
703*4882a593Smuzhiyun return 32;
704*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_IP6SA:
705*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_IP6DA:
706*4882a593Smuzhiyun return 128;
707*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_L4SIP:
708*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_L4DIP:
709*4882a593Smuzhiyun return 16;
710*4882a593Smuzhiyun default:
711*4882a593Smuzhiyun return -1;
712*4882a593Smuzhiyun }
713*4882a593Smuzhiyun }
714*4882a593Smuzhiyun
mvpp2_cls_flow_get(int flow)715*4882a593Smuzhiyun const struct mvpp2_cls_flow *mvpp2_cls_flow_get(int flow)
716*4882a593Smuzhiyun {
717*4882a593Smuzhiyun if (flow >= MVPP2_N_PRS_FLOWS)
718*4882a593Smuzhiyun return NULL;
719*4882a593Smuzhiyun
720*4882a593Smuzhiyun return &cls_flows[flow];
721*4882a593Smuzhiyun }
722*4882a593Smuzhiyun
723*4882a593Smuzhiyun /* Set the hash generation options for the given traffic flow.
724*4882a593Smuzhiyun * One traffic flow (in the ethtool sense) has multiple classification flows,
725*4882a593Smuzhiyun * to handle specific cases such as fragmentation, or the presence of a
726*4882a593Smuzhiyun * VLAN / DSA Tag.
727*4882a593Smuzhiyun *
728*4882a593Smuzhiyun * Each of these individual flows has different constraints, for example we
729*4882a593Smuzhiyun * can't hash fragmented packets on L4 data (else we would risk having packet
730*4882a593Smuzhiyun * re-ordering), so each classification flows masks the options with their
731*4882a593Smuzhiyun * supported ones.
732*4882a593Smuzhiyun *
733*4882a593Smuzhiyun */
mvpp2_port_rss_hash_opts_set(struct mvpp2_port * port,int flow_type,u16 requested_opts)734*4882a593Smuzhiyun static int mvpp2_port_rss_hash_opts_set(struct mvpp2_port *port, int flow_type,
735*4882a593Smuzhiyun u16 requested_opts)
736*4882a593Smuzhiyun {
737*4882a593Smuzhiyun const struct mvpp2_cls_flow *flow;
738*4882a593Smuzhiyun struct mvpp2_cls_flow_entry fe;
739*4882a593Smuzhiyun int i, engine, flow_index;
740*4882a593Smuzhiyun u16 hash_opts;
741*4882a593Smuzhiyun
742*4882a593Smuzhiyun for_each_cls_flow_id_with_type(i, flow_type) {
743*4882a593Smuzhiyun flow = mvpp2_cls_flow_get(i);
744*4882a593Smuzhiyun if (!flow)
745*4882a593Smuzhiyun return -EINVAL;
746*4882a593Smuzhiyun
747*4882a593Smuzhiyun flow_index = MVPP2_CLS_FLT_HASH_ENTRY(port->id, flow->flow_id);
748*4882a593Smuzhiyun
749*4882a593Smuzhiyun mvpp2_cls_flow_read(port->priv, flow_index, &fe);
750*4882a593Smuzhiyun
751*4882a593Smuzhiyun hash_opts = flow->supported_hash_opts & requested_opts;
752*4882a593Smuzhiyun
753*4882a593Smuzhiyun /* Use C3HB engine to access L4 infos. This adds L4 infos to the
754*4882a593Smuzhiyun * hash parameters
755*4882a593Smuzhiyun */
756*4882a593Smuzhiyun if (hash_opts & MVPP22_CLS_HEK_L4_OPTS)
757*4882a593Smuzhiyun engine = MVPP22_CLS_ENGINE_C3HB;
758*4882a593Smuzhiyun else
759*4882a593Smuzhiyun engine = MVPP22_CLS_ENGINE_C3HA;
760*4882a593Smuzhiyun
761*4882a593Smuzhiyun if (mvpp2_flow_set_hek_fields(&fe, hash_opts))
762*4882a593Smuzhiyun return -EINVAL;
763*4882a593Smuzhiyun
764*4882a593Smuzhiyun mvpp2_cls_flow_eng_set(&fe, engine);
765*4882a593Smuzhiyun
766*4882a593Smuzhiyun mvpp2_cls_flow_write(port->priv, &fe);
767*4882a593Smuzhiyun }
768*4882a593Smuzhiyun
769*4882a593Smuzhiyun return 0;
770*4882a593Smuzhiyun }
771*4882a593Smuzhiyun
mvpp2_flow_get_hek_fields(struct mvpp2_cls_flow_entry * fe)772*4882a593Smuzhiyun u16 mvpp2_flow_get_hek_fields(struct mvpp2_cls_flow_entry *fe)
773*4882a593Smuzhiyun {
774*4882a593Smuzhiyun u16 hash_opts = 0;
775*4882a593Smuzhiyun int n_fields, i, field;
776*4882a593Smuzhiyun
777*4882a593Smuzhiyun n_fields = mvpp2_cls_flow_hek_num_get(fe);
778*4882a593Smuzhiyun
779*4882a593Smuzhiyun for (i = 0; i < n_fields; i++) {
780*4882a593Smuzhiyun field = mvpp2_cls_flow_hek_get(fe, i);
781*4882a593Smuzhiyun
782*4882a593Smuzhiyun switch (field) {
783*4882a593Smuzhiyun case MVPP22_CLS_FIELD_MAC_DA:
784*4882a593Smuzhiyun hash_opts |= MVPP22_CLS_HEK_OPT_MAC_DA;
785*4882a593Smuzhiyun break;
786*4882a593Smuzhiyun case MVPP22_CLS_FIELD_VLAN:
787*4882a593Smuzhiyun hash_opts |= MVPP22_CLS_HEK_OPT_VLAN;
788*4882a593Smuzhiyun break;
789*4882a593Smuzhiyun case MVPP22_CLS_FIELD_VLAN_PRI:
790*4882a593Smuzhiyun hash_opts |= MVPP22_CLS_HEK_OPT_VLAN_PRI;
791*4882a593Smuzhiyun break;
792*4882a593Smuzhiyun case MVPP22_CLS_FIELD_L3_PROTO:
793*4882a593Smuzhiyun hash_opts |= MVPP22_CLS_HEK_OPT_L3_PROTO;
794*4882a593Smuzhiyun break;
795*4882a593Smuzhiyun case MVPP22_CLS_FIELD_IP4SA:
796*4882a593Smuzhiyun hash_opts |= MVPP22_CLS_HEK_OPT_IP4SA;
797*4882a593Smuzhiyun break;
798*4882a593Smuzhiyun case MVPP22_CLS_FIELD_IP4DA:
799*4882a593Smuzhiyun hash_opts |= MVPP22_CLS_HEK_OPT_IP4DA;
800*4882a593Smuzhiyun break;
801*4882a593Smuzhiyun case MVPP22_CLS_FIELD_IP6SA:
802*4882a593Smuzhiyun hash_opts |= MVPP22_CLS_HEK_OPT_IP6SA;
803*4882a593Smuzhiyun break;
804*4882a593Smuzhiyun case MVPP22_CLS_FIELD_IP6DA:
805*4882a593Smuzhiyun hash_opts |= MVPP22_CLS_HEK_OPT_IP6DA;
806*4882a593Smuzhiyun break;
807*4882a593Smuzhiyun case MVPP22_CLS_FIELD_L4SIP:
808*4882a593Smuzhiyun hash_opts |= MVPP22_CLS_HEK_OPT_L4SIP;
809*4882a593Smuzhiyun break;
810*4882a593Smuzhiyun case MVPP22_CLS_FIELD_L4DIP:
811*4882a593Smuzhiyun hash_opts |= MVPP22_CLS_HEK_OPT_L4DIP;
812*4882a593Smuzhiyun break;
813*4882a593Smuzhiyun default:
814*4882a593Smuzhiyun break;
815*4882a593Smuzhiyun }
816*4882a593Smuzhiyun }
817*4882a593Smuzhiyun return hash_opts;
818*4882a593Smuzhiyun }
819*4882a593Smuzhiyun
820*4882a593Smuzhiyun /* Returns the hash opts for this flow. There are several classifier flows
821*4882a593Smuzhiyun * for one traffic flow, this returns an aggregation of all configurations.
822*4882a593Smuzhiyun */
mvpp2_port_rss_hash_opts_get(struct mvpp2_port * port,int flow_type)823*4882a593Smuzhiyun static u16 mvpp2_port_rss_hash_opts_get(struct mvpp2_port *port, int flow_type)
824*4882a593Smuzhiyun {
825*4882a593Smuzhiyun const struct mvpp2_cls_flow *flow;
826*4882a593Smuzhiyun struct mvpp2_cls_flow_entry fe;
827*4882a593Smuzhiyun int i, flow_index;
828*4882a593Smuzhiyun u16 hash_opts = 0;
829*4882a593Smuzhiyun
830*4882a593Smuzhiyun for_each_cls_flow_id_with_type(i, flow_type) {
831*4882a593Smuzhiyun flow = mvpp2_cls_flow_get(i);
832*4882a593Smuzhiyun if (!flow)
833*4882a593Smuzhiyun return 0;
834*4882a593Smuzhiyun
835*4882a593Smuzhiyun flow_index = MVPP2_CLS_FLT_HASH_ENTRY(port->id, flow->flow_id);
836*4882a593Smuzhiyun
837*4882a593Smuzhiyun mvpp2_cls_flow_read(port->priv, flow_index, &fe);
838*4882a593Smuzhiyun
839*4882a593Smuzhiyun hash_opts |= mvpp2_flow_get_hek_fields(&fe);
840*4882a593Smuzhiyun }
841*4882a593Smuzhiyun
842*4882a593Smuzhiyun return hash_opts;
843*4882a593Smuzhiyun }
844*4882a593Smuzhiyun
mvpp2_cls_port_init_flows(struct mvpp2 * priv)845*4882a593Smuzhiyun static void mvpp2_cls_port_init_flows(struct mvpp2 *priv)
846*4882a593Smuzhiyun {
847*4882a593Smuzhiyun const struct mvpp2_cls_flow *flow;
848*4882a593Smuzhiyun int i;
849*4882a593Smuzhiyun
850*4882a593Smuzhiyun for (i = 0; i < MVPP2_N_PRS_FLOWS; i++) {
851*4882a593Smuzhiyun flow = mvpp2_cls_flow_get(i);
852*4882a593Smuzhiyun if (!flow)
853*4882a593Smuzhiyun break;
854*4882a593Smuzhiyun
855*4882a593Smuzhiyun mvpp2_cls_flow_prs_init(priv, flow);
856*4882a593Smuzhiyun mvpp2_cls_flow_lkp_init(priv, flow);
857*4882a593Smuzhiyun mvpp2_cls_flow_init(priv, flow);
858*4882a593Smuzhiyun }
859*4882a593Smuzhiyun }
860*4882a593Smuzhiyun
mvpp2_port_c2_cls_init(struct mvpp2_port * port)861*4882a593Smuzhiyun static void mvpp2_port_c2_cls_init(struct mvpp2_port *port)
862*4882a593Smuzhiyun {
863*4882a593Smuzhiyun struct mvpp2_cls_c2_entry c2;
864*4882a593Smuzhiyun u8 qh, ql, pmap;
865*4882a593Smuzhiyun
866*4882a593Smuzhiyun memset(&c2, 0, sizeof(c2));
867*4882a593Smuzhiyun
868*4882a593Smuzhiyun c2.index = MVPP22_CLS_C2_RSS_ENTRY(port->id);
869*4882a593Smuzhiyun
870*4882a593Smuzhiyun pmap = BIT(port->id);
871*4882a593Smuzhiyun c2.tcam[4] = MVPP22_CLS_C2_PORT_ID(pmap);
872*4882a593Smuzhiyun c2.tcam[4] |= MVPP22_CLS_C2_TCAM_EN(MVPP22_CLS_C2_PORT_ID(pmap));
873*4882a593Smuzhiyun
874*4882a593Smuzhiyun /* Match on Lookup Type */
875*4882a593Smuzhiyun c2.tcam[4] |= MVPP22_CLS_C2_TCAM_EN(MVPP22_CLS_C2_LU_TYPE(MVPP2_CLS_LU_TYPE_MASK));
876*4882a593Smuzhiyun c2.tcam[4] |= MVPP22_CLS_C2_LU_TYPE(MVPP22_CLS_LU_TYPE_ALL);
877*4882a593Smuzhiyun
878*4882a593Smuzhiyun /* Update RSS status after matching this entry */
879*4882a593Smuzhiyun c2.act = MVPP22_CLS_C2_ACT_RSS_EN(MVPP22_C2_UPD_LOCK);
880*4882a593Smuzhiyun
881*4882a593Smuzhiyun /* Mark packet as "forwarded to software", needed for RSS */
882*4882a593Smuzhiyun c2.act |= MVPP22_CLS_C2_ACT_FWD(MVPP22_C2_FWD_SW_LOCK);
883*4882a593Smuzhiyun
884*4882a593Smuzhiyun /* Configure the default rx queue : Update Queue Low and Queue High, but
885*4882a593Smuzhiyun * don't lock, since the rx queue selection might be overridden by RSS
886*4882a593Smuzhiyun */
887*4882a593Smuzhiyun c2.act |= MVPP22_CLS_C2_ACT_QHIGH(MVPP22_C2_UPD) |
888*4882a593Smuzhiyun MVPP22_CLS_C2_ACT_QLOW(MVPP22_C2_UPD);
889*4882a593Smuzhiyun
890*4882a593Smuzhiyun qh = (port->first_rxq >> 3) & MVPP22_CLS_C2_ATTR0_QHIGH_MASK;
891*4882a593Smuzhiyun ql = port->first_rxq & MVPP22_CLS_C2_ATTR0_QLOW_MASK;
892*4882a593Smuzhiyun
893*4882a593Smuzhiyun c2.attr[0] = MVPP22_CLS_C2_ATTR0_QHIGH(qh) |
894*4882a593Smuzhiyun MVPP22_CLS_C2_ATTR0_QLOW(ql);
895*4882a593Smuzhiyun
896*4882a593Smuzhiyun c2.valid = true;
897*4882a593Smuzhiyun
898*4882a593Smuzhiyun mvpp2_cls_c2_write(port->priv, &c2);
899*4882a593Smuzhiyun }
900*4882a593Smuzhiyun
901*4882a593Smuzhiyun /* Classifier default initialization */
mvpp2_cls_init(struct mvpp2 * priv)902*4882a593Smuzhiyun void mvpp2_cls_init(struct mvpp2 *priv)
903*4882a593Smuzhiyun {
904*4882a593Smuzhiyun struct mvpp2_cls_lookup_entry le;
905*4882a593Smuzhiyun struct mvpp2_cls_flow_entry fe;
906*4882a593Smuzhiyun struct mvpp2_cls_c2_entry c2;
907*4882a593Smuzhiyun int index;
908*4882a593Smuzhiyun
909*4882a593Smuzhiyun /* Enable classifier */
910*4882a593Smuzhiyun mvpp2_write(priv, MVPP2_CLS_MODE_REG, MVPP2_CLS_MODE_ACTIVE_MASK);
911*4882a593Smuzhiyun
912*4882a593Smuzhiyun /* Clear classifier flow table */
913*4882a593Smuzhiyun memset(&fe.data, 0, sizeof(fe.data));
914*4882a593Smuzhiyun for (index = 0; index < MVPP2_CLS_FLOWS_TBL_SIZE; index++) {
915*4882a593Smuzhiyun fe.index = index;
916*4882a593Smuzhiyun mvpp2_cls_flow_write(priv, &fe);
917*4882a593Smuzhiyun }
918*4882a593Smuzhiyun
919*4882a593Smuzhiyun /* Clear classifier lookup table */
920*4882a593Smuzhiyun le.data = 0;
921*4882a593Smuzhiyun for (index = 0; index < MVPP2_CLS_LKP_TBL_SIZE; index++) {
922*4882a593Smuzhiyun le.lkpid = index;
923*4882a593Smuzhiyun le.way = 0;
924*4882a593Smuzhiyun mvpp2_cls_lookup_write(priv, &le);
925*4882a593Smuzhiyun
926*4882a593Smuzhiyun le.way = 1;
927*4882a593Smuzhiyun mvpp2_cls_lookup_write(priv, &le);
928*4882a593Smuzhiyun }
929*4882a593Smuzhiyun
930*4882a593Smuzhiyun /* Clear C2 TCAM engine table */
931*4882a593Smuzhiyun memset(&c2, 0, sizeof(c2));
932*4882a593Smuzhiyun c2.valid = false;
933*4882a593Smuzhiyun for (index = 0; index < MVPP22_CLS_C2_N_ENTRIES; index++) {
934*4882a593Smuzhiyun c2.index = index;
935*4882a593Smuzhiyun mvpp2_cls_c2_write(priv, &c2);
936*4882a593Smuzhiyun }
937*4882a593Smuzhiyun
938*4882a593Smuzhiyun /* Disable the FIFO stages in C2 engine, which are only used in BIST
939*4882a593Smuzhiyun * mode
940*4882a593Smuzhiyun */
941*4882a593Smuzhiyun mvpp2_write(priv, MVPP22_CLS_C2_TCAM_CTRL,
942*4882a593Smuzhiyun MVPP22_CLS_C2_TCAM_BYPASS_FIFO);
943*4882a593Smuzhiyun
944*4882a593Smuzhiyun mvpp2_cls_port_init_flows(priv);
945*4882a593Smuzhiyun }
946*4882a593Smuzhiyun
mvpp2_cls_port_config(struct mvpp2_port * port)947*4882a593Smuzhiyun void mvpp2_cls_port_config(struct mvpp2_port *port)
948*4882a593Smuzhiyun {
949*4882a593Smuzhiyun struct mvpp2_cls_lookup_entry le;
950*4882a593Smuzhiyun u32 val;
951*4882a593Smuzhiyun
952*4882a593Smuzhiyun /* Set way for the port */
953*4882a593Smuzhiyun val = mvpp2_read(port->priv, MVPP2_CLS_PORT_WAY_REG);
954*4882a593Smuzhiyun val &= ~MVPP2_CLS_PORT_WAY_MASK(port->id);
955*4882a593Smuzhiyun mvpp2_write(port->priv, MVPP2_CLS_PORT_WAY_REG, val);
956*4882a593Smuzhiyun
957*4882a593Smuzhiyun /* Pick the entry to be accessed in lookup ID decoding table
958*4882a593Smuzhiyun * according to the way and lkpid.
959*4882a593Smuzhiyun */
960*4882a593Smuzhiyun le.lkpid = port->id;
961*4882a593Smuzhiyun le.way = 0;
962*4882a593Smuzhiyun le.data = 0;
963*4882a593Smuzhiyun
964*4882a593Smuzhiyun /* Set initial CPU queue for receiving packets */
965*4882a593Smuzhiyun le.data &= ~MVPP2_CLS_LKP_TBL_RXQ_MASK;
966*4882a593Smuzhiyun le.data |= port->first_rxq;
967*4882a593Smuzhiyun
968*4882a593Smuzhiyun /* Disable classification engines */
969*4882a593Smuzhiyun le.data &= ~MVPP2_CLS_LKP_TBL_LOOKUP_EN_MASK;
970*4882a593Smuzhiyun
971*4882a593Smuzhiyun /* Update lookup ID table entry */
972*4882a593Smuzhiyun mvpp2_cls_lookup_write(port->priv, &le);
973*4882a593Smuzhiyun
974*4882a593Smuzhiyun mvpp2_port_c2_cls_init(port);
975*4882a593Smuzhiyun }
976*4882a593Smuzhiyun
mvpp2_cls_c2_hit_count(struct mvpp2 * priv,int c2_index)977*4882a593Smuzhiyun u32 mvpp2_cls_c2_hit_count(struct mvpp2 *priv, int c2_index)
978*4882a593Smuzhiyun {
979*4882a593Smuzhiyun mvpp2_write(priv, MVPP22_CLS_C2_TCAM_IDX, c2_index);
980*4882a593Smuzhiyun
981*4882a593Smuzhiyun return mvpp2_read(priv, MVPP22_CLS_C2_HIT_CTR);
982*4882a593Smuzhiyun }
983*4882a593Smuzhiyun
mvpp2_rss_port_c2_enable(struct mvpp2_port * port,u32 ctx)984*4882a593Smuzhiyun static void mvpp2_rss_port_c2_enable(struct mvpp2_port *port, u32 ctx)
985*4882a593Smuzhiyun {
986*4882a593Smuzhiyun struct mvpp2_cls_c2_entry c2;
987*4882a593Smuzhiyun u8 qh, ql;
988*4882a593Smuzhiyun
989*4882a593Smuzhiyun mvpp2_cls_c2_read(port->priv, MVPP22_CLS_C2_RSS_ENTRY(port->id), &c2);
990*4882a593Smuzhiyun
991*4882a593Smuzhiyun /* The RxQ number is used to select the RSS table. It that case, we set
992*4882a593Smuzhiyun * it to be the ctx number.
993*4882a593Smuzhiyun */
994*4882a593Smuzhiyun qh = (ctx >> 3) & MVPP22_CLS_C2_ATTR0_QHIGH_MASK;
995*4882a593Smuzhiyun ql = ctx & MVPP22_CLS_C2_ATTR0_QLOW_MASK;
996*4882a593Smuzhiyun
997*4882a593Smuzhiyun c2.attr[0] = MVPP22_CLS_C2_ATTR0_QHIGH(qh) |
998*4882a593Smuzhiyun MVPP22_CLS_C2_ATTR0_QLOW(ql);
999*4882a593Smuzhiyun
1000*4882a593Smuzhiyun c2.attr[2] |= MVPP22_CLS_C2_ATTR2_RSS_EN;
1001*4882a593Smuzhiyun
1002*4882a593Smuzhiyun mvpp2_cls_c2_write(port->priv, &c2);
1003*4882a593Smuzhiyun }
1004*4882a593Smuzhiyun
mvpp2_rss_port_c2_disable(struct mvpp2_port * port)1005*4882a593Smuzhiyun static void mvpp2_rss_port_c2_disable(struct mvpp2_port *port)
1006*4882a593Smuzhiyun {
1007*4882a593Smuzhiyun struct mvpp2_cls_c2_entry c2;
1008*4882a593Smuzhiyun u8 qh, ql;
1009*4882a593Smuzhiyun
1010*4882a593Smuzhiyun mvpp2_cls_c2_read(port->priv, MVPP22_CLS_C2_RSS_ENTRY(port->id), &c2);
1011*4882a593Smuzhiyun
1012*4882a593Smuzhiyun /* Reset the default destination RxQ to the port's first rx queue. */
1013*4882a593Smuzhiyun qh = (port->first_rxq >> 3) & MVPP22_CLS_C2_ATTR0_QHIGH_MASK;
1014*4882a593Smuzhiyun ql = port->first_rxq & MVPP22_CLS_C2_ATTR0_QLOW_MASK;
1015*4882a593Smuzhiyun
1016*4882a593Smuzhiyun c2.attr[0] = MVPP22_CLS_C2_ATTR0_QHIGH(qh) |
1017*4882a593Smuzhiyun MVPP22_CLS_C2_ATTR0_QLOW(ql);
1018*4882a593Smuzhiyun
1019*4882a593Smuzhiyun c2.attr[2] &= ~MVPP22_CLS_C2_ATTR2_RSS_EN;
1020*4882a593Smuzhiyun
1021*4882a593Smuzhiyun mvpp2_cls_c2_write(port->priv, &c2);
1022*4882a593Smuzhiyun }
1023*4882a593Smuzhiyun
mvpp22_rss_ctx(struct mvpp2_port * port,int port_rss_ctx)1024*4882a593Smuzhiyun static inline int mvpp22_rss_ctx(struct mvpp2_port *port, int port_rss_ctx)
1025*4882a593Smuzhiyun {
1026*4882a593Smuzhiyun return port->rss_ctx[port_rss_ctx];
1027*4882a593Smuzhiyun }
1028*4882a593Smuzhiyun
mvpp22_port_rss_enable(struct mvpp2_port * port)1029*4882a593Smuzhiyun int mvpp22_port_rss_enable(struct mvpp2_port *port)
1030*4882a593Smuzhiyun {
1031*4882a593Smuzhiyun if (mvpp22_rss_ctx(port, 0) < 0)
1032*4882a593Smuzhiyun return -EINVAL;
1033*4882a593Smuzhiyun
1034*4882a593Smuzhiyun mvpp2_rss_port_c2_enable(port, mvpp22_rss_ctx(port, 0));
1035*4882a593Smuzhiyun
1036*4882a593Smuzhiyun return 0;
1037*4882a593Smuzhiyun }
1038*4882a593Smuzhiyun
mvpp22_port_rss_disable(struct mvpp2_port * port)1039*4882a593Smuzhiyun int mvpp22_port_rss_disable(struct mvpp2_port *port)
1040*4882a593Smuzhiyun {
1041*4882a593Smuzhiyun if (mvpp22_rss_ctx(port, 0) < 0)
1042*4882a593Smuzhiyun return -EINVAL;
1043*4882a593Smuzhiyun
1044*4882a593Smuzhiyun mvpp2_rss_port_c2_disable(port);
1045*4882a593Smuzhiyun
1046*4882a593Smuzhiyun return 0;
1047*4882a593Smuzhiyun }
1048*4882a593Smuzhiyun
mvpp22_port_c2_lookup_disable(struct mvpp2_port * port,int entry)1049*4882a593Smuzhiyun static void mvpp22_port_c2_lookup_disable(struct mvpp2_port *port, int entry)
1050*4882a593Smuzhiyun {
1051*4882a593Smuzhiyun struct mvpp2_cls_c2_entry c2;
1052*4882a593Smuzhiyun
1053*4882a593Smuzhiyun mvpp2_cls_c2_read(port->priv, entry, &c2);
1054*4882a593Smuzhiyun
1055*4882a593Smuzhiyun /* Clear the port map so that the entry doesn't match anymore */
1056*4882a593Smuzhiyun c2.tcam[4] &= ~(MVPP22_CLS_C2_PORT_ID(BIT(port->id)));
1057*4882a593Smuzhiyun
1058*4882a593Smuzhiyun mvpp2_cls_c2_write(port->priv, &c2);
1059*4882a593Smuzhiyun }
1060*4882a593Smuzhiyun
1061*4882a593Smuzhiyun /* Set CPU queue number for oversize packets */
mvpp2_cls_oversize_rxq_set(struct mvpp2_port * port)1062*4882a593Smuzhiyun void mvpp2_cls_oversize_rxq_set(struct mvpp2_port *port)
1063*4882a593Smuzhiyun {
1064*4882a593Smuzhiyun u32 val;
1065*4882a593Smuzhiyun
1066*4882a593Smuzhiyun mvpp2_write(port->priv, MVPP2_CLS_OVERSIZE_RXQ_LOW_REG(port->id),
1067*4882a593Smuzhiyun port->first_rxq & MVPP2_CLS_OVERSIZE_RXQ_LOW_MASK);
1068*4882a593Smuzhiyun
1069*4882a593Smuzhiyun mvpp2_write(port->priv, MVPP2_CLS_SWFWD_P2HQ_REG(port->id),
1070*4882a593Smuzhiyun (port->first_rxq >> MVPP2_CLS_OVERSIZE_RXQ_LOW_BITS));
1071*4882a593Smuzhiyun
1072*4882a593Smuzhiyun val = mvpp2_read(port->priv, MVPP2_CLS_SWFWD_PCTRL_REG);
1073*4882a593Smuzhiyun val &= ~MVPP2_CLS_SWFWD_PCTRL_MASK(port->id);
1074*4882a593Smuzhiyun mvpp2_write(port->priv, MVPP2_CLS_SWFWD_PCTRL_REG, val);
1075*4882a593Smuzhiyun }
1076*4882a593Smuzhiyun
mvpp2_port_c2_tcam_rule_add(struct mvpp2_port * port,struct mvpp2_rfs_rule * rule)1077*4882a593Smuzhiyun static int mvpp2_port_c2_tcam_rule_add(struct mvpp2_port *port,
1078*4882a593Smuzhiyun struct mvpp2_rfs_rule *rule)
1079*4882a593Smuzhiyun {
1080*4882a593Smuzhiyun struct flow_action_entry *act;
1081*4882a593Smuzhiyun struct mvpp2_cls_c2_entry c2;
1082*4882a593Smuzhiyun u8 qh, ql, pmap;
1083*4882a593Smuzhiyun int index, ctx;
1084*4882a593Smuzhiyun
1085*4882a593Smuzhiyun if (!flow_action_basic_hw_stats_check(&rule->flow->action, NULL))
1086*4882a593Smuzhiyun return -EOPNOTSUPP;
1087*4882a593Smuzhiyun
1088*4882a593Smuzhiyun memset(&c2, 0, sizeof(c2));
1089*4882a593Smuzhiyun
1090*4882a593Smuzhiyun index = mvpp2_cls_c2_port_flow_index(port, rule->loc);
1091*4882a593Smuzhiyun if (index < 0)
1092*4882a593Smuzhiyun return -EINVAL;
1093*4882a593Smuzhiyun c2.index = index;
1094*4882a593Smuzhiyun
1095*4882a593Smuzhiyun act = &rule->flow->action.entries[0];
1096*4882a593Smuzhiyun
1097*4882a593Smuzhiyun rule->c2_index = c2.index;
1098*4882a593Smuzhiyun
1099*4882a593Smuzhiyun c2.tcam[3] = (rule->c2_tcam & 0xffff) |
1100*4882a593Smuzhiyun ((rule->c2_tcam_mask & 0xffff) << 16);
1101*4882a593Smuzhiyun c2.tcam[2] = ((rule->c2_tcam >> 16) & 0xffff) |
1102*4882a593Smuzhiyun (((rule->c2_tcam_mask >> 16) & 0xffff) << 16);
1103*4882a593Smuzhiyun c2.tcam[1] = ((rule->c2_tcam >> 32) & 0xffff) |
1104*4882a593Smuzhiyun (((rule->c2_tcam_mask >> 32) & 0xffff) << 16);
1105*4882a593Smuzhiyun c2.tcam[0] = ((rule->c2_tcam >> 48) & 0xffff) |
1106*4882a593Smuzhiyun (((rule->c2_tcam_mask >> 48) & 0xffff) << 16);
1107*4882a593Smuzhiyun
1108*4882a593Smuzhiyun pmap = BIT(port->id);
1109*4882a593Smuzhiyun c2.tcam[4] = MVPP22_CLS_C2_PORT_ID(pmap);
1110*4882a593Smuzhiyun c2.tcam[4] |= MVPP22_CLS_C2_TCAM_EN(MVPP22_CLS_C2_PORT_ID(pmap));
1111*4882a593Smuzhiyun
1112*4882a593Smuzhiyun /* Match on Lookup Type */
1113*4882a593Smuzhiyun c2.tcam[4] |= MVPP22_CLS_C2_TCAM_EN(MVPP22_CLS_C2_LU_TYPE(MVPP2_CLS_LU_TYPE_MASK));
1114*4882a593Smuzhiyun c2.tcam[4] |= MVPP22_CLS_C2_LU_TYPE(rule->loc);
1115*4882a593Smuzhiyun
1116*4882a593Smuzhiyun if (act->id == FLOW_ACTION_DROP) {
1117*4882a593Smuzhiyun c2.act = MVPP22_CLS_C2_ACT_COLOR(MVPP22_C2_COL_RED_LOCK);
1118*4882a593Smuzhiyun } else {
1119*4882a593Smuzhiyun /* We want to keep the default color derived from the Header
1120*4882a593Smuzhiyun * Parser drop entries, for VLAN and MAC filtering. This will
1121*4882a593Smuzhiyun * assign a default color of Green or Red, and we want matches
1122*4882a593Smuzhiyun * with a non-drop action to keep that color.
1123*4882a593Smuzhiyun */
1124*4882a593Smuzhiyun c2.act = MVPP22_CLS_C2_ACT_COLOR(MVPP22_C2_COL_NO_UPD_LOCK);
1125*4882a593Smuzhiyun
1126*4882a593Smuzhiyun /* Update RSS status after matching this entry */
1127*4882a593Smuzhiyun if (act->queue.ctx)
1128*4882a593Smuzhiyun c2.attr[2] |= MVPP22_CLS_C2_ATTR2_RSS_EN;
1129*4882a593Smuzhiyun
1130*4882a593Smuzhiyun /* Always lock the RSS_EN decision. We might have high prio
1131*4882a593Smuzhiyun * rules steering to an RXQ, and a lower one steering to RSS,
1132*4882a593Smuzhiyun * we don't want the low prio RSS rule overwriting this flag.
1133*4882a593Smuzhiyun */
1134*4882a593Smuzhiyun c2.act = MVPP22_CLS_C2_ACT_RSS_EN(MVPP22_C2_UPD_LOCK);
1135*4882a593Smuzhiyun
1136*4882a593Smuzhiyun /* Mark packet as "forwarded to software", needed for RSS */
1137*4882a593Smuzhiyun c2.act |= MVPP22_CLS_C2_ACT_FWD(MVPP22_C2_FWD_SW_LOCK);
1138*4882a593Smuzhiyun
1139*4882a593Smuzhiyun c2.act |= MVPP22_CLS_C2_ACT_QHIGH(MVPP22_C2_UPD_LOCK) |
1140*4882a593Smuzhiyun MVPP22_CLS_C2_ACT_QLOW(MVPP22_C2_UPD_LOCK);
1141*4882a593Smuzhiyun
1142*4882a593Smuzhiyun if (act->queue.ctx) {
1143*4882a593Smuzhiyun /* Get the global ctx number */
1144*4882a593Smuzhiyun ctx = mvpp22_rss_ctx(port, act->queue.ctx);
1145*4882a593Smuzhiyun if (ctx < 0)
1146*4882a593Smuzhiyun return -EINVAL;
1147*4882a593Smuzhiyun
1148*4882a593Smuzhiyun qh = (ctx >> 3) & MVPP22_CLS_C2_ATTR0_QHIGH_MASK;
1149*4882a593Smuzhiyun ql = ctx & MVPP22_CLS_C2_ATTR0_QLOW_MASK;
1150*4882a593Smuzhiyun } else {
1151*4882a593Smuzhiyun qh = ((act->queue.index + port->first_rxq) >> 3) &
1152*4882a593Smuzhiyun MVPP22_CLS_C2_ATTR0_QHIGH_MASK;
1153*4882a593Smuzhiyun ql = (act->queue.index + port->first_rxq) &
1154*4882a593Smuzhiyun MVPP22_CLS_C2_ATTR0_QLOW_MASK;
1155*4882a593Smuzhiyun }
1156*4882a593Smuzhiyun
1157*4882a593Smuzhiyun c2.attr[0] = MVPP22_CLS_C2_ATTR0_QHIGH(qh) |
1158*4882a593Smuzhiyun MVPP22_CLS_C2_ATTR0_QLOW(ql);
1159*4882a593Smuzhiyun }
1160*4882a593Smuzhiyun
1161*4882a593Smuzhiyun c2.valid = true;
1162*4882a593Smuzhiyun
1163*4882a593Smuzhiyun mvpp2_cls_c2_write(port->priv, &c2);
1164*4882a593Smuzhiyun
1165*4882a593Smuzhiyun return 0;
1166*4882a593Smuzhiyun }
1167*4882a593Smuzhiyun
mvpp2_port_c2_rfs_rule_insert(struct mvpp2_port * port,struct mvpp2_rfs_rule * rule)1168*4882a593Smuzhiyun static int mvpp2_port_c2_rfs_rule_insert(struct mvpp2_port *port,
1169*4882a593Smuzhiyun struct mvpp2_rfs_rule *rule)
1170*4882a593Smuzhiyun {
1171*4882a593Smuzhiyun return mvpp2_port_c2_tcam_rule_add(port, rule);
1172*4882a593Smuzhiyun }
1173*4882a593Smuzhiyun
mvpp2_port_cls_rfs_rule_remove(struct mvpp2_port * port,struct mvpp2_rfs_rule * rule)1174*4882a593Smuzhiyun static int mvpp2_port_cls_rfs_rule_remove(struct mvpp2_port *port,
1175*4882a593Smuzhiyun struct mvpp2_rfs_rule *rule)
1176*4882a593Smuzhiyun {
1177*4882a593Smuzhiyun const struct mvpp2_cls_flow *flow;
1178*4882a593Smuzhiyun struct mvpp2_cls_flow_entry fe;
1179*4882a593Smuzhiyun int index, i;
1180*4882a593Smuzhiyun
1181*4882a593Smuzhiyun for_each_cls_flow_id_containing_type(i, rule->flow_type) {
1182*4882a593Smuzhiyun flow = mvpp2_cls_flow_get(i);
1183*4882a593Smuzhiyun if (!flow)
1184*4882a593Smuzhiyun return 0;
1185*4882a593Smuzhiyun
1186*4882a593Smuzhiyun index = MVPP2_CLS_FLT_C2_RFS(port->id, flow->flow_id, rule->loc);
1187*4882a593Smuzhiyun
1188*4882a593Smuzhiyun mvpp2_cls_flow_read(port->priv, index, &fe);
1189*4882a593Smuzhiyun mvpp2_cls_flow_port_remove(&fe, BIT(port->id));
1190*4882a593Smuzhiyun mvpp2_cls_flow_write(port->priv, &fe);
1191*4882a593Smuzhiyun }
1192*4882a593Smuzhiyun
1193*4882a593Smuzhiyun if (rule->c2_index >= 0)
1194*4882a593Smuzhiyun mvpp22_port_c2_lookup_disable(port, rule->c2_index);
1195*4882a593Smuzhiyun
1196*4882a593Smuzhiyun return 0;
1197*4882a593Smuzhiyun }
1198*4882a593Smuzhiyun
mvpp2_port_flt_rfs_rule_insert(struct mvpp2_port * port,struct mvpp2_rfs_rule * rule)1199*4882a593Smuzhiyun static int mvpp2_port_flt_rfs_rule_insert(struct mvpp2_port *port,
1200*4882a593Smuzhiyun struct mvpp2_rfs_rule *rule)
1201*4882a593Smuzhiyun {
1202*4882a593Smuzhiyun const struct mvpp2_cls_flow *flow;
1203*4882a593Smuzhiyun struct mvpp2 *priv = port->priv;
1204*4882a593Smuzhiyun struct mvpp2_cls_flow_entry fe;
1205*4882a593Smuzhiyun int index, ret, i;
1206*4882a593Smuzhiyun
1207*4882a593Smuzhiyun if (rule->engine != MVPP22_CLS_ENGINE_C2)
1208*4882a593Smuzhiyun return -EOPNOTSUPP;
1209*4882a593Smuzhiyun
1210*4882a593Smuzhiyun ret = mvpp2_port_c2_rfs_rule_insert(port, rule);
1211*4882a593Smuzhiyun if (ret)
1212*4882a593Smuzhiyun return ret;
1213*4882a593Smuzhiyun
1214*4882a593Smuzhiyun for_each_cls_flow_id_containing_type(i, rule->flow_type) {
1215*4882a593Smuzhiyun flow = mvpp2_cls_flow_get(i);
1216*4882a593Smuzhiyun if (!flow)
1217*4882a593Smuzhiyun return 0;
1218*4882a593Smuzhiyun
1219*4882a593Smuzhiyun if ((rule->hek_fields & flow->supported_hash_opts) != rule->hek_fields)
1220*4882a593Smuzhiyun continue;
1221*4882a593Smuzhiyun
1222*4882a593Smuzhiyun index = MVPP2_CLS_FLT_C2_RFS(port->id, flow->flow_id, rule->loc);
1223*4882a593Smuzhiyun
1224*4882a593Smuzhiyun mvpp2_cls_flow_read(priv, index, &fe);
1225*4882a593Smuzhiyun mvpp2_cls_flow_eng_set(&fe, rule->engine);
1226*4882a593Smuzhiyun mvpp2_cls_flow_port_id_sel(&fe, true);
1227*4882a593Smuzhiyun mvpp2_flow_set_hek_fields(&fe, rule->hek_fields);
1228*4882a593Smuzhiyun mvpp2_cls_flow_lu_type_set(&fe, rule->loc);
1229*4882a593Smuzhiyun mvpp2_cls_flow_port_add(&fe, 0xf);
1230*4882a593Smuzhiyun
1231*4882a593Smuzhiyun mvpp2_cls_flow_write(priv, &fe);
1232*4882a593Smuzhiyun }
1233*4882a593Smuzhiyun
1234*4882a593Smuzhiyun return 0;
1235*4882a593Smuzhiyun }
1236*4882a593Smuzhiyun
mvpp2_cls_c2_build_match(struct mvpp2_rfs_rule * rule)1237*4882a593Smuzhiyun static int mvpp2_cls_c2_build_match(struct mvpp2_rfs_rule *rule)
1238*4882a593Smuzhiyun {
1239*4882a593Smuzhiyun struct flow_rule *flow = rule->flow;
1240*4882a593Smuzhiyun int offs = 0;
1241*4882a593Smuzhiyun
1242*4882a593Smuzhiyun /* The order of insertion in C2 tcam must match the order in which
1243*4882a593Smuzhiyun * the fields are found in the header
1244*4882a593Smuzhiyun */
1245*4882a593Smuzhiyun if (flow_rule_match_key(flow, FLOW_DISSECTOR_KEY_VLAN)) {
1246*4882a593Smuzhiyun struct flow_match_vlan match;
1247*4882a593Smuzhiyun
1248*4882a593Smuzhiyun flow_rule_match_vlan(flow, &match);
1249*4882a593Smuzhiyun if (match.mask->vlan_id) {
1250*4882a593Smuzhiyun rule->hek_fields |= MVPP22_CLS_HEK_OPT_VLAN;
1251*4882a593Smuzhiyun
1252*4882a593Smuzhiyun rule->c2_tcam |= ((u64)match.key->vlan_id) << offs;
1253*4882a593Smuzhiyun rule->c2_tcam_mask |= ((u64)match.mask->vlan_id) << offs;
1254*4882a593Smuzhiyun
1255*4882a593Smuzhiyun /* Don't update the offset yet */
1256*4882a593Smuzhiyun }
1257*4882a593Smuzhiyun
1258*4882a593Smuzhiyun if (match.mask->vlan_priority) {
1259*4882a593Smuzhiyun rule->hek_fields |= MVPP22_CLS_HEK_OPT_VLAN_PRI;
1260*4882a593Smuzhiyun
1261*4882a593Smuzhiyun /* VLAN pri is always at offset 13 relative to the
1262*4882a593Smuzhiyun * current offset
1263*4882a593Smuzhiyun */
1264*4882a593Smuzhiyun rule->c2_tcam |= ((u64)match.key->vlan_priority) <<
1265*4882a593Smuzhiyun (offs + 13);
1266*4882a593Smuzhiyun rule->c2_tcam_mask |= ((u64)match.mask->vlan_priority) <<
1267*4882a593Smuzhiyun (offs + 13);
1268*4882a593Smuzhiyun }
1269*4882a593Smuzhiyun
1270*4882a593Smuzhiyun if (match.mask->vlan_dei)
1271*4882a593Smuzhiyun return -EOPNOTSUPP;
1272*4882a593Smuzhiyun
1273*4882a593Smuzhiyun /* vlan id and prio always seem to take a full 16-bit slot in
1274*4882a593Smuzhiyun * the Header Extracted Key.
1275*4882a593Smuzhiyun */
1276*4882a593Smuzhiyun offs += 16;
1277*4882a593Smuzhiyun }
1278*4882a593Smuzhiyun
1279*4882a593Smuzhiyun if (flow_rule_match_key(flow, FLOW_DISSECTOR_KEY_PORTS)) {
1280*4882a593Smuzhiyun struct flow_match_ports match;
1281*4882a593Smuzhiyun
1282*4882a593Smuzhiyun flow_rule_match_ports(flow, &match);
1283*4882a593Smuzhiyun if (match.mask->src) {
1284*4882a593Smuzhiyun rule->hek_fields |= MVPP22_CLS_HEK_OPT_L4SIP;
1285*4882a593Smuzhiyun
1286*4882a593Smuzhiyun rule->c2_tcam |= ((u64)ntohs(match.key->src)) << offs;
1287*4882a593Smuzhiyun rule->c2_tcam_mask |= ((u64)ntohs(match.mask->src)) << offs;
1288*4882a593Smuzhiyun offs += mvpp2_cls_hek_field_size(MVPP22_CLS_HEK_OPT_L4SIP);
1289*4882a593Smuzhiyun }
1290*4882a593Smuzhiyun
1291*4882a593Smuzhiyun if (match.mask->dst) {
1292*4882a593Smuzhiyun rule->hek_fields |= MVPP22_CLS_HEK_OPT_L4DIP;
1293*4882a593Smuzhiyun
1294*4882a593Smuzhiyun rule->c2_tcam |= ((u64)ntohs(match.key->dst)) << offs;
1295*4882a593Smuzhiyun rule->c2_tcam_mask |= ((u64)ntohs(match.mask->dst)) << offs;
1296*4882a593Smuzhiyun offs += mvpp2_cls_hek_field_size(MVPP22_CLS_HEK_OPT_L4DIP);
1297*4882a593Smuzhiyun }
1298*4882a593Smuzhiyun }
1299*4882a593Smuzhiyun
1300*4882a593Smuzhiyun if (hweight16(rule->hek_fields) > MVPP2_FLOW_N_FIELDS)
1301*4882a593Smuzhiyun return -EOPNOTSUPP;
1302*4882a593Smuzhiyun
1303*4882a593Smuzhiyun return 0;
1304*4882a593Smuzhiyun }
1305*4882a593Smuzhiyun
mvpp2_cls_rfs_parse_rule(struct mvpp2_rfs_rule * rule)1306*4882a593Smuzhiyun static int mvpp2_cls_rfs_parse_rule(struct mvpp2_rfs_rule *rule)
1307*4882a593Smuzhiyun {
1308*4882a593Smuzhiyun struct flow_rule *flow = rule->flow;
1309*4882a593Smuzhiyun struct flow_action_entry *act;
1310*4882a593Smuzhiyun
1311*4882a593Smuzhiyun if (!flow_action_basic_hw_stats_check(&rule->flow->action, NULL))
1312*4882a593Smuzhiyun return -EOPNOTSUPP;
1313*4882a593Smuzhiyun
1314*4882a593Smuzhiyun act = &flow->action.entries[0];
1315*4882a593Smuzhiyun if (act->id != FLOW_ACTION_QUEUE && act->id != FLOW_ACTION_DROP)
1316*4882a593Smuzhiyun return -EOPNOTSUPP;
1317*4882a593Smuzhiyun
1318*4882a593Smuzhiyun /* When both an RSS context and an queue index are set, the index
1319*4882a593Smuzhiyun * is considered as an offset to be added to the indirection table
1320*4882a593Smuzhiyun * entries. We don't support this, so reject this rule.
1321*4882a593Smuzhiyun */
1322*4882a593Smuzhiyun if (act->queue.ctx && act->queue.index)
1323*4882a593Smuzhiyun return -EOPNOTSUPP;
1324*4882a593Smuzhiyun
1325*4882a593Smuzhiyun /* For now, only use the C2 engine which has a HEK size limited to 64
1326*4882a593Smuzhiyun * bits for TCAM matching.
1327*4882a593Smuzhiyun */
1328*4882a593Smuzhiyun rule->engine = MVPP22_CLS_ENGINE_C2;
1329*4882a593Smuzhiyun
1330*4882a593Smuzhiyun if (mvpp2_cls_c2_build_match(rule))
1331*4882a593Smuzhiyun return -EINVAL;
1332*4882a593Smuzhiyun
1333*4882a593Smuzhiyun return 0;
1334*4882a593Smuzhiyun }
1335*4882a593Smuzhiyun
mvpp2_ethtool_cls_rule_get(struct mvpp2_port * port,struct ethtool_rxnfc * rxnfc)1336*4882a593Smuzhiyun int mvpp2_ethtool_cls_rule_get(struct mvpp2_port *port,
1337*4882a593Smuzhiyun struct ethtool_rxnfc *rxnfc)
1338*4882a593Smuzhiyun {
1339*4882a593Smuzhiyun struct mvpp2_ethtool_fs *efs;
1340*4882a593Smuzhiyun
1341*4882a593Smuzhiyun if (rxnfc->fs.location >= MVPP2_N_RFS_ENTRIES_PER_FLOW)
1342*4882a593Smuzhiyun return -EINVAL;
1343*4882a593Smuzhiyun
1344*4882a593Smuzhiyun efs = port->rfs_rules[rxnfc->fs.location];
1345*4882a593Smuzhiyun if (!efs)
1346*4882a593Smuzhiyun return -ENOENT;
1347*4882a593Smuzhiyun
1348*4882a593Smuzhiyun memcpy(rxnfc, &efs->rxnfc, sizeof(efs->rxnfc));
1349*4882a593Smuzhiyun
1350*4882a593Smuzhiyun return 0;
1351*4882a593Smuzhiyun }
1352*4882a593Smuzhiyun
mvpp2_ethtool_cls_rule_ins(struct mvpp2_port * port,struct ethtool_rxnfc * info)1353*4882a593Smuzhiyun int mvpp2_ethtool_cls_rule_ins(struct mvpp2_port *port,
1354*4882a593Smuzhiyun struct ethtool_rxnfc *info)
1355*4882a593Smuzhiyun {
1356*4882a593Smuzhiyun struct ethtool_rx_flow_spec_input input = {};
1357*4882a593Smuzhiyun struct ethtool_rx_flow_rule *ethtool_rule;
1358*4882a593Smuzhiyun struct mvpp2_ethtool_fs *efs, *old_efs;
1359*4882a593Smuzhiyun int ret = 0;
1360*4882a593Smuzhiyun
1361*4882a593Smuzhiyun if (info->fs.location >= MVPP2_N_RFS_ENTRIES_PER_FLOW)
1362*4882a593Smuzhiyun return -EINVAL;
1363*4882a593Smuzhiyun
1364*4882a593Smuzhiyun efs = kzalloc(sizeof(*efs), GFP_KERNEL);
1365*4882a593Smuzhiyun if (!efs)
1366*4882a593Smuzhiyun return -ENOMEM;
1367*4882a593Smuzhiyun
1368*4882a593Smuzhiyun input.fs = &info->fs;
1369*4882a593Smuzhiyun
1370*4882a593Smuzhiyun /* We need to manually set the rss_ctx, since this info isn't present
1371*4882a593Smuzhiyun * in info->fs
1372*4882a593Smuzhiyun */
1373*4882a593Smuzhiyun if (info->fs.flow_type & FLOW_RSS)
1374*4882a593Smuzhiyun input.rss_ctx = info->rss_context;
1375*4882a593Smuzhiyun
1376*4882a593Smuzhiyun ethtool_rule = ethtool_rx_flow_rule_create(&input);
1377*4882a593Smuzhiyun if (IS_ERR(ethtool_rule)) {
1378*4882a593Smuzhiyun ret = PTR_ERR(ethtool_rule);
1379*4882a593Smuzhiyun goto clean_rule;
1380*4882a593Smuzhiyun }
1381*4882a593Smuzhiyun
1382*4882a593Smuzhiyun efs->rule.flow = ethtool_rule->rule;
1383*4882a593Smuzhiyun efs->rule.flow_type = mvpp2_cls_ethtool_flow_to_type(info->fs.flow_type);
1384*4882a593Smuzhiyun if (efs->rule.flow_type < 0) {
1385*4882a593Smuzhiyun ret = efs->rule.flow_type;
1386*4882a593Smuzhiyun goto clean_rule;
1387*4882a593Smuzhiyun }
1388*4882a593Smuzhiyun
1389*4882a593Smuzhiyun ret = mvpp2_cls_rfs_parse_rule(&efs->rule);
1390*4882a593Smuzhiyun if (ret)
1391*4882a593Smuzhiyun goto clean_eth_rule;
1392*4882a593Smuzhiyun
1393*4882a593Smuzhiyun efs->rule.loc = info->fs.location;
1394*4882a593Smuzhiyun
1395*4882a593Smuzhiyun /* Replace an already existing rule */
1396*4882a593Smuzhiyun if (port->rfs_rules[efs->rule.loc]) {
1397*4882a593Smuzhiyun old_efs = port->rfs_rules[efs->rule.loc];
1398*4882a593Smuzhiyun ret = mvpp2_port_cls_rfs_rule_remove(port, &old_efs->rule);
1399*4882a593Smuzhiyun if (ret)
1400*4882a593Smuzhiyun goto clean_eth_rule;
1401*4882a593Smuzhiyun kfree(old_efs);
1402*4882a593Smuzhiyun port->n_rfs_rules--;
1403*4882a593Smuzhiyun }
1404*4882a593Smuzhiyun
1405*4882a593Smuzhiyun ret = mvpp2_port_flt_rfs_rule_insert(port, &efs->rule);
1406*4882a593Smuzhiyun if (ret)
1407*4882a593Smuzhiyun goto clean_eth_rule;
1408*4882a593Smuzhiyun
1409*4882a593Smuzhiyun ethtool_rx_flow_rule_destroy(ethtool_rule);
1410*4882a593Smuzhiyun efs->rule.flow = NULL;
1411*4882a593Smuzhiyun
1412*4882a593Smuzhiyun memcpy(&efs->rxnfc, info, sizeof(*info));
1413*4882a593Smuzhiyun port->rfs_rules[efs->rule.loc] = efs;
1414*4882a593Smuzhiyun port->n_rfs_rules++;
1415*4882a593Smuzhiyun
1416*4882a593Smuzhiyun return ret;
1417*4882a593Smuzhiyun
1418*4882a593Smuzhiyun clean_eth_rule:
1419*4882a593Smuzhiyun ethtool_rx_flow_rule_destroy(ethtool_rule);
1420*4882a593Smuzhiyun clean_rule:
1421*4882a593Smuzhiyun kfree(efs);
1422*4882a593Smuzhiyun return ret;
1423*4882a593Smuzhiyun }
1424*4882a593Smuzhiyun
mvpp2_ethtool_cls_rule_del(struct mvpp2_port * port,struct ethtool_rxnfc * info)1425*4882a593Smuzhiyun int mvpp2_ethtool_cls_rule_del(struct mvpp2_port *port,
1426*4882a593Smuzhiyun struct ethtool_rxnfc *info)
1427*4882a593Smuzhiyun {
1428*4882a593Smuzhiyun struct mvpp2_ethtool_fs *efs;
1429*4882a593Smuzhiyun int ret;
1430*4882a593Smuzhiyun
1431*4882a593Smuzhiyun if (info->fs.location >= MVPP2_N_RFS_ENTRIES_PER_FLOW)
1432*4882a593Smuzhiyun return -EINVAL;
1433*4882a593Smuzhiyun
1434*4882a593Smuzhiyun efs = port->rfs_rules[info->fs.location];
1435*4882a593Smuzhiyun if (!efs)
1436*4882a593Smuzhiyun return -EINVAL;
1437*4882a593Smuzhiyun
1438*4882a593Smuzhiyun /* Remove the rule from the engines. */
1439*4882a593Smuzhiyun ret = mvpp2_port_cls_rfs_rule_remove(port, &efs->rule);
1440*4882a593Smuzhiyun if (ret)
1441*4882a593Smuzhiyun return ret;
1442*4882a593Smuzhiyun
1443*4882a593Smuzhiyun port->n_rfs_rules--;
1444*4882a593Smuzhiyun port->rfs_rules[info->fs.location] = NULL;
1445*4882a593Smuzhiyun kfree(efs);
1446*4882a593Smuzhiyun
1447*4882a593Smuzhiyun return 0;
1448*4882a593Smuzhiyun }
1449*4882a593Smuzhiyun
mvpp22_rxfh_indir(struct mvpp2_port * port,u32 rxq)1450*4882a593Smuzhiyun static inline u32 mvpp22_rxfh_indir(struct mvpp2_port *port, u32 rxq)
1451*4882a593Smuzhiyun {
1452*4882a593Smuzhiyun int nrxqs, cpu, cpus = num_possible_cpus();
1453*4882a593Smuzhiyun
1454*4882a593Smuzhiyun /* Number of RXQs per CPU */
1455*4882a593Smuzhiyun nrxqs = port->nrxqs / cpus;
1456*4882a593Smuzhiyun
1457*4882a593Smuzhiyun /* CPU that will handle this rx queue */
1458*4882a593Smuzhiyun cpu = rxq / nrxqs;
1459*4882a593Smuzhiyun
1460*4882a593Smuzhiyun if (!cpu_online(cpu))
1461*4882a593Smuzhiyun return port->first_rxq;
1462*4882a593Smuzhiyun
1463*4882a593Smuzhiyun /* Indirection to better distribute the paquets on the CPUs when
1464*4882a593Smuzhiyun * configuring the RSS queues.
1465*4882a593Smuzhiyun */
1466*4882a593Smuzhiyun return port->first_rxq + ((rxq * nrxqs + rxq / cpus) % port->nrxqs);
1467*4882a593Smuzhiyun }
1468*4882a593Smuzhiyun
mvpp22_rss_fill_table(struct mvpp2_port * port,struct mvpp2_rss_table * table,u32 rss_ctx)1469*4882a593Smuzhiyun static void mvpp22_rss_fill_table(struct mvpp2_port *port,
1470*4882a593Smuzhiyun struct mvpp2_rss_table *table,
1471*4882a593Smuzhiyun u32 rss_ctx)
1472*4882a593Smuzhiyun {
1473*4882a593Smuzhiyun struct mvpp2 *priv = port->priv;
1474*4882a593Smuzhiyun int i;
1475*4882a593Smuzhiyun
1476*4882a593Smuzhiyun for (i = 0; i < MVPP22_RSS_TABLE_ENTRIES; i++) {
1477*4882a593Smuzhiyun u32 sel = MVPP22_RSS_INDEX_TABLE(rss_ctx) |
1478*4882a593Smuzhiyun MVPP22_RSS_INDEX_TABLE_ENTRY(i);
1479*4882a593Smuzhiyun mvpp2_write(priv, MVPP22_RSS_INDEX, sel);
1480*4882a593Smuzhiyun
1481*4882a593Smuzhiyun mvpp2_write(priv, MVPP22_RSS_TABLE_ENTRY,
1482*4882a593Smuzhiyun mvpp22_rxfh_indir(port, table->indir[i]));
1483*4882a593Smuzhiyun }
1484*4882a593Smuzhiyun }
1485*4882a593Smuzhiyun
mvpp22_rss_context_create(struct mvpp2_port * port,u32 * rss_ctx)1486*4882a593Smuzhiyun static int mvpp22_rss_context_create(struct mvpp2_port *port, u32 *rss_ctx)
1487*4882a593Smuzhiyun {
1488*4882a593Smuzhiyun struct mvpp2 *priv = port->priv;
1489*4882a593Smuzhiyun u32 ctx;
1490*4882a593Smuzhiyun
1491*4882a593Smuzhiyun /* Find the first free RSS table */
1492*4882a593Smuzhiyun for (ctx = 0; ctx < MVPP22_N_RSS_TABLES; ctx++) {
1493*4882a593Smuzhiyun if (!priv->rss_tables[ctx])
1494*4882a593Smuzhiyun break;
1495*4882a593Smuzhiyun }
1496*4882a593Smuzhiyun
1497*4882a593Smuzhiyun if (ctx == MVPP22_N_RSS_TABLES)
1498*4882a593Smuzhiyun return -EINVAL;
1499*4882a593Smuzhiyun
1500*4882a593Smuzhiyun priv->rss_tables[ctx] = kzalloc(sizeof(*priv->rss_tables[ctx]),
1501*4882a593Smuzhiyun GFP_KERNEL);
1502*4882a593Smuzhiyun if (!priv->rss_tables[ctx])
1503*4882a593Smuzhiyun return -ENOMEM;
1504*4882a593Smuzhiyun
1505*4882a593Smuzhiyun *rss_ctx = ctx;
1506*4882a593Smuzhiyun
1507*4882a593Smuzhiyun /* Set the table width: replace the whole classifier Rx queue number
1508*4882a593Smuzhiyun * with the ones configured in RSS table entries.
1509*4882a593Smuzhiyun */
1510*4882a593Smuzhiyun mvpp2_write(priv, MVPP22_RSS_INDEX, MVPP22_RSS_INDEX_TABLE(ctx));
1511*4882a593Smuzhiyun mvpp2_write(priv, MVPP22_RSS_WIDTH, 8);
1512*4882a593Smuzhiyun
1513*4882a593Smuzhiyun mvpp2_write(priv, MVPP22_RSS_INDEX, MVPP22_RSS_INDEX_QUEUE(ctx));
1514*4882a593Smuzhiyun mvpp2_write(priv, MVPP22_RXQ2RSS_TABLE, MVPP22_RSS_TABLE_POINTER(ctx));
1515*4882a593Smuzhiyun
1516*4882a593Smuzhiyun return 0;
1517*4882a593Smuzhiyun }
1518*4882a593Smuzhiyun
mvpp22_port_rss_ctx_create(struct mvpp2_port * port,u32 * port_ctx)1519*4882a593Smuzhiyun int mvpp22_port_rss_ctx_create(struct mvpp2_port *port, u32 *port_ctx)
1520*4882a593Smuzhiyun {
1521*4882a593Smuzhiyun u32 rss_ctx;
1522*4882a593Smuzhiyun int ret, i;
1523*4882a593Smuzhiyun
1524*4882a593Smuzhiyun ret = mvpp22_rss_context_create(port, &rss_ctx);
1525*4882a593Smuzhiyun if (ret)
1526*4882a593Smuzhiyun return ret;
1527*4882a593Smuzhiyun
1528*4882a593Smuzhiyun /* Find the first available context number in the port, starting from 1.
1529*4882a593Smuzhiyun * Context 0 on each port is reserved for the default context.
1530*4882a593Smuzhiyun */
1531*4882a593Smuzhiyun for (i = 1; i < MVPP22_N_RSS_TABLES; i++) {
1532*4882a593Smuzhiyun if (port->rss_ctx[i] < 0)
1533*4882a593Smuzhiyun break;
1534*4882a593Smuzhiyun }
1535*4882a593Smuzhiyun
1536*4882a593Smuzhiyun if (i == MVPP22_N_RSS_TABLES)
1537*4882a593Smuzhiyun return -EINVAL;
1538*4882a593Smuzhiyun
1539*4882a593Smuzhiyun port->rss_ctx[i] = rss_ctx;
1540*4882a593Smuzhiyun *port_ctx = i;
1541*4882a593Smuzhiyun
1542*4882a593Smuzhiyun return 0;
1543*4882a593Smuzhiyun }
1544*4882a593Smuzhiyun
mvpp22_rss_table_get(struct mvpp2 * priv,int rss_ctx)1545*4882a593Smuzhiyun static struct mvpp2_rss_table *mvpp22_rss_table_get(struct mvpp2 *priv,
1546*4882a593Smuzhiyun int rss_ctx)
1547*4882a593Smuzhiyun {
1548*4882a593Smuzhiyun if (rss_ctx < 0 || rss_ctx >= MVPP22_N_RSS_TABLES)
1549*4882a593Smuzhiyun return NULL;
1550*4882a593Smuzhiyun
1551*4882a593Smuzhiyun return priv->rss_tables[rss_ctx];
1552*4882a593Smuzhiyun }
1553*4882a593Smuzhiyun
mvpp22_port_rss_ctx_delete(struct mvpp2_port * port,u32 port_ctx)1554*4882a593Smuzhiyun int mvpp22_port_rss_ctx_delete(struct mvpp2_port *port, u32 port_ctx)
1555*4882a593Smuzhiyun {
1556*4882a593Smuzhiyun struct mvpp2 *priv = port->priv;
1557*4882a593Smuzhiyun struct ethtool_rxnfc *rxnfc;
1558*4882a593Smuzhiyun int i, rss_ctx, ret;
1559*4882a593Smuzhiyun
1560*4882a593Smuzhiyun rss_ctx = mvpp22_rss_ctx(port, port_ctx);
1561*4882a593Smuzhiyun
1562*4882a593Smuzhiyun if (rss_ctx < 0 || rss_ctx >= MVPP22_N_RSS_TABLES)
1563*4882a593Smuzhiyun return -EINVAL;
1564*4882a593Smuzhiyun
1565*4882a593Smuzhiyun /* Invalidate any active classification rule that use this context */
1566*4882a593Smuzhiyun for (i = 0; i < MVPP2_N_RFS_ENTRIES_PER_FLOW; i++) {
1567*4882a593Smuzhiyun if (!port->rfs_rules[i])
1568*4882a593Smuzhiyun continue;
1569*4882a593Smuzhiyun
1570*4882a593Smuzhiyun rxnfc = &port->rfs_rules[i]->rxnfc;
1571*4882a593Smuzhiyun if (!(rxnfc->fs.flow_type & FLOW_RSS) ||
1572*4882a593Smuzhiyun rxnfc->rss_context != port_ctx)
1573*4882a593Smuzhiyun continue;
1574*4882a593Smuzhiyun
1575*4882a593Smuzhiyun ret = mvpp2_ethtool_cls_rule_del(port, rxnfc);
1576*4882a593Smuzhiyun if (ret) {
1577*4882a593Smuzhiyun netdev_warn(port->dev,
1578*4882a593Smuzhiyun "couldn't remove classification rule %d associated to this context",
1579*4882a593Smuzhiyun rxnfc->fs.location);
1580*4882a593Smuzhiyun }
1581*4882a593Smuzhiyun }
1582*4882a593Smuzhiyun
1583*4882a593Smuzhiyun kfree(priv->rss_tables[rss_ctx]);
1584*4882a593Smuzhiyun
1585*4882a593Smuzhiyun priv->rss_tables[rss_ctx] = NULL;
1586*4882a593Smuzhiyun port->rss_ctx[port_ctx] = -1;
1587*4882a593Smuzhiyun
1588*4882a593Smuzhiyun return 0;
1589*4882a593Smuzhiyun }
1590*4882a593Smuzhiyun
mvpp22_port_rss_ctx_indir_set(struct mvpp2_port * port,u32 port_ctx,const u32 * indir)1591*4882a593Smuzhiyun int mvpp22_port_rss_ctx_indir_set(struct mvpp2_port *port, u32 port_ctx,
1592*4882a593Smuzhiyun const u32 *indir)
1593*4882a593Smuzhiyun {
1594*4882a593Smuzhiyun int rss_ctx = mvpp22_rss_ctx(port, port_ctx);
1595*4882a593Smuzhiyun struct mvpp2_rss_table *rss_table = mvpp22_rss_table_get(port->priv,
1596*4882a593Smuzhiyun rss_ctx);
1597*4882a593Smuzhiyun
1598*4882a593Smuzhiyun if (!rss_table)
1599*4882a593Smuzhiyun return -EINVAL;
1600*4882a593Smuzhiyun
1601*4882a593Smuzhiyun memcpy(rss_table->indir, indir,
1602*4882a593Smuzhiyun MVPP22_RSS_TABLE_ENTRIES * sizeof(rss_table->indir[0]));
1603*4882a593Smuzhiyun
1604*4882a593Smuzhiyun mvpp22_rss_fill_table(port, rss_table, rss_ctx);
1605*4882a593Smuzhiyun
1606*4882a593Smuzhiyun return 0;
1607*4882a593Smuzhiyun }
1608*4882a593Smuzhiyun
mvpp22_port_rss_ctx_indir_get(struct mvpp2_port * port,u32 port_ctx,u32 * indir)1609*4882a593Smuzhiyun int mvpp22_port_rss_ctx_indir_get(struct mvpp2_port *port, u32 port_ctx,
1610*4882a593Smuzhiyun u32 *indir)
1611*4882a593Smuzhiyun {
1612*4882a593Smuzhiyun int rss_ctx = mvpp22_rss_ctx(port, port_ctx);
1613*4882a593Smuzhiyun struct mvpp2_rss_table *rss_table = mvpp22_rss_table_get(port->priv,
1614*4882a593Smuzhiyun rss_ctx);
1615*4882a593Smuzhiyun
1616*4882a593Smuzhiyun if (!rss_table)
1617*4882a593Smuzhiyun return -EINVAL;
1618*4882a593Smuzhiyun
1619*4882a593Smuzhiyun memcpy(indir, rss_table->indir,
1620*4882a593Smuzhiyun MVPP22_RSS_TABLE_ENTRIES * sizeof(rss_table->indir[0]));
1621*4882a593Smuzhiyun
1622*4882a593Smuzhiyun return 0;
1623*4882a593Smuzhiyun }
1624*4882a593Smuzhiyun
mvpp2_ethtool_rxfh_set(struct mvpp2_port * port,struct ethtool_rxnfc * info)1625*4882a593Smuzhiyun int mvpp2_ethtool_rxfh_set(struct mvpp2_port *port, struct ethtool_rxnfc *info)
1626*4882a593Smuzhiyun {
1627*4882a593Smuzhiyun u16 hash_opts = 0;
1628*4882a593Smuzhiyun u32 flow_type;
1629*4882a593Smuzhiyun
1630*4882a593Smuzhiyun flow_type = mvpp2_cls_ethtool_flow_to_type(info->flow_type);
1631*4882a593Smuzhiyun
1632*4882a593Smuzhiyun switch (flow_type) {
1633*4882a593Smuzhiyun case MVPP22_FLOW_TCP4:
1634*4882a593Smuzhiyun case MVPP22_FLOW_UDP4:
1635*4882a593Smuzhiyun case MVPP22_FLOW_TCP6:
1636*4882a593Smuzhiyun case MVPP22_FLOW_UDP6:
1637*4882a593Smuzhiyun if (info->data & RXH_L4_B_0_1)
1638*4882a593Smuzhiyun hash_opts |= MVPP22_CLS_HEK_OPT_L4SIP;
1639*4882a593Smuzhiyun if (info->data & RXH_L4_B_2_3)
1640*4882a593Smuzhiyun hash_opts |= MVPP22_CLS_HEK_OPT_L4DIP;
1641*4882a593Smuzhiyun fallthrough;
1642*4882a593Smuzhiyun case MVPP22_FLOW_IP4:
1643*4882a593Smuzhiyun case MVPP22_FLOW_IP6:
1644*4882a593Smuzhiyun if (info->data & RXH_L2DA)
1645*4882a593Smuzhiyun hash_opts |= MVPP22_CLS_HEK_OPT_MAC_DA;
1646*4882a593Smuzhiyun if (info->data & RXH_VLAN)
1647*4882a593Smuzhiyun hash_opts |= MVPP22_CLS_HEK_OPT_VLAN;
1648*4882a593Smuzhiyun if (info->data & RXH_L3_PROTO)
1649*4882a593Smuzhiyun hash_opts |= MVPP22_CLS_HEK_OPT_L3_PROTO;
1650*4882a593Smuzhiyun if (info->data & RXH_IP_SRC)
1651*4882a593Smuzhiyun hash_opts |= (MVPP22_CLS_HEK_OPT_IP4SA |
1652*4882a593Smuzhiyun MVPP22_CLS_HEK_OPT_IP6SA);
1653*4882a593Smuzhiyun if (info->data & RXH_IP_DST)
1654*4882a593Smuzhiyun hash_opts |= (MVPP22_CLS_HEK_OPT_IP4DA |
1655*4882a593Smuzhiyun MVPP22_CLS_HEK_OPT_IP6DA);
1656*4882a593Smuzhiyun break;
1657*4882a593Smuzhiyun default: return -EOPNOTSUPP;
1658*4882a593Smuzhiyun }
1659*4882a593Smuzhiyun
1660*4882a593Smuzhiyun return mvpp2_port_rss_hash_opts_set(port, flow_type, hash_opts);
1661*4882a593Smuzhiyun }
1662*4882a593Smuzhiyun
mvpp2_ethtool_rxfh_get(struct mvpp2_port * port,struct ethtool_rxnfc * info)1663*4882a593Smuzhiyun int mvpp2_ethtool_rxfh_get(struct mvpp2_port *port, struct ethtool_rxnfc *info)
1664*4882a593Smuzhiyun {
1665*4882a593Smuzhiyun unsigned long hash_opts;
1666*4882a593Smuzhiyun u32 flow_type;
1667*4882a593Smuzhiyun int i;
1668*4882a593Smuzhiyun
1669*4882a593Smuzhiyun flow_type = mvpp2_cls_ethtool_flow_to_type(info->flow_type);
1670*4882a593Smuzhiyun
1671*4882a593Smuzhiyun hash_opts = mvpp2_port_rss_hash_opts_get(port, flow_type);
1672*4882a593Smuzhiyun info->data = 0;
1673*4882a593Smuzhiyun
1674*4882a593Smuzhiyun for_each_set_bit(i, &hash_opts, MVPP22_CLS_HEK_N_FIELDS) {
1675*4882a593Smuzhiyun switch (BIT(i)) {
1676*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_MAC_DA:
1677*4882a593Smuzhiyun info->data |= RXH_L2DA;
1678*4882a593Smuzhiyun break;
1679*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_VLAN:
1680*4882a593Smuzhiyun info->data |= RXH_VLAN;
1681*4882a593Smuzhiyun break;
1682*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_L3_PROTO:
1683*4882a593Smuzhiyun info->data |= RXH_L3_PROTO;
1684*4882a593Smuzhiyun break;
1685*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_IP4SA:
1686*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_IP6SA:
1687*4882a593Smuzhiyun info->data |= RXH_IP_SRC;
1688*4882a593Smuzhiyun break;
1689*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_IP4DA:
1690*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_IP6DA:
1691*4882a593Smuzhiyun info->data |= RXH_IP_DST;
1692*4882a593Smuzhiyun break;
1693*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_L4SIP:
1694*4882a593Smuzhiyun info->data |= RXH_L4_B_0_1;
1695*4882a593Smuzhiyun break;
1696*4882a593Smuzhiyun case MVPP22_CLS_HEK_OPT_L4DIP:
1697*4882a593Smuzhiyun info->data |= RXH_L4_B_2_3;
1698*4882a593Smuzhiyun break;
1699*4882a593Smuzhiyun default:
1700*4882a593Smuzhiyun return -EINVAL;
1701*4882a593Smuzhiyun }
1702*4882a593Smuzhiyun }
1703*4882a593Smuzhiyun return 0;
1704*4882a593Smuzhiyun }
1705*4882a593Smuzhiyun
mvpp22_port_rss_init(struct mvpp2_port * port)1706*4882a593Smuzhiyun int mvpp22_port_rss_init(struct mvpp2_port *port)
1707*4882a593Smuzhiyun {
1708*4882a593Smuzhiyun struct mvpp2_rss_table *table;
1709*4882a593Smuzhiyun u32 context = 0;
1710*4882a593Smuzhiyun int i, ret;
1711*4882a593Smuzhiyun
1712*4882a593Smuzhiyun for (i = 0; i < MVPP22_N_RSS_TABLES; i++)
1713*4882a593Smuzhiyun port->rss_ctx[i] = -1;
1714*4882a593Smuzhiyun
1715*4882a593Smuzhiyun ret = mvpp22_rss_context_create(port, &context);
1716*4882a593Smuzhiyun if (ret)
1717*4882a593Smuzhiyun return ret;
1718*4882a593Smuzhiyun
1719*4882a593Smuzhiyun table = mvpp22_rss_table_get(port->priv, context);
1720*4882a593Smuzhiyun if (!table)
1721*4882a593Smuzhiyun return -EINVAL;
1722*4882a593Smuzhiyun
1723*4882a593Smuzhiyun port->rss_ctx[0] = context;
1724*4882a593Smuzhiyun
1725*4882a593Smuzhiyun /* Configure the first table to evenly distribute the packets across
1726*4882a593Smuzhiyun * real Rx Queues. The table entries map a hash to a port Rx Queue.
1727*4882a593Smuzhiyun */
1728*4882a593Smuzhiyun for (i = 0; i < MVPP22_RSS_TABLE_ENTRIES; i++)
1729*4882a593Smuzhiyun table->indir[i] = ethtool_rxfh_indir_default(i, port->nrxqs);
1730*4882a593Smuzhiyun
1731*4882a593Smuzhiyun mvpp22_rss_fill_table(port, table, mvpp22_rss_ctx(port, 0));
1732*4882a593Smuzhiyun
1733*4882a593Smuzhiyun /* Configure default flows */
1734*4882a593Smuzhiyun mvpp2_port_rss_hash_opts_set(port, MVPP22_FLOW_IP4, MVPP22_CLS_HEK_IP4_2T);
1735*4882a593Smuzhiyun mvpp2_port_rss_hash_opts_set(port, MVPP22_FLOW_IP6, MVPP22_CLS_HEK_IP6_2T);
1736*4882a593Smuzhiyun mvpp2_port_rss_hash_opts_set(port, MVPP22_FLOW_TCP4, MVPP22_CLS_HEK_IP4_5T);
1737*4882a593Smuzhiyun mvpp2_port_rss_hash_opts_set(port, MVPP22_FLOW_TCP6, MVPP22_CLS_HEK_IP6_5T);
1738*4882a593Smuzhiyun mvpp2_port_rss_hash_opts_set(port, MVPP22_FLOW_UDP4, MVPP22_CLS_HEK_IP4_5T);
1739*4882a593Smuzhiyun mvpp2_port_rss_hash_opts_set(port, MVPP22_FLOW_UDP6, MVPP22_CLS_HEK_IP6_5T);
1740*4882a593Smuzhiyun
1741*4882a593Smuzhiyun return 0;
1742*4882a593Smuzhiyun }
1743