From patchwork Sun Nov 5 10:15:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Matveychikov X-Patchwork-Id: 31176 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 39D721B2E3; Sun, 5 Nov 2017 11:15:12 +0100 (CET) Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by dpdk.org (Postfix) with ESMTP id C5BAE1B2D4 for ; Sun, 5 Nov 2017 11:15:11 +0100 (CET) Received: by mail-wm0-f67.google.com with SMTP id p75so8569783wmg.3 for ; Sun, 05 Nov 2017 02:15:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:content-transfer-encoding:mime-version:subject:date:references :to:in-reply-to:message-id; bh=4OJK4++VlfQVYTQe1YSTRZ98nj3B9PlxQrpwBXnEtn8=; b=CWvj4CvSC07cDe6zkOD6tTnQN75MgA8c7X1T9GiZKKgrLAXpgzxf5BR1abIFHwALCM RtqXO2B0Vf43bhbhT8UHWrs4sIt2W9C8HnszPyUN5vp7z4FZ9L01cwky/Nzg2xJL1jS1 BZ0c3wmPJifriq5jS9DSTVRHEFWGoXBkOvskOK7p9I8HBq+A0GneRsvk5XMQ3mzrfKLB xFATpawMdV5MD4u3AkDTGGZf4x07vC6jKDPHoExyBT4VKr9OKgdx+pJqpKk+jzqGEav8 mUQrDs1ARJFMl4/+IC0K/a1ogv4tBD7oEuf4FjaqdctCdpVW7c+P6nsMdvbu1Vje8AkI N4+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:date:references:to:in-reply-to:message-id; bh=4OJK4++VlfQVYTQe1YSTRZ98nj3B9PlxQrpwBXnEtn8=; b=F2GMR+6MCOIon/t6h0adGgH5GH2v5dk8ctENxocI539o6L6hPOojI1YtrsCOK8agaF Alqd4tD/qBPZr/u+KaePPlb1USRkqesAUwD6Rb//dV0f0vMY5Vu85Xpms7edLIF5mc2j kA7h8ehqqkfZ19Zv3Nq2+6IP3Mj+gfT6hJ1VW3tpSQF5Ww+pBFn/3RFPw6uaZcPjJW0+ gxJPdh1RLRMrpltizpwrFKDN8V1awcYoEbO5PM8EST7j0K1BWOXl/l4MuBW2vfOTBM+P eBvRrXNVo/smJHkImUqi7d8GW0mbqurKr0Sk52sNUH7ocK+ikIA64BrR83NsGHDVtoNU r5LA== X-Gm-Message-State: AMCzsaUNXcHFEAdUt9OzEbZAHWUHP7zS4KzEUGNvreNya2R0AurM8Bun ucronf0m7AAE2cUG2YWRooao2zvT X-Google-Smtp-Source: ABhQp+SkiXEd0gqFBG87XVKmxPiam8mIsPHiNDMob71KM0QOzFAu05Fhw+XxUwIlhghaBUgNjUwc3w== X-Received: by 10.80.181.71 with SMTP id z7mr15924391edd.201.1509876911158; Sun, 05 Nov 2017 02:15:11 -0800 (PST) Received: from [10.0.1.160] ([78.129.189.119]) by smtp.gmail.com with ESMTPSA id w7sm9361526edw.65.2017.11.05.02.15.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 05 Nov 2017 02:15:10 -0800 (PST) From: Ilya Matveychikov Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Date: Sun, 5 Nov 2017 14:15:09 +0400 References: To: dev@dpdk.org In-Reply-To: Message-Id: X-Mailer: Apple Mail (2.3273) Subject: [dpdk-dev] net/pcap: remove single interface constraint (v2) 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" Hello folks, This patch removes single interface constraint from the libpcap-based PMD. The problem it solves is to allow PCAP device consists of more than single device: # testpmd --vdev net_pcap0,iface=vethA,iface=vethB,iface=vethC and so.. I found the issue when performed RSS emulation based on PCAP PMD. For my task I had to create multi-queue PCAP device based on a number of veth devices which in turn was combined in bonding device. Signed-off-by: Ilya V. Matveychikov --- drivers/net/pcap/rte_eth_pcap.c | 77 +++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 34 deletions(-) -- 2.7.4 diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c index defb3b4..ae03c3b 100644 --- a/drivers/net/pcap/rte_eth_pcap.c +++ b/drivers/net/pcap/rte_eth_pcap.c @@ -94,7 +94,6 @@ struct pmd_internals { struct pcap_rx_queue rx_queue[RTE_PMD_PCAP_MAX_QUEUES]; struct pcap_tx_queue tx_queue[RTE_PMD_PCAP_MAX_QUEUES]; int if_index; - int single_iface; }; struct pmd_devargs { @@ -441,15 +440,19 @@ eth_dev_start(struct rte_eth_dev *dev) struct pcap_rx_queue *rx; /* Special iface case. Single pcap is open and shared between tx/rx. */ - if (internals->single_iface) { - tx = &internals->tx_queue[0]; - rx = &internals->rx_queue[0]; - - if (!tx->pcap && strcmp(tx->type, ETH_PCAP_IFACE_ARG) == 0) { - if (open_single_iface(tx->name, &tx->pcap) < 0) - return -1; - rx->pcap = tx->pcap; + if (internals->tx_queue[0].pcap == internals->rx_queue[0].pcap) { + RTE_ASSERT(dev->data->nb_tx_queues == dev->data->nb_rx_queues); + for (i = 0; i < dev->data->nb_tx_queues; i++) { + tx = &internals->tx_queue[i]; + rx = &internals->rx_queue[i]; + + if (!tx->pcap && strcmp(tx->type, ETH_PCAP_IFACE_ARG) == 0) { + if (open_single_iface(tx->name, &tx->pcap) < 0) + return -1; + rx->pcap = tx->pcap; + } } + goto status_up; } @@ -504,12 +507,15 @@ eth_dev_stop(struct rte_eth_dev *dev) struct pcap_rx_queue *rx; /* Special iface case. Single pcap is open and shared between tx/rx. */ - if (internals->single_iface) { - tx = &internals->tx_queue[0]; - rx = &internals->rx_queue[0]; - pcap_close(tx->pcap); - tx->pcap = NULL; - rx->pcap = NULL; + if (internals->tx_queue[0].pcap == internals->rx_queue[0].pcap) { + RTE_ASSERT(dev->data->nb_tx_queues == dev->data->nb_rx_queues); + for (i = 0; i < dev->data->nb_tx_queues; i++) { + tx = &internals->tx_queue[i]; + rx = &internals->rx_queue[i]; + pcap_close(tx->pcap); + tx->pcap = NULL; + rx->pcap = NULL; + } goto status_down; } @@ -730,6 +736,7 @@ open_tx_pcap(const char *key, const char *value, void *extra_args) static inline int open_rx_tx_iface(const char *key, const char *value, void *extra_args) { + unsigned int i; const char *iface = value; struct pmd_devargs *tx = extra_args; pcap_t *pcap = NULL; @@ -737,9 +744,14 @@ open_rx_tx_iface(const char *key, const char *value, void *extra_args) if (open_single_iface(iface, &pcap) < 0) return -1; - tx->queue[0].pcap = pcap; - tx->queue[0].name = iface; - tx->queue[0].type = key; + for (i = 0; i < tx->num_of_queue; i++) { + if (tx->queue[i].pcap == NULL) { + tx->queue[i].pcap = pcap; + tx->queue[i].name = iface; + tx->queue[i].type = key; + break; + } + } return 0; } @@ -901,8 +913,7 @@ 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, - struct rte_kvargs *kvlist, int single_iface, - unsigned int using_dumpers) + struct rte_kvargs *kvlist, unsigned int using_dumpers) { struct pmd_internals *internals = NULL; struct rte_eth_dev *eth_dev = NULL; @@ -914,9 +925,6 @@ eth_from_pcaps(struct rte_vdev_device *vdev, if (ret < 0) return ret; - /* store weather we are using a single interface for rx/tx or not */ - internals->single_iface = single_iface; - eth_dev->rx_pkt_burst = eth_pcap_rx; if (using_dumpers) @@ -935,7 +943,6 @@ pmd_pcap_probe(struct rte_vdev_device *dev) struct rte_kvargs *kvlist; struct pmd_devargs pcaps = {0}; struct pmd_devargs dumpers = {0}; - int single_iface = 0; int ret; name = rte_vdev_device_name(dev); @@ -953,19 +960,21 @@ pmd_pcap_probe(struct rte_vdev_device *dev) * If iface argument is passed we open the NICs and use them for * reading / writing */ - if (rte_kvargs_count(kvlist, ETH_PCAP_IFACE_ARG) == 1) { + if (rte_kvargs_count(kvlist, ETH_PCAP_IFACE_ARG)) { + int i, queues = rte_kvargs_count(kvlist, ETH_PCAP_IFACE_ARG); - ret = rte_kvargs_process(kvlist, ETH_PCAP_IFACE_ARG, - &open_rx_tx_iface, &pcaps); + pcaps.num_of_queue = queues; + dumpers.num_of_queue = queues; - if (ret < 0) - goto free_kvlist; + for (i = 0; i < queues; i++) { + ret = rte_kvargs_process(kvlist, ETH_PCAP_IFACE_ARG, + &open_rx_tx_iface, &pcaps); - dumpers.queue[0] = pcaps.queue[0]; + if (ret < 0) + goto free_kvlist; - single_iface = 1; - pcaps.num_of_queue = 1; - dumpers.num_of_queue = 1; + dumpers.queue[i] = pcaps.queue[i]; + } goto create_eth; } @@ -1020,7 +1029,7 @@ pmd_pcap_probe(struct rte_vdev_device *dev) create_eth: ret = eth_from_pcaps(dev, &pcaps, pcaps.num_of_queue, &dumpers, - dumpers.num_of_queue, kvlist, single_iface, is_tx_pcap); + dumpers.num_of_queue, kvlist, is_tx_pcap); free_kvlist: rte_kvargs_free(kvlist);