summaryrefslogtreecommitdiff
path: root/drivers/net/ethernet/microchip/sparx5/sparx5_vcap_debugfs.c
blob: 07b472c84a47c9b10da492364d6c3a3cfbe3b289 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
// SPDX-License-Identifier: GPL-2.0+
/* Microchip Sparx5 Switch driver VCAP debugFS implementation
 *
 * Copyright (c) 2022 Microchip Technology Inc. and its subsidiaries.
 */

#include <linux/types.h>
#include <linux/list.h>

#include "sparx5_vcap_debugfs.h"
#include "sparx5_main_regs.h"
#include "sparx5_main.h"
#include "sparx5_vcap_impl.h"
#include "sparx5_vcap_ag_api.h"

static const char *sparx5_vcap_is0_etype_str(u32 value)
{
	switch (value) {
	case VCAP_IS0_PS_ETYPE_DEFAULT:
		return "default";
	case VCAP_IS0_PS_ETYPE_NORMAL_7TUPLE:
		return "normal_7tuple";
	case VCAP_IS0_PS_ETYPE_NORMAL_5TUPLE_IP4:
		return "normal_5tuple_ip4";
	case VCAP_IS0_PS_ETYPE_MLL:
		return "mll";
	case VCAP_IS0_PS_ETYPE_LL_FULL:
		return "ll_full";
	case VCAP_IS0_PS_ETYPE_PURE_5TUPLE_IP4:
		return "pure_5tuple_ip4";
	case VCAP_IS0_PS_ETYPE_ETAG:
		return "etag";
	case VCAP_IS0_PS_ETYPE_NO_LOOKUP:
		return "no lookup";
	default:
		return "unknown";
	}
}

static const char *sparx5_vcap_is0_mpls_str(u32 value)
{
	switch (value) {
	case VCAP_IS0_PS_MPLS_FOLLOW_ETYPE:
		return "follow_etype";
	case VCAP_IS0_PS_MPLS_NORMAL_7TUPLE:
		return "normal_7tuple";
	case VCAP_IS0_PS_MPLS_NORMAL_5TUPLE_IP4:
		return "normal_5tuple_ip4";
	case VCAP_IS0_PS_MPLS_MLL:
		return "mll";
	case VCAP_IS0_PS_MPLS_LL_FULL:
		return "ll_full";
	case VCAP_IS0_PS_MPLS_PURE_5TUPLE_IP4:
		return "pure_5tuple_ip4";
	case VCAP_IS0_PS_MPLS_ETAG:
		return "etag";
	case VCAP_IS0_PS_MPLS_NO_LOOKUP:
		return "no lookup";
	default:
		return "unknown";
	}
}

static const char *sparx5_vcap_is0_mlbs_str(u32 value)
{
	switch (value) {
	case VCAP_IS0_PS_MLBS_FOLLOW_ETYPE:
		return "follow_etype";
	case VCAP_IS0_PS_MLBS_NO_LOOKUP:
		return "no lookup";
	default:
		return "unknown";
	}
}

static void sparx5_vcap_is0_port_keys(struct sparx5 *sparx5,
				      struct vcap_admin *admin,
				      struct sparx5_port *port,
				      struct vcap_output_print *out)
{
	int lookup;
	u32 value, val;

