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;
2283 uint16_t nb_rxq, nb_txq;
2285 hw->adapter_stopped = 0;
2287 rte_intr_disable(intr_handle);
2289 if ((rte_intr_cap_multiple(intr_handle) ||
2290 !RTE_ETH_DEV_SRIOV(dev).active) &&
2291 dev->data->dev_conf.intr_conf.rxq != 0) {
2292 intr_vector = dev->data->nb_rx_queues;
2293 ret = rte_intr_efd_enable(intr_handle, intr_vector);
2298 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
2299 intr_handle->intr_vec =
2300 rte_zmalloc("intr_vec",
2301 dev->data->nb_rx_queues * sizeof(int),
2303 if (!intr_handle->intr_vec) {
2305 "Failed to allocate %d rx_queues intr_vec",
2306 dev->data->nb_rx_queues);
2311 /* Initialize VSI */
2312 ret = i40e_dev_rxtx_init(pf);
2313 if (ret != I40E_SUCCESS) {
2314 PMD_DRV_LOG(ERR, "Failed to init rx/tx queues");
2318 /* Map queues with MSIX interrupt */
2319 main_vsi->nb_used_qps = dev->data->nb_rx_queues -
2320 pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
2321 i40e_vsi_queues_bind_intr(main_vsi, I40E_ITR_INDEX_DEFAULT);
2322 i40e_vsi_enable_queues_intr(main_vsi);
2324 /* Map VMDQ VSI queues with MSIX interrupt */
2325 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2326 pf->vmdq[i].vsi->nb_used_qps = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
2327 i40e_vsi_queues_bind_intr(pf->vmdq[i].vsi,
2328 I40E_ITR_INDEX_DEFAULT);
2329 i40e_vsi_enable_queues_intr(pf->vmdq[i].vsi);
2332 /* enable FDIR MSIX interrupt */
2333 if (pf->fdir.fdir_vsi) {
2334 i40e_vsi_queues_bind_intr(pf->fdir.fdir_vsi,
2335 I40E_ITR_INDEX_NONE);
2336 i40e_vsi_enable_queues_intr(pf->fdir.fdir_vsi);
2339 /* Enable all queues which have been configured */
2340 for (nb_rxq = 0; nb_rxq < dev->data->nb_rx_queues; nb_rxq++) {
2341 ret = i40e_dev_rx_queue_start(dev, nb_rxq);
2346 for (nb_txq = 0; nb_txq < dev->data->nb_tx_queues; nb_txq++) {
2347 ret = i40e_dev_tx_queue_start(dev, nb_txq);
2352 /* Enable receiving broadcast packets */
2353 ret = i40e_aq_set_vsi_broadcast(hw, main_vsi->seid, true, NULL);
2354 if (ret != I40E_SUCCESS)
2355 PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
2357 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2358 ret = i40e_aq_set_vsi_broadcast(hw, pf->vmdq[i].vsi->seid,
2360 if (ret != I40E_SUCCESS)
2361 PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
2364 /* Enable the VLAN promiscuous mode. */
2366 for (i = 0; i < pf->vf_num; i++) {
2367 vsi = pf->vfs[i].vsi;
2368 i40e_aq_set_vsi_vlan_promisc(hw, vsi->seid,
2373 /* Enable mac loopback mode */
2374 if (dev->data->dev_conf.lpbk_mode == I40E_AQ_LB_MODE_NONE ||
2375 dev->data->dev_conf.lpbk_mode == I40E_AQ_LB_PHY_LOCAL) {
2376 ret = i40e_aq_set_lb_modes(hw, dev->data->dev_conf.lpbk_mode, NULL);
2377 if (ret != I40E_SUCCESS) {
2378 PMD_DRV_LOG(ERR, "fail to set loopback link");
2383 /* Apply link configure */
2384 ret = i40e_apply_link_speed(dev);
2385 if (I40E_SUCCESS != ret) {
2386 PMD_DRV_LOG(ERR, "Fail to apply link setting");
2390 if (!rte_intr_allow_others(intr_handle)) {
2391 rte_intr_callback_unregister(intr_handle,
2392 i40e_dev_interrupt_handler,
2394 /* configure and enable device interrupt */
2395 i40e_pf_config_irq0(hw, FALSE);
2396 i40e_pf_enable_irq0(hw);
2398 if (dev->data->dev_conf.intr_conf.lsc != 0)
2400 "lsc won't enable because of no intr multiplex");
2402 ret = i40e_aq_set_phy_int_mask(hw,
2403 ~(I40E_AQ_EVENT_LINK_UPDOWN |
2404 I40E_AQ_EVENT_MODULE_QUAL_FAIL |
2405 I40E_AQ_EVENT_MEDIA_NA), NULL);
2406 if (ret != I40E_SUCCESS)
2407 PMD_DRV_LOG(WARNING, "Fail to set phy mask");
2409 /* Call get_link_info aq commond to enable/disable LSE */
2410 i40e_dev_link_update(dev, 0);
2413 if (dev->data->dev_conf.intr_conf.rxq == 0) {
2414 rte_eal_alarm_set(I40E_ALARM_INTERVAL,
2415 i40e_dev_alarm_handler, dev);
2417 /* enable uio intr after callback register */
2418 rte_intr_enable(intr_handle);
2421 i40e_filter_restore(pf);
2423 if (pf->tm_conf.root && !pf->tm_conf.committed)
2424 PMD_DRV_LOG(WARNING,
2425 "please call hierarchy_commit() "
2426 "before starting the port");
2428 return I40E_SUCCESS;
2431 for (i = 0; i < nb_txq; i++)
2432 i40e_dev_tx_queue_stop(dev, i);
2434 for (i = 0; i < nb_rxq; i++)
2435 i40e_dev_rx_queue_stop(dev, i);
2441 i40e_dev_stop(struct rte_eth_dev *dev)
2443 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2444 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2445 struct i40e_vsi *main_vsi = pf->main_vsi;
2446 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2447 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2450 if (hw->adapter_stopped == 1)
2453 if (dev->data->dev_conf.intr_conf.rxq == 0) {
2454 rte_eal_alarm_cancel(i40e_dev_alarm_handler, dev);
2455 rte_intr_enable(intr_handle);
2458 /* Disable all queues */
2459 for (i = 0; i < dev->data->nb_tx_queues; i++)
2460 i40e_dev_tx_queue_stop(dev, i);
2462 for (i = 0; i < dev->data->nb_rx_queues; i++)
2463 i40e_dev_rx_queue_stop(dev, i);
2465 /* un-map queues with interrupt registers */
2466 i40e_vsi_disable_queues_intr(main_vsi);
2467 i40e_vsi_queues_unbind_intr(main_vsi);
2469 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2470 i40e_vsi_disable_queues_intr(pf->vmdq[i].vsi);
2471 i40e_vsi_queues_unbind_intr(pf->vmdq[i].vsi);
2474 if (pf->fdir.fdir_vsi) {
2475 i40e_vsi_queues_unbind_intr(pf->fdir.fdir_vsi);
2476 i40e_vsi_disable_queues_intr(pf->fdir.fdir_vsi);
2478 /* Clear all queues and release memory */
2479 i40e_dev_clear_queues(dev);
2482 i40e_dev_set_link_down(dev);
2484 if (!rte_intr_allow_others(intr_handle))
2485 /* resume to the default handler */
2486 rte_intr_callback_register(intr_handle,
2487 i40e_dev_interrupt_handler,
2490 /* Clean datapath event and queue/vec mapping */
2491 rte_intr_efd_disable(intr_handle);
2492 if (intr_handle->intr_vec) {
2493 rte_free(intr_handle->intr_vec);
2494 intr_handle->intr_vec = NULL;
2497 /* reset hierarchy commit */
2498 pf->tm_conf.committed = false;
2500 hw->adapter_stopped = 1;
2502 pf->adapter->rss_reta_updated = 0;
2506 i40e_dev_close(struct rte_eth_dev *dev)
2508 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2509 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2510 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2511 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2512 struct i40e_mirror_rule *p_mirror;
2513 struct i40e_filter_control_settings settings;
2514 struct rte_flow *p_flow;
2518 uint8_t aq_fail = 0;
2521 PMD_INIT_FUNC_TRACE();
2523 ret = rte_eth_switch_domain_free(pf->switch_domain_id);
2525 PMD_INIT_LOG(WARNING, "failed to free switch domain: %d", ret);
2530 /* Remove all mirror rules */
2531 while ((p_mirror = TAILQ_FIRST(&pf->mirror_list))) {
2532 ret = i40e_aq_del_mirror_rule(hw,
2533 pf->main_vsi->veb->seid,
2534 p_mirror->rule_type,
2536 p_mirror->num_entries,
2539 PMD_DRV_LOG(ERR, "failed to remove mirror rule: "
2540 "status = %d, aq_err = %d.", ret,
2541 hw->aq.asq_last_status);
2543 /* remove mirror software resource anyway */
2544 TAILQ_REMOVE(&pf->mirror_list, p_mirror, rules);
2546 pf->nb_mirror_rule--;
2549 i40e_dev_free_queues(dev);
2551 /* Disable interrupt */
2552 i40e_pf_disable_irq0(hw);
2553 rte_intr_disable(intr_handle);
2556 * Only legacy filter API needs the following fdir config. So when the
2557 * legacy filter API is deprecated, the following code should also be
2560 i40e_fdir_teardown(pf);
2562 /* shutdown and destroy the HMC */
2563 i40e_shutdown_lan_hmc(hw);
2565 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2566 i40e_vsi_release(pf->vmdq[i].vsi);
2567 pf->vmdq[i].vsi = NULL;
2572 /* release all the existing VSIs and VEBs */
2573 i40e_vsi_release(pf->main_vsi);
2575 /* shutdown the adminq */
2576 i40e_aq_queue_shutdown(hw, true);
2577 i40e_shutdown_adminq(hw);
2579 i40e_res_pool_destroy(&pf->qp_pool);
2580 i40e_res_pool_destroy(&pf->msix_pool);
2582 /* Disable flexible payload in global configuration */
2583 if (!pf->support_multi_driver)
2584 i40e_flex_payload_reg_set_default(hw);
2586 /* force a PF reset to clean anything leftover */
2587 reg = I40E_READ_REG(hw, I40E_PFGEN_CTRL);
2588 I40E_WRITE_REG(hw, I40E_PFGEN_CTRL,
2589 (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
2590 I40E_WRITE_FLUSH(hw);
2592 dev->dev_ops = NULL;
2593 dev->rx_pkt_burst = NULL;
2594 dev->tx_pkt_burst = NULL;
2596 /* Clear PXE mode */
2597 i40e_clear_pxe_mode(hw);
2599 /* Unconfigure filter control */
2600 memset(&settings, 0, sizeof(settings));
2601 ret = i40e_set_filter_control(hw, &settings);
2603 PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
2606 /* Disable flow control */
2607 hw->fc.requested_mode = I40E_FC_NONE;
2608 i40e_set_fc(hw, &aq_fail, TRUE);
2610 /* uninitialize pf host driver */
2611 i40e_pf_host_uninit(dev);
2614 ret = rte_intr_callback_unregister(intr_handle,
2615 i40e_dev_interrupt_handler, dev);
2616 if (ret >= 0 || ret == -ENOENT) {
2618 } else if (ret != -EAGAIN) {
2620 "intr callback unregister failed: %d",
2623 i40e_msec_delay(500);
2624 } while (retries++ < 5);
2626 i40e_rm_ethtype_filter_list(pf);
2627 i40e_rm_tunnel_filter_list(pf);
2628 i40e_rm_fdir_filter_list(pf);
2630 /* Remove all flows */
2631 while ((p_flow = TAILQ_FIRST(&pf->flow_list))) {
2632 TAILQ_REMOVE(&pf->flow_list, p_flow, node);
2636 /* Remove all Traffic Manager configuration */
2637 i40e_tm_conf_uninit(dev);
2639 hw->adapter_closed = 1;
2643 * Reset PF device only to re-initialize resources in PMD layer
2646 i40e_dev_reset(struct rte_eth_dev *dev)
2650 /* When a DPDK PMD PF begin to reset PF port, it should notify all
2651 * its VF to make them align with it. The detailed notification
2652 * mechanism is PMD specific. As to i40e PF, it is rather complex.
2653 * To avoid unexpected behavior in VF, currently reset of PF with
2654 * SR-IOV activation is not supported. It might be supported later.
2656 if (dev->data->sriov.active)
2659 ret = eth_i40e_dev_uninit(dev);
2663 ret = eth_i40e_dev_init(dev, NULL);
2669 i40e_dev_promiscuous_enable(struct rte_eth_dev *dev)
2671 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2672 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2673 struct i40e_vsi *vsi = pf->main_vsi;
2676 status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2678 if (status != I40E_SUCCESS) {
2679 PMD_DRV_LOG(ERR, "Failed to enable unicast promiscuous");
2683 status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
2685 if (status != I40E_SUCCESS) {
2686 PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
2687 /* Rollback unicast promiscuous mode */
2688 i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2697 i40e_dev_promiscuous_disable(struct rte_eth_dev *dev)
2699 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2700 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2701 struct i40e_vsi *vsi = pf->main_vsi;
2704 status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2706 if (status != I40E_SUCCESS) {
2707 PMD_DRV_LOG(ERR, "Failed to disable unicast promiscuous");
2711 /* must remain in all_multicast mode */
2712 if (dev->data->all_multicast == 1)
2715 status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
2717 if (status != I40E_SUCCESS) {
2718 PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
2719 /* Rollback unicast promiscuous mode */
2720 i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2729 i40e_dev_allmulticast_enable(struct rte_eth_dev *dev)
2731 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2732 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2733 struct i40e_vsi *vsi = pf->main_vsi;
2736 ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid, TRUE, NULL);
2737 if (ret != I40E_SUCCESS) {
2738 PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
2746 i40e_dev_allmulticast_disable(struct rte_eth_dev *dev)
2748 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2749 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2750 struct i40e_vsi *vsi = pf->main_vsi;
2753 if (dev->data->promiscuous == 1)
2754 return 0; /* must remain in all_multicast mode */
2756 ret = i40e_aq_set_vsi_multicast_promiscuous(hw,
2757 vsi->seid, FALSE, NULL);
2758 if (ret != I40E_SUCCESS) {
2759 PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
2767 * Set device link up.
2770 i40e_dev_set_link_up(struct rte_eth_dev *dev)
2772 /* re-apply link speed setting */
2773 return i40e_apply_link_speed(dev);
2777 * Set device link down.
2780 i40e_dev_set_link_down(struct rte_eth_dev *dev)
2782 uint8_t speed = I40E_LINK_SPEED_UNKNOWN;
2783 uint8_t abilities = 0;
2784 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2786 abilities = I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
2787 return i40e_phy_conf_link(hw, abilities, speed, false);
2790 static __rte_always_inline void
2791 update_link_reg(struct i40e_hw *hw, struct rte_eth_link *link)
2793 /* Link status registers and values*/
2794 #define I40E_PRTMAC_LINKSTA 0x001E2420
2795 #define I40E_REG_LINK_UP 0x40000080
2796 #define I40E_PRTMAC_MACC 0x001E24E0
2797 #define I40E_REG_MACC_25GB 0x00020000
2798 #define I40E_REG_SPEED_MASK 0x38000000
2799 #define I40E_REG_SPEED_0 0x00000000
2800 #define I40E_REG_SPEED_1 0x08000000
2801 #define I40E_REG_SPEED_2 0x10000000
2802 #define I40E_REG_SPEED_3 0x18000000
2803 #define I40E_REG_SPEED_4 0x20000000
2804 uint32_t link_speed;
2807 reg_val = I40E_READ_REG(hw, I40E_PRTMAC_LINKSTA);
2808 link_speed = reg_val & I40E_REG_SPEED_MASK;
2809 reg_val &= I40E_REG_LINK_UP;
2810 link->link_status = (reg_val == I40E_REG_LINK_UP) ? 1 : 0;
2812 if (unlikely(link->link_status == 0))
2815 /* Parse the link status */
2816 switch (link_speed) {
2817 case I40E_REG_SPEED_0:
2818 link->link_speed = ETH_SPEED_NUM_100M;
2820 case I40E_REG_SPEED_1:
2821 link->link_speed = ETH_SPEED_NUM_1G;
2823 case I40E_REG_SPEED_2:
2824 if (hw->mac.type == I40E_MAC_X722)
2825 link->link_speed = ETH_SPEED_NUM_2_5G;
2827 link->link_speed = ETH_SPEED_NUM_10G;
2829 case I40E_REG_SPEED_3:
2830 if (hw->mac.type == I40E_MAC_X722) {
2831 link->link_speed = ETH_SPEED_NUM_5G;
2833 reg_val = I40E_READ_REG(hw, I40E_PRTMAC_MACC);
2835 if (reg_val & I40E_REG_MACC_25GB)
2836 link->link_speed = ETH_SPEED_NUM_25G;
2838 link->link_speed = ETH_SPEED_NUM_40G;
2841 case I40E_REG_SPEED_4:
2842 if (hw->mac.type == I40E_MAC_X722)
2843 link->link_speed = ETH_SPEED_NUM_10G;
2845 link->link_speed = ETH_SPEED_NUM_20G;
2848 PMD_DRV_LOG(ERR, "Unknown link speed info %u", link_speed);
2853 static __rte_always_inline void
2854 update_link_aq(struct i40e_hw *hw, struct rte_eth_link *link,
2855 bool enable_lse, int wait_to_complete)
2857 #define CHECK_INTERVAL 100 /* 100ms */
2858 #define MAX_REPEAT_TIME 10 /* 1s (10 * 100ms) in total */
2859 uint32_t rep_cnt = MAX_REPEAT_TIME;
2860 struct i40e_link_status link_status;
2863 memset(&link_status, 0, sizeof(link_status));
2866 memset(&link_status, 0, sizeof(link_status));
2868 /* Get link status information from hardware */
2869 status = i40e_aq_get_link_info(hw, enable_lse,
2870 &link_status, NULL);
2871 if (unlikely(status != I40E_SUCCESS)) {
2872 link->link_speed = ETH_SPEED_NUM_NONE;
2873 link->link_duplex = ETH_LINK_FULL_DUPLEX;
2874 PMD_DRV_LOG(ERR, "Failed to get link info");
2878 link->link_status = link_status.link_info & I40E_AQ_LINK_UP;
2879 if (!wait_to_complete || link->link_status)
2882 rte_delay_ms(CHECK_INTERVAL);
2883 } while (--rep_cnt);
2885 /* Parse the link status */
2886 switch (link_status.link_speed) {
2887 case I40E_LINK_SPEED_100MB:
2888 link->link_speed = ETH_SPEED_NUM_100M;
2890 case I40E_LINK_SPEED_1GB:
2891 link->link_speed = ETH_SPEED_NUM_1G;
2893 case I40E_LINK_SPEED_10GB:
2894 link->link_speed = ETH_SPEED_NUM_10G;
2896 case I40E_LINK_SPEED_20GB:
2897 link->link_speed = ETH_SPEED_NUM_20G;
2899 case I40E_LINK_SPEED_25GB:
2900 link->link_speed = ETH_SPEED_NUM_25G;
2902 case I40E_LINK_SPEED_40GB:
2903 link->link_speed = ETH_SPEED_NUM_40G;
2906 link->link_speed = ETH_SPEED_NUM_NONE;
2912 i40e_dev_link_update(struct rte_eth_dev *dev,
2913 int wait_to_complete)
2915 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2916 struct rte_eth_link link;
2917 bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
2920 memset(&link, 0, sizeof(link));
2922 /* i40e uses full duplex only */
2923 link.link_duplex = ETH_LINK_FULL_DUPLEX;
2924 link.link_autoneg = !(dev->data->dev_conf.link_speeds &
2925 ETH_LINK_SPEED_FIXED);
2927 if (!wait_to_complete && !enable_lse)
2928 update_link_reg(hw, &link);
2930 update_link_aq(hw, &link, enable_lse, wait_to_complete);
2933 rte_eth_linkstatus_get(hw->switch_dev, &link);
2935 ret = rte_eth_linkstatus_set(dev, &link);
2936 i40e_notify_all_vfs_link_status(dev);
2941 /* Get all the statistics of a VSI */
2943 i40e_update_vsi_stats(struct i40e_vsi *vsi)
2945 struct i40e_eth_stats *oes = &vsi->eth_stats_offset;
2946 struct i40e_eth_stats *nes = &vsi->eth_stats;
2947 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2948 int idx = rte_le_to_cpu_16(vsi->info.stat_counter_idx);
2950 i40e_stat_update_48(hw, I40E_GLV_GORCH(idx), I40E_GLV_GORCL(idx),
2951 vsi->offset_loaded, &oes->rx_bytes,
2953 i40e_stat_update_48(hw, I40E_GLV_UPRCH(idx), I40E_GLV_UPRCL(idx),
2954 vsi->offset_loaded, &oes->rx_unicast,
2956 i40e_stat_update_48(hw, I40E_GLV_MPRCH(idx), I40E_GLV_MPRCL(idx),
2957 vsi->offset_loaded, &oes->rx_multicast,
2958 &nes->rx_multicast);
2959 i40e_stat_update_48(hw, I40E_GLV_BPRCH(idx), I40E_GLV_BPRCL(idx),
2960 vsi->offset_loaded, &oes->rx_broadcast,
2961 &nes->rx_broadcast);
2962 /* exclude CRC bytes */
2963 nes->rx_bytes -= (nes->rx_unicast + nes->rx_multicast +
2964 nes->rx_broadcast) * RTE_ETHER_CRC_LEN;
2966 i40e_stat_update_32(hw, I40E_GLV_RDPC(idx), vsi->offset_loaded,
2967 &oes->rx_discards, &nes->rx_discards);
2968 /* GLV_REPC not supported */
2969 /* GLV_RMPC not supported */
2970 i40e_stat_update_32(hw, I40E_GLV_RUPP(idx), vsi->offset_loaded,
2971 &oes->rx_unknown_protocol,
2972 &nes->rx_unknown_protocol);
2973 i40e_stat_update_48(hw, I40E_GLV_GOTCH(idx), I40E_GLV_GOTCL(idx),
2974 vsi->offset_loaded, &oes->tx_bytes,
2976 i40e_stat_update_48(hw, I40E_GLV_UPTCH(idx), I40E_GLV_UPTCL(idx),
2977 vsi->offset_loaded, &oes->tx_unicast,
2979 i40e_stat_update_48(hw, I40E_GLV_MPTCH(idx), I40E_GLV_MPTCL(idx),
2980 vsi->offset_loaded, &oes->tx_multicast,
2981 &nes->tx_multicast);
2982 i40e_stat_update_48(hw, I40E_GLV_BPTCH(idx), I40E_GLV_BPTCL(idx),
2983 vsi->offset_loaded, &oes->tx_broadcast,
2984 &nes->tx_broadcast);
2985 /* GLV_TDPC not supported */
2986 i40e_stat_update_32(hw, I40E_GLV_TEPC(idx), vsi->offset_loaded,
2987 &oes->tx_errors, &nes->tx_errors);
2988 vsi->offset_loaded = true;
2990 PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats start *******************",
2992 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", nes->rx_bytes);
2993 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", nes->rx_unicast);
2994 PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", nes->rx_multicast);
2995 PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", nes->rx_broadcast);
2996 PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", nes->rx_discards);
2997 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
2998 nes->rx_unknown_protocol);
2999 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", nes->tx_bytes);
3000 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", nes->tx_unicast);
3001 PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", nes->tx_multicast);
3002 PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", nes->tx_broadcast);
3003 PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", nes->tx_discards);
3004 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", nes->tx_errors);
3005 PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats end *******************",
3010 i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw)
3013 struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
3014 struct i40e_hw_port_stats *os = &pf->stats_offset; /* old stats */
3016 /* Get rx/tx bytes of internal transfer packets */
3017 i40e_stat_update_48(hw, I40E_GLV_GORCH(hw->port),
3018 I40E_GLV_GORCL(hw->port),
3020 &pf->internal_stats_offset.rx_bytes,
3021 &pf->internal_stats.rx_bytes);
3023 i40e_stat_update_48(hw, I40E_GLV_GOTCH(hw->port),
3024 I40E_GLV_GOTCL(hw->port),
3026 &pf->internal_stats_offset.tx_bytes,
3027 &pf->internal_stats.tx_bytes);
3028 /* Get total internal rx packet count */
3029 i40e_stat_update_48(hw, I40E_GLV_UPRCH(hw->port),
3030 I40E_GLV_UPRCL(hw->port),
3032 &pf->internal_stats_offset.rx_unicast,
3033 &pf->internal_stats.rx_unicast);
3034 i40e_stat_update_48(hw, I40E_GLV_MPRCH(hw->port),
3035 I40E_GLV_MPRCL(hw->port),
3037 &pf->internal_stats_offset.rx_multicast,
3038 &pf->internal_stats.rx_multicast);
3039 i40e_stat_update_48(hw, I40E_GLV_BPRCH(hw->port),
3040 I40E_GLV_BPRCL(hw->port),
3042 &pf->internal_stats_offset.rx_broadcast,
3043 &pf->internal_stats.rx_broadcast);
3044 /* Get total internal tx packet count */
3045 i40e_stat_update_48(hw, I40E_GLV_UPTCH(hw->port),
3046 I40E_GLV_UPTCL(hw->port),
3048 &pf->internal_stats_offset.tx_unicast,
3049 &pf->internal_stats.tx_unicast);
3050 i40e_stat_update_48(hw, I40E_GLV_MPTCH(hw->port),
3051 I40E_GLV_MPTCL(hw->port),
3053 &pf->internal_stats_offset.tx_multicast,
3054 &pf->internal_stats.tx_multicast);
3055 i40e_stat_update_48(hw, I40E_GLV_BPTCH(hw->port),
3056 I40E_GLV_BPTCL(hw->port),
3058 &pf->internal_stats_offset.tx_broadcast,
3059 &pf->internal_stats.tx_broadcast);
3061 /* exclude CRC size */
3062 pf->internal_stats.rx_bytes -= (pf->internal_stats.rx_unicast +
3063 pf->internal_stats.rx_multicast +
3064 pf->internal_stats.rx_broadcast) * RTE_ETHER_CRC_LEN;
3066 /* Get statistics of struct i40e_eth_stats */
3067 i40e_stat_update_48(hw, I40E_GLPRT_GORCH(hw->port),
3068 I40E_GLPRT_GORCL(hw->port),
3069 pf->offset_loaded, &os->eth.rx_bytes,
3071 i40e_stat_update_48(hw, I40E_GLPRT_UPRCH(hw->port),
3072 I40E_GLPRT_UPRCL(hw->port),
3073 pf->offset_loaded, &os->eth.rx_unicast,
3074 &ns->eth.rx_unicast);
3075 i40e_stat_update_48(hw, I40E_GLPRT_MPRCH(hw->port),
3076 I40E_GLPRT_MPRCL(hw->port),
3077 pf->offset_loaded, &os->eth.rx_multicast,
3078 &ns->eth.rx_multicast);
3079 i40e_stat_update_48(hw, I40E_GLPRT_BPRCH(hw->port),
3080 I40E_GLPRT_BPRCL(hw->port),
3081 pf->offset_loaded, &os->eth.rx_broadcast,
3082 &ns->eth.rx_broadcast);
3083 /* Workaround: CRC size should not be included in byte statistics,
3084 * so subtract RTE_ETHER_CRC_LEN from the byte counter for each rx
3087 ns->eth.rx_bytes -= (ns->eth.rx_unicast + ns->eth.rx_multicast +
3088 ns->eth.rx_broadcast) * RTE_ETHER_CRC_LEN;
3090 /* exclude internal rx bytes
3091 * Workaround: it is possible I40E_GLV_GORCH[H/L] is updated before
3092 * I40E_GLPRT_GORCH[H/L], so there is a small window that cause negative
3094 * same to I40E_GLV_UPRC[H/L], I40E_GLV_MPRC[H/L], I40E_GLV_BPRC[H/L].
3096 if (ns->eth.rx_bytes < pf->internal_stats.rx_bytes)
3097 ns->eth.rx_bytes = 0;
3099 ns->eth.rx_bytes -= pf->internal_stats.rx_bytes;
3101 if (ns->eth.rx_unicast < pf->internal_stats.rx_unicast)
3102 ns->eth.rx_unicast = 0;
3104 ns->eth.rx_unicast -= pf->internal_stats.rx_unicast;
3106 if (ns->eth.rx_multicast < pf->internal_stats.rx_multicast)
3107 ns->eth.rx_multicast = 0;
3109 ns->eth.rx_multicast -= pf->internal_stats.rx_multicast;
3111 if (ns->eth.rx_broadcast < pf->internal_stats.rx_broadcast)
3112 ns->eth.rx_broadcast = 0;
3114 ns->eth.rx_broadcast -= pf->internal_stats.rx_broadcast;
3116 i40e_stat_update_32(hw, I40E_GLPRT_RDPC(hw->port),
3117 pf->offset_loaded, &os->eth.rx_discards,
3118 &ns->eth.rx_discards);
3119 /* GLPRT_REPC not supported */
3120 /* GLPRT_RMPC not supported */
3121 i40e_stat_update_32(hw, I40E_GLPRT_RUPP(hw->port),
3123 &os->eth.rx_unknown_protocol,
3124 &ns->eth.rx_unknown_protocol);
3125 i40e_stat_update_48(hw, I40E_GLPRT_GOTCH(hw->port),
3126 I40E_GLPRT_GOTCL(hw->port),
3127 pf->offset_loaded, &os->eth.tx_bytes,
3129 i40e_stat_update_48(hw, I40E_GLPRT_UPTCH(hw->port),
3130 I40E_GLPRT_UPTCL(hw->port),
3131 pf->offset_loaded, &os->eth.tx_unicast,
3132 &ns->eth.tx_unicast);
3133 i40e_stat_update_48(hw, I40E_GLPRT_MPTCH(hw->port),
3134 I40E_GLPRT_MPTCL(hw->port),
3135 pf->offset_loaded, &os->eth.tx_multicast,
3136 &ns->eth.tx_multicast);
3137 i40e_stat_update_48(hw, I40E_GLPRT_BPTCH(hw->port),
3138 I40E_GLPRT_BPTCL(hw->port),
3139 pf->offset_loaded, &os->eth.tx_broadcast,
3140 &ns->eth.tx_broadcast);
3141 ns->eth.tx_bytes -= (ns->eth.tx_unicast + ns->eth.tx_multicast +
3142 ns->eth.tx_broadcast) * RTE_ETHER_CRC_LEN;
3144 /* exclude internal tx bytes
3145 * Workaround: it is possible I40E_GLV_GOTCH[H/L] is updated before
3146 * I40E_GLPRT_GOTCH[H/L], so there is a small window that cause negative
3148 * same to I40E_GLV_UPTC[H/L], I40E_GLV_MPTC[H/L], I40E_GLV_BPTC[H/L].
3150 if (ns->eth.tx_bytes < pf->internal_stats.tx_bytes)
3151 ns->eth.tx_bytes = 0;
3153 ns->eth.tx_bytes -= pf->internal_stats.tx_bytes;
3155 if (ns->eth.tx_unicast < pf->internal_stats.tx_unicast)
3156 ns->eth.tx_unicast = 0;
3158 ns->eth.tx_unicast -= pf->internal_stats.tx_unicast;
3160 if (ns->eth.tx_multicast < pf->internal_stats.tx_multicast)
3161 ns->eth.tx_multicast = 0;
3163 ns->eth.tx_multicast -= pf->internal_stats.tx_multicast;
3165 if (ns->eth.tx_broadcast < pf->internal_stats.tx_broadcast)
3166 ns->eth.tx_broadcast = 0;
3168 ns->eth.tx_broadcast -= pf->internal_stats.tx_broadcast;
3170 /* GLPRT_TEPC not supported */
3172 /* additional port specific stats */
3173 i40e_stat_update_32(hw, I40E_GLPRT_TDOLD(hw->port),
3174 pf->offset_loaded, &os->tx_dropped_link_down,
3175 &ns->tx_dropped_link_down);
3176 i40e_stat_update_32(hw, I40E_GLPRT_CRCERRS(hw->port),
3177 pf->offset_loaded, &os->crc_errors,
3179 i40e_stat_update_32(hw, I40E_GLPRT_ILLERRC(hw->port),
3180 pf->offset_loaded, &os->illegal_bytes,
3181 &ns->illegal_bytes);
3182 /* GLPRT_ERRBC not supported */
3183 i40e_stat_update_32(hw, I40E_GLPRT_MLFC(hw->port),
3184 pf->offset_loaded, &os->mac_local_faults,
3185 &ns->mac_local_faults);
3186 i40e_stat_update_32(hw, I40E_GLPRT_MRFC(hw->port),
3187 pf->offset_loaded, &os->mac_remote_faults,
3188 &ns->mac_remote_faults);
3189 i40e_stat_update_32(hw, I40E_GLPRT_RLEC(hw->port),
3190 pf->offset_loaded, &os->rx_length_errors,
3191 &ns->rx_length_errors);
3192 i40e_stat_update_32(hw, I40E_GLPRT_LXONRXC(hw->port),
3193 pf->offset_loaded, &os->link_xon_rx,
3195 i40e_stat_update_32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
3196 pf->offset_loaded, &os->link_xoff_rx,
3198 for (i = 0; i < 8; i++) {
3199 i40e_stat_update_32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
3201 &os->priority_xon_rx[i],
3202 &ns->priority_xon_rx[i]);
3203 i40e_stat_update_32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
3205 &os->priority_xoff_rx[i],
3206 &ns->priority_xoff_rx[i]);
3208 i40e_stat_update_32(hw, I40E_GLPRT_LXONTXC(hw->port),
3209 pf->offset_loaded, &os->link_xon_tx,
3211 i40e_stat_update_32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
3212 pf->offset_loaded, &os->link_xoff_tx,
3214 for (i = 0; i < 8; i++) {
3215 i40e_stat_update_32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
3217 &os->priority_xon_tx[i],
3218 &ns->priority_xon_tx[i]);
3219 i40e_stat_update_32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
3221 &os->priority_xoff_tx[i],
3222 &ns->priority_xoff_tx[i]);
3223 i40e_stat_update_32(hw, I40E_GLPRT_RXON2OFFCNT(hw->port, i),
3225 &os->priority_xon_2_xoff[i],
3226 &ns->priority_xon_2_xoff[i]);
3228 i40e_stat_update_48(hw, I40E_GLPRT_PRC64H(hw->port),
3229 I40E_GLPRT_PRC64L(hw->port),
3230 pf->offset_loaded, &os->rx_size_64,
3232 i40e_stat_update_48(hw, I40E_GLPRT_PRC127H(hw->port),
3233 I40E_GLPRT_PRC127L(hw->port),
3234 pf->offset_loaded, &os->rx_size_127,
3236 i40e_stat_update_48(hw, I40E_GLPRT_PRC255H(hw->port),
3237 I40E_GLPRT_PRC255L(hw->port),
3238 pf->offset_loaded, &os->rx_size_255,
3240 i40e_stat_update_48(hw, I40E_GLPRT_PRC511H(hw->port),
3241 I40E_GLPRT_PRC511L(hw->port),
3242 pf->offset_loaded, &os->rx_size_511,
3244 i40e_stat_update_48(hw, I40E_GLPRT_PRC1023H(hw->port),
3245 I40E_GLPRT_PRC1023L(hw->port),
3246 pf->offset_loaded, &os->rx_size_1023,
3248 i40e_stat_update_48(hw, I40E_GLPRT_PRC1522H(hw->port),
3249 I40E_GLPRT_PRC1522L(hw->port),
3250 pf->offset_loaded, &os->rx_size_1522,
3252 i40e_stat_update_48(hw, I40E_GLPRT_PRC9522H(hw->port),
3253 I40E_GLPRT_PRC9522L(hw->port),
3254 pf->offset_loaded, &os->rx_size_big,
3256 i40e_stat_update_32(hw, I40E_GLPRT_RUC(hw->port),
3257 pf->offset_loaded, &os->rx_undersize,
3259 i40e_stat_update_32(hw, I40E_GLPRT_RFC(hw->port),
3260 pf->offset_loaded, &os->rx_fragments,
3262 i40e_stat_update_32(hw, I40E_GLPRT_ROC(hw->port),
3263 pf->offset_loaded, &os->rx_oversize,
3265 i40e_stat_update_32(hw, I40E_GLPRT_RJC(hw->port),
3266 pf->offset_loaded, &os->rx_jabber,
3268 i40e_stat_update_48(hw, I40E_GLPRT_PTC64H(hw->port),
3269 I40E_GLPRT_PTC64L(hw->port),
3270 pf->offset_loaded, &os->tx_size_64,
3272 i40e_stat_update_48(hw, I40E_GLPRT_PTC127H(hw->port),
3273 I40E_GLPRT_PTC127L(hw->port),
3274 pf->offset_loaded, &os->tx_size_127,
3276 i40e_stat_update_48(hw, I40E_GLPRT_PTC255H(hw->port),
3277 I40E_GLPRT_PTC255L(hw->port),
3278 pf->offset_loaded, &os->tx_size_255,
3280 i40e_stat_update_48(hw, I40E_GLPRT_PTC511H(hw->port),
3281 I40E_GLPRT_PTC511L(hw->port),
3282 pf->offset_loaded, &os->tx_size_511,
3284 i40e_stat_update_48(hw, I40E_GLPRT_PTC1023H(hw->port),
3285 I40E_GLPRT_PTC1023L(hw->port),
3286 pf->offset_loaded, &os->tx_size_1023,
3288 i40e_stat_update_48(hw, I40E_GLPRT_PTC1522H(hw->port),
3289 I40E_GLPRT_PTC1522L(hw->port),
3290 pf->offset_loaded, &os->tx_size_1522,
3292 i40e_stat_update_48(hw, I40E_GLPRT_PTC9522H(hw->port),
3293 I40E_GLPRT_PTC9522L(hw->port),
3294 pf->offset_loaded, &os->tx_size_big,
3296 i40e_stat_update_32(hw, I40E_GLQF_PCNT(pf->fdir.match_counter_index),
3298 &os->fd_sb_match, &ns->fd_sb_match);
3299 /* GLPRT_MSPDC not supported */
3300 /* GLPRT_XEC not supported */
3302 pf->offset_loaded = true;
3305 i40e_update_vsi_stats(pf->main_vsi);
3308 /* Get all statistics of a port */
3310 i40e_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
3312 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3313 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3314 struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
3315 struct i40e_vsi *vsi;
3318 /* call read registers - updates values, now write them to struct */
3319 i40e_read_stats_registers(pf, hw);
3321 stats->ipackets = pf->main_vsi->eth_stats.rx_unicast +
3322 pf->main_vsi->eth_stats.rx_multicast +
3323 pf->main_vsi->eth_stats.rx_broadcast -
3324 pf->main_vsi->eth_stats.rx_discards;
3325 stats->opackets = ns->eth.tx_unicast +
3326 ns->eth.tx_multicast +
3327 ns->eth.tx_broadcast;
3328 stats->ibytes = pf->main_vsi->eth_stats.rx_bytes;
3329 stats->obytes = ns->eth.tx_bytes;
3330 stats->oerrors = ns->eth.tx_errors +
3331 pf->main_vsi->eth_stats.tx_errors;
3334 stats->imissed = ns->eth.rx_discards +
3335 pf->main_vsi->eth_stats.rx_discards;
3336 stats->ierrors = ns->crc_errors +
3337 ns->rx_length_errors + ns->rx_undersize +
3338 ns->rx_oversize + ns->rx_fragments + ns->rx_jabber;
3341 for (i = 0; i < pf->vf_num; i++) {
3342 vsi = pf->vfs[i].vsi;
3343 i40e_update_vsi_stats(vsi);
3345 stats->ipackets += (vsi->eth_stats.rx_unicast +
3346 vsi->eth_stats.rx_multicast +
3347 vsi->eth_stats.rx_broadcast -
3348 vsi->eth_stats.rx_discards);
3349 stats->ibytes += vsi->eth_stats.rx_bytes;
3350 stats->oerrors += vsi->eth_stats.tx_errors;
3351 stats->imissed += vsi->eth_stats.rx_discards;
3355 PMD_DRV_LOG(DEBUG, "***************** PF stats start *******************");
3356 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", ns->eth.rx_bytes);
3357 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", ns->eth.rx_unicast);
3358 PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", ns->eth.rx_multicast);
3359 PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", ns->eth.rx_broadcast);
3360 PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", ns->eth.rx_discards);
3361 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
3362 ns->eth.rx_unknown_protocol);
3363 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", ns->eth.tx_bytes);
3364 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", ns->eth.tx_unicast);
3365 PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", ns->eth.tx_multicast);
3366 PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", ns->eth.tx_broadcast);
3367 PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", ns->eth.tx_discards);
3368 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", ns->eth.tx_errors);
3370 PMD_DRV_LOG(DEBUG, "tx_dropped_link_down: %"PRIu64"",
3371 ns->tx_dropped_link_down);
3372 PMD_DRV_LOG(DEBUG, "crc_errors: %"PRIu64"", ns->crc_errors);
3373 PMD_DRV_LOG(DEBUG, "illegal_bytes: %"PRIu64"",
3375 PMD_DRV_LOG(DEBUG, "error_bytes: %"PRIu64"", ns->error_bytes);
3376 PMD_DRV_LOG(DEBUG, "mac_local_faults: %"PRIu64"",
3377 ns->mac_local_faults);
3378 PMD_DRV_LOG(DEBUG, "mac_remote_faults: %"PRIu64"",
3379 ns->mac_remote_faults);
3380 PMD_DRV_LOG(DEBUG, "rx_length_errors: %"PRIu64"",
3381 ns->rx_length_errors);
3382 PMD_DRV_LOG(DEBUG, "link_xon_rx: %"PRIu64"", ns->link_xon_rx);
3383 PMD_DRV_LOG(DEBUG, "link_xoff_rx: %"PRIu64"", ns->link_xoff_rx);
3384 for (i = 0; i < 8; i++) {
3385 PMD_DRV_LOG(DEBUG, "priority_xon_rx[%d]: %"PRIu64"",
3386 i, ns->priority_xon_rx[i]);
3387 PMD_DRV_LOG(DEBUG, "priority_xoff_rx[%d]: %"PRIu64"",
3388 i, ns->priority_xoff_rx[i]);
3390 PMD_DRV_LOG(DEBUG, "link_xon_tx: %"PRIu64"", ns->link_xon_tx);
3391 PMD_DRV_LOG(DEBUG, "link_xoff_tx: %"PRIu64"", ns->link_xoff_tx);
3392 for (i = 0; i < 8; i++) {
3393 PMD_DRV_LOG(DEBUG, "priority_xon_tx[%d]: %"PRIu64"",
3394 i, ns->priority_xon_tx[i]);
3395 PMD_DRV_LOG(DEBUG, "priority_xoff_tx[%d]: %"PRIu64"",
3396 i, ns->priority_xoff_tx[i]);
3397 PMD_DRV_LOG(DEBUG, "priority_xon_2_xoff[%d]: %"PRIu64"",
3398 i, ns->priority_xon_2_xoff[i]);
3400 PMD_DRV_LOG(DEBUG, "rx_size_64: %"PRIu64"", ns->rx_size_64);
3401 PMD_DRV_LOG(DEBUG, "rx_size_127: %"PRIu64"", ns->rx_size_127);
3402 PMD_DRV_LOG(DEBUG, "rx_size_255: %"PRIu64"", ns->rx_size_255);
3403 PMD_DRV_LOG(DEBUG, "rx_size_511: %"PRIu64"", ns->rx_size_511);
3404 PMD_DRV_LOG(DEBUG, "rx_size_1023: %"PRIu64"", ns->rx_size_1023);
3405 PMD_DRV_LOG(DEBUG, "rx_size_1522: %"PRIu64"", ns->rx_size_1522);
3406 PMD_DRV_LOG(DEBUG, "rx_size_big: %"PRIu64"", ns->rx_size_big);
3407 PMD_DRV_LOG(DEBUG, "rx_undersize: %"PRIu64"", ns->rx_undersize);
3408 PMD_DRV_LOG(DEBUG, "rx_fragments: %"PRIu64"", ns->rx_fragments);
3409 PMD_DRV_LOG(DEBUG, "rx_oversize: %"PRIu64"", ns->rx_oversize);
3410 PMD_DRV_LOG(DEBUG, "rx_jabber: %"PRIu64"", ns->rx_jabber);
3411 PMD_DRV_LOG(DEBUG, "tx_size_64: %"PRIu64"", ns->tx_size_64);
3412 PMD_DRV_LOG(DEBUG, "tx_size_127: %"PRIu64"", ns->tx_size_127);
3413 PMD_DRV_LOG(DEBUG, "tx_size_255: %"PRIu64"", ns->tx_size_255);
3414 PMD_DRV_LOG(DEBUG, "tx_size_511: %"PRIu64"", ns->tx_size_511);
3415 PMD_DRV_LOG(DEBUG, "tx_size_1023: %"PRIu64"", ns->tx_size_1023);
3416 PMD_DRV_LOG(DEBUG, "tx_size_1522: %"PRIu64"", ns->tx_size_1522);
3417 PMD_DRV_LOG(DEBUG, "tx_size_big: %"PRIu64"", ns->tx_size_big);
3418 PMD_DRV_LOG(DEBUG, "mac_short_packet_dropped: %"PRIu64"",
3419 ns->mac_short_packet_dropped);
3420 PMD_DRV_LOG(DEBUG, "checksum_error: %"PRIu64"",
3421 ns->checksum_error);
3422 PMD_DRV_LOG(DEBUG, "fdir_match: %"PRIu64"", ns->fd_sb_match);
3423 PMD_DRV_LOG(DEBUG, "***************** PF stats end ********************");
3427 /* Reset the statistics */
3429 i40e_dev_stats_reset(struct rte_eth_dev *dev)
3431 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3432 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3434 /* Mark PF and VSI stats to update the offset, aka "reset" */
3435 pf->offset_loaded = false;
3437 pf->main_vsi->offset_loaded = false;
3439 /* read the stats, reading current register values into offset */
3440 i40e_read_stats_registers(pf, hw);
3446 i40e_xstats_calc_num(void)
3448 return I40E_NB_ETH_XSTATS + I40E_NB_HW_PORT_XSTATS +
3449 (I40E_NB_RXQ_PRIO_XSTATS * 8) +
3450 (I40E_NB_TXQ_PRIO_XSTATS * 8);
3453 static int i40e_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
3454 struct rte_eth_xstat_name *xstats_names,
3455 __rte_unused unsigned limit)
3460 if (xstats_names == NULL)
3461 return i40e_xstats_calc_num();
3463 /* Note: limit checked in rte_eth_xstats_names() */
3465 /* Get stats from i40e_eth_stats struct */
3466 for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
3467 strlcpy(xstats_names[count].name,
3468 rte_i40e_stats_strings[i].name,
3469 sizeof(xstats_names[count].name));
3473 /* Get individiual stats from i40e_hw_port struct */
3474 for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
3475 strlcpy(xstats_names[count].name,
3476 rte_i40e_hw_port_strings[i].name,
3477 sizeof(xstats_names[count].name));
3481 for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
3482 for (prio = 0; prio < 8; prio++) {
3483 snprintf(xstats_names[count].name,
3484 sizeof(xstats_names[count].name),
3485 "rx_priority%u_%s", prio,
3486 rte_i40e_rxq_prio_strings[i].name);
3491 for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
3492 for (prio = 0; prio < 8; prio++) {
3493 snprintf(xstats_names[count].name,
3494 sizeof(xstats_names[count].name),
3495 "tx_priority%u_%s", prio,
3496 rte_i40e_txq_prio_strings[i].name);
3504 i40e_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
3507 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3508 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3509 unsigned i, count, prio;
3510 struct i40e_hw_port_stats *hw_stats = &pf->stats;
3512 count = i40e_xstats_calc_num();
3516 i40e_read_stats_registers(pf, hw);
3523 /* Get stats from i40e_eth_stats struct */
3524 for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
3525 xstats[count].value = *(uint64_t *)(((char *)&hw_stats->eth) +
3526 rte_i40e_stats_strings[i].offset);
3527 xstats[count].id = count;
3531 /* Get individiual stats from i40e_hw_port struct */
3532 for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
3533 xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
3534 rte_i40e_hw_port_strings[i].offset);
3535 xstats[count].id = count;
3539 for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
3540 for (prio = 0; prio < 8; prio++) {
3541 xstats[count].value =
3542 *(uint64_t *)(((char *)hw_stats) +
3543 rte_i40e_rxq_prio_strings[i].offset +
3544 (sizeof(uint64_t) * prio));
3545 xstats[count].id = count;
3550 for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
3551 for (prio = 0; prio < 8; prio++) {
3552 xstats[count].value =
3553 *(uint64_t *)(((char *)hw_stats) +
3554 rte_i40e_txq_prio_strings[i].offset +
3555 (sizeof(uint64_t) * prio));
3556 xstats[count].id = count;
3565 i40e_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
3567 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3573 full_ver = hw->nvm.oem_ver;
3574 ver = (u8)(full_ver >> 24);
3575 build = (u16)((full_ver >> 8) & 0xffff);
3576 patch = (u8)(full_ver & 0xff);
3578 ret = snprintf(fw_version, fw_size,
3579 "%d.%d%d 0x%08x %d.%d.%d",
3580 ((hw->nvm.version >> 12) & 0xf),
3581 ((hw->nvm.version >> 4) & 0xff),
3582 (hw->nvm.version & 0xf), hw->nvm.eetrack,
3585 ret += 1; /* add the size of '\0' */
3586 if (fw_size < (u32)ret)
3593 * When using NVM 6.01(for X710 XL710 XXV710)/3.33(for X722) or later,
3594 * the Rx data path does not hang if the FW LLDP is stopped.
3595 * return true if lldp need to stop
3596 * return false if we cannot disable the LLDP to avoid Rx data path blocking.
3599 i40e_need_stop_lldp(struct rte_eth_dev *dev)
3602 char ver_str[64] = {0};
3603 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3605 i40e_fw_version_get(dev, ver_str, 64);
3606 nvm_ver = atof(ver_str);
3607 if ((hw->mac.type == I40E_MAC_X722 ||
3608 hw->mac.type == I40E_MAC_X722_VF) &&
3609 ((uint32_t)(nvm_ver * 1000) >= (uint32_t)(3.33 * 1000)))
3611 else if ((uint32_t)(nvm_ver * 1000) >= (uint32_t)(6.01 * 1000))
3618 i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
3620 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3621 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3622 struct i40e_vsi *vsi = pf->main_vsi;
3623 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3625 dev_info->max_rx_queues = vsi->nb_qps;
3626 dev_info->max_tx_queues = vsi->nb_qps;
3627 dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
3628 dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
3629 dev_info->max_mac_addrs = vsi->max_macaddrs;
3630 dev_info->max_vfs = pci_dev->max_vfs;
3631 dev_info->max_mtu = dev_info->max_rx_pktlen - I40E_ETH_OVERHEAD;
3632 dev_info->min_mtu = RTE_ETHER_MIN_MTU;
3633 dev_info->rx_queue_offload_capa = 0;
3634 dev_info->rx_offload_capa =
3635 DEV_RX_OFFLOAD_VLAN_STRIP |
3636 DEV_RX_OFFLOAD_QINQ_STRIP |
3637 DEV_RX_OFFLOAD_IPV4_CKSUM |
3638 DEV_RX_OFFLOAD_UDP_CKSUM |
3639 DEV_RX_OFFLOAD_TCP_CKSUM |
3640 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
3641 DEV_RX_OFFLOAD_KEEP_CRC |
3642 DEV_RX_OFFLOAD_SCATTER |
3643 DEV_RX_OFFLOAD_VLAN_EXTEND |
3644 DEV_RX_OFFLOAD_VLAN_FILTER |
3645 DEV_RX_OFFLOAD_JUMBO_FRAME |
3646 DEV_RX_OFFLOAD_RSS_HASH;
3648 dev_info->tx_queue_offload_capa = DEV_TX_OFFLOAD_MBUF_FAST_FREE;
3649 dev_info->tx_offload_capa =
3650 DEV_TX_OFFLOAD_VLAN_INSERT |
3651 DEV_TX_OFFLOAD_QINQ_INSERT |
3652 DEV_TX_OFFLOAD_IPV4_CKSUM |
3653 DEV_TX_OFFLOAD_UDP_CKSUM |
3654 DEV_TX_OFFLOAD_TCP_CKSUM |
3655 DEV_TX_OFFLOAD_SCTP_CKSUM |
3656 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
3657 DEV_TX_OFFLOAD_TCP_TSO |
3658 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
3659 DEV_TX_OFFLOAD_GRE_TNL_TSO |
3660 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
3661 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
3662 DEV_TX_OFFLOAD_MULTI_SEGS |
3663 dev_info->tx_queue_offload_capa;
3664 dev_info->dev_capa =
3665 RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
3666 RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
3668 dev_info->hash_key_size = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
3670 dev_info->reta_size = pf->hash_lut_size;
3671 dev_info->flow_type_rss_offloads = pf->adapter->flow_types_mask;
3673 dev_info->default_rxconf = (struct rte_eth_rxconf) {
3675 .pthresh = I40E_DEFAULT_RX_PTHRESH,
3676 .hthresh = I40E_DEFAULT_RX_HTHRESH,
3677 .wthresh = I40E_DEFAULT_RX_WTHRESH,
3679 .rx_free_thresh = I40E_DEFAULT_RX_FREE_THRESH,
3684 dev_info->default_txconf = (struct rte_eth_txconf) {
3686 .pthresh = I40E_DEFAULT_TX_PTHRESH,
3687 .hthresh = I40E_DEFAULT_TX_HTHRESH,
3688 .wthresh = I40E_DEFAULT_TX_WTHRESH,
3690 .tx_free_thresh = I40E_DEFAULT_TX_FREE_THRESH,
3691 .tx_rs_thresh = I40E_DEFAULT_TX_RSBIT_THRESH,
3695 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
3696 .nb_max = I40E_MAX_RING_DESC,
3697 .nb_min = I40E_MIN_RING_DESC,
3698 .nb_align = I40E_ALIGN_RING_DESC,
3701 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
3702 .nb_max = I40E_MAX_RING_DESC,
3703 .nb_min = I40E_MIN_RING_DESC,
3704 .nb_align = I40E_ALIGN_RING_DESC,
3705 .nb_seg_max = I40E_TX_MAX_SEG,
3706 .nb_mtu_seg_max = I40E_TX_MAX_MTU_SEG,
3709 if (pf->flags & I40E_FLAG_VMDQ) {
3710 dev_info->max_vmdq_pools = pf->max_nb_vmdq_vsi;
3711 dev_info->vmdq_queue_base = dev_info->max_rx_queues;
3712 dev_info->vmdq_queue_num = pf->vmdq_nb_qps *
3713 pf->max_nb_vmdq_vsi;
3714 dev_info->vmdq_pool_base = I40E_VMDQ_POOL_BASE;
3715 dev_info->max_rx_queues += dev_info->vmdq_queue_num;
3716 dev_info->max_tx_queues += dev_info->vmdq_queue_num;
3719 if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
3721 dev_info->speed_capa = ETH_LINK_SPEED_40G;
3722 dev_info->default_rxportconf.nb_queues = 2;
3723 dev_info->default_txportconf.nb_queues = 2;
3724 if (dev->data->nb_rx_queues == 1)
3725 dev_info->default_rxportconf.ring_size = 2048;
3727 dev_info->default_rxportconf.ring_size = 1024;
3728 if (dev->data->nb_tx_queues == 1)
3729 dev_info->default_txportconf.ring_size = 1024;
3731 dev_info->default_txportconf.ring_size = 512;
3733 } else if (I40E_PHY_TYPE_SUPPORT_25G(hw->phy.phy_types)) {
3735 dev_info->speed_capa = ETH_LINK_SPEED_25G;
3736 dev_info->default_rxportconf.nb_queues = 1;
3737 dev_info->default_txportconf.nb_queues = 1;
3738 dev_info->default_rxportconf.ring_size = 256;
3739 dev_info->default_txportconf.ring_size = 256;
3742 dev_info->speed_capa = ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G;
3743 dev_info->default_rxportconf.nb_queues = 1;
3744 dev_info->default_txportconf.nb_queues = 1;
3745 if (dev->data->dev_conf.link_speeds & ETH_LINK_SPEED_10G) {
3746 dev_info->default_rxportconf.ring_size = 512;
3747 dev_info->default_txportconf.ring_size = 256;
3749 dev_info->default_rxportconf.ring_size = 256;
3750 dev_info->default_txportconf.ring_size = 256;
3753 dev_info->default_rxportconf.burst_size = 32;
3754 dev_info->default_txportconf.burst_size = 32;
3760 i40e_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
3762 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3763 struct i40e_vsi *vsi = pf->main_vsi;
3764 PMD_INIT_FUNC_TRACE();
3767 return i40e_vsi_add_vlan(vsi, vlan_id);
3769 return i40e_vsi_delete_vlan(vsi, vlan_id);
3773 i40e_vlan_tpid_set_by_registers(struct rte_eth_dev *dev,
3774 enum rte_vlan_type vlan_type,
3775 uint16_t tpid, int qinq)
3777 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3780 uint16_t reg_id = 3;
3784 if (vlan_type == ETH_VLAN_TYPE_OUTER)
3788 ret = i40e_aq_debug_read_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
3790 if (ret != I40E_SUCCESS) {
3792 "Fail to debug read from I40E_GL_SWT_L2TAGCTRL[%d]",
3797 "Debug read from I40E_GL_SWT_L2TAGCTRL[%d]: 0x%08"PRIx64,
3800 reg_w = reg_r & (~(I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_MASK));
3801 reg_w |= ((uint64_t)tpid << I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT);
3802 if (reg_r == reg_w) {
3803 PMD_DRV_LOG(DEBUG, "No need to write");
3807 ret = i40e_aq_debug_write_global_register(hw,
3808 I40E_GL_SWT_L2TAGCTRL(reg_id),
3810 if (ret != I40E_SUCCESS) {
3812 "Fail to debug write to I40E_GL_SWT_L2TAGCTRL[%d]",
3817 "Global register 0x%08x is changed with value 0x%08x",
3818 I40E_GL_SWT_L2TAGCTRL(reg_id), (uint32_t)reg_w);
3824 i40e_vlan_tpid_set(struct rte_eth_dev *dev,
3825 enum rte_vlan_type vlan_type,
3828 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3829 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3830 int qinq = dev->data->dev_conf.rxmode.offloads &
3831 DEV_RX_OFFLOAD_VLAN_EXTEND;
3834 if ((vlan_type != ETH_VLAN_TYPE_INNER &&
3835 vlan_type != ETH_VLAN_TYPE_OUTER) ||
3836 (!qinq && vlan_type == ETH_VLAN_TYPE_INNER)) {
3838 "Unsupported vlan type.");
3842 if (pf->support_multi_driver) {
3843 PMD_DRV_LOG(ERR, "Setting TPID is not supported.");
3847 /* 802.1ad frames ability is added in NVM API 1.7*/
3848 if (hw->flags & I40E_HW_FLAG_802_1AD_CAPABLE) {
3850 if (vlan_type == ETH_VLAN_TYPE_OUTER)
3851 hw->first_tag = rte_cpu_to_le_16(tpid);
3852 else if (vlan_type == ETH_VLAN_TYPE_INNER)
3853 hw->second_tag = rte_cpu_to_le_16(tpid);
3855 if (vlan_type == ETH_VLAN_TYPE_OUTER)
3856 hw->second_tag = rte_cpu_to_le_16(tpid);
3858 ret = i40e_aq_set_switch_config(hw, 0, 0, 0, NULL);
3859 if (ret != I40E_SUCCESS) {
3861 "Set switch config failed aq_err: %d",
3862 hw->aq.asq_last_status);
3866 /* If NVM API < 1.7, keep the register setting */
3867 ret = i40e_vlan_tpid_set_by_registers(dev, vlan_type,
3874 i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask)
3876 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3877 struct i40e_vsi *vsi = pf->main_vsi;
3878 struct rte_eth_rxmode *rxmode;
3880 if (mask & ETH_QINQ_STRIP_MASK) {
3881 PMD_DRV_LOG(ERR, "Strip qinq is not supported.");
3885 rxmode = &dev->data->dev_conf.rxmode;
3886 if (mask & ETH_VLAN_FILTER_MASK) {
3887 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
3888 i40e_vsi_config_vlan_filter(vsi, TRUE);
3890 i40e_vsi_config_vlan_filter(vsi, FALSE);
3893 if (mask & ETH_VLAN_STRIP_MASK) {
3894 /* Enable or disable VLAN stripping */
3895 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
3896 i40e_vsi_config_vlan_stripping(vsi, TRUE);
3898 i40e_vsi_config_vlan_stripping(vsi, FALSE);
3901 if (mask & ETH_VLAN_EXTEND_MASK) {
3902 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_EXTEND) {
3903 i40e_vsi_config_double_vlan(vsi, TRUE);
3904 /* Set global registers with default ethertype. */
3905 i40e_vlan_tpid_set(dev, ETH_VLAN_TYPE_OUTER,
3906 RTE_ETHER_TYPE_VLAN);
3907 i40e_vlan_tpid_set(dev, ETH_VLAN_TYPE_INNER,
3908 RTE_ETHER_TYPE_VLAN);
3911 i40e_vsi_config_double_vlan(vsi, FALSE);
3918 i40e_vlan_strip_queue_set(__rte_unused struct rte_eth_dev *dev,
3919 __rte_unused uint16_t queue,
3920 __rte_unused int on)
3922 PMD_INIT_FUNC_TRACE();
3926 i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
3928 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3929 struct i40e_vsi *vsi = pf->main_vsi;
3930 struct rte_eth_dev_data *data = I40E_VSI_TO_DEV_DATA(vsi);
3931 struct i40e_vsi_vlan_pvid_info info;
3933 memset(&info, 0, sizeof(info));
3936 info.config.pvid = pvid;
3938 info.config.reject.tagged =
3939 data->dev_conf.txmode.hw_vlan_reject_tagged;
3940 info.config.reject.untagged =
3941 data->dev_conf.txmode.hw_vlan_reject_untagged;
3944 return i40e_vsi_vlan_pvid_set(vsi, &info);
3948 i40e_dev_led_on(struct rte_eth_dev *dev)
3950 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3951 uint32_t mode = i40e_led_get(hw);
3954 i40e_led_set(hw, 0xf, true); /* 0xf means led always true */
3960 i40e_dev_led_off(struct rte_eth_dev *dev)
3962 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3963 uint32_t mode = i40e_led_get(hw);
3966 i40e_led_set(hw, 0, false);
3972 i40e_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
3974 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3975 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3977 fc_conf->pause_time = pf->fc_conf.pause_time;
3979 /* read out from register, in case they are modified by other port */
3980 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] =
3981 I40E_READ_REG(hw, I40E_GLRPB_GHW) >> I40E_KILOSHIFT;
3982 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] =
3983 I40E_READ_REG(hw, I40E_GLRPB_GLW) >> I40E_KILOSHIFT;
3985 fc_conf->high_water = pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS];
3986 fc_conf->low_water = pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS];
3988 /* Return current mode according to actual setting*/
3989 switch (hw->fc.current_mode) {
3991 fc_conf->mode = RTE_FC_FULL;
3993 case I40E_FC_TX_PAUSE:
3994 fc_conf->mode = RTE_FC_TX_PAUSE;
3996 case I40E_FC_RX_PAUSE:
3997 fc_conf->mode = RTE_FC_RX_PAUSE;
4001 fc_conf->mode = RTE_FC_NONE;
4008 i40e_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
4010 uint32_t mflcn_reg, fctrl_reg, reg;
4011 uint32_t max_high_water;
4012 uint8_t i, aq_failure;
4016 enum i40e_fc_mode rte_fcmode_2_i40e_fcmode[] = {
4017 [RTE_FC_NONE] = I40E_FC_NONE,
4018 [RTE_FC_RX_PAUSE] = I40E_FC_RX_PAUSE,
4019 [RTE_FC_TX_PAUSE] = I40E_FC_TX_PAUSE,
4020 [RTE_FC_FULL] = I40E_FC_FULL
4023 /* high_water field in the rte_eth_fc_conf using the kilobytes unit */
4025 max_high_water = I40E_RXPBSIZE >> I40E_KILOSHIFT;
4026 if ((fc_conf->high_water > max_high_water) ||
4027 (fc_conf->high_water < fc_conf->low_water)) {
4029 "Invalid high/low water setup value in KB, High_water must be <= %d.",
4034 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4035 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4036 hw->fc.requested_mode = rte_fcmode_2_i40e_fcmode[fc_conf->mode];
4038 pf->fc_conf.pause_time = fc_conf->pause_time;
4039 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->high_water;
4040 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->low_water;
4042 PMD_INIT_FUNC_TRACE();
4044 /* All the link flow control related enable/disable register
4045 * configuration is handle by the F/W
4047 err = i40e_set_fc(hw, &aq_failure, true);
4051 if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
4052 /* Configure flow control refresh threshold,
4053 * the value for stat_tx_pause_refresh_timer[8]
4054 * is used for global pause operation.
4058 I40E_PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER(8),
4059 pf->fc_conf.pause_time);
4061 /* configure the timer value included in transmitted pause
4063 * the value for stat_tx_pause_quanta[8] is used for global
4066 I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA(8),
4067 pf->fc_conf.pause_time);
4069 fctrl_reg = I40E_READ_REG(hw,
4070 I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL);
4072 if (fc_conf->mac_ctrl_frame_fwd != 0)
4073 fctrl_reg |= I40E_PRTMAC_FWD_CTRL;
4075 fctrl_reg &= ~I40E_PRTMAC_FWD_CTRL;
4077 I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL,
4080 /* Configure pause time (2 TCs per register) */
4081 reg = (uint32_t)pf->fc_conf.pause_time * (uint32_t)0x00010001;
4082 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS / 2; i++)
4083 I40E_WRITE_REG(hw, I40E_PRTDCB_FCTTVN(i), reg);
4085 /* Configure flow control refresh threshold value */
4086 I40E_WRITE_REG(hw, I40E_PRTDCB_FCRTV,
4087 pf->fc_conf.pause_time / 2);
4089 mflcn_reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
4091 /* set or clear MFLCN.PMCF & MFLCN.DPF bits
4092 *depending on configuration
4094 if (fc_conf->mac_ctrl_frame_fwd != 0) {
4095 mflcn_reg |= I40E_PRTDCB_MFLCN_PMCF_MASK;
4096 mflcn_reg &= ~I40E_PRTDCB_MFLCN_DPF_MASK;
4098 mflcn_reg &= ~I40E_PRTDCB_MFLCN_PMCF_MASK;
4099 mflcn_reg |= I40E_PRTDCB_MFLCN_DPF_MASK;
4102 I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, mflcn_reg);
4105 if (!pf->support_multi_driver) {
4106 /* config water marker both based on the packets and bytes */
4107 I40E_WRITE_GLB_REG(hw, I40E_GLRPB_PHW,
4108 (pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
4109 << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
4110 I40E_WRITE_GLB_REG(hw, I40E_GLRPB_PLW,
4111 (pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
4112 << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
4113 I40E_WRITE_GLB_REG(hw, I40E_GLRPB_GHW,
4114 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
4116 I40E_WRITE_GLB_REG(hw, I40E_GLRPB_GLW,
4117 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
4121 "Water marker configuration is not supported.");
4124 I40E_WRITE_FLUSH(hw);
4130 i40e_priority_flow_ctrl_set(__rte_unused struct rte_eth_dev *dev,
4131 __rte_unused struct rte_eth_pfc_conf *pfc_conf)
4133 PMD_INIT_FUNC_TRACE();
4138 /* Add a MAC address, and update filters */
4140 i40e_macaddr_add(struct rte_eth_dev *dev,
4141 struct rte_ether_addr *mac_addr,
4142 __rte_unused uint32_t index,
4145 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4146 struct i40e_mac_filter_info mac_filter;
4147 struct i40e_vsi *vsi;
4148 struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
4151 /* If VMDQ not enabled or configured, return */
4152 if (pool != 0 && (!(pf->flags & I40E_FLAG_VMDQ) ||
4153 !pf->nb_cfg_vmdq_vsi)) {
4154 PMD_DRV_LOG(ERR, "VMDQ not %s, can't set mac to pool %u",
4155 pf->flags & I40E_FLAG_VMDQ ? "configured" : "enabled",
4160 if (pool > pf->nb_cfg_vmdq_vsi) {
4161 PMD_DRV_LOG(ERR, "Pool number %u invalid. Max pool is %u",
4162 pool, pf->nb_cfg_vmdq_vsi);
4166 rte_memcpy(&mac_filter.mac_addr, mac_addr, RTE_ETHER_ADDR_LEN);
4167 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
4168 mac_filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
4170 mac_filter.filter_type = RTE_MAC_PERFECT_MATCH;
4175 vsi = pf->vmdq[pool - 1].vsi;
4177 ret = i40e_vsi_add_mac(vsi, &mac_filter);
4178 if (ret != I40E_SUCCESS) {
4179 PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
4185 /* Remove a MAC address, and update filters */
4187 i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
4189 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4190 struct i40e_vsi *vsi;
4191 struct rte_eth_dev_data *data = dev->data;
4192 struct rte_ether_addr *macaddr;
4197 macaddr = &(data->mac_addrs[index]);
4199 pool_sel = dev->data->mac_pool_sel[index];
4201 for (i = 0; i < sizeof(pool_sel) * CHAR_BIT; i++) {
4202 if (pool_sel & (1ULL << i)) {
4206 /* No VMDQ pool enabled or configured */
4207 if (!(pf->flags & I40E_FLAG_VMDQ) ||
4208 (i > pf->nb_cfg_vmdq_vsi)) {
4210 "No VMDQ pool enabled/configured");
4213 vsi = pf->vmdq[i - 1].vsi;
4215 ret = i40e_vsi_delete_mac(vsi, macaddr);
4218 PMD_DRV_LOG(ERR, "Failed to remove MACVLAN filter");
4225 /* Set perfect match or hash match of MAC and VLAN for a VF */
4227 i40e_vf_mac_filter_set(struct i40e_pf *pf,
4228 struct rte_eth_mac_filter *filter,
4232 struct i40e_mac_filter_info mac_filter;
4233 struct rte_ether_addr old_mac;
4234 struct rte_ether_addr *new_mac;
4235 struct i40e_pf_vf *vf = NULL;
4240 PMD_DRV_LOG(ERR, "Invalid PF argument.");
4243 hw = I40E_PF_TO_HW(pf);
4245 if (filter == NULL) {
4246 PMD_DRV_LOG(ERR, "Invalid mac filter argument.");
4250 new_mac = &filter->mac_addr;
4252 if (rte_is_zero_ether_addr(new_mac)) {
4253 PMD_DRV_LOG(ERR, "Invalid ethernet address.");
4257 vf_id = filter->dst_id;
4259 if (vf_id > pf->vf_num - 1 || !pf->vfs) {
4260 PMD_DRV_LOG(ERR, "Invalid argument.");
4263 vf = &pf->vfs[vf_id];
4265 if (add && rte_is_same_ether_addr(new_mac, &pf->dev_addr)) {
4266 PMD_DRV_LOG(INFO, "Ignore adding permanent MAC address.");
4271 rte_memcpy(&old_mac, hw->mac.addr, RTE_ETHER_ADDR_LEN);
4272 rte_memcpy(hw->mac.addr, new_mac->addr_bytes,
4273 RTE_ETHER_ADDR_LEN);
4274 rte_memcpy(&mac_filter.mac_addr, &filter->mac_addr,
4275 RTE_ETHER_ADDR_LEN);
4277 mac_filter.filter_type = filter->filter_type;
4278 ret = i40e_vsi_add_mac(vf->vsi, &mac_filter);
4279 if (ret != I40E_SUCCESS) {
4280 PMD_DRV_LOG(ERR, "Failed to add MAC filter.");
4283 rte_ether_addr_copy(new_mac, &pf->dev_addr);
4285 rte_memcpy(hw->mac.addr, hw->mac.perm_addr,
4286 RTE_ETHER_ADDR_LEN);
4287 ret = i40e_vsi_delete_mac(vf->vsi, &filter->mac_addr);
4288 if (ret != I40E_SUCCESS) {
4289 PMD_DRV_LOG(ERR, "Failed to delete MAC filter.");
4293 /* Clear device address as it has been removed */
4294 if (rte_is_same_ether_addr(&pf->dev_addr, new_mac))
4295 memset(&pf->dev_addr, 0, sizeof(struct rte_ether_addr));
4301 /* MAC filter handle */
4303 i40e_mac_filter_handle(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
4306 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4307 struct rte_eth_mac_filter *filter;
4308 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4309 int ret = I40E_NOT_SUPPORTED;
4311 filter = (struct rte_eth_mac_filter *)(arg);
4313 switch (filter_op) {
4314 case RTE_ETH_FILTER_NOP:
4317 case RTE_ETH_FILTER_ADD:
4318 i40e_pf_disable_irq0(hw);
4320 ret = i40e_vf_mac_filter_set(pf, filter, 1);
4321 i40e_pf_enable_irq0(hw);
4323 case RTE_ETH_FILTER_DELETE:
4324 i40e_pf_disable_irq0(hw);
4326 ret = i40e_vf_mac_filter_set(pf, filter, 0);
4327 i40e_pf_enable_irq0(hw);
4330 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
4331 ret = I40E_ERR_PARAM;
4339 i40e_get_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4341 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
4342 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4349 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
4350 ret = i40e_aq_get_rss_lut(hw, vsi->vsi_id,
4351 vsi->type != I40E_VSI_SRIOV,
4354 PMD_DRV_LOG(ERR, "Failed to get RSS lookup table");
4358 uint32_t *lut_dw = (uint32_t *)lut;
4359 uint16_t i, lut_size_dw = lut_size / 4;
4361 if (vsi->type == I40E_VSI_SRIOV) {
4362 for (i = 0; i <= lut_size_dw; i++) {
4363 reg = I40E_VFQF_HLUT1(i, vsi->user_param);
4364 lut_dw[i] = i40e_read_rx_ctl(hw, reg);
4367 for (i = 0; i < lut_size_dw; i++)
4368 lut_dw[i] = I40E_READ_REG(hw,
4377 i40e_set_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4386 pf = I40E_VSI_TO_PF(vsi);
4387 hw = I40E_VSI_TO_HW(vsi);
4389 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
4390 ret = i40e_aq_set_rss_lut(hw, vsi->vsi_id,
4391 vsi->type != I40E_VSI_SRIOV,
4394 PMD_DRV_LOG(ERR, "Failed to set RSS lookup table");
4398 uint32_t *lut_dw = (uint32_t *)lut;
4399 uint16_t i, lut_size_dw = lut_size / 4;
4401 if (vsi->type == I40E_VSI_SRIOV) {
4402 for (i = 0; i < lut_size_dw; i++)
4405 I40E_VFQF_HLUT1(i, vsi->user_param),
4408 for (i = 0; i < lut_size_dw; i++)
4409 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i),
4412 I40E_WRITE_FLUSH(hw);
4419 i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
4420 struct rte_eth_rss_reta_entry64 *reta_conf,
4423 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4424 uint16_t i, lut_size = pf->hash_lut_size;
4425 uint16_t idx, shift;
4429 if (reta_size != lut_size ||
4430 reta_size > ETH_RSS_RETA_SIZE_512) {
4432 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)",
4433 reta_size, lut_size);
4437 lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
4439 PMD_DRV_LOG(ERR, "No memory can be allocated");
4442 ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
4445 for (i = 0; i < reta_size; i++) {
4446 idx = i / RTE_RETA_GROUP_SIZE;
4447 shift = i % RTE_RETA_GROUP_SIZE;
4448 if (reta_conf[idx].mask & (1ULL << shift))
4449 lut[i] = reta_conf[idx].reta[shift];
4451 ret = i40e_set_rss_lut(pf->main_vsi, lut, reta_size);
4453 pf->adapter->rss_reta_updated = 1;
4462 i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
4463 struct rte_eth_rss_reta_entry64 *reta_conf,
4466 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4467 uint16_t i, lut_size = pf->hash_lut_size;
4468 uint16_t idx, shift;
4472 if (reta_size != lut_size ||
4473 reta_size > ETH_RSS_RETA_SIZE_512) {
4475 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)",
4476 reta_size, lut_size);
4480 lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
4482 PMD_DRV_LOG(ERR, "No memory can be allocated");
4486 ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
4489 for (i = 0; i < reta_size; i++) {
4490 idx = i / RTE_RETA_GROUP_SIZE;
4491 shift = i % RTE_RETA_GROUP_SIZE;
4492 if (reta_conf[idx].mask & (1ULL << shift))
4493 reta_conf[idx].reta[shift] = lut[i];
4503 * i40e_allocate_dma_mem_d - specific memory alloc for shared code (base driver)
4504 * @hw: pointer to the HW structure
4505 * @mem: pointer to mem struct to fill out
4506 * @size: size of memory requested
4507 * @alignment: what to align the allocation to
4509 enum i40e_status_code
4510 i40e_allocate_dma_mem_d(__rte_unused struct i40e_hw *hw,
4511 struct i40e_dma_mem *mem,
4515 const struct rte_memzone *mz = NULL;
4516 char z_name[RTE_MEMZONE_NAMESIZE];
4519 return I40E_ERR_PARAM;
4521 snprintf(z_name, sizeof(z_name), "i40e_dma_%"PRIu64, rte_rand());
4522 mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY,
4523 RTE_MEMZONE_IOVA_CONTIG, alignment, RTE_PGSIZE_2M);
4525 return I40E_ERR_NO_MEMORY;
4530 mem->zone = (const void *)mz;
4532 "memzone %s allocated with physical address: %"PRIu64,
4535 return I40E_SUCCESS;
4539 * i40e_free_dma_mem_d - specific memory free for shared code (base driver)
4540 * @hw: pointer to the HW structure
4541 * @mem: ptr to mem struct to free
4543 enum i40e_status_code
4544 i40e_free_dma_mem_d(__rte_unused struct i40e_hw *hw,
4545 struct i40e_dma_mem *mem)
4548 return I40E_ERR_PARAM;
4551 "memzone %s to be freed with physical address: %"PRIu64,
4552 ((const struct rte_memzone *)mem->zone)->name, mem->pa);
4553 rte_memzone_free((const struct rte_memzone *)mem->zone);
4558 return I40E_SUCCESS;
4562 * i40e_allocate_virt_mem_d - specific memory alloc for shared code (base driver)
4563 * @hw: pointer to the HW structure
4564 * @mem: pointer to mem struct to fill out
4565 * @size: size of memory requested
4567 enum i40e_status_code
4568 i40e_allocate_virt_mem_d(__rte_unused struct i40e_hw *hw,
4569 struct i40e_virt_mem *mem,
4573 return I40E_ERR_PARAM;
4576 mem->va = rte_zmalloc("i40e", size, 0);
4579 return I40E_SUCCESS;
4581 return I40E_ERR_NO_MEMORY;
4585 * i40e_free_virt_mem_d - specific memory free for shared code (base driver)
4586 * @hw: pointer to the HW structure
4587 * @mem: pointer to mem struct to free
4589 enum i40e_status_code
4590 i40e_free_virt_mem_d(__rte_unused struct i40e_hw *hw,
4591 struct i40e_virt_mem *mem)
4594 return I40E_ERR_PARAM;
4599 return I40E_SUCCESS;
4603 i40e_init_spinlock_d(struct i40e_spinlock *sp)
4605 rte_spinlock_init(&sp->spinlock);
4609 i40e_acquire_spinlock_d(struct i40e_spinlock *sp)
4611 rte_spinlock_lock(&sp->spinlock);
4615 i40e_release_spinlock_d(struct i40e_spinlock *sp)
4617 rte_spinlock_unlock(&sp->spinlock);
4621 i40e_destroy_spinlock_d(__rte_unused struct i40e_spinlock *sp)
4627 * Get the hardware capabilities, which will be parsed
4628 * and saved into struct i40e_hw.
4631 i40e_get_cap(struct i40e_hw *hw)
4633 struct i40e_aqc_list_capabilities_element_resp *buf;
4634 uint16_t len, size = 0;
4637 /* Calculate a huge enough buff for saving response data temporarily */
4638 len = sizeof(struct i40e_aqc_list_capabilities_element_resp) *
4639 I40E_MAX_CAP_ELE_NUM;
4640 buf = rte_zmalloc("i40e", len, 0);
4642 PMD_DRV_LOG(ERR, "Failed to allocate memory");
4643 return I40E_ERR_NO_MEMORY;
4646 /* Get, parse the capabilities and save it to hw */
4647 ret = i40e_aq_discover_capabilities(hw, buf, len, &size,
4648 i40e_aqc_opc_list_func_capabilities, NULL);
4649 if (ret != I40E_SUCCESS)
4650 PMD_DRV_LOG(ERR, "Failed to discover capabilities");
4652 /* Free the temporary buffer after being used */
4658 #define RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF 4
4660 static int i40e_pf_parse_vf_queue_number_handler(const char *key,
4668 pf = (struct i40e_pf *)opaque;
4672 num = strtoul(value, &end, 0);
4673 if (errno != 0 || end == value || *end != 0) {
4674 PMD_DRV_LOG(WARNING, "Wrong VF queue number = %s, Now it is "
4675 "kept the value = %hu", value, pf->vf_nb_qp_max);
4679 if (num <= I40E_MAX_QP_NUM_PER_VF && rte_is_power_of_2(num))
4680 pf->vf_nb_qp_max = (uint16_t)num;
4682 /* here return 0 to make next valid same argument work */
4683 PMD_DRV_LOG(WARNING, "Wrong VF queue number = %lu, it must be "
4684 "power of 2 and equal or less than 16 !, Now it is "
4685 "kept the value = %hu", num, pf->vf_nb_qp_max);
4690 static int i40e_pf_config_vf_rxq_number(struct rte_eth_dev *dev)
4692 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4693 struct rte_kvargs *kvlist;
4696 /* set default queue number per VF as 4 */
4697 pf->vf_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF;
4699 if (dev->device->devargs == NULL)
4702 kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
4706 kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_QUEUE_NUM_PER_VF_ARG);
4707 if (!kvargs_count) {
4708 rte_kvargs_free(kvlist);
4712 if (kvargs_count > 1)
4713 PMD_DRV_LOG(WARNING, "More than one argument \"%s\" and only "
4714 "the first invalid or last valid one is used !",
4715 ETH_I40E_QUEUE_NUM_PER_VF_ARG);
4717 rte_kvargs_process(kvlist, ETH_I40E_QUEUE_NUM_PER_VF_ARG,
4718 i40e_pf_parse_vf_queue_number_handler, pf);
4720 rte_kvargs_free(kvlist);
4726 i40e_pf_parameter_init(struct rte_eth_dev *dev)
4728 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4729 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4730 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
4731 uint16_t qp_count = 0, vsi_count = 0;
4733 if (pci_dev->max_vfs && !hw->func_caps.sr_iov_1_1) {
4734 PMD_INIT_LOG(ERR, "HW configuration doesn't support SRIOV");
4738 i40e_pf_config_vf_rxq_number(dev);
4740 /* Add the parameter init for LFC */
4741 pf->fc_conf.pause_time = I40E_DEFAULT_PAUSE_TIME;
4742 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_HIGH_WATER;
4743 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_LOW_WATER;
4745 pf->flags = I40E_FLAG_HEADER_SPLIT_DISABLED;
4746 pf->max_num_vsi = hw->func_caps.num_vsis;
4747 pf->lan_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_PF;
4748 pf->vmdq_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
4750 /* FDir queue/VSI allocation */
4751 pf->fdir_qp_offset = 0;
4752 if (hw->func_caps.fd) {
4753 pf->flags |= I40E_FLAG_FDIR;
4754 pf->fdir_nb_qps = I40E_DEFAULT_QP_NUM_FDIR;
4756 pf->fdir_nb_qps = 0;
4758 qp_count += pf->fdir_nb_qps;
4761 /* LAN queue/VSI allocation */
4762 pf->lan_qp_offset = pf->fdir_qp_offset + pf->fdir_nb_qps;
4763 if (!hw->func_caps.rss) {
4766 pf->flags |= I40E_FLAG_RSS;
4767 if (hw->mac.type == I40E_MAC_X722)
4768 pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE;
4769 pf->lan_nb_qps = pf->lan_nb_qp_max;
4771 qp_count += pf->lan_nb_qps;
4774 /* VF queue/VSI allocation */
4775 pf->vf_qp_offset = pf->lan_qp_offset + pf->lan_nb_qps;
4776 if (hw->func_caps.sr_iov_1_1 && pci_dev->max_vfs) {
4777 pf->flags |= I40E_FLAG_SRIOV;
4778 pf->vf_nb_qps = pf->vf_nb_qp_max;
4779 pf->vf_num = pci_dev->max_vfs;
4781 "%u VF VSIs, %u queues per VF VSI, in total %u queues",
4782 pf->vf_num, pf->vf_nb_qps, pf->vf_nb_qps * pf->vf_num);
4787 qp_count += pf->vf_nb_qps * pf->vf_num;
4788 vsi_count += pf->vf_num;
4790 /* VMDq queue/VSI allocation */
4791 pf->vmdq_qp_offset = pf->vf_qp_offset + pf->vf_nb_qps * pf->vf_num;
4792 pf->vmdq_nb_qps = 0;
4793 pf->max_nb_vmdq_vsi = 0;
4794 if (hw->func_caps.vmdq) {
4795 if (qp_count < hw->func_caps.num_tx_qp &&
4796 vsi_count < hw->func_caps.num_vsis) {
4797 pf->max_nb_vmdq_vsi = (hw->func_caps.num_tx_qp -
4798 qp_count) / pf->vmdq_nb_qp_max;
4800 /* Limit the maximum number of VMDq vsi to the maximum
4801 * ethdev can support
4803 pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
4804 hw->func_caps.num_vsis - vsi_count);
4805 pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
4807 if (pf->max_nb_vmdq_vsi) {
4808 pf->flags |= I40E_FLAG_VMDQ;
4809 pf->vmdq_nb_qps = pf->vmdq_nb_qp_max;
4811 "%u VMDQ VSIs, %u queues per VMDQ VSI, in total %u queues",
4812 pf->max_nb_vmdq_vsi, pf->vmdq_nb_qps,
4813 pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi);
4816 "No enough queues left for VMDq");
4819 PMD_DRV_LOG(INFO, "No queue or VSI left for VMDq");
4822 qp_count += pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi;
4823 vsi_count += pf->max_nb_vmdq_vsi;
4825 if (hw->func_caps.dcb)
4826 pf->flags |= I40E_FLAG_DCB;
4828 if (qp_count > hw->func_caps.num_tx_qp) {
4830 "Failed to allocate %u queues, which exceeds the hardware maximum %u",
4831 qp_count, hw->func_caps.num_tx_qp);
4834 if (vsi_count > hw->func_caps.num_vsis) {
4836 "Failed to allocate %u VSIs, which exceeds the hardware maximum %u",
4837 vsi_count, hw->func_caps.num_vsis);
4845 i40e_pf_get_switch_config(struct i40e_pf *pf)
4847 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4848 struct i40e_aqc_get_switch_config_resp *switch_config;
4849 struct i40e_aqc_switch_config_element_resp *element;
4850 uint16_t start_seid = 0, num_reported;
4853 switch_config = (struct i40e_aqc_get_switch_config_resp *)\
4854 rte_zmalloc("i40e", I40E_AQ_LARGE_BUF, 0);
4855 if (!switch_config) {
4856 PMD_DRV_LOG(ERR, "Failed to allocated memory");
4860 /* Get the switch configurations */
4861 ret = i40e_aq_get_switch_config(hw, switch_config,
4862 I40E_AQ_LARGE_BUF, &start_seid, NULL);
4863 if (ret != I40E_SUCCESS) {
4864 PMD_DRV_LOG(ERR, "Failed to get switch configurations");
4867 num_reported = rte_le_to_cpu_16(switch_config->header.num_reported);
4868 if (num_reported != 1) { /* The number should be 1 */
4869 PMD_DRV_LOG(ERR, "Wrong number of switch config reported");
4873 /* Parse the switch configuration elements */
4874 element = &(switch_config->element[0]);
4875 if (element->element_type == I40E_SWITCH_ELEMENT_TYPE_VSI) {
4876 pf->mac_seid = rte_le_to_cpu_16(element->uplink_seid);
4877 pf->main_vsi_seid = rte_le_to_cpu_16(element->seid);
4879 PMD_DRV_LOG(INFO, "Unknown element type");
4882 rte_free(switch_config);
4888 i40e_res_pool_init (struct i40e_res_pool_info *pool, uint32_t base,
4891 struct pool_entry *entry;
4893 if (pool == NULL || num == 0)
4896 entry = rte_zmalloc("i40e", sizeof(*entry), 0);
4897 if (entry == NULL) {
4898 PMD_DRV_LOG(ERR, "Failed to allocate memory for resource pool");
4902 /* queue heap initialize */
4903 pool->num_free = num;
4904 pool->num_alloc = 0;
4906 LIST_INIT(&pool->alloc_list);
4907 LIST_INIT(&pool->free_list);
4909 /* Initialize element */
4913 LIST_INSERT_HEAD(&pool->free_list, entry, next);
4918 i40e_res_pool_destroy(struct i40e_res_pool_info *pool)
4920 struct pool_entry *entry, *next_entry;
4925 for (entry = LIST_FIRST(&pool->alloc_list);
4926 entry && (next_entry = LIST_NEXT(entry, next), 1);
4927 entry = next_entry) {
4928 LIST_REMOVE(entry, next);
4932 for (entry = LIST_FIRST(&pool->free_list);
4933 entry && (next_entry = LIST_NEXT(entry, next), 1);
4934 entry = next_entry) {
4935 LIST_REMOVE(entry, next);
4940 pool->num_alloc = 0;
4942 LIST_INIT(&pool->alloc_list);
4943 LIST_INIT(&pool->free_list);
4947 i40e_res_pool_free(struct i40e_res_pool_info *pool,
4950 struct pool_entry *entry, *next, *prev, *valid_entry = NULL;
4951 uint32_t pool_offset;
4956 PMD_DRV_LOG(ERR, "Invalid parameter");
4960 pool_offset = base - pool->base;
4961 /* Lookup in alloc list */
4962 LIST_FOREACH(entry, &pool->alloc_list, next) {
4963 if (entry->base == pool_offset) {
4964 valid_entry = entry;
4965 LIST_REMOVE(entry, next);
4970 /* Not find, return */
4971 if (valid_entry == NULL) {
4972 PMD_DRV_LOG(ERR, "Failed to find entry");
4977 * Found it, move it to free list and try to merge.
4978 * In order to make merge easier, always sort it by qbase.
4979 * Find adjacent prev and last entries.
4982 LIST_FOREACH(entry, &pool->free_list, next) {
4983 if (entry->base > valid_entry->base) {
4991 len = valid_entry->len;
4992 /* Try to merge with next one*/
4994 /* Merge with next one */
4995 if (valid_entry->base + len == next->base) {
4996 next->base = valid_entry->base;
4998 rte_free(valid_entry);
5005 /* Merge with previous one */
5006 if (prev->base + prev->len == valid_entry->base) {
5008 /* If it merge with next one, remove next node */
5010 LIST_REMOVE(valid_entry, next);
5011 rte_free(valid_entry);
5014 rte_free(valid_entry);
5021 /* Not find any entry to merge, insert */
5024 LIST_INSERT_AFTER(prev, valid_entry, next);
5025 else if (next != NULL)
5026 LIST_INSERT_BEFORE(next, valid_entry, next);
5027 else /* It's empty list, insert to head */
5028 LIST_INSERT_HEAD(&pool->free_list, valid_entry, next);
5031 pool->num_free += len;
5032 pool->num_alloc -= len;
5038 i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
5041 struct pool_entry *entry, *valid_entry;
5043 if (pool == NULL || num == 0) {
5044 PMD_DRV_LOG(ERR, "Invalid parameter");
5048 if (pool->num_free < num) {
5049 PMD_DRV_LOG(ERR, "No resource. ask:%u, available:%u",
5050 num, pool->num_free);
5055 /* Lookup in free list and find most fit one */
5056 LIST_FOREACH(entry, &pool->free_list, next) {
5057 if (entry->len >= num) {
5059 if (entry->len == num) {
5060 valid_entry = entry;
5063 if (valid_entry == NULL || valid_entry->len > entry->len)
5064 valid_entry = entry;
5068 /* Not find one to satisfy the request, return */
5069 if (valid_entry == NULL) {
5070 PMD_DRV_LOG(ERR, "No valid entry found");
5074 * The entry have equal queue number as requested,
5075 * remove it from alloc_list.
5077 if (valid_entry->len == num) {
5078 LIST_REMOVE(valid_entry, next);
5081 * The entry have more numbers than requested,
5082 * create a new entry for alloc_list and minus its
5083 * queue base and number in free_list.
5085 entry = rte_zmalloc("res_pool", sizeof(*entry), 0);
5086 if (entry == NULL) {
5088 "Failed to allocate memory for resource pool");
5091 entry->base = valid_entry->base;
5093 valid_entry->base += num;
5094 valid_entry->len -= num;
5095 valid_entry = entry;
5098 /* Insert it into alloc list, not sorted */
5099 LIST_INSERT_HEAD(&pool->alloc_list, valid_entry, next);
5101 pool->num_free -= valid_entry->len;
5102 pool->num_alloc += valid_entry->len;
5104 return valid_entry->base + pool->base;
5108 * bitmap_is_subset - Check whether src2 is subset of src1
5111 bitmap_is_subset(uint8_t src1, uint8_t src2)
5113 return !((src1 ^ src2) & src2);
5116 static enum i40e_status_code
5117 validate_tcmap_parameter(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
5119 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5121 /* If DCB is not supported, only default TC is supported */
5122 if (!hw->func_caps.dcb && enabled_tcmap != I40E_DEFAULT_TCMAP) {
5123 PMD_DRV_LOG(ERR, "DCB is not enabled, only TC0 is supported");
5124 return I40E_NOT_SUPPORTED;
5127 if (!bitmap_is_subset(hw->func_caps.enabled_tcmap, enabled_tcmap)) {
5129 "Enabled TC map 0x%x not applicable to HW support 0x%x",
5130 hw->func_caps.enabled_tcmap, enabled_tcmap);
5131 return I40E_NOT_SUPPORTED;
5133 return I40E_SUCCESS;
5137 i40e_vsi_vlan_pvid_set(struct i40e_vsi *vsi,
5138 struct i40e_vsi_vlan_pvid_info *info)
5141 struct i40e_vsi_context ctxt;
5142 uint8_t vlan_flags = 0;
5145 if (vsi == NULL || info == NULL) {
5146 PMD_DRV_LOG(ERR, "invalid parameters");
5147 return I40E_ERR_PARAM;
5151 vsi->info.pvid = info->config.pvid;
5153 * If insert pvid is enabled, only tagged pkts are
5154 * allowed to be sent out.
5156 vlan_flags |= I40E_AQ_VSI_PVLAN_INSERT_PVID |
5157 I40E_AQ_VSI_PVLAN_MODE_TAGGED;
5160 if (info->config.reject.tagged == 0)
5161 vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_TAGGED;
5163 if (info->config.reject.untagged == 0)
5164 vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_UNTAGGED;
5166 vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_INSERT_PVID |
5167 I40E_AQ_VSI_PVLAN_MODE_MASK);
5168 vsi->info.port_vlan_flags |= vlan_flags;
5169 vsi->info.valid_sections =
5170 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5171 memset(&ctxt, 0, sizeof(ctxt));
5172 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
5173 ctxt.seid = vsi->seid;
5175 hw = I40E_VSI_TO_HW(vsi);
5176 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5177 if (ret != I40E_SUCCESS)
5178 PMD_DRV_LOG(ERR, "Failed to update VSI params");
5184 i40e_vsi_update_tc_bandwidth(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
5186 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5188 struct i40e_aqc_configure_vsi_tc_bw_data tc_bw_data;
5190 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
5191 if (ret != I40E_SUCCESS)
5195 PMD_DRV_LOG(ERR, "seid not valid");
5199 memset(&tc_bw_data, 0, sizeof(tc_bw_data));
5200 tc_bw_data.tc_valid_bits = enabled_tcmap;
5201 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5202 tc_bw_data.tc_bw_credits[i] =
5203 (enabled_tcmap & (1 << i)) ? 1 : 0;
5205 ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &tc_bw_data, NULL);
5206 if (ret != I40E_SUCCESS) {
5207 PMD_DRV_LOG(ERR, "Failed to configure TC BW");
5211 rte_memcpy(vsi->info.qs_handle, tc_bw_data.qs_handles,
5212 sizeof(vsi->info.qs_handle));
5213 return I40E_SUCCESS;
5216 static enum i40e_status_code
5217 i40e_vsi_config_tc_queue_mapping(struct i40e_vsi *vsi,
5218 struct i40e_aqc_vsi_properties_data *info,
5219 uint8_t enabled_tcmap)
5221 enum i40e_status_code ret;
5222 int i, total_tc = 0;
5223 uint16_t qpnum_per_tc, bsf, qp_idx;
5225 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
5226 if (ret != I40E_SUCCESS)
5229 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5230 if (enabled_tcmap & (1 << i))
5234 vsi->enabled_tc = enabled_tcmap;
5236 /* Number of queues per enabled TC */
5237 qpnum_per_tc = i40e_align_floor(vsi->nb_qps / total_tc);
5238 qpnum_per_tc = RTE_MIN(qpnum_per_tc, I40E_MAX_Q_PER_TC);
5239 bsf = rte_bsf32(qpnum_per_tc);
5241 /* Adjust the queue number to actual queues that can be applied */
5242 if (!(vsi->type == I40E_VSI_MAIN && total_tc == 1))
5243 vsi->nb_qps = qpnum_per_tc * total_tc;
5246 * Configure TC and queue mapping parameters, for enabled TC,
5247 * allocate qpnum_per_tc queues to this traffic. For disabled TC,
5248 * default queue will serve it.
5251 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5252 if (vsi->enabled_tc & (1 << i)) {
5253 info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
5254 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
5255 (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
5256 qp_idx += qpnum_per_tc;
5258 info->tc_mapping[i] = 0;
5261 /* Associate queue number with VSI */
5262 if (vsi->type == I40E_VSI_SRIOV) {
5263 info->mapping_flags |=
5264 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
5265 for (i = 0; i < vsi->nb_qps; i++)
5266 info->queue_mapping[i] =
5267 rte_cpu_to_le_16(vsi->base_queue + i);
5269 info->mapping_flags |=
5270 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
5271 info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
5273 info->valid_sections |=
5274 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
5276 return I40E_SUCCESS;
5280 i40e_veb_release(struct i40e_veb *veb)
5282 struct i40e_vsi *vsi;
5288 if (!TAILQ_EMPTY(&veb->head)) {
5289 PMD_DRV_LOG(ERR, "VEB still has VSI attached, can't remove");
5292 /* associate_vsi field is NULL for floating VEB */
5293 if (veb->associate_vsi != NULL) {
5294 vsi = veb->associate_vsi;
5295 hw = I40E_VSI_TO_HW(vsi);
5297 vsi->uplink_seid = veb->uplink_seid;
5300 veb->associate_pf->main_vsi->floating_veb = NULL;
5301 hw = I40E_VSI_TO_HW(veb->associate_pf->main_vsi);
5304 i40e_aq_delete_element(hw, veb->seid, NULL);
5306 return I40E_SUCCESS;
5310 static struct i40e_veb *
5311 i40e_veb_setup(struct i40e_pf *pf, struct i40e_vsi *vsi)
5313 struct i40e_veb *veb;
5319 "veb setup failed, associated PF shouldn't null");
5322 hw = I40E_PF_TO_HW(pf);
5324 veb = rte_zmalloc("i40e_veb", sizeof(struct i40e_veb), 0);
5326 PMD_DRV_LOG(ERR, "Failed to allocate memory for veb");
5330 veb->associate_vsi = vsi;
5331 veb->associate_pf = pf;
5332 TAILQ_INIT(&veb->head);
5333 veb->uplink_seid = vsi ? vsi->uplink_seid : 0;
5335 /* create floating veb if vsi is NULL */
5337 ret = i40e_aq_add_veb(hw, veb->uplink_seid, vsi->seid,
5338 I40E_DEFAULT_TCMAP, false,
5339 &veb->seid, false, NULL);
5341 ret = i40e_aq_add_veb(hw, 0, 0, I40E_DEFAULT_TCMAP,
5342 true, &veb->seid, false, NULL);
5345 if (ret != I40E_SUCCESS) {
5346 PMD_DRV_LOG(ERR, "Add veb failed, aq_err: %d",
5347 hw->aq.asq_last_status);
5350 veb->enabled_tc = I40E_DEFAULT_TCMAP;
5352 /* get statistics index */
5353 ret = i40e_aq_get_veb_parameters(hw, veb->seid, NULL, NULL,
5354 &veb->stats_idx, NULL, NULL, NULL);
5355 if (ret != I40E_SUCCESS) {
5356 PMD_DRV_LOG(ERR, "Get veb statistics index failed, aq_err: %d",
5357 hw->aq.asq_last_status);
5360 /* Get VEB bandwidth, to be implemented */
5361 /* Now associated vsi binding to the VEB, set uplink to this VEB */
5363 vsi->uplink_seid = veb->seid;
5372 i40e_vsi_release(struct i40e_vsi *vsi)
5376 struct i40e_vsi_list *vsi_list;
5379 struct i40e_mac_filter *f;
5380 uint16_t user_param;
5383 return I40E_SUCCESS;
5388 user_param = vsi->user_param;
5390 pf = I40E_VSI_TO_PF(vsi);
5391 hw = I40E_VSI_TO_HW(vsi);
5393 /* VSI has child to attach, release child first */
5395 TAILQ_FOREACH_SAFE(vsi_list, &vsi->veb->head, list, temp) {
5396 if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
5399 i40e_veb_release(vsi->veb);
5402 if (vsi->floating_veb) {
5403 TAILQ_FOREACH_SAFE(vsi_list, &vsi->floating_veb->head, list, temp) {
5404 if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
5409 /* Remove all macvlan filters of the VSI */
5410 i40e_vsi_remove_all_macvlan_filter(vsi);
5411 TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp)
5414 if (vsi->type != I40E_VSI_MAIN &&
5415 ((vsi->type != I40E_VSI_SRIOV) ||
5416 !pf->floating_veb_list[user_param])) {
5417 /* Remove vsi from parent's sibling list */
5418 if (vsi->parent_vsi == NULL || vsi->parent_vsi->veb == NULL) {
5419 PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
5420 return I40E_ERR_PARAM;
5422 TAILQ_REMOVE(&vsi->parent_vsi->veb->head,
5423 &vsi->sib_vsi_list, list);
5425 /* Remove all switch element of the VSI */
5426 ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
5427 if (ret != I40E_SUCCESS)
5428 PMD_DRV_LOG(ERR, "Failed to delete element");
5431 if ((vsi->type == I40E_VSI_SRIOV) &&
5432 pf->floating_veb_list[user_param]) {
5433 /* Remove vsi from parent's sibling list */
5434 if (vsi->parent_vsi == NULL ||
5435 vsi->parent_vsi->floating_veb == NULL) {
5436 PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
5437 return I40E_ERR_PARAM;
5439 TAILQ_REMOVE(&vsi->parent_vsi->floating_veb->head,
5440 &vsi->sib_vsi_list, list);
5442 /* Remove all switch element of the VSI */
5443 ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
5444 if (ret != I40E_SUCCESS)
5445 PMD_DRV_LOG(ERR, "Failed to delete element");
5448 i40e_res_pool_free(&pf->qp_pool, vsi->base_queue);
5450 if (vsi->type != I40E_VSI_SRIOV)
5451 i40e_res_pool_free(&pf->msix_pool, vsi->msix_intr);
5454 return I40E_SUCCESS;
5458 i40e_update_default_filter_setting(struct i40e_vsi *vsi)
5460 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5461 struct i40e_aqc_remove_macvlan_element_data def_filter;
5462 struct i40e_mac_filter_info filter;
5465 if (vsi->type != I40E_VSI_MAIN)
5466 return I40E_ERR_CONFIG;
5467 memset(&def_filter, 0, sizeof(def_filter));
5468 rte_memcpy(def_filter.mac_addr, hw->mac.perm_addr,
5470 def_filter.vlan_tag = 0;
5471 def_filter.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
5472 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
5473 ret = i40e_aq_remove_macvlan(hw, vsi->seid, &def_filter, 1, NULL);
5474 if (ret != I40E_SUCCESS) {
5475 struct i40e_mac_filter *f;
5476 struct rte_ether_addr *mac;
5479 "Cannot remove the default macvlan filter");
5480 /* It needs to add the permanent mac into mac list */
5481 f = rte_zmalloc("macv_filter", sizeof(*f), 0);
5483 PMD_DRV_LOG(ERR, "failed to allocate memory");
5484 return I40E_ERR_NO_MEMORY;
5486 mac = &f->mac_info.mac_addr;
5487 rte_memcpy(&mac->addr_bytes, hw->mac.perm_addr,
5489 f->mac_info.filter_type = RTE_MACVLAN_PERFECT_MATCH;
5490 TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
5495 rte_memcpy(&filter.mac_addr,
5496 (struct rte_ether_addr *)(hw->mac.perm_addr), ETH_ADDR_LEN);
5497 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
5498 return i40e_vsi_add_mac(vsi, &filter);
5502 * i40e_vsi_get_bw_config - Query VSI BW Information
5503 * @vsi: the VSI to be queried
5505 * Returns 0 on success, negative value on failure
5507 static enum i40e_status_code
5508 i40e_vsi_get_bw_config(struct i40e_vsi *vsi)
5510 struct i40e_aqc_query_vsi_bw_config_resp bw_config;
5511 struct i40e_aqc_query_vsi_ets_sla_config_resp ets_sla_config;
5512 struct i40e_hw *hw = &vsi->adapter->hw;
5517 memset(&bw_config, 0, sizeof(bw_config));
5518 ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
5519 if (ret != I40E_SUCCESS) {
5520 PMD_DRV_LOG(ERR, "VSI failed to get bandwidth configuration %u",
5521 hw->aq.asq_last_status);
5525 memset(&ets_sla_config, 0, sizeof(ets_sla_config));
5526 ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid,
5527 &ets_sla_config, NULL);
5528 if (ret != I40E_SUCCESS) {
5530 "VSI failed to get TC bandwdith configuration %u",
5531 hw->aq.asq_last_status);
5535 /* store and print out BW info */
5536 vsi->bw_info.bw_limit = rte_le_to_cpu_16(bw_config.port_bw_limit);
5537 vsi->bw_info.bw_max = bw_config.max_bw;
5538 PMD_DRV_LOG(DEBUG, "VSI bw limit:%u", vsi->bw_info.bw_limit);
5539 PMD_DRV_LOG(DEBUG, "VSI max_bw:%u", vsi->bw_info.bw_max);
5540 bw_max = rte_le_to_cpu_16(ets_sla_config.tc_bw_max[0]) |
5541 (rte_le_to_cpu_16(ets_sla_config.tc_bw_max[1]) <<
5543 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5544 vsi->bw_info.bw_ets_share_credits[i] =
5545 ets_sla_config.share_credits[i];
5546 vsi->bw_info.bw_ets_credits[i] =
5547 rte_le_to_cpu_16(ets_sla_config.credits[i]);
5548 /* 4 bits per TC, 4th bit is reserved */
5549 vsi->bw_info.bw_ets_max[i] =
5550 (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
5551 RTE_LEN2MASK(3, uint8_t));
5552 PMD_DRV_LOG(DEBUG, "\tVSI TC%u:share credits %u", i,
5553 vsi->bw_info.bw_ets_share_credits[i]);
5554 PMD_DRV_LOG(DEBUG, "\tVSI TC%u:credits %u", i,
5555 vsi->bw_info.bw_ets_credits[i]);
5556 PMD_DRV_LOG(DEBUG, "\tVSI TC%u: max credits: %u", i,
5557 vsi->bw_info.bw_ets_max[i]);
5560 return I40E_SUCCESS;
5563 /* i40e_enable_pf_lb
5564 * @pf: pointer to the pf structure
5566 * allow loopback on pf
5569 i40e_enable_pf_lb(struct i40e_pf *pf)
5571 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5572 struct i40e_vsi_context ctxt;
5575 /* Use the FW API if FW >= v5.0 */
5576 if (hw->aq.fw_maj_ver < 5 && hw->mac.type != I40E_MAC_X722) {
5577 PMD_INIT_LOG(ERR, "FW < v5.0, cannot enable loopback");
5581 memset(&ctxt, 0, sizeof(ctxt));
5582 ctxt.seid = pf->main_vsi_seid;
5583 ctxt.pf_num = hw->pf_id;
5584 ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5586 PMD_DRV_LOG(ERR, "cannot get pf vsi config, err %d, aq_err %d",
5587 ret, hw->aq.asq_last_status);
5590 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
5591 ctxt.info.valid_sections =
5592 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5593 ctxt.info.switch_id |=
5594 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5596 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5598 PMD_DRV_LOG(ERR, "update vsi switch failed, aq_err=%d",
5599 hw->aq.asq_last_status);
5604 i40e_vsi_setup(struct i40e_pf *pf,
5605 enum i40e_vsi_type type,
5606 struct i40e_vsi *uplink_vsi,
5607 uint16_t user_param)
5609 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5610 struct i40e_vsi *vsi;
5611 struct i40e_mac_filter_info filter;
5613 struct i40e_vsi_context ctxt;
5614 struct rte_ether_addr broadcast =
5615 {.addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
5617 if (type != I40E_VSI_MAIN && type != I40E_VSI_SRIOV &&
5618 uplink_vsi == NULL) {
5620 "VSI setup failed, VSI link shouldn't be NULL");
5624 if (type == I40E_VSI_MAIN && uplink_vsi != NULL) {
5626 "VSI setup failed, MAIN VSI uplink VSI should be NULL");
5631 * 1.type is not MAIN and uplink vsi is not NULL
5632 * If uplink vsi didn't setup VEB, create one first under veb field
5633 * 2.type is SRIOV and the uplink is NULL
5634 * If floating VEB is NULL, create one veb under floating veb field
5637 if (type != I40E_VSI_MAIN && uplink_vsi != NULL &&
5638 uplink_vsi->veb == NULL) {
5639 uplink_vsi->veb = i40e_veb_setup(pf, uplink_vsi);
5641 if (uplink_vsi->veb == NULL) {
5642 PMD_DRV_LOG(ERR, "VEB setup failed");
5645 /* set ALLOWLOOPBACk on pf, when veb is created */
5646 i40e_enable_pf_lb(pf);
5649 if (type == I40E_VSI_SRIOV && uplink_vsi == NULL &&
5650 pf->main_vsi->floating_veb == NULL) {
5651 pf->main_vsi->floating_veb = i40e_veb_setup(pf, uplink_vsi);
5653 if (pf->main_vsi->floating_veb == NULL) {
5654 PMD_DRV_LOG(ERR, "VEB setup failed");
5659 vsi = rte_zmalloc("i40e_vsi", sizeof(struct i40e_vsi), 0);
5661 PMD_DRV_LOG(ERR, "Failed to allocate memory for vsi");
5664 TAILQ_INIT(&vsi->mac_list);
5666 vsi->adapter = I40E_PF_TO_ADAPTER(pf);
5667 vsi->max_macaddrs = I40E_NUM_MACADDR_MAX;
5668 vsi->parent_vsi = uplink_vsi ? uplink_vsi : pf->main_vsi;
5669 vsi->user_param = user_param;
5670 vsi->vlan_anti_spoof_on = 0;
5671 vsi->vlan_filter_on = 0;
5672 /* Allocate queues */
5673 switch (vsi->type) {
5674 case I40E_VSI_MAIN :
5675 vsi->nb_qps = pf->lan_nb_qps;
5677 case I40E_VSI_SRIOV :
5678 vsi->nb_qps = pf->vf_nb_qps;
5680 case I40E_VSI_VMDQ2:
5681 vsi->nb_qps = pf->vmdq_nb_qps;
5684 vsi->nb_qps = pf->fdir_nb_qps;
5690 * The filter status descriptor is reported in rx queue 0,
5691 * while the tx queue for fdir filter programming has no
5692 * such constraints, can be non-zero queues.
5693 * To simplify it, choose FDIR vsi use queue 0 pair.
5694 * To make sure it will use queue 0 pair, queue allocation
5695 * need be done before this function is called
5697 if (type != I40E_VSI_FDIR) {
5698 ret = i40e_res_pool_alloc(&pf->qp_pool, vsi->nb_qps);
5700 PMD_DRV_LOG(ERR, "VSI %d allocate queue failed %d",
5704 vsi->base_queue = ret;
5706 vsi->base_queue = I40E_FDIR_QUEUE_ID;
5708 /* VF has MSIX interrupt in VF range, don't allocate here */
5709 if (type == I40E_VSI_MAIN) {
5710 if (pf->support_multi_driver) {
5711 /* If support multi-driver, need to use INT0 instead of
5712 * allocating from msix pool. The Msix pool is init from
5713 * INT1, so it's OK just set msix_intr to 0 and nb_msix
5714 * to 1 without calling i40e_res_pool_alloc.
5719 ret = i40e_res_pool_alloc(&pf->msix_pool,
5720 RTE_MIN(vsi->nb_qps,
5721 RTE_MAX_RXTX_INTR_VEC_ID));
5724 "VSI MAIN %d get heap failed %d",
5726 goto fail_queue_alloc;
5728 vsi->msix_intr = ret;
5729 vsi->nb_msix = RTE_MIN(vsi->nb_qps,
5730 RTE_MAX_RXTX_INTR_VEC_ID);
5732 } else if (type != I40E_VSI_SRIOV) {
5733 ret = i40e_res_pool_alloc(&pf->msix_pool, 1);
5735 PMD_DRV_LOG(ERR, "VSI %d get heap failed %d", vsi->seid, ret);
5736 goto fail_queue_alloc;
5738 vsi->msix_intr = ret;
5746 if (type == I40E_VSI_MAIN) {
5747 /* For main VSI, no need to add since it's default one */
5748 vsi->uplink_seid = pf->mac_seid;
5749 vsi->seid = pf->main_vsi_seid;
5750 /* Bind queues with specific MSIX interrupt */
5752 * Needs 2 interrupt at least, one for misc cause which will
5753 * enabled from OS side, Another for queues binding the
5754 * interrupt from device side only.
5757 /* Get default VSI parameters from hardware */
5758 memset(&ctxt, 0, sizeof(ctxt));
5759 ctxt.seid = vsi->seid;
5760 ctxt.pf_num = hw->pf_id;
5761 ctxt.uplink_seid = vsi->uplink_seid;
5763 ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5764 if (ret != I40E_SUCCESS) {
5765 PMD_DRV_LOG(ERR, "Failed to get VSI params");
5766 goto fail_msix_alloc;
5768 rte_memcpy(&vsi->info, &ctxt.info,
5769 sizeof(struct i40e_aqc_vsi_properties_data));
5770 vsi->vsi_id = ctxt.vsi_number;
5771 vsi->info.valid_sections = 0;
5773 /* Configure tc, enabled TC0 only */
5774 if (i40e_vsi_update_tc_bandwidth(vsi, I40E_DEFAULT_TCMAP) !=
5776 PMD_DRV_LOG(ERR, "Failed to update TC bandwidth");
5777 goto fail_msix_alloc;
5780 /* TC, queue mapping */
5781 memset(&ctxt, 0, sizeof(ctxt));
5782 vsi->info.valid_sections |=
5783 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5784 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
5785 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
5786 rte_memcpy(&ctxt.info, &vsi->info,
5787 sizeof(struct i40e_aqc_vsi_properties_data));
5788 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
5789 I40E_DEFAULT_TCMAP);
5790 if (ret != I40E_SUCCESS) {
5792 "Failed to configure TC queue mapping");
5793 goto fail_msix_alloc;
5795 ctxt.seid = vsi->seid;
5796 ctxt.pf_num = hw->pf_id;
5797 ctxt.uplink_seid = vsi->uplink_seid;
5800 /* Update VSI parameters */
5801 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5802 if (ret != I40E_SUCCESS) {
5803 PMD_DRV_LOG(ERR, "Failed to update VSI params");
5804 goto fail_msix_alloc;
5807 rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
5808 sizeof(vsi->info.tc_mapping));
5809 rte_memcpy(&vsi->info.queue_mapping,
5810 &ctxt.info.queue_mapping,
5811 sizeof(vsi->info.queue_mapping));
5812 vsi->info.mapping_flags = ctxt.info.mapping_flags;
5813 vsi->info.valid_sections = 0;
5815 rte_memcpy(pf->dev_addr.addr_bytes, hw->mac.perm_addr,
5819 * Updating default filter settings are necessary to prevent
5820 * reception of tagged packets.
5821 * Some old firmware configurations load a default macvlan
5822 * filter which accepts both tagged and untagged packets.
5823 * The updating is to use a normal filter instead if needed.
5824 * For NVM 4.2.2 or after, the updating is not needed anymore.
5825 * The firmware with correct configurations load the default
5826 * macvlan filter which is expected and cannot be removed.
5828 i40e_update_default_filter_setting(vsi);
5829 i40e_config_qinq(hw, vsi);
5830 } else if (type == I40E_VSI_SRIOV) {
5831 memset(&ctxt, 0, sizeof(ctxt));
5833 * For other VSI, the uplink_seid equals to uplink VSI's
5834 * uplink_seid since they share same VEB
5836 if (uplink_vsi == NULL)
5837 vsi->uplink_seid = pf->main_vsi->floating_veb->seid;
5839 vsi->uplink_seid = uplink_vsi->uplink_seid;
5840 ctxt.pf_num = hw->pf_id;
5841 ctxt.vf_num = hw->func_caps.vf_base_id + user_param;
5842 ctxt.uplink_seid = vsi->uplink_seid;
5843 ctxt.connection_type = 0x1;
5844 ctxt.flags = I40E_AQ_VSI_TYPE_VF;
5846 /* Use the VEB configuration if FW >= v5.0 */
5847 if (hw->aq.fw_maj_ver >= 5 || hw->mac.type == I40E_MAC_X722) {
5848 /* Configure switch ID */
5849 ctxt.info.valid_sections |=
5850 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5851 ctxt.info.switch_id =
5852 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5855 /* Configure port/vlan */
5856 ctxt.info.valid_sections |=
5857 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5858 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
5859 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
5860 hw->func_caps.enabled_tcmap);
5861 if (ret != I40E_SUCCESS) {
5863 "Failed to configure TC queue mapping");
5864 goto fail_msix_alloc;
5867 ctxt.info.up_enable_bits = hw->func_caps.enabled_tcmap;
5868 ctxt.info.valid_sections |=
5869 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
5871 * Since VSI is not created yet, only configure parameter,
5872 * will add vsi below.
5875 i40e_config_qinq(hw, vsi);
5876 } else if (type == I40E_VSI_VMDQ2) {
5877 memset(&ctxt, 0, sizeof(ctxt));
5879 * For other VSI, the uplink_seid equals to uplink VSI's
5880 * uplink_seid since they share same VEB
5882 vsi->uplink_seid = uplink_vsi->uplink_seid;
5883 ctxt.pf_num = hw->pf_id;
5885 ctxt.uplink_seid = vsi->uplink_seid;
5886 ctxt.connection_type = 0x1;
5887 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
5889 ctxt.info.valid_sections |=
5890 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5891 /* user_param carries flag to enable loop back */
5893 ctxt.info.switch_id =
5894 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
5895 ctxt.info.switch_id |=
5896 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5899 /* Configure port/vlan */
5900 ctxt.info.valid_sections |=
5901 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5902 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
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);
5913 } else if (type == I40E_VSI_FDIR) {
5914 memset(&ctxt, 0, sizeof(ctxt));
5915 vsi->uplink_seid = uplink_vsi->uplink_seid;
5916 ctxt.pf_num = hw->pf_id;
5918 ctxt.uplink_seid = vsi->uplink_seid;
5919 ctxt.connection_type = 0x1; /* regular data port */
5920 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
5921 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
5922 I40E_DEFAULT_TCMAP);
5923 if (ret != I40E_SUCCESS) {
5925 "Failed to configure TC queue mapping.");
5926 goto fail_msix_alloc;
5928 ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
5929 ctxt.info.valid_sections |=
5930 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
5932 PMD_DRV_LOG(ERR, "VSI: Not support other type VSI yet");
5933 goto fail_msix_alloc;
5936 if (vsi->type != I40E_VSI_MAIN) {
5937 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
5938 if (ret != I40E_SUCCESS) {
5939 PMD_DRV_LOG(ERR, "add vsi failed, aq_err=%d",
5940 hw->aq.asq_last_status);
5941 goto fail_msix_alloc;
5943 memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
5944 vsi->info.valid_sections = 0;
5945 vsi->seid = ctxt.seid;
5946 vsi->vsi_id = ctxt.vsi_number;
5947 vsi->sib_vsi_list.vsi = vsi;
5948 if (vsi->type == I40E_VSI_SRIOV && uplink_vsi == NULL) {
5949 TAILQ_INSERT_TAIL(&pf->main_vsi->floating_veb->head,
5950 &vsi->sib_vsi_list, list);
5952 TAILQ_INSERT_TAIL(&uplink_vsi->veb->head,
5953 &vsi->sib_vsi_list, list);
5957 /* MAC/VLAN configuration */
5958 rte_memcpy(&filter.mac_addr, &broadcast, RTE_ETHER_ADDR_LEN);
5959 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
5961 ret = i40e_vsi_add_mac(vsi, &filter);
5962 if (ret != I40E_SUCCESS) {
5963 PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
5964 goto fail_msix_alloc;
5967 /* Get VSI BW information */
5968 i40e_vsi_get_bw_config(vsi);
5971 i40e_res_pool_free(&pf->msix_pool,vsi->msix_intr);
5973 i40e_res_pool_free(&pf->qp_pool,vsi->base_queue);
5979 /* Configure vlan filter on or off */
5981 i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on)
5984 struct i40e_mac_filter *f;
5986 struct i40e_mac_filter_info *mac_filter;
5987 enum rte_mac_filter_type desired_filter;
5988 int ret = I40E_SUCCESS;
5991 /* Filter to match MAC and VLAN */
5992 desired_filter = RTE_MACVLAN_PERFECT_MATCH;
5994 /* Filter to match only MAC */
5995 desired_filter = RTE_MAC_PERFECT_MATCH;
6000 mac_filter = rte_zmalloc("mac_filter_info_data",
6001 num * sizeof(*mac_filter), 0);
6002 if (mac_filter == NULL) {
6003 PMD_DRV_LOG(ERR, "failed to allocate memory");
6004 return I40E_ERR_NO_MEMORY;
6009 /* Remove all existing mac */
6010 TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
6011 mac_filter[i] = f->mac_info;
6012 ret = i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
6014 PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
6015 on ? "enable" : "disable");
6021 /* Override with new filter */
6022 for (i = 0; i < num; i++) {
6023 mac_filter[i].filter_type = desired_filter;
6024 ret = i40e_vsi_add_mac(vsi, &mac_filter[i]);
6026 PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
6027 on ? "enable" : "disable");
6033 rte_free(mac_filter);
6037 /* Configure vlan stripping on or off */
6039 i40e_vsi_config_vlan_stripping(struct i40e_vsi *vsi, bool on)
6041 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6042 struct i40e_vsi_context ctxt;
6044 int ret = I40E_SUCCESS;
6046 /* Check if it has been already on or off */
6047 if (vsi->info.valid_sections &
6048 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID)) {
6050 if ((vsi->info.port_vlan_flags &
6051 I40E_AQ_VSI_PVLAN_EMOD_MASK) == 0)
6052 return 0; /* already on */
6054 if ((vsi->info.port_vlan_flags &
6055 I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
6056 I40E_AQ_VSI_PVLAN_EMOD_MASK)
6057 return 0; /* already off */
6062 vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
6064 vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
6065 vsi->info.valid_sections =
6066 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
6067 vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_EMOD_MASK);
6068 vsi->info.port_vlan_flags |= vlan_flags;
6069 ctxt.seid = vsi->seid;
6070 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
6071 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
6073 PMD_DRV_LOG(INFO, "Update VSI failed to %s vlan stripping",
6074 on ? "enable" : "disable");
6080 i40e_dev_init_vlan(struct rte_eth_dev *dev)
6082 struct rte_eth_dev_data *data = dev->data;
6086 /* Apply vlan offload setting */
6087 mask = ETH_VLAN_STRIP_MASK |
6088 ETH_VLAN_FILTER_MASK |
6089 ETH_VLAN_EXTEND_MASK;
6090 ret = i40e_vlan_offload_set(dev, mask);
6092 PMD_DRV_LOG(INFO, "Failed to update vlan offload");
6096 /* Apply pvid setting */
6097 ret = i40e_vlan_pvid_set(dev, data->dev_conf.txmode.pvid,
6098 data->dev_conf.txmode.hw_vlan_insert_pvid);
6100 PMD_DRV_LOG(INFO, "Failed to update VSI params");
6106 i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on)
6108 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6110 return i40e_aq_set_port_parameters(hw, vsi->seid, 0, 1, on, NULL);
6114 i40e_update_flow_control(struct i40e_hw *hw)
6116 #define I40E_LINK_PAUSE_RXTX (I40E_AQ_LINK_PAUSE_RX | I40E_AQ_LINK_PAUSE_TX)
6117 struct i40e_link_status link_status;
6118 uint32_t rxfc = 0, txfc = 0, reg;
6122 memset(&link_status, 0, sizeof(link_status));
6123 ret = i40e_aq_get_link_info(hw, FALSE, &link_status, NULL);
6124 if (ret != I40E_SUCCESS) {
6125 PMD_DRV_LOG(ERR, "Failed to get link status information");
6126 goto write_reg; /* Disable flow control */
6129 an_info = hw->phy.link_info.an_info;
6130 if (!(an_info & I40E_AQ_AN_COMPLETED)) {
6131 PMD_DRV_LOG(INFO, "Link auto negotiation not completed");
6132 ret = I40E_ERR_NOT_READY;
6133 goto write_reg; /* Disable flow control */
6136 * If link auto negotiation is enabled, flow control needs to
6137 * be configured according to it
6139 switch (an_info & I40E_LINK_PAUSE_RXTX) {
6140 case I40E_LINK_PAUSE_RXTX:
6143 hw->fc.current_mode = I40E_FC_FULL;
6145 case I40E_AQ_LINK_PAUSE_RX:
6147 hw->fc.current_mode = I40E_FC_RX_PAUSE;
6149 case I40E_AQ_LINK_PAUSE_TX:
6151 hw->fc.current_mode = I40E_FC_TX_PAUSE;
6154 hw->fc.current_mode = I40E_FC_NONE;
6159 I40E_WRITE_REG(hw, I40E_PRTDCB_FCCFG,
6160 txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT);
6161 reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
6162 reg &= ~I40E_PRTDCB_MFLCN_RFCE_MASK;
6163 reg |= rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT;
6164 I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, reg);
6171 i40e_pf_setup(struct i40e_pf *pf)
6173 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6174 struct i40e_filter_control_settings settings;
6175 struct i40e_vsi *vsi;
6178 /* Clear all stats counters */
6179 pf->offset_loaded = FALSE;
6180 memset(&pf->stats, 0, sizeof(struct i40e_hw_port_stats));
6181 memset(&pf->stats_offset, 0, sizeof(struct i40e_hw_port_stats));
6182 memset(&pf->internal_stats, 0, sizeof(struct i40e_eth_stats));
6183 memset(&pf->internal_stats_offset, 0, sizeof(struct i40e_eth_stats));
6185 ret = i40e_pf_get_switch_config(pf);
6186 if (ret != I40E_SUCCESS) {
6187 PMD_DRV_LOG(ERR, "Could not get switch config, err %d", ret);
6191 ret = rte_eth_switch_domain_alloc(&pf->switch_domain_id);
6193 PMD_INIT_LOG(WARNING,
6194 "failed to allocate switch domain for device %d", ret);
6196 if (pf->flags & I40E_FLAG_FDIR) {
6197 /* make queue allocated first, let FDIR use queue pair 0*/
6198 ret = i40e_res_pool_alloc(&pf->qp_pool, I40E_DEFAULT_QP_NUM_FDIR);
6199 if (ret != I40E_FDIR_QUEUE_ID) {
6201 "queue allocation fails for FDIR: ret =%d",
6203 pf->flags &= ~I40E_FLAG_FDIR;
6206 /* main VSI setup */
6207 vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, NULL, 0);
6209 PMD_DRV_LOG(ERR, "Setup of main vsi failed");
6210 return I40E_ERR_NOT_READY;
6214 /* Configure filter control */
6215 memset(&settings, 0, sizeof(settings));
6216 if (hw->func_caps.rss_table_size == ETH_RSS_RETA_SIZE_128)
6217 settings.hash_lut_size = I40E_HASH_LUT_SIZE_128;
6218 else if (hw->func_caps.rss_table_size == ETH_RSS_RETA_SIZE_512)
6219 settings.hash_lut_size = I40E_HASH_LUT_SIZE_512;
6221 PMD_DRV_LOG(ERR, "Hash lookup table size (%u) not supported",
6222 hw->func_caps.rss_table_size);
6223 return I40E_ERR_PARAM;
6225 PMD_DRV_LOG(INFO, "Hardware capability of hash lookup table size: %u",
6226 hw->func_caps.rss_table_size);
6227 pf->hash_lut_size = hw->func_caps.rss_table_size;
6229 /* Enable ethtype and macvlan filters */
6230 settings.enable_ethtype = TRUE;
6231 settings.enable_macvlan = TRUE;
6232 ret = i40e_set_filter_control(hw, &settings);
6234 PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
6237 /* Update flow control according to the auto negotiation */
6238 i40e_update_flow_control(hw);
6240 return I40E_SUCCESS;
6244 i40e_switch_tx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
6250 * Set or clear TX Queue Disable flags,
6251 * which is required by hardware.
6253 i40e_pre_tx_queue_cfg(hw, q_idx, on);
6254 rte_delay_us(I40E_PRE_TX_Q_CFG_WAIT_US);
6256 /* Wait until the request is finished */
6257 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6258 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6259 reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
6260 if (!(((reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 0x1) ^
6261 ((reg >> I40E_QTX_ENA_QENA_STAT_SHIFT)
6267 if (reg & I40E_QTX_ENA_QENA_STAT_MASK)
6268 return I40E_SUCCESS; /* already on, skip next steps */
6270 I40E_WRITE_REG(hw, I40E_QTX_HEAD(q_idx), 0);
6271 reg |= I40E_QTX_ENA_QENA_REQ_MASK;
6273 if (!(reg & I40E_QTX_ENA_QENA_STAT_MASK))
6274 return I40E_SUCCESS; /* already off, skip next steps */
6275 reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
6277 /* Write the register */
6278 I40E_WRITE_REG(hw, I40E_QTX_ENA(q_idx), reg);
6279 /* Check the result */
6280 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6281 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6282 reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
6284 if ((reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
6285 (reg & I40E_QTX_ENA_QENA_STAT_MASK))
6288 if (!(reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
6289 !(reg & I40E_QTX_ENA_QENA_STAT_MASK))
6293 /* Check if it is timeout */
6294 if (j >= I40E_CHK_Q_ENA_COUNT) {
6295 PMD_DRV_LOG(ERR, "Failed to %s tx queue[%u]",
6296 (on ? "enable" : "disable"), q_idx);
6297 return I40E_ERR_TIMEOUT;
6300 return I40E_SUCCESS;
6304 i40e_switch_rx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
6309 /* Wait until the request is finished */
6310 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6311 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6312 reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
6313 if (!((reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 0x1) ^
6314 ((reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 0x1))
6319 if (reg & I40E_QRX_ENA_QENA_STAT_MASK)
6320 return I40E_SUCCESS; /* Already on, skip next steps */
6321 reg |= I40E_QRX_ENA_QENA_REQ_MASK;
6323 if (!(reg & I40E_QRX_ENA_QENA_STAT_MASK))
6324 return I40E_SUCCESS; /* Already off, skip next steps */
6325 reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
6328 /* Write the register */
6329 I40E_WRITE_REG(hw, I40E_QRX_ENA(q_idx), reg);
6330 /* Check the result */
6331 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6332 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6333 reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
6335 if ((reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
6336 (reg & I40E_QRX_ENA_QENA_STAT_MASK))
6339 if (!(reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
6340 !(reg & I40E_QRX_ENA_QENA_STAT_MASK))
6345 /* Check if it is timeout */
6346 if (j >= I40E_CHK_Q_ENA_COUNT) {
6347 PMD_DRV_LOG(ERR, "Failed to %s rx queue[%u]",
6348 (on ? "enable" : "disable"), q_idx);
6349 return I40E_ERR_TIMEOUT;
6352 return I40E_SUCCESS;
6355 /* Initialize VSI for TX */
6357 i40e_dev_tx_init(struct i40e_pf *pf)
6359 struct rte_eth_dev_data *data = pf->dev_data;
6361 uint32_t ret = I40E_SUCCESS;
6362 struct i40e_tx_queue *txq;
6364 for (i = 0; i < data->nb_tx_queues; i++) {
6365 txq = data->tx_queues[i];
6366 if (!txq || !txq->q_set)
6368 ret = i40e_tx_queue_init(txq);
6369 if (ret != I40E_SUCCESS)
6372 if (ret == I40E_SUCCESS)
6373 i40e_set_tx_function(container_of(pf, struct i40e_adapter, pf)
6379 /* Initialize VSI for RX */
6381 i40e_dev_rx_init(struct i40e_pf *pf)
6383 struct rte_eth_dev_data *data = pf->dev_data;
6384 int ret = I40E_SUCCESS;
6386 struct i40e_rx_queue *rxq;
6388 i40e_pf_config_mq_rx(pf);
6389 for (i = 0; i < data->nb_rx_queues; i++) {
6390 rxq = data->rx_queues[i];
6391 if (!rxq || !rxq->q_set)
6394 ret = i40e_rx_queue_init(rxq);
6395 if (ret != I40E_SUCCESS) {
6397 "Failed to do RX queue initialization");
6401 if (ret == I40E_SUCCESS)
6402 i40e_set_rx_function(container_of(pf, struct i40e_adapter, pf)
6409 i40e_dev_rxtx_init(struct i40e_pf *pf)
6413 err = i40e_dev_tx_init(pf);
6415 PMD_DRV_LOG(ERR, "Failed to do TX initialization");
6418 err = i40e_dev_rx_init(pf);
6420 PMD_DRV_LOG(ERR, "Failed to do RX initialization");
6428 i40e_vmdq_setup(struct rte_eth_dev *dev)
6430 struct rte_eth_conf *conf = &dev->data->dev_conf;
6431 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6432 int i, err, conf_vsis, j, loop;
6433 struct i40e_vsi *vsi;
6434 struct i40e_vmdq_info *vmdq_info;
6435 struct rte_eth_vmdq_rx_conf *vmdq_conf;
6436 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6439 * Disable interrupt to avoid message from VF. Furthermore, it will
6440 * avoid race condition in VSI creation/destroy.
6442 i40e_pf_disable_irq0(hw);
6444 if ((pf->flags & I40E_FLAG_VMDQ) == 0) {
6445 PMD_INIT_LOG(ERR, "FW doesn't support VMDQ");
6449 conf_vsis = conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools;
6450 if (conf_vsis > pf->max_nb_vmdq_vsi) {
6451 PMD_INIT_LOG(ERR, "VMDQ config: %u, max support:%u",
6452 conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools,
6453 pf->max_nb_vmdq_vsi);
6457 if (pf->vmdq != NULL) {
6458 PMD_INIT_LOG(INFO, "VMDQ already configured");
6462 pf->vmdq = rte_zmalloc("vmdq_info_struct",
6463 sizeof(*vmdq_info) * conf_vsis, 0);
6465 if (pf->vmdq == NULL) {
6466 PMD_INIT_LOG(ERR, "Failed to allocate memory");
6470 vmdq_conf = &conf->rx_adv_conf.vmdq_rx_conf;
6472 /* Create VMDQ VSI */
6473 for (i = 0; i < conf_vsis; i++) {
6474 vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, pf->main_vsi,
6475 vmdq_conf->enable_loop_back);
6477 PMD_INIT_LOG(ERR, "Failed to create VMDQ VSI");
6481 vmdq_info = &pf->vmdq[i];
6483 vmdq_info->vsi = vsi;
6485 pf->nb_cfg_vmdq_vsi = conf_vsis;
6487 /* Configure Vlan */
6488 loop = sizeof(vmdq_conf->pool_map[0].pools) * CHAR_BIT;
6489 for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
6490 for (j = 0; j < loop && j < pf->nb_cfg_vmdq_vsi; j++) {
6491 if (vmdq_conf->pool_map[i].pools & (1UL << j)) {
6492 PMD_INIT_LOG(INFO, "Add vlan %u to vmdq pool %u",
6493 vmdq_conf->pool_map[i].vlan_id, j);
6495 err = i40e_vsi_add_vlan(pf->vmdq[j].vsi,
6496 vmdq_conf->pool_map[i].vlan_id);
6498 PMD_INIT_LOG(ERR, "Failed to add vlan");
6506 i40e_pf_enable_irq0(hw);
6511 for (i = 0; i < conf_vsis; i++)
6512 if (pf->vmdq[i].vsi == NULL)
6515 i40e_vsi_release(pf->vmdq[i].vsi);
6519 i40e_pf_enable_irq0(hw);
6524 i40e_stat_update_32(struct i40e_hw *hw,
6532 new_data = (uint64_t)I40E_READ_REG(hw, reg);
6536 if (new_data >= *offset)
6537 *stat = (uint64_t)(new_data - *offset);
6539 *stat = (uint64_t)((new_data +
6540 ((uint64_t)1 << I40E_32_BIT_WIDTH)) - *offset);
6544 i40e_stat_update_48(struct i40e_hw *hw,
6553 new_data = (uint64_t)I40E_READ_REG(hw, loreg);
6554 new_data |= ((uint64_t)(I40E_READ_REG(hw, hireg) &
6555 I40E_16_BIT_MASK)) << I40E_32_BIT_WIDTH;
6560 if (new_data >= *offset)
6561 *stat = new_data - *offset;
6563 *stat = (uint64_t)((new_data +
6564 ((uint64_t)1 << I40E_48_BIT_WIDTH)) - *offset);
6566 *stat &= I40E_48_BIT_MASK;
6571 i40e_pf_disable_irq0(struct i40e_hw *hw)
6573 /* Disable all interrupt types */
6574 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
6575 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
6576 I40E_WRITE_FLUSH(hw);
6581 i40e_pf_enable_irq0(struct i40e_hw *hw)
6583 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
6584 I40E_PFINT_DYN_CTL0_INTENA_MASK |
6585 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
6586 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
6587 I40E_WRITE_FLUSH(hw);
6591 i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue)
6593 /* read pending request and disable first */
6594 i40e_pf_disable_irq0(hw);
6595 I40E_WRITE_REG(hw, I40E_PFINT_ICR0_ENA, I40E_PFINT_ICR0_ENA_MASK);
6596 I40E_WRITE_REG(hw, I40E_PFINT_STAT_CTL0,
6597 I40E_PFINT_STAT_CTL0_OTHER_ITR_INDX_MASK);
6600 /* Link no queues with irq0 */
6601 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
6602 I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
6606 i40e_dev_handle_vfr_event(struct rte_eth_dev *dev)
6608 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6609 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6612 uint32_t index, offset, val;
6617 * Try to find which VF trigger a reset, use absolute VF id to access
6618 * since the reg is global register.
6620 for (i = 0; i < pf->vf_num; i++) {
6621 abs_vf_id = hw->func_caps.vf_base_id + i;
6622 index = abs_vf_id / I40E_UINT32_BIT_SIZE;
6623 offset = abs_vf_id % I40E_UINT32_BIT_SIZE;
6624 val = I40E_READ_REG(hw, I40E_GLGEN_VFLRSTAT(index));
6625 /* VFR event occurred */
6626 if (val & (0x1 << offset)) {
6629 /* Clear the event first */
6630 I40E_WRITE_REG(hw, I40E_GLGEN_VFLRSTAT(index),
6632 PMD_DRV_LOG(INFO, "VF %u reset occurred", abs_vf_id);
6634 * Only notify a VF reset event occurred,
6635 * don't trigger another SW reset
6637 ret = i40e_pf_host_vf_reset(&pf->vfs[i], 0);
6638 if (ret != I40E_SUCCESS)
6639 PMD_DRV_LOG(ERR, "Failed to do VF reset");
6645 i40e_notify_all_vfs_link_status(struct rte_eth_dev *dev)
6647 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6650 for (i = 0; i < pf->vf_num; i++)
6651 i40e_notify_vf_link_status(dev, &pf->vfs[i]);
6655 i40e_dev_handle_aq_msg(struct rte_eth_dev *dev)
6657 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6658 struct i40e_arq_event_info info;
6659 uint16_t pending, opcode;
6662 info.buf_len = I40E_AQ_BUF_SZ;
6663 info.msg_buf = rte_zmalloc("msg_buffer", info.buf_len, 0);
6664 if (!info.msg_buf) {
6665 PMD_DRV_LOG(ERR, "Failed to allocate mem");
6671 ret = i40e_clean_arq_element(hw, &info, &pending);
6673 if (ret != I40E_SUCCESS) {
6675 "Failed to read msg from AdminQ, aq_err: %u",
6676 hw->aq.asq_last_status);
6679 opcode = rte_le_to_cpu_16(info.desc.opcode);
6682 case i40e_aqc_opc_send_msg_to_pf:
6683 /* Refer to i40e_aq_send_msg_to_pf() for argument layout*/
6684 i40e_pf_host_handle_vf_msg(dev,
6685 rte_le_to_cpu_16(info.desc.retval),
6686 rte_le_to_cpu_32(info.desc.cookie_high),
6687 rte_le_to_cpu_32(info.desc.cookie_low),
6691 case i40e_aqc_opc_get_link_status:
6692 ret = i40e_dev_link_update(dev, 0);
6694 _rte_eth_dev_callback_process(dev,
6695 RTE_ETH_EVENT_INTR_LSC, NULL);
6698 PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
6703 rte_free(info.msg_buf);
6707 i40e_handle_mdd_event(struct rte_eth_dev *dev)
6709 #define I40E_MDD_CLEAR32 0xFFFFFFFF
6710 #define I40E_MDD_CLEAR16 0xFFFF
6711 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6712 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6713 bool mdd_detected = false;
6714 struct i40e_pf_vf *vf;
6718 /* find what triggered the MDD event */
6719 reg = I40E_READ_REG(hw, I40E_GL_MDET_TX);
6720 if (reg & I40E_GL_MDET_TX_VALID_MASK) {
6721 uint8_t pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
6722 I40E_GL_MDET_TX_PF_NUM_SHIFT;
6723 uint16_t vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
6724 I40E_GL_MDET_TX_VF_NUM_SHIFT;
6725 uint8_t event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
6726 I40E_GL_MDET_TX_EVENT_SHIFT;
6727 uint16_t queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
6728 I40E_GL_MDET_TX_QUEUE_SHIFT) -
6729 hw->func_caps.base_queue;
6730 PMD_DRV_LOG(WARNING, "Malicious Driver Detection event 0x%02x on TX "
6731 "queue %d PF number 0x%02x VF number 0x%02x device %s\n",
6732 event, queue, pf_num, vf_num, dev->data->name);
6733 I40E_WRITE_REG(hw, I40E_GL_MDET_TX, I40E_MDD_CLEAR32);
6734 mdd_detected = true;
6736 reg = I40E_READ_REG(hw, I40E_GL_MDET_RX);
6737 if (reg & I40E_GL_MDET_RX_VALID_MASK) {
6738 uint8_t func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
6739 I40E_GL_MDET_RX_FUNCTION_SHIFT;
6740 uint8_t event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
6741 I40E_GL_MDET_RX_EVENT_SHIFT;
6742 uint16_t queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
6743 I40E_GL_MDET_RX_QUEUE_SHIFT) -
6744 hw->func_caps.base_queue;
6746 PMD_DRV_LOG(WARNING, "Malicious Driver Detection event 0x%02x on RX "
6747 "queue %d of function 0x%02x device %s\n",
6748 event, queue, func, dev->data->name);
6749 I40E_WRITE_REG(hw, I40E_GL_MDET_RX, I40E_MDD_CLEAR32);
6750 mdd_detected = true;
6754 reg = I40E_READ_REG(hw, I40E_PF_MDET_TX);
6755 if (reg & I40E_PF_MDET_TX_VALID_MASK) {
6756 I40E_WRITE_REG(hw, I40E_PF_MDET_TX, I40E_MDD_CLEAR16);
6757 PMD_DRV_LOG(WARNING, "TX driver issue detected on PF\n");
6759 reg = I40E_READ_REG(hw, I40E_PF_MDET_RX);
6760 if (reg & I40E_PF_MDET_RX_VALID_MASK) {
6761 I40E_WRITE_REG(hw, I40E_PF_MDET_RX,
6763 PMD_DRV_LOG(WARNING, "RX driver issue detected on PF\n");
6767 /* see if one of the VFs needs its hand slapped */
6768 for (i = 0; i < pf->vf_num && mdd_detected; i++) {
6770 reg = I40E_READ_REG(hw, I40E_VP_MDET_TX(i));
6771 if (reg & I40E_VP_MDET_TX_VALID_MASK) {
6772 I40E_WRITE_REG(hw, I40E_VP_MDET_TX(i),
6774 vf->num_mdd_events++;
6775 PMD_DRV_LOG(WARNING, "TX driver issue detected on VF %d %-"
6777 i, vf->num_mdd_events);
6780 reg = I40E_READ_REG(hw, I40E_VP_MDET_RX(i));
6781 if (reg & I40E_VP_MDET_RX_VALID_MASK) {
6782 I40E_WRITE_REG(hw, I40E_VP_MDET_RX(i),
6784 vf->num_mdd_events++;
6785 PMD_DRV_LOG(WARNING, "RX driver issue detected on VF %d %-"
6787 i, vf->num_mdd_events);
6793 * Interrupt handler triggered by NIC for handling
6794 * specific interrupt.
6797 * Pointer to interrupt handle.
6799 * The address of parameter (struct rte_eth_dev *) regsitered before.
6805 i40e_dev_interrupt_handler(void *param)
6807 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
6808 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6811 /* Disable interrupt */
6812 i40e_pf_disable_irq0(hw);
6814 /* read out interrupt causes */
6815 icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
6817 /* No interrupt event indicated */
6818 if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK)) {
6819 PMD_DRV_LOG(INFO, "No interrupt event");
6822 if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
6823 PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
6824 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
6825 PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
6826 i40e_handle_mdd_event(dev);
6828 if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
6829 PMD_DRV_LOG(INFO, "ICR0: global reset requested");
6830 if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
6831 PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
6832 if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
6833 PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
6834 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
6835 PMD_DRV_LOG(ERR, "ICR0: HMC error");
6836 if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
6837 PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
6839 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
6840 PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
6841 i40e_dev_handle_vfr_event(dev);
6843 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
6844 PMD_DRV_LOG(INFO, "ICR0: adminq event");
6845 i40e_dev_handle_aq_msg(dev);
6849 /* Enable interrupt */
6850 i40e_pf_enable_irq0(hw);
6854 i40e_dev_alarm_handler(void *param)
6856 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
6857 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6860 /* Disable interrupt */
6861 i40e_pf_disable_irq0(hw);
6863 /* read out interrupt causes */
6864 icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
6866 /* No interrupt event indicated */
6867 if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK))
6869 if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
6870 PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
6871 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
6872 PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
6873 i40e_handle_mdd_event(dev);
6875 if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
6876 PMD_DRV_LOG(INFO, "ICR0: global reset requested");
6877 if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
6878 PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
6879 if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
6880 PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
6881 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
6882 PMD_DRV_LOG(ERR, "ICR0: HMC error");
6883 if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
6884 PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
6886 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
6887 PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
6888 i40e_dev_handle_vfr_event(dev);
6890 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
6891 PMD_DRV_LOG(INFO, "ICR0: adminq event");
6892 i40e_dev_handle_aq_msg(dev);
6896 /* Enable interrupt */
6897 i40e_pf_enable_irq0(hw);
6898 rte_eal_alarm_set(I40E_ALARM_INTERVAL,
6899 i40e_dev_alarm_handler, dev);
6903 i40e_add_macvlan_filters(struct i40e_vsi *vsi,
6904 struct i40e_macvlan_filter *filter,
6907 int ele_num, ele_buff_size;
6908 int num, actual_num, i;
6910 int ret = I40E_SUCCESS;
6911 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6912 struct i40e_aqc_add_macvlan_element_data *req_list;
6914 if (filter == NULL || total == 0)
6915 return I40E_ERR_PARAM;
6916 ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
6917 ele_buff_size = hw->aq.asq_buf_size;
6919 req_list = rte_zmalloc("macvlan_add", ele_buff_size, 0);
6920 if (req_list == NULL) {
6921 PMD_DRV_LOG(ERR, "Fail to allocate memory");
6922 return I40E_ERR_NO_MEMORY;
6927 actual_num = (num + ele_num > total) ? (total - num) : ele_num;
6928 memset(req_list, 0, ele_buff_size);
6930 for (i = 0; i < actual_num; i++) {
6931 rte_memcpy(req_list[i].mac_addr,
6932 &filter[num + i].macaddr, ETH_ADDR_LEN);
6933 req_list[i].vlan_tag =
6934 rte_cpu_to_le_16(filter[num + i].vlan_id);
6936 switch (filter[num + i].filter_type) {
6937 case RTE_MAC_PERFECT_MATCH:
6938 flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH |
6939 I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
6941 case RTE_MACVLAN_PERFECT_MATCH:
6942 flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
6944 case RTE_MAC_HASH_MATCH:
6945 flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH |
6946 I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
6948 case RTE_MACVLAN_HASH_MATCH:
6949 flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH;
6952 PMD_DRV_LOG(ERR, "Invalid MAC match type");
6953 ret = I40E_ERR_PARAM;
6957 req_list[i].queue_number = 0;
6959 req_list[i].flags = rte_cpu_to_le_16(flags);
6962 ret = i40e_aq_add_macvlan(hw, vsi->seid, req_list,
6964 if (ret != I40E_SUCCESS) {
6965 PMD_DRV_LOG(ERR, "Failed to add macvlan filter");
6969 } while (num < total);
6977 i40e_remove_macvlan_filters(struct i40e_vsi *vsi,
6978 struct i40e_macvlan_filter *filter,
6981 int ele_num, ele_buff_size;
6982 int num, actual_num, i;
6984 int ret = I40E_SUCCESS;
6985 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6986 struct i40e_aqc_remove_macvlan_element_data *req_list;
6988 if (filter == NULL || total == 0)
6989 return I40E_ERR_PARAM;
6991 ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
6992 ele_buff_size = hw->aq.asq_buf_size;
6994 req_list = rte_zmalloc("macvlan_remove", ele_buff_size, 0);
6995 if (req_list == NULL) {
6996 PMD_DRV_LOG(ERR, "Fail to allocate memory");
6997 return I40E_ERR_NO_MEMORY;
7002 actual_num = (num + ele_num > total) ? (total - num) : ele_num;
7003 memset(req_list, 0, ele_buff_size);
7005 for (i = 0; i < actual_num; i++) {
7006 rte_memcpy(req_list[i].mac_addr,
7007 &filter[num + i].macaddr, ETH_ADDR_LEN);
7008 req_list[i].vlan_tag =
7009 rte_cpu_to_le_16(filter[num + i].vlan_id);
7011 switch (filter[num + i].filter_type) {
7012 case RTE_MAC_PERFECT_MATCH:
7013 flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
7014 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
7016 case RTE_MACVLAN_PERFECT_MATCH:
7017 flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
7019 case RTE_MAC_HASH_MATCH:
7020 flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH |
7021 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
7023 case RTE_MACVLAN_HASH_MATCH:
7024 flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH;
7027 PMD_DRV_LOG(ERR, "Invalid MAC filter type");
7028 ret = I40E_ERR_PARAM;
7031 req_list[i].flags = rte_cpu_to_le_16(flags);
7034 ret = i40e_aq_remove_macvlan(hw, vsi->seid, req_list,
7036 if (ret != I40E_SUCCESS) {
7037 PMD_DRV_LOG(ERR, "Failed to remove macvlan filter");
7041 } while (num < total);
7048 /* Find out specific MAC filter */
7049 static struct i40e_mac_filter *
7050 i40e_find_mac_filter(struct i40e_vsi *vsi,
7051 struct rte_ether_addr *macaddr)
7053 struct i40e_mac_filter *f;
7055 TAILQ_FOREACH(f, &vsi->mac_list, next) {
7056 if (rte_is_same_ether_addr(macaddr, &f->mac_info.mac_addr))
7064 i40e_find_vlan_filter(struct i40e_vsi *vsi,
7067 uint32_t vid_idx, vid_bit;
7069 if (vlan_id > ETH_VLAN_ID_MAX)
7072 vid_idx = I40E_VFTA_IDX(vlan_id);
7073 vid_bit = I40E_VFTA_BIT(vlan_id);
7075 if (vsi->vfta[vid_idx] & vid_bit)
7082 i40e_store_vlan_filter(struct i40e_vsi *vsi,
7083 uint16_t vlan_id, bool on)
7085 uint32_t vid_idx, vid_bit;
7087 vid_idx = I40E_VFTA_IDX(vlan_id);
7088 vid_bit = I40E_VFTA_BIT(vlan_id);
7091 vsi->vfta[vid_idx] |= vid_bit;
7093 vsi->vfta[vid_idx] &= ~vid_bit;
7097 i40e_set_vlan_filter(struct i40e_vsi *vsi,
7098 uint16_t vlan_id, bool on)
7100 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7101 struct i40e_aqc_add_remove_vlan_element_data vlan_data = {0};
7104 if (vlan_id > ETH_VLAN_ID_MAX)
7107 i40e_store_vlan_filter(vsi, vlan_id, on);
7109 if ((!vsi->vlan_anti_spoof_on && !vsi->vlan_filter_on) || !vlan_id)
7112 vlan_data.vlan_tag = rte_cpu_to_le_16(vlan_id);
7115 ret = i40e_aq_add_vlan(hw, vsi->seid,
7116 &vlan_data, 1, NULL);
7117 if (ret != I40E_SUCCESS)
7118 PMD_DRV_LOG(ERR, "Failed to add vlan filter");
7120 ret = i40e_aq_remove_vlan(hw, vsi->seid,
7121 &vlan_data, 1, NULL);
7122 if (ret != I40E_SUCCESS)
7124 "Failed to remove vlan filter");
7129 * Find all vlan options for specific mac addr,
7130 * return with actual vlan found.
7133 i40e_find_all_vlan_for_mac(struct i40e_vsi *vsi,
7134 struct i40e_macvlan_filter *mv_f,
7135 int num, struct rte_ether_addr *addr)
7141 * Not to use i40e_find_vlan_filter to decrease the loop time,
7142 * although the code looks complex.
7144 if (num < vsi->vlan_num)
7145 return I40E_ERR_PARAM;
7148 for (j = 0; j < I40E_VFTA_SIZE; j++) {
7150 for (k = 0; k < I40E_UINT32_BIT_SIZE; k++) {
7151 if (vsi->vfta[j] & (1 << k)) {
7154 "vlan number doesn't match");
7155 return I40E_ERR_PARAM;
7157 rte_memcpy(&mv_f[i].macaddr,
7158 addr, ETH_ADDR_LEN);
7160 j * I40E_UINT32_BIT_SIZE + k;
7166 return I40E_SUCCESS;
7170 i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
7171 struct i40e_macvlan_filter *mv_f,
7176 struct i40e_mac_filter *f;
7178 if (num < vsi->mac_num)
7179 return I40E_ERR_PARAM;
7181 TAILQ_FOREACH(f, &vsi->mac_list, next) {
7183 PMD_DRV_LOG(ERR, "buffer number not match");
7184 return I40E_ERR_PARAM;
7186 rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
7188 mv_f[i].vlan_id = vlan;
7189 mv_f[i].filter_type = f->mac_info.filter_type;
7193 return I40E_SUCCESS;
7197 i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi)
7200 struct i40e_mac_filter *f;
7201 struct i40e_macvlan_filter *mv_f;
7202 int ret = I40E_SUCCESS;
7204 if (vsi == NULL || vsi->mac_num == 0)
7205 return I40E_ERR_PARAM;
7207 /* Case that no vlan is set */
7208 if (vsi->vlan_num == 0)
7211 num = vsi->mac_num * vsi->vlan_num;
7213 mv_f = rte_zmalloc("macvlan_data", num * sizeof(*mv_f), 0);
7215 PMD_DRV_LOG(ERR, "failed to allocate memory");
7216 return I40E_ERR_NO_MEMORY;
7220 if (vsi->vlan_num == 0) {
7221 TAILQ_FOREACH(f, &vsi->mac_list, next) {
7222 rte_memcpy(&mv_f[i].macaddr,
7223 &f->mac_info.mac_addr, ETH_ADDR_LEN);
7224 mv_f[i].filter_type = f->mac_info.filter_type;
7225 mv_f[i].vlan_id = 0;
7229 TAILQ_FOREACH(f, &vsi->mac_list, next) {
7230 ret = i40e_find_all_vlan_for_mac(vsi,&mv_f[i],
7231 vsi->vlan_num, &f->mac_info.mac_addr);
7232 if (ret != I40E_SUCCESS)
7234 for (j = i; j < i + vsi->vlan_num; j++)
7235 mv_f[j].filter_type = f->mac_info.filter_type;
7240 ret = i40e_remove_macvlan_filters(vsi, mv_f, num);
7248 i40e_vsi_add_vlan(struct i40e_vsi *vsi, uint16_t vlan)
7250 struct i40e_macvlan_filter *mv_f;
7252 int ret = I40E_SUCCESS;
7254 if (!vsi || vlan > RTE_ETHER_MAX_VLAN_ID)
7255 return I40E_ERR_PARAM;
7257 /* If it's already set, just return */
7258 if (i40e_find_vlan_filter(vsi,vlan))
7259 return I40E_SUCCESS;
7261 mac_num = vsi->mac_num;
7264 PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
7265 return I40E_ERR_PARAM;
7268 mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
7271 PMD_DRV_LOG(ERR, "failed to allocate memory");
7272 return I40E_ERR_NO_MEMORY;
7275 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
7277 if (ret != I40E_SUCCESS)
7280 ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
7282 if (ret != I40E_SUCCESS)
7285 i40e_set_vlan_filter(vsi, vlan, 1);
7295 i40e_vsi_delete_vlan(struct i40e_vsi *vsi, uint16_t vlan)
7297 struct i40e_macvlan_filter *mv_f;
7299 int ret = I40E_SUCCESS;
7302 * Vlan 0 is the generic filter for untagged packets
7303 * and can't be removed.
7305 if (!vsi || vlan == 0 || vlan > RTE_ETHER_MAX_VLAN_ID)
7306 return I40E_ERR_PARAM;
7308 /* If can't find it, just return */
7309 if (!i40e_find_vlan_filter(vsi, vlan))
7310 return I40E_ERR_PARAM;
7312 mac_num = vsi->mac_num;
7315 PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
7316 return I40E_ERR_PARAM;
7319 mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
7322 PMD_DRV_LOG(ERR, "failed to allocate memory");
7323 return I40E_ERR_NO_MEMORY;
7326 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
7328 if (ret != I40E_SUCCESS)
7331 ret = i40e_remove_macvlan_filters(vsi, mv_f, mac_num);
7333 if (ret != I40E_SUCCESS)
7336 /* This is last vlan to remove, replace all mac filter with vlan 0 */
7337 if (vsi->vlan_num == 1) {
7338 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, 0);
7339 if (ret != I40E_SUCCESS)
7342 ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
7343 if (ret != I40E_SUCCESS)
7347 i40e_set_vlan_filter(vsi, vlan, 0);
7357 i40e_vsi_add_mac(struct i40e_vsi *vsi, struct i40e_mac_filter_info *mac_filter)
7359 struct i40e_mac_filter *f;
7360 struct i40e_macvlan_filter *mv_f;
7361 int i, vlan_num = 0;
7362 int ret = I40E_SUCCESS;
7364 /* If it's add and we've config it, return */
7365 f = i40e_find_mac_filter(vsi, &mac_filter->mac_addr);
7367 return I40E_SUCCESS;
7368 if ((mac_filter->filter_type == RTE_MACVLAN_PERFECT_MATCH) ||
7369 (mac_filter->filter_type == RTE_MACVLAN_HASH_MATCH)) {
7372 * If vlan_num is 0, that's the first time to add mac,
7373 * set mask for vlan_id 0.
7375 if (vsi->vlan_num == 0) {
7376 i40e_set_vlan_filter(vsi, 0, 1);
7379 vlan_num = vsi->vlan_num;
7380 } else if ((mac_filter->filter_type == RTE_MAC_PERFECT_MATCH) ||
7381 (mac_filter->filter_type == RTE_MAC_HASH_MATCH))
7384 mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
7386 PMD_DRV_LOG(ERR, "failed to allocate memory");
7387 return I40E_ERR_NO_MEMORY;
7390 for (i = 0; i < vlan_num; i++) {
7391 mv_f[i].filter_type = mac_filter->filter_type;
7392 rte_memcpy(&mv_f[i].macaddr, &mac_filter->mac_addr,
7396 if (mac_filter->filter_type == RTE_MACVLAN_PERFECT_MATCH ||
7397 mac_filter->filter_type == RTE_MACVLAN_HASH_MATCH) {
7398 ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
7399 &mac_filter->mac_addr);
7400 if (ret != I40E_SUCCESS)
7404 ret = i40e_add_macvlan_filters(vsi, mv_f, vlan_num);
7405 if (ret != I40E_SUCCESS)
7408 /* Add the mac addr into mac list */
7409 f = rte_zmalloc("macv_filter", sizeof(*f), 0);
7411 PMD_DRV_LOG(ERR, "failed to allocate memory");
7412 ret = I40E_ERR_NO_MEMORY;
7415 rte_memcpy(&f->mac_info.mac_addr, &mac_filter->mac_addr,
7417 f->mac_info.filter_type = mac_filter->filter_type;
7418 TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
7429 i40e_vsi_delete_mac(struct i40e_vsi *vsi, struct rte_ether_addr *addr)
7431 struct i40e_mac_filter *f;
7432 struct i40e_macvlan_filter *mv_f;
7434 enum rte_mac_filter_type filter_type;
7435 int ret = I40E_SUCCESS;
7437 /* Can't find it, return an error */
7438 f = i40e_find_mac_filter(vsi, addr);
7440 return I40E_ERR_PARAM;
7442 vlan_num = vsi->vlan_num;
7443 filter_type = f->mac_info.filter_type;
7444 if (filter_type == RTE_MACVLAN_PERFECT_MATCH ||
7445 filter_type == RTE_MACVLAN_HASH_MATCH) {
7446 if (vlan_num == 0) {
7447 PMD_DRV_LOG(ERR, "VLAN number shouldn't be 0");
7448 return I40E_ERR_PARAM;
7450 } else if (filter_type == RTE_MAC_PERFECT_MATCH ||
7451 filter_type == RTE_MAC_HASH_MATCH)
7454 mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
7456 PMD_DRV_LOG(ERR, "failed to allocate memory");
7457 return I40E_ERR_NO_MEMORY;
7460 for (i = 0; i < vlan_num; i++) {
7461 mv_f[i].filter_type = filter_type;
7462 rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
7465 if (filter_type == RTE_MACVLAN_PERFECT_MATCH ||
7466 filter_type == RTE_MACVLAN_HASH_MATCH) {
7467 ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num, addr);
7468 if (ret != I40E_SUCCESS)
7472 ret = i40e_remove_macvlan_filters(vsi, mv_f, vlan_num);
7473 if (ret != I40E_SUCCESS)
7476 /* Remove the mac addr into mac list */
7477 TAILQ_REMOVE(&vsi->mac_list, f, next);
7487 /* Configure hash enable flags for RSS */
7489 i40e_config_hena(const struct i40e_adapter *adapter, uint64_t flags)
7497 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < I40E_FLOW_TYPE_MAX; i++) {
7498 if (flags & (1ULL << i))
7499 hena |= adapter->pctypes_tbl[i];
7505 /* Parse the hash enable flags */
7507 i40e_parse_hena(const struct i40e_adapter *adapter, uint64_t flags)
7509 uint64_t rss_hf = 0;
7515 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < I40E_FLOW_TYPE_MAX; i++) {
7516 if (flags & adapter->pctypes_tbl[i])
7517 rss_hf |= (1ULL << i);
7524 i40e_pf_disable_rss(struct i40e_pf *pf)
7526 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7528 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
7529 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
7530 I40E_WRITE_FLUSH(hw);
7534 i40e_set_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t key_len)
7536 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
7537 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7538 uint16_t key_idx = (vsi->type == I40E_VSI_SRIOV) ?
7539 I40E_VFQF_HKEY_MAX_INDEX :
7540 I40E_PFQF_HKEY_MAX_INDEX;
7543 if (!key || key_len == 0) {
7544 PMD_DRV_LOG(DEBUG, "No key to be configured");
7546 } else if (key_len != (key_idx + 1) *
7548 PMD_DRV_LOG(ERR, "Invalid key length %u", key_len);
7552 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
7553 struct i40e_aqc_get_set_rss_key_data *key_dw =
7554 (struct i40e_aqc_get_set_rss_key_data *)key;
7556 ret = i40e_aq_set_rss_key(hw, vsi->vsi_id, key_dw);
7558 PMD_INIT_LOG(ERR, "Failed to configure RSS key via AQ");
7560 uint32_t *hash_key = (uint32_t *)key;
7563 if (vsi->type == I40E_VSI_SRIOV) {
7564 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
7567 I40E_VFQF_HKEY1(i, vsi->user_param),
7571 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
7572 I40E_WRITE_REG(hw, I40E_PFQF_HKEY(i),
7575 I40E_WRITE_FLUSH(hw);
7582 i40e_get_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t *key_len)
7584 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
7585 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7589 if (!key || !key_len)
7592 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
7593 ret = i40e_aq_get_rss_key(hw, vsi->vsi_id,
7594 (struct i40e_aqc_get_set_rss_key_data *)key);
7596 PMD_INIT_LOG(ERR, "Failed to get RSS key via AQ");
7600 uint32_t *key_dw = (uint32_t *)key;
7603 if (vsi->type == I40E_VSI_SRIOV) {
7604 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++) {
7605 reg = I40E_VFQF_HKEY1(i, vsi->user_param);
7606 key_dw[i] = i40e_read_rx_ctl(hw, reg);
7608 *key_len = (I40E_VFQF_HKEY_MAX_INDEX + 1) *
7611 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
7612 reg = I40E_PFQF_HKEY(i);
7613 key_dw[i] = i40e_read_rx_ctl(hw, reg);
7615 *key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
7623 i40e_hw_rss_hash_set(struct i40e_pf *pf, struct rte_eth_rss_conf *rss_conf)
7625 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7629 ret = i40e_set_rss_key(pf->main_vsi, rss_conf->rss_key,
7630 rss_conf->rss_key_len);
7634 hena = i40e_config_hena(pf->adapter, rss_conf->rss_hf);
7635 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
7636 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
7637 I40E_WRITE_FLUSH(hw);
7643 i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
7644 struct rte_eth_rss_conf *rss_conf)
7646 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7647 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7648 uint64_t rss_hf = rss_conf->rss_hf & pf->adapter->flow_types_mask;
7651 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
7652 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
7654 if (!(hena & pf->adapter->pctypes_mask)) { /* RSS disabled */
7655 if (rss_hf != 0) /* Enable RSS */
7657 return 0; /* Nothing to do */
7660 if (rss_hf == 0) /* Disable RSS */
7663 return i40e_hw_rss_hash_set(pf, rss_conf);
7667 i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
7668 struct rte_eth_rss_conf *rss_conf)
7670 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7671 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7678 ret = i40e_get_rss_key(pf->main_vsi, rss_conf->rss_key,
7679 &rss_conf->rss_key_len);
7683 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
7684 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
7685 rss_conf->rss_hf = i40e_parse_hena(pf->adapter, hena);
7691 i40e_dev_get_filter_type(uint16_t filter_type, uint16_t *flag)
7693 switch (filter_type) {
7694 case RTE_TUNNEL_FILTER_IMAC_IVLAN:
7695 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
7697 case RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID:
7698 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
7700 case RTE_TUNNEL_FILTER_IMAC_TENID:
7701 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID;
7703 case RTE_TUNNEL_FILTER_OMAC_TENID_IMAC:
7704 *flag = I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC;
7706 case ETH_TUNNEL_FILTER_IMAC:
7707 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
7709 case ETH_TUNNEL_FILTER_OIP:
7710 *flag = I40E_AQC_ADD_CLOUD_FILTER_OIP;
7712 case ETH_TUNNEL_FILTER_IIP:
7713 *flag = I40E_AQC_ADD_CLOUD_FILTER_IIP;
7716 PMD_DRV_LOG(ERR, "invalid tunnel filter type");
7723 /* Convert tunnel filter structure */
7725 i40e_tunnel_filter_convert(
7726 struct i40e_aqc_cloud_filters_element_bb *cld_filter,
7727 struct i40e_tunnel_filter *tunnel_filter)
7729 rte_ether_addr_copy((struct rte_ether_addr *)
7730 &cld_filter->element.outer_mac,
7731 (struct rte_ether_addr *)&tunnel_filter->input.outer_mac);
7732 rte_ether_addr_copy((struct rte_ether_addr *)
7733 &cld_filter->element.inner_mac,
7734 (struct rte_ether_addr *)&tunnel_filter->input.inner_mac);
7735 tunnel_filter->input.inner_vlan = cld_filter->element.inner_vlan;
7736 if ((rte_le_to_cpu_16(cld_filter->element.flags) &
7737 I40E_AQC_ADD_CLOUD_FLAGS_IPV6) ==
7738 I40E_AQC_ADD_CLOUD_FLAGS_IPV6)
7739 tunnel_filter->input.ip_type = I40E_TUNNEL_IPTYPE_IPV6;
7741 tunnel_filter->input.ip_type = I40E_TUNNEL_IPTYPE_IPV4;
7742 tunnel_filter->input.flags = cld_filter->element.flags;
7743 tunnel_filter->input.tenant_id = cld_filter->element.tenant_id;
7744 tunnel_filter->queue = cld_filter->element.queue_number;
7745 rte_memcpy(tunnel_filter->input.general_fields,
7746 cld_filter->general_fields,
7747 sizeof(cld_filter->general_fields));
7752 /* Check if there exists the tunnel filter */
7753 struct i40e_tunnel_filter *
7754 i40e_sw_tunnel_filter_lookup(struct i40e_tunnel_rule *tunnel_rule,
7755 const struct i40e_tunnel_filter_input *input)
7759 ret = rte_hash_lookup(tunnel_rule->hash_table, (const void *)input);
7763 return tunnel_rule->hash_map[ret];
7766 /* Add a tunnel filter into the SW list */
7768 i40e_sw_tunnel_filter_insert(struct i40e_pf *pf,
7769 struct i40e_tunnel_filter *tunnel_filter)
7771 struct i40e_tunnel_rule *rule = &pf->tunnel;
7774 ret = rte_hash_add_key(rule->hash_table, &tunnel_filter->input);
7777 "Failed to insert tunnel filter to hash table %d!",
7781 rule->hash_map[ret] = tunnel_filter;
7783 TAILQ_INSERT_TAIL(&rule->tunnel_list, tunnel_filter, rules);
7788 /* Delete a tunnel filter from the SW list */
7790 i40e_sw_tunnel_filter_del(struct i40e_pf *pf,
7791 struct i40e_tunnel_filter_input *input)
7793 struct i40e_tunnel_rule *rule = &pf->tunnel;
7794 struct i40e_tunnel_filter *tunnel_filter;
7797 ret = rte_hash_del_key(rule->hash_table, input);
7800 "Failed to delete tunnel filter to hash table %d!",
7804 tunnel_filter = rule->hash_map[ret];
7805 rule->hash_map[ret] = NULL;
7807 TAILQ_REMOVE(&rule->tunnel_list, tunnel_filter, rules);
7808 rte_free(tunnel_filter);
7814 i40e_dev_tunnel_filter_set(struct i40e_pf *pf,
7815 struct rte_eth_tunnel_filter_conf *tunnel_filter,
7819 uint32_t ipv4_addr, ipv4_addr_le;
7820 uint8_t i, tun_type = 0;
7821 /* internal varialbe to convert ipv6 byte order */
7822 uint32_t convert_ipv6[4];
7824 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7825 struct i40e_vsi *vsi = pf->main_vsi;
7826 struct i40e_aqc_cloud_filters_element_bb *cld_filter;
7827 struct i40e_aqc_cloud_filters_element_bb *pfilter;
7828 struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
7829 struct i40e_tunnel_filter *tunnel, *node;
7830 struct i40e_tunnel_filter check_filter; /* Check if filter exists */
7832 cld_filter = rte_zmalloc("tunnel_filter",
7833 sizeof(struct i40e_aqc_add_rm_cloud_filt_elem_ext),
7836 if (NULL == cld_filter) {
7837 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
7840 pfilter = cld_filter;
7842 rte_ether_addr_copy(&tunnel_filter->outer_mac,
7843 (struct rte_ether_addr *)&pfilter->element.outer_mac);
7844 rte_ether_addr_copy(&tunnel_filter->inner_mac,
7845 (struct rte_ether_addr *)&pfilter->element.inner_mac);
7847 pfilter->element.inner_vlan =
7848 rte_cpu_to_le_16(tunnel_filter->inner_vlan);
7849 if (tunnel_filter->ip_type == RTE_TUNNEL_IPTYPE_IPV4) {
7850 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV4;
7851 ipv4_addr = rte_be_to_cpu_32(tunnel_filter->ip_addr.ipv4_addr);
7852 ipv4_addr_le = rte_cpu_to_le_32(ipv4_addr);
7853 rte_memcpy(&pfilter->element.ipaddr.v4.data,
7855 sizeof(pfilter->element.ipaddr.v4.data));
7857 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV6;
7858 for (i = 0; i < 4; i++) {
7860 rte_cpu_to_le_32(rte_be_to_cpu_32(tunnel_filter->ip_addr.ipv6_addr[i]));
7862 rte_memcpy(&pfilter->element.ipaddr.v6.data,
7864 sizeof(pfilter->element.ipaddr.v6.data));
7867 /* check tunneled type */
7868 switch (tunnel_filter->tunnel_type) {
7869 case RTE_TUNNEL_TYPE_VXLAN:
7870 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_VXLAN;
7872 case RTE_TUNNEL_TYPE_NVGRE:
7873 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_NVGRE_OMAC;
7875 case RTE_TUNNEL_TYPE_IP_IN_GRE:
7876 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_IP;
7878 case RTE_TUNNEL_TYPE_VXLAN_GPE:
7879 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_VXLAN_GPE;
7882 /* Other tunnel types is not supported. */
7883 PMD_DRV_LOG(ERR, "tunnel type is not supported.");
7884 rte_free(cld_filter);
7888 val = i40e_dev_get_filter_type(tunnel_filter->filter_type,
7889 &pfilter->element.flags);
7891 rte_free(cld_filter);
7895 pfilter->element.flags |= rte_cpu_to_le_16(
7896 I40E_AQC_ADD_CLOUD_FLAGS_TO_QUEUE |
7897 ip_type | (tun_type << I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT));
7898 pfilter->element.tenant_id = rte_cpu_to_le_32(tunnel_filter->tenant_id);
7899 pfilter->element.queue_number =
7900 rte_cpu_to_le_16(tunnel_filter->queue_id);
7902 /* Check if there is the filter in SW list */
7903 memset(&check_filter, 0, sizeof(check_filter));
7904 i40e_tunnel_filter_convert(cld_filter, &check_filter);
7905 node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
7907 PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
7908 rte_free(cld_filter);
7912 if (!add && !node) {
7913 PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
7914 rte_free(cld_filter);
7919 ret = i40e_aq_add_cloud_filters(hw,
7920 vsi->seid, &cld_filter->element, 1);
7922 PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
7923 rte_free(cld_filter);
7926 tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
7927 if (tunnel == NULL) {
7928 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
7929 rte_free(cld_filter);
7933 rte_memcpy(tunnel, &check_filter, sizeof(check_filter));
7934 ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
7938 ret = i40e_aq_rem_cloud_filters(hw, vsi->seid,
7939 &cld_filter->element, 1);
7941 PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
7942 rte_free(cld_filter);
7945 ret = i40e_sw_tunnel_filter_del(pf, &node->input);
7948 rte_free(cld_filter);
7952 #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_TR_WORD0 0x48
7953 #define I40E_TR_VXLAN_GRE_KEY_MASK 0x4
7954 #define I40E_TR_GENEVE_KEY_MASK 0x8
7955 #define I40E_TR_GENERIC_UDP_TUNNEL_MASK 0x40
7956 #define I40E_TR_GRE_KEY_MASK 0x400
7957 #define I40E_TR_GRE_KEY_WITH_XSUM_MASK 0x800
7958 #define I40E_TR_GRE_NO_KEY_MASK 0x8000
7961 i40e_status_code i40e_replace_mpls_l1_filter(struct i40e_pf *pf)
7963 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
7964 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
7965 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7966 struct rte_eth_dev *dev = ((struct i40e_adapter *)hw->back)->eth_dev;
7967 enum i40e_status_code status = I40E_SUCCESS;
7969 if (pf->support_multi_driver) {
7970 PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
7971 return I40E_NOT_SUPPORTED;
7974 memset(&filter_replace, 0,
7975 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
7976 memset(&filter_replace_buf, 0,
7977 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
7979 /* create L1 filter */
7980 filter_replace.old_filter_type =
7981 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_IMAC;
7982 filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X11;
7983 filter_replace.tr_bit = 0;
7985 /* Prepare the buffer, 3 entries */
7986 filter_replace_buf.data[0] =
7987 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
7988 filter_replace_buf.data[0] |=
7989 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7990 filter_replace_buf.data[2] = 0xFF;
7991 filter_replace_buf.data[3] = 0xFF;
7992 filter_replace_buf.data[4] =
7993 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
7994 filter_replace_buf.data[4] |=
7995 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7996 filter_replace_buf.data[7] = 0xF0;
7997 filter_replace_buf.data[8]
7998 = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_TR_WORD0;
7999 filter_replace_buf.data[8] |=
8000 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8001 filter_replace_buf.data[10] = I40E_TR_VXLAN_GRE_KEY_MASK |
8002 I40E_TR_GENEVE_KEY_MASK |
8003 I40E_TR_GENERIC_UDP_TUNNEL_MASK;
8004 filter_replace_buf.data[11] = (I40E_TR_GRE_KEY_MASK |
8005 I40E_TR_GRE_KEY_WITH_XSUM_MASK |
8006 I40E_TR_GRE_NO_KEY_MASK) >> 8;
8008 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8009 &filter_replace_buf);
8010 if (!status && (filter_replace.old_filter_type !=
8011 filter_replace.new_filter_type))
8012 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8013 " original: 0x%x, new: 0x%x",
8015 filter_replace.old_filter_type,
8016 filter_replace.new_filter_type);
8022 i40e_status_code i40e_replace_mpls_cloud_filter(struct i40e_pf *pf)
8024 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8025 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8026 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8027 struct rte_eth_dev *dev = ((struct i40e_adapter *)hw->back)->eth_dev;
8028 enum i40e_status_code status = I40E_SUCCESS;
8030 if (pf->support_multi_driver) {
8031 PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8032 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));
8040 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER |
8041 I40E_AQC_MIRROR_CLOUD_FILTER;
8042 filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IIP;
8043 filter_replace.new_filter_type =
8044 I40E_AQC_ADD_CLOUD_FILTER_0X11;
8045 /* Prepare the buffer, 2 entries */
8046 filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8047 filter_replace_buf.data[0] |=
8048 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8049 filter_replace_buf.data[4] = I40E_AQC_ADD_L1_FILTER_0X11;
8050 filter_replace_buf.data[4] |=
8051 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8052 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8053 &filter_replace_buf);
8056 if (filter_replace.old_filter_type !=
8057 filter_replace.new_filter_type)
8058 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8059 " original: 0x%x, new: 0x%x",
8061 filter_replace.old_filter_type,
8062 filter_replace.new_filter_type);
8065 memset(&filter_replace, 0,
8066 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8067 memset(&filter_replace_buf, 0,
8068 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8070 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER |
8071 I40E_AQC_MIRROR_CLOUD_FILTER;
8072 filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
8073 filter_replace.new_filter_type =
8074 I40E_AQC_ADD_CLOUD_FILTER_0X12;
8075 /* Prepare the buffer, 2 entries */
8076 filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8077 filter_replace_buf.data[0] |=
8078 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8079 filter_replace_buf.data[4] = I40E_AQC_ADD_L1_FILTER_0X11;
8080 filter_replace_buf.data[4] |=
8081 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8083 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8084 &filter_replace_buf);
8085 if (!status && (filter_replace.old_filter_type !=
8086 filter_replace.new_filter_type))
8087 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8088 " original: 0x%x, new: 0x%x",
8090 filter_replace.old_filter_type,
8091 filter_replace.new_filter_type);
8096 static enum i40e_status_code
8097 i40e_replace_gtp_l1_filter(struct i40e_pf *pf)
8099 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8100 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8101 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8102 struct rte_eth_dev *dev = ((struct i40e_adapter *)hw->back)->eth_dev;
8103 enum i40e_status_code status = I40E_SUCCESS;
8105 if (pf->support_multi_driver) {
8106 PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
8107 return I40E_NOT_SUPPORTED;
8111 memset(&filter_replace, 0,
8112 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8113 memset(&filter_replace_buf, 0,
8114 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8115 /* create L1 filter */
8116 filter_replace.old_filter_type =
8117 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_IMAC;
8118 filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X12;
8119 filter_replace.tr_bit = I40E_AQC_NEW_TR_22 |
8120 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8121 /* Prepare the buffer, 2 entries */
8122 filter_replace_buf.data[0] =
8123 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8124 filter_replace_buf.data[0] |=
8125 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8126 filter_replace_buf.data[2] = 0xFF;
8127 filter_replace_buf.data[3] = 0xFF;
8128 filter_replace_buf.data[4] =
8129 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8130 filter_replace_buf.data[4] |=
8131 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8132 filter_replace_buf.data[6] = 0xFF;
8133 filter_replace_buf.data[7] = 0xFF;
8134 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8135 &filter_replace_buf);
8138 if (filter_replace.old_filter_type !=
8139 filter_replace.new_filter_type)
8140 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8141 " original: 0x%x, new: 0x%x",
8143 filter_replace.old_filter_type,
8144 filter_replace.new_filter_type);
8147 memset(&filter_replace, 0,
8148 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8149 memset(&filter_replace_buf, 0,
8150 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8151 /* create L1 filter */
8152 filter_replace.old_filter_type =
8153 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TUNNLE_KEY;
8154 filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X13;
8155 filter_replace.tr_bit = I40E_AQC_NEW_TR_21 |
8156 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8157 /* Prepare the buffer, 2 entries */
8158 filter_replace_buf.data[0] =
8159 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8160 filter_replace_buf.data[0] |=
8161 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8162 filter_replace_buf.data[2] = 0xFF;
8163 filter_replace_buf.data[3] = 0xFF;
8164 filter_replace_buf.data[4] =
8165 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8166 filter_replace_buf.data[4] |=
8167 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8168 filter_replace_buf.data[6] = 0xFF;
8169 filter_replace_buf.data[7] = 0xFF;
8171 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8172 &filter_replace_buf);
8173 if (!status && (filter_replace.old_filter_type !=
8174 filter_replace.new_filter_type))
8175 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8176 " original: 0x%x, new: 0x%x",
8178 filter_replace.old_filter_type,
8179 filter_replace.new_filter_type);
8185 i40e_status_code i40e_replace_gtp_cloud_filter(struct i40e_pf *pf)
8187 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8188 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8189 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8190 struct rte_eth_dev *dev = ((struct i40e_adapter *)hw->back)->eth_dev;
8191 enum i40e_status_code status = I40E_SUCCESS;
8193 if (pf->support_multi_driver) {
8194 PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8195 return I40E_NOT_SUPPORTED;
8199 memset(&filter_replace, 0,
8200 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8201 memset(&filter_replace_buf, 0,
8202 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8203 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8204 filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
8205 filter_replace.new_filter_type =
8206 I40E_AQC_ADD_CLOUD_FILTER_0X11;
8207 /* Prepare the buffer, 2 entries */
8208 filter_replace_buf.data[0] = I40E_AQC_ADD_L1_FILTER_0X12;
8209 filter_replace_buf.data[0] |=
8210 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8211 filter_replace_buf.data[4] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8212 filter_replace_buf.data[4] |=
8213 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8214 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8215 &filter_replace_buf);
8218 if (filter_replace.old_filter_type !=
8219 filter_replace.new_filter_type)
8220 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8221 " original: 0x%x, new: 0x%x",
8223 filter_replace.old_filter_type,
8224 filter_replace.new_filter_type);
8227 memset(&filter_replace, 0,
8228 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8229 memset(&filter_replace_buf, 0,
8230 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8231 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8232 filter_replace.old_filter_type =
8233 I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
8234 filter_replace.new_filter_type =
8235 I40E_AQC_ADD_CLOUD_FILTER_0X12;
8236 /* Prepare the buffer, 2 entries */
8237 filter_replace_buf.data[0] = I40E_AQC_ADD_L1_FILTER_0X13;
8238 filter_replace_buf.data[0] |=
8239 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8240 filter_replace_buf.data[4] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8241 filter_replace_buf.data[4] |=
8242 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8244 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8245 &filter_replace_buf);
8246 if (!status && (filter_replace.old_filter_type !=
8247 filter_replace.new_filter_type))
8248 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8249 " original: 0x%x, new: 0x%x",
8251 filter_replace.old_filter_type,
8252 filter_replace.new_filter_type);
8258 i40e_dev_consistent_tunnel_filter_set(struct i40e_pf *pf,
8259 struct i40e_tunnel_filter_conf *tunnel_filter,
8263 uint32_t ipv4_addr, ipv4_addr_le;
8264 uint8_t i, tun_type = 0;
8265 /* internal variable to convert ipv6 byte order */
8266 uint32_t convert_ipv6[4];
8268 struct i40e_pf_vf *vf = NULL;
8269 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8270 struct i40e_vsi *vsi;
8271 struct i40e_aqc_cloud_filters_element_bb *cld_filter;
8272 struct i40e_aqc_cloud_filters_element_bb *pfilter;
8273 struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
8274 struct i40e_tunnel_filter *tunnel, *node;
8275 struct i40e_tunnel_filter check_filter; /* Check if filter exists */
8277 bool big_buffer = 0;
8279 cld_filter = rte_zmalloc("tunnel_filter",
8280 sizeof(struct i40e_aqc_add_rm_cloud_filt_elem_ext),
8283 if (cld_filter == NULL) {
8284 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
8287 pfilter = cld_filter;
8289 rte_ether_addr_copy(&tunnel_filter->outer_mac,
8290 (struct rte_ether_addr *)&pfilter->element.outer_mac);
8291 rte_ether_addr_copy(&tunnel_filter->inner_mac,
8292 (struct rte_ether_addr *)&pfilter->element.inner_mac);
8294 pfilter->element.inner_vlan =
8295 rte_cpu_to_le_16(tunnel_filter->inner_vlan);
8296 if (tunnel_filter->ip_type == I40E_TUNNEL_IPTYPE_IPV4) {
8297 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV4;
8298 ipv4_addr = rte_be_to_cpu_32(tunnel_filter->ip_addr.ipv4_addr);
8299 ipv4_addr_le = rte_cpu_to_le_32(ipv4_addr);
8300 rte_memcpy(&pfilter->element.ipaddr.v4.data,
8302 sizeof(pfilter->element.ipaddr.v4.data));
8304 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV6;
8305 for (i = 0; i < 4; i++) {
8307 rte_cpu_to_le_32(rte_be_to_cpu_32(
8308 tunnel_filter->ip_addr.ipv6_addr[i]));
8310 rte_memcpy(&pfilter->element.ipaddr.v6.data,
8312 sizeof(pfilter->element.ipaddr.v6.data));
8315 /* check tunneled type */
8316 switch (tunnel_filter->tunnel_type) {
8317 case I40E_TUNNEL_TYPE_VXLAN:
8318 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_VXLAN;
8320 case I40E_TUNNEL_TYPE_NVGRE:
8321 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_NVGRE_OMAC;
8323 case I40E_TUNNEL_TYPE_IP_IN_GRE:
8324 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_IP;
8326 case I40E_TUNNEL_TYPE_MPLSoUDP:
8327 if (!pf->mpls_replace_flag) {
8328 i40e_replace_mpls_l1_filter(pf);
8329 i40e_replace_mpls_cloud_filter(pf);
8330 pf->mpls_replace_flag = 1;
8332 teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8333 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8335 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8336 (teid_le & 0xF) << 12;
8337 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8340 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_MPLSOUDP;
8342 case I40E_TUNNEL_TYPE_MPLSoGRE:
8343 if (!pf->mpls_replace_flag) {
8344 i40e_replace_mpls_l1_filter(pf);
8345 i40e_replace_mpls_cloud_filter(pf);
8346 pf->mpls_replace_flag = 1;
8348 teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8349 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8351 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8352 (teid_le & 0xF) << 12;
8353 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8356 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_MPLSOGRE;
8358 case I40E_TUNNEL_TYPE_GTPC:
8359 if (!pf->gtp_replace_flag) {
8360 i40e_replace_gtp_l1_filter(pf);
8361 i40e_replace_gtp_cloud_filter(pf);
8362 pf->gtp_replace_flag = 1;
8364 teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8365 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD0] =
8366 (teid_le >> 16) & 0xFFFF;
8367 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD1] =
8369 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD2] =
8373 case I40E_TUNNEL_TYPE_GTPU:
8374 if (!pf->gtp_replace_flag) {
8375 i40e_replace_gtp_l1_filter(pf);
8376 i40e_replace_gtp_cloud_filter(pf);
8377 pf->gtp_replace_flag = 1;
8379 teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8380 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD0] =
8381 (teid_le >> 16) & 0xFFFF;
8382 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD1] =
8384 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD2] =
8388 case I40E_TUNNEL_TYPE_QINQ:
8389 if (!pf->qinq_replace_flag) {
8390 ret = i40e_cloud_filter_qinq_create(pf);
8393 "QinQ tunnel filter already created.");
8394 pf->qinq_replace_flag = 1;
8396 /* Add in the General fields the values of
8397 * the Outer and Inner VLAN
8398 * Big Buffer should be set, see changes in
8399 * i40e_aq_add_cloud_filters
8401 pfilter->general_fields[0] = tunnel_filter->inner_vlan;
8402 pfilter->general_fields[1] = tunnel_filter->outer_vlan;
8406 /* Other tunnel types is not supported. */
8407 PMD_DRV_LOG(ERR, "tunnel type is not supported.");
8408 rte_free(cld_filter);
8412 if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_MPLSoUDP)
8413 pfilter->element.flags =
8414 I40E_AQC_ADD_CLOUD_FILTER_0X11;
8415 else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_MPLSoGRE)
8416 pfilter->element.flags =
8417 I40E_AQC_ADD_CLOUD_FILTER_0X12;
8418 else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_GTPC)
8419 pfilter->element.flags =
8420 I40E_AQC_ADD_CLOUD_FILTER_0X11;
8421 else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_GTPU)
8422 pfilter->element.flags =
8423 I40E_AQC_ADD_CLOUD_FILTER_0X12;
8424 else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_QINQ)
8425 pfilter->element.flags |=
8426 I40E_AQC_ADD_CLOUD_FILTER_0X10;
8428 val = i40e_dev_get_filter_type(tunnel_filter->filter_type,
8429 &pfilter->element.flags);
8431 rte_free(cld_filter);
8436 pfilter->element.flags |= rte_cpu_to_le_16(
8437 I40E_AQC_ADD_CLOUD_FLAGS_TO_QUEUE |
8438 ip_type | (tun_type << I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT));
8439 pfilter->element.tenant_id = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8440 pfilter->element.queue_number =
8441 rte_cpu_to_le_16(tunnel_filter->queue_id);
8443 if (!tunnel_filter->is_to_vf)
8446 if (tunnel_filter->vf_id >= pf->vf_num) {
8447 PMD_DRV_LOG(ERR, "Invalid argument.");
8448 rte_free(cld_filter);
8451 vf = &pf->vfs[tunnel_filter->vf_id];
8455 /* Check if there is the filter in SW list */
8456 memset(&check_filter, 0, sizeof(check_filter));
8457 i40e_tunnel_filter_convert(cld_filter, &check_filter);
8458 check_filter.is_to_vf = tunnel_filter->is_to_vf;
8459 check_filter.vf_id = tunnel_filter->vf_id;
8460 node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
8462 PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
8463 rte_free(cld_filter);
8467 if (!add && !node) {
8468 PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
8469 rte_free(cld_filter);
8475 ret = i40e_aq_add_cloud_filters_bb(hw,
8476 vsi->seid, cld_filter, 1);
8478 ret = i40e_aq_add_cloud_filters(hw,
8479 vsi->seid, &cld_filter->element, 1);
8481 PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
8482 rte_free(cld_filter);
8485 tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
8486 if (tunnel == NULL) {
8487 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
8488 rte_free(cld_filter);
8492 rte_memcpy(tunnel, &check_filter, sizeof(check_filter));
8493 ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
8498 ret = i40e_aq_rem_cloud_filters_bb(
8499 hw, vsi->seid, cld_filter, 1);
8501 ret = i40e_aq_rem_cloud_filters(hw, vsi->seid,
8502 &cld_filter->element, 1);
8504 PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
8505 rte_free(cld_filter);
8508 ret = i40e_sw_tunnel_filter_del(pf, &node->input);
8511 rte_free(cld_filter);
8516 i40e_get_vxlan_port_idx(struct i40e_pf *pf, uint16_t port)
8520 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
8521 if (pf->vxlan_ports[i] == port)
8529 i40e_add_vxlan_port(struct i40e_pf *pf, uint16_t port, int udp_type)
8532 uint8_t filter_idx = 0;
8533 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8535 idx = i40e_get_vxlan_port_idx(pf, port);
8537 /* Check if port already exists */
8539 PMD_DRV_LOG(ERR, "Port %d already offloaded", port);
8543 /* Now check if there is space to add the new port */
8544 idx = i40e_get_vxlan_port_idx(pf, 0);
8547 "Maximum number of UDP ports reached, not adding port %d",
8552 ret = i40e_aq_add_udp_tunnel(hw, port, udp_type,
8555 PMD_DRV_LOG(ERR, "Failed to add VXLAN UDP port %d", port);
8559 PMD_DRV_LOG(INFO, "Added port %d with AQ command with index %d",
8562 /* New port: add it and mark its index in the bitmap */
8563 pf->vxlan_ports[idx] = port;
8564 pf->vxlan_bitmap |= (1 << idx);
8566 if (!(pf->flags & I40E_FLAG_VXLAN))
8567 pf->flags |= I40E_FLAG_VXLAN;
8573 i40e_del_vxlan_port(struct i40e_pf *pf, uint16_t port)
8576 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8578 if (!(pf->flags & I40E_FLAG_VXLAN)) {
8579 PMD_DRV_LOG(ERR, "VXLAN UDP port was not configured.");
8583 idx = i40e_get_vxlan_port_idx(pf, port);
8586 PMD_DRV_LOG(ERR, "Port %d doesn't exist", port);
8590 if (i40e_aq_del_udp_tunnel(hw, idx, NULL) < 0) {
8591 PMD_DRV_LOG(ERR, "Failed to delete VXLAN UDP port %d", port);
8595 PMD_DRV_LOG(INFO, "Deleted port %d with AQ command with index %d",
8598 pf->vxlan_ports[idx] = 0;
8599 pf->vxlan_bitmap &= ~(1 << idx);
8601 if (!pf->vxlan_bitmap)
8602 pf->flags &= ~I40E_FLAG_VXLAN;
8607 /* Add UDP tunneling port */
8609 i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
8610 struct rte_eth_udp_tunnel *udp_tunnel)
8613 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8615 if (udp_tunnel == NULL)
8618 switch (udp_tunnel->prot_type) {
8619 case RTE_TUNNEL_TYPE_VXLAN:
8620 ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port,
8621 I40E_AQC_TUNNEL_TYPE_VXLAN);
8623 case RTE_TUNNEL_TYPE_VXLAN_GPE:
8624 ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port,
8625 I40E_AQC_TUNNEL_TYPE_VXLAN_GPE);
8627 case RTE_TUNNEL_TYPE_GENEVE:
8628 case RTE_TUNNEL_TYPE_TEREDO:
8629 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8634 PMD_DRV_LOG(ERR, "Invalid tunnel type");
8642 /* Remove UDP tunneling port */
8644 i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
8645 struct rte_eth_udp_tunnel *udp_tunnel)
8648 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8650 if (udp_tunnel == NULL)
8653 switch (udp_tunnel->prot_type) {
8654 case RTE_TUNNEL_TYPE_VXLAN:
8655 case RTE_TUNNEL_TYPE_VXLAN_GPE:
8656 ret = i40e_del_vxlan_port(pf, udp_tunnel->udp_port);
8658 case RTE_TUNNEL_TYPE_GENEVE:
8659 case RTE_TUNNEL_TYPE_TEREDO:
8660 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8664 PMD_DRV_LOG(ERR, "Invalid tunnel type");
8672 /* Calculate the maximum number of contiguous PF queues that are configured */
8674 i40e_pf_calc_configured_queues_num(struct i40e_pf *pf)
8676 struct rte_eth_dev_data *data = pf->dev_data;
8678 struct i40e_rx_queue *rxq;
8681 for (i = 0; i < pf->lan_nb_qps; i++) {
8682 rxq = data->rx_queues[i];
8683 if (rxq && rxq->q_set)
8694 i40e_pf_config_rss(struct i40e_pf *pf)
8696 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8697 struct rte_eth_rss_conf rss_conf;
8698 uint32_t i, lut = 0;
8702 * If both VMDQ and RSS enabled, not all of PF queues are configured.
8703 * It's necessary to calculate the actual PF queues that are configured.
8705 if (pf->dev_data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG)
8706 num = i40e_pf_calc_configured_queues_num(pf);
8708 num = pf->dev_data->nb_rx_queues;
8710 num = RTE_MIN(num, I40E_MAX_Q_PER_TC);
8711 PMD_INIT_LOG(INFO, "Max of contiguous %u PF queues are configured",
8716 "No PF queues are configured to enable RSS for port %u",
8717 pf->dev_data->port_id);
8721 if (pf->adapter->rss_reta_updated == 0) {
8722 for (i = 0, j = 0; i < hw->func_caps.rss_table_size; i++, j++) {
8725 lut = (lut << 8) | (j & ((0x1 <<
8726 hw->func_caps.rss_table_entry_width) - 1));
8728 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i >> 2),
8733 rss_conf = pf->dev_data->dev_conf.rx_adv_conf.rss_conf;
8734 if ((rss_conf.rss_hf & pf->adapter->flow_types_mask) == 0) {
8735 i40e_pf_disable_rss(pf);
8738 if (rss_conf.rss_key == NULL || rss_conf.rss_key_len <
8739 (I40E_PFQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t)) {
8740 /* Random default keys */
8741 static uint32_t rss_key_default[] = {0x6b793944,
8742 0x23504cb5, 0x5bea75b6, 0x309f4f12, 0x3dc0a2b8,
8743 0x024ddcdf, 0x339b8ca0, 0x4c4af64a, 0x34fac605,
8744 0x55d85839, 0x3a58997d, 0x2ec938e1, 0x66031581};
8746 rss_conf.rss_key = (uint8_t *)rss_key_default;
8747 rss_conf.rss_key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
8751 return i40e_hw_rss_hash_set(pf, &rss_conf);
8755 i40e_tunnel_filter_param_check(struct i40e_pf *pf,
8756 struct rte_eth_tunnel_filter_conf *filter)
8758 if (pf == NULL || filter == NULL) {
8759 PMD_DRV_LOG(ERR, "Invalid parameter");
8763 if (filter->queue_id >= pf->dev_data->nb_rx_queues) {
8764 PMD_DRV_LOG(ERR, "Invalid queue ID");
8768 if (filter->inner_vlan > RTE_ETHER_MAX_VLAN_ID) {
8769 PMD_DRV_LOG(ERR, "Invalid inner VLAN ID");
8773 if ((filter->filter_type & ETH_TUNNEL_FILTER_OMAC) &&
8774 (rte_is_zero_ether_addr(&filter->outer_mac))) {
8775 PMD_DRV_LOG(ERR, "Cannot add NULL outer MAC address");
8779 if ((filter->filter_type & ETH_TUNNEL_FILTER_IMAC) &&
8780 (rte_is_zero_ether_addr(&filter->inner_mac))) {
8781 PMD_DRV_LOG(ERR, "Cannot add NULL inner MAC address");
8788 #define I40E_GL_PRS_FVBM_MSK_ENA 0x80000000
8789 #define I40E_GL_PRS_FVBM(_i) (0x00269760 + ((_i) * 4))
8791 i40e_dev_set_gre_key_len(struct i40e_hw *hw, uint8_t len)
8793 struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
8797 if (pf->support_multi_driver) {
8798 PMD_DRV_LOG(ERR, "GRE key length configuration is unsupported");
8802 val = I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2));
8803 PMD_DRV_LOG(DEBUG, "Read original GL_PRS_FVBM with 0x%08x", val);
8806 reg = val | I40E_GL_PRS_FVBM_MSK_ENA;
8807 } else if (len == 4) {
8808 reg = val & ~I40E_GL_PRS_FVBM_MSK_ENA;
8810 PMD_DRV_LOG(ERR, "Unsupported GRE key length of %u", len);
8815 ret = i40e_aq_debug_write_global_register(hw,
8816 I40E_GL_PRS_FVBM(2),
8820 PMD_DRV_LOG(DEBUG, "Global register 0x%08x is changed "
8821 "with value 0x%08x",
8822 I40E_GL_PRS_FVBM(2), reg);
8826 PMD_DRV_LOG(DEBUG, "Read modified GL_PRS_FVBM with 0x%08x",
8827 I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2)));
8833 i40e_dev_global_config_set(struct i40e_hw *hw, struct rte_eth_global_cfg *cfg)
8840 switch (cfg->cfg_type) {
8841 case RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN:
8842 ret = i40e_dev_set_gre_key_len(hw, cfg->cfg.gre_key_len);
8845 PMD_DRV_LOG(ERR, "Unknown config type %u", cfg->cfg_type);
8853 i40e_filter_ctrl_global_config(struct rte_eth_dev *dev,
8854 enum rte_filter_op filter_op,
8857 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8858 int ret = I40E_ERR_PARAM;
8860 switch (filter_op) {
8861 case RTE_ETH_FILTER_SET:
8862 ret = i40e_dev_global_config_set(hw,
8863 (struct rte_eth_global_cfg *)arg);
8866 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
8874 i40e_tunnel_filter_handle(struct rte_eth_dev *dev,
8875 enum rte_filter_op filter_op,
8878 struct rte_eth_tunnel_filter_conf *filter;
8879 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8880 int ret = I40E_SUCCESS;
8882 filter = (struct rte_eth_tunnel_filter_conf *)(arg);
8884 if (i40e_tunnel_filter_param_check(pf, filter) < 0)
8885 return I40E_ERR_PARAM;
8887 switch (filter_op) {
8888 case RTE_ETH_FILTER_NOP:
8889 if (!(pf->flags & I40E_FLAG_VXLAN))
8890 ret = I40E_NOT_SUPPORTED;
8892 case RTE_ETH_FILTER_ADD:
8893 ret = i40e_dev_tunnel_filter_set(pf, filter, 1);
8895 case RTE_ETH_FILTER_DELETE:
8896 ret = i40e_dev_tunnel_filter_set(pf, filter, 0);
8899 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
8900 ret = I40E_ERR_PARAM;
8908 i40e_pf_config_mq_rx(struct i40e_pf *pf)
8911 enum rte_eth_rx_mq_mode mq_mode = pf->dev_data->dev_conf.rxmode.mq_mode;
8914 if (mq_mode & ETH_MQ_RX_RSS_FLAG)
8915 ret = i40e_pf_config_rss(pf);
8917 i40e_pf_disable_rss(pf);
8922 /* Get the symmetric hash enable configurations per port */
8924 i40e_get_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t *enable)
8926 uint32_t reg = i40e_read_rx_ctl(hw, I40E_PRTQF_CTL_0);
8928 *enable = reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK ? 1 : 0;
8931 /* Set the symmetric hash enable configurations per port */
8933 i40e_set_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t enable)
8935 uint32_t reg = i40e_read_rx_ctl(hw, I40E_PRTQF_CTL_0);
8938 if (reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK) {
8940 "Symmetric hash has already been enabled");
8943 reg |= I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
8945 if (!(reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK)) {
8947 "Symmetric hash has already been disabled");
8950 reg &= ~I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
8952 i40e_write_rx_ctl(hw, I40E_PRTQF_CTL_0, reg);
8953 I40E_WRITE_FLUSH(hw);
8957 * Get global configurations of hash function type and symmetric hash enable
8958 * per flow type (pctype). Note that global configuration means it affects all
8959 * the ports on the same NIC.
8962 i40e_get_hash_filter_global_config(struct i40e_hw *hw,
8963 struct rte_eth_hash_global_conf *g_cfg)
8965 struct i40e_adapter *adapter = (struct i40e_adapter *)hw->back;
8969 memset(g_cfg, 0, sizeof(*g_cfg));
8970 reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
8971 if (reg & I40E_GLQF_CTL_HTOEP_MASK)
8972 g_cfg->hash_func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
8974 g_cfg->hash_func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
8975 PMD_DRV_LOG(DEBUG, "Hash function is %s",
8976 (reg & I40E_GLQF_CTL_HTOEP_MASK) ? "Toeplitz" : "Simple XOR");
8979 * As i40e supports less than 64 flow types, only first 64 bits need to
8982 for (i = 1; i < RTE_SYM_HASH_MASK_ARRAY_SIZE; i++) {
8983 g_cfg->valid_bit_mask[i] = 0ULL;
8984 g_cfg->sym_hash_enable_mask[i] = 0ULL;
8987 g_cfg->valid_bit_mask[0] = adapter->flow_types_mask;
8989 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < UINT64_BIT; i++) {
8990 if (!adapter->pctypes_tbl[i])
8992 for (j = I40E_FILTER_PCTYPE_INVALID + 1;
8993 j < I40E_FILTER_PCTYPE_MAX; j++) {
8994 if (adapter->pctypes_tbl[i] & (1ULL << j)) {
8995 reg = i40e_read_rx_ctl(hw, I40E_GLQF_HSYM(j));
8996 if (reg & I40E_GLQF_HSYM_SYMH_ENA_MASK) {
8997 g_cfg->sym_hash_enable_mask[0] |=
9008 i40e_hash_global_config_check(const struct i40e_adapter *adapter,
9009 const struct rte_eth_hash_global_conf *g_cfg)
9012 uint64_t mask0, i40e_mask = adapter->flow_types_mask;
9014 if (g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_TOEPLITZ &&
9015 g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_SIMPLE_XOR &&
9016 g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_DEFAULT) {
9017 PMD_DRV_LOG(ERR, "Unsupported hash function type %d",
9023 * As i40e supports less than 64 flow types, only first 64 bits need to
9026 mask0 = g_cfg->valid_bit_mask[0];
9027 for (i = 0; i < RTE_SYM_HASH_MASK_ARRAY_SIZE; i++) {
9029 /* Check if any unsupported flow type configured */
9030 if ((mask0 | i40e_mask) ^ i40e_mask)
9033 if (g_cfg->valid_bit_mask[i])
9041 PMD_DRV_LOG(ERR, "i40e unsupported flow type bit(s) configured");
9047 * Set global configurations of hash function type and symmetric hash enable
9048 * per flow type (pctype). Note any modifying global configuration will affect
9049 * all the ports on the same NIC.
9052 i40e_set_hash_filter_global_config(struct i40e_hw *hw,
9053 struct rte_eth_hash_global_conf *g_cfg)
9055 struct i40e_adapter *adapter = (struct i40e_adapter *)hw->back;
9056 struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
9060 uint64_t mask0 = g_cfg->valid_bit_mask[0] & adapter->flow_types_mask;
9062 if (pf->support_multi_driver) {
9063 PMD_DRV_LOG(ERR, "Hash global configuration is not supported.");
9067 /* Check the input parameters */
9068 ret = i40e_hash_global_config_check(adapter, g_cfg);
9073 * As i40e supports less than 64 flow types, only first 64 bits need to
9076 for (i = RTE_ETH_FLOW_UNKNOWN + 1; mask0 && i < UINT64_BIT; i++) {
9077 if (mask0 & (1UL << i)) {
9078 reg = (g_cfg->sym_hash_enable_mask[0] & (1ULL << i)) ?
9079 I40E_GLQF_HSYM_SYMH_ENA_MASK : 0;
9081 for (j = I40E_FILTER_PCTYPE_INVALID + 1;
9082 j < I40E_FILTER_PCTYPE_MAX; j++) {
9083 if (adapter->pctypes_tbl[i] & (1ULL << j))
9084 i40e_write_global_rx_ctl(hw,
9091 reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
9092 if (g_cfg->hash_func == RTE_ETH_HASH_FUNCTION_TOEPLITZ) {
9094 if (reg & I40E_GLQF_CTL_HTOEP_MASK) {
9096 "Hash function already set to Toeplitz");
9099 reg |= I40E_GLQF_CTL_HTOEP_MASK;
9100 } else if (g_cfg->hash_func == RTE_ETH_HASH_FUNCTION_SIMPLE_XOR) {
9102 if (!(reg & I40E_GLQF_CTL_HTOEP_MASK)) {
9104 "Hash function already set to Simple XOR");
9107 reg &= ~I40E_GLQF_CTL_HTOEP_MASK;
9109 /* Use the default, and keep it as it is */
9112 i40e_write_global_rx_ctl(hw, I40E_GLQF_CTL, reg);
9115 I40E_WRITE_FLUSH(hw);
9121 * Valid input sets for hash and flow director filters per PCTYPE
9124 i40e_get_valid_input_set(enum i40e_filter_pctype pctype,
9125 enum rte_filter_type filter)
9129 static const uint64_t valid_hash_inset_table[] = {
9130 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9131 I40E_INSET_DMAC | I40E_INSET_SMAC |
9132 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9133 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_SRC |
9134 I40E_INSET_IPV4_DST | I40E_INSET_IPV4_TOS |
9135 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9136 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9137 I40E_INSET_FLEX_PAYLOAD,
9138 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9139 I40E_INSET_DMAC | I40E_INSET_SMAC |
9140 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9141 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9142 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9143 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9144 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9145 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9146 I40E_INSET_FLEX_PAYLOAD,
9147 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9148 I40E_INSET_DMAC | I40E_INSET_SMAC |
9149 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9150 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9151 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9152 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9153 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9154 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9155 I40E_INSET_FLEX_PAYLOAD,
9156 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9157 I40E_INSET_DMAC | I40E_INSET_SMAC |
9158 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9159 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9160 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9161 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9162 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9163 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9164 I40E_INSET_FLEX_PAYLOAD,
9165 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9166 I40E_INSET_DMAC | I40E_INSET_SMAC |
9167 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9168 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9169 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9170 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9171 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9172 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9173 I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
9174 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9175 I40E_INSET_DMAC | I40E_INSET_SMAC |
9176 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9177 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9178 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9179 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9180 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9181 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9182 I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
9183 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9184 I40E_INSET_DMAC | I40E_INSET_SMAC |
9185 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9186 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9187 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9188 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9189 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9190 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9191 I40E_INSET_SCTP_VT | I40E_INSET_FLEX_PAYLOAD,
9192 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9193 I40E_INSET_DMAC | I40E_INSET_SMAC |
9194 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9195 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9196 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9197 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9198 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9199 I40E_INSET_FLEX_PAYLOAD,
9200 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9201 I40E_INSET_DMAC | I40E_INSET_SMAC |
9202 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9203 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9204 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9205 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_TUNNEL_DMAC |
9206 I40E_INSET_TUNNEL_ID | I40E_INSET_IPV6_SRC |
9207 I40E_INSET_IPV6_DST | I40E_INSET_FLEX_PAYLOAD,
9208 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9209 I40E_INSET_DMAC | I40E_INSET_SMAC |
9210 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9211 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9212 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9213 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9214 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9215 I40E_INSET_DST_PORT | I40E_INSET_FLEX_PAYLOAD,
9216 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9217 I40E_INSET_DMAC | I40E_INSET_SMAC |
9218 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9219 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9220 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9221 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9222 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9223 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9224 I40E_INSET_FLEX_PAYLOAD,
9225 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9226 I40E_INSET_DMAC | I40E_INSET_SMAC |
9227 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9228 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9229 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9230 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9231 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9232 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9233 I40E_INSET_FLEX_PAYLOAD,
9234 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9235 I40E_INSET_DMAC | I40E_INSET_SMAC |
9236 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9237 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9238 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9239 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9240 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9241 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9242 I40E_INSET_FLEX_PAYLOAD,
9243 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9244 I40E_INSET_DMAC | I40E_INSET_SMAC |
9245 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9246 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9247 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9248 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9249 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9250 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9251 I40E_INSET_FLEX_PAYLOAD,
9252 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9253 I40E_INSET_DMAC | I40E_INSET_SMAC |
9254 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9255 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9256 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9257 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9258 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9259 I40E_INSET_DST_PORT | I40E_INSET_SCTP_VT |
9260 I40E_INSET_FLEX_PAYLOAD,
9261 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9262 I40E_INSET_DMAC | I40E_INSET_SMAC |
9263 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9264 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9265 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9266 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9267 I40E_INSET_IPV6_DST | I40E_INSET_TUNNEL_ID |
9268 I40E_INSET_FLEX_PAYLOAD,
9269 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9270 I40E_INSET_DMAC | I40E_INSET_SMAC |
9271 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9272 I40E_INSET_VLAN_TUNNEL | I40E_INSET_LAST_ETHER_TYPE |
9273 I40E_INSET_FLEX_PAYLOAD,
9277 * Flow director supports only fields defined in
9278 * union rte_eth_fdir_flow.
9280 static const uint64_t valid_fdir_inset_table[] = {
9281 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9282 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9283 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9284 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9285 I40E_INSET_IPV4_TTL,
9286 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9287 I40E_INSET_DMAC | I40E_INSET_SMAC |
9288 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9289 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9290 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9291 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9292 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9293 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9294 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9295 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9296 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9297 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9298 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9299 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9300 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9301 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9302 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9303 I40E_INSET_DMAC | I40E_INSET_SMAC |
9304 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9305 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9306 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9307 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9308 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9309 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9310 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9311 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9312 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9313 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9314 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9315 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9316 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9317 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9319 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9320 I40E_INSET_DMAC | I40E_INSET_SMAC |
9321 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9322 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9323 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9324 I40E_INSET_IPV4_TTL,
9325 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9326 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9327 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9328 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
9329 I40E_INSET_IPV6_HOP_LIMIT,
9330 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9331 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9332 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9333 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9334 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9335 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9336 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9337 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9338 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9339 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9340 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9341 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9342 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9343 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9344 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9345 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9346 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9347 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9348 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9349 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9350 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9351 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9352 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9353 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9354 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9355 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9356 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9357 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9358 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9359 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9361 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9362 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9363 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9364 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
9365 I40E_INSET_IPV6_HOP_LIMIT,
9366 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9367 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9368 I40E_INSET_LAST_ETHER_TYPE,
9371 if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
9373 if (filter == RTE_ETH_FILTER_HASH)
9374 valid = valid_hash_inset_table[pctype];
9376 valid = valid_fdir_inset_table[pctype];
9382 * Validate if the input set is allowed for a specific PCTYPE
9385 i40e_validate_input_set(enum i40e_filter_pctype pctype,
9386 enum rte_filter_type filter, uint64_t inset)
9390 valid = i40e_get_valid_input_set(pctype, filter);
9391 if (inset & (~valid))
9397 /* default input set fields combination per pctype */
9399 i40e_get_default_input_set(uint16_t pctype)
9401 static const uint64_t default_inset_table[] = {
9402 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9403 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
9404 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9405 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9406 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9407 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9408 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9409 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9410 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9411 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9412 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9413 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9414 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9415 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9416 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9417 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9418 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9419 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9420 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9421 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9423 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9424 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
9425 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9426 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
9427 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9428 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9429 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9430 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9431 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9432 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9433 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9434 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9435 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9436 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9437 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9438 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9439 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9440 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9441 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9442 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9443 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9444 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9446 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9447 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
9448 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9449 I40E_INSET_LAST_ETHER_TYPE,
9452 if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
9455 return default_inset_table[pctype];
9459 * Parse the input set from index to logical bit masks
9462 i40e_parse_input_set(uint64_t *inset,
9463 enum i40e_filter_pctype pctype,
9464 enum rte_eth_input_set_field *field,
9470 static const struct {
9471 enum rte_eth_input_set_field field;
9473 } inset_convert_table[] = {
9474 {RTE_ETH_INPUT_SET_NONE, I40E_INSET_NONE},
9475 {RTE_ETH_INPUT_SET_L2_SRC_MAC, I40E_INSET_SMAC},
9476 {RTE_ETH_INPUT_SET_L2_DST_MAC, I40E_INSET_DMAC},
9477 {RTE_ETH_INPUT_SET_L2_OUTER_VLAN, I40E_INSET_VLAN_OUTER},
9478 {RTE_ETH_INPUT_SET_L2_INNER_VLAN, I40E_INSET_VLAN_INNER},
9479 {RTE_ETH_INPUT_SET_L2_ETHERTYPE, I40E_INSET_LAST_ETHER_TYPE},
9480 {RTE_ETH_INPUT_SET_L3_SRC_IP4, I40E_INSET_IPV4_SRC},
9481 {RTE_ETH_INPUT_SET_L3_DST_IP4, I40E_INSET_IPV4_DST},
9482 {RTE_ETH_INPUT_SET_L3_IP4_TOS, I40E_INSET_IPV4_TOS},
9483 {RTE_ETH_INPUT_SET_L3_IP4_PROTO, I40E_INSET_IPV4_PROTO},
9484 {RTE_ETH_INPUT_SET_L3_IP4_TTL, I40E_INSET_IPV4_TTL},
9485 {RTE_ETH_INPUT_SET_L3_SRC_IP6, I40E_INSET_IPV6_SRC},
9486 {RTE_ETH_INPUT_SET_L3_DST_IP6, I40E_INSET_IPV6_DST},
9487 {RTE_ETH_INPUT_SET_L3_IP6_TC, I40E_INSET_IPV6_TC},
9488 {RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER,
9489 I40E_INSET_IPV6_NEXT_HDR},
9490 {RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS,
9491 I40E_INSET_IPV6_HOP_LIMIT},
9492 {RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT, I40E_INSET_SRC_PORT},
9493 {RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT, I40E_INSET_SRC_PORT},
9494 {RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT, I40E_INSET_SRC_PORT},
9495 {RTE_ETH_INPUT_SET_L4_UDP_DST_PORT, I40E_INSET_DST_PORT},
9496 {RTE_ETH_INPUT_SET_L4_TCP_DST_PORT, I40E_INSET_DST_PORT},
9497 {RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT, I40E_INSET_DST_PORT},
9498 {RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG,
9499 I40E_INSET_SCTP_VT},
9500 {RTE_ETH_INPUT_SET_TUNNEL_L2_INNER_DST_MAC,
9501 I40E_INSET_TUNNEL_DMAC},
9502 {RTE_ETH_INPUT_SET_TUNNEL_L2_INNER_VLAN,
9503 I40E_INSET_VLAN_TUNNEL},
9504 {RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY,
9505 I40E_INSET_TUNNEL_ID},
9506 {RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY, I40E_INSET_TUNNEL_ID},
9507 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD,
9508 I40E_INSET_FLEX_PAYLOAD_W1},
9509 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD,
9510 I40E_INSET_FLEX_PAYLOAD_W2},
9511 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD,
9512 I40E_INSET_FLEX_PAYLOAD_W3},
9513 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD,
9514 I40E_INSET_FLEX_PAYLOAD_W4},
9515 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD,
9516 I40E_INSET_FLEX_PAYLOAD_W5},
9517 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD,
9518 I40E_INSET_FLEX_PAYLOAD_W6},
9519 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD,
9520 I40E_INSET_FLEX_PAYLOAD_W7},
9521 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD,
9522 I40E_INSET_FLEX_PAYLOAD_W8},
9525 if (!inset || !field || size > RTE_ETH_INSET_SIZE_MAX)
9528 /* Only one item allowed for default or all */
9530 if (field[0] == RTE_ETH_INPUT_SET_DEFAULT) {
9531 *inset = i40e_get_default_input_set(pctype);
9533 } else if (field[0] == RTE_ETH_INPUT_SET_NONE) {
9534 *inset = I40E_INSET_NONE;
9539 for (i = 0, *inset = 0; i < size; i++) {
9540 for (j = 0; j < RTE_DIM(inset_convert_table); j++) {
9541 if (field[i] == inset_convert_table[j].field) {
9542 *inset |= inset_convert_table[j].inset;
9547 /* It contains unsupported input set, return immediately */
9548 if (j == RTE_DIM(inset_convert_table))
9556 * Translate the input set from bit masks to register aware bit masks
9560 i40e_translate_input_set_reg(enum i40e_mac_type type, uint64_t input)
9570 static const struct inset_map inset_map_common[] = {
9571 {I40E_INSET_DMAC, I40E_REG_INSET_L2_DMAC},
9572 {I40E_INSET_SMAC, I40E_REG_INSET_L2_SMAC},
9573 {I40E_INSET_VLAN_OUTER, I40E_REG_INSET_L2_OUTER_VLAN},
9574 {I40E_INSET_VLAN_INNER, I40E_REG_INSET_L2_INNER_VLAN},
9575 {I40E_INSET_LAST_ETHER_TYPE, I40E_REG_INSET_LAST_ETHER_TYPE},
9576 {I40E_INSET_IPV4_TOS, I40E_REG_INSET_L3_IP4_TOS},
9577 {I40E_INSET_IPV6_SRC, I40E_REG_INSET_L3_SRC_IP6},
9578 {I40E_INSET_IPV6_DST, I40E_REG_INSET_L3_DST_IP6},
9579 {I40E_INSET_IPV6_TC, I40E_REG_INSET_L3_IP6_TC},
9580 {I40E_INSET_IPV6_NEXT_HDR, I40E_REG_INSET_L3_IP6_NEXT_HDR},
9581 {I40E_INSET_IPV6_HOP_LIMIT, I40E_REG_INSET_L3_IP6_HOP_LIMIT},
9582 {I40E_INSET_SRC_PORT, I40E_REG_INSET_L4_SRC_PORT},
9583 {I40E_INSET_DST_PORT, I40E_REG_INSET_L4_DST_PORT},
9584 {I40E_INSET_SCTP_VT, I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG},
9585 {I40E_INSET_TUNNEL_ID, I40E_REG_INSET_TUNNEL_ID},
9586 {I40E_INSET_TUNNEL_DMAC,
9587 I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC},
9588 {I40E_INSET_TUNNEL_IPV4_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP4},
9589 {I40E_INSET_TUNNEL_IPV6_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP6},
9590 {I40E_INSET_TUNNEL_SRC_PORT,
9591 I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT},
9592 {I40E_INSET_TUNNEL_DST_PORT,
9593 I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT},
9594 {I40E_INSET_VLAN_TUNNEL, I40E_REG_INSET_TUNNEL_VLAN},
9595 {I40E_INSET_FLEX_PAYLOAD_W1, I40E_REG_INSET_FLEX_PAYLOAD_WORD1},
9596 {I40E_INSET_FLEX_PAYLOAD_W2, I40E_REG_INSET_FLEX_PAYLOAD_WORD2},
9597 {I40E_INSET_FLEX_PAYLOAD_W3, I40E_REG_INSET_FLEX_PAYLOAD_WORD3},
9598 {I40E_INSET_FLEX_PAYLOAD_W4, I40E_REG_INSET_FLEX_PAYLOAD_WORD4},
9599 {I40E_INSET_FLEX_PAYLOAD_W5, I40E_REG_INSET_FLEX_PAYLOAD_WORD5},
9600 {I40E_INSET_FLEX_PAYLOAD_W6, I40E_REG_INSET_FLEX_PAYLOAD_WORD6},
9601 {I40E_INSET_FLEX_PAYLOAD_W7, I40E_REG_INSET_FLEX_PAYLOAD_WORD7},
9602 {I40E_INSET_FLEX_PAYLOAD_W8, I40E_REG_INSET_FLEX_PAYLOAD_WORD8},
9605 /* some different registers map in x722*/
9606 static const struct inset_map inset_map_diff_x722[] = {
9607 {I40E_INSET_IPV4_SRC, I40E_X722_REG_INSET_L3_SRC_IP4},
9608 {I40E_INSET_IPV4_DST, I40E_X722_REG_INSET_L3_DST_IP4},
9609 {I40E_INSET_IPV4_PROTO, I40E_X722_REG_INSET_L3_IP4_PROTO},
9610 {I40E_INSET_IPV4_TTL, I40E_X722_REG_INSET_L3_IP4_TTL},
9613 static const struct inset_map inset_map_diff_not_x722[] = {
9614 {I40E_INSET_IPV4_SRC, I40E_REG_INSET_L3_SRC_IP4},
9615 {I40E_INSET_IPV4_DST, I40E_REG_INSET_L3_DST_IP4},
9616 {I40E_INSET_IPV4_PROTO, I40E_REG_INSET_L3_IP4_PROTO},
9617 {I40E_INSET_IPV4_TTL, I40E_REG_INSET_L3_IP4_TTL},
9623 /* Translate input set to register aware inset */
9624 if (type == I40E_MAC_X722) {
9625 for (i = 0; i < RTE_DIM(inset_map_diff_x722); i++) {
9626 if (input & inset_map_diff_x722[i].inset)
9627 val |= inset_map_diff_x722[i].inset_reg;
9630 for (i = 0; i < RTE_DIM(inset_map_diff_not_x722); i++) {
9631 if (input & inset_map_diff_not_x722[i].inset)
9632 val |= inset_map_diff_not_x722[i].inset_reg;
9636 for (i = 0; i < RTE_DIM(inset_map_common); i++) {
9637 if (input & inset_map_common[i].inset)
9638 val |= inset_map_common[i].inset_reg;
9645 i40e_generate_inset_mask_reg(uint64_t inset, uint32_t *mask, uint8_t nb_elem)
9648 uint64_t inset_need_mask = inset;
9650 static const struct {
9653 } inset_mask_map[] = {
9654 {I40E_INSET_IPV4_TOS, I40E_INSET_IPV4_TOS_MASK},
9655 {I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL, 0},
9656 {I40E_INSET_IPV4_PROTO, I40E_INSET_IPV4_PROTO_MASK},
9657 {I40E_INSET_IPV4_TTL, I40E_INSET_IPv4_TTL_MASK},
9658 {I40E_INSET_IPV6_TC, I40E_INSET_IPV6_TC_MASK},
9659 {I40E_INSET_IPV6_NEXT_HDR | I40E_INSET_IPV6_HOP_LIMIT, 0},
9660 {I40E_INSET_IPV6_NEXT_HDR, I40E_INSET_IPV6_NEXT_HDR_MASK},
9661 {I40E_INSET_IPV6_HOP_LIMIT, I40E_INSET_IPV6_HOP_LIMIT_MASK},
9664 if (!inset || !mask || !nb_elem)
9667 for (i = 0, idx = 0; i < RTE_DIM(inset_mask_map); i++) {
9668 /* Clear the inset bit, if no MASK is required,
9669 * for example proto + ttl
9671 if ((inset & inset_mask_map[i].inset) ==
9672 inset_mask_map[i].inset && inset_mask_map[i].mask == 0)
9673 inset_need_mask &= ~inset_mask_map[i].inset;
9674 if (!inset_need_mask)
9677 for (i = 0, idx = 0; i < RTE_DIM(inset_mask_map); i++) {
9678 if ((inset_need_mask & inset_mask_map[i].inset) ==
9679 inset_mask_map[i].inset) {
9680 if (idx >= nb_elem) {
9681 PMD_DRV_LOG(ERR, "exceed maximal number of bitmasks");
9684 mask[idx] = inset_mask_map[i].mask;
9693 i40e_check_write_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
9695 uint32_t reg = i40e_read_rx_ctl(hw, addr);
9697 PMD_DRV_LOG(DEBUG, "[0x%08x] original: 0x%08x", addr, reg);
9699 i40e_write_rx_ctl(hw, addr, val);
9700 PMD_DRV_LOG(DEBUG, "[0x%08x] after: 0x%08x", addr,
9701 (uint32_t)i40e_read_rx_ctl(hw, addr));
9705 i40e_check_write_global_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
9707 uint32_t reg = i40e_read_rx_ctl(hw, addr);
9708 struct rte_eth_dev *dev;
9710 dev = ((struct i40e_adapter *)hw->back)->eth_dev;
9712 i40e_write_rx_ctl(hw, addr, val);
9713 PMD_DRV_LOG(WARNING,
9714 "i40e device %s changed global register [0x%08x]."
9715 " original: 0x%08x, new: 0x%08x",
9716 dev->device->name, addr, reg,
9717 (uint32_t)i40e_read_rx_ctl(hw, addr));
9722 i40e_filter_input_set_init(struct i40e_pf *pf)
9724 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9725 enum i40e_filter_pctype pctype;
9726 uint64_t input_set, inset_reg;
9727 uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9731 for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
9732 pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++) {
9733 flow_type = i40e_pctype_to_flowtype(pf->adapter, pctype);
9735 if (flow_type == RTE_ETH_FLOW_UNKNOWN)
9738 input_set = i40e_get_default_input_set(pctype);
9740 num = i40e_generate_inset_mask_reg(input_set, mask_reg,
9741 I40E_INSET_MASK_NUM_REG);
9744 if (pf->support_multi_driver && num > 0) {
9745 PMD_DRV_LOG(ERR, "Input set setting is not supported.");
9748 inset_reg = i40e_translate_input_set_reg(hw->mac.type,
9751 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
9752 (uint32_t)(inset_reg & UINT32_MAX));
9753 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
9754 (uint32_t)((inset_reg >>
9755 I40E_32_BIT_WIDTH) & UINT32_MAX));
9756 if (!pf->support_multi_driver) {
9757 i40e_check_write_global_reg(hw,
9758 I40E_GLQF_HASH_INSET(0, pctype),
9759 (uint32_t)(inset_reg & UINT32_MAX));
9760 i40e_check_write_global_reg(hw,
9761 I40E_GLQF_HASH_INSET(1, pctype),
9762 (uint32_t)((inset_reg >>
9763 I40E_32_BIT_WIDTH) & UINT32_MAX));
9765 for (i = 0; i < num; i++) {
9766 i40e_check_write_global_reg(hw,
9767 I40E_GLQF_FD_MSK(i, pctype),
9769 i40e_check_write_global_reg(hw,
9770 I40E_GLQF_HASH_MSK(i, pctype),
9773 /*clear unused mask registers of the pctype */
9774 for (i = num; i < I40E_INSET_MASK_NUM_REG; i++) {
9775 i40e_check_write_global_reg(hw,
9776 I40E_GLQF_FD_MSK(i, pctype),
9778 i40e_check_write_global_reg(hw,
9779 I40E_GLQF_HASH_MSK(i, pctype),
9783 PMD_DRV_LOG(ERR, "Input set setting is not supported.");
9785 I40E_WRITE_FLUSH(hw);
9787 /* store the default input set */
9788 if (!pf->support_multi_driver)
9789 pf->hash_input_set[pctype] = input_set;
9790 pf->fdir.input_set[pctype] = input_set;
9795 i40e_hash_filter_inset_select(struct i40e_hw *hw,
9796 struct rte_eth_input_set_conf *conf)
9798 struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
9799 enum i40e_filter_pctype pctype;
9800 uint64_t input_set, inset_reg = 0;
9801 uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9805 PMD_DRV_LOG(ERR, "Invalid pointer");
9808 if (conf->op != RTE_ETH_INPUT_SET_SELECT &&
9809 conf->op != RTE_ETH_INPUT_SET_ADD) {
9810 PMD_DRV_LOG(ERR, "Unsupported input set operation");
9814 if (pf->support_multi_driver) {
9815 PMD_DRV_LOG(ERR, "Hash input set setting is not supported.");
9819 pctype = i40e_flowtype_to_pctype(pf->adapter, conf->flow_type);
9820 if (pctype == I40E_FILTER_PCTYPE_INVALID) {
9821 PMD_DRV_LOG(ERR, "invalid flow_type input.");
9825 if (hw->mac.type == I40E_MAC_X722) {
9826 /* get translated pctype value in fd pctype register */
9827 pctype = (enum i40e_filter_pctype)i40e_read_rx_ctl(hw,
9828 I40E_GLQF_FD_PCTYPES((int)pctype));
9831 ret = i40e_parse_input_set(&input_set, pctype, conf->field,
9834 PMD_DRV_LOG(ERR, "Failed to parse input set");
9838 if (conf->op == RTE_ETH_INPUT_SET_ADD) {
9839 /* get inset value in register */
9840 inset_reg = i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, pctype));
9841 inset_reg <<= I40E_32_BIT_WIDTH;
9842 inset_reg |= i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, pctype));
9843 input_set |= pf->hash_input_set[pctype];
9845 num = i40e_generate_inset_mask_reg(input_set, mask_reg,
9846 I40E_INSET_MASK_NUM_REG);
9850 inset_reg |= i40e_translate_input_set_reg(hw->mac.type, input_set);
9852 i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(0, pctype),
9853 (uint32_t)(inset_reg & UINT32_MAX));
9854 i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(1, pctype),
9855 (uint32_t)((inset_reg >>
9856 I40E_32_BIT_WIDTH) & UINT32_MAX));
9858 for (i = 0; i < num; i++)
9859 i40e_check_write_global_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
9861 /*clear unused mask registers of the pctype */
9862 for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
9863 i40e_check_write_global_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
9865 I40E_WRITE_FLUSH(hw);
9867 pf->hash_input_set[pctype] = input_set;
9872 i40e_fdir_filter_inset_select(struct i40e_pf *pf,
9873 struct rte_eth_input_set_conf *conf)
9875 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9876 enum i40e_filter_pctype pctype;
9877 uint64_t input_set, inset_reg = 0;
9878 uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9882 PMD_DRV_LOG(ERR, "Invalid pointer");
9885 if (conf->op != RTE_ETH_INPUT_SET_SELECT &&
9886 conf->op != RTE_ETH_INPUT_SET_ADD) {
9887 PMD_DRV_LOG(ERR, "Unsupported input set operation");
9891 pctype = i40e_flowtype_to_pctype(pf->adapter, conf->flow_type);
9893 if (pctype == I40E_FILTER_PCTYPE_INVALID) {
9894 PMD_DRV_LOG(ERR, "invalid flow_type input.");
9898 ret = i40e_parse_input_set(&input_set, pctype, conf->field,
9901 PMD_DRV_LOG(ERR, "Failed to parse input set");
9905 /* get inset value in register */
9906 inset_reg = i40e_read_rx_ctl(hw, I40E_PRTQF_FD_INSET(pctype, 1));
9907 inset_reg <<= I40E_32_BIT_WIDTH;
9908 inset_reg |= i40e_read_rx_ctl(hw, I40E_PRTQF_FD_INSET(pctype, 0));
9910 /* Can not change the inset reg for flex payload for fdir,
9911 * it is done by writing I40E_PRTQF_FD_FLXINSET
9912 * in i40e_set_flex_mask_on_pctype.
9914 if (conf->op == RTE_ETH_INPUT_SET_SELECT)
9915 inset_reg &= I40E_REG_INSET_FLEX_PAYLOAD_WORDS;
9917 input_set |= pf->fdir.input_set[pctype];
9918 num = i40e_generate_inset_mask_reg(input_set, mask_reg,
9919 I40E_INSET_MASK_NUM_REG);
9922 if (pf->support_multi_driver && num > 0) {
9923 PMD_DRV_LOG(ERR, "FDIR bit mask is not supported.");
9927 inset_reg |= i40e_translate_input_set_reg(hw->mac.type, input_set);
9929 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
9930 (uint32_t)(inset_reg & UINT32_MAX));
9931 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
9932 (uint32_t)((inset_reg >>
9933 I40E_32_BIT_WIDTH) & UINT32_MAX));
9935 if (!pf->support_multi_driver) {
9936 for (i = 0; i < num; i++)
9937 i40e_check_write_global_reg(hw,
9938 I40E_GLQF_FD_MSK(i, pctype),
9940 /*clear unused mask registers of the pctype */
9941 for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
9942 i40e_check_write_global_reg(hw,
9943 I40E_GLQF_FD_MSK(i, pctype),
9946 PMD_DRV_LOG(ERR, "FDIR bit mask is not supported.");
9948 I40E_WRITE_FLUSH(hw);
9950 pf->fdir.input_set[pctype] = input_set;
9955 i40e_hash_filter_get(struct i40e_hw *hw, struct rte_eth_hash_filter_info *info)
9960 PMD_DRV_LOG(ERR, "Invalid pointer");
9964 switch (info->info_type) {
9965 case RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT:
9966 i40e_get_symmetric_hash_enable_per_port(hw,
9967 &(info->info.enable));
9969 case RTE_ETH_HASH_FILTER_GLOBAL_CONFIG:
9970 ret = i40e_get_hash_filter_global_config(hw,
9971 &(info->info.global_conf));
9974 PMD_DRV_LOG(ERR, "Hash filter info type (%d) not supported",
9984 i40e_hash_filter_set(struct i40e_hw *hw, struct rte_eth_hash_filter_info *info)
9989 PMD_DRV_LOG(ERR, "Invalid pointer");
9993 switch (info->info_type) {
9994 case RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT:
9995 i40e_set_symmetric_hash_enable_per_port(hw, info->info.enable);
9997 case RTE_ETH_HASH_FILTER_GLOBAL_CONFIG:
9998 ret = i40e_set_hash_filter_global_config(hw,
9999 &(info->info.global_conf));
10001 case RTE_ETH_HASH_FILTER_INPUT_SET_SELECT:
10002 ret = i40e_hash_filter_inset_select(hw,
10003 &(info->info.input_set_conf));
10007 PMD_DRV_LOG(ERR, "Hash filter info type (%d) not supported",
10016 /* Operations for hash function */
10018 i40e_hash_filter_ctrl(struct rte_eth_dev *dev,
10019 enum rte_filter_op filter_op,
10022 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10025 switch (filter_op) {
10026 case RTE_ETH_FILTER_NOP:
10028 case RTE_ETH_FILTER_GET:
10029 ret = i40e_hash_filter_get(hw,
10030 (struct rte_eth_hash_filter_info *)arg);
10032 case RTE_ETH_FILTER_SET:
10033 ret = i40e_hash_filter_set(hw,
10034 (struct rte_eth_hash_filter_info *)arg);
10037 PMD_DRV_LOG(WARNING, "Filter operation (%d) not supported",
10046 /* Convert ethertype filter structure */
10048 i40e_ethertype_filter_convert(const struct rte_eth_ethertype_filter *input,
10049 struct i40e_ethertype_filter *filter)
10051 rte_memcpy(&filter->input.mac_addr, &input->mac_addr,
10052 RTE_ETHER_ADDR_LEN);
10053 filter->input.ether_type = input->ether_type;
10054 filter->flags = input->flags;
10055 filter->queue = input->queue;
10060 /* Check if there exists the ehtertype filter */
10061 struct i40e_ethertype_filter *
10062 i40e_sw_ethertype_filter_lookup(struct i40e_ethertype_rule *ethertype_rule,
10063 const struct i40e_ethertype_filter_input *input)
10067 ret = rte_hash_lookup(ethertype_rule->hash_table, (const void *)input);
10071 return ethertype_rule->hash_map[ret];
10074 /* Add ethertype filter in SW list */
10076 i40e_sw_ethertype_filter_insert(struct i40e_pf *pf,
10077 struct i40e_ethertype_filter *filter)
10079 struct i40e_ethertype_rule *rule = &pf->ethertype;
10082 ret = rte_hash_add_key(rule->hash_table, &filter->input);
10085 "Failed to insert ethertype filter"
10086 " to hash table %d!",
10090 rule->hash_map[ret] = filter;
10092 TAILQ_INSERT_TAIL(&rule->ethertype_list, filter, rules);
10097 /* Delete ethertype filter in SW list */
10099 i40e_sw_ethertype_filter_del(struct i40e_pf *pf,
10100 struct i40e_ethertype_filter_input *input)
10102 struct i40e_ethertype_rule *rule = &pf->ethertype;
10103 struct i40e_ethertype_filter *filter;
10106 ret = rte_hash_del_key(rule->hash_table, input);
10109 "Failed to delete ethertype filter"
10110 " to hash table %d!",
10114 filter = rule->hash_map[ret];
10115 rule->hash_map[ret] = NULL;
10117 TAILQ_REMOVE(&rule->ethertype_list, filter, rules);
10124 * Configure ethertype filter, which can director packet by filtering
10125 * with mac address and ether_type or only ether_type
10128 i40e_ethertype_filter_set(struct i40e_pf *pf,
10129 struct rte_eth_ethertype_filter *filter,
10132 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
10133 struct i40e_ethertype_rule *ethertype_rule = &pf->ethertype;
10134 struct i40e_ethertype_filter *ethertype_filter, *node;
10135 struct i40e_ethertype_filter check_filter;
10136 struct i40e_control_filter_stats stats;
10137 uint16_t flags = 0;
10140 if (filter->queue >= pf->dev_data->nb_rx_queues) {
10141 PMD_DRV_LOG(ERR, "Invalid queue ID");
10144 if (filter->ether_type == RTE_ETHER_TYPE_IPV4 ||
10145 filter->ether_type == RTE_ETHER_TYPE_IPV6) {
10147 "unsupported ether_type(0x%04x) in control packet filter.",
10148 filter->ether_type);
10151 if (filter->ether_type == RTE_ETHER_TYPE_VLAN)
10152 PMD_DRV_LOG(WARNING,
10153 "filter vlan ether_type in first tag is not supported.");
10155 /* Check if there is the filter in SW list */
10156 memset(&check_filter, 0, sizeof(check_filter));
10157 i40e_ethertype_filter_convert(filter, &check_filter);
10158 node = i40e_sw_ethertype_filter_lookup(ethertype_rule,
10159 &check_filter.input);
10161 PMD_DRV_LOG(ERR, "Conflict with existing ethertype rules!");
10165 if (!add && !node) {
10166 PMD_DRV_LOG(ERR, "There's no corresponding ethertype filter!");
10170 if (!(filter->flags & RTE_ETHTYPE_FLAGS_MAC))
10171 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
10172 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP)
10173 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
10174 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
10176 memset(&stats, 0, sizeof(stats));
10177 ret = i40e_aq_add_rem_control_packet_filter(hw,
10178 filter->mac_addr.addr_bytes,
10179 filter->ether_type, flags,
10180 pf->main_vsi->seid,
10181 filter->queue, add, &stats, NULL);
10184 "add/rem control packet filter, return %d, mac_etype_used = %u, etype_used = %u, mac_etype_free = %u, etype_free = %u",
10185 ret, stats.mac_etype_used, stats.etype_used,
10186 stats.mac_etype_free, stats.etype_free);
10190 /* Add or delete a filter in SW list */
10192 ethertype_filter = rte_zmalloc("ethertype_filter",
10193 sizeof(*ethertype_filter), 0);
10194 if (ethertype_filter == NULL) {
10195 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
10199 rte_memcpy(ethertype_filter, &check_filter,
10200 sizeof(check_filter));
10201 ret = i40e_sw_ethertype_filter_insert(pf, ethertype_filter);
10203 rte_free(ethertype_filter);
10205 ret = i40e_sw_ethertype_filter_del(pf, &node->input);
10212 * Handle operations for ethertype filter.
10215 i40e_ethertype_filter_handle(struct rte_eth_dev *dev,
10216 enum rte_filter_op filter_op,
10219 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
10222 if (filter_op == RTE_ETH_FILTER_NOP)
10226 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
10231 switch (filter_op) {
10232 case RTE_ETH_FILTER_ADD:
10233 ret = i40e_ethertype_filter_set(pf,
10234 (struct rte_eth_ethertype_filter *)arg,
10237 case RTE_ETH_FILTER_DELETE:
10238 ret = i40e_ethertype_filter_set(pf,
10239 (struct rte_eth_ethertype_filter *)arg,
10243 PMD_DRV_LOG(ERR, "unsupported operation %u", filter_op);
10251 i40e_dev_filter_ctrl(struct rte_eth_dev *dev,
10252 enum rte_filter_type filter_type,
10253 enum rte_filter_op filter_op,
10261 switch (filter_type) {
10262 case RTE_ETH_FILTER_NONE:
10263 /* For global configuration */
10264 ret = i40e_filter_ctrl_global_config(dev, filter_op, arg);
10266 case RTE_ETH_FILTER_HASH:
10267 ret = i40e_hash_filter_ctrl(dev, filter_op, arg);
10269 case RTE_ETH_FILTER_MACVLAN:
10270 ret = i40e_mac_filter_handle(dev, filter_op, arg);
10272 case RTE_ETH_FILTER_ETHERTYPE:
10273 ret = i40e_ethertype_filter_handle(dev, filter_op, arg);
10275 case RTE_ETH_FILTER_TUNNEL:
10276 ret = i40e_tunnel_filter_handle(dev, filter_op, arg);
10278 case RTE_ETH_FILTER_FDIR:
10279 ret = i40e_fdir_ctrl_func(dev, filter_op, arg);
10281 case RTE_ETH_FILTER_GENERIC:
10282 if (filter_op != RTE_ETH_FILTER_GET)
10284 *(const void **)arg = &i40e_flow_ops;
10287 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
10297 * Check and enable Extended Tag.
10298 * Enabling Extended Tag is important for 40G performance.
10301 i40e_enable_extended_tag(struct rte_eth_dev *dev)
10303 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
10307 ret = rte_pci_read_config(pci_dev, &buf, sizeof(buf),
10310 PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
10314 if (!(buf & PCI_DEV_CAP_EXT_TAG_MASK)) {
10315 PMD_DRV_LOG(ERR, "Does not support Extended Tag");
10320 ret = rte_pci_read_config(pci_dev, &buf, sizeof(buf),
10323 PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
10327 if (buf & PCI_DEV_CTRL_EXT_TAG_MASK) {
10328 PMD_DRV_LOG(DEBUG, "Extended Tag has already been enabled");
10331 buf |= PCI_DEV_CTRL_EXT_TAG_MASK;
10332 ret = rte_pci_write_config(pci_dev, &buf, sizeof(buf),
10335 PMD_DRV_LOG(ERR, "Failed to write PCI offset 0x%x",
10342 * As some registers wouldn't be reset unless a global hardware reset,
10343 * hardware initialization is needed to put those registers into an
10344 * expected initial state.
10347 i40e_hw_init(struct rte_eth_dev *dev)
10349 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10351 i40e_enable_extended_tag(dev);
10353 /* clear the PF Queue Filter control register */
10354 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, 0);
10356 /* Disable symmetric hash per port */
10357 i40e_set_symmetric_hash_enable_per_port(hw, 0);
10361 * For X722 it is possible to have multiple pctypes mapped to the same flowtype
10362 * however this function will return only one highest pctype index,
10363 * which is not quite correct. This is known problem of i40e driver
10364 * and needs to be fixed later.
10366 enum i40e_filter_pctype
10367 i40e_flowtype_to_pctype(const struct i40e_adapter *adapter, uint16_t flow_type)
10370 uint64_t pctype_mask;
10372 if (flow_type < I40E_FLOW_TYPE_MAX) {
10373 pctype_mask = adapter->pctypes_tbl[flow_type];
10374 for (i = I40E_FILTER_PCTYPE_MAX - 1; i > 0; i--) {
10375 if (pctype_mask & (1ULL << i))
10376 return (enum i40e_filter_pctype)i;
10379 return I40E_FILTER_PCTYPE_INVALID;
10383 i40e_pctype_to_flowtype(const struct i40e_adapter *adapter,
10384 enum i40e_filter_pctype pctype)
10387 uint64_t pctype_mask = 1ULL << pctype;
10389 for (flowtype = RTE_ETH_FLOW_UNKNOWN + 1; flowtype < I40E_FLOW_TYPE_MAX;
10391 if (adapter->pctypes_tbl[flowtype] & pctype_mask)
10395 return RTE_ETH_FLOW_UNKNOWN;
10399 * On X710, performance number is far from the expectation on recent firmware
10400 * versions; on XL710, performance number is also far from the expectation on
10401 * recent firmware versions, if promiscuous mode is disabled, or promiscuous
10402 * mode is enabled and port MAC address is equal to the packet destination MAC
10403 * address. The fix for this issue may not be integrated in the following
10404 * firmware version. So the workaround in software driver is needed. It needs
10405 * to modify the initial values of 3 internal only registers for both X710 and
10406 * XL710. Note that the values for X710 or XL710 could be different, and the
10407 * workaround can be removed when it is fixed in firmware in the future.
10410 /* For both X710 and XL710 */
10411 #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1 0x10000200
10412 #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2 0x203F0200
10413 #define I40E_GL_SWR_PRI_JOIN_MAP_0 0x26CE00
10415 #define I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x011f0200
10416 #define I40E_GL_SWR_PRI_JOIN_MAP_2 0x26CE08
10419 #define I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE 0x20000200
10420 #define I40E_X722_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x013F0200
10423 #define I40E_GL_SWR_PM_UP_THR_EF_VALUE 0x03030303
10425 #define I40E_GL_SWR_PM_UP_THR_SF_VALUE 0x06060606
10426 #define I40E_GL_SWR_PM_UP_THR 0x269FBC
10429 * GL_SWR_PM_UP_THR:
10430 * The value is not impacted from the link speed, its value is set according
10431 * to the total number of ports for a better pipe-monitor configuration.
10434 i40e_get_swr_pm_cfg(struct i40e_hw *hw, uint32_t *value)
10436 #define I40E_GL_SWR_PM_EF_DEVICE(dev) \
10437 .device_id = (dev), \
10438 .val = I40E_GL_SWR_PM_UP_THR_EF_VALUE
10440 #define I40E_GL_SWR_PM_SF_DEVICE(dev) \
10441 .device_id = (dev), \
10442 .val = I40E_GL_SWR_PM_UP_THR_SF_VALUE
10444 static const struct {
10445 uint16_t device_id;
10447 } swr_pm_table[] = {
10448 { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_SFP_XL710) },
10449 { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_KX_C) },
10450 { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_10G_BASE_T) },
10451 { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_10G_BASE_T4) },
10452 { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_SFP_X722) },
10454 { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_KX_B) },
10455 { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_QSFP_A) },
10456 { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_QSFP_B) },
10457 { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_20G_KR2) },
10458 { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_20G_KR2_A) },
10459 { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_25G_B) },
10460 { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_25G_SFP28) },
10464 if (value == NULL) {
10465 PMD_DRV_LOG(ERR, "value is NULL");
10469 for (i = 0; i < RTE_DIM(swr_pm_table); i++) {
10470 if (hw->device_id == swr_pm_table[i].device_id) {
10471 *value = swr_pm_table[i].val;
10473 PMD_DRV_LOG(DEBUG, "Device 0x%x with GL_SWR_PM_UP_THR "
10475 hw->device_id, *value);
10484 i40e_dev_sync_phy_type(struct i40e_hw *hw)
10486 enum i40e_status_code status;
10487 struct i40e_aq_get_phy_abilities_resp phy_ab;
10488 int ret = -ENOTSUP;
10491 status = i40e_aq_get_phy_capabilities(hw, false, true, &phy_ab,
10495 PMD_INIT_LOG(WARNING, "Failed to sync phy type: status=%d",
10498 rte_delay_us(100000);
10500 status = i40e_aq_get_phy_capabilities(hw, false,
10501 true, &phy_ab, NULL);
10509 i40e_configure_registers(struct i40e_hw *hw)
10515 {I40E_GL_SWR_PRI_JOIN_MAP_0, 0},
10516 {I40E_GL_SWR_PRI_JOIN_MAP_2, 0},
10517 {I40E_GL_SWR_PM_UP_THR, 0}, /* Compute value dynamically */
10523 for (i = 0; i < RTE_DIM(reg_table); i++) {
10524 if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_0) {
10525 if (hw->mac.type == I40E_MAC_X722) /* For X722 */
10527 I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE;
10528 else /* For X710/XL710/XXV710 */
10529 if (hw->aq.fw_maj_ver < 6)
10531 I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1;
10534 I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2;
10537 if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_2) {
10538 if (hw->mac.type == I40E_MAC_X722) /* For X722 */
10540 I40E_X722_GL_SWR_PRI_JOIN_MAP_2_VALUE;
10541 else /* For X710/XL710/XXV710 */
10543 I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE;
10546 if (reg_table[i].addr == I40E_GL_SWR_PM_UP_THR) {
10549 if (!i40e_get_swr_pm_cfg(hw, &cfg_val)) {
10550 PMD_DRV_LOG(DEBUG, "Device 0x%x skips "
10551 "GL_SWR_PM_UP_THR value fixup",
10556 reg_table[i].val = cfg_val;
10559 ret = i40e_aq_debug_read_register(hw, reg_table[i].addr,
10562 PMD_DRV_LOG(ERR, "Failed to read from 0x%"PRIx32,
10563 reg_table[i].addr);
10566 PMD_DRV_LOG(DEBUG, "Read from 0x%"PRIx32": 0x%"PRIx64,
10567 reg_table[i].addr, reg);
10568 if (reg == reg_table[i].val)
10571 ret = i40e_aq_debug_write_register(hw, reg_table[i].addr,
10572 reg_table[i].val, NULL);
10575 "Failed to write 0x%"PRIx64" to the address of 0x%"PRIx32,
10576 reg_table[i].val, reg_table[i].addr);
10579 PMD_DRV_LOG(DEBUG, "Write 0x%"PRIx64" to the address of "
10580 "0x%"PRIx32, reg_table[i].val, reg_table[i].addr);
10584 #define I40E_VSI_TSR(_i) (0x00050800 + ((_i) * 4))
10585 #define I40E_VSI_TSR_QINQ_CONFIG 0xc030
10586 #define I40E_VSI_L2TAGSTXVALID(_i) (0x00042800 + ((_i) * 4))
10587 #define I40E_VSI_L2TAGSTXVALID_QINQ 0xab
10589 i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi)
10594 if (vsi->vsi_id >= I40E_MAX_NUM_VSIS) {
10595 PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
10599 /* Configure for double VLAN RX stripping */
10600 reg = I40E_READ_REG(hw, I40E_VSI_TSR(vsi->vsi_id));
10601 if ((reg & I40E_VSI_TSR_QINQ_CONFIG) != I40E_VSI_TSR_QINQ_CONFIG) {
10602 reg |= I40E_VSI_TSR_QINQ_CONFIG;
10603 ret = i40e_aq_debug_write_register(hw,
10604 I40E_VSI_TSR(vsi->vsi_id),
10607 PMD_DRV_LOG(ERR, "Failed to update VSI_TSR[%d]",
10609 return I40E_ERR_CONFIG;
10613 /* Configure for double VLAN TX insertion */
10614 reg = I40E_READ_REG(hw, I40E_VSI_L2TAGSTXVALID(vsi->vsi_id));
10615 if ((reg & 0xff) != I40E_VSI_L2TAGSTXVALID_QINQ) {
10616 reg = I40E_VSI_L2TAGSTXVALID_QINQ;
10617 ret = i40e_aq_debug_write_register(hw,
10618 I40E_VSI_L2TAGSTXVALID(
10619 vsi->vsi_id), reg, NULL);
10622 "Failed to update VSI_L2TAGSTXVALID[%d]",
10624 return I40E_ERR_CONFIG;
10632 * i40e_aq_add_mirror_rule
10633 * @hw: pointer to the hardware structure
10634 * @seid: VEB seid to add mirror rule to
10635 * @dst_id: destination vsi seid
10636 * @entries: Buffer which contains the entities to be mirrored
10637 * @count: number of entities contained in the buffer
10638 * @rule_id:the rule_id of the rule to be added
10640 * Add a mirror rule for a given veb.
10643 static enum i40e_status_code
10644 i40e_aq_add_mirror_rule(struct i40e_hw *hw,
10645 uint16_t seid, uint16_t dst_id,
10646 uint16_t rule_type, uint16_t *entries,
10647 uint16_t count, uint16_t *rule_id)
10649 struct i40e_aq_desc desc;
10650 struct i40e_aqc_add_delete_mirror_rule cmd;
10651 struct i40e_aqc_add_delete_mirror_rule_completion *resp =
10652 (struct i40e_aqc_add_delete_mirror_rule_completion *)
10655 enum i40e_status_code status;
10657 i40e_fill_default_direct_cmd_desc(&desc,
10658 i40e_aqc_opc_add_mirror_rule);
10659 memset(&cmd, 0, sizeof(cmd));
10661 buff_len = sizeof(uint16_t) * count;
10662 desc.datalen = rte_cpu_to_le_16(buff_len);
10664 desc.flags |= rte_cpu_to_le_16(
10665 (uint16_t)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
10666 cmd.rule_type = rte_cpu_to_le_16(rule_type <<
10667 I40E_AQC_MIRROR_RULE_TYPE_SHIFT);
10668 cmd.num_entries = rte_cpu_to_le_16(count);
10669 cmd.seid = rte_cpu_to_le_16(seid);
10670 cmd.destination = rte_cpu_to_le_16(dst_id);
10672 rte_memcpy(&desc.params.raw, &cmd, sizeof(cmd));
10673 status = i40e_asq_send_command(hw, &desc, entries, buff_len, NULL);
10675 "i40e_aq_add_mirror_rule, aq_status %d, rule_id = %u mirror_rules_used = %u, mirror_rules_free = %u,",
10676 hw->aq.asq_last_status, resp->rule_id,
10677 resp->mirror_rules_used, resp->mirror_rules_free);
10678 *rule_id = rte_le_to_cpu_16(resp->rule_id);
10684 * i40e_aq_del_mirror_rule
10685 * @hw: pointer to the hardware structure
10686 * @seid: VEB seid to add mirror rule to
10687 * @entries: Buffer which contains the entities to be mirrored
10688 * @count: number of entities contained in the buffer
10689 * @rule_id:the rule_id of the rule to be delete
10691 * Delete a mirror rule for a given veb.
10694 static enum i40e_status_code
10695 i40e_aq_del_mirror_rule(struct i40e_hw *hw,
10696 uint16_t seid, uint16_t rule_type, uint16_t *entries,
10697 uint16_t count, uint16_t rule_id)
10699 struct i40e_aq_desc desc;
10700 struct i40e_aqc_add_delete_mirror_rule cmd;
10701 uint16_t buff_len = 0;
10702 enum i40e_status_code status;
10705 i40e_fill_default_direct_cmd_desc(&desc,
10706 i40e_aqc_opc_delete_mirror_rule);
10707 memset(&cmd, 0, sizeof(cmd));
10708 if (rule_type == I40E_AQC_MIRROR_RULE_TYPE_VLAN) {
10709 desc.flags |= rte_cpu_to_le_16((uint16_t)(I40E_AQ_FLAG_BUF |
10711 cmd.num_entries = count;
10712 buff_len = sizeof(uint16_t) * count;
10713 desc.datalen = rte_cpu_to_le_16(buff_len);
10714 buff = (void *)entries;
10716 /* rule id is filled in destination field for deleting mirror rule */
10717 cmd.destination = rte_cpu_to_le_16(rule_id);
10719 cmd.rule_type = rte_cpu_to_le_16(rule_type <<
10720 I40E_AQC_MIRROR_RULE_TYPE_SHIFT);
10721 cmd.seid = rte_cpu_to_le_16(seid);
10723 rte_memcpy(&desc.params.raw, &cmd, sizeof(cmd));
10724 status = i40e_asq_send_command(hw, &desc, buff, buff_len, NULL);
10730 * i40e_mirror_rule_set
10731 * @dev: pointer to the hardware structure
10732 * @mirror_conf: mirror rule info
10733 * @sw_id: mirror rule's sw_id
10734 * @on: enable/disable
10736 * set a mirror rule.
10740 i40e_mirror_rule_set(struct rte_eth_dev *dev,
10741 struct rte_eth_mirror_conf *mirror_conf,
10742 uint8_t sw_id, uint8_t on)
10744 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
10745 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10746 struct i40e_mirror_rule *it, *mirr_rule = NULL;
10747 struct i40e_mirror_rule *parent = NULL;
10748 uint16_t seid, dst_seid, rule_id;
10752 PMD_DRV_LOG(DEBUG, "i40e_mirror_rule_set: sw_id = %d.", sw_id);
10754 if (pf->main_vsi->veb == NULL || pf->vfs == NULL) {
10756 "mirror rule can not be configured without veb or vfs.");
10759 if (pf->nb_mirror_rule > I40E_MAX_MIRROR_RULES) {
10760 PMD_DRV_LOG(ERR, "mirror table is full.");
10763 if (mirror_conf->dst_pool > pf->vf_num) {
10764 PMD_DRV_LOG(ERR, "invalid destination pool %u.",
10765 mirror_conf->dst_pool);
10769 seid = pf->main_vsi->veb->seid;
10771 TAILQ_FOREACH(it, &pf->mirror_list, rules) {
10772 if (sw_id <= it->index) {
10778 if (mirr_rule && sw_id == mirr_rule->index) {
10780 PMD_DRV_LOG(ERR, "mirror rule exists.");
10783 ret = i40e_aq_del_mirror_rule(hw, seid,
10784 mirr_rule->rule_type,
10785 mirr_rule->entries,
10786 mirr_rule->num_entries, mirr_rule->id);
10789 "failed to remove mirror rule: ret = %d, aq_err = %d.",
10790 ret, hw->aq.asq_last_status);
10793 TAILQ_REMOVE(&pf->mirror_list, mirr_rule, rules);
10794 rte_free(mirr_rule);
10795 pf->nb_mirror_rule--;
10799 PMD_DRV_LOG(ERR, "mirror rule doesn't exist.");
10803 mirr_rule = rte_zmalloc("i40e_mirror_rule",
10804 sizeof(struct i40e_mirror_rule) , 0);
10806 PMD_DRV_LOG(ERR, "failed to allocate memory");
10807 return I40E_ERR_NO_MEMORY;
10809 switch (mirror_conf->rule_type) {
10810 case ETH_MIRROR_VLAN:
10811 for (i = 0, j = 0; i < ETH_MIRROR_MAX_VLANS; i++) {
10812 if (mirror_conf->vlan.vlan_mask & (1ULL << i)) {
10813 mirr_rule->entries[j] =
10814 mirror_conf->vlan.vlan_id[i];
10819 PMD_DRV_LOG(ERR, "vlan is not specified.");
10820 rte_free(mirr_rule);
10823 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_VLAN;
10825 case ETH_MIRROR_VIRTUAL_POOL_UP:
10826 case ETH_MIRROR_VIRTUAL_POOL_DOWN:
10827 /* check if the specified pool bit is out of range */
10828 if (mirror_conf->pool_mask > (uint64_t)(1ULL << (pf->vf_num + 1))) {
10829 PMD_DRV_LOG(ERR, "pool mask is out of range.");
10830 rte_free(mirr_rule);
10833 for (i = 0, j = 0; i < pf->vf_num; i++) {
10834 if (mirror_conf->pool_mask & (1ULL << i)) {
10835 mirr_rule->entries[j] = pf->vfs[i].vsi->seid;
10839 if (mirror_conf->pool_mask & (1ULL << pf->vf_num)) {
10840 /* add pf vsi to entries */
10841 mirr_rule->entries[j] = pf->main_vsi_seid;
10845 PMD_DRV_LOG(ERR, "pool is not specified.");
10846 rte_free(mirr_rule);
10849 /* egress and ingress in aq commands means from switch but not port */
10850 mirr_rule->rule_type =
10851 (mirror_conf->rule_type == ETH_MIRROR_VIRTUAL_POOL_UP) ?
10852 I40E_AQC_MIRROR_RULE_TYPE_VPORT_EGRESS :
10853 I40E_AQC_MIRROR_RULE_TYPE_VPORT_INGRESS;
10855 case ETH_MIRROR_UPLINK_PORT:
10856 /* egress and ingress in aq commands means from switch but not port*/
10857 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_ALL_EGRESS;
10859 case ETH_MIRROR_DOWNLINK_PORT:
10860 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_ALL_INGRESS;
10863 PMD_DRV_LOG(ERR, "unsupported mirror type %d.",
10864 mirror_conf->rule_type);
10865 rte_free(mirr_rule);
10869 /* If the dst_pool is equal to vf_num, consider it as PF */
10870 if (mirror_conf->dst_pool == pf->vf_num)
10871 dst_seid = pf->main_vsi_seid;
10873 dst_seid = pf->vfs[mirror_conf->dst_pool].vsi->seid;
10875 ret = i40e_aq_add_mirror_rule(hw, seid, dst_seid,
10876 mirr_rule->rule_type, mirr_rule->entries,
10880 "failed to add mirror rule: ret = %d, aq_err = %d.",
10881 ret, hw->aq.asq_last_status);
10882 rte_free(mirr_rule);
10886 mirr_rule->index = sw_id;
10887 mirr_rule->num_entries = j;
10888 mirr_rule->id = rule_id;
10889 mirr_rule->dst_vsi_seid = dst_seid;
10892 TAILQ_INSERT_AFTER(&pf->mirror_list, parent, mirr_rule, rules);
10894 TAILQ_INSERT_HEAD(&pf->mirror_list, mirr_rule, rules);
10896 pf->nb_mirror_rule++;
10901 * i40e_mirror_rule_reset
10902 * @dev: pointer to the device
10903 * @sw_id: mirror rule's sw_id
10905 * reset a mirror rule.
10909 i40e_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t sw_id)
10911 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
10912 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10913 struct i40e_mirror_rule *it, *mirr_rule = NULL;
10917 PMD_DRV_LOG(DEBUG, "i40e_mirror_rule_reset: sw_id = %d.", sw_id);
10919 seid = pf->main_vsi->veb->seid;
10921 TAILQ_FOREACH(it, &pf->mirror_list, rules) {
10922 if (sw_id == it->index) {
10928 ret = i40e_aq_del_mirror_rule(hw, seid,
10929 mirr_rule->rule_type,
10930 mirr_rule->entries,
10931 mirr_rule->num_entries, mirr_rule->id);
10934 "failed to remove mirror rule: status = %d, aq_err = %d.",
10935 ret, hw->aq.asq_last_status);
10938 TAILQ_REMOVE(&pf->mirror_list, mirr_rule, rules);
10939 rte_free(mirr_rule);
10940 pf->nb_mirror_rule--;
10942 PMD_DRV_LOG(ERR, "mirror rule doesn't exist.");
10949 i40e_read_systime_cyclecounter(struct rte_eth_dev *dev)
10951 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10952 uint64_t systim_cycles;
10954 systim_cycles = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_L);
10955 systim_cycles |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_H)
10958 return systim_cycles;
10962 i40e_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev, uint8_t index)
10964 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10965 uint64_t rx_tstamp;
10967 rx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_L(index));
10968 rx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(index))
10975 i40e_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
10977 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10978 uint64_t tx_tstamp;
10980 tx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_L);
10981 tx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H)
10988 i40e_start_timecounters(struct rte_eth_dev *dev)
10990 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10991 struct i40e_adapter *adapter = dev->data->dev_private;
10992 struct rte_eth_link link;
10993 uint32_t tsync_inc_l;
10994 uint32_t tsync_inc_h;
10996 /* Get current link speed. */
10997 i40e_dev_link_update(dev, 1);
10998 rte_eth_linkstatus_get(dev, &link);
11000 switch (link.link_speed) {
11001 case ETH_SPEED_NUM_40G:
11002 case ETH_SPEED_NUM_25G:
11003 tsync_inc_l = I40E_PTP_40GB_INCVAL & 0xFFFFFFFF;
11004 tsync_inc_h = I40E_PTP_40GB_INCVAL >> 32;
11006 case ETH_SPEED_NUM_10G:
11007 tsync_inc_l = I40E_PTP_10GB_INCVAL & 0xFFFFFFFF;
11008 tsync_inc_h = I40E_PTP_10GB_INCVAL >> 32;
11010 case ETH_SPEED_NUM_1G:
11011 tsync_inc_l = I40E_PTP_1GB_INCVAL & 0xFFFFFFFF;
11012 tsync_inc_h = I40E_PTP_1GB_INCVAL >> 32;
11019 /* Set the timesync increment value. */
11020 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, tsync_inc_l);
11021 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, tsync_inc_h);
11023 memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
11024 memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
11025 memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
11027 adapter->systime_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
11028 adapter->systime_tc.cc_shift = 0;
11029 adapter->systime_tc.nsec_mask = 0;
11031 adapter->rx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
11032 adapter->rx_tstamp_tc.cc_shift = 0;
11033 adapter->rx_tstamp_tc.nsec_mask = 0;
11035 adapter->tx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
11036 adapter->tx_tstamp_tc.cc_shift = 0;
11037 adapter->tx_tstamp_tc.nsec_mask = 0;
11041 i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
11043 struct i40e_adapter *adapter = dev->data->dev_private;
11045 adapter->systime_tc.nsec += delta;
11046 adapter->rx_tstamp_tc.nsec += delta;
11047 adapter->tx_tstamp_tc.nsec += delta;
11053 i40e_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
11056 struct i40e_adapter *adapter = dev->data->dev_private;
11058 ns = rte_timespec_to_ns(ts);
11060 /* Set the timecounters to a new value. */
11061 adapter->systime_tc.nsec = ns;
11062 adapter->rx_tstamp_tc.nsec = ns;
11063 adapter->tx_tstamp_tc.nsec = ns;
11069 i40e_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
11071 uint64_t ns, systime_cycles;
11072 struct i40e_adapter *adapter = dev->data->dev_private;
11074 systime_cycles = i40e_read_systime_cyclecounter(dev);
11075 ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
11076 *ts = rte_ns_to_timespec(ns);
11082 i40e_timesync_enable(struct rte_eth_dev *dev)
11084 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11085 uint32_t tsync_ctl_l;
11086 uint32_t tsync_ctl_h;
11088 /* Stop the timesync system time. */
11089 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
11090 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
11091 /* Reset the timesync system time value. */
11092 I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_L, 0x0);
11093 I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_H, 0x0);
11095 i40e_start_timecounters(dev);
11097 /* Clear timesync registers. */
11098 I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
11099 I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H);
11100 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(0));
11101 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(1));
11102 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(2));
11103 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(3));
11105 /* Enable timestamping of PTP packets. */
11106 tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
11107 tsync_ctl_l |= I40E_PRTTSYN_TSYNENA;
11109 tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
11110 tsync_ctl_h |= I40E_PRTTSYN_TSYNENA;
11111 tsync_ctl_h |= I40E_PRTTSYN_TSYNTYPE;
11113 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
11114 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
11120 i40e_timesync_disable(struct rte_eth_dev *dev)
11122 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11123 uint32_t tsync_ctl_l;
11124 uint32_t tsync_ctl_h;
11126 /* Disable timestamping of transmitted PTP packets. */
11127 tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
11128 tsync_ctl_l &= ~I40E_PRTTSYN_TSYNENA;
11130 tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
11131 tsync_ctl_h &= ~I40E_PRTTSYN_TSYNENA;
11133 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
11134 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
11136 /* Reset the timesync increment value. */
11137 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
11138 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
11144 i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
11145 struct timespec *timestamp, uint32_t flags)
11147 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11148 struct i40e_adapter *adapter = dev->data->dev_private;
11149 uint32_t sync_status;
11150 uint32_t index = flags & 0x03;
11151 uint64_t rx_tstamp_cycles;
11154 sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_1);
11155 if ((sync_status & (1 << index)) == 0)
11158 rx_tstamp_cycles = i40e_read_rx_tstamp_cyclecounter(dev, index);
11159 ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
11160 *timestamp = rte_ns_to_timespec(ns);
11166 i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
11167 struct timespec *timestamp)
11169 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11170 struct i40e_adapter *adapter = dev->data->dev_private;
11171 uint32_t sync_status;
11172 uint64_t tx_tstamp_cycles;
11175 sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
11176 if ((sync_status & I40E_PRTTSYN_STAT_0_TXTIME_MASK) == 0)
11179 tx_tstamp_cycles = i40e_read_tx_tstamp_cyclecounter(dev);
11180 ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
11181 *timestamp = rte_ns_to_timespec(ns);
11187 * i40e_parse_dcb_configure - parse dcb configure from user
11188 * @dev: the device being configured
11189 * @dcb_cfg: pointer of the result of parse
11190 * @*tc_map: bit map of enabled traffic classes
11192 * Returns 0 on success, negative value on failure
11195 i40e_parse_dcb_configure(struct rte_eth_dev *dev,
11196 struct i40e_dcbx_config *dcb_cfg,
11199 struct rte_eth_dcb_rx_conf *dcb_rx_conf;
11200 uint8_t i, tc_bw, bw_lf;
11202 memset(dcb_cfg, 0, sizeof(struct i40e_dcbx_config));
11204 dcb_rx_conf = &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
11205 if (dcb_rx_conf->nb_tcs > I40E_MAX_TRAFFIC_CLASS) {
11206 PMD_INIT_LOG(ERR, "number of tc exceeds max.");
11210 /* assume each tc has the same bw */
11211 tc_bw = I40E_MAX_PERCENT / dcb_rx_conf->nb_tcs;
11212 for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
11213 dcb_cfg->etscfg.tcbwtable[i] = tc_bw;
11214 /* to ensure the sum of tcbw is equal to 100 */
11215 bw_lf = I40E_MAX_PERCENT % dcb_rx_conf->nb_tcs;
11216 for (i = 0; i < bw_lf; i++)
11217 dcb_cfg->etscfg.tcbwtable[i]++;
11219 /* assume each tc has the same Transmission Selection Algorithm */
11220 for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
11221 dcb_cfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
11223 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
11224 dcb_cfg->etscfg.prioritytable[i] =
11225 dcb_rx_conf->dcb_tc[i];
11227 /* FW needs one App to configure HW */
11228 dcb_cfg->numapps = I40E_DEFAULT_DCB_APP_NUM;
11229 dcb_cfg->app[0].selector = I40E_APP_SEL_ETHTYPE;
11230 dcb_cfg->app[0].priority = I40E_DEFAULT_DCB_APP_PRIO;
11231 dcb_cfg->app[0].protocolid = I40E_APP_PROTOID_FCOE;
11233 if (dcb_rx_conf->nb_tcs == 0)
11234 *tc_map = 1; /* tc0 only */
11236 *tc_map = RTE_LEN2MASK(dcb_rx_conf->nb_tcs, uint8_t);
11238 if (dev->data->dev_conf.dcb_capability_en & ETH_DCB_PFC_SUPPORT) {
11239 dcb_cfg->pfc.willing = 0;
11240 dcb_cfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
11241 dcb_cfg->pfc.pfcenable = *tc_map;
11247 static enum i40e_status_code
11248 i40e_vsi_update_queue_mapping(struct i40e_vsi *vsi,
11249 struct i40e_aqc_vsi_properties_data *info,
11250 uint8_t enabled_tcmap)
11252 enum i40e_status_code ret;
11253 int i, total_tc = 0;
11254 uint16_t qpnum_per_tc, bsf, qp_idx;
11255 struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(vsi);
11256 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
11257 uint16_t used_queues;
11259 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
11260 if (ret != I40E_SUCCESS)
11263 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11264 if (enabled_tcmap & (1 << i))
11269 vsi->enabled_tc = enabled_tcmap;
11271 /* different VSI has different queues assigned */
11272 if (vsi->type == I40E_VSI_MAIN)
11273 used_queues = dev_data->nb_rx_queues -
11274 pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
11275 else if (vsi->type == I40E_VSI_VMDQ2)
11276 used_queues = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
11278 PMD_INIT_LOG(ERR, "unsupported VSI type.");
11279 return I40E_ERR_NO_AVAILABLE_VSI;
11282 qpnum_per_tc = used_queues / total_tc;
11283 /* Number of queues per enabled TC */
11284 if (qpnum_per_tc == 0) {
11285 PMD_INIT_LOG(ERR, " number of queues is less that tcs.");
11286 return I40E_ERR_INVALID_QP_ID;
11288 qpnum_per_tc = RTE_MIN(i40e_align_floor(qpnum_per_tc),
11289 I40E_MAX_Q_PER_TC);
11290 bsf = rte_bsf32(qpnum_per_tc);
11293 * Configure TC and queue mapping parameters, for enabled TC,
11294 * allocate qpnum_per_tc queues to this traffic. For disabled TC,
11295 * default queue will serve it.
11298 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11299 if (vsi->enabled_tc & (1 << i)) {
11300 info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
11301 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
11302 (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
11303 qp_idx += qpnum_per_tc;
11305 info->tc_mapping[i] = 0;
11308 /* Associate queue number with VSI, Keep vsi->nb_qps unchanged */
11309 if (vsi->type == I40E_VSI_SRIOV) {
11310 info->mapping_flags |=
11311 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
11312 for (i = 0; i < vsi->nb_qps; i++)
11313 info->queue_mapping[i] =
11314 rte_cpu_to_le_16(vsi->base_queue + i);
11316 info->mapping_flags |=
11317 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
11318 info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
11320 info->valid_sections |=
11321 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
11323 return I40E_SUCCESS;
11327 * i40e_config_switch_comp_tc - Configure VEB tc setting for given TC map
11328 * @veb: VEB to be configured
11329 * @tc_map: enabled TC bitmap
11331 * Returns 0 on success, negative value on failure
11333 static enum i40e_status_code
11334 i40e_config_switch_comp_tc(struct i40e_veb *veb, uint8_t tc_map)
11336 struct i40e_aqc_configure_switching_comp_bw_config_data veb_bw;
11337 struct i40e_aqc_query_switching_comp_bw_config_resp bw_query;
11338 struct i40e_aqc_query_switching_comp_ets_config_resp ets_query;
11339 struct i40e_hw *hw = I40E_VSI_TO_HW(veb->associate_vsi);
11340 enum i40e_status_code ret = I40E_SUCCESS;
11344 /* Check if enabled_tc is same as existing or new TCs */
11345 if (veb->enabled_tc == tc_map)
11348 /* configure tc bandwidth */
11349 memset(&veb_bw, 0, sizeof(veb_bw));
11350 veb_bw.tc_valid_bits = tc_map;
11351 /* Enable ETS TCs with equal BW Share for now across all VSIs */
11352 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11353 if (tc_map & BIT_ULL(i))
11354 veb_bw.tc_bw_share_credits[i] = 1;
11356 ret = i40e_aq_config_switch_comp_bw_config(hw, veb->seid,
11360 "AQ command Config switch_comp BW allocation per TC failed = %d",
11361 hw->aq.asq_last_status);
11365 memset(&ets_query, 0, sizeof(ets_query));
11366 ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
11368 if (ret != I40E_SUCCESS) {
11370 "Failed to get switch_comp ETS configuration %u",
11371 hw->aq.asq_last_status);
11374 memset(&bw_query, 0, sizeof(bw_query));
11375 ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
11377 if (ret != I40E_SUCCESS) {
11379 "Failed to get switch_comp bandwidth configuration %u",
11380 hw->aq.asq_last_status);
11384 /* store and print out BW info */
11385 veb->bw_info.bw_limit = rte_le_to_cpu_16(ets_query.port_bw_limit);
11386 veb->bw_info.bw_max = ets_query.tc_bw_max;
11387 PMD_DRV_LOG(DEBUG, "switch_comp bw limit:%u", veb->bw_info.bw_limit);
11388 PMD_DRV_LOG(DEBUG, "switch_comp max_bw:%u", veb->bw_info.bw_max);
11389 bw_max = rte_le_to_cpu_16(bw_query.tc_bw_max[0]) |
11390 (rte_le_to_cpu_16(bw_query.tc_bw_max[1]) <<
11391 I40E_16_BIT_WIDTH);
11392 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11393 veb->bw_info.bw_ets_share_credits[i] =
11394 bw_query.tc_bw_share_credits[i];
11395 veb->bw_info.bw_ets_credits[i] =
11396 rte_le_to_cpu_16(bw_query.tc_bw_limits[i]);
11397 /* 4 bits per TC, 4th bit is reserved */
11398 veb->bw_info.bw_ets_max[i] =
11399 (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
11400 RTE_LEN2MASK(3, uint8_t));
11401 PMD_DRV_LOG(DEBUG, "\tVEB TC%u:share credits %u", i,
11402 veb->bw_info.bw_ets_share_credits[i]);
11403 PMD_DRV_LOG(DEBUG, "\tVEB TC%u:credits %u", i,
11404 veb->bw_info.bw_ets_credits[i]);
11405 PMD_DRV_LOG(DEBUG, "\tVEB TC%u: max credits: %u", i,
11406 veb->bw_info.bw_ets_max[i]);
11409 veb->enabled_tc = tc_map;
11416 * i40e_vsi_config_tc - Configure VSI tc setting for given TC map
11417 * @vsi: VSI to be configured
11418 * @tc_map: enabled TC bitmap
11420 * Returns 0 on success, negative value on failure
11422 static enum i40e_status_code
11423 i40e_vsi_config_tc(struct i40e_vsi *vsi, uint8_t tc_map)
11425 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
11426 struct i40e_vsi_context ctxt;
11427 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
11428 enum i40e_status_code ret = I40E_SUCCESS;
11431 /* Check if enabled_tc is same as existing or new TCs */
11432 if (vsi->enabled_tc == tc_map)
11435 /* configure tc bandwidth */
11436 memset(&bw_data, 0, sizeof(bw_data));
11437 bw_data.tc_valid_bits = tc_map;
11438 /* Enable ETS TCs with equal BW Share for now across all VSIs */
11439 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11440 if (tc_map & BIT_ULL(i))
11441 bw_data.tc_bw_credits[i] = 1;
11443 ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &bw_data, NULL);
11446 "AQ command Config VSI BW allocation per TC failed = %d",
11447 hw->aq.asq_last_status);
11450 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
11451 vsi->info.qs_handle[i] = bw_data.qs_handles[i];
11453 /* Update Queue Pairs Mapping for currently enabled UPs */
11454 ctxt.seid = vsi->seid;
11455 ctxt.pf_num = hw->pf_id;
11457 ctxt.uplink_seid = vsi->uplink_seid;
11458 ctxt.info = vsi->info;
11460 ret = i40e_vsi_update_queue_mapping(vsi, &ctxt.info, tc_map);
11464 /* Update the VSI after updating the VSI queue-mapping information */
11465 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
11467 PMD_INIT_LOG(ERR, "Failed to configure TC queue mapping = %d",
11468 hw->aq.asq_last_status);
11471 /* update the local VSI info with updated queue map */
11472 rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
11473 sizeof(vsi->info.tc_mapping));
11474 rte_memcpy(&vsi->info.queue_mapping,
11475 &ctxt.info.queue_mapping,
11476 sizeof(vsi->info.queue_mapping));
11477 vsi->info.mapping_flags = ctxt.info.mapping_flags;
11478 vsi->info.valid_sections = 0;
11480 /* query and update current VSI BW information */
11481 ret = i40e_vsi_get_bw_config(vsi);
11484 "Failed updating vsi bw info, err %s aq_err %s",
11485 i40e_stat_str(hw, ret),
11486 i40e_aq_str(hw, hw->aq.asq_last_status));
11490 vsi->enabled_tc = tc_map;
11497 * i40e_dcb_hw_configure - program the dcb setting to hw
11498 * @pf: pf the configuration is taken on
11499 * @new_cfg: new configuration
11500 * @tc_map: enabled TC bitmap
11502 * Returns 0 on success, negative value on failure
11504 static enum i40e_status_code
11505 i40e_dcb_hw_configure(struct i40e_pf *pf,
11506 struct i40e_dcbx_config *new_cfg,
11509 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11510 struct i40e_dcbx_config *old_cfg = &hw->local_dcbx_config;
11511 struct i40e_vsi *main_vsi = pf->main_vsi;
11512 struct i40e_vsi_list *vsi_list;
11513 enum i40e_status_code ret;
11517 /* Use the FW API if FW > v4.4*/
11518 if (!(((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver >= 4)) ||
11519 (hw->aq.fw_maj_ver >= 5))) {
11521 "FW < v4.4, can not use FW LLDP API to configure DCB");
11522 return I40E_ERR_FIRMWARE_API_VERSION;
11525 /* Check if need reconfiguration */
11526 if (!memcmp(new_cfg, old_cfg, sizeof(struct i40e_dcbx_config))) {
11527 PMD_INIT_LOG(ERR, "No Change in DCB Config required.");
11528 return I40E_SUCCESS;
11531 /* Copy the new config to the current config */
11532 *old_cfg = *new_cfg;
11533 old_cfg->etsrec = old_cfg->etscfg;
11534 ret = i40e_set_dcb_config(hw);
11536 PMD_INIT_LOG(ERR, "Set DCB Config failed, err %s aq_err %s",
11537 i40e_stat_str(hw, ret),
11538 i40e_aq_str(hw, hw->aq.asq_last_status));
11541 /* set receive Arbiter to RR mode and ETS scheme by default */
11542 for (i = 0; i <= I40E_PRTDCB_RETSTCC_MAX_INDEX; i++) {
11543 val = I40E_READ_REG(hw, I40E_PRTDCB_RETSTCC(i));
11544 val &= ~(I40E_PRTDCB_RETSTCC_BWSHARE_MASK |
11545 I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK |
11546 I40E_PRTDCB_RETSTCC_ETSTC_SHIFT);
11547 val |= ((uint32_t)old_cfg->etscfg.tcbwtable[i] <<
11548 I40E_PRTDCB_RETSTCC_BWSHARE_SHIFT) &
11549 I40E_PRTDCB_RETSTCC_BWSHARE_MASK;
11550 val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_UPINTC_MODE_SHIFT) &
11551 I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK;
11552 val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_ETSTC_SHIFT) &
11553 I40E_PRTDCB_RETSTCC_ETSTC_MASK;
11554 I40E_WRITE_REG(hw, I40E_PRTDCB_RETSTCC(i), val);
11556 /* get local mib to check whether it is configured correctly */
11558 hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_IEEE;
11559 /* Get Local DCB Config */
11560 i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
11561 &hw->local_dcbx_config);
11563 /* if Veb is created, need to update TC of it at first */
11564 if (main_vsi->veb) {
11565 ret = i40e_config_switch_comp_tc(main_vsi->veb, tc_map);
11567 PMD_INIT_LOG(WARNING,
11568 "Failed configuring TC for VEB seid=%d",
11569 main_vsi->veb->seid);
11571 /* Update each VSI */
11572 i40e_vsi_config_tc(main_vsi, tc_map);
11573 if (main_vsi->veb) {
11574 TAILQ_FOREACH(vsi_list, &main_vsi->veb->head, list) {
11575 /* Beside main VSI and VMDQ VSIs, only enable default
11576 * TC for other VSIs
11578 if (vsi_list->vsi->type == I40E_VSI_VMDQ2)
11579 ret = i40e_vsi_config_tc(vsi_list->vsi,
11582 ret = i40e_vsi_config_tc(vsi_list->vsi,
11583 I40E_DEFAULT_TCMAP);
11585 PMD_INIT_LOG(WARNING,
11586 "Failed configuring TC for VSI seid=%d",
11587 vsi_list->vsi->seid);
11591 return I40E_SUCCESS;
11595 * i40e_dcb_init_configure - initial dcb config
11596 * @dev: device being configured
11597 * @sw_dcb: indicate whether dcb is sw configured or hw offload
11599 * Returns 0 on success, negative value on failure
11602 i40e_dcb_init_configure(struct rte_eth_dev *dev, bool sw_dcb)
11604 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11605 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11608 if ((pf->flags & I40E_FLAG_DCB) == 0) {
11609 PMD_INIT_LOG(ERR, "HW doesn't support DCB");
11613 /* DCB initialization:
11614 * Update DCB configuration from the Firmware and configure
11615 * LLDP MIB change event.
11617 if (sw_dcb == TRUE) {
11618 /* Stopping lldp is necessary for DPDK, but it will cause
11619 * DCB init failed. For i40e_init_dcb(), the prerequisite
11620 * for successful initialization of DCB is that LLDP is
11621 * enabled. So it is needed to start lldp before DCB init
11622 * and stop it after initialization.
11624 ret = i40e_aq_start_lldp(hw, true, NULL);
11625 if (ret != I40E_SUCCESS)
11626 PMD_INIT_LOG(DEBUG, "Failed to start lldp");
11628 ret = i40e_init_dcb(hw, true);
11629 /* If lldp agent is stopped, the return value from
11630 * i40e_init_dcb we expect is failure with I40E_AQ_RC_EPERM
11631 * adminq status. Otherwise, it should return success.
11633 if ((ret == I40E_SUCCESS) || (ret != I40E_SUCCESS &&
11634 hw->aq.asq_last_status == I40E_AQ_RC_EPERM)) {
11635 memset(&hw->local_dcbx_config, 0,
11636 sizeof(struct i40e_dcbx_config));
11637 /* set dcb default configuration */
11638 hw->local_dcbx_config.etscfg.willing = 0;
11639 hw->local_dcbx_config.etscfg.maxtcs = 0;
11640 hw->local_dcbx_config.etscfg.tcbwtable[0] = 100;
11641 hw->local_dcbx_config.etscfg.tsatable[0] =
11643 /* all UPs mapping to TC0 */
11644 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
11645 hw->local_dcbx_config.etscfg.prioritytable[i] = 0;
11646 hw->local_dcbx_config.etsrec =
11647 hw->local_dcbx_config.etscfg;
11648 hw->local_dcbx_config.pfc.willing = 0;
11649 hw->local_dcbx_config.pfc.pfccap =
11650 I40E_MAX_TRAFFIC_CLASS;
11651 /* FW needs one App to configure HW */
11652 hw->local_dcbx_config.numapps = 1;
11653 hw->local_dcbx_config.app[0].selector =
11654 I40E_APP_SEL_ETHTYPE;
11655 hw->local_dcbx_config.app[0].priority = 3;
11656 hw->local_dcbx_config.app[0].protocolid =
11657 I40E_APP_PROTOID_FCOE;
11658 ret = i40e_set_dcb_config(hw);
11661 "default dcb config fails. err = %d, aq_err = %d.",
11662 ret, hw->aq.asq_last_status);
11667 "DCB initialization in FW fails, err = %d, aq_err = %d.",
11668 ret, hw->aq.asq_last_status);
11672 if (i40e_need_stop_lldp(dev)) {
11673 ret = i40e_aq_stop_lldp(hw, true, true, NULL);
11674 if (ret != I40E_SUCCESS)
11675 PMD_INIT_LOG(DEBUG, "Failed to stop lldp");
11678 ret = i40e_aq_start_lldp(hw, true, NULL);
11679 if (ret != I40E_SUCCESS)
11680 PMD_INIT_LOG(DEBUG, "Failed to start lldp");
11682 ret = i40e_init_dcb(hw, true);
11684 if (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED) {
11686 "HW doesn't support DCBX offload.");
11691 "DCBX configuration failed, err = %d, aq_err = %d.",
11692 ret, hw->aq.asq_last_status);
11700 * i40e_dcb_setup - setup dcb related config
11701 * @dev: device being configured
11703 * Returns 0 on success, negative value on failure
11706 i40e_dcb_setup(struct rte_eth_dev *dev)
11708 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11709 struct i40e_dcbx_config dcb_cfg;
11710 uint8_t tc_map = 0;
11713 if ((pf->flags & I40E_FLAG_DCB) == 0) {
11714 PMD_INIT_LOG(ERR, "HW doesn't support DCB");
11718 if (pf->vf_num != 0)
11719 PMD_INIT_LOG(DEBUG, " DCB only works on pf and vmdq vsis.");
11721 ret = i40e_parse_dcb_configure(dev, &dcb_cfg, &tc_map);
11723 PMD_INIT_LOG(ERR, "invalid dcb config");
11726 ret = i40e_dcb_hw_configure(pf, &dcb_cfg, tc_map);
11728 PMD_INIT_LOG(ERR, "dcb sw configure fails");
11736 i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
11737 struct rte_eth_dcb_info *dcb_info)
11739 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11740 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11741 struct i40e_vsi *vsi = pf->main_vsi;
11742 struct i40e_dcbx_config *dcb_cfg = &hw->local_dcbx_config;
11743 uint16_t bsf, tc_mapping;
11746 if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_DCB_FLAG)
11747 dcb_info->nb_tcs = rte_bsf32(vsi->enabled_tc + 1);
11749 dcb_info->nb_tcs = 1;
11750 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
11751 dcb_info->prio_tc[i] = dcb_cfg->etscfg.prioritytable[i];
11752 for (i = 0; i < dcb_info->nb_tcs; i++)
11753 dcb_info->tc_bws[i] = dcb_cfg->etscfg.tcbwtable[i];
11755 /* get queue mapping if vmdq is disabled */
11756 if (!pf->nb_cfg_vmdq_vsi) {
11757 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11758 if (!(vsi->enabled_tc & (1 << i)))
11760 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
11761 dcb_info->tc_queue.tc_rxq[j][i].base =
11762 (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
11763 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
11764 dcb_info->tc_queue.tc_txq[j][i].base =
11765 dcb_info->tc_queue.tc_rxq[j][i].base;
11766 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
11767 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
11768 dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
11769 dcb_info->tc_queue.tc_txq[j][i].nb_queue =
11770 dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
11775 /* get queue mapping if vmdq is enabled */
11777 vsi = pf->vmdq[j].vsi;
11778 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11779 if (!(vsi->enabled_tc & (1 << i)))
11781 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
11782 dcb_info->tc_queue.tc_rxq[j][i].base =
11783 (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
11784 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
11785 dcb_info->tc_queue.tc_txq[j][i].base =
11786 dcb_info->tc_queue.tc_rxq[j][i].base;
11787 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
11788 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
11789 dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
11790 dcb_info->tc_queue.tc_txq[j][i].nb_queue =
11791 dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
11794 } while (j < RTE_MIN(pf->nb_cfg_vmdq_vsi, ETH_MAX_VMDQ_POOL));
11799 i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
11801 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
11802 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
11803 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11804 uint16_t msix_intr;
11806 msix_intr = intr_handle->intr_vec[queue_id];
11807 if (msix_intr == I40E_MISC_VEC_ID)
11808 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
11809 I40E_PFINT_DYN_CTL0_INTENA_MASK |
11810 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
11811 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
11814 I40E_PFINT_DYN_CTLN(msix_intr -
11815 I40E_RX_VEC_START),
11816 I40E_PFINT_DYN_CTLN_INTENA_MASK |
11817 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
11818 I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
11820 I40E_WRITE_FLUSH(hw);
11821 rte_intr_ack(&pci_dev->intr_handle);
11827 i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
11829 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
11830 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
11831 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11832 uint16_t msix_intr;
11834 msix_intr = intr_handle->intr_vec[queue_id];
11835 if (msix_intr == I40E_MISC_VEC_ID)
11836 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
11837 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
11840 I40E_PFINT_DYN_CTLN(msix_intr -
11841 I40E_RX_VEC_START),
11842 I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
11843 I40E_WRITE_FLUSH(hw);
11849 * This function is used to check if the register is valid.
11850 * Below is the valid registers list for X722 only:
11854 * 0x208e00--0x209000
11855 * 0x20be00--0x20c000
11856 * 0x263c00--0x264000
11857 * 0x265c00--0x266000
11859 static inline int i40e_valid_regs(enum i40e_mac_type type, uint32_t reg_offset)
11861 if ((type != I40E_MAC_X722) &&
11862 ((reg_offset >= 0x2b800 && reg_offset <= 0x2bb00) ||
11863 (reg_offset >= 0x38700 && reg_offset <= 0x38a00) ||
11864 (reg_offset >= 0x3d800 && reg_offset <= 0x3db00) ||
11865 (reg_offset >= 0x208e00 && reg_offset <= 0x209000) ||
11866 (reg_offset >= 0x20be00 && reg_offset <= 0x20c000) ||
11867 (reg_offset >= 0x263c00 && reg_offset <= 0x264000) ||
11868 (reg_offset >= 0x265c00 && reg_offset <= 0x266000)))
11874 static int i40e_get_regs(struct rte_eth_dev *dev,
11875 struct rte_dev_reg_info *regs)
11877 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11878 uint32_t *ptr_data = regs->data;
11879 uint32_t reg_idx, arr_idx, arr_idx2, reg_offset;
11880 const struct i40e_reg_info *reg_info;
11882 if (ptr_data == NULL) {
11883 regs->length = I40E_GLGEN_STAT_CLEAR + 4;
11884 regs->width = sizeof(uint32_t);
11888 /* The first few registers have to be read using AQ operations */
11890 while (i40e_regs_adminq[reg_idx].name) {
11891 reg_info = &i40e_regs_adminq[reg_idx++];
11892 for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
11894 arr_idx2 <= reg_info->count2;
11896 reg_offset = arr_idx * reg_info->stride1 +
11897 arr_idx2 * reg_info->stride2;
11898 reg_offset += reg_info->base_addr;
11899 ptr_data[reg_offset >> 2] =
11900 i40e_read_rx_ctl(hw, reg_offset);
11904 /* The remaining registers can be read using primitives */
11906 while (i40e_regs_others[reg_idx].name) {
11907 reg_info = &i40e_regs_others[reg_idx++];
11908 for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
11910 arr_idx2 <= reg_info->count2;
11912 reg_offset = arr_idx * reg_info->stride1 +
11913 arr_idx2 * reg_info->stride2;
11914 reg_offset += reg_info->base_addr;
11915 if (!i40e_valid_regs(hw->mac.type, reg_offset))
11916 ptr_data[reg_offset >> 2] = 0;
11918 ptr_data[reg_offset >> 2] =
11919 I40E_READ_REG(hw, reg_offset);
11926 static int i40e_get_eeprom_length(struct rte_eth_dev *dev)
11928 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11930 /* Convert word count to byte count */
11931 return hw->nvm.sr_size << 1;
11934 static int i40e_get_eeprom(struct rte_eth_dev *dev,
11935 struct rte_dev_eeprom_info *eeprom)
11937 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11938 uint16_t *data = eeprom->data;
11939 uint16_t offset, length, cnt_words;
11942 offset = eeprom->offset >> 1;
11943 length = eeprom->length >> 1;
11944 cnt_words = length;
11946 if (offset > hw->nvm.sr_size ||
11947 offset + length > hw->nvm.sr_size) {
11948 PMD_DRV_LOG(ERR, "Requested EEPROM bytes out of range.");
11952 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
11954 ret_code = i40e_read_nvm_buffer(hw, offset, &cnt_words, data);
11955 if (ret_code != I40E_SUCCESS || cnt_words != length) {
11956 PMD_DRV_LOG(ERR, "EEPROM read failed.");
11963 static int i40e_get_module_info(struct rte_eth_dev *dev,
11964 struct rte_eth_dev_module_info *modinfo)
11966 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11967 uint32_t sff8472_comp = 0;
11968 uint32_t sff8472_swap = 0;
11969 uint32_t sff8636_rev = 0;
11970 i40e_status status;
11973 /* Check if firmware supports reading module EEPROM. */
11974 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
11976 "Module EEPROM memory read not supported. "
11977 "Please update the NVM image.\n");
11981 status = i40e_update_link_info(hw);
11985 if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
11987 "Cannot read module EEPROM memory. "
11988 "No module connected.\n");
11992 type = hw->phy.link_info.module_type[0];
11995 case I40E_MODULE_TYPE_SFP:
11996 status = i40e_aq_get_phy_register(hw,
11997 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11998 I40E_I2C_EEPROM_DEV_ADDR, 1,
11999 I40E_MODULE_SFF_8472_COMP,
12000 &sff8472_comp, NULL);
12004 status = i40e_aq_get_phy_register(hw,
12005 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
12006 I40E_I2C_EEPROM_DEV_ADDR, 1,
12007 I40E_MODULE_SFF_8472_SWAP,
12008 &sff8472_swap, NULL);
12012 /* Check if the module requires address swap to access
12013 * the other EEPROM memory page.
12015 if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
12016 PMD_DRV_LOG(WARNING,
12017 "Module address swap to access "
12018 "page 0xA2 is not supported.\n");
12019 modinfo->type = RTE_ETH_MODULE_SFF_8079;
12020 modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
12021 } else if (sff8472_comp == 0x00) {
12022 /* Module is not SFF-8472 compliant */
12023 modinfo->type = RTE_ETH_MODULE_SFF_8079;
12024 modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
12026 modinfo->type = RTE_ETH_MODULE_SFF_8472;
12027 modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8472_LEN;
12030 case I40E_MODULE_TYPE_QSFP_PLUS:
12031 /* Read from memory page 0. */
12032 status = i40e_aq_get_phy_register(hw,
12033 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
12035 I40E_MODULE_REVISION_ADDR,
12036 &sff8636_rev, NULL);
12039 /* Determine revision compliance byte */
12040 if (sff8636_rev > 0x02) {
12041 /* Module is SFF-8636 compliant */
12042 modinfo->type = RTE_ETH_MODULE_SFF_8636;
12043 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
12045 modinfo->type = RTE_ETH_MODULE_SFF_8436;
12046 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
12049 case I40E_MODULE_TYPE_QSFP28:
12050 modinfo->type = RTE_ETH_MODULE_SFF_8636;
12051 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
12054 PMD_DRV_LOG(ERR, "Module type unrecognized\n");
12060 static int i40e_get_module_eeprom(struct rte_eth_dev *dev,
12061 struct rte_dev_eeprom_info *info)
12063 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
12064 bool is_sfp = false;
12065 i40e_status status;
12067 uint32_t value = 0;
12070 if (!info || !info->length || !info->data)
12073 if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
12077 for (i = 0; i < info->length; i++) {
12078 u32 offset = i + info->offset;
12079 u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
12081 /* Check if we need to access the other memory page */
12083 if (offset >= RTE_ETH_MODULE_SFF_8079_LEN) {
12084 offset -= RTE_ETH_MODULE_SFF_8079_LEN;
12085 addr = I40E_I2C_EEPROM_DEV_ADDR2;
12088 while (offset >= RTE_ETH_MODULE_SFF_8436_LEN) {
12089 /* Compute memory page number and offset. */
12090 offset -= RTE_ETH_MODULE_SFF_8436_LEN / 2;
12094 status = i40e_aq_get_phy_register(hw,
12095 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
12096 addr, offset, 1, &value, NULL);
12099 data[i] = (uint8_t)value;
12104 static int i40e_set_default_mac_addr(struct rte_eth_dev *dev,
12105 struct rte_ether_addr *mac_addr)
12107 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
12108 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
12109 struct i40e_vsi *vsi = pf->main_vsi;
12110 struct i40e_mac_filter_info mac_filter;
12111 struct i40e_mac_filter *f;
12114 if (!rte_is_valid_assigned_ether_addr(mac_addr)) {
12115 PMD_DRV_LOG(ERR, "Tried to set invalid MAC address.");
12119 TAILQ_FOREACH(f, &vsi->mac_list, next) {
12120 if (rte_is_same_ether_addr(&pf->dev_addr,
12121 &f->mac_info.mac_addr))
12126 PMD_DRV_LOG(ERR, "Failed to find filter for default mac");
12130 mac_filter = f->mac_info;
12131 ret = i40e_vsi_delete_mac(vsi, &mac_filter.mac_addr);
12132 if (ret != I40E_SUCCESS) {
12133 PMD_DRV_LOG(ERR, "Failed to delete mac filter");
12136 memcpy(&mac_filter.mac_addr, mac_addr, ETH_ADDR_LEN);
12137 ret = i40e_vsi_add_mac(vsi, &mac_filter);
12138 if (ret != I40E_SUCCESS) {
12139 PMD_DRV_LOG(ERR, "Failed to add mac filter");
12142 memcpy(&pf->dev_addr, mac_addr, ETH_ADDR_LEN);
12144 ret = i40e_aq_mac_address_write(hw, I40E_AQC_WRITE_TYPE_LAA_WOL,
12145 mac_addr->addr_bytes, NULL);
12146 if (ret != I40E_SUCCESS) {
12147 PMD_DRV_LOG(ERR, "Failed to change mac");
12155 i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
12157 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
12158 struct rte_eth_dev_data *dev_data = pf->dev_data;
12159 uint32_t frame_size = mtu + I40E_ETH_OVERHEAD;
12162 /* check if mtu is within the allowed range */
12163 if (mtu < RTE_ETHER_MIN_MTU || frame_size > I40E_FRAME_SIZE_MAX)
12166 /* mtu setting is forbidden if port is start */
12167 if (dev_data->dev_started) {
12168 PMD_DRV_LOG(ERR, "port %d must be stopped before configuration",
12169 dev_data->port_id);
12173 if (frame_size > RTE_ETHER_MAX_LEN)
12174 dev_data->dev_conf.rxmode.offloads |=
12175 DEV_RX_OFFLOAD_JUMBO_FRAME;
12177 dev_data->dev_conf.rxmode.offloads &=
12178 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
12180 dev_data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
12185 /* Restore ethertype filter */
12187 i40e_ethertype_filter_restore(struct i40e_pf *pf)
12189 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
12190 struct i40e_ethertype_filter_list
12191 *ethertype_list = &pf->ethertype.ethertype_list;
12192 struct i40e_ethertype_filter *f;
12193 struct i40e_control_filter_stats stats;
12196 TAILQ_FOREACH(f, ethertype_list, rules) {
12198 if (!(f->flags & RTE_ETHTYPE_FLAGS_MAC))
12199 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
12200 if (f->flags & RTE_ETHTYPE_FLAGS_DROP)
12201 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
12202 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
12204 memset(&stats, 0, sizeof(stats));
12205 i40e_aq_add_rem_control_packet_filter(hw,
12206 f->input.mac_addr.addr_bytes,
12207 f->input.ether_type,
12208 flags, pf->main_vsi->seid,
12209 f->queue, 1, &stats, NULL);
12211 PMD_DRV_LOG(INFO, "Ethertype filter:"
12212 " mac_etype_used = %u, etype_used = %u,"
12213 " mac_etype_free = %u, etype_free = %u",
12214 stats.mac_etype_used, stats.etype_used,
12215 stats.mac_etype_free, stats.etype_free);
12218 /* Restore tunnel filter */
12220 i40e_tunnel_filter_restore(struct i40e_pf *pf)
12222 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
12223 struct i40e_vsi *vsi;
12224 struct i40e_pf_vf *vf;
12225 struct i40e_tunnel_filter_list
12226 *tunnel_list = &pf->tunnel.tunnel_list;
12227 struct i40e_tunnel_filter *f;
12228 struct i40e_aqc_cloud_filters_element_bb cld_filter;
12229 bool big_buffer = 0;
12231 TAILQ_FOREACH(f, tunnel_list, rules) {
12233 vsi = pf->main_vsi;
12235 vf = &pf->vfs[f->vf_id];
12238 memset(&cld_filter, 0, sizeof(cld_filter));
12239 rte_ether_addr_copy((struct rte_ether_addr *)
12240 &f->input.outer_mac,
12241 (struct rte_ether_addr *)&cld_filter.element.outer_mac);
12242 rte_ether_addr_copy((struct rte_ether_addr *)
12243 &f->input.inner_mac,
12244 (struct rte_ether_addr *)&cld_filter.element.inner_mac);
12245 cld_filter.element.inner_vlan = f->input.inner_vlan;
12246 cld_filter.element.flags = f->input.flags;
12247 cld_filter.element.tenant_id = f->input.tenant_id;
12248 cld_filter.element.queue_number = f->queue;
12249 rte_memcpy(cld_filter.general_fields,
12250 f->input.general_fields,
12251 sizeof(f->input.general_fields));
12253 if (((f->input.flags &
12254 I40E_AQC_ADD_CLOUD_FILTER_0X11) ==
12255 I40E_AQC_ADD_CLOUD_FILTER_0X11) ||
12257 I40E_AQC_ADD_CLOUD_FILTER_0X12) ==
12258 I40E_AQC_ADD_CLOUD_FILTER_0X12) ||
12260 I40E_AQC_ADD_CLOUD_FILTER_0X10) ==
12261 I40E_AQC_ADD_CLOUD_FILTER_0X10))
12265 i40e_aq_add_cloud_filters_bb(hw,
12266 vsi->seid, &cld_filter, 1);
12268 i40e_aq_add_cloud_filters(hw, vsi->seid,
12269 &cld_filter.element, 1);
12273 /* Restore RSS filter */
12275 i40e_rss_filter_restore(struct i40e_pf *pf)
12277 struct i40e_rss_conf_list *list = &pf->rss_config_list;
12278 struct i40e_rss_filter *filter;
12280 TAILQ_FOREACH(filter, list, next) {
12281 i40e_config_rss_filter(pf, &filter->rss_filter_info, TRUE);
12286 i40e_filter_restore(struct i40e_pf *pf)
12288 i40e_ethertype_filter_restore(pf);
12289 i40e_tunnel_filter_restore(pf);
12290 i40e_fdir_filter_restore(pf);
12291 i40e_rss_filter_restore(pf);
12295 is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
12297 if (strcmp(dev->device->driver->name, drv->driver.name))
12304 is_i40e_supported(struct rte_eth_dev *dev)
12306 return is_device_supported(dev, &rte_i40e_pmd);
12309 struct i40e_customized_pctype*
12310 i40e_find_customized_pctype(struct i40e_pf *pf, uint8_t index)
12314 for (i = 0; i < I40E_CUSTOMIZED_MAX; i++) {
12315 if (pf->customized_pctype[i].index == index)
12316 return &pf->customized_pctype[i];
12322 i40e_update_customized_pctype(struct rte_eth_dev *dev, uint8_t *pkg,
12323 uint32_t pkg_size, uint32_t proto_num,
12324 struct rte_pmd_i40e_proto_info *proto,
12325 enum rte_pmd_i40e_package_op op)
12327 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
12328 uint32_t pctype_num;
12329 struct rte_pmd_i40e_ptype_info *pctype;
12330 uint32_t buff_size;
12331 struct i40e_customized_pctype *new_pctype = NULL;
12333 uint8_t pctype_value;
12338 if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
12339 op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
12340 PMD_DRV_LOG(ERR, "Unsupported operation.");
12344 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12345 (uint8_t *)&pctype_num, sizeof(pctype_num),
12346 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
12348 PMD_DRV_LOG(ERR, "Failed to get pctype number");
12352 PMD_DRV_LOG(INFO, "No new pctype added");
12356 buff_size = pctype_num * sizeof(struct rte_pmd_i40e_proto_info);
12357 pctype = rte_zmalloc("new_pctype", buff_size, 0);
12359 PMD_DRV_LOG(ERR, "Failed to allocate memory");
12362 /* get information about new pctype list */
12363 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12364 (uint8_t *)pctype, buff_size,
12365 RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
12367 PMD_DRV_LOG(ERR, "Failed to get pctype list");
12372 /* Update customized pctype. */
12373 for (i = 0; i < pctype_num; i++) {
12374 pctype_value = pctype[i].ptype_id;
12375 memset(name, 0, sizeof(name));
12376 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
12377 proto_id = pctype[i].protocols[j];
12378 if (proto_id == RTE_PMD_I40E_PROTO_UNUSED)
12380 for (n = 0; n < proto_num; n++) {
12381 if (proto[n].proto_id != proto_id)
12383 strlcat(name, proto[n].name, sizeof(name));
12384 strlcat(name, "_", sizeof(name));
12388 name[strlen(name) - 1] = '\0';
12389 PMD_DRV_LOG(INFO, "name = %s\n", name);
12390 if (!strcmp(name, "GTPC"))
12392 i40e_find_customized_pctype(pf,
12393 I40E_CUSTOMIZED_GTPC);
12394 else if (!strcmp(name, "GTPU_IPV4"))
12396 i40e_find_customized_pctype(pf,
12397 I40E_CUSTOMIZED_GTPU_IPV4);
12398 else if (!strcmp(name, "GTPU_IPV6"))
12400 i40e_find_customized_pctype(pf,
12401 I40E_CUSTOMIZED_GTPU_IPV6);
12402 else if (!strcmp(name, "GTPU"))
12404 i40e_find_customized_pctype(pf,
12405 I40E_CUSTOMIZED_GTPU);
12406 else if (!strcmp(name, "IPV4_L2TPV3"))
12408 i40e_find_customized_pctype(pf,
12409 I40E_CUSTOMIZED_IPV4_L2TPV3);
12410 else if (!strcmp(name, "IPV6_L2TPV3"))
12412 i40e_find_customized_pctype(pf,
12413 I40E_CUSTOMIZED_IPV6_L2TPV3);
12414 else if (!strcmp(name, "IPV4_ESP"))
12416 i40e_find_customized_pctype(pf,
12417 I40E_CUSTOMIZED_ESP_IPV4);
12418 else if (!strcmp(name, "IPV6_ESP"))
12420 i40e_find_customized_pctype(pf,
12421 I40E_CUSTOMIZED_ESP_IPV6);
12422 else if (!strcmp(name, "IPV4_UDP_ESP"))
12424 i40e_find_customized_pctype(pf,
12425 I40E_CUSTOMIZED_ESP_IPV4_UDP);
12426 else if (!strcmp(name, "IPV6_UDP_ESP"))
12428 i40e_find_customized_pctype(pf,
12429 I40E_CUSTOMIZED_ESP_IPV6_UDP);
12430 else if (!strcmp(name, "IPV4_AH"))
12432 i40e_find_customized_pctype(pf,
12433 I40E_CUSTOMIZED_AH_IPV4);
12434 else if (!strcmp(name, "IPV6_AH"))
12436 i40e_find_customized_pctype(pf,
12437 I40E_CUSTOMIZED_AH_IPV6);
12439 if (op == RTE_PMD_I40E_PKG_OP_WR_ADD) {
12440 new_pctype->pctype = pctype_value;
12441 new_pctype->valid = true;
12443 new_pctype->pctype = I40E_FILTER_PCTYPE_INVALID;
12444 new_pctype->valid = false;
12454 i40e_update_customized_ptype(struct rte_eth_dev *dev, uint8_t *pkg,
12455 uint32_t pkg_size, uint32_t proto_num,
12456 struct rte_pmd_i40e_proto_info *proto,
12457 enum rte_pmd_i40e_package_op op)
12459 struct rte_pmd_i40e_ptype_mapping *ptype_mapping;
12460 uint16_t port_id = dev->data->port_id;
12461 uint32_t ptype_num;
12462 struct rte_pmd_i40e_ptype_info *ptype;
12463 uint32_t buff_size;
12465 char name[RTE_PMD_I40E_DDP_NAME_SIZE];
12470 if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
12471 op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
12472 PMD_DRV_LOG(ERR, "Unsupported operation.");
12476 if (op == RTE_PMD_I40E_PKG_OP_WR_DEL) {
12477 rte_pmd_i40e_ptype_mapping_reset(port_id);
12481 /* get information about new ptype num */
12482 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12483 (uint8_t *)&ptype_num, sizeof(ptype_num),
12484 RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
12486 PMD_DRV_LOG(ERR, "Failed to get ptype number");
12490 PMD_DRV_LOG(INFO, "No new ptype added");
12494 buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
12495 ptype = rte_zmalloc("new_ptype", buff_size, 0);
12497 PMD_DRV_LOG(ERR, "Failed to allocate memory");
12501 /* get information about new ptype list */
12502 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12503 (uint8_t *)ptype, buff_size,
12504 RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
12506 PMD_DRV_LOG(ERR, "Failed to get ptype list");
12511 buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_mapping);
12512 ptype_mapping = rte_zmalloc("ptype_mapping", buff_size, 0);
12513 if (!ptype_mapping) {
12514 PMD_DRV_LOG(ERR, "Failed to allocate memory");
12519 /* Update ptype mapping table. */
12520 for (i = 0; i < ptype_num; i++) {
12521 ptype_mapping[i].hw_ptype = ptype[i].ptype_id;
12522 ptype_mapping[i].sw_ptype = 0;
12524 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
12525 proto_id = ptype[i].protocols[j];
12526 if (proto_id == RTE_PMD_I40E_PROTO_UNUSED)
12528 for (n = 0; n < proto_num; n++) {
12529 if (proto[n].proto_id != proto_id)
12531 memset(name, 0, sizeof(name));
12532 strcpy(name, proto[n].name);
12533 PMD_DRV_LOG(INFO, "name = %s\n", name);
12534 if (!strncasecmp(name, "PPPOE", 5))
12535 ptype_mapping[i].sw_ptype |=
12536 RTE_PTYPE_L2_ETHER_PPPOE;
12537 else if (!strncasecmp(name, "IPV4FRAG", 8) &&
12539 ptype_mapping[i].sw_ptype |=
12540 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
12541 ptype_mapping[i].sw_ptype |=
12543 } else if (!strncasecmp(name, "IPV4FRAG", 8) &&
12545 ptype_mapping[i].sw_ptype |=
12546 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
12547 ptype_mapping[i].sw_ptype |=
12548 RTE_PTYPE_INNER_L4_FRAG;
12549 } else if (!strncasecmp(name, "OIPV4", 5)) {
12550 ptype_mapping[i].sw_ptype |=
12551 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
12553 } else if (!strncasecmp(name, "IPV4", 4) &&
12555 ptype_mapping[i].sw_ptype |=
12556 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
12557 else if (!strncasecmp(name, "IPV4", 4) &&
12559 ptype_mapping[i].sw_ptype |=
12560 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
12561 else if (!strncasecmp(name, "IPV6FRAG", 8) &&
12563 ptype_mapping[i].sw_ptype |=
12564 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
12565 ptype_mapping[i].sw_ptype |=
12567 } else if (!strncasecmp(name, "IPV6FRAG", 8) &&
12569 ptype_mapping[i].sw_ptype |=
12570 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
12571 ptype_mapping[i].sw_ptype |=
12572 RTE_PTYPE_INNER_L4_FRAG;
12573 } else if (!strncasecmp(name, "OIPV6", 5)) {
12574 ptype_mapping[i].sw_ptype |=
12575 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
12577 } else if (!strncasecmp(name, "IPV6", 4) &&
12579 ptype_mapping[i].sw_ptype |=
12580 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
12581 else if (!strncasecmp(name, "IPV6", 4) &&
12583 ptype_mapping[i].sw_ptype |=
12584 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
12585 else if (!strncasecmp(name, "UDP", 3) &&
12587 ptype_mapping[i].sw_ptype |=
12589 else if (!strncasecmp(name, "UDP", 3) &&
12591 ptype_mapping[i].sw_ptype |=
12592 RTE_PTYPE_INNER_L4_UDP;
12593 else if (!strncasecmp(name, "TCP", 3) &&
12595 ptype_mapping[i].sw_ptype |=
12597 else if (!strncasecmp(name, "TCP", 3) &&
12599 ptype_mapping[i].sw_ptype |=
12600 RTE_PTYPE_INNER_L4_TCP;
12601 else if (!strncasecmp(name, "SCTP", 4) &&
12603 ptype_mapping[i].sw_ptype |=
12605 else if (!strncasecmp(name, "SCTP", 4) &&
12607 ptype_mapping[i].sw_ptype |=
12608 RTE_PTYPE_INNER_L4_SCTP;
12609 else if ((!strncasecmp(name, "ICMP", 4) ||
12610 !strncasecmp(name, "ICMPV6", 6)) &&
12612 ptype_mapping[i].sw_ptype |=
12614 else if ((!strncasecmp(name, "ICMP", 4) ||
12615 !strncasecmp(name, "ICMPV6", 6)) &&
12617 ptype_mapping[i].sw_ptype |=
12618 RTE_PTYPE_INNER_L4_ICMP;
12619 else if (!strncasecmp(name, "GTPC", 4)) {
12620 ptype_mapping[i].sw_ptype |=
12621 RTE_PTYPE_TUNNEL_GTPC;
12623 } else if (!strncasecmp(name, "GTPU", 4)) {
12624 ptype_mapping[i].sw_ptype |=
12625 RTE_PTYPE_TUNNEL_GTPU;
12627 } else if (!strncasecmp(name, "ESP", 3)) {
12628 ptype_mapping[i].sw_ptype |=
12629 RTE_PTYPE_TUNNEL_ESP;
12631 } else if (!strncasecmp(name, "GRENAT", 6)) {
12632 ptype_mapping[i].sw_ptype |=
12633 RTE_PTYPE_TUNNEL_GRENAT;
12635 } else if (!strncasecmp(name, "L2TPV2CTL", 9) ||
12636 !strncasecmp(name, "L2TPV2", 6) ||
12637 !strncasecmp(name, "L2TPV3", 6)) {
12638 ptype_mapping[i].sw_ptype |=
12639 RTE_PTYPE_TUNNEL_L2TP;
12648 ret = rte_pmd_i40e_ptype_mapping_update(port_id, ptype_mapping,
12651 PMD_DRV_LOG(ERR, "Failed to update ptype mapping table.");
12653 rte_free(ptype_mapping);
12659 i40e_update_customized_info(struct rte_eth_dev *dev, uint8_t *pkg,
12660 uint32_t pkg_size, enum rte_pmd_i40e_package_op op)
12662 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
12663 uint32_t proto_num;
12664 struct rte_pmd_i40e_proto_info *proto;
12665 uint32_t buff_size;
12669 if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
12670 op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
12671 PMD_DRV_LOG(ERR, "Unsupported operation.");
12675 /* get information about protocol number */
12676 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12677 (uint8_t *)&proto_num, sizeof(proto_num),
12678 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
12680 PMD_DRV_LOG(ERR, "Failed to get protocol number");
12684 PMD_DRV_LOG(INFO, "No new protocol added");
12688 buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
12689 proto = rte_zmalloc("new_proto", buff_size, 0);
12691 PMD_DRV_LOG(ERR, "Failed to allocate memory");
12695 /* get information about protocol list */
12696 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12697 (uint8_t *)proto, buff_size,
12698 RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
12700 PMD_DRV_LOG(ERR, "Failed to get protocol list");
12705 /* Check if GTP is supported. */
12706 for (i = 0; i < proto_num; i++) {
12707 if (!strncmp(proto[i].name, "GTP", 3)) {
12708 if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
12709 pf->gtp_support = true;
12711 pf->gtp_support = false;
12716 /* Check if ESP is supported. */
12717 for (i = 0; i < proto_num; i++) {
12718 if (!strncmp(proto[i].name, "ESP", 3)) {
12719 if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
12720 pf->esp_support = true;
12722 pf->esp_support = false;
12727 /* Update customized pctype info */
12728 ret = i40e_update_customized_pctype(dev, pkg, pkg_size,
12729 proto_num, proto, op);
12731 PMD_DRV_LOG(INFO, "No pctype is updated.");
12733 /* Update customized ptype info */
12734 ret = i40e_update_customized_ptype(dev, pkg, pkg_size,
12735 proto_num, proto, op);
12737 PMD_DRV_LOG(INFO, "No ptype is updated.");
12742 /* Create a QinQ cloud filter
12744 * The Fortville NIC has limited resources for tunnel filters,
12745 * so we can only reuse existing filters.
12747 * In step 1 we define which Field Vector fields can be used for
12749 * As we do not have the inner tag defined as a field,
12750 * we have to define it first, by reusing one of L1 entries.
12752 * In step 2 we are replacing one of existing filter types with
12753 * a new one for QinQ.
12754 * As we reusing L1 and replacing L2, some of the default filter
12755 * types will disappear,which depends on L1 and L2 entries we reuse.
12757 * Step 1: Create L1 filter of outer vlan (12b) + inner vlan (12b)
12759 * 1. Create L1 filter of outer vlan (12b) which will be in use
12760 * later when we define the cloud filter.
12761 * a. Valid_flags.replace_cloud = 0
12762 * b. Old_filter = 10 (Stag_Inner_Vlan)
12763 * c. New_filter = 0x10
12764 * d. TR bit = 0xff (optional, not used here)
12765 * e. Buffer – 2 entries:
12766 * i. Byte 0 = 8 (outer vlan FV index).
12768 * Byte 2-3 = 0x0fff
12769 * ii. Byte 0 = 37 (inner vlan FV index).
12771 * Byte 2-3 = 0x0fff
12774 * 2. Create cloud filter using two L1 filters entries: stag and
12775 * new filter(outer vlan+ inner vlan)
12776 * a. Valid_flags.replace_cloud = 1
12777 * b. Old_filter = 1 (instead of outer IP)
12778 * c. New_filter = 0x10
12779 * d. Buffer – 2 entries:
12780 * i. Byte 0 = 0x80 | 7 (valid | Stag).
12781 * Byte 1-3 = 0 (rsv)
12782 * ii. Byte 8 = 0x80 | 0x10 (valid | new l1 filter step1)
12783 * Byte 9-11 = 0 (rsv)
12786 i40e_cloud_filter_qinq_create(struct i40e_pf *pf)
12788 int ret = -ENOTSUP;
12789 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
12790 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
12791 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
12792 struct rte_eth_dev *dev = ((struct i40e_adapter *)hw->back)->eth_dev;
12794 if (pf->support_multi_driver) {
12795 PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
12800 memset(&filter_replace, 0,
12801 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
12802 memset(&filter_replace_buf, 0,
12803 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
12805 /* create L1 filter */
12806 filter_replace.old_filter_type =
12807 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG_IVLAN;
12808 filter_replace.new_filter_type = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12809 filter_replace.tr_bit = 0;
12811 /* Prepare the buffer, 2 entries */
12812 filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_VLAN;
12813 filter_replace_buf.data[0] |=
12814 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12815 /* Field Vector 12b mask */
12816 filter_replace_buf.data[2] = 0xff;
12817 filter_replace_buf.data[3] = 0x0f;
12818 filter_replace_buf.data[4] =
12819 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_INNER_VLAN;
12820 filter_replace_buf.data[4] |=
12821 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12822 /* Field Vector 12b mask */
12823 filter_replace_buf.data[6] = 0xff;
12824 filter_replace_buf.data[7] = 0x0f;
12825 ret = i40e_aq_replace_cloud_filters(hw, &filter_replace,
12826 &filter_replace_buf);
12827 if (ret != I40E_SUCCESS)
12830 if (filter_replace.old_filter_type !=
12831 filter_replace.new_filter_type)
12832 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
12833 " original: 0x%x, new: 0x%x",
12835 filter_replace.old_filter_type,
12836 filter_replace.new_filter_type);
12838 /* Apply the second L2 cloud filter */
12839 memset(&filter_replace, 0,
12840 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
12841 memset(&filter_replace_buf, 0,
12842 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
12844 /* create L2 filter, input for L2 filter will be L1 filter */
12845 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
12846 filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_OIP;
12847 filter_replace.new_filter_type = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12849 /* Prepare the buffer, 2 entries */
12850 filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
12851 filter_replace_buf.data[0] |=
12852 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12853 filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12854 filter_replace_buf.data[4] |=
12855 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12856 ret = i40e_aq_replace_cloud_filters(hw, &filter_replace,
12857 &filter_replace_buf);
12858 if (!ret && (filter_replace.old_filter_type !=
12859 filter_replace.new_filter_type))
12860 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
12861 " original: 0x%x, new: 0x%x",
12863 filter_replace.old_filter_type,
12864 filter_replace.new_filter_type);
12870 i40e_rss_conf_init(struct i40e_rte_flow_rss_conf *out,
12871 const struct rte_flow_action_rss *in)
12873 if (in->key_len > RTE_DIM(out->key) ||
12874 in->queue_num > RTE_DIM(out->queue))
12876 if (!in->key && in->key_len)
12878 out->conf = (struct rte_flow_action_rss){
12880 .level = in->level,
12881 .types = in->types,
12882 .key_len = in->key_len,
12883 .queue_num = in->queue_num,
12884 .queue = memcpy(out->queue, in->queue,
12885 sizeof(*in->queue) * in->queue_num),
12888 out->conf.key = memcpy(out->key, in->key, in->key_len);
12892 /* Write HENA register to enable hash */
12894 i40e_rss_hash_set(struct i40e_pf *pf, struct i40e_rte_flow_rss_conf *rss_conf)
12896 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
12897 uint8_t *key = (void *)(uintptr_t)rss_conf->conf.key;
12901 ret = i40e_set_rss_key(pf->main_vsi, key,
12902 rss_conf->conf.key_len);
12906 hena = i40e_config_hena(pf->adapter, rss_conf->conf.types);
12907 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
12908 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
12909 I40E_WRITE_FLUSH(hw);
12914 /* Configure hash input set */
12916 i40e_rss_conf_hash_inset(struct i40e_pf *pf, uint64_t types)
12918 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
12919 struct rte_eth_input_set_conf conf;
12924 static const struct {
12926 enum rte_eth_input_set_field field;
12927 } inset_match_table[] = {
12928 {ETH_RSS_FRAG_IPV4 | ETH_RSS_L3_SRC_ONLY,
12929 RTE_ETH_INPUT_SET_L3_SRC_IP4},
12930 {ETH_RSS_FRAG_IPV4 | ETH_RSS_L3_DST_ONLY,
12931 RTE_ETH_INPUT_SET_L3_DST_IP4},
12932 {ETH_RSS_FRAG_IPV4 | ETH_RSS_L4_SRC_ONLY,
12933 RTE_ETH_INPUT_SET_UNKNOWN},
12934 {ETH_RSS_FRAG_IPV4 | ETH_RSS_L4_DST_ONLY,
12935 RTE_ETH_INPUT_SET_UNKNOWN},
12937 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L3_SRC_ONLY,
12938 RTE_ETH_INPUT_SET_L3_SRC_IP4},
12939 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L3_DST_ONLY,
12940 RTE_ETH_INPUT_SET_L3_DST_IP4},
12941 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L4_SRC_ONLY,
12942 RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12943 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L4_DST_ONLY,
12944 RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12946 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L3_SRC_ONLY,
12947 RTE_ETH_INPUT_SET_L3_SRC_IP4},
12948 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L3_DST_ONLY,
12949 RTE_ETH_INPUT_SET_L3_DST_IP4},
12950 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L4_SRC_ONLY,
12951 RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12952 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L4_DST_ONLY,
12953 RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
12955 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L3_SRC_ONLY,
12956 RTE_ETH_INPUT_SET_L3_SRC_IP4},
12957 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L3_DST_ONLY,
12958 RTE_ETH_INPUT_SET_L3_DST_IP4},
12959 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L4_SRC_ONLY,
12960 RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
12961 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L4_DST_ONLY,
12962 RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
12964 {ETH_RSS_NONFRAG_IPV4_OTHER | ETH_RSS_L3_SRC_ONLY,
12965 RTE_ETH_INPUT_SET_L3_SRC_IP4},
12966 {ETH_RSS_NONFRAG_IPV4_OTHER | ETH_RSS_L3_DST_ONLY,
12967 RTE_ETH_INPUT_SET_L3_DST_IP4},
12968 {ETH_RSS_NONFRAG_IPV4_OTHER | ETH_RSS_L4_SRC_ONLY,
12969 RTE_ETH_INPUT_SET_UNKNOWN},
12970 {ETH_RSS_NONFRAG_IPV4_OTHER | ETH_RSS_L4_DST_ONLY,
12971 RTE_ETH_INPUT_SET_UNKNOWN},
12973 {ETH_RSS_FRAG_IPV6 | ETH_RSS_L3_SRC_ONLY,
12974 RTE_ETH_INPUT_SET_L3_SRC_IP6},
12975 {ETH_RSS_FRAG_IPV6 | ETH_RSS_L3_DST_ONLY,
12976 RTE_ETH_INPUT_SET_L3_DST_IP6},
12977 {ETH_RSS_FRAG_IPV6 | ETH_RSS_L4_SRC_ONLY,
12978 RTE_ETH_INPUT_SET_UNKNOWN},
12979 {ETH_RSS_FRAG_IPV6 | ETH_RSS_L4_DST_ONLY,
12980 RTE_ETH_INPUT_SET_UNKNOWN},
12982 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L3_SRC_ONLY,
12983 RTE_ETH_INPUT_SET_L3_SRC_IP6},
12984 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L3_DST_ONLY,
12985 RTE_ETH_INPUT_SET_L3_DST_IP6},
12986 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L4_SRC_ONLY,
12987 RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT},
12988 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L4_DST_ONLY,
12989 RTE_ETH_INPUT_SET_L4_TCP_DST_PORT},
12991 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L3_SRC_ONLY,
12992 RTE_ETH_INPUT_SET_L3_SRC_IP6},
12993 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L3_DST_ONLY,
12994 RTE_ETH_INPUT_SET_L3_DST_IP6},
12995 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L4_SRC_ONLY,
12996 RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT},
12997 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L4_DST_ONLY,
12998 RTE_ETH_INPUT_SET_L4_UDP_DST_PORT},
13000 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L3_SRC_ONLY,
13001 RTE_ETH_INPUT_SET_L3_SRC_IP6},
13002 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L3_DST_ONLY,
13003 RTE_ETH_INPUT_SET_L3_DST_IP6},
13004 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L4_SRC_ONLY,
13005 RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT},
13006 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L4_DST_ONLY,
13007 RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT},
13009 {ETH_RSS_NONFRAG_IPV6_OTHER | ETH_RSS_L3_SRC_ONLY,
13010 RTE_ETH_INPUT_SET_L3_SRC_IP6},
13011 {ETH_RSS_NONFRAG_IPV6_OTHER | ETH_RSS_L3_DST_ONLY,
13012 RTE_ETH_INPUT_SET_L3_DST_IP6},
13013 {ETH_RSS_NONFRAG_IPV6_OTHER | ETH_RSS_L4_SRC_ONLY,
13014 RTE_ETH_INPUT_SET_UNKNOWN},
13015 {ETH_RSS_NONFRAG_IPV6_OTHER | ETH_RSS_L4_DST_ONLY,
13016 RTE_ETH_INPUT_SET_UNKNOWN},
13019 mask0 = types & pf->adapter->flow_types_mask;
13020 conf.op = RTE_ETH_INPUT_SET_SELECT;
13021 conf.inset_size = 0;
13022 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < RTE_ETH_FLOW_MAX; i++) {
13023 if (mask0 & (1ULL << i)) {
13024 conf.flow_type = i;
13029 for (j = 0; j < RTE_DIM(inset_match_table); j++) {
13030 if ((types & inset_match_table[j].type) ==
13031 inset_match_table[j].type) {
13032 if (inset_match_table[j].field ==
13033 RTE_ETH_INPUT_SET_UNKNOWN)
13036 conf.field[conf.inset_size] =
13037 inset_match_table[j].field;
13042 if (conf.inset_size) {
13043 ret = i40e_hash_filter_inset_select(hw, &conf);
13051 /* Look up the conflicted rule then mark it as invalid */
13053 i40e_rss_mark_invalid_rule(struct i40e_pf *pf,
13054 struct i40e_rte_flow_rss_conf *conf)
13056 struct i40e_rss_filter *rss_item;
13057 uint64_t rss_inset;
13059 /* Clear input set bits before comparing the pctype */
13060 rss_inset = ~(ETH_RSS_L3_SRC_ONLY | ETH_RSS_L3_DST_ONLY |
13061 ETH_RSS_L4_SRC_ONLY | ETH_RSS_L4_DST_ONLY);
13063 /* Look up the conflicted rule then mark it as invalid */
13064 TAILQ_FOREACH(rss_item, &pf->rss_config_list, next) {
13065 if (!rss_item->rss_filter_info.valid)
13068 if (conf->conf.queue_num &&
13069 rss_item->rss_filter_info.conf.queue_num)
13070 rss_item->rss_filter_info.valid = false;
13072 if (conf->conf.types &&
13073 (rss_item->rss_filter_info.conf.types &
13075 (conf->conf.types & rss_inset))
13076 rss_item->rss_filter_info.valid = false;
13078 if (conf->conf.func ==
13079 RTE_ETH_HASH_FUNCTION_SIMPLE_XOR &&
13080 rss_item->rss_filter_info.conf.func ==
13081 RTE_ETH_HASH_FUNCTION_SIMPLE_XOR)
13082 rss_item->rss_filter_info.valid = false;
13086 /* Configure RSS hash function */
13088 i40e_rss_config_hash_function(struct i40e_pf *pf,
13089 struct i40e_rte_flow_rss_conf *conf)
13091 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
13096 if (conf->conf.func == RTE_ETH_HASH_FUNCTION_SIMPLE_XOR) {
13097 reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
13098 if (!(reg & I40E_GLQF_CTL_HTOEP_MASK)) {
13099 PMD_DRV_LOG(DEBUG, "Hash function already set to Simple XOR");
13100 I40E_WRITE_FLUSH(hw);
13101 i40e_rss_mark_invalid_rule(pf, conf);
13105 reg &= ~I40E_GLQF_CTL_HTOEP_MASK;
13107 i40e_write_global_rx_ctl(hw, I40E_GLQF_CTL, reg);
13108 I40E_WRITE_FLUSH(hw);
13109 i40e_rss_mark_invalid_rule(pf, conf);
13110 } else if (conf->conf.func ==
13111 RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ) {
13112 mask0 = conf->conf.types & pf->adapter->flow_types_mask;
13114 i40e_set_symmetric_hash_enable_per_port(hw, 1);
13115 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < UINT64_BIT; i++) {
13116 if (mask0 & (1UL << i))
13120 if (i == UINT64_BIT)
13123 for (j = I40E_FILTER_PCTYPE_INVALID + 1;
13124 j < I40E_FILTER_PCTYPE_MAX; j++) {
13125 if (pf->adapter->pctypes_tbl[i] & (1ULL << j))
13126 i40e_write_global_rx_ctl(hw,
13128 I40E_GLQF_HSYM_SYMH_ENA_MASK);
13135 /* Enable RSS according to the configuration */
13137 i40e_rss_enable_hash(struct i40e_pf *pf,
13138 struct i40e_rte_flow_rss_conf *conf)
13140 struct i40e_rte_flow_rss_conf *rss_info = &pf->rss_info;
13141 struct i40e_rte_flow_rss_conf rss_conf;
13143 if (!(conf->conf.types & pf->adapter->flow_types_mask))
13146 memset(&rss_conf, 0, sizeof(rss_conf));
13147 rte_memcpy(&rss_conf, conf, sizeof(rss_conf));
13149 /* Configure hash input set */
13150 if (i40e_rss_conf_hash_inset(pf, conf->conf.types))
13153 if (rss_conf.conf.key == NULL || rss_conf.conf.key_len <
13154 (I40E_PFQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t)) {
13155 /* Random default keys */
13156 static uint32_t rss_key_default[] = {0x6b793944,
13157 0x23504cb5, 0x5bea75b6, 0x309f4f12, 0x3dc0a2b8,
13158 0x024ddcdf, 0x339b8ca0, 0x4c4af64a, 0x34fac605,
13159 0x55d85839, 0x3a58997d, 0x2ec938e1, 0x66031581};
13161 rss_conf.conf.key = (uint8_t *)rss_key_default;
13162 rss_conf.conf.key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
13165 "No valid RSS key config for i40e, using default\n");
13168 rss_conf.conf.types |= rss_info->conf.types;
13169 i40e_rss_hash_set(pf, &rss_conf);
13171 if (conf->conf.func == RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ)
13172 i40e_rss_config_hash_function(pf, conf);
13174 i40e_rss_mark_invalid_rule(pf, conf);
13179 /* Configure RSS queue region */
13181 i40e_rss_config_queue_region(struct i40e_pf *pf,
13182 struct i40e_rte_flow_rss_conf *conf)
13184 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
13189 /* If both VMDQ and RSS enabled, not all of PF queues are configured.
13190 * It's necessary to calculate the actual PF queues that are configured.
13192 if (pf->dev_data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG)
13193 num = i40e_pf_calc_configured_queues_num(pf);
13195 num = pf->dev_data->nb_rx_queues;
13197 num = RTE_MIN(num, conf->conf.queue_num);
13198 PMD_DRV_LOG(INFO, "Max of contiguous %u PF queues are configured",
13203 "No PF queues are configured to enable RSS for port %u",
13204 pf->dev_data->port_id);
13208 /* Fill in redirection table */
13209 for (i = 0, j = 0; i < hw->func_caps.rss_table_size; i++, j++) {
13212 lut = (lut << 8) | (conf->conf.queue[j] & ((0x1 <<
13213 hw->func_caps.rss_table_entry_width) - 1));
13215 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i >> 2), lut);
13218 i40e_rss_mark_invalid_rule(pf, conf);
13223 /* Configure RSS hash function to default */
13225 i40e_rss_clear_hash_function(struct i40e_pf *pf,
13226 struct i40e_rte_flow_rss_conf *conf)
13228 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
13233 if (conf->conf.func == RTE_ETH_HASH_FUNCTION_SIMPLE_XOR) {
13234 reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
13235 if (reg & I40E_GLQF_CTL_HTOEP_MASK) {
13237 "Hash function already set to Toeplitz");
13238 I40E_WRITE_FLUSH(hw);
13242 reg |= I40E_GLQF_CTL_HTOEP_MASK;
13244 i40e_write_global_rx_ctl(hw, I40E_GLQF_CTL, reg);
13245 I40E_WRITE_FLUSH(hw);
13246 } else if (conf->conf.func ==
13247 RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ) {
13248 mask0 = conf->conf.types & pf->adapter->flow_types_mask;
13250 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < UINT64_BIT; i++) {
13251 if (mask0 & (1UL << i))
13255 if (i == UINT64_BIT)
13258 for (j = I40E_FILTER_PCTYPE_INVALID + 1;
13259 j < I40E_FILTER_PCTYPE_MAX; j++) {
13260 if (pf->adapter->pctypes_tbl[i] & (1ULL << j))
13261 i40e_write_global_rx_ctl(hw,
13270 /* Disable RSS hash and configure default input set */
13272 i40e_rss_disable_hash(struct i40e_pf *pf,
13273 struct i40e_rte_flow_rss_conf *conf)
13275 struct i40e_rte_flow_rss_conf *rss_info = &pf->rss_info;
13276 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
13277 struct i40e_rte_flow_rss_conf rss_conf;
13280 memset(&rss_conf, 0, sizeof(rss_conf));
13281 rte_memcpy(&rss_conf, conf, sizeof(rss_conf));
13283 /* Disable RSS hash */
13284 rss_conf.conf.types = rss_info->conf.types & ~(conf->conf.types);
13285 i40e_rss_hash_set(pf, &rss_conf);
13287 for (i = RTE_ETH_FLOW_IPV4; i <= RTE_ETH_FLOW_L2_PAYLOAD; i++) {
13288 if (!(pf->adapter->flow_types_mask & (1ULL << i)) ||
13289 !(conf->conf.types & (1ULL << i)))
13292 /* Configure default input set */
13293 struct rte_eth_input_set_conf input_conf = {
13294 .op = RTE_ETH_INPUT_SET_SELECT,
13298 input_conf.field[0] = RTE_ETH_INPUT_SET_DEFAULT;
13299 i40e_hash_filter_inset_select(hw, &input_conf);
13302 rss_info->conf.types = rss_conf.conf.types;
13304 i40e_rss_clear_hash_function(pf, conf);
13309 /* Configure RSS queue region to default */
13311 i40e_rss_clear_queue_region(struct i40e_pf *pf)
13313 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
13314 struct i40e_rte_flow_rss_conf *rss_info = &pf->rss_info;
13315 uint16_t queue[I40E_MAX_Q_PER_TC];
13316 uint32_t num_rxq, i;
13320 num_rxq = RTE_MIN(pf->dev_data->nb_rx_queues, I40E_MAX_Q_PER_TC);
13322 for (j = 0; j < num_rxq; j++)
13325 /* If both VMDQ and RSS enabled, not all of PF queues are configured.
13326 * It's necessary to calculate the actual PF queues that are configured.
13328 if (pf->dev_data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG)
13329 num = i40e_pf_calc_configured_queues_num(pf);
13331 num = pf->dev_data->nb_rx_queues;
13333 num = RTE_MIN(num, num_rxq);
13334 PMD_DRV_LOG(INFO, "Max of contiguous %u PF queues are configured",
13339 "No PF queues are configured to enable RSS for port %u",
13340 pf->dev_data->port_id);
13344 /* Fill in redirection table */
13345 for (i = 0, j = 0; i < hw->func_caps.rss_table_size; i++, j++) {
13348 lut = (lut << 8) | (queue[j] & ((0x1 <<
13349 hw->func_caps.rss_table_entry_width) - 1));
13351 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i >> 2), lut);
13354 rss_info->conf.queue_num = 0;
13355 memset(&rss_info->conf.queue, 0, sizeof(uint16_t));
13361 i40e_config_rss_filter(struct i40e_pf *pf,
13362 struct i40e_rte_flow_rss_conf *conf, bool add)
13364 struct i40e_rte_flow_rss_conf *rss_info = &pf->rss_info;
13365 struct rte_flow_action_rss update_conf = rss_info->conf;
13369 if (conf->conf.queue_num) {
13370 /* Configure RSS queue region */
13371 ret = i40e_rss_config_queue_region(pf, conf);
13375 update_conf.queue_num = conf->conf.queue_num;
13376 update_conf.queue = conf->conf.queue;
13377 } else if (conf->conf.func ==
13378 RTE_ETH_HASH_FUNCTION_SIMPLE_XOR) {
13379 /* Configure hash function */
13380 ret = i40e_rss_config_hash_function(pf, conf);
13384 update_conf.func = conf->conf.func;
13386 /* Configure hash enable and input set */
13387 ret = i40e_rss_enable_hash(pf, conf);
13391 update_conf.types |= conf->conf.types;
13392 update_conf.key = conf->conf.key;
13393 update_conf.key_len = conf->conf.key_len;
13396 /* Update RSS info in pf */
13397 if (i40e_rss_conf_init(rss_info, &update_conf))
13403 if (conf->conf.queue_num)
13404 i40e_rss_clear_queue_region(pf);
13405 else if (conf->conf.func == RTE_ETH_HASH_FUNCTION_SIMPLE_XOR)
13406 i40e_rss_clear_hash_function(pf, conf);
13408 i40e_rss_disable_hash(pf, conf);
13414 RTE_INIT(i40e_init_log)
13416 i40e_logtype_init = rte_log_register("pmd.net.i40e.init");
13417 if (i40e_logtype_init >= 0)
13418 rte_log_set_level(i40e_logtype_init, RTE_LOG_NOTICE);
13419 i40e_logtype_driver = rte_log_register("pmd.net.i40e.driver");
13420 if (i40e_logtype_driver >= 0)
13421 rte_log_set_level(i40e_logtype_driver, RTE_LOG_NOTICE);
13423 #ifdef RTE_LIBRTE_I40E_DEBUG_RX
13424 i40e_logtype_rx = rte_log_register("pmd.net.i40e.rx");
13425 if (i40e_logtype_rx >= 0)
13426 rte_log_set_level(i40e_logtype_rx, RTE_LOG_DEBUG);
13429 #ifdef RTE_LIBRTE_I40E_DEBUG_TX
13430 i40e_logtype_tx = rte_log_register("pmd.net.i40e.tx");
13431 if (i40e_logtype_tx >= 0)
13432 rte_log_set_level(i40e_logtype_tx, RTE_LOG_DEBUG);
13435 #ifdef RTE_LIBRTE_I40E_DEBUG_TX_FREE
13436 i40e_logtype_tx_free = rte_log_register("pmd.net.i40e.tx_free");
13437 if (i40e_logtype_tx_free >= 0)
13438 rte_log_set_level(i40e_logtype_tx_free, RTE_LOG_DEBUG);
13442 RTE_PMD_REGISTER_PARAM_STRING(net_i40e,
13443 ETH_I40E_FLOATING_VEB_ARG "=1"
13444 ETH_I40E_FLOATING_VEB_LIST_ARG "=<string>"
13445 ETH_I40E_QUEUE_NUM_PER_VF_ARG "=1|2|4|8|16"
13446 ETH_I40E_SUPPORT_MULTI_DRIVER "=1"
13447 ETH_I40E_USE_LATEST_VEC "=0|1");