DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v2 5/6] test: put dev_ops in private
Date: Tue,  7 Apr 2015 14:21:02 -0700	[thread overview]
Message-ID: <1428441663-3825-5-git-send-email-stephen@networkplumber.org> (raw)
In-Reply-To: <1428441663-3825-1-git-send-email-stephen@networkplumber.org>

The test PMD uses a special type of eth_dev_ops to test features.
Rather allocating this separately, just put in the private data area.
This allows for next change to make dev_ops const.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
v2 -- split into separate patch and put dev_ops in private

 app/test/virtual_pmd.c | 57 +++++++++++++++++++++++++-------------------------
 1 file changed, 28 insertions(+), 29 deletions(-)

diff --git a/app/test/virtual_pmd.c b/app/test/virtual_pmd.c
index 1f4da96..3ae8c90 100644
--- a/app/test/virtual_pmd.c
+++ b/app/test/virtual_pmd.c
@@ -45,6 +45,7 @@
 static const char *virtual_ethdev_driver_name = "Virtual PMD";
 
 struct virtual_ethdev_private {
+	struct eth_dev_ops dev_ops;
 	struct rte_eth_stats eth_stats;
 
 	struct rte_ring *rx_queue;
@@ -262,61 +263,67 @@ static struct eth_dev_ops virtual_ethdev_default_dev_ops = {
 void
 virtual_ethdev_start_fn_set_success(uint8_t port_id, uint8_t success)
 {
-	struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	struct virtual_ethdev_private *dev_private = dev->data->dev_private;
+	struct eth_dev_ops *dev_ops = &dev_private->dev_ops;
 
 	if (success)
-		vrtl_eth_dev->dev_ops->dev_start = virtual_ethdev_start_success;
+		dev_ops->dev_start = virtual_ethdev_start_success;
 	else
-		vrtl_eth_dev->dev_ops->dev_start = virtual_ethdev_start_fail;
+		dev_ops->dev_start = virtual_ethdev_start_fail;
 
 }
 
 void
 virtual_ethdev_configure_fn_set_success(uint8_t port_id, uint8_t success)
 {
-	struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	struct virtual_ethdev_private *dev_private = dev->data->dev_private;
+	struct eth_dev_ops *dev_ops = &dev_private->dev_ops;
 
 	if (success)
-		vrtl_eth_dev->dev_ops->dev_configure = virtual_ethdev_configure_success;
+		dev_ops->dev_configure = virtual_ethdev_configure_success;
 	else
-		vrtl_eth_dev->dev_ops->dev_configure = virtual_ethdev_configure_fail;
+		dev_ops->dev_configure = virtual_ethdev_configure_fail;
 }
 
 void
 virtual_ethdev_rx_queue_setup_fn_set_success(uint8_t port_id, uint8_t success)
 {
-	struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	struct virtual_ethdev_private *dev_private = dev->data->dev_private;
+	struct eth_dev_ops *dev_ops = &dev_private->dev_ops;
 
 	if (success)
-		vrtl_eth_dev->dev_ops->rx_queue_setup =
-				virtual_ethdev_rx_queue_setup_success;
+		dev_ops->rx_queue_setup = virtual_ethdev_rx_queue_setup_success;
 	else
-		vrtl_eth_dev->dev_ops->rx_queue_setup =
-				virtual_ethdev_rx_queue_setup_fail;
+		dev_ops->rx_queue_setup = virtual_ethdev_rx_queue_setup_fail;
 }
 
 void
 virtual_ethdev_tx_queue_setup_fn_set_success(uint8_t port_id, uint8_t success)
 {
-	struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	struct virtual_ethdev_private *dev_private = dev->data->dev_private;
+	struct eth_dev_ops *dev_ops = &dev_private->dev_ops;
 
 	if (success)
-		vrtl_eth_dev->dev_ops->tx_queue_setup =
-				virtual_ethdev_tx_queue_setup_success;
+		dev_ops->tx_queue_setup = virtual_ethdev_tx_queue_setup_success;
 	else
-		vrtl_eth_dev->dev_ops->tx_queue_setup =
-				virtual_ethdev_tx_queue_setup_fail;
+		dev_ops->tx_queue_setup = virtual_ethdev_tx_queue_setup_fail;
 }
 
 void
 virtual_ethdev_link_update_fn_set_success(uint8_t port_id, uint8_t success)
 {
-	struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	struct virtual_ethdev_private *dev_private = dev->data->dev_private;
+	struct eth_dev_ops *dev_ops = &dev_private->dev_ops;
 
 	if (success)
-		vrtl_eth_dev->dev_ops->link_update = virtual_ethdev_link_update_success;
+		dev_ops->link_update = virtual_ethdev_link_update_success;
 	else
-		vrtl_eth_dev->dev_ops->link_update = virtual_ethdev_link_update_fail;
+		dev_ops->link_update = virtual_ethdev_link_update_fail;
 }
 
 
@@ -528,7 +535,6 @@ virtual_ethdev_create(const char *name, struct ether_addr *mac_addr,
 	struct rte_eth_dev *eth_dev = NULL;
 	struct eth_driver *eth_drv = NULL;
 	struct rte_pci_driver *pci_drv = NULL;
-	struct eth_dev_ops *dev_ops = NULL;
 	struct rte_pci_id *id_table = NULL;
 	struct virtual_ethdev_private *dev_private = NULL;
 	char name_buf[RTE_RING_NAMESIZE];
@@ -553,10 +559,6 @@ virtual_ethdev_create(const char *name, struct ether_addr *mac_addr,
 	if (pci_drv == NULL)
 		goto err;
 
-	dev_ops = rte_zmalloc_socket(name, sizeof(*dev_ops), 0, socket_id);
-	if (dev_ops == NULL)
-		goto err;
-
 	id_table = rte_zmalloc_socket(name, sizeof(*id_table), 0, socket_id);
 	if (id_table == NULL)
 		goto err;
@@ -618,11 +620,9 @@ virtual_ethdev_create(const char *name, struct ether_addr *mac_addr,
 
 	eth_dev->data->dev_private = dev_private;
 
-	eth_dev->dev_ops = dev_ops;
-
 	/* Copy default device operation functions */
-	memcpy(eth_dev->dev_ops, &virtual_ethdev_default_dev_ops,
-			sizeof(*eth_dev->dev_ops));
+	dev_private->dev_ops = virtual_ethdev_default_dev_ops;
+	eth_dev->dev_ops = &dev_private->dev_ops;
 
 	eth_dev->pci_dev = pci_dev;
 	eth_dev->pci_dev->driver = &eth_drv->pci_drv;
@@ -638,7 +638,6 @@ err:
 	rte_free(pci_dev);
 	rte_free(pci_drv);
 	rte_free(eth_drv);
-	rte_free(dev_ops);
 	rte_free(id_table);
 	rte_free(dev_private);
 
-- 
2.1.4

  parent reply	other threads:[~2015-04-07 21:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-07 21:20 [dpdk-dev] [PATCH v2 1/6] test: remove useless memset Stephen Hemminger
2015-04-07 21:20 ` [dpdk-dev] [PATCH v2 2/6] test: remove useless check of NULL before rte_free Stephen Hemminger
2015-04-07 21:21 ` [dpdk-dev] [PATCH v2 3/6] examples: get rid of unneeded null checks " Stephen Hemminger
2015-04-07 21:21 ` [dpdk-dev] [PATCH v2 4/6] pmd: remove unnecessary if() " Stephen Hemminger
2015-04-07 21:21 ` Stephen Hemminger [this message]
2015-04-07 21:21 ` [dpdk-dev] [PATCH v2 6/6] eth: make dev_ops const Stephen Hemminger
2015-04-08 11:49 ` [dpdk-dev] [PATCH v2 1/6] test: remove useless memset Neil Horman
2015-04-13 20:36   ` Thomas Monjalon

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=1428441663-3825-5-git-send-email-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    /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).