DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jianfeng Tan <jianfeng.tan@intel.com>
To: dev@dpdk.org
Cc: yuanhan.liu@linux.intel.com, stephen@networkplumber.org,
	lei.a.yao@intel.com, Jianfeng Tan <jianfeng.tan@intel.com>
Subject: [dpdk-dev] [PATCH v3 09/10] examples/l3fwd-power: add parse-ptype option
Date: Mon, 16 Jan 2017 14:47:01 +0000	[thread overview]
Message-ID: <1484578022-92705-10-git-send-email-jianfeng.tan@intel.com> (raw)
In-Reply-To: <1484578022-92705-1-git-send-email-jianfeng.tan@intel.com>

To support those devices that do not provide packet type info when
receiving packets, add a new option, --parse-ptype, to analyze
packet type in the Rx callback.

Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
---
 examples/l3fwd-power/main.c | 110 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 109 insertions(+), 1 deletion(-)

diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c
index b65d683..6f10d0a 100644
--- a/examples/l3fwd-power/main.c
+++ b/examples/l3fwd-power/main.c
@@ -164,6 +164,8 @@ static uint32_t enabled_port_mask = 0;
 static int promiscuous_on = 0;
 /* NUMA is enabled by default. */
 static int numa_on = 1;
+static int parse_ptype; /**< Parse packet type using rx callback, and */
+			/**< disabled by default */
 
 enum freq_scale_hint_t
 {
@@ -607,6 +609,48 @@ get_ipv4_dst_port(struct ipv4_hdr *ipv4_hdr, uint8_t portid,
 #endif
 
 static inline void
+parse_ptype_one(struct rte_mbuf *m)
+{
+	struct ether_hdr *eth_hdr;
+	uint32_t packet_type = RTE_PTYPE_UNKNOWN;
+	uint16_t ether_type;
+
+	eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
+	ether_type = eth_hdr->ether_type;
+	if (ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4))
+		packet_type |= RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
+	else if (ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv6))
+		packet_type |= RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
+
+	m->packet_type = packet_type;
+}
+
+static uint16_t
+cb_parse_ptype(uint8_t port __rte_unused, uint16_t queue __rte_unused,
+	       struct rte_mbuf *pkts[], uint16_t nb_pkts,
+	       uint16_t max_pkts __rte_unused,
+	       void *user_param __rte_unused)
+{
+	unsigned int i;
+
+	for (i = 0; i < nb_pkts; ++i)
+		parse_ptype_one(pkts[i]);
+
+	return nb_pkts;
+}
+
+static int
+add_cb_parse_ptype(uint8_t portid, uint16_t queueid)
+{
+	printf("Port %d: softly parse packet type info\n", portid);
+	if (rte_eth_add_rx_callback(portid, queueid, cb_parse_ptype, NULL))
+		return 0;
+
+	printf("Failed to add rx callback: port=%d\n", portid);
+	return -1;
+}
+
+static inline void
 l3fwd_simple_forward(struct rte_mbuf *m, uint8_t portid,
 				struct lcore_conf *qconf)
 {
@@ -1108,7 +1152,8 @@ print_usage(const char *prgname)
 		"  --config (port,queue,lcore): rx queues configuration\n"
 		"  --no-numa: optional, disable numa awareness\n"
 		"  --enable-jumbo: enable jumbo frame"
-		" which max packet len is PKTLEN in decimal (64-9600)\n",
+		" which max packet len is PKTLEN in decimal (64-9600)\n"
+		"  --parse-ptype: parse packet type by software\n",
 		prgname);
 }
 
@@ -1202,6 +1247,8 @@ parse_config(const char *q_arg)
 	return 0;
 }
 
+#define CMD_LINE_OPT_PARSE_PTYPE "parse-ptype"
+
 /* Parse the argument given in the command line of the application */
 static int
 parse_args(int argc, char **argv)
@@ -1214,6 +1261,7 @@ parse_args(int argc, char **argv)
 		{"config", 1, 0, 0},
 		{"no-numa", 0, 0, 0},
 		{"enable-jumbo", 0, 0, 0},
+		{CMD_LINE_OPT_PARSE_PTYPE, 0, 0, 0},
 		{NULL, 0, 0, 0}
 	};
 
@@ -1284,6 +1332,13 @@ parse_args(int argc, char **argv)
 				(unsigned int)port_conf.rxmode.max_rx_pkt_len);
 			}
 
+			if (!strncmp(lgopts[option_index].name,
+				     CMD_LINE_OPT_PARSE_PTYPE,
+				     sizeof(CMD_LINE_OPT_PARSE_PTYPE))) {
+				printf("soft parse-ptype is enabled\n");
+				parse_ptype = 1;
+			}
+
 			break;
 
 		default:
@@ -1531,6 +1586,51 @@ check_all_ports_link_status(uint8_t port_num, uint32_t port_mask)
 	}
 }
 
