-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
net: microchip: sparx5: Add tc matchall filter and enable VCAP lookups
Use a tc matchall rule with a goto action to the VCAP specific chain to enable the VCAP lookups. If the matchall rule is removed the VCAP lookups will be disabled again using its cookie as lookup to find the VCAP instance. To enable the Sparx5 IS2 VCAP on eth0 you would use this command: tc filter add dev eth0 ingress prio 5 handle 5 matchall \ skip_sw action goto chain 8000000 as the first lookup in IS2 has chain id 8000000 Signed-off-by: Steen Hegelund <steen.hegelund@microchip.com> Signed-off-by: David S. Miller <davem@davemloft.net>
- Loading branch information
Steen Hegelund
authored and
David S. Miller
committed
Nov 11, 2022
1 parent
242df4f
commit 6745671
Showing
8 changed files
with
263 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
drivers/net/ethernet/microchip/sparx5/sparx5_tc_matchall.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// SPDX-License-Identifier: GPL-2.0+ | ||
/* Microchip VCAP API | ||
* | ||
* Copyright (c) 2022 Microchip Technology Inc. and its subsidiaries. | ||
*/ | ||
|
||
#include "sparx5_tc.h" | ||
#include "vcap_api.h" | ||
#include "vcap_api_client.h" | ||
#include "sparx5_main_regs.h" | ||
#include "sparx5_main.h" | ||
#include "sparx5_vcap_impl.h" | ||
|
||
static int sparx5_tc_matchall_replace(struct net_device *ndev, | ||
struct tc_cls_matchall_offload *tmo, | ||
bool ingress) | ||
{ | ||
struct sparx5_port *port = netdev_priv(ndev); | ||
struct flow_action_entry *action; | ||
struct sparx5 *sparx5; | ||
int err; | ||
|
||
if (!flow_offload_has_one_action(&tmo->rule->action)) { | ||
NL_SET_ERR_MSG_MOD(tmo->common.extack, | ||
"Only one action per filter is supported"); | ||
return -EOPNOTSUPP; | ||
} | ||
action = &tmo->rule->action.entries[0]; | ||
|
||
sparx5 = port->sparx5; | ||
switch (action->id) { | ||
case FLOW_ACTION_GOTO: | ||
err = vcap_enable_lookups(sparx5->vcap_ctrl, ndev, | ||
action->chain_index, tmo->cookie, | ||
true); | ||
if (err == -EFAULT) { | ||
NL_SET_ERR_MSG_MOD(tmo->common.extack, | ||
"Unsupported goto chain"); | ||
return -EOPNOTSUPP; | ||
} | ||
if (err == -EADDRINUSE) { | ||
NL_SET_ERR_MSG_MOD(tmo->common.extack, | ||
"VCAP already enabled"); | ||
return -EOPNOTSUPP; | ||
} | ||
if (err) { | ||
NL_SET_ERR_MSG_MOD(tmo->common.extack, | ||
"Could not enable VCAP lookups"); | ||
return err; | ||
} | ||
break; | ||
default: | ||
NL_SET_ERR_MSG_MOD(tmo->common.extack, "Unsupported action"); | ||
return -EOPNOTSUPP; | ||
} | ||
return 0; | ||
} | ||
|
||
static int sparx5_tc_matchall_destroy(struct net_device *ndev, | ||
struct tc_cls_matchall_offload *tmo, | ||
bool ingress) | ||
{ | ||
struct sparx5_port *port = netdev_priv(ndev); | ||
struct sparx5 *sparx5; | ||
int err; | ||
|
||
sparx5 = port->sparx5; | ||
if (!tmo->rule && tmo->cookie) { | ||
err = vcap_enable_lookups(sparx5->vcap_ctrl, ndev, 0, | ||
tmo->cookie, false); | ||
if (err) | ||
return err; | ||
return 0; | ||
} | ||
NL_SET_ERR_MSG_MOD(tmo->common.extack, "Unsupported action"); | ||
return -EOPNOTSUPP; | ||
} | ||
|
||
int sparx5_tc_matchall(struct net_device *ndev, | ||
struct tc_cls_matchall_offload *tmo, | ||
bool ingress) | ||
{ | ||
if (!tc_cls_can_offload_and_chain0(ndev, &tmo->common)) { | ||
NL_SET_ERR_MSG_MOD(tmo->common.extack, | ||
"Only chain zero is supported"); | ||
return -EOPNOTSUPP; | ||
} | ||
|
||
switch (tmo->command) { | ||
case TC_CLSMATCHALL_REPLACE: | ||
return sparx5_tc_matchall_replace(ndev, tmo, ingress); | ||
case TC_CLSMATCHALL_DESTROY: | ||
return sparx5_tc_matchall_destroy(ndev, tmo, ingress); | ||
default: | ||
return -EOPNOTSUPP; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters