Commit ae913318 authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'net-lan966x-add-support-for-is1-vcap'

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.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents cc4342f6 44d706fd
......@@ -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 */
......@@ -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 {
......
......@@ -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)
......
......@@ -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;
......@@ -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)
......@@ -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);
......@@ -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
......@@ -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,
......@@ -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;
......@@ -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,
......@@ -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);
......@@ -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,
......
......@@ -5,9 +5,124 @@
#include "vcap_api.h"
#include "vcap_api_client.h"
static void lan966x_vcap_port_keys(struct lan966x_port *port,
struct vcap_admin *admin,
struct vcap_output_print *out)
static void lan966x_vcap_is1_port_keys(struct lan966x_port *port,
struct vcap_admin *admin,
struct vcap_output_print *out)
{
struct lan966x *lan966x = port->lan966x;
u32 val;
out->prf(out->dst, " port[%d] (%s): ", port->chip_port,
netdev_name(port->dev));
val = lan_rd(lan966x, ANA_VCAP_CFG(port->chip_port));
out->prf(out->dst, "\n state: ");
if (ANA_VCAP_CFG_S1_ENA_GET(val))
out->prf(out->dst, "on");
else
out->prf(out->dst, "off");
for (int l = 0; l < admin->lookups; ++l) {
out->prf(out->dst, "\n Lookup %d: ", l);
out->prf(out->dst, "\n other: ");
switch (ANA_VCAP_S1_CFG_KEY_OTHER_CFG_GET(val)) {
case VCAP_IS1_PS_OTHER_NORMAL:
out->prf(out->dst, "normal");
break;
case VCAP_IS1_PS_OTHER_7TUPLE:
out->prf(out->dst, "7tuple");
break;
case VCAP_IS1_PS_OTHER_DBL_VID:
out->prf(out->dst, "dbl_vid");
break;
case VCAP_IS1_PS_OTHER_DMAC_VID:
out->prf(out->dst, "dmac_vid");
break;
default:
out->prf(out->dst, "-");
break;
}
out->prf(out->dst, "\n ipv4: ");
switch (ANA_VCAP_S1_CFG_KEY_IP4_CFG_GET(val)) {
case VCAP_IS1_PS_IPV4_NORMAL:
out->prf(out->dst, "normal");
break;
case VCAP_IS1_PS_IPV4_7TUPLE:
out->prf(out->dst, "7tuple");
break;
case VCAP_IS1_PS_IPV4_5TUPLE_IP4:
out->prf(out->dst, "5tuple_ipv4");
break;
case VCAP_IS1_PS_IPV4_DBL_VID:
out->prf(out->dst, "dbl_vid");
break;
case VCAP_IS1_PS_IPV4_DMAC_VID:
out->prf(out->dst, "dmac_vid");
break;
default:
out->prf(out->dst, "-");
break;
}
out->prf(out->dst, "\n ipv6: ");
switch (ANA_VCAP_S1_CFG_KEY_IP6_CFG_GET(val)) {
case VCAP_IS1_PS_IPV6_NORMAL:
out->prf(out->dst, "normal");
break;
case VCAP_IS1_PS_IPV6_7TUPLE:
out->prf(out->dst, "7tuple");
break;
case VCAP_IS1_PS_IPV6_5TUPLE_IP4:
out->prf(out->dst, "5tuple_ip4");
break;
case VCAP_IS1_PS_IPV6_NORMAL_IP6:
out->prf(out->dst, "normal_ip6");
break;
case VCAP_IS1_PS_IPV6_5TUPLE_IP6:
out->prf(out->dst, "5tuple_ip6");
break;
case VCAP_IS1_PS_IPV6_DBL_VID:
out->prf(out->dst, "dbl_vid");
break;
case VCAP_IS1_PS_IPV6_DMAC_VID:
out->prf(out->dst, "dmac_vid");
break;
default:
out->prf(out->dst, "-");
break;
}
out->prf(out->dst, "\n rt: ");
switch (ANA_VCAP_S1_CFG_KEY_RT_CFG_GET(val)) {
case VCAP_IS1_PS_RT_NORMAL:
out->prf(out->dst, "normal");
break;
case VCAP_IS1_PS_RT_7TUPLE:
out->prf(out->dst, "7tuple");
break;
case VCAP_IS1_PS_RT_DBL_VID:
out->prf(out->dst, "dbl_vid");
break;
case VCAP_IS1_PS_RT_DMAC_VID:
out->prf(out->dst, "dmac_vid");
break;
case VCAP_IS1_PS_RT_FOLLOW_OTHER:
out->prf(out->dst, "follow_other");
break;
default:
out->prf(out->dst, "-");
break;
}
}
out->prf(out->dst, "\n");
}
static void lan966x_vcap_is2_port_keys(struct lan966x_port *port,
struct vcap_admin *admin,
struct vcap_output_print *out)
{
struct lan966x *lan966x = port->lan966x;
u32 val;
......@@ -88,7 +203,17 @@ int lan966x_vcap_port_info(struct net_device *dev,
vcap = &vctrl->vcaps[admin->vtype];
out->prf(out->dst, "%s:\n", vcap->name);
lan966x_vcap_port_keys(port, admin, out);
switch (admin->vtype) {
case VCAP_TYPE_IS2:
lan966x_vcap_is2_port_keys(port, admin, out);
break;
case VCAP_TYPE_IS1:
lan966x_vcap_is1_port_keys(port, admin, out);
break;
default:
out->prf(out->dst, " no info\n");
break;
}
return 0;
}
......@@ -8,6 +8,7 @@
#define STREAMSIZE (64 * 4)
#define LAN966X_IS1_LOOKUPS 3
#define LAN966X_IS2_LOOKUPS 2
static struct lan966x_vcap_inst {
......@@ -19,6 +20,15 @@ static struct lan966x_vcap_inst {
int count; /* number of available addresses */
bool ingress; /* is vcap in the ingress path */
} lan966x_vcap_inst_cfg[] = {
{
.vtype = VCAP_TYPE_IS1, /* IS1-0 */
.tgt_inst = 1,
.lookups = LAN966X_IS1_LOOKUPS,
.first_cid = LAN966X_VCAP_CID_IS1_L0,
.last_cid = LAN966X_VCAP_CID_IS1_MAX,
.count = 768,
.ingress = true,
},
{
.vtype = VCAP_TYPE_IS2, /* IS2-0 */
.tgt_inst = 2,
......@@ -72,7 +82,21 @@ static void __lan966x_vcap_range_init(struct lan966x *lan966x,
lan966x_vcap_wait_update(lan966x, admin->tgt_inst);
}
static int lan966x_vcap_cid_to_lookup(int cid)
static int lan966x_vcap_is1_cid_to_lookup(int cid)
{
int lookup = 0;
if (cid >= LAN966X_VCAP_CID_IS1_L1 &&
cid < LAN966X_VCAP_CID_IS1_L2)
lookup = 1;
else if (cid >= LAN966X_VCAP_CID_IS1_L2 &&
cid < LAN966X_VCAP_CID_IS1_MAX)
lookup = 2;
return lookup;
}
static int lan966x_vcap_is2_cid_to_lookup(int cid)
{
if (cid >= LAN966X_VCAP_CID_IS2_L1 &&
cid < LAN966X_VCAP_CID_IS2_MAX)
......@@ -81,6 +105,67 @@ static int lan966x_vcap_cid_to_lookup(int cid)
return 0;
}
/* Return the list of keysets for the vcap port configuration */
static int
lan966x_vcap_is1_get_port_keysets(struct net_device *ndev, int lookup,
struct vcap_keyset_list *keysetlist,
u16 l3_proto)
{
struct lan966x_port *port = netdev_priv(ndev);
struct lan966x *lan966x = port->lan966x;
u32 val;
val = lan_rd(lan966x, ANA_VCAP_S1_CFG(port->chip_port, lookup));
/* Collect all keysets for the port in a list */
if (l3_proto == ETH_P_ALL || l3_proto == ETH_P_IP) {
switch (ANA_VCAP_S1_CFG_KEY_IP4_CFG_GET(val)) {
case VCAP_IS1_PS_IPV4_7TUPLE:
vcap_keyset_list_add(keysetlist, VCAP_KFS_7TUPLE);
break;
case VCAP_IS1_PS_IPV4_5TUPLE_IP4:
vcap_keyset_list_add(keysetlist, VCAP_KFS_5TUPLE_IP4);
break;
case VCAP_IS1_PS_IPV4_NORMAL:
vcap_keyset_list_add(keysetlist, VCAP_KFS_NORMAL);
break;
}
}
if (l3_proto == ETH_P_ALL || l3_proto == ETH_P_IPV6) {
switch (ANA_VCAP_S1_CFG_KEY_IP6_CFG_GET(val)) {
case VCAP_IS1_PS_IPV6_NORMAL:
case VCAP_IS1_PS_IPV6_NORMAL_IP6:
vcap_keyset_list_add(keysetlist, VCAP_KFS_NORMAL);
vcap_keyset_list_add(keysetlist, VCAP_KFS_NORMAL_IP6);
break;
case VCAP_IS1_PS_IPV6_5TUPLE_IP6:
vcap_keyset_list_add(keysetlist, VCAP_KFS_5TUPLE_IP6);
break;
case VCAP_IS1_PS_IPV6_7TUPLE:
vcap_keyset_list_add(keysetlist, VCAP_KFS_7TUPLE);
break;
case VCAP_IS1_PS_IPV6_5TUPLE_IP4:
vcap_keyset_list_add(keysetlist, VCAP_KFS_5TUPLE_IP4);
break;
case VCAP_IS1_PS_IPV6_DMAC_VID:
vcap_keyset_list_add(keysetlist, VCAP_KFS_DMAC_VID);
break;
}
}
switch (ANA_VCAP_S1_CFG_KEY_OTHER_CFG_GET(val)) {
case VCAP_IS1_PS_OTHER_7TUPLE:
vcap_keyset_list_add(keysetlist, VCAP_KFS_7TUPLE);
break;
case VCAP_IS1_PS_OTHER_NORMAL:
vcap_keyset_list_add(keysetlist, VCAP_KFS_NORMAL);
break;
}
return 0;
}
static int
lan966x_vcap_is2_get_port_keysets(struct net_device *dev, int lookup,
struct vcap_keyset_list *keysetlist,
......@@ -180,11 +265,26 @@ lan966x_vcap_validate_keyset(struct net_device *dev,
if (!kslist || kslist->cnt == 0)
return VCAP_KFS_NO_VALUE;
lookup = lan966x_vcap_cid_to_lookup(rule->vcap_chain_id);
keysetlist.max = ARRAY_SIZE(keysets);
keysetlist.keysets = keysets;
err = lan966x_vcap_is2_get_port_keysets(dev, lookup, &keysetlist,
l3_proto);
switch (admin->vtype) {
case VCAP_TYPE_IS1:
lookup = lan966x_vcap_is1_cid_to_lookup(rule->vcap_chain_id);
err = lan966x_vcap_is1_get_port_keysets(dev, lookup, &keysetlist,
l3_proto);
break;
case VCAP_TYPE_IS2:
lookup = lan966x_vcap_is2_cid_to_lookup(rule->vcap_chain_id);
err = lan966x_vcap_is2_get_port_keysets(dev, lookup, &keysetlist,
l3_proto);
break;
default:
pr_err("vcap type: %s not supported\n",
lan966x_vcaps[admin->vtype].name);
return VCAP_KFS_NO_VALUE;
}
if (err)
return VCAP_KFS_NO_VALUE;
......@@ -197,17 +297,32 @@ lan966x_vcap_validate_keyset(struct net_device *dev,
return VCAP_KFS_NO_VALUE;
}
static bool lan966x_vcap_is_first_chain(struct vcap_rule *rule)
static bool lan966x_vcap_is2_is_first_chain(struct vcap_rule *rule)
{
return (rule->vcap_chain_id >= LAN966X_VCAP_CID_IS2_L0 &&
rule->vcap_chain_id < LAN966X_VCAP_CID_IS2_L1);
}
static void lan966x_vcap_add_default_fields(struct net_device *dev,
struct vcap_admin *admin,
struct vcap_rule *rule)
static void lan966x_vcap_is1_add_default_fields(struct lan966x_port *port,
struct vcap_admin *admin,
struct vcap_rule *rule)
{
u32 value, mask;
u32 lookup;
if (vcap_rule_get_key_u32(rule, VCAP_KF_IF_IGR_PORT_MASK,
&value, &mask))
vcap_rule_add_key_u32(rule, VCAP_KF_IF_IGR_PORT_MASK, 0,
~BIT(port->chip_port));
lookup = lan966x_vcap_is1_cid_to_lookup(rule->vcap_chain_id);
vcap_rule_add_key_u32(rule, VCAP_KF_LOOKUP_INDEX, lookup, 0x3);
}
static void lan966x_vcap_is2_add_default_fields(struct lan966x_port *port,
struct vcap_admin *admin,
struct vcap_rule *rule)
{
struct lan966x_port *port = netdev_priv(dev);
u32 value, mask;
if (vcap_rule_get_key_u32(rule, VCAP_KF_IF_IGR_PORT_MASK,
......@@ -215,7 +330,7 @@ static void lan966x_vcap_add_default_fields(struct net_device *dev,
vcap_rule_add_key_u32(rule, VCAP_KF_IF_IGR_PORT_MASK, 0,
~BIT(port->chip_port));
if (lan966x_vcap_is_first_chain(rule))
if (lan966x_vcap_is2_is_first_chain(rule))
vcap_rule_add_key_bit(rule, VCAP_KF_LOOKUP_FIRST_IS,
VCAP_BIT_1);
else
......@@ -223,6 +338,26 @@ static void lan966x_vcap_add_default_fields(struct net_device *dev,
VCAP_BIT_0);
}
static void lan966x_vcap_add_default_fields(struct net_device *dev,
struct vcap_admin *admin,
struct vcap_rule *rule)
{
struct lan966x_port *port = netdev_priv(dev);
switch (admin->vtype) {
case VCAP_TYPE_IS1:
lan966x_vcap_is1_add_default_fields(port, admin, rule);
break;
case VCAP_TYPE_IS2:
lan966x_vcap_is2_add_default_fields(port, admin, rule);
break;
default:
pr_err("vcap type: %s not supported\n",
lan966x_vcaps[admin->vtype].name);
break;
}
}
static void lan966x_vcap_cache_erase(struct vcap_admin *admin)
{
memset(admin->cache.keystream, 0, STREAMSIZE);
......@@ -464,8 +599,37 @@ static void lan966x_vcap_block_init(struct lan966x *lan966x,
static void lan966x_vcap_port_key_deselection(struct lan966x *lan966x,
struct vcap_admin *admin)
{
for (int p = 0; p < lan966x->num_phys_ports; ++p)
lan_wr(0, lan966x, ANA_VCAP_S2_CFG(p));
u32 val;
switch (admin->vtype) {
case VCAP_TYPE_IS1:
val = ANA_VCAP_S1_CFG_KEY_IP6_CFG_SET(VCAP_IS1_PS_IPV6_5TUPLE_IP6) |
ANA_VCAP_S1_CFG_KEY_IP4_CFG_SET(VCAP_IS1_PS_IPV4_5TUPLE_IP4) |
ANA_VCAP_S1_CFG_KEY_OTHER_CFG_SET(VCAP_IS1_PS_OTHER_NORMAL);
for (int p = 0; p < lan966x->num_phys_ports; ++p) {
if (!lan966x->ports[p])
continue;
for (int l = 0; l < LAN966X_IS1_LOOKUPS; ++l)
lan_wr(val, lan966x, ANA_VCAP_S1_CFG(p, l));
lan_rmw(ANA_VCAP_CFG_S1_ENA_SET(true),
ANA_VCAP_CFG_S1_ENA, lan966x,
ANA_VCAP_CFG(p));
}
break;
case VCAP_TYPE_IS2:
for (int p = 0; p < lan966x->num_phys_ports; ++p)
lan_wr(0, lan966x, ANA_VCAP_S2_CFG(p));
break;
default:
pr_err("vcap type: %s not supported\n",
lan966x_vcaps[admin->vtype].name);
break;
}
}
int lan966x_vcap_init(struct lan966x *lan966x)
......@@ -506,6 +670,10 @@ int lan966x_vcap_init(struct lan966x *lan966x)
lan_rmw(ANA_VCAP_S2_CFG_ENA_SET(true),
ANA_VCAP_S2_CFG_ENA, lan966x,
ANA_VCAP_S2_CFG(lan966x->ports[p]->chip_port));
lan_rmw(ANA_VCAP_CFG_S1_ENA_SET(true),
ANA_VCAP_CFG_S1_ENA, lan966x,
ANA_VCAP_CFG(lan966x->ports[p]->chip_port));
}
}
......
......@@ -387,7 +387,7 @@ static const char * const test_admin_info_expect[] = {
"default_cnt: 73\n",
"require_cnt_dis: 0\n",
"version: 1\n",
"vtype: 3\n",
"vtype: 4\n",
"vinst: 0\n",
"ingress: 1\n",
"first_cid: 10000\n",
......@@ -435,7 +435,7 @@ static const char * const test_admin_expect[] = {
"default_cnt: 73\n",
"require_cnt_dis: 0\n",
"version: 1\n",
"vtype: 3\n",
"vtype: 4\n",
"vinst: 0\n",
"ingress: 1\n",
"first_cid: 8000000\n",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment