1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2017 Intel Corporation
14 #include <rte_common.h>
16 #include <rte_string_fns.h>
18 #include <rte_bus_pci.h>
19 #include <rte_ether.h>
20 #include <rte_ethdev_driver.h>
21 #include <rte_ethdev_pci.h>
22 #include <rte_memzone.h>
23 #include <rte_malloc.h>
24 #include <rte_memcpy.h>
25 #include <rte_alarm.h>
27 #include <rte_tailq.h>
28 #include <rte_hash_crc.h>
30 #include "i40e_logs.h"
31 #include "base/i40e_prototype.h"
32 #include "base/i40e_adminq_cmd.h"
33 #include "base/i40e_type.h"
34 #include "base/i40e_register.h"
35 #include "base/i40e_dcb.h"
36 #include "i40e_ethdev.h"
37 #include "i40e_rxtx.h"
39 #include "i40e_regs.h"
40 #include "rte_pmd_i40e.h"
42 #define ETH_I40E_FLOATING_VEB_ARG "enable_floating_veb"
43 #define ETH_I40E_FLOATING_VEB_LIST_ARG "floating_veb_list"
44 #define ETH_I40E_SUPPORT_MULTI_DRIVER "support-multi-driver"
45 #define ETH_I40E_QUEUE_NUM_PER_VF_ARG "queue-num-per-vf"
46 #define ETH_I40E_USE_LATEST_VEC "use-latest-supported-vec"
47 #define ETH_I40E_VF_MSG_CFG "vf_msg_cfg"
49 #define I40E_CLEAR_PXE_WAIT_MS 200
51 /* Maximun number of capability elements */
52 #define I40E_MAX_CAP_ELE_NUM 128
54 /* Wait count and interval */
55 #define I40E_CHK_Q_ENA_COUNT 1000
56 #define I40E_CHK_Q_ENA_INTERVAL_US 1000
58 /* Maximun number of VSI */
59 #define I40E_MAX_NUM_VSIS (384UL)
61 #define I40E_PRE_TX_Q_CFG_WAIT_US 10 /* 10 us */
63 /* Flow control default timer */
64 #define I40E_DEFAULT_PAUSE_TIME 0xFFFFU
66 /* Flow control enable fwd bit */
67 #define I40E_PRTMAC_FWD_CTRL 0x00000001
69 /* Receive Packet Buffer size */
70 #define I40E_RXPBSIZE (968 * 1024)
73 #define I40E_KILOSHIFT 10
75 /* Flow control default high water */
76 #define I40E_DEFAULT_HIGH_WATER (0xF2000 >> I40E_KILOSHIFT)
78 /* Flow control default low water */
79 #define I40E_DEFAULT_LOW_WATER (0xF2000 >> I40E_KILOSHIFT)
81 /* Receive Average Packet Size in Byte*/
82 #define I40E_PACKET_AVERAGE_SIZE 128
84 /* Mask of PF interrupt causes */
85 #define I40E_PFINT_ICR0_ENA_MASK ( \
86 I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | \
87 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | \
88 I40E_PFINT_ICR0_ENA_GRST_MASK | \
89 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | \
90 I40E_PFINT_ICR0_ENA_STORM_DETECT_MASK | \
91 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | \
92 I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK | \
93 I40E_PFINT_ICR0_ENA_VFLR_MASK | \
94 I40E_PFINT_ICR0_ENA_ADMINQ_MASK)
96 #define I40E_FLOW_TYPES ( \
97 (1UL << RTE_ETH_FLOW_FRAG_IPV4) | \
98 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_TCP) | \
99 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_UDP) | \
100 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_SCTP) | \
101 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_OTHER) | \
102 (1UL << RTE_ETH_FLOW_FRAG_IPV6) | \
103 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_TCP) | \
104 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_UDP) | \
105 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_SCTP) | \
106 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_OTHER) | \
107 (1UL << RTE_ETH_FLOW_L2_PAYLOAD))
109 /* Additional timesync values. */
110 #define I40E_PTP_40GB_INCVAL 0x0199999999ULL
111 #define I40E_PTP_10GB_INCVAL 0x0333333333ULL
112 #define I40E_PTP_1GB_INCVAL 0x2000000000ULL
113 #define I40E_PRTTSYN_TSYNENA 0x80000000
114 #define I40E_PRTTSYN_TSYNTYPE 0x0e000000
115 #define I40E_CYCLECOUNTER_MASK 0xffffffffffffffffULL
118 * Below are values for writing un-exposed registers suggested
121 /* Destination MAC address */
122 #define I40E_REG_INSET_L2_DMAC 0xE000000000000000ULL
123 /* Source MAC address */
124 #define I40E_REG_INSET_L2_SMAC 0x1C00000000000000ULL
125 /* Outer (S-Tag) VLAN tag in the outer L2 header */
126 #define I40E_REG_INSET_L2_OUTER_VLAN 0x0000000004000000ULL
127 /* Inner (C-Tag) or single VLAN tag in the outer L2 header */
128 #define I40E_REG_INSET_L2_INNER_VLAN 0x0080000000000000ULL
129 /* Single VLAN tag in the inner L2 header */
130 #define I40E_REG_INSET_TUNNEL_VLAN 0x0100000000000000ULL
131 /* Source IPv4 address */
132 #define I40E_REG_INSET_L3_SRC_IP4 0x0001800000000000ULL
133 /* Destination IPv4 address */
134 #define I40E_REG_INSET_L3_DST_IP4 0x0000001800000000ULL
135 /* Source IPv4 address for X722 */
136 #define I40E_X722_REG_INSET_L3_SRC_IP4 0x0006000000000000ULL
137 /* Destination IPv4 address for X722 */
138 #define I40E_X722_REG_INSET_L3_DST_IP4 0x0000060000000000ULL
139 /* IPv4 Protocol for X722 */
140 #define I40E_X722_REG_INSET_L3_IP4_PROTO 0x0010000000000000ULL
141 /* IPv4 Time to Live for X722 */
142 #define I40E_X722_REG_INSET_L3_IP4_TTL 0x0010000000000000ULL
143 /* IPv4 Type of Service (TOS) */
144 #define I40E_REG_INSET_L3_IP4_TOS 0x0040000000000000ULL
146 #define I40E_REG_INSET_L3_IP4_PROTO 0x0004000000000000ULL
147 /* IPv4 Time to Live */
148 #define I40E_REG_INSET_L3_IP4_TTL 0x0004000000000000ULL
149 /* Source IPv6 address */
150 #define I40E_REG_INSET_L3_SRC_IP6 0x0007F80000000000ULL
151 /* Destination IPv6 address */
152 #define I40E_REG_INSET_L3_DST_IP6 0x000007F800000000ULL
153 /* IPv6 Traffic Class (TC) */
154 #define I40E_REG_INSET_L3_IP6_TC 0x0040000000000000ULL
155 /* IPv6 Next Header */
156 #define I40E_REG_INSET_L3_IP6_NEXT_HDR 0x0008000000000000ULL
158 #define I40E_REG_INSET_L3_IP6_HOP_LIMIT 0x0008000000000000ULL
160 #define I40E_REG_INSET_L4_SRC_PORT 0x0000000400000000ULL
161 /* Destination L4 port */
162 #define I40E_REG_INSET_L4_DST_PORT 0x0000000200000000ULL
163 /* SCTP verification tag */
164 #define I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG 0x0000000180000000ULL
165 /* Inner destination MAC address (MAC-in-UDP/MAC-in-GRE)*/
166 #define I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC 0x0000000001C00000ULL
167 /* Source port of tunneling UDP */
168 #define I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT 0x0000000000200000ULL
169 /* Destination port of tunneling UDP */
170 #define I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT 0x0000000000100000ULL
171 /* UDP Tunneling ID, NVGRE/GRE key */
172 #define I40E_REG_INSET_TUNNEL_ID 0x00000000000C0000ULL
173 /* Last ether type */
174 #define I40E_REG_INSET_LAST_ETHER_TYPE 0x0000000000004000ULL
175 /* Tunneling outer destination IPv4 address */
176 #define I40E_REG_INSET_TUNNEL_L3_DST_IP4 0x00000000000000C0ULL
177 /* Tunneling outer destination IPv6 address */
178 #define I40E_REG_INSET_TUNNEL_L3_DST_IP6 0x0000000000003FC0ULL
179 /* 1st word of flex payload */
180 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD1 0x0000000000002000ULL
181 /* 2nd word of flex payload */
182 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD2 0x0000000000001000ULL
183 /* 3rd word of flex payload */
184 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD3 0x0000000000000800ULL
185 /* 4th word of flex payload */
186 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD4 0x0000000000000400ULL
187 /* 5th word of flex payload */
188 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD5 0x0000000000000200ULL
189 /* 6th word of flex payload */
190 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD6 0x0000000000000100ULL
191 /* 7th word of flex payload */
192 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD7 0x0000000000000080ULL
193 /* 8th word of flex payload */
194 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD8 0x0000000000000040ULL
195 /* all 8 words flex payload */
196 #define I40E_REG_INSET_FLEX_PAYLOAD_WORDS 0x0000000000003FC0ULL
197 #define I40E_REG_INSET_MASK_DEFAULT 0x0000000000000000ULL
199 #define I40E_TRANSLATE_INSET 0
200 #define I40E_TRANSLATE_REG 1
202 #define I40E_INSET_IPV4_TOS_MASK 0x0009FF00UL
203 #define I40E_INSET_IPv4_TTL_MASK 0x000D00FFUL
204 #define I40E_INSET_IPV4_PROTO_MASK 0x000DFF00UL
205 #define I40E_INSET_IPV6_TC_MASK 0x0009F00FUL
206 #define I40E_INSET_IPV6_HOP_LIMIT_MASK 0x000CFF00UL
207 #define I40E_INSET_IPV6_NEXT_HDR_MASK 0x000C00FFUL
209 /* PCI offset for querying capability */
210 #define PCI_DEV_CAP_REG 0xA4
211 /* PCI offset for enabling/disabling Extended Tag */
212 #define PCI_DEV_CTRL_REG 0xA8
213 /* Bit mask of Extended Tag capability */
214 #define PCI_DEV_CAP_EXT_TAG_MASK 0x20
215 /* Bit shift of Extended Tag enable/disable */
216 #define PCI_DEV_CTRL_EXT_TAG_SHIFT 8
217 /* Bit mask of Extended Tag enable/disable */
218 #define PCI_DEV_CTRL_EXT_TAG_MASK (1 << PCI_DEV_CTRL_EXT_TAG_SHIFT)
220 static int eth_i40e_dev_init(struct rte_eth_dev *eth_dev, void *init_params);
221 static int eth_i40e_dev_uninit(struct rte_eth_dev *eth_dev);
222 static int i40e_dev_configure(struct rte_eth_dev *dev);
223 static int i40e_dev_start(struct rte_eth_dev *dev);
224 static void i40e_dev_stop(struct rte_eth_dev *dev);
225 static void i40e_dev_close(struct rte_eth_dev *dev);
226 static int i40e_dev_reset(struct rte_eth_dev *dev);
227 static int i40e_dev_promiscuous_enable(struct rte_eth_dev *dev);
228 static int i40e_dev_promiscuous_disable(struct rte_eth_dev *dev);
229 static int i40e_dev_allmulticast_enable(struct rte_eth_dev *dev);
230 static int i40e_dev_allmulticast_disable(struct rte_eth_dev *dev);
231 static int i40e_dev_set_link_up(struct rte_eth_dev *dev);
232 static int i40e_dev_set_link_down(struct rte_eth_dev *dev);
233 static int i40e_dev_stats_get(struct rte_eth_dev *dev,
234 struct rte_eth_stats *stats);
235 static int i40e_dev_xstats_get(struct rte_eth_dev *dev,
236 struct rte_eth_xstat *xstats, unsigned n);
237 static int i40e_dev_xstats_get_names(struct rte_eth_dev *dev,
238 struct rte_eth_xstat_name *xstats_names,
240 static int i40e_dev_stats_reset(struct rte_eth_dev *dev);
241 static int i40e_fw_version_get(struct rte_eth_dev *dev,
242 char *fw_version, size_t fw_size);
243 static int i40e_dev_info_get(struct rte_eth_dev *dev,
244 struct rte_eth_dev_info *dev_info);
245 static int i40e_vlan_filter_set(struct rte_eth_dev *dev,
248 static int i40e_vlan_tpid_set(struct rte_eth_dev *dev,
249 enum rte_vlan_type vlan_type,
251 static int i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask);
252 static void i40e_vlan_strip_queue_set(struct rte_eth_dev *dev,
255 static int i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on);
256 static int i40e_dev_led_on(struct rte_eth_dev *dev);
257 static int i40e_dev_led_off(struct rte_eth_dev *dev);
258 static int i40e_flow_ctrl_get(struct rte_eth_dev *dev,
259 struct rte_eth_fc_conf *fc_conf);
260 static int i40e_flow_ctrl_set(struct rte_eth_dev *dev,
261 struct rte_eth_fc_conf *fc_conf);
262 static int i40e_priority_flow_ctrl_set(struct rte_eth_dev *dev,
263 struct rte_eth_pfc_conf *pfc_conf);
264 static int i40e_macaddr_add(struct rte_eth_dev *dev,
265 struct rte_ether_addr *mac_addr,
268 static void i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index);
269 static int i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
270 struct rte_eth_rss_reta_entry64 *reta_conf,
272 static int i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
273 struct rte_eth_rss_reta_entry64 *reta_conf,
276 static int i40e_get_cap(struct i40e_hw *hw);
277 static int i40e_pf_parameter_init(struct rte_eth_dev *dev);
278 static int i40e_pf_setup(struct i40e_pf *pf);
279 static int i40e_dev_rxtx_init(struct i40e_pf *pf);
280 static int i40e_vmdq_setup(struct rte_eth_dev *dev);
281 static int i40e_dcb_setup(struct rte_eth_dev *dev);
282 static void i40e_stat_update_32(struct i40e_hw *hw, uint32_t reg,
283 bool offset_loaded, uint64_t *offset, uint64_t *stat);
284 static void i40e_stat_update_48(struct i40e_hw *hw,
290 static void i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue);
291 static void i40e_dev_interrupt_handler(void *param);
292 static void i40e_dev_alarm_handler(void *param);
293 static int i40e_res_pool_init(struct i40e_res_pool_info *pool,
294 uint32_t base, uint32_t num);
295 static void i40e_res_pool_destroy(struct i40e_res_pool_info *pool);
296 static int i40e_res_pool_free(struct i40e_res_pool_info *pool,
298 static int i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
300 static int i40e_dev_init_vlan(struct rte_eth_dev *dev);
301 static int i40e_veb_release(struct i40e_veb *veb);
302 static struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf,
303 struct i40e_vsi *vsi);
304 static int i40e_pf_config_mq_rx(struct i40e_pf *pf);
305 static int i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on);
306 static inline int i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
307 struct i40e_macvlan_filter *mv_f,
310 static int i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi);
311 static int i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
312 struct rte_eth_rss_conf *rss_conf);
313 static int i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
314 struct rte_eth_rss_conf *rss_conf);
315 static int i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
316 struct rte_eth_udp_tunnel *udp_tunnel);
317 static int i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
318 struct rte_eth_udp_tunnel *udp_tunnel);
319 static void i40e_filter_input_set_init(struct i40e_pf *pf);
320 static int i40e_ethertype_filter_handle(struct rte_eth_dev *dev,
321 enum rte_filter_op filter_op,
323 static int i40e_dev_filter_ctrl(struct rte_eth_dev *dev,
324 enum rte_filter_type filter_type,
325 enum rte_filter_op filter_op,
327 static int i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
328 struct rte_eth_dcb_info *dcb_info);
329 static int i40e_dev_sync_phy_type(struct i40e_hw *hw);
330 static void i40e_configure_registers(struct i40e_hw *hw);
331 static void i40e_hw_init(struct rte_eth_dev *dev);
332 static int i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi);
333 static enum i40e_status_code i40e_aq_del_mirror_rule(struct i40e_hw *hw,
339 static int i40e_mirror_rule_set(struct rte_eth_dev *dev,
340 struct rte_eth_mirror_conf *mirror_conf,
341 uint8_t sw_id, uint8_t on);
342 static int i40e_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t sw_id);
344 static int i40e_timesync_enable(struct rte_eth_dev *dev);
345 static int i40e_timesync_disable(struct rte_eth_dev *dev);
346 static int i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
347 struct timespec *timestamp,
349 static int i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
350 struct timespec *timestamp);
351 static void i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw);
353 static int i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
355 static int i40e_timesync_read_time(struct rte_eth_dev *dev,
356 struct timespec *timestamp);
357 static int i40e_timesync_write_time(struct rte_eth_dev *dev,
358 const struct timespec *timestamp);
360 static int i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
362 static int i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
365 static int i40e_get_regs(struct rte_eth_dev *dev,
366 struct rte_dev_reg_info *regs);
368 static int i40e_get_eeprom_length(struct rte_eth_dev *dev);
370 static int i40e_get_eeprom(struct rte_eth_dev *dev,
371 struct rte_dev_eeprom_info *eeprom);
373 static int i40e_get_module_info(struct rte_eth_dev *dev,
374 struct rte_eth_dev_module_info *modinfo);
375 static int i40e_get_module_eeprom(struct rte_eth_dev *dev,
376 struct rte_dev_eeprom_info *info);
378 static int i40e_set_default_mac_addr(struct rte_eth_dev *dev,
379 struct rte_ether_addr *mac_addr);
381 static int i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
383 static int i40e_ethertype_filter_convert(
384 const struct rte_eth_ethertype_filter *input,
385 struct i40e_ethertype_filter *filter);
386 static int i40e_sw_ethertype_filter_insert(struct i40e_pf *pf,
387 struct i40e_ethertype_filter *filter);
389 static int i40e_tunnel_filter_convert(
390 struct i40e_aqc_cloud_filters_element_bb *cld_filter,
391 struct i40e_tunnel_filter *tunnel_filter);
392 static int i40e_sw_tunnel_filter_insert(struct i40e_pf *pf,
393 struct i40e_tunnel_filter *tunnel_filter);
394 static int i40e_cloud_filter_qinq_create(struct i40e_pf *pf);
396 static void i40e_ethertype_filter_restore(struct i40e_pf *pf);
397 static void i40e_tunnel_filter_restore(struct i40e_pf *pf);
398 static void i40e_filter_restore(struct i40e_pf *pf);
399 static void i40e_notify_all_vfs_link_status(struct rte_eth_dev *dev);
401 int i40e_logtype_init;
402 int i40e_logtype_driver;
403 #ifdef RTE_LIBRTE_I40E_DEBUG_RX
406 #ifdef RTE_LIBRTE_I40E_DEBUG_TX
409 #ifdef RTE_LIBRTE_I40E_DEBUG_TX_FREE
410 int i40e_logtype_tx_free;
413 static const char *const valid_keys[] = {
414 ETH_I40E_FLOATING_VEB_ARG,
415 ETH_I40E_FLOATING_VEB_LIST_ARG,
416 ETH_I40E_SUPPORT_MULTI_DRIVER,
417 ETH_I40E_QUEUE_NUM_PER_VF_ARG,
418 ETH_I40E_USE_LATEST_VEC,
422 static const struct rte_pci_id pci_id_i40e_map[] = {
423 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_XL710) },
424 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QEMU) },
425 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_B) },
426 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_C) },
427 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_A) },
428 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_B) },
429 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_C) },
430 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T) },
431 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_20G_KR2) },
432 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_20G_KR2_A) },
433 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T4) },
434 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_B) },
435 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_SFP28) },
436 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_X722_A0) },
437 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_X722) },
438 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_X722) },
439 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_X722) },
440 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_1G_BASE_T_X722) },
441 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_X722) },
442 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_I_X722) },
443 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_X710_N3000) },
444 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_XXV710_N3000) },
445 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_BC) },
446 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_5G_BASE_T_BC) },
447 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_B) },
448 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_SFP) },
449 { .vendor_id = 0, /* sentinel */ },
452 static const struct eth_dev_ops i40e_eth_dev_ops = {
453 .dev_configure = i40e_dev_configure,
454 .dev_start = i40e_dev_start,
455 .dev_stop = i40e_dev_stop,
456 .dev_close = i40e_dev_close,
457 .dev_reset = i40e_dev_reset,
458 .promiscuous_enable = i40e_dev_promiscuous_enable,
459 .promiscuous_disable = i40e_dev_promiscuous_disable,
460 .allmulticast_enable = i40e_dev_allmulticast_enable,
461 .allmulticast_disable = i40e_dev_allmulticast_disable,
462 .dev_set_link_up = i40e_dev_set_link_up,
463 .dev_set_link_down = i40e_dev_set_link_down,
464 .link_update = i40e_dev_link_update,
465 .stats_get = i40e_dev_stats_get,
466 .xstats_get = i40e_dev_xstats_get,
467 .xstats_get_names = i40e_dev_xstats_get_names,
468 .stats_reset = i40e_dev_stats_reset,
469 .xstats_reset = i40e_dev_stats_reset,
470 .fw_version_get = i40e_fw_version_get,
471 .dev_infos_get = i40e_dev_info_get,
472 .dev_supported_ptypes_get = i40e_dev_supported_ptypes_get,
473 .vlan_filter_set = i40e_vlan_filter_set,
474 .vlan_tpid_set = i40e_vlan_tpid_set,
475 .vlan_offload_set = i40e_vlan_offload_set,
476 .vlan_strip_queue_set = i40e_vlan_strip_queue_set,
477 .vlan_pvid_set = i40e_vlan_pvid_set,
478 .rx_queue_start = i40e_dev_rx_queue_start,
479 .rx_queue_stop = i40e_dev_rx_queue_stop,
480 .tx_queue_start = i40e_dev_tx_queue_start,
481 .tx_queue_stop = i40e_dev_tx_queue_stop,
482 .rx_queue_setup = i40e_dev_rx_queue_setup,
483 .rx_queue_intr_enable = i40e_dev_rx_queue_intr_enable,
484 .rx_queue_intr_disable = i40e_dev_rx_queue_intr_disable,
485 .rx_queue_release = i40e_dev_rx_queue_release,
486 .rx_queue_count = i40e_dev_rx_queue_count,
487 .rx_descriptor_done = i40e_dev_rx_descriptor_done,
488 .rx_descriptor_status = i40e_dev_rx_descriptor_status,
489 .tx_descriptor_status = i40e_dev_tx_descriptor_status,
490 .tx_queue_setup = i40e_dev_tx_queue_setup,
491 .tx_queue_release = i40e_dev_tx_queue_release,
492 .dev_led_on = i40e_dev_led_on,
493 .dev_led_off = i40e_dev_led_off,
494 .flow_ctrl_get = i40e_flow_ctrl_get,
495 .flow_ctrl_set = i40e_flow_ctrl_set,
496 .priority_flow_ctrl_set = i40e_priority_flow_ctrl_set,
497 .mac_addr_add = i40e_macaddr_add,
498 .mac_addr_remove = i40e_macaddr_remove,
499 .reta_update = i40e_dev_rss_reta_update,
500 .reta_query = i40e_dev_rss_reta_query,
501 .rss_hash_update = i40e_dev_rss_hash_update,
502 .rss_hash_conf_get = i40e_dev_rss_hash_conf_get,
503 .udp_tunnel_port_add = i40e_dev_udp_tunnel_port_add,
504 .udp_tunnel_port_del = i40e_dev_udp_tunnel_port_del,
505 .filter_ctrl = i40e_dev_filter_ctrl,
506 .rxq_info_get = i40e_rxq_info_get,
507 .txq_info_get = i40e_txq_info_get,
508 .rx_burst_mode_get = i40e_rx_burst_mode_get,
509 .tx_burst_mode_get = i40e_tx_burst_mode_get,
510 .mirror_rule_set = i40e_mirror_rule_set,
511 .mirror_rule_reset = i40e_mirror_rule_reset,
512 .timesync_enable = i40e_timesync_enable,
513 .timesync_disable = i40e_timesync_disable,
514 .timesync_read_rx_timestamp = i40e_timesync_read_rx_timestamp,
515 .timesync_read_tx_timestamp = i40e_timesync_read_tx_timestamp,
516 .get_dcb_info = i40e_dev_get_dcb_info,
517 .timesync_adjust_time = i40e_timesync_adjust_time,
518 .timesync_read_time = i40e_timesync_read_time,
519 .timesync_write_time = i40e_timesync_write_time,
520 .get_reg = i40e_get_regs,
521 .get_eeprom_length = i40e_get_eeprom_length,
522 .get_eeprom = i40e_get_eeprom,
523 .get_module_info = i40e_get_module_info,
524 .get_module_eeprom = i40e_get_module_eeprom,
525 .mac_addr_set = i40e_set_default_mac_addr,
526 .mtu_set = i40e_dev_mtu_set,
527 .tm_ops_get = i40e_tm_ops_get,
528 .tx_done_cleanup = i40e_tx_done_cleanup,
531 /* store statistics names and its offset in stats structure */
532 struct rte_i40e_xstats_name_off {
533 char name[RTE_ETH_XSTATS_NAME_SIZE];
537 static const struct rte_i40e_xstats_name_off rte_i40e_stats_strings[] = {
538 {"rx_unicast_packets", offsetof(struct i40e_eth_stats, rx_unicast)},
539 {"rx_multicast_packets", offsetof(struct i40e_eth_stats, rx_multicast)},
540 {"rx_broadcast_packets", offsetof(struct i40e_eth_stats, rx_broadcast)},
541 {"rx_dropped_packets", offsetof(struct i40e_eth_stats, rx_discards)},
542 {"rx_unknown_protocol_packets", offsetof(struct i40e_eth_stats,
543 rx_unknown_protocol)},
544 {"tx_unicast_packets", offsetof(struct i40e_eth_stats, tx_unicast)},
545 {"tx_multicast_packets", offsetof(struct i40e_eth_stats, tx_multicast)},
546 {"tx_broadcast_packets", offsetof(struct i40e_eth_stats, tx_broadcast)},
547 {"tx_dropped_packets", offsetof(struct i40e_eth_stats, tx_discards)},
550 #define I40E_NB_ETH_XSTATS (sizeof(rte_i40e_stats_strings) / \
551 sizeof(rte_i40e_stats_strings[0]))
553 static const struct rte_i40e_xstats_name_off rte_i40e_hw_port_strings[] = {
554 {"tx_link_down_dropped", offsetof(struct i40e_hw_port_stats,
555 tx_dropped_link_down)},
556 {"rx_crc_errors", offsetof(struct i40e_hw_port_stats, crc_errors)},
557 {"rx_illegal_byte_errors", offsetof(struct i40e_hw_port_stats,
559 {"rx_error_bytes", offsetof(struct i40e_hw_port_stats, error_bytes)},
560 {"mac_local_errors", offsetof(struct i40e_hw_port_stats,
562 {"mac_remote_errors", offsetof(struct i40e_hw_port_stats,
564 {"rx_length_errors", offsetof(struct i40e_hw_port_stats,
566 {"tx_xon_packets", offsetof(struct i40e_hw_port_stats, link_xon_tx)},
567 {"rx_xon_packets", offsetof(struct i40e_hw_port_stats, link_xon_rx)},
568 {"tx_xoff_packets", offsetof(struct i40e_hw_port_stats, link_xoff_tx)},
569 {"rx_xoff_packets", offsetof(struct i40e_hw_port_stats, link_xoff_rx)},
570 {"rx_size_64_packets", offsetof(struct i40e_hw_port_stats, rx_size_64)},
571 {"rx_size_65_to_127_packets", offsetof(struct i40e_hw_port_stats,
573 {"rx_size_128_to_255_packets", offsetof(struct i40e_hw_port_stats,
575 {"rx_size_256_to_511_packets", offsetof(struct i40e_hw_port_stats,
577 {"rx_size_512_to_1023_packets", offsetof(struct i40e_hw_port_stats,
579 {"rx_size_1024_to_1522_packets", offsetof(struct i40e_hw_port_stats,
581 {"rx_size_1523_to_max_packets", offsetof(struct i40e_hw_port_stats,
583 {"rx_undersized_errors", offsetof(struct i40e_hw_port_stats,
585 {"rx_oversize_errors", offsetof(struct i40e_hw_port_stats,
587 {"rx_mac_short_dropped", offsetof(struct i40e_hw_port_stats,
588 mac_short_packet_dropped)},
589 {"rx_fragmented_errors", offsetof(struct i40e_hw_port_stats,
591 {"rx_jabber_errors", offsetof(struct i40e_hw_port_stats, rx_jabber)},
592 {"tx_size_64_packets", offsetof(struct i40e_hw_port_stats, tx_size_64)},
593 {"tx_size_65_to_127_packets", offsetof(struct i40e_hw_port_stats,
595 {"tx_size_128_to_255_packets", offsetof(struct i40e_hw_port_stats,
597 {"tx_size_256_to_511_packets", offsetof(struct i40e_hw_port_stats,
599 {"tx_size_512_to_1023_packets", offsetof(struct i40e_hw_port_stats,
601 {"tx_size_1024_to_1522_packets", offsetof(struct i40e_hw_port_stats,
603 {"tx_size_1523_to_max_packets", offsetof(struct i40e_hw_port_stats,
605 {"rx_flow_director_atr_match_packets",
606 offsetof(struct i40e_hw_port_stats, fd_atr_match)},
607 {"rx_flow_director_sb_match_packets",
608 offsetof(struct i40e_hw_port_stats, fd_sb_match)},
609 {"tx_low_power_idle_status", offsetof(struct i40e_hw_port_stats,
611 {"rx_low_power_idle_status", offsetof(struct i40e_hw_port_stats,
613 {"tx_low_power_idle_count", offsetof(struct i40e_hw_port_stats,
615 {"rx_low_power_idle_count", offsetof(struct i40e_hw_port_stats,
619 #define I40E_NB_HW_PORT_XSTATS (sizeof(rte_i40e_hw_port_strings) / \
620 sizeof(rte_i40e_hw_port_strings[0]))
622 static const struct rte_i40e_xstats_name_off rte_i40e_rxq_prio_strings[] = {
623 {"xon_packets", offsetof(struct i40e_hw_port_stats,
625 {"xoff_packets", offsetof(struct i40e_hw_port_stats,
629 #define I40E_NB_RXQ_PRIO_XSTATS (sizeof(rte_i40e_rxq_prio_strings) / \
630 sizeof(rte_i40e_rxq_prio_strings[0]))
632 static const struct rte_i40e_xstats_name_off rte_i40e_txq_prio_strings[] = {
633 {"xon_packets", offsetof(struct i40e_hw_port_stats,
635 {"xoff_packets", offsetof(struct i40e_hw_port_stats,
637 {"xon_to_xoff_packets", offsetof(struct i40e_hw_port_stats,
638 priority_xon_2_xoff)},
641 #define I40E_NB_TXQ_PRIO_XSTATS (sizeof(rte_i40e_txq_prio_strings) / \
642 sizeof(rte_i40e_txq_prio_strings[0]))
645 eth_i40e_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
646 struct rte_pci_device *pci_dev)
648 char name[RTE_ETH_NAME_MAX_LEN];
649 struct rte_eth_devargs eth_da = { .nb_representor_ports = 0 };
652 if (pci_dev->device.devargs) {
653 retval = rte_eth_devargs_parse(pci_dev->device.devargs->args,
659 retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
660 sizeof(struct i40e_adapter),
661 eth_dev_pci_specific_init, pci_dev,
662 eth_i40e_dev_init, NULL);
664 if (retval || eth_da.nb_representor_ports < 1)
667 /* probe VF representor ports */
668 struct rte_eth_dev *pf_ethdev = rte_eth_dev_allocated(
669 pci_dev->device.name);
671 if (pf_ethdev == NULL)
674 for (i = 0; i < eth_da.nb_representor_ports; i++) {
675 struct i40e_vf_representor representor = {
676 .vf_id = eth_da.representor_ports[i],
677 .switch_domain_id = I40E_DEV_PRIVATE_TO_PF(
678 pf_ethdev->data->dev_private)->switch_domain_id,
679 .adapter = I40E_DEV_PRIVATE_TO_ADAPTER(
680 pf_ethdev->data->dev_private)
683 /* representor port net_bdf_port */
684 snprintf(name, sizeof(name), "net_%s_representor_%d",
685 pci_dev->device.name, eth_da.representor_ports[i]);
687 retval = rte_eth_dev_create(&pci_dev->device, name,
688 sizeof(struct i40e_vf_representor), NULL, NULL,
689 i40e_vf_representor_init, &representor);
692 PMD_DRV_LOG(ERR, "failed to create i40e vf "
693 "representor %s.", name);
699 static int eth_i40e_pci_remove(struct rte_pci_device *pci_dev)
701 struct rte_eth_dev *ethdev;
703 ethdev = rte_eth_dev_allocated(pci_dev->device.name);
707 if (ethdev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)
708 return rte_eth_dev_pci_generic_remove(pci_dev,
709 i40e_vf_representor_uninit);
711 return rte_eth_dev_pci_generic_remove(pci_dev,
712 eth_i40e_dev_uninit);
715 static struct rte_pci_driver rte_i40e_pmd = {
716 .id_table = pci_id_i40e_map,
717 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
718 .probe = eth_i40e_pci_probe,
719 .remove = eth_i40e_pci_remove,
723 i40e_write_global_rx_ctl(struct i40e_hw *hw, uint32_t reg_addr,
726 uint32_t ori_reg_val;
727 struct rte_eth_dev *dev;
729 ori_reg_val = i40e_read_rx_ctl(hw, reg_addr);
730 dev = ((struct i40e_adapter *)hw->back)->eth_dev;
731 i40e_write_rx_ctl(hw, reg_addr, reg_val);
732 if (ori_reg_val != reg_val)
734 "i40e device %s changed global register [0x%08x]."
735 " original: 0x%08x, new: 0x%08x",
736 dev->device->name, reg_addr, ori_reg_val, reg_val);
739 RTE_PMD_REGISTER_PCI(net_i40e, rte_i40e_pmd);
740 RTE_PMD_REGISTER_PCI_TABLE(net_i40e, pci_id_i40e_map);
741 RTE_PMD_REGISTER_KMOD_DEP(net_i40e, "* igb_uio | uio_pci_generic | vfio-pci");
743 #ifndef I40E_GLQF_ORT
744 #define I40E_GLQF_ORT(_i) (0x00268900 + ((_i) * 4))
746 #ifndef I40E_GLQF_PIT
747 #define I40E_GLQF_PIT(_i) (0x00268C80 + ((_i) * 4))
749 #ifndef I40E_GLQF_L3_MAP
750 #define I40E_GLQF_L3_MAP(_i) (0x0026C700 + ((_i) * 4))
753 static inline void i40e_GLQF_reg_init(struct i40e_hw *hw)
756 * Initialize registers for parsing packet type of QinQ
757 * This should be removed from code once proper
758 * configuration API is added to avoid configuration conflicts
759 * between ports of the same device.
761 I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(40), 0x00000029);
762 I40E_WRITE_GLB_REG(hw, I40E_GLQF_PIT(9), 0x00009420);
765 static inline void i40e_config_automask(struct i40e_pf *pf)
767 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
770 /* INTENA flag is not auto-cleared for interrupt */
771 val = I40E_READ_REG(hw, I40E_GLINT_CTL);
772 val |= I40E_GLINT_CTL_DIS_AUTOMASK_PF0_MASK |
773 I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK;
775 /* If support multi-driver, PF will use INT0. */
776 if (!pf->support_multi_driver)
777 val |= I40E_GLINT_CTL_DIS_AUTOMASK_N_MASK;
779 I40E_WRITE_REG(hw, I40E_GLINT_CTL, val);
782 #define I40E_FLOW_CONTROL_ETHERTYPE 0x8808
785 * Add a ethertype filter to drop all flow control frames transmitted
789 i40e_add_tx_flow_control_drop_filter(struct i40e_pf *pf)
791 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
792 uint16_t flags = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
793 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
794 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
797 ret = i40e_aq_add_rem_control_packet_filter(hw, NULL,
798 I40E_FLOW_CONTROL_ETHERTYPE, flags,
799 pf->main_vsi_seid, 0,
803 "Failed to add filter to drop flow control frames from VSIs.");
807 floating_veb_list_handler(__rte_unused const char *key,
808 const char *floating_veb_value,
812 unsigned int count = 0;
815 bool *vf_floating_veb = opaque;
817 while (isblank(*floating_veb_value))
818 floating_veb_value++;
820 /* Reset floating VEB configuration for VFs */
821 for (idx = 0; idx < I40E_MAX_VF; idx++)
822 vf_floating_veb[idx] = false;
826 while (isblank(*floating_veb_value))
827 floating_veb_value++;
828 if (*floating_veb_value == '\0')
831 idx = strtoul(floating_veb_value, &end, 10);
832 if (errno || end == NULL)
834 while (isblank(*end))
838 } else if ((*end == ';') || (*end == '\0')) {
840 if (min == I40E_MAX_VF)
842 if (max >= I40E_MAX_VF)
843 max = I40E_MAX_VF - 1;
844 for (idx = min; idx <= max; idx++) {
845 vf_floating_veb[idx] = true;
852 floating_veb_value = end + 1;
853 } while (*end != '\0');
862 config_vf_floating_veb(struct rte_devargs *devargs,
863 uint16_t floating_veb,
864 bool *vf_floating_veb)
866 struct rte_kvargs *kvlist;
868 const char *floating_veb_list = ETH_I40E_FLOATING_VEB_LIST_ARG;
872 /* All the VFs attach to the floating VEB by default
873 * when the floating VEB is enabled.
875 for (i = 0; i < I40E_MAX_VF; i++)
876 vf_floating_veb[i] = true;
881 kvlist = rte_kvargs_parse(devargs->args, valid_keys);
885 if (!rte_kvargs_count(kvlist, floating_veb_list)) {
886 rte_kvargs_free(kvlist);
889 /* When the floating_veb_list parameter exists, all the VFs
890 * will attach to the legacy VEB firstly, then configure VFs
891 * to the floating VEB according to the floating_veb_list.
893 if (rte_kvargs_process(kvlist, floating_veb_list,
894 floating_veb_list_handler,
895 vf_floating_veb) < 0) {
896 rte_kvargs_free(kvlist);
899 rte_kvargs_free(kvlist);
903 i40e_check_floating_handler(__rte_unused const char *key,
905 __rte_unused void *opaque)
907 if (strcmp(value, "1"))
914 is_floating_veb_supported(struct rte_devargs *devargs)
916 struct rte_kvargs *kvlist;
917 const char *floating_veb_key = ETH_I40E_FLOATING_VEB_ARG;
922 kvlist = rte_kvargs_parse(devargs->args, valid_keys);
926 if (!rte_kvargs_count(kvlist, floating_veb_key)) {
927 rte_kvargs_free(kvlist);
930 /* Floating VEB is enabled when there's key-value:
931 * enable_floating_veb=1
933 if (rte_kvargs_process(kvlist, floating_veb_key,
934 i40e_check_floating_handler, NULL) < 0) {
935 rte_kvargs_free(kvlist);
938 rte_kvargs_free(kvlist);
944 config_floating_veb(struct rte_eth_dev *dev)
946 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
947 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
948 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
950 memset(pf->floating_veb_list, 0, sizeof(pf->floating_veb_list));
952 if (hw->aq.fw_maj_ver >= FLOATING_VEB_SUPPORTED_FW_MAJ) {
954 is_floating_veb_supported(pci_dev->device.devargs);
955 config_vf_floating_veb(pci_dev->device.devargs,
957 pf->floating_veb_list);
959 pf->floating_veb = false;
963 #define I40E_L2_TAGS_S_TAG_SHIFT 1
964 #define I40E_L2_TAGS_S_TAG_MASK I40E_MASK(0x1, I40E_L2_TAGS_S_TAG_SHIFT)
967 i40e_init_ethtype_filter_list(struct rte_eth_dev *dev)
969 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
970 struct i40e_ethertype_rule *ethertype_rule = &pf->ethertype;
971 char ethertype_hash_name[RTE_HASH_NAMESIZE];
974 struct rte_hash_parameters ethertype_hash_params = {
975 .name = ethertype_hash_name,
976 .entries = I40E_MAX_ETHERTYPE_FILTER_NUM,
977 .key_len = sizeof(struct i40e_ethertype_filter_input),
978 .hash_func = rte_hash_crc,
979 .hash_func_init_val = 0,
980 .socket_id = rte_socket_id(),
983 /* Initialize ethertype filter rule list and hash */
984 TAILQ_INIT(ðertype_rule->ethertype_list);
985 snprintf(ethertype_hash_name, RTE_HASH_NAMESIZE,
986 "ethertype_%s", dev->device->name);
987 ethertype_rule->hash_table = rte_hash_create(ðertype_hash_params);
988 if (!ethertype_rule->hash_table) {
989 PMD_INIT_LOG(ERR, "Failed to create ethertype hash table!");
992 ethertype_rule->hash_map = rte_zmalloc("i40e_ethertype_hash_map",
993 sizeof(struct i40e_ethertype_filter *) *
994 I40E_MAX_ETHERTYPE_FILTER_NUM,
996 if (!ethertype_rule->hash_map) {
998 "Failed to allocate memory for ethertype hash map!");
1000 goto err_ethertype_hash_map_alloc;
1005 err_ethertype_hash_map_alloc:
1006 rte_hash_free(ethertype_rule->hash_table);
1012 i40e_init_tunnel_filter_list(struct rte_eth_dev *dev)
1014 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1015 struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
1016 char tunnel_hash_name[RTE_HASH_NAMESIZE];
1019 struct rte_hash_parameters tunnel_hash_params = {
1020 .name = tunnel_hash_name,
1021 .entries = I40E_MAX_TUNNEL_FILTER_NUM,
1022 .key_len = sizeof(struct i40e_tunnel_filter_input),
1023 .hash_func = rte_hash_crc,
1024 .hash_func_init_val = 0,
1025 .socket_id = rte_socket_id(),
1028 /* Initialize tunnel filter rule list and hash */
1029 TAILQ_INIT(&tunnel_rule->tunnel_list);
1030 snprintf(tunnel_hash_name, RTE_HASH_NAMESIZE,
1031 "tunnel_%s", dev->device->name);
1032 tunnel_rule->hash_table = rte_hash_create(&tunnel_hash_params);
1033 if (!tunnel_rule->hash_table) {
1034 PMD_INIT_LOG(ERR, "Failed to create tunnel hash table!");
1037 tunnel_rule->hash_map = rte_zmalloc("i40e_tunnel_hash_map",
1038 sizeof(struct i40e_tunnel_filter *) *
1039 I40E_MAX_TUNNEL_FILTER_NUM,
1041 if (!tunnel_rule->hash_map) {
1043 "Failed to allocate memory for tunnel hash map!");
1045 goto err_tunnel_hash_map_alloc;
1050 err_tunnel_hash_map_alloc:
1051 rte_hash_free(tunnel_rule->hash_table);
1057 i40e_init_fdir_filter_list(struct rte_eth_dev *dev)
1059 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1060 struct i40e_fdir_info *fdir_info = &pf->fdir;
1061 char fdir_hash_name[RTE_HASH_NAMESIZE];
1064 struct rte_hash_parameters fdir_hash_params = {
1065 .name = fdir_hash_name,
1066 .entries = I40E_MAX_FDIR_FILTER_NUM,
1067 .key_len = sizeof(struct i40e_fdir_input),
1068 .hash_func = rte_hash_crc,
1069 .hash_func_init_val = 0,
1070 .socket_id = rte_socket_id(),
1073 /* Initialize flow director filter rule list and hash */
1074 TAILQ_INIT(&fdir_info->fdir_list);
1075 snprintf(fdir_hash_name, RTE_HASH_NAMESIZE,
1076 "fdir_%s", dev->device->name);
1077 fdir_info->hash_table = rte_hash_create(&fdir_hash_params);
1078 if (!fdir_info->hash_table) {
1079 PMD_INIT_LOG(ERR, "Failed to create fdir hash table!");
1082 fdir_info->hash_map = rte_zmalloc("i40e_fdir_hash_map",
1083 sizeof(struct i40e_fdir_filter *) *
1084 I40E_MAX_FDIR_FILTER_NUM,
1086 if (!fdir_info->hash_map) {
1088 "Failed to allocate memory for fdir hash map!");
1090 goto err_fdir_hash_map_alloc;
1094 err_fdir_hash_map_alloc:
1095 rte_hash_free(fdir_info->hash_table);
1101 i40e_init_customized_info(struct i40e_pf *pf)
1105 /* Initialize customized pctype */
1106 for (i = I40E_CUSTOMIZED_GTPC; i < I40E_CUSTOMIZED_MAX; i++) {
1107 pf->customized_pctype[i].index = i;
1108 pf->customized_pctype[i].pctype = I40E_FILTER_PCTYPE_INVALID;
1109 pf->customized_pctype[i].valid = false;
1112 pf->gtp_support = false;
1113 pf->esp_support = false;
1117 i40e_init_queue_region_conf(struct rte_eth_dev *dev)
1119 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1120 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1121 struct i40e_queue_regions *info = &pf->queue_region;
1124 for (i = 0; i < I40E_PFQF_HREGION_MAX_INDEX; i++)
1125 i40e_write_rx_ctl(hw, I40E_PFQF_HREGION(i), 0);
1127 memset(info, 0, sizeof(struct i40e_queue_regions));
1131 i40e_parse_multi_drv_handler(__rte_unused const char *key,
1136 unsigned long support_multi_driver;
1139 pf = (struct i40e_pf *)opaque;
1142 support_multi_driver = strtoul(value, &end, 10);
1143 if (errno != 0 || end == value || *end != 0) {
1144 PMD_DRV_LOG(WARNING, "Wrong global configuration");
1148 if (support_multi_driver == 1 || support_multi_driver == 0)
1149 pf->support_multi_driver = (bool)support_multi_driver;
1151 PMD_DRV_LOG(WARNING, "%s must be 1 or 0,",
1152 "enable global configuration by default."
1153 ETH_I40E_SUPPORT_MULTI_DRIVER);
1158 i40e_support_multi_driver(struct rte_eth_dev *dev)
1160 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1161 struct rte_kvargs *kvlist;
1164 /* Enable global configuration by default */
1165 pf->support_multi_driver = false;
1167 if (!dev->device->devargs)
1170 kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
1174 kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_SUPPORT_MULTI_DRIVER);
1175 if (!kvargs_count) {
1176 rte_kvargs_free(kvlist);
1180 if (kvargs_count > 1)
1181 PMD_DRV_LOG(WARNING, "More than one argument \"%s\" and only "
1182 "the first invalid or last valid one is used !",
1183 ETH_I40E_SUPPORT_MULTI_DRIVER);
1185 if (rte_kvargs_process(kvlist, ETH_I40E_SUPPORT_MULTI_DRIVER,
1186 i40e_parse_multi_drv_handler, pf) < 0) {
1187 rte_kvargs_free(kvlist);
1191 rte_kvargs_free(kvlist);
1196 i40e_aq_debug_write_global_register(struct i40e_hw *hw,
1197 uint32_t reg_addr, uint64_t reg_val,
1198 struct i40e_asq_cmd_details *cmd_details)
1200 uint64_t ori_reg_val;
1201 struct rte_eth_dev *dev;
1204 ret = i40e_aq_debug_read_register(hw, reg_addr, &ori_reg_val, NULL);
1205 if (ret != I40E_SUCCESS) {
1207 "Fail to debug read from 0x%08x",
1211 dev = ((struct i40e_adapter *)hw->back)->eth_dev;
1213 if (ori_reg_val != reg_val)
1214 PMD_DRV_LOG(WARNING,
1215 "i40e device %s changed global register [0x%08x]."
1216 " original: 0x%"PRIx64", after: 0x%"PRIx64,
1217 dev->device->name, reg_addr, ori_reg_val, reg_val);
1219 return i40e_aq_debug_write_register(hw, reg_addr, reg_val, cmd_details);
1223 i40e_parse_latest_vec_handler(__rte_unused const char *key,
1227 struct i40e_adapter *ad = opaque;
1230 use_latest_vec = atoi(value);
1232 if (use_latest_vec != 0 && use_latest_vec != 1)
1233 PMD_DRV_LOG(WARNING, "Value should be 0 or 1, set it as 1!");
1235 ad->use_latest_vec = (uint8_t)use_latest_vec;
1241 i40e_use_latest_vec(struct rte_eth_dev *dev)
1243 struct i40e_adapter *ad =
1244 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1245 struct rte_kvargs *kvlist;
1248 ad->use_latest_vec = false;
1250 if (!dev->device->devargs)
1253 kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
1257 kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_USE_LATEST_VEC);
1258 if (!kvargs_count) {
1259 rte_kvargs_free(kvlist);
1263 if (kvargs_count > 1)
1264 PMD_DRV_LOG(WARNING, "More than one argument \"%s\" and only "
1265 "the first invalid or last valid one is used !",
1266 ETH_I40E_USE_LATEST_VEC);
1268 if (rte_kvargs_process(kvlist, ETH_I40E_USE_LATEST_VEC,
1269 i40e_parse_latest_vec_handler, ad) < 0) {
1270 rte_kvargs_free(kvlist);
1274 rte_kvargs_free(kvlist);
1279 read_vf_msg_config(__rte_unused const char *key,
1283 struct i40e_vf_msg_cfg *cfg = opaque;
1285 if (sscanf(value, "%u@%u:%u", &cfg->max_msg, &cfg->period,
1286 &cfg->ignore_second) != 3) {
1287 memset(cfg, 0, sizeof(*cfg));
1288 PMD_DRV_LOG(ERR, "format error! example: "
1289 "%s=60@120:180", ETH_I40E_VF_MSG_CFG);
1294 * If the message validation function been enabled, the 'period'
1295 * and 'ignore_second' must greater than 0.
1297 if (cfg->max_msg && (!cfg->period || !cfg->ignore_second)) {
1298 memset(cfg, 0, sizeof(*cfg));
1299 PMD_DRV_LOG(ERR, "%s error! the second and third"
1300 " number must be greater than 0!",
1301 ETH_I40E_VF_MSG_CFG);
1309 i40e_parse_vf_msg_config(struct rte_eth_dev *dev,
1310 struct i40e_vf_msg_cfg *msg_cfg)
1312 struct rte_kvargs *kvlist;
1316 memset(msg_cfg, 0, sizeof(*msg_cfg));
1318 if (!dev->device->devargs)
1321 kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
1325 kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_VF_MSG_CFG);
1329 if (kvargs_count > 1) {
1330 PMD_DRV_LOG(ERR, "More than one argument \"%s\"!",
1331 ETH_I40E_VF_MSG_CFG);
1336 if (rte_kvargs_process(kvlist, ETH_I40E_VF_MSG_CFG,
1337 read_vf_msg_config, msg_cfg) < 0)
1341 rte_kvargs_free(kvlist);
1345 #define I40E_ALARM_INTERVAL 50000 /* us */
1348 eth_i40e_dev_init(struct rte_eth_dev *dev, void *init_params __rte_unused)
1350 struct rte_pci_device *pci_dev;
1351 struct rte_intr_handle *intr_handle;
1352 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1353 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1354 struct i40e_vsi *vsi;
1357 uint8_t aq_fail = 0;
1359 PMD_INIT_FUNC_TRACE();
1361 dev->dev_ops = &i40e_eth_dev_ops;
1362 dev->rx_pkt_burst = i40e_recv_pkts;
1363 dev->tx_pkt_burst = i40e_xmit_pkts;
1364 dev->tx_pkt_prepare = i40e_prep_pkts;
1366 /* for secondary processes, we don't initialise any further as primary
1367 * has already done this work. Only check we don't need a different
1369 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
1370 i40e_set_rx_function(dev);
1371 i40e_set_tx_function(dev);
1374 i40e_set_default_ptype_table(dev);
1375 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1376 intr_handle = &pci_dev->intr_handle;
1378 rte_eth_copy_pci_info(dev, pci_dev);
1380 pf->adapter = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1381 pf->adapter->eth_dev = dev;
1382 pf->dev_data = dev->data;
1384 hw->back = I40E_PF_TO_ADAPTER(pf);
1385 hw->hw_addr = (uint8_t *)(pci_dev->mem_resource[0].addr);
1388 "Hardware is not available, as address is NULL");
1392 hw->vendor_id = pci_dev->id.vendor_id;
1393 hw->device_id = pci_dev->id.device_id;
1394 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
1395 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
1396 hw->bus.device = pci_dev->addr.devid;
1397 hw->bus.func = pci_dev->addr.function;
1398 hw->adapter_stopped = 0;
1399 hw->adapter_closed = 0;
1401 /* Init switch device pointer */
1402 hw->switch_dev = NULL;
1405 * Switch Tag value should not be identical to either the First Tag
1406 * or Second Tag values. So set something other than common Ethertype
1407 * for internal switching.
1409 hw->switch_tag = 0xffff;
1411 val = I40E_READ_REG(hw, I40E_GL_FWSTS);
1412 if (val & I40E_GL_FWSTS_FWS1B_MASK) {
1413 PMD_INIT_LOG(ERR, "\nERROR: "
1414 "Firmware recovery mode detected. Limiting functionality.\n"
1415 "Refer to the Intel(R) Ethernet Adapters and Devices "
1416 "User Guide for details on firmware recovery mode.");
1420 i40e_parse_vf_msg_config(dev, &pf->vf_msg_cfg);
1421 /* Check if need to support multi-driver */
1422 i40e_support_multi_driver(dev);
1423 /* Check if users want the latest supported vec path */
1424 i40e_use_latest_vec(dev);
1426 /* Make sure all is clean before doing PF reset */
1429 /* Reset here to make sure all is clean for each PF */
1430 ret = i40e_pf_reset(hw);
1432 PMD_INIT_LOG(ERR, "Failed to reset pf: %d", ret);
1436 /* Initialize the shared code (base driver) */
1437 ret = i40e_init_shared_code(hw);
1439 PMD_INIT_LOG(ERR, "Failed to init shared code (base driver): %d", ret);
1443 /* Initialize the parameters for adminq */
1444 i40e_init_adminq_parameter(hw);
1445 ret = i40e_init_adminq(hw);
1446 if (ret != I40E_SUCCESS) {
1447 PMD_INIT_LOG(ERR, "Failed to init adminq: %d", ret);
1450 /* Firmware of SFP x722 does not support adminq option */
1451 if (hw->device_id == I40E_DEV_ID_SFP_X722)
1452 hw->flags &= ~I40E_HW_FLAG_802_1AD_CAPABLE;
1454 PMD_INIT_LOG(INFO, "FW %d.%d API %d.%d NVM %02d.%02d.%02d eetrack %04x",
1455 hw->aq.fw_maj_ver, hw->aq.fw_min_ver,
1456 hw->aq.api_maj_ver, hw->aq.api_min_ver,
1457 ((hw->nvm.version >> 12) & 0xf),
1458 ((hw->nvm.version >> 4) & 0xff),
1459 (hw->nvm.version & 0xf), hw->nvm.eetrack);
1461 /* Initialize the hardware */
1464 i40e_config_automask(pf);
1466 i40e_set_default_pctype_table(dev);
1469 * To work around the NVM issue, initialize registers
1470 * for packet type of QinQ by software.
1471 * It should be removed once issues are fixed in NVM.
1473 if (!pf->support_multi_driver)
1474 i40e_GLQF_reg_init(hw);
1476 /* Initialize the input set for filters (hash and fd) to default value */
1477 i40e_filter_input_set_init(pf);
1479 /* initialise the L3_MAP register */
1480 if (!pf->support_multi_driver) {
1481 ret = i40e_aq_debug_write_global_register(hw,
1482 I40E_GLQF_L3_MAP(40),
1485 PMD_INIT_LOG(ERR, "Failed to write L3 MAP register %d",
1488 "Global register 0x%08x is changed with 0x28",
1489 I40E_GLQF_L3_MAP(40));
1492 /* Need the special FW version to support floating VEB */
1493 config_floating_veb(dev);
1494 /* Clear PXE mode */
1495 i40e_clear_pxe_mode(hw);
1496 i40e_dev_sync_phy_type(hw);
1499 * On X710, performance number is far from the expectation on recent
1500 * firmware versions. The fix for this issue may not be integrated in
1501 * the following firmware version. So the workaround in software driver
1502 * is needed. It needs to modify the initial values of 3 internal only
1503 * registers. Note that the workaround can be removed when it is fixed
1504 * in firmware in the future.
1506 i40e_configure_registers(hw);
1508 /* Get hw capabilities */
1509 ret = i40e_get_cap(hw);
1510 if (ret != I40E_SUCCESS) {
1511 PMD_INIT_LOG(ERR, "Failed to get capabilities: %d", ret);
1512 goto err_get_capabilities;
1515 /* Initialize parameters for PF */
1516 ret = i40e_pf_parameter_init(dev);
1518 PMD_INIT_LOG(ERR, "Failed to do parameter init: %d", ret);
1519 goto err_parameter_init;
1522 /* Initialize the queue management */
1523 ret = i40e_res_pool_init(&pf->qp_pool, 0, hw->func_caps.num_tx_qp);
1525 PMD_INIT_LOG(ERR, "Failed to init queue pool");
1526 goto err_qp_pool_init;
1528 ret = i40e_res_pool_init(&pf->msix_pool, 1,
1529 hw->func_caps.num_msix_vectors - 1);
1531 PMD_INIT_LOG(ERR, "Failed to init MSIX pool");
1532 goto err_msix_pool_init;
1535 /* Initialize lan hmc */
1536 ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
1537 hw->func_caps.num_rx_qp, 0, 0);
1538 if (ret != I40E_SUCCESS) {
1539 PMD_INIT_LOG(ERR, "Failed to init lan hmc: %d", ret);
1540 goto err_init_lan_hmc;
1543 /* Configure lan hmc */
1544 ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
1545 if (ret != I40E_SUCCESS) {
1546 PMD_INIT_LOG(ERR, "Failed to configure lan hmc: %d", ret);
1547 goto err_configure_lan_hmc;
1550 /* Get and check the mac address */
1551 i40e_get_mac_addr(hw, hw->mac.addr);
1552 if (i40e_validate_mac_addr(hw->mac.addr) != I40E_SUCCESS) {
1553 PMD_INIT_LOG(ERR, "mac address is not valid");
1555 goto err_get_mac_addr;
1557 /* Copy the permanent MAC address */
1558 rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
1559 (struct rte_ether_addr *)hw->mac.perm_addr);
1561 /* Disable flow control */
1562 hw->fc.requested_mode = I40E_FC_NONE;
1563 i40e_set_fc(hw, &aq_fail, TRUE);
1565 /* Set the global registers with default ether type value */
1566 if (!pf->support_multi_driver) {
1567 ret = i40e_vlan_tpid_set(dev, ETH_VLAN_TYPE_OUTER,
1568 RTE_ETHER_TYPE_VLAN);
1569 if (ret != I40E_SUCCESS) {
1571 "Failed to set the default outer "
1573 goto err_setup_pf_switch;
1577 /* PF setup, which includes VSI setup */
1578 ret = i40e_pf_setup(pf);
1580 PMD_INIT_LOG(ERR, "Failed to setup pf switch: %d", ret);
1581 goto err_setup_pf_switch;
1586 /* Disable double vlan by default */
1587 i40e_vsi_config_double_vlan(vsi, FALSE);
1589 /* Disable S-TAG identification when floating_veb is disabled */
1590 if (!pf->floating_veb) {
1591 ret = I40E_READ_REG(hw, I40E_PRT_L2TAGSEN);
1592 if (ret & I40E_L2_TAGS_S_TAG_MASK) {
1593 ret &= ~I40E_L2_TAGS_S_TAG_MASK;
1594 I40E_WRITE_REG(hw, I40E_PRT_L2TAGSEN, ret);
1598 if (!vsi->max_macaddrs)
1599 len = RTE_ETHER_ADDR_LEN;
1601 len = RTE_ETHER_ADDR_LEN * vsi->max_macaddrs;
1603 /* Should be after VSI initialized */
1604 dev->data->mac_addrs = rte_zmalloc("i40e", len, 0);
1605 if (!dev->data->mac_addrs) {
1607 "Failed to allocated memory for storing mac address");
1610 rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.perm_addr,
1611 &dev->data->mac_addrs[0]);
1613 /* Pass the information to the rte_eth_dev_close() that it should also
1614 * release the private port resources.
1616 dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
1618 /* Init dcb to sw mode by default */
1619 ret = i40e_dcb_init_configure(dev, TRUE);
1620 if (ret != I40E_SUCCESS) {
1621 PMD_INIT_LOG(INFO, "Failed to init dcb.");
1622 pf->flags &= ~I40E_FLAG_DCB;
1624 /* Update HW struct after DCB configuration */
1627 /* initialize pf host driver to setup SRIOV resource if applicable */
1628 i40e_pf_host_init(dev);
1630 /* register callback func to eal lib */
1631 rte_intr_callback_register(intr_handle,
1632 i40e_dev_interrupt_handler, dev);
1634 /* configure and enable device interrupt */
1635 i40e_pf_config_irq0(hw, TRUE);
1636 i40e_pf_enable_irq0(hw);
1638 /* enable uio intr after callback register */
1639 rte_intr_enable(intr_handle);
1641 /* By default disable flexible payload in global configuration */
1642 if (!pf->support_multi_driver)
1643 i40e_flex_payload_reg_set_default(hw);
1646 * Add an ethertype filter to drop all flow control frames transmitted
1647 * from VSIs. By doing so, we stop VF from sending out PAUSE or PFC
1650 i40e_add_tx_flow_control_drop_filter(pf);
1652 /* Set the max frame size to 0x2600 by default,
1653 * in case other drivers changed the default value.
1655 i40e_aq_set_mac_config(hw, I40E_FRAME_SIZE_MAX, TRUE, false, 0, NULL);
1657 /* initialize mirror rule list */
1658 TAILQ_INIT(&pf->mirror_list);
1660 /* initialize RSS rule list */
1661 TAILQ_INIT(&pf->rss_config_list);
1663 /* initialize Traffic Manager configuration */
1664 i40e_tm_conf_init(dev);
1666 /* Initialize customized information */
1667 i40e_init_customized_info(pf);
1669 ret = i40e_init_ethtype_filter_list(dev);
1671 goto err_init_ethtype_filter_list;
1672 ret = i40e_init_tunnel_filter_list(dev);
1674 goto err_init_tunnel_filter_list;
1675 ret = i40e_init_fdir_filter_list(dev);
1677 goto err_init_fdir_filter_list;
1679 /* initialize queue region configuration */
1680 i40e_init_queue_region_conf(dev);
1682 /* initialize RSS configuration from rte_flow */
1683 memset(&pf->rss_info, 0,
1684 sizeof(struct i40e_rte_flow_rss_conf));
1686 /* reset all stats of the device, including pf and main vsi */
1687 i40e_dev_stats_reset(dev);
1691 err_init_fdir_filter_list:
1692 rte_free(pf->tunnel.hash_table);
1693 rte_free(pf->tunnel.hash_map);
1694 err_init_tunnel_filter_list:
1695 rte_free(pf->ethertype.hash_table);
1696 rte_free(pf->ethertype.hash_map);
1697 err_init_ethtype_filter_list:
1698 rte_free(dev->data->mac_addrs);
1699 dev->data->mac_addrs = NULL;
1701 i40e_vsi_release(pf->main_vsi);
1702 err_setup_pf_switch:
1704 err_configure_lan_hmc:
1705 (void)i40e_shutdown_lan_hmc(hw);
1707 i40e_res_pool_destroy(&pf->msix_pool);
1709 i40e_res_pool_destroy(&pf->qp_pool);
1712 err_get_capabilities:
1713 (void)i40e_shutdown_adminq(hw);
1719 i40e_rm_ethtype_filter_list(struct i40e_pf *pf)
1721 struct i40e_ethertype_filter *p_ethertype;
1722 struct i40e_ethertype_rule *ethertype_rule;
1724 ethertype_rule = &pf->ethertype;
1725 /* Remove all ethertype filter rules and hash */
1726 if (ethertype_rule->hash_map)
1727 rte_free(ethertype_rule->hash_map);
1728 if (ethertype_rule->hash_table)
1729 rte_hash_free(ethertype_rule->hash_table);
1731 while ((p_ethertype = TAILQ_FIRST(ðertype_rule->ethertype_list))) {
1732 TAILQ_REMOVE(ðertype_rule->ethertype_list,
1733 p_ethertype, rules);
1734 rte_free(p_ethertype);
1739 i40e_rm_tunnel_filter_list(struct i40e_pf *pf)
1741 struct i40e_tunnel_filter *p_tunnel;
1742 struct i40e_tunnel_rule *tunnel_rule;
1744 tunnel_rule = &pf->tunnel;
1745 /* Remove all tunnel director rules and hash */
1746 if (tunnel_rule->hash_map)
1747 rte_free(tunnel_rule->hash_map);
1748 if (tunnel_rule->hash_table)
1749 rte_hash_free(tunnel_rule->hash_table);
1751 while ((p_tunnel = TAILQ_FIRST(&tunnel_rule->tunnel_list))) {
1752 TAILQ_REMOVE(&tunnel_rule->tunnel_list, p_tunnel, rules);
1758 i40e_rm_fdir_filter_list(struct i40e_pf *pf)
1760 struct i40e_fdir_filter *p_fdir;
1761 struct i40e_fdir_info *fdir_info;
1763 fdir_info = &pf->fdir;
1764 /* Remove all flow director rules and hash */
1765 if (fdir_info->hash_map)
1766 rte_free(fdir_info->hash_map);
1767 if (fdir_info->hash_table)
1768 rte_hash_free(fdir_info->hash_table);
1770 while ((p_fdir = TAILQ_FIRST(&fdir_info->fdir_list))) {
1771 TAILQ_REMOVE(&fdir_info->fdir_list, p_fdir, rules);
1776 void i40e_flex_payload_reg_set_default(struct i40e_hw *hw)
1779 * Disable by default flexible payload
1780 * for corresponding L2/L3/L4 layers.
1782 I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(33), 0x00000000);
1783 I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(34), 0x00000000);
1784 I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(35), 0x00000000);
1788 eth_i40e_dev_uninit(struct rte_eth_dev *dev)
1792 PMD_INIT_FUNC_TRACE();
1794 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1797 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1799 if (hw->adapter_closed == 0)
1800 i40e_dev_close(dev);
1806 i40e_dev_configure(struct rte_eth_dev *dev)
1808 struct i40e_adapter *ad =
1809 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1810 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1811 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1812 enum rte_eth_rx_mq_mode mq_mode = dev->data->dev_conf.rxmode.mq_mode;
1815 ret = i40e_dev_sync_phy_type(hw);
1819 /* Initialize to TRUE. If any of Rx queues doesn't meet the
1820 * bulk allocation or vector Rx preconditions we will reset it.
1822 ad->rx_bulk_alloc_allowed = true;
1823 ad->rx_vec_allowed = true;
1824 ad->tx_simple_allowed = true;
1825 ad->tx_vec_allowed = true;
1827 if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
1828 dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
1830 /* Only legacy filter API needs the following fdir config. So when the
1831 * legacy filter API is deprecated, the following codes should also be
1834 if (dev->data->dev_conf.fdir_conf.mode == RTE_FDIR_MODE_PERFECT) {
1835 ret = i40e_fdir_setup(pf);
1836 if (ret != I40E_SUCCESS) {
1837 PMD_DRV_LOG(ERR, "Failed to setup flow director.");
1840 ret = i40e_fdir_configure(dev);
1842 PMD_DRV_LOG(ERR, "failed to configure fdir.");
1846 i40e_fdir_teardown(pf);
1848 ret = i40e_dev_init_vlan(dev);
1853 * Needs to move VMDQ setting out of i40e_pf_config_mq_rx() as VMDQ and
1854 * RSS setting have different requirements.
1855 * General PMD driver call sequence are NIC init, configure,
1856 * rx/tx_queue_setup and dev_start. In rx/tx_queue_setup() function, it
1857 * will try to lookup the VSI that specific queue belongs to if VMDQ
1858 * applicable. So, VMDQ setting has to be done before
1859 * rx/tx_queue_setup(). This function is good to place vmdq_setup.
1860 * For RSS setting, it will try to calculate actual configured RX queue
1861 * number, which will be available after rx_queue_setup(). dev_start()
1862 * function is good to place RSS setup.
1864 if (mq_mode & ETH_MQ_RX_VMDQ_FLAG) {
1865 ret = i40e_vmdq_setup(dev);
1870 if (mq_mode & ETH_MQ_RX_DCB_FLAG) {
1871 ret = i40e_dcb_setup(dev);
1873 PMD_DRV_LOG(ERR, "failed to configure DCB.");
1878 TAILQ_INIT(&pf->flow_list);
1883 /* need to release vmdq resource if exists */
1884 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1885 i40e_vsi_release(pf->vmdq[i].vsi);
1886 pf->vmdq[i].vsi = NULL;
1891 /* Need to release fdir resource if exists.
1892 * Only legacy filter API needs the following fdir config. So when the
1893 * legacy filter API is deprecated, the following code should also be
1896 i40e_fdir_teardown(pf);
1901 i40e_vsi_queues_unbind_intr(struct i40e_vsi *vsi)
1903 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1904 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1905 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1906 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1907 uint16_t msix_vect = vsi->msix_intr;
1910 for (i = 0; i < vsi->nb_qps; i++) {
1911 I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
1912 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
1916 if (vsi->type != I40E_VSI_SRIOV) {
1917 if (!rte_intr_allow_others(intr_handle)) {
1918 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
1919 I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
1921 I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
1924 I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
1925 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
1927 I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
1932 reg = (hw->func_caps.num_msix_vectors_vf - 1) *
1933 vsi->user_param + (msix_vect - 1);
1935 I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
1936 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
1938 I40E_WRITE_FLUSH(hw);
1942 __vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t msix_vect,
1943 int base_queue, int nb_queue,
1948 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1949 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
1951 /* Bind all RX queues to allocated MSIX interrupt */
1952 for (i = 0; i < nb_queue; i++) {
1953 val = (msix_vect << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
1954 itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT |
1955 ((base_queue + i + 1) <<
1956 I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
1957 (0 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
1958 I40E_QINT_RQCTL_CAUSE_ENA_MASK;
1960 if (i == nb_queue - 1)
1961 val |= I40E_QINT_RQCTL_NEXTQ_INDX_MASK;
1962 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(base_queue + i), val);
1965 /* Write first RX queue to Link list register as the head element */
1966 if (vsi->type != I40E_VSI_SRIOV) {
1968 i40e_calc_itr_interval(1, pf->support_multi_driver);
1970 if (msix_vect == I40E_MISC_VEC_ID) {
1971 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
1973 I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
1975 I40E_PFINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
1977 I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
1980 I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
1982 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
1984 I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
1986 I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
1993 if (msix_vect == I40E_MISC_VEC_ID) {
1995 I40E_VPINT_LNKLST0(vsi->user_param),
1997 I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
1999 I40E_VPINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
2001 /* num_msix_vectors_vf needs to minus irq0 */
2002 reg = (hw->func_caps.num_msix_vectors_vf - 1) *
2003 vsi->user_param + (msix_vect - 1);
2005 I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
2007 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
2009 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
2013 I40E_WRITE_FLUSH(hw);
2017 i40e_vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t itr_idx)
2019 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
2020 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2021 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2022 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2023 uint16_t msix_vect = vsi->msix_intr;
2024 uint16_t nb_msix = RTE_MIN(vsi->nb_msix, intr_handle->nb_efd);
2025 uint16_t queue_idx = 0;
2029 for (i = 0; i < vsi->nb_qps; i++) {
2030 I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
2031 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
2034 /* VF bind interrupt */
2035 if (vsi->type == I40E_VSI_SRIOV) {
2036 __vsi_queues_bind_intr(vsi, msix_vect,
2037 vsi->base_queue, vsi->nb_qps,
2042 /* PF & VMDq bind interrupt */
2043 if (rte_intr_dp_is_en(intr_handle)) {
2044 if (vsi->type == I40E_VSI_MAIN) {
2047 } else if (vsi->type == I40E_VSI_VMDQ2) {
2048 struct i40e_vsi *main_vsi =
2049 I40E_DEV_PRIVATE_TO_MAIN_VSI(vsi->adapter);
2050 queue_idx = vsi->base_queue - main_vsi->nb_qps;
2055 for (i = 0; i < vsi->nb_used_qps; i++) {
2057 if (!rte_intr_allow_others(intr_handle))
2058 /* allow to share MISC_VEC_ID */
2059 msix_vect = I40E_MISC_VEC_ID;
2061 /* no enough msix_vect, map all to one */
2062 __vsi_queues_bind_intr(vsi, msix_vect,
2063 vsi->base_queue + i,
2064 vsi->nb_used_qps - i,
2066 for (; !!record && i < vsi->nb_used_qps; i++)
2067 intr_handle->intr_vec[queue_idx + i] =
2071 /* 1:1 queue/msix_vect mapping */
2072 __vsi_queues_bind_intr(vsi, msix_vect,
2073 vsi->base_queue + i, 1,
2076 intr_handle->intr_vec[queue_idx + i] = msix_vect;
2084 i40e_vsi_enable_queues_intr(struct i40e_vsi *vsi)
2086 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
2087 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2088 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2089 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2090 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2091 uint16_t msix_intr, i;
2093 if (rte_intr_allow_others(intr_handle) && !pf->support_multi_driver)
2094 for (i = 0; i < vsi->nb_msix; i++) {
2095 msix_intr = vsi->msix_intr + i;
2096 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
2097 I40E_PFINT_DYN_CTLN_INTENA_MASK |
2098 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
2099 I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
2102 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
2103 I40E_PFINT_DYN_CTL0_INTENA_MASK |
2104 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
2105 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
2107 I40E_WRITE_FLUSH(hw);
2111 i40e_vsi_disable_queues_intr(struct i40e_vsi *vsi)
2113 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
2114 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2115 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2116 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2117 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2118 uint16_t msix_intr, i;
2120 if (rte_intr_allow_others(intr_handle) && !pf->support_multi_driver)
2121 for (i = 0; i < vsi->nb_msix; i++) {
2122 msix_intr = vsi->msix_intr + i;
2123 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
2124 I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
2127 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
2128 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
2130 I40E_WRITE_FLUSH(hw);
2133 static inline uint8_t
2134 i40e_parse_link_speeds(uint16_t link_speeds)
2136 uint8_t link_speed = I40E_LINK_SPEED_UNKNOWN;
2138 if (link_speeds & ETH_LINK_SPEED_40G)
2139 link_speed |= I40E_LINK_SPEED_40GB;
2140 if (link_speeds & ETH_LINK_SPEED_25G)
2141 link_speed |= I40E_LINK_SPEED_25GB;
2142 if (link_speeds & ETH_LINK_SPEED_20G)
2143 link_speed |= I40E_LINK_SPEED_20GB;
2144 if (link_speeds & ETH_LINK_SPEED_10G)
2145 link_speed |= I40E_LINK_SPEED_10GB;
2146 if (link_speeds & ETH_LINK_SPEED_1G)
2147 link_speed |= I40E_LINK_SPEED_1GB;
2148 if (link_speeds & ETH_LINK_SPEED_100M)
2149 link_speed |= I40E_LINK_SPEED_100MB;
2155 i40e_phy_conf_link(struct i40e_hw *hw,
2157 uint8_t force_speed,
2160 enum i40e_status_code status;
2161 struct i40e_aq_get_phy_abilities_resp phy_ab;
2162 struct i40e_aq_set_phy_config phy_conf;
2163 enum i40e_aq_phy_type cnt;
2164 uint8_t avail_speed;
2165 uint32_t phy_type_mask = 0;
2167 const uint8_t mask = I40E_AQ_PHY_FLAG_PAUSE_TX |
2168 I40E_AQ_PHY_FLAG_PAUSE_RX |
2169 I40E_AQ_PHY_FLAG_PAUSE_RX |
2170 I40E_AQ_PHY_FLAG_LOW_POWER;
2173 /* To get phy capabilities of available speeds. */
2174 status = i40e_aq_get_phy_capabilities(hw, false, true, &phy_ab,
2177 PMD_DRV_LOG(ERR, "Failed to get PHY capabilities: %d\n",
2181 avail_speed = phy_ab.link_speed;
2183 /* To get the current phy config. */
2184 status = i40e_aq_get_phy_capabilities(hw, false, false, &phy_ab,
2187 PMD_DRV_LOG(ERR, "Failed to get the current PHY config: %d\n",
2192 /* If link needs to go up and it is in autoneg mode the speed is OK,
2193 * no need to set up again.
2195 if (is_up && phy_ab.phy_type != 0 &&
2196 abilities & I40E_AQ_PHY_AN_ENABLED &&
2197 phy_ab.link_speed != 0)
2198 return I40E_SUCCESS;
2200 memset(&phy_conf, 0, sizeof(phy_conf));
2202 /* bits 0-2 use the values from get_phy_abilities_resp */
2204 abilities |= phy_ab.abilities & mask;
2206 phy_conf.abilities = abilities;
2208 /* If link needs to go up, but the force speed is not supported,
2209 * Warn users and config the default available speeds.
2211 if (is_up && !(force_speed & avail_speed)) {
2212 PMD_DRV_LOG(WARNING, "Invalid speed setting, set to default!\n");
2213 phy_conf.link_speed = avail_speed;
2215 phy_conf.link_speed = is_up ? force_speed : avail_speed;
2218 /* PHY type mask needs to include each type except PHY type extension */
2219 for (cnt = I40E_PHY_TYPE_SGMII; cnt < I40E_PHY_TYPE_25GBASE_KR; cnt++)
2220 phy_type_mask |= 1 << cnt;
2222 /* use get_phy_abilities_resp value for the rest */
2223 phy_conf.phy_type = is_up ? cpu_to_le32(phy_type_mask) : 0;
2224 phy_conf.phy_type_ext = is_up ? (I40E_AQ_PHY_TYPE_EXT_25G_KR |
2225 I40E_AQ_PHY_TYPE_EXT_25G_CR | I40E_AQ_PHY_TYPE_EXT_25G_SR |
2226 I40E_AQ_PHY_TYPE_EXT_25G_LR) : 0;
2227 phy_conf.fec_config = phy_ab.fec_cfg_curr_mod_ext_info;
2228 phy_conf.eee_capability = phy_ab.eee_capability;
2229 phy_conf.eeer = phy_ab.eeer_val;
2230 phy_conf.low_power_ctrl = phy_ab.d3_lpan;
2232 PMD_DRV_LOG(DEBUG, "\tCurrent: abilities %x, link_speed %x",
2233 phy_ab.abilities, phy_ab.link_speed);
2234 PMD_DRV_LOG(DEBUG, "\tConfig: abilities %x, link_speed %x",
2235 phy_conf.abilities, phy_conf.link_speed);
2237 status = i40e_aq_set_phy_config(hw, &phy_conf, NULL);
2241 return I40E_SUCCESS;
2245 i40e_apply_link_speed(struct rte_eth_dev *dev)
2248 uint8_t abilities = 0;
2249 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2250 struct rte_eth_conf *conf = &dev->data->dev_conf;
2252 abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK |
2253 I40E_AQ_PHY_LINK_ENABLED;
2255 if (conf->link_speeds == ETH_LINK_SPEED_AUTONEG) {
2256 conf->link_speeds = ETH_LINK_SPEED_40G |
2257 ETH_LINK_SPEED_25G |
2258 ETH_LINK_SPEED_20G |
2259 ETH_LINK_SPEED_10G |
2261 ETH_LINK_SPEED_100M;
2263 abilities |= I40E_AQ_PHY_AN_ENABLED;
2265 abilities &= ~I40E_AQ_PHY_AN_ENABLED;
2267 speed = i40e_parse_link_speeds(conf->link_speeds);
2269 return i40e_phy_conf_link(hw, abilities, speed, true);
2273 i40e_dev_start(struct rte_eth_dev *dev)
2275 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2276 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2277 struct i40e_vsi *main_vsi = pf->main_vsi;
2279 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2280 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2281 uint32_t intr_vector = 0;
2282 struct i40e_vsi *vsi;
2284 hw->adapter_stopped = 0;
2286 rte_intr_disable(intr_handle);
2288 if ((rte_intr_cap_multiple(intr_handle) ||
2289 !RTE_ETH_DEV_SRIOV(dev).active) &&
2290 dev->data->dev_conf.intr_conf.rxq != 0) {
2291 intr_vector = dev->data->nb_rx_queues;
2292 ret = rte_intr_efd_enable(intr_handle, intr_vector);
2297 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
2298 intr_handle->intr_vec =
2299 rte_zmalloc("intr_vec",
2300 dev->data->nb_rx_queues * sizeof(int),
2302 if (!intr_handle->intr_vec) {
2304 "Failed to allocate %d rx_queues intr_vec",
2305 dev->data->nb_rx_queues);
2310 /* Initialize VSI */
2311 ret = i40e_dev_rxtx_init(pf);
2312 if (ret != I40E_SUCCESS) {
2313 PMD_DRV_LOG(ERR, "Failed to init rx/tx queues");
2317 /* Map queues with MSIX interrupt */
2318 main_vsi->nb_used_qps = dev->data->nb_rx_queues -
2319 pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
2320 i40e_vsi_queues_bind_intr(main_vsi, I40E_ITR_INDEX_DEFAULT);
2321 i40e_vsi_enable_queues_intr(main_vsi);
2323 /* Map VMDQ VSI queues with MSIX interrupt */
2324 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2325 pf->vmdq[i].vsi->nb_used_qps = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
2326 i40e_vsi_queues_bind_intr(pf->vmdq[i].vsi,
2327 I40E_ITR_INDEX_DEFAULT);
2328 i40e_vsi_enable_queues_intr(pf->vmdq[i].vsi);
2331 /* enable FDIR MSIX interrupt */
2332 if (pf->fdir.fdir_vsi) {
2333 i40e_vsi_queues_bind_intr(pf->fdir.fdir_vsi,
2334 I40E_ITR_INDEX_NONE);
2335 i40e_vsi_enable_queues_intr(pf->fdir.fdir_vsi);
2338 /* Enable all queues which have been configured */
2339 ret = i40e_dev_switch_queues(pf, TRUE);
2340 if (ret != I40E_SUCCESS) {
2341 PMD_DRV_LOG(ERR, "Failed to enable VSI");
2345 /* Enable receiving broadcast packets */
2346 ret = i40e_aq_set_vsi_broadcast(hw, main_vsi->seid, true, NULL);
2347 if (ret != I40E_SUCCESS)
2348 PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
2350 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2351 ret = i40e_aq_set_vsi_broadcast(hw, pf->vmdq[i].vsi->seid,
2353 if (ret != I40E_SUCCESS)
2354 PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
2357 /* Enable the VLAN promiscuous mode. */
2359 for (i = 0; i < pf->vf_num; i++) {
2360 vsi = pf->vfs[i].vsi;
2361 i40e_aq_set_vsi_vlan_promisc(hw, vsi->seid,
2366 /* Enable mac loopback mode */
2367 if (dev->data->dev_conf.lpbk_mode == I40E_AQ_LB_MODE_NONE ||
2368 dev->data->dev_conf.lpbk_mode == I40E_AQ_LB_PHY_LOCAL) {
2369 ret = i40e_aq_set_lb_modes(hw, dev->data->dev_conf.lpbk_mode, NULL);
2370 if (ret != I40E_SUCCESS) {
2371 PMD_DRV_LOG(ERR, "fail to set loopback link");
2376 /* Apply link configure */
2377 ret = i40e_apply_link_speed(dev);
2378 if (I40E_SUCCESS != ret) {
2379 PMD_DRV_LOG(ERR, "Fail to apply link setting");
2383 if (!rte_intr_allow_others(intr_handle)) {
2384 rte_intr_callback_unregister(intr_handle,
2385 i40e_dev_interrupt_handler,
2387 /* configure and enable device interrupt */
2388 i40e_pf_config_irq0(hw, FALSE);
2389 i40e_pf_enable_irq0(hw);
2391 if (dev->data->dev_conf.intr_conf.lsc != 0)
2393 "lsc won't enable because of no intr multiplex");
2395 ret = i40e_aq_set_phy_int_mask(hw,
2396 ~(I40E_AQ_EVENT_LINK_UPDOWN |
2397 I40E_AQ_EVENT_MODULE_QUAL_FAIL |
2398 I40E_AQ_EVENT_MEDIA_NA), NULL);
2399 if (ret != I40E_SUCCESS)
2400 PMD_DRV_LOG(WARNING, "Fail to set phy mask");
2402 /* Call get_link_info aq commond to enable/disable LSE */
2403 i40e_dev_link_update(dev, 0);
2406 if (dev->data->dev_conf.intr_conf.rxq == 0) {
2407 rte_eal_alarm_set(I40E_ALARM_INTERVAL,
2408 i40e_dev_alarm_handler, dev);
2410 /* enable uio intr after callback register */
2411 rte_intr_enable(intr_handle);
2414 i40e_filter_restore(pf);
2416 if (pf->tm_conf.root && !pf->tm_conf.committed)
2417 PMD_DRV_LOG(WARNING,
2418 "please call hierarchy_commit() "
2419 "before starting the port");
2421 return I40E_SUCCESS;
2424 i40e_dev_switch_queues(pf, FALSE);
2425 i40e_dev_clear_queues(dev);
2431 i40e_dev_stop(struct rte_eth_dev *dev)
2433 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2434 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2435 struct i40e_vsi *main_vsi = pf->main_vsi;
2436 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2437 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2440 if (hw->adapter_stopped == 1)
2443 if (dev->data->dev_conf.intr_conf.rxq == 0) {
2444 rte_eal_alarm_cancel(i40e_dev_alarm_handler, dev);
2445 rte_intr_enable(intr_handle);
2448 /* Disable all queues */
2449 i40e_dev_switch_queues(pf, FALSE);
2451 /* un-map queues with interrupt registers */
2452 i40e_vsi_disable_queues_intr(main_vsi);
2453 i40e_vsi_queues_unbind_intr(main_vsi);
2455 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2456 i40e_vsi_disable_queues_intr(pf->vmdq[i].vsi);
2457 i40e_vsi_queues_unbind_intr(pf->vmdq[i].vsi);
2460 if (pf->fdir.fdir_vsi) {
2461 i40e_vsi_queues_unbind_intr(pf->fdir.fdir_vsi);
2462 i40e_vsi_disable_queues_intr(pf->fdir.fdir_vsi);
2464 /* Clear all queues and release memory */
2465 i40e_dev_clear_queues(dev);
2468 i40e_dev_set_link_down(dev);
2470 if (!rte_intr_allow_others(intr_handle))
2471 /* resume to the default handler */
2472 rte_intr_callback_register(intr_handle,
2473 i40e_dev_interrupt_handler,
2476 /* Clean datapath event and queue/vec mapping */
2477 rte_intr_efd_disable(intr_handle);
2478 if (intr_handle->intr_vec) {
2479 rte_free(intr_handle->intr_vec);
2480 intr_handle->intr_vec = NULL;
2483 /* reset hierarchy commit */
2484 pf->tm_conf.committed = false;
2486 hw->adapter_stopped = 1;
2488 pf->adapter->rss_reta_updated = 0;
2492 i40e_dev_close(struct rte_eth_dev *dev)
2494 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2495 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2496 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2497 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2498 struct i40e_mirror_rule *p_mirror;
2499 struct i40e_filter_control_settings settings;
2500 struct rte_flow *p_flow;
2504 uint8_t aq_fail = 0;
2507 PMD_INIT_FUNC_TRACE();
2509 ret = rte_eth_switch_domain_free(pf->switch_domain_id);
2511 PMD_INIT_LOG(WARNING, "failed to free switch domain: %d", ret);
2516 /* Remove all mirror rules */
2517 while ((p_mirror = TAILQ_FIRST(&pf->mirror_list))) {
2518 ret = i40e_aq_del_mirror_rule(hw,
2519 pf->main_vsi->veb->seid,
2520 p_mirror->rule_type,
2522 p_mirror->num_entries,
2525 PMD_DRV_LOG(ERR, "failed to remove mirror rule: "
2526 "status = %d, aq_err = %d.", ret,
2527 hw->aq.asq_last_status);
2529 /* remove mirror software resource anyway */
2530 TAILQ_REMOVE(&pf->mirror_list, p_mirror, rules);
2532 pf->nb_mirror_rule--;
2535 i40e_dev_free_queues(dev);
2537 /* Disable interrupt */
2538 i40e_pf_disable_irq0(hw);
2539 rte_intr_disable(intr_handle);
2542 * Only legacy filter API needs the following fdir config. So when the
2543 * legacy filter API is deprecated, the following code should also be
2546 i40e_fdir_teardown(pf);
2548 /* shutdown and destroy the HMC */
2549 i40e_shutdown_lan_hmc(hw);
2551 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2552 i40e_vsi_release(pf->vmdq[i].vsi);
2553 pf->vmdq[i].vsi = NULL;
2558 /* release all the existing VSIs and VEBs */
2559 i40e_vsi_release(pf->main_vsi);
2561 /* shutdown the adminq */
2562 i40e_aq_queue_shutdown(hw, true);
2563 i40e_shutdown_adminq(hw);
2565 i40e_res_pool_destroy(&pf->qp_pool);
2566 i40e_res_pool_destroy(&pf->msix_pool);
2568 /* Disable flexible payload in global configuration */
2569 if (!pf->support_multi_driver)
2570 i40e_flex_payload_reg_set_default(hw);
2572 /* force a PF reset to clean anything leftover */
2573 reg = I40E_READ_REG(hw, I40E_PFGEN_CTRL);
2574 I40E_WRITE_REG(hw, I40E_PFGEN_CTRL,
2575 (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
2576 I40E_WRITE_FLUSH(hw);
2578 dev->dev_ops = NULL;
2579 dev->rx_pkt_burst = NULL;
2580 dev->tx_pkt_burst = NULL;
2582 /* Clear PXE mode */
2583 i40e_clear_pxe_mode(hw);
2585 /* Unconfigure filter control */
2586 memset(&settings, 0, sizeof(settings));
2587 ret = i40e_set_filter_control(hw, &settings);
2589 PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
2592 /* Disable flow control */
2593 hw->fc.requested_mode = I40E_FC_NONE;
2594 i40e_set_fc(hw, &aq_fail, TRUE);
2596 /* uninitialize pf host driver */
2597 i40e_pf_host_uninit(dev);
2600 ret = rte_intr_callback_unregister(intr_handle,
2601 i40e_dev_interrupt_handler, dev);
2602 if (ret >= 0 || ret == -ENOENT) {
2604 } else if (ret != -EAGAIN) {
2606 "intr callback unregister failed: %d",
2609 i40e_msec_delay(500);
2610 } while (retries++ < 5);
2612 i40e_rm_ethtype_filter_list(pf);
2613 i40e_rm_tunnel_filter_list(pf);
2614 i40e_rm_fdir_filter_list(pf);
2616 /* Remove all flows */
2617 while ((p_flow = TAILQ_FIRST(&pf->flow_list))) {
2618 TAILQ_REMOVE(&pf->flow_list, p_flow, node);
2622 /* Remove all Traffic Manager configuration */
2623 i40e_tm_conf_uninit(dev);
2625 hw->adapter_closed = 1;
2629 * Reset PF device only to re-initialize resources in PMD layer
2632 i40e_dev_reset(struct rte_eth_dev *dev)
2636 /* When a DPDK PMD PF begin to reset PF port, it should notify all
2637 * its VF to make them align with it. The detailed notification
2638 * mechanism is PMD specific. As to i40e PF, it is rather complex.
2639 * To avoid unexpected behavior in VF, currently reset of PF with
2640 * SR-IOV activation is not supported. It might be supported later.
2642 if (dev->data->sriov.active)
2645 ret = eth_i40e_dev_uninit(dev);
2649 ret = eth_i40e_dev_init(dev, NULL);
2655 i40e_dev_promiscuous_enable(struct rte_eth_dev *dev)
2657 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2658 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2659 struct i40e_vsi *vsi = pf->main_vsi;
2662 status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2664 if (status != I40E_SUCCESS) {
2665 PMD_DRV_LOG(ERR, "Failed to enable unicast promiscuous");
2669 status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
2671 if (status != I40E_SUCCESS) {
2672 PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
2673 /* Rollback unicast promiscuous mode */
2674 i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2683 i40e_dev_promiscuous_disable(struct rte_eth_dev *dev)
2685 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2686 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2687 struct i40e_vsi *vsi = pf->main_vsi;
2690 status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2692 if (status != I40E_SUCCESS) {
2693 PMD_DRV_LOG(ERR, "Failed to disable unicast promiscuous");
2697 /* must remain in all_multicast mode */
2698 if (dev->data->all_multicast == 1)
2701 status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
2703 if (status != I40E_SUCCESS) {
2704 PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
2705 /* Rollback unicast promiscuous mode */
2706 i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2715 i40e_dev_allmulticast_enable(struct rte_eth_dev *dev)
2717 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2718 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2719 struct i40e_vsi *vsi = pf->main_vsi;
2722 ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid, TRUE, NULL);
2723 if (ret != I40E_SUCCESS) {
2724 PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
2732 i40e_dev_allmulticast_disable(struct rte_eth_dev *dev)
2734 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2735 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2736 struct i40e_vsi *vsi = pf->main_vsi;
2739 if (dev->data->promiscuous == 1)
2740 return 0; /* must remain in all_multicast mode */
2742 ret = i40e_aq_set_vsi_multicast_promiscuous(hw,
2743 vsi->seid, FALSE, NULL);
2744 if (ret != I40E_SUCCESS) {
2745 PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
2753 * Set device link up.
2756 i40e_dev_set_link_up(struct rte_eth_dev *dev)
2758 /* re-apply link speed setting */
2759 return i40e_apply_link_speed(dev);
2763 * Set device link down.
2766 i40e_dev_set_link_down(struct rte_eth_dev *dev)
2768 uint8_t speed = I40E_LINK_SPEED_UNKNOWN;
2769 uint8_t abilities = 0;
2770 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2772 abilities = I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
2773 return i40e_phy_conf_link(hw, abilities, speed, false);
2776 static __rte_always_inline void
2777 update_link_reg(struct i40e_hw *hw, struct rte_eth_link *link)
2779 /* Link status registers and values*/
2780 #define I40E_PRTMAC_LINKSTA 0x001E2420
2781 #define I40E_REG_LINK_UP 0x40000080
2782 #define I40E_PRTMAC_MACC 0x001E24E0
2783 #define I40E_REG_MACC_25GB 0x00020000
2784 #define I40E_REG_SPEED_MASK 0x38000000
2785 #define I40E_REG_SPEED_0 0x00000000
2786 #define I40E_REG_SPEED_1 0x08000000
2787 #define I40E_REG_SPEED_2 0x10000000
2788 #define I40E_REG_SPEED_3 0x18000000
2789 #define I40E_REG_SPEED_4 0x20000000
2790 uint32_t link_speed;
2793 reg_val = I40E_READ_REG(hw, I40E_PRTMAC_LINKSTA);
2794 link_speed = reg_val & I40E_REG_SPEED_MASK;
2795 reg_val &= I40E_REG_LINK_UP;
2796 link->link_status = (reg_val == I40E_REG_LINK_UP) ? 1 : 0;
2798 if (unlikely(link->link_status == 0))
2801 /* Parse the link status */
2802 switch (link_speed) {
2803 case I40E_REG_SPEED_0:
2804 link->link_speed = ETH_SPEED_NUM_100M;
2806 case I40E_REG_SPEED_1:
2807 link->link_speed = ETH_SPEED_NUM_1G;
2809 case I40E_REG_SPEED_2:
2810 if (hw->mac.type == I40E_MAC_X722)
2811 link->link_speed = ETH_SPEED_NUM_2_5G;
2813 link->link_speed = ETH_SPEED_NUM_10G;
2815 case I40E_REG_SPEED_3:
2816 if (hw->mac.type == I40E_MAC_X722) {
2817 link->link_speed = ETH_SPEED_NUM_5G;
2819 reg_val = I40E_READ_REG(hw, I40E_PRTMAC_MACC);
2821 if (reg_val & I40E_REG_MACC_25GB)
2822 link->link_speed = ETH_SPEED_NUM_25G;
2824 link->link_speed = ETH_SPEED_NUM_40G;
2827 case I40E_REG_SPEED_4:
2828 if (hw->mac.type == I40E_MAC_X722)
2829 link->link_speed = ETH_SPEED_NUM_10G;
2831 link->link_speed = ETH_SPEED_NUM_20G;
2834 PMD_DRV_LOG(ERR, "Unknown link speed info %u", link_speed);
2839 static __rte_always_inline void
2840 update_link_aq(struct i40e_hw *hw, struct rte_eth_link *link,
2841 bool enable_lse, int wait_to_complete)
2843 #define CHECK_INTERVAL 100 /* 100ms */
2844 #define MAX_REPEAT_TIME 10 /* 1s (10 * 100ms) in total */
2845 uint32_t rep_cnt = MAX_REPEAT_TIME;
2846 struct i40e_link_status link_status;
2849 memset(&link_status, 0, sizeof(link_status));
2852 memset(&link_status, 0, sizeof(link_status));
2854 /* Get link status information from hardware */
2855 status = i40e_aq_get_link_info(hw, enable_lse,
2856 &link_status, NULL);
2857 if (unlikely(status != I40E_SUCCESS)) {
2858 link->link_speed = ETH_SPEED_NUM_NONE;
2859 link->link_duplex = ETH_LINK_FULL_DUPLEX;
2860 PMD_DRV_LOG(ERR, "Failed to get link info");
2864 link->link_status = link_status.link_info & I40E_AQ_LINK_UP;
2865 if (!wait_to_complete || link->link_status)
2868 rte_delay_ms(CHECK_INTERVAL);
2869 } while (--rep_cnt);
2871 /* Parse the link status */
2872 switch (link_status.link_speed) {
2873 case I40E_LINK_SPEED_100MB:
2874 link->link_speed = ETH_SPEED_NUM_100M;
2876 case I40E_LINK_SPEED_1GB:
2877 link->link_speed = ETH_SPEED_NUM_1G;
2879 case I40E_LINK_SPEED_10GB:
2880 link->link_speed = ETH_SPEED_NUM_10G;
2882 case I40E_LINK_SPEED_20GB:
2883 link->link_speed = ETH_SPEED_NUM_20G;
2885 case I40E_LINK_SPEED_25GB:
2886 link->link_speed = ETH_SPEED_NUM_25G;
2888 case I40E_LINK_SPEED_40GB:
2889 link->link_speed = ETH_SPEED_NUM_40G;
2892 link->link_speed = ETH_SPEED_NUM_NONE;
2898 i40e_dev_link_update(struct rte_eth_dev *dev,
2899 int wait_to_complete)
2901 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2902 struct rte_eth_link link;
2903 bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
2906 memset(&link, 0, sizeof(link));
2908 /* i40e uses full duplex only */
2909 link.link_duplex = ETH_LINK_FULL_DUPLEX;
2910 link.link_autoneg = !(dev->data->dev_conf.link_speeds &
2911 ETH_LINK_SPEED_FIXED);
2913 if (!wait_to_complete && !enable_lse)
2914 update_link_reg(hw, &link);
2916 update_link_aq(hw, &link, enable_lse, wait_to_complete);
2919 rte_eth_linkstatus_get(hw->switch_dev, &link);
2921 ret = rte_eth_linkstatus_set(dev, &link);
2922 i40e_notify_all_vfs_link_status(dev);
2927 /* Get all the statistics of a VSI */
2929 i40e_update_vsi_stats(struct i40e_vsi *vsi)
2931 struct i40e_eth_stats *oes = &vsi->eth_stats_offset;
2932 struct i40e_eth_stats *nes = &vsi->eth_stats;
2933 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2934 int idx = rte_le_to_cpu_16(vsi->info.stat_counter_idx);
2936 i40e_stat_update_48(hw, I40E_GLV_GORCH(idx), I40E_GLV_GORCL(idx),
2937 vsi->offset_loaded, &oes->rx_bytes,
2939 i40e_stat_update_48(hw, I40E_GLV_UPRCH(idx), I40E_GLV_UPRCL(idx),
2940 vsi->offset_loaded, &oes->rx_unicast,
2942 i40e_stat_update_48(hw, I40E_GLV_MPRCH(idx), I40E_GLV_MPRCL(idx),
2943 vsi->offset_loaded, &oes->rx_multicast,
2944 &nes->rx_multicast);
2945 i40e_stat_update_48(hw, I40E_GLV_BPRCH(idx), I40E_GLV_BPRCL(idx),
2946 vsi->offset_loaded, &oes->rx_broadcast,
2947 &nes->rx_broadcast);
2948 /* exclude CRC bytes */
2949 nes->rx_bytes -= (nes->rx_unicast + nes->rx_multicast +
2950 nes->rx_broadcast) * RTE_ETHER_CRC_LEN;
2952 i40e_stat_update_32(hw, I40E_GLV_RDPC(idx), vsi->offset_loaded,
2953 &oes->rx_discards, &nes->rx_discards);
2954 /* GLV_REPC not supported */
2955 /* GLV_RMPC not supported */
2956 i40e_stat_update_32(hw, I40E_GLV_RUPP(idx), vsi->offset_loaded,
2957 &oes->rx_unknown_protocol,
2958 &nes->rx_unknown_protocol);
2959 i40e_stat_update_48(hw, I40E_GLV_GOTCH(idx), I40E_GLV_GOTCL(idx),
2960 vsi->offset_loaded, &oes->tx_bytes,
2962 i40e_stat_update_48(hw, I40E_GLV_UPTCH(idx), I40E_GLV_UPTCL(idx),
2963 vsi->offset_loaded, &oes->tx_unicast,
2965 i40e_stat_update_48(hw, I40E_GLV_MPTCH(idx), I40E_GLV_MPTCL(idx),
2966 vsi->offset_loaded, &oes->tx_multicast,
2967 &nes->tx_multicast);
2968 i40e_stat_update_48(hw, I40E_GLV_BPTCH(idx), I40E_GLV_BPTCL(idx),
2969 vsi->offset_loaded, &oes->tx_broadcast,
2970 &nes->tx_broadcast);
2971 /* GLV_TDPC not supported */
2972 i40e_stat_update_32(hw, I40E_GLV_TEPC(idx), vsi->offset_loaded,
2973 &oes->tx_errors, &nes->tx_errors);
2974 vsi->offset_loaded = true;
2976 PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats start *******************",
2978 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", nes->rx_bytes);
2979 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", nes->rx_unicast);
2980 PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", nes->rx_multicast);
2981 PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", nes->rx_broadcast);
2982 PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", nes->rx_discards);
2983 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
2984 nes->rx_unknown_protocol);
2985 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", nes->tx_bytes);
2986 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", nes->tx_unicast);
2987 PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", nes->tx_multicast);
2988 PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", nes->tx_broadcast);
2989 PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", nes->tx_discards);
2990 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", nes->tx_errors);
2991 PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats end *******************",
2996 i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw)
2999 struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
3000 struct i40e_hw_port_stats *os = &pf->stats_offset; /* old stats */
3002 /* Get rx/tx bytes of internal transfer packets */
3003 i40e_stat_update_48(hw, I40E_GLV_GORCH(hw->port),
3004 I40E_GLV_GORCL(hw->port),
3006 &pf->internal_stats_offset.rx_bytes,
3007 &pf->internal_stats.rx_bytes);
3009 i40e_stat_update_48(hw, I40E_GLV_GOTCH(hw->port),
3010 I40E_GLV_GOTCL(hw->port),
3012 &pf->internal_stats_offset.tx_bytes,
3013 &pf->internal_stats.tx_bytes);
3014 /* Get total internal rx packet count */
3015 i40e_stat_update_48(hw, I40E_GLV_UPRCH(hw->port),
3016 I40E_GLV_UPRCL(hw->port),
3018 &pf->internal_stats_offset.rx_unicast,
3019 &pf->internal_stats.rx_unicast);
3020 i40e_stat_update_48(hw, I40E_GLV_MPRCH(hw->port),
3021 I40E_GLV_MPRCL(hw->port),
3023 &pf->internal_stats_offset.rx_multicast,
3024 &pf->internal_stats.rx_multicast);
3025 i40e_stat_update_48(hw, I40E_GLV_BPRCH(hw->port),
3026 I40E_GLV_BPRCL(hw->port),
3028 &pf->internal_stats_offset.rx_broadcast,
3029 &pf->internal_stats.rx_broadcast);
3030 /* Get total internal tx packet count */
3031 i40e_stat_update_48(hw, I40E_GLV_UPTCH(hw->port),
3032 I40E_GLV_UPTCL(hw->port),
3034 &pf->internal_stats_offset.tx_unicast,
3035 &pf->internal_stats.tx_unicast);
3036 i40e_stat_update_48(hw, I40E_GLV_MPTCH(hw->port),
3037 I40E_GLV_MPTCL(hw->port),
3039 &pf->internal_stats_offset.tx_multicast,
3040 &pf->internal_stats.tx_multicast);
3041 i40e_stat_update_48(hw, I40E_GLV_BPTCH(hw->port),
3042 I40E_GLV_BPTCL(hw->port),
3044 &pf->internal_stats_offset.tx_broadcast,
3045 &pf->internal_stats.tx_broadcast);
3047 /* exclude CRC size */
3048 pf->internal_stats.rx_bytes -= (pf->internal_stats.rx_unicast +
3049 pf->internal_stats.rx_multicast +
3050 pf->internal_stats.rx_broadcast) * RTE_ETHER_CRC_LEN;
3052 /* Get statistics of struct i40e_eth_stats */
3053 i40e_stat_update_48(hw, I40E_GLPRT_GORCH(hw->port),
3054 I40E_GLPRT_GORCL(hw->port),
3055 pf->offset_loaded, &os->eth.rx_bytes,
3057 i40e_stat_update_48(hw, I40E_GLPRT_UPRCH(hw->port),
3058 I40E_GLPRT_UPRCL(hw->port),
3059 pf->offset_loaded, &os->eth.rx_unicast,
3060 &ns->eth.rx_unicast);
3061 i40e_stat_update_48(hw, I40E_GLPRT_MPRCH(hw->port),
3062 I40E_GLPRT_MPRCL(hw->port),
3063 pf->offset_loaded, &os->eth.rx_multicast,
3064 &ns->eth.rx_multicast);
3065 i40e_stat_update_48(hw, I40E_GLPRT_BPRCH(hw->port),
3066 I40E_GLPRT_BPRCL(hw->port),
3067 pf->offset_loaded, &os->eth.rx_broadcast,
3068 &ns->eth.rx_broadcast);
3069 /* Workaround: CRC size should not be included in byte statistics,
3070 * so subtract RTE_ETHER_CRC_LEN from the byte counter for each rx
3073 ns->eth.rx_bytes -= (ns->eth.rx_unicast + ns->eth.rx_multicast +
3074 ns->eth.rx_broadcast) * RTE_ETHER_CRC_LEN;
3076 /* exclude internal rx bytes
3077 * Workaround: it is possible I40E_GLV_GORCH[H/L] is updated before
3078 * I40E_GLPRT_GORCH[H/L], so there is a small window that cause negative
3080 * same to I40E_GLV_UPRC[H/L], I40E_GLV_MPRC[H/L], I40E_GLV_BPRC[H/L].
3082 if (ns->eth.rx_bytes < pf->internal_stats.rx_bytes)
3083 ns->eth.rx_bytes = 0;
3085 ns->eth.rx_bytes -= pf->internal_stats.rx_bytes;
3087 if (ns->eth.rx_unicast < pf->internal_stats.rx_unicast)
3088 ns->eth.rx_unicast = 0;
3090 ns->eth.rx_unicast -= pf->internal_stats.rx_unicast;
3092 if (ns->eth.rx_multicast < pf->internal_stats.rx_multicast)
3093 ns->eth.rx_multicast = 0;
3095 ns->eth.rx_multicast -= pf->internal_stats.rx_multicast;
3097 if (ns->eth.rx_broadcast < pf->internal_stats.rx_broadcast)
3098 ns->eth.rx_broadcast = 0;
3100 ns->eth.rx_broadcast -= pf->internal_stats.rx_broadcast;
3102 i40e_stat_update_32(hw, I40E_GLPRT_RDPC(hw->port),
3103 pf->offset_loaded, &os->eth.rx_discards,
3104 &ns->eth.rx_discards);
3105 /* GLPRT_REPC not supported */
3106 /* GLPRT_RMPC not supported */
3107 i40e_stat_update_32(hw, I40E_GLPRT_RUPP(hw->port),
3109 &os->eth.rx_unknown_protocol,
3110 &ns->eth.rx_unknown_protocol);
3111 i40e_stat_update_48(hw, I40E_GLPRT_GOTCH(hw->port),
3112 I40E_GLPRT_GOTCL(hw->port),
3113 pf->offset_loaded, &os->eth.tx_bytes,
3115 i40e_stat_update_48(hw, I40E_GLPRT_UPTCH(hw->port),
3116 I40E_GLPRT_UPTCL(hw->port),
3117 pf->offset_loaded, &os->eth.tx_unicast,
3118 &ns->eth.tx_unicast);
3119 i40e_stat_update_48(hw, I40E_GLPRT_MPTCH(hw->port),
3120 I40E_GLPRT_MPTCL(hw->port),
3121 pf->offset_loaded, &os->eth.tx_multicast,
3122 &ns->eth.tx_multicast);
3123 i40e_stat_update_48(hw, I40E_GLPRT_BPTCH(hw->port),
3124 I40E_GLPRT_BPTCL(hw->port),
3125 pf->offset_loaded, &os->eth.tx_broadcast,
3126 &ns->eth.tx_broadcast);
3127 ns->eth.tx_bytes -= (ns->eth.tx_unicast + ns->eth.tx_multicast +
3128 ns->eth.tx_broadcast) * RTE_ETHER_CRC_LEN;
3130 /* exclude internal tx bytes
3131 * Workaround: it is possible I40E_GLV_GOTCH[H/L] is updated before
3132 * I40E_GLPRT_GOTCH[H/L], so there is a small window that cause negative
3134 * same to I40E_GLV_UPTC[H/L], I40E_GLV_MPTC[H/L], I40E_GLV_BPTC[H/L].
3136 if (ns->eth.tx_bytes < pf->internal_stats.tx_bytes)
3137 ns->eth.tx_bytes = 0;
3139 ns->eth.tx_bytes -= pf->internal_stats.tx_bytes;
3141 if (ns->eth.tx_unicast < pf->internal_stats.tx_unicast)
3142 ns->eth.tx_unicast = 0;
3144 ns->eth.tx_unicast -= pf->internal_stats.tx_unicast;
3146 if (ns->eth.tx_multicast < pf->internal_stats.tx_multicast)
3147 ns->eth.tx_multicast = 0;
3149 ns->eth.tx_multicast -= pf->internal_stats.tx_multicast;
3151 if (ns->eth.tx_broadcast < pf->internal_stats.tx_broadcast)
3152 ns->eth.tx_broadcast = 0;
3154 ns->eth.tx_broadcast -= pf->internal_stats.tx_broadcast;
3156 /* GLPRT_TEPC not supported */
3158 /* additional port specific stats */
3159 i40e_stat_update_32(hw, I40E_GLPRT_TDOLD(hw->port),
3160 pf->offset_loaded, &os->tx_dropped_link_down,
3161 &ns->tx_dropped_link_down);
3162 i40e_stat_update_32(hw, I40E_GLPRT_CRCERRS(hw->port),
3163 pf->offset_loaded, &os->crc_errors,
3165 i40e_stat_update_32(hw, I40E_GLPRT_ILLERRC(hw->port),
3166 pf->offset_loaded, &os->illegal_bytes,
3167 &ns->illegal_bytes);
3168 /* GLPRT_ERRBC not supported */
3169 i40e_stat_update_32(hw, I40E_GLPRT_MLFC(hw->port),
3170 pf->offset_loaded, &os->mac_local_faults,
3171 &ns->mac_local_faults);
3172 i40e_stat_update_32(hw, I40E_GLPRT_MRFC(hw->port),
3173 pf->offset_loaded, &os->mac_remote_faults,
3174 &ns->mac_remote_faults);
3175 i40e_stat_update_32(hw, I40E_GLPRT_RLEC(hw->port),
3176 pf->offset_loaded, &os->rx_length_errors,
3177 &ns->rx_length_errors);
3178 i40e_stat_update_32(hw, I40E_GLPRT_LXONRXC(hw->port),
3179 pf->offset_loaded, &os->link_xon_rx,
3181 i40e_stat_update_32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
3182 pf->offset_loaded, &os->link_xoff_rx,
3184 for (i = 0; i < 8; i++) {
3185 i40e_stat_update_32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
3187 &os->priority_xon_rx[i],
3188 &ns->priority_xon_rx[i]);
3189 i40e_stat_update_32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
3191 &os->priority_xoff_rx[i],
3192 &ns->priority_xoff_rx[i]);
3194 i40e_stat_update_32(hw, I40E_GLPRT_LXONTXC(hw->port),
3195 pf->offset_loaded, &os->link_xon_tx,
3197 i40e_stat_update_32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
3198 pf->offset_loaded, &os->link_xoff_tx,
3200 for (i = 0; i < 8; i++) {
3201 i40e_stat_update_32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
3203 &os->priority_xon_tx[i],
3204 &ns->priority_xon_tx[i]);
3205 i40e_stat_update_32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
3207 &os->priority_xoff_tx[i],
3208 &ns->priority_xoff_tx[i]);
3209 i40e_stat_update_32(hw, I40E_GLPRT_RXON2OFFCNT(hw->port, i),
3211 &os->priority_xon_2_xoff[i],
3212 &ns->priority_xon_2_xoff[i]);
3214 i40e_stat_update_48(hw, I40E_GLPRT_PRC64H(hw->port),
3215 I40E_GLPRT_PRC64L(hw->port),
3216 pf->offset_loaded, &os->rx_size_64,
3218 i40e_stat_update_48(hw, I40E_GLPRT_PRC127H(hw->port),
3219 I40E_GLPRT_PRC127L(hw->port),
3220 pf->offset_loaded, &os->rx_size_127,
3222 i40e_stat_update_48(hw, I40E_GLPRT_PRC255H(hw->port),
3223 I40E_GLPRT_PRC255L(hw->port),
3224 pf->offset_loaded, &os->rx_size_255,
3226 i40e_stat_update_48(hw, I40E_GLPRT_PRC511H(hw->port),
3227 I40E_GLPRT_PRC511L(hw->port),
3228 pf->offset_loaded, &os->rx_size_511,
3230 i40e_stat_update_48(hw, I40E_GLPRT_PRC1023H(hw->port),
3231 I40E_GLPRT_PRC1023L(hw->port),
3232 pf->offset_loaded, &os->rx_size_1023,
3234 i40e_stat_update_48(hw, I40E_GLPRT_PRC1522H(hw->port),
3235 I40E_GLPRT_PRC1522L(hw->port),
3236 pf->offset_loaded, &os->rx_size_1522,
3238 i40e_stat_update_48(hw, I40E_GLPRT_PRC9522H(hw->port),
3239 I40E_GLPRT_PRC9522L(hw->port),
3240 pf->offset_loaded, &os->rx_size_big,
3242 i40e_stat_update_32(hw, I40E_GLPRT_RUC(hw->port),
3243 pf->offset_loaded, &os->rx_undersize,
3245 i40e_stat_update_32(hw, I40E_GLPRT_RFC(hw->port),
3246 pf->offset_loaded, &os->rx_fragments,
3248 i40e_stat_update_32(hw, I40E_GLPRT_ROC(hw->port),
3249 pf->offset_loaded, &os->rx_oversize,
3251 i40e_stat_update_32(hw, I40E_GLPRT_RJC(hw->port),
3252 pf->offset_loaded, &os->rx_jabber,
3254 i40e_stat_update_48(hw, I40E_GLPRT_PTC64H(hw->port),
3255 I40E_GLPRT_PTC64L(hw->port),
3256 pf->offset_loaded, &os->tx_size_64,
3258 i40e_stat_update_48(hw, I40E_GLPRT_PTC127H(hw->port),
3259 I40E_GLPRT_PTC127L(hw->port),
3260 pf->offset_loaded, &os->tx_size_127,
3262 i40e_stat_update_48(hw, I40E_GLPRT_PTC255H(hw->port),
3263 I40E_GLPRT_PTC255L(hw->port),
3264 pf->offset_loaded, &os->tx_size_255,
3266 i40e_stat_update_48(hw, I40E_GLPRT_PTC511H(hw->port),
3267 I40E_GLPRT_PTC511L(hw->port),
3268 pf->offset_loaded, &os->tx_size_511,
3270 i40e_stat_update_48(hw, I40E_GLPRT_PTC1023H(hw->port),
3271 I40E_GLPRT_PTC1023L(hw->port),
3272 pf->offset_loaded, &os->tx_size_1023,
3274 i40e_stat_update_48(hw, I40E_GLPRT_PTC1522H(hw->port),
3275 I40E_GLPRT_PTC1522L(hw->port),
3276 pf->offset_loaded, &os->tx_size_1522,
3278 i40e_stat_update_48(hw, I40E_GLPRT_PTC9522H(hw->port),
3279 I40E_GLPRT_PTC9522L(hw->port),
3280 pf->offset_loaded, &os->tx_size_big,
3282 i40e_stat_update_32(hw, I40E_GLQF_PCNT(pf->fdir.match_counter_index),
3284 &os->fd_sb_match, &ns->fd_sb_match);
3285 /* GLPRT_MSPDC not supported */
3286 /* GLPRT_XEC not supported */
3288 pf->offset_loaded = true;
3291 i40e_update_vsi_stats(pf->main_vsi);
3294 /* Get all statistics of a port */
3296 i40e_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
3298 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3299 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3300 struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
3301 struct i40e_vsi *vsi;
3304 /* call read registers - updates values, now write them to struct */
3305 i40e_read_stats_registers(pf, hw);
3307 stats->ipackets = pf->main_vsi->eth_stats.rx_unicast +
3308 pf->main_vsi->eth_stats.rx_multicast +
3309 pf->main_vsi->eth_stats.rx_broadcast -
3310 pf->main_vsi->eth_stats.rx_discards;
3311 stats->opackets = ns->eth.tx_unicast +
3312 ns->eth.tx_multicast +
3313 ns->eth.tx_broadcast;
3314 stats->ibytes = pf->main_vsi->eth_stats.rx_bytes;
3315 stats->obytes = ns->eth.tx_bytes;
3316 stats->oerrors = ns->eth.tx_errors +
3317 pf->main_vsi->eth_stats.tx_errors;
3320 stats->imissed = ns->eth.rx_discards +
3321 pf->main_vsi->eth_stats.rx_discards;
3322 stats->ierrors = ns->crc_errors +
3323 ns->rx_length_errors + ns->rx_undersize +
3324 ns->rx_oversize + ns->rx_fragments + ns->rx_jabber;
3327 for (i = 0; i < pf->vf_num; i++) {
3328 vsi = pf->vfs[i].vsi;
3329 i40e_update_vsi_stats(vsi);
3331 stats->ipackets += (vsi->eth_stats.rx_unicast +
3332 vsi->eth_stats.rx_multicast +
3333 vsi->eth_stats.rx_broadcast -
3334 vsi->eth_stats.rx_discards);
3335 stats->ibytes += vsi->eth_stats.rx_bytes;
3336 stats->oerrors += vsi->eth_stats.tx_errors;
3337 stats->imissed += vsi->eth_stats.rx_discards;
3341 PMD_DRV_LOG(DEBUG, "***************** PF stats start *******************");
3342 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", ns->eth.rx_bytes);
3343 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", ns->eth.rx_unicast);
3344 PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", ns->eth.rx_multicast);
3345 PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", ns->eth.rx_broadcast);
3346 PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", ns->eth.rx_discards);
3347 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
3348 ns->eth.rx_unknown_protocol);
3349 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", ns->eth.tx_bytes);
3350 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", ns->eth.tx_unicast);
3351 PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", ns->eth.tx_multicast);
3352 PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", ns->eth.tx_broadcast);
3353 PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", ns->eth.tx_discards);
3354 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", ns->eth.tx_errors);
3356 PMD_DRV_LOG(DEBUG, "tx_dropped_link_down: %"PRIu64"",
3357 ns->tx_dropped_link_down);
3358 PMD_DRV_LOG(DEBUG, "crc_errors: %"PRIu64"", ns->crc_errors);
3359 PMD_DRV_LOG(DEBUG, "illegal_bytes: %"PRIu64"",
3361 PMD_DRV_LOG(DEBUG, "error_bytes: %"PRIu64"", ns->error_bytes);
3362 PMD_DRV_LOG(DEBUG, "mac_local_faults: %"PRIu64"",
3363 ns->mac_local_faults);
3364 PMD_DRV_LOG(DEBUG, "mac_remote_faults: %"PRIu64"",
3365 ns->mac_remote_faults);
3366 PMD_DRV_LOG(DEBUG, "rx_length_errors: %"PRIu64"",
3367 ns->rx_length_errors);
3368 PMD_DRV_LOG(DEBUG, "link_xon_rx: %"PRIu64"", ns->link_xon_rx);
3369 PMD_DRV_LOG(DEBUG, "link_xoff_rx: %"PRIu64"", ns->link_xoff_rx);
3370 for (i = 0; i < 8; i++) {
3371 PMD_DRV_LOG(DEBUG, "priority_xon_rx[%d]: %"PRIu64"",
3372 i, ns->priority_xon_rx[i]);
3373 PMD_DRV_LOG(DEBUG, "priority_xoff_rx[%d]: %"PRIu64"",
3374 i, ns->priority_xoff_rx[i]);
3376 PMD_DRV_LOG(DEBUG, "link_xon_tx: %"PRIu64"", ns->link_xon_tx);
3377 PMD_DRV_LOG(DEBUG, "link_xoff_tx: %"PRIu64"", ns->link_xoff_tx);
3378 for (i = 0; i < 8; i++) {
3379 PMD_DRV_LOG(DEBUG, "priority_xon_tx[%d]: %"PRIu64"",
3380 i, ns->priority_xon_tx[i]);
3381 PMD_DRV_LOG(DEBUG, "priority_xoff_tx[%d]: %"PRIu64"",
3382 i, ns->priority_xoff_tx[i]);
3383 PMD_DRV_LOG(DEBUG, "priority_xon_2_xoff[%d]: %"PRIu64"",
3384 i, ns->priority_xon_2_xoff[i]);
3386 PMD_DRV_LOG(DEBUG, "rx_size_64: %"PRIu64"", ns->rx_size_64);
3387 PMD_DRV_LOG(DEBUG, "rx_size_127: %"PRIu64"", ns->rx_size_127);
3388 PMD_DRV_LOG(DEBUG, "rx_size_255: %"PRIu64"", ns->rx_size_255);
3389 PMD_DRV_LOG(DEBUG, "rx_size_511: %"PRIu64"", ns->rx_size_511);
3390 PMD_DRV_LOG(DEBUG, "rx_size_1023: %"PRIu64"", ns->rx_size_1023);
3391 PMD_DRV_LOG(DEBUG, "rx_size_1522: %"PRIu64"", ns->rx_size_1522);
3392 PMD_DRV_LOG(DEBUG, "rx_size_big: %"PRIu64"", ns->rx_size_big);
3393 PMD_DRV_LOG(DEBUG, "rx_undersize: %"PRIu64"", ns->rx_undersize);
3394 PMD_DRV_LOG(DEBUG, "rx_fragments: %"PRIu64"", ns->rx_fragments);
3395 PMD_DRV_LOG(DEBUG, "rx_oversize: %"PRIu64"", ns->rx_oversize);
3396 PMD_DRV_LOG(DEBUG, "rx_jabber: %"PRIu64"", ns->rx_jabber);
3397 PMD_DRV_LOG(DEBUG, "tx_size_64: %"PRIu64"", ns->tx_size_64);
3398 PMD_DRV_LOG(DEBUG, "tx_size_127: %"PRIu64"", ns->tx_size_127);
3399 PMD_DRV_LOG(DEBUG, "tx_size_255: %"PRIu64"", ns->tx_size_255);
3400 PMD_DRV_LOG(DEBUG, "tx_size_511: %"PRIu64"", ns->tx_size_511);
3401 PMD_DRV_LOG(DEBUG, "tx_size_1023: %"PRIu64"", ns->tx_size_1023);
3402 PMD_DRV_LOG(DEBUG, "tx_size_1522: %"PRIu64"", ns->tx_size_1522);
3403 PMD_DRV_LOG(DEBUG, "tx_size_big: %"PRIu64"", ns->tx_size_big);
3404 PMD_DRV_LOG(DEBUG, "mac_short_packet_dropped: %"PRIu64"",
3405 ns->mac_short_packet_dropped);
3406 PMD_DRV_LOG(DEBUG, "checksum_error: %"PRIu64"",
3407 ns->checksum_error);
3408 PMD_DRV_LOG(DEBUG, "fdir_match: %"PRIu64"", ns->fd_sb_match);
3409 PMD_DRV_LOG(DEBUG, "***************** PF stats end ********************");
3413 /* Reset the statistics */
3415 i40e_dev_stats_reset(struct rte_eth_dev *dev)
3417 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3418 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3420 /* Mark PF and VSI stats to update the offset, aka "reset" */
3421 pf->offset_loaded = false;
3423 pf->main_vsi->offset_loaded = false;
3425 /* read the stats, reading current register values into offset */
3426 i40e_read_stats_registers(pf, hw);
3432 i40e_xstats_calc_num(void)
3434 return I40E_NB_ETH_XSTATS + I40E_NB_HW_PORT_XSTATS +
3435 (I40E_NB_RXQ_PRIO_XSTATS * 8) +
3436 (I40E_NB_TXQ_PRIO_XSTATS * 8);
3439 static int i40e_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
3440 struct rte_eth_xstat_name *xstats_names,
3441 __rte_unused unsigned limit)
3446 if (xstats_names == NULL)
3447 return i40e_xstats_calc_num();
3449 /* Note: limit checked in rte_eth_xstats_names() */
3451 /* Get stats from i40e_eth_stats struct */
3452 for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
3453 strlcpy(xstats_names[count].name,
3454 rte_i40e_stats_strings[i].name,
3455 sizeof(xstats_names[count].name));
3459 /* Get individiual stats from i40e_hw_port struct */
3460 for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
3461 strlcpy(xstats_names[count].name,
3462 rte_i40e_hw_port_strings[i].name,
3463 sizeof(xstats_names[count].name));
3467 for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
3468 for (prio = 0; prio < 8; prio++) {
3469 snprintf(xstats_names[count].name,
3470 sizeof(xstats_names[count].name),
3471 "rx_priority%u_%s", prio,
3472 rte_i40e_rxq_prio_strings[i].name);
3477 for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
3478 for (prio = 0; prio < 8; prio++) {
3479 snprintf(xstats_names[count].name,
3480 sizeof(xstats_names[count].name),
3481 "tx_priority%u_%s", prio,
3482 rte_i40e_txq_prio_strings[i].name);
3490 i40e_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
3493 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3494 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3495 unsigned i, count, prio;
3496 struct i40e_hw_port_stats *hw_stats = &pf->stats;
3498 count = i40e_xstats_calc_num();
3502 i40e_read_stats_registers(pf, hw);
3509 /* Get stats from i40e_eth_stats struct */
3510 for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
3511 xstats[count].value = *(uint64_t *)(((char *)&hw_stats->eth) +
3512 rte_i40e_stats_strings[i].offset);
3513 xstats[count].id = count;
3517 /* Get individiual stats from i40e_hw_port struct */
3518 for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
3519 xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
3520 rte_i40e_hw_port_strings[i].offset);
3521 xstats[count].id = count;
3525 for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
3526 for (prio = 0; prio < 8; prio++) {
3527 xstats[count].value =
3528 *(uint64_t *)(((char *)hw_stats) +
3529 rte_i40e_rxq_prio_strings[i].offset +
3530 (sizeof(uint64_t) * prio));
3531 xstats[count].id = count;
3536 for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
3537 for (prio = 0; prio < 8; prio++) {
3538 xstats[count].value =
3539 *(uint64_t *)(((char *)hw_stats) +
3540 rte_i40e_txq_prio_strings[i].offset +
3541 (sizeof(uint64_t) * prio));
3542 xstats[count].id = count;
3551 i40e_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
3553 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3559 full_ver = hw->nvm.oem_ver;
3560 ver = (u8)(full_ver >> 24);
3561 build = (u16)((full_ver >> 8) & 0xffff);
3562 patch = (u8)(full_ver & 0xff);
3564 ret = snprintf(fw_version, fw_size,
3565 "%d.%d%d 0x%08x %d.%d.%d",
3566 ((hw->nvm.version >> 12) & 0xf),
3567 ((hw->nvm.version >> 4) & 0xff),
3568 (hw->nvm.version & 0xf), hw->nvm.eetrack,
3571 ret += 1; /* add the size of '\0' */
3572 if (fw_size < (u32)ret)
3579 * When using NVM 6.01(for X710 XL710 XXV710)/3.33(for X722) or later,
3580 * the Rx data path does not hang if the FW LLDP is stopped.
3581 * return true if lldp need to stop
3582 * return false if we cannot disable the LLDP to avoid Rx data path blocking.
3585 i40e_need_stop_lldp(struct rte_eth_dev *dev)
3588 char ver_str[64] = {0};
3589 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3591 i40e_fw_version_get(dev, ver_str, 64);
3592 nvm_ver = atof(ver_str);
3593 if ((hw->mac.type == I40E_MAC_X722 ||
3594 hw->mac.type == I40E_MAC_X722_VF) &&
3595 ((uint32_t)(nvm_ver * 1000) >= (uint32_t)(3.33 * 1000)))
3597 else if ((uint32_t)(nvm_ver * 1000) >= (uint32_t)(6.01 * 1000))
3604 i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
3606 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3607 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3608 struct i40e_vsi *vsi = pf->main_vsi;
3609 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3611 dev_info->max_rx_queues = vsi->nb_qps;
3612 dev_info->max_tx_queues = vsi->nb_qps;
3613 dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
3614 dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
3615 dev_info->max_mac_addrs = vsi->max_macaddrs;
3616 dev_info->max_vfs = pci_dev->max_vfs;
3617 dev_info->max_mtu = dev_info->max_rx_pktlen - I40E_ETH_OVERHEAD;
3618 dev_info->min_mtu = RTE_ETHER_MIN_MTU;
3619 dev_info->rx_queue_offload_capa = 0;
3620 dev_info->rx_offload_capa =
3621 DEV_RX_OFFLOAD_VLAN_STRIP |
3622 DEV_RX_OFFLOAD_QINQ_STRIP |
3623 DEV_RX_OFFLOAD_IPV4_CKSUM |
3624 DEV_RX_OFFLOAD_UDP_CKSUM |
3625 DEV_RX_OFFLOAD_TCP_CKSUM |
3626 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
3627 DEV_RX_OFFLOAD_KEEP_CRC |
3628 DEV_RX_OFFLOAD_SCATTER |
3629 DEV_RX_OFFLOAD_VLAN_EXTEND |
3630 DEV_RX_OFFLOAD_VLAN_FILTER |
3631 DEV_RX_OFFLOAD_JUMBO_FRAME |
3632 DEV_RX_OFFLOAD_RSS_HASH;
3634 dev_info->tx_queue_offload_capa = DEV_TX_OFFLOAD_MBUF_FAST_FREE;
3635 dev_info->tx_offload_capa =
3636 DEV_TX_OFFLOAD_VLAN_INSERT |
3637 DEV_TX_OFFLOAD_QINQ_INSERT |
3638 DEV_TX_OFFLOAD_IPV4_CKSUM |
3639 DEV_TX_OFFLOAD_UDP_CKSUM |
3640 DEV_TX_OFFLOAD_TCP_CKSUM |
3641 DEV_TX_OFFLOAD_SCTP_CKSUM |
3642 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
3643 DEV_TX_OFFLOAD_TCP_TSO |
3644 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
3645 DEV_TX_OFFLOAD_GRE_TNL_TSO |
3646 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
3647 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
3648 DEV_TX_OFFLOAD_MULTI_SEGS |
3649 dev_info->tx_queue_offload_capa;
3650 dev_info->dev_capa =
3651 RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
3652 RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
3654 dev_info->hash_key_size = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
3656 dev_info->reta_size = pf->hash_lut_size;
3657 dev_info->flow_type_rss_offloads = pf->adapter->flow_types_mask;
3659 dev_info->default_rxconf = (struct rte_eth_rxconf) {
3661 .pthresh = I40E_DEFAULT_RX_PTHRESH,
3662 .hthresh = I40E_DEFAULT_RX_HTHRESH,
3663 .wthresh = I40E_DEFAULT_RX_WTHRESH,
3665 .rx_free_thresh = I40E_DEFAULT_RX_FREE_THRESH,
3670 dev_info->default_txconf = (struct rte_eth_txconf) {
3672 .pthresh = I40E_DEFAULT_TX_PTHRESH,
3673 .hthresh = I40E_DEFAULT_TX_HTHRESH,
3674 .wthresh = I40E_DEFAULT_TX_WTHRESH,
3676 .tx_free_thresh = I40E_DEFAULT_TX_FREE_THRESH,
3677 .tx_rs_thresh = I40E_DEFAULT_TX_RSBIT_THRESH,
3681 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
3682 .nb_max = I40E_MAX_RING_DESC,
3683 .nb_min = I40E_MIN_RING_DESC,
3684 .nb_align = I40E_ALIGN_RING_DESC,
3687 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
3688 .nb_max = I40E_MAX_RING_DESC,
3689 .nb_min = I40E_MIN_RING_DESC,
3690 .nb_align = I40E_ALIGN_RING_DESC,
3691 .nb_seg_max = I40E_TX_MAX_SEG,
3692 .nb_mtu_seg_max = I40E_TX_MAX_MTU_SEG,
3695 if (pf->flags & I40E_FLAG_VMDQ) {
3696 dev_info->max_vmdq_pools = pf->max_nb_vmdq_vsi;
3697 dev_info->vmdq_queue_base = dev_info->max_rx_queues;
3698 dev_info->vmdq_queue_num = pf->vmdq_nb_qps *
3699 pf->max_nb_vmdq_vsi;
3700 dev_info->vmdq_pool_base = I40E_VMDQ_POOL_BASE;
3701 dev_info->max_rx_queues += dev_info->vmdq_queue_num;
3702 dev_info->max_tx_queues += dev_info->vmdq_queue_num;
3705 if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
3707 dev_info->speed_capa = ETH_LINK_SPEED_40G;
3708 dev_info->default_rxportconf.nb_queues = 2;
3709 dev_info->default_txportconf.nb_queues = 2;
3710 if (dev->data->nb_rx_queues == 1)
3711 dev_info->default_rxportconf.ring_size = 2048;
3713 dev_info->default_rxportconf.ring_size = 1024;
3714 if (dev->data->nb_tx_queues == 1)
3715 dev_info->default_txportconf.ring_size = 1024;
3717 dev_info->default_txportconf.ring_size = 512;
3719 } else if (I40E_PHY_TYPE_SUPPORT_25G(hw->phy.phy_types)) {
3721 dev_info->speed_capa = ETH_LINK_SPEED_25G;
3722 dev_info->default_rxportconf.nb_queues = 1;
3723 dev_info->default_txportconf.nb_queues = 1;
3724 dev_info->default_rxportconf.ring_size = 256;
3725 dev_info->default_txportconf.ring_size = 256;
3728 dev_info->speed_capa = ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G;
3729 dev_info->default_rxportconf.nb_queues = 1;
3730 dev_info->default_txportconf.nb_queues = 1;
3731 if (dev->data->dev_conf.link_speeds & ETH_LINK_SPEED_10G) {
3732 dev_info->default_rxportconf.ring_size = 512;
3733 dev_info->default_txportconf.ring_size = 256;
3735 dev_info->default_rxportconf.ring_size = 256;
3736 dev_info->default_txportconf.ring_size = 256;
3739 dev_info->default_rxportconf.burst_size = 32;
3740 dev_info->default_txportconf.burst_size = 32;
3746 i40e_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
3748 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3749 struct i40e_vsi *vsi = pf->main_vsi;
3750 PMD_INIT_FUNC_TRACE();
3753 return i40e_vsi_add_vlan(vsi, vlan_id);
3755 return i40e_vsi_delete_vlan(vsi, vlan_id);
3759 i40e_vlan_tpid_set_by_registers(struct rte_eth_dev *dev,
3760 enum rte_vlan_type vlan_type,
3761 uint16_t tpid, int qinq)
3763 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3766 uint16_t reg_id = 3;
3770 if (vlan_type == ETH_VLAN_TYPE_OUTER)
3774 ret = i40e_aq_debug_read_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
3776 if (ret != I40E_SUCCESS) {
3778 "Fail to debug read from I40E_GL_SWT_L2TAGCTRL[%d]",
3783 "Debug read from I40E_GL_SWT_L2TAGCTRL[%d]: 0x%08"PRIx64,
3786 reg_w = reg_r & (~(I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_MASK));
3787 reg_w |= ((uint64_t)tpid << I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT);
3788 if (reg_r == reg_w) {
3789 PMD_DRV_LOG(DEBUG, "No need to write");
3793 ret = i40e_aq_debug_write_global_register(hw,
3794 I40E_GL_SWT_L2TAGCTRL(reg_id),
3796 if (ret != I40E_SUCCESS) {
3798 "Fail to debug write to I40E_GL_SWT_L2TAGCTRL[%d]",
3803 "Global register 0x%08x is changed with value 0x%08x",
3804 I40E_GL_SWT_L2TAGCTRL(reg_id), (uint32_t)reg_w);
3810 i40e_vlan_tpid_set(struct rte_eth_dev *dev,
3811 enum rte_vlan_type vlan_type,
3814 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3815 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3816 int qinq = dev->data->dev_conf.rxmode.offloads &
3817 DEV_RX_OFFLOAD_VLAN_EXTEND;
3820 if ((vlan_type != ETH_VLAN_TYPE_INNER &&
3821 vlan_type != ETH_VLAN_TYPE_OUTER) ||
3822 (!qinq && vlan_type == ETH_VLAN_TYPE_INNER)) {
3824 "Unsupported vlan type.");
3828 if (pf->support_multi_driver) {
3829 PMD_DRV_LOG(ERR, "Setting TPID is not supported.");
3833 /* 802.1ad frames ability is added in NVM API 1.7*/
3834 if (hw->flags & I40E_HW_FLAG_802_1AD_CAPABLE) {
3836 if (vlan_type == ETH_VLAN_TYPE_OUTER)
3837 hw->first_tag = rte_cpu_to_le_16(tpid);
3838 else if (vlan_type == ETH_VLAN_TYPE_INNER)
3839 hw->second_tag = rte_cpu_to_le_16(tpid);
3841 if (vlan_type == ETH_VLAN_TYPE_OUTER)
3842 hw->second_tag = rte_cpu_to_le_16(tpid);
3844 ret = i40e_aq_set_switch_config(hw, 0, 0, 0, NULL);
3845 if (ret != I40E_SUCCESS) {
3847 "Set switch config failed aq_err: %d",
3848 hw->aq.asq_last_status);
3852 /* If NVM API < 1.7, keep the register setting */
3853 ret = i40e_vlan_tpid_set_by_registers(dev, vlan_type,
3860 i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask)
3862 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3863 struct i40e_vsi *vsi = pf->main_vsi;
3864 struct rte_eth_rxmode *rxmode;
3866 if (mask & ETH_QINQ_STRIP_MASK) {
3867 PMD_DRV_LOG(ERR, "Strip qinq is not supported.");
3871 rxmode = &dev->data->dev_conf.rxmode;
3872 if (mask & ETH_VLAN_FILTER_MASK) {
3873 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
3874 i40e_vsi_config_vlan_filter(vsi, TRUE);
3876 i40e_vsi_config_vlan_filter(vsi, FALSE);
3879 if (mask & ETH_VLAN_STRIP_MASK) {
3880 /* Enable or disable VLAN stripping */
3881 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
3882 i40e_vsi_config_vlan_stripping(vsi, TRUE);
3884 i40e_vsi_config_vlan_stripping(vsi, FALSE);
3887 if (mask & ETH_VLAN_EXTEND_MASK) {
3888 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_EXTEND) {
3889 i40e_vsi_config_double_vlan(vsi, TRUE);
3890 /* Set global registers with default ethertype. */
3891 i40e_vlan_tpid_set(dev, ETH_VLAN_TYPE_OUTER,
3892 RTE_ETHER_TYPE_VLAN);
3893 i40e_vlan_tpid_set(dev, ETH_VLAN_TYPE_INNER,
3894 RTE_ETHER_TYPE_VLAN);
3897 i40e_vsi_config_double_vlan(vsi, FALSE);
3904 i40e_vlan_strip_queue_set(__rte_unused struct rte_eth_dev *dev,
3905 __rte_unused uint16_t queue,
3906 __rte_unused int on)
3908 PMD_INIT_FUNC_TRACE();
3912 i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
3914 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3915 struct i40e_vsi *vsi = pf->main_vsi;
3916 struct rte_eth_dev_data *data = I40E_VSI_TO_DEV_DATA(vsi);
3917 struct i40e_vsi_vlan_pvid_info info;
3919 memset(&info, 0, sizeof(info));
3922 info.config.pvid = pvid;
3924 info.config.reject.tagged =
3925 data->dev_conf.txmode.hw_vlan_reject_tagged;
3926 info.config.reject.untagged =
3927 data->dev_conf.txmode.hw_vlan_reject_untagged;
3930 return i40e_vsi_vlan_pvid_set(vsi, &info);
3934 i40e_dev_led_on(struct rte_eth_dev *dev)
3936 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3937 uint32_t mode = i40e_led_get(hw);
3940 i40e_led_set(hw, 0xf, true); /* 0xf means led always true */
3946 i40e_dev_led_off(struct rte_eth_dev *dev)
3948 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3949 uint32_t mode = i40e_led_get(hw);
3952 i40e_led_set(hw, 0, false);
3958 i40e_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
3960 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3961 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3963 fc_conf->pause_time = pf->fc_conf.pause_time;
3965 /* read out from register, in case they are modified by other port */
3966 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] =
3967 I40E_READ_REG(hw, I40E_GLRPB_GHW) >> I40E_KILOSHIFT;
3968 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] =
3969 I40E_READ_REG(hw, I40E_GLRPB_GLW) >> I40E_KILOSHIFT;
3971 fc_conf->high_water = pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS];
3972 fc_conf->low_water = pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS];
3974 /* Return current mode according to actual setting*/
3975 switch (hw->fc.current_mode) {
3977 fc_conf->mode = RTE_FC_FULL;
3979 case I40E_FC_TX_PAUSE:
3980 fc_conf->mode = RTE_FC_TX_PAUSE;
3982 case I40E_FC_RX_PAUSE:
3983 fc_conf->mode = RTE_FC_RX_PAUSE;
3987 fc_conf->mode = RTE_FC_NONE;
3994 i40e_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
3996 uint32_t mflcn_reg, fctrl_reg, reg;
3997 uint32_t max_high_water;
3998 uint8_t i, aq_failure;
4002 enum i40e_fc_mode rte_fcmode_2_i40e_fcmode[] = {
4003 [RTE_FC_NONE] = I40E_FC_NONE,
4004 [RTE_FC_RX_PAUSE] = I40E_FC_RX_PAUSE,
4005 [RTE_FC_TX_PAUSE] = I40E_FC_TX_PAUSE,
4006 [RTE_FC_FULL] = I40E_FC_FULL
4009 /* high_water field in the rte_eth_fc_conf using the kilobytes unit */
4011 max_high_water = I40E_RXPBSIZE >> I40E_KILOSHIFT;
4012 if ((fc_conf->high_water > max_high_water) ||
4013 (fc_conf->high_water < fc_conf->low_water)) {
4015 "Invalid high/low water setup value in KB, High_water must be <= %d.",
4020 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4021 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4022 hw->fc.requested_mode = rte_fcmode_2_i40e_fcmode[fc_conf->mode];
4024 pf->fc_conf.pause_time = fc_conf->pause_time;
4025 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->high_water;
4026 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->low_water;
4028 PMD_INIT_FUNC_TRACE();
4030 /* All the link flow control related enable/disable register
4031 * configuration is handle by the F/W
4033 err = i40e_set_fc(hw, &aq_failure, true);
4037 if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
4038 /* Configure flow control refresh threshold,
4039 * the value for stat_tx_pause_refresh_timer[8]
4040 * is used for global pause operation.
4044 I40E_PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER(8),
4045 pf->fc_conf.pause_time);
4047 /* configure the timer value included in transmitted pause
4049 * the value for stat_tx_pause_quanta[8] is used for global
4052 I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA(8),
4053 pf->fc_conf.pause_time);
4055 fctrl_reg = I40E_READ_REG(hw,
4056 I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL);
4058 if (fc_conf->mac_ctrl_frame_fwd != 0)
4059 fctrl_reg |= I40E_PRTMAC_FWD_CTRL;
4061 fctrl_reg &= ~I40E_PRTMAC_FWD_CTRL;
4063 I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL,
4066 /* Configure pause time (2 TCs per register) */
4067 reg = (uint32_t)pf->fc_conf.pause_time * (uint32_t)0x00010001;
4068 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS / 2; i++)
4069 I40E_WRITE_REG(hw, I40E_PRTDCB_FCTTVN(i), reg);
4071 /* Configure flow control refresh threshold value */
4072 I40E_WRITE_REG(hw, I40E_PRTDCB_FCRTV,
4073 pf->fc_conf.pause_time / 2);
4075 mflcn_reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
4077 /* set or clear MFLCN.PMCF & MFLCN.DPF bits
4078 *depending on configuration
4080 if (fc_conf->mac_ctrl_frame_fwd != 0) {
4081 mflcn_reg |= I40E_PRTDCB_MFLCN_PMCF_MASK;
4082 mflcn_reg &= ~I40E_PRTDCB_MFLCN_DPF_MASK;
4084 mflcn_reg &= ~I40E_PRTDCB_MFLCN_PMCF_MASK;
4085 mflcn_reg |= I40E_PRTDCB_MFLCN_DPF_MASK;
4088 I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, mflcn_reg);
4091 if (!pf->support_multi_driver) {
4092 /* config water marker both based on the packets and bytes */
4093 I40E_WRITE_GLB_REG(hw, I40E_GLRPB_PHW,
4094 (pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
4095 << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
4096 I40E_WRITE_GLB_REG(hw, I40E_GLRPB_PLW,
4097 (pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
4098 << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
4099 I40E_WRITE_GLB_REG(hw, I40E_GLRPB_GHW,
4100 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
4102 I40E_WRITE_GLB_REG(hw, I40E_GLRPB_GLW,
4103 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
4107 "Water marker configuration is not supported.");
4110 I40E_WRITE_FLUSH(hw);
4116 i40e_priority_flow_ctrl_set(__rte_unused struct rte_eth_dev *dev,
4117 __rte_unused struct rte_eth_pfc_conf *pfc_conf)
4119 PMD_INIT_FUNC_TRACE();
4124 /* Add a MAC address, and update filters */
4126 i40e_macaddr_add(struct rte_eth_dev *dev,
4127 struct rte_ether_addr *mac_addr,
4128 __rte_unused uint32_t index,
4131 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4132 struct i40e_mac_filter_info mac_filter;
4133 struct i40e_vsi *vsi;
4134 struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
4137 /* If VMDQ not enabled or configured, return */
4138 if (pool != 0 && (!(pf->flags & I40E_FLAG_VMDQ) ||
4139 !pf->nb_cfg_vmdq_vsi)) {
4140 PMD_DRV_LOG(ERR, "VMDQ not %s, can't set mac to pool %u",
4141 pf->flags & I40E_FLAG_VMDQ ? "configured" : "enabled",
4146 if (pool > pf->nb_cfg_vmdq_vsi) {
4147 PMD_DRV_LOG(ERR, "Pool number %u invalid. Max pool is %u",
4148 pool, pf->nb_cfg_vmdq_vsi);
4152 rte_memcpy(&mac_filter.mac_addr, mac_addr, RTE_ETHER_ADDR_LEN);
4153 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
4154 mac_filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
4156 mac_filter.filter_type = RTE_MAC_PERFECT_MATCH;
4161 vsi = pf->vmdq[pool - 1].vsi;
4163 ret = i40e_vsi_add_mac(vsi, &mac_filter);
4164 if (ret != I40E_SUCCESS) {
4165 PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
4171 /* Remove a MAC address, and update filters */
4173 i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
4175 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4176 struct i40e_vsi *vsi;
4177 struct rte_eth_dev_data *data = dev->data;
4178 struct rte_ether_addr *macaddr;
4183 macaddr = &(data->mac_addrs[index]);
4185 pool_sel = dev->data->mac_pool_sel[index];
4187 for (i = 0; i < sizeof(pool_sel) * CHAR_BIT; i++) {
4188 if (pool_sel & (1ULL << i)) {
4192 /* No VMDQ pool enabled or configured */
4193 if (!(pf->flags & I40E_FLAG_VMDQ) ||
4194 (i > pf->nb_cfg_vmdq_vsi)) {
4196 "No VMDQ pool enabled/configured");
4199 vsi = pf->vmdq[i - 1].vsi;
4201 ret = i40e_vsi_delete_mac(vsi, macaddr);
4204 PMD_DRV_LOG(ERR, "Failed to remove MACVLAN filter");
4211 /* Set perfect match or hash match of MAC and VLAN for a VF */
4213 i40e_vf_mac_filter_set(struct i40e_pf *pf,
4214 struct rte_eth_mac_filter *filter,
4218 struct i40e_mac_filter_info mac_filter;
4219 struct rte_ether_addr old_mac;
4220 struct rte_ether_addr *new_mac;
4221 struct i40e_pf_vf *vf = NULL;
4226 PMD_DRV_LOG(ERR, "Invalid PF argument.");
4229 hw = I40E_PF_TO_HW(pf);
4231 if (filter == NULL) {
4232 PMD_DRV_LOG(ERR, "Invalid mac filter argument.");
4236 new_mac = &filter->mac_addr;
4238 if (rte_is_zero_ether_addr(new_mac)) {
4239 PMD_DRV_LOG(ERR, "Invalid ethernet address.");
4243 vf_id = filter->dst_id;
4245 if (vf_id > pf->vf_num - 1 || !pf->vfs) {
4246 PMD_DRV_LOG(ERR, "Invalid argument.");
4249 vf = &pf->vfs[vf_id];
4251 if (add && rte_is_same_ether_addr(new_mac, &pf->dev_addr)) {
4252 PMD_DRV_LOG(INFO, "Ignore adding permanent MAC address.");
4257 rte_memcpy(&old_mac, hw->mac.addr, RTE_ETHER_ADDR_LEN);
4258 rte_memcpy(hw->mac.addr, new_mac->addr_bytes,
4259 RTE_ETHER_ADDR_LEN);
4260 rte_memcpy(&mac_filter.mac_addr, &filter->mac_addr,
4261 RTE_ETHER_ADDR_LEN);
4263 mac_filter.filter_type = filter->filter_type;
4264 ret = i40e_vsi_add_mac(vf->vsi, &mac_filter);
4265 if (ret != I40E_SUCCESS) {
4266 PMD_DRV_LOG(ERR, "Failed to add MAC filter.");
4269 rte_ether_addr_copy(new_mac, &pf->dev_addr);
4271 rte_memcpy(hw->mac.addr, hw->mac.perm_addr,
4272 RTE_ETHER_ADDR_LEN);
4273 ret = i40e_vsi_delete_mac(vf->vsi, &filter->mac_addr);
4274 if (ret != I40E_SUCCESS) {
4275 PMD_DRV_LOG(ERR, "Failed to delete MAC filter.");
4279 /* Clear device address as it has been removed */
4280 if (rte_is_same_ether_addr(&pf->dev_addr, new_mac))
4281 memset(&pf->dev_addr, 0, sizeof(struct rte_ether_addr));
4287 /* MAC filter handle */
4289 i40e_mac_filter_handle(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
4292 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4293 struct rte_eth_mac_filter *filter;
4294 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4295 int ret = I40E_NOT_SUPPORTED;
4297 filter = (struct rte_eth_mac_filter *)(arg);
4299 switch (filter_op) {
4300 case RTE_ETH_FILTER_NOP:
4303 case RTE_ETH_FILTER_ADD:
4304 i40e_pf_disable_irq0(hw);
4306 ret = i40e_vf_mac_filter_set(pf, filter, 1);
4307 i40e_pf_enable_irq0(hw);
4309 case RTE_ETH_FILTER_DELETE:
4310 i40e_pf_disable_irq0(hw);
4312 ret = i40e_vf_mac_filter_set(pf, filter, 0);
4313 i40e_pf_enable_irq0(hw);
4316 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
4317 ret = I40E_ERR_PARAM;
4325 i40e_get_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4327 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
4328 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4335 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
4336 ret = i40e_aq_get_rss_lut(hw, vsi->vsi_id,
4337 vsi->type != I40E_VSI_SRIOV,
4340 PMD_DRV_LOG(ERR, "Failed to get RSS lookup table");
4344 uint32_t *lut_dw = (uint32_t *)lut;
4345 uint16_t i, lut_size_dw = lut_size / 4;
4347 if (vsi->type == I40E_VSI_SRIOV) {
4348 for (i = 0; i <= lut_size_dw; i++) {
4349 reg = I40E_VFQF_HLUT1(i, vsi->user_param);
4350 lut_dw[i] = i40e_read_rx_ctl(hw, reg);
4353 for (i = 0; i < lut_size_dw; i++)
4354 lut_dw[i] = I40E_READ_REG(hw,
4363 i40e_set_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4372 pf = I40E_VSI_TO_PF(vsi);
4373 hw = I40E_VSI_TO_HW(vsi);
4375 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
4376 ret = i40e_aq_set_rss_lut(hw, vsi->vsi_id,
4377 vsi->type != I40E_VSI_SRIOV,
4380 PMD_DRV_LOG(ERR, "Failed to set RSS lookup table");
4384 uint32_t *lut_dw = (uint32_t *)lut;
4385 uint16_t i, lut_size_dw = lut_size / 4;
4387 if (vsi->type == I40E_VSI_SRIOV) {
4388 for (i = 0; i < lut_size_dw; i++)
4391 I40E_VFQF_HLUT1(i, vsi->user_param),
4394 for (i = 0; i < lut_size_dw; i++)
4395 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i),
4398 I40E_WRITE_FLUSH(hw);
4405 i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
4406 struct rte_eth_rss_reta_entry64 *reta_conf,
4409 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4410 uint16_t i, lut_size = pf->hash_lut_size;
4411 uint16_t idx, shift;
4415 if (reta_size != lut_size ||
4416 reta_size > ETH_RSS_RETA_SIZE_512) {
4418 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)",
4419 reta_size, lut_size);
4423 lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
4425 PMD_DRV_LOG(ERR, "No memory can be allocated");
4428 ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
4431 for (i = 0; i < reta_size; i++) {
4432 idx = i / RTE_RETA_GROUP_SIZE;
4433 shift = i % RTE_RETA_GROUP_SIZE;
4434 if (reta_conf[idx].mask & (1ULL << shift))
4435 lut[i] = reta_conf[idx].reta[shift];
4437 ret = i40e_set_rss_lut(pf->main_vsi, lut, reta_size);
4439 pf->adapter->rss_reta_updated = 1;
4448 i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
4449 struct rte_eth_rss_reta_entry64 *reta_conf,
4452 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4453 uint16_t i, lut_size = pf->hash_lut_size;
4454 uint16_t idx, shift;
4458 if (reta_size != lut_size ||
4459 reta_size > ETH_RSS_RETA_SIZE_512) {
4461 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)",
4462 reta_size, lut_size);
4466 lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
4468 PMD_DRV_LOG(ERR, "No memory can be allocated");
4472 ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
4475 for (i = 0; i < reta_size; i++) {
4476 idx = i / RTE_RETA_GROUP_SIZE;
4477 shift = i % RTE_RETA_GROUP_SIZE;
4478 if (reta_conf[idx].mask & (1ULL << shift))
4479 reta_conf[idx].reta[shift] = lut[i];
4489 * i40e_allocate_dma_mem_d - specific memory alloc for shared code (base driver)
4490 * @hw: pointer to the HW structure
4491 * @mem: pointer to mem struct to fill out
4492 * @size: size of memory requested
4493 * @alignment: what to align the allocation to
4495 enum i40e_status_code
4496 i40e_allocate_dma_mem_d(__rte_unused struct i40e_hw *hw,
4497 struct i40e_dma_mem *mem,
4501 const struct rte_memzone *mz = NULL;
4502 char z_name[RTE_MEMZONE_NAMESIZE];
4505 return I40E_ERR_PARAM;
4507 snprintf(z_name, sizeof(z_name), "i40e_dma_%"PRIu64, rte_rand());
4508 mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY,
4509 RTE_MEMZONE_IOVA_CONTIG, alignment, RTE_PGSIZE_2M);
4511 return I40E_ERR_NO_MEMORY;
4516 mem->zone = (const void *)mz;
4518 "memzone %s allocated with physical address: %"PRIu64,
4521 return I40E_SUCCESS;
4525 * i40e_free_dma_mem_d - specific memory free for shared code (base driver)
4526 * @hw: pointer to the HW structure
4527 * @mem: ptr to mem struct to free
4529 enum i40e_status_code
4530 i40e_free_dma_mem_d(__rte_unused struct i40e_hw *hw,
4531 struct i40e_dma_mem *mem)
4534 return I40E_ERR_PARAM;
4537 "memzone %s to be freed with physical address: %"PRIu64,
4538 ((const struct rte_memzone *)mem->zone)->name, mem->pa);
4539 rte_memzone_free((const struct rte_memzone *)mem->zone);
4544 return I40E_SUCCESS;
4548 * i40e_allocate_virt_mem_d - specific memory alloc for shared code (base driver)
4549 * @hw: pointer to the HW structure
4550 * @mem: pointer to mem struct to fill out
4551 * @size: size of memory requested
4553 enum i40e_status_code
4554 i40e_allocate_virt_mem_d(__rte_unused struct i40e_hw *hw,
4555 struct i40e_virt_mem *mem,
4559 return I40E_ERR_PARAM;
4562 mem->va = rte_zmalloc("i40e", size, 0);
4565 return I40E_SUCCESS;
4567 return I40E_ERR_NO_MEMORY;
4571 * i40e_free_virt_mem_d - specific memory free for shared code (base driver)
4572 * @hw: pointer to the HW structure
4573 * @mem: pointer to mem struct to free
4575 enum i40e_status_code
4576 i40e_free_virt_mem_d(__rte_unused struct i40e_hw *hw,
4577 struct i40e_virt_mem *mem)
4580 return I40E_ERR_PARAM;
4585 return I40E_SUCCESS;
4589 i40e_init_spinlock_d(struct i40e_spinlock *sp)
4591 rte_spinlock_init(&sp->spinlock);
4595 i40e_acquire_spinlock_d(struct i40e_spinlock *sp)
4597 rte_spinlock_lock(&sp->spinlock);
4601 i40e_release_spinlock_d(struct i40e_spinlock *sp)
4603 rte_spinlock_unlock(&sp->spinlock);
4607 i40e_destroy_spinlock_d(__rte_unused struct i40e_spinlock *sp)
4613 * Get the hardware capabilities, which will be parsed
4614 * and saved into struct i40e_hw.
4617 i40e_get_cap(struct i40e_hw *hw)
4619 struct i40e_aqc_list_capabilities_element_resp *buf;
4620 uint16_t len, size = 0;
4623 /* Calculate a huge enough buff for saving response data temporarily */
4624 len = sizeof(struct i40e_aqc_list_capabilities_element_resp) *
4625 I40E_MAX_CAP_ELE_NUM;
4626 buf = rte_zmalloc("i40e", len, 0);
4628 PMD_DRV_LOG(ERR, "Failed to allocate memory");
4629 return I40E_ERR_NO_MEMORY;
4632 /* Get, parse the capabilities and save it to hw */
4633 ret = i40e_aq_discover_capabilities(hw, buf, len, &size,
4634 i40e_aqc_opc_list_func_capabilities, NULL);
4635 if (ret != I40E_SUCCESS)
4636 PMD_DRV_LOG(ERR, "Failed to discover capabilities");
4638 /* Free the temporary buffer after being used */
4644 #define RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF 4
4646 static int i40e_pf_parse_vf_queue_number_handler(const char *key,
4654 pf = (struct i40e_pf *)opaque;
4658 num = strtoul(value, &end, 0);
4659 if (errno != 0 || end == value || *end != 0) {
4660 PMD_DRV_LOG(WARNING, "Wrong VF queue number = %s, Now it is "
4661 "kept the value = %hu", value, pf->vf_nb_qp_max);
4665 if (num <= I40E_MAX_QP_NUM_PER_VF && rte_is_power_of_2(num))
4666 pf->vf_nb_qp_max = (uint16_t)num;
4668 /* here return 0 to make next valid same argument work */
4669 PMD_DRV_LOG(WARNING, "Wrong VF queue number = %lu, it must be "
4670 "power of 2 and equal or less than 16 !, Now it is "
4671 "kept the value = %hu", num, pf->vf_nb_qp_max);
4676 static int i40e_pf_config_vf_rxq_number(struct rte_eth_dev *dev)
4678 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4679 struct rte_kvargs *kvlist;
4682 /* set default queue number per VF as 4 */
4683 pf->vf_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF;
4685 if (dev->device->devargs == NULL)
4688 kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
4692 kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_QUEUE_NUM_PER_VF_ARG);
4693 if (!kvargs_count) {
4694 rte_kvargs_free(kvlist);
4698 if (kvargs_count > 1)
4699 PMD_DRV_LOG(WARNING, "More than one argument \"%s\" and only "
4700 "the first invalid or last valid one is used !",
4701 ETH_I40E_QUEUE_NUM_PER_VF_ARG);
4703 rte_kvargs_process(kvlist, ETH_I40E_QUEUE_NUM_PER_VF_ARG,
4704 i40e_pf_parse_vf_queue_number_handler, pf);
4706 rte_kvargs_free(kvlist);
4712 i40e_pf_parameter_init(struct rte_eth_dev *dev)
4714 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4715 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4716 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
4717 uint16_t qp_count = 0, vsi_count = 0;
4719 if (pci_dev->max_vfs && !hw->func_caps.sr_iov_1_1) {
4720 PMD_INIT_LOG(ERR, "HW configuration doesn't support SRIOV");
4724 i40e_pf_config_vf_rxq_number(dev);
4726 /* Add the parameter init for LFC */
4727 pf->fc_conf.pause_time = I40E_DEFAULT_PAUSE_TIME;
4728 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_HIGH_WATER;
4729 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_LOW_WATER;
4731 pf->flags = I40E_FLAG_HEADER_SPLIT_DISABLED;
4732 pf->max_num_vsi = hw->func_caps.num_vsis;
4733 pf->lan_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_PF;
4734 pf->vmdq_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
4736 /* FDir queue/VSI allocation */
4737 pf->fdir_qp_offset = 0;
4738 if (hw->func_caps.fd) {
4739 pf->flags |= I40E_FLAG_FDIR;
4740 pf->fdir_nb_qps = I40E_DEFAULT_QP_NUM_FDIR;
4742 pf->fdir_nb_qps = 0;
4744 qp_count += pf->fdir_nb_qps;
4747 /* LAN queue/VSI allocation */
4748 pf->lan_qp_offset = pf->fdir_qp_offset + pf->fdir_nb_qps;
4749 if (!hw->func_caps.rss) {
4752 pf->flags |= I40E_FLAG_RSS;
4753 if (hw->mac.type == I40E_MAC_X722)
4754 pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE;
4755 pf->lan_nb_qps = pf->lan_nb_qp_max;
4757 qp_count += pf->lan_nb_qps;
4760 /* VF queue/VSI allocation */
4761 pf->vf_qp_offset = pf->lan_qp_offset + pf->lan_nb_qps;
4762 if (hw->func_caps.sr_iov_1_1 && pci_dev->max_vfs) {
4763 pf->flags |= I40E_FLAG_SRIOV;
4764 pf->vf_nb_qps = pf->vf_nb_qp_max;
4765 pf->vf_num = pci_dev->max_vfs;
4767 "%u VF VSIs, %u queues per VF VSI, in total %u queues",
4768 pf->vf_num, pf->vf_nb_qps, pf->vf_nb_qps * pf->vf_num);
4773 qp_count += pf->vf_nb_qps * pf->vf_num;
4774 vsi_count += pf->vf_num;
4776 /* VMDq queue/VSI allocation */
4777 pf->vmdq_qp_offset = pf->vf_qp_offset + pf->vf_nb_qps * pf->vf_num;
4778 pf->vmdq_nb_qps = 0;
4779 pf->max_nb_vmdq_vsi = 0;
4780 if (hw->func_caps.vmdq) {
4781 if (qp_count < hw->func_caps.num_tx_qp &&
4782 vsi_count < hw->func_caps.num_vsis) {
4783 pf->max_nb_vmdq_vsi = (hw->func_caps.num_tx_qp -
4784 qp_count) / pf->vmdq_nb_qp_max;
4786 /* Limit the maximum number of VMDq vsi to the maximum
4787 * ethdev can support
4789 pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
4790 hw->func_caps.num_vsis - vsi_count);
4791 pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
4793 if (pf->max_nb_vmdq_vsi) {
4794 pf->flags |= I40E_FLAG_VMDQ;
4795 pf->vmdq_nb_qps = pf->vmdq_nb_qp_max;
4797 "%u VMDQ VSIs, %u queues per VMDQ VSI, in total %u queues",
4798 pf->max_nb_vmdq_vsi, pf->vmdq_nb_qps,
4799 pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi);
4802 "No enough queues left for VMDq");
4805 PMD_DRV_LOG(INFO, "No queue or VSI left for VMDq");
4808 qp_count += pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi;
4809 vsi_count += pf->max_nb_vmdq_vsi;
4811 if (hw->func_caps.dcb)
4812 pf->flags |= I40E_FLAG_DCB;
4814 if (qp_count > hw->func_caps.num_tx_qp) {
4816 "Failed to allocate %u queues, which exceeds the hardware maximum %u",
4817 qp_count, hw->func_caps.num_tx_qp);
4820 if (vsi_count > hw->func_caps.num_vsis) {
4822 "Failed to allocate %u VSIs, which exceeds the hardware maximum %u",
4823 vsi_count, hw->func_caps.num_vsis);
4831 i40e_pf_get_switch_config(struct i40e_pf *pf)
4833 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4834 struct i40e_aqc_get_switch_config_resp *switch_config;
4835 struct i40e_aqc_switch_config_element_resp *element;
4836 uint16_t start_seid = 0, num_reported;
4839 switch_config = (struct i40e_aqc_get_switch_config_resp *)\
4840 rte_zmalloc("i40e", I40E_AQ_LARGE_BUF, 0);
4841 if (!switch_config) {
4842 PMD_DRV_LOG(ERR, "Failed to allocated memory");
4846 /* Get the switch configurations */
4847 ret = i40e_aq_get_switch_config(hw, switch_config,
4848 I40E_AQ_LARGE_BUF, &start_seid, NULL);
4849 if (ret != I40E_SUCCESS) {
4850 PMD_DRV_LOG(ERR, "Failed to get switch configurations");
4853 num_reported = rte_le_to_cpu_16(switch_config->header.num_reported);
4854 if (num_reported != 1) { /* The number should be 1 */
4855 PMD_DRV_LOG(ERR, "Wrong number of switch config reported");
4859 /* Parse the switch configuration elements */
4860 element = &(switch_config->element[0]);
4861 if (element->element_type == I40E_SWITCH_ELEMENT_TYPE_VSI) {
4862 pf->mac_seid = rte_le_to_cpu_16(element->uplink_seid);
4863 pf->main_vsi_seid = rte_le_to_cpu_16(element->seid);
4865 PMD_DRV_LOG(INFO, "Unknown element type");
4868 rte_free(switch_config);
4874 i40e_res_pool_init (struct i40e_res_pool_info *pool, uint32_t base,
4877 struct pool_entry *entry;
4879 if (pool == NULL || num == 0)
4882 entry = rte_zmalloc("i40e", sizeof(*entry), 0);
4883 if (entry == NULL) {
4884 PMD_DRV_LOG(ERR, "Failed to allocate memory for resource pool");
4888 /* queue heap initialize */
4889 pool->num_free = num;
4890 pool->num_alloc = 0;
4892 LIST_INIT(&pool->alloc_list);
4893 LIST_INIT(&pool->free_list);
4895 /* Initialize element */
4899 LIST_INSERT_HEAD(&pool->free_list, entry, next);
4904 i40e_res_pool_destroy(struct i40e_res_pool_info *pool)
4906 struct pool_entry *entry, *next_entry;
4911 for (entry = LIST_FIRST(&pool->alloc_list);
4912 entry && (next_entry = LIST_NEXT(entry, next), 1);
4913 entry = next_entry) {
4914 LIST_REMOVE(entry, next);
4918 for (entry = LIST_FIRST(&pool->free_list);
4919 entry && (next_entry = LIST_NEXT(entry, next), 1);
4920 entry = next_entry) {
4921 LIST_REMOVE(entry, next);
4926 pool->num_alloc = 0;
4928 LIST_INIT(&pool->alloc_list);
4929 LIST_INIT(&pool->free_list);
4933 i40e_res_pool_free(struct i40e_res_pool_info *pool,
4936 struct pool_entry *entry, *next, *prev, *valid_entry = NULL;
4937 uint32_t pool_offset;
4941 PMD_DRV_LOG(ERR, "Invalid parameter");
4945 pool_offset = base - pool->base;
4946 /* Lookup in alloc list */
4947 LIST_FOREACH(entry, &pool->alloc_list, next) {
4948 if (entry->base == pool_offset) {
4949 valid_entry = entry;
4950 LIST_REMOVE(entry, next);
4955 /* Not find, return */
4956 if (valid_entry == NULL) {
4957 PMD_DRV_LOG(ERR, "Failed to find entry");
4962 * Found it, move it to free list and try to merge.
4963 * In order to make merge easier, always sort it by qbase.
4964 * Find adjacent prev and last entries.
4967 LIST_FOREACH(entry, &pool->free_list, next) {
4968 if (entry->base > valid_entry->base) {
4976 /* Try to merge with next one*/
4978 /* Merge with next one */
4979 if (valid_entry->base + valid_entry->len == next->base) {
4980 next->base = valid_entry->base;
4981 next->len += valid_entry->len;
4982 rte_free(valid_entry);
4989 /* Merge with previous one */
4990 if (prev->base + prev->len == valid_entry->base) {
4991 prev->len += valid_entry->len;
4992 /* If it merge with next one, remove next node */
4994 LIST_REMOVE(valid_entry, next);
4995 rte_free(valid_entry);
4997 rte_free(valid_entry);
5003 /* Not find any entry to merge, insert */
5006 LIST_INSERT_AFTER(prev, valid_entry, next);
5007 else if (next != NULL)
5008 LIST_INSERT_BEFORE(next, valid_entry, next);
5009 else /* It's empty list, insert to head */
5010 LIST_INSERT_HEAD(&pool->free_list, valid_entry, next);
5013 pool->num_free += valid_entry->len;
5014 pool->num_alloc -= valid_entry->len;
5020 i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
5023 struct pool_entry *entry, *valid_entry;
5025 if (pool == NULL || num == 0) {
5026 PMD_DRV_LOG(ERR, "Invalid parameter");
5030 if (pool->num_free < num) {
5031 PMD_DRV_LOG(ERR, "No resource. ask:%u, available:%u",
5032 num, pool->num_free);
5037 /* Lookup in free list and find most fit one */
5038 LIST_FOREACH(entry, &pool->free_list, next) {
5039 if (entry->len >= num) {
5041 if (entry->len == num) {
5042 valid_entry = entry;
5045 if (valid_entry == NULL || valid_entry->len > entry->len)
5046 valid_entry = entry;
5050 /* Not find one to satisfy the request, return */
5051 if (valid_entry == NULL) {
5052 PMD_DRV_LOG(ERR, "No valid entry found");
5056 * The entry have equal queue number as requested,
5057 * remove it from alloc_list.
5059 if (valid_entry->len == num) {
5060 LIST_REMOVE(valid_entry, next);
5063 * The entry have more numbers than requested,
5064 * create a new entry for alloc_list and minus its
5065 * queue base and number in free_list.
5067 entry = rte_zmalloc("res_pool", sizeof(*entry), 0);
5068 if (entry == NULL) {
5070 "Failed to allocate memory for resource pool");
5073 entry->base = valid_entry->base;
5075 valid_entry->base += num;
5076 valid_entry->len -= num;
5077 valid_entry = entry;
5080 /* Insert it into alloc list, not sorted */
5081 LIST_INSERT_HEAD(&pool->alloc_list, valid_entry, next);
5083 pool->num_free -= valid_entry->len;
5084 pool->num_alloc += valid_entry->len;
5086 return valid_entry->base + pool->base;
5090 * bitmap_is_subset - Check whether src2 is subset of src1
5093 bitmap_is_subset(uint8_t src1, uint8_t src2)
5095 return !((src1 ^ src2) & src2);
5098 static enum i40e_status_code
5099 validate_tcmap_parameter(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
5101 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5103 /* If DCB is not supported, only default TC is supported */
5104 if (!hw->func_caps.dcb && enabled_tcmap != I40E_DEFAULT_TCMAP) {
5105 PMD_DRV_LOG(ERR, "DCB is not enabled, only TC0 is supported");
5106 return I40E_NOT_SUPPORTED;
5109 if (!bitmap_is_subset(hw->func_caps.enabled_tcmap, enabled_tcmap)) {
5111 "Enabled TC map 0x%x not applicable to HW support 0x%x",
5112 hw->func_caps.enabled_tcmap, enabled_tcmap);
5113 return I40E_NOT_SUPPORTED;
5115 return I40E_SUCCESS;
5119 i40e_vsi_vlan_pvid_set(struct i40e_vsi *vsi,
5120 struct i40e_vsi_vlan_pvid_info *info)
5123 struct i40e_vsi_context ctxt;
5124 uint8_t vlan_flags = 0;
5127 if (vsi == NULL || info == NULL) {
5128 PMD_DRV_LOG(ERR, "invalid parameters");
5129 return I40E_ERR_PARAM;
5133 vsi->info.pvid = info->config.pvid;
5135 * If insert pvid is enabled, only tagged pkts are
5136 * allowed to be sent out.
5138 vlan_flags |= I40E_AQ_VSI_PVLAN_INSERT_PVID |
5139 I40E_AQ_VSI_PVLAN_MODE_TAGGED;
5142 if (info->config.reject.tagged == 0)
5143 vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_TAGGED;
5145 if (info->config.reject.untagged == 0)
5146 vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_UNTAGGED;
5148 vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_INSERT_PVID |
5149 I40E_AQ_VSI_PVLAN_MODE_MASK);
5150 vsi->info.port_vlan_flags |= vlan_flags;
5151 vsi->info.valid_sections =
5152 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5153 memset(&ctxt, 0, sizeof(ctxt));
5154 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
5155 ctxt.seid = vsi->seid;
5157 hw = I40E_VSI_TO_HW(vsi);
5158 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5159 if (ret != I40E_SUCCESS)
5160 PMD_DRV_LOG(ERR, "Failed to update VSI params");
5166 i40e_vsi_update_tc_bandwidth(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
5168 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5170 struct i40e_aqc_configure_vsi_tc_bw_data tc_bw_data;
5172 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
5173 if (ret != I40E_SUCCESS)
5177 PMD_DRV_LOG(ERR, "seid not valid");
5181 memset(&tc_bw_data, 0, sizeof(tc_bw_data));
5182 tc_bw_data.tc_valid_bits = enabled_tcmap;
5183 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5184 tc_bw_data.tc_bw_credits[i] =
5185 (enabled_tcmap & (1 << i)) ? 1 : 0;
5187 ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &tc_bw_data, NULL);
5188 if (ret != I40E_SUCCESS) {
5189 PMD_DRV_LOG(ERR, "Failed to configure TC BW");
5193 rte_memcpy(vsi->info.qs_handle, tc_bw_data.qs_handles,
5194 sizeof(vsi->info.qs_handle));
5195 return I40E_SUCCESS;
5198 static enum i40e_status_code
5199 i40e_vsi_config_tc_queue_mapping(struct i40e_vsi *vsi,
5200 struct i40e_aqc_vsi_properties_data *info,
5201 uint8_t enabled_tcmap)
5203 enum i40e_status_code ret;
5204 int i, total_tc = 0;
5205 uint16_t qpnum_per_tc, bsf, qp_idx;
5207 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
5208 if (ret != I40E_SUCCESS)
5211 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5212 if (enabled_tcmap & (1 << i))
5216 vsi->enabled_tc = enabled_tcmap;
5218 /* Number of queues per enabled TC */
5219 qpnum_per_tc = i40e_align_floor(vsi->nb_qps / total_tc);
5220 qpnum_per_tc = RTE_MIN(qpnum_per_tc, I40E_MAX_Q_PER_TC);
5221 bsf = rte_bsf32(qpnum_per_tc);
5223 /* Adjust the queue number to actual queues that can be applied */
5224 if (!(vsi->type == I40E_VSI_MAIN && total_tc == 1))
5225 vsi->nb_qps = qpnum_per_tc * total_tc;
5228 * Configure TC and queue mapping parameters, for enabled TC,
5229 * allocate qpnum_per_tc queues to this traffic. For disabled TC,
5230 * default queue will serve it.
5233 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5234 if (vsi->enabled_tc & (1 << i)) {
5235 info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
5236 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
5237 (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
5238 qp_idx += qpnum_per_tc;
5240 info->tc_mapping[i] = 0;
5243 /* Associate queue number with VSI */
5244 if (vsi->type == I40E_VSI_SRIOV) {
5245 info->mapping_flags |=
5246 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
5247 for (i = 0; i < vsi->nb_qps; i++)
5248 info->queue_mapping[i] =
5249 rte_cpu_to_le_16(vsi->base_queue + i);
5251 info->mapping_flags |=
5252 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
5253 info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
5255 info->valid_sections |=
5256 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
5258 return I40E_SUCCESS;
5262 i40e_veb_release(struct i40e_veb *veb)
5264 struct i40e_vsi *vsi;
5270 if (!TAILQ_EMPTY(&veb->head)) {
5271 PMD_DRV_LOG(ERR, "VEB still has VSI attached, can't remove");
5274 /* associate_vsi field is NULL for floating VEB */
5275 if (veb->associate_vsi != NULL) {
5276 vsi = veb->associate_vsi;
5277 hw = I40E_VSI_TO_HW(vsi);
5279 vsi->uplink_seid = veb->uplink_seid;
5282 veb->associate_pf->main_vsi->floating_veb = NULL;
5283 hw = I40E_VSI_TO_HW(veb->associate_pf->main_vsi);
5286 i40e_aq_delete_element(hw, veb->seid, NULL);
5288 return I40E_SUCCESS;
5292 static struct i40e_veb *
5293 i40e_veb_setup(struct i40e_pf *pf, struct i40e_vsi *vsi)
5295 struct i40e_veb *veb;
5301 "veb setup failed, associated PF shouldn't null");
5304 hw = I40E_PF_TO_HW(pf);
5306 veb = rte_zmalloc("i40e_veb", sizeof(struct i40e_veb), 0);
5308 PMD_DRV_LOG(ERR, "Failed to allocate memory for veb");
5312 veb->associate_vsi = vsi;
5313 veb->associate_pf = pf;
5314 TAILQ_INIT(&veb->head);
5315 veb->uplink_seid = vsi ? vsi->uplink_seid : 0;
5317 /* create floating veb if vsi is NULL */
5319 ret = i40e_aq_add_veb(hw, veb->uplink_seid, vsi->seid,
5320 I40E_DEFAULT_TCMAP, false,
5321 &veb->seid, false, NULL);
5323 ret = i40e_aq_add_veb(hw, 0, 0, I40E_DEFAULT_TCMAP,
5324 true, &veb->seid, false, NULL);
5327 if (ret != I40E_SUCCESS) {
5328 PMD_DRV_LOG(ERR, "Add veb failed, aq_err: %d",
5329 hw->aq.asq_last_status);
5332 veb->enabled_tc = I40E_DEFAULT_TCMAP;
5334 /* get statistics index */
5335 ret = i40e_aq_get_veb_parameters(hw, veb->seid, NULL, NULL,
5336 &veb->stats_idx, NULL, NULL, NULL);
5337 if (ret != I40E_SUCCESS) {
5338 PMD_DRV_LOG(ERR, "Get veb statistics index failed, aq_err: %d",
5339 hw->aq.asq_last_status);
5342 /* Get VEB bandwidth, to be implemented */
5343 /* Now associated vsi binding to the VEB, set uplink to this VEB */
5345 vsi->uplink_seid = veb->seid;
5354 i40e_vsi_release(struct i40e_vsi *vsi)
5358 struct i40e_vsi_list *vsi_list;
5361 struct i40e_mac_filter *f;
5362 uint16_t user_param;
5365 return I40E_SUCCESS;
5370 user_param = vsi->user_param;
5372 pf = I40E_VSI_TO_PF(vsi);
5373 hw = I40E_VSI_TO_HW(vsi);
5375 /* VSI has child to attach, release child first */
5377 TAILQ_FOREACH_SAFE(vsi_list, &vsi->veb->head, list, temp) {
5378 if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
5381 i40e_veb_release(vsi->veb);
5384 if (vsi->floating_veb) {
5385 TAILQ_FOREACH_SAFE(vsi_list, &vsi->floating_veb->head, list, temp) {
5386 if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
5391 /* Remove all macvlan filters of the VSI */
5392 i40e_vsi_remove_all_macvlan_filter(vsi);
5393 TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp)
5396 if (vsi->type != I40E_VSI_MAIN &&
5397 ((vsi->type != I40E_VSI_SRIOV) ||
5398 !pf->floating_veb_list[user_param])) {
5399 /* Remove vsi from parent's sibling list */
5400 if (vsi->parent_vsi == NULL || vsi->parent_vsi->veb == NULL) {
5401 PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
5402 return I40E_ERR_PARAM;
5404 TAILQ_REMOVE(&vsi->parent_vsi->veb->head,
5405 &vsi->sib_vsi_list, list);
5407 /* Remove all switch element of the VSI */
5408 ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
5409 if (ret != I40E_SUCCESS)
5410 PMD_DRV_LOG(ERR, "Failed to delete element");
5413 if ((vsi->type == I40E_VSI_SRIOV) &&
5414 pf->floating_veb_list[user_param]) {
5415 /* Remove vsi from parent's sibling list */
5416 if (vsi->parent_vsi == NULL ||
5417 vsi->parent_vsi->floating_veb == NULL) {
5418 PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
5419 return I40E_ERR_PARAM;
5421 TAILQ_REMOVE(&vsi->parent_vsi->floating_veb->head,
5422 &vsi->sib_vsi_list, list);
5424 /* Remove all switch element of the VSI */
5425 ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
5426 if (ret != I40E_SUCCESS)
5427 PMD_DRV_LOG(ERR, "Failed to delete element");
5430 i40e_res_pool_free(&pf->qp_pool, vsi->base_queue);
5432 if (vsi->type != I40E_VSI_SRIOV)
5433 i40e_res_pool_free(&pf->msix_pool, vsi->msix_intr);
5436 return I40E_SUCCESS;
5440 i40e_update_default_filter_setting(struct i40e_vsi *vsi)
5442 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5443 struct i40e_aqc_remove_macvlan_element_data def_filter;
5444 struct i40e_mac_filter_info filter;
5447 if (vsi->type != I40E_VSI_MAIN)
5448 return I40E_ERR_CONFIG;
5449 memset(&def_filter, 0, sizeof(def_filter));
5450 rte_memcpy(def_filter.mac_addr, hw->mac.perm_addr,
5452 def_filter.vlan_tag = 0;
5453 def_filter.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
5454 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
5455 ret = i40e_aq_remove_macvlan(hw, vsi->seid, &def_filter, 1, NULL);
5456 if (ret != I40E_SUCCESS) {
5457 struct i40e_mac_filter *f;
5458 struct rte_ether_addr *mac;
5461 "Cannot remove the default macvlan filter");
5462 /* It needs to add the permanent mac into mac list */
5463 f = rte_zmalloc("macv_filter", sizeof(*f), 0);
5465 PMD_DRV_LOG(ERR, "failed to allocate memory");
5466 return I40E_ERR_NO_MEMORY;
5468 mac = &f->mac_info.mac_addr;
5469 rte_memcpy(&mac->addr_bytes, hw->mac.perm_addr,
5471 f->mac_info.filter_type = RTE_MACVLAN_PERFECT_MATCH;
5472 TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
5477 rte_memcpy(&filter.mac_addr,
5478 (struct rte_ether_addr *)(hw->mac.perm_addr), ETH_ADDR_LEN);
5479 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
5480 return i40e_vsi_add_mac(vsi, &filter);
5484 * i40e_vsi_get_bw_config - Query VSI BW Information
5485 * @vsi: the VSI to be queried
5487 * Returns 0 on success, negative value on failure
5489 static enum i40e_status_code
5490 i40e_vsi_get_bw_config(struct i40e_vsi *vsi)
5492 struct i40e_aqc_query_vsi_bw_config_resp bw_config;
5493 struct i40e_aqc_query_vsi_ets_sla_config_resp ets_sla_config;
5494 struct i40e_hw *hw = &vsi->adapter->hw;
5499 memset(&bw_config, 0, sizeof(bw_config));
5500 ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
5501 if (ret != I40E_SUCCESS) {
5502 PMD_DRV_LOG(ERR, "VSI failed to get bandwidth configuration %u",
5503 hw->aq.asq_last_status);
5507 memset(&ets_sla_config, 0, sizeof(ets_sla_config));
5508 ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid,
5509 &ets_sla_config, NULL);
5510 if (ret != I40E_SUCCESS) {
5512 "VSI failed to get TC bandwdith configuration %u",
5513 hw->aq.asq_last_status);
5517 /* store and print out BW info */
5518 vsi->bw_info.bw_limit = rte_le_to_cpu_16(bw_config.port_bw_limit);
5519 vsi->bw_info.bw_max = bw_config.max_bw;
5520 PMD_DRV_LOG(DEBUG, "VSI bw limit:%u", vsi->bw_info.bw_limit);
5521 PMD_DRV_LOG(DEBUG, "VSI max_bw:%u", vsi->bw_info.bw_max);
5522 bw_max = rte_le_to_cpu_16(ets_sla_config.tc_bw_max[0]) |
5523 (rte_le_to_cpu_16(ets_sla_config.tc_bw_max[1]) <<
5525 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5526 vsi->bw_info.bw_ets_share_credits[i] =
5527 ets_sla_config.share_credits[i];
5528 vsi->bw_info.bw_ets_credits[i] =
5529 rte_le_to_cpu_16(ets_sla_config.credits[i]);
5530 /* 4 bits per TC, 4th bit is reserved */
5531 vsi->bw_info.bw_ets_max[i] =
5532 (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
5533 RTE_LEN2MASK(3, uint8_t));
5534 PMD_DRV_LOG(DEBUG, "\tVSI TC%u:share credits %u", i,
5535 vsi->bw_info.bw_ets_share_credits[i]);
5536 PMD_DRV_LOG(DEBUG, "\tVSI TC%u:credits %u", i,
5537 vsi->bw_info.bw_ets_credits[i]);
5538 PMD_DRV_LOG(DEBUG, "\tVSI TC%u: max credits: %u", i,
5539 vsi->bw_info.bw_ets_max[i]);
5542 return I40E_SUCCESS;
5545 /* i40e_enable_pf_lb
5546 * @pf: pointer to the pf structure
5548 * allow loopback on pf
5551 i40e_enable_pf_lb(struct i40e_pf *pf)
5553 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5554 struct i40e_vsi_context ctxt;
5557 /* Use the FW API if FW >= v5.0 */
5558 if (hw->aq.fw_maj_ver < 5 && hw->mac.type != I40E_MAC_X722) {
5559 PMD_INIT_LOG(ERR, "FW < v5.0, cannot enable loopback");
5563 memset(&ctxt, 0, sizeof(ctxt));
5564 ctxt.seid = pf->main_vsi_seid;
5565 ctxt.pf_num = hw->pf_id;
5566 ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5568 PMD_DRV_LOG(ERR, "cannot get pf vsi config, err %d, aq_err %d",
5569 ret, hw->aq.asq_last_status);
5572 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
5573 ctxt.info.valid_sections =
5574 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5575 ctxt.info.switch_id |=
5576 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5578 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5580 PMD_DRV_LOG(ERR, "update vsi switch failed, aq_err=%d",
5581 hw->aq.asq_last_status);
5586 i40e_vsi_setup(struct i40e_pf *pf,
5587 enum i40e_vsi_type type,
5588 struct i40e_vsi *uplink_vsi,
5589 uint16_t user_param)
5591 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5592 struct i40e_vsi *vsi;
5593 struct i40e_mac_filter_info filter;
5595 struct i40e_vsi_context ctxt;
5596 struct rte_ether_addr broadcast =
5597 {.addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
5599 if (type != I40E_VSI_MAIN && type != I40E_VSI_SRIOV &&
5600 uplink_vsi == NULL) {
5602 "VSI setup failed, VSI link shouldn't be NULL");
5606 if (type == I40E_VSI_MAIN && uplink_vsi != NULL) {
5608 "VSI setup failed, MAIN VSI uplink VSI should be NULL");
5613 * 1.type is not MAIN and uplink vsi is not NULL
5614 * If uplink vsi didn't setup VEB, create one first under veb field
5615 * 2.type is SRIOV and the uplink is NULL
5616 * If floating VEB is NULL, create one veb under floating veb field
5619 if (type != I40E_VSI_MAIN && uplink_vsi != NULL &&
5620 uplink_vsi->veb == NULL) {
5621 uplink_vsi->veb = i40e_veb_setup(pf, uplink_vsi);
5623 if (uplink_vsi->veb == NULL) {
5624 PMD_DRV_LOG(ERR, "VEB setup failed");
5627 /* set ALLOWLOOPBACk on pf, when veb is created */
5628 i40e_enable_pf_lb(pf);
5631 if (type == I40E_VSI_SRIOV && uplink_vsi == NULL &&
5632 pf->main_vsi->floating_veb == NULL) {
5633 pf->main_vsi->floating_veb = i40e_veb_setup(pf, uplink_vsi);
5635 if (pf->main_vsi->floating_veb == NULL) {
5636 PMD_DRV_LOG(ERR, "VEB setup failed");
5641 vsi = rte_zmalloc("i40e_vsi", sizeof(struct i40e_vsi), 0);
5643 PMD_DRV_LOG(ERR, "Failed to allocate memory for vsi");
5646 TAILQ_INIT(&vsi->mac_list);
5648 vsi->adapter = I40E_PF_TO_ADAPTER(pf);
5649 vsi->max_macaddrs = I40E_NUM_MACADDR_MAX;
5650 vsi->parent_vsi = uplink_vsi ? uplink_vsi : pf->main_vsi;
5651 vsi->user_param = user_param;
5652 vsi->vlan_anti_spoof_on = 0;
5653 vsi->vlan_filter_on = 0;
5654 /* Allocate queues */
5655 switch (vsi->type) {
5656 case I40E_VSI_MAIN :
5657 vsi->nb_qps = pf->lan_nb_qps;
5659 case I40E_VSI_SRIOV :
5660 vsi->nb_qps = pf->vf_nb_qps;
5662 case I40E_VSI_VMDQ2:
5663 vsi->nb_qps = pf->vmdq_nb_qps;
5666 vsi->nb_qps = pf->fdir_nb_qps;
5672 * The filter status descriptor is reported in rx queue 0,
5673 * while the tx queue for fdir filter programming has no
5674 * such constraints, can be non-zero queues.
5675 * To simplify it, choose FDIR vsi use queue 0 pair.
5676 * To make sure it will use queue 0 pair, queue allocation
5677 * need be done before this function is called
5679 if (type != I40E_VSI_FDIR) {
5680 ret = i40e_res_pool_alloc(&pf->qp_pool, vsi->nb_qps);
5682 PMD_DRV_LOG(ERR, "VSI %d allocate queue failed %d",
5686 vsi->base_queue = ret;
5688 vsi->base_queue = I40E_FDIR_QUEUE_ID;
5690 /* VF has MSIX interrupt in VF range, don't allocate here */
5691 if (type == I40E_VSI_MAIN) {
5692 if (pf->support_multi_driver) {
5693 /* If support multi-driver, need to use INT0 instead of
5694 * allocating from msix pool. The Msix pool is init from
5695 * INT1, so it's OK just set msix_intr to 0 and nb_msix
5696 * to 1 without calling i40e_res_pool_alloc.
5701 ret = i40e_res_pool_alloc(&pf->msix_pool,
5702 RTE_MIN(vsi->nb_qps,
5703 RTE_MAX_RXTX_INTR_VEC_ID));
5706 "VSI MAIN %d get heap failed %d",
5708 goto fail_queue_alloc;
5710 vsi->msix_intr = ret;
5711 vsi->nb_msix = RTE_MIN(vsi->nb_qps,
5712 RTE_MAX_RXTX_INTR_VEC_ID);
5714 } else if (type != I40E_VSI_SRIOV) {
5715 ret = i40e_res_pool_alloc(&pf->msix_pool, 1);
5717 PMD_DRV_LOG(ERR, "VSI %d get heap failed %d", vsi->seid, ret);
5718 goto fail_queue_alloc;
5720 vsi->msix_intr = ret;
5728 if (type == I40E_VSI_MAIN) {
5729 /* For main VSI, no need to add since it's default one */
5730 vsi->uplink_seid = pf->mac_seid;
5731 vsi->seid = pf->main_vsi_seid;
5732 /* Bind queues with specific MSIX interrupt */
5734 * Needs 2 interrupt at least, one for misc cause which will
5735 * enabled from OS side, Another for queues binding the
5736 * interrupt from device side only.
5739 /* Get default VSI parameters from hardware */
5740 memset(&ctxt, 0, sizeof(ctxt));
5741 ctxt.seid = vsi->seid;
5742 ctxt.pf_num = hw->pf_id;
5743 ctxt.uplink_seid = vsi->uplink_seid;
5745 ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5746 if (ret != I40E_SUCCESS) {
5747 PMD_DRV_LOG(ERR, "Failed to get VSI params");
5748 goto fail_msix_alloc;
5750 rte_memcpy(&vsi->info, &ctxt.info,
5751 sizeof(struct i40e_aqc_vsi_properties_data));
5752 vsi->vsi_id = ctxt.vsi_number;
5753 vsi->info.valid_sections = 0;
5755 /* Configure tc, enabled TC0 only */
5756 if (i40e_vsi_update_tc_bandwidth(vsi, I40E_DEFAULT_TCMAP) !=
5758 PMD_DRV_LOG(ERR, "Failed to update TC bandwidth");
5759 goto fail_msix_alloc;
5762 /* TC, queue mapping */
5763 memset(&ctxt, 0, sizeof(ctxt));
5764 vsi->info.valid_sections |=
5765 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5766 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
5767 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
5768 rte_memcpy(&ctxt.info, &vsi->info,
5769 sizeof(struct i40e_aqc_vsi_properties_data));
5770 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
5771 I40E_DEFAULT_TCMAP);
5772 if (ret != I40E_SUCCESS) {
5774 "Failed to configure TC queue mapping");
5775 goto fail_msix_alloc;
5777 ctxt.seid = vsi->seid;
5778 ctxt.pf_num = hw->pf_id;
5779 ctxt.uplink_seid = vsi->uplink_seid;
5782 /* Update VSI parameters */
5783 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5784 if (ret != I40E_SUCCESS) {
5785 PMD_DRV_LOG(ERR, "Failed to update VSI params");
5786 goto fail_msix_alloc;
5789 rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
5790 sizeof(vsi->info.tc_mapping));
5791 rte_memcpy(&vsi->info.queue_mapping,
5792 &ctxt.info.queue_mapping,
5793 sizeof(vsi->info.queue_mapping));
5794 vsi->info.mapping_flags = ctxt.info.mapping_flags;
5795 vsi->info.valid_sections = 0;
5797 rte_memcpy(pf->dev_addr.addr_bytes, hw->mac.perm_addr,
5801 * Updating default filter settings are necessary to prevent
5802 * reception of tagged packets.
5803 * Some old firmware configurations load a default macvlan
5804 * filter which accepts both tagged and untagged packets.
5805 * The updating is to use a normal filter instead if needed.
5806 * For NVM 4.2.2 or after, the updating is not needed anymore.
5807 * The firmware with correct configurations load the default
5808 * macvlan filter which is expected and cannot be removed.
5810 i40e_update_default_filter_setting(vsi);
5811 i40e_config_qinq(hw, vsi);
5812 } else if (type == I40E_VSI_SRIOV) {
5813 memset(&ctxt, 0, sizeof(ctxt));
5815 * For other VSI, the uplink_seid equals to uplink VSI's
5816 * uplink_seid since they share same VEB
5818 if (uplink_vsi == NULL)
5819 vsi->uplink_seid = pf->main_vsi->floating_veb->seid;
5821 vsi->uplink_seid = uplink_vsi->uplink_seid;
5822 ctxt.pf_num = hw->pf_id;
5823 ctxt.vf_num = hw->func_caps.vf_base_id + user_param;
5824 ctxt.uplink_seid = vsi->uplink_seid;
5825 ctxt.connection_type = 0x1;
5826 ctxt.flags = I40E_AQ_VSI_TYPE_VF;
5828 /* Use the VEB configuration if FW >= v5.0 */
5829 if (hw->aq.fw_maj_ver >= 5 || hw->mac.type == I40E_MAC_X722) {
5830 /* Configure switch ID */
5831 ctxt.info.valid_sections |=
5832 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5833 ctxt.info.switch_id =
5834 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5837 /* Configure port/vlan */
5838 ctxt.info.valid_sections |=
5839 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5840 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
5841 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
5842 hw->func_caps.enabled_tcmap);
5843 if (ret != I40E_SUCCESS) {
5845 "Failed to configure TC queue mapping");
5846 goto fail_msix_alloc;
5849 ctxt.info.up_enable_bits = hw->func_caps.enabled_tcmap;
5850 ctxt.info.valid_sections |=
5851 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
5853 * Since VSI is not created yet, only configure parameter,
5854 * will add vsi below.
5857 i40e_config_qinq(hw, vsi);
5858 } else if (type == I40E_VSI_VMDQ2) {
5859 memset(&ctxt, 0, sizeof(ctxt));
5861 * For other VSI, the uplink_seid equals to uplink VSI's
5862 * uplink_seid since they share same VEB
5864 vsi->uplink_seid = uplink_vsi->uplink_seid;
5865 ctxt.pf_num = hw->pf_id;
5867 ctxt.uplink_seid = vsi->uplink_seid;
5868 ctxt.connection_type = 0x1;
5869 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
5871 ctxt.info.valid_sections |=
5872 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5873 /* user_param carries flag to enable loop back */
5875 ctxt.info.switch_id =
5876 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
5877 ctxt.info.switch_id |=
5878 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5881 /* Configure port/vlan */
5882 ctxt.info.valid_sections |=
5883 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5884 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
5885 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
5886 I40E_DEFAULT_TCMAP);
5887 if (ret != I40E_SUCCESS) {
5889 "Failed to configure TC queue mapping");
5890 goto fail_msix_alloc;
5892 ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
5893 ctxt.info.valid_sections |=
5894 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
5895 } else if (type == I40E_VSI_FDIR) {
5896 memset(&ctxt, 0, sizeof(ctxt));
5897 vsi->uplink_seid = uplink_vsi->uplink_seid;
5898 ctxt.pf_num = hw->pf_id;
5900 ctxt.uplink_seid = vsi->uplink_seid;
5901 ctxt.connection_type = 0x1; /* regular data port */
5902 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
5903 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
5904 I40E_DEFAULT_TCMAP);
5905 if (ret != I40E_SUCCESS) {
5907 "Failed to configure TC queue mapping.");
5908 goto fail_msix_alloc;
5910 ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
5911 ctxt.info.valid_sections |=
5912 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
5914 PMD_DRV_LOG(ERR, "VSI: Not support other type VSI yet");
5915 goto fail_msix_alloc;
5918 if (vsi->type != I40E_VSI_MAIN) {
5919 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
5920 if (ret != I40E_SUCCESS) {
5921 PMD_DRV_LOG(ERR, "add vsi failed, aq_err=%d",
5922 hw->aq.asq_last_status);
5923 goto fail_msix_alloc;
5925 memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
5926 vsi->info.valid_sections = 0;
5927 vsi->seid = ctxt.seid;
5928 vsi->vsi_id = ctxt.vsi_number;
5929 vsi->sib_vsi_list.vsi = vsi;
5930 if (vsi->type == I40E_VSI_SRIOV && uplink_vsi == NULL) {
5931 TAILQ_INSERT_TAIL(&pf->main_vsi->floating_veb->head,
5932 &vsi->sib_vsi_list, list);
5934 TAILQ_INSERT_TAIL(&uplink_vsi->veb->head,
5935 &vsi->sib_vsi_list, list);
5939 /* MAC/VLAN configuration */
5940 rte_memcpy(&filter.mac_addr, &broadcast, RTE_ETHER_ADDR_LEN);
5941 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
5943 ret = i40e_vsi_add_mac(vsi, &filter);
5944 if (ret != I40E_SUCCESS) {
5945 PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
5946 goto fail_msix_alloc;
5949 /* Get VSI BW information */
5950 i40e_vsi_get_bw_config(vsi);
5953 i40e_res_pool_free(&pf->msix_pool,vsi->msix_intr);
5955 i40e_res_pool_free(&pf->qp_pool,vsi->base_queue);
5961 /* Configure vlan filter on or off */
5963 i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on)
5966 struct i40e_mac_filter *f;
5968 struct i40e_mac_filter_info *mac_filter;
5969 enum rte_mac_filter_type desired_filter;
5970 int ret = I40E_SUCCESS;
5973 /* Filter to match MAC and VLAN */
5974 desired_filter = RTE_MACVLAN_PERFECT_MATCH;
5976 /* Filter to match only MAC */
5977 desired_filter = RTE_MAC_PERFECT_MATCH;
5982 mac_filter = rte_zmalloc("mac_filter_info_data",
5983 num * sizeof(*mac_filter), 0);
5984 if (mac_filter == NULL) {
5985 PMD_DRV_LOG(ERR, "failed to allocate memory");
5986 return I40E_ERR_NO_MEMORY;
5991 /* Remove all existing mac */
5992 TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
5993 mac_filter[i] = f->mac_info;
5994 ret = i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
5996 PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
5997 on ? "enable" : "disable");
6003 /* Override with new filter */
6004 for (i = 0; i < num; i++) {
6005 mac_filter[i].filter_type = desired_filter;
6006 ret = i40e_vsi_add_mac(vsi, &mac_filter[i]);
6008 PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
6009 on ? "enable" : "disable");
6015 rte_free(mac_filter);
6019 /* Configure vlan stripping on or off */
6021 i40e_vsi_config_vlan_stripping(struct i40e_vsi *vsi, bool on)
6023 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6024 struct i40e_vsi_context ctxt;
6026 int ret = I40E_SUCCESS;
6028 /* Check if it has been already on or off */
6029 if (vsi->info.valid_sections &
6030 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID)) {
6032 if ((vsi->info.port_vlan_flags &
6033 I40E_AQ_VSI_PVLAN_EMOD_MASK) == 0)
6034 return 0; /* already on */
6036 if ((vsi->info.port_vlan_flags &
6037 I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
6038 I40E_AQ_VSI_PVLAN_EMOD_MASK)
6039 return 0; /* already off */
6044 vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
6046 vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
6047 vsi->info.valid_sections =
6048 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
6049 vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_EMOD_MASK);
6050 vsi->info.port_vlan_flags |= vlan_flags;
6051 ctxt.seid = vsi->seid;
6052 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
6053 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
6055 PMD_DRV_LOG(INFO, "Update VSI failed to %s vlan stripping",
6056 on ? "enable" : "disable");
6062 i40e_dev_init_vlan(struct rte_eth_dev *dev)
6064 struct rte_eth_dev_data *data = dev->data;
6068 /* Apply vlan offload setting */
6069 mask = ETH_VLAN_STRIP_MASK |
6070 ETH_VLAN_FILTER_MASK |
6071 ETH_VLAN_EXTEND_MASK;
6072 ret = i40e_vlan_offload_set(dev, mask);
6074 PMD_DRV_LOG(INFO, "Failed to update vlan offload");
6078 /* Apply pvid setting */
6079 ret = i40e_vlan_pvid_set(dev, data->dev_conf.txmode.pvid,
6080 data->dev_conf.txmode.hw_vlan_insert_pvid);
6082 PMD_DRV_LOG(INFO, "Failed to update VSI params");
6088 i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on)
6090 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6092 return i40e_aq_set_port_parameters(hw, vsi->seid, 0, 1, on, NULL);
6096 i40e_update_flow_control(struct i40e_hw *hw)
6098 #define I40E_LINK_PAUSE_RXTX (I40E_AQ_LINK_PAUSE_RX | I40E_AQ_LINK_PAUSE_TX)
6099 struct i40e_link_status link_status;
6100 uint32_t rxfc = 0, txfc = 0, reg;
6104 memset(&link_status, 0, sizeof(link_status));
6105 ret = i40e_aq_get_link_info(hw, FALSE, &link_status, NULL);
6106 if (ret != I40E_SUCCESS) {
6107 PMD_DRV_LOG(ERR, "Failed to get link status information");
6108 goto write_reg; /* Disable flow control */
6111 an_info = hw->phy.link_info.an_info;
6112 if (!(an_info & I40E_AQ_AN_COMPLETED)) {
6113 PMD_DRV_LOG(INFO, "Link auto negotiation not completed");
6114 ret = I40E_ERR_NOT_READY;
6115 goto write_reg; /* Disable flow control */
6118 * If link auto negotiation is enabled, flow control needs to
6119 * be configured according to it
6121 switch (an_info & I40E_LINK_PAUSE_RXTX) {
6122 case I40E_LINK_PAUSE_RXTX:
6125 hw->fc.current_mode = I40E_FC_FULL;
6127 case I40E_AQ_LINK_PAUSE_RX:
6129 hw->fc.current_mode = I40E_FC_RX_PAUSE;
6131 case I40E_AQ_LINK_PAUSE_TX:
6133 hw->fc.current_mode = I40E_FC_TX_PAUSE;
6136 hw->fc.current_mode = I40E_FC_NONE;
6141 I40E_WRITE_REG(hw, I40E_PRTDCB_FCCFG,
6142 txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT);
6143 reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
6144 reg &= ~I40E_PRTDCB_MFLCN_RFCE_MASK;
6145 reg |= rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT;
6146 I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, reg);
6153 i40e_pf_setup(struct i40e_pf *pf)
6155 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6156 struct i40e_filter_control_settings settings;
6157 struct i40e_vsi *vsi;
6160 /* Clear all stats counters */
6161 pf->offset_loaded = FALSE;
6162 memset(&pf->stats, 0, sizeof(struct i40e_hw_port_stats));
6163 memset(&pf->stats_offset, 0, sizeof(struct i40e_hw_port_stats));
6164 memset(&pf->internal_stats, 0, sizeof(struct i40e_eth_stats));
6165 memset(&pf->internal_stats_offset, 0, sizeof(struct i40e_eth_stats));
6167 ret = i40e_pf_get_switch_config(pf);
6168 if (ret != I40E_SUCCESS) {
6169 PMD_DRV_LOG(ERR, "Could not get switch config, err %d", ret);
6173 ret = rte_eth_switch_domain_alloc(&pf->switch_domain_id);
6175 PMD_INIT_LOG(WARNING,
6176 "failed to allocate switch domain for device %d", ret);
6178 if (pf->flags & I40E_FLAG_FDIR) {
6179 /* make queue allocated first, let FDIR use queue pair 0*/
6180 ret = i40e_res_pool_alloc(&pf->qp_pool, I40E_DEFAULT_QP_NUM_FDIR);
6181 if (ret != I40E_FDIR_QUEUE_ID) {
6183 "queue allocation fails for FDIR: ret =%d",
6185 pf->flags &= ~I40E_FLAG_FDIR;
6188 /* main VSI setup */
6189 vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, NULL, 0);
6191 PMD_DRV_LOG(ERR, "Setup of main vsi failed");
6192 return I40E_ERR_NOT_READY;
6196 /* Configure filter control */
6197 memset(&settings, 0, sizeof(settings));
6198 if (hw->func_caps.rss_table_size == ETH_RSS_RETA_SIZE_128)
6199 settings.hash_lut_size = I40E_HASH_LUT_SIZE_128;
6200 else if (hw->func_caps.rss_table_size == ETH_RSS_RETA_SIZE_512)
6201 settings.hash_lut_size = I40E_HASH_LUT_SIZE_512;
6203 PMD_DRV_LOG(ERR, "Hash lookup table size (%u) not supported",
6204 hw->func_caps.rss_table_size);
6205 return I40E_ERR_PARAM;
6207 PMD_DRV_LOG(INFO, "Hardware capability of hash lookup table size: %u",
6208 hw->func_caps.rss_table_size);
6209 pf->hash_lut_size = hw->func_caps.rss_table_size;
6211 /* Enable ethtype and macvlan filters */
6212 settings.enable_ethtype = TRUE;
6213 settings.enable_macvlan = TRUE;
6214 ret = i40e_set_filter_control(hw, &settings);
6216 PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
6219 /* Update flow control according to the auto negotiation */
6220 i40e_update_flow_control(hw);
6222 return I40E_SUCCESS;
6226 i40e_switch_tx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
6232 * Set or clear TX Queue Disable flags,
6233 * which is required by hardware.
6235 i40e_pre_tx_queue_cfg(hw, q_idx, on);
6236 rte_delay_us(I40E_PRE_TX_Q_CFG_WAIT_US);
6238 /* Wait until the request is finished */
6239 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6240 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6241 reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
6242 if (!(((reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 0x1) ^
6243 ((reg >> I40E_QTX_ENA_QENA_STAT_SHIFT)
6249 if (reg & I40E_QTX_ENA_QENA_STAT_MASK)
6250 return I40E_SUCCESS; /* already on, skip next steps */
6252 I40E_WRITE_REG(hw, I40E_QTX_HEAD(q_idx), 0);
6253 reg |= I40E_QTX_ENA_QENA_REQ_MASK;
6255 if (!(reg & I40E_QTX_ENA_QENA_STAT_MASK))
6256 return I40E_SUCCESS; /* already off, skip next steps */
6257 reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
6259 /* Write the register */
6260 I40E_WRITE_REG(hw, I40E_QTX_ENA(q_idx), reg);
6261 /* Check the result */
6262 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6263 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6264 reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
6266 if ((reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
6267 (reg & I40E_QTX_ENA_QENA_STAT_MASK))
6270 if (!(reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
6271 !(reg & I40E_QTX_ENA_QENA_STAT_MASK))
6275 /* Check if it is timeout */
6276 if (j >= I40E_CHK_Q_ENA_COUNT) {
6277 PMD_DRV_LOG(ERR, "Failed to %s tx queue[%u]",
6278 (on ? "enable" : "disable"), q_idx);
6279 return I40E_ERR_TIMEOUT;
6282 return I40E_SUCCESS;
6285 /* Swith on or off the tx queues */
6287 i40e_dev_switch_tx_queues(struct i40e_pf *pf, bool on)
6289 struct rte_eth_dev_data *dev_data = pf->dev_data;
6290 struct i40e_tx_queue *txq;
6291 struct rte_eth_dev *dev = pf->adapter->eth_dev;
6295 for (i = 0; i < dev_data->nb_tx_queues; i++) {
6296 txq = dev_data->tx_queues[i];
6297 /* Don't operate the queue if not configured or
6298 * if starting only per queue */
6299 if (!txq || !txq->q_set || (on && txq->tx_deferred_start))
6302 ret = i40e_dev_tx_queue_start(dev, i);
6304 ret = i40e_dev_tx_queue_stop(dev, i);
6305 if ( ret != I40E_SUCCESS)
6309 return I40E_SUCCESS;
6313 i40e_switch_rx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
6318 /* Wait until the request is finished */
6319 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6320 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6321 reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
6322 if (!((reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 0x1) ^
6323 ((reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 0x1))
6328 if (reg & I40E_QRX_ENA_QENA_STAT_MASK)
6329 return I40E_SUCCESS; /* Already on, skip next steps */
6330 reg |= I40E_QRX_ENA_QENA_REQ_MASK;
6332 if (!(reg & I40E_QRX_ENA_QENA_STAT_MASK))
6333 return I40E_SUCCESS; /* Already off, skip next steps */
6334 reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
6337 /* Write the register */
6338 I40E_WRITE_REG(hw, I40E_QRX_ENA(q_idx), reg);
6339 /* Check the result */
6340 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6341 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6342 reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
6344 if ((reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
6345 (reg & I40E_QRX_ENA_QENA_STAT_MASK))
6348 if (!(reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
6349 !(reg & I40E_QRX_ENA_QENA_STAT_MASK))
6354 /* Check if it is timeout */
6355 if (j >= I40E_CHK_Q_ENA_COUNT) {
6356 PMD_DRV_LOG(ERR, "Failed to %s rx queue[%u]",
6357 (on ? "enable" : "disable"), q_idx);
6358 return I40E_ERR_TIMEOUT;
6361 return I40E_SUCCESS;
6363 /* Switch on or off the rx queues */
6365 i40e_dev_switch_rx_queues(struct i40e_pf *pf, bool on)
6367 struct rte_eth_dev_data *dev_data = pf->dev_data;
6368 struct i40e_rx_queue *rxq;
6369 struct rte_eth_dev *dev = pf->adapter->eth_dev;
6373 for (i = 0; i < dev_data->nb_rx_queues; i++) {
6374 rxq = dev_data->rx_queues[i];
6375 /* Don't operate the queue if not configured or
6376 * if starting only per queue */
6377 if (!rxq || !rxq->q_set || (on && rxq->rx_deferred_start))
6380 ret = i40e_dev_rx_queue_start(dev, i);
6382 ret = i40e_dev_rx_queue_stop(dev, i);
6383 if (ret != I40E_SUCCESS)
6387 return I40E_SUCCESS;
6390 /* Switch on or off all the rx/tx queues */
6392 i40e_dev_switch_queues(struct i40e_pf *pf, bool on)
6397 /* enable rx queues before enabling tx queues */
6398 ret = i40e_dev_switch_rx_queues(pf, on);
6400 PMD_DRV_LOG(ERR, "Failed to switch rx queues");
6403 ret = i40e_dev_switch_tx_queues(pf, on);
6405 /* Stop tx queues before stopping rx queues */
6406 ret = i40e_dev_switch_tx_queues(pf, on);
6408 PMD_DRV_LOG(ERR, "Failed to switch tx queues");
6411 ret = i40e_dev_switch_rx_queues(pf, on);
6417 /* Initialize VSI for TX */
6419 i40e_dev_tx_init(struct i40e_pf *pf)
6421 struct rte_eth_dev_data *data = pf->dev_data;
6423 uint32_t ret = I40E_SUCCESS;
6424 struct i40e_tx_queue *txq;
6426 for (i = 0; i < data->nb_tx_queues; i++) {
6427 txq = data->tx_queues[i];
6428 if (!txq || !txq->q_set)
6430 ret = i40e_tx_queue_init(txq);
6431 if (ret != I40E_SUCCESS)
6434 if (ret == I40E_SUCCESS)
6435 i40e_set_tx_function(container_of(pf, struct i40e_adapter, pf)
6441 /* Initialize VSI for RX */
6443 i40e_dev_rx_init(struct i40e_pf *pf)
6445 struct rte_eth_dev_data *data = pf->dev_data;
6446 int ret = I40E_SUCCESS;
6448 struct i40e_rx_queue *rxq;
6450 i40e_pf_config_mq_rx(pf);
6451 for (i = 0; i < data->nb_rx_queues; i++) {
6452 rxq = data->rx_queues[i];
6453 if (!rxq || !rxq->q_set)
6456 ret = i40e_rx_queue_init(rxq);
6457 if (ret != I40E_SUCCESS) {
6459 "Failed to do RX queue initialization");
6463 if (ret == I40E_SUCCESS)
6464 i40e_set_rx_function(container_of(pf, struct i40e_adapter, pf)
6471 i40e_dev_rxtx_init(struct i40e_pf *pf)
6475 err = i40e_dev_tx_init(pf);
6477 PMD_DRV_LOG(ERR, "Failed to do TX initialization");
6480 err = i40e_dev_rx_init(pf);
6482 PMD_DRV_LOG(ERR, "Failed to do RX initialization");
6490 i40e_vmdq_setup(struct rte_eth_dev *dev)
6492 struct rte_eth_conf *conf = &dev->data->dev_conf;
6493 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6494 int i, err, conf_vsis, j, loop;
6495 struct i40e_vsi *vsi;
6496 struct i40e_vmdq_info *vmdq_info;
6497 struct rte_eth_vmdq_rx_conf *vmdq_conf;
6498 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6501 * Disable interrupt to avoid message from VF. Furthermore, it will
6502 * avoid race condition in VSI creation/destroy.
6504 i40e_pf_disable_irq0(hw);
6506 if ((pf->flags & I40E_FLAG_VMDQ) == 0) {
6507 PMD_INIT_LOG(ERR, "FW doesn't support VMDQ");
6511 conf_vsis = conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools;
6512 if (conf_vsis > pf->max_nb_vmdq_vsi) {
6513 PMD_INIT_LOG(ERR, "VMDQ config: %u, max support:%u",
6514 conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools,
6515 pf->max_nb_vmdq_vsi);
6519 if (pf->vmdq != NULL) {
6520 PMD_INIT_LOG(INFO, "VMDQ already configured");
6524 pf->vmdq = rte_zmalloc("vmdq_info_struct",
6525 sizeof(*vmdq_info) * conf_vsis, 0);
6527 if (pf->vmdq == NULL) {
6528 PMD_INIT_LOG(ERR, "Failed to allocate memory");
6532 vmdq_conf = &conf->rx_adv_conf.vmdq_rx_conf;
6534 /* Create VMDQ VSI */
6535 for (i = 0; i < conf_vsis; i++) {
6536 vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, pf->main_vsi,
6537 vmdq_conf->enable_loop_back);
6539 PMD_INIT_LOG(ERR, "Failed to create VMDQ VSI");
6543 vmdq_info = &pf->vmdq[i];
6545 vmdq_info->vsi = vsi;
6547 pf->nb_cfg_vmdq_vsi = conf_vsis;
6549 /* Configure Vlan */
6550 loop = sizeof(vmdq_conf->pool_map[0].pools) * CHAR_BIT;
6551 for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
6552 for (j = 0; j < loop && j < pf->nb_cfg_vmdq_vsi; j++) {
6553 if (vmdq_conf->pool_map[i].pools & (1UL << j)) {
6554 PMD_INIT_LOG(INFO, "Add vlan %u to vmdq pool %u",
6555 vmdq_conf->pool_map[i].vlan_id, j);
6557 err = i40e_vsi_add_vlan(pf->vmdq[j].vsi,
6558 vmdq_conf->pool_map[i].vlan_id);
6560 PMD_INIT_LOG(ERR, "Failed to add vlan");
6568 i40e_pf_enable_irq0(hw);
6573 for (i = 0; i < conf_vsis; i++)
6574 if (pf->vmdq[i].vsi == NULL)
6577 i40e_vsi_release(pf->vmdq[i].vsi);
6581 i40e_pf_enable_irq0(hw);
6586 i40e_stat_update_32(struct i40e_hw *hw,
6594 new_data = (uint64_t)I40E_READ_REG(hw, reg);
6598 if (new_data >= *offset)
6599 *stat = (uint64_t)(new_data - *offset);
6601 *stat = (uint64_t)((new_data +
6602 ((uint64_t)1 << I40E_32_BIT_WIDTH)) - *offset);
6606 i40e_stat_update_48(struct i40e_hw *hw,
6615 new_data = (uint64_t)I40E_READ_REG(hw, loreg);
6616 new_data |= ((uint64_t)(I40E_READ_REG(hw, hireg) &
6617 I40E_16_BIT_MASK)) << I40E_32_BIT_WIDTH;
6622 if (new_data >= *offset)
6623 *stat = new_data - *offset;
6625 *stat = (uint64_t)((new_data +
6626 ((uint64_t)1 << I40E_48_BIT_WIDTH)) - *offset);
6628 *stat &= I40E_48_BIT_MASK;
6633 i40e_pf_disable_irq0(struct i40e_hw *hw)
6635 /* Disable all interrupt types */
6636 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
6637 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
6638 I40E_WRITE_FLUSH(hw);
6643 i40e_pf_enable_irq0(struct i40e_hw *hw)
6645 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
6646 I40E_PFINT_DYN_CTL0_INTENA_MASK |
6647 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
6648 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
6649 I40E_WRITE_FLUSH(hw);
6653 i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue)
6655 /* read pending request and disable first */
6656 i40e_pf_disable_irq0(hw);
6657 I40E_WRITE_REG(hw, I40E_PFINT_ICR0_ENA, I40E_PFINT_ICR0_ENA_MASK);
6658 I40E_WRITE_REG(hw, I40E_PFINT_STAT_CTL0,
6659 I40E_PFINT_STAT_CTL0_OTHER_ITR_INDX_MASK);
6662 /* Link no queues with irq0 */
6663 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
6664 I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
6668 i40e_dev_handle_vfr_event(struct rte_eth_dev *dev)
6670 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6671 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6674 uint32_t index, offset, val;
6679 * Try to find which VF trigger a reset, use absolute VF id to access
6680 * since the reg is global register.
6682 for (i = 0; i < pf->vf_num; i++) {
6683 abs_vf_id = hw->func_caps.vf_base_id + i;
6684 index = abs_vf_id / I40E_UINT32_BIT_SIZE;
6685 offset = abs_vf_id % I40E_UINT32_BIT_SIZE;
6686 val = I40E_READ_REG(hw, I40E_GLGEN_VFLRSTAT(index));
6687 /* VFR event occurred */
6688 if (val & (0x1 << offset)) {
6691 /* Clear the event first */
6692 I40E_WRITE_REG(hw, I40E_GLGEN_VFLRSTAT(index),
6694 PMD_DRV_LOG(INFO, "VF %u reset occurred", abs_vf_id);
6696 * Only notify a VF reset event occurred,
6697 * don't trigger another SW reset
6699 ret = i40e_pf_host_vf_reset(&pf->vfs[i], 0);
6700 if (ret != I40E_SUCCESS)
6701 PMD_DRV_LOG(ERR, "Failed to do VF reset");
6707 i40e_notify_all_vfs_link_status(struct rte_eth_dev *dev)
6709 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6712 for (i = 0; i < pf->vf_num; i++)
6713 i40e_notify_vf_link_status(dev, &pf->vfs[i]);
6717 i40e_dev_handle_aq_msg(struct rte_eth_dev *dev)
6719 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6720 struct i40e_arq_event_info info;
6721 uint16_t pending, opcode;
6724 info.buf_len = I40E_AQ_BUF_SZ;
6725 info.msg_buf = rte_zmalloc("msg_buffer", info.buf_len, 0);
6726 if (!info.msg_buf) {
6727 PMD_DRV_LOG(ERR, "Failed to allocate mem");
6733 ret = i40e_clean_arq_element(hw, &info, &pending);
6735 if (ret != I40E_SUCCESS) {
6737 "Failed to read msg from AdminQ, aq_err: %u",
6738 hw->aq.asq_last_status);
6741 opcode = rte_le_to_cpu_16(info.desc.opcode);
6744 case i40e_aqc_opc_send_msg_to_pf:
6745 /* Refer to i40e_aq_send_msg_to_pf() for argument layout*/
6746 i40e_pf_host_handle_vf_msg(dev,
6747 rte_le_to_cpu_16(info.desc.retval),
6748 rte_le_to_cpu_32(info.desc.cookie_high),
6749 rte_le_to_cpu_32(info.desc.cookie_low),
6753 case i40e_aqc_opc_get_link_status:
6754 ret = i40e_dev_link_update(dev, 0);
6756 _rte_eth_dev_callback_process(dev,
6757 RTE_ETH_EVENT_INTR_LSC, NULL);
6760 PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
6765 rte_free(info.msg_buf);
6769 i40e_handle_mdd_event(struct rte_eth_dev *dev)
6771 #define I40E_MDD_CLEAR32 0xFFFFFFFF
6772 #define I40E_MDD_CLEAR16 0xFFFF
6773 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6774 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6775 bool mdd_detected = false;
6776 struct i40e_pf_vf *vf;
6780 /* find what triggered the MDD event */
6781 reg = I40E_READ_REG(hw, I40E_GL_MDET_TX);
6782 if (reg & I40E_GL_MDET_TX_VALID_MASK) {
6783 uint8_t pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
6784 I40E_GL_MDET_TX_PF_NUM_SHIFT;
6785 uint16_t vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
6786 I40E_GL_MDET_TX_VF_NUM_SHIFT;
6787 uint8_t event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
6788 I40E_GL_MDET_TX_EVENT_SHIFT;
6789 uint16_t queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
6790 I40E_GL_MDET_TX_QUEUE_SHIFT) -
6791 hw->func_caps.base_queue;
6792 PMD_DRV_LOG(WARNING, "Malicious Driver Detection event 0x%02x on TX "
6793 "queue %d PF number 0x%02x VF number 0x%02x device %s\n",
6794 event, queue, pf_num, vf_num, dev->data->name);
6795 I40E_WRITE_REG(hw, I40E_GL_MDET_TX, I40E_MDD_CLEAR32);
6796 mdd_detected = true;
6798 reg = I40E_READ_REG(hw, I40E_GL_MDET_RX);
6799 if (reg & I40E_GL_MDET_RX_VALID_MASK) {
6800 uint8_t func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
6801 I40E_GL_MDET_RX_FUNCTION_SHIFT;
6802 uint8_t event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
6803 I40E_GL_MDET_RX_EVENT_SHIFT;
6804 uint16_t queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
6805 I40E_GL_MDET_RX_QUEUE_SHIFT) -
6806 hw->func_caps.base_queue;
6808 PMD_DRV_LOG(WARNING, "Malicious Driver Detection event 0x%02x on RX "
6809 "queue %d of function 0x%02x device %s\n",
6810 event, queue, func, dev->data->name);
6811 I40E_WRITE_REG(hw, I40E_GL_MDET_RX, I40E_MDD_CLEAR32);
6812 mdd_detected = true;
6816 reg = I40E_READ_REG(hw, I40E_PF_MDET_TX);
6817 if (reg & I40E_PF_MDET_TX_VALID_MASK) {
6818 I40E_WRITE_REG(hw, I40E_PF_MDET_TX, I40E_MDD_CLEAR16);
6819 PMD_DRV_LOG(WARNING, "TX driver issue detected on PF\n");
6821 reg = I40E_READ_REG(hw, I40E_PF_MDET_RX);
6822 if (reg & I40E_PF_MDET_RX_VALID_MASK) {
6823 I40E_WRITE_REG(hw, I40E_PF_MDET_RX,
6825 PMD_DRV_LOG(WARNING, "RX driver issue detected on PF\n");
6829 /* see if one of the VFs needs its hand slapped */
6830 for (i = 0; i < pf->vf_num && mdd_detected; i++) {
6832 reg = I40E_READ_REG(hw, I40E_VP_MDET_TX(i));
6833 if (reg & I40E_VP_MDET_TX_VALID_MASK) {
6834 I40E_WRITE_REG(hw, I40E_VP_MDET_TX(i),
6836 vf->num_mdd_events++;
6837 PMD_DRV_LOG(WARNING, "TX driver issue detected on VF %d %-"
6839 i, vf->num_mdd_events);
6842 reg = I40E_READ_REG(hw, I40E_VP_MDET_RX(i));
6843 if (reg & I40E_VP_MDET_RX_VALID_MASK) {
6844 I40E_WRITE_REG(hw, I40E_VP_MDET_RX(i),
6846 vf->num_mdd_events++;
6847 PMD_DRV_LOG(WARNING, "RX driver issue detected on VF %d %-"
6849 i, vf->num_mdd_events);
6855 * Interrupt handler triggered by NIC for handling
6856 * specific interrupt.
6859 * Pointer to interrupt handle.
6861 * The address of parameter (struct rte_eth_dev *) regsitered before.
6867 i40e_dev_interrupt_handler(void *param)
6869 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
6870 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6873 /* Disable interrupt */
6874 i40e_pf_disable_irq0(hw);
6876 /* read out interrupt causes */
6877 icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
6879 /* No interrupt event indicated */
6880 if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK)) {
6881 PMD_DRV_LOG(INFO, "No interrupt event");
6884 if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
6885 PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
6886 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
6887 PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
6888 i40e_handle_mdd_event(dev);
6890 if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
6891 PMD_DRV_LOG(INFO, "ICR0: global reset requested");
6892 if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
6893 PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
6894 if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
6895 PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
6896 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
6897 PMD_DRV_LOG(ERR, "ICR0: HMC error");
6898 if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
6899 PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
6901 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
6902 PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
6903 i40e_dev_handle_vfr_event(dev);
6905 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
6906 PMD_DRV_LOG(INFO, "ICR0: adminq event");
6907 i40e_dev_handle_aq_msg(dev);
6911 /* Enable interrupt */
6912 i40e_pf_enable_irq0(hw);
6916 i40e_dev_alarm_handler(void *param)
6918 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
6919 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6922 /* Disable interrupt */
6923 i40e_pf_disable_irq0(hw);
6925 /* read out interrupt causes */
6926 icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
6928 /* No interrupt event indicated */
6929 if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK))
6931 if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
6932 PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
6933 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
6934 PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
6935 i40e_handle_mdd_event(dev);
6937 if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
6938 PMD_DRV_LOG(INFO, "ICR0: global reset requested");
6939 if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
6940 PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
6941 if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
6942 PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
6943 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
6944 PMD_DRV_LOG(ERR, "ICR0: HMC error");
6945 if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
6946 PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
6948 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
6949 PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
6950 i40e_dev_handle_vfr_event(dev);
6952 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
6953 PMD_DRV_LOG(INFO, "ICR0: adminq event");
6954 i40e_dev_handle_aq_msg(dev);
6958 /* Enable interrupt */
6959 i40e_pf_enable_irq0(hw);
6960 rte_eal_alarm_set(I40E_ALARM_INTERVAL,
6961 i40e_dev_alarm_handler, dev);
6965 i40e_add_macvlan_filters(struct i40e_vsi *vsi,
6966 struct i40e_macvlan_filter *filter,
6969 int ele_num, ele_buff_size;
6970 int num, actual_num, i;
6972 int ret = I40E_SUCCESS;
6973 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6974 struct i40e_aqc_add_macvlan_element_data *req_list;
6976 if (filter == NULL || total == 0)
6977 return I40E_ERR_PARAM;
6978 ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
6979 ele_buff_size = hw->aq.asq_buf_size;
6981 req_list = rte_zmalloc("macvlan_add", ele_buff_size, 0);
6982 if (req_list == NULL) {
6983 PMD_DRV_LOG(ERR, "Fail to allocate memory");
6984 return I40E_ERR_NO_MEMORY;
6989 actual_num = (num + ele_num > total) ? (total - num) : ele_num;
6990 memset(req_list, 0, ele_buff_size);
6992 for (i = 0; i < actual_num; i++) {
6993 rte_memcpy(req_list[i].mac_addr,
6994 &filter[num + i].macaddr, ETH_ADDR_LEN);
6995 req_list[i].vlan_tag =
6996 rte_cpu_to_le_16(filter[num + i].vlan_id);
6998 switch (filter[num + i].filter_type) {
6999 case RTE_MAC_PERFECT_MATCH:
7000 flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH |
7001 I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
7003 case RTE_MACVLAN_PERFECT_MATCH:
7004 flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
7006 case RTE_MAC_HASH_MATCH:
7007 flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH |
7008 I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
7010 case RTE_MACVLAN_HASH_MATCH:
7011 flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH;
7014 PMD_DRV_LOG(ERR, "Invalid MAC match type");
7015 ret = I40E_ERR_PARAM;
7019 req_list[i].queue_number = 0;
7021 req_list[i].flags = rte_cpu_to_le_16(flags);
7024 ret = i40e_aq_add_macvlan(hw, vsi->seid, req_list,
7026 if (ret != I40E_SUCCESS) {
7027 PMD_DRV_LOG(ERR, "Failed to add macvlan filter");
7031 } while (num < total);
7039 i40e_remove_macvlan_filters(struct i40e_vsi *vsi,
7040 struct i40e_macvlan_filter *filter,
7043 int ele_num, ele_buff_size;
7044 int num, actual_num, i;
7046 int ret = I40E_SUCCESS;
7047 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7048 struct i40e_aqc_remove_macvlan_element_data *req_list;
7050 if (filter == NULL || total == 0)
7051 return I40E_ERR_PARAM;
7053 ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
7054 ele_buff_size = hw->aq.asq_buf_size;
7056 req_list = rte_zmalloc("macvlan_remove", ele_buff_size, 0);
7057 if (req_list == NULL) {
7058 PMD_DRV_LOG(ERR, "Fail to allocate memory");
7059 return I40E_ERR_NO_MEMORY;
7064 actual_num = (num + ele_num > total) ? (total - num) : ele_num;
7065 memset(req_list, 0, ele_buff_size);
7067 for (i = 0; i < actual_num; i++) {
7068 rte_memcpy(req_list[i].mac_addr,
7069 &filter[num + i].macaddr, ETH_ADDR_LEN);
7070 req_list[i].vlan_tag =
7071 rte_cpu_to_le_16(filter[num + i].vlan_id);
7073 switch (filter[num + i].filter_type) {
7074 case RTE_MAC_PERFECT_MATCH:
7075 flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
7076 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
7078 case RTE_MACVLAN_PERFECT_MATCH:
7079 flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
7081 case RTE_MAC_HASH_MATCH:
7082 flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH |
7083 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
7085 case RTE_MACVLAN_HASH_MATCH:
7086 flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH;
7089 PMD_DRV_LOG(ERR, "Invalid MAC filter type");
7090 ret = I40E_ERR_PARAM;
7093 req_list[i].flags = rte_cpu_to_le_16(flags);
7096 ret = i40e_aq_remove_macvlan(hw, vsi->seid, req_list,
7098 if (ret != I40E_SUCCESS) {
7099 PMD_DRV_LOG(ERR, "Failed to remove macvlan filter");
7103 } while (num < total);
7110 /* Find out specific MAC filter */
7111 static struct i40e_mac_filter *
7112 i40e_find_mac_filter(struct i40e_vsi *vsi,
7113 struct rte_ether_addr *macaddr)
7115 struct i40e_mac_filter *f;
7117 TAILQ_FOREACH(f, &vsi->mac_list, next) {
7118 if (rte_is_same_ether_addr(macaddr, &f->mac_info.mac_addr))
7126 i40e_find_vlan_filter(struct i40e_vsi *vsi,
7129 uint32_t vid_idx, vid_bit;
7131 if (vlan_id > ETH_VLAN_ID_MAX)
7134 vid_idx = I40E_VFTA_IDX(vlan_id);
7135 vid_bit = I40E_VFTA_BIT(vlan_id);
7137 if (vsi->vfta[vid_idx] & vid_bit)
7144 i40e_store_vlan_filter(struct i40e_vsi *vsi,
7145 uint16_t vlan_id, bool on)
7147 uint32_t vid_idx, vid_bit;
7149 vid_idx = I40E_VFTA_IDX(vlan_id);
7150 vid_bit = I40E_VFTA_BIT(vlan_id);
7153 vsi->vfta[vid_idx] |= vid_bit;
7155 vsi->vfta[vid_idx] &= ~vid_bit;
7159 i40e_set_vlan_filter(struct i40e_vsi *vsi,
7160 uint16_t vlan_id, bool on)
7162 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7163 struct i40e_aqc_add_remove_vlan_element_data vlan_data = {0};
7166 if (vlan_id > ETH_VLAN_ID_MAX)
7169 i40e_store_vlan_filter(vsi, vlan_id, on);
7171 if ((!vsi->vlan_anti_spoof_on && !vsi->vlan_filter_on) || !vlan_id)
7174 vlan_data.vlan_tag = rte_cpu_to_le_16(vlan_id);
7177 ret = i40e_aq_add_vlan(hw, vsi->seid,
7178 &vlan_data, 1, NULL);
7179 if (ret != I40E_SUCCESS)
7180 PMD_DRV_LOG(ERR, "Failed to add vlan filter");
7182 ret = i40e_aq_remove_vlan(hw, vsi->seid,
7183 &vlan_data, 1, NULL);
7184 if (ret != I40E_SUCCESS)
7186 "Failed to remove vlan filter");
7191 * Find all vlan options for specific mac addr,
7192 * return with actual vlan found.
7195 i40e_find_all_vlan_for_mac(struct i40e_vsi *vsi,
7196 struct i40e_macvlan_filter *mv_f,
7197 int num, struct rte_ether_addr *addr)
7203 * Not to use i40e_find_vlan_filter to decrease the loop time,
7204 * although the code looks complex.
7206 if (num < vsi->vlan_num)
7207 return I40E_ERR_PARAM;
7210 for (j = 0; j < I40E_VFTA_SIZE; j++) {
7212 for (k = 0; k < I40E_UINT32_BIT_SIZE; k++) {
7213 if (vsi->vfta[j] & (1 << k)) {
7216 "vlan number doesn't match");
7217 return I40E_ERR_PARAM;
7219 rte_memcpy(&mv_f[i].macaddr,
7220 addr, ETH_ADDR_LEN);
7222 j * I40E_UINT32_BIT_SIZE + k;
7228 return I40E_SUCCESS;
7232 i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
7233 struct i40e_macvlan_filter *mv_f,
7238 struct i40e_mac_filter *f;
7240 if (num < vsi->mac_num)
7241 return I40E_ERR_PARAM;
7243 TAILQ_FOREACH(f, &vsi->mac_list, next) {
7245 PMD_DRV_LOG(ERR, "buffer number not match");
7246 return I40E_ERR_PARAM;
7248 rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
7250 mv_f[i].vlan_id = vlan;
7251 mv_f[i].filter_type = f->mac_info.filter_type;
7255 return I40E_SUCCESS;
7259 i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi)
7262 struct i40e_mac_filter *f;
7263 struct i40e_macvlan_filter *mv_f;
7264 int ret = I40E_SUCCESS;
7266 if (vsi == NULL || vsi->mac_num == 0)
7267 return I40E_ERR_PARAM;
7269 /* Case that no vlan is set */
7270 if (vsi->vlan_num == 0)
7273 num = vsi->mac_num * vsi->vlan_num;
7275 mv_f = rte_zmalloc("macvlan_data", num * sizeof(*mv_f), 0);
7277 PMD_DRV_LOG(ERR, "failed to allocate memory");
7278 return I40E_ERR_NO_MEMORY;
7282 if (vsi->vlan_num == 0) {
7283 TAILQ_FOREACH(f, &vsi->mac_list, next) {
7284 rte_memcpy(&mv_f[i].macaddr,
7285 &f->mac_info.mac_addr, ETH_ADDR_LEN);
7286 mv_f[i].filter_type = f->mac_info.filter_type;
7287 mv_f[i].vlan_id = 0;
7291 TAILQ_FOREACH(f, &vsi->mac_list, next) {
7292 ret = i40e_find_all_vlan_for_mac(vsi,&mv_f[i],
7293 vsi->vlan_num, &f->mac_info.mac_addr);
7294 if (ret != I40E_SUCCESS)
7296 for (j = i; j < i + vsi->vlan_num; j++)
7297 mv_f[j].filter_type = f->mac_info.filter_type;
7302 ret = i40e_remove_macvlan_filters(vsi, mv_f, num);
7310 i40e_vsi_add_vlan(struct i40e_vsi *vsi, uint16_t vlan)
7312 struct i40e_macvlan_filter *mv_f;
7314 int ret = I40E_SUCCESS;
7316 if (!vsi || vlan > RTE_ETHER_MAX_VLAN_ID)
7317 return I40E_ERR_PARAM;
7319 /* If it's already set, just return */
7320 if (i40e_find_vlan_filter(vsi,vlan))
7321 return I40E_SUCCESS;
7323 mac_num = vsi->mac_num;
7326 PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
7327 return I40E_ERR_PARAM;
7330 mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
7333 PMD_DRV_LOG(ERR, "failed to allocate memory");
7334 return I40E_ERR_NO_MEMORY;
7337 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
7339 if (ret != I40E_SUCCESS)
7342 ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
7344 if (ret != I40E_SUCCESS)
7347 i40e_set_vlan_filter(vsi, vlan, 1);
7357 i40e_vsi_delete_vlan(struct i40e_vsi *vsi, uint16_t vlan)
7359 struct i40e_macvlan_filter *mv_f;
7361 int ret = I40E_SUCCESS;
7364 * Vlan 0 is the generic filter for untagged packets
7365 * and can't be removed.
7367 if (!vsi || vlan == 0 || vlan > RTE_ETHER_MAX_VLAN_ID)
7368 return I40E_ERR_PARAM;
7370 /* If can't find it, just return */
7371 if (!i40e_find_vlan_filter(vsi, vlan))
7372 return I40E_ERR_PARAM;
7374 mac_num = vsi->mac_num;
7377 PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
7378 return I40E_ERR_PARAM;
7381 mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
7384 PMD_DRV_LOG(ERR, "failed to allocate memory");
7385 return I40E_ERR_NO_MEMORY;
7388 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
7390 if (ret != I40E_SUCCESS)
7393 ret = i40e_remove_macvlan_filters(vsi, mv_f, mac_num);
7395 if (ret != I40E_SUCCESS)
7398 /* This is last vlan to remove, replace all mac filter with vlan 0 */
7399 if (vsi->vlan_num == 1) {
7400 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, 0);
7401 if (ret != I40E_SUCCESS)
7404 ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
7405 if (ret != I40E_SUCCESS)
7409 i40e_set_vlan_filter(vsi, vlan, 0);
7419 i40e_vsi_add_mac(struct i40e_vsi *vsi, struct i40e_mac_filter_info *mac_filter)
7421 struct i40e_mac_filter *f;
7422 struct i40e_macvlan_filter *mv_f;
7423 int i, vlan_num = 0;
7424 int ret = I40E_SUCCESS;
7426 /* If it's add and we've config it, return */
7427 f = i40e_find_mac_filter(vsi, &mac_filter->mac_addr);
7429 return I40E_SUCCESS;
7430 if ((mac_filter->filter_type == RTE_MACVLAN_PERFECT_MATCH) ||
7431 (mac_filter->filter_type == RTE_MACVLAN_HASH_MATCH)) {
7434 * If vlan_num is 0, that's the first time to add mac,
7435 * set mask for vlan_id 0.
7437 if (vsi->vlan_num == 0) {
7438 i40e_set_vlan_filter(vsi, 0, 1);
7441 vlan_num = vsi->vlan_num;
7442 } else if ((mac_filter->filter_type == RTE_MAC_PERFECT_MATCH) ||
7443 (mac_filter->filter_type == RTE_MAC_HASH_MATCH))
7446 mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
7448 PMD_DRV_LOG(ERR, "failed to allocate memory");
7449 return I40E_ERR_NO_MEMORY;
7452 for (i = 0; i < vlan_num; i++) {
7453 mv_f[i].filter_type = mac_filter->filter_type;
7454 rte_memcpy(&mv_f[i].macaddr, &mac_filter->mac_addr,
7458 if (mac_filter->filter_type == RTE_MACVLAN_PERFECT_MATCH ||
7459 mac_filter->filter_type == RTE_MACVLAN_HASH_MATCH) {
7460 ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
7461 &mac_filter->mac_addr);
7462 if (ret != I40E_SUCCESS)
7466 ret = i40e_add_macvlan_filters(vsi, mv_f, vlan_num);
7467 if (ret != I40E_SUCCESS)
7470 /* Add the mac addr into mac list */
7471 f = rte_zmalloc("macv_filter", sizeof(*f), 0);
7473 PMD_DRV_LOG(ERR, "failed to allocate memory");
7474 ret = I40E_ERR_NO_MEMORY;
7477 rte_memcpy(&f->mac_info.mac_addr, &mac_filter->mac_addr,
7479 f->mac_info.filter_type = mac_filter->filter_type;
7480 TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
7491 i40e_vsi_delete_mac(struct i40e_vsi *vsi, struct rte_ether_addr *addr)
7493 struct i40e_mac_filter *f;
7494 struct i40e_macvlan_filter *mv_f;
7496 enum rte_mac_filter_type filter_type;
7497 int ret = I40E_SUCCESS;
7499 /* Can't find it, return an error */
7500 f = i40e_find_mac_filter(vsi, addr);
7502 return I40E_ERR_PARAM;
7504 vlan_num = vsi->vlan_num;
7505 filter_type = f->mac_info.filter_type;
7506 if (filter_type == RTE_MACVLAN_PERFECT_MATCH ||
7507 filter_type == RTE_MACVLAN_HASH_MATCH) {
7508 if (vlan_num == 0) {
7509 PMD_DRV_LOG(ERR, "VLAN number shouldn't be 0");
7510 return I40E_ERR_PARAM;
7512 } else if (filter_type == RTE_MAC_PERFECT_MATCH ||
7513 filter_type == RTE_MAC_HASH_MATCH)
7516 mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
7518 PMD_DRV_LOG(ERR, "failed to allocate memory");
7519 return I40E_ERR_NO_MEMORY;
7522 for (i = 0; i < vlan_num; i++) {
7523 mv_f[i].filter_type = filter_type;
7524 rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
7527 if (filter_type == RTE_MACVLAN_PERFECT_MATCH ||
7528 filter_type == RTE_MACVLAN_HASH_MATCH) {
7529 ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num, addr);
7530 if (ret != I40E_SUCCESS)
7534 ret = i40e_remove_macvlan_filters(vsi, mv_f, vlan_num);
7535 if (ret != I40E_SUCCESS)
7538 /* Remove the mac addr into mac list */
7539 TAILQ_REMOVE(&vsi->mac_list, f, next);
7549 /* Configure hash enable flags for RSS */
7551 i40e_config_hena(const struct i40e_adapter *adapter, uint64_t flags)
7559 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < I40E_FLOW_TYPE_MAX; i++) {
7560 if (flags & (1ULL << i))
7561 hena |= adapter->pctypes_tbl[i];
7567 /* Parse the hash enable flags */
7569 i40e_parse_hena(const struct i40e_adapter *adapter, uint64_t flags)
7571 uint64_t rss_hf = 0;
7577 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < I40E_FLOW_TYPE_MAX; i++) {
7578 if (flags & adapter->pctypes_tbl[i])
7579 rss_hf |= (1ULL << i);
7586 i40e_pf_disable_rss(struct i40e_pf *pf)
7588 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7590 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
7591 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
7592 I40E_WRITE_FLUSH(hw);
7596 i40e_set_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t key_len)
7598 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
7599 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7600 uint16_t key_idx = (vsi->type == I40E_VSI_SRIOV) ?
7601 I40E_VFQF_HKEY_MAX_INDEX :
7602 I40E_PFQF_HKEY_MAX_INDEX;
7605 if (!key || key_len == 0) {
7606 PMD_DRV_LOG(DEBUG, "No key to be configured");
7608 } else if (key_len != (key_idx + 1) *
7610 PMD_DRV_LOG(ERR, "Invalid key length %u", key_len);
7614 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
7615 struct i40e_aqc_get_set_rss_key_data *key_dw =
7616 (struct i40e_aqc_get_set_rss_key_data *)key;
7618 ret = i40e_aq_set_rss_key(hw, vsi->vsi_id, key_dw);
7620 PMD_INIT_LOG(ERR, "Failed to configure RSS key via AQ");
7622 uint32_t *hash_key = (uint32_t *)key;
7625 if (vsi->type == I40E_VSI_SRIOV) {
7626 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
7629 I40E_VFQF_HKEY1(i, vsi->user_param),
7633 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
7634 I40E_WRITE_REG(hw, I40E_PFQF_HKEY(i),
7637 I40E_WRITE_FLUSH(hw);
7644 i40e_get_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t *key_len)
7646 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
7647 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7651 if (!key || !key_len)
7654 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
7655 ret = i40e_aq_get_rss_key(hw, vsi->vsi_id,
7656 (struct i40e_aqc_get_set_rss_key_data *)key);
7658 PMD_INIT_LOG(ERR, "Failed to get RSS key via AQ");
7662 uint32_t *key_dw = (uint32_t *)key;
7665 if (vsi->type == I40E_VSI_SRIOV) {
7666 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++) {
7667 reg = I40E_VFQF_HKEY1(i, vsi->user_param);
7668 key_dw[i] = i40e_read_rx_ctl(hw, reg);
7670 *key_len = (I40E_VFQF_HKEY_MAX_INDEX + 1) *
7673 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
7674 reg = I40E_PFQF_HKEY(i);
7675 key_dw[i] = i40e_read_rx_ctl(hw, reg);
7677 *key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
7685 i40e_hw_rss_hash_set(struct i40e_pf *pf, struct rte_eth_rss_conf *rss_conf)
7687 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7691 ret = i40e_set_rss_key(pf->main_vsi, rss_conf->rss_key,
7692 rss_conf->rss_key_len);
7696 hena = i40e_config_hena(pf->adapter, rss_conf->rss_hf);
7697 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
7698 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
7699 I40E_WRITE_FLUSH(hw);
7705 i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
7706 struct rte_eth_rss_conf *rss_conf)
7708 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7709 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7710 uint64_t rss_hf = rss_conf->rss_hf & pf->adapter->flow_types_mask;
7713 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
7714 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
7716 if (!(hena & pf->adapter->pctypes_mask)) { /* RSS disabled */
7717 if (rss_hf != 0) /* Enable RSS */
7719 return 0; /* Nothing to do */
7722 if (rss_hf == 0) /* Disable RSS */
7725 return i40e_hw_rss_hash_set(pf, rss_conf);
7729 i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
7730 struct rte_eth_rss_conf *rss_conf)
7732 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7733 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7740 ret = i40e_get_rss_key(pf->main_vsi, rss_conf->rss_key,
7741 &rss_conf->rss_key_len);
7745 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
7746 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
7747 rss_conf->rss_hf = i40e_parse_hena(pf->adapter, hena);
7753 i40e_dev_get_filter_type(uint16_t filter_type, uint16_t *flag)
7755 switch (filter_type) {
7756 case RTE_TUNNEL_FILTER_IMAC_IVLAN:
7757 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
7759 case RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID:
7760 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
7762 case RTE_TUNNEL_FILTER_IMAC_TENID:
7763 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID;
7765 case RTE_TUNNEL_FILTER_OMAC_TENID_IMAC:
7766 *flag = I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC;
7768 case ETH_TUNNEL_FILTER_IMAC:
7769 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
7771 case ETH_TUNNEL_FILTER_OIP:
7772 *flag = I40E_AQC_ADD_CLOUD_FILTER_OIP;
7774 case ETH_TUNNEL_FILTER_IIP:
7775 *flag = I40E_AQC_ADD_CLOUD_FILTER_IIP;
7778 PMD_DRV_LOG(ERR, "invalid tunnel filter type");
7785 /* Convert tunnel filter structure */
7787 i40e_tunnel_filter_convert(
7788 struct i40e_aqc_cloud_filters_element_bb *cld_filter,
7789 struct i40e_tunnel_filter *tunnel_filter)
7791 rte_ether_addr_copy((struct rte_ether_addr *)
7792 &cld_filter->element.outer_mac,
7793 (struct rte_ether_addr *)&tunnel_filter->input.outer_mac);
7794 rte_ether_addr_copy((struct rte_ether_addr *)
7795 &cld_filter->element.inner_mac,
7796 (struct rte_ether_addr *)&tunnel_filter->input.inner_mac);
7797 tunnel_filter->input.inner_vlan = cld_filter->element.inner_vlan;
7798 if ((rte_le_to_cpu_16(cld_filter->element.flags) &
7799 I40E_AQC_ADD_CLOUD_FLAGS_IPV6) ==
7800 I40E_AQC_ADD_CLOUD_FLAGS_IPV6)
7801 tunnel_filter->input.ip_type = I40E_TUNNEL_IPTYPE_IPV6;
7803 tunnel_filter->input.ip_type = I40E_TUNNEL_IPTYPE_IPV4;
7804 tunnel_filter->input.flags = cld_filter->element.flags;
7805 tunnel_filter->input.tenant_id = cld_filter->element.tenant_id;
7806 tunnel_filter->queue = cld_filter->element.queue_number;
7807 rte_memcpy(tunnel_filter->input.general_fields,
7808 cld_filter->general_fields,
7809 sizeof(cld_filter->general_fields));
7814 /* Check if there exists the tunnel filter */
7815 struct i40e_tunnel_filter *
7816 i40e_sw_tunnel_filter_lookup(struct i40e_tunnel_rule *tunnel_rule,
7817 const struct i40e_tunnel_filter_input *input)
7821 ret = rte_hash_lookup(tunnel_rule->hash_table, (const void *)input);
7825 return tunnel_rule->hash_map[ret];
7828 /* Add a tunnel filter into the SW list */
7830 i40e_sw_tunnel_filter_insert(struct i40e_pf *pf,
7831 struct i40e_tunnel_filter *tunnel_filter)
7833 struct i40e_tunnel_rule *rule = &pf->tunnel;
7836 ret = rte_hash_add_key(rule->hash_table, &tunnel_filter->input);
7839 "Failed to insert tunnel filter to hash table %d!",
7843 rule->hash_map[ret] = tunnel_filter;
7845 TAILQ_INSERT_TAIL(&rule->tunnel_list, tunnel_filter, rules);
7850 /* Delete a tunnel filter from the SW list */
7852 i40e_sw_tunnel_filter_del(struct i40e_pf *pf,
7853 struct i40e_tunnel_filter_input *input)
7855 struct i40e_tunnel_rule *rule = &pf->tunnel;
7856 struct i40e_tunnel_filter *tunnel_filter;
7859 ret = rte_hash_del_key(rule->hash_table, input);
7862 "Failed to delete tunnel filter to hash table %d!",
7866 tunnel_filter = rule->hash_map[ret];
7867 rule->hash_map[ret] = NULL;
7869 TAILQ_REMOVE(&rule->tunnel_list, tunnel_filter, rules);
7870 rte_free(tunnel_filter);
7876 i40e_dev_tunnel_filter_set(struct i40e_pf *pf,
7877 struct rte_eth_tunnel_filter_conf *tunnel_filter,
7881 uint32_t ipv4_addr, ipv4_addr_le;
7882 uint8_t i, tun_type = 0;
7883 /* internal varialbe to convert ipv6 byte order */
7884 uint32_t convert_ipv6[4];
7886 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7887 struct i40e_vsi *vsi = pf->main_vsi;
7888 struct i40e_aqc_cloud_filters_element_bb *cld_filter;
7889 struct i40e_aqc_cloud_filters_element_bb *pfilter;
7890 struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
7891 struct i40e_tunnel_filter *tunnel, *node;
7892 struct i40e_tunnel_filter check_filter; /* Check if filter exists */
7894 cld_filter = rte_zmalloc("tunnel_filter",
7895 sizeof(struct i40e_aqc_add_rm_cloud_filt_elem_ext),
7898 if (NULL == cld_filter) {
7899 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
7902 pfilter = cld_filter;
7904 rte_ether_addr_copy(&tunnel_filter->outer_mac,
7905 (struct rte_ether_addr *)&pfilter->element.outer_mac);
7906 rte_ether_addr_copy(&tunnel_filter->inner_mac,
7907 (struct rte_ether_addr *)&pfilter->element.inner_mac);
7909 pfilter->element.inner_vlan =
7910 rte_cpu_to_le_16(tunnel_filter->inner_vlan);
7911 if (tunnel_filter->ip_type == RTE_TUNNEL_IPTYPE_IPV4) {
7912 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV4;
7913 ipv4_addr = rte_be_to_cpu_32(tunnel_filter->ip_addr.ipv4_addr);
7914 ipv4_addr_le = rte_cpu_to_le_32(ipv4_addr);
7915 rte_memcpy(&pfilter->element.ipaddr.v4.data,
7917 sizeof(pfilter->element.ipaddr.v4.data));
7919 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV6;
7920 for (i = 0; i < 4; i++) {
7922 rte_cpu_to_le_32(rte_be_to_cpu_32(tunnel_filter->ip_addr.ipv6_addr[i]));
7924 rte_memcpy(&pfilter->element.ipaddr.v6.data,
7926 sizeof(pfilter->element.ipaddr.v6.data));
7929 /* check tunneled type */
7930 switch (tunnel_filter->tunnel_type) {
7931 case RTE_TUNNEL_TYPE_VXLAN:
7932 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_VXLAN;
7934 case RTE_TUNNEL_TYPE_NVGRE:
7935 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_NVGRE_OMAC;
7937 case RTE_TUNNEL_TYPE_IP_IN_GRE:
7938 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_IP;
7940 case RTE_TUNNEL_TYPE_VXLAN_GPE:
7941 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_VXLAN_GPE;
7944 /* Other tunnel types is not supported. */
7945 PMD_DRV_LOG(ERR, "tunnel type is not supported.");
7946 rte_free(cld_filter);
7950 val = i40e_dev_get_filter_type(tunnel_filter->filter_type,
7951 &pfilter->element.flags);
7953 rte_free(cld_filter);
7957 pfilter->element.flags |= rte_cpu_to_le_16(
7958 I40E_AQC_ADD_CLOUD_FLAGS_TO_QUEUE |
7959 ip_type | (tun_type << I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT));
7960 pfilter->element.tenant_id = rte_cpu_to_le_32(tunnel_filter->tenant_id);
7961 pfilter->element.queue_number =
7962 rte_cpu_to_le_16(tunnel_filter->queue_id);
7964 /* Check if there is the filter in SW list */
7965 memset(&check_filter, 0, sizeof(check_filter));
7966 i40e_tunnel_filter_convert(cld_filter, &check_filter);
7967 node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
7969 PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
7970 rte_free(cld_filter);
7974 if (!add && !node) {
7975 PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
7976 rte_free(cld_filter);
7981 ret = i40e_aq_add_cloud_filters(hw,
7982 vsi->seid, &cld_filter->element, 1);
7984 PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
7985 rte_free(cld_filter);
7988 tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
7989 if (tunnel == NULL) {
7990 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
7991 rte_free(cld_filter);
7995 rte_memcpy(tunnel, &check_filter, sizeof(check_filter));
7996 ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
8000 ret = i40e_aq_rem_cloud_filters(hw, vsi->seid,
8001 &cld_filter->element, 1);
8003 PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
8004 rte_free(cld_filter);
8007 ret = i40e_sw_tunnel_filter_del(pf, &node->input);
8010 rte_free(cld_filter);
8014 #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_TR_WORD0 0x48
8015 #define I40E_TR_VXLAN_GRE_KEY_MASK 0x4
8016 #define I40E_TR_GENEVE_KEY_MASK 0x8
8017 #define I40E_TR_GENERIC_UDP_TUNNEL_MASK 0x40
8018 #define I40E_TR_GRE_KEY_MASK 0x400
8019 #define I40E_TR_GRE_KEY_WITH_XSUM_MASK 0x800
8020 #define I40E_TR_GRE_NO_KEY_MASK 0x8000
8023 i40e_status_code i40e_replace_mpls_l1_filter(struct i40e_pf *pf)
8025 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8026 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8027 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8028 struct rte_eth_dev *dev = ((struct i40e_adapter *)hw->back)->eth_dev;
8029 enum i40e_status_code status = I40E_SUCCESS;
8031 if (pf->support_multi_driver) {
8032 PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
8033 return I40E_NOT_SUPPORTED;
8036 memset(&filter_replace, 0,
8037 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8038 memset(&filter_replace_buf, 0,
8039 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8041 /* create L1 filter */
8042 filter_replace.old_filter_type =
8043 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_IMAC;
8044 filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X11;
8045 filter_replace.tr_bit = 0;
8047 /* Prepare the buffer, 3 entries */
8048 filter_replace_buf.data[0] =
8049 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8050 filter_replace_buf.data[0] |=
8051 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8052 filter_replace_buf.data[2] = 0xFF;
8053 filter_replace_buf.data[3] = 0xFF;
8054 filter_replace_buf.data[4] =
8055 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8056 filter_replace_buf.data[4] |=
8057 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8058 filter_replace_buf.data[7] = 0xF0;
8059 filter_replace_buf.data[8]
8060 = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_TR_WORD0;
8061 filter_replace_buf.data[8] |=
8062 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8063 filter_replace_buf.data[10] = I40E_TR_VXLAN_GRE_KEY_MASK |
8064 I40E_TR_GENEVE_KEY_MASK |
8065 I40E_TR_GENERIC_UDP_TUNNEL_MASK;
8066 filter_replace_buf.data[11] = (I40E_TR_GRE_KEY_MASK |
8067 I40E_TR_GRE_KEY_WITH_XSUM_MASK |
8068 I40E_TR_GRE_NO_KEY_MASK) >> 8;
8070 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8071 &filter_replace_buf);
8072 if (!status && (filter_replace.old_filter_type !=
8073 filter_replace.new_filter_type))
8074 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8075 " original: 0x%x, new: 0x%x",
8077 filter_replace.old_filter_type,
8078 filter_replace.new_filter_type);
8084 i40e_status_code i40e_replace_mpls_cloud_filter(struct i40e_pf *pf)
8086 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8087 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8088 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8089 struct rte_eth_dev *dev = ((struct i40e_adapter *)hw->back)->eth_dev;
8090 enum i40e_status_code status = I40E_SUCCESS;
8092 if (pf->support_multi_driver) {
8093 PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8094 return I40E_NOT_SUPPORTED;
8098 memset(&filter_replace, 0,
8099 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8100 memset(&filter_replace_buf, 0,
8101 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8102 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER |
8103 I40E_AQC_MIRROR_CLOUD_FILTER;
8104 filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IIP;
8105 filter_replace.new_filter_type =
8106 I40E_AQC_ADD_CLOUD_FILTER_0X11;
8107 /* Prepare the buffer, 2 entries */
8108 filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8109 filter_replace_buf.data[0] |=
8110 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8111 filter_replace_buf.data[4] = I40E_AQC_ADD_L1_FILTER_0X11;
8112 filter_replace_buf.data[4] |=
8113 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8114 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8115 &filter_replace_buf);
8118 if (filter_replace.old_filter_type !=
8119 filter_replace.new_filter_type)
8120 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8121 " original: 0x%x, new: 0x%x",
8123 filter_replace.old_filter_type,
8124 filter_replace.new_filter_type);
8127 memset(&filter_replace, 0,
8128 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8129 memset(&filter_replace_buf, 0,
8130 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8132 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER |
8133 I40E_AQC_MIRROR_CLOUD_FILTER;
8134 filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
8135 filter_replace.new_filter_type =
8136 I40E_AQC_ADD_CLOUD_FILTER_0X12;
8137 /* Prepare the buffer, 2 entries */
8138 filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8139 filter_replace_buf.data[0] |=
8140 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8141 filter_replace_buf.data[4] = I40E_AQC_ADD_L1_FILTER_0X11;
8142 filter_replace_buf.data[4] |=
8143 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8145 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8146 &filter_replace_buf);
8147 if (!status && (filter_replace.old_filter_type !=
8148 filter_replace.new_filter_type))
8149 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8150 " original: 0x%x, new: 0x%x",
8152 filter_replace.old_filter_type,
8153 filter_replace.new_filter_type);
8158 static enum i40e_status_code
8159 i40e_replace_gtp_l1_filter(struct i40e_pf *pf)
8161 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8162 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8163 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8164 struct rte_eth_dev *dev = ((struct i40e_adapter *)hw->back)->eth_dev;
8165 enum i40e_status_code status = I40E_SUCCESS;
8167 if (pf->support_multi_driver) {
8168 PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
8169 return I40E_NOT_SUPPORTED;
8173 memset(&filter_replace, 0,
8174 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8175 memset(&filter_replace_buf, 0,
8176 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8177 /* create L1 filter */
8178 filter_replace.old_filter_type =
8179 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_IMAC;
8180 filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X12;
8181 filter_replace.tr_bit = I40E_AQC_NEW_TR_22 |
8182 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8183 /* Prepare the buffer, 2 entries */
8184 filter_replace_buf.data[0] =
8185 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8186 filter_replace_buf.data[0] |=
8187 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8188 filter_replace_buf.data[2] = 0xFF;
8189 filter_replace_buf.data[3] = 0xFF;
8190 filter_replace_buf.data[4] =
8191 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8192 filter_replace_buf.data[4] |=
8193 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8194 filter_replace_buf.data[6] = 0xFF;
8195 filter_replace_buf.data[7] = 0xFF;
8196 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8197 &filter_replace_buf);
8200 if (filter_replace.old_filter_type !=
8201 filter_replace.new_filter_type)
8202 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8203 " original: 0x%x, new: 0x%x",
8205 filter_replace.old_filter_type,
8206 filter_replace.new_filter_type);
8209 memset(&filter_replace, 0,
8210 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8211 memset(&filter_replace_buf, 0,
8212 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8213 /* create L1 filter */
8214 filter_replace.old_filter_type =
8215 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TUNNLE_KEY;
8216 filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X13;
8217 filter_replace.tr_bit = I40E_AQC_NEW_TR_21 |
8218 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8219 /* Prepare the buffer, 2 entries */
8220 filter_replace_buf.data[0] =
8221 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8222 filter_replace_buf.data[0] |=
8223 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8224 filter_replace_buf.data[2] = 0xFF;
8225 filter_replace_buf.data[3] = 0xFF;
8226 filter_replace_buf.data[4] =
8227 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8228 filter_replace_buf.data[4] |=
8229 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8230 filter_replace_buf.data[6] = 0xFF;
8231 filter_replace_buf.data[7] = 0xFF;
8233 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8234 &filter_replace_buf);
8235 if (!status && (filter_replace.old_filter_type !=
8236 filter_replace.new_filter_type))
8237 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8238 " original: 0x%x, new: 0x%x",
8240 filter_replace.old_filter_type,
8241 filter_replace.new_filter_type);
8247 i40e_status_code i40e_replace_gtp_cloud_filter(struct i40e_pf *pf)
8249 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8250 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8251 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8252 struct rte_eth_dev *dev = ((struct i40e_adapter *)hw->back)->eth_dev;
8253 enum i40e_status_code status = I40E_SUCCESS;
8255 if (pf->support_multi_driver) {
8256 PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8257 return I40E_NOT_SUPPORTED;
8261 memset(&filter_replace, 0,
8262 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8263 memset(&filter_replace_buf, 0,
8264 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8265 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8266 filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
8267 filter_replace.new_filter_type =
8268 I40E_AQC_ADD_CLOUD_FILTER_0X11;
8269 /* Prepare the buffer, 2 entries */
8270 filter_replace_buf.data[0] = I40E_AQC_ADD_L1_FILTER_0X12;
8271 filter_replace_buf.data[0] |=
8272 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8273 filter_replace_buf.data[4] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8274 filter_replace_buf.data[4] |=
8275 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8276 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8277 &filter_replace_buf);
8280 if (filter_replace.old_filter_type !=
8281 filter_replace.new_filter_type)
8282 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8283 " original: 0x%x, new: 0x%x",
8285 filter_replace.old_filter_type,
8286 filter_replace.new_filter_type);
8289 memset(&filter_replace, 0,
8290 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8291 memset(&filter_replace_buf, 0,
8292 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8293 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8294 filter_replace.old_filter_type =
8295 I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
8296 filter_replace.new_filter_type =
8297 I40E_AQC_ADD_CLOUD_FILTER_0X12;
8298 /* Prepare the buffer, 2 entries */
8299 filter_replace_buf.data[0] = I40E_AQC_ADD_L1_FILTER_0X13;
8300 filter_replace_buf.data[0] |=
8301 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8302 filter_replace_buf.data[4] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8303 filter_replace_buf.data[4] |=
8304 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8306 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8307 &filter_replace_buf);
8308 if (!status && (filter_replace.old_filter_type !=
8309 filter_replace.new_filter_type))
8310 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8311 " original: 0x%x, new: 0x%x",
8313 filter_replace.old_filter_type,
8314 filter_replace.new_filter_type);
8320 i40e_dev_consistent_tunnel_filter_set(struct i40e_pf *pf,
8321 struct i40e_tunnel_filter_conf *tunnel_filter,
8325 uint32_t ipv4_addr, ipv4_addr_le;
8326 uint8_t i, tun_type = 0;
8327 /* internal variable to convert ipv6 byte order */
8328 uint32_t convert_ipv6[4];
8330 struct i40e_pf_vf *vf = NULL;
8331 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8332 struct i40e_vsi *vsi;
8333 struct i40e_aqc_cloud_filters_element_bb *cld_filter;
8334 struct i40e_aqc_cloud_filters_element_bb *pfilter;
8335 struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
8336 struct i40e_tunnel_filter *tunnel, *node;
8337 struct i40e_tunnel_filter check_filter; /* Check if filter exists */
8339 bool big_buffer = 0;
8341 cld_filter = rte_zmalloc("tunnel_filter",
8342 sizeof(struct i40e_aqc_add_rm_cloud_filt_elem_ext),
8345 if (cld_filter == NULL) {
8346 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
8349 pfilter = cld_filter;
8351 rte_ether_addr_copy(&tunnel_filter->outer_mac,
8352 (struct rte_ether_addr *)&pfilter->element.outer_mac);
8353 rte_ether_addr_copy(&tunnel_filter->inner_mac,
8354 (struct rte_ether_addr *)&pfilter->element.inner_mac);
8356 pfilter->element.inner_vlan =
8357 rte_cpu_to_le_16(tunnel_filter->inner_vlan);
8358 if (tunnel_filter->ip_type == I40E_TUNNEL_IPTYPE_IPV4) {
8359 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV4;
8360 ipv4_addr = rte_be_to_cpu_32(tunnel_filter->ip_addr.ipv4_addr);
8361 ipv4_addr_le = rte_cpu_to_le_32(ipv4_addr);
8362 rte_memcpy(&pfilter->element.ipaddr.v4.data,
8364 sizeof(pfilter->element.ipaddr.v4.data));
8366 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV6;
8367 for (i = 0; i < 4; i++) {
8369 rte_cpu_to_le_32(rte_be_to_cpu_32(
8370 tunnel_filter->ip_addr.ipv6_addr[i]));
8372 rte_memcpy(&pfilter->element.ipaddr.v6.data,
8374 sizeof(pfilter->element.ipaddr.v6.data));
8377 /* check tunneled type */
8378 switch (tunnel_filter->tunnel_type) {
8379 case I40E_TUNNEL_TYPE_VXLAN:
8380 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_VXLAN;
8382 case I40E_TUNNEL_TYPE_NVGRE:
8383 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_NVGRE_OMAC;
8385 case I40E_TUNNEL_TYPE_IP_IN_GRE:
8386 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_IP;
8388 case I40E_TUNNEL_TYPE_MPLSoUDP:
8389 if (!pf->mpls_replace_flag) {
8390 i40e_replace_mpls_l1_filter(pf);
8391 i40e_replace_mpls_cloud_filter(pf);
8392 pf->mpls_replace_flag = 1;
8394 teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8395 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8397 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8398 (teid_le & 0xF) << 12;
8399 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8402 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_MPLSOUDP;
8404 case I40E_TUNNEL_TYPE_MPLSoGRE:
8405 if (!pf->mpls_replace_flag) {
8406 i40e_replace_mpls_l1_filter(pf);
8407 i40e_replace_mpls_cloud_filter(pf);
8408 pf->mpls_replace_flag = 1;
8410 teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8411 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8413 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8414 (teid_le & 0xF) << 12;
8415 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8418 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_MPLSOGRE;
8420 case I40E_TUNNEL_TYPE_GTPC:
8421 if (!pf->gtp_replace_flag) {
8422 i40e_replace_gtp_l1_filter(pf);
8423 i40e_replace_gtp_cloud_filter(pf);
8424 pf->gtp_replace_flag = 1;
8426 teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8427 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD0] =
8428 (teid_le >> 16) & 0xFFFF;
8429 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD1] =
8431 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD2] =
8435 case I40E_TUNNEL_TYPE_GTPU:
8436 if (!pf->gtp_replace_flag) {
8437 i40e_replace_gtp_l1_filter(pf);
8438 i40e_replace_gtp_cloud_filter(pf);
8439 pf->gtp_replace_flag = 1;
8441 teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8442 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD0] =
8443 (teid_le >> 16) & 0xFFFF;
8444 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD1] =
8446 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD2] =
8450 case I40E_TUNNEL_TYPE_QINQ:
8451 if (!pf->qinq_replace_flag) {
8452 ret = i40e_cloud_filter_qinq_create(pf);
8455 "QinQ tunnel filter already created.");
8456 pf->qinq_replace_flag = 1;
8458 /* Add in the General fields the values of
8459 * the Outer and Inner VLAN
8460 * Big Buffer should be set, see changes in
8461 * i40e_aq_add_cloud_filters
8463 pfilter->general_fields[0] = tunnel_filter->inner_vlan;
8464 pfilter->general_fields[1] = tunnel_filter->outer_vlan;
8468 /* Other tunnel types is not supported. */
8469 PMD_DRV_LOG(ERR, "tunnel type is not supported.");
8470 rte_free(cld_filter);
8474 if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_MPLSoUDP)
8475 pfilter->element.flags =
8476 I40E_AQC_ADD_CLOUD_FILTER_0X11;
8477 else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_MPLSoGRE)
8478 pfilter->element.flags =
8479 I40E_AQC_ADD_CLOUD_FILTER_0X12;
8480 else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_GTPC)
8481 pfilter->element.flags =
8482 I40E_AQC_ADD_CLOUD_FILTER_0X11;
8483 else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_GTPU)
8484 pfilter->element.flags =
8485 I40E_AQC_ADD_CLOUD_FILTER_0X12;
8486 else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_QINQ)
8487 pfilter->element.flags |=
8488 I40E_AQC_ADD_CLOUD_FILTER_0X10;
8490 val = i40e_dev_get_filter_type(tunnel_filter->filter_type,
8491 &pfilter->element.flags);
8493 rte_free(cld_filter);
8498 pfilter->element.flags |= rte_cpu_to_le_16(
8499 I40E_AQC_ADD_CLOUD_FLAGS_TO_QUEUE |
8500 ip_type | (tun_type << I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT));
8501 pfilter->element.tenant_id = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8502 pfilter->element.queue_number =
8503 rte_cpu_to_le_16(tunnel_filter->queue_id);
8505 if (!tunnel_filter->is_to_vf)
8508 if (tunnel_filter->vf_id >= pf->vf_num) {
8509 PMD_DRV_LOG(ERR, "Invalid argument.");
8510 rte_free(cld_filter);
8513 vf = &pf->vfs[tunnel_filter->vf_id];
8517 /* Check if there is the filter in SW list */
8518 memset(&check_filter, 0, sizeof(check_filter));
8519 i40e_tunnel_filter_convert(cld_filter, &check_filter);
8520 check_filter.is_to_vf = tunnel_filter->is_to_vf;
8521 check_filter.vf_id = tunnel_filter->vf_id;
8522 node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
8524 PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
8525 rte_free(cld_filter);
8529 if (!add && !node) {
8530 PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
8531 rte_free(cld_filter);
8537 ret = i40e_aq_add_cloud_filters_bb(hw,
8538 vsi->seid, cld_filter, 1);
8540 ret = i40e_aq_add_cloud_filters(hw,
8541 vsi->seid, &cld_filter->element, 1);
8543 PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
8544 rte_free(cld_filter);
8547 tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
8548 if (tunnel == NULL) {
8549 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
8550 rte_free(cld_filter);
8554 rte_memcpy(tunnel, &check_filter, sizeof(check_filter));
8555 ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
8560 ret = i40e_aq_rem_cloud_filters_bb(
8561 hw, vsi->seid, cld_filter, 1);
8563 ret = i40e_aq_rem_cloud_filters(hw, vsi->seid,
8564 &cld_filter->element, 1);
8566 PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
8567 rte_free(cld_filter);
8570 ret = i40e_sw_tunnel_filter_del(pf, &node->input);
8573 rte_free(cld_filter);
8578 i40e_get_vxlan_port_idx(struct i40e_pf *pf, uint16_t port)
8582 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
8583 if (pf->vxlan_ports[i] == port)
8591 i40e_add_vxlan_port(struct i40e_pf *pf, uint16_t port, int udp_type)
8594 uint8_t filter_idx = 0;
8595 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8597 idx = i40e_get_vxlan_port_idx(pf, port);
8599 /* Check if port already exists */
8601 PMD_DRV_LOG(ERR, "Port %d already offloaded", port);
8605 /* Now check if there is space to add the new port */
8606 idx = i40e_get_vxlan_port_idx(pf, 0);
8609 "Maximum number of UDP ports reached, not adding port %d",
8614 ret = i40e_aq_add_udp_tunnel(hw, port, udp_type,
8617 PMD_DRV_LOG(ERR, "Failed to add VXLAN UDP port %d", port);
8621 PMD_DRV_LOG(INFO, "Added port %d with AQ command with index %d",
8624 /* New port: add it and mark its index in the bitmap */
8625 pf->vxlan_ports[idx] = port;
8626 pf->vxlan_bitmap |= (1 << idx);
8628 if (!(pf->flags & I40E_FLAG_VXLAN))
8629 pf->flags |= I40E_FLAG_VXLAN;
8635 i40e_del_vxlan_port(struct i40e_pf *pf, uint16_t port)
8638 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8640 if (!(pf->flags & I40E_FLAG_VXLAN)) {
8641 PMD_DRV_LOG(ERR, "VXLAN UDP port was not configured.");
8645 idx = i40e_get_vxlan_port_idx(pf, port);
8648 PMD_DRV_LOG(ERR, "Port %d doesn't exist", port);
8652 if (i40e_aq_del_udp_tunnel(hw, idx, NULL) < 0) {
8653 PMD_DRV_LOG(ERR, "Failed to delete VXLAN UDP port %d", port);
8657 PMD_DRV_LOG(INFO, "Deleted port %d with AQ command with index %d",
8660 pf->vxlan_ports[idx] = 0;
8661 pf->vxlan_bitmap &= ~(1 << idx);
8663 if (!pf->vxlan_bitmap)
8664 pf->flags &= ~I40E_FLAG_VXLAN;
8669 /* Add UDP tunneling port */
8671 i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
8672 struct rte_eth_udp_tunnel *udp_tunnel)
8675 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8677 if (udp_tunnel == NULL)
8680 switch (udp_tunnel->prot_type) {
8681 case RTE_TUNNEL_TYPE_VXLAN:
8682 ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port,
8683 I40E_AQC_TUNNEL_TYPE_VXLAN);
8685 case RTE_TUNNEL_TYPE_VXLAN_GPE:
8686 ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port,
8687 I40E_AQC_TUNNEL_TYPE_VXLAN_GPE);
8689 case RTE_TUNNEL_TYPE_GENEVE:
8690 case RTE_TUNNEL_TYPE_TEREDO:
8691 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8696 PMD_DRV_LOG(ERR, "Invalid tunnel type");
8704 /* Remove UDP tunneling port */
8706 i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
8707 struct rte_eth_udp_tunnel *udp_tunnel)
8710 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8712 if (udp_tunnel == NULL)
8715 switch (udp_tunnel->prot_type) {
8716 case RTE_TUNNEL_TYPE_VXLAN:
8717 case RTE_TUNNEL_TYPE_VXLAN_GPE:
8718 ret = i40e_del_vxlan_port(pf, udp_tunnel->udp_port);
8720 case RTE_TUNNEL_TYPE_GENEVE:
8721 case RTE_TUNNEL_TYPE_TEREDO:
8722 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8726 PMD_DRV_LOG(ERR, "Invalid tunnel type");
8734 /* Calculate the maximum number of contiguous PF queues that are configured */
8736 i40e_pf_calc_configured_queues_num(struct i40e_pf *pf)
8738 struct rte_eth_dev_data *data = pf->dev_data;
8740 struct i40e_rx_queue *rxq;
8743 for (i = 0; i < pf->lan_nb_qps; i++) {
8744 rxq = data->rx_queues[i];
8745 if (rxq && rxq->q_set)
8756 i40e_pf_config_rss(struct i40e_pf *pf)
8758 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8759 struct rte_eth_rss_conf rss_conf;
8760 uint32_t i, lut = 0;
8764 * If both VMDQ and RSS enabled, not all of PF queues are configured.
8765 * It's necessary to calculate the actual PF queues that are configured.
8767 if (pf->dev_data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG)
8768 num = i40e_pf_calc_configured_queues_num(pf);
8770 num = pf->dev_data->nb_rx_queues;
8772 num = RTE_MIN(num, I40E_MAX_Q_PER_TC);
8773 PMD_INIT_LOG(INFO, "Max of contiguous %u PF queues are configured",
8778 "No PF queues are configured to enable RSS for port %u",
8779 pf->dev_data->port_id);
8783 if (pf->adapter->rss_reta_updated == 0) {
8784 for (i = 0, j = 0; i < hw->func_caps.rss_table_size; i++, j++) {
8787 lut = (lut << 8) | (j & ((0x1 <<
8788 hw->func_caps.rss_table_entry_width) - 1));
8790 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i >> 2),
8795 rss_conf = pf->dev_data->dev_conf.rx_adv_conf.rss_conf;
8796 if ((rss_conf.rss_hf & pf->adapter->flow_types_mask) == 0) {
8797 i40e_pf_disable_rss(pf);
8800 if (rss_conf.rss_key == NULL || rss_conf.rss_key_len <
8801 (I40E_PFQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t)) {
8802 /* Random default keys */
8803 static uint32_t rss_key_default[] = {0x6b793944,
8804 0x23504cb5, 0x5bea75b6, 0x309f4f12, 0x3dc0a2b8,
8805 0x024ddcdf, 0x339b8ca0, 0x4c4af64a, 0x34fac605,
8806 0x55d85839, 0x3a58997d, 0x2ec938e1, 0x66031581};
8808 rss_conf.rss_key = (uint8_t *)rss_key_default;
8809 rss_conf.rss_key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
8813 return i40e_hw_rss_hash_set(pf, &rss_conf);
8817 i40e_tunnel_filter_param_check(struct i40e_pf *pf,
8818 struct rte_eth_tunnel_filter_conf *filter)
8820 if (pf == NULL || filter == NULL) {
8821 PMD_DRV_LOG(ERR, "Invalid parameter");
8825 if (filter->queue_id >= pf->dev_data->nb_rx_queues) {
8826 PMD_DRV_LOG(ERR, "Invalid queue ID");
8830 if (filter->inner_vlan > RTE_ETHER_MAX_VLAN_ID) {
8831 PMD_DRV_LOG(ERR, "Invalid inner VLAN ID");
8835 if ((filter->filter_type & ETH_TUNNEL_FILTER_OMAC) &&
8836 (rte_is_zero_ether_addr(&filter->outer_mac))) {
8837 PMD_DRV_LOG(ERR, "Cannot add NULL outer MAC address");
8841 if ((filter->filter_type & ETH_TUNNEL_FILTER_IMAC) &&
8842 (rte_is_zero_ether_addr(&filter->inner_mac))) {
8843 PMD_DRV_LOG(ERR, "Cannot add NULL inner MAC address");
8850 #define I40E_GL_PRS_FVBM_MSK_ENA 0x80000000
8851 #define I40E_GL_PRS_FVBM(_i) (0x00269760 + ((_i) * 4))
8853 i40e_dev_set_gre_key_len(struct i40e_hw *hw, uint8_t len)
8855 struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
8859 if (pf->support_multi_driver) {
8860 PMD_DRV_LOG(ERR, "GRE key length configuration is unsupported");
8864 val = I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2));
8865 PMD_DRV_LOG(DEBUG, "Read original GL_PRS_FVBM with 0x%08x", val);
8868 reg = val | I40E_GL_PRS_FVBM_MSK_ENA;
8869 } else if (len == 4) {
8870 reg = val & ~I40E_GL_PRS_FVBM_MSK_ENA;
8872 PMD_DRV_LOG(ERR, "Unsupported GRE key length of %u", len);
8877 ret = i40e_aq_debug_write_global_register(hw,
8878 I40E_GL_PRS_FVBM(2),
8882 PMD_DRV_LOG(DEBUG, "Global register 0x%08x is changed "
8883 "with value 0x%08x",
8884 I40E_GL_PRS_FVBM(2), reg);
8888 PMD_DRV_LOG(DEBUG, "Read modified GL_PRS_FVBM with 0x%08x",
8889 I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2)));
8895 i40e_dev_global_config_set(struct i40e_hw *hw, struct rte_eth_global_cfg *cfg)
8902 switch (cfg->cfg_type) {
8903 case RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN:
8904 ret = i40e_dev_set_gre_key_len(hw, cfg->cfg.gre_key_len);
8907 PMD_DRV_LOG(ERR, "Unknown config type %u", cfg->cfg_type);
8915 i40e_filter_ctrl_global_config(struct rte_eth_dev *dev,
8916 enum rte_filter_op filter_op,
8919 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8920 int ret = I40E_ERR_PARAM;
8922 switch (filter_op) {
8923 case RTE_ETH_FILTER_SET:
8924 ret = i40e_dev_global_config_set(hw,
8925 (struct rte_eth_global_cfg *)arg);
8928 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
8936 i40e_tunnel_filter_handle(struct rte_eth_dev *dev,
8937 enum rte_filter_op filter_op,
8940 struct rte_eth_tunnel_filter_conf *filter;
8941 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8942 int ret = I40E_SUCCESS;
8944 filter = (struct rte_eth_tunnel_filter_conf *)(arg);
8946 if (i40e_tunnel_filter_param_check(pf, filter) < 0)
8947 return I40E_ERR_PARAM;
8949 switch (filter_op) {
8950 case RTE_ETH_FILTER_NOP:
8951 if (!(pf->flags & I40E_FLAG_VXLAN))
8952 ret = I40E_NOT_SUPPORTED;
8954 case RTE_ETH_FILTER_ADD:
8955 ret = i40e_dev_tunnel_filter_set(pf, filter, 1);
8957 case RTE_ETH_FILTER_DELETE:
8958 ret = i40e_dev_tunnel_filter_set(pf, filter, 0);
8961 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
8962 ret = I40E_ERR_PARAM;
8970 i40e_pf_config_mq_rx(struct i40e_pf *pf)
8973 enum rte_eth_rx_mq_mode mq_mode = pf->dev_data->dev_conf.rxmode.mq_mode;
8976 if (mq_mode & ETH_MQ_RX_RSS_FLAG)
8977 ret = i40e_pf_config_rss(pf);
8979 i40e_pf_disable_rss(pf);
8984 /* Get the symmetric hash enable configurations per port */
8986 i40e_get_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t *enable)
8988 uint32_t reg = i40e_read_rx_ctl(hw, I40E_PRTQF_CTL_0);
8990 *enable = reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK ? 1 : 0;
8993 /* Set the symmetric hash enable configurations per port */
8995 i40e_set_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t enable)
8997 uint32_t reg = i40e_read_rx_ctl(hw, I40E_PRTQF_CTL_0);
9000 if (reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK) {
9002 "Symmetric hash has already been enabled");
9005 reg |= I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
9007 if (!(reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK)) {
9009 "Symmetric hash has already been disabled");
9012 reg &= ~I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
9014 i40e_write_rx_ctl(hw, I40E_PRTQF_CTL_0, reg);
9015 I40E_WRITE_FLUSH(hw);
9019 * Get global configurations of hash function type and symmetric hash enable
9020 * per flow type (pctype). Note that global configuration means it affects all
9021 * the ports on the same NIC.
9024 i40e_get_hash_filter_global_config(struct i40e_hw *hw,
9025 struct rte_eth_hash_global_conf *g_cfg)
9027 struct i40e_adapter *adapter = (struct i40e_adapter *)hw->back;
9031 memset(g_cfg, 0, sizeof(*g_cfg));
9032 reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
9033 if (reg & I40E_GLQF_CTL_HTOEP_MASK)
9034 g_cfg->hash_func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
9036 g_cfg->hash_func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
9037 PMD_DRV_LOG(DEBUG, "Hash function is %s",
9038 (reg & I40E_GLQF_CTL_HTOEP_MASK) ? "Toeplitz" : "Simple XOR");
9041 * As i40e supports less than 64 flow types, only first 64 bits need to
9044 for (i = 1; i < RTE_SYM_HASH_MASK_ARRAY_SIZE; i++) {
9045 g_cfg->valid_bit_mask[i] = 0ULL;
9046 g_cfg->sym_hash_enable_mask[i] = 0ULL;
9049 g_cfg->valid_bit_mask[0] = adapter->flow_types_mask;
9051 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < UINT64_BIT; i++) {
9052 if (!adapter->pctypes_tbl[i])
9054 for (j = I40E_FILTER_PCTYPE_INVALID + 1;
9055 j < I40E_FILTER_PCTYPE_MAX; j++) {
9056 if (adapter->pctypes_tbl[i] & (1ULL << j)) {
9057 reg = i40e_read_rx_ctl(hw, I40E_GLQF_HSYM(j));
9058 if (reg & I40E_GLQF_HSYM_SYMH_ENA_MASK) {
9059 g_cfg->sym_hash_enable_mask[0] |=
9070 i40e_hash_global_config_check(const struct i40e_adapter *adapter,
9071 const struct rte_eth_hash_global_conf *g_cfg)
9074 uint64_t mask0, i40e_mask = adapter->flow_types_mask;
9076 if (g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_TOEPLITZ &&
9077 g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_SIMPLE_XOR &&
9078 g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_DEFAULT) {
9079 PMD_DRV_LOG(ERR, "Unsupported hash function type %d",
9085 * As i40e supports less than 64 flow types, only first 64 bits need to
9088 mask0 = g_cfg->valid_bit_mask[0];
9089 for (i = 0; i < RTE_SYM_HASH_MASK_ARRAY_SIZE; i++) {
9091 /* Check if any unsupported flow type configured */
9092 if ((mask0 | i40e_mask) ^ i40e_mask)
9095 if (g_cfg->valid_bit_mask[i])
9103 PMD_DRV_LOG(ERR, "i40e unsupported flow type bit(s) configured");
9109 * Set global configurations of hash function type and symmetric hash enable
9110 * per flow type (pctype). Note any modifying global configuration will affect
9111 * all the ports on the same NIC.
9114 i40e_set_hash_filter_global_config(struct i40e_hw *hw,
9115 struct rte_eth_hash_global_conf *g_cfg)
9117 struct i40e_adapter *adapter = (struct i40e_adapter *)hw->back;
9118 struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
9122 uint64_t mask0 = g_cfg->valid_bit_mask[0] & adapter->flow_types_mask;
9124 if (pf->support_multi_driver) {
9125 PMD_DRV_LOG(ERR, "Hash global configuration is not supported.");
9129 /* Check the input parameters */
9130 ret = i40e_hash_global_config_check(adapter, g_cfg);
9135 * As i40e supports less than 64 flow types, only first 64 bits need to
9138 for (i = RTE_ETH_FLOW_UNKNOWN + 1; mask0 && i < UINT64_BIT; i++) {
9139 if (mask0 & (1UL << i)) {
9140 reg = (g_cfg->sym_hash_enable_mask[0] & (1ULL << i)) ?
9141 I40E_GLQF_HSYM_SYMH_ENA_MASK : 0;
9143 for (j = I40E_FILTER_PCTYPE_INVALID + 1;
9144 j < I40E_FILTER_PCTYPE_MAX; j++) {
9145 if (adapter->pctypes_tbl[i] & (1ULL << j))
9146 i40e_write_global_rx_ctl(hw,
9153 reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
9154 if (g_cfg->hash_func == RTE_ETH_HASH_FUNCTION_TOEPLITZ) {
9156 if (reg & I40E_GLQF_CTL_HTOEP_MASK) {
9158 "Hash function already set to Toeplitz");
9161 reg |= I40E_GLQF_CTL_HTOEP_MASK;
9162 } else if (g_cfg->hash_func == RTE_ETH_HASH_FUNCTION_SIMPLE_XOR) {
9164 if (!(reg & I40E_GLQF_CTL_HTOEP_MASK)) {
9166 "Hash function already set to Simple XOR");
9169 reg &= ~I40E_GLQF_CTL_HTOEP_MASK;
9171 /* Use the default, and keep it as it is */
9174 i40e_write_global_rx_ctl(hw, I40E_GLQF_CTL, reg);
9177 I40E_WRITE_FLUSH(hw);
9183 * Valid input sets for hash and flow director filters per PCTYPE
9186 i40e_get_valid_input_set(enum i40e_filter_pctype pctype,
9187 enum rte_filter_type filter)
9191 static const uint64_t valid_hash_inset_table[] = {
9192 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9193 I40E_INSET_DMAC | I40E_INSET_SMAC |
9194 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9195 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_SRC |
9196 I40E_INSET_IPV4_DST | I40E_INSET_IPV4_TOS |
9197 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9198 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9199 I40E_INSET_FLEX_PAYLOAD,
9200 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9201 I40E_INSET_DMAC | I40E_INSET_SMAC |
9202 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9203 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9204 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9205 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9206 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9207 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9208 I40E_INSET_FLEX_PAYLOAD,
9209 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9210 I40E_INSET_DMAC | I40E_INSET_SMAC |
9211 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9212 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9213 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9214 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9215 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9216 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9217 I40E_INSET_FLEX_PAYLOAD,
9218 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9219 I40E_INSET_DMAC | I40E_INSET_SMAC |
9220 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9221 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9222 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9223 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9224 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9225 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9226 I40E_INSET_FLEX_PAYLOAD,
9227 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9228 I40E_INSET_DMAC | I40E_INSET_SMAC |
9229 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9230 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9231 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9232 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9233 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9234 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9235 I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
9236 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9237 I40E_INSET_DMAC | I40E_INSET_SMAC |
9238 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9239 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9240 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9241 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9242 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9243 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9244 I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
9245 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9246 I40E_INSET_DMAC | I40E_INSET_SMAC |
9247 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9248 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9249 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9250 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9251 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9252 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9253 I40E_INSET_SCTP_VT | I40E_INSET_FLEX_PAYLOAD,
9254 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9255 I40E_INSET_DMAC | I40E_INSET_SMAC |
9256 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9257 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9258 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9259 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9260 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9261 I40E_INSET_FLEX_PAYLOAD,
9262 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9263 I40E_INSET_DMAC | I40E_INSET_SMAC |
9264 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9265 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9266 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9267 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_TUNNEL_DMAC |
9268 I40E_INSET_TUNNEL_ID | I40E_INSET_IPV6_SRC |
9269 I40E_INSET_IPV6_DST | I40E_INSET_FLEX_PAYLOAD,
9270 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9271 I40E_INSET_DMAC | I40E_INSET_SMAC |
9272 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9273 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9274 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9275 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9276 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9277 I40E_INSET_DST_PORT | I40E_INSET_FLEX_PAYLOAD,
9278 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9279 I40E_INSET_DMAC | I40E_INSET_SMAC |
9280 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9281 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9282 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9283 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9284 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9285 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9286 I40E_INSET_FLEX_PAYLOAD,
9287 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9288 I40E_INSET_DMAC | I40E_INSET_SMAC |
9289 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9290 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9291 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9292 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9293 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9294 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9295 I40E_INSET_FLEX_PAYLOAD,
9296 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9297 I40E_INSET_DMAC | I40E_INSET_SMAC |
9298 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9299 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9300 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9301 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9302 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9303 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9304 I40E_INSET_FLEX_PAYLOAD,
9305 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9306 I40E_INSET_DMAC | I40E_INSET_SMAC |
9307 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9308 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9309 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9310 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9311 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9312 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9313 I40E_INSET_FLEX_PAYLOAD,
9314 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9315 I40E_INSET_DMAC | I40E_INSET_SMAC |
9316 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9317 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9318 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9319 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9320 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9321 I40E_INSET_DST_PORT | I40E_INSET_SCTP_VT |
9322 I40E_INSET_FLEX_PAYLOAD,
9323 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9324 I40E_INSET_DMAC | I40E_INSET_SMAC |
9325 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9326 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9327 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9328 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9329 I40E_INSET_IPV6_DST | I40E_INSET_TUNNEL_ID |
9330 I40E_INSET_FLEX_PAYLOAD,
9331 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9332 I40E_INSET_DMAC | I40E_INSET_SMAC |
9333 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9334 I40E_INSET_VLAN_TUNNEL | I40E_INSET_LAST_ETHER_TYPE |
9335 I40E_INSET_FLEX_PAYLOAD,
9339 * Flow director supports only fields defined in
9340 * union rte_eth_fdir_flow.
9342 static const uint64_t valid_fdir_inset_table[] = {
9343 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9344 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9345 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9346 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9347 I40E_INSET_IPV4_TTL,
9348 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9349 I40E_INSET_DMAC | I40E_INSET_SMAC |
9350 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9351 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9352 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9353 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9354 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9355 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9356 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9357 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9358 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9359 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9360 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9361 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9362 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9363 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9364 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9365 I40E_INSET_DMAC | I40E_INSET_SMAC |
9366 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9367 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9368 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9369 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9370 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9371 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9372 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9373 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9374 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9375 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9376 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9377 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9378 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9379 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9381 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9382 I40E_INSET_DMAC | I40E_INSET_SMAC |
9383 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9384 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9385 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9386 I40E_INSET_IPV4_TTL,
9387 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9388 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9389 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9390 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
9391 I40E_INSET_IPV6_HOP_LIMIT,
9392 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9393 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9394 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9395 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9396 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9397 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9398 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9399 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9400 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9401 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9402 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9403 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9404 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9405 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9406 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9407 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9408 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9409 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9410 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9411 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9412 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9413 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9414 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9415 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9416 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9417 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9418 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9419 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9420 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9421 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9423 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9424 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9425 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9426 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
9427 I40E_INSET_IPV6_HOP_LIMIT,
9428 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9429 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9430 I40E_INSET_LAST_ETHER_TYPE,
9433 if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
9435 if (filter == RTE_ETH_FILTER_HASH)
9436 valid = valid_hash_inset_table[pctype];
9438 valid = valid_fdir_inset_table[pctype];
9444 * Validate if the input set is allowed for a specific PCTYPE
9447 i40e_validate_input_set(enum i40e_filter_pctype pctype,
9448 enum rte_filter_type filter, uint64_t inset)
9452 valid = i40e_get_valid_input_set(pctype, filter);
9453 if (inset & (~valid))
9459 /* default input set fields combination per pctype */
9461 i40e_get_default_input_set(uint16_t pctype)
9463 static const uint64_t default_inset_table[] = {
9464 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9465 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
9466 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9467 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9468 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9469 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9470 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9471 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9472 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9473 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9474 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9475 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9476 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9477 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9478 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9479 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9480 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9481 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9482 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9483 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9485 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9486 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
9487 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9488 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
9489 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9490 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9491 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9492 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9493 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9494 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9495 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9496 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9497 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9498 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9499 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9500 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9501 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9502 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9503 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9504 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9505 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9506 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9508 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9509 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
9510 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9511 I40E_INSET_LAST_ETHER_TYPE,
9514 if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
9517 return default_inset_table[pctype];
9521 * Parse the input set from index to logical bit masks
9524 i40e_parse_input_set(uint64_t *inset,
9525 enum i40e_filter_pctype pctype,
9526 enum rte_eth_input_set_field *field,
9532 static const struct {
9533 enum rte_eth_input_set_field field;
9535 } inset_convert_table[] = {
9536 {RTE_ETH_INPUT_SET_NONE, I40E_INSET_NONE},
9537 {RTE_ETH_INPUT_SET_L2_SRC_MAC, I40E_INSET_SMAC},
9538 {RTE_ETH_INPUT_SET_L2_DST_MAC, I40E_INSET_DMAC},
9539 {RTE_ETH_INPUT_SET_L2_OUTER_VLAN, I40E_INSET_VLAN_OUTER},
9540 {RTE_ETH_INPUT_SET_L2_INNER_VLAN, I40E_INSET_VLAN_INNER},
9541 {RTE_ETH_INPUT_SET_L2_ETHERTYPE, I40E_INSET_LAST_ETHER_TYPE},
9542 {RTE_ETH_INPUT_SET_L3_SRC_IP4, I40E_INSET_IPV4_SRC},
9543 {RTE_ETH_INPUT_SET_L3_DST_IP4, I40E_INSET_IPV4_DST},
9544 {RTE_ETH_INPUT_SET_L3_IP4_TOS, I40E_INSET_IPV4_TOS},
9545 {RTE_ETH_INPUT_SET_L3_IP4_PROTO, I40E_INSET_IPV4_PROTO},
9546 {RTE_ETH_INPUT_SET_L3_IP4_TTL, I40E_INSET_IPV4_TTL},
9547 {RTE_ETH_INPUT_SET_L3_SRC_IP6, I40E_INSET_IPV6_SRC},
9548 {RTE_ETH_INPUT_SET_L3_DST_IP6, I40E_INSET_IPV6_DST},
9549 {RTE_ETH_INPUT_SET_L3_IP6_TC, I40E_INSET_IPV6_TC},
9550 {RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER,
9551 I40E_INSET_IPV6_NEXT_HDR},
9552 {RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS,
9553 I40E_INSET_IPV6_HOP_LIMIT},
9554 {RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT, I40E_INSET_SRC_PORT},
9555 {RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT, I40E_INSET_SRC_PORT},
9556 {RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT, I40E_INSET_SRC_PORT},
9557 {RTE_ETH_INPUT_SET_L4_UDP_DST_PORT, I40E_INSET_DST_PORT},
9558 {RTE_ETH_INPUT_SET_L4_TCP_DST_PORT, I40E_INSET_DST_PORT},
9559 {RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT, I40E_INSET_DST_PORT},
9560 {RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG,
9561 I40E_INSET_SCTP_VT},
9562 {RTE_ETH_INPUT_SET_TUNNEL_L2_INNER_DST_MAC,
9563 I40E_INSET_TUNNEL_DMAC},
9564 {RTE_ETH_INPUT_SET_TUNNEL_L2_INNER_VLAN,
9565 I40E_INSET_VLAN_TUNNEL},
9566 {RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY,
9567 I40E_INSET_TUNNEL_ID},
9568 {RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY, I40E_INSET_TUNNEL_ID},
9569 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD,
9570 I40E_INSET_FLEX_PAYLOAD_W1},
9571 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD,
9572 I40E_INSET_FLEX_PAYLOAD_W2},
9573 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD,
9574 I40E_INSET_FLEX_PAYLOAD_W3},
9575 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD,
9576 I40E_INSET_FLEX_PAYLOAD_W4},
9577 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD,
9578 I40E_INSET_FLEX_PAYLOAD_W5},
9579 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD,
9580 I40E_INSET_FLEX_PAYLOAD_W6},
9581 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD,
9582 I40E_INSET_FLEX_PAYLOAD_W7},
9583 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD,
9584 I40E_INSET_FLEX_PAYLOAD_W8},
9587 if (!inset || !field || size > RTE_ETH_INSET_SIZE_MAX)
9590 /* Only one item allowed for default or all */
9592 if (field[0] == RTE_ETH_INPUT_SET_DEFAULT) {
9593 *inset = i40e_get_default_input_set(pctype);
9595 } else if (field[0] == RTE_ETH_INPUT_SET_NONE) {
9596 *inset = I40E_INSET_NONE;
9601 for (i = 0, *inset = 0; i < size; i++) {
9602 for (j = 0; j < RTE_DIM(inset_convert_table); j++) {
9603 if (field[i] == inset_convert_table[j].field) {
9604 *inset |= inset_convert_table[j].inset;
9609 /* It contains unsupported input set, return immediately */
9610 if (j == RTE_DIM(inset_convert_table))
9618 * Translate the input set from bit masks to register aware bit masks
9622 i40e_translate_input_set_reg(enum i40e_mac_type type, uint64_t input)
9632 static const struct inset_map inset_map_common[] = {
9633 {I40E_INSET_DMAC, I40E_REG_INSET_L2_DMAC},
9634 {I40E_INSET_SMAC, I40E_REG_INSET_L2_SMAC},
9635 {I40E_INSET_VLAN_OUTER, I40E_REG_INSET_L2_OUTER_VLAN},
9636 {I40E_INSET_VLAN_INNER, I40E_REG_INSET_L2_INNER_VLAN},
9637 {I40E_INSET_LAST_ETHER_TYPE, I40E_REG_INSET_LAST_ETHER_TYPE},
9638 {I40E_INSET_IPV4_TOS, I40E_REG_INSET_L3_IP4_TOS},
9639 {I40E_INSET_IPV6_SRC, I40E_REG_INSET_L3_SRC_IP6},
9640 {I40E_INSET_IPV6_DST, I40E_REG_INSET_L3_DST_IP6},
9641 {I40E_INSET_IPV6_TC, I40E_REG_INSET_L3_IP6_TC},
9642 {I40E_INSET_IPV6_NEXT_HDR, I40E_REG_INSET_L3_IP6_NEXT_HDR},
9643 {I40E_INSET_IPV6_HOP_LIMIT, I40E_REG_INSET_L3_IP6_HOP_LIMIT},
9644 {I40E_INSET_SRC_PORT, I40E_REG_INSET_L4_SRC_PORT},
9645 {I40E_INSET_DST_PORT, I40E_REG_INSET_L4_DST_PORT},
9646 {I40E_INSET_SCTP_VT, I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG},
9647 {I40E_INSET_TUNNEL_ID, I40E_REG_INSET_TUNNEL_ID},
9648 {I40E_INSET_TUNNEL_DMAC,
9649 I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC},
9650 {I40E_INSET_TUNNEL_IPV4_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP4},
9651 {I40E_INSET_TUNNEL_IPV6_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP6},
9652 {I40E_INSET_TUNNEL_SRC_PORT,
9653 I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT},
9654 {I40E_INSET_TUNNEL_DST_PORT,
9655 I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT},
9656 {I40E_INSET_VLAN_TUNNEL, I40E_REG_INSET_TUNNEL_VLAN},
9657 {I40E_INSET_FLEX_PAYLOAD_W1, I40E_REG_INSET_FLEX_PAYLOAD_WORD1},
9658 {I40E_INSET_FLEX_PAYLOAD_W2, I40E_REG_INSET_FLEX_PAYLOAD_WORD2},
9659 {I40E_INSET_FLEX_PAYLOAD_W3, I40E_REG_INSET_FLEX_PAYLOAD_WORD3},
9660 {I40E_INSET_FLEX_PAYLOAD_W4, I40E_REG_INSET_FLEX_PAYLOAD_WORD4},
9661 {I40E_INSET_FLEX_PAYLOAD_W5, I40E_REG_INSET_FLEX_PAYLOAD_WORD5},
9662 {I40E_INSET_FLEX_PAYLOAD_W6, I40E_REG_INSET_FLEX_PAYLOAD_WORD6},
9663 {I40E_INSET_FLEX_PAYLOAD_W7, I40E_REG_INSET_FLEX_PAYLOAD_WORD7},
9664 {I40E_INSET_FLEX_PAYLOAD_W8, I40E_REG_INSET_FLEX_PAYLOAD_WORD8},
9667 /* some different registers map in x722*/
9668 static const struct inset_map inset_map_diff_x722[] = {
9669 {I40E_INSET_IPV4_SRC, I40E_X722_REG_INSET_L3_SRC_IP4},
9670 {I40E_INSET_IPV4_DST, I40E_X722_REG_INSET_L3_DST_IP4},
9671 {I40E_INSET_IPV4_PROTO, I40E_X722_REG_INSET_L3_IP4_PROTO},
9672 {I40E_INSET_IPV4_TTL, I40E_X722_REG_INSET_L3_IP4_TTL},
9675 static const struct inset_map inset_map_diff_not_x722[] = {
9676 {I40E_INSET_IPV4_SRC, I40E_REG_INSET_L3_SRC_IP4},
9677 {I40E_INSET_IPV4_DST, I40E_REG_INSET_L3_DST_IP4},
9678 {I40E_INSET_IPV4_PROTO, I40E_REG_INSET_L3_IP4_PROTO},
9679 {I40E_INSET_IPV4_TTL, I40E_REG_INSET_L3_IP4_TTL},
9685 /* Translate input set to register aware inset */
9686 if (type == I40E_MAC_X722) {
9687 for (i = 0; i < RTE_DIM(inset_map_diff_x722); i++) {
9688 if (input & inset_map_diff_x722[i].inset)
9689 val |= inset_map_diff_x722[i].inset_reg;
9692 for (i = 0; i < RTE_DIM(inset_map_diff_not_x722); i++) {
9693 if (input & inset_map_diff_not_x722[i].inset)
9694 val |= inset_map_diff_not_x722[i].inset_reg;
9698 for (i = 0; i < RTE_DIM(inset_map_common); i++) {
9699 if (input & inset_map_common[i].inset)
9700 val |= inset_map_common[i].inset_reg;
9707 i40e_generate_inset_mask_reg(uint64_t inset, uint32_t *mask, uint8_t nb_elem)
9710 uint64_t inset_need_mask = inset;
9712 static const struct {
9715 } inset_mask_map[] = {
9716 {I40E_INSET_IPV4_TOS, I40E_INSET_IPV4_TOS_MASK},
9717 {I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL, 0},
9718 {I40E_INSET_IPV4_PROTO, I40E_INSET_IPV4_PROTO_MASK},
9719 {I40E_INSET_IPV4_TTL, I40E_INSET_IPv4_TTL_MASK},
9720 {I40E_INSET_IPV6_TC, I40E_INSET_IPV6_TC_MASK},
9721 {I40E_INSET_IPV6_NEXT_HDR | I40E_INSET_IPV6_HOP_LIMIT, 0},
9722 {I40E_INSET_IPV6_NEXT_HDR, I40E_INSET_IPV6_NEXT_HDR_MASK},
9723 {I40E_INSET_IPV6_HOP_LIMIT, I40E_INSET_IPV6_HOP_LIMIT_MASK},
9726 if (!inset || !mask || !nb_elem)
9729 for (i = 0, idx = 0; i < RTE_DIM(inset_mask_map); i++) {
9730 /* Clear the inset bit, if no MASK is required,
9731 * for example proto + ttl
9733 if ((inset & inset_mask_map[i].inset) ==
9734 inset_mask_map[i].inset && inset_mask_map[i].mask == 0)
9735 inset_need_mask &= ~inset_mask_map[i].inset;
9736 if (!inset_need_mask)
9739 for (i = 0, idx = 0; i < RTE_DIM(inset_mask_map); i++) {
9740 if ((inset_need_mask & inset_mask_map[i].inset) ==
9741 inset_mask_map[i].inset) {
9742 if (idx >= nb_elem) {
9743 PMD_DRV_LOG(ERR, "exceed maximal number of bitmasks");
9746 mask[idx] = inset_mask_map[i].mask;
9755 i40e_check_write_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
9757 uint32_t reg = i40e_read_rx_ctl(hw, addr);
9759 PMD_DRV_LOG(DEBUG, "[0x%08x] original: 0x%08x", addr, reg);
9761 i40e_write_rx_ctl(hw, addr, val);
9762 PMD_DRV_LOG(DEBUG, "[0x%08x] after: 0x%08x", addr,
9763 (uint32_t)i40e_read_rx_ctl(hw, addr));
9767 i40e_check_write_global_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
9769 uint32_t reg = i40e_read_rx_ctl(hw, addr);
9770 struct rte_eth_dev *dev;
9772 dev = ((struct i40e_adapter *)hw->back)->eth_dev;
9774 i40e_write_rx_ctl(hw, addr, val);
9775 PMD_DRV_LOG(WARNING,
9776 "i40e device %s changed global register [0x%08x]."
9777 " original: 0x%08x, new: 0x%08x",
9778 dev->device->name, addr, reg,
9779 (uint32_t)i40e_read_rx_ctl(hw, addr));
9784 i40e_filter_input_set_init(struct i40e_pf *pf)
9786 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9787 enum i40e_filter_pctype pctype;
9788 uint64_t input_set, inset_reg;
9789 uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9793 for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
9794 pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++) {
9795 flow_type = i40e_pctype_to_flowtype(pf->adapter, pctype);
9797 if (flow_type == RTE_ETH_FLOW_UNKNOWN)
9800 input_set = i40e_get_default_input_set(pctype);
9802 num = i40e_generate_inset_mask_reg(input_set, mask_reg,
9803 I40E_INSET_MASK_NUM_REG);
9806 if (pf->support_multi_driver && num > 0) {
9807 PMD_DRV_LOG(ERR, "Input set setting is not supported.");
9810 inset_reg = i40e_translate_input_set_reg(hw->mac.type,
9813 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
9814 (uint32_t)(inset_reg & UINT32_MAX));
9815 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
9816 (uint32_t)((inset_reg >>
9817 I40E_32_BIT_WIDTH) & UINT32_MAX));
9818 if (!pf->support_multi_driver) {
9819 i40e_check_write_global_reg(hw,
9820 I40E_GLQF_HASH_INSET(0, pctype),
9821 (uint32_t)(inset_reg & UINT32_MAX));
9822 i40e_check_write_global_reg(hw,
9823 I40E_GLQF_HASH_INSET(1, pctype),
9824 (uint32_t)((inset_reg >>
9825 I40E_32_BIT_WIDTH) & UINT32_MAX));
9827 for (i = 0; i < num; i++) {
9828 i40e_check_write_global_reg(hw,
9829 I40E_GLQF_FD_MSK(i, pctype),
9831 i40e_check_write_global_reg(hw,
9832 I40E_GLQF_HASH_MSK(i, pctype),
9835 /*clear unused mask registers of the pctype */
9836 for (i = num; i < I40E_INSET_MASK_NUM_REG; i++) {
9837 i40e_check_write_global_reg(hw,
9838 I40E_GLQF_FD_MSK(i, pctype),
9840 i40e_check_write_global_reg(hw,
9841 I40E_GLQF_HASH_MSK(i, pctype),
9845 PMD_DRV_LOG(ERR, "Input set setting is not supported.");
9847 I40E_WRITE_FLUSH(hw);
9849 /* store the default input set */
9850 if (!pf->support_multi_driver)
9851 pf->hash_input_set[pctype] = input_set;
9852 pf->fdir.input_set[pctype] = input_set;
9857 i40e_hash_filter_inset_select(struct i40e_hw *hw,
9858 struct rte_eth_input_set_conf *conf)
9860 struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
9861 enum i40e_filter_pctype pctype;
9862 uint64_t input_set, inset_reg = 0;
9863 uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9867 PMD_DRV_LOG(ERR, "Invalid pointer");
9870 if (conf->op != RTE_ETH_INPUT_SET_SELECT &&
9871 conf->op != RTE_ETH_INPUT_SET_ADD) {
9872 PMD_DRV_LOG(ERR, "Unsupported input set operation");
9876 if (pf->support_multi_driver) {
9877 PMD_DRV_LOG(ERR, "Hash input set setting is not supported.");
9881 pctype = i40e_flowtype_to_pctype(pf->adapter, conf->flow_type);
9882 if (pctype == I40E_FILTER_PCTYPE_INVALID) {
9883 PMD_DRV_LOG(ERR, "invalid flow_type input.");
9887 if (hw->mac.type == I40E_MAC_X722) {
9888 /* get translated pctype value in fd pctype register */
9889 pctype = (enum i40e_filter_pctype)i40e_read_rx_ctl(hw,
9890 I40E_GLQF_FD_PCTYPES((int)pctype));
9893 ret = i40e_parse_input_set(&input_set, pctype, conf->field,
9896 PMD_DRV_LOG(ERR, "Failed to parse input set");
9900 if (conf->op == RTE_ETH_INPUT_SET_ADD) {
9901 /* get inset value in register */
9902 inset_reg = i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, pctype));
9903 inset_reg <<= I40E_32_BIT_WIDTH;
9904 inset_reg |= i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, pctype));
9905 input_set |= pf->hash_input_set[pctype];
9907 num = i40e_generate_inset_mask_reg(input_set, mask_reg,
9908 I40E_INSET_MASK_NUM_REG);
9912 inset_reg |= i40e_translate_input_set_reg(hw->mac.type, input_set);
9914 i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(0, pctype),
9915 (uint32_t)(inset_reg & UINT32_MAX));
9916 i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(1, pctype),
9917 (uint32_t)((inset_reg >>
9918 I40E_32_BIT_WIDTH) & UINT32_MAX));
9920 for (i = 0; i < num; i++)
9921 i40e_check_write_global_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
9923 /*clear unused mask registers of the pctype */
9924 for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
9925 i40e_check_write_global_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
9927 I40E_WRITE_FLUSH(hw);
9929 pf->hash_input_set[pctype] = input_set;
9934 i40e_fdir_filter_inset_select(struct i40e_pf *pf,
9935 struct rte_eth_input_set_conf *conf)
9937 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9938 enum i40e_filter_pctype pctype;
9939 uint64_t input_set, inset_reg = 0;
9940 uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9944 PMD_DRV_LOG(ERR, "Invalid pointer");
9947 if (conf->op != RTE_ETH_INPUT_SET_SELECT &&
9948 conf->op != RTE_ETH_INPUT_SET_ADD) {
9949 PMD_DRV_LOG(ERR, "Unsupported input set operation");
9953 pctype = i40e_flowtype_to_pctype(pf->adapter, conf->flow_type);
9955 if (pctype == I40E_FILTER_PCTYPE_INVALID) {
9956 PMD_DRV_LOG(ERR, "invalid flow_type input.");
9960 ret = i40e_parse_input_set(&input_set, pctype, conf->field,
9963 PMD_DRV_LOG(ERR, "Failed to parse input set");
9967 /* get inset value in register */
9968 inset_reg = i40e_read_rx_ctl(hw, I40E_PRTQF_FD_INSET(pctype, 1));
9969 inset_reg <<= I40E_32_BIT_WIDTH;
9970 inset_reg |= i40e_read_rx_ctl(hw, I40E_PRTQF_FD_INSET(pctype, 0));
9972 /* Can not change the inset reg for flex payload for fdir,
9973 * it is done by writing I40E_PRTQF_FD_FLXINSET
9974 * in i40e_set_flex_mask_on_pctype.
9976 if (conf->op == RTE_ETH_INPUT_SET_SELECT)
9977 inset_reg &= I40E_REG_INSET_FLEX_PAYLOAD_WORDS;
9979 input_set |= pf->fdir.input_set[pctype];
9980 num = i40e_generate_inset_mask_reg(input_set, mask_reg,
9981 I40E_INSET_MASK_NUM_REG);
9984 if (pf->support_multi_driver && num > 0) {
9985 PMD_DRV_LOG(ERR, "FDIR bit mask is not supported.");
9989 inset_reg |= i40e_translate_input_set_reg(hw->mac.type, input_set);
9991 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
9992 (uint32_t)(inset_reg & UINT32_MAX));
9993 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
9994 (uint32_t)((inset_reg >>
9995 I40E_32_BIT_WIDTH) & UINT32_MAX));
9997 if (!pf->support_multi_driver) {
9998 for (i = 0; i < num; i++)
9999 i40e_check_write_global_reg(hw,
10000 I40E_GLQF_FD_MSK(i, pctype),
10002 /*clear unused mask registers of the pctype */
10003 for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
10004 i40e_check_write_global_reg(hw,
10005 I40E_GLQF_FD_MSK(i, pctype),
10008 PMD_DRV_LOG(ERR, "FDIR bit mask is not supported.");
10010 I40E_WRITE_FLUSH(hw);
10012 pf->fdir.input_set[pctype] = input_set;
10017 i40e_hash_filter_get(struct i40e_hw *hw, struct rte_eth_hash_filter_info *info)
10021 if (!hw || !info) {
10022 PMD_DRV_LOG(ERR, "Invalid pointer");
10026 switch (info->info_type) {
10027 case RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT:
10028 i40e_get_symmetric_hash_enable_per_port(hw,
10029 &(info->info.enable));
10031 case RTE_ETH_HASH_FILTER_GLOBAL_CONFIG:
10032 ret = i40e_get_hash_filter_global_config(hw,
10033 &(info->info.global_conf));
10036 PMD_DRV_LOG(ERR, "Hash filter info type (%d) not supported",
10046 i40e_hash_filter_set(struct i40e_hw *hw, struct rte_eth_hash_filter_info *info)
10050 if (!hw || !info) {
10051 PMD_DRV_LOG(ERR, "Invalid pointer");
10055 switch (info->info_type) {
10056 case RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT:
10057 i40e_set_symmetric_hash_enable_per_port(hw, info->info.enable);
10059 case RTE_ETH_HASH_FILTER_GLOBAL_CONFIG:
10060 ret = i40e_set_hash_filter_global_config(hw,
10061 &(info->info.global_conf));
10063 case RTE_ETH_HASH_FILTER_INPUT_SET_SELECT:
10064 ret = i40e_hash_filter_inset_select(hw,
10065 &(info->info.input_set_conf));
10069 PMD_DRV_LOG(ERR, "Hash filter info type (%d) not supported",
10078 /* Operations for hash function */
10080 i40e_hash_filter_ctrl(struct rte_eth_dev *dev,
10081 enum rte_filter_op filter_op,
10084 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10087 switch (filter_op) {
10088 case RTE_ETH_FILTER_NOP:
10090 case RTE_ETH_FILTER_GET:
10091 ret = i40e_hash_filter_get(hw,
10092 (struct rte_eth_hash_filter_info *)arg);
10094 case RTE_ETH_FILTER_SET:
10095 ret = i40e_hash_filter_set(hw,
10096 (struct rte_eth_hash_filter_info *)arg);
10099 PMD_DRV_LOG(WARNING, "Filter operation (%d) not supported",
10108 /* Convert ethertype filter structure */
10110 i40e_ethertype_filter_convert(const struct rte_eth_ethertype_filter *input,
10111 struct i40e_ethertype_filter *filter)
10113 rte_memcpy(&filter->input.mac_addr, &input->mac_addr,
10114 RTE_ETHER_ADDR_LEN);
10115 filter->input.ether_type = input->ether_type;
10116 filter->flags = input->flags;
10117 filter->queue = input->queue;
10122 /* Check if there exists the ehtertype filter */
10123 struct i40e_ethertype_filter *
10124 i40e_sw_ethertype_filter_lookup(struct i40e_ethertype_rule *ethertype_rule,
10125 const struct i40e_ethertype_filter_input *input)
10129 ret = rte_hash_lookup(ethertype_rule->hash_table, (const void *)input);
10133 return ethertype_rule->hash_map[ret];
10136 /* Add ethertype filter in SW list */
10138 i40e_sw_ethertype_filter_insert(struct i40e_pf *pf,
10139 struct i40e_ethertype_filter *filter)
10141 struct i40e_ethertype_rule *rule = &pf->ethertype;
10144 ret = rte_hash_add_key(rule->hash_table, &filter->input);
10147 "Failed to insert ethertype filter"
10148 " to hash table %d!",
10152 rule->hash_map[ret] = filter;
10154 TAILQ_INSERT_TAIL(&rule->ethertype_list, filter, rules);
10159 /* Delete ethertype filter in SW list */
10161 i40e_sw_ethertype_filter_del(struct i40e_pf *pf,
10162 struct i40e_ethertype_filter_input *input)
10164 struct i40e_ethertype_rule *rule = &pf->ethertype;
10165 struct i40e_ethertype_filter *filter;
10168 ret = rte_hash_del_key(rule->hash_table, input);
10171 "Failed to delete ethertype filter"
10172 " to hash table %d!",
10176 filter = rule->hash_map[ret];
10177 rule->hash_map[ret] = NULL;
10179 TAILQ_REMOVE(&rule->ethertype_list, filter, rules);
10186 * Configure ethertype filter, which can director packet by filtering
10187 * with mac address and ether_type or only ether_type
10190 i40e_ethertype_filter_set(struct i40e_pf *pf,
10191 struct rte_eth_ethertype_filter *filter,
10194 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
10195 struct i40e_ethertype_rule *ethertype_rule = &pf->ethertype;
10196 struct i40e_ethertype_filter *ethertype_filter, *node;
10197 struct i40e_ethertype_filter check_filter;
10198 struct i40e_control_filter_stats stats;
10199 uint16_t flags = 0;
10202 if (filter->queue >= pf->dev_data->nb_rx_queues) {
10203 PMD_DRV_LOG(ERR, "Invalid queue ID");
10206 if (filter->ether_type == RTE_ETHER_TYPE_IPV4 ||
10207 filter->ether_type == RTE_ETHER_TYPE_IPV6) {
10209 "unsupported ether_type(0x%04x) in control packet filter.",
10210 filter->ether_type);
10213 if (filter->ether_type == RTE_ETHER_TYPE_VLAN)
10214 PMD_DRV_LOG(WARNING,
10215 "filter vlan ether_type in first tag is not supported.");
10217 /* Check if there is the filter in SW list */
10218 memset(&check_filter, 0, sizeof(check_filter));
10219 i40e_ethertype_filter_convert(filter, &check_filter);
10220 node = i40e_sw_ethertype_filter_lookup(ethertype_rule,
10221 &check_filter.input);
10223 PMD_DRV_LOG(ERR, "Conflict with existing ethertype rules!");
10227 if (!add && !node) {
10228 PMD_DRV_LOG(ERR, "There's no corresponding ethertype filter!");
10232 if (!(filter->flags & RTE_ETHTYPE_FLAGS_MAC))
10233 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
10234 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP)
10235 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
10236 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
10238 memset(&stats, 0, sizeof(stats));
10239 ret = i40e_aq_add_rem_control_packet_filter(hw,
10240 filter->mac_addr.addr_bytes,
10241 filter->ether_type, flags,
10242 pf->main_vsi->seid,
10243 filter->queue, add, &stats, NULL);
10246 "add/rem control packet filter, return %d, mac_etype_used = %u, etype_used = %u, mac_etype_free = %u, etype_free = %u",
10247 ret, stats.mac_etype_used, stats.etype_used,
10248 stats.mac_etype_free, stats.etype_free);
10252 /* Add or delete a filter in SW list */
10254 ethertype_filter = rte_zmalloc("ethertype_filter",
10255 sizeof(*ethertype_filter), 0);
10256 if (ethertype_filter == NULL) {
10257 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
10261 rte_memcpy(ethertype_filter, &check_filter,
10262 sizeof(check_filter));
10263 ret = i40e_sw_ethertype_filter_insert(pf, ethertype_filter);
10265 rte_free(ethertype_filter);
10267 ret = i40e_sw_ethertype_filter_del(pf, &node->input);
10274 * Handle operations for ethertype filter.
10277 i40e_ethertype_filter_handle(struct rte_eth_dev *dev,
10278 enum rte_filter_op filter_op,
10281 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
10284 if (filter_op == RTE_ETH_FILTER_NOP)
10288 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
10293 switch (filter_op) {
10294 case RTE_ETH_FILTER_ADD:
10295 ret = i40e_ethertype_filter_set(pf,
10296 (struct rte_eth_ethertype_filter *)arg,
10299 case RTE_ETH_FILTER_DELETE:
10300 ret = i40e_ethertype_filter_set(pf,
10301 (struct rte_eth_ethertype_filter *)arg,
10305 PMD_DRV_LOG(ERR, "unsupported operation %u", filter_op);
10313 i40e_dev_filter_ctrl(struct rte_eth_dev *dev,
10314 enum rte_filter_type filter_type,
10315 enum rte_filter_op filter_op,
10323 switch (filter_type) {
10324 case RTE_ETH_FILTER_NONE:
10325 /* For global configuration */
10326 ret = i40e_filter_ctrl_global_config(dev, filter_op, arg);
10328 case RTE_ETH_FILTER_HASH:
10329 ret = i40e_hash_filter_ctrl(dev, filter_op, arg);
10331 case RTE_ETH_FILTER_MACVLAN:
10332 ret = i40e_mac_filter_handle(dev, filter_op, arg);
10334 case RTE_ETH_FILTER_ETHERTYPE:
10335 ret = i40e_ethertype_filter_handle(dev, filter_op, arg);
10337 case RTE_ETH_FILTER_TUNNEL:
10338 ret = i40e_tunnel_filter_handle(dev, filter_op, arg);
10340 case RTE_ETH_FILTER_FDIR:
10341 ret = i40e_fdir_ctrl_func(dev, filter_op, arg);
10343 case RTE_ETH_FILTER_GENERIC:
10344 if (filter_op != RTE_ETH_FILTER_GET)
10346 *(const void **)arg = &i40e_flow_ops;
10349 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
10359 * Check and enable Extended Tag.
10360 * Enabling Extended Tag is important for 40G performance.
10363 i40e_enable_extended_tag(struct rte_eth_dev *dev)
10365 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
10369 ret = rte_pci_read_config(pci_dev, &buf, sizeof(buf),
10372 PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
10376 if (!(buf & PCI_DEV_CAP_EXT_TAG_MASK)) {
10377 PMD_DRV_LOG(ERR, "Does not support Extended Tag");
10382 ret = rte_pci_read_config(pci_dev, &buf, sizeof(buf),
10385 PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
10389 if (buf & PCI_DEV_CTRL_EXT_TAG_MASK) {
10390 PMD_DRV_LOG(DEBUG, "Extended Tag has already been enabled");
10393 buf |= PCI_DEV_CTRL_EXT_TAG_MASK;
10394 ret = rte_pci_write_config(pci_dev, &buf, sizeof(buf),
10397 PMD_DRV_LOG(ERR, "Failed to write PCI offset 0x%x",
10404 * As some registers wouldn't be reset unless a global hardware reset,
10405 * hardware initialization is needed to put those registers into an
10406 * expected initial state.
10409 i40e_hw_init(struct rte_eth_dev *dev)
10411 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10413 i40e_enable_extended_tag(dev);
10415 /* clear the PF Queue Filter control register */
10416 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, 0);
10418 /* Disable symmetric hash per port */
10419 i40e_set_symmetric_hash_enable_per_port(hw, 0);
10423 * For X722 it is possible to have multiple pctypes mapped to the same flowtype
10424 * however this function will return only one highest pctype index,
10425 * which is not quite correct. This is known problem of i40e driver
10426 * and needs to be fixed later.
10428 enum i40e_filter_pctype
10429 i40e_flowtype_to_pctype(const struct i40e_adapter *adapter, uint16_t flow_type)
10432 uint64_t pctype_mask;
10434 if (flow_type < I40E_FLOW_TYPE_MAX) {
10435 pctype_mask = adapter->pctypes_tbl[flow_type];
10436 for (i = I40E_FILTER_PCTYPE_MAX - 1; i > 0; i--) {
10437 if (pctype_mask & (1ULL << i))
10438 return (enum i40e_filter_pctype)i;
10441 return I40E_FILTER_PCTYPE_INVALID;
10445 i40e_pctype_to_flowtype(const struct i40e_adapter *adapter,
10446 enum i40e_filter_pctype pctype)
10449 uint64_t pctype_mask = 1ULL << pctype;
10451 for (flowtype = RTE_ETH_FLOW_UNKNOWN + 1; flowtype < I40E_FLOW_TYPE_MAX;
10453 if (adapter->pctypes_tbl[flowtype] & pctype_mask)
10457 return RTE_ETH_FLOW_UNKNOWN;
10461 * On X710, performance number is far from the expectation on recent firmware
10462 * versions; on XL710, performance number is also far from the expectation on
10463 * recent firmware versions, if promiscuous mode is disabled, or promiscuous
10464 * mode is enabled and port MAC address is equal to the packet destination MAC
10465 * address. The fix for this issue may not be integrated in the following
10466 * firmware version. So the workaround in software driver is needed. It needs
10467 * to modify the initial values of 3 internal only registers for both X710 and
10468 * XL710. Note that the values for X710 or XL710 could be different, and the
10469 * workaround can be removed when it is fixed in firmware in the future.
10472 /* For both X710 and XL710 */
10473 #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1 0x10000200
10474 #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2 0x203F0200
10475 #define I40E_GL_SWR_PRI_JOIN_MAP_0 0x26CE00
10477 #define I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x011f0200
10478 #define I40E_GL_SWR_PRI_JOIN_MAP_2 0x26CE08
10481 #define I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE 0x20000200
10482 #define I40E_X722_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x013F0200
10485 #define I40E_GL_SWR_PM_UP_THR_EF_VALUE 0x03030303
10487 #define I40E_GL_SWR_PM_UP_THR_SF_VALUE 0x06060606
10488 #define I40E_GL_SWR_PM_UP_THR 0x269FBC
10491 * GL_SWR_PM_UP_THR:
10492 * The value is not impacted from the link speed, its value is set according
10493 * to the total number of ports for a better pipe-monitor configuration.
10496 i40e_get_swr_pm_cfg(struct i40e_hw *hw, uint32_t *value)
10498 #define I40E_GL_SWR_PM_EF_DEVICE(dev) \
10499 .device_id = (dev), \
10500 .val = I40E_GL_SWR_PM_UP_THR_EF_VALUE
10502 #define I40E_GL_SWR_PM_SF_DEVICE(dev) \
10503 .device_id = (dev), \
10504 .val = I40E_GL_SWR_PM_UP_THR_SF_VALUE
10506 static const struct {
10507 uint16_t device_id;
10509 } swr_pm_table[] = {
10510 { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_SFP_XL710) },
10511 { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_KX_C) },
10512 { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_10G_BASE_T) },
10513 { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_10G_BASE_T4) },
10514 { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_SFP_X722) },
10516 { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_KX_B) },
10517 { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_QSFP_A) },
10518 { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_QSFP_B) },
10519 { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_20G_KR2) },
10520 { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_20G_KR2_A) },
10521 { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_25G_B) },
10522 { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_25G_SFP28) },
10526 if (value == NULL) {
10527 PMD_DRV_LOG(ERR, "value is NULL");
10531 for (i = 0; i < RTE_DIM(swr_pm_table); i++) {
10532 if (hw->device_id == swr_pm_table[i].device_id) {
10533 *value = swr_pm_table[i].val;
10535 PMD_DRV_LOG(DEBUG, "Device 0x%x with GL_SWR_PM_UP_THR "
10537 hw->device_id, *value);
10546 i40e_dev_sync_phy_type(struct i40e_hw *hw)
10548 enum i40e_status_code status;
10549 struct i40e_aq_get_phy_abilities_resp phy_ab;
10550 int ret = -ENOTSUP;
10553 status = i40e_aq_get_phy_capabilities(hw, false, true, &phy_ab,
10557 PMD_INIT_LOG(WARNING, "Failed to sync phy type: status=%d",
10560 rte_delay_us(100000);
10562 status = i40e_aq_get_phy_capabilities(hw, false,
10563 true, &phy_ab, NULL);
10571 i40e_configure_registers(struct i40e_hw *hw)
10577 {I40E_GL_SWR_PRI_JOIN_MAP_0, 0},
10578 {I40E_GL_SWR_PRI_JOIN_MAP_2, 0},
10579 {I40E_GL_SWR_PM_UP_THR, 0}, /* Compute value dynamically */
10585 for (i = 0; i < RTE_DIM(reg_table); i++) {
10586 if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_0) {
10587 if (hw->mac.type == I40E_MAC_X722) /* For X722 */
10589 I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE;
10590 else /* For X710/XL710/XXV710 */
10591 if (hw->aq.fw_maj_ver < 6)
10593 I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1;
10596 I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2;
10599 if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_2) {
10600 if (hw->mac.type == I40E_MAC_X722) /* For X722 */
10602 I40E_X722_GL_SWR_PRI_JOIN_MAP_2_VALUE;
10603 else /* For X710/XL710/XXV710 */
10605 I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE;
10608 if (reg_table[i].addr == I40E_GL_SWR_PM_UP_THR) {
10611 if (!i40e_get_swr_pm_cfg(hw, &cfg_val)) {
10612 PMD_DRV_LOG(DEBUG, "Device 0x%x skips "
10613 "GL_SWR_PM_UP_THR value fixup",
10618 reg_table[i].val = cfg_val;
10621 ret = i40e_aq_debug_read_register(hw, reg_table[i].addr,
10624 PMD_DRV_LOG(ERR, "Failed to read from 0x%"PRIx32,
10625 reg_table[i].addr);
10628 PMD_DRV_LOG(DEBUG, "Read from 0x%"PRIx32": 0x%"PRIx64,
10629 reg_table[i].addr, reg);
10630 if (reg == reg_table[i].val)
10633 ret = i40e_aq_debug_write_register(hw, reg_table[i].addr,
10634 reg_table[i].val, NULL);
10637 "Failed to write 0x%"PRIx64" to the address of 0x%"PRIx32,
10638 reg_table[i].val, reg_table[i].addr);
10641 PMD_DRV_LOG(DEBUG, "Write 0x%"PRIx64" to the address of "
10642 "0x%"PRIx32, reg_table[i].val, reg_table[i].addr);
10646 #define I40E_VSI_TSR(_i) (0x00050800 + ((_i) * 4))
10647 #define I40E_VSI_TSR_QINQ_CONFIG 0xc030
10648 #define I40E_VSI_L2TAGSTXVALID(_i) (0x00042800 + ((_i) * 4))
10649 #define I40E_VSI_L2TAGSTXVALID_QINQ 0xab
10651 i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi)
10656 if (vsi->vsi_id >= I40E_MAX_NUM_VSIS) {
10657 PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
10661 /* Configure for double VLAN RX stripping */
10662 reg = I40E_READ_REG(hw, I40E_VSI_TSR(vsi->vsi_id));
10663 if ((reg & I40E_VSI_TSR_QINQ_CONFIG) != I40E_VSI_TSR_QINQ_CONFIG) {
10664 reg |= I40E_VSI_TSR_QINQ_CONFIG;
10665 ret = i40e_aq_debug_write_register(hw,
10666 I40E_VSI_TSR(vsi->vsi_id),
10669 PMD_DRV_LOG(ERR, "Failed to update VSI_TSR[%d]",
10671 return I40E_ERR_CONFIG;
10675 /* Configure for double VLAN TX insertion */
10676 reg = I40E_READ_REG(hw, I40E_VSI_L2TAGSTXVALID(vsi->vsi_id));
10677 if ((reg & 0xff) != I40E_VSI_L2TAGSTXVALID_QINQ) {
10678 reg = I40E_VSI_L2TAGSTXVALID_QINQ;
10679 ret = i40e_aq_debug_write_register(hw,
10680 I40E_VSI_L2TAGSTXVALID(
10681 vsi->vsi_id), reg, NULL);
10684 "Failed to update VSI_L2TAGSTXVALID[%d]",
10686 return I40E_ERR_CONFIG;
10694 * i40e_aq_add_mirror_rule
10695 * @hw: pointer to the hardware structure
10696 * @seid: VEB seid to add mirror rule to
10697 * @dst_id: destination vsi seid
10698 * @entries: Buffer which contains the entities to be mirrored
10699 * @count: number of entities contained in the buffer
10700 * @rule_id:the rule_id of the rule to be added
10702 * Add a mirror rule for a given veb.
10705 static enum i40e_status_code
10706 i40e_aq_add_mirror_rule(struct i40e_hw *hw,
10707 uint16_t seid, uint16_t dst_id,
10708 uint16_t rule_type, uint16_t *entries,
10709 uint16_t count, uint16_t *rule_id)
10711 struct i40e_aq_desc desc;
10712 struct i40e_aqc_add_delete_mirror_rule cmd;
10713 struct i40e_aqc_add_delete_mirror_rule_completion *resp =
10714 (struct i40e_aqc_add_delete_mirror_rule_completion *)
10717 enum i40e_status_code status;
10719 i40e_fill_default_direct_cmd_desc(&desc,
10720 i40e_aqc_opc_add_mirror_rule);
10721 memset(&cmd, 0, sizeof(cmd));
10723 buff_len = sizeof(uint16_t) * count;
10724 desc.datalen = rte_cpu_to_le_16(buff_len);
10726 desc.flags |= rte_cpu_to_le_16(
10727 (uint16_t)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
10728 cmd.rule_type = rte_cpu_to_le_16(rule_type <<
10729 I40E_AQC_MIRROR_RULE_TYPE_SHIFT);
10730 cmd.num_entries = rte_cpu_to_le_16(count);
10731 cmd.seid = rte_cpu_to_le_16(seid);
10732 cmd.destination = rte_cpu_to_le_16(dst_id);
10734 rte_memcpy(&desc.params.raw, &cmd, sizeof(cmd));
10735 status = i40e_asq_send_command(hw, &desc, entries, buff_len, NULL);
10737 "i40e_aq_add_mirror_rule, aq_status %d, rule_id = %u mirror_rules_used = %u, mirror_rules_free = %u,",
10738 hw->aq.asq_last_status, resp->rule_id,
10739 resp->mirror_rules_used, resp->mirror_rules_free);
10740 *rule_id = rte_le_to_cpu_16(resp->rule_id);
10746 * i40e_aq_del_mirror_rule
10747 * @hw: pointer to the hardware structure
10748 * @seid: VEB seid to add mirror rule to
10749 * @entries: Buffer which contains the entities to be mirrored
10750 * @count: number of entities contained in the buffer
10751 * @rule_id:the rule_id of the rule to be delete
10753 * Delete a mirror rule for a given veb.
10756 static enum i40e_status_code
10757 i40e_aq_del_mirror_rule(struct i40e_hw *hw,
10758 uint16_t seid, uint16_t rule_type, uint16_t *entries,
10759 uint16_t count, uint16_t rule_id)
10761 struct i40e_aq_desc desc;
10762 struct i40e_aqc_add_delete_mirror_rule cmd;
10763 uint16_t buff_len = 0;
10764 enum i40e_status_code status;
10767 i40e_fill_default_direct_cmd_desc(&desc,
10768 i40e_aqc_opc_delete_mirror_rule);
10769 memset(&cmd, 0, sizeof(cmd));
10770 if (rule_type == I40E_AQC_MIRROR_RULE_TYPE_VLAN) {
10771 desc.flags |= rte_cpu_to_le_16((uint16_t)(I40E_AQ_FLAG_BUF |
10773 cmd.num_entries = count;
10774 buff_len = sizeof(uint16_t) * count;
10775 desc.datalen = rte_cpu_to_le_16(buff_len);
10776 buff = (void *)entries;
10778 /* rule id is filled in destination field for deleting mirror rule */
10779 cmd.destination = rte_cpu_to_le_16(rule_id);
10781 cmd.rule_type = rte_cpu_to_le_16(rule_type <<
10782 I40E_AQC_MIRROR_RULE_TYPE_SHIFT);
10783 cmd.seid = rte_cpu_to_le_16(seid);
10785 rte_memcpy(&desc.params.raw, &cmd, sizeof(cmd));
10786 status = i40e_asq_send_command(hw, &desc, buff, buff_len, NULL);
10792 * i40e_mirror_rule_set
10793 * @dev: pointer to the hardware structure
10794 * @mirror_conf: mirror rule info
10795 * @sw_id: mirror rule's sw_id
10796 * @on: enable/disable
10798 * set a mirror rule.
10802 i40e_mirror_rule_set(struct rte_eth_dev *dev,
10803 struct rte_eth_mirror_conf *mirror_conf,
10804 uint8_t sw_id, uint8_t on)
10806 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
10807 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10808 struct i40e_mirror_rule *it, *mirr_rule = NULL;
10809 struct i40e_mirror_rule *parent = NULL;
10810 uint16_t seid, dst_seid, rule_id;
10814 PMD_DRV_LOG(DEBUG, "i40e_mirror_rule_set: sw_id = %d.", sw_id);
10816 if (pf->main_vsi->veb == NULL || pf->vfs == NULL) {
10818 "mirror rule can not be configured without veb or vfs.");
10821 if (pf->nb_mirror_rule > I40E_MAX_MIRROR_RULES) {
10822 PMD_DRV_LOG(ERR, "mirror table is full.");
10825 if (mirror_conf->dst_pool > pf->vf_num) {
10826 PMD_DRV_LOG(ERR, "invalid destination pool %u.",
10827 mirror_conf->dst_pool);
10831 seid = pf->main_vsi->veb->seid;
10833 TAILQ_FOREACH(it, &pf->mirror_list, rules) {
10834 if (sw_id <= it->index) {
10840 if (mirr_rule && sw_id == mirr_rule->index) {
10842 PMD_DRV_LOG(ERR, "mirror rule exists.");
10845 ret = i40e_aq_del_mirror_rule(hw, seid,
10846 mirr_rule->rule_type,
10847 mirr_rule->entries,
10848 mirr_rule->num_entries, mirr_rule->id);
10851 "failed to remove mirror rule: ret = %d, aq_err = %d.",
10852 ret, hw->aq.asq_last_status);
10855 TAILQ_REMOVE(&pf->mirror_list, mirr_rule, rules);
10856 rte_free(mirr_rule);
10857 pf->nb_mirror_rule--;
10861 PMD_DRV_LOG(ERR, "mirror rule doesn't exist.");
10865 mirr_rule = rte_zmalloc("i40e_mirror_rule",
10866 sizeof(struct i40e_mirror_rule) , 0);
10868 PMD_DRV_LOG(ERR, "failed to allocate memory");
10869 return I40E_ERR_NO_MEMORY;
10871 switch (mirror_conf->rule_type) {
10872 case ETH_MIRROR_VLAN:
10873 for (i = 0, j = 0; i < ETH_MIRROR_MAX_VLANS; i++) {
10874 if (mirror_conf->vlan.vlan_mask & (1ULL << i)) {
10875 mirr_rule->entries[j] =
10876 mirror_conf->vlan.vlan_id[i];
10881 PMD_DRV_LOG(ERR, "vlan is not specified.");
10882 rte_free(mirr_rule);
10885 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_VLAN;
10887 case ETH_MIRROR_VIRTUAL_POOL_UP:
10888 case ETH_MIRROR_VIRTUAL_POOL_DOWN:
10889 /* check if the specified pool bit is out of range */
10890 if (mirror_conf->pool_mask > (uint64_t)(1ULL << (pf->vf_num + 1))) {
10891 PMD_DRV_LOG(ERR, "pool mask is out of range.");
10892 rte_free(mirr_rule);
10895 for (i = 0, j = 0; i < pf->vf_num; i++) {
10896 if (mirror_conf->pool_mask & (1ULL << i)) {
10897 mirr_rule->entries[j] = pf->vfs[i].vsi->seid;
10901 if (mirror_conf->pool_mask & (1ULL << pf->vf_num)) {
10902 /* add pf vsi to entries */
10903 mirr_rule->entries[j] = pf->main_vsi_seid;
10907 PMD_DRV_LOG(ERR, "pool is not specified.");
10908 rte_free(mirr_rule);
10911 /* egress and ingress in aq commands means from switch but not port */
10912 mirr_rule->rule_type =
10913 (mirror_conf->rule_type == ETH_MIRROR_VIRTUAL_POOL_UP) ?
10914 I40E_AQC_MIRROR_RULE_TYPE_VPORT_EGRESS :
10915 I40E_AQC_MIRROR_RULE_TYPE_VPORT_INGRESS;
10917 case ETH_MIRROR_UPLINK_PORT:
10918 /* egress and ingress in aq commands means from switch but not port*/
10919 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_ALL_EGRESS;
10921 case ETH_MIRROR_DOWNLINK_PORT:
10922 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_ALL_INGRESS;
10925 PMD_DRV_LOG(ERR, "unsupported mirror type %d.",
10926 mirror_conf->rule_type);
10927 rte_free(mirr_rule);
10931 /* If the dst_pool is equal to vf_num, consider it as PF */
10932 if (mirror_conf->dst_pool == pf->vf_num)
10933 dst_seid = pf->main_vsi_seid;
10935 dst_seid = pf->vfs[mirror_conf->dst_pool].vsi->seid;
10937 ret = i40e_aq_add_mirror_rule(hw, seid, dst_seid,
10938 mirr_rule->rule_type, mirr_rule->entries,
10942 "failed to add mirror rule: ret = %d, aq_err = %d.",
10943 ret, hw->aq.asq_last_status);
10944 rte_free(mirr_rule);
10948 mirr_rule->index = sw_id;
10949 mirr_rule->num_entries = j;
10950 mirr_rule->id = rule_id;
10951 mirr_rule->dst_vsi_seid = dst_seid;
10954 TAILQ_INSERT_AFTER(&pf->mirror_list, parent, mirr_rule, rules);
10956 TAILQ_INSERT_HEAD(&pf->mirror_list, mirr_rule, rules);
10958 pf->nb_mirror_rule++;
10963 * i40e_mirror_rule_reset
10964 * @dev: pointer to the device
10965 * @sw_id: mirror rule's sw_id
10967 * reset a mirror rule.
10971 i40e_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t sw_id)
10973 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
10974 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10975 struct i40e_mirror_rule *it, *mirr_rule = NULL;
10979 PMD_DRV_LOG(DEBUG, "i40e_mirror_rule_reset: sw_id = %d.", sw_id);
10981 seid = pf->main_vsi->veb->seid;
10983 TAILQ_FOREACH(it, &pf->mirror_list, rules) {
10984 if (sw_id == it->index) {
10990 ret = i40e_aq_del_mirror_rule(hw, seid,
10991 mirr_rule->rule_type,
10992 mirr_rule->entries,
10993 mirr_rule->num_entries, mirr_rule->id);
10996 "failed to remove mirror rule: status = %d, aq_err = %d.",
10997 ret, hw->aq.asq_last_status);
11000 TAILQ_REMOVE(&pf->mirror_list, mirr_rule, rules);
11001 rte_free(mirr_rule);
11002 pf->nb_mirror_rule--;
11004 PMD_DRV_LOG(ERR, "mirror rule doesn't exist.");
11011 i40e_read_systime_cyclecounter(struct rte_eth_dev *dev)
11013 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11014 uint64_t systim_cycles;
11016 systim_cycles = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_L);
11017 systim_cycles |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_H)
11020 return systim_cycles;
11024 i40e_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev, uint8_t index)
11026 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11027 uint64_t rx_tstamp;
11029 rx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_L(index));
11030 rx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(index))
11037 i40e_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
11039 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11040 uint64_t tx_tstamp;
11042 tx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_L);
11043 tx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H)
11050 i40e_start_timecounters(struct rte_eth_dev *dev)
11052 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11053 struct i40e_adapter *adapter = dev->data->dev_private;
11054 struct rte_eth_link link;
11055 uint32_t tsync_inc_l;
11056 uint32_t tsync_inc_h;
11058 /* Get current link speed. */
11059 i40e_dev_link_update(dev, 1);
11060 rte_eth_linkstatus_get(dev, &link);
11062 switch (link.link_speed) {
11063 case ETH_SPEED_NUM_40G:
11064 case ETH_SPEED_NUM_25G:
11065 tsync_inc_l = I40E_PTP_40GB_INCVAL & 0xFFFFFFFF;
11066 tsync_inc_h = I40E_PTP_40GB_INCVAL >> 32;
11068 case ETH_SPEED_NUM_10G:
11069 tsync_inc_l = I40E_PTP_10GB_INCVAL & 0xFFFFFFFF;
11070 tsync_inc_h = I40E_PTP_10GB_INCVAL >> 32;
11072 case ETH_SPEED_NUM_1G:
11073 tsync_inc_l = I40E_PTP_1GB_INCVAL & 0xFFFFFFFF;
11074 tsync_inc_h = I40E_PTP_1GB_INCVAL >> 32;
11081 /* Set the timesync increment value. */
11082 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, tsync_inc_l);
11083 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, tsync_inc_h);
11085 memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
11086 memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
11087 memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
11089 adapter->systime_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
11090 adapter->systime_tc.cc_shift = 0;
11091 adapter->systime_tc.nsec_mask = 0;
11093 adapter->rx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
11094 adapter->rx_tstamp_tc.cc_shift = 0;
11095 adapter->rx_tstamp_tc.nsec_mask = 0;
11097 adapter->tx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
11098 adapter->tx_tstamp_tc.cc_shift = 0;
11099 adapter->tx_tstamp_tc.nsec_mask = 0;
11103 i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
11105 struct i40e_adapter *adapter = dev->data->dev_private;
11107 adapter->systime_tc.nsec += delta;
11108 adapter->rx_tstamp_tc.nsec += delta;
11109 adapter->tx_tstamp_tc.nsec += delta;
11115 i40e_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
11118 struct i40e_adapter *adapter = dev->data->dev_private;
11120 ns = rte_timespec_to_ns(ts);
11122 /* Set the timecounters to a new value. */
11123 adapter->systime_tc.nsec = ns;
11124 adapter->rx_tstamp_tc.nsec = ns;
11125 adapter->tx_tstamp_tc.nsec = ns;
11131 i40e_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
11133 uint64_t ns, systime_cycles;
11134 struct i40e_adapter *adapter = dev->data->dev_private;
11136 systime_cycles = i40e_read_systime_cyclecounter(dev);
11137 ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
11138 *ts = rte_ns_to_timespec(ns);
11144 i40e_timesync_enable(struct rte_eth_dev *dev)
11146 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11147 uint32_t tsync_ctl_l;
11148 uint32_t tsync_ctl_h;
11150 /* Stop the timesync system time. */
11151 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
11152 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
11153 /* Reset the timesync system time value. */
11154 I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_L, 0x0);
11155 I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_H, 0x0);
11157 i40e_start_timecounters(dev);
11159 /* Clear timesync registers. */
11160 I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
11161 I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H);
11162 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(0));
11163 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(1));
11164 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(2));
11165 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(3));
11167 /* Enable timestamping of PTP packets. */
11168 tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
11169 tsync_ctl_l |= I40E_PRTTSYN_TSYNENA;
11171 tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
11172 tsync_ctl_h |= I40E_PRTTSYN_TSYNENA;
11173 tsync_ctl_h |= I40E_PRTTSYN_TSYNTYPE;
11175 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
11176 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
11182 i40e_timesync_disable(struct rte_eth_dev *dev)
11184 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11185 uint32_t tsync_ctl_l;
11186 uint32_t tsync_ctl_h;
11188 /* Disable timestamping of transmitted PTP packets. */
11189 tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
11190 tsync_ctl_l &= ~I40E_PRTTSYN_TSYNENA;
11192 tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
11193 tsync_ctl_h &= ~I40E_PRTTSYN_TSYNENA;
11195 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
11196 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
11198 /* Reset the timesync increment value. */
11199 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
11200 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
11206 i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
11207 struct timespec *timestamp, uint32_t flags)
11209 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11210 struct i40e_adapter *adapter = dev->data->dev_private;
11211 uint32_t sync_status;
11212 uint32_t index = flags & 0x03;
11213 uint64_t rx_tstamp_cycles;
11216 sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_1);
11217 if ((sync_status & (1 << index)) == 0)
11220 rx_tstamp_cycles = i40e_read_rx_tstamp_cyclecounter(dev, index);
11221 ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
11222 *timestamp = rte_ns_to_timespec(ns);
11228 i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
11229 struct timespec *timestamp)
11231 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11232 struct i40e_adapter *adapter = dev->data->dev_private;
11233 uint32_t sync_status;
11234 uint64_t tx_tstamp_cycles;
11237 sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
11238 if ((sync_status & I40E_PRTTSYN_STAT_0_TXTIME_MASK) == 0)
11241 tx_tstamp_cycles = i40e_read_tx_tstamp_cyclecounter(dev);
11242 ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
11243 *timestamp = rte_ns_to_timespec(ns);
11249 * i40e_parse_dcb_configure - parse dcb configure from user
11250 * @dev: the device being configured
11251 * @dcb_cfg: pointer of the result of parse
11252 * @*tc_map: bit map of enabled traffic classes
11254 * Returns 0 on success, negative value on failure
11257 i40e_parse_dcb_configure(struct rte_eth_dev *dev,
11258 struct i40e_dcbx_config *dcb_cfg,
11261 struct rte_eth_dcb_rx_conf *dcb_rx_conf;
11262 uint8_t i, tc_bw, bw_lf;
11264 memset(dcb_cfg, 0, sizeof(struct i40e_dcbx_config));
11266 dcb_rx_conf = &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
11267 if (dcb_rx_conf->nb_tcs > I40E_MAX_TRAFFIC_CLASS) {
11268 PMD_INIT_LOG(ERR, "number of tc exceeds max.");
11272 /* assume each tc has the same bw */
11273 tc_bw = I40E_MAX_PERCENT / dcb_rx_conf->nb_tcs;
11274 for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
11275 dcb_cfg->etscfg.tcbwtable[i] = tc_bw;
11276 /* to ensure the sum of tcbw is equal to 100 */
11277 bw_lf = I40E_MAX_PERCENT % dcb_rx_conf->nb_tcs;
11278 for (i = 0; i < bw_lf; i++)
11279 dcb_cfg->etscfg.tcbwtable[i]++;
11281 /* assume each tc has the same Transmission Selection Algorithm */
11282 for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
11283 dcb_cfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
11285 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
11286 dcb_cfg->etscfg.prioritytable[i] =
11287 dcb_rx_conf->dcb_tc[i];
11289 /* FW needs one App to configure HW */
11290 dcb_cfg->numapps = I40E_DEFAULT_DCB_APP_NUM;
11291 dcb_cfg->app[0].selector = I40E_APP_SEL_ETHTYPE;
11292 dcb_cfg->app[0].priority = I40E_DEFAULT_DCB_APP_PRIO;
11293 dcb_cfg->app[0].protocolid = I40E_APP_PROTOID_FCOE;
11295 if (dcb_rx_conf->nb_tcs == 0)
11296 *tc_map = 1; /* tc0 only */
11298 *tc_map = RTE_LEN2MASK(dcb_rx_conf->nb_tcs, uint8_t);
11300 if (dev->data->dev_conf.dcb_capability_en & ETH_DCB_PFC_SUPPORT) {
11301 dcb_cfg->pfc.willing = 0;
11302 dcb_cfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
11303 dcb_cfg->pfc.pfcenable = *tc_map;
11309 static enum i40e_status_code
11310 i40e_vsi_update_queue_mapping(struct i40e_vsi *vsi,
11311 struct i40e_aqc_vsi_properties_data *info,
11312 uint8_t enabled_tcmap)
11314 enum i40e_status_code ret;
11315 int i, total_tc = 0;
11316 uint16_t qpnum_per_tc, bsf, qp_idx;
11317 struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(vsi);
11318 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
11319 uint16_t used_queues;
11321 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
11322 if (ret != I40E_SUCCESS)
11325 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11326 if (enabled_tcmap & (1 << i))
11331 vsi->enabled_tc = enabled_tcmap;
11333 /* different VSI has different queues assigned */
11334 if (vsi->type == I40E_VSI_MAIN)
11335 used_queues = dev_data->nb_rx_queues -
11336 pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
11337 else if (vsi->type == I40E_VSI_VMDQ2)
11338 used_queues = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
11340 PMD_INIT_LOG(ERR, "unsupported VSI type.");
11341 return I40E_ERR_NO_AVAILABLE_VSI;
11344 qpnum_per_tc = used_queues / total_tc;
11345 /* Number of queues per enabled TC */
11346 if (qpnum_per_tc == 0) {
11347 PMD_INIT_LOG(ERR, " number of queues is less that tcs.");
11348 return I40E_ERR_INVALID_QP_ID;
11350 qpnum_per_tc = RTE_MIN(i40e_align_floor(qpnum_per_tc),
11351 I40E_MAX_Q_PER_TC);
11352 bsf = rte_bsf32(qpnum_per_tc);
11355 * Configure TC and queue mapping parameters, for enabled TC,
11356 * allocate qpnum_per_tc queues to this traffic. For disabled TC,
11357 * default queue will serve it.
11360 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11361 if (vsi->enabled_tc & (1 << i)) {
11362 info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
11363 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
11364 (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
11365 qp_idx += qpnum_per_tc;
11367 info->tc_mapping[i] = 0;
11370 /* Associate queue number with VSI, Keep vsi->nb_qps unchanged */
11371 if (vsi->type == I40E_VSI_SRIOV) {
11372 info->mapping_flags |=
11373 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
11374 for (i = 0; i < vsi->nb_qps; i++)
11375 info->queue_mapping[i] =
11376 rte_cpu_to_le_16(vsi->base_queue + i);
11378 info->mapping_flags |=
11379 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
11380 info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
11382 info->valid_sections |=
11383 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
11385 return I40E_SUCCESS;
11389 * i40e_config_switch_comp_tc - Configure VEB tc setting for given TC map
11390 * @veb: VEB to be configured
11391 * @tc_map: enabled TC bitmap
11393 * Returns 0 on success, negative value on failure
11395 static enum i40e_status_code
11396 i40e_config_switch_comp_tc(struct i40e_veb *veb, uint8_t tc_map)
11398 struct i40e_aqc_configure_switching_comp_bw_config_data veb_bw;
11399 struct i40e_aqc_query_switching_comp_bw_config_resp bw_query;
11400 struct i40e_aqc_query_switching_comp_ets_config_resp ets_query;
11401 struct i40e_hw *hw = I40E_VSI_TO_HW(veb->associate_vsi);
11402 enum i40e_status_code ret = I40E_SUCCESS;
11406 /* Check if enabled_tc is same as existing or new TCs */
11407 if (veb->enabled_tc == tc_map)
11410 /* configure tc bandwidth */
11411 memset(&veb_bw, 0, sizeof(veb_bw));
11412 veb_bw.tc_valid_bits = tc_map;
11413 /* Enable ETS TCs with equal BW Share for now across all VSIs */
11414 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11415 if (tc_map & BIT_ULL(i))
11416 veb_bw.tc_bw_share_credits[i] = 1;
11418 ret = i40e_aq_config_switch_comp_bw_config(hw, veb->seid,
11422 "AQ command Config switch_comp BW allocation per TC failed = %d",
11423 hw->aq.asq_last_status);
11427 memset(&ets_query, 0, sizeof(ets_query));
11428 ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
11430 if (ret != I40E_SUCCESS) {
11432 "Failed to get switch_comp ETS configuration %u",
11433 hw->aq.asq_last_status);
11436 memset(&bw_query, 0, sizeof(bw_query));
11437 ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
11439 if (ret != I40E_SUCCESS) {
11441 "Failed to get switch_comp bandwidth configuration %u",
11442 hw->aq.asq_last_status);
11446 /* store and print out BW info */
11447 veb->bw_info.bw_limit = rte_le_to_cpu_16(ets_query.port_bw_limit);
11448 veb->bw_info.bw_max = ets_query.tc_bw_max;
11449 PMD_DRV_LOG(DEBUG, "switch_comp bw limit:%u", veb->bw_info.bw_limit);
11450 PMD_DRV_LOG(DEBUG, "switch_comp max_bw:%u", veb->bw_info.bw_max);
11451 bw_max = rte_le_to_cpu_16(bw_query.tc_bw_max[0]) |
11452 (rte_le_to_cpu_16(bw_query.tc_bw_max[1]) <<
11453 I40E_16_BIT_WIDTH);
11454 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11455 veb->bw_info.bw_ets_share_credits[i] =
11456 bw_query.tc_bw_share_credits[i];
11457 veb->bw_info.bw_ets_credits[i] =
11458 rte_le_to_cpu_16(bw_query.tc_bw_limits[i]);
11459 /* 4 bits per TC, 4th bit is reserved */
11460 veb->bw_info.bw_ets_max[i] =
11461 (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
11462 RTE_LEN2MASK(3, uint8_t));
11463 PMD_DRV_LOG(DEBUG, "\tVEB TC%u:share credits %u", i,
11464 veb->bw_info.bw_ets_share_credits[i]);
11465 PMD_DRV_LOG(DEBUG, "\tVEB TC%u:credits %u", i,
11466 veb->bw_info.bw_ets_credits[i]);
11467 PMD_DRV_LOG(DEBUG, "\tVEB TC%u: max credits: %u", i,
11468 veb->bw_info.bw_ets_max[i]);
11471 veb->enabled_tc = tc_map;
11478 * i40e_vsi_config_tc - Configure VSI tc setting for given TC map
11479 * @vsi: VSI to be configured
11480 * @tc_map: enabled TC bitmap
11482 * Returns 0 on success, negative value on failure
11484 static enum i40e_status_code
11485 i40e_vsi_config_tc(struct i40e_vsi *vsi, uint8_t tc_map)
11487 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
11488 struct i40e_vsi_context ctxt;
11489 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
11490 enum i40e_status_code ret = I40E_SUCCESS;
11493 /* Check if enabled_tc is same as existing or new TCs */
11494 if (vsi->enabled_tc == tc_map)
11497 /* configure tc bandwidth */
11498 memset(&bw_data, 0, sizeof(bw_data));
11499 bw_data.tc_valid_bits = tc_map;
11500 /* Enable ETS TCs with equal BW Share for now across all VSIs */
11501 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11502 if (tc_map & BIT_ULL(i))
11503 bw_data.tc_bw_credits[i] = 1;
11505 ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &bw_data, NULL);
11508 "AQ command Config VSI BW allocation per TC failed = %d",
11509 hw->aq.asq_last_status);
11512 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
11513 vsi->info.qs_handle[i] = bw_data.qs_handles[i];
11515 /* Update Queue Pairs Mapping for currently enabled UPs */
11516 ctxt.seid = vsi->seid;
11517 ctxt.pf_num = hw->pf_id;
11519 ctxt.uplink_seid = vsi->uplink_seid;
11520 ctxt.info = vsi->info;
11522 ret = i40e_vsi_update_queue_mapping(vsi, &ctxt.info, tc_map);
11526 /* Update the VSI after updating the VSI queue-mapping information */
11527 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
11529 PMD_INIT_LOG(ERR, "Failed to configure TC queue mapping = %d",
11530 hw->aq.asq_last_status);
11533 /* update the local VSI info with updated queue map */
11534 rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
11535 sizeof(vsi->info.tc_mapping));
11536 rte_memcpy(&vsi->info.queue_mapping,
11537 &ctxt.info.queue_mapping,
11538 sizeof(vsi->info.queue_mapping));
11539 vsi->info.mapping_flags = ctxt.info.mapping_flags;
11540 vsi->info.valid_sections = 0;
11542 /* query and update current VSI BW information */
11543 ret = i40e_vsi_get_bw_config(vsi);
11546 "Failed updating vsi bw info, err %s aq_err %s",
11547 i40e_stat_str(hw, ret),
11548 i40e_aq_str(hw, hw->aq.asq_last_status));
11552 vsi->enabled_tc = tc_map;
11559 * i40e_dcb_hw_configure - program the dcb setting to hw
11560 * @pf: pf the configuration is taken on
11561 * @new_cfg: new configuration
11562 * @tc_map: enabled TC bitmap
11564 * Returns 0 on success, negative value on failure
11566 static enum i40e_status_code
11567 i40e_dcb_hw_configure(struct i40e_pf *pf,
11568 struct i40e_dcbx_config *new_cfg,
11571 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11572 struct i40e_dcbx_config *old_cfg = &hw->local_dcbx_config;
11573 struct i40e_vsi *main_vsi = pf->main_vsi;
11574 struct i40e_vsi_list *vsi_list;
11575 enum i40e_status_code ret;
11579 /* Use the FW API if FW > v4.4*/
11580 if (!(((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver >= 4)) ||
11581 (hw->aq.fw_maj_ver >= 5))) {
11583 "FW < v4.4, can not use FW LLDP API to configure DCB");
11584 return I40E_ERR_FIRMWARE_API_VERSION;
11587 /* Check if need reconfiguration */
11588 if (!memcmp(new_cfg, old_cfg, sizeof(struct i40e_dcbx_config))) {
11589 PMD_INIT_LOG(ERR, "No Change in DCB Config required.");
11590 return I40E_SUCCESS;
11593 /* Copy the new config to the current config */
11594 *old_cfg = *new_cfg;
11595 old_cfg->etsrec = old_cfg->etscfg;
11596 ret = i40e_set_dcb_config(hw);
11598 PMD_INIT_LOG(ERR, "Set DCB Config failed, err %s aq_err %s",
11599 i40e_stat_str(hw, ret),
11600 i40e_aq_str(hw, hw->aq.asq_last_status));
11603 /* set receive Arbiter to RR mode and ETS scheme by default */
11604 for (i = 0; i <= I40E_PRTDCB_RETSTCC_MAX_INDEX; i++) {
11605 val = I40E_READ_REG(hw, I40E_PRTDCB_RETSTCC(i));
11606 val &= ~(I40E_PRTDCB_RETSTCC_BWSHARE_MASK |
11607 I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK |
11608 I40E_PRTDCB_RETSTCC_ETSTC_SHIFT);
11609 val |= ((uint32_t)old_cfg->etscfg.tcbwtable[i] <<
11610 I40E_PRTDCB_RETSTCC_BWSHARE_SHIFT) &
11611 I40E_PRTDCB_RETSTCC_BWSHARE_MASK;
11612 val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_UPINTC_MODE_SHIFT) &
11613 I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK;
11614 val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_ETSTC_SHIFT) &
11615 I40E_PRTDCB_RETSTCC_ETSTC_MASK;
11616 I40E_WRITE_REG(hw, I40E_PRTDCB_RETSTCC(i), val);
11618 /* get local mib to check whether it is configured correctly */
11620 hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_IEEE;
11621 /* Get Local DCB Config */
11622 i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
11623 &hw->local_dcbx_config);
11625 /* if Veb is created, need to update TC of it at first */
11626 if (main_vsi->veb) {
11627 ret = i40e_config_switch_comp_tc(main_vsi->veb, tc_map);
11629 PMD_INIT_LOG(WARNING,
11630 "Failed configuring TC for VEB seid=%d",
11631 main_vsi->veb->seid);
11633 /* Update each VSI */
11634 i40e_vsi_config_tc(main_vsi, tc_map);
11635 if (main_vsi->veb) {
11636 TAILQ_FOREACH(vsi_list, &main_vsi->veb->head, list) {
11637 /* Beside main VSI and VMDQ VSIs, only enable default
11638 * TC for other VSIs
11640 if (vsi_list->vsi->type == I40E_VSI_VMDQ2)
11641 ret = i40e_vsi_config_tc(vsi_list->vsi,
11644 ret = i40e_vsi_config_tc(vsi_list->vsi,
11645 I40E_DEFAULT_TCMAP);
11647 PMD_INIT_LOG(WARNING,
11648 "Failed configuring TC for VSI seid=%d",
11649 vsi_list->vsi->seid);
11653 return I40E_SUCCESS;
11657 * i40e_dcb_init_configure - initial dcb config
11658 * @dev: device being configured
11659 * @sw_dcb: indicate whether dcb is sw configured or hw offload
11661 * Returns 0 on success, negative value on failure
11664 i40e_dcb_init_configure(struct rte_eth_dev *dev, bool sw_dcb)
11666 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11667 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11670 if ((pf->flags & I40E_FLAG_DCB) == 0) {
11671 PMD_INIT_LOG(ERR, "HW doesn't support DCB");
11675 /* DCB initialization:
11676 * Update DCB configuration from the Firmware and configure
11677 * LLDP MIB change event.
11679 if (sw_dcb == TRUE) {
11680 /* Stopping lldp is necessary for DPDK, but it will cause
11681 * DCB init failed. For i40e_init_dcb(), the prerequisite
11682 * for successful initialization of DCB is that LLDP is
11683 * enabled. So it is needed to start lldp before DCB init
11684 * and stop it after initialization.
11686 ret = i40e_aq_start_lldp(hw, true, NULL);
11687 if (ret != I40E_SUCCESS)
11688 PMD_INIT_LOG(DEBUG, "Failed to start lldp");
11690 ret = i40e_init_dcb(hw, true);
11691 /* If lldp agent is stopped, the return value from
11692 * i40e_init_dcb we expect is failure with I40E_AQ_RC_EPERM
11693 * adminq status. Otherwise, it should return success.
11695 if ((ret == I40E_SUCCESS) || (ret != I40E_SUCCESS &&
11696 hw->aq.asq_last_status == I40E_AQ_RC_EPERM)) {
11697 memset(&hw->local_dcbx_config, 0,
11698 sizeof(struct i40e_dcbx_config));
11699 /* set dcb default configuration */
11700 hw->local_dcbx_config.etscfg.willing = 0;
11701 hw->local_dcbx_config.etscfg.maxtcs = 0;
11702 hw->local_dcbx_config.etscfg.tcbwtable[0] = 100;
11703 hw->local_dcbx_config.etscfg.tsatable[0] =
11705 /* all UPs mapping to TC0 */
11706 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
11707 hw->local_dcbx_config.etscfg.prioritytable[i] = 0;
11708 hw->local_dcbx_config.etsrec =
11709 hw->local_dcbx_config.etscfg;
11710 hw->local_dcbx_config.pfc.willing = 0;
11711 hw->local_dcbx_config.pfc.pfccap =
11712 I40E_MAX_TRAFFIC_CLASS;
11713 /* FW needs one App to configure HW */
11714 hw->local_dcbx_config.numapps = 1;
11715 hw->local_dcbx_config.app[0].selector =
11716 I40E_APP_SEL_ETHTYPE;
11717 hw->local_dcbx_config.app[0].priority = 3;
11718 hw->local_dcbx_config.app[0].protocolid =
11719 I40E_APP_PROTOID_FCOE;
11720 ret = i40e_set_dcb_config(hw);
11723 "default dcb config fails. err = %d, aq_err = %d.",
11724 ret, hw->aq.asq_last_status);
11729 "DCB initialization in FW fails, err = %d, aq_err = %d.",
11730 ret, hw->aq.asq_last_status);
11734 if (i40e_need_stop_lldp(dev)) {
11735 ret = i40e_aq_stop_lldp(hw, true, true, NULL);
11736 if (ret != I40E_SUCCESS)
11737 PMD_INIT_LOG(DEBUG, "Failed to stop lldp");
11740 ret = i40e_aq_start_lldp(hw, true, NULL);
11741 if (ret != I40E_SUCCESS)
11742 PMD_INIT_LOG(DEBUG, "Failed to start lldp");
11744 ret = i40e_init_dcb(hw, true);
11746 if (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED) {
11748 "HW doesn't support DCBX offload.");
11753 "DCBX configuration failed, err = %d, aq_err = %d.",
11754 ret, hw->aq.asq_last_status);
11762 * i40e_dcb_setup - setup dcb related config
11763 * @dev: device being configured
11765 * Returns 0 on success, negative value on failure
11768 i40e_dcb_setup(struct rte_eth_dev *dev)
11770 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11771 struct i40e_dcbx_config dcb_cfg;
11772 uint8_t tc_map = 0;
11775 if ((pf->flags & I40E_FLAG_DCB) == 0) {
11776 PMD_INIT_LOG(ERR, "HW doesn't support DCB");
11780 if (pf->vf_num != 0)
11781 PMD_INIT_LOG(DEBUG, " DCB only works on pf and vmdq vsis.");
11783 ret = i40e_parse_dcb_configure(dev, &dcb_cfg, &tc_map);
11785 PMD_INIT_LOG(ERR, "invalid dcb config");
11788 ret = i40e_dcb_hw_configure(pf, &dcb_cfg, tc_map);
11790 PMD_INIT_LOG(ERR, "dcb sw configure fails");
11798 i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
11799 struct rte_eth_dcb_info *dcb_info)
11801 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11802 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11803 struct i40e_vsi *vsi = pf->main_vsi;
11804 struct i40e_dcbx_config *dcb_cfg = &hw->local_dcbx_config;
11805 uint16_t bsf, tc_mapping;
11808 if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_DCB_FLAG)
11809 dcb_info->nb_tcs = rte_bsf32(vsi->enabled_tc + 1);
11811 dcb_info->nb_tcs = 1;
11812 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
11813 dcb_info->prio_tc[i] = dcb_cfg->etscfg.prioritytable[i];
11814 for (i = 0; i < dcb_info->nb_tcs; i++)
11815 dcb_info->tc_bws[i] = dcb_cfg->etscfg.tcbwtable[i];
11817 /* get queue mapping if vmdq is disabled */
11818 if (!pf->nb_cfg_vmdq_vsi) {
11819 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11820 if (!(vsi->enabled_tc & (1 << i)))
11822 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
11823 dcb_info->tc_queue.tc_rxq[j][i].base =
11824 (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
11825 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
11826 dcb_info->tc_queue.tc_txq[j][i].base =
11827 dcb_info->tc_queue.tc_rxq[j][i].base;
11828 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
11829 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
11830 dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
11831 dcb_info->tc_queue.tc_txq[j][i].nb_queue =
11832 dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
11837 /* get queue mapping if vmdq is enabled */
11839 vsi = pf->vmdq[j].vsi;
11840 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11841 if (!(vsi->enabled_tc & (1 << i)))
11843 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
11844 dcb_info->tc_queue.tc_rxq[j][i].base =
11845 (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
11846 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
11847 dcb_info->tc_queue.tc_txq[j][i].base =
11848 dcb_info->tc_queue.tc_rxq[j][i].base;
11849 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
11850 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
11851 dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
11852 dcb_info->tc_queue.tc_txq[j][i].nb_queue =
11853 dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
11856 } while (j < RTE_MIN(pf->nb_cfg_vmdq_vsi, ETH_MAX_VMDQ_POOL));
11861 i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
11863 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
11864 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
11865 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11866 uint16_t msix_intr;
11868 msix_intr = intr_handle->intr_vec[queue_id];
11869 if (msix_intr == I40E_MISC_VEC_ID)
11870 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
11871 I40E_PFINT_DYN_CTL0_INTENA_MASK |
11872 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
11873 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
11876 I40E_PFINT_DYN_CTLN(msix_intr -
11877 I40E_RX_VEC_START),
11878 I40E_PFINT_DYN_CTLN_INTENA_MASK |
11879 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
11880 I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
11882 I40E_WRITE_FLUSH(hw);
11883 rte_intr_ack(&pci_dev->intr_handle);
11889 i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
11891 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
11892 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
11893 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11894 uint16_t msix_intr;
11896 msix_intr = intr_handle->intr_vec[queue_id];
11897 if (msix_intr == I40E_MISC_VEC_ID)
11898 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
11899 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
11902 I40E_PFINT_DYN_CTLN(msix_intr -
11903 I40E_RX_VEC_START),
11904 I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
11905 I40E_WRITE_FLUSH(hw);
11911 * This function is used to check if the register is valid.
11912 * Below is the valid registers list for X722 only:
11916 * 0x208e00--0x209000
11917 * 0x20be00--0x20c000
11918 * 0x263c00--0x264000
11919 * 0x265c00--0x266000
11921 static inline int i40e_valid_regs(enum i40e_mac_type type, uint32_t reg_offset)
11923 if ((type != I40E_MAC_X722) &&
11924 ((reg_offset >= 0x2b800 && reg_offset <= 0x2bb00) ||
11925 (reg_offset >= 0x38700 && reg_offset <= 0x38a00) ||
11926 (reg_offset >= 0x3d800 && reg_offset <= 0x3db00) ||
11927 (reg_offset >= 0x208e00 && reg_offset <= 0x209000) ||
11928 (reg_offset >= 0x20be00 && reg_offset <= 0x20c000) ||
11929 (reg_offset >= 0x263c00 && reg_offset <= 0x264000) ||
11930 (reg_offset >= 0x265c00 && reg_offset <= 0x266000)))
11936 static int i40e_get_regs(struct rte_eth_dev *dev,
11937 struct rte_dev_reg_info *regs)
11939 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11940 uint32_t *ptr_data = regs->data;
11941 uint32_t reg_idx, arr_idx, arr_idx2, reg_offset;
11942 const struct i40e_reg_info *reg_info;
11944 if (ptr_data == NULL) {
11945 regs->length = I40E_GLGEN_STAT_CLEAR + 4;
11946 regs->width = sizeof(uint32_t);
11950 /* The first few registers have to be read using AQ operations */
11952 while (i40e_regs_adminq[reg_idx].name) {
11953 reg_info = &i40e_regs_adminq[reg_idx++];
11954 for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
11956 arr_idx2 <= reg_info->count2;
11958 reg_offset = arr_idx * reg_info->stride1 +
11959 arr_idx2 * reg_info->stride2;
11960 reg_offset += reg_info->base_addr;
11961 ptr_data[reg_offset >> 2] =
11962 i40e_read_rx_ctl(hw, reg_offset);
11966 /* The remaining registers can be read using primitives */
11968 while (i40e_regs_others[reg_idx].name) {
11969 reg_info = &i40e_regs_others[reg_idx++];
11970 for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
11972 arr_idx2 <= reg_info->count2;
11974 reg_offset = arr_idx * reg_info->stride1 +
11975 arr_idx2 * reg_info->stride2;
11976 reg_offset += reg_info->base_addr;
11977 if (!i40e_valid_regs(hw->mac.type, reg_offset))
11978 ptr_data[reg_offset >> 2] = 0;
11980 ptr_data[reg_offset >> 2] =
11981 I40E_READ_REG(hw, reg_offset);
11988 static int i40e_get_eeprom_length(struct rte_eth_dev *dev)
11990 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11992 /* Convert word count to byte count */
11993 return hw->nvm.sr_size << 1;
11996 static int i40e_get_eeprom(struct rte_eth_dev *dev,
11997 struct rte_dev_eeprom_info *eeprom)
11999 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
12000 uint16_t *data = eeprom->data;
12001 uint16_t offset, length, cnt_words;
12004 offset = eeprom->offset >> 1;
12005 length = eeprom->length >> 1;
12006 cnt_words = length;
12008 if (offset > hw->nvm.sr_size ||
12009 offset + length > hw->nvm.sr_size) {
12010 PMD_DRV_LOG(ERR, "Requested EEPROM bytes out of range.");
12014 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
12016 ret_code = i40e_read_nvm_buffer(hw, offset, &cnt_words, data);
12017 if (ret_code != I40E_SUCCESS || cnt_words != length) {
12018 PMD_DRV_LOG(ERR, "EEPROM read failed.");
12025 static int i40e_get_module_info(struct rte_eth_dev *dev,
12026 struct rte_eth_dev_module_info *modinfo)
12028 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
12029 uint32_t sff8472_comp = 0;
12030 uint32_t sff8472_swap = 0;
12031 uint32_t sff8636_rev = 0;
12032 i40e_status status;
12035 /* Check if firmware supports reading module EEPROM. */
12036 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
12038 "Module EEPROM memory read not supported. "
12039 "Please update the NVM image.\n");
12043 status = i40e_update_link_info(hw);
12047 if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
12049 "Cannot read module EEPROM memory. "
12050 "No module connected.\n");
12054 type = hw->phy.link_info.module_type[0];
12057 case I40E_MODULE_TYPE_SFP:
12058 status = i40e_aq_get_phy_register(hw,
12059 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
12060 I40E_I2C_EEPROM_DEV_ADDR, 1,
12061 I40E_MODULE_SFF_8472_COMP,
12062 &sff8472_comp, NULL);
12066 status = i40e_aq_get_phy_register(hw,
12067 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
12068 I40E_I2C_EEPROM_DEV_ADDR, 1,
12069 I40E_MODULE_SFF_8472_SWAP,
12070 &sff8472_swap, NULL);
12074 /* Check if the module requires address swap to access
12075 * the other EEPROM memory page.
12077 if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
12078 PMD_DRV_LOG(WARNING,
12079 "Module address swap to access "
12080 "page 0xA2 is not supported.\n");
12081 modinfo->type = RTE_ETH_MODULE_SFF_8079;
12082 modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
12083 } else if (sff8472_comp == 0x00) {
12084 /* Module is not SFF-8472 compliant */
12085 modinfo->type = RTE_ETH_MODULE_SFF_8079;
12086 modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
12088 modinfo->type = RTE_ETH_MODULE_SFF_8472;
12089 modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8472_LEN;
12092 case I40E_MODULE_TYPE_QSFP_PLUS:
12093 /* Read from memory page 0. */
12094 status = i40e_aq_get_phy_register(hw,
12095 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
12097 I40E_MODULE_REVISION_ADDR,
12098 &sff8636_rev, NULL);
12101 /* Determine revision compliance byte */
12102 if (sff8636_rev > 0x02) {
12103 /* Module is SFF-8636 compliant */
12104 modinfo->type = RTE_ETH_MODULE_SFF_8636;
12105 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
12107 modinfo->type = RTE_ETH_MODULE_SFF_8436;
12108 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
12111 case I40E_MODULE_TYPE_QSFP28:
12112 modinfo->type = RTE_ETH_MODULE_SFF_8636;
12113 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
12116 PMD_DRV_LOG(ERR, "Module type unrecognized\n");
12122 static int i40e_get_module_eeprom(struct rte_eth_dev *dev,
12123 struct rte_dev_eeprom_info *info)
12125 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
12126 bool is_sfp = false;
12127 i40e_status status;
12129 uint32_t value = 0;
12132 if (!info || !info->length || !info->data)
12135 if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
12139 for (i = 0; i < info->length; i++) {
12140 u32 offset = i + info->offset;
12141 u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
12143 /* Check if we need to access the other memory page */
12145 if (offset >= RTE_ETH_MODULE_SFF_8079_LEN) {
12146 offset -= RTE_ETH_MODULE_SFF_8079_LEN;
12147 addr = I40E_I2C_EEPROM_DEV_ADDR2;
12150 while (offset >= RTE_ETH_MODULE_SFF_8436_LEN) {
12151 /* Compute memory page number and offset. */
12152 offset -= RTE_ETH_MODULE_SFF_8436_LEN / 2;
12156 status = i40e_aq_get_phy_register(hw,
12157 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
12158 addr, offset, 1, &value, NULL);
12161 data[i] = (uint8_t)value;
12166 static int i40e_set_default_mac_addr(struct rte_eth_dev *dev,
12167 struct rte_ether_addr *mac_addr)
12169 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
12170 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
12171 struct i40e_vsi *vsi = pf->main_vsi;
12172 struct i40e_mac_filter_info mac_filter;
12173 struct i40e_mac_filter *f;
12176 if (!rte_is_valid_assigned_ether_addr(mac_addr)) {
12177 PMD_DRV_LOG(ERR, "Tried to set invalid MAC address.");
12181 TAILQ_FOREACH(f, &vsi->mac_list, next) {
12182 if (rte_is_same_ether_addr(&pf->dev_addr,
12183 &f->mac_info.mac_addr))
12188 PMD_DRV_LOG(ERR, "Failed to find filter for default mac");
12192 mac_filter = f->mac_info;
12193 ret = i40e_vsi_delete_mac(vsi, &mac_filter.mac_addr);
12194 if (ret != I40E_SUCCESS) {
12195 PMD_DRV_LOG(ERR, "Failed to delete mac filter");
12198 memcpy(&mac_filter.mac_addr, mac_addr, ETH_ADDR_LEN);
12199 ret = i40e_vsi_add_mac(vsi, &mac_filter);
12200 if (ret != I40E_SUCCESS) {
12201 PMD_DRV_LOG(ERR, "Failed to add mac filter");
12204 memcpy(&pf->dev_addr, mac_addr, ETH_ADDR_LEN);
12206 ret = i40e_aq_mac_address_write(hw, I40E_AQC_WRITE_TYPE_LAA_WOL,
12207 mac_addr->addr_bytes, NULL);
12208 if (ret != I40E_SUCCESS) {
12209 PMD_DRV_LOG(ERR, "Failed to change mac");
12217 i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
12219 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
12220 struct rte_eth_dev_data *dev_data = pf->dev_data;
12221 uint32_t frame_size = mtu + I40E_ETH_OVERHEAD;
12224 /* check if mtu is within the allowed range */
12225 if (mtu < RTE_ETHER_MIN_MTU || frame_size > I40E_FRAME_SIZE_MAX)
12228 /* mtu setting is forbidden if port is start */
12229 if (dev_data->dev_started) {
12230 PMD_DRV_LOG(ERR, "port %d must be stopped before configuration",
12231 dev_data->port_id);
12235 if (frame_size > RTE_ETHER_MAX_LEN)
12236 dev_data->dev_conf.rxmode.offloads |=
12237 DEV_RX_OFFLOAD_JUMBO_FRAME;
12239 dev_data->dev_conf.rxmode.offloads &=
12240 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
12242 dev_data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
12247 /* Restore ethertype filter */
12249 i40e_ethertype_filter_restore(struct i40e_pf *pf)
12251 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
12252 struct i40e_ethertype_filter_list
12253 *ethertype_list = &pf->ethertype.ethertype_list;
12254 struct i40e_ethertype_filter *f;
12255 struct i40e_control_filter_stats stats;
12258 TAILQ_FOREACH(f, ethertype_list, rules) {
12260 if (!(f->flags & RTE_ETHTYPE_FLAGS_MAC))
12261 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
12262 if (f->flags & RTE_ETHTYPE_FLAGS_DROP)
12263 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
12264 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
12266 memset(&stats, 0, sizeof(stats));
12267 i40e_aq_add_rem_control_packet_filter(hw,
12268 f->input.mac_addr.addr_bytes,
12269 f->input.ether_type,
12270 flags, pf->main_vsi->seid,
12271 f->queue, 1, &stats, NULL);
12273 PMD_DRV_LOG(INFO, "Ethertype filter:"
12274 " mac_etype_used = %u, etype_used = %u,"
12275 " mac_etype_free = %u, etype_free = %u",
12276 stats.mac_etype_used, stats.etype_used,
12277 stats.mac_etype_free, stats.etype_free);
12280 /* Restore tunnel filter */
12282 i40e_tunnel_filter_restore(struct i40e_pf *pf)
12284 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
12285 struct i40e_vsi *vsi;
12286 struct i40e_pf_vf *vf;
12287 struct i40e_tunnel_filter_list
12288 *tunnel_list = &pf->tunnel.tunnel_list;
12289 struct i40e_tunnel_filter *f;
12290 struct i40e_aqc_cloud_filters_element_bb cld_filter;
12291 bool big_buffer = 0;
12293 TAILQ_FOREACH(f, tunnel_list, rules) {
12295 vsi = pf->main_vsi;
12297 vf = &pf->vfs[f->vf_id];
12300 memset(&cld_filter, 0, sizeof(cld_filter));
12301 rte_ether_addr_copy((struct rte_ether_addr *)
12302 &f->input.outer_mac,
12303 (struct rte_ether_addr *)&cld_filter.element.outer_mac);
12304 rte_ether_addr_copy((struct rte_ether_addr *)
12305 &f->input.inner_mac,
12306 (struct rte_ether_addr *)&cld_filter.element.inner_mac);
12307 cld_filter.element.inner_vlan = f->input.inner_vlan;
12308 cld_filter.element.flags = f->input.flags;
12309 cld_filter.element.tenant_id = f->input.tenant_id;
12310 cld_filter.element.queue_number = f->queue;
12311 rte_memcpy(cld_filter.general_fields,
12312 f->input.general_fields,
12313 sizeof(f->input.general_fields));
12315 if (((f->input.flags &
12316 I40E_AQC_ADD_CLOUD_FILTER_0X11) ==
12317 I40E_AQC_ADD_CLOUD_FILTER_0X11) ||
12319 I40E_AQC_ADD_CLOUD_FILTER_0X12) ==
12320 I40E_AQC_ADD_CLOUD_FILTER_0X12) ||
12322 I40E_AQC_ADD_CLOUD_FILTER_0X10) ==
12323 I40E_AQC_ADD_CLOUD_FILTER_0X10))
12327 i40e_aq_add_cloud_filters_bb(hw,
12328 vsi->seid, &cld_filter, 1);
12330 i40e_aq_add_cloud_filters(hw, vsi->seid,
12331 &cld_filter.element, 1);
12335 /* Restore RSS filter */
12337 i40e_rss_filter_restore(struct i40e_pf *pf)
12339 struct i40e_rss_conf_list *list = &pf->rss_config_list;
12340 struct i40e_rss_filter *filter;
12342 TAILQ_FOREACH(filter, list, next) {
12343 i40e_config_rss_filter(pf, &filter->rss_filter_info, TRUE);
12348 i40e_filter_restore(struct i40e_pf *pf)
12350 i40e_ethertype_filter_restore(pf);
12351 i40e_tunnel_filter_restore(pf);
12352 i40e_fdir_filter_restore(pf);
12353 i40e_rss_filter_restore(pf);
12357 is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
12359 if (strcmp(dev->device->driver->name, drv->driver.name))
12366 is_i40e_supported(struct rte_eth_dev *dev)
12368 return is_device_supported(dev, &rte_i40e_pmd);
12371 struct i40e_customized_pctype*
12372 i40e_find_customized_pctype(struct i40e_pf *pf, uint8_t index)
12376 for (i = 0; i < I40E_CUSTOMIZED_MAX; i++) {
12377 if (pf->customized_pctype[i].index == index)
12378 return &pf->customized_pctype[i];
12384 i40e_update_customized_pctype(struct rte_eth_dev *dev, uint8_t *pkg,
12385 uint32_t pkg_size, uint32_t proto_num,
12386 struct rte_pmd_i40e_proto_info *proto,
12387 enum rte_pmd_i40e_package_op op)
12389 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
12390 uint32_t pctype_num;
12391 struct rte_pmd_i40e_ptype_info *pctype;
12392 uint32_t buff_size;
12393 struct i40e_customized_pctype *new_pctype = NULL;
12395 uint8_t pctype_value;
12400 if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
12401 op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
12402 PMD_DRV_LOG(ERR, "Unsupported operation.");
12406 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12407 (uint8_t *)&pctype_num, sizeof(pctype_num),
12408 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
12410 PMD_DRV_LOG(ERR, "Failed to get pctype number");
12414 PMD_DRV_LOG(INFO, "No new pctype added");
12418 buff_size = pctype_num * sizeof(struct rte_pmd_i40e_proto_info);
12419 pctype = rte_zmalloc("new_pctype", buff_size, 0);
12421 PMD_DRV_LOG(ERR, "Failed to allocate memory");
12424 /* get information about new pctype list */
12425 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12426 (uint8_t *)pctype, buff_size,
12427 RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
12429 PMD_DRV_LOG(ERR, "Failed to get pctype list");
12434 /* Update customized pctype. */
12435 for (i = 0; i < pctype_num; i++) {
12436 pctype_value = pctype[i].ptype_id;
12437 memset(name, 0, sizeof(name));
12438 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
12439 proto_id = pctype[i].protocols[j];
12440 if (proto_id == RTE_PMD_I40E_PROTO_UNUSED)
12442 for (n = 0; n < proto_num; n++) {
12443 if (proto[n].proto_id != proto_id)
12445 strlcat(name, proto[n].name, sizeof(name));
12446 strlcat(name, "_", sizeof(name));
12450 name[strlen(name) - 1] = '\0';
12451 PMD_DRV_LOG(INFO, "name = %s\n", name);
12452 if (!strcmp(name, "GTPC"))
12454 i40e_find_customized_pctype(pf,
12455 I40E_CUSTOMIZED_GTPC);
12456 else if (!strcmp(name, "GTPU_IPV4"))
12458 i40e_find_customized_pctype(pf,
12459 I40E_CUSTOMIZED_GTPU_IPV4);
12460 else if (!strcmp(name, "GTPU_IPV6"))
12462 i40e_find_customized_pctype(pf,
12463 I40E_CUSTOMIZED_GTPU_IPV6);
12464 else if (!strcmp(name, "GTPU"))
12466 i40e_find_customized_pctype(pf,
12467 I40E_CUSTOMIZED_GTPU);
12468 else if (!strcmp(name, "IPV4_L2TPV3"))
12470 i40e_find_customized_pctype(pf,
12471 I40E_CUSTOMIZED_IPV4_L2TPV3);
12472 else if (!strcmp(name, "IPV6_L2TPV3"))
12474 i40e_find_customized_pctype(pf,
12475 I40E_CUSTOMIZED_IPV6_L2TPV3);
12476 else if (!strcmp(name, "IPV4_ESP"))
12478 i40e_find_customized_pctype(pf,
12479 I40E_CUSTOMIZED_ESP_IPV4);
12480 else if (!strcmp(name, "IPV6_ESP"))
12482 i40e_find_customized_pctype(pf,
12483 I40E_CUSTOMIZED_ESP_IPV6);
12484 else if (!strcmp(name, "IPV4_UDP_ESP"))
12486 i40e_find_customized_pctype(pf,
12487 I40E_CUSTOMIZED_ESP_IPV4_UDP);
12488 else if (!strcmp(name, "IPV6_UDP_ESP"))
12490 i40e_find_customized_pctype(pf,
12491 I40E_CUSTOMIZED_ESP_IPV6_UDP);
12492 else if (!strcmp(name, "IPV4_AH"))
12494 i40e_find_customized_pctype(pf,
12495 I40E_CUSTOMIZED_AH_IPV4);
12496 else if (!strcmp(name, "IPV6_AH"))
12498 i40e_find_customized_pctype(pf,
12499 I40E_CUSTOMIZED_AH_IPV6);
12501 if (op == RTE_PMD_I40E_PKG_OP_WR_ADD) {
12502 new_pctype->pctype = pctype_value;
12503 new_pctype->valid = true;
12505 new_pctype->pctype = I40E_FILTER_PCTYPE_INVALID;
12506 new_pctype->valid = false;
12516 i40e_update_customized_ptype(struct rte_eth_dev *dev, uint8_t *pkg,
12517 uint32_t pkg_size, uint32_t proto_num,
12518 struct rte_pmd_i40e_proto_info *proto,
12519 enum rte_pmd_i40e_package_op op)
12521 struct rte_pmd_i40e_ptype_mapping *ptype_mapping;
12522 uint16_t port_id = dev->data->port_id;
12523 uint32_t ptype_num;
12524 struct rte_pmd_i40e_ptype_info *ptype;
12525 uint32_t buff_size;
12527 char name[RTE_PMD_I40E_DDP_NAME_SIZE];
12532 if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
12533 op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
12534 PMD_DRV_LOG(ERR, "Unsupported operation.");
12538 if (op == RTE_PMD_I40E_PKG_OP_WR_DEL) {
12539 rte_pmd_i40e_ptype_mapping_reset(port_id);
12543 /* get information about new ptype num */
12544 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12545 (uint8_t *)&ptype_num, sizeof(ptype_num),
12546 RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
12548 PMD_DRV_LOG(ERR, "Failed to get ptype number");
12552 PMD_DRV_LOG(INFO, "No new ptype added");
12556 buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
12557 ptype = rte_zmalloc("new_ptype", buff_size, 0);
12559 PMD_DRV_LOG(ERR, "Failed to allocate memory");
12563 /* get information about new ptype list */
12564 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12565 (uint8_t *)ptype, buff_size,
12566 RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
12568 PMD_DRV_LOG(ERR, "Failed to get ptype list");
12573 buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_mapping);
12574 ptype_mapping = rte_zmalloc("ptype_mapping", buff_size, 0);
12575 if (!ptype_mapping) {
12576 PMD_DRV_LOG(ERR, "Failed to allocate memory");
12581 /* Update ptype mapping table. */
12582 for (i = 0; i < ptype_num; i++) {
12583 ptype_mapping[i].hw_ptype = ptype[i].ptype_id;
12584 ptype_mapping[i].sw_ptype = 0;
12586 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
12587 proto_id = ptype[i].protocols[j];
12588 if (proto_id == RTE_PMD_I40E_PROTO_UNUSED)
12590 for (n = 0; n < proto_num; n++) {
12591 if (proto[n].proto_id != proto_id)
12593 memset(name, 0, sizeof(name));
12594 strcpy(name, proto[n].name);
12595 PMD_DRV_LOG(INFO, "name = %s\n", name);
12596 if (!strncasecmp(name, "PPPOE", 5))
12597 ptype_mapping[i].sw_ptype |=
12598 RTE_PTYPE_L2_ETHER_PPPOE;
12599 else if (!strncasecmp(name, "IPV4FRAG", 8) &&
12601 ptype_mapping[i].sw_ptype |=
12602 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
12603 ptype_mapping[i].sw_ptype |=
12605 } else if (!strncasecmp(name, "IPV4FRAG", 8) &&
12607 ptype_mapping[i].sw_ptype |=
12608 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
12609 ptype_mapping[i].sw_ptype |=
12610 RTE_PTYPE_INNER_L4_FRAG;
12611 } else if (!strncasecmp(name, "OIPV4", 5)) {
12612 ptype_mapping[i].sw_ptype |=
12613 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
12615 } else if (!strncasecmp(name, "IPV4", 4) &&
12617 ptype_mapping[i].sw_ptype |=
12618 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
12619 else if (!strncasecmp(name, "IPV4", 4) &&
12621 ptype_mapping[i].sw_ptype |=
12622 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
12623 else if (!strncasecmp(name, "IPV6FRAG", 8) &&
12625 ptype_mapping[i].sw_ptype |=
12626 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
12627 ptype_mapping[i].sw_ptype |=
12629 } else if (!strncasecmp(name, "IPV6FRAG", 8) &&
12631 ptype_mapping[i].sw_ptype |=
12632 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
12633 ptype_mapping[i].sw_ptype |=
12634 RTE_PTYPE_INNER_L4_FRAG;
12635 } else if (!strncasecmp(name, "OIPV6", 5)) {
12636 ptype_mapping[i].sw_ptype |=
12637 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
12639 } else if (!strncasecmp(name, "IPV6", 4) &&
12641 ptype_mapping[i].sw_ptype |=
12642 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
12643 else if (!strncasecmp(name, "IPV6", 4) &&
12645 ptype_mapping[i].sw_ptype |=
12646 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
12647 else if (!strncasecmp(name, "UDP", 3) &&
12649 ptype_mapping[i].sw_ptype |=
12651 else if (!strncasecmp(name, "UDP", 3) &&
12653 ptype_mapping[i].sw_ptype |=
12654 RTE_PTYPE_INNER_L4_UDP;
12655 else if (!strncasecmp(name, "TCP", 3) &&
12657 ptype_mapping[i].sw_ptype |=
12659 else if (!strncasecmp(name, "TCP", 3) &&
12661 ptype_mapping[i].sw_ptype |=
12662 RTE_PTYPE_INNER_L4_TCP;
12663 else if (!strncasecmp(name, "SCTP", 4) &&
12665 ptype_mapping[i].sw_ptype |=
12667 else if (!strncasecmp(name, "SCTP", 4) &&
12669 ptype_mapping[i].sw_ptype |=
12670 RTE_PTYPE_INNER_L4_SCTP;
12671 else if ((!strncasecmp(name, "ICMP", 4) ||
12672 !strncasecmp(name, "ICMPV6", 6)) &&
12674 ptype_mapping[i].sw_ptype |=
12676 else if ((!strncasecmp(name, "ICMP", 4) ||
12677 !strncasecmp(name, "ICMPV6", 6)) &&
12679 ptype_mapping[i].sw_ptype |=
12680 RTE_PTYPE_INNER_L4_ICMP;
12681 else if (!strncasecmp(name, "GTPC", 4)) {
12682 ptype_mapping[i].sw_ptype |=
12683 RTE_PTYPE_TUNNEL_GTPC;
12685 } else if (!strncasecmp(name, "GTPU", 4)) {
12686 ptype_mapping[i].sw_ptype |=
12687 RTE_PTYPE_TUNNEL_GTPU;
12689 } else if (!strncasecmp(name, "ESP", 3)) {
12690 ptype_mapping[i].sw_ptype |=
12691 RTE_PTYPE_TUNNEL_ESP;
12693 } else if (!strncasecmp(name, "GRENAT", 6)) {
12694 ptype_mapping[i].sw_ptype |=
12695 RTE_PTYPE_TUNNEL_GRENAT;
12697 } else if (!strncasecmp(name, "L2TPV2CTL", 9) ||
12698 !strncasecmp(name, "L2TPV2", 6) ||
12699 !strncasecmp(name, "L2TPV3", 6)) {
12700 ptype_mapping[i].sw_ptype |=
12701 RTE_PTYPE_TUNNEL_L2TP;
12710 ret = rte_pmd_i40e_ptype_mapping_update(port_id, ptype_mapping,
12713 PMD_DRV_LOG(ERR, "Failed to update ptype mapping table.");
12715 rte_free(ptype_mapping);
12721 i40e_update_customized_info(struct rte_eth_dev *dev, uint8_t *pkg,
12722 uint32_t pkg_size, enum rte_pmd_i40e_package_op op)
12724 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
12725 uint32_t proto_num;
12726 struct rte_pmd_i40e_proto_info *proto;
12727 uint32_t buff_size;
12731 if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
12732 op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
12733 PMD_DRV_LOG(ERR, "Unsupported operation.");
12737 /* get information about protocol number */
12738 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12739 (uint8_t *)&proto_num, sizeof(proto_num),
12740 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
12742 PMD_DRV_LOG(ERR, "Failed to get protocol number");
12746 PMD_DRV_LOG(INFO, "No new protocol added");
12750 buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
12751 proto = rte_zmalloc("new_proto", buff_size, 0);
12753 PMD_DRV_LOG(ERR, "Failed to allocate memory");
12757 /* get information about protocol list */
12758 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12759 (uint8_t *)proto, buff_size,
12760 RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
12762 PMD_DRV_LOG(ERR, "Failed to get protocol list");
12767 /* Check if GTP is supported. */
12768 for (i = 0; i < proto_num; i++) {
12769 if (!strncmp(proto[i].name, "GTP", 3)) {
12770 if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
12771 pf->gtp_support = true;
12773 pf->gtp_support = false;
12778 /* Check if ESP is supported. */
12779 for (i = 0; i < proto_num; i++) {
12780 if (!strncmp(proto[i].name, "ESP", 3)) {
12781 if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
12782 pf->esp_support = true;
12784 pf->esp_support = false;
12789 /* Update customized pctype info */
12790 ret = i40e_update_customized_pctype(dev, pkg, pkg_size,
12791 proto_num, proto, op);
12793 PMD_DRV_LOG(INFO, "No pctype is updated.");
12795 /* Update customized ptype info */
12796 ret = i40e_update_customized_ptype(dev, pkg, pkg_size,
12797 proto_num, proto, op);
12799 PMD_DRV_LOG(INFO, "No ptype is updated.");
12804 /* Create a QinQ cloud filter
12806 * The Fortville NIC has limited resources for tunnel filters,
12807 * so we can only reuse existing filters.
12809 * In step 1 we define which Field Vector fields can be used for
12811 * As we do not have the inner tag defined as a field,
12812 * we have to define it first, by reusing one of L1 entries.
12814 * In step 2 we are replacing one of existing filter types with
12815 * a new one for QinQ.
12816 * As we reusing L1 and replacing L2, some of the default filter
12817 * types will disappear,which depends on L1 and L2 entries we reuse.
12819 * Step 1: Create L1 filter of outer vlan (12b) + inner vlan (12b)
12821 * 1. Create L1 filter of outer vlan (12b) which will be in use
12822 * later when we define the cloud filter.
12823 * a. Valid_flags.replace_cloud = 0
12824 * b. Old_filter = 10 (Stag_Inner_Vlan)
12825 * c. New_filter = 0x10
12826 * d. TR bit = 0xff (optional, not used here)
12827 * e. Buffer – 2 entries:
12828 * i. Byte 0 = 8 (outer vlan FV index).
12830 * Byte 2-3 = 0x0fff
12831 * ii. Byte 0 = 37 (inner vlan FV index).
12833 * Byte 2-3 = 0x0fff
12836 * 2. Create cloud filter using two L1 filters entries: stag and
12837 * new filter(outer vlan+ inner vlan)
12838 * a. Valid_flags.replace_cloud = 1
12839 * b. Old_filter = 1 (instead of outer IP)
12840 * c. New_filter = 0x10
12841 * d. Buffer – 2 entries:
12842 * i. Byte 0 = 0x80 | 7 (valid | Stag).
12843 * Byte 1-3 = 0 (rsv)
12844 * ii. Byte 8 = 0x80 | 0x10 (valid | new l1 filter step1)
12845 * Byte 9-11 = 0 (rsv)
12848 i40e_cloud_filter_qinq_create(struct i40e_pf *pf)
12850 int ret = -ENOTSUP;
12851 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
12852 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
12853 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
12854 struct rte_eth_dev *dev = ((struct i40e_adapter *)hw->back)->eth_dev;
12856 if (pf->support_multi_driver) {
12857 PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
12862 memset(&filter_replace, 0,
12863 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
12864 memset(&filter_replace_buf, 0,
12865 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
12867 /* create L1 filter */
12868 filter_replace.old_filter_type =
12869 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG_IVLAN;
12870 filter_replace.new_filter_type = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12871 filter_replace.tr_bit = 0;
12873 /* Prepare the buffer, 2 entries */
12874 filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_VLAN;
12875 filter_replace_buf.data[0] |=
12876 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12877 /* Field Vector 12b mask */
12878 filter_replace_buf.data[2] = 0xff;
12879 filter_replace_buf.data[3] = 0x0f;
12880 filter_replace_buf.data[4] =
12881 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_INNER_VLAN;
12882 filter_replace_buf.data[4] |=
12883 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12884 /* Field Vector 12b mask */
12885 filter_replace_buf.data[6] = 0xff;
12886 filter_replace_buf.data[7] = 0x0f;
12887 ret = i40e_aq_replace_cloud_filters(hw, &filter_replace,
12888 &filter_replace_buf);
12889 if (ret != I40E_SUCCESS)
12892 if (filter_replace.old_filter_type !=
12893 filter_replace.new_filter_type)
12894 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
12895 " original: 0x%x, new: 0x%x",
12897 filter_replace.old_filter_type,
12898 filter_replace.new_filter_type);
12900 /* Apply the second L2 cloud filter */
12901 memset(&filter_replace, 0,
12902 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
12903 memset(&filter_replace_buf, 0,
12904 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
12906 /* create L2 filter, input for L2 filter will be L1 filter */
12907 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
12908 filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_OIP;
12909 filter_replace.new_filter_type = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12911 /* Prepare the buffer, 2 entries */
12912 filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
12913 filter_replace_buf.data[0] |=
12914 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12915 filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12916 filter_replace_buf.data[4] |=
12917 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12918 ret = i40e_aq_replace_cloud_filters(hw, &filter_replace,
12919 &filter_replace_buf);
12920 if (!ret && (filter_replace.old_filter_type !=
12921 filter_replace.new_filter_type))
12922 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
12923 " original: 0x%x, new: 0x%x",
12925 filter_replace.old_filter_type,
12926 filter_replace.new_filter_type);
12932 i40e_rss_conf_init(struct i40e_rte_flow_rss_conf *out,
12933 const struct rte_flow_action_rss *in)
12935 if (in->key_len > RTE_DIM(out->key) ||
12936 in->queue_num > RTE_DIM(out->queue))
12938 if (!in->key && in->key_len)
12940 out->conf = (struct rte_flow_action_rss){
12942 .level = in->level,
12943 .types = in->types,
12944 .key_len = in->key_len,
12945 .queue_num = in->queue_num,
12946 .queue = memcpy(out->queue, in->queue,
12947 sizeof(*in->queue) * in->queue_num),
12950 out->conf.key = memcpy(out->key, in->key, in->key_len);
12954 /* Write HENA register to enable hash */
12956 i40e_rss_hash_set(struct i40e_pf *pf, struct i40e_rte_flow_rss_conf *rss_conf)
12958 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
12959 uint8_t *key = (void *)(uintptr_t)rss_conf->conf.key;
12963 ret = i40e_set_rss_key(pf->main_vsi, key,
12964 rss_conf->conf.key_len);
12968 hena = i40e_config_hena(pf->adapter, rss_conf->conf.types);
12969 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
12970 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
12971 I40E_WRITE_FLUSH(hw);
12976 /* Configure hash input set */
12978 i40e_rss_conf_hash_inset(struct i40e_pf *pf, uint64_t types)
12980 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
12981 struct rte_eth_input_set_conf conf;
12986 static const struct {
12988 enum rte_eth_input_set_field field;
12989 } inset_match_table[] = {
12990 {ETH_RSS_FRAG_IPV4 | ETH_RSS_L3_SRC_ONLY,
12991 RTE_ETH_INPUT_SET_L3_SRC_IP4},
12992 {ETH_RSS_FRAG_IPV4 | ETH_RSS_L3_DST_ONLY,
12993 RTE_ETH_INPUT_SET_L3_DST_IP4},
12994 {ETH_RSS_FRAG_IPV4 | ETH_RSS_L4_SRC_ONLY,
12995 RTE_ETH_INPUT_SET_UNKNOWN},
12996 {ETH_RSS_FRAG_IPV4 | ETH_RSS_L4_DST_ONLY,
12997 RTE_ETH_INPUT_SET_UNKNOWN},
12999 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L3_SRC_ONLY,
13000 RTE_ETH_INPUT_SET_L3_SRC_IP4},
13001 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L3_DST_ONLY,
13002 RTE_ETH_INPUT_SET_L3_DST_IP4},
13003 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L4_SRC_ONLY,
13004 RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
13005 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L4_DST_ONLY,
13006 RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
13008 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L3_SRC_ONLY,
13009 RTE_ETH_INPUT_SET_L3_SRC_IP4},
13010 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L3_DST_ONLY,
13011 RTE_ETH_INPUT_SET_L3_DST_IP4},
13012 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L4_SRC_ONLY,
13013 RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
13014 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L4_DST_ONLY,
13015 RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
13017 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L3_SRC_ONLY,
13018 RTE_ETH_INPUT_SET_L3_SRC_IP4},
13019 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L3_DST_ONLY,
13020 RTE_ETH_INPUT_SET_L3_DST_IP4},
13021 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L4_SRC_ONLY,
13022 RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
13023 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L4_DST_ONLY,
13024 RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
13026 {ETH_RSS_NONFRAG_IPV4_OTHER | ETH_RSS_L3_SRC_ONLY,
13027 RTE_ETH_INPUT_SET_L3_SRC_IP4},
13028 {ETH_RSS_NONFRAG_IPV4_OTHER | ETH_RSS_L3_DST_ONLY,
13029 RTE_ETH_INPUT_SET_L3_DST_IP4},
13030 {ETH_RSS_NONFRAG_IPV4_OTHER | ETH_RSS_L4_SRC_ONLY,
13031 RTE_ETH_INPUT_SET_UNKNOWN},
13032 {ETH_RSS_NONFRAG_IPV4_OTHER | ETH_RSS_L4_DST_ONLY,
13033 RTE_ETH_INPUT_SET_UNKNOWN},
13035 {ETH_RSS_FRAG_IPV6 | ETH_RSS_L3_SRC_ONLY,
13036 RTE_ETH_INPUT_SET_L3_SRC_IP6},
13037 {ETH_RSS_FRAG_IPV6 | ETH_RSS_L3_DST_ONLY,
13038 RTE_ETH_INPUT_SET_L3_DST_IP6},
13039 {ETH_RSS_FRAG_IPV6 | ETH_RSS_L4_SRC_ONLY,
13040 RTE_ETH_INPUT_SET_UNKNOWN},
13041 {ETH_RSS_FRAG_IPV6 | ETH_RSS_L4_DST_ONLY,
13042 RTE_ETH_INPUT_SET_UNKNOWN},
13044 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L3_SRC_ONLY,
13045 RTE_ETH_INPUT_SET_L3_SRC_IP6},
13046 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L3_DST_ONLY,
13047 RTE_ETH_INPUT_SET_L3_DST_IP6},
13048 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L4_SRC_ONLY,
13049 RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
13050 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L4_DST_ONLY,
13051 RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
13053 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L3_SRC_ONLY,
13054 RTE_ETH_INPUT_SET_L3_SRC_IP6},
13055 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L3_DST_ONLY,
13056 RTE_ETH_INPUT_SET_L3_DST_IP6},
13057 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L4_SRC_ONLY,
13058 RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
13059 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L4_DST_ONLY,
13060 RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
13062 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L3_SRC_ONLY,
13063 RTE_ETH_INPUT_SET_L3_SRC_IP6},
13064 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L3_DST_ONLY,
13065 RTE_ETH_INPUT_SET_L3_DST_IP6},
13066 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L4_SRC_ONLY,
13067 RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
13068 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L4_DST_ONLY,
13069 RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
13071 {ETH_RSS_NONFRAG_IPV6_OTHER | ETH_RSS_L3_SRC_ONLY,
13072 RTE_ETH_INPUT_SET_L3_SRC_IP6},
13073 {ETH_RSS_NONFRAG_IPV6_OTHER | ETH_RSS_L3_DST_ONLY,
13074 RTE_ETH_INPUT_SET_L3_DST_IP6},
13075 {ETH_RSS_NONFRAG_IPV6_OTHER | ETH_RSS_L4_SRC_ONLY,
13076 RTE_ETH_INPUT_SET_UNKNOWN},
13077 {ETH_RSS_NONFRAG_IPV6_OTHER | ETH_RSS_L4_DST_ONLY,
13078 RTE_ETH_INPUT_SET_UNKNOWN},
13081 mask0 = types & pf->adapter->flow_types_mask;
13082 conf.op = RTE_ETH_INPUT_SET_SELECT;
13083 conf.inset_size = 0;
13084 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < RTE_ETH_FLOW_MAX; i++) {
13085 if (mask0 & (1ULL << i)) {
13086 conf.flow_type = i;
13091 for (j = 0; j < RTE_DIM(inset_match_table); j++) {
13092 if ((types & inset_match_table[j].type) ==
13093 inset_match_table[j].type) {
13094 if (inset_match_table[j].field ==
13095 RTE_ETH_INPUT_SET_UNKNOWN)
13098 conf.field[conf.inset_size] =
13099 inset_match_table[j].field;
13104 if (conf.inset_size) {
13105 ret = i40e_hash_filter_inset_select(hw, &conf);
13113 /* Look up the conflicted rule then mark it as invalid */
13115 i40e_rss_mark_invalid_rule(struct i40e_pf *pf,
13116 struct i40e_rte_flow_rss_conf *conf)
13118 struct i40e_rss_filter *rss_item;
13119 uint64_t rss_inset;
13121 /* Clear input set bits before comparing the pctype */
13122 rss_inset = ~(ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY |
13123 ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY);
13125 /* Look up the conflicted rule then mark it as invalid */
13126 TAILQ_FOREACH(rss_item, &pf->rss_config_list, next) {
13127 if (!rss_item->rss_filter_info.valid)
13130 if (conf->conf.queue_num &&
13131 rss_item->rss_filter_info.conf.queue_num)
13132 rss_item->rss_filter_info.valid = false;
13134 if (conf->conf.types &&
13135 (rss_item->rss_filter_info.conf.types &
13137 (conf->conf.types & rss_inset))
13138 rss_item->rss_filter_info.valid = false;
13140 if (conf->conf.func ==
13141 RTE_ETH_HASH_FUNCTION_SIMPLE_XOR &&
13142 rss_item->rss_filter_info.conf.func ==
13143 RTE_ETH_HASH_FUNCTION_SIMPLE_XOR)
13144 rss_item->rss_filter_info.valid = false;
13148 /* Configure RSS hash function */
13150 i40e_rss_config_hash_function(struct i40e_pf *pf,
13151 struct i40e_rte_flow_rss_conf *conf)
13153 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
13158 if (conf->conf.func == RTE_ETH_HASH_FUNCTION_SIMPLE_XOR) {
13159 reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
13160 if (!(reg & I40E_GLQF_CTL_HTOEP_MASK)) {
13161 PMD_DRV_LOG(DEBUG, "Hash function already set to Simple XOR");
13162 I40E_WRITE_FLUSH(hw);
13163 i40e_rss_mark_invalid_rule(pf, conf);
13167 reg &= ~I40E_GLQF_CTL_HTOEP_MASK;
13169 i40e_write_global_rx_ctl(hw, I40E_GLQF_CTL, reg);
13170 I40E_WRITE_FLUSH(hw);
13171 i40e_rss_mark_invalid_rule(pf, conf);
13172 } else if (conf->conf.func ==
13173 RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ) {
13174 mask0 = conf->conf.types & pf->adapter->flow_types_mask;
13176 i40e_set_symmetric_hash_enable_per_port(hw, 1);
13177 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < UINT64_BIT; i++) {
13178 if (mask0 & (1UL << i))
13182 for (j = I40E_FILTER_PCTYPE_INVALID + 1;
13183 j < I40E_FILTER_PCTYPE_MAX; j++) {
13184 if (pf->adapter->pctypes_tbl[i] & (1ULL << j))
13185 i40e_write_global_rx_ctl(hw,
13187 I40E_GLQF_HSYM_SYMH_ENA_MASK);
13194 /* Enable RSS according to the configuration */
13196 i40e_rss_enable_hash(struct i40e_pf *pf,
13197 struct i40e_rte_flow_rss_conf *conf)
13199 struct i40e_rte_flow_rss_conf *rss_info = &pf->rss_info;
13200 struct i40e_rte_flow_rss_conf rss_conf;
13202 if (!(conf->conf.types & pf->adapter->flow_types_mask))
13205 memset(&rss_conf, 0, sizeof(rss_conf));
13206 rte_memcpy(&rss_conf, conf, sizeof(rss_conf));
13208 /* Configure hash input set */
13209 if (i40e_rss_conf_hash_inset(pf, conf->conf.types))
13212 if (rss_conf.conf.key == NULL || rss_conf.conf.key_len <
13213 (I40E_PFQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t)) {
13214 /* Random default keys */
13215 static uint32_t rss_key_default[] = {0x6b793944,
13216 0x23504cb5, 0x5bea75b6, 0x309f4f12, 0x3dc0a2b8,
13217 0x024ddcdf, 0x339b8ca0, 0x4c4af64a, 0x34fac605,
13218 0x55d85839, 0x3a58997d, 0x2ec938e1, 0x66031581};
13220 rss_conf.conf.key = (uint8_t *)rss_key_default;
13221 rss_conf.conf.key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
13224 "No valid RSS key config for i40e, using default\n");
13227 rss_conf.conf.types |= rss_info->conf.types;
13228 i40e_rss_hash_set(pf, &rss_conf);
13230 if (conf->conf.func == RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ)
13231 i40e_rss_config_hash_function(pf, conf);
13233 i40e_rss_mark_invalid_rule(pf, conf);
13238 /* Configure RSS queue region */
13240 i40e_rss_config_queue_region(struct i40e_pf *pf,
13241 struct i40e_rte_flow_rss_conf *conf)
13243 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
13248 /* If both VMDQ and RSS enabled, not all of PF queues are configured.
13249 * It's necessary to calculate the actual PF queues that are configured.
13251 if (pf->dev_data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG)
13252 num = i40e_pf_calc_configured_queues_num(pf);
13254 num = pf->dev_data->nb_rx_queues;
13256 num = RTE_MIN(num, conf->conf.queue_num);
13257 PMD_DRV_LOG(INFO, "Max of contiguous %u PF queues are configured",
13262 "No PF queues are configured to enable RSS for port %u",
13263 pf->dev_data->port_id);
13267 /* Fill in redirection table */
13268 for (i = 0, j = 0; i < hw->func_caps.rss_table_size; i++, j++) {
13271 lut = (lut << 8) | (conf->conf.queue[j] & ((0x1 <<
13272 hw->func_caps.rss_table_entry_width) - 1));
13274 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i >> 2), lut);
13277 i40e_rss_mark_invalid_rule(pf, conf);
13282 /* Configure RSS hash function to default */
13284 i40e_rss_clear_hash_function(struct i40e_pf *pf,
13285 struct i40e_rte_flow_rss_conf *conf)
13287 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
13292 if (conf->conf.func == RTE_ETH_HASH_FUNCTION_SIMPLE_XOR) {
13293 reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
13294 if (reg & I40E_GLQF_CTL_HTOEP_MASK) {
13296 "Hash function already set to Toeplitz");
13297 I40E_WRITE_FLUSH(hw);
13301 reg |= I40E_GLQF_CTL_HTOEP_MASK;
13303 i40e_write_global_rx_ctl(hw, I40E_GLQF_CTL, reg);
13304 I40E_WRITE_FLUSH(hw);
13305 } else if (conf->conf.func ==
13306 RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ) {
13307 mask0 = conf->conf.types & pf->adapter->flow_types_mask;
13309 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < UINT64_BIT; i++) {
13310 if (mask0 & (1UL << i))
13314 for (j = I40E_FILTER_PCTYPE_INVALID + 1;
13315 j < I40E_FILTER_PCTYPE_MAX; j++) {
13316 if (pf->adapter->pctypes_tbl[i] & (1ULL << j))
13317 i40e_write_global_rx_ctl(hw,
13326 /* Disable RSS hash and configure default input set */
13328 i40e_rss_disable_hash(struct i40e_pf *pf,
13329 struct i40e_rte_flow_rss_conf *conf)
13331 struct i40e_rte_flow_rss_conf *rss_info = &pf->rss_info;
13332 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
13333 struct i40e_rte_flow_rss_conf rss_conf;
13336 memset(&rss_conf, 0, sizeof(rss_conf));
13337 rte_memcpy(&rss_conf, conf, sizeof(rss_conf));
13339 /* Disable RSS hash */
13340 rss_conf.conf.types = rss_info->conf.types & ~(conf->conf.types);
13341 i40e_rss_hash_set(pf, &rss_conf);
13343 for (i = RTE_ETH_FLOW_IPV4; i <= RTE_ETH_FLOW_L2_PAYLOAD; i++) {
13344 if (!(pf->adapter->flow_types_mask & (1ULL << i)) ||
13345 !(conf->conf.types & (1ULL << i)))
13348 /* Configure default input set */
13349 struct rte_eth_input_set_conf input_conf = {
13350 .op = RTE_ETH_INPUT_SET_SELECT,
13354 input_conf.field[0] = RTE_ETH_INPUT_SET_DEFAULT;
13355 i40e_hash_filter_inset_select(hw, &input_conf);
13358 rss_info->conf.types = rss_conf.conf.types;
13360 i40e_rss_clear_hash_function(pf, conf);
13365 /* Configure RSS queue region to default */
13367 i40e_rss_clear_queue_region(struct i40e_pf *pf)
13369 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
13370 struct i40e_rte_flow_rss_conf *rss_info = &pf->rss_info;
13371 uint16_t queue[I40E_MAX_Q_PER_TC];
13372 uint32_t num_rxq, i;
13376 num_rxq = RTE_MIN(pf->dev_data->nb_rx_queues, I40E_MAX_Q_PER_TC);
13378 for (j = 0; j < num_rxq; j++)
13381 /* If both VMDQ and RSS enabled, not all of PF queues are configured.
13382 * It's necessary to calculate the actual PF queues that are configured.
13384 if (pf->dev_data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG)
13385 num = i40e_pf_calc_configured_queues_num(pf);
13387 num = pf->dev_data->nb_rx_queues;
13389 num = RTE_MIN(num, num_rxq);
13390 PMD_DRV_LOG(INFO, "Max of contiguous %u PF queues are configured",
13395 "No PF queues are configured to enable RSS for port %u",
13396 pf->dev_data->port_id);
13400 /* Fill in redirection table */
13401 for (i = 0, j = 0; i < hw->func_caps.rss_table_size; i++, j++) {
13404 lut = (lut << 8) | (queue[j] & ((0x1 <<
13405 hw->func_caps.rss_table_entry_width) - 1));
13407 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i >> 2), lut);
13410 rss_info->conf.queue_num = 0;
13411 memset(&rss_info->conf.queue, 0, sizeof(uint16_t));
13417 i40e_config_rss_filter(struct i40e_pf *pf,
13418 struct i40e_rte_flow_rss_conf *conf, bool add)
13420 struct i40e_rte_flow_rss_conf *rss_info = &pf->rss_info;
13421 struct rte_flow_action_rss update_conf = rss_info->conf;
13425 if (conf->conf.queue_num) {
13426 /* Configure RSS queue region */
13427 ret = i40e_rss_config_queue_region(pf, conf);
13431 update_conf.queue_num = conf->conf.queue_num;
13432 update_conf.queue = conf->conf.queue;
13433 } else if (conf->conf.func ==
13434 RTE_ETH_HASH_FUNCTION_SIMPLE_XOR) {
13435 /* Configure hash function */
13436 ret = i40e_rss_config_hash_function(pf, conf);
13440 update_conf.func = conf->conf.func;
13442 /* Configure hash enable and input set */
13443 ret = i40e_rss_enable_hash(pf, conf);
13447 update_conf.types |= conf->conf.types;
13448 update_conf.key = conf->conf.key;
13449 update_conf.key_len = conf->conf.key_len;
13452 /* Update RSS info in pf */
13453 if (i40e_rss_conf_init(rss_info, &update_conf))
13459 if (conf->conf.queue_num)
13460 i40e_rss_clear_queue_region(pf);
13461 else if (conf->conf.func == RTE_ETH_HASH_FUNCTION_SIMPLE_XOR)
13462 i40e_rss_clear_hash_function(pf, conf);
13464 i40e_rss_disable_hash(pf, conf);
13470 RTE_INIT(i40e_init_log)
13472 i40e_logtype_init = rte_log_register("pmd.net.i40e.init");
13473 if (i40e_logtype_init >= 0)
13474 rte_log_set_level(i40e_logtype_init, RTE_LOG_NOTICE);
13475 i40e_logtype_driver = rte_log_register("pmd.net.i40e.driver");
13476 if (i40e_logtype_driver >= 0)
13477 rte_log_set_level(i40e_logtype_driver, RTE_LOG_NOTICE);
13479 #ifdef RTE_LIBRTE_I40E_DEBUG_RX
13480 i40e_logtype_rx = rte_log_register("pmd.net.i40e.rx");
13481 if (i40e_logtype_rx >= 0)
13482 rte_log_set_level(i40e_logtype_rx, RTE_LOG_DEBUG);
13485 #ifdef RTE_LIBRTE_I40E_DEBUG_TX
13486 i40e_logtype_tx = rte_log_register("pmd.net.i40e.tx");
13487 if (i40e_logtype_tx >= 0)
13488 rte_log_set_level(i40e_logtype_tx, RTE_LOG_DEBUG);
13491 #ifdef RTE_LIBRTE_I40E_DEBUG_TX_FREE
13492 i40e_logtype_tx_free = rte_log_register("pmd.net.i40e.tx_free");
13493 if (i40e_logtype_tx_free >= 0)
13494 rte_log_set_level(i40e_logtype_tx_free, RTE_LOG_DEBUG);
13498 RTE_PMD_REGISTER_PARAM_STRING(net_i40e,
13499 ETH_I40E_FLOATING_VEB_ARG "=1"
13500 ETH_I40E_FLOATING_VEB_LIST_ARG "=<string>"
13501 ETH_I40E_QUEUE_NUM_PER_VF_ARG "=1|2|4|8|16"
13502 ETH_I40E_SUPPORT_MULTI_DRIVER "=1"
13503 ETH_I40E_USE_LATEST_VEC "=0|1");