1 // SPDX-License-Identifier: GPL-2.0+
2 
3 #include "lan966x_main.h"
4 #include "lan966x_vcap_ag_api.h"
5 #include "vcap_api.h"
6 #include "vcap_api_client.h"
7 
8 static void lan966x_vcap_port_keys(struct lan966x_port *port,
9 				   struct vcap_admin *admin,
10 				   struct vcap_output_print *out)
11 {
12 	struct lan966x *lan966x = port->lan966x;
13 	u32 val;
14 
15 	out->prf(out->dst, "  port[%d] (%s): ", port->chip_port,
16 		 netdev_name(port->dev));
17 
18 	val = lan_rd(lan966x, ANA_VCAP_S2_CFG(port->chip_port));
19 	out->prf(out->dst, "\n    state: ");
20 	if (ANA_VCAP_S2_CFG_ENA_GET(val))
21 		out->prf(out->dst, "on");
22 	else
23 		out->prf(out->dst, "off");
24 
25 	for (int l = 0; l < admin->lookups; ++l) {
26 		out->prf(out->dst, "\n    Lookup %d: ", l);
27 
28 		out->prf(out->dst, "\n      snap: ");
29 		if (ANA_VCAP_S2_CFG_SNAP_DIS_GET(val) & (BIT(0) << l))
30 			out->prf(out->dst, "mac_llc");
31 		else
32 			out->prf(out->dst, "mac_snap");
33 
34 		out->prf(out->dst, "\n      oam: ");
35 		if (ANA_VCAP_S2_CFG_OAM_DIS_GET(val) & (BIT(0) << l))
36 			out->prf(out->dst, "mac_etype");
37 		else
38 			out->prf(out->dst, "mac_oam");
39 
40 		out->prf(out->dst, "\n      arp: ");
41 		if (ANA_VCAP_S2_CFG_ARP_DIS_GET(val) & (BIT(0) << l))
42 			out->prf(out->dst, "mac_etype");
43 		else
44 			out->prf(out->dst, "mac_arp");
45 
46 		out->prf(out->dst, "\n      ipv4_other: ");
47 		if (ANA_VCAP_S2_CFG_IP_OTHER_DIS_GET(val) & (BIT(0) << l))
48 			out->prf(out->dst, "mac_etype");
49 		else
50 			out->prf(out->dst, "ip4_other");
51 
52 		out->prf(out->dst, "\n      ipv4_tcp_udp: ");
53 		if (ANA_VCAP_S2_CFG_IP_TCPUDP_DIS_GET(val) & (BIT(0) << l))
54 			out->prf(out->dst, "mac_etype");
55 		else
56 			out->prf(out->dst, "ipv4_tcp_udp");
57 
58 		out->prf(out->dst, "\n      ipv6: ");
59 		switch (ANA_VCAP_S2_CFG_IP6_CFG_GET(val) & (0x3 << l)) {
60 		case VCAP_IS2_PS_IPV6_TCPUDP_OTHER:
61 			out->prf(out->dst, "ipv6_tcp_udp ipv6_tcp_udp");
62 			break;
63 		case VCAP_IS2_PS_IPV6_STD:
64 			out->prf(out->dst, "ipv6_std");
65 			break;
66 		case VCAP_IS2_PS_IPV6_IP4_TCPUDP_IP4_OTHER:
67 			out->prf(out->dst, "ipv4_tcp_udp ipv4_tcp_udp");
68 			break;
69 		case VCAP_IS2_PS_IPV6_MAC_ETYPE:
70 			out->prf(out->dst, "mac_etype");
71 			break;
72 		}
73 	}
74 
75 	out->prf(out->dst, "\n");
76 }
77 
78 int lan966x_vcap_port_info(struct net_device *dev,
79 			   struct vcap_admin *admin,
80 			   struct vcap_output_print *out)
81 {
82 	struct lan966x_port *port = netdev_priv(dev);
83 	struct lan966x *lan966x = port->lan966x;
84 	const struct vcap_info *vcap;
85 	struct vcap_control *vctrl;
86 
87 	vctrl = lan966x->vcap_ctrl;
88 	vcap = &vctrl->vcaps[admin->vtype];
89 
90 	out->prf(out->dst, "%s:\n", vcap->name);
91 	lan966x_vcap_port_keys(port, admin, out);
92 
93 	return 0;
94 }
95