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