	out->prf(out->dst, "  port[%02d] (%s): ", port->portno,
		 netdev_name(port->ndev));
	for (lookup = 0; lookup < admin->lookups; ++lookup) {
		out->prf(out->dst, "\n    Lookup %d: ", lookup);

		/* Get lookup state */
		value = spx5_rd(sparx5,
				ANA_CL_ADV_CL_CFG(port->portno, lookup));
		out->prf(out->dst, "\n      state: ");
		if (ANA_CL_ADV_CL_CFG_LOOKUP_ENA_GET(value))
			out->prf(out->dst, "on");
		else
			out->prf(out->dst, "off");
		val = ANA_CL_ADV_CL_CFG_ETYPE_CLM_KEY_SEL_GET(value);
		out->prf(out->dst, "\n      etype: %s",
			 sparx5_vcap_is0_etype_str(val));
		val = ANA_CL_ADV_CL_CFG_IP4_CLM_KEY_SEL_GET(value);
		out->prf(out->dst, "\n      ipv4: %s",
			 sparx5_vcap_is0_etype_str(val));
		val = ANA_CL_ADV_CL_CFG_IP6_CLM_KEY_SEL_GET(value);
		out->prf(out->dst, "\n      ipv6: %s",
			 sparx5_vcap_is0_etype_str(val));
		val = ANA_CL_ADV_CL_CFG_MPLS_UC_CLM_KEY_SEL_GET(value);
		out->prf(out->dst, "\n      mpls_uc: %s",
			 sparx5_vcap_is0_mpls_str(val));
		val = ANA_CL_ADV_CL_CFG_MPLS_MC_CLM_KEY_SEL_GET(value);
		out->prf(out->dst, "\n      mpls_mc: %s",
			 sparx5_vcap_is0_mpls_str(val));
		val = ANA_CL_ADV_CL_CFG_MLBS_CLM_KEY_SEL_GET(value);
		out->prf(out->dst, "\n      mlbs: %s",
			 sparx5_vcap_is0_mlbs_str(val));
	}
	out->prf(out->dst, "\n");
}

static void sparx5_vcap_is2_port_keys(struct sparx5 *sparx5,
				      struct vcap_admin *admin,
				      struct sparx5_port *port,
				      struct vcap_output_print *out)
{
	int lookup;
	u32 value;

