Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2019-2020 Intel Corporation 3 : : */ 4 : : 5 : : #ifndef _IGC_ETHDEV_H_ 6 : : #define _IGC_ETHDEV_H_ 7 : : 8 : : #include <rte_ethdev.h> 9 : : #include <rte_flow.h> 10 : : #include <rte_time.h> 11 : : 12 : : #include "base/igc_osdep.h" 13 : : #include "base/igc_hw.h" 14 : : #include "base/igc_i225.h" 15 : : #include "base/igc_api.h" 16 : : 17 : : #ifdef __cplusplus 18 : : extern "C" { 19 : : #endif 20 : : 21 : : #define IGC_RSS_RDT_SIZD 128 22 : : 23 : : /* VLAN filter table size */ 24 : : #define IGC_VFTA_SIZE 128 25 : : 26 : : #define IGC_QUEUE_PAIRS_NUM 4 27 : : 28 : : #define IGC_HKEY_MAX_INDEX 10 29 : : #define IGC_RSS_RDT_SIZD 128 30 : : 31 : : #define IGC_DEFAULT_REG_SIZE 4 32 : : #define IGC_DEFAULT_REG_SIZE_MASK 0xf 33 : : 34 : : #define IGC_RSS_RDT_REG_SIZE IGC_DEFAULT_REG_SIZE 35 : : #define IGC_RSS_RDT_REG_SIZE_MASK IGC_DEFAULT_REG_SIZE_MASK 36 : : #define IGC_HKEY_REG_SIZE IGC_DEFAULT_REG_SIZE 37 : : #define IGC_HKEY_SIZE (IGC_HKEY_REG_SIZE * IGC_HKEY_MAX_INDEX) 38 : : 39 : : /* 40 : : * The overhead from MTU to max frame size. 41 : : * Considering VLAN so tag needs to be counted. 42 : : */ 43 : : #define IGC_ETH_OVERHEAD (RTE_ETHER_HDR_LEN + \ 44 : : RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE * 2) 45 : : 46 : : /* 47 : : * TDBA/RDBA should be aligned on 16 byte boundary. But TDLEN/RDLEN should be 48 : : * multiple of 128 bytes. So we align TDBA/RDBA on 128 byte boundary. 49 : : * This will also optimize cache line size effect. 50 : : * H/W supports up to cache line size 128. 51 : : */ 52 : : #define IGC_ALIGN 128 53 : : 54 : : #define IGC_TX_DESCRIPTOR_MULTIPLE 8 55 : : #define IGC_RX_DESCRIPTOR_MULTIPLE 8 56 : : 57 : : #define IGC_RXD_ALIGN ((uint16_t)(IGC_ALIGN / \ 58 : : sizeof(union igc_adv_rx_desc))) 59 : : #define IGC_TXD_ALIGN ((uint16_t)(IGC_ALIGN / \ 60 : : sizeof(union igc_adv_tx_desc))) 61 : : #define IGC_MIN_TXD IGC_TX_DESCRIPTOR_MULTIPLE 62 : : #define IGC_MAX_TXD ((uint16_t)(0x80000 / sizeof(union igc_adv_tx_desc))) 63 : : #define IGC_MIN_RXD IGC_RX_DESCRIPTOR_MULTIPLE 64 : : #define IGC_MAX_RXD ((uint16_t)(0x80000 / sizeof(union igc_adv_rx_desc))) 65 : : 66 : : #define IGC_TX_MAX_SEG UINT8_MAX 67 : : #define IGC_TX_MAX_MTU_SEG UINT8_MAX 68 : : 69 : : #define IGC_RX_OFFLOAD_ALL ( \ 70 : : RTE_ETH_RX_OFFLOAD_VLAN_STRIP | \ 71 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER | \ 72 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND | \ 73 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM | \ 74 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM | \ 75 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM | \ 76 : : RTE_ETH_RX_OFFLOAD_SCTP_CKSUM | \ 77 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC | \ 78 : : RTE_ETH_RX_OFFLOAD_SCATTER | \ 79 : : RTE_ETH_RX_OFFLOAD_RSS_HASH | \ 80 : : RTE_ETH_RX_OFFLOAD_TIMESTAMP) 81 : : 82 : : #define IGC_TX_OFFLOAD_ALL ( \ 83 : : RTE_ETH_TX_OFFLOAD_VLAN_INSERT | \ 84 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM | \ 85 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM | \ 86 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM | \ 87 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM | \ 88 : : RTE_ETH_TX_OFFLOAD_TCP_TSO | \ 89 : : RTE_ETH_TX_OFFLOAD_UDP_TSO | \ 90 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS | \ 91 : : RTE_ETH_TX_OFFLOAD_SEND_ON_TIMESTAMP) 92 : : 93 : : #define IGC_RSS_OFFLOAD_ALL ( \ 94 : : RTE_ETH_RSS_IPV4 | \ 95 : : RTE_ETH_RSS_NONFRAG_IPV4_TCP | \ 96 : : RTE_ETH_RSS_NONFRAG_IPV4_UDP | \ 97 : : RTE_ETH_RSS_IPV6 | \ 98 : : RTE_ETH_RSS_NONFRAG_IPV6_TCP | \ 99 : : RTE_ETH_RSS_NONFRAG_IPV6_UDP | \ 100 : : RTE_ETH_RSS_IPV6_EX | \ 101 : : RTE_ETH_RSS_IPV6_TCP_EX | \ 102 : : RTE_ETH_RSS_IPV6_UDP_EX) 103 : : 104 : : #define IGC_MAX_ETQF_FILTERS 3 /* etqf(3) is used for 1588 */ 105 : : #define IGC_ETQF_FILTER_1588 3 106 : : #define IGC_ETQF_QUEUE_SHIFT 16 107 : : #define IGC_ETQF_QUEUE_MASK (7u << IGC_ETQF_QUEUE_SHIFT) 108 : : 109 : : #define IGC_MAX_NTUPLE_FILTERS 8 110 : : #define IGC_NTUPLE_MAX_PRI 7 111 : : 112 : : #define IGC_SYN_FILTER_ENABLE 0x01 /* syn filter enable field */ 113 : : #define IGC_SYN_FILTER_QUEUE_SHIFT 1 /* syn filter queue field */ 114 : : #define IGC_SYN_FILTER_QUEUE 0x0000000E /* syn filter queue field */ 115 : : #define IGC_RFCTL_SYNQFP 0x00080000 /* SYNQFP in RFCTL register */ 116 : : 117 : : /* structure for interrupt relative data */ 118 : : struct igc_interrupt { 119 : : uint32_t flags; 120 : : uint32_t mask; 121 : : }; 122 : : 123 : : /* Union of RSS redirect table register */ 124 : : union igc_rss_reta_reg { 125 : : uint32_t dword; 126 : : uint8_t bytes[4]; 127 : : }; 128 : : 129 : : /* Structure to per-queue statics */ 130 : : struct igc_hw_queue_stats { 131 : : u64 pqgprc[IGC_QUEUE_PAIRS_NUM]; 132 : : /* per queue good packets received count */ 133 : : u64 pqgptc[IGC_QUEUE_PAIRS_NUM]; 134 : : /* per queue good packets transmitted count */ 135 : : u64 pqgorc[IGC_QUEUE_PAIRS_NUM]; 136 : : /* per queue good octets received count */ 137 : : u64 pqgotc[IGC_QUEUE_PAIRS_NUM]; 138 : : /* per queue good octets transmitted count */ 139 : : u64 pqmprc[IGC_QUEUE_PAIRS_NUM]; 140 : : /* per queue multicast packets received count */ 141 : : u64 rqdpc[IGC_QUEUE_PAIRS_NUM]; 142 : : /* per receive queue drop packet count */ 143 : : u64 tqdpc[IGC_QUEUE_PAIRS_NUM]; 144 : : /* per transmit queue drop packet count */ 145 : : }; 146 : : 147 : : /* local vfta copy */ 148 : : struct igc_vfta { 149 : : uint32_t vfta[IGC_VFTA_SIZE]; 150 : : }; 151 : : 152 : : /* ethertype filter structure */ 153 : : struct igc_ethertype_filter { 154 : : uint16_t ether_type; 155 : : uint16_t queue; 156 : : }; 157 : : 158 : : /* Structure of ntuple filter info. */ 159 : : struct igc_ntuple_info { 160 : : uint16_t dst_port; 161 : : uint8_t proto; /* l4 protocol. */ 162 : : 163 : : /* 164 : : * the packet matched above 2tuple and contain any set bit will hit 165 : : * this filter. 166 : : */ 167 : : uint8_t tcp_flags; 168 : : 169 : : /* 170 : : * seven levels (001b-111b), 111b is highest, used when more than one 171 : : * filter matches. 172 : : */ 173 : : uint8_t priority; 174 : : uint8_t dst_port_mask:1, /* if mask is 1b, do compare dst port. */ 175 : : proto_mask:1; /* if mask is 1b, do compare protocol. */ 176 : : }; 177 : : 178 : : /* Structure of n-tuple filter */ 179 : : struct igc_ntuple_filter { 180 : : union { 181 : : uint64_t hash_val; 182 : : struct igc_ntuple_info tuple_info; 183 : : }; 184 : : 185 : : uint8_t queue; 186 : : }; 187 : : 188 : : /* Structure of TCP SYN filter */ 189 : : struct igc_syn_filter { 190 : : uint8_t queue; 191 : : 192 : : uint8_t hig_pri:1, /* 1 - higher priority than other filters, */ 193 : : /* 0 - lower priority. */ 194 : : enable:1; /* 1-enable; 0-disable */ 195 : : }; 196 : : 197 : : /* Structure to store RTE flow RSS configure. */ 198 : : struct igc_rss_filter { 199 : : struct rte_flow_action_rss conf; /* RSS parameters. */ 200 : : uint8_t key[IGC_HKEY_MAX_INDEX * sizeof(uint32_t)]; /* Hash key. */ 201 : : uint16_t queue[IGC_RSS_RDT_SIZD];/* Queues indices to use. */ 202 : : uint8_t enable; /* 1-enabled, 0-disabled */ 203 : : }; 204 : : 205 : : /* Feature filter types */ 206 : : enum igc_filter_type { 207 : : IGC_FILTER_TYPE_ETHERTYPE, 208 : : IGC_FILTER_TYPE_NTUPLE, 209 : : IGC_FILTER_TYPE_SYN, 210 : : IGC_FILTER_TYPE_HASH 211 : : }; 212 : : 213 : : /* Structure to store flow */ 214 : : struct rte_flow { 215 : : TAILQ_ENTRY(rte_flow) node; 216 : : enum igc_filter_type filter_type; 217 : : char filter[0]; /* filter data */ 218 : : }; 219 : : 220 : : /* Flow list header */ 221 : : TAILQ_HEAD(igc_flow_list, rte_flow); 222 : : 223 : : /* 224 : : * Structure to store private data for each driver instance (for each port). 225 : : */ 226 : : struct igc_adapter { 227 : : struct igc_hw hw; 228 : : struct igc_hw_stats stats; 229 : : struct igc_hw_queue_stats queue_stats; 230 : : int16_t txq_stats_map[IGC_QUEUE_PAIRS_NUM]; 231 : : int16_t rxq_stats_map[IGC_QUEUE_PAIRS_NUM]; 232 : : 233 : : struct igc_interrupt intr; 234 : : struct igc_vfta shadow_vfta; 235 : : bool stopped; 236 : : 237 : : struct igc_ethertype_filter ethertype_filters[IGC_MAX_ETQF_FILTERS]; 238 : : struct igc_ntuple_filter ntuple_filters[IGC_MAX_NTUPLE_FILTERS]; 239 : : struct igc_syn_filter syn_filter; 240 : : struct igc_rss_filter rss_filter; 241 : : struct igc_flow_list flow_list; 242 : : 243 : : int64_t base_time; 244 : : uint32_t cycle_time; 245 : : }; 246 : : 247 : : #define IGC_DEV_PRIVATE(_dev) ((_dev)->data->dev_private) 248 : : 249 : : #define IGC_DEV_PRIVATE_HW(_dev) \ 250 : : (&((struct igc_adapter *)(_dev)->data->dev_private)->hw) 251 : : 252 : : #define IGC_DEV_PRIVATE_STATS(_dev) \ 253 : : (&((struct igc_adapter *)(_dev)->data->dev_private)->stats) 254 : : 255 : : #define IGC_DEV_PRIVATE_QUEUE_STATS(_dev) \ 256 : : (&((struct igc_adapter *)(_dev)->data->dev_private)->queue_stats) 257 : : 258 : : #define IGC_DEV_PRIVATE_INTR(_dev) \ 259 : : (&((struct igc_adapter *)(_dev)->data->dev_private)->intr) 260 : : 261 : : #define IGC_DEV_PRIVATE_VFTA(_dev) \ 262 : : (&((struct igc_adapter *)(_dev)->data->dev_private)->shadow_vfta) 263 : : 264 : : #define IGC_DEV_PRIVATE_RSS_FILTER(_dev) \ 265 : : (&((struct igc_adapter *)(_dev)->data->dev_private)->rss_filter) 266 : : 267 : : #define IGC_DEV_PRIVATE_FLOW_LIST(_dev) \ 268 : : (&((struct igc_adapter *)(_dev)->data->dev_private)->flow_list) 269 : : 270 : : static inline void 271 : : igc_read_reg_check_set_bits(struct igc_hw *hw, uint32_t reg, uint32_t bits) 272 : : { 273 : 0 : uint32_t reg_val = IGC_READ_REG(hw, reg); 274 : : 275 : 0 : bits |= reg_val; 276 [ # # # # : 0 : if (bits == reg_val) # # # # # # # # ] 277 : : return; /* no need to write back */ 278 : : 279 : 0 : IGC_WRITE_REG(hw, reg, bits); 280 : : } 281 : : 282 : : static inline void 283 : : igc_read_reg_check_clear_bits(struct igc_hw *hw, uint32_t reg, uint32_t bits) 284 : : { 285 : 0 : uint32_t reg_val = IGC_READ_REG(hw, reg); 286 : : 287 : 0 : bits = reg_val & ~bits; 288 [ # # # # : 0 : if (bits == reg_val) # # ] 289 : : return; /* no need to write back */ 290 : : 291 : 0 : IGC_WRITE_REG(hw, reg, bits); 292 : : } 293 : : 294 : : #ifdef __cplusplus 295 : : } 296 : : #endif 297 : : 298 : : #endif /* _IGC_ETHDEV_H_ */