+static int check_ptype(uint8_t portid)
+{
+	int i, ret;
+	int ptype_l3_ipv4 = 0;
+#if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
+	int ptype_l3_ipv6 = 0;
+#endif
+	uint32_t ptype_mask = RTE_PTYPE_L3_MASK;
+
+	ret = rte_eth_dev_get_supported_ptypes(portid, ptype_mask, NULL, 0);
+	if (ret <= 0)
+		return 0;
+
+	uint32_t ptypes[ret];
+
+	ret = rte_eth_dev_get_supported_ptypes(portid, ptype_mask, ptypes, ret);
+	for (i = 0; i < ret; ++i) {
+		if (ptypes[i] & RTE_PTYPE_L3_IPV4)
+			ptype_l3_ipv4 = 1;
+#if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
+		if (ptypes[i] & RTE_PTYPE_L3_IPV6)
+			ptype_l3_ipv6 = 1;
+#endif
+	}
+
+	if (ptype_l3_ipv4 == 0)
+		printf("port %d cannot parse RTE_PTYPE_L3_IPV4\n", portid);
+
+#if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH)
+	if (ptype_l3_ipv6 == 0)
+		printf("port %d cannot parse RTE_PTYPE_L3_IPV6\n", portid);
+#endif
+
+#if (APP_LOOKUP_METHOD == APP_LOOKUP_LPM)
+	if (ptype_l3_ipv4)
+#else
+	// APP_LOOKUP_EXACT_MATCH
+	if (ptype_l3_ipv4 && ptype_l3_ipv6)
+#endif
+		return 1;
+
+	return 0;
+
+}
+
 int
 main(int argc, char **argv)
 {
@@ -1716,6 +1816,14 @@ main(int argc, char **argv)
 				rte_exit(EXIT_FAILURE,
 					"rte_eth_rx_queue_setup: err=%d, "
 						"port=%d\n", ret, portid);
+
+			if (parse_ptype) {
+				if (add_cb_parse_ptype(portid, queueid) < 0)
+					rte_exit(EXIT_FAILURE,
+						 "Fail to add ptype cb\n");
+			} else if (!check_ptype(portid))
+				rte_exit(EXIT_FAILURE,
+					 "PMD can not provide needed ptypes\n");
 		}
 	}
 
