1 // SPDX-License-Identifier: GPL-2.0+
2 
3 #include "lan966x_main.h"
4 #include "vcap_api_client.h"
5 
lan966x_goto_port_add(struct lan966x_port * port,int from_cid,int to_cid,unsigned long goto_id,struct netlink_ext_ack * extack)6 int lan966x_goto_port_add(struct lan966x_port *port,
7 			  int from_cid, int to_cid,
8 			  unsigned long goto_id,
9 			  struct netlink_ext_ack *extack)
10 {
11 	struct lan966x *lan966x = port->lan966x;
12 	int err;
13 
14 	err = vcap_enable_lookups(lan966x->vcap_ctrl, port->dev,
15 				  from_cid, to_cid, goto_id,
16 				  true);
17 	if (err == -EFAULT) {
18 		NL_SET_ERR_MSG_MOD(extack, "Unsupported goto chain");
19 		return -EOPNOTSUPP;
20 	}
21 
22 	if (err == -EADDRINUSE) {
23 		NL_SET_ERR_MSG_MOD(extack, "VCAP already enabled");
24 		return -EOPNOTSUPP;
25 	}
26 
27 	if (err) {
28 		NL_SET_ERR_MSG_MOD(extack, "Could not enable VCAP lookups");
29 		return err;
30 	}
31 
32 	return 0;
33 }
34 
lan966x_goto_port_del(struct lan966x_port * port,unsigned long goto_id,struct netlink_ext_ack * extack)35 int lan966x_goto_port_del(struct lan966x_port *port,
36 			  unsigned long goto_id,
37 			  struct netlink_ext_ack *extack)
38 {
39 	struct lan966x *lan966x = port->lan966x;
40 	int err;
41 
42 	err = vcap_enable_lookups(lan966x->vcap_ctrl, port->dev, 0, 0,
43 				  goto_id, false);
44 	if (err) {
45 		NL_SET_ERR_MSG_MOD(extack, "Could not disable VCAP lookups");
46 		return err;
47 	}
48 
49 	return 0;
50 }
51