1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * RSS and Classifier definitions for Marvell PPv2 Network Controller
4  *
5  * Copyright (C) 2014 Marvell
6  *
7  * Marcin Wojtas <mw@semihalf.com>
8  */
9 
10 #ifndef _MVPP2_CLS_H_
11 #define _MVPP2_CLS_H_
12 
13 #include "mvpp2.h"
14 #include "mvpp2_prs.h"
15 
16 /* Classifier constants */
17 #define MVPP2_CLS_FLOWS_TBL_SIZE	512
18 #define MVPP2_CLS_FLOWS_TBL_DATA_WORDS	3
19 #define MVPP2_CLS_LKP_TBL_SIZE		64
20 #define MVPP2_CLS_RX_QUEUES		256
21 
22 /* Classifier flow constants */
23 
24 #define MVPP2_FLOW_N_FIELDS		4
25 
26 enum mvpp2_cls_engine {
27 	MVPP22_CLS_ENGINE_C2 = 1,
28 	MVPP22_CLS_ENGINE_C3A,
29 	MVPP22_CLS_ENGINE_C3B,
30 	MVPP22_CLS_ENGINE_C4,
31 	MVPP22_CLS_ENGINE_C3HA = 6,
32 	MVPP22_CLS_ENGINE_C3HB = 7,
33 };
34 
35 #define MVPP22_CLS_HEK_OPT_MAC_DA	BIT(0)
36 #define MVPP22_CLS_HEK_OPT_VLAN		BIT(1)
37 #define MVPP22_CLS_HEK_OPT_L3_PROTO	BIT(2)
38 #define MVPP22_CLS_HEK_OPT_IP4SA	BIT(3)
39 #define MVPP22_CLS_HEK_OPT_IP4DA	BIT(4)
40 #define MVPP22_CLS_HEK_OPT_IP6SA	BIT(5)
41 #define MVPP22_CLS_HEK_OPT_IP6DA	BIT(6)
42 #define MVPP22_CLS_HEK_OPT_L4SIP	BIT(7)
43 #define MVPP22_CLS_HEK_OPT_L4DIP	BIT(8)
44 #define MVPP22_CLS_HEK_N_FIELDS		9
45 
46 #define MVPP22_CLS_HEK_L4_OPTS	(MVPP22_CLS_HEK_OPT_L4SIP | \
47 				 MVPP22_CLS_HEK_OPT_L4DIP)
48 
49 #define MVPP22_CLS_HEK_IP4_2T	(MVPP22_CLS_HEK_OPT_IP4SA | \
50 				 MVPP22_CLS_HEK_OPT_IP4DA)
51 
52 #define MVPP22_CLS_HEK_IP6_2T	(MVPP22_CLS_HEK_OPT_IP6SA | \
53 				 MVPP22_CLS_HEK_OPT_IP6DA)
54 
55 /* The fifth tuple in "5T" is the L4_Info field */
56 #define MVPP22_CLS_HEK_IP4_5T	(MVPP22_CLS_HEK_IP4_2T | \
57 				 MVPP22_CLS_HEK_L4_OPTS)
58 
59 #define MVPP22_CLS_HEK_IP6_5T	(MVPP22_CLS_HEK_IP6_2T | \
60 				 MVPP22_CLS_HEK_L4_OPTS)
61 
62 enum mvpp2_cls_field_id {
63 	MVPP22_CLS_FIELD_MAC_DA = 0x03,
64 	MVPP22_CLS_FIELD_VLAN = 0x06,
65 	MVPP22_CLS_FIELD_L3_PROTO = 0x0f,
66 	MVPP22_CLS_FIELD_IP4SA = 0x10,
67 	MVPP22_CLS_FIELD_IP4DA = 0x11,
68 	MVPP22_CLS_FIELD_IP6SA = 0x17,
69 	MVPP22_CLS_FIELD_IP6DA = 0x1a,
70 	MVPP22_CLS_FIELD_L4SIP = 0x1d,
71 	MVPP22_CLS_FIELD_L4DIP = 0x1e,
72 };
73 
74 /* Classifier C2 engine constants */
75 #define MVPP22_CLS_C2_TCAM_EN(data)		((data) << 16)
76 
77 enum mvpp22_cls_c2_action {
78 	MVPP22_C2_NO_UPD = 0,
79 	MVPP22_C2_NO_UPD_LOCK,
80 	MVPP22_C2_UPD,
81 	MVPP22_C2_UPD_LOCK,
82 };
83 
84 enum mvpp22_cls_c2_fwd_action {
85 	MVPP22_C2_FWD_NO_UPD = 0,
86 	MVPP22_C2_FWD_NO_UPD_LOCK,
87 	MVPP22_C2_FWD_SW,
88 	MVPP22_C2_FWD_SW_LOCK,
89 	MVPP22_C2_FWD_HW,
90 	MVPP22_C2_FWD_HW_LOCK,
91 	MVPP22_C2_FWD_HW_LOW_LAT,
92 	MVPP22_C2_FWD_HW_LOW_LAT_LOCK,
93 };
94 
95 #define MVPP2_CLS_C2_TCAM_WORDS			5
96 #define MVPP2_CLS_C2_ATTR_WORDS			5
97 
98 struct mvpp2_cls_c2_entry {
99 	u32 index;
100 	/* TCAM lookup key */
101 	u32 tcam[MVPP2_CLS_C2_TCAM_WORDS];
102 	/* Actions to perform upon TCAM match */
103 	u32 act;
104 	/* Attributes relative to the actions to perform */
105 	u32 attr[MVPP2_CLS_C2_ATTR_WORDS];
106 	/* Entry validity */
107 	u8 valid;
108 };
109 
110 /* Classifier C2 engine entries */
111 #define MVPP22_CLS_C2_N_ENTRIES		256
112 
113 /* Number of per-port dedicated entries in the C2 TCAM */
114 #define MVPP22_CLS_C2_PORT_RANGE	8
115 
116 #define MVPP22_CLS_C2_PORT_FIRST(p)	(MVPP22_CLS_C2_N_ENTRIES - \
117 					((p) * MVPP22_CLS_C2_PORT_RANGE))
118 #define MVPP22_CLS_C2_RSS_ENTRY(p)	(MVPP22_CLS_C2_PORT_FIRST(p) - 1)
119 
120 /* Packet flow ID */
121 enum mvpp2_prs_flow {
122 	MVPP2_FL_START = 8,
123 	MVPP2_FL_IP4_TCP_NF_UNTAG = MVPP2_FL_START,
124 	MVPP2_FL_IP4_UDP_NF_UNTAG,
125 	MVPP2_FL_IP4_TCP_NF_TAG,
126 	MVPP2_FL_IP4_UDP_NF_TAG,
127 	MVPP2_FL_IP6_TCP_NF_UNTAG,
128 	MVPP2_FL_IP6_UDP_NF_UNTAG,
129 	MVPP2_FL_IP6_TCP_NF_TAG,
130 	MVPP2_FL_IP6_UDP_NF_TAG,
131 	MVPP2_FL_IP4_TCP_FRAG_UNTAG,
132 	MVPP2_FL_IP4_UDP_FRAG_UNTAG,
133 	MVPP2_FL_IP4_TCP_FRAG_TAG,
134 	MVPP2_FL_IP4_UDP_FRAG_TAG,
135 	MVPP2_FL_IP6_TCP_FRAG_UNTAG,
136 	MVPP2_FL_IP6_UDP_FRAG_UNTAG,
137 	MVPP2_FL_IP6_TCP_FRAG_TAG,
138 	MVPP2_FL_IP6_UDP_FRAG_TAG,
139 	MVPP2_FL_IP4_UNTAG, /* non-TCP, non-UDP, same for below */
140 	MVPP2_FL_IP4_TAG,
141 	MVPP2_FL_IP6_UNTAG,
142 	MVPP2_FL_IP6_TAG,
143 	MVPP2_FL_NON_IP_UNTAG,
144 	MVPP2_FL_NON_IP_TAG,
145 	MVPP2_FL_LAST,
146 };
147 
148 enum mvpp2_cls_lu_type {
149 	MVPP2_CLS_LU_ALL = 0,
150 };
151 
152 /* LU Type defined for all engines, and specified in the flow table */
153 #define MVPP2_CLS_LU_TYPE_MASK			0x3f
154 
155 #define MVPP2_N_FLOWS		(MVPP2_FL_LAST - MVPP2_FL_START)
156 
157 struct mvpp2_cls_flow {
158 	/* The L2-L4 traffic flow type */
159 	int flow_type;
160 
161 	/* The first id in the flow table for this flow */
162 	u16 flow_id;
163 
164 	/* The supported HEK fields for this flow */
165 	u16 supported_hash_opts;
166 
167 	/* The Header Parser result_info that matches this flow */
168 	struct mvpp2_prs_result_info prs_ri;
169 };
170 
171 #define MVPP2_CLS_FLT_ENTRIES_PER_FLOW		(MVPP2_MAX_PORTS + 1)
172 #define MVPP2_CLS_FLT_FIRST(id)			(((id) - MVPP2_FL_START) * \
173 						 MVPP2_CLS_FLT_ENTRIES_PER_FLOW)
174 #define MVPP2_CLS_FLT_C2_RSS_ENTRY(id)		(MVPP2_CLS_FLT_FIRST(id))
175 #define MVPP2_CLS_FLT_HASH_ENTRY(port, id)	(MVPP2_CLS_FLT_C2_RSS_ENTRY(id) + (port) + 1)
176 #define MVPP2_CLS_FLT_LAST(id)			(MVPP2_CLS_FLT_FIRST(id) + \
177 						 MVPP2_CLS_FLT_ENTRIES_PER_FLOW - 1)
178 
179 /* Iterate on each classifier flow id. Sets 'i' to be the index of the first
180  * entry in the cls_flows table for each different flow_id.
181  * This relies on entries having the same flow_id in the cls_flows table being
182  * contiguous.
183  */
184 #define for_each_cls_flow_id(i)						      \
185 	for ((i) = 0; (i) < MVPP2_N_PRS_FLOWS; (i)++)			      \
186 		if ((i) > 0 &&						      \
187 		    cls_flows[(i)].flow_id == cls_flows[(i) - 1].flow_id)       \
188 			continue;					      \
189 		else
190 
191 /* Iterate on each classifier flow that has a given flow_type. Sets 'i' to be
192  * the index of the first entry in the cls_flow table for each different flow_id
193  * that has the given flow_type. This allows to operate on all flows that
194  * matches a given ethtool flow type.
195  */
196 #define for_each_cls_flow_id_with_type(i, type)				      \
197 	for_each_cls_flow_id((i))					      \
198 		if (cls_flows[(i)].flow_type != (type))			      \
199 			continue;					      \
200 		else
201 
202 struct mvpp2_cls_flow_entry {
203 	u32 index;
204 	u32 data[MVPP2_CLS_FLOWS_TBL_DATA_WORDS];
205 };
206 
207 struct mvpp2_cls_lookup_entry {
208 	u32 lkpid;
209 	u32 way;
210 	u32 data;
211 };
212 
213 void mvpp22_rss_fill_table(struct mvpp2_port *port, u32 table);
214 void mvpp22_port_rss_init(struct mvpp2_port *port);
215 
216 void mvpp22_port_rss_enable(struct mvpp2_port *port);
217 void mvpp22_port_rss_disable(struct mvpp2_port *port);
218 
219 int mvpp2_ethtool_rxfh_get(struct mvpp2_port *port, struct ethtool_rxnfc *info);
220 int mvpp2_ethtool_rxfh_set(struct mvpp2_port *port, struct ethtool_rxnfc *info);
221 
222 void mvpp2_cls_init(struct mvpp2 *priv);
223 
224 void mvpp2_cls_port_config(struct mvpp2_port *port);
225 
226 void mvpp2_cls_oversize_rxq_set(struct mvpp2_port *port);
227 
228 int mvpp2_cls_flow_eng_get(struct mvpp2_cls_flow_entry *fe);
229 
230 u16 mvpp2_flow_get_hek_fields(struct mvpp2_cls_flow_entry *fe);
231 
232 const struct mvpp2_cls_flow *mvpp2_cls_flow_get(int flow);
233 
234 u32 mvpp2_cls_flow_hits(struct mvpp2 *priv, int index);
235 
236 void mvpp2_cls_flow_read(struct mvpp2 *priv, int index,
237 			 struct mvpp2_cls_flow_entry *fe);
238 
239 u32 mvpp2_cls_lookup_hits(struct mvpp2 *priv, int index);
240 
241 void mvpp2_cls_lookup_read(struct mvpp2 *priv, int lkpid, int way,
242 			   struct mvpp2_cls_lookup_entry *le);
243 
244 u32 mvpp2_cls_c2_hit_count(struct mvpp2 *priv, int c2_index);
245 
246 void mvpp2_cls_c2_read(struct mvpp2 *priv, int index,
247 		       struct mvpp2_cls_c2_entry *c2);
248 
249 #endif
250