Skip to content

Commit

Permalink
Merge branch 'net-lan966x-add-support-for-is1-vcap'
Browse files Browse the repository at this point in the history
Horatiu Vultur says:

====================
net: lan966x: Add support for IS1 VCAP

Provide the Ingress Stage 1 (IS1) VCAP (Versatile Content-Aware
Processor) support for the Lan966x platform.

The IS1 VCAP has 3 lookups and they are accessible with a TC chain id:
- chain 1000000: IS1 Lookup 0
- chain 1100000: IS1 Lookup 1
- chain 1200000: IS1 Lookup 2

The IS1 is capable of different actions like rewrite VLAN tags, change
priority of the frames, police the traffic, etc. These features will be
added at a later point.

The IS1 currently implements the action that allows setting the value
of a PAG (Policy Association Group) key field in the frame metadata and
this can be used for matching in an IS2 VCAP rule. In this way a rule in
IS0 VCAP can be linked to rules in the IS2 VCAP. The linking is exposed
by using the TC "goto chain" action with an offset from the IS2 chain ids.
For example "goto chain 8000001" will use a PAG value of 1 to chain to a
rule in IS2 lookup 0.
====================

Link: https://lore.kernel.org/r/20230307220929.834219-1-horatiu.vultur@microchip.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Mar 11, 2023
2 parents cc4342f + 44d706f commit ae91331
Show file tree
Hide file tree
Showing 8 changed files with 2,156 additions and 87 deletions.
38 changes: 38 additions & 0 deletions drivers/net/ethernet/microchip/lan966x/lan966x_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@
#define SE_IDX_QUEUE 0 /* 0-79 : Queue scheduler elements */
#define SE_IDX_PORT 80 /* 80-89 : Port schedular elements */

#define LAN966X_VCAP_CID_IS1_L0 VCAP_CID_INGRESS_L0 /* IS1 lookup 0 */
#define LAN966X_VCAP_CID_IS1_L1 VCAP_CID_INGRESS_L1 /* IS1 lookup 1 */
#define LAN966X_VCAP_CID_IS1_L2 VCAP_CID_INGRESS_L2 /* IS1 lookup 2 */
#define LAN966X_VCAP_CID_IS1_MAX (VCAP_CID_INGRESS_L3 - 1) /* IS1 Max */

#define LAN966X_VCAP_CID_IS2_L0 VCAP_CID_INGRESS_STAGE2_L0 /* IS2 lookup 0 */
#define LAN966X_VCAP_CID_IS2_L1 VCAP_CID_INGRESS_STAGE2_L1 /* IS2 lookup 1 */
#define LAN966X_VCAP_CID_IS2_MAX (VCAP_CID_INGRESS_STAGE2_L2 - 1) /* IS2 Max */
Expand Down Expand Up @@ -139,6 +144,39 @@ enum vcap_is2_port_sel_ipv6 {
VCAP_IS2_PS_IPV6_MAC_ETYPE,
};

enum vcap_is1_port_sel_other {
VCAP_IS1_PS_OTHER_NORMAL,
VCAP_IS1_PS_OTHER_7TUPLE,
VCAP_IS1_PS_OTHER_DBL_VID,
VCAP_IS1_PS_OTHER_DMAC_VID,
};

enum vcap_is1_port_sel_ipv4 {
VCAP_IS1_PS_IPV4_NORMAL,
VCAP_IS1_PS_IPV4_7TUPLE,
VCAP_IS1_PS_IPV4_5TUPLE_IP4,
VCAP_IS1_PS_IPV4_DBL_VID,
VCAP_IS1_PS_IPV4_DMAC_VID,
};

enum vcap_is1_port_sel_ipv6 {
VCAP_IS1_PS_IPV6_NORMAL,
VCAP_IS1_PS_IPV6_7TUPLE,
VCAP_IS1_PS_IPV6_5TUPLE_IP4,
VCAP_IS1_PS_IPV6_NORMAL_IP6,
VCAP_IS1_PS_IPV6_5TUPLE_IP6,
VCAP_IS1_PS_IPV6_DBL_VID,
VCAP_IS1_PS_IPV6_DMAC_VID,
};

enum vcap_is1_port_sel_rt {
VCAP_IS1_PS_RT_NORMAL,
VCAP_IS1_PS_RT_7TUPLE,
VCAP_IS1_PS_RT_DBL_VID,
VCAP_IS1_PS_RT_DMAC_VID,
VCAP_IS1_PS_RT_FOLLOW_OTHER = 7,
};

struct lan966x_port;

