From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9C224A04B5; Sun, 13 Dec 2020 09:05:22 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 615BDC872; Sun, 13 Dec 2020 09:03:24 +0100 (CET) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by dpdk.org (Postfix) with ESMTP id 196B8C9C4 for ; Sun, 13 Dec 2020 09:03:22 +0100 (CET) Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Ctxnz2Sl1z15cD3 for ; Sun, 13 Dec 2020 16:02:31 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.498.0; Sun, 13 Dec 2020 16:02:59 +0800 From: Lijun Ou To: CC: , Date: Sun, 13 Dec 2020 16:03:04 +0800 Message-ID: <1607846585-2381-7-git-send-email-oulijun@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1607846585-2381-1-git-send-email-oulijun@huawei.com> References: <1607846585-2381-1-git-send-email-oulijun@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH 6/7] net/hns3: fix directly access with rte device 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" From: "Min Hu (Connor)" 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) Signed-off-by: Lijun Ou --- 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