	out->prf(out->dst, "  port[%02d] (%s): ", port->portno,
	   netdev_name(port->ndev));
	for (lookup = 0; lookup < admin->lookups; ++lookup) {
		out->prf(out->dst, "\n    Lookup %d: ", lookup);

		/* Get lookup state */
		value = spx5_rd(sparx5, ANA_ACL_VCAP_S2_CFG(port->portno));
		out->prf(out->dst, "\n      state: ");
		if (ANA_ACL_VCAP_S2_CFG_SEC_ENA_GET(value) & BIT(lookup))
			out->prf(out->dst, "on");
		else
			out->prf(out->dst, "off");

		/* Get key selection state */
		value = spx5_rd(sparx5,
				ANA_ACL_VCAP_S2_KEY_SEL(port->portno, lookup));

		out->prf(out->dst, "\n      noneth: ");
		switch (ANA_ACL_VCAP_S2_KEY_SEL_NON_ETH_KEY_SEL_GET(value)) {
		case VCAP_IS2_PS_NONETH_MAC_ETYPE:
			out->prf(out->dst, "mac_etype");
			break;
		case VCAP_IS2_PS_NONETH_CUSTOM_1:
			out->prf(out->dst, "custom1");
			break;
		case VCAP_IS2_PS_NONETH_CUSTOM_2:
			out->prf(out->dst, "custom2");
			break;
		case VCAP_IS2_PS_NONETH_NO_LOOKUP:
			out->prf(out->dst, "none");
			break;
		}
		out->prf(out->dst, "\n      ipv4_mc: ");
		switch (ANA_ACL_VCAP_S2_KEY_SEL_IP4_MC_KEY_SEL_GET(value)) {
		case VCAP_IS2_PS_IPV4_MC_MAC_ETYPE:
			out->prf(out->dst, "mac_etype");
			break;
		case VCAP_IS2_PS_IPV4_MC_IP4_TCP_UDP_OTHER:
			out->prf(out->dst, "ip4_tcp_udp ip4_other");
			break;
		case VCAP_IS2_PS_IPV4_MC_IP_7TUPLE:
			out->prf(out->dst, "ip_7tuple");
			break;
		case VCAP_IS2_PS_IPV4_MC_IP4_VID:
			out->prf(out->dst, "ip4_vid");
			break;
		}
		out->prf(out->dst, "\n      ipv4_uc: ");
		switch (ANA_ACL_VCAP_S2_KEY_SEL_IP4_UC_KEY_SEL_GET(value)) {
		case VCAP_IS2_PS_IPV4_UC_MAC_ETYPE:
			out->prf(out->dst, "mac_etype");
			break;
		case VCAP_IS2_PS_IPV4_UC_IP4_TCP_UDP_OTHER:
			out->prf(out->dst, "ip4_tcp_udp ip4_other");
			break;
		case VCAP_IS2_PS_IPV4_UC_IP_7TUPLE:
			out->prf(out->dst, "ip_7tuple");
			break;
		}
		out->prf(out->dst, "\n      ipv6_mc: ");
		switch (ANA_ACL_VCAP_S2_KEY_SEL_IP6_MC_KEY_SEL_GET(value)) {
		case VCAP_IS2_PS_IPV6_MC_MAC_ETYPE:
			out->prf(out->dst, "mac_etype");
			break;
		case VCAP_IS2_PS_IPV6_MC_IP_7TUPLE:
			out->prf(out->dst, "ip_7tuple");
			break;
		case VCAP_IS2_PS_IPV6_MC_IP6_VID:
			out->prf(out->dst, "ip6_vid");
			break;
		case VCAP_IS2_PS_IPV6_MC_IP6_STD:
			out->prf(out->dst, "ip6_std");
			break;
		case VCAP_IS2_PS_IPV6_MC_IP4_TCP_UDP_OTHER:
			out->prf(out->dst, "ip4_tcp_udp ipv4_other");
			break;
		}
		out->prf(out->dst, "\n      ipv6_uc: ");
		switch (ANA_ACL_VCAP_S2_KEY_SEL_IP6_UC_KEY_SEL_GET(value)) {
		case VCAP_IS2_PS_IPV6_UC_MAC_ETYPE:
			out->prf(out->dst, "mac_etype");
			break;
		case VCAP_IS2_PS_IPV6_UC_IP_7TUPLE:
			out->prf(out->dst, "ip_7tuple");
			break;
		case VCAP_IS2_PS_IPV6_UC_IP6_STD:
			out->prf(out->dst, "ip6_std");
			break;
		case VCAP_IS2_PS_IPV6_UC_IP4_TCP_UDP_OTHER:
			out->prf(out->dst, "ip4_tcp_udp ip4_other");
			break;
		}
		out->prf(out->dst, "\n      arp: ");
		switch (ANA_ACL_VCAP_S2_KEY_SEL_ARP_KEY_SEL_GET(value)) {
		case VCAP_IS2_PS_ARP_MAC_ETYPE:
			out->prf(out->dst, "mac_etype");
			break;
		case VCAP_IS2_PS_ARP_ARP:
			out->prf(out->dst, "arp");
			break;
		}
	}
	out->prf(out->dst, "\n");
}

static void sparx5_vcap_is2_port_stickies(struct sparx5 *sparx5,
					  struct vcap_admin *admin,
					  struct vcap_output_print *out)
{
	int lookup;
	u32 value;

