DPDK patches and discussions
 help / color / mirror / Atom feed
From: Lijun Ou <oulijun@huawei.com>
To: <ferruh.yigit@intel.com>
Cc: <dev@dpdk.org>, <linuxarm@huawei.com>
Subject: [dpdk-dev] [PATCH 6/7] net/hns3: fix directly access with rte device
Date: Sun, 13 Dec 2020 16:03:04 +0800
Message-ID: <1607846585-2381-7-git-send-email-oulijun@huawei.com> (raw)
In-Reply-To: <1607846585-2381-1-git-send-email-oulijun@huawei.com>

From: "Min Hu (Connor)" <humin29@huawei.com>

In current version, there exists the way of access
global 'rte_eth_devices' array directly, and this
is not a good way.
Better way is to store the 'eth_dev' in the device
private data in the probe(). Then driver could use
it later.

Fixes: ab2e2e344163 ("net/hns3: get device capability in primary process")
Fixes: c4ae39b2cfc5 ("net/hns3: fix Rx interrupt after reset")
Fixes: 2790c6464725 ("net/hns3: support device reset")
Fixes: c203571b3602 ("net/hns3: register and add log interface")
Fixes: 1265b5372d9d ("net/hns3: add some definitions for data structure and macro")
Fixes: 521ab3e93361 ("net/hns3: add simple Rx path")
Fixes: a3d4f4d291d7 ("net/hns3: support NEON Rx")
Fixes: 952ebacce4f2 ("net/hns3: support SVE Rx")
Cc: stable@dpdk.org

Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
Signed-off-by: Lijun Ou <oulijun@huawei.com>
---
 drivers/net/hns3/hns3_ethdev.c       | 11 +++++------
 drivers/net/hns3/hns3_ethdev.h       |  6 ++++++
 drivers/net/hns3/hns3_ethdev_vf.c    | 13 ++++++-------
 drivers/net/hns3/hns3_rxtx.c         | 13 ++++++-------
 drivers/net/hns3/hns3_rxtx_vec.c     |  4 +++-
 drivers/net/hns3/hns3_rxtx_vec_sve.c |  4 +++-
 6 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index f49b779..1093be1 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -2992,15 +2992,14 @@ hns3_query_dev_specifications(struct hns3_hw *hw)
 static int
 hns3_get_capability(struct hns3_hw *hw)
 {
+	struct rte_eth_dev *eth_dev = HNS3_DEV_HW_TO_ETH_DEV(hw);
 	struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
 	struct rte_pci_device *pci_dev;
 	struct hns3_pf *pf = &hns->pf;
-	struct rte_eth_dev *eth_dev;
 	uint16_t device_id;
 	uint8_t revision;
 	int ret;
 
-	eth_dev = &rte_eth_devices[hw->data->port_id];
 	pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
 	device_id = pci_dev->id.device_id;
 
@@ -4836,7 +4835,7 @@ hns3_map_rx_interrupt(struct rte_eth_dev *dev)
 static int
 hns3_restore_rx_interrupt(struct hns3_hw *hw)
 {
-	struct rte_eth_dev *dev = &rte_eth_devices[hw->data->port_id];
+	struct rte_eth_dev *dev = HNS3_DEV_HW_TO_ETH_DEV(hw);
 	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint16_t q_id;
@@ -5526,7 +5525,7 @@ hns3_stop_service(struct hns3_adapter *hns)
 	struct hns3_hw *hw = &hns->hw;
 	struct rte_eth_dev *eth_dev;
 
-	eth_dev = &rte_eth_devices[hw->data->port_id];
+	eth_dev = hns->eth_dev;
 	if (hw->adapter_state == HNS3_NIC_STARTED)
 		rte_eal_alarm_cancel(hns3_service_handler, eth_dev);
 	hw->mac.link_status = ETH_LINK_DOWN;
@@ -5567,7 +5566,7 @@ hns3_start_service(struct hns3_adapter *hns)
 	if (hw->reset.level == HNS3_IMP_RESET ||
 	    hw->reset.level == HNS3_GLOBAL_RESET)
 		hns3_set_rst_done(hw);
-	eth_dev = &rte_eth_devices[hw->data->port_id];
+	eth_dev = hns->eth_dev;
 	hns3_set_rxtx_function(eth_dev);
 	hns3_mp_req_start_rxtx(eth_dev);
 	if (hw->adapter_state == HNS3_NIC_STARTED) {
@@ -5668,7 +5667,7 @@ hns3_reset_service(void *param)
 	if (rte_atomic16_read(&hns->hw.reset.schedule) == SCHEDULE_DEFERRED) {
 		rte_atomic16_set(&hns->hw.reset.schedule, SCHEDULE_REQUESTED);
 		hns3_err(hw, "Handling interrupts in delayed tasks");
-		hns3_interrupt_handler(&rte_eth_devices[hw->data->port_id]);
+		hns3_interrupt_handler(hns->eth_dev);
 		reset_level = hns3_get_reset_level(hns, &hw->reset.pending);
 		if (reset_level == HNS3_NONE_RESET) {
 			hns3_err(hw, "No reset level is set, try IMP reset");
diff --git a/drivers/net/hns3/hns3_ethdev.h b/drivers/net/hns3/hns3_ethdev.h
index 8d6b8cd..51e450a 100644
--- a/drivers/net/hns3/hns3_ethdev.h
+++ b/drivers/net/hns3/hns3_ethdev.h
@@ -798,6 +798,12 @@ struct hns3_adapter {
 #define HNS3_DEV_HW_TO_ADAPTER(hw) \
 	container_of(hw, struct hns3_adapter, hw)
 
+static inline struct rte_eth_dev *HNS3_DEV_HW_TO_ETH_DEV(struct hns3_hw *hw)
+{
+	struct hns3_adapter *adapter = HNS3_DEV_HW_TO_ADAPTER(hw);
+	return adapter->eth_dev;
+}
+
 #define hns3_set_field(origin, mask, shift, val) \
 	do { \
 		(origin) &= (~(mask)); \
diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c
index 9c382bf..890d33d 100644
--- a/drivers/net/hns3/hns3_ethdev_vf.c
+++ b/drivers/net/hns3/hns3_ethdev_vf.c
@@ -1180,12 +1180,11 @@ hns3vf_query_dev_specifications(struct hns3_hw *hw)
 static int
 hns3vf_get_capability(struct hns3_hw *hw)
 {
+	struct rte_eth_dev *eth_dev = HNS3_DEV_HW_TO_ETH_DEV(hw);
 	struct rte_pci_device *pci_dev;
-	struct rte_eth_dev *eth_dev;
 	uint8_t revision;
 	int ret;
 
-	eth_dev = &rte_eth_devices[hw->data->port_id];
 	pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
 
 	/* Get PCI revision id */
@@ -2152,7 +2151,7 @@ hns3vf_map_rx_interrupt(struct rte_eth_dev *dev)
 static int
 hns3vf_restore_rx_interrupt(struct hns3_hw *hw)
 {
-	struct rte_eth_dev *dev = &rte_eth_devices[hw->data->port_id];
+	struct rte_eth_dev *dev = HNS3_DEV_HW_TO_ETH_DEV(hw);
 	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
 	struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
 	uint16_t q_id;
@@ -2377,7 +2376,7 @@ hns3vf_stop_service(struct hns3_adapter *hns)
 	struct hns3_hw *hw = &hns->hw;
 	struct rte_eth_dev *eth_dev;
 
-	eth_dev = &rte_eth_devices[hw->data->port_id];
+	eth_dev = hns->eth_dev;
 	if (hw->adapter_state == HNS3_NIC_STARTED)
 		rte_eal_alarm_cancel(hns3vf_service_handler, eth_dev);
 	hw->mac.link_status = ETH_LINK_DOWN;
@@ -2415,7 +2414,7 @@ hns3vf_start_service(struct hns3_adapter *hns)
 	struct hns3_hw *hw = &hns->hw;
 	struct rte_eth_dev *eth_dev;
 
-	eth_dev = &rte_eth_devices[hw->data->port_id];
+	eth_dev = hns->eth_dev;
 	hns3_set_rxtx_function(eth_dev);
 	hns3_mp_req_start_rxtx(eth_dev);
 	if (hw->adapter_state == HNS3_NIC_STARTED) {
@@ -2577,7 +2576,7 @@ hns3vf_reset_service(void *param)
 	if (rte_atomic16_read(&hns->hw.reset.schedule) == SCHEDULE_DEFERRED) {
 		rte_atomic16_set(&hns->hw.reset.schedule, SCHEDULE_REQUESTED);
 		hns3_err(hw, "Handling interrupts in delayed tasks");
-		hns3vf_interrupt_handler(&rte_eth_devices[hw->data->port_id]);
+		hns3vf_interrupt_handler(hns->eth_dev);
 		reset_level = hns3vf_get_reset_level(hw, &hw->reset.pending);
 		if (reset_level == HNS3_NONE_RESET) {
 			hns3_err(hw, "No reset level is set, try global reset");
@@ -2608,7 +2607,7 @@ hns3vf_reset_service(void *param)
 static int
 hns3vf_reinit_dev(struct hns3_adapter *hns)
 {
-	struct rte_eth_dev *eth_dev = &rte_eth_devices[hns->hw.data->port_id];
+	struct rte_eth_dev *eth_dev = hns->eth_dev;
 	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
 	struct hns3_hw *hw = &hns->hw;
 	int ret;
diff --git a/drivers/net/hns3/hns3_rxtx.c b/drivers/net/hns3/hns3_rxtx.c
index 88d3bab..b7a28e8 100644
--- a/drivers/net/hns3/hns3_rxtx.c
+++ b/drivers/net/hns3/hns3_rxtx.c
@@ -912,7 +912,7 @@ hns3_queue_intr_enable(struct hns3_hw *hw, uint16_t queue_id, bool en)
 void
 hns3_dev_all_rx_queue_intr_enable(struct hns3_hw *hw, bool en)
 {
-	struct rte_eth_dev *dev = &rte_eth_devices[hw->data->port_id];
+	struct rte_eth_dev *dev = HNS3_DEV_HW_TO_ETH_DEV(hw);
 	uint16_t nb_rx_q = hw->data->nb_rx_queues;
 	int i;
 
@@ -1620,7 +1620,7 @@ static int
 hns3_rxq_conf_runtime_check(struct hns3_hw *hw, uint16_t buf_size,
 				uint16_t nb_desc)
 {
-	struct rte_eth_dev *dev = &rte_eth_devices[hw->data->port_id];
+	struct rte_eth_dev *dev = HNS3_DEV_HW_TO_ETH_DEV(hw);
 	struct rte_eth_rxmode *rxmode = &hw->data->dev_conf.rxmode;
 	eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
 	uint16_t min_vec_bds;
@@ -2078,6 +2078,7 @@ hns3_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 	volatile struct hns3_desc *rxdp;     /* pointer of the current desc */
 	struct hns3_rx_queue *rxq;      /* RX queue */
 	struct hns3_entry *sw_ring;
+	struct rte_eth_dev *dev;
 	struct hns3_entry *rxe;
 	struct hns3_desc rxd;
 	struct rte_mbuf *nmb;           /* pointer of the new mbuf */
@@ -2110,10 +2111,8 @@ hns3_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 
 		nmb = hns3_rx_alloc_buffer(rxq);
 		if (unlikely(nmb == NULL)) {
-			uint16_t port_id;
-
-			port_id = rxq->port_id;
-			rte_eth_devices[port_id].data->rx_mbuf_alloc_failed++;
+			dev = rxq->hns->eth_dev;
+			dev->data->rx_mbuf_alloc_failed++;
 			break;
 		}
 
@@ -2289,7 +2288,7 @@ hns3_recv_scattered_pkts(void *rx_queue,
 
 		nmb = hns3_rx_alloc_buffer(rxq);
 		if (unlikely(nmb == NULL)) {
-			dev = &rte_eth_devices[rxq->port_id];
+			dev = rxq->hns->eth_dev;
 			dev->data->rx_mbuf_alloc_failed++;
 			break;
 		}
diff --git a/drivers/net/hns3/hns3_rxtx_vec.c b/drivers/net/hns3/hns3_rxtx_vec.c
index a26c83d..5d02588 100644
--- a/drivers/net/hns3/hns3_rxtx_vec.c
+++ b/drivers/net/hns3/hns3_rxtx_vec.c
@@ -52,12 +52,14 @@ hns3_rxq_rearm_mbuf(struct hns3_rx_queue *rxq)
 #define REARM_LOOP_STEP_NUM	4
 	struct hns3_entry *rxep = &rxq->sw_ring[rxq->rx_rearm_start];
 	struct hns3_desc *rxdp = rxq->rx_ring + rxq->rx_rearm_start;
+	struct rte_eth_dev *dev;
 	uint64_t dma_addr;
 	int i;
 
 	if (unlikely(rte_mempool_get_bulk(rxq->mb_pool, (void *)rxep,
 					  HNS3_DEFAULT_RXQ_REARM_THRESH) < 0)) {
-		rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed++;
+		dev = rxq->hns->eth_dev;
+		dev->data->rx_mbuf_alloc_failed++;
 		return;
 	}
 
diff --git a/drivers/net/hns3/hns3_rxtx_vec_sve.c b/drivers/net/hns3/hns3_rxtx_vec_sve.c
index 8c2c8f6..603d726 100644
--- a/drivers/net/hns3/hns3_rxtx_vec_sve.c
+++ b/drivers/net/hns3/hns3_rxtx_vec_sve.c
@@ -239,11 +239,13 @@ hns3_rxq_rearm_mbuf_sve(struct hns3_rx_queue *rxq)
 	struct hns3_entry *rxep = &rxq->sw_ring[rxq->rx_rearm_start];
 	struct hns3_desc *rxdp = rxq->rx_ring + rxq->rx_rearm_start;
 	struct hns3_entry *rxep_tmp = rxep;
+	struct rte_eth_dev *dev;
 	int i;
 
 	if (unlikely(rte_mempool_get_bulk(rxq->mb_pool, (void *)rxep,
 					  HNS3_DEFAULT_RXQ_REARM_THRESH) < 0)) {
-		rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed++;
+		dev = rxq->hns->eth_dev;
+		dev->data->rx_mbuf_alloc_failed++;
 		return;
 	}
 
-- 
2.7.4


  parent reply	other threads:[~2020-12-13  8:05 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-13  8:02 [dpdk-dev] [PATCH 0/7] some bugfixes for hns3 Lijun Ou
2020-12-13  8:02 ` [dpdk-dev] [PATCH 1/7] net/hns3: fix incorrect interception with filter director Lijun Ou
2020-12-13  8:03 ` [dpdk-dev] [PATCH 2/7] net/hns3: fix xstats statistics with id Lijun Ou
2020-12-17 15:20   ` Ferruh Yigit
2020-12-18  7:06     ` oulijun
2020-12-18 13:34       ` Ferruh Yigit
2020-12-13  8:03 ` [dpdk-dev] [PATCH 3/7] net/hns3: fix abnormal return value in xstats Lijun Ou
2020-12-13  8:03 ` [dpdk-dev] [PATCH 4/7] net/hns3: fix Rx/Tx abnormal errors stats Lijun Ou
2020-12-13  8:03 ` [dpdk-dev] [PATCH 5/7] net/hns3: fix location of saving ethdev Lijun Ou
2020-12-18 14:11   ` Ferruh Yigit
2020-12-13  8:03 ` Lijun Ou [this message]
2020-12-13  8:03 ` [dpdk-dev] [PATCH 7/7] net/hns3: remove unnecessary memset Lijun Ou
2021-01-06  3:46 ` [dpdk-dev] [PATCH v2 0/6] some bugfixes for hns3 Lijun Ou
2021-01-06  3:46   ` [dpdk-dev] [PATCH v2 1/6] net/hns3: fix incorrect interception with filter director Lijun Ou
2021-01-19 21:27     ` Thomas Monjalon
2021-01-06  3:46   ` [dpdk-dev] [PATCH v2 2/6] net/hns3: fix xstats statistics with id and names Lijun Ou
2021-01-06  3:46   ` [dpdk-dev] [PATCH v2 3/6] net/hns3: fix abnormal return value in xstats Lijun Ou
2021-01-06  3:46   ` [dpdk-dev] [PATCH v2 4/6] net/hns3: fix Rx/Tx abnormal errors stats Lijun Ou
2021-01-06  3:46   ` [dpdk-dev] [PATCH v2 5/6] net/hns3: fix crash with multi-process Lijun Ou
2021-01-06  3:46   ` [dpdk-dev] [PATCH v2 6/6] net/hns3: remove unnecessary memset Lijun Ou
2021-01-14 23:34   ` [dpdk-dev] [PATCH v2 0/6] some bugfixes for hns3 Ferruh Yigit

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=1607846585-2381-7-git-send-email-oulijun@huawei.com \
    --to=oulijun@huawei.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=linuxarm@huawei.com \
    /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

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git