net/hinic: use common bit operations API
authorJoyce Kong <joyce.kong@arm.com>
Mon, 27 Apr 2020 07:58:56 +0000 (15:58 +0800)
committerThomas Monjalon <thomas@monjalon.net>
Tue, 16 Jun 2020 12:34:42 +0000 (14:34 +0200)
Remove its own bit operation APIs and use the common one,
this can reduce the code duplication largely.

Signed-off-by: Joyce Kong <joyce.kong@arm.com>
Reviewed-by: Gavin Hu <gavin.hu@arm.com>
drivers/net/hinic/base/hinic_compat.h
drivers/net/hinic/hinic_pmd_ethdev.c
drivers/net/hinic/hinic_pmd_ethdev.h

index 921b830..2d21b7b 100644 (file)
@@ -10,6 +10,7 @@
 #include <unistd.h>
 #include <pthread.h>
 #include <rte_common.h>
+#include <rte_bitops.h>
 #include <rte_byteorder.h>
 #include <rte_memzone.h>
 #include <rte_memcpy.h>
@@ -116,38 +117,6 @@ extern int hinic_logtype;
 
 #define HINIC_PAGE_SIZE_DPDK   6
 
-static inline int hinic_test_bit(int nr, volatile unsigned long *addr)
-{
-       int res;
-
-       res = ((*addr) & (1UL << nr)) != 0;
-       return res;
-}
-
-static inline void hinic_set_bit(unsigned int nr, volatile unsigned long *addr)
-{
-       __sync_fetch_and_or(addr, (1UL << nr));
-}
-
-static inline void hinic_clear_bit(int nr, volatile unsigned long *addr)
-{
-       __sync_fetch_and_and(addr, ~(1UL << nr));
-}
-
-static inline int hinic_test_and_clear_bit(int nr, volatile unsigned long *addr)
-{
-       unsigned long mask = (1UL << nr);
-
-       return __sync_fetch_and_and(addr, ~mask) & mask;
-}
-
-static inline int hinic_test_and_set_bit(int nr, volatile unsigned long *addr)
-{
-       unsigned long mask = (1UL << nr);
-
-       return __sync_fetch_and_or(addr, mask) & mask;
-}
-
 void *dma_zalloc_coherent(void *dev, size_t size, dma_addr_t *dma_handle,
                          unsigned int socket_id);
 
index 2f0f33a..0c3e1c0 100644 (file)
@@ -271,7 +271,7 @@ static void hinic_dev_interrupt_handler(void *param)
        struct rte_eth_dev *dev = param;
        struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
-       if (!hinic_test_bit(HINIC_DEV_INTR_EN, &nic_dev->dev_status)) {
+       if (!rte_bit_relaxed_get32(HINIC_DEV_INTR_EN, &nic_dev->dev_status)) {
                PMD_DRV_LOG(WARNING, "Device's interrupt is disabled, ignore interrupt event, dev_name: %s, port_id: %d",
                            nic_dev->proc_dev_name, dev->data->port_id);
                return;
@@ -1067,7 +1067,7 @@ static int hinic_dev_start(struct rte_eth_dev *dev)
        if (dev->data->dev_conf.intr_conf.lsc != 0)
                (void)hinic_link_update(dev, 0);
 
-       hinic_set_bit(HINIC_DEV_START, &nic_dev->dev_status);
+       rte_bit_relaxed_set32(HINIC_DEV_START, &nic_dev->dev_status);
 
        return 0;
 
@@ -1192,7 +1192,8 @@ static void hinic_dev_stop(struct rte_eth_dev *dev)
        name = dev->data->name;
        port_id = dev->data->port_id;
 
-       if (!hinic_test_and_clear_bit(HINIC_DEV_START, &nic_dev->dev_status)) {
+       if (!rte_bit_relaxed_test_and_clear32(HINIC_DEV_START,
+                                             &nic_dev->dev_status)) {
                PMD_DRV_LOG(INFO, "Device %s already stopped", name);
                return;
        }
@@ -1237,7 +1238,7 @@ static void hinic_disable_interrupt(struct rte_eth_dev *dev)
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
        int ret, retries = 0;
 
-       hinic_clear_bit(HINIC_DEV_INTR_EN, &nic_dev->dev_status);
+       rte_bit_relaxed_clear32(HINIC_DEV_INTR_EN, &nic_dev->dev_status);
 
        /* disable msix interrupt in hardware */
        hinic_set_msix_state(nic_dev->hwdev, 0, HINIC_MSIX_DISABLE);
@@ -2926,7 +2927,8 @@ static void hinic_dev_close(struct rte_eth_dev *dev)
 {
        struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
-       if (hinic_test_and_set_bit(HINIC_DEV_CLOSE, &nic_dev->dev_status)) {
+       if (rte_bit_relaxed_test_and_set32(HINIC_DEV_CLOSE,
+                                          &nic_dev->dev_status)) {
                PMD_DRV_LOG(WARNING, "Device %s already closed",
                            dev->data->name);
                return;
@@ -3126,7 +3128,7 @@ static int hinic_func_init(struct rte_eth_dev *eth_dev)
                            eth_dev->data->name);
                goto enable_intr_fail;
        }
-       hinic_set_bit(HINIC_DEV_INTR_EN, &nic_dev->dev_status);
+       rte_bit_relaxed_set32(HINIC_DEV_INTR_EN, &nic_dev->dev_status);
 
        /* initialize filter info */
        filter_info = &nic_dev->filter;
@@ -3141,7 +3143,7 @@ static int hinic_func_init(struct rte_eth_dev *eth_dev)
        TAILQ_INIT(&nic_dev->filter_fdir_rule_list);
        TAILQ_INIT(&nic_dev->hinic_flow_list);
 
-       hinic_set_bit(HINIC_DEV_INIT, &nic_dev->dev_status);
+       rte_bit_relaxed_set32(HINIC_DEV_INIT, &nic_dev->dev_status);
        PMD_DRV_LOG(INFO, "Initialize %s in primary successfully",
                    eth_dev->data->name);
 
@@ -3197,7 +3199,7 @@ static int hinic_dev_uninit(struct rte_eth_dev *dev)
        struct hinic_nic_dev *nic_dev;
 
        nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
-       hinic_clear_bit(HINIC_DEV_INIT, &nic_dev->dev_status);
+       rte_bit_relaxed_clear32(HINIC_DEV_INIT, &nic_dev->dev_status);
 
        if (rte_eal_process_type() != RTE_PROC_PRIMARY)
                return 0;
index 64b2c81..77b4b91 100644 (file)
@@ -329,7 +329,7 @@ struct hinic_nic_dev {
        unsigned int flags;
        struct nic_service_cap nic_cap;
        u32 rx_mode_status;     /* promisc or allmulticast */
-       unsigned long dev_status;
+       u32 dev_status;
 
        char proc_dev_name[HINIC_DEV_NAME_LEN];
        /* PF0->COS4, PF1->COS5, PF2->COS6, PF3->COS7,