	out->prf(out->dst, "  Sticky bits: ");
	for (lookup = 0; lookup < admin->lookups; ++lookup) {
		out->prf(out->dst, "\n    Lookup %d: ", lookup);
		/* Get lookup sticky bits */
		value = spx5_rd(sparx5, ANA_ACL_SEC_LOOKUP_STICKY(lookup));

		if (ANA_ACL_SEC_LOOKUP_STICKY_KEY_SEL_CLM_STICKY_GET(value))
			out->prf(out->dst, " sel_clm");
		if (ANA_ACL_SEC_LOOKUP_STICKY_KEY_SEL_IRLEG_STICKY_GET(value))
			out->prf(out->dst, " sel_irleg");
		if (ANA_ACL_SEC_LOOKUP_STICKY_KEY_SEL_ERLEG_STICKY_GET(value))
			out->prf(out->dst, " sel_erleg");
		if (ANA_ACL_SEC_LOOKUP_STICKY_KEY_SEL_PORT_STICKY_GET(value))
			out->prf(out->dst, " sel_port");
		if (ANA_ACL_SEC_LOOKUP_STICKY_SEC_TYPE_CUSTOM2_STICKY_GET(value))
			out->prf(out->dst, " custom2");
		if (ANA_ACL_SEC_LOOKUP_STICKY_SEC_TYPE_CUSTOM1_STICKY_GET(value))
			out->prf(out->dst, " custom1");
		if (ANA_ACL_SEC_LOOKUP_STICKY_SEC_TYPE_OAM_STICKY_GET(value))
			out->prf(out->dst, " oam");
		if (ANA_ACL_SEC_LOOKUP_STICKY_SEC_TYPE_IP6_VID_STICKY_GET(value))
			out->prf(out->dst, " ip6_vid");
		if (ANA_ACL_SEC_LOOKUP_STICKY_SEC_TYPE_IP6_STD_STICKY_GET(value))
			out->prf(out->dst, " ip6_std");
		if (ANA_ACL_SEC_LOOKUP_STICKY_SEC_TYPE_IP6_TCPUDP_STICKY_GET(value))
			out->prf(out->dst, " ip6_tcpudp");
		if (ANA_ACL_SEC_LOOKUP_STICKY_SEC_TYPE_IP_7TUPLE_STICKY_GET(value))
			out->prf(out->dst, " ip_7tuple");
		if (ANA_ACL_SEC_LOOKUP_STICKY_SEC_TYPE_IP4_VID_STICKY_GET(value))
			out->prf(out->dst, " ip4_vid");
		if (ANA_ACL_SEC_LOOKUP_STICKY_SEC_TYPE_IP4_TCPUDP_STICKY_GET(value))
			out->prf(out->dst, " ip4_tcpudp");
		if (ANA_ACL_SEC_LOOKUP_STICKY_SEC_TYPE_IP4_OTHER_STICKY_GET(value))
			out->prf(out->dst, " ip4_other");
		if (ANA_ACL_SEC_LOOKUP_STICKY_SEC_TYPE_ARP_STICKY_GET(value))
			out->prf(out->dst, " arp");
		if (ANA_ACL_SEC_LOOKUP_STICKY_SEC_TYPE_MAC_SNAP_STICKY_GET(value))
			out->prf(out->dst, " mac_snap");
		if (ANA_ACL_SEC_LOOKUP_STICKY_SEC_TYPE_MAC_LLC_STICKY_GET(value))
			out->prf(out->dst, " mac_llc");
		if (ANA_ACL_SEC_LOOKUP_STICKY_SEC_TYPE_MAC_ETYPE_STICKY_GET(value))
			out->prf(out->dst, " mac_etype");
		/* Clear stickies */
		spx5_wr(value, sparx5, ANA_ACL_SEC_LOOKUP_STICKY(lookup));
	}
	out->prf(out->dst, "\n");
}

static void sparx5_vcap_es0_port_keys(struct sparx5 *sparx5,
				      struct vcap_admin *admin,
				      struct sparx5_port *port,
				      struct vcap_output_print *out)
{
	u32 value;

	out->prf(out->dst, "  port[%02d] (%s): ", port->portno,
		 netdev_name(port->ndev));
	out->prf(out->dst, "\n    Lookup 0: ");

	/* Get lookup state */
	value = spx5_rd(sparx5, REW_ES0_CTRL);
	out->prf(out->dst, "\n      state: ");
	if (REW_ES0_CTRL_ES0_LU_ENA_GET(value))
		out->prf(out->dst, "on");
	else
		out->prf(out->dst, "off");