struct lan966x_db {
Expand Down
36 changes: 36 additions & 0 deletions drivers/net/ethernet/microchip/lan966x/lan966x_regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,42 @@ enum lan966x_target {
#define ANA_DROP_CFG_DROP_MC_SMAC_ENA_GET(x)\
FIELD_GET(ANA_DROP_CFG_DROP_MC_SMAC_ENA, x)

/* ANA:PORT:VCAP_CFG */
#define ANA_VCAP_CFG(g) __REG(TARGET_ANA, 0, 1, 28672, g, 9, 128, 12, 0, 1, 4)

#define ANA_VCAP_CFG_S1_ENA BIT(14)
#define ANA_VCAP_CFG_S1_ENA_SET(x)\
FIELD_PREP(ANA_VCAP_CFG_S1_ENA, x)
#define ANA_VCAP_CFG_S1_ENA_GET(x)\
FIELD_GET(ANA_VCAP_CFG_S1_ENA, x)

/* ANA:PORT:VCAP_S1_KEY_CFG */
#define ANA_VCAP_S1_CFG(g, r) __REG(TARGET_ANA, 0, 1, 28672, g, 9, 128, 16, r, 3, 4)

#define ANA_VCAP_S1_CFG_KEY_RT_CFG GENMASK(11, 9)
#define ANA_VCAP_S1_CFG_KEY_RT_CFG_SET(x)\
FIELD_PREP(ANA_VCAP_S1_CFG_KEY_RT_CFG, x)
#define ANA_VCAP_S1_CFG_KEY_RT_CFG_GET(x)\
FIELD_GET(ANA_VCAP_S1_CFG_KEY_RT_CFG, x)

#define ANA_VCAP_S1_CFG_KEY_IP6_CFG GENMASK(8, 6)
#define ANA_VCAP_S1_CFG_KEY_IP6_CFG_SET(x)\
FIELD_PREP(ANA_VCAP_S1_CFG_KEY_IP6_CFG, x)
#define ANA_VCAP_S1_CFG_KEY_IP6_CFG_GET(x)\
FIELD_GET(ANA_VCAP_S1_CFG_KEY_IP6_CFG, x)

#define ANA_VCAP_S1_CFG_KEY_IP4_CFG GENMASK(5, 3)
#define ANA_VCAP_S1_CFG_KEY_IP4_CFG_SET(x)\
FIELD_PREP(ANA_VCAP_S1_CFG_KEY_IP4_CFG, x)
#define ANA_VCAP_S1_CFG_KEY_IP4_CFG_GET(x)\
FIELD_GET(ANA_VCAP_S1_CFG_KEY_IP4_CFG, x)

#define ANA_VCAP_S1_CFG_KEY_OTHER_CFG GENMASK(2, 0)
#define ANA_VCAP_S1_CFG_KEY_OTHER_CFG_SET(x)\
FIELD_PREP(ANA_VCAP_S1_CFG_KEY_OTHER_CFG, x)
#define ANA_VCAP_S1_CFG_KEY_OTHER_CFG_GET(x)\
FIELD_GET(ANA_VCAP_S1_CFG_KEY_OTHER_CFG, x)

/* ANA:PORT:VCAP_S2_CFG */
#define ANA_VCAP_S2_CFG(g) __REG(TARGET_ANA, 0, 1, 28672, g, 9, 128, 28, 0, 1, 4)

Expand Down
221 changes: 210 additions & 11 deletions drivers/net/ethernet/microchip/lan966x/lan966x_tc_flower.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,34 @@
#include "vcap_api_client.h"
#include "vcap_tc.h"

static bool lan966x_tc_is_known_etype(u16 etype)
static bool lan966x_tc_is_known_etype(struct vcap_tc_flower_parse_usage *st,
u16 etype)
{
switch (etype) {
case ETH_P_ALL:
case ETH_P_ARP:
case ETH_P_IP:
case ETH_P_IPV6:
return true;
switch (st->admin->vtype) {
case VCAP_TYPE_IS1:
switch (etype) {
case ETH_P_ALL:
case ETH_P_ARP:
case ETH_P_IP:
case ETH_P_IPV6:
return true;
}
break;
case VCAP_TYPE_IS2:
switch (etype) {
case ETH_P_ALL:
case ETH_P_ARP:
case ETH_P_IP:
case ETH_P_IPV6:
case ETH_P_SNAP:
case ETH_P_802_2:
return true;
}
break;
default:
NL_SET_ERR_MSG_MOD(st->fco->common.extack,
"VCAP type not supported");
return false;
}

return false;
Expand Down Expand Up @@ -69,7 +89,7 @@ lan966x_tc_flower_handler_basic_usage(struct vcap_tc_flower_parse_usage *st)
flow_rule_match_basic(st->frule, &match);
if (match.mask->n_proto) {
st->l3_proto = be16_to_cpu(match.key->n_proto);
if (!lan966x_tc_is_known_etype(st->l3_proto)) {
if (!lan966x_tc_is_known_etype(st, st->l3_proto)) {
err = vcap_rule_add_key_u32(st->vrule, VCAP_KF_ETYPE,
st->l3_proto, ~0);
if (err)
Expand All @@ -79,18 +99,61 @@ lan966x_tc_flower_handler_basic_usage(struct vcap_tc_flower_parse_usage *st)
VCAP_BIT_1);
if (err)
goto out;
} else if (st->l3_proto == ETH_P_IPV6 &&
st->admin->vtype == VCAP_TYPE_IS1) {
/* Don't set any keys in this case */
} else if (st->l3_proto == ETH_P_SNAP &&
st->admin->vtype == VCAP_TYPE_IS1) {
err = vcap_rule_add_key_bit(st->vrule,
VCAP_KF_ETYPE_LEN_IS,
VCAP_BIT_0);
if (err)
goto out;

err = vcap_rule_add_key_bit(st->vrule,
VCAP_KF_IP_SNAP_IS,
VCAP_BIT_1);
if (err)
goto out;
} else if (st->admin->vtype == VCAP_TYPE_IS1) {
err = vcap_rule_add_key_bit(st->vrule,
VCAP_KF_ETYPE_LEN_IS,
VCAP_BIT_1);
if (err)
goto out;

err = vcap_rule_add_key_u32(st->vrule, VCAP_KF_ETYPE,
st->l3_proto, ~0);
if (err)
goto out;
}
}
if (match.mask->ip_proto) {
st->l4_proto = match.key->ip_proto;

if (st->l4_proto == IPPROTO_TCP) {
if (st->admin->vtype == VCAP_TYPE_IS1) {
err = vcap_rule_add_key_bit(st->vrule,
VCAP_KF_TCP_UDP_IS,
VCAP_BIT_1);
if (err)
goto out;
}

err = vcap_rule_add_key_bit(st->vrule,
VCAP_KF_TCP_IS,
VCAP_BIT_1);
if (err)
goto out;
} else if (st->l4_proto == IPPROTO_UDP) {
if (st->admin->vtype == VCAP_TYPE_IS1) {
err = vcap_rule_add_key_bit(st->vrule,
VCAP_KF_TCP_UDP_IS,
VCAP_BIT_1);
if (err)
goto out;
}

err = vcap_rule_add_key_bit(st->vrule,
VCAP_KF_TCP_IS,
VCAP_BIT_0);
Expand All @@ -112,12 +175,30 @@ lan966x_tc_flower_handler_basic_usage(struct vcap_tc_flower_parse_usage *st)
return err;
}

static int
lan966x_tc_flower_handler_cvlan_usage(struct vcap_tc_flower_parse_usage *st)
{
if (st->admin->vtype != VCAP_TYPE_IS1) {
NL_SET_ERR_MSG_MOD(st->fco->common.extack,
"cvlan not supported in this VCAP");
return -EINVAL;
}

return vcap_tc_flower_handler_cvlan_usage(st);
}

static int
lan966x_tc_flower_handler_vlan_usage(struct vcap_tc_flower_parse_usage *st)
{
return vcap_tc_flower_handler_vlan_usage(st,
VCAP_KF_8021Q_VID_CLS,
VCAP_KF_8021Q_PCP_CLS);
enum vcap_key_field vid_key = VCAP_KF_8021Q_VID_CLS;
enum vcap_key_field pcp_key = VCAP_KF_8021Q_PCP_CLS;

if (st->admin->vtype == VCAP_TYPE_IS1) {
vid_key = VCAP_KF_8021Q_VID0;
pcp_key = VCAP_KF_8021Q_PCP0;
}

return vcap_tc_flower_handler_vlan_usage(st, vid_key, pcp_key);
}

static int
Expand All @@ -128,6 +209,7 @@ static int
[FLOW_DISSECTOR_KEY_CONTROL] = lan966x_tc_flower_handler_control_usage,
[FLOW_DISSECTOR_KEY_PORTS] = vcap_tc_flower_handler_portnum_usage,
[FLOW_DISSECTOR_KEY_BASIC] = lan966x_tc_flower_handler_basic_usage,
[FLOW_DISSECTOR_KEY_CVLAN] = lan966x_tc_flower_handler_cvlan_usage,
[FLOW_DISSECTOR_KEY_VLAN] = lan966x_tc_flower_handler_vlan_usage,
[FLOW_DISSECTOR_KEY_TCP] = vcap_tc_flower_handler_tcp_usage,
[FLOW_DISSECTOR_KEY_ARP] = vcap_tc_flower_handler_arp_usage,
Expand All @@ -143,6 +225,7 @@ static int lan966x_tc_flower_use_dissectors(struct flow_cls_offload *f,
.fco = f,
.vrule = vrule,
.l3_proto = ETH_P_ALL,
.admin = admin,
};
int err = 0;

Expand Down Expand Up @@ -221,6 +304,100 @@ static int lan966x_tc_flower_action_check(struct vcap_control *vctrl,
return 0;
}

/* Add the actionset that is the default for the VCAP type */
static int lan966x_tc_set_actionset(struct vcap_admin *admin,
struct vcap_rule *vrule)
{
enum vcap_actionfield_set aset;
int err = 0;

switch (admin->vtype) {
case VCAP_TYPE_IS1:
aset = VCAP_AFS_S1;
break;
case VCAP_TYPE_IS2:
aset = VCAP_AFS_BASE_TYPE;
break;
default:
return -EINVAL;
}

/* Do not overwrite any current actionset */
if (vrule->actionset == VCAP_AFS_NO_VALUE)
err = vcap_set_rule_set_actionset(vrule, aset);

return err;
}

static int lan966x_tc_add_rule_link_target(struct vcap_admin *admin,
struct vcap_rule *vrule,
int target_cid)
{
int link_val = target_cid % VCAP_CID_LOOKUP_SIZE;
int err;

if (!link_val)
return 0;

switch (admin->vtype) {
case VCAP_TYPE_IS1:
/* Choose IS1 specific NXT_IDX key (for chaining rules from IS1) */
err = vcap_rule_add_key_u32(vrule, VCAP_KF_LOOKUP_GEN_IDX_SEL,
1, ~0);
if (err)
return err;

return vcap_rule_add_key_u32(vrule, VCAP_KF_LOOKUP_GEN_IDX,
link_val, ~0);
case VCAP_TYPE_IS2:
/* Add IS2 specific PAG key (for chaining rules from IS1) */
return vcap_rule_add_key_u32(vrule, VCAP_KF_LOOKUP_PAG,
link_val, ~0);
default:
break;
}
return 0;
}

static int lan966x_tc_add_rule_link(struct vcap_control *vctrl,
struct vcap_admin *admin,
struct vcap_rule *vrule,
struct flow_cls_offload *f,
int to_cid)
{
struct vcap_admin *to_admin = vcap_find_admin(vctrl, to_cid);
int diff, err = 0;

if (!to_admin) {
NL_SET_ERR_MSG_MOD(f->common.extack,
"Unknown destination chain");
return -EINVAL;
}

diff = vcap_chain_offset(vctrl, f->common.chain_index, to_cid);
if (!diff)
return 0;

/* Between IS1 and IS2 the PAG value is used */
if (admin->vtype == VCAP_TYPE_IS1 && to_admin->vtype == VCAP_TYPE_IS2) {
/* This works for IS1->IS2 */
err = vcap_rule_add_action_u32(vrule, VCAP_AF_PAG_VAL, diff);
if (err)
return err;

err = vcap_rule_add_action_u32(vrule, VCAP_AF_PAG_OVERRIDE_MASK,
0xff);
if (err)
return err;
} else {
NL_SET_ERR_MSG_MOD(f->common.extack,
"Unsupported chain destination");
return -EOPNOTSUPP;
}

return err;
}

static int lan966x_tc_flower_add(struct lan966x_port *port,
struct flow_cls_offload *f,
struct vcap_admin *admin,
Expand Down Expand Up @@ -248,11 +425,23 @@ static int lan966x_tc_flower_add(struct lan966x_port *port,
if (err)
goto out;

err = lan966x_tc_add_rule_link_target(admin, vrule,
f->common.chain_index);
if (err)
goto out;

frule = flow_cls_offload_flow_rule(f);

flow_action_for_each(idx, act, &frule->action) {
switch (act->id) {
case FLOW_ACTION_TRAP:
if (admin->vtype != VCAP_TYPE_IS2) {
NL_SET_ERR_MSG_MOD(f->common.extack,
"Trap action not supported in this VCAP");
err = -EOPNOTSUPP;
goto out;
}

err = vcap_rule_add_action_bit(vrule,
VCAP_AF_CPU_COPY_ENA,
VCAP_BIT_1);
Expand All @@ -266,6 +455,16 @@ static int lan966x_tc_flower_add(struct lan966x_port *port,

break;
case FLOW_ACTION_GOTO:
err = lan966x_tc_set_actionset(admin, vrule);
if (err)
goto out;

err = lan966x_tc_add_rule_link(port->lan966x->vcap_ctrl,
admin, vrule,
f, act->chain_index);
if (err)
goto out;

break;
default:
NL_SET_ERR_MSG_MOD(f->common.extack,
Expand Down
Loading

0 comments on commit ae91331

Please sign in to comment.