LCOV - code coverage report
Current view: top level - drivers/net/zxdh - zxdh_common.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 36 0.0 %
Date: 2025-07-01 21:32:37 Functions: 0 2 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 10 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2024 ZTE Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #ifndef ZXDH_COMMON_H
       6                 :            : #define ZXDH_COMMON_H
       7                 :            : 
       8                 :            : #include <stdint.h>
       9                 :            : #include <rte_ethdev.h>
      10                 :            : 
      11                 :            : #include "zxdh_ethdev.h"
      12                 :            : #include "zxdh_logs.h"
      13                 :            : 
      14                 :            : #define ZXDH_VF_LOCK_REG               0x90
      15                 :            : #define ZXDH_VF_LOCK_ENABLE_MASK       0x1
      16                 :            : #define ZXDH_ACQUIRE_CHANNEL_NUM_MAX   10
      17                 :            : 
      18                 :            : struct zxdh_res_para {
      19                 :            :         uint64_t virt_addr;
      20                 :            :         uint16_t pcie_id;
      21                 :            :         uint16_t src_type; /* refer to BAR_DRIVER_TYPE */
      22                 :            : };
      23                 :            : 
      24                 :            : static inline size_t
      25                 :          0 : zxdh_get_value(uint32_t fld_sz, uint8_t *addr) {
      26                 :            :         size_t result = 0;
      27   [ #  #  #  #  :          0 :         switch (fld_sz) {
                      # ]
      28                 :          0 :         case 1:
      29                 :          0 :                 result = *((uint8_t *)addr);
      30                 :          0 :                 break;
      31                 :          0 :         case 2:
      32                 :          0 :                 result = *((uint16_t *)addr);
      33                 :          0 :                 break;
      34                 :          0 :         case 4:
      35                 :          0 :                 result = *((uint32_t *)addr);
      36                 :          0 :                 break;
      37                 :          0 :         case 8:
      38                 :          0 :                 result = *((uint64_t *)addr);
      39                 :          0 :                 break;
      40                 :          0 :         default:
      41                 :          0 :                 PMD_MSG_LOG(ERR, "unreachable field size %u", fld_sz);
      42                 :          0 :                 break;
      43                 :            :         }
      44                 :          0 :         return result;
      45                 :            : }
      46                 :            : 
      47                 :            : static inline void
      48                 :          0 : zxdh_set_value(uint32_t fld_sz, uint8_t *addr, size_t value) {
      49   [ #  #  #  #  :          0 :         switch (fld_sz) {
                      # ]
      50                 :          0 :         case 1:
      51                 :          0 :                 *(uint8_t *)addr = (uint8_t)value;
      52                 :          0 :                 break;
      53                 :          0 :         case 2:
      54                 :          0 :                 *(uint16_t *)addr = (uint16_t)value;
      55                 :          0 :                 break;
      56                 :          0 :         case 4:
      57                 :          0 :                 *(uint32_t *)addr = (uint32_t)value;
      58                 :          0 :                 break;
      59                 :          0 :         case 8:
      60                 :          0 :                 *(uint64_t *)addr = (uint64_t)value;
      61                 :          0 :                 break;
      62                 :          0 :         default:
      63                 :          0 :                 PMD_MSG_LOG(ERR, "unreachable field size %u", fld_sz);
      64                 :          0 :                 break;
      65                 :            :         }
      66                 :          0 : }
      67                 :            : 
      68                 :            : #define __zxdh_nullp(typ) ((struct zxdh_ifc_##typ##_bits *)0)
      69                 :            : #define __zxdh_bit_sz(typ, fld) sizeof(__zxdh_nullp(typ)->fld)
      70                 :            : #define __zxdh_bit_off(typ, fld) ((unsigned int)(uintptr_t) \
      71                 :            :                                   (&(__zxdh_nullp(typ)->fld)))
      72                 :            : #define __zxdh_dw_bit_off(typ, fld) (32 - __zxdh_bit_sz(typ, fld) - \
      73                 :            :                                     (__zxdh_bit_off(typ, fld) & 0x1f))
      74                 :            : #define __zxdh_dw_off(typ, fld) (__zxdh_bit_off(typ, fld) / 32)
      75                 :            : #define __zxdh_64_off(typ, fld) (__zxdh_bit_off(typ, fld) / 64)
      76                 :            : #define __zxdh_dw_mask(typ, fld) (__zxdh_mask(typ, fld) << \
      77                 :            :                                   __zxdh_dw_bit_off(typ, fld))
      78                 :            : #define __zxdh_mask(typ, fld) ((uint32_t)((1ull << __zxdh_bit_sz(typ, fld)) - 1))
      79                 :            : #define __zxdh_16_off(typ, fld) (__zxdh_bit_off(typ, fld) / 16)
      80                 :            : #define __zxdh_16_bit_off(typ, fld) (16 - __zxdh_bit_sz(typ, fld) - \
      81                 :            :                                     (__zxdh_bit_off(typ, fld) & 0xf))
      82                 :            : #define __zxdh_mask16(typ, fld) ((uint16_t)((1ull << __zxdh_bit_sz(typ, fld)) - 1))
      83                 :            : #define __zxdh_16_mask(typ, fld) (__zxdh_mask16(typ, fld) << \
      84                 :            :                                   __zxdh_16_bit_off(typ, fld))
      85                 :            : #define ZXDH_ST_SZ_BYTES(typ) (sizeof(struct zxdh_ifc_##typ##_bits) / 8)
      86                 :            : #define ZXDH_ST_SZ_DW(typ) (sizeof(struct zxdh_ifc_##typ##_bits) / 32)
      87                 :            : #define ZXDH_BYTE_OFF(typ, fld) (__zxdh_bit_off(typ, fld) / 8)
      88                 :            : #define ZXDH_ADDR_OF(typ, p, fld) ((uint8_t *)(p) + ZXDH_BYTE_OFF(typ, fld))
      89                 :            : 
      90                 :            : #define ZXDH_SET(typ, p, fld, v) do { \
      91                 :            :         RTE_BUILD_BUG_ON(__zxdh_bit_sz(typ, fld) % 8); \
      92                 :            :         uint32_t fld_sz = __zxdh_bit_sz(typ, fld) / 8; \
      93                 :            :         uint8_t *addr = ZXDH_ADDR_OF(typ, p, fld); \
      94                 :            :         zxdh_set_value(fld_sz, addr, v); \
      95                 :            : } while (0)
      96                 :            : 
      97                 :            : #define ZXDH_GET(typ, p, fld) ({ \
      98                 :            :         RTE_BUILD_BUG_ON(__zxdh_bit_sz(typ, fld) % 8); \
      99                 :            :         uint32_t fld_sz = __zxdh_bit_sz(typ, fld) / 8; \
     100                 :            :         uint8_t *addr = ZXDH_ADDR_OF(typ, p, fld); \
     101                 :            :         zxdh_get_value(fld_sz, addr); \
     102                 :            : })
     103                 :            : 
     104                 :            : #define ZXDH_SET_ARRAY(typ, p, fld, index, value, type) \
     105                 :            :         do { \
     106                 :            :                 type *addr = (type *)((uint8_t *)ZXDH_ADDR_OF(typ, p, fld) + \
     107                 :            :                 (index) * sizeof(type)); \
     108                 :            :                 *addr = (type)(value); \
     109                 :            :         } while (0)
     110                 :            : 
     111                 :            : #define ZXDH_GET_ARRAY(typ, p, fld, index, type) \
     112                 :            :         ({ \
     113                 :            :                 type *addr = (type *)((uint8_t *)ZXDH_ADDR_OF(typ, p, fld) + \
     114                 :            :                 (index) * sizeof(type)); \
     115                 :            :                 *addr; \
     116                 :            :         })
     117                 :            : 
     118                 :            : int32_t zxdh_phyport_get(struct rte_eth_dev *dev, uint8_t *phyport);
     119                 :            : int32_t zxdh_panelid_get(struct rte_eth_dev *dev, uint8_t *pannelid);
     120                 :            : int32_t zxdh_hashidx_get(struct rte_eth_dev *dev, uint8_t *hash_idx);
     121                 :            : uint32_t zxdh_read_bar_reg(struct rte_eth_dev *dev, uint32_t bar, uint32_t reg);
     122                 :            : void zxdh_write_bar_reg(struct rte_eth_dev *dev, uint32_t bar, uint32_t reg, uint32_t val);
     123                 :            : void zxdh_release_lock(struct zxdh_hw *hw);
     124                 :            : int32_t zxdh_timedlock(struct zxdh_hw *hw, uint32_t us);
     125                 :            : uint32_t zxdh_read_comm_reg(uint64_t pci_comm_cfg_baseaddr, uint32_t reg);
     126                 :            : void zxdh_write_comm_reg(uint64_t pci_comm_cfg_baseaddr, uint32_t reg, uint32_t val);
     127                 :            : int32_t zxdh_datach_set(struct rte_eth_dev *dev);
     128                 :            : 
     129                 :            : bool zxdh_rx_offload_enabled(struct zxdh_hw *hw);
     130                 :            : bool zxdh_tx_offload_enabled(struct zxdh_hw *hw);
     131                 :            : 
     132                 :            : #endif /* ZXDH_COMMON_H */

Generated by: LCOV version 1.14