	out->prf(out->dst, "\n      keyset: ");
	value = spx5_rd(sparx5, REW_RTAG_ETAG_CTRL(port->portno));
	switch (REW_RTAG_ETAG_CTRL_ES0_ISDX_KEY_ENA_GET(value)) {
	case VCAP_ES0_PS_NORMAL_SELECTION:
		out->prf(out->dst, "normal");
		break;
	case VCAP_ES0_PS_FORCE_ISDX_LOOKUPS:
		out->prf(out->dst, "isdx");
		break;
	case VCAP_ES0_PS_FORCE_VID_LOOKUPS:
		out->prf(out->dst, "vid");
		break;
	case VCAP_ES0_PS_RESERVED:
		out->prf(out->dst, "reserved");
		break;
	}
	out->prf(out->dst, "\n");
}

static void sparx5_vcap_es2_port_keys(struct sparx5 *sparx5,
				      struct vcap_admin *admin,
				      struct sparx5_port *port,
				      struct vcap_output_print *out)
{
	int lookup;
	u32 value;

	out->prf(out->dst, "  port[%02d] (%s): ", port->portno,
	   netdev_name(port->ndev));
	for (lookup = 0; lookup < admin->lookups; ++lookup) {
		out->prf(out->dst, "\n    Lookup %d: ", lookup);

		/* Get lookup state */
		value = spx5_rd(sparx5, EACL_VCAP_ES2_KEY_SEL(port->portno,
							      lookup));
		out->prf(out->dst, "\n      state: ");
		if (EACL_VCAP_ES2_KEY_SEL_KEY_ENA_GET(value))
			out->prf(out->dst, "on");
		else
			out->prf(out->dst, "off");

		out->prf(out->dst, "\n      arp: ");
		switch (EACL_VCAP_ES2_KEY_SEL_ARP_KEY_SEL_GET(value)) {
		case VCAP_ES2_PS_ARP_MAC_ETYPE:
			out->prf(out->dst, "mac_etype");
			break;
		case VCAP_ES2_PS_ARP_ARP:
			out->prf(out->dst, "arp");
			break;
		}
		out->prf(out->dst, "\n      ipv4: ");
		switch (EACL_VCAP_ES2_KEY_SEL_IP4_KEY_SEL_GET(value)) {
		case VCAP_ES2_PS_IPV4_MAC_ETYPE:
			out->prf(out->dst, "mac_etype");
			break;
		case VCAP_ES2_PS_IPV4_IP_7TUPLE:
			out->prf(out->dst, "ip_7tuple");
			break;
		case VCAP_ES2_PS_IPV4_IP4_TCP_UDP_VID:
			out->prf(out->dst, "ip4_tcp_udp ip4_vid");
			break;
		case VCAP_ES2_PS_IPV4_IP4_TCP_UDP_OTHER:
			out->prf(out->dst, "ip4_tcp_udp ip4_other");
			break;
		case VCAP_ES2_PS_IPV4_IP4_VID:
			out->prf(out->dst, "ip4_vid");
			break;
		case VCAP_ES2_PS_IPV4_IP4_OTHER:
			out->prf(out->dst, "ip4_other");
			break;
		}
		out->prf(out->dst, "\n      ipv6: ");
		switch (EACL_VCAP_ES2_KEY_SEL_IP6_KEY_SEL_GET(value)) {
		case VCAP_ES2_PS_IPV6_MAC_ETYPE:
			out->prf(out->dst, "mac_etype");
			break;
		case VCAP_ES2_PS_IPV6_IP_7TUPLE:
			out->prf(out->dst, "ip_7tuple");
			break;
		case VCAP_ES2_PS_IPV6_IP_7TUPLE_VID:
			out->prf(out->dst, "ip_7tuple ip6_vid");
			break;
		case VCAP_ES2_PS_IPV6_IP_7TUPLE_STD:
			out->prf(out->dst, "ip_7tuple ip6_std");
			break;
		case VCAP_ES2_PS_IPV6_IP6_VID:
			out->prf(out->dst, "ip6_vid");
			break;
		case VCAP_ES2_PS_IPV6_IP6_STD:
			out->prf(out->dst, "ip6_std");
			break;
		case VCAP_ES2_PS_IPV6_IP4_DOWNGRADE:
			out->prf(out->dst, "ip4_downgrade");
			break;
		}
	}
	out->prf(out->dst, "\n");
}

