diff mbox

[dpdk-dev,2/3] app/test: use ethdev helper functions

Message ID 1455718817-14171-3-git-send-email-ferruh.yigit@intel.com (mailing list archive)
State Rejected, archived
Delegated to: Thomas Monjalon
Headers show

Commit Message

Ferruh Yigit Feb. 17, 2016, 2:20 p.m. UTC
Use rte_eth_by_port(), rte_eth_private_by_port(),
rte_eth_private_by_dev() helper functions.

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 app/test/test_link_bonding.c | 35 +++++++++++++++++-------------
 app/test/virtual_pmd.c       | 51 +++++++++++++++++++-------------------------
 2 files changed, 42 insertions(+), 44 deletions(-)
diff mbox

Patch

diff --git a/app/test/test_link_bonding.c b/app/test/test_link_bonding.c
index 7cbc289..f2e364b 100644
--- a/app/test/test_link_bonding.c
+++ b/app/test/test_link_bonding.c
@@ -4567,6 +4567,8 @@  test_alb_change_mac_in_reply_sent(void)
 	struct ether_addr bond_mac, client_mac;
 	struct ether_addr *slave_mac1, *slave_mac2;
 
+	struct rte_eth_dev *dev;
+
 	TEST_ASSERT_SUCCESS(
 			initialize_bonded_device_with_slaves(BONDING_MODE_ALB,
 					0, TEST_ALB_SLAVE_COUNT, 1),
@@ -4581,9 +4583,8 @@  test_alb_change_mac_in_reply_sent(void)
 				MAX_PKT_BURST);
 	}
 
