[dpdk-dev,v3,08/12] i40e: extend flow director to filter by tunnel ID

Message ID 1457502180-14124-9-git-send-email-jingjing.wu@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Bruce Richardson
Headers

Commit Message

Jingjing Wu March 9, 2016, 5:42 a.m. UTC
  This patch extended flow director to select Vxlan/GRE tunnel ID
as filter's input set and program the filter rule with the defined
tunnel type.

Signed-off-by: Jingjing Wu <jingjing.wu@intel.com>
---
 drivers/net/i40e/i40e_ethdev.c |  11 +++
 drivers/net/i40e/i40e_fdir.c   | 150 +++++++++++++++++++++++++++++++----------
 2 files changed, 125 insertions(+), 36 deletions(-)
  

Patch

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index e24b026..70a1c6c 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -6616,48 +6616,59 @@  i40e_get_valid_input_set(enum i40e_filter_pctype pctype,
 	 */
 	static const uint64_t valid_fdir_inset_table[] = {
 		[I40E_FILTER_PCTYPE_FRAG_IPV4] =
+		I40E_INSET_TUNNEL_ID |
 		I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
 		I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
 		I40E_INSET_IPV4_TTL,
 		[I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
+		I40E_INSET_TUNNEL_ID |
 		I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
 		I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
 		I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
 		[I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
+		I40E_INSET_TUNNEL_ID |
 		I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
 		I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
 		I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
 		[I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
+		I40E_INSET_TUNNEL_ID |
 		I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
 		I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
 		I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
 		I40E_INSET_SCTP_VT,
 		[I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
+		I40E_INSET_TUNNEL_ID |
 		I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
 		I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
 		I40E_INSET_IPV4_TTL,
 		[I40E_FILTER_PCTYPE_FRAG_IPV6] =
+		I40E_INSET_TUNNEL_ID |
 		I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
 		I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
 		I40E_INSET_IPV6_HOP_LIMIT,
 		[I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
+		I40E_INSET_TUNNEL_ID |
 		I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
 		I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
 		I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
 		[I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
+		I40E_INSET_TUNNEL_ID |
 		I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
 		I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
 		I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
 		[I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
+		I40E_INSET_TUNNEL_ID |
 		I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
 		I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
 		I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
 		I40E_INSET_SCTP_VT,
 		[I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
+		I40E_INSET_TUNNEL_ID |
 		I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
 		I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
 		I40E_INSET_IPV6_HOP_LIMIT,
 		[I40E_FILTER_PCTYPE_L2_PAYLOAD] =
+		I40E_INSET_TUNNEL_ID |
 		I40E_INSET_LAST_ETHER_TYPE,
 	};
 
diff --git a/drivers/net/i40e/i40e_fdir.c b/drivers/net/i40e/i40e_fdir.c
index ebbe612..e4ac79d 100644
--- a/drivers/net/i40e/i40e_fdir.c
+++ b/drivers/net/i40e/i40e_fdir.c
@@ -688,12 +688,41 @@  i40e_fdir_configure(struct rte_eth_dev *dev)
 }
 
 static inline void
-i40e_fdir_fill_eth_ip_head(const struct rte_eth_fdir_input *fdir_input,
-			       unsigned char *raw_pkt)
+i40e_fdir_fill_ether_head(const struct rte_eth_fdir_input *fdir_input,
+			       unsigned char *pkt)
 {
-	struct ether_hdr *ether = (struct ether_hdr *)raw_pkt;
-	struct ipv4_hdr *ip;
-	struct ipv6_hdr *ip6;
+	struct ether_hdr *ether = (struct ether_hdr *)pkt;
+	switch (fdir_input->flow_type) {
+	case RTE_ETH_FLOW_L2_PAYLOAD:
+		ether->ether_type = fdir_input->flow.l2_flow.ether_type;
+		break;
+	case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
+	case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
+	case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
+	case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
+	case RTE_ETH_FLOW_FRAG_IPV4:
+		ether->ether_type = rte_cpu_to_be_16(ETHER_TYPE_IPv4);
+		break;
+	case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
+	case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
+	case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
+	case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
+	case RTE_ETH_FLOW_FRAG_IPV6:
+		ether->ether_type = rte_cpu_to_be_16(ETHER_TYPE_IPv6);
+		break;
+	default:
+		PMD_DRV_LOG(ERR, "unknown flow type %u.",
+			    fdir_input->flow_type);
+		break;
+	}
+}
+
+static inline void
+i40e_fdir_fill_ip_head(const struct rte_eth_fdir_input *fdir_input,
+			       unsigned char *pkt)
+{
+	struct ipv4_hdr *ip = (struct ipv4_hdr *)pkt;
+	struct ipv6_hdr *ip6 = (struct ipv6_hdr *)pkt;
 	static const uint8_t next_proto[] = {
 		[RTE_ETH_FLOW_FRAG_IPV4] = IPPROTO_IP,
 		[RTE_ETH_FLOW_NONFRAG_IPV4_TCP] = IPPROTO_TCP,
@@ -708,17 +737,11 @@  i40e_fdir_fill_eth_ip_head(const struct rte_eth_fdir_input *fdir_input,
 	};
 
 	switch (fdir_input->flow_type) {
-	case RTE_ETH_FLOW_L2_PAYLOAD:
-		ether->ether_type = fdir_input->flow.l2_flow.ether_type;
-		break;
 	case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
 	case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
 	case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
 	case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
 	case RTE_ETH_FLOW_FRAG_IPV4:
-		ip = (struct ipv4_hdr *)(raw_pkt + sizeof(struct ether_hdr));
-
-		ether->ether_type = rte_cpu_to_be_16(ETHER_TYPE_IPv4);
 		ip->version_ihl = I40E_FDIR_IP_DEFAULT_VERSION_IHL;
 		/* set len to by default */
 		ip->total_length = rte_cpu_to_be_16(I40E_FDIR_IP_DEFAULT_LEN);
@@ -742,9 +765,6 @@  i40e_fdir_fill_eth_ip_head(const struct rte_eth_fdir_input *fdir_input,
 	case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
 	case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
 	case RTE_ETH_FLOW_FRAG_IPV6:
-		ip6 = (struct ipv6_hdr *)(raw_pkt + sizeof(struct ether_hdr));
-
-		ether->ether_type = rte_cpu_to_be_16(ETHER_TYPE_IPv6);
 		ip6->vtc_flow =
 			rte_cpu_to_be_32(I40E_FDIR_IPv6_DEFAULT_VTC_FLOW |
 					 (fdir_input->flow.ipv6_flow.tc <<
@@ -776,7 +796,7 @@  i40e_fdir_fill_eth_ip_head(const struct rte_eth_fdir_input *fdir_input,
 	}
 }
 
-
+#define I40E_TUNNEL_KEY_LEN 4
 /*
  * i40e_fdir_construct_pkt - construct packet based on fields in input
  * @pf: board private structure
@@ -788,21 +808,86 @@  i40e_fdir_construct_pkt(struct i40e_pf *pf,
 			     const struct rte_eth_fdir_input *fdir_input,
 			     unsigned char *raw_pkt)
 {
-	unsigned char *payload, *ptr;
+	unsigned char *payload, *ptr, *inner_pkt = raw_pkt;
 	struct udp_hdr *udp;
 	struct tcp_hdr *tcp;
 	struct sctp_hdr *sctp;
 	uint8_t size, dst = 0;
 	uint8_t i, pit_idx, set_idx = I40E_FLXPLD_L4_IDX; /* use l4 by default*/
+	static uint8_t gre4_frame[] = {0x08, 0,
+			0x45, 0, 0, 0x3A, 0, 0, 0, 0, 0x40, 0x2F,
+			0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x20, 0, 0x08, 0,
+			0, 0, 0, 0}; /* Mac+ IP + GRE hdr + key */
+	static uint8_t gre6_frame[] = {0x08, 0,
+			0x45, 0, 0, 0x3A, 0, 0, 0, 0, 0x40, 0x2F,
+			0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x20, 0, 0x86, 0xDD,
+			0, 0, 0, 0}; /* Mac+ IP + GRE hdr + key */
+	static uint8_t vxlan_frame[] = {0x08, 0,
+			0x45, 0, 0, 0x3A, 0, 0, 0, 0, 0x40, 0x11,
+			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+			0x12, 0xB5, 0x12, 0xB5, 0x08, 0, 0, 0,
+			0, 0, 0, 0, 0, 0, 0, 0}; /* Mac + IP + UDP + VXLAN hdr */
+	static uint8_t nvgre_frame[] = {0x08, 0,
+			0x45, 0, 0, 0x3A, 0, 0, 0, 0, 0x40, 0x2F,
+			0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x20, 0, 0x65, 0x58,
+			0, 0, 0, 0}; /*Mac + IP + NVGRE hdr*/
+
+	inner_pkt += 2 * sizeof(struct ether_addr);
+	/* fill the tunnel header if required */
+	switch (fdir_input->flow.tunnel_flow.tunnel_type) {
+	case RTE_FDIR_TUNNEL_TYPE_GRE:
+		if (fdir_input->flow_type == RTE_ETH_FLOW_L2_PAYLOAD) {
+			PMD_DRV_LOG(ERR, "GRE's inner pkt shouldn't"
+				    " be L2 frame.");
+			return -EINVAL;
+		}
+		if ((fdir_input->flow_type) == RTE_ETH_FLOW_FRAG_IPV4 ||
+		    (fdir_input->flow_type) == RTE_ETH_FLOW_NONFRAG_IPV4_TCP ||
+		    (fdir_input->flow_type) == RTE_ETH_FLOW_NONFRAG_IPV4_UDP ||
+		    (fdir_input->flow_type) == RTE_ETH_FLOW_NONFRAG_IPV4_SCTP ||
+		    (fdir_input->flow_type) == RTE_ETH_FLOW_NONFRAG_IPV4_OTHER)
+			rte_memcpy(inner_pkt, gre4_frame, sizeof(gre4_frame));
+		else
+			rte_memcpy(inner_pkt, gre6_frame, sizeof(gre6_frame));
+		/* gre4_frame and gre6_frame have the same size */
+		inner_pkt += sizeof(gre4_frame);
+		rte_memcpy(inner_pkt - I40E_TUNNEL_KEY_LEN,
+			   &fdir_input->flow.tunnel_flow.tunnel_id,
+			   I40E_TUNNEL_KEY_LEN);
+		break;
+	case RTE_FDIR_TUNNEL_TYPE_VXLAN:
+		rte_memcpy(inner_pkt, vxlan_frame, sizeof(vxlan_frame));
+		inner_pkt += sizeof(vxlan_frame);
+		rte_memcpy(inner_pkt - I40E_TUNNEL_KEY_LEN,
+			   &fdir_input->flow.tunnel_flow.tunnel_id,
+			   I40E_TUNNEL_KEY_LEN);
+		/* fill the ethernet and IP head of inner frame */
+		i40e_fdir_fill_ether_head(fdir_input, inner_pkt);
+		inner_pkt += sizeof(struct ether_hdr);
+		break;
+	case RTE_FDIR_TUNNEL_TYPE_NVGRE:
+		rte_memcpy(inner_pkt, nvgre_frame, sizeof(nvgre_frame));
+		inner_pkt += sizeof(nvgre_frame);
+		rte_memcpy(inner_pkt - I40E_TUNNEL_KEY_LEN,
+			   &fdir_input->flow.tunnel_flow.tunnel_id,
+			   I40E_TUNNEL_KEY_LEN);
+		/* fill the Ether header of inner frame */
+		i40e_fdir_fill_ether_head(fdir_input, inner_pkt);
+		inner_pkt += sizeof(struct ether_hdr);
+		break;
+	default:
+		/* fill the Ether header of single frame */
+		i40e_fdir_fill_ether_head(fdir_input, raw_pkt);
+		inner_pkt = raw_pkt + sizeof(struct ether_hdr);
+		break;
+	}
 
-	/* fill the ethernet and IP head */
-	i40e_fdir_fill_eth_ip_head(fdir_input, raw_pkt);
-
+	/* fill the IP header of inner or single frame */
+	i40e_fdir_fill_ip_head(fdir_input, inner_pkt);
 	/* fill the L4 head */
 	switch (fdir_input->flow_type) {
 	case RTE_ETH_FLOW_NONFRAG_IPV4_UDP:
-		udp = (struct udp_hdr *)(raw_pkt + sizeof(struct ether_hdr) +
-				sizeof(struct ipv4_hdr));
+		udp = (struct udp_hdr *)(inner_pkt + sizeof(struct ipv4_hdr));
 		payload = (unsigned char *)udp + sizeof(struct udp_hdr);
 		/*
 		 * The source and destination fields in the transmitted packet
@@ -815,8 +900,7 @@  i40e_fdir_construct_pkt(struct i40e_pf *pf,
 		break;
 
 	case RTE_ETH_FLOW_NONFRAG_IPV4_TCP:
-		tcp = (struct tcp_hdr *)(raw_pkt + sizeof(struct ether_hdr) +
-					 sizeof(struct ipv4_hdr));
+		tcp = (struct tcp_hdr *)(inner_pkt + sizeof(struct ipv4_hdr));
 		payload = (unsigned char *)tcp + sizeof(struct tcp_hdr);
 		/*
 		 * The source and destination fields in the transmitted packet
@@ -829,8 +913,7 @@  i40e_fdir_construct_pkt(struct i40e_pf *pf,
 		break;
 
 	case RTE_ETH_FLOW_NONFRAG_IPV4_SCTP:
-		sctp = (struct sctp_hdr *)(raw_pkt + sizeof(struct ether_hdr) +
-					   sizeof(struct ipv4_hdr));
+		sctp = (struct sctp_hdr *)(inner_pkt + sizeof(struct ipv4_hdr));
 		payload = (unsigned char *)sctp + sizeof(struct sctp_hdr);
 		/*
 		 * The source and destination fields in the transmitted packet
@@ -844,14 +927,12 @@  i40e_fdir_construct_pkt(struct i40e_pf *pf,
 
 	case RTE_ETH_FLOW_NONFRAG_IPV4_OTHER:
 	case RTE_ETH_FLOW_FRAG_IPV4:
-		payload = raw_pkt + sizeof(struct ether_hdr) +
-			  sizeof(struct ipv4_hdr);
+		payload = inner_pkt + sizeof(struct ipv4_hdr);
 		set_idx = I40E_FLXPLD_L3_IDX;
 		break;
 
 	case RTE_ETH_FLOW_NONFRAG_IPV6_UDP:
-		udp = (struct udp_hdr *)(raw_pkt + sizeof(struct ether_hdr) +
-					 sizeof(struct ipv6_hdr));
+		udp = (struct udp_hdr *)(inner_pkt + sizeof(struct ipv6_hdr));
 		payload = (unsigned char *)udp + sizeof(struct udp_hdr);
 		/*
 		 * The source and destination fields in the transmitted packet
@@ -864,8 +945,7 @@  i40e_fdir_construct_pkt(struct i40e_pf *pf,
 		break;
 
 	case RTE_ETH_FLOW_NONFRAG_IPV6_TCP:
-		tcp = (struct tcp_hdr *)(raw_pkt + sizeof(struct ether_hdr) +
-					 sizeof(struct ipv6_hdr));
+		tcp = (struct tcp_hdr *)(inner_pkt + sizeof(struct ipv6_hdr));
 		payload = (unsigned char *)tcp + sizeof(struct tcp_hdr);
 		/*
 		 * The source and destination fields in the transmitted packet
@@ -878,8 +958,7 @@  i40e_fdir_construct_pkt(struct i40e_pf *pf,
 		break;
 
 	case RTE_ETH_FLOW_NONFRAG_IPV6_SCTP:
-		sctp = (struct sctp_hdr *)(raw_pkt + sizeof(struct ether_hdr) +
-					   sizeof(struct ipv6_hdr));
+		sctp = (struct sctp_hdr *)(inner_pkt + sizeof(struct ipv6_hdr));
 		payload = (unsigned char *)sctp + sizeof(struct sctp_hdr);
 		/*
 		 * The source and destination fields in the transmitted packet
@@ -893,12 +972,11 @@  i40e_fdir_construct_pkt(struct i40e_pf *pf,
 
 	case RTE_ETH_FLOW_NONFRAG_IPV6_OTHER:
 	case RTE_ETH_FLOW_FRAG_IPV6:
-		payload = raw_pkt + sizeof(struct ether_hdr) +
-			  sizeof(struct ipv6_hdr);
+		payload = inner_pkt + sizeof(struct ipv6_hdr);
 		set_idx = I40E_FLXPLD_L3_IDX;
 		break;
 	case RTE_ETH_FLOW_L2_PAYLOAD:
-		payload = raw_pkt + sizeof(struct ether_hdr);
+		payload = inner_pkt;
 		/*
 		 * ARP packet is a special case on which the payload
 		 * starts after the whole ARP header