static void sparx5_vcap_es2_port_stickies(struct sparx5 *sparx5,
					  struct vcap_admin *admin,
					  struct vcap_output_print *out)
{
	int lookup;
	u32 value;

	out->prf(out->dst, "  Sticky bits: ");
	for (lookup = 0; lookup < admin->lookups; ++lookup) {
		value = spx5_rd(sparx5, EACL_SEC_LOOKUP_STICKY(lookup));
		out->prf(out->dst, "\n    Lookup %d: ", lookup);
		if (EACL_SEC_LOOKUP_STICKY_SEC_TYPE_IP_7TUPLE_STICKY_GET(value))
			out->prf(out->dst, " ip_7tuple");
		if (EACL_SEC_LOOKUP_STICKY_SEC_TYPE_IP6_VID_STICKY_GET(value))
			out->prf(out->dst, " ip6_vid");
		if (EACL_SEC_LOOKUP_STICKY_SEC_TYPE_IP6_STD_STICKY_GET(value))
			out->prf(out->dst, " ip6_std");
		if (EACL_SEC_LOOKUP_STICKY_SEC_TYPE_IP4_TCPUDP_STICKY_GET(value))
			out->prf(out->dst, " ip4_tcp_udp");
		if (EACL_SEC_LOOKUP_STICKY_SEC_TYPE_IP4_VID_STICKY_GET(value))
			out->prf(out->dst, " ip4_vid");
		if (EACL_SEC_LOOKUP_STICKY_SEC_TYPE_IP4_OTHER_STICKY_GET(value))
			out->prf(out->dst, " ip4_other");
		if (EACL_SEC_LOOKUP_STICKY_SEC_TYPE_ARP_STICKY_GET(value))
			out->prf(out->dst, " arp");
		if (EACL_SEC_LOOKUP_STICKY_SEC_TYPE_MAC_ETYPE_STICKY_GET(value))
			out->prf(out->dst, " mac_etype");
		/* Clear stickies */
		spx5_wr(value, sparx5, EACL_SEC_LOOKUP_STICKY(lookup));
	}
	out->prf(out->dst, "\n");
}

/* Provide port information via a callback interface */
int sparx5_port_info(struct net_device *ndev,
		     struct vcap_admin *admin,
		     struct vcap_output_print *out)
{
	struct sparx5_port *port = netdev_priv(ndev);
	struct sparx5 *sparx5 = port->sparx5;
	const struct vcap_info *vcap;
	struct vcap_control *vctrl;

	vctrl = sparx5->vcap_ctrl;
	vcap = &vctrl->vcaps[admin->vtype];
	out->prf(out->dst, "%s:\n", vcap->name);
	switch (admin->vtype) {
	case VCAP_TYPE_IS0:
		sparx5_vcap_is0_port_keys(sparx5, admin, port, out);
		break;
	case VCAP_TYPE_IS2:
		sparx5_vcap_is2_port_keys(sparx5, admin, port, out);
		sparx5_vcap_is2_port_stickies(sparx5, admin, out);
		break;
	case VCAP_TYPE_ES0:
		sparx5_vcap_es0_port_keys(sparx5, admin, port, out);
		break;
	case VCAP_TYPE_ES2:
		sparx5_vcap_es2_port_keys(sparx5, admin, port, out);
		sparx5_vcap_es2_port_stickies(sparx5, admin, out);
		break;
	default:
		out->prf(out->dst, "  no info\n");
		break;
	}
	return 0;
}