Skip to content

Commit 73b4c04

Browse files
rkannoth1davem330
authored andcommitted
octeontx2-pf: TC flower offload support for SPI field
Driver support to offload TC flower rules which matches against SPI field of IPSEC packets (AH/ESP). Signed-off-by: Ratheesh Kannoth <rkannoth@marvell.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c8915d7 commit 73b4c04

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

drivers/net/ethernet/marvell/octeontx2/af/mbox.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,10 @@ struct flow_msg {
14511451
__be32 ip4dst;
14521452
__be32 ip6dst[4];
14531453
};
1454+
union {
1455+
__be32 spi;
1456+
};
1457+
14541458
u8 tos;
14551459
u8 ip_ver;
14561460
u8 ip_proto;

drivers/net/ethernet/marvell/octeontx2/af/npc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ enum key_fields {
204204
NPC_DPORT_UDP,
205205
NPC_SPORT_SCTP,
206206
NPC_DPORT_SCTP,
207+
NPC_IPSEC_SPI,
207208
NPC_HEADER_FIELDS_MAX,
208209
NPC_CHAN = NPC_HEADER_FIELDS_MAX, /* Valid when Rx */
209210
NPC_PF_FUNC, /* Valid when Tx */

drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,6 +2827,10 @@ static void rvu_dbg_npc_mcam_show_flows(struct seq_file *s,
28272827
seq_printf(s, "%d ", ntohs(rule->packet.dport));
28282828
seq_printf(s, "mask 0x%x\n", ntohs(rule->mask.dport));
28292829
break;
2830+
case NPC_IPSEC_SPI:
2831+
seq_printf(s, "0x%x ", ntohl(rule->packet.spi));
2832+
seq_printf(s, "mask 0x%x\n", ntohl(rule->mask.spi));
2833+
break;
28302834
default:
28312835
seq_puts(s, "\n");
28322836
break;

drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static const char * const npc_flow_names[] = {
4141
[NPC_SPORT_SCTP] = "sctp source port",
4242
[NPC_DPORT_SCTP] = "sctp destination port",
4343
[NPC_LXMB] = "Mcast/Bcast header ",
44+
[NPC_IPSEC_SPI] = "SPI ",
4445
[NPC_UNKNOWN] = "unknown",
4546
};
4647

@@ -513,6 +514,10 @@ do { \
513514
NPC_SCAN_HDR(NPC_VLAN_TAG1, NPC_LID_LB, NPC_LT_LB_CTAG, 2, 2);
514515
NPC_SCAN_HDR(NPC_VLAN_TAG2, NPC_LID_LB, NPC_LT_LB_STAG_QINQ, 2, 2);
515516
NPC_SCAN_HDR(NPC_DMAC, NPC_LID_LA, la_ltype, la_start, 6);
517+
518+
NPC_SCAN_HDR(NPC_IPSEC_SPI, NPC_LID_LD, NPC_LT_LD_AH, 4, 4);
519+
NPC_SCAN_HDR(NPC_IPSEC_SPI, NPC_LID_LE, NPC_LT_LE_ESP, 0, 4);
520+
516521
/* SMAC follows the DMAC(which is 6 bytes) */
517522
NPC_SCAN_HDR(NPC_SMAC, NPC_LID_LA, la_ltype, la_start + 6, 6);
518523
/* PF_FUNC is 2 bytes at 0th byte of NPC_LT_LA_IH_NIX_ETHER */
@@ -564,6 +569,9 @@ static void npc_set_features(struct rvu *rvu, int blkaddr, u8 intf)
564569
if (!npc_check_field(rvu, blkaddr, NPC_LB, intf))
565570
*features &= ~BIT_ULL(NPC_OUTER_VID);
566571

572+
if (*features & (BIT_ULL(NPC_IPPROTO_AH) | BIT_ULL(NPC_IPPROTO_ESP)))
573+
*features |= BIT_ULL(NPC_IPSEC_SPI);
574+
567575
/* for vlan ethertypes corresponding layer type should be in the key */
568576
if (npc_check_field(rvu, blkaddr, NPC_LB, intf))
569577
*features |= BIT_ULL(NPC_VLAN_ETYPE_CTAG) |
@@ -930,6 +938,9 @@ do { \
930938
NPC_WRITE_FLOW(NPC_DPORT_SCTP, dport, ntohs(pkt->dport), 0,
931939
ntohs(mask->dport), 0);
932940

941+
NPC_WRITE_FLOW(NPC_IPSEC_SPI, spi, ntohl(pkt->spi), 0,
942+
ntohl(mask->spi), 0);
943+
933944
NPC_WRITE_FLOW(NPC_OUTER_VID, vlan_tci, ntohs(pkt->vlan_tci), 0,
934945
ntohs(mask->vlan_tci), 0);
935946

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ static int otx2_tc_prepare_flow(struct otx2_nic *nic, struct otx2_tc_flow *node,
461461
BIT_ULL(FLOW_DISSECTOR_KEY_IPV4_ADDRS) |
462462
BIT_ULL(FLOW_DISSECTOR_KEY_IPV6_ADDRS) |
463463
BIT_ULL(FLOW_DISSECTOR_KEY_PORTS) |
464+
BIT(FLOW_DISSECTOR_KEY_IPSEC) |
464465
BIT_ULL(FLOW_DISSECTOR_KEY_IP)))) {
465466
netdev_info(nic->netdev, "unsupported flow used key 0x%llx",
466467
dissector->used_keys);
@@ -482,6 +483,8 @@ static int otx2_tc_prepare_flow(struct otx2_nic *nic, struct otx2_tc_flow *node,
482483
match.key->ip_proto != IPPROTO_UDP &&
483484
match.key->ip_proto != IPPROTO_SCTP &&
484485
match.key->ip_proto != IPPROTO_ICMP &&
486+
match.key->ip_proto != IPPROTO_ESP &&
487+
match.key->ip_proto != IPPROTO_AH &&
485488
match.key->ip_proto != IPPROTO_ICMPV6)) {
486489
netdev_info(nic->netdev,
487490
"ip_proto=0x%x not supported\n",
@@ -501,6 +504,10 @@ static int otx2_tc_prepare_flow(struct otx2_nic *nic, struct otx2_tc_flow *node,
501504
req->features |= BIT_ULL(NPC_IPPROTO_ICMP);
502505
else if (ip_proto == IPPROTO_ICMPV6)
503506
req->features |= BIT_ULL(NPC_IPPROTO_ICMP6);
507+
else if (ip_proto == IPPROTO_ESP)
508+
req->features |= BIT_ULL(NPC_IPPROTO_ESP);
509+
else if (ip_proto == IPPROTO_AH)
510+
req->features |= BIT_ULL(NPC_IPPROTO_AH);
504511
}
505512

506513
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CONTROL)) {
@@ -545,6 +552,26 @@ static int otx2_tc_prepare_flow(struct otx2_nic *nic, struct otx2_tc_flow *node,
545552
}
546553
}
547554

555+
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_IPSEC)) {
556+
struct flow_match_ipsec match;
557+
558+
flow_rule_match_ipsec(rule, &match);
559+
if (!match.mask->spi) {
560+
NL_SET_ERR_MSG_MOD(extack, "spi index not specified");
561+
return -EOPNOTSUPP;
562+
}
563+
if (ip_proto != IPPROTO_ESP &&
564+
ip_proto != IPPROTO_AH) {
565+
NL_SET_ERR_MSG_MOD(extack,
566+
"SPI index is valid only for ESP/AH proto");
567+
return -EOPNOTSUPP;
568+
}
569+
570+
flow_spec->spi = match.key->spi;
571+
flow_mask->spi = match.mask->spi;
572+
req->features |= BIT_ULL(NPC_IPSEC_SPI);
573+
}
574+
548575
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_IP)) {
549576
struct flow_match_ip match;
550577

0 commit comments

Comments
 (0)