-	ether_addr_copy(
-			rte_eth_devices[test_params->bonded_port_id].data->mac_addrs,
-			&bond_mac);
+	dev = rte_eth_by_port(test_params->bonded_port_id);
+	ether_addr_copy(dev->data->mac_addrs, &bond_mac);
 
 	/*
 	 * Generating four packets with different mac and ip addresses and sending
@@ -4629,10 +4630,10 @@  test_alb_change_mac_in_reply_sent(void)
 			ARP_OP_REPLY);
 	rte_eth_tx_burst(test_params->bonded_port_id, 0, &pkt, 1);
 
-	slave_mac1 =
-			rte_eth_devices[test_params->slave_port_ids[0]].data->mac_addrs;
-	slave_mac2 =
-			rte_eth_devices[test_params->slave_port_ids[1]].data->mac_addrs;
+	dev = rte_eth_by_port(test_params->slave_port_ids[0]);
+	slave_mac1 = dev->data->mac_addrs;
+	dev = rte_eth_by_port(test_params->slave_port_ids[1]);
+	slave_mac2 = dev->data->mac_addrs;
 
 	/*
 	 * Checking if packets are properly distributed on bonding ports. Packets
@@ -4681,6 +4682,8 @@  test_alb_reply_from_client(void)
 	struct ether_addr bond_mac, client_mac;
 	struct ether_addr *slave_mac1, *slave_mac2;
 
+	struct rte_eth_dev *dev;
+
 	TEST_ASSERT_SUCCESS(
 			initialize_bonded_device_with_slaves(BONDING_MODE_ALB,
 					0, TEST_ALB_SLAVE_COUNT, 1),
@@ -4694,9 +4697,8 @@  test_alb_reply_from_client(void)
 				MAX_PKT_BURST);
 	}
 
-	ether_addr_copy(
-			rte_eth_devices[test_params->bonded_port_id].data->mac_addrs,
-			&bond_mac);
+	dev = rte_eth_by_port(test_params->bonded_port_id);
+	ether_addr_copy(dev->data->mac_addrs, &bond_mac);
 
 	/*
 	 * Generating four packets with different mac and ip addresses and placing
@@ -4753,8 +4755,10 @@  test_alb_reply_from_client(void)
 	rte_eth_rx_burst(test_params->bonded_port_id, 0, pkts_sent, MAX_PKT_BURST);
 	rte_eth_tx_burst(test_params->bonded_port_id, 0, NULL, 0);
 
-	slave_mac1 = rte_eth_devices[test_params->slave_port_ids[0]].data->mac_addrs;
-	slave_mac2 = rte_eth_devices[test_params->slave_port_ids[1]].data->mac_addrs;
+	dev = rte_eth_by_port(test_params->slave_port_ids[0]);
+	slave_mac1 = dev->data->mac_addrs;
+	dev = rte_eth_by_port(test_params->slave_port_ids[1]);
+	slave_mac2 = dev->data->mac_addrs;
 
 	/*
 	 * Checking if update ARP packets were properly send on slave ports.
@@ -4808,6 +4812,8 @@  test_alb_receive_vlan_reply(void)
 
 	struct ether_addr bond_mac, client_mac;
 
+	struct rte_eth_dev *dev;
+
 	TEST_ASSERT_SUCCESS(
 			initialize_bonded_device_with_slaves(BONDING_MODE_ALB,
 					0, TEST_ALB_SLAVE_COUNT, 1),
@@ -4821,9 +4827,8 @@  test_alb_receive_vlan_reply(void)
 				MAX_PKT_BURST);
 	}
 
-	ether_addr_copy(
-			rte_eth_devices[test_params->bonded_port_id].data->mac_addrs,
-			&bond_mac);
+	dev = rte_eth_by_port(test_params->bonded_port_id);
+	ether_addr_copy(dev->data->mac_addrs, &bond_mac);
 
 	/*
 	 * Generating packet with double VLAN header and placing it in the rx queue.
diff --git a/app/test/virtual_pmd.c b/app/test/virtual_pmd.c
index a538c8a..b1af805 100644
--- a/app/test/virtual_pmd.c
+++ b/app/test/virtual_pmd.c
@@ -263,8 +263,8 @@  static const 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 *dev = &rte_eth_devices[port_id];
-	struct virtual_ethdev_private *dev_private = dev->data->dev_private;
+	struct virtual_ethdev_private *dev_private =
+		rte_eth_private_by_port(port_id);
 	struct eth_dev_ops *dev_ops = &dev_private->dev_ops;
 
 	if (success)
@@ -277,8 +277,8 @@  virtual_ethdev_start_fn_set_success(uint8_t port_id, uint8_t success)
 void
 virtual_ethdev_configure_fn_set_success(uint8_t port_id, uint8_t success)
 {
-	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
-	struct virtual_ethdev_private *dev_private = dev->data->dev_private;
+	struct virtual_ethdev_private *dev_private =
+		rte_eth_private_by_port(port_id);
 	struct eth_dev_ops *dev_ops = &dev_private->dev_ops;
 
 	if (success)
@@ -290,8 +290,8 @@  virtual_ethdev_configure_fn_set_success(uint8_t port_id, uint8_t success)
 void
 virtual_ethdev_rx_queue_setup_fn_set_success(uint8_t port_id, uint8_t success)
 {
-	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
-	struct virtual_ethdev_private *dev_private = dev->data->dev_private;
+	struct virtual_ethdev_private *dev_private =
+		rte_eth_private_by_port(port_id);
 	struct eth_dev_ops *dev_ops = &dev_private->dev_ops;
 
 	if (success)
@@ -303,8 +303,8 @@  virtual_ethdev_rx_queue_setup_fn_set_success(uint8_t port_id, uint8_t success)
 void
 virtual_ethdev_tx_queue_setup_fn_set_success(uint8_t port_id, uint8_t success)
 {
-	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
-	struct virtual_ethdev_private *dev_private = dev->data->dev_private;
+	struct virtual_ethdev_private *dev_private =
+		rte_eth_private_by_port(port_id);
 	struct eth_dev_ops *dev_ops = &dev_private->dev_ops;
 
 	if (success)
@@ -316,8 +316,8 @@  virtual_ethdev_tx_queue_setup_fn_set_success(uint8_t port_id, uint8_t success)
 void
 virtual_ethdev_link_update_fn_set_success(uint8_t port_id, uint8_t success)
 {
-	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
-	struct virtual_ethdev_private *dev_private = dev->data->dev_private;
+	struct virtual_ethdev_private *dev_private =
+		rte_eth_private_by_port(port_id);
 	struct eth_dev_ops *dev_ops = &dev_private->dev_ops;
 
 	if (success)
@@ -332,15 +332,13 @@  virtual_ethdev_rx_burst_success(void *queue __rte_unused,
 							 struct rte_mbuf **bufs,
 							 uint16_t nb_pkts)
 {
-	struct rte_eth_dev *vrtl_eth_dev;
 	struct virtual_ethdev_queue *pq_map;
 	struct virtual_ethdev_private *dev_private;
 
 	int rx_count, i;
 
 	pq_map = (struct virtual_ethdev_queue *)queue;
-	vrtl_eth_dev = &rte_eth_devices[pq_map->port_id];
-	dev_private = vrtl_eth_dev->data->dev_private;
+	dev_private = rte_eth_private_by_port(pq_map->port_id);
 
 	rx_count = rte_ring_dequeue_burst(dev_private->rx_queue, (void **) bufs,
 			nb_pkts);
@@ -374,7 +372,7 @@  virtual_ethdev_tx_burst_success(void *queue, struct rte_mbuf **bufs,
 
 	int i;
 
-	vrtl_eth_dev = &rte_eth_devices[tx_q->port_id];
+	vrtl_eth_dev = rte_eth_by_port(tx_q->port_id);
 	dev_private = vrtl_eth_dev->data->dev_private;
 
 	if (!vrtl_eth_dev->data->dev_link.link_status)
@@ -397,15 +395,13 @@  static uint16_t
 virtual_ethdev_tx_burst_fail(void *queue, struct rte_mbuf **bufs,
 		uint16_t nb_pkts)
 {
-	struct rte_eth_dev *vrtl_eth_dev = NULL;
 	struct virtual_ethdev_queue *tx_q = NULL;
 	struct virtual_ethdev_private *dev_private = NULL;
 
 	int i;
 
 	tx_q = (struct virtual_ethdev_queue *)queue;
-	vrtl_eth_dev = &rte_eth_devices[tx_q->port_id];
-	dev_private = vrtl_eth_dev->data->dev_private;
+	dev_private = rte_eth_private_by_port(tx_q->port_id);
 
 	if (dev_private->tx_burst_fail_count < nb_pkts) {
 		int successfully_txd = nb_pkts - dev_private->tx_burst_fail_count;
@@ -432,7 +428,7 @@  virtual_ethdev_tx_burst_fail(void *queue, struct rte_mbuf **bufs,
 void
 virtual_ethdev_rx_burst_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 *vrtl_eth_dev = rte_eth_by_port(port_id);
 
 	if (success)
 		vrtl_eth_dev->rx_pkt_burst = virtual_ethdev_rx_burst_success;
@@ -445,7 +441,7 @@  void
 virtual_ethdev_tx_burst_fn_set_success(uint8_t port_id, uint8_t success)
 {
 	struct virtual_ethdev_private *dev_private = NULL;
-	struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
+	struct rte_eth_dev *vrtl_eth_dev = rte_eth_by_port(port_id);
 
 	dev_private = vrtl_eth_dev->data->dev_private;
 
@@ -461,18 +457,17 @@  void
 virtual_ethdev_tx_burst_fn_set_tx_pkt_fail_count(uint8_t port_id,
 		uint8_t packet_fail_count)
 {
-	struct virtual_ethdev_private *dev_private = NULL;
-	struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
+	struct virtual_ethdev_private *dev_private;
 
 
-	dev_private = vrtl_eth_dev->data->dev_private;
+	dev_private = rte_eth_private_by_port(port_id);
 	dev_private->tx_burst_fail_count = packet_fail_count;
 }
 
 void
 virtual_ethdev_set_link_status(uint8_t port_id, uint8_t link_status)
 {
-	struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
+	struct rte_eth_dev *vrtl_eth_dev = rte_eth_by_port(port_id);
 
 	vrtl_eth_dev->data->dev_link.link_status = link_status;
 }
@@ -481,7 +476,7 @@  void
 virtual_ethdev_simulate_link_status_interrupt(uint8_t port_id,
 		uint8_t link_status)
 {
-	struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
+	struct rte_eth_dev *vrtl_eth_dev = rte_eth_by_port(port_id);
 
 	vrtl_eth_dev->data->dev_link.link_status = link_status;
 
@@ -492,9 +487,8 @@  int
 virtual_ethdev_add_mbufs_to_rx_queue(uint8_t port_id,
 		struct rte_mbuf **pkt_burst, int burst_length)
 {
-	struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
 	struct virtual_ethdev_private *dev_private =
-			vrtl_eth_dev->data->dev_private;
+			rte_eth_private_by_port(port_id);
 
 	return rte_ring_enqueue_burst(dev_private->rx_queue, (void **)pkt_burst,
 			burst_length);
@@ -504,10 +498,9 @@  int
 virtual_ethdev_get_mbufs_from_tx_queue(uint8_t port_id,
 		struct rte_mbuf **pkt_burst, int burst_length)
 {
-	struct virtual_ethdev_private *dev_private;
-	struct rte_eth_dev *vrtl_eth_dev = &rte_eth_devices[port_id];
+	struct virtual_ethdev_private *dev_private =
+			rte_eth_private_by_port(port_id);
 
-	dev_private = vrtl_eth_dev->data->dev_private;
 	return rte_ring_dequeue_burst(dev_private->tx_queue, (void **)pkt_burst,
 		burst_length);
 }