From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9D1A5A056A; Mon, 2 Mar 2020 18:37:40 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E9CFE1C002; Mon, 2 Mar 2020 18:37:04 +0100 (CET) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id E0A9F1C044 for ; Mon, 2 Mar 2020 18:37:02 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Mar 2020 09:37:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,507,1574150400"; d="scan'208";a="228535194" Received: from silpixa00399752.ir.intel.com (HELO silpixa00399752.ger.corp.intel.com) ([10.237.222.180]) by orsmga007.jf.intel.com with ESMTP; 02 Mar 2020 09:37:00 -0800 From: Ferruh Yigit To: dev@dpdk.org, John McNamara , Marko Kovacevic , Tetsuya Mukawa Cc: Ferruh Yigit Date: Mon, 2 Mar 2020 17:36:45 +0000 Message-Id: <20200302173646.54984-6-ferruh.yigit@intel.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200302173646.54984-1-ferruh.yigit@intel.com> References: <20200302173646.54984-1-ferruh.yigit@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 6/6] net/null: add argument for no Rx X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add an new device argument 'no-rx', which will prevent PMD receiving packets. This is useful for testing when a PMD is needed only to send packets to. Signed-off-by: Ferruh Yigit --- doc/guides/nics/null.rst | 4 +++ drivers/net/null/rte_eth_null.c | 55 ++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/doc/guides/nics/null.rst b/doc/guides/nics/null.rst index 405edf07b..c68d0d605 100644 --- a/doc/guides/nics/null.rst +++ b/doc/guides/nics/null.rst @@ -37,3 +37,7 @@ Runtime Config Options $RTE_TARGET/app/testpmd -l 0-3 -n 4 --vdev "net_null0,size=256" -- -i +- ``no-rx`` [optional, default disabled] + + Makes PMD more like ``/dev/null``. On Rx no packets received, on Tx all packets are freed. + This option can't co-exist with ``copy`` option. diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c index 2c08ebf8c..11258ccea 100644 --- a/drivers/net/null/rte_eth_null.c +++ b/drivers/net/null/rte_eth_null.c @@ -14,13 +14,16 @@ #define ETH_NULL_PACKET_SIZE_ARG "size" #define ETH_NULL_PACKET_COPY_ARG "copy" +#define ETH_NULL_PACKET_NO_RX_ARG "no-rx" static unsigned int default_packet_size = 64; static unsigned int default_packet_copy; +static unsigned int default_no_rx; static const char *valid_arguments[] = { ETH_NULL_PACKET_SIZE_ARG, ETH_NULL_PACKET_COPY_ARG, + ETH_NULL_PACKET_NO_RX_ARG, NULL }; @@ -39,11 +42,13 @@ struct null_queue { struct pmd_options { unsigned int packet_copy; unsigned int packet_size; + unsigned int no_rx; }; struct pmd_internals { unsigned int packet_size; unsigned int packet_copy; + unsigned int no_rx; uint16_t port_id; struct null_queue rx_null_queues[RTE_MAX_QUEUES_PER_PORT]; @@ -126,6 +131,13 @@ eth_null_copy_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) return i; } +static uint16_t +eth_null_no_rx(void *q __rte_unused, struct rte_mbuf **bufs __rte_unused, + uint16_t nb_bufs __rte_unused) +{ + return 0; +} + static uint16_t eth_null_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) { @@ -504,6 +516,7 @@ eth_dev_null_create(struct rte_vdev_device *dev, struct pmd_options *args) internals = eth_dev->data->dev_private; internals->packet_size = args->packet_size; internals->packet_copy = args->packet_copy; + internals->no_rx = args->no_rx; internals->port_id = eth_dev->data->port_id; rte_eth_random_addr(internals->eth_addr.addr_bytes); @@ -526,6 +539,9 @@ eth_dev_null_create(struct rte_vdev_device *dev, struct pmd_options *args) if (internals->packet_copy) { eth_dev->rx_pkt_burst = eth_null_copy_rx; eth_dev->tx_pkt_burst = eth_null_copy_tx; + } else if (internals->no_rx) { + eth_dev->rx_pkt_burst = eth_null_no_rx; + eth_dev->tx_pkt_burst = eth_null_tx; } else { eth_dev->rx_pkt_burst = eth_null_rx; eth_dev->tx_pkt_burst = eth_null_tx; @@ -569,6 +585,24 @@ get_packet_copy_arg(const char *key __rte_unused, return 0; } +static int +get_packet_no_rx_arg(const char *key __rte_unused, + const char *value, void *extra_args) +{ + const char *a = value; + unsigned int no_rx; + + if (value == NULL || extra_args == NULL) + return -EINVAL; + + no_rx = (unsigned int)strtoul(a, NULL, 0); + if (no_rx != 0 && no_rx != 1) + return -1; + + *(unsigned int *)extra_args = no_rx; + return 0; +} + static int rte_pmd_null_probe(struct rte_vdev_device *dev) { @@ -576,6 +610,7 @@ rte_pmd_null_probe(struct rte_vdev_device *dev) struct pmd_options args = { .packet_copy = default_packet_copy, .packet_size = default_packet_size, + .no_rx = default_no_rx, }; struct rte_kvargs *kvlist = NULL; struct rte_eth_dev *eth_dev; @@ -602,6 +637,9 @@ rte_pmd_null_probe(struct rte_vdev_device *dev) if (internals->packet_copy) { eth_dev->rx_pkt_burst = eth_null_copy_rx; eth_dev->tx_pkt_burst = eth_null_copy_tx; + } else if (internals->no_rx) { + eth_dev->rx_pkt_burst = eth_null_no_rx; + eth_dev->tx_pkt_burst = eth_null_tx; } else { eth_dev->rx_pkt_burst = eth_null_rx; eth_dev->tx_pkt_burst = eth_null_tx; @@ -627,6 +665,20 @@ rte_pmd_null_probe(struct rte_vdev_device *dev) &get_packet_copy_arg, &args.packet_copy); if (ret < 0) goto free_kvlist; + + ret = rte_kvargs_process(kvlist, + ETH_NULL_PACKET_NO_RX_ARG, + &get_packet_no_rx_arg, &args.no_rx); + if (ret < 0) + goto free_kvlist; + + if (args.no_rx && args.packet_copy) { + PMD_LOG(ERR, + "Both %s and %s arguments at the same time not supported", + ETH_NULL_PACKET_COPY_ARG, + ETH_NULL_PACKET_NO_RX_ARG); + goto free_kvlist; + } } PMD_LOG(INFO, "Configure pmd_null: packet size is %d, " @@ -675,7 +727,8 @@ RTE_PMD_REGISTER_VDEV(net_null, pmd_null_drv); RTE_PMD_REGISTER_ALIAS(net_null, eth_null); RTE_PMD_REGISTER_PARAM_STRING(net_null, "size= " - "copy="); + "copy= " + ETH_NULL_PACKET_NO_RX_ARG "=0|1"); RTE_INIT(eth_null_init_log) { -- 2.24.1