[dpdk-dev] [PATCH 19.08 v3 1/2] net/pcap: use a struct to pass user options

Cian Ferriter cian.ferriter at intel.com
Fri Jun 14 16:43:36 CEST 2019


The argument lists on some of the device creation functions are quite
large. Using a struct to hold the user options parsed in
'pmd_pcap_probe' will allow for cleaner function calls and definitions.
Adding user options will also be easier.

Signed-off-by: Cian Ferriter <cian.ferriter at intel.com>
---
 drivers/net/pcap/rte_eth_pcap.c | 51 ++++++++++++++++++++++-----------
 1 file changed, 35 insertions(+), 16 deletions(-)

diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
index 10277b9b6..c35f501cf 100644
--- a/drivers/net/pcap/rte_eth_pcap.c
+++ b/drivers/net/pcap/rte_eth_pcap.c
@@ -101,6 +101,14 @@ struct pmd_devargs {
 	int phy_mac;
 };
 
+struct pmd_devargs_all {
+	struct pmd_devargs rx_queues;
+	struct pmd_devargs tx_queues;
+	int single_iface;
+	unsigned int is_tx_pcap;
+	unsigned int is_tx_iface;
+};
+
 static const char *valid_arguments[] = {
 	ETH_PCAP_RX_PCAP_ARG,
 	ETH_PCAP_TX_PCAP_ARG,
@@ -1061,11 +1069,14 @@ eth_pcap_update_mac(const char *if_name, struct rte_eth_dev *eth_dev,
 
 static int
 eth_from_pcaps_common(struct rte_vdev_device *vdev,
-		struct pmd_devargs *rx_queues, const unsigned int nb_rx_queues,
-		struct pmd_devargs *tx_queues, const unsigned int nb_tx_queues,
+		struct pmd_devargs_all *devargs_all,
 		struct pmd_internals **internals, struct rte_eth_dev **eth_dev)
 {
 	struct pmd_process_private *pp;
+	struct pmd_devargs *rx_queues = &devargs_all->rx_queues;
+	struct pmd_devargs *tx_queues = &devargs_all->tx_queues;
+	const unsigned int nb_rx_queues = rx_queues->num_of_queue;
+	const unsigned int nb_tx_queues = tx_queues->num_of_queue;
 	unsigned int i;
 
 	/* do some parameter checking */
@@ -1103,16 +1114,15 @@ eth_from_pcaps_common(struct rte_vdev_device *vdev,
 
 static int
 eth_from_pcaps(struct rte_vdev_device *vdev,
-		struct pmd_devargs *rx_queues, const unsigned int nb_rx_queues,
-		struct pmd_devargs *tx_queues, const unsigned int nb_tx_queues,
-		int single_iface, unsigned int using_dumpers)
+		struct pmd_devargs_all *devargs_all)
 {
 	struct pmd_internals *internals = NULL;
 	struct rte_eth_dev *eth_dev = NULL;
+	struct pmd_devargs *rx_queues = &devargs_all->rx_queues;
+	int single_iface = devargs_all->single_iface;
 	int ret;
 
-	ret = eth_from_pcaps_common(vdev, rx_queues, nb_rx_queues,
-		tx_queues, nb_tx_queues, &internals, &eth_dev);
+	ret = eth_from_pcaps_common(vdev, devargs_all, &internals, &eth_dev);
 
 	if (ret < 0)
 		return ret;
@@ -1134,7 +1144,8 @@ eth_from_pcaps(struct rte_vdev_device *vdev,
 
 	eth_dev->rx_pkt_burst = eth_pcap_rx;
 
-	if (using_dumpers)
+	/* Assign tx ops. */
+	if (devargs_all->is_tx_pcap)
 		eth_dev->tx_pkt_burst = eth_pcap_tx_dumper;
 	else
 		eth_dev->tx_pkt_burst = eth_pcap_tx;
@@ -1147,15 +1158,20 @@ static int
 pmd_pcap_probe(struct rte_vdev_device *dev)
 {
 	const char *name;
-	unsigned int is_rx_pcap = 0, is_tx_pcap = 0;
+	unsigned int is_rx_pcap = 0;
 	struct rte_kvargs *kvlist;
 	struct pmd_devargs pcaps = {0};
 	struct pmd_devargs dumpers = {0};
 	struct rte_eth_dev *eth_dev =  NULL;
 	struct pmd_internals *internal;
-	int single_iface = 0;
 	int ret;
 
+	struct pmd_devargs_all devargs_all = {
+		.single_iface = 0,
+		.is_tx_pcap = 0,
+		.is_tx_iface = 0,
+	};
+
 	name = rte_vdev_device_name(dev);
 	PMD_LOG(INFO, "Initializing pmd_pcap for %s", name);
 
@@ -1202,7 +1218,7 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 
 		dumpers.phy_mac = pcaps.phy_mac;
 
-		single_iface = 1;
+		devargs_all.single_iface = 1;
 		pcaps.num_of_queue = 1;
 		dumpers.num_of_queue = 1;
 
@@ -1231,10 +1247,11 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 	 * We check whether we want to open a TX stream to a real NIC or a
 	 * pcap file
 	 */
-	is_tx_pcap = rte_kvargs_count(kvlist, ETH_PCAP_TX_PCAP_ARG) ? 1 : 0;
+	devargs_all.is_tx_pcap =
+		rte_kvargs_count(kvlist, ETH_PCAP_TX_PCAP_ARG) ? 1 : 0;
 	dumpers.num_of_queue = 0;
 
-	if (is_tx_pcap)
+	if (devargs_all.is_tx_pcap)
 		ret = rte_kvargs_process(kvlist, ETH_PCAP_TX_PCAP_ARG,
 				&open_tx_pcap, &dumpers);
 	else
@@ -1276,7 +1293,7 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 
 		eth_dev->process_private = pp;
 		eth_dev->rx_pkt_burst = eth_pcap_rx;
-		if (is_tx_pcap)
+		if (devargs_all.is_tx_pcap)
 			eth_dev->tx_pkt_burst = eth_pcap_tx_dumper;
 		else
 			eth_dev->tx_pkt_burst = eth_pcap_tx;
@@ -1285,8 +1302,10 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
 		goto free_kvlist;
 	}
 
-	ret = eth_from_pcaps(dev, &pcaps, pcaps.num_of_queue, &dumpers,
-		dumpers.num_of_queue, single_iface, is_tx_pcap);
+	devargs_all.rx_queues = pcaps;
+	devargs_all.tx_queues = dumpers;
+
+	ret = eth_from_pcaps(dev, &devargs_all);
 
 free_kvlist:
 	rte_kvargs_free(kvlist);
-- 
2.17.1



More information about the dev mailing list