xref: /linux/drivers/net/ethernet/microchip/lan966x/lan966x_goto.c (revision 9f2c9170934eace462499ba0bfe042cc72900173)
1 // SPDX-License-Identifier: GPL-2.0+
2 
3 #include "lan966x_main.h"
4 #include "vcap_api_client.h"
5 
6 int lan966x_goto_port_add(struct lan966x_port *port,
7 			  struct flow_action_entry *act,
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 				  act->chain_index, 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 	port->tc.goto_id = goto_id;
33 
34 	return 0;
35 }
36 
37 int lan966x_goto_port_del(struct lan966x_port *port,
38 			  unsigned long goto_id,
39 			  struct netlink_ext_ack *extack)
40 {
41 	struct lan966x *lan966x = port->lan966x;
42 	int err;
43 
44 	err = vcap_enable_lookups(lan966x->vcap_ctrl, port->dev, 0,
45 				  goto_id, false);
46 	if (err) {
47 		NL_SET_ERR_MSG_MOD(extack, "Could not disable VCAP lookups");
48 		return err;
49 	}
50 
51 	port->tc.goto_id = 0;
52 
53 	return 0;
54 }
55