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;
 	}
 