-- 
2.7.4

  parent reply	other threads:[~2017-01-16 14:46 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-04  0:18 [dpdk-dev] [PATCH 0/5] Interrupt mode for virtio PMD Jianfeng Tan
2016-12-04  0:18 ` [dpdk-dev] [PATCH 1/5] net/virtio: add Rx descriptor check Jianfeng Tan
2016-12-04  0:18 ` [dpdk-dev] [PATCH 2/5] net/virtio: setup Rx fastpath interrupts Jianfeng Tan
2016-12-04  0:18 ` [dpdk-dev] [PATCH 3/5] net/virtio: remove Rx queue interrupts when stopping Jianfeng Tan
2016-12-04  0:18 ` [dpdk-dev] [PATCH 4/5] net/virtio: add Rx queue intr enable/disable functions Jianfeng Tan
2016-12-04  0:18 ` [dpdk-dev] [PATCH 5/5] examples/l3fwd: add parse-ptype option Jianfeng Tan
2016-12-08  6:59   ` Yuanhan Liu
2016-12-08  7:40     ` Tan, Jianfeng
2016-12-29  7:30 ` [dpdk-dev] [PATCH v2 0/9] rxq interrupt mode for virtio PMD Jianfeng Tan
2016-12-29  7:30   ` [dpdk-dev] [PATCH v2 1/9] net/virtio: fix rewriting LSC flag Jianfeng Tan
2016-12-29  7:30   ` [dpdk-dev] [PATCH v2 2/9] net/virtio: add Rx descriptor check Jianfeng Tan
2016-12-29  7:30   ` [dpdk-dev] [PATCH v2 3/9] net/virtio: add PCI ops for queue/irq binding Jianfeng Tan
2016-12-30  5:46     ` Yuanhan Liu
2016-12-29  7:30   ` [dpdk-dev] [PATCH v2 4/9] net/virtio: add Rx queue intr enable/disable functions Jianfeng Tan
2016-12-30  5:59     ` Yuanhan Liu
2016-12-29  7:30   ` [dpdk-dev] [PATCH v2 5/9] net/virtio: setup rxq interrupts Jianfeng Tan
2016-12-30  6:27     ` Yuanhan Liu
2017-01-04  6:56       ` Tan, Jianfeng
2017-01-04  7:22         ` Yuanhan Liu
2017-01-04  7:30           ` Tan, Jianfeng
2016-12-29  7:30   ` [dpdk-dev] [PATCH v2 6/9] net/virtio: unbind intr/eventfd when stop device Jianfeng Tan
2016-12-29  7:30   ` [dpdk-dev] [PATCH v2 7/9] net/virtio: unmapping queue/irq when close device Jianfeng Tan
2016-12-30  6:30     ` Yuanhan Liu
2016-12-29  7:30   ` [dpdk-dev] [PATCH v2 8/9] examples/l3fwd: add parse-ptype option Jianfeng Tan
2016-12-30  6:39     ` Yuanhan Liu
2016-12-30  7:30       ` Tan, Jianfeng
2017-01-03  6:59         ` Yuanhan Liu
2016-12-29  7:30   ` [dpdk-dev] [PATCH v2 9/9] examples/l3fwd-power: fix not stop and close device Jianfeng Tan
2016-12-30  6:44     ` Yuanhan Liu
2016-12-30  6:56       ` Tan, Jianfeng
2016-12-29  7:42   ` [dpdk-dev] [PATCH v2 0/9] rxq interrupt mode for virtio PMD Tan, Jianfeng
2016-12-30  5:41     ` Yuanhan Liu
2016-12-30  6:57   ` Yuanhan Liu
2017-01-16 14:46 ` [dpdk-dev] [PATCH v3 00/10] " Jianfeng Tan
2017-01-16 14:46   ` [dpdk-dev] [PATCH v3 01/10] net/virtio: fix rewriting LSC flag Jianfeng Tan
2017-01-16 14:46   ` [dpdk-dev] [PATCH v3 02/10] net/virtio: clean up wrapper of set_config_irq Jianfeng Tan
2017-01-16 14:46   ` [dpdk-dev] [PATCH v3 03/10] net/virtio: add Rx descriptor check Jianfeng Tan
2017-01-16 19:16     ` Stephen Hemminger
2017-01-17  4:09       ` Yuanhan Liu
2017-01-16 14:46   ` [dpdk-dev] [PATCH v3 04/10] net/virtio: add PCI ops for queue/irq binding Jianfeng Tan
2017-01-16 14:46   ` [dpdk-dev] [PATCH v3 05/10] net/virtio: add Rx queue intr enable/disable functions Jianfeng Tan
2017-01-17  2:30     ` Jason Wang
2017-01-16 14:46   ` [dpdk-dev] [PATCH v3 06/10] net/virtio: setup rxq interrupts Jianfeng Tan
2017-01-16 14:46   ` [dpdk-dev] [PATCH v3 07/10] net/virtio: unbind intr/eventfd when stop device Jianfeng Tan
2017-01-16 14:47   ` [dpdk-dev] [PATCH v3 08/10] net/virtio: unmapping queue/irq when close device Jianfeng Tan
2017-01-16 14:47   ` Jianfeng Tan [this message]
2017-01-17  5:16     ` [dpdk-dev] [PATCH v3 09/10] examples/l3fwd-power: add parse-ptype option Yuanhan Liu
2017-01-17  5:23       ` Tan, Jianfeng
2017-01-16 14:47   ` [dpdk-dev] [PATCH v3 10/10] examples/l3fwd-power: fix not stop and close device Jianfeng Tan
2017-01-17  2:14   ` [dpdk-dev] [PATCH v3 00/10] rxq interrupt mode for virtio PMD Yao, Lei A
2017-01-17  7:10 ` [dpdk-dev] [PATCH v4 " Jianfeng Tan
2017-01-17  7:10   ` [dpdk-dev] [PATCH v4 01/10] net/virtio: fix rewriting LSC flag Jianfeng Tan
2017-01-17  7:10   ` [dpdk-dev] [PATCH v4 02/10] net/virtio: clean up wrapper of set_config_irq Jianfeng Tan
2017-01-17  7:10   ` [dpdk-dev] [PATCH v4 03/10] net/virtio: add Rx descriptor check Jianfeng Tan
2017-01-17  7:10   ` [dpdk-dev] [PATCH v4 04/10] net/virtio: add PCI ops for queue/irq binding Jianfeng Tan
2017-01-17  7:10   ` [dpdk-dev] [PATCH v4 05/10] net/virtio: add Rx queue intr enable/disable functions Jianfeng Tan
2017-01-17  7:10   ` [dpdk-dev] [PATCH v4 06/10] net/virtio: setup rxq interrupts Jianfeng Tan
2017-01-17  7:10   ` [dpdk-dev] [PATCH v4 07/10] net/virtio: unbind intr/eventfd when stop device Jianfeng Tan
2017-01-17  7:10   ` [dpdk-dev] [PATCH v4 08/10] net/virtio: unmapping queue/irq when close device Jianfeng Tan
2017-01-17  7:10   ` [dpdk-dev] [PATCH v4 09/10] examples/l3fwd-power: add parse-ptype option Jianfeng Tan
2017-01-17  7:10   ` [dpdk-dev] [PATCH v4 10/10] examples/l3fwd-power: fix not stop and close device Jianfeng Tan
2017-01-17  8:28   ` [dpdk-dev] [PATCH v4 00/10] rxq interrupt mode for virtio PMD Yuanhan Liu
2017-01-17  8:00 ` [dpdk-dev] [PATCH v5 06/10] net/virtio: setup rxq interrupts Jianfeng Tan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1484578022-92705-10-git-send-email-jianfeng.tan@intel.com \
    --to=jianfeng.tan@intel.com \
    --cc=dev@dpdk.org \
    --cc=lei.a.yao@intel.com \
    --cc=stephen@networkplumber.org \
    --cc=yuanhan.liu@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).