Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2024 ZTE Corporation 3 : : */ 4 : : 5 : : #ifndef ZXDH_QUEUE_H 6 : : #define ZXDH_QUEUE_H 7 : : 8 : : #include <stdint.h> 9 : : 10 : : #include <rte_common.h> 11 : : 12 : : #include "zxdh_ethdev.h" 13 : : #include "zxdh_rxtx.h" 14 : : #include "zxdh_pci.h" 15 : : 16 : : enum { ZXDH_VTNET_RQ = 0, ZXDH_VTNET_TQ = 1 }; 17 : : 18 : : #define ZXDH_VIRTQUEUE_MAX_NAME_SZ 32 19 : : #define ZXDH_RQ_QUEUE_IDX 0 20 : : #define ZXDH_TQ_QUEUE_IDX 1 21 : : #define ZXDH_MAX_TX_INDIRECT 8 22 : : 23 : : /* This marks a buffer as write-only (otherwise read-only). */ 24 : : #define ZXDH_VRING_DESC_F_WRITE 2 25 : : /* This flag means the descriptor was made available by the driver */ 26 : : #define ZXDH_VRING_PACKED_DESC_F_AVAIL (1 << (7)) 27 : : 28 : : #define ZXDH_RING_EVENT_FLAGS_ENABLE 0x0 29 : : #define ZXDH_RING_EVENT_FLAGS_DISABLE 0x1 30 : : #define ZXDH_RING_EVENT_FLAGS_DESC 0x2 31 : : 32 : : #define ZXDH_VQ_RING_DESC_CHAIN_END 32768 33 : : 34 : : /* 35 : : * ring descriptors: 16 bytes. 36 : : * These can chain together via "next". 37 : : */ 38 : : struct __rte_packed_begin zxdh_vring_desc { 39 : : uint64_t addr; /* Address (guest-physical). */ 40 : : uint32_t len; /* Length. */ 41 : : uint16_t flags; /* The flags as indicated above. */ 42 : : uint16_t next; /* We chain unused descriptors via this. */ 43 : : } __rte_packed_end; 44 : : 45 : : struct zxdh_vring_used_elem { 46 : : /* Index of start of used descriptor chain. */ 47 : : uint32_t id; 48 : : /* Total length of the descriptor chain which was written to. */ 49 : : uint32_t len; 50 : : }; 51 : : 52 : : struct __rte_packed_begin zxdh_vring_used { 53 : : uint16_t flags; 54 : : uint16_t idx; 55 : : struct zxdh_vring_used_elem ring[]; 56 : : } __rte_packed_end; 57 : : 58 : : struct __rte_packed_begin zxdh_vring_avail { 59 : : uint16_t flags; 60 : : uint16_t idx; 61 : : uint16_t ring[]; 62 : : } __rte_packed_end; 63 : : 64 : : struct __rte_packed_begin zxdh_vring_packed_desc { 65 : : uint64_t addr; 66 : : uint32_t len; 67 : : uint16_t id; 68 : : uint16_t flags; 69 : : } __rte_packed_end; 70 : : 71 : : struct __rte_packed_begin zxdh_vring_packed_desc_event { 72 : : uint16_t desc_event_off_wrap; 73 : : uint16_t desc_event_flags; 74 : : } __rte_packed_end; 75 : : 76 : : struct __rte_packed_begin zxdh_vring_packed { 77 : : uint32_t num; 78 : : struct zxdh_vring_packed_desc *desc; 79 : : struct zxdh_vring_packed_desc_event *driver; 80 : : struct zxdh_vring_packed_desc_event *device; 81 : : } __rte_packed_end; 82 : : 83 : : struct __rte_packed_begin zxdh_vq_desc_extra { 84 : : void *cookie; 85 : : uint16_t ndescs; 86 : : uint16_t next; 87 : : } __rte_packed_end; 88 : : 89 : : struct __rte_packed_begin zxdh_virtqueue { 90 : : struct zxdh_hw *hw; /* < zxdh_hw structure pointer. */ 91 : : struct __rte_packed_begin { 92 : : /* vring keeping descs and events */ 93 : : struct zxdh_vring_packed ring; 94 : : uint8_t used_wrap_counter; 95 : : uint8_t rsv; 96 : : uint16_t cached_flags; /* < cached flags for descs */ 97 : : uint16_t event_flags_shadow; 98 : : uint16_t rsv1; 99 : : } __rte_packed_end vq_packed; 100 : : uint16_t vq_used_cons_idx; /* < last consumed descriptor */ 101 : : uint16_t vq_nentries; /* < vring desc numbers */ 102 : : uint16_t vq_free_cnt; /* < num of desc available */ 103 : : uint16_t vq_avail_idx; /* < sync until needed */ 104 : : uint16_t vq_free_thresh; /* < free threshold */ 105 : : uint16_t rsv2; 106 : : 107 : : void *vq_ring_virt_mem; /* < linear address of vring */ 108 : : uint32_t vq_ring_size; 109 : : 110 : : union { 111 : : struct zxdh_virtnet_rx rxq; 112 : : struct zxdh_virtnet_tx txq; 113 : : }; 114 : : 115 : : /* 116 : : * physical address of vring, or virtual address 117 : : */ 118 : : rte_iova_t vq_ring_mem; 119 : : 120 : : /* 121 : : * Head of the free chain in the descriptor table. If 122 : : * there are no free descriptors, this will be set to 123 : : * VQ_RING_DESC_CHAIN_END. 124 : : */ 125 : : uint16_t vq_desc_head_idx; 126 : : uint16_t vq_desc_tail_idx; 127 : : uint16_t vq_queue_index; /* < PCI queue index */ 128 : : uint16_t offset; /* < relative offset to obtain addr in mbuf */ 129 : : uint16_t *notify_addr; 130 : : struct rte_mbuf **sw_ring; /* < RX software ring. */ 131 : : struct zxdh_vq_desc_extra vq_descx[]; 132 : : } __rte_packed_end; 133 : : 134 : : struct __rte_packed_begin zxdh_type_hdr { 135 : : uint8_t port; /* bit[0:1] 00-np 01-DRS 10-DTP */ 136 : : uint8_t pd_len; 137 : : uint8_t num_buffers; 138 : : uint8_t reserved; 139 : : } __rte_packed_end; /* 4B */ 140 : : 141 : : struct __rte_packed_begin zxdh_pi_hdr { 142 : : uint8_t pi_len; 143 : : uint8_t pkt_type; 144 : : uint16_t vlan_id; 145 : : uint32_t ipv6_extend; 146 : : uint16_t l3_offset; 147 : : uint16_t l4_offset; 148 : : uint8_t phy_port; 149 : : uint8_t pkt_flag_hi8; 150 : : uint16_t pkt_flag_lw16; 151 : : union { 152 : : struct { 153 : : uint64_t sa_idx; 154 : : uint8_t reserved_8[8]; 155 : : } dl; 156 : : struct { 157 : : uint32_t lro_flag; 158 : : uint32_t lro_mss; 159 : : uint16_t err_code; 160 : : uint16_t pm_id; 161 : : uint16_t pkt_len; 162 : : uint8_t reserved[2]; 163 : : } ul; 164 : : }; 165 : : } __rte_packed_end; /* 32B */ 166 : : 167 : : struct __rte_packed_begin zxdh_pd_hdr_dl { 168 : : uint32_t ol_flag; 169 : : uint8_t tag_idx; 170 : : uint8_t tag_data; 171 : : uint16_t dst_vfid; 172 : : uint32_t svlan_insert; 173 : : uint32_t cvlan_insert; 174 : : } __rte_packed_end; /* 16B */ 175 : : 176 : : struct __rte_packed_begin zxdh_net_hdr_dl { 177 : : struct zxdh_type_hdr type_hdr; /* 4B */ 178 : : struct zxdh_pi_hdr pi_hdr; /* 32B */ 179 : : struct zxdh_pd_hdr_dl pd_hdr; /* 16B */ 180 : : } __rte_packed_end; 181 : : 182 : : struct __rte_packed_begin zxdh_pd_hdr_ul { 183 : : uint32_t pkt_flag; 184 : : uint32_t rss_hash; 185 : : uint32_t fd; 186 : : uint32_t striped_vlan_tci; 187 : : uint8_t tag_idx; 188 : : uint8_t tag_data; 189 : : uint16_t src_vfid; 190 : : uint16_t pkt_type_out; 191 : : uint16_t pkt_type_in; 192 : : } __rte_packed_end; /* 24B */ 193 : : 194 : : struct __rte_packed_begin zxdh_net_hdr_ul { 195 : : struct zxdh_type_hdr type_hdr; /* 4B */ 196 : : struct zxdh_pi_hdr pi_hdr; /* 32B */ 197 : : struct zxdh_pd_hdr_ul pd_hdr; /* 24B */ 198 : : } __rte_packed_end; /* 60B */ 199 : : 200 : : struct zxdh_tx_region { 201 : : struct zxdh_net_hdr_dl tx_hdr; 202 : : union __rte_packed_begin { 203 : : struct zxdh_vring_desc tx_indir[ZXDH_MAX_TX_INDIRECT]; 204 : : struct zxdh_vring_packed_desc tx_packed_indir[ZXDH_MAX_TX_INDIRECT]; 205 : : } __rte_packed_end; 206 : : }; 207 : : 208 : : static inline size_t 209 [ # # ]: 0 : vring_size(struct zxdh_hw *hw, uint32_t num, unsigned long align) 210 : : { 211 : : size_t size; 212 : : 213 [ # # ]: 0 : if (vtpci_packed_queue(hw)) { 214 : 0 : size = num * sizeof(struct zxdh_vring_packed_desc); 215 : 0 : size += sizeof(struct zxdh_vring_packed_desc_event); 216 : 0 : size = RTE_ALIGN_CEIL(size, align); 217 : 0 : size += sizeof(struct zxdh_vring_packed_desc_event); 218 : 0 : return size; 219 : : } 220 : : 221 : 0 : size = num * sizeof(struct zxdh_vring_desc); 222 : 0 : size += sizeof(struct zxdh_vring_avail) + (num * sizeof(uint16_t)); 223 : 0 : size = RTE_ALIGN_CEIL(size, align); 224 : 0 : size += sizeof(struct zxdh_vring_used) + (num * sizeof(struct zxdh_vring_used_elem)); 225 : 0 : return size; 226 : : } 227 : : 228 : : static inline void 229 : : vring_init_packed(struct zxdh_vring_packed *vr, uint8_t *p, 230 : : unsigned long align, uint32_t num) 231 : : { 232 : 0 : vr->num = num; 233 : 0 : vr->desc = (struct zxdh_vring_packed_desc *)p; 234 : 0 : vr->driver = (struct zxdh_vring_packed_desc_event *)(p + 235 : 0 : vr->num * sizeof(struct zxdh_vring_packed_desc)); 236 : 0 : vr->device = (struct zxdh_vring_packed_desc_event *)RTE_ALIGN_CEIL(((uintptr_t)vr->driver + 237 : : sizeof(struct zxdh_vring_packed_desc_event)), align); 238 : 0 : } 239 : : 240 : : static inline void 241 : : vring_desc_init_packed(struct zxdh_virtqueue *vq, int32_t n) 242 : : { 243 : : int32_t i = 0; 244 : : 245 [ # # ]: 0 : for (i = 0; i < n - 1; i++) { 246 : 0 : vq->vq_packed.ring.desc[i].id = i; 247 : 0 : vq->vq_descx[i].next = i + 1; 248 : : } 249 : 0 : vq->vq_packed.ring.desc[i].id = i; 250 : 0 : vq->vq_descx[i].next = ZXDH_VQ_RING_DESC_CHAIN_END; 251 : : } 252 : : 253 : : static inline void 254 : : vring_desc_init_indirect_packed(struct zxdh_vring_packed_desc *dp, int32_t n) 255 : : { 256 : : int32_t i = 0; 257 : : 258 [ # # ]: 0 : for (i = 0; i < n; i++) { 259 : 0 : dp[i].id = (uint16_t)i; 260 : 0 : dp[i].flags = ZXDH_VRING_DESC_F_WRITE; 261 : : } 262 : : } 263 : : 264 : : static inline void 265 : : virtqueue_disable_intr(struct zxdh_virtqueue *vq) 266 : : { 267 [ # # ]: 0 : if (vq->vq_packed.event_flags_shadow != ZXDH_RING_EVENT_FLAGS_DISABLE) { 268 : 0 : vq->vq_packed.event_flags_shadow = ZXDH_RING_EVENT_FLAGS_DISABLE; 269 : 0 : vq->vq_packed.ring.driver->desc_event_flags = vq->vq_packed.event_flags_shadow; 270 : : } 271 : : } 272 : : 273 : : struct rte_mbuf *zxdh_virtqueue_detach_unused(struct zxdh_virtqueue *vq); 274 : : int32_t zxdh_free_queues(struct rte_eth_dev *dev); 275 : : int32_t zxdh_get_queue_type(uint16_t vtpci_queue_idx); 276 : : 277 : : #endif /* ZXDH_QUEUE_H */