LCOV - code coverage report
Current view: top level - drivers/net/hinic3/base - hinic3_compat.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 13 0.0 %
Date: 2025-11-01 17:50:34 Functions: 0 0 -
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 36 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2025 Huawei Technologies Co., Ltd
       3                 :            :  */
       4                 :            : 
       5                 :            : #ifndef _HINIC3_COMPAT_H_
       6                 :            : #define _HINIC3_COMPAT_H_
       7                 :            : 
       8                 :            : #include <rte_ethdev.h>
       9                 :            : #include <rte_io.h>
      10                 :            : #include <rte_log.h>
      11                 :            : 
      12                 :            : #define upper_32_bits(n) ((uint32_t)((n) >> 32))
      13                 :            : #define lower_32_bits(n) ((uint32_t)(n))
      14                 :            : 
      15                 :            : #define HINIC3_MEM_ALLOC_ALIGN_MIN 1
      16                 :            : 
      17                 :            : extern int hinic3_logtype;
      18                 :            : #define RTE_LOGTYPE_HINIC3_DRIVER hinic3_logtype
      19                 :            : 
      20                 :            : #define PMD_DRV_LOG(level, ...) \
      21                 :            :         RTE_LOG_LINE_PREFIX(level, HINIC3_DRIVER, "%s(): ", __func__, __VA_ARGS__)
      22                 :            : 
      23                 :            : #ifdef HW_CONVERT_ENDIAN
      24                 :            : /* If csrs to enable endianness converting are configured, hw will do the
      25                 :            :  * endianness converting for stateless SQ ci, the fields less than 4B for
      26                 :            :  * doorbell, the fields less than 4B in the CQE data.
      27                 :            :  */
      28                 :            : #define hinic3_hw_be32(val)  (val)
      29                 :            : #define hinic3_hw_cpu32(val) (val)
      30                 :            : #define hinic3_hw_cpu16(val) (val)
      31                 :            : #else
      32                 :            : #define hinic3_hw_be32(val)  rte_cpu_to_be_32(val)
      33                 :            : #define hinic3_hw_cpu32(val) rte_be_to_cpu_32(val)
      34                 :            : #define hinic3_hw_cpu16(val) rte_be_to_cpu_16(val)
      35                 :            : #endif
      36                 :            : 
      37                 :            : static inline void
      38                 :            : hinic3_cpu_to_hw(void *data, uint32_t len)
      39                 :            : {
      40                 :            :         uint32_t i, seg = len / sizeof(uint32_t);
      41                 :            :         uint32_t *mem = data;
      42                 :            : 
      43                 :            :         for (i = 0; i < seg; i++) {
      44                 :            :                 *mem = hinic3_hw_be32(*mem);
      45                 :            :                 mem++;
      46                 :            :         }
      47                 :            : }
      48                 :            : 
      49                 :            : static inline int
      50                 :            : hinic3_get_bit(uint32_t nr, volatile RTE_ATOMIC(uint64_t) *addr)
      51                 :            : {
      52   [ #  #  #  #  :          0 :         return rte_atomic_fetch_or_explicit(addr, RTE_BIT64(nr),
             #  #  #  # ]
      53                 :            :                                      rte_memory_order_relaxed);
      54                 :            : }
      55                 :            : 
      56                 :            : static inline void
      57                 :            : hinic3_set_bit(uint32_t nr, volatile RTE_ATOMIC(uint64_t) *addr)
      58                 :            : {
      59                 :          0 :         rte_atomic_fetch_or_explicit(addr, RTE_BIT64(nr),
      60                 :            :                                      rte_memory_order_seq_cst);
      61                 :            : }
      62                 :            : 
      63                 :            : static inline void
      64                 :            : hinic3_clear_bit(uint32_t nr, volatile RTE_ATOMIC(uint64_t) *addr)
      65                 :            : {
      66                 :          0 :         rte_atomic_fetch_and_explicit(addr, ~RTE_BIT64(nr),
      67                 :            :                                       rte_memory_order_seq_cst);
      68                 :            : }
      69                 :            : 
      70                 :            : static inline int
      71                 :            : hinic3_test_and_clear_bit(uint32_t nr, volatile RTE_ATOMIC(uint64_t) *addr)
      72                 :            : {
      73                 :            :         unsigned long mask = RTE_BIT64(nr);
      74                 :            : 
      75                 :          0 :         return rte_atomic_fetch_and_explicit(addr, ~mask,
      76         [ #  # ]:          0 :                                       rte_memory_order_seq_cst) & mask;
      77                 :            : }
      78                 :            : 
      79                 :            : static inline int
      80                 :            : hinic3_test_and_set_bit(uint32_t nr, volatile RTE_ATOMIC(uint64_t) *addr)
      81                 :            : {
      82                 :            :         unsigned long mask = RTE_BIT64(nr);
      83                 :            : 
      84                 :          0 :         return rte_atomic_fetch_or_explicit(addr, mask,
      85         [ #  # ]:          0 :                                       rte_memory_order_seq_cst) & mask;
      86                 :            : }
      87                 :            : 
      88                 :            : #define HINIC3_S_TO_MS_UNIT  1000
      89                 :            : 
      90                 :            : #define cycles                rte_get_timer_cycles()
      91                 :            : #define msecs_to_cycles(ms)  ((ms) * rte_get_timer_hz() / HINIC3_S_TO_MS_UNIT)
      92                 :            : #define time_before(now, end) ((int64_t)((now) - (end)) < 0)
      93                 :            : 
      94                 :            : /**
      95                 :            :  * Convert data to big endian 32 bit format.
      96                 :            :  *
      97                 :            :  * @param data
      98                 :            :  * The data to convert.
      99                 :            :  * @param len
     100                 :            :  * Length of data to convert, must be Multiple of 4B.
     101                 :            :  */
     102                 :            : static inline void
     103                 :            : hinic3_cpu_to_be32(void *data, uint32_t len)
     104                 :            : {
     105                 :            :         uint32_t i, seg = len / sizeof(uint32_t);
     106                 :            :         uint32_t *mem = data;
     107                 :            : 
     108   [ #  #  #  #  :          0 :         for (i = 0; i < seg; i++) {
             #  #  #  # ]
     109   [ #  #  #  #  :          0 :                 *mem = rte_cpu_to_be_32(*mem);
             #  #  #  # ]
     110                 :          0 :                 mem++;
     111                 :            :         }
     112                 :            : }
     113                 :            : 
     114                 :            : /**
     115                 :            :  * Convert data from big endian 32 bit format.
     116                 :            :  *
     117                 :            :  * @param data
     118                 :            :  * The data to convert.
     119                 :            :  * @param len
     120                 :            :  * Length of data to convert, must be Multiple of 4B.
     121                 :            :  */
     122                 :            : static inline void
     123                 :            : hinic3_be32_to_cpu(void *data, uint32_t len)
     124                 :            : {
     125                 :            :         uint32_t i, seg = len / sizeof(uint32_t);
     126                 :            :         uint32_t *mem = data;
     127                 :            : 
     128   [ #  #  #  # ]:          0 :         for (i = 0; i < seg; i++) {
     129   [ #  #  #  # ]:          0 :                 *mem = rte_be_to_cpu_32(*mem);
     130                 :          0 :                 mem++;
     131                 :            :         }
     132                 :            : }
     133                 :            : #endif /* _HINIC3_COMPAT_H_ */

Generated by: LCOV version 1.14