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 <ethdev_driver.h>
21 #include <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>
29 #include <rte_bitmap.h>
30 #include <rte_os_shim.h>
32 #include "i40e_logs.h"
33 #include "base/i40e_prototype.h"
34 #include "base/i40e_adminq_cmd.h"
35 #include "base/i40e_type.h"
36 #include "base/i40e_register.h"
37 #include "base/i40e_dcb.h"
38 #include "i40e_ethdev.h"
39 #include "i40e_rxtx.h"
41 #include "i40e_regs.h"
42 #include "rte_pmd_i40e.h"
43 #include "i40e_hash.h"
45 #define ETH_I40E_FLOATING_VEB_ARG "enable_floating_veb"
46 #define ETH_I40E_FLOATING_VEB_LIST_ARG "floating_veb_list"
47 #define ETH_I40E_SUPPORT_MULTI_DRIVER "support-multi-driver"
48 #define ETH_I40E_QUEUE_NUM_PER_VF_ARG "queue-num-per-vf"
49 #define ETH_I40E_VF_MSG_CFG "vf_msg_cfg"
51 #define I40E_CLEAR_PXE_WAIT_MS 200
52 #define I40E_VSI_TSR_QINQ_STRIP 0x4010
53 #define I40E_VSI_TSR(_i) (0x00050800 + ((_i) * 4))
55 /* Maximun number of capability elements */
56 #define I40E_MAX_CAP_ELE_NUM 128
58 /* Wait count and interval */
59 #define I40E_CHK_Q_ENA_COUNT 1000
60 #define I40E_CHK_Q_ENA_INTERVAL_US 1000
62 /* Maximun number of VSI */
63 #define I40E_MAX_NUM_VSIS (384UL)
65 #define I40E_PRE_TX_Q_CFG_WAIT_US 10 /* 10 us */
67 /* Flow control default timer */
68 #define I40E_DEFAULT_PAUSE_TIME 0xFFFFU
70 /* Flow control enable fwd bit */
71 #define I40E_PRTMAC_FWD_CTRL 0x00000001
73 /* Receive Packet Buffer size */
74 #define I40E_RXPBSIZE (968 * 1024)
77 #define I40E_KILOSHIFT 10
79 /* Flow control default high water */
80 #define I40E_DEFAULT_HIGH_WATER (0xF2000 >> I40E_KILOSHIFT)
82 /* Flow control default low water */
83 #define I40E_DEFAULT_LOW_WATER (0xF2000 >> I40E_KILOSHIFT)
85 /* Receive Average Packet Size in Byte*/
86 #define I40E_PACKET_AVERAGE_SIZE 128
88 /* Mask of PF interrupt causes */
89 #define I40E_PFINT_ICR0_ENA_MASK ( \
90 I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | \
91 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | \
92 I40E_PFINT_ICR0_ENA_GRST_MASK | \
93 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | \
94 I40E_PFINT_ICR0_ENA_STORM_DETECT_MASK | \
95 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | \
96 I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK | \
97 I40E_PFINT_ICR0_ENA_VFLR_MASK | \
98 I40E_PFINT_ICR0_ENA_ADMINQ_MASK)
100 #define I40E_FLOW_TYPES ( \
101 (1UL << RTE_ETH_FLOW_FRAG_IPV4) | \
102 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_TCP) | \
103 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_UDP) | \
104 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_SCTP) | \
105 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_OTHER) | \
106 (1UL << RTE_ETH_FLOW_FRAG_IPV6) | \
107 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_TCP) | \
108 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_UDP) | \
109 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_SCTP) | \
110 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_OTHER) | \
111 (1UL << RTE_ETH_FLOW_L2_PAYLOAD))
113 /* Additional timesync values. */
114 #define I40E_PTP_40GB_INCVAL 0x0199999999ULL
115 #define I40E_PTP_10GB_INCVAL 0x0333333333ULL
116 #define I40E_PTP_1GB_INCVAL 0x2000000000ULL
117 #define I40E_PRTTSYN_TSYNENA 0x80000000
118 #define I40E_PRTTSYN_TSYNTYPE 0x0e000000
119 #define I40E_CYCLECOUNTER_MASK 0xffffffffffffffffULL
122 * Below are values for writing un-exposed registers suggested
125 /* Destination MAC address */
126 #define I40E_REG_INSET_L2_DMAC 0xE000000000000000ULL
127 /* Source MAC address */
128 #define I40E_REG_INSET_L2_SMAC 0x1C00000000000000ULL
129 /* Outer (S-Tag) VLAN tag in the outer L2 header */
130 #define I40E_REG_INSET_L2_OUTER_VLAN 0x0000000004000000ULL
131 /* Inner (C-Tag) or single VLAN tag in the outer L2 header */
132 #define I40E_REG_INSET_L2_INNER_VLAN 0x0080000000000000ULL
133 /* Single VLAN tag in the inner L2 header */
134 #define I40E_REG_INSET_TUNNEL_VLAN 0x0100000000000000ULL
135 /* Source IPv4 address */
136 #define I40E_REG_INSET_L3_SRC_IP4 0x0001800000000000ULL
137 /* Destination IPv4 address */
138 #define I40E_REG_INSET_L3_DST_IP4 0x0000001800000000ULL
139 /* Source IPv4 address for X722 */
140 #define I40E_X722_REG_INSET_L3_SRC_IP4 0x0006000000000000ULL
141 /* Destination IPv4 address for X722 */
142 #define I40E_X722_REG_INSET_L3_DST_IP4 0x0000060000000000ULL
143 /* IPv4 Protocol for X722 */
144 #define I40E_X722_REG_INSET_L3_IP4_PROTO 0x0010000000000000ULL
145 /* IPv4 Time to Live for X722 */
146 #define I40E_X722_REG_INSET_L3_IP4_TTL 0x0010000000000000ULL
147 /* IPv4 Type of Service (TOS) */
148 #define I40E_REG_INSET_L3_IP4_TOS 0x0040000000000000ULL
150 #define I40E_REG_INSET_L3_IP4_PROTO 0x0004000000000000ULL
151 /* IPv4 Time to Live */
152 #define I40E_REG_INSET_L3_IP4_TTL 0x0004000000000000ULL
153 /* Source IPv6 address */
154 #define I40E_REG_INSET_L3_SRC_IP6 0x0007F80000000000ULL
155 /* Destination IPv6 address */
156 #define I40E_REG_INSET_L3_DST_IP6 0x000007F800000000ULL
157 /* IPv6 Traffic Class (TC) */
158 #define I40E_REG_INSET_L3_IP6_TC 0x0040000000000000ULL
159 /* IPv6 Next Header */
160 #define I40E_REG_INSET_L3_IP6_NEXT_HDR 0x0008000000000000ULL
162 #define I40E_REG_INSET_L3_IP6_HOP_LIMIT 0x0008000000000000ULL
164 #define I40E_REG_INSET_L4_SRC_PORT 0x0000000400000000ULL
165 /* Destination L4 port */
166 #define I40E_REG_INSET_L4_DST_PORT 0x0000000200000000ULL
167 /* SCTP verification tag */
168 #define I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG 0x0000000180000000ULL
169 /* Inner destination MAC address (MAC-in-UDP/MAC-in-GRE)*/
170 #define I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC 0x0000000001C00000ULL
171 /* Source port of tunneling UDP */
172 #define I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT 0x0000000000200000ULL
173 /* Destination port of tunneling UDP */
174 #define I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT 0x0000000000100000ULL
175 /* UDP Tunneling ID, NVGRE/GRE key */
176 #define I40E_REG_INSET_TUNNEL_ID 0x00000000000C0000ULL
177 /* Last ether type */
178 #define I40E_REG_INSET_LAST_ETHER_TYPE 0x0000000000004000ULL
179 /* Tunneling outer destination IPv4 address */
180 #define I40E_REG_INSET_TUNNEL_L3_DST_IP4 0x00000000000000C0ULL
181 /* Tunneling outer destination IPv6 address */
182 #define I40E_REG_INSET_TUNNEL_L3_DST_IP6 0x0000000000003FC0ULL
183 /* 1st word of flex payload */
184 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD1 0x0000000000002000ULL
185 /* 2nd word of flex payload */
186 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD2 0x0000000000001000ULL
187 /* 3rd word of flex payload */
188 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD3 0x0000000000000800ULL
189 /* 4th word of flex payload */
190 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD4 0x0000000000000400ULL
191 /* 5th word of flex payload */
192 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD5 0x0000000000000200ULL
193 /* 6th word of flex payload */
194 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD6 0x0000000000000100ULL
195 /* 7th word of flex payload */
196 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD7 0x0000000000000080ULL
197 /* 8th word of flex payload */
198 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD8 0x0000000000000040ULL
199 /* all 8 words flex payload */
200 #define I40E_REG_INSET_FLEX_PAYLOAD_WORDS 0x0000000000003FC0ULL
201 #define I40E_REG_INSET_MASK_DEFAULT 0x0000000000000000ULL
203 #define I40E_TRANSLATE_INSET 0
204 #define I40E_TRANSLATE_REG 1
206 #define I40E_INSET_IPV4_TOS_MASK 0x0000FF00UL
207 #define I40E_INSET_IPV4_TTL_MASK 0x000000FFUL
208 #define I40E_INSET_IPV4_PROTO_MASK 0x0000FF00UL
209 #define I40E_INSET_IPV6_TC_MASK 0x0000F00FUL
210 #define I40E_INSET_IPV6_HOP_LIMIT_MASK 0x0000FF00UL
211 #define I40E_INSET_IPV6_NEXT_HDR_MASK 0x000000FFUL
213 /* PCI offset for querying capability */
214 #define PCI_DEV_CAP_REG 0xA4
215 /* PCI offset for enabling/disabling Extended Tag */
216 #define PCI_DEV_CTRL_REG 0xA8
217 /* Bit mask of Extended Tag capability */
218 #define PCI_DEV_CAP_EXT_TAG_MASK 0x20
219 /* Bit shift of Extended Tag enable/disable */
220 #define PCI_DEV_CTRL_EXT_TAG_SHIFT 8
221 /* Bit mask of Extended Tag enable/disable */
222 #define PCI_DEV_CTRL_EXT_TAG_MASK (1 << PCI_DEV_CTRL_EXT_TAG_SHIFT)
224 #define I40E_GLQF_PIT_IPV4_START 2
225 #define I40E_GLQF_PIT_IPV4_COUNT 2
226 #define I40E_GLQF_PIT_IPV6_START 4
227 #define I40E_GLQF_PIT_IPV6_COUNT 2
229 #define I40E_GLQF_PIT_SOURCE_OFF_GET(a) \
230 (((a) & I40E_GLQF_PIT_SOURCE_OFF_MASK) >> \
231 I40E_GLQF_PIT_SOURCE_OFF_SHIFT)
233 #define I40E_GLQF_PIT_DEST_OFF_GET(a) \
234 (((a) & I40E_GLQF_PIT_DEST_OFF_MASK) >> \
235 I40E_GLQF_PIT_DEST_OFF_SHIFT)
237 #define I40E_GLQF_PIT_FSIZE_GET(a) (((a) & I40E_GLQF_PIT_FSIZE_MASK) >> \
238 I40E_GLQF_PIT_FSIZE_SHIFT)
240 #define I40E_GLQF_PIT_BUILD(off, mask) (((off) << 16) | (mask))
241 #define I40E_FDIR_FIELD_OFFSET(a) ((a) >> 1)
243 static int eth_i40e_dev_init(struct rte_eth_dev *eth_dev, void *init_params);
244 static int eth_i40e_dev_uninit(struct rte_eth_dev *eth_dev);
245 static int i40e_dev_configure(struct rte_eth_dev *dev);
246 static int i40e_dev_start(struct rte_eth_dev *dev);
247 static int i40e_dev_stop(struct rte_eth_dev *dev);
248 static int i40e_dev_close(struct rte_eth_dev *dev);
249 static int i40e_dev_reset(struct rte_eth_dev *dev);
250 static int i40e_dev_promiscuous_enable(struct rte_eth_dev *dev);
251 static int i40e_dev_promiscuous_disable(struct rte_eth_dev *dev);
252 static int i40e_dev_allmulticast_enable(struct rte_eth_dev *dev);
253 static int i40e_dev_allmulticast_disable(struct rte_eth_dev *dev);
254 static int i40e_dev_set_link_up(struct rte_eth_dev *dev);
255 static int i40e_dev_set_link_down(struct rte_eth_dev *dev);
256 static int i40e_dev_stats_get(struct rte_eth_dev *dev,
257 struct rte_eth_stats *stats);
258 static int i40e_dev_xstats_get(struct rte_eth_dev *dev,
259 struct rte_eth_xstat *xstats, unsigned n);
260 static int i40e_dev_xstats_get_names(struct rte_eth_dev *dev,
261 struct rte_eth_xstat_name *xstats_names,
263 static int i40e_dev_stats_reset(struct rte_eth_dev *dev);
264 static int i40e_fw_version_get(struct rte_eth_dev *dev,
265 char *fw_version, size_t fw_size);
266 static int i40e_dev_info_get(struct rte_eth_dev *dev,
267 struct rte_eth_dev_info *dev_info);
268 static int i40e_vlan_filter_set(struct rte_eth_dev *dev,
271 static int i40e_vlan_tpid_set(struct rte_eth_dev *dev,
272 enum rte_vlan_type vlan_type,
274 static int i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask);
275 static void i40e_vlan_strip_queue_set(struct rte_eth_dev *dev,
278 static int i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on);
279 static int i40e_dev_led_on(struct rte_eth_dev *dev);
280 static int i40e_dev_led_off(struct rte_eth_dev *dev);
281 static int i40e_flow_ctrl_get(struct rte_eth_dev *dev,
282 struct rte_eth_fc_conf *fc_conf);
283 static int i40e_flow_ctrl_set(struct rte_eth_dev *dev,
284 struct rte_eth_fc_conf *fc_conf);
285 static int i40e_priority_flow_ctrl_set(struct rte_eth_dev *dev,
286 struct rte_eth_pfc_conf *pfc_conf);
287 static int i40e_macaddr_add(struct rte_eth_dev *dev,
288 struct rte_ether_addr *mac_addr,
291 static void i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index);
292 static int i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
293 struct rte_eth_rss_reta_entry64 *reta_conf,
295 static int i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
296 struct rte_eth_rss_reta_entry64 *reta_conf,
299 static int i40e_get_cap(struct i40e_hw *hw);
300 static int i40e_pf_parameter_init(struct rte_eth_dev *dev);
301 static int i40e_pf_setup(struct i40e_pf *pf);
302 static int i40e_dev_rxtx_init(struct i40e_pf *pf);
303 static int i40e_vmdq_setup(struct rte_eth_dev *dev);
304 static int i40e_dcb_setup(struct rte_eth_dev *dev);
305 static void i40e_stat_update_32(struct i40e_hw *hw, uint32_t reg,
306 bool offset_loaded, uint64_t *offset, uint64_t *stat);
307 static void i40e_stat_update_48(struct i40e_hw *hw,
313 static void i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue);
314 static void i40e_dev_interrupt_handler(void *param);
315 static void i40e_dev_alarm_handler(void *param);
316 static int i40e_res_pool_init(struct i40e_res_pool_info *pool,
317 uint32_t base, uint32_t num);
318 static void i40e_res_pool_destroy(struct i40e_res_pool_info *pool);
319 static int i40e_res_pool_free(struct i40e_res_pool_info *pool,
321 static int i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
323 static int i40e_dev_init_vlan(struct rte_eth_dev *dev);
324 static int i40e_veb_release(struct i40e_veb *veb);
325 static struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf,
326 struct i40e_vsi *vsi);
327 static int i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on);
328 static inline int i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
329 struct i40e_macvlan_filter *mv_f,
332 static int i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi);
333 static int i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
334 struct rte_eth_rss_conf *rss_conf);
335 static int i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
336 struct rte_eth_rss_conf *rss_conf);
337 static int i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
338 struct rte_eth_udp_tunnel *udp_tunnel);
339 static int i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
340 struct rte_eth_udp_tunnel *udp_tunnel);
341 static void i40e_filter_input_set_init(struct i40e_pf *pf);
342 static int i40e_dev_flow_ops_get(struct rte_eth_dev *dev,
343 const struct rte_flow_ops **ops);
344 static int i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
345 struct rte_eth_dcb_info *dcb_info);
346 static int i40e_dev_sync_phy_type(struct i40e_hw *hw);
347 static void i40e_configure_registers(struct i40e_hw *hw);
348 static void i40e_hw_init(struct rte_eth_dev *dev);
349 static int i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi);
351 static int i40e_timesync_enable(struct rte_eth_dev *dev);
352 static int i40e_timesync_disable(struct rte_eth_dev *dev);
353 static int i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
354 struct timespec *timestamp,
356 static int i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
357 struct timespec *timestamp);
358 static void i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw);
360 static int i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
362 static int i40e_timesync_read_time(struct rte_eth_dev *dev,
363 struct timespec *timestamp);
364 static int i40e_timesync_write_time(struct rte_eth_dev *dev,
365 const struct timespec *timestamp);
367 static int i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
369 static int i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
372 static int i40e_get_regs(struct rte_eth_dev *dev,
373 struct rte_dev_reg_info *regs);
375 static int i40e_get_eeprom_length(struct rte_eth_dev *dev);
377 static int i40e_get_eeprom(struct rte_eth_dev *dev,
378 struct rte_dev_eeprom_info *eeprom);
380 static int i40e_get_module_info(struct rte_eth_dev *dev,
381 struct rte_eth_dev_module_info *modinfo);
382 static int i40e_get_module_eeprom(struct rte_eth_dev *dev,
383 struct rte_dev_eeprom_info *info);
385 static int i40e_set_default_mac_addr(struct rte_eth_dev *dev,
386 struct rte_ether_addr *mac_addr);
388 static int i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
389 static void i40e_set_mac_max_frame(struct rte_eth_dev *dev, uint16_t size);
391 static int i40e_ethertype_filter_convert(
392 const struct rte_eth_ethertype_filter *input,
393 struct i40e_ethertype_filter *filter);
394 static int i40e_sw_ethertype_filter_insert(struct i40e_pf *pf,
395 struct i40e_ethertype_filter *filter);
397 static int i40e_tunnel_filter_convert(
398 struct i40e_aqc_cloud_filters_element_bb *cld_filter,
399 struct i40e_tunnel_filter *tunnel_filter);
400 static int i40e_sw_tunnel_filter_insert(struct i40e_pf *pf,
401 struct i40e_tunnel_filter *tunnel_filter);
402 static int i40e_cloud_filter_qinq_create(struct i40e_pf *pf);
404 static void i40e_ethertype_filter_restore(struct i40e_pf *pf);
405 static void i40e_tunnel_filter_restore(struct i40e_pf *pf);
406 static void i40e_filter_restore(struct i40e_pf *pf);
407 static void i40e_notify_all_vfs_link_status(struct rte_eth_dev *dev);
409 static const char *const valid_keys[] = {
410 ETH_I40E_FLOATING_VEB_ARG,
411 ETH_I40E_FLOATING_VEB_LIST_ARG,
412 ETH_I40E_SUPPORT_MULTI_DRIVER,
413 ETH_I40E_QUEUE_NUM_PER_VF_ARG,
417 static const struct rte_pci_id pci_id_i40e_map[] = {
418 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_XL710) },
419 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QEMU) },
420 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_B) },
421 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_C) },
422 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_A) },
423 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_B) },
424 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_C) },
425 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T) },
426 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_20G_KR2) },
427 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_20G_KR2_A) },
428 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T4) },
429 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_B) },
430 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_SFP28) },
431 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_X722_A0) },
432 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_X722) },
433 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_X722) },
434 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_X722) },
435 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_1G_BASE_T_X722) },
436 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_X722) },
437 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_I_X722) },
438 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_X710_N3000) },
439 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_XXV710_N3000) },
440 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_BC) },
441 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_5G_BASE_T_BC) },
442 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_B) },
443 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_SFP) },
444 { .vendor_id = 0, /* sentinel */ },
447 static const struct eth_dev_ops i40e_eth_dev_ops = {
448 .dev_configure = i40e_dev_configure,
449 .dev_start = i40e_dev_start,
450 .dev_stop = i40e_dev_stop,
451 .dev_close = i40e_dev_close,
452 .dev_reset = i40e_dev_reset,
453 .promiscuous_enable = i40e_dev_promiscuous_enable,
454 .promiscuous_disable = i40e_dev_promiscuous_disable,
455 .allmulticast_enable = i40e_dev_allmulticast_enable,
456 .allmulticast_disable = i40e_dev_allmulticast_disable,
457 .dev_set_link_up = i40e_dev_set_link_up,
458 .dev_set_link_down = i40e_dev_set_link_down,
459 .link_update = i40e_dev_link_update,
460 .stats_get = i40e_dev_stats_get,
461 .xstats_get = i40e_dev_xstats_get,
462 .xstats_get_names = i40e_dev_xstats_get_names,
463 .stats_reset = i40e_dev_stats_reset,
464 .xstats_reset = i40e_dev_stats_reset,
465 .fw_version_get = i40e_fw_version_get,
466 .dev_infos_get = i40e_dev_info_get,
467 .dev_supported_ptypes_get = i40e_dev_supported_ptypes_get,
468 .vlan_filter_set = i40e_vlan_filter_set,
469 .vlan_tpid_set = i40e_vlan_tpid_set,
470 .vlan_offload_set = i40e_vlan_offload_set,
471 .vlan_strip_queue_set = i40e_vlan_strip_queue_set,
472 .vlan_pvid_set = i40e_vlan_pvid_set,
473 .rx_queue_start = i40e_dev_rx_queue_start,
474 .rx_queue_stop = i40e_dev_rx_queue_stop,
475 .tx_queue_start = i40e_dev_tx_queue_start,
476 .tx_queue_stop = i40e_dev_tx_queue_stop,
477 .rx_queue_setup = i40e_dev_rx_queue_setup,
478 .rx_queue_intr_enable = i40e_dev_rx_queue_intr_enable,
479 .rx_queue_intr_disable = i40e_dev_rx_queue_intr_disable,
480 .rx_queue_release = i40e_dev_rx_queue_release,
481 .tx_queue_setup = i40e_dev_tx_queue_setup,
482 .tx_queue_release = i40e_dev_tx_queue_release,
483 .dev_led_on = i40e_dev_led_on,
484 .dev_led_off = i40e_dev_led_off,
485 .flow_ctrl_get = i40e_flow_ctrl_get,
486 .flow_ctrl_set = i40e_flow_ctrl_set,
487 .priority_flow_ctrl_set = i40e_priority_flow_ctrl_set,
488 .mac_addr_add = i40e_macaddr_add,
489 .mac_addr_remove = i40e_macaddr_remove,
490 .reta_update = i40e_dev_rss_reta_update,
491 .reta_query = i40e_dev_rss_reta_query,
492 .rss_hash_update = i40e_dev_rss_hash_update,
493 .rss_hash_conf_get = i40e_dev_rss_hash_conf_get,
494 .udp_tunnel_port_add = i40e_dev_udp_tunnel_port_add,
495 .udp_tunnel_port_del = i40e_dev_udp_tunnel_port_del,
496 .flow_ops_get = i40e_dev_flow_ops_get,
497 .rxq_info_get = i40e_rxq_info_get,
498 .txq_info_get = i40e_txq_info_get,
499 .rx_burst_mode_get = i40e_rx_burst_mode_get,
500 .tx_burst_mode_get = i40e_tx_burst_mode_get,
501 .timesync_enable = i40e_timesync_enable,
502 .timesync_disable = i40e_timesync_disable,
503 .timesync_read_rx_timestamp = i40e_timesync_read_rx_timestamp,
504 .timesync_read_tx_timestamp = i40e_timesync_read_tx_timestamp,
505 .get_dcb_info = i40e_dev_get_dcb_info,
506 .timesync_adjust_time = i40e_timesync_adjust_time,
507 .timesync_read_time = i40e_timesync_read_time,
508 .timesync_write_time = i40e_timesync_write_time,
509 .get_reg = i40e_get_regs,
510 .get_eeprom_length = i40e_get_eeprom_length,
511 .get_eeprom = i40e_get_eeprom,
512 .get_module_info = i40e_get_module_info,
513 .get_module_eeprom = i40e_get_module_eeprom,
514 .mac_addr_set = i40e_set_default_mac_addr,
515 .mtu_set = i40e_dev_mtu_set,
516 .tm_ops_get = i40e_tm_ops_get,
517 .tx_done_cleanup = i40e_tx_done_cleanup,
518 .get_monitor_addr = i40e_get_monitor_addr,
521 /* store statistics names and its offset in stats structure */
522 struct rte_i40e_xstats_name_off {
523 char name[RTE_ETH_XSTATS_NAME_SIZE];
527 static const struct rte_i40e_xstats_name_off rte_i40e_stats_strings[] = {
528 {"rx_unicast_packets", offsetof(struct i40e_eth_stats, rx_unicast)},
529 {"rx_multicast_packets", offsetof(struct i40e_eth_stats, rx_multicast)},
530 {"rx_broadcast_packets", offsetof(struct i40e_eth_stats, rx_broadcast)},
531 {"rx_dropped_packets", offsetof(struct i40e_eth_stats, rx_discards)},
532 {"rx_unknown_protocol_packets", offsetof(struct i40e_eth_stats,
533 rx_unknown_protocol)},
534 {"rx_size_error_packets", offsetof(struct i40e_pf, rx_err1) -
535 offsetof(struct i40e_pf, stats)},
536 {"tx_unicast_packets", offsetof(struct i40e_eth_stats, tx_unicast)},
537 {"tx_multicast_packets", offsetof(struct i40e_eth_stats, tx_multicast)},
538 {"tx_broadcast_packets", offsetof(struct i40e_eth_stats, tx_broadcast)},
539 {"tx_dropped_packets", offsetof(struct i40e_eth_stats, tx_discards)},
542 #define I40E_NB_ETH_XSTATS (sizeof(rte_i40e_stats_strings) / \
543 sizeof(rte_i40e_stats_strings[0]))
545 static const struct rte_i40e_xstats_name_off rte_i40e_hw_port_strings[] = {
546 {"tx_link_down_dropped", offsetof(struct i40e_hw_port_stats,
547 tx_dropped_link_down)},
548 {"rx_crc_errors", offsetof(struct i40e_hw_port_stats, crc_errors)},
549 {"rx_illegal_byte_errors", offsetof(struct i40e_hw_port_stats,
551 {"rx_error_bytes", offsetof(struct i40e_hw_port_stats, error_bytes)},
552 {"mac_local_errors", offsetof(struct i40e_hw_port_stats,
554 {"mac_remote_errors", offsetof(struct i40e_hw_port_stats,
556 {"rx_length_errors", offsetof(struct i40e_hw_port_stats,
558 {"tx_xon_packets", offsetof(struct i40e_hw_port_stats, link_xon_tx)},
559 {"rx_xon_packets", offsetof(struct i40e_hw_port_stats, link_xon_rx)},
560 {"tx_xoff_packets", offsetof(struct i40e_hw_port_stats, link_xoff_tx)},
561 {"rx_xoff_packets", offsetof(struct i40e_hw_port_stats, link_xoff_rx)},
562 {"rx_size_64_packets", offsetof(struct i40e_hw_port_stats, rx_size_64)},
563 {"rx_size_65_to_127_packets", offsetof(struct i40e_hw_port_stats,
565 {"rx_size_128_to_255_packets", offsetof(struct i40e_hw_port_stats,
567 {"rx_size_256_to_511_packets", offsetof(struct i40e_hw_port_stats,
569 {"rx_size_512_to_1023_packets", offsetof(struct i40e_hw_port_stats,
571 {"rx_size_1024_to_1522_packets", offsetof(struct i40e_hw_port_stats,
573 {"rx_size_1523_to_max_packets", offsetof(struct i40e_hw_port_stats,
575 {"rx_undersized_errors", offsetof(struct i40e_hw_port_stats,
577 {"rx_oversize_errors", offsetof(struct i40e_hw_port_stats,
579 {"rx_mac_short_dropped", offsetof(struct i40e_hw_port_stats,
580 mac_short_packet_dropped)},
581 {"rx_fragmented_errors", offsetof(struct i40e_hw_port_stats,
583 {"rx_jabber_errors", offsetof(struct i40e_hw_port_stats, rx_jabber)},
584 {"tx_size_64_packets", offsetof(struct i40e_hw_port_stats, tx_size_64)},
585 {"tx_size_65_to_127_packets", offsetof(struct i40e_hw_port_stats,
587 {"tx_size_128_to_255_packets", offsetof(struct i40e_hw_port_stats,
589 {"tx_size_256_to_511_packets", offsetof(struct i40e_hw_port_stats,
591 {"tx_size_512_to_1023_packets", offsetof(struct i40e_hw_port_stats,
593 {"tx_size_1024_to_1522_packets", offsetof(struct i40e_hw_port_stats,
595 {"tx_size_1523_to_max_packets", offsetof(struct i40e_hw_port_stats,
597 {"rx_flow_director_atr_match_packets",
598 offsetof(struct i40e_hw_port_stats, fd_atr_match)},
599 {"rx_flow_director_sb_match_packets",
600 offsetof(struct i40e_hw_port_stats, fd_sb_match)},
601 {"tx_low_power_idle_status", offsetof(struct i40e_hw_port_stats,
603 {"rx_low_power_idle_status", offsetof(struct i40e_hw_port_stats,
605 {"tx_low_power_idle_count", offsetof(struct i40e_hw_port_stats,
607 {"rx_low_power_idle_count", offsetof(struct i40e_hw_port_stats,
611 #define I40E_NB_HW_PORT_XSTATS (sizeof(rte_i40e_hw_port_strings) / \
612 sizeof(rte_i40e_hw_port_strings[0]))
614 static const struct rte_i40e_xstats_name_off rte_i40e_rxq_prio_strings[] = {
615 {"xon_packets", offsetof(struct i40e_hw_port_stats,
617 {"xoff_packets", offsetof(struct i40e_hw_port_stats,
621 #define I40E_NB_RXQ_PRIO_XSTATS (sizeof(rte_i40e_rxq_prio_strings) / \
622 sizeof(rte_i40e_rxq_prio_strings[0]))
624 static const struct rte_i40e_xstats_name_off rte_i40e_txq_prio_strings[] = {
625 {"xon_packets", offsetof(struct i40e_hw_port_stats,
627 {"xoff_packets", offsetof(struct i40e_hw_port_stats,
629 {"xon_to_xoff_packets", offsetof(struct i40e_hw_port_stats,
630 priority_xon_2_xoff)},
633 #define I40E_NB_TXQ_PRIO_XSTATS (sizeof(rte_i40e_txq_prio_strings) / \
634 sizeof(rte_i40e_txq_prio_strings[0]))
637 eth_i40e_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
638 struct rte_pci_device *pci_dev)
640 char name[RTE_ETH_NAME_MAX_LEN];
641 struct rte_eth_devargs eth_da = { .nb_representor_ports = 0 };
644 if (pci_dev->device.devargs) {
645 retval = rte_eth_devargs_parse(pci_dev->device.devargs->args,
651 if (eth_da.nb_representor_ports > 0 &&
652 eth_da.type != RTE_ETH_REPRESENTOR_VF) {
653 PMD_DRV_LOG(ERR, "unsupported representor type: %s\n",
654 pci_dev->device.devargs->args);
658 retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
659 sizeof(struct i40e_adapter),
660 eth_dev_pci_specific_init, pci_dev,
661 eth_i40e_dev_init, NULL);
663 if (retval || eth_da.nb_representor_ports < 1)
666 /* probe VF representor ports */
667 struct rte_eth_dev *pf_ethdev = rte_eth_dev_allocated(
668 pci_dev->device.name);
670 if (pf_ethdev == NULL)
673 for (i = 0; i < eth_da.nb_representor_ports; i++) {
674 struct i40e_vf_representor representor = {
675 .vf_id = eth_da.representor_ports[i],
676 .switch_domain_id = I40E_DEV_PRIVATE_TO_PF(
677 pf_ethdev->data->dev_private)->switch_domain_id,
678 .adapter = I40E_DEV_PRIVATE_TO_ADAPTER(
679 pf_ethdev->data->dev_private)
682 /* representor port net_bdf_port */
683 snprintf(name, sizeof(name), "net_%s_representor_%d",
684 pci_dev->device.name, eth_da.representor_ports[i]);
686 retval = rte_eth_dev_create(&pci_dev->device, name,
687 sizeof(struct i40e_vf_representor), NULL, NULL,
688 i40e_vf_representor_init, &representor);
691 PMD_DRV_LOG(ERR, "failed to create i40e vf "
692 "representor %s.", name);
698 static int eth_i40e_pci_remove(struct rte_pci_device *pci_dev)
700 struct rte_eth_dev *ethdev;
702 ethdev = rte_eth_dev_allocated(pci_dev->device.name);
706 if (ethdev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR)
707 return rte_eth_dev_pci_generic_remove(pci_dev,
708 i40e_vf_representor_uninit);
710 return rte_eth_dev_pci_generic_remove(pci_dev,
711 eth_i40e_dev_uninit);
714 static struct rte_pci_driver rte_i40e_pmd = {
715 .id_table = pci_id_i40e_map,
716 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
717 .probe = eth_i40e_pci_probe,
718 .remove = eth_i40e_pci_remove,
722 i40e_write_global_rx_ctl(struct i40e_hw *hw, uint32_t reg_addr,
725 uint32_t ori_reg_val;
726 struct rte_eth_dev_data *dev_data =
727 ((struct i40e_adapter *)hw->back)->pf.dev_data;
728 struct rte_eth_dev *dev = &rte_eth_devices[dev_data->port_id];
730 ori_reg_val = i40e_read_rx_ctl(hw, reg_addr);
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 static inline void i40e_clear_automask(struct i40e_pf *pf)
784 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
787 val = I40E_READ_REG(hw, I40E_GLINT_CTL);
788 val &= ~(I40E_GLINT_CTL_DIS_AUTOMASK_PF0_MASK |
789 I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK);
791 if (!pf->support_multi_driver)
792 val &= ~I40E_GLINT_CTL_DIS_AUTOMASK_N_MASK;
794 I40E_WRITE_REG(hw, I40E_GLINT_CTL, val);
797 #define I40E_FLOW_CONTROL_ETHERTYPE 0x8808
800 * Add a ethertype filter to drop all flow control frames transmitted
804 i40e_add_tx_flow_control_drop_filter(struct i40e_pf *pf)
806 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
807 uint16_t flags = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
808 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
809 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
812 ret = i40e_aq_add_rem_control_packet_filter(hw, NULL,
813 I40E_FLOW_CONTROL_ETHERTYPE, flags,
814 pf->main_vsi_seid, 0,
818 "Failed to add filter to drop flow control frames from VSIs.");
822 floating_veb_list_handler(__rte_unused const char *key,
823 const char *floating_veb_value,
827 unsigned int count = 0;
830 bool *vf_floating_veb = opaque;
832 while (isblank(*floating_veb_value))
833 floating_veb_value++;
835 /* Reset floating VEB configuration for VFs */
836 for (idx = 0; idx < I40E_MAX_VF; idx++)
837 vf_floating_veb[idx] = false;
841 while (isblank(*floating_veb_value))
842 floating_veb_value++;
843 if (*floating_veb_value == '\0')
846 idx = strtoul(floating_veb_value, &end, 10);
847 if (errno || end == NULL)
851 while (isblank(*end))
855 } else if ((*end == ';') || (*end == '\0')) {
857 if (min == I40E_MAX_VF)
859 if (max >= I40E_MAX_VF)
860 max = I40E_MAX_VF - 1;
861 for (idx = min; idx <= max; idx++) {
862 vf_floating_veb[idx] = true;
869 floating_veb_value = end + 1;
870 } while (*end != '\0');
879 config_vf_floating_veb(struct rte_devargs *devargs,
880 uint16_t floating_veb,
881 bool *vf_floating_veb)
883 struct rte_kvargs *kvlist;
885 const char *floating_veb_list = ETH_I40E_FLOATING_VEB_LIST_ARG;
889 /* All the VFs attach to the floating VEB by default
890 * when the floating VEB is enabled.
892 for (i = 0; i < I40E_MAX_VF; i++)
893 vf_floating_veb[i] = true;
898 kvlist = rte_kvargs_parse(devargs->args, valid_keys);
902 if (!rte_kvargs_count(kvlist, floating_veb_list)) {
903 rte_kvargs_free(kvlist);
906 /* When the floating_veb_list parameter exists, all the VFs
907 * will attach to the legacy VEB firstly, then configure VFs
908 * to the floating VEB according to the floating_veb_list.
910 if (rte_kvargs_process(kvlist, floating_veb_list,
911 floating_veb_list_handler,
912 vf_floating_veb) < 0) {
913 rte_kvargs_free(kvlist);
916 rte_kvargs_free(kvlist);
920 i40e_check_floating_handler(__rte_unused const char *key,
922 __rte_unused void *opaque)
924 if (strcmp(value, "1"))
931 is_floating_veb_supported(struct rte_devargs *devargs)
933 struct rte_kvargs *kvlist;
934 const char *floating_veb_key = ETH_I40E_FLOATING_VEB_ARG;
939 kvlist = rte_kvargs_parse(devargs->args, valid_keys);
943 if (!rte_kvargs_count(kvlist, floating_veb_key)) {
944 rte_kvargs_free(kvlist);
947 /* Floating VEB is enabled when there's key-value:
948 * enable_floating_veb=1
950 if (rte_kvargs_process(kvlist, floating_veb_key,
951 i40e_check_floating_handler, NULL) < 0) {
952 rte_kvargs_free(kvlist);
955 rte_kvargs_free(kvlist);
961 config_floating_veb(struct rte_eth_dev *dev)
963 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
964 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
965 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
967 memset(pf->floating_veb_list, 0, sizeof(pf->floating_veb_list));
969 if (hw->aq.fw_maj_ver >= FLOATING_VEB_SUPPORTED_FW_MAJ) {
971 is_floating_veb_supported(pci_dev->device.devargs);
972 config_vf_floating_veb(pci_dev->device.devargs,
974 pf->floating_veb_list);
976 pf->floating_veb = false;
980 #define I40E_L2_TAGS_S_TAG_SHIFT 1
981 #define I40E_L2_TAGS_S_TAG_MASK I40E_MASK(0x1, I40E_L2_TAGS_S_TAG_SHIFT)
984 i40e_init_ethtype_filter_list(struct rte_eth_dev *dev)
986 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
987 struct i40e_ethertype_rule *ethertype_rule = &pf->ethertype;
988 char ethertype_hash_name[RTE_HASH_NAMESIZE];
991 struct rte_hash_parameters ethertype_hash_params = {
992 .name = ethertype_hash_name,
993 .entries = I40E_MAX_ETHERTYPE_FILTER_NUM,
994 .key_len = sizeof(struct i40e_ethertype_filter_input),
995 .hash_func = rte_hash_crc,
996 .hash_func_init_val = 0,
997 .socket_id = rte_socket_id(),
1000 /* Initialize ethertype filter rule list and hash */
1001 TAILQ_INIT(ðertype_rule->ethertype_list);
1002 snprintf(ethertype_hash_name, RTE_HASH_NAMESIZE,
1003 "ethertype_%s", dev->device->name);
1004 ethertype_rule->hash_table = rte_hash_create(ðertype_hash_params);
1005 if (!ethertype_rule->hash_table) {
1006 PMD_INIT_LOG(ERR, "Failed to create ethertype hash table!");
1009 ethertype_rule->hash_map = rte_zmalloc("i40e_ethertype_hash_map",
1010 sizeof(struct i40e_ethertype_filter *) *
1011 I40E_MAX_ETHERTYPE_FILTER_NUM,
1013 if (!ethertype_rule->hash_map) {
1015 "Failed to allocate memory for ethertype hash map!");
1017 goto err_ethertype_hash_map_alloc;
1022 err_ethertype_hash_map_alloc:
1023 rte_hash_free(ethertype_rule->hash_table);
1029 i40e_init_tunnel_filter_list(struct rte_eth_dev *dev)
1031 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1032 struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
1033 char tunnel_hash_name[RTE_HASH_NAMESIZE];
1036 struct rte_hash_parameters tunnel_hash_params = {
1037 .name = tunnel_hash_name,
1038 .entries = I40E_MAX_TUNNEL_FILTER_NUM,
1039 .key_len = sizeof(struct i40e_tunnel_filter_input),
1040 .hash_func = rte_hash_crc,
1041 .hash_func_init_val = 0,
1042 .socket_id = rte_socket_id(),
1045 /* Initialize tunnel filter rule list and hash */
1046 TAILQ_INIT(&tunnel_rule->tunnel_list);
1047 snprintf(tunnel_hash_name, RTE_HASH_NAMESIZE,
1048 "tunnel_%s", dev->device->name);
1049 tunnel_rule->hash_table = rte_hash_create(&tunnel_hash_params);
1050 if (!tunnel_rule->hash_table) {
1051 PMD_INIT_LOG(ERR, "Failed to create tunnel hash table!");
1054 tunnel_rule->hash_map = rte_zmalloc("i40e_tunnel_hash_map",
1055 sizeof(struct i40e_tunnel_filter *) *
1056 I40E_MAX_TUNNEL_FILTER_NUM,
1058 if (!tunnel_rule->hash_map) {
1060 "Failed to allocate memory for tunnel hash map!");
1062 goto err_tunnel_hash_map_alloc;
1067 err_tunnel_hash_map_alloc:
1068 rte_hash_free(tunnel_rule->hash_table);
1074 i40e_init_fdir_filter_list(struct rte_eth_dev *dev)
1076 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1077 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1078 struct i40e_fdir_info *fdir_info = &pf->fdir;
1079 char fdir_hash_name[RTE_HASH_NAMESIZE];
1080 uint32_t alloc = hw->func_caps.fd_filters_guaranteed;
1081 uint32_t best = hw->func_caps.fd_filters_best_effort;
1082 enum i40e_filter_pctype pctype;
1083 struct rte_bitmap *bmp = NULL;
1089 struct rte_hash_parameters fdir_hash_params = {
1090 .name = fdir_hash_name,
1091 .entries = I40E_MAX_FDIR_FILTER_NUM,
1092 .key_len = sizeof(struct i40e_fdir_input),
1093 .hash_func = rte_hash_crc,
1094 .hash_func_init_val = 0,
1095 .socket_id = rte_socket_id(),
1098 /* Initialize flow director filter rule list and hash */
1099 TAILQ_INIT(&fdir_info->fdir_list);
1100 snprintf(fdir_hash_name, RTE_HASH_NAMESIZE,
1101 "fdir_%s", dev->device->name);
1102 fdir_info->hash_table = rte_hash_create(&fdir_hash_params);
1103 if (!fdir_info->hash_table) {
1104 PMD_INIT_LOG(ERR, "Failed to create fdir hash table!");
1108 fdir_info->hash_map = rte_zmalloc("i40e_fdir_hash_map",
1109 sizeof(struct i40e_fdir_filter *) *
1110 I40E_MAX_FDIR_FILTER_NUM,
1112 if (!fdir_info->hash_map) {
1114 "Failed to allocate memory for fdir hash map!");
1116 goto err_fdir_hash_map_alloc;
1119 fdir_info->fdir_filter_array = rte_zmalloc("fdir_filter",
1120 sizeof(struct i40e_fdir_filter) *
1121 I40E_MAX_FDIR_FILTER_NUM,
1124 if (!fdir_info->fdir_filter_array) {
1126 "Failed to allocate memory for fdir filter array!");
1128 goto err_fdir_filter_array_alloc;
1131 for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
1132 pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++)
1133 pf->fdir.flow_count[pctype] = 0;
1135 fdir_info->fdir_space_size = alloc + best;
1136 fdir_info->fdir_actual_cnt = 0;
1137 fdir_info->fdir_guarantee_total_space = alloc;
1138 fdir_info->fdir_guarantee_free_space =
1139 fdir_info->fdir_guarantee_total_space;
1141 PMD_DRV_LOG(INFO, "FDIR guarantee space: %u, best_effort space %u.", alloc, best);
1143 fdir_info->fdir_flow_pool.pool =
1144 rte_zmalloc("i40e_fdir_entry",
1145 sizeof(struct i40e_fdir_entry) *
1146 fdir_info->fdir_space_size,
1149 if (!fdir_info->fdir_flow_pool.pool) {
1151 "Failed to allocate memory for bitmap flow!");
1153 goto err_fdir_bitmap_flow_alloc;
1156 for (i = 0; i < fdir_info->fdir_space_size; i++)
1157 fdir_info->fdir_flow_pool.pool[i].idx = i;
1160 rte_bitmap_get_memory_footprint(fdir_info->fdir_space_size);
1161 mem = rte_zmalloc("fdir_bmap", bmp_size, RTE_CACHE_LINE_SIZE);
1164 "Failed to allocate memory for fdir bitmap!");
1166 goto err_fdir_mem_alloc;
1168 bmp = rte_bitmap_init(fdir_info->fdir_space_size, mem, bmp_size);
1171 "Failed to initialization fdir bitmap!");
1173 goto err_fdir_bmp_alloc;
1175 for (i = 0; i < fdir_info->fdir_space_size; i++)
1176 rte_bitmap_set(bmp, i);
1178 fdir_info->fdir_flow_pool.bitmap = bmp;
1185 rte_free(fdir_info->fdir_flow_pool.pool);
1186 err_fdir_bitmap_flow_alloc:
1187 rte_free(fdir_info->fdir_filter_array);
1188 err_fdir_filter_array_alloc:
1189 rte_free(fdir_info->hash_map);
1190 err_fdir_hash_map_alloc:
1191 rte_hash_free(fdir_info->hash_table);
1197 i40e_init_customized_info(struct i40e_pf *pf)
1201 /* Initialize customized pctype */
1202 for (i = I40E_CUSTOMIZED_GTPC; i < I40E_CUSTOMIZED_MAX; i++) {
1203 pf->customized_pctype[i].index = i;
1204 pf->customized_pctype[i].pctype = I40E_FILTER_PCTYPE_INVALID;
1205 pf->customized_pctype[i].valid = false;
1208 pf->gtp_support = false;
1209 pf->esp_support = false;
1213 i40e_init_filter_invalidation(struct i40e_pf *pf)
1215 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1216 struct i40e_fdir_info *fdir_info = &pf->fdir;
1217 uint32_t glqf_ctl_reg = 0;
1219 glqf_ctl_reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
1220 if (!pf->support_multi_driver) {
1221 fdir_info->fdir_invalprio = 1;
1222 glqf_ctl_reg |= I40E_GLQF_CTL_INVALPRIO_MASK;
1223 PMD_DRV_LOG(INFO, "FDIR INVALPRIO set to guaranteed first");
1224 i40e_write_rx_ctl(hw, I40E_GLQF_CTL, glqf_ctl_reg);
1226 if (glqf_ctl_reg & I40E_GLQF_CTL_INVALPRIO_MASK) {
1227 fdir_info->fdir_invalprio = 1;
1228 PMD_DRV_LOG(INFO, "FDIR INVALPRIO is: guaranteed first");
1230 fdir_info->fdir_invalprio = 0;
1231 PMD_DRV_LOG(INFO, "FDIR INVALPRIO is: shared first");
1237 i40e_init_queue_region_conf(struct rte_eth_dev *dev)
1239 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1240 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1241 struct i40e_queue_regions *info = &pf->queue_region;
1244 for (i = 0; i < I40E_PFQF_HREGION_MAX_INDEX; i++)
1245 i40e_write_rx_ctl(hw, I40E_PFQF_HREGION(i), 0);
1247 memset(info, 0, sizeof(struct i40e_queue_regions));
1251 i40e_parse_multi_drv_handler(__rte_unused const char *key,
1256 unsigned long support_multi_driver;
1259 pf = (struct i40e_pf *)opaque;
1262 support_multi_driver = strtoul(value, &end, 10);
1263 if (errno != 0 || end == value || *end != 0) {
1264 PMD_DRV_LOG(WARNING, "Wrong global configuration");
1268 if (support_multi_driver == 1 || support_multi_driver == 0)
1269 pf->support_multi_driver = (bool)support_multi_driver;
1271 PMD_DRV_LOG(WARNING, "%s must be 1 or 0,",
1272 "enable global configuration by default."
1273 ETH_I40E_SUPPORT_MULTI_DRIVER);
1278 i40e_support_multi_driver(struct rte_eth_dev *dev)
1280 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1281 struct rte_kvargs *kvlist;
1284 /* Enable global configuration by default */
1285 pf->support_multi_driver = false;
1287 if (!dev->device->devargs)
1290 kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
1294 kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_SUPPORT_MULTI_DRIVER);
1295 if (!kvargs_count) {
1296 rte_kvargs_free(kvlist);
1300 if (kvargs_count > 1)
1301 PMD_DRV_LOG(WARNING, "More than one argument \"%s\" and only "
1302 "the first invalid or last valid one is used !",
1303 ETH_I40E_SUPPORT_MULTI_DRIVER);
1305 if (rte_kvargs_process(kvlist, ETH_I40E_SUPPORT_MULTI_DRIVER,
1306 i40e_parse_multi_drv_handler, pf) < 0) {
1307 rte_kvargs_free(kvlist);
1311 rte_kvargs_free(kvlist);
1316 i40e_aq_debug_write_global_register(struct i40e_hw *hw,
1317 uint32_t reg_addr, uint64_t reg_val,
1318 struct i40e_asq_cmd_details *cmd_details)
1320 uint64_t ori_reg_val;
1321 struct rte_eth_dev_data *dev_data =
1322 ((struct i40e_adapter *)hw->back)->pf.dev_data;
1323 struct rte_eth_dev *dev = &rte_eth_devices[dev_data->port_id];
1326 ret = i40e_aq_debug_read_register(hw, reg_addr, &ori_reg_val, NULL);
1327 if (ret != I40E_SUCCESS) {
1329 "Fail to debug read from 0x%08x",
1334 if (ori_reg_val != reg_val)
1335 PMD_DRV_LOG(WARNING,
1336 "i40e device %s changed global register [0x%08x]."
1337 " original: 0x%"PRIx64", after: 0x%"PRIx64,
1338 dev->device->name, reg_addr, ori_reg_val, reg_val);
1340 return i40e_aq_debug_write_register(hw, reg_addr, reg_val, cmd_details);
1344 read_vf_msg_config(__rte_unused const char *key,
1348 struct i40e_vf_msg_cfg *cfg = opaque;
1350 if (sscanf(value, "%u@%u:%u", &cfg->max_msg, &cfg->period,
1351 &cfg->ignore_second) != 3) {
1352 memset(cfg, 0, sizeof(*cfg));
1353 PMD_DRV_LOG(ERR, "format error! example: "
1354 "%s=60@120:180", ETH_I40E_VF_MSG_CFG);
1359 * If the message validation function been enabled, the 'period'
1360 * and 'ignore_second' must greater than 0.
1362 if (cfg->max_msg && (!cfg->period || !cfg->ignore_second)) {
1363 memset(cfg, 0, sizeof(*cfg));
1364 PMD_DRV_LOG(ERR, "%s error! the second and third"
1365 " number must be greater than 0!",
1366 ETH_I40E_VF_MSG_CFG);
1374 i40e_parse_vf_msg_config(struct rte_eth_dev *dev,
1375 struct i40e_vf_msg_cfg *msg_cfg)
1377 struct rte_kvargs *kvlist;
1381 memset(msg_cfg, 0, sizeof(*msg_cfg));
1383 if (!dev->device->devargs)
1386 kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
1390 kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_VF_MSG_CFG);
1394 if (kvargs_count > 1) {
1395 PMD_DRV_LOG(ERR, "More than one argument \"%s\"!",
1396 ETH_I40E_VF_MSG_CFG);
1401 if (rte_kvargs_process(kvlist, ETH_I40E_VF_MSG_CFG,
1402 read_vf_msg_config, msg_cfg) < 0)
1406 rte_kvargs_free(kvlist);
1410 #define I40E_ALARM_INTERVAL 50000 /* us */
1413 eth_i40e_dev_init(struct rte_eth_dev *dev, void *init_params __rte_unused)
1415 struct rte_pci_device *pci_dev;
1416 struct rte_intr_handle *intr_handle;
1417 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1418 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1419 struct i40e_vsi *vsi;
1422 uint8_t aq_fail = 0;
1424 PMD_INIT_FUNC_TRACE();
1426 dev->dev_ops = &i40e_eth_dev_ops;
1427 dev->rx_queue_count = i40e_dev_rx_queue_count;
1428 dev->rx_descriptor_status = i40e_dev_rx_descriptor_status;
1429 dev->tx_descriptor_status = i40e_dev_tx_descriptor_status;
1430 dev->rx_pkt_burst = i40e_recv_pkts;
1431 dev->tx_pkt_burst = i40e_xmit_pkts;
1432 dev->tx_pkt_prepare = i40e_prep_pkts;
1434 /* for secondary processes, we don't initialise any further as primary
1435 * has already done this work. Only check we don't need a different
1437 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
1438 i40e_set_rx_function(dev);
1439 i40e_set_tx_function(dev);
1442 i40e_set_default_ptype_table(dev);
1443 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1444 intr_handle = pci_dev->intr_handle;
1446 rte_eth_copy_pci_info(dev, pci_dev);
1448 pf->adapter = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1449 pf->dev_data = dev->data;
1451 hw->back = I40E_PF_TO_ADAPTER(pf);
1452 hw->hw_addr = (uint8_t *)(pci_dev->mem_resource[0].addr);
1455 "Hardware is not available, as address is NULL");
1459 hw->vendor_id = pci_dev->id.vendor_id;
1460 hw->device_id = pci_dev->id.device_id;
1461 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
1462 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
1463 hw->bus.device = pci_dev->addr.devid;
1464 hw->bus.func = pci_dev->addr.function;
1465 hw->adapter_stopped = 0;
1466 hw->adapter_closed = 0;
1468 /* Init switch device pointer */
1469 hw->switch_dev = NULL;
1472 * Switch Tag value should not be identical to either the First Tag
1473 * or Second Tag values. So set something other than common Ethertype
1474 * for internal switching.
1476 hw->switch_tag = 0xffff;
1478 val = I40E_READ_REG(hw, I40E_GL_FWSTS);
1479 if (val & I40E_GL_FWSTS_FWS1B_MASK) {
1480 PMD_INIT_LOG(ERR, "\nERROR: "
1481 "Firmware recovery mode detected. Limiting functionality.\n"
1482 "Refer to the Intel(R) Ethernet Adapters and Devices "
1483 "User Guide for details on firmware recovery mode.");
1487 i40e_parse_vf_msg_config(dev, &pf->vf_msg_cfg);
1488 /* Check if need to support multi-driver */
1489 i40e_support_multi_driver(dev);
1491 /* Make sure all is clean before doing PF reset */
1494 /* Reset here to make sure all is clean for each PF */
1495 ret = i40e_pf_reset(hw);
1497 PMD_INIT_LOG(ERR, "Failed to reset pf: %d", ret);
1501 /* Initialize the shared code (base driver) */
1502 ret = i40e_init_shared_code(hw);
1504 PMD_INIT_LOG(ERR, "Failed to init shared code (base driver): %d", ret);
1508 /* Initialize the parameters for adminq */
1509 i40e_init_adminq_parameter(hw);
1510 ret = i40e_init_adminq(hw);
1511 if (ret != I40E_SUCCESS) {
1512 PMD_INIT_LOG(ERR, "Failed to init adminq: %d", ret);
1515 /* Firmware of SFP x722 does not support 802.1ad frames ability */
1516 if (hw->device_id == I40E_DEV_ID_SFP_X722 ||
1517 hw->device_id == I40E_DEV_ID_SFP_I_X722)
1518 hw->flags &= ~I40E_HW_FLAG_802_1AD_CAPABLE;
1520 PMD_INIT_LOG(INFO, "FW %d.%d API %d.%d NVM %02d.%02d.%02d eetrack %04x",
1521 hw->aq.fw_maj_ver, hw->aq.fw_min_ver,
1522 hw->aq.api_maj_ver, hw->aq.api_min_ver,
1523 ((hw->nvm.version >> 12) & 0xf),
1524 ((hw->nvm.version >> 4) & 0xff),
1525 (hw->nvm.version & 0xf), hw->nvm.eetrack);
1527 /* Initialize the hardware */
1530 i40e_config_automask(pf);
1532 i40e_set_default_pctype_table(dev);
1535 * To work around the NVM issue, initialize registers
1536 * for packet type of QinQ by software.
1537 * It should be removed once issues are fixed in NVM.
1539 if (!pf->support_multi_driver)
1540 i40e_GLQF_reg_init(hw);
1542 /* Initialize the input set for filters (hash and fd) to default value */
1543 i40e_filter_input_set_init(pf);
1545 /* initialise the L3_MAP register */
1546 if (!pf->support_multi_driver) {
1547 ret = i40e_aq_debug_write_global_register(hw,
1548 I40E_GLQF_L3_MAP(40),
1551 PMD_INIT_LOG(ERR, "Failed to write L3 MAP register %d",
1554 "Global register 0x%08x is changed with 0x28",
1555 I40E_GLQF_L3_MAP(40));
1558 /* Need the special FW version to support floating VEB */
1559 config_floating_veb(dev);
1560 /* Clear PXE mode */
1561 i40e_clear_pxe_mode(hw);
1562 i40e_dev_sync_phy_type(hw);
1565 * On X710, performance number is far from the expectation on recent
1566 * firmware versions. The fix for this issue may not be integrated in
1567 * the following firmware version. So the workaround in software driver
1568 * is needed. It needs to modify the initial values of 3 internal only
1569 * registers. Note that the workaround can be removed when it is fixed
1570 * in firmware in the future.
1572 i40e_configure_registers(hw);
1574 /* Get hw capabilities */
1575 ret = i40e_get_cap(hw);
1576 if (ret != I40E_SUCCESS) {
1577 PMD_INIT_LOG(ERR, "Failed to get capabilities: %d", ret);
1578 goto err_get_capabilities;
1581 /* Initialize parameters for PF */
1582 ret = i40e_pf_parameter_init(dev);
1584 PMD_INIT_LOG(ERR, "Failed to do parameter init: %d", ret);
1585 goto err_parameter_init;
1588 /* Initialize the queue management */
1589 ret = i40e_res_pool_init(&pf->qp_pool, 0, hw->func_caps.num_tx_qp);
1591 PMD_INIT_LOG(ERR, "Failed to init queue pool");
1592 goto err_qp_pool_init;
1594 ret = i40e_res_pool_init(&pf->msix_pool, 1,
1595 hw->func_caps.num_msix_vectors - 1);
1597 PMD_INIT_LOG(ERR, "Failed to init MSIX pool");
1598 goto err_msix_pool_init;
1601 /* Initialize lan hmc */
1602 ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
1603 hw->func_caps.num_rx_qp, 0, 0);
1604 if (ret != I40E_SUCCESS) {
1605 PMD_INIT_LOG(ERR, "Failed to init lan hmc: %d", ret);
1606 goto err_init_lan_hmc;
1609 /* Configure lan hmc */
1610 ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
1611 if (ret != I40E_SUCCESS) {
1612 PMD_INIT_LOG(ERR, "Failed to configure lan hmc: %d", ret);
1613 goto err_configure_lan_hmc;
1616 /* Get and check the mac address */
1617 i40e_get_mac_addr(hw, hw->mac.addr);
1618 if (i40e_validate_mac_addr(hw->mac.addr) != I40E_SUCCESS) {
1619 PMD_INIT_LOG(ERR, "mac address is not valid");
1621 goto err_get_mac_addr;
1623 /* Copy the permanent MAC address */
1624 rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
1625 (struct rte_ether_addr *)hw->mac.perm_addr);
1627 /* Disable flow control */
1628 hw->fc.requested_mode = I40E_FC_NONE;
1629 i40e_set_fc(hw, &aq_fail, TRUE);
1631 /* Set the global registers with default ether type value */
1632 if (!pf->support_multi_driver) {
1633 ret = i40e_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_OUTER,
1634 RTE_ETHER_TYPE_VLAN);
1635 if (ret != I40E_SUCCESS) {
1637 "Failed to set the default outer "
1639 goto err_setup_pf_switch;
1643 /* PF setup, which includes VSI setup */
1644 ret = i40e_pf_setup(pf);
1646 PMD_INIT_LOG(ERR, "Failed to setup pf switch: %d", ret);
1647 goto err_setup_pf_switch;
1652 /* Disable double vlan by default */
1653 i40e_vsi_config_double_vlan(vsi, FALSE);
1655 /* Disable S-TAG identification when floating_veb is disabled */
1656 if (!pf->floating_veb) {
1657 ret = I40E_READ_REG(hw, I40E_PRT_L2TAGSEN);
1658 if (ret & I40E_L2_TAGS_S_TAG_MASK) {
1659 ret &= ~I40E_L2_TAGS_S_TAG_MASK;
1660 I40E_WRITE_REG(hw, I40E_PRT_L2TAGSEN, ret);
1664 if (!vsi->max_macaddrs)
1665 len = RTE_ETHER_ADDR_LEN;
1667 len = RTE_ETHER_ADDR_LEN * vsi->max_macaddrs;
1669 /* Should be after VSI initialized */
1670 dev->data->mac_addrs = rte_zmalloc("i40e", len, 0);
1671 if (!dev->data->mac_addrs) {
1673 "Failed to allocated memory for storing mac address");
1676 rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.perm_addr,
1677 &dev->data->mac_addrs[0]);
1679 /* Init dcb to sw mode by default */
1680 ret = i40e_dcb_init_configure(dev, TRUE);
1681 if (ret != I40E_SUCCESS) {
1682 PMD_INIT_LOG(INFO, "Failed to init dcb.");
1683 pf->flags &= ~I40E_FLAG_DCB;
1685 /* Update HW struct after DCB configuration */
1688 /* initialize pf host driver to setup SRIOV resource if applicable */
1689 i40e_pf_host_init(dev);
1691 /* register callback func to eal lib */
1692 rte_intr_callback_register(intr_handle,
1693 i40e_dev_interrupt_handler, dev);
1695 /* configure and enable device interrupt */
1696 i40e_pf_config_irq0(hw, TRUE);
1697 i40e_pf_enable_irq0(hw);
1699 /* enable uio intr after callback register */
1700 rte_intr_enable(intr_handle);
1702 /* By default disable flexible payload in global configuration */
1703 if (!pf->support_multi_driver)
1704 i40e_flex_payload_reg_set_default(hw);
1707 * Add an ethertype filter to drop all flow control frames transmitted
1708 * from VSIs. By doing so, we stop VF from sending out PAUSE or PFC
1711 i40e_add_tx_flow_control_drop_filter(pf);
1713 /* initialize RSS rule list */
1714 TAILQ_INIT(&pf->rss_config_list);
1716 /* initialize Traffic Manager configuration */
1717 i40e_tm_conf_init(dev);
1719 /* Initialize customized information */
1720 i40e_init_customized_info(pf);
1722 /* Initialize the filter invalidation configuration */
1723 i40e_init_filter_invalidation(pf);
1725 ret = i40e_init_ethtype_filter_list(dev);
1727 goto err_init_ethtype_filter_list;
1728 ret = i40e_init_tunnel_filter_list(dev);
1730 goto err_init_tunnel_filter_list;
1731 ret = i40e_init_fdir_filter_list(dev);
1733 goto err_init_fdir_filter_list;
1735 /* initialize queue region configuration */
1736 i40e_init_queue_region_conf(dev);
1738 /* reset all stats of the device, including pf and main vsi */
1739 i40e_dev_stats_reset(dev);
1743 err_init_fdir_filter_list:
1744 rte_hash_free(pf->tunnel.hash_table);
1745 rte_free(pf->tunnel.hash_map);
1746 err_init_tunnel_filter_list:
1747 rte_hash_free(pf->ethertype.hash_table);
1748 rte_free(pf->ethertype.hash_map);
1749 err_init_ethtype_filter_list:
1750 rte_intr_callback_unregister(intr_handle,
1751 i40e_dev_interrupt_handler, dev);
1752 rte_free(dev->data->mac_addrs);
1753 dev->data->mac_addrs = NULL;
1755 i40e_vsi_release(pf->main_vsi);
1756 err_setup_pf_switch:
1758 err_configure_lan_hmc:
1759 (void)i40e_shutdown_lan_hmc(hw);
1761 i40e_res_pool_destroy(&pf->msix_pool);
1763 i40e_res_pool_destroy(&pf->qp_pool);
1766 err_get_capabilities:
1767 (void)i40e_shutdown_adminq(hw);
1773 i40e_rm_ethtype_filter_list(struct i40e_pf *pf)
1775 struct i40e_ethertype_filter *p_ethertype;
1776 struct i40e_ethertype_rule *ethertype_rule;
1778 ethertype_rule = &pf->ethertype;
1779 /* Remove all ethertype filter rules and hash */
1780 rte_free(ethertype_rule->hash_map);
1781 rte_hash_free(ethertype_rule->hash_table);
1783 while ((p_ethertype = TAILQ_FIRST(ðertype_rule->ethertype_list))) {
1784 TAILQ_REMOVE(ðertype_rule->ethertype_list,
1785 p_ethertype, rules);
1786 rte_free(p_ethertype);
1791 i40e_rm_tunnel_filter_list(struct i40e_pf *pf)
1793 struct i40e_tunnel_filter *p_tunnel;
1794 struct i40e_tunnel_rule *tunnel_rule;
1796 tunnel_rule = &pf->tunnel;
1797 /* Remove all tunnel director rules and hash */
1798 rte_free(tunnel_rule->hash_map);
1799 rte_hash_free(tunnel_rule->hash_table);
1801 while ((p_tunnel = TAILQ_FIRST(&tunnel_rule->tunnel_list))) {
1802 TAILQ_REMOVE(&tunnel_rule->tunnel_list, p_tunnel, rules);
1808 i40e_rm_fdir_filter_list(struct i40e_pf *pf)
1810 struct i40e_fdir_filter *p_fdir;
1811 struct i40e_fdir_info *fdir_info;
1813 fdir_info = &pf->fdir;
1815 /* Remove all flow director rules */
1816 while ((p_fdir = TAILQ_FIRST(&fdir_info->fdir_list)))
1817 TAILQ_REMOVE(&fdir_info->fdir_list, p_fdir, rules);
1821 i40e_fdir_memory_cleanup(struct i40e_pf *pf)
1823 struct i40e_fdir_info *fdir_info;
1825 fdir_info = &pf->fdir;
1827 /* flow director memory cleanup */
1828 rte_free(fdir_info->hash_map);
1829 rte_hash_free(fdir_info->hash_table);
1830 rte_free(fdir_info->fdir_flow_pool.bitmap);
1831 rte_free(fdir_info->fdir_flow_pool.pool);
1832 rte_free(fdir_info->fdir_filter_array);
1835 void i40e_flex_payload_reg_set_default(struct i40e_hw *hw)
1838 * Disable by default flexible payload
1839 * for corresponding L2/L3/L4 layers.
1841 I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(33), 0x00000000);
1842 I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(34), 0x00000000);
1843 I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(35), 0x00000000);
1847 eth_i40e_dev_uninit(struct rte_eth_dev *dev)
1851 PMD_INIT_FUNC_TRACE();
1853 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1856 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1858 if (hw->adapter_closed == 0)
1859 i40e_dev_close(dev);
1865 i40e_dev_configure(struct rte_eth_dev *dev)
1867 struct i40e_adapter *ad =
1868 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1869 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1870 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1871 enum rte_eth_rx_mq_mode mq_mode = dev->data->dev_conf.rxmode.mq_mode;
1874 ret = i40e_dev_sync_phy_type(hw);
1878 /* Initialize to TRUE. If any of Rx queues doesn't meet the
1879 * bulk allocation or vector Rx preconditions we will reset it.
1881 ad->rx_bulk_alloc_allowed = true;
1882 ad->rx_vec_allowed = true;
1883 ad->tx_simple_allowed = true;
1884 ad->tx_vec_allowed = true;
1886 if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
1887 dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
1889 /* Only legacy filter API needs the following fdir config. So when the
1890 * legacy filter API is deprecated, the following codes should also be
1893 if (dev->data->dev_conf.fdir_conf.mode == RTE_FDIR_MODE_PERFECT) {
1894 ret = i40e_fdir_setup(pf);
1895 if (ret != I40E_SUCCESS) {
1896 PMD_DRV_LOG(ERR, "Failed to setup flow director.");
1899 ret = i40e_fdir_configure(dev);
1901 PMD_DRV_LOG(ERR, "failed to configure fdir.");
1905 i40e_fdir_teardown(pf);
1907 ret = i40e_dev_init_vlan(dev);
1912 * General PMD call sequence are NIC init, configure,
1913 * rx/tx_queue_setup and dev_start. In rx/tx_queue_setup() function, it
1914 * will try to lookup the VSI that specific queue belongs to if VMDQ
1915 * applicable. So, VMDQ setting has to be done before
1916 * rx/tx_queue_setup(). This function is good to place vmdq_setup.
1917 * For RSS setting, it will try to calculate actual configured RX queue
1918 * number, which will be available after rx_queue_setup(). dev_start()
1919 * function is good to place RSS setup.
1921 if (mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG) {
1922 ret = i40e_vmdq_setup(dev);
1927 if (mq_mode & RTE_ETH_MQ_RX_DCB_FLAG) {
1928 ret = i40e_dcb_setup(dev);
1930 PMD_DRV_LOG(ERR, "failed to configure DCB.");
1935 TAILQ_INIT(&pf->flow_list);
1940 /* need to release vmdq resource if exists */
1941 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1942 i40e_vsi_release(pf->vmdq[i].vsi);
1943 pf->vmdq[i].vsi = NULL;
1948 /* Need to release fdir resource if exists.
1949 * Only legacy filter API needs the following fdir config. So when the
1950 * legacy filter API is deprecated, the following code should also be
1953 i40e_fdir_teardown(pf);
1958 i40e_vsi_queues_unbind_intr(struct i40e_vsi *vsi)
1960 struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
1961 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1962 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1963 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1964 uint16_t msix_vect = vsi->msix_intr;
1967 for (i = 0; i < vsi->nb_qps; i++) {
1968 I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
1969 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
1973 if (vsi->type != I40E_VSI_SRIOV) {
1974 if (!rte_intr_allow_others(intr_handle)) {
1975 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
1976 I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
1978 I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
1981 I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
1982 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
1984 I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
1989 reg = (hw->func_caps.num_msix_vectors_vf - 1) *
1990 vsi->user_param + (msix_vect - 1);
1992 I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
1993 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
1995 I40E_WRITE_FLUSH(hw);
1999 __vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t msix_vect,
2000 int base_queue, int nb_queue,
2005 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2006 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2008 /* Bind all RX queues to allocated MSIX interrupt */
2009 for (i = 0; i < nb_queue; i++) {
2010 val = (msix_vect << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
2011 itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT |
2012 ((base_queue + i + 1) <<
2013 I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
2014 (0 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
2015 I40E_QINT_RQCTL_CAUSE_ENA_MASK;
2017 if (i == nb_queue - 1)
2018 val |= I40E_QINT_RQCTL_NEXTQ_INDX_MASK;
2019 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(base_queue + i), val);
2022 /* Write first RX queue to Link list register as the head element */
2023 if (vsi->type != I40E_VSI_SRIOV) {
2025 i40e_calc_itr_interval(1, pf->support_multi_driver);
2027 if (msix_vect == I40E_MISC_VEC_ID) {
2028 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
2030 I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
2032 I40E_PFINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
2034 I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
2037 I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
2039 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
2041 I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
2043 I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
2050 if (msix_vect == I40E_MISC_VEC_ID) {
2052 I40E_VPINT_LNKLST0(vsi->user_param),
2054 I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
2056 I40E_VPINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
2058 /* num_msix_vectors_vf needs to minus irq0 */
2059 reg = (hw->func_caps.num_msix_vectors_vf - 1) *
2060 vsi->user_param + (msix_vect - 1);
2062 I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
2064 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
2066 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
2070 I40E_WRITE_FLUSH(hw);
2074 i40e_vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t itr_idx)
2076 struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
2077 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2078 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2079 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2080 uint16_t msix_vect = vsi->msix_intr;
2081 uint16_t nb_msix = RTE_MIN(vsi->nb_msix,
2082 rte_intr_nb_efd_get(intr_handle));
2083 uint16_t queue_idx = 0;
2087 for (i = 0; i < vsi->nb_qps; i++) {
2088 I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
2089 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
2092 /* VF bind interrupt */
2093 if (vsi->type == I40E_VSI_SRIOV) {
2094 if (vsi->nb_msix == 0) {
2095 PMD_DRV_LOG(ERR, "No msix resource");
2098 __vsi_queues_bind_intr(vsi, msix_vect,
2099 vsi->base_queue, vsi->nb_qps,
2104 /* PF & VMDq bind interrupt */
2105 if (rte_intr_dp_is_en(intr_handle)) {
2106 if (vsi->type == I40E_VSI_MAIN) {
2109 } else if (vsi->type == I40E_VSI_VMDQ2) {
2110 struct i40e_vsi *main_vsi =
2111 I40E_DEV_PRIVATE_TO_MAIN_VSI(vsi->adapter);
2112 queue_idx = vsi->base_queue - main_vsi->nb_qps;
2117 for (i = 0; i < vsi->nb_used_qps; i++) {
2118 if (vsi->nb_msix == 0) {
2119 PMD_DRV_LOG(ERR, "No msix resource");
2121 } else if (nb_msix <= 1) {
2122 if (!rte_intr_allow_others(intr_handle))
2123 /* allow to share MISC_VEC_ID */
2124 msix_vect = I40E_MISC_VEC_ID;
2126 /* no enough msix_vect, map all to one */
2127 __vsi_queues_bind_intr(vsi, msix_vect,
2128 vsi->base_queue + i,
2129 vsi->nb_used_qps - i,
2131 for (; !!record && i < vsi->nb_used_qps; i++)
2132 rte_intr_vec_list_index_set(intr_handle,
2133 queue_idx + i, msix_vect);
2136 /* 1:1 queue/msix_vect mapping */
2137 __vsi_queues_bind_intr(vsi, msix_vect,
2138 vsi->base_queue + i, 1,
2141 if (rte_intr_vec_list_index_set(intr_handle,
2142 queue_idx + i, msix_vect))
2153 i40e_vsi_enable_queues_intr(struct i40e_vsi *vsi)
2155 struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
2156 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2157 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2158 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2159 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2160 uint16_t msix_intr, i;
2162 if (rte_intr_allow_others(intr_handle) && !pf->support_multi_driver)
2163 for (i = 0; i < vsi->nb_msix; i++) {
2164 msix_intr = vsi->msix_intr + i;
2165 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
2166 I40E_PFINT_DYN_CTLN_INTENA_MASK |
2167 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
2168 I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
2171 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
2172 I40E_PFINT_DYN_CTL0_INTENA_MASK |
2173 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
2174 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
2176 I40E_WRITE_FLUSH(hw);
2180 i40e_vsi_disable_queues_intr(struct i40e_vsi *vsi)
2182 struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
2183 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2184 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2185 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2186 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2187 uint16_t msix_intr, i;
2189 if (rte_intr_allow_others(intr_handle) && !pf->support_multi_driver)
2190 for (i = 0; i < vsi->nb_msix; i++) {
2191 msix_intr = vsi->msix_intr + i;
2192 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
2193 I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
2196 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
2197 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
2199 I40E_WRITE_FLUSH(hw);
2202 static inline uint8_t
2203 i40e_parse_link_speeds(uint16_t link_speeds)
2205 uint8_t link_speed = I40E_LINK_SPEED_UNKNOWN;
2207 if (link_speeds & RTE_ETH_LINK_SPEED_40G)
2208 link_speed |= I40E_LINK_SPEED_40GB;
2209 if (link_speeds & RTE_ETH_LINK_SPEED_25G)
2210 link_speed |= I40E_LINK_SPEED_25GB;
2211 if (link_speeds & RTE_ETH_LINK_SPEED_20G)
2212 link_speed |= I40E_LINK_SPEED_20GB;
2213 if (link_speeds & RTE_ETH_LINK_SPEED_10G)
2214 link_speed |= I40E_LINK_SPEED_10GB;
2215 if (link_speeds & RTE_ETH_LINK_SPEED_1G)
2216 link_speed |= I40E_LINK_SPEED_1GB;
2217 if (link_speeds & RTE_ETH_LINK_SPEED_100M)
2218 link_speed |= I40E_LINK_SPEED_100MB;
2224 i40e_phy_conf_link(struct i40e_hw *hw,
2226 uint8_t force_speed,
2229 enum i40e_status_code status;
2230 struct i40e_aq_get_phy_abilities_resp phy_ab;
2231 struct i40e_aq_set_phy_config phy_conf;
2232 enum i40e_aq_phy_type cnt;
2233 uint8_t avail_speed;
2234 uint32_t phy_type_mask = 0;
2236 const uint8_t mask = I40E_AQ_PHY_FLAG_PAUSE_TX |
2237 I40E_AQ_PHY_FLAG_PAUSE_RX |
2238 I40E_AQ_PHY_FLAG_PAUSE_RX |
2239 I40E_AQ_PHY_FLAG_LOW_POWER;
2242 /* To get phy capabilities of available speeds. */
2243 status = i40e_aq_get_phy_capabilities(hw, false, true, &phy_ab,
2246 PMD_DRV_LOG(ERR, "Failed to get PHY capabilities: %d\n",
2250 avail_speed = phy_ab.link_speed;
2252 /* To get the current phy config. */
2253 status = i40e_aq_get_phy_capabilities(hw, false, false, &phy_ab,
2256 PMD_DRV_LOG(ERR, "Failed to get the current PHY config: %d\n",
2261 /* If link needs to go up and it is in autoneg mode the speed is OK,
2262 * no need to set up again.
2264 if (is_up && phy_ab.phy_type != 0 &&
2265 abilities & I40E_AQ_PHY_AN_ENABLED &&
2266 phy_ab.link_speed != 0)
2267 return I40E_SUCCESS;
2269 memset(&phy_conf, 0, sizeof(phy_conf));
2271 /* bits 0-2 use the values from get_phy_abilities_resp */
2273 abilities |= phy_ab.abilities & mask;
2275 phy_conf.abilities = abilities;
2277 /* If link needs to go up, but the force speed is not supported,
2278 * Warn users and config the default available speeds.
2280 if (is_up && !(force_speed & avail_speed)) {
2281 PMD_DRV_LOG(WARNING, "Invalid speed setting, set to default!\n");
2282 phy_conf.link_speed = avail_speed;
2284 phy_conf.link_speed = is_up ? force_speed : avail_speed;
2287 /* PHY type mask needs to include each type except PHY type extension */
2288 for (cnt = I40E_PHY_TYPE_SGMII; cnt < I40E_PHY_TYPE_25GBASE_KR; cnt++)
2289 phy_type_mask |= 1 << cnt;
2291 /* use get_phy_abilities_resp value for the rest */
2292 phy_conf.phy_type = is_up ? cpu_to_le32(phy_type_mask) : 0;
2293 phy_conf.phy_type_ext = is_up ? (I40E_AQ_PHY_TYPE_EXT_25G_KR |
2294 I40E_AQ_PHY_TYPE_EXT_25G_CR | I40E_AQ_PHY_TYPE_EXT_25G_SR |
2295 I40E_AQ_PHY_TYPE_EXT_25G_LR | I40E_AQ_PHY_TYPE_EXT_25G_AOC |
2296 I40E_AQ_PHY_TYPE_EXT_25G_ACC) : 0;
2297 phy_conf.fec_config = phy_ab.fec_cfg_curr_mod_ext_info;
2298 phy_conf.eee_capability = phy_ab.eee_capability;
2299 phy_conf.eeer = phy_ab.eeer_val;
2300 phy_conf.low_power_ctrl = phy_ab.d3_lpan;
2302 PMD_DRV_LOG(DEBUG, "\tCurrent: abilities %x, link_speed %x",
2303 phy_ab.abilities, phy_ab.link_speed);
2304 PMD_DRV_LOG(DEBUG, "\tConfig: abilities %x, link_speed %x",
2305 phy_conf.abilities, phy_conf.link_speed);
2307 status = i40e_aq_set_phy_config(hw, &phy_conf, NULL);
2311 return I40E_SUCCESS;
2315 i40e_apply_link_speed(struct rte_eth_dev *dev)
2318 uint8_t abilities = 0;
2319 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2320 struct rte_eth_conf *conf = &dev->data->dev_conf;
2322 abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK |
2323 I40E_AQ_PHY_LINK_ENABLED;
2325 if (conf->link_speeds == RTE_ETH_LINK_SPEED_AUTONEG) {
2326 conf->link_speeds = RTE_ETH_LINK_SPEED_40G |
2327 RTE_ETH_LINK_SPEED_25G |
2328 RTE_ETH_LINK_SPEED_20G |
2329 RTE_ETH_LINK_SPEED_10G |
2330 RTE_ETH_LINK_SPEED_1G |
2331 RTE_ETH_LINK_SPEED_100M;
2333 abilities |= I40E_AQ_PHY_AN_ENABLED;
2335 abilities &= ~I40E_AQ_PHY_AN_ENABLED;
2337 speed = i40e_parse_link_speeds(conf->link_speeds);
2339 return i40e_phy_conf_link(hw, abilities, speed, true);
2343 i40e_dev_start(struct rte_eth_dev *dev)
2345 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2346 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2347 struct i40e_vsi *main_vsi = pf->main_vsi;
2349 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2350 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2351 uint32_t intr_vector = 0;
2352 struct i40e_vsi *vsi;
2353 uint16_t nb_rxq, nb_txq;
2354 uint16_t max_frame_size;
2356 hw->adapter_stopped = 0;
2358 rte_intr_disable(intr_handle);
2360 if ((rte_intr_cap_multiple(intr_handle) ||
2361 !RTE_ETH_DEV_SRIOV(dev).active) &&
2362 dev->data->dev_conf.intr_conf.rxq != 0) {
2363 intr_vector = dev->data->nb_rx_queues;
2364 ret = rte_intr_efd_enable(intr_handle, intr_vector);
2369 if (rte_intr_dp_is_en(intr_handle)) {
2370 if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
2371 dev->data->nb_rx_queues)) {
2373 "Failed to allocate %d rx_queues intr_vec",
2374 dev->data->nb_rx_queues);
2379 /* Initialize VSI */
2380 ret = i40e_dev_rxtx_init(pf);
2381 if (ret != I40E_SUCCESS) {
2382 PMD_DRV_LOG(ERR, "Failed to init rx/tx queues");
2386 /* Map queues with MSIX interrupt */
2387 main_vsi->nb_used_qps = dev->data->nb_rx_queues -
2388 pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
2389 ret = i40e_vsi_queues_bind_intr(main_vsi, I40E_ITR_INDEX_DEFAULT);
2392 i40e_vsi_enable_queues_intr(main_vsi);
2394 /* Map VMDQ VSI queues with MSIX interrupt */
2395 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2396 pf->vmdq[i].vsi->nb_used_qps = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
2397 ret = i40e_vsi_queues_bind_intr(pf->vmdq[i].vsi,
2398 I40E_ITR_INDEX_DEFAULT);
2401 i40e_vsi_enable_queues_intr(pf->vmdq[i].vsi);
2404 /* Enable all queues which have been configured */
2405 for (nb_rxq = 0; nb_rxq < dev->data->nb_rx_queues; nb_rxq++) {
2406 ret = i40e_dev_rx_queue_start(dev, nb_rxq);
2411 for (nb_txq = 0; nb_txq < dev->data->nb_tx_queues; nb_txq++) {
2412 ret = i40e_dev_tx_queue_start(dev, nb_txq);
2417 /* Enable receiving broadcast packets */
2418 ret = i40e_aq_set_vsi_broadcast(hw, main_vsi->seid, true, NULL);
2419 if (ret != I40E_SUCCESS)
2420 PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
2422 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2423 ret = i40e_aq_set_vsi_broadcast(hw, pf->vmdq[i].vsi->seid,
2425 if (ret != I40E_SUCCESS)
2426 PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
2429 /* Enable the VLAN promiscuous mode. */
2431 for (i = 0; i < pf->vf_num; i++) {
2432 vsi = pf->vfs[i].vsi;
2433 i40e_aq_set_vsi_vlan_promisc(hw, vsi->seid,
2438 /* Enable mac loopback mode */
2439 if (dev->data->dev_conf.lpbk_mode == I40E_AQ_LB_MODE_NONE ||
2440 dev->data->dev_conf.lpbk_mode == I40E_AQ_LB_PHY_LOCAL) {
2441 ret = i40e_aq_set_lb_modes(hw, dev->data->dev_conf.lpbk_mode, NULL);
2442 if (ret != I40E_SUCCESS) {
2443 PMD_DRV_LOG(ERR, "fail to set loopback link");
2448 /* Apply link configure */
2449 ret = i40e_apply_link_speed(dev);
2450 if (I40E_SUCCESS != ret) {
2451 PMD_DRV_LOG(ERR, "Fail to apply link setting");
2455 if (!rte_intr_allow_others(intr_handle)) {
2456 rte_intr_callback_unregister(intr_handle,
2457 i40e_dev_interrupt_handler,
2459 /* configure and enable device interrupt */
2460 i40e_pf_config_irq0(hw, FALSE);
2461 i40e_pf_enable_irq0(hw);
2463 if (dev->data->dev_conf.intr_conf.lsc != 0)
2465 "lsc won't enable because of no intr multiplex");
2467 ret = i40e_aq_set_phy_int_mask(hw,
2468 ~(I40E_AQ_EVENT_LINK_UPDOWN |
2469 I40E_AQ_EVENT_MODULE_QUAL_FAIL |
2470 I40E_AQ_EVENT_MEDIA_NA), NULL);
2471 if (ret != I40E_SUCCESS)
2472 PMD_DRV_LOG(WARNING, "Fail to set phy mask");
2474 /* Call get_link_info aq command to enable/disable LSE */
2475 i40e_dev_link_update(dev, 0);
2478 if (dev->data->dev_conf.intr_conf.rxq == 0) {
2479 rte_eal_alarm_set(I40E_ALARM_INTERVAL,
2480 i40e_dev_alarm_handler, dev);
2482 /* enable uio intr after callback register */
2483 rte_intr_enable(intr_handle);
2486 i40e_filter_restore(pf);
2488 if (pf->tm_conf.root && !pf->tm_conf.committed)
2489 PMD_DRV_LOG(WARNING,
2490 "please call hierarchy_commit() "
2491 "before starting the port");
2493 max_frame_size = dev->data->mtu + I40E_ETH_OVERHEAD;
2494 i40e_set_mac_max_frame(dev, max_frame_size);
2496 return I40E_SUCCESS;
2499 for (i = 0; i < nb_txq; i++)
2500 i40e_dev_tx_queue_stop(dev, i);
2502 for (i = 0; i < nb_rxq; i++)
2503 i40e_dev_rx_queue_stop(dev, i);
2509 i40e_dev_stop(struct rte_eth_dev *dev)
2511 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2512 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2513 struct i40e_vsi *main_vsi = pf->main_vsi;
2514 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2515 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2518 if (hw->adapter_stopped == 1)
2521 if (dev->data->dev_conf.intr_conf.rxq == 0) {
2522 rte_eal_alarm_cancel(i40e_dev_alarm_handler, dev);
2523 rte_intr_enable(intr_handle);
2526 /* Disable all queues */
2527 for (i = 0; i < dev->data->nb_tx_queues; i++)
2528 i40e_dev_tx_queue_stop(dev, i);
2530 for (i = 0; i < dev->data->nb_rx_queues; i++)
2531 i40e_dev_rx_queue_stop(dev, i);
2533 /* un-map queues with interrupt registers */
2534 i40e_vsi_disable_queues_intr(main_vsi);
2535 i40e_vsi_queues_unbind_intr(main_vsi);
2537 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2538 i40e_vsi_disable_queues_intr(pf->vmdq[i].vsi);
2539 i40e_vsi_queues_unbind_intr(pf->vmdq[i].vsi);
2542 /* Clear all queues and release memory */
2543 i40e_dev_clear_queues(dev);
2546 i40e_dev_set_link_down(dev);
2548 if (!rte_intr_allow_others(intr_handle))
2549 /* resume to the default handler */
2550 rte_intr_callback_register(intr_handle,
2551 i40e_dev_interrupt_handler,
2554 /* Clean datapath event and queue/vec mapping */
2555 rte_intr_efd_disable(intr_handle);
2557 /* Cleanup vector list */
2558 rte_intr_vec_list_free(intr_handle);
2560 /* reset hierarchy commit */
2561 pf->tm_conf.committed = false;
2563 hw->adapter_stopped = 1;
2564 dev->data->dev_started = 0;
2566 pf->adapter->rss_reta_updated = 0;
2572 i40e_dev_close(struct rte_eth_dev *dev)
2574 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2575 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2576 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2577 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2578 struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
2579 struct i40e_filter_control_settings settings;
2580 struct rte_flow *p_flow;
2584 uint8_t aq_fail = 0;
2587 PMD_INIT_FUNC_TRACE();
2588 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2592 * It is a workaround, if the double VLAN is disabled when
2593 * the program exits, an abnormal error will occur on the
2594 * NIC. Need to enable double VLAN when dev is closed.
2597 if (!(rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND)) {
2598 rxmode->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
2599 i40e_vlan_offload_set(dev, RTE_ETH_VLAN_EXTEND_MASK);
2603 ret = rte_eth_switch_domain_free(pf->switch_domain_id);
2605 PMD_INIT_LOG(WARNING, "failed to free switch domain: %d", ret);
2608 ret = i40e_dev_stop(dev);
2610 i40e_dev_free_queues(dev);
2612 /* Disable interrupt */
2613 i40e_pf_disable_irq0(hw);
2614 rte_intr_disable(intr_handle);
2617 * Only legacy filter API needs the following fdir config. So when the
2618 * legacy filter API is deprecated, the following code should also be
2621 i40e_fdir_teardown(pf);
2623 /* shutdown and destroy the HMC */
2624 i40e_shutdown_lan_hmc(hw);
2626 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2627 i40e_vsi_release(pf->vmdq[i].vsi);
2628 pf->vmdq[i].vsi = NULL;
2633 /* release all the existing VSIs and VEBs */
2634 i40e_vsi_release(pf->main_vsi);
2636 /* shutdown the adminq */
2637 i40e_aq_queue_shutdown(hw, true);
2638 i40e_shutdown_adminq(hw);
2640 i40e_res_pool_destroy(&pf->qp_pool);
2641 i40e_res_pool_destroy(&pf->msix_pool);
2643 /* Disable flexible payload in global configuration */
2644 if (!pf->support_multi_driver)
2645 i40e_flex_payload_reg_set_default(hw);
2647 /* force a PF reset to clean anything leftover */
2648 reg = I40E_READ_REG(hw, I40E_PFGEN_CTRL);
2649 I40E_WRITE_REG(hw, I40E_PFGEN_CTRL,
2650 (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
2651 I40E_WRITE_FLUSH(hw);
2653 /* Clear PXE mode */
2654 i40e_clear_pxe_mode(hw);
2656 /* Unconfigure filter control */
2657 memset(&settings, 0, sizeof(settings));
2658 ret = i40e_set_filter_control(hw, &settings);
2660 PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
2663 /* Disable flow control */
2664 hw->fc.requested_mode = I40E_FC_NONE;
2665 i40e_set_fc(hw, &aq_fail, TRUE);
2667 /* uninitialize pf host driver */
2668 i40e_pf_host_uninit(dev);
2671 ret = rte_intr_callback_unregister(intr_handle,
2672 i40e_dev_interrupt_handler, dev);
2673 if (ret >= 0 || ret == -ENOENT) {
2675 } else if (ret != -EAGAIN) {
2677 "intr callback unregister failed: %d",
2680 i40e_msec_delay(500);
2681 } while (retries++ < 5);
2683 i40e_rm_ethtype_filter_list(pf);
2684 i40e_rm_tunnel_filter_list(pf);
2685 i40e_rm_fdir_filter_list(pf);
2687 /* Remove all flows */
2688 while ((p_flow = TAILQ_FIRST(&pf->flow_list))) {
2689 TAILQ_REMOVE(&pf->flow_list, p_flow, node);
2690 /* Do not free FDIR flows since they are static allocated */
2691 if (p_flow->filter_type != RTE_ETH_FILTER_FDIR)
2695 /* release the fdir static allocated memory */
2696 i40e_fdir_memory_cleanup(pf);
2698 /* Remove all Traffic Manager configuration */
2699 i40e_tm_conf_uninit(dev);
2701 i40e_clear_automask(pf);
2703 hw->adapter_closed = 1;
2708 * Reset PF device only to re-initialize resources in PMD layer
2711 i40e_dev_reset(struct rte_eth_dev *dev)
2715 /* When a DPDK PMD PF begin to reset PF port, it should notify all
2716 * its VF to make them align with it. The detailed notification
2717 * mechanism is PMD specific. As to i40e PF, it is rather complex.
2718 * To avoid unexpected behavior in VF, currently reset of PF with
2719 * SR-IOV activation is not supported. It might be supported later.
2721 if (dev->data->sriov.active)
2724 ret = eth_i40e_dev_uninit(dev);
2728 ret = eth_i40e_dev_init(dev, NULL);
2734 i40e_dev_promiscuous_enable(struct rte_eth_dev *dev)
2736 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2737 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2738 struct i40e_vsi *vsi = pf->main_vsi;
2741 status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2743 if (status != I40E_SUCCESS) {
2744 PMD_DRV_LOG(ERR, "Failed to enable unicast promiscuous");
2748 status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
2750 if (status != I40E_SUCCESS) {
2751 PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
2752 /* Rollback unicast promiscuous mode */
2753 i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2762 i40e_dev_promiscuous_disable(struct rte_eth_dev *dev)
2764 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2765 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2766 struct i40e_vsi *vsi = pf->main_vsi;
2769 status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2771 if (status != I40E_SUCCESS) {
2772 PMD_DRV_LOG(ERR, "Failed to disable unicast promiscuous");
2776 /* must remain in all_multicast mode */
2777 if (dev->data->all_multicast == 1)
2780 status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
2782 if (status != I40E_SUCCESS) {
2783 PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
2784 /* Rollback unicast promiscuous mode */
2785 i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2794 i40e_dev_allmulticast_enable(struct rte_eth_dev *dev)
2796 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2797 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2798 struct i40e_vsi *vsi = pf->main_vsi;
2801 ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid, TRUE, NULL);
2802 if (ret != I40E_SUCCESS) {
2803 PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
2811 i40e_dev_allmulticast_disable(struct rte_eth_dev *dev)
2813 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2814 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2815 struct i40e_vsi *vsi = pf->main_vsi;
2818 if (dev->data->promiscuous == 1)
2819 return 0; /* must remain in all_multicast mode */
2821 ret = i40e_aq_set_vsi_multicast_promiscuous(hw,
2822 vsi->seid, FALSE, NULL);
2823 if (ret != I40E_SUCCESS) {
2824 PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
2832 * Set device link up.
2835 i40e_dev_set_link_up(struct rte_eth_dev *dev)
2837 /* re-apply link speed setting */
2838 return i40e_apply_link_speed(dev);
2842 * Set device link down.
2845 i40e_dev_set_link_down(struct rte_eth_dev *dev)
2847 uint8_t speed = I40E_LINK_SPEED_UNKNOWN;
2848 uint8_t abilities = 0;
2849 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2851 abilities = I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
2852 return i40e_phy_conf_link(hw, abilities, speed, false);
2855 #define CHECK_INTERVAL 100 /* 100ms */
2856 #define MAX_REPEAT_TIME 10 /* 1s (10 * 100ms) in total */
2858 static __rte_always_inline void
2859 update_link_reg(struct i40e_hw *hw, struct rte_eth_link *link)
2861 /* Link status registers and values*/
2862 #define I40E_REG_LINK_UP 0x40000080
2863 #define I40E_PRTMAC_MACC 0x001E24E0
2864 #define I40E_REG_MACC_25GB 0x00020000
2865 #define I40E_REG_SPEED_MASK 0x38000000
2866 #define I40E_REG_SPEED_0 0x00000000
2867 #define I40E_REG_SPEED_1 0x08000000
2868 #define I40E_REG_SPEED_2 0x10000000
2869 #define I40E_REG_SPEED_3 0x18000000
2870 #define I40E_REG_SPEED_4 0x20000000
2871 uint32_t link_speed;
2874 reg_val = I40E_READ_REG(hw, I40E_PRTMAC_LINKSTA(0));
2875 link_speed = reg_val & I40E_REG_SPEED_MASK;
2876 reg_val &= I40E_REG_LINK_UP;
2877 link->link_status = (reg_val == I40E_REG_LINK_UP) ? 1 : 0;
2879 if (unlikely(link->link_status == 0))
2882 /* Parse the link status */
2883 switch (link_speed) {
2884 case I40E_REG_SPEED_0:
2885 link->link_speed = RTE_ETH_SPEED_NUM_100M;
2887 case I40E_REG_SPEED_1:
2888 link->link_speed = RTE_ETH_SPEED_NUM_1G;
2890 case I40E_REG_SPEED_2:
2891 if (hw->mac.type == I40E_MAC_X722)
2892 link->link_speed = RTE_ETH_SPEED_NUM_2_5G;
2894 link->link_speed = RTE_ETH_SPEED_NUM_10G;
2896 case I40E_REG_SPEED_3:
2897 if (hw->mac.type == I40E_MAC_X722) {
2898 link->link_speed = RTE_ETH_SPEED_NUM_5G;
2900 reg_val = I40E_READ_REG(hw, I40E_PRTMAC_MACC);
2902 if (reg_val & I40E_REG_MACC_25GB)
2903 link->link_speed = RTE_ETH_SPEED_NUM_25G;
2905 link->link_speed = RTE_ETH_SPEED_NUM_40G;
2908 case I40E_REG_SPEED_4:
2909 if (hw->mac.type == I40E_MAC_X722)
2910 link->link_speed = RTE_ETH_SPEED_NUM_10G;
2912 link->link_speed = RTE_ETH_SPEED_NUM_20G;
2915 PMD_DRV_LOG(ERR, "Unknown link speed info %u", link_speed);
2920 static __rte_always_inline void
2921 update_link_aq(struct i40e_hw *hw, struct rte_eth_link *link,
2922 bool enable_lse, int wait_to_complete)
2924 uint32_t rep_cnt = MAX_REPEAT_TIME;
2925 struct i40e_link_status link_status;
2928 memset(&link_status, 0, sizeof(link_status));
2931 memset(&link_status, 0, sizeof(link_status));
2933 /* Get link status information from hardware */
2934 status = i40e_aq_get_link_info(hw, enable_lse,
2935 &link_status, NULL);
2936 if (unlikely(status != I40E_SUCCESS)) {
2937 link->link_speed = RTE_ETH_SPEED_NUM_NONE;
2938 link->link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
2939 PMD_DRV_LOG(ERR, "Failed to get link info");
2943 link->link_status = link_status.link_info & I40E_AQ_LINK_UP;
2944 if (!wait_to_complete || link->link_status)
2947 rte_delay_ms(CHECK_INTERVAL);
2948 } while (--rep_cnt);
2950 /* Parse the link status */
2951 switch (link_status.link_speed) {
2952 case I40E_LINK_SPEED_100MB:
2953 link->link_speed = RTE_ETH_SPEED_NUM_100M;
2955 case I40E_LINK_SPEED_1GB:
2956 link->link_speed = RTE_ETH_SPEED_NUM_1G;
2958 case I40E_LINK_SPEED_10GB:
2959 link->link_speed = RTE_ETH_SPEED_NUM_10G;
2961 case I40E_LINK_SPEED_20GB:
2962 link->link_speed = RTE_ETH_SPEED_NUM_20G;
2964 case I40E_LINK_SPEED_25GB:
2965 link->link_speed = RTE_ETH_SPEED_NUM_25G;
2967 case I40E_LINK_SPEED_40GB:
2968 link->link_speed = RTE_ETH_SPEED_NUM_40G;
2971 if (link->link_status)
2972 link->link_speed = RTE_ETH_SPEED_NUM_UNKNOWN;
2974 link->link_speed = RTE_ETH_SPEED_NUM_NONE;
2980 i40e_dev_link_update(struct rte_eth_dev *dev,
2981 int wait_to_complete)
2983 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2984 struct rte_eth_link link;
2985 bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
2988 memset(&link, 0, sizeof(link));
2990 /* i40e uses full duplex only */
2991 link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
2992 link.link_autoneg = !(dev->data->dev_conf.link_speeds &
2993 RTE_ETH_LINK_SPEED_FIXED);
2995 if (!wait_to_complete && !enable_lse)
2996 update_link_reg(hw, &link);
2998 update_link_aq(hw, &link, enable_lse, wait_to_complete);
3001 rte_eth_linkstatus_get(hw->switch_dev, &link);
3003 ret = rte_eth_linkstatus_set(dev, &link);
3004 i40e_notify_all_vfs_link_status(dev);
3010 i40e_stat_update_48_in_64(struct i40e_hw *hw, uint32_t hireg,
3011 uint32_t loreg, bool offset_loaded, uint64_t *offset,
3012 uint64_t *stat, uint64_t *prev_stat)
3014 i40e_stat_update_48(hw, hireg, loreg, offset_loaded, offset, stat);
3015 /* enlarge the limitation when statistics counters overflowed */
3016 if (offset_loaded) {
3017 if (I40E_RXTX_BYTES_L_48_BIT(*prev_stat) > *stat)
3018 *stat += (uint64_t)1 << I40E_48_BIT_WIDTH;
3019 *stat += I40E_RXTX_BYTES_H_16_BIT(*prev_stat);
3024 /* Get all the statistics of a VSI */
3026 i40e_update_vsi_stats(struct i40e_vsi *vsi)
3028 struct i40e_eth_stats *oes = &vsi->eth_stats_offset;
3029 struct i40e_eth_stats *nes = &vsi->eth_stats;
3030 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3031 int idx = rte_le_to_cpu_16(vsi->info.stat_counter_idx);
3033 i40e_stat_update_48_in_64(hw, I40E_GLV_GORCH(idx), I40E_GLV_GORCL(idx),
3034 vsi->offset_loaded, &oes->rx_bytes,
3035 &nes->rx_bytes, &vsi->prev_rx_bytes);
3036 i40e_stat_update_48(hw, I40E_GLV_UPRCH(idx), I40E_GLV_UPRCL(idx),
3037 vsi->offset_loaded, &oes->rx_unicast,
3039 i40e_stat_update_48(hw, I40E_GLV_MPRCH(idx), I40E_GLV_MPRCL(idx),
3040 vsi->offset_loaded, &oes->rx_multicast,
3041 &nes->rx_multicast);
3042 i40e_stat_update_48(hw, I40E_GLV_BPRCH(idx), I40E_GLV_BPRCL(idx),
3043 vsi->offset_loaded, &oes->rx_broadcast,
3044 &nes->rx_broadcast);
3045 /* exclude CRC bytes */
3046 nes->rx_bytes -= (nes->rx_unicast + nes->rx_multicast +
3047 nes->rx_broadcast) * RTE_ETHER_CRC_LEN;
3049 i40e_stat_update_32(hw, I40E_GLV_RDPC(idx), vsi->offset_loaded,
3050 &oes->rx_discards, &nes->rx_discards);
3051 /* GLV_REPC not supported */
3052 /* GLV_RMPC not supported */
3053 i40e_stat_update_32(hw, I40E_GLV_RUPP(idx), vsi->offset_loaded,
3054 &oes->rx_unknown_protocol,
3055 &nes->rx_unknown_protocol);
3056 i40e_stat_update_48_in_64(hw, I40E_GLV_GOTCH(idx), I40E_GLV_GOTCL(idx),
3057 vsi->offset_loaded, &oes->tx_bytes,
3058 &nes->tx_bytes, &vsi->prev_tx_bytes);
3059 i40e_stat_update_48(hw, I40E_GLV_UPTCH(idx), I40E_GLV_UPTCL(idx),
3060 vsi->offset_loaded, &oes->tx_unicast,
3062 i40e_stat_update_48(hw, I40E_GLV_MPTCH(idx), I40E_GLV_MPTCL(idx),
3063 vsi->offset_loaded, &oes->tx_multicast,
3064 &nes->tx_multicast);
3065 i40e_stat_update_48(hw, I40E_GLV_BPTCH(idx), I40E_GLV_BPTCL(idx),
3066 vsi->offset_loaded, &oes->tx_broadcast,
3067 &nes->tx_broadcast);
3068 /* GLV_TDPC not supported */
3069 i40e_stat_update_32(hw, I40E_GLV_TEPC(idx), vsi->offset_loaded,
3070 &oes->tx_errors, &nes->tx_errors);
3071 vsi->offset_loaded = true;
3073 PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats start *******************",
3075 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", nes->rx_bytes);
3076 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", nes->rx_unicast);
3077 PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", nes->rx_multicast);
3078 PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", nes->rx_broadcast);
3079 PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", nes->rx_discards);
3080 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
3081 nes->rx_unknown_protocol);
3082 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", nes->tx_bytes);
3083 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", nes->tx_unicast);
3084 PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", nes->tx_multicast);
3085 PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", nes->tx_broadcast);
3086 PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", nes->tx_discards);
3087 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", nes->tx_errors);
3088 PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats end *******************",
3093 i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw)
3096 struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
3097 struct i40e_hw_port_stats *os = &pf->stats_offset; /* old stats */
3099 /* Get rx/tx bytes of internal transfer packets */
3100 i40e_stat_update_48_in_64(hw, I40E_GLV_GORCH(hw->port),
3101 I40E_GLV_GORCL(hw->port),
3103 &pf->internal_stats_offset.rx_bytes,
3104 &pf->internal_stats.rx_bytes,
3105 &pf->internal_prev_rx_bytes);
3106 i40e_stat_update_48_in_64(hw, I40E_GLV_GOTCH(hw->port),
3107 I40E_GLV_GOTCL(hw->port),
3109 &pf->internal_stats_offset.tx_bytes,
3110 &pf->internal_stats.tx_bytes,
3111 &pf->internal_prev_tx_bytes);
3112 /* Get total internal rx packet count */
3113 i40e_stat_update_48(hw, I40E_GLV_UPRCH(hw->port),
3114 I40E_GLV_UPRCL(hw->port),
3116 &pf->internal_stats_offset.rx_unicast,
3117 &pf->internal_stats.rx_unicast);
3118 i40e_stat_update_48(hw, I40E_GLV_MPRCH(hw->port),
3119 I40E_GLV_MPRCL(hw->port),
3121 &pf->internal_stats_offset.rx_multicast,
3122 &pf->internal_stats.rx_multicast);
3123 i40e_stat_update_48(hw, I40E_GLV_BPRCH(hw->port),
3124 I40E_GLV_BPRCL(hw->port),
3126 &pf->internal_stats_offset.rx_broadcast,
3127 &pf->internal_stats.rx_broadcast);
3128 /* Get total internal tx packet count */
3129 i40e_stat_update_48(hw, I40E_GLV_UPTCH(hw->port),
3130 I40E_GLV_UPTCL(hw->port),
3132 &pf->internal_stats_offset.tx_unicast,
3133 &pf->internal_stats.tx_unicast);
3134 i40e_stat_update_48(hw, I40E_GLV_MPTCH(hw->port),
3135 I40E_GLV_MPTCL(hw->port),
3137 &pf->internal_stats_offset.tx_multicast,
3138 &pf->internal_stats.tx_multicast);
3139 i40e_stat_update_48(hw, I40E_GLV_BPTCH(hw->port),
3140 I40E_GLV_BPTCL(hw->port),
3142 &pf->internal_stats_offset.tx_broadcast,
3143 &pf->internal_stats.tx_broadcast);
3145 /* exclude CRC size */
3146 pf->internal_stats.rx_bytes -= (pf->internal_stats.rx_unicast +
3147 pf->internal_stats.rx_multicast +
3148 pf->internal_stats.rx_broadcast) * RTE_ETHER_CRC_LEN;
3150 /* Get statistics of struct i40e_eth_stats */
3151 i40e_stat_update_48_in_64(hw, I40E_GLPRT_GORCH(hw->port),
3152 I40E_GLPRT_GORCL(hw->port),
3153 pf->offset_loaded, &os->eth.rx_bytes,
3154 &ns->eth.rx_bytes, &pf->prev_rx_bytes);
3155 i40e_stat_update_48(hw, I40E_GLPRT_UPRCH(hw->port),
3156 I40E_GLPRT_UPRCL(hw->port),
3157 pf->offset_loaded, &os->eth.rx_unicast,
3158 &ns->eth.rx_unicast);
3159 i40e_stat_update_48(hw, I40E_GLPRT_MPRCH(hw->port),
3160 I40E_GLPRT_MPRCL(hw->port),
3161 pf->offset_loaded, &os->eth.rx_multicast,
3162 &ns->eth.rx_multicast);
3163 i40e_stat_update_48(hw, I40E_GLPRT_BPRCH(hw->port),
3164 I40E_GLPRT_BPRCL(hw->port),
3165 pf->offset_loaded, &os->eth.rx_broadcast,
3166 &ns->eth.rx_broadcast);
3167 /* Workaround: CRC size should not be included in byte statistics,
3168 * so subtract RTE_ETHER_CRC_LEN from the byte counter for each rx
3171 ns->eth.rx_bytes -= (ns->eth.rx_unicast + ns->eth.rx_multicast +
3172 ns->eth.rx_broadcast) * RTE_ETHER_CRC_LEN;
3174 /* exclude internal rx bytes
3175 * Workaround: it is possible I40E_GLV_GORCH[H/L] is updated before
3176 * I40E_GLPRT_GORCH[H/L], so there is a small window that cause negative
3178 * same to I40E_GLV_UPRC[H/L], I40E_GLV_MPRC[H/L], I40E_GLV_BPRC[H/L].
3180 if (ns->eth.rx_bytes < pf->internal_stats.rx_bytes)
3181 ns->eth.rx_bytes = 0;
3183 ns->eth.rx_bytes -= pf->internal_stats.rx_bytes;
3185 if (ns->eth.rx_unicast < pf->internal_stats.rx_unicast)
3186 ns->eth.rx_unicast = 0;
3188 ns->eth.rx_unicast -= pf->internal_stats.rx_unicast;
3190 if (ns->eth.rx_multicast < pf->internal_stats.rx_multicast)
3191 ns->eth.rx_multicast = 0;
3193 ns->eth.rx_multicast -= pf->internal_stats.rx_multicast;
3195 if (ns->eth.rx_broadcast < pf->internal_stats.rx_broadcast)
3196 ns->eth.rx_broadcast = 0;
3198 ns->eth.rx_broadcast -= pf->internal_stats.rx_broadcast;
3200 i40e_stat_update_32(hw, I40E_GLPRT_RDPC(hw->port),
3201 pf->offset_loaded, &os->eth.rx_discards,
3202 &ns->eth.rx_discards);
3203 /* GLPRT_REPC not supported */
3204 /* GLPRT_RMPC not supported */
3205 i40e_stat_update_32(hw, I40E_GLPRT_RUPP(hw->port),
3207 &os->eth.rx_unknown_protocol,
3208 &ns->eth.rx_unknown_protocol);
3209 i40e_stat_update_48(hw, I40E_GL_RXERR1_H(hw->pf_id + I40E_MAX_VF),
3210 I40E_GL_RXERR1_L(hw->pf_id + I40E_MAX_VF),
3211 pf->offset_loaded, &pf->rx_err1_offset,
3213 i40e_stat_update_48_in_64(hw, I40E_GLPRT_GOTCH(hw->port),
3214 I40E_GLPRT_GOTCL(hw->port),
3215 pf->offset_loaded, &os->eth.tx_bytes,
3216 &ns->eth.tx_bytes, &pf->prev_tx_bytes);
3217 i40e_stat_update_48(hw, I40E_GLPRT_UPTCH(hw->port),
3218 I40E_GLPRT_UPTCL(hw->port),
3219 pf->offset_loaded, &os->eth.tx_unicast,
3220 &ns->eth.tx_unicast);
3221 i40e_stat_update_48(hw, I40E_GLPRT_MPTCH(hw->port),
3222 I40E_GLPRT_MPTCL(hw->port),
3223 pf->offset_loaded, &os->eth.tx_multicast,
3224 &ns->eth.tx_multicast);
3225 i40e_stat_update_48(hw, I40E_GLPRT_BPTCH(hw->port),
3226 I40E_GLPRT_BPTCL(hw->port),
3227 pf->offset_loaded, &os->eth.tx_broadcast,
3228 &ns->eth.tx_broadcast);
3229 ns->eth.tx_bytes -= (ns->eth.tx_unicast + ns->eth.tx_multicast +
3230 ns->eth.tx_broadcast) * RTE_ETHER_CRC_LEN;
3232 /* exclude internal tx bytes
3233 * Workaround: it is possible I40E_GLV_GOTCH[H/L] is updated before
3234 * I40E_GLPRT_GOTCH[H/L], so there is a small window that cause negative
3236 * same to I40E_GLV_UPTC[H/L], I40E_GLV_MPTC[H/L], I40E_GLV_BPTC[H/L].
3238 if (ns->eth.tx_bytes < pf->internal_stats.tx_bytes)
3239 ns->eth.tx_bytes = 0;
3241 ns->eth.tx_bytes -= pf->internal_stats.tx_bytes;
3243 if (ns->eth.tx_unicast < pf->internal_stats.tx_unicast)
3244 ns->eth.tx_unicast = 0;
3246 ns->eth.tx_unicast -= pf->internal_stats.tx_unicast;
3248 if (ns->eth.tx_multicast < pf->internal_stats.tx_multicast)
3249 ns->eth.tx_multicast = 0;
3251 ns->eth.tx_multicast -= pf->internal_stats.tx_multicast;
3253 if (ns->eth.tx_broadcast < pf->internal_stats.tx_broadcast)
3254 ns->eth.tx_broadcast = 0;
3256 ns->eth.tx_broadcast -= pf->internal_stats.tx_broadcast;
3258 /* GLPRT_TEPC not supported */
3260 /* additional port specific stats */
3261 i40e_stat_update_32(hw, I40E_GLPRT_TDOLD(hw->port),
3262 pf->offset_loaded, &os->tx_dropped_link_down,
3263 &ns->tx_dropped_link_down);
3264 i40e_stat_update_32(hw, I40E_GLPRT_CRCERRS(hw->port),
3265 pf->offset_loaded, &os->crc_errors,
3267 i40e_stat_update_32(hw, I40E_GLPRT_ILLERRC(hw->port),
3268 pf->offset_loaded, &os->illegal_bytes,
3269 &ns->illegal_bytes);
3270 /* GLPRT_ERRBC not supported */
3271 i40e_stat_update_32(hw, I40E_GLPRT_MLFC(hw->port),
3272 pf->offset_loaded, &os->mac_local_faults,
3273 &ns->mac_local_faults);
3274 i40e_stat_update_32(hw, I40E_GLPRT_MRFC(hw->port),
3275 pf->offset_loaded, &os->mac_remote_faults,
3276 &ns->mac_remote_faults);
3277 i40e_stat_update_32(hw, I40E_GLPRT_RLEC(hw->port),
3278 pf->offset_loaded, &os->rx_length_errors,
3279 &ns->rx_length_errors);
3280 i40e_stat_update_32(hw, I40E_GLPRT_LXONRXC(hw->port),
3281 pf->offset_loaded, &os->link_xon_rx,
3283 i40e_stat_update_32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
3284 pf->offset_loaded, &os->link_xoff_rx,
3286 for (i = 0; i < 8; i++) {
3287 i40e_stat_update_32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
3289 &os->priority_xon_rx[i],
3290 &ns->priority_xon_rx[i]);
3291 i40e_stat_update_32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
3293 &os->priority_xoff_rx[i],
3294 &ns->priority_xoff_rx[i]);
3296 i40e_stat_update_32(hw, I40E_GLPRT_LXONTXC(hw->port),
3297 pf->offset_loaded, &os->link_xon_tx,
3299 i40e_stat_update_32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
3300 pf->offset_loaded, &os->link_xoff_tx,
3302 for (i = 0; i < 8; i++) {
3303 i40e_stat_update_32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
3305 &os->priority_xon_tx[i],
3306 &ns->priority_xon_tx[i]);
3307 i40e_stat_update_32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
3309 &os->priority_xoff_tx[i],
3310 &ns->priority_xoff_tx[i]);
3311 i40e_stat_update_32(hw, I40E_GLPRT_RXON2OFFCNT(hw->port, i),
3313 &os->priority_xon_2_xoff[i],
3314 &ns->priority_xon_2_xoff[i]);
3316 i40e_stat_update_48(hw, I40E_GLPRT_PRC64H(hw->port),
3317 I40E_GLPRT_PRC64L(hw->port),
3318 pf->offset_loaded, &os->rx_size_64,
3320 i40e_stat_update_48(hw, I40E_GLPRT_PRC127H(hw->port),
3321 I40E_GLPRT_PRC127L(hw->port),
3322 pf->offset_loaded, &os->rx_size_127,
3324 i40e_stat_update_48(hw, I40E_GLPRT_PRC255H(hw->port),
3325 I40E_GLPRT_PRC255L(hw->port),
3326 pf->offset_loaded, &os->rx_size_255,
3328 i40e_stat_update_48(hw, I40E_GLPRT_PRC511H(hw->port),
3329 I40E_GLPRT_PRC511L(hw->port),
3330 pf->offset_loaded, &os->rx_size_511,
3332 i40e_stat_update_48(hw, I40E_GLPRT_PRC1023H(hw->port),
3333 I40E_GLPRT_PRC1023L(hw->port),
3334 pf->offset_loaded, &os->rx_size_1023,
3336 i40e_stat_update_48(hw, I40E_GLPRT_PRC1522H(hw->port),
3337 I40E_GLPRT_PRC1522L(hw->port),
3338 pf->offset_loaded, &os->rx_size_1522,
3340 i40e_stat_update_48(hw, I40E_GLPRT_PRC9522H(hw->port),
3341 I40E_GLPRT_PRC9522L(hw->port),
3342 pf->offset_loaded, &os->rx_size_big,
3344 i40e_stat_update_32(hw, I40E_GLPRT_RUC(hw->port),
3345 pf->offset_loaded, &os->rx_undersize,
3347 i40e_stat_update_32(hw, I40E_GLPRT_RFC(hw->port),
3348 pf->offset_loaded, &os->rx_fragments,
3350 i40e_stat_update_32(hw, I40E_GLPRT_ROC(hw->port),
3351 pf->offset_loaded, &os->rx_oversize,
3353 i40e_stat_update_32(hw, I40E_GLPRT_RJC(hw->port),
3354 pf->offset_loaded, &os->rx_jabber,
3356 i40e_stat_update_48(hw, I40E_GLPRT_PTC64H(hw->port),
3357 I40E_GLPRT_PTC64L(hw->port),
3358 pf->offset_loaded, &os->tx_size_64,
3360 i40e_stat_update_48(hw, I40E_GLPRT_PTC127H(hw->port),
3361 I40E_GLPRT_PTC127L(hw->port),
3362 pf->offset_loaded, &os->tx_size_127,
3364 i40e_stat_update_48(hw, I40E_GLPRT_PTC255H(hw->port),
3365 I40E_GLPRT_PTC255L(hw->port),
3366 pf->offset_loaded, &os->tx_size_255,
3368 i40e_stat_update_48(hw, I40E_GLPRT_PTC511H(hw->port),
3369 I40E_GLPRT_PTC511L(hw->port),
3370 pf->offset_loaded, &os->tx_size_511,
3372 i40e_stat_update_48(hw, I40E_GLPRT_PTC1023H(hw->port),
3373 I40E_GLPRT_PTC1023L(hw->port),
3374 pf->offset_loaded, &os->tx_size_1023,
3376 i40e_stat_update_48(hw, I40E_GLPRT_PTC1522H(hw->port),
3377 I40E_GLPRT_PTC1522L(hw->port),
3378 pf->offset_loaded, &os->tx_size_1522,
3380 i40e_stat_update_48(hw, I40E_GLPRT_PTC9522H(hw->port),
3381 I40E_GLPRT_PTC9522L(hw->port),
3382 pf->offset_loaded, &os->tx_size_big,
3384 i40e_stat_update_32(hw, I40E_GLQF_PCNT(pf->fdir.match_counter_index),
3386 &os->fd_sb_match, &ns->fd_sb_match);
3387 /* GLPRT_MSPDC not supported */
3388 /* GLPRT_XEC not supported */
3390 pf->offset_loaded = true;
3393 i40e_update_vsi_stats(pf->main_vsi);
3396 /* Get all statistics of a port */
3398 i40e_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
3400 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3401 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3402 struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
3403 struct i40e_vsi *vsi;
3406 /* call read registers - updates values, now write them to struct */
3407 i40e_read_stats_registers(pf, hw);
3409 stats->ipackets = pf->main_vsi->eth_stats.rx_unicast +
3410 pf->main_vsi->eth_stats.rx_multicast +
3411 pf->main_vsi->eth_stats.rx_broadcast -
3412 pf->main_vsi->eth_stats.rx_discards -
3414 stats->opackets = ns->eth.tx_unicast +
3415 ns->eth.tx_multicast +
3416 ns->eth.tx_broadcast;
3417 stats->ibytes = pf->main_vsi->eth_stats.rx_bytes;
3418 stats->obytes = ns->eth.tx_bytes;
3419 stats->oerrors = ns->eth.tx_errors +
3420 pf->main_vsi->eth_stats.tx_errors;
3423 stats->imissed = ns->eth.rx_discards +
3424 pf->main_vsi->eth_stats.rx_discards;
3425 stats->ierrors = ns->crc_errors +
3426 ns->rx_length_errors + ns->rx_undersize +
3427 ns->rx_oversize + ns->rx_fragments + ns->rx_jabber +
3431 for (i = 0; i < pf->vf_num; i++) {
3432 vsi = pf->vfs[i].vsi;
3433 i40e_update_vsi_stats(vsi);
3435 stats->ipackets += (vsi->eth_stats.rx_unicast +
3436 vsi->eth_stats.rx_multicast +
3437 vsi->eth_stats.rx_broadcast -
3438 vsi->eth_stats.rx_discards);
3439 stats->ibytes += vsi->eth_stats.rx_bytes;
3440 stats->oerrors += vsi->eth_stats.tx_errors;
3441 stats->imissed += vsi->eth_stats.rx_discards;
3445 PMD_DRV_LOG(DEBUG, "***************** PF stats start *******************");
3446 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", ns->eth.rx_bytes);
3447 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", ns->eth.rx_unicast);
3448 PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", ns->eth.rx_multicast);
3449 PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", ns->eth.rx_broadcast);
3450 PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", ns->eth.rx_discards);
3451 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
3452 ns->eth.rx_unknown_protocol);
3453 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", ns->eth.tx_bytes);
3454 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", ns->eth.tx_unicast);
3455 PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", ns->eth.tx_multicast);
3456 PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", ns->eth.tx_broadcast);
3457 PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", ns->eth.tx_discards);
3458 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", ns->eth.tx_errors);
3460 PMD_DRV_LOG(DEBUG, "tx_dropped_link_down: %"PRIu64"",
3461 ns->tx_dropped_link_down);
3462 PMD_DRV_LOG(DEBUG, "crc_errors: %"PRIu64"", ns->crc_errors);
3463 PMD_DRV_LOG(DEBUG, "illegal_bytes: %"PRIu64"",
3465 PMD_DRV_LOG(DEBUG, "error_bytes: %"PRIu64"", ns->error_bytes);
3466 PMD_DRV_LOG(DEBUG, "mac_local_faults: %"PRIu64"",
3467 ns->mac_local_faults);
3468 PMD_DRV_LOG(DEBUG, "mac_remote_faults: %"PRIu64"",
3469 ns->mac_remote_faults);
3470 PMD_DRV_LOG(DEBUG, "rx_length_errors: %"PRIu64"",
3471 ns->rx_length_errors);
3472 PMD_DRV_LOG(DEBUG, "link_xon_rx: %"PRIu64"", ns->link_xon_rx);
3473 PMD_DRV_LOG(DEBUG, "link_xoff_rx: %"PRIu64"", ns->link_xoff_rx);
3474 for (i = 0; i < 8; i++) {
3475 PMD_DRV_LOG(DEBUG, "priority_xon_rx[%d]: %"PRIu64"",
3476 i, ns->priority_xon_rx[i]);
3477 PMD_DRV_LOG(DEBUG, "priority_xoff_rx[%d]: %"PRIu64"",
3478 i, ns->priority_xoff_rx[i]);
3480 PMD_DRV_LOG(DEBUG, "link_xon_tx: %"PRIu64"", ns->link_xon_tx);
3481 PMD_DRV_LOG(DEBUG, "link_xoff_tx: %"PRIu64"", ns->link_xoff_tx);
3482 for (i = 0; i < 8; i++) {
3483 PMD_DRV_LOG(DEBUG, "priority_xon_tx[%d]: %"PRIu64"",
3484 i, ns->priority_xon_tx[i]);
3485 PMD_DRV_LOG(DEBUG, "priority_xoff_tx[%d]: %"PRIu64"",
3486 i, ns->priority_xoff_tx[i]);
3487 PMD_DRV_LOG(DEBUG, "priority_xon_2_xoff[%d]: %"PRIu64"",
3488 i, ns->priority_xon_2_xoff[i]);
3490 PMD_DRV_LOG(DEBUG, "rx_size_64: %"PRIu64"", ns->rx_size_64);
3491 PMD_DRV_LOG(DEBUG, "rx_size_127: %"PRIu64"", ns->rx_size_127);
3492 PMD_DRV_LOG(DEBUG, "rx_size_255: %"PRIu64"", ns->rx_size_255);
3493 PMD_DRV_LOG(DEBUG, "rx_size_511: %"PRIu64"", ns->rx_size_511);
3494 PMD_DRV_LOG(DEBUG, "rx_size_1023: %"PRIu64"", ns->rx_size_1023);
3495 PMD_DRV_LOG(DEBUG, "rx_size_1522: %"PRIu64"", ns->rx_size_1522);
3496 PMD_DRV_LOG(DEBUG, "rx_size_big: %"PRIu64"", ns->rx_size_big);
3497 PMD_DRV_LOG(DEBUG, "rx_undersize: %"PRIu64"", ns->rx_undersize);
3498 PMD_DRV_LOG(DEBUG, "rx_fragments: %"PRIu64"", ns->rx_fragments);
3499 PMD_DRV_LOG(DEBUG, "rx_oversize: %"PRIu64"", ns->rx_oversize);
3500 PMD_DRV_LOG(DEBUG, "rx_jabber: %"PRIu64"", ns->rx_jabber);
3501 PMD_DRV_LOG(DEBUG, "tx_size_64: %"PRIu64"", ns->tx_size_64);
3502 PMD_DRV_LOG(DEBUG, "tx_size_127: %"PRIu64"", ns->tx_size_127);
3503 PMD_DRV_LOG(DEBUG, "tx_size_255: %"PRIu64"", ns->tx_size_255);
3504 PMD_DRV_LOG(DEBUG, "tx_size_511: %"PRIu64"", ns->tx_size_511);
3505 PMD_DRV_LOG(DEBUG, "tx_size_1023: %"PRIu64"", ns->tx_size_1023);
3506 PMD_DRV_LOG(DEBUG, "tx_size_1522: %"PRIu64"", ns->tx_size_1522);
3507 PMD_DRV_LOG(DEBUG, "tx_size_big: %"PRIu64"", ns->tx_size_big);
3508 PMD_DRV_LOG(DEBUG, "mac_short_packet_dropped: %"PRIu64"",
3509 ns->mac_short_packet_dropped);
3510 PMD_DRV_LOG(DEBUG, "checksum_error: %"PRIu64"",
3511 ns->checksum_error);
3512 PMD_DRV_LOG(DEBUG, "fdir_match: %"PRIu64"", ns->fd_sb_match);
3513 PMD_DRV_LOG(DEBUG, "***************** PF stats end ********************");
3517 /* Reset the statistics */
3519 i40e_dev_stats_reset(struct rte_eth_dev *dev)
3521 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3522 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3524 /* Mark PF and VSI stats to update the offset, aka "reset" */
3525 pf->offset_loaded = false;
3527 pf->main_vsi->offset_loaded = false;
3529 /* read the stats, reading current register values into offset */
3530 i40e_read_stats_registers(pf, hw);
3536 i40e_xstats_calc_num(void)
3538 return I40E_NB_ETH_XSTATS + I40E_NB_HW_PORT_XSTATS +
3539 (I40E_NB_RXQ_PRIO_XSTATS * 8) +
3540 (I40E_NB_TXQ_PRIO_XSTATS * 8);
3543 static int i40e_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
3544 struct rte_eth_xstat_name *xstats_names,
3545 __rte_unused unsigned limit)
3550 if (xstats_names == NULL)
3551 return i40e_xstats_calc_num();
3553 /* Note: limit checked in rte_eth_xstats_names() */
3555 /* Get stats from i40e_eth_stats struct */
3556 for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
3557 strlcpy(xstats_names[count].name,
3558 rte_i40e_stats_strings[i].name,
3559 sizeof(xstats_names[count].name));
3563 /* Get individual stats from i40e_hw_port struct */
3564 for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
3565 strlcpy(xstats_names[count].name,
3566 rte_i40e_hw_port_strings[i].name,
3567 sizeof(xstats_names[count].name));
3571 for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
3572 for (prio = 0; prio < 8; prio++) {
3573 snprintf(xstats_names[count].name,
3574 sizeof(xstats_names[count].name),
3575 "rx_priority%u_%s", prio,
3576 rte_i40e_rxq_prio_strings[i].name);
3581 for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
3582 for (prio = 0; prio < 8; prio++) {
3583 snprintf(xstats_names[count].name,
3584 sizeof(xstats_names[count].name),
3585 "tx_priority%u_%s", prio,
3586 rte_i40e_txq_prio_strings[i].name);
3594 i40e_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
3597 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3598 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3599 unsigned i, count, prio;
3600 struct i40e_hw_port_stats *hw_stats = &pf->stats;
3602 count = i40e_xstats_calc_num();
3606 i40e_read_stats_registers(pf, hw);
3613 /* Get stats from i40e_eth_stats struct */
3614 for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
3615 xstats[count].value = *(uint64_t *)(((char *)&hw_stats->eth) +
3616 rte_i40e_stats_strings[i].offset);
3617 xstats[count].id = count;
3621 /* Get individual stats from i40e_hw_port struct */
3622 for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
3623 xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
3624 rte_i40e_hw_port_strings[i].offset);
3625 xstats[count].id = count;
3629 for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
3630 for (prio = 0; prio < 8; prio++) {
3631 xstats[count].value =
3632 *(uint64_t *)(((char *)hw_stats) +
3633 rte_i40e_rxq_prio_strings[i].offset +
3634 (sizeof(uint64_t) * prio));
3635 xstats[count].id = count;
3640 for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
3641 for (prio = 0; prio < 8; prio++) {
3642 xstats[count].value =
3643 *(uint64_t *)(((char *)hw_stats) +
3644 rte_i40e_txq_prio_strings[i].offset +
3645 (sizeof(uint64_t) * prio));
3646 xstats[count].id = count;
3655 i40e_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
3657 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3663 full_ver = hw->nvm.oem_ver;
3664 ver = (u8)(full_ver >> 24);
3665 build = (u16)((full_ver >> 8) & 0xffff);
3666 patch = (u8)(full_ver & 0xff);
3668 ret = snprintf(fw_version, fw_size,
3669 "%d.%d%d 0x%08x %d.%d.%d",
3670 ((hw->nvm.version >> 12) & 0xf),
3671 ((hw->nvm.version >> 4) & 0xff),
3672 (hw->nvm.version & 0xf), hw->nvm.eetrack,
3677 ret += 1; /* add the size of '\0' */
3678 if (fw_size < (size_t)ret)
3685 * When using NVM 6.01(for X710 XL710 XXV710)/3.33(for X722) or later,
3686 * the Rx data path does not hang if the FW LLDP is stopped.
3687 * return true if lldp need to stop
3688 * return false if we cannot disable the LLDP to avoid Rx data path blocking.
3691 i40e_need_stop_lldp(struct rte_eth_dev *dev)
3694 char ver_str[64] = {0};
3695 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3697 i40e_fw_version_get(dev, ver_str, 64);
3698 nvm_ver = atof(ver_str);
3699 if ((hw->mac.type == I40E_MAC_X722 ||
3700 hw->mac.type == I40E_MAC_X722_VF) &&
3701 ((uint32_t)(nvm_ver * 1000) >= (uint32_t)(3.33 * 1000)))
3703 else if ((uint32_t)(nvm_ver * 1000) >= (uint32_t)(6.01 * 1000))
3710 i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
3712 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3713 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3714 struct i40e_vsi *vsi = pf->main_vsi;
3715 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3717 dev_info->max_rx_queues = vsi->nb_qps;
3718 dev_info->max_tx_queues = vsi->nb_qps;
3719 dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
3720 dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
3721 dev_info->max_mac_addrs = vsi->max_macaddrs;
3722 dev_info->max_vfs = pci_dev->max_vfs;
3723 dev_info->max_mtu = dev_info->max_rx_pktlen - I40E_ETH_OVERHEAD;
3724 dev_info->min_mtu = RTE_ETHER_MIN_MTU;
3725 dev_info->rx_queue_offload_capa = 0;
3726 dev_info->rx_offload_capa =
3727 RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
3728 RTE_ETH_RX_OFFLOAD_QINQ_STRIP |
3729 RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
3730 RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
3731 RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
3732 RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
3733 RTE_ETH_RX_OFFLOAD_KEEP_CRC |
3734 RTE_ETH_RX_OFFLOAD_SCATTER |
3735 RTE_ETH_RX_OFFLOAD_VLAN_EXTEND |
3736 RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
3737 RTE_ETH_RX_OFFLOAD_RSS_HASH;
3739 dev_info->tx_queue_offload_capa = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
3740 dev_info->tx_offload_capa =
3741 RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
3742 RTE_ETH_TX_OFFLOAD_QINQ_INSERT |
3743 RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
3744 RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
3745 RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
3746 RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
3747 RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
3748 RTE_ETH_TX_OFFLOAD_TCP_TSO |
3749 RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
3750 RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
3751 RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
3752 RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
3753 RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
3754 RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM |
3755 dev_info->tx_queue_offload_capa;
3756 dev_info->dev_capa =
3757 RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
3758 RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
3759 dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
3761 dev_info->hash_key_size = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
3763 dev_info->reta_size = pf->hash_lut_size;
3764 dev_info->flow_type_rss_offloads = pf->adapter->flow_types_mask;
3766 dev_info->default_rxconf = (struct rte_eth_rxconf) {
3768 .pthresh = I40E_DEFAULT_RX_PTHRESH,
3769 .hthresh = I40E_DEFAULT_RX_HTHRESH,
3770 .wthresh = I40E_DEFAULT_RX_WTHRESH,
3772 .rx_free_thresh = I40E_DEFAULT_RX_FREE_THRESH,
3777 dev_info->default_txconf = (struct rte_eth_txconf) {
3779 .pthresh = I40E_DEFAULT_TX_PTHRESH,
3780 .hthresh = I40E_DEFAULT_TX_HTHRESH,
3781 .wthresh = I40E_DEFAULT_TX_WTHRESH,
3783 .tx_free_thresh = I40E_DEFAULT_TX_FREE_THRESH,
3784 .tx_rs_thresh = I40E_DEFAULT_TX_RSBIT_THRESH,
3788 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
3789 .nb_max = I40E_MAX_RING_DESC,
3790 .nb_min = I40E_MIN_RING_DESC,
3791 .nb_align = I40E_ALIGN_RING_DESC,
3794 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
3795 .nb_max = I40E_MAX_RING_DESC,
3796 .nb_min = I40E_MIN_RING_DESC,
3797 .nb_align = I40E_ALIGN_RING_DESC,
3798 .nb_seg_max = I40E_TX_MAX_SEG,
3799 .nb_mtu_seg_max = I40E_TX_MAX_MTU_SEG,
3802 if (pf->flags & I40E_FLAG_VMDQ) {
3803 dev_info->max_vmdq_pools = pf->max_nb_vmdq_vsi;
3804 dev_info->vmdq_queue_base = dev_info->max_rx_queues;
3805 dev_info->vmdq_queue_num = pf->vmdq_nb_qps *
3806 pf->max_nb_vmdq_vsi;
3807 dev_info->vmdq_pool_base = I40E_VMDQ_POOL_BASE;
3808 dev_info->max_rx_queues += dev_info->vmdq_queue_num;
3809 dev_info->max_tx_queues += dev_info->vmdq_queue_num;
3812 if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
3814 dev_info->speed_capa = RTE_ETH_LINK_SPEED_40G;
3815 dev_info->default_rxportconf.nb_queues = 2;
3816 dev_info->default_txportconf.nb_queues = 2;
3817 if (dev->data->nb_rx_queues == 1)
3818 dev_info->default_rxportconf.ring_size = 2048;
3820 dev_info->default_rxportconf.ring_size = 1024;
3821 if (dev->data->nb_tx_queues == 1)
3822 dev_info->default_txportconf.ring_size = 1024;
3824 dev_info->default_txportconf.ring_size = 512;
3826 } else if (I40E_PHY_TYPE_SUPPORT_25G(hw->phy.phy_types)) {
3828 dev_info->speed_capa = RTE_ETH_LINK_SPEED_25G;
3829 dev_info->default_rxportconf.nb_queues = 1;
3830 dev_info->default_txportconf.nb_queues = 1;
3831 dev_info->default_rxportconf.ring_size = 256;
3832 dev_info->default_txportconf.ring_size = 256;
3835 dev_info->speed_capa = RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_10G;
3836 dev_info->default_rxportconf.nb_queues = 1;
3837 dev_info->default_txportconf.nb_queues = 1;
3838 if (dev->data->dev_conf.link_speeds & RTE_ETH_LINK_SPEED_10G) {
3839 dev_info->default_rxportconf.ring_size = 512;
3840 dev_info->default_txportconf.ring_size = 256;
3842 dev_info->default_rxportconf.ring_size = 256;
3843 dev_info->default_txportconf.ring_size = 256;
3846 dev_info->default_rxportconf.burst_size = 32;
3847 dev_info->default_txportconf.burst_size = 32;
3853 i40e_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
3855 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3856 struct i40e_vsi *vsi = pf->main_vsi;
3857 PMD_INIT_FUNC_TRACE();
3860 return i40e_vsi_add_vlan(vsi, vlan_id);
3862 return i40e_vsi_delete_vlan(vsi, vlan_id);
3866 i40e_vlan_tpid_set_by_registers(struct rte_eth_dev *dev,
3867 enum rte_vlan_type vlan_type,
3868 uint16_t tpid, int qinq)
3870 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3873 uint16_t reg_id = 3;
3877 if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
3881 ret = i40e_aq_debug_read_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
3883 if (ret != I40E_SUCCESS) {
3885 "Fail to debug read from I40E_GL_SWT_L2TAGCTRL[%d]",
3890 "Debug read from I40E_GL_SWT_L2TAGCTRL[%d]: 0x%08"PRIx64,
3893 reg_w = reg_r & (~(I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_MASK));
3894 reg_w |= ((uint64_t)tpid << I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT);
3895 if (reg_r == reg_w) {
3896 PMD_DRV_LOG(DEBUG, "No need to write");
3900 ret = i40e_aq_debug_write_global_register(hw,
3901 I40E_GL_SWT_L2TAGCTRL(reg_id),
3903 if (ret != I40E_SUCCESS) {
3905 "Fail to debug write to I40E_GL_SWT_L2TAGCTRL[%d]",
3910 "Global register 0x%08x is changed with value 0x%08x",
3911 I40E_GL_SWT_L2TAGCTRL(reg_id), (uint32_t)reg_w);
3917 i40e_vlan_tpid_set(struct rte_eth_dev *dev,
3918 enum rte_vlan_type vlan_type,
3921 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3922 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3923 int qinq = dev->data->dev_conf.rxmode.offloads &
3924 RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
3925 u16 sw_flags = 0, valid_flags = 0;
3928 if ((vlan_type != RTE_ETH_VLAN_TYPE_INNER &&
3929 vlan_type != RTE_ETH_VLAN_TYPE_OUTER) ||
3930 (!qinq && vlan_type == RTE_ETH_VLAN_TYPE_INNER)) {
3932 "Unsupported vlan type.");
3936 if (pf->support_multi_driver) {
3937 PMD_DRV_LOG(ERR, "Setting TPID is not supported.");
3941 /* 802.1ad frames ability is added in NVM API 1.7*/
3942 if (hw->flags & I40E_HW_FLAG_802_1AD_CAPABLE) {
3945 sw_flags = I40E_AQ_SET_SWITCH_CFG_OUTER_VLAN;
3946 valid_flags = I40E_AQ_SET_SWITCH_CFG_OUTER_VLAN;
3948 if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
3949 hw->first_tag = rte_cpu_to_le_16(tpid);
3950 else if (vlan_type == RTE_ETH_VLAN_TYPE_INNER)
3951 hw->second_tag = rte_cpu_to_le_16(tpid);
3954 * If tpid is equal to 0x88A8, indicates that the
3955 * disable double VLAN operation is in progress.
3956 * Need set switch configuration back to default.
3958 if (pf->fw8_3gt && tpid == RTE_ETHER_TYPE_QINQ) {
3960 valid_flags = I40E_AQ_SET_SWITCH_CFG_OUTER_VLAN;
3961 if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
3962 hw->first_tag = rte_cpu_to_le_16(tpid);
3964 if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
3965 hw->second_tag = rte_cpu_to_le_16(tpid);
3968 ret = i40e_aq_set_switch_config(hw, sw_flags,
3969 valid_flags, 0, NULL);
3970 if (ret != I40E_SUCCESS) {
3972 "Set switch config failed aq_err: %d",
3973 hw->aq.asq_last_status);
3977 /* If NVM API < 1.7, keep the register setting */
3978 ret = i40e_vlan_tpid_set_by_registers(dev, vlan_type,
3984 /* Configure outer vlan stripping on or off in QinQ mode */
3986 i40e_vsi_config_outer_vlan_stripping(struct i40e_vsi *vsi, bool on)
3988 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3989 int ret = I40E_SUCCESS;
3992 if (vsi->vsi_id >= I40E_MAX_NUM_VSIS) {
3993 PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
3997 /* Configure for outer VLAN RX stripping */
3998 reg = I40E_READ_REG(hw, I40E_VSI_TSR(vsi->vsi_id));
4001 reg |= I40E_VSI_TSR_QINQ_STRIP;
4003 reg &= ~I40E_VSI_TSR_QINQ_STRIP;
4005 ret = i40e_aq_debug_write_register(hw,
4006 I40E_VSI_TSR(vsi->vsi_id),
4009 PMD_DRV_LOG(ERR, "Failed to update VSI_TSR[%d]",
4011 return I40E_ERR_CONFIG;
4018 i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask)
4020 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4021 struct i40e_mac_filter_info *mac_filter;
4022 struct i40e_vsi *vsi = pf->main_vsi;
4023 struct rte_eth_rxmode *rxmode;
4024 struct i40e_mac_filter *f;
4029 rxmode = &dev->data->dev_conf.rxmode;
4030 if (mask & RTE_ETH_VLAN_FILTER_MASK) {
4031 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
4032 i40e_vsi_config_vlan_filter(vsi, TRUE);
4034 i40e_vsi_config_vlan_filter(vsi, FALSE);
4037 if (mask & RTE_ETH_VLAN_STRIP_MASK) {
4038 /* Enable or disable VLAN stripping */
4039 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
4040 i40e_vsi_config_vlan_stripping(vsi, TRUE);
4042 i40e_vsi_config_vlan_stripping(vsi, FALSE);
4045 if (mask & RTE_ETH_VLAN_EXTEND_MASK) {
4048 mac_filter = rte_zmalloc("mac_filter_info_data",
4049 num * sizeof(*mac_filter), 0);
4050 if (mac_filter == NULL) {
4051 PMD_DRV_LOG(ERR, "failed to allocate memory");
4052 return I40E_ERR_NO_MEMORY;
4056 * Outer VLAN processing is supported after firmware v8.4, kernel driver
4057 * also change the default behavior to support this feature. To align with
4058 * kernel driver, set switch config in 'i40e_vlan_tpie_set' to support for
4059 * outer VLAN processing. But it is forbidden for firmware to change the
4060 * Inner/Outer VLAN configuration while there are MAC/VLAN filters in the
4061 * switch table. Therefore, we need to clear the MAC table before setting
4062 * config, and then restore the MAC table after setting. This feature is
4063 * recommended to be used in firmware v8.6.
4065 /* Remove all existing mac */
4066 RTE_TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
4067 mac_filter[i] = f->mac_info;
4068 ret = i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
4070 PMD_DRV_LOG(ERR, "i40e vsi delete mac fail.");
4073 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND) {
4074 i40e_vsi_config_double_vlan(vsi, TRUE);
4075 /* Set global registers with default ethertype. */
4076 i40e_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_OUTER,
4077 RTE_ETHER_TYPE_VLAN);
4078 i40e_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_INNER,
4079 RTE_ETHER_TYPE_VLAN);
4082 i40e_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_OUTER,
4083 RTE_ETHER_TYPE_QINQ);
4084 i40e_vsi_config_double_vlan(vsi, FALSE);
4086 /* Restore all mac */
4087 for (i = 0; i < num; i++) {
4088 ret = i40e_vsi_add_mac(vsi, &mac_filter[i]);
4090 PMD_DRV_LOG(ERR, "i40e vsi add mac fail.");
4092 rte_free(mac_filter);
4095 if (mask & RTE_ETH_QINQ_STRIP_MASK) {
4096 /* Enable or disable outer VLAN stripping */
4097 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP)
4098 i40e_vsi_config_outer_vlan_stripping(vsi, TRUE);
4100 i40e_vsi_config_outer_vlan_stripping(vsi, FALSE);
4107 i40e_vlan_strip_queue_set(__rte_unused struct rte_eth_dev *dev,
4108 __rte_unused uint16_t queue,
4109 __rte_unused int on)
4111 PMD_INIT_FUNC_TRACE();
4115 i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
4117 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4118 struct i40e_vsi *vsi = pf->main_vsi;
4119 struct rte_eth_dev_data *data = I40E_VSI_TO_DEV_DATA(vsi);
4120 struct i40e_vsi_vlan_pvid_info info;
4122 memset(&info, 0, sizeof(info));
4125 info.config.pvid = pvid;
4127 info.config.reject.tagged =
4128 data->dev_conf.txmode.hw_vlan_reject_tagged;
4129 info.config.reject.untagged =
4130 data->dev_conf.txmode.hw_vlan_reject_untagged;
4133 return i40e_vsi_vlan_pvid_set(vsi, &info);
4137 i40e_dev_led_on(struct rte_eth_dev *dev)
4139 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4140 uint32_t mode = i40e_led_get(hw);
4143 i40e_led_set(hw, 0xf, true); /* 0xf means led always true */
4149 i40e_dev_led_off(struct rte_eth_dev *dev)
4151 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4152 uint32_t mode = i40e_led_get(hw);
4155 i40e_led_set(hw, 0, false);
4161 i40e_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
4163 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4164 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4166 fc_conf->pause_time = pf->fc_conf.pause_time;
4168 /* read out from register, in case they are modified by other port */
4169 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] =
4170 I40E_READ_REG(hw, I40E_GLRPB_GHW) >> I40E_KILOSHIFT;
4171 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] =
4172 I40E_READ_REG(hw, I40E_GLRPB_GLW) >> I40E_KILOSHIFT;
4174 fc_conf->high_water = pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS];
4175 fc_conf->low_water = pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS];
4177 /* Return current mode according to actual setting*/
4178 switch (hw->fc.current_mode) {
4180 fc_conf->mode = RTE_ETH_FC_FULL;
4182 case I40E_FC_TX_PAUSE:
4183 fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
4185 case I40E_FC_RX_PAUSE:
4186 fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
4190 fc_conf->mode = RTE_ETH_FC_NONE;
4197 i40e_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
4199 uint32_t mflcn_reg, fctrl_reg, reg;
4200 uint32_t max_high_water;
4201 uint8_t i, aq_failure;
4205 enum i40e_fc_mode rte_fcmode_2_i40e_fcmode[] = {
4206 [RTE_ETH_FC_NONE] = I40E_FC_NONE,
4207 [RTE_ETH_FC_RX_PAUSE] = I40E_FC_RX_PAUSE,
4208 [RTE_ETH_FC_TX_PAUSE] = I40E_FC_TX_PAUSE,
4209 [RTE_ETH_FC_FULL] = I40E_FC_FULL
4212 /* high_water field in the rte_eth_fc_conf using the kilobytes unit */
4214 max_high_water = I40E_RXPBSIZE >> I40E_KILOSHIFT;
4215 if ((fc_conf->high_water > max_high_water) ||
4216 (fc_conf->high_water < fc_conf->low_water)) {
4218 "Invalid high/low water setup value in KB, High_water must be <= %d.",
4223 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4224 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4225 hw->fc.requested_mode = rte_fcmode_2_i40e_fcmode[fc_conf->mode];
4227 pf->fc_conf.pause_time = fc_conf->pause_time;
4228 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->high_water;
4229 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->low_water;
4231 PMD_INIT_FUNC_TRACE();
4233 /* All the link flow control related enable/disable register
4234 * configuration is handle by the F/W
4236 err = i40e_set_fc(hw, &aq_failure, true);
4240 if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
4241 /* Configure flow control refresh threshold,
4242 * the value for stat_tx_pause_refresh_timer[8]
4243 * is used for global pause operation.
4247 I40E_PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER(8),
4248 pf->fc_conf.pause_time);
4250 /* configure the timer value included in transmitted pause
4252 * the value for stat_tx_pause_quanta[8] is used for global
4255 I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA(8),
4256 pf->fc_conf.pause_time);
4258 fctrl_reg = I40E_READ_REG(hw,
4259 I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL);
4261 if (fc_conf->mac_ctrl_frame_fwd != 0)
4262 fctrl_reg |= I40E_PRTMAC_FWD_CTRL;
4264 fctrl_reg &= ~I40E_PRTMAC_FWD_CTRL;
4266 I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL,
4269 /* Configure pause time (2 TCs per register) */
4270 reg = (uint32_t)pf->fc_conf.pause_time * (uint32_t)0x00010001;
4271 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS / 2; i++)
4272 I40E_WRITE_REG(hw, I40E_PRTDCB_FCTTVN(i), reg);
4274 /* Configure flow control refresh threshold value */
4275 I40E_WRITE_REG(hw, I40E_PRTDCB_FCRTV,
4276 pf->fc_conf.pause_time / 2);
4278 mflcn_reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
4280 /* set or clear MFLCN.PMCF & MFLCN.DPF bits
4281 *depending on configuration
4283 if (fc_conf->mac_ctrl_frame_fwd != 0) {
4284 mflcn_reg |= I40E_PRTDCB_MFLCN_PMCF_MASK;
4285 mflcn_reg &= ~I40E_PRTDCB_MFLCN_DPF_MASK;
4287 mflcn_reg &= ~I40E_PRTDCB_MFLCN_PMCF_MASK;
4288 mflcn_reg |= I40E_PRTDCB_MFLCN_DPF_MASK;
4291 I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, mflcn_reg);
4294 if (!pf->support_multi_driver) {
4295 /* config water marker both based on the packets and bytes */
4296 I40E_WRITE_GLB_REG(hw, I40E_GLRPB_PHW,
4297 (pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
4298 << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
4299 I40E_WRITE_GLB_REG(hw, I40E_GLRPB_PLW,
4300 (pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
4301 << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
4302 I40E_WRITE_GLB_REG(hw, I40E_GLRPB_GHW,
4303 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
4305 I40E_WRITE_GLB_REG(hw, I40E_GLRPB_GLW,
4306 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
4310 "Water marker configuration is not supported.");
4313 I40E_WRITE_FLUSH(hw);
4319 i40e_priority_flow_ctrl_set(__rte_unused struct rte_eth_dev *dev,
4320 __rte_unused struct rte_eth_pfc_conf *pfc_conf)
4322 PMD_INIT_FUNC_TRACE();
4327 /* Add a MAC address, and update filters */
4329 i40e_macaddr_add(struct rte_eth_dev *dev,
4330 struct rte_ether_addr *mac_addr,
4331 __rte_unused uint32_t index,
4334 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4335 struct i40e_mac_filter_info mac_filter;
4336 struct i40e_vsi *vsi;
4337 struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
4340 /* If VMDQ not enabled or configured, return */
4341 if (pool != 0 && (!(pf->flags & I40E_FLAG_VMDQ) ||
4342 !pf->nb_cfg_vmdq_vsi)) {
4343 PMD_DRV_LOG(ERR, "VMDQ not %s, can't set mac to pool %u",
4344 pf->flags & I40E_FLAG_VMDQ ? "configured" : "enabled",
4349 if (pool > pf->nb_cfg_vmdq_vsi) {
4350 PMD_DRV_LOG(ERR, "Pool number %u invalid. Max pool is %u",
4351 pool, pf->nb_cfg_vmdq_vsi);
4355 rte_memcpy(&mac_filter.mac_addr, mac_addr, RTE_ETHER_ADDR_LEN);
4356 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
4357 mac_filter.filter_type = I40E_MACVLAN_PERFECT_MATCH;
4359 mac_filter.filter_type = I40E_MAC_PERFECT_MATCH;
4364 vsi = pf->vmdq[pool - 1].vsi;
4366 ret = i40e_vsi_add_mac(vsi, &mac_filter);
4367 if (ret != I40E_SUCCESS) {
4368 PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
4374 /* Remove a MAC address, and update filters */
4376 i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
4378 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4379 struct i40e_vsi *vsi;
4380 struct rte_eth_dev_data *data = dev->data;
4381 struct rte_ether_addr *macaddr;
4386 macaddr = &(data->mac_addrs[index]);
4388 pool_sel = dev->data->mac_pool_sel[index];
4390 for (i = 0; i < sizeof(pool_sel) * CHAR_BIT; i++) {
4391 if (pool_sel & (1ULL << i)) {
4395 /* No VMDQ pool enabled or configured */
4396 if (!(pf->flags & I40E_FLAG_VMDQ) ||
4397 (i > pf->nb_cfg_vmdq_vsi)) {
4399 "No VMDQ pool enabled/configured");
4402 vsi = pf->vmdq[i - 1].vsi;
4404 ret = i40e_vsi_delete_mac(vsi, macaddr);
4407 PMD_DRV_LOG(ERR, "Failed to remove MACVLAN filter");
4415 i40e_get_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4417 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
4418 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4425 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
4426 ret = i40e_aq_get_rss_lut(hw, vsi->vsi_id,
4427 vsi->type != I40E_VSI_SRIOV,
4430 PMD_DRV_LOG(ERR, "Failed to get RSS lookup table");
4434 uint32_t *lut_dw = (uint32_t *)lut;
4435 uint16_t i, lut_size_dw = lut_size / 4;
4437 if (vsi->type == I40E_VSI_SRIOV) {
4438 for (i = 0; i <= lut_size_dw; i++) {
4439 reg = I40E_VFQF_HLUT1(i, vsi->user_param);
4440 lut_dw[i] = i40e_read_rx_ctl(hw, reg);
4443 for (i = 0; i < lut_size_dw; i++)
4444 lut_dw[i] = I40E_READ_REG(hw,
4453 i40e_set_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4461 pf = I40E_VSI_TO_PF(vsi);
4462 hw = I40E_VSI_TO_HW(vsi);
4464 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
4465 enum i40e_status_code status;
4467 status = i40e_aq_set_rss_lut(hw, vsi->vsi_id,
4468 vsi->type != I40E_VSI_SRIOV,
4472 "Failed to update RSS lookup table, error status: %d",
4477 uint32_t *lut_dw = (uint32_t *)lut;
4478 uint16_t i, lut_size_dw = lut_size / 4;
4480 if (vsi->type == I40E_VSI_SRIOV) {
4481 for (i = 0; i < lut_size_dw; i++)
4484 I40E_VFQF_HLUT1(i, vsi->user_param),
4487 for (i = 0; i < lut_size_dw; i++)
4488 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i),
4491 I40E_WRITE_FLUSH(hw);
4498 i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
4499 struct rte_eth_rss_reta_entry64 *reta_conf,
4502 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4503 uint16_t i, lut_size = pf->hash_lut_size;
4504 uint16_t idx, shift;
4508 if (reta_size != lut_size ||
4509 reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
4511 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)",
4512 reta_size, lut_size);
4516 lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
4518 PMD_DRV_LOG(ERR, "No memory can be allocated");
4521 ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
4524 for (i = 0; i < reta_size; i++) {
4525 idx = i / RTE_ETH_RETA_GROUP_SIZE;
4526 shift = i % RTE_ETH_RETA_GROUP_SIZE;
4527 if (reta_conf[idx].mask & (1ULL << shift))
4528 lut[i] = reta_conf[idx].reta[shift];
4530 ret = i40e_set_rss_lut(pf->main_vsi, lut, reta_size);
4532 pf->adapter->rss_reta_updated = 1;
4541 i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
4542 struct rte_eth_rss_reta_entry64 *reta_conf,
4545 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4546 uint16_t i, lut_size = pf->hash_lut_size;
4547 uint16_t idx, shift;
4551 if (reta_size != lut_size ||
4552 reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
4554 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)",
4555 reta_size, lut_size);
4559 lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
4561 PMD_DRV_LOG(ERR, "No memory can be allocated");
4565 ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
4568 for (i = 0; i < reta_size; i++) {
4569 idx = i / RTE_ETH_RETA_GROUP_SIZE;
4570 shift = i % RTE_ETH_RETA_GROUP_SIZE;
4571 if (reta_conf[idx].mask & (1ULL << shift))
4572 reta_conf[idx].reta[shift] = lut[i];
4582 * i40e_allocate_dma_mem_d - specific memory alloc for shared code (base driver)
4583 * @hw: pointer to the HW structure
4584 * @mem: pointer to mem struct to fill out
4585 * @size: size of memory requested
4586 * @alignment: what to align the allocation to
4588 enum i40e_status_code
4589 i40e_allocate_dma_mem_d(__rte_unused struct i40e_hw *hw,
4590 struct i40e_dma_mem *mem,
4594 static uint64_t i40e_dma_memzone_id;
4595 const struct rte_memzone *mz = NULL;
4596 char z_name[RTE_MEMZONE_NAMESIZE];
4599 return I40E_ERR_PARAM;
4601 snprintf(z_name, sizeof(z_name), "i40e_dma_%" PRIu64,
4602 __atomic_fetch_add(&i40e_dma_memzone_id, 1, __ATOMIC_RELAXED));
4603 mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY,
4604 RTE_MEMZONE_IOVA_CONTIG, alignment, RTE_PGSIZE_2M);
4606 return I40E_ERR_NO_MEMORY;
4611 mem->zone = (const void *)mz;
4613 "memzone %s allocated with physical address: %"PRIu64,
4616 return I40E_SUCCESS;
4620 * i40e_free_dma_mem_d - specific memory free for shared code (base driver)
4621 * @hw: pointer to the HW structure
4622 * @mem: ptr to mem struct to free
4624 enum i40e_status_code
4625 i40e_free_dma_mem_d(__rte_unused struct i40e_hw *hw,
4626 struct i40e_dma_mem *mem)
4629 return I40E_ERR_PARAM;
4632 "memzone %s to be freed with physical address: %"PRIu64,
4633 ((const struct rte_memzone *)mem->zone)->name, mem->pa);
4634 rte_memzone_free((const struct rte_memzone *)mem->zone);
4639 return I40E_SUCCESS;
4643 * i40e_allocate_virt_mem_d - specific memory alloc for shared code (base driver)
4644 * @hw: pointer to the HW structure
4645 * @mem: pointer to mem struct to fill out
4646 * @size: size of memory requested
4648 enum i40e_status_code
4649 i40e_allocate_virt_mem_d(__rte_unused struct i40e_hw *hw,
4650 struct i40e_virt_mem *mem,
4654 return I40E_ERR_PARAM;
4657 mem->va = rte_zmalloc("i40e", size, 0);
4660 return I40E_SUCCESS;
4662 return I40E_ERR_NO_MEMORY;
4666 * i40e_free_virt_mem_d - specific memory free for shared code (base driver)
4667 * @hw: pointer to the HW structure
4668 * @mem: pointer to mem struct to free
4670 enum i40e_status_code
4671 i40e_free_virt_mem_d(__rte_unused struct i40e_hw *hw,
4672 struct i40e_virt_mem *mem)
4675 return I40E_ERR_PARAM;
4680 return I40E_SUCCESS;
4684 i40e_init_spinlock_d(struct i40e_spinlock *sp)
4686 rte_spinlock_init(&sp->spinlock);
4690 i40e_acquire_spinlock_d(struct i40e_spinlock *sp)
4692 rte_spinlock_lock(&sp->spinlock);
4696 i40e_release_spinlock_d(struct i40e_spinlock *sp)
4698 rte_spinlock_unlock(&sp->spinlock);
4702 i40e_destroy_spinlock_d(__rte_unused struct i40e_spinlock *sp)
4708 * Get the hardware capabilities, which will be parsed
4709 * and saved into struct i40e_hw.
4712 i40e_get_cap(struct i40e_hw *hw)
4714 struct i40e_aqc_list_capabilities_element_resp *buf;
4715 uint16_t len, size = 0;
4718 /* Calculate a huge enough buff for saving response data temporarily */
4719 len = sizeof(struct i40e_aqc_list_capabilities_element_resp) *
4720 I40E_MAX_CAP_ELE_NUM;
4721 buf = rte_zmalloc("i40e", len, 0);
4723 PMD_DRV_LOG(ERR, "Failed to allocate memory");
4724 return I40E_ERR_NO_MEMORY;
4727 /* Get, parse the capabilities and save it to hw */
4728 ret = i40e_aq_discover_capabilities(hw, buf, len, &size,
4729 i40e_aqc_opc_list_func_capabilities, NULL);
4730 if (ret != I40E_SUCCESS)
4731 PMD_DRV_LOG(ERR, "Failed to discover capabilities");
4733 /* Free the temporary buffer after being used */
4739 #define RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF 4
4741 static int i40e_pf_parse_vf_queue_number_handler(const char *key,
4749 pf = (struct i40e_pf *)opaque;
4753 num = strtoul(value, &end, 0);
4754 if (errno != 0 || end == value || *end != 0) {
4755 PMD_DRV_LOG(WARNING, "Wrong VF queue number = %s, Now it is "
4756 "kept the value = %hu", value, pf->vf_nb_qp_max);
4760 if (num <= I40E_MAX_QP_NUM_PER_VF && rte_is_power_of_2(num))
4761 pf->vf_nb_qp_max = (uint16_t)num;
4763 /* here return 0 to make next valid same argument work */
4764 PMD_DRV_LOG(WARNING, "Wrong VF queue number = %lu, it must be "
4765 "power of 2 and equal or less than 16 !, Now it is "
4766 "kept the value = %hu", num, pf->vf_nb_qp_max);
4771 static int i40e_pf_config_vf_rxq_number(struct rte_eth_dev *dev)
4773 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4774 struct rte_kvargs *kvlist;
4777 /* set default queue number per VF as 4 */
4778 pf->vf_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF;
4780 if (dev->device->devargs == NULL)
4783 kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
4787 kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_QUEUE_NUM_PER_VF_ARG);
4788 if (!kvargs_count) {
4789 rte_kvargs_free(kvlist);
4793 if (kvargs_count > 1)
4794 PMD_DRV_LOG(WARNING, "More than one argument \"%s\" and only "
4795 "the first invalid or last valid one is used !",
4796 ETH_I40E_QUEUE_NUM_PER_VF_ARG);
4798 rte_kvargs_process(kvlist, ETH_I40E_QUEUE_NUM_PER_VF_ARG,
4799 i40e_pf_parse_vf_queue_number_handler, pf);
4801 rte_kvargs_free(kvlist);
4807 i40e_pf_parameter_init(struct rte_eth_dev *dev)
4809 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4810 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4811 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
4812 uint16_t qp_count = 0, vsi_count = 0;
4814 if (pci_dev->max_vfs && !hw->func_caps.sr_iov_1_1) {
4815 PMD_INIT_LOG(ERR, "HW configuration doesn't support SRIOV");
4819 i40e_pf_config_vf_rxq_number(dev);
4821 /* Add the parameter init for LFC */
4822 pf->fc_conf.pause_time = I40E_DEFAULT_PAUSE_TIME;
4823 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_HIGH_WATER;
4824 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_LOW_WATER;
4826 pf->flags = I40E_FLAG_HEADER_SPLIT_DISABLED;
4827 pf->max_num_vsi = hw->func_caps.num_vsis;
4828 pf->lan_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_PF;
4829 pf->vmdq_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
4831 /* FDir queue/VSI allocation */
4832 pf->fdir_qp_offset = 0;
4833 if (hw->func_caps.fd) {
4834 pf->flags |= I40E_FLAG_FDIR;
4835 pf->fdir_nb_qps = I40E_DEFAULT_QP_NUM_FDIR;
4837 pf->fdir_nb_qps = 0;
4839 qp_count += pf->fdir_nb_qps;
4842 /* LAN queue/VSI allocation */
4843 pf->lan_qp_offset = pf->fdir_qp_offset + pf->fdir_nb_qps;
4844 if (!hw->func_caps.rss) {
4847 pf->flags |= I40E_FLAG_RSS;
4848 if (hw->mac.type == I40E_MAC_X722)
4849 pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE;
4850 pf->lan_nb_qps = pf->lan_nb_qp_max;
4852 qp_count += pf->lan_nb_qps;
4855 /* VF queue/VSI allocation */
4856 pf->vf_qp_offset = pf->lan_qp_offset + pf->lan_nb_qps;
4857 if (hw->func_caps.sr_iov_1_1 && pci_dev->max_vfs) {
4858 pf->flags |= I40E_FLAG_SRIOV;
4859 pf->vf_nb_qps = pf->vf_nb_qp_max;
4860 pf->vf_num = pci_dev->max_vfs;
4862 "%u VF VSIs, %u queues per VF VSI, in total %u queues",
4863 pf->vf_num, pf->vf_nb_qps, pf->vf_nb_qps * pf->vf_num);
4868 qp_count += pf->vf_nb_qps * pf->vf_num;
4869 vsi_count += pf->vf_num;
4871 /* VMDq queue/VSI allocation */
4872 pf->vmdq_qp_offset = pf->vf_qp_offset + pf->vf_nb_qps * pf->vf_num;
4873 pf->vmdq_nb_qps = 0;
4874 pf->max_nb_vmdq_vsi = 0;
4875 if (hw->func_caps.vmdq) {
4876 if (qp_count < hw->func_caps.num_tx_qp &&
4877 vsi_count < hw->func_caps.num_vsis) {
4878 pf->max_nb_vmdq_vsi = (hw->func_caps.num_tx_qp -
4879 qp_count) / pf->vmdq_nb_qp_max;
4881 /* Limit the maximum number of VMDq vsi to the maximum
4882 * ethdev can support
4884 pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
4885 hw->func_caps.num_vsis - vsi_count);
4886 pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
4888 if (pf->max_nb_vmdq_vsi) {
4889 pf->flags |= I40E_FLAG_VMDQ;
4890 pf->vmdq_nb_qps = pf->vmdq_nb_qp_max;
4892 "%u VMDQ VSIs, %u queues per VMDQ VSI, in total %u queues",
4893 pf->max_nb_vmdq_vsi, pf->vmdq_nb_qps,
4894 pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi);
4897 "No enough queues left for VMDq");
4900 PMD_DRV_LOG(INFO, "No queue or VSI left for VMDq");
4903 qp_count += pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi;
4904 vsi_count += pf->max_nb_vmdq_vsi;
4906 if (hw->func_caps.dcb)
4907 pf->flags |= I40E_FLAG_DCB;
4909 if (qp_count > hw->func_caps.num_tx_qp) {
4911 "Failed to allocate %u queues, which exceeds the hardware maximum %u",
4912 qp_count, hw->func_caps.num_tx_qp);
4915 if (vsi_count > hw->func_caps.num_vsis) {
4917 "Failed to allocate %u VSIs, which exceeds the hardware maximum %u",
4918 vsi_count, hw->func_caps.num_vsis);
4923 * Enable outer VLAN processing if firmware version is greater
4926 if (hw->aq.fw_maj_ver > 8 ||
4927 (hw->aq.fw_maj_ver == 8 && hw->aq.fw_min_ver > 3)) {
4930 pf->fw8_3gt = false;
4937 i40e_pf_get_switch_config(struct i40e_pf *pf)
4939 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4940 struct i40e_aqc_get_switch_config_resp *switch_config;
4941 struct i40e_aqc_switch_config_element_resp *element;
4942 uint16_t start_seid = 0, num_reported;
4945 switch_config = (struct i40e_aqc_get_switch_config_resp *)\
4946 rte_zmalloc("i40e", I40E_AQ_LARGE_BUF, 0);
4947 if (!switch_config) {
4948 PMD_DRV_LOG(ERR, "Failed to allocated memory");
4952 /* Get the switch configurations */
4953 ret = i40e_aq_get_switch_config(hw, switch_config,
4954 I40E_AQ_LARGE_BUF, &start_seid, NULL);
4955 if (ret != I40E_SUCCESS) {
4956 PMD_DRV_LOG(ERR, "Failed to get switch configurations");
4959 num_reported = rte_le_to_cpu_16(switch_config->header.num_reported);
4960 if (num_reported != 1) { /* The number should be 1 */
4961 PMD_DRV_LOG(ERR, "Wrong number of switch config reported");
4965 /* Parse the switch configuration elements */
4966 element = &(switch_config->element[0]);
4967 if (element->element_type == I40E_SWITCH_ELEMENT_TYPE_VSI) {
4968 pf->mac_seid = rte_le_to_cpu_16(element->uplink_seid);
4969 pf->main_vsi_seid = rte_le_to_cpu_16(element->seid);
4971 PMD_DRV_LOG(INFO, "Unknown element type");
4974 rte_free(switch_config);
4980 i40e_res_pool_init (struct i40e_res_pool_info *pool, uint32_t base,
4983 struct pool_entry *entry;
4985 if (pool == NULL || num == 0)
4988 entry = rte_zmalloc("i40e", sizeof(*entry), 0);
4989 if (entry == NULL) {
4990 PMD_DRV_LOG(ERR, "Failed to allocate memory for resource pool");
4994 /* queue heap initialize */
4995 pool->num_free = num;
4996 pool->num_alloc = 0;
4998 LIST_INIT(&pool->alloc_list);
4999 LIST_INIT(&pool->free_list);
5001 /* Initialize element */
5005 LIST_INSERT_HEAD(&pool->free_list, entry, next);
5010 i40e_res_pool_destroy(struct i40e_res_pool_info *pool)
5012 struct pool_entry *entry, *next_entry;
5017 for (entry = LIST_FIRST(&pool->alloc_list);
5018 entry && (next_entry = LIST_NEXT(entry, next), 1);
5019 entry = next_entry) {
5020 LIST_REMOVE(entry, next);
5024 for (entry = LIST_FIRST(&pool->free_list);
5025 entry && (next_entry = LIST_NEXT(entry, next), 1);
5026 entry = next_entry) {
5027 LIST_REMOVE(entry, next);
5032 pool->num_alloc = 0;
5034 LIST_INIT(&pool->alloc_list);
5035 LIST_INIT(&pool->free_list);
5039 i40e_res_pool_free(struct i40e_res_pool_info *pool,
5042 struct pool_entry *entry, *next, *prev, *valid_entry = NULL;
5043 uint32_t pool_offset;
5048 PMD_DRV_LOG(ERR, "Invalid parameter");
5052 pool_offset = base - pool->base;
5053 /* Lookup in alloc list */
5054 LIST_FOREACH(entry, &pool->alloc_list, next) {
5055 if (entry->base == pool_offset) {
5056 valid_entry = entry;
5057 LIST_REMOVE(entry, next);
5062 /* Not find, return */
5063 if (valid_entry == NULL) {
5064 PMD_DRV_LOG(ERR, "Failed to find entry");
5069 * Found it, move it to free list and try to merge.
5070 * In order to make merge easier, always sort it by qbase.
5071 * Find adjacent prev and last entries.
5074 LIST_FOREACH(entry, &pool->free_list, next) {
5075 if (entry->base > valid_entry->base) {
5083 len = valid_entry->len;
5084 /* Try to merge with next one*/
5086 /* Merge with next one */
5087 if (valid_entry->base + len == next->base) {
5088 next->base = valid_entry->base;
5090 rte_free(valid_entry);
5097 /* Merge with previous one */
5098 if (prev->base + prev->len == valid_entry->base) {
5100 /* If it merge with next one, remove next node */
5102 LIST_REMOVE(valid_entry, next);
5103 rte_free(valid_entry);
5106 rte_free(valid_entry);
5113 /* Not find any entry to merge, insert */
5116 LIST_INSERT_AFTER(prev, valid_entry, next);
5117 else if (next != NULL)
5118 LIST_INSERT_BEFORE(next, valid_entry, next);
5119 else /* It's empty list, insert to head */
5120 LIST_INSERT_HEAD(&pool->free_list, valid_entry, next);
5123 pool->num_free += len;
5124 pool->num_alloc -= len;
5130 i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
5133 struct pool_entry *entry, *valid_entry;
5135 if (pool == NULL || num == 0) {
5136 PMD_DRV_LOG(ERR, "Invalid parameter");
5140 if (pool->num_free < num) {
5141 PMD_DRV_LOG(ERR, "No resource. ask:%u, available:%u",
5142 num, pool->num_free);
5147 /* Lookup in free list and find most fit one */
5148 LIST_FOREACH(entry, &pool->free_list, next) {
5149 if (entry->len >= num) {
5151 if (entry->len == num) {
5152 valid_entry = entry;
5155 if (valid_entry == NULL || valid_entry->len > entry->len)
5156 valid_entry = entry;
5160 /* Not find one to satisfy the request, return */
5161 if (valid_entry == NULL) {
5162 PMD_DRV_LOG(ERR, "No valid entry found");
5166 * The entry have equal queue number as requested,
5167 * remove it from alloc_list.
5169 if (valid_entry->len == num) {
5170 LIST_REMOVE(valid_entry, next);
5173 * The entry have more numbers than requested,
5174 * create a new entry for alloc_list and minus its
5175 * queue base and number in free_list.
5177 entry = rte_zmalloc("res_pool", sizeof(*entry), 0);
5178 if (entry == NULL) {
5180 "Failed to allocate memory for resource pool");
5183 entry->base = valid_entry->base;
5185 valid_entry->base += num;
5186 valid_entry->len -= num;
5187 valid_entry = entry;
5190 /* Insert it into alloc list, not sorted */
5191 LIST_INSERT_HEAD(&pool->alloc_list, valid_entry, next);
5193 pool->num_free -= valid_entry->len;
5194 pool->num_alloc += valid_entry->len;
5196 return valid_entry->base + pool->base;
5200 * bitmap_is_subset - Check whether src2 is subset of src1
5203 bitmap_is_subset(uint8_t src1, uint8_t src2)
5205 return !((src1 ^ src2) & src2);
5208 static enum i40e_status_code
5209 validate_tcmap_parameter(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
5211 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5213 /* If DCB is not supported, only default TC is supported */
5214 if (!hw->func_caps.dcb && enabled_tcmap != I40E_DEFAULT_TCMAP) {
5215 PMD_DRV_LOG(ERR, "DCB is not enabled, only TC0 is supported");
5216 return I40E_NOT_SUPPORTED;
5219 if (!bitmap_is_subset(hw->func_caps.enabled_tcmap, enabled_tcmap)) {
5221 "Enabled TC map 0x%x not applicable to HW support 0x%x",
5222 hw->func_caps.enabled_tcmap, enabled_tcmap);
5223 return I40E_NOT_SUPPORTED;
5225 return I40E_SUCCESS;
5229 i40e_vsi_vlan_pvid_set(struct i40e_vsi *vsi,
5230 struct i40e_vsi_vlan_pvid_info *info)
5233 struct i40e_vsi_context ctxt;
5234 uint8_t vlan_flags = 0;
5237 if (vsi == NULL || info == NULL) {
5238 PMD_DRV_LOG(ERR, "invalid parameters");
5239 return I40E_ERR_PARAM;
5243 vsi->info.pvid = info->config.pvid;
5245 * If insert pvid is enabled, only tagged pkts are
5246 * allowed to be sent out.
5248 vlan_flags |= I40E_AQ_VSI_PVLAN_INSERT_PVID |
5249 I40E_AQ_VSI_PVLAN_MODE_TAGGED;
5252 if (info->config.reject.tagged == 0)
5253 vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_TAGGED;
5255 if (info->config.reject.untagged == 0)
5256 vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_UNTAGGED;
5258 vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_INSERT_PVID |
5259 I40E_AQ_VSI_PVLAN_MODE_MASK);
5260 vsi->info.port_vlan_flags |= vlan_flags;
5261 vsi->info.valid_sections =
5262 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5263 memset(&ctxt, 0, sizeof(ctxt));
5264 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
5265 ctxt.seid = vsi->seid;
5267 hw = I40E_VSI_TO_HW(vsi);
5268 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5269 if (ret != I40E_SUCCESS)
5270 PMD_DRV_LOG(ERR, "Failed to update VSI params");
5276 i40e_vsi_update_tc_bandwidth(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
5278 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5280 struct i40e_aqc_configure_vsi_tc_bw_data tc_bw_data;
5282 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
5283 if (ret != I40E_SUCCESS)
5287 PMD_DRV_LOG(ERR, "seid not valid");
5291 memset(&tc_bw_data, 0, sizeof(tc_bw_data));
5292 tc_bw_data.tc_valid_bits = enabled_tcmap;
5293 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5294 tc_bw_data.tc_bw_credits[i] =
5295 (enabled_tcmap & (1 << i)) ? 1 : 0;
5297 ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &tc_bw_data, NULL);
5298 if (ret != I40E_SUCCESS) {
5299 PMD_DRV_LOG(ERR, "Failed to configure TC BW");
5303 rte_memcpy(vsi->info.qs_handle, tc_bw_data.qs_handles,
5304 sizeof(vsi->info.qs_handle));
5305 return I40E_SUCCESS;
5308 static enum i40e_status_code
5309 i40e_vsi_config_tc_queue_mapping(struct i40e_vsi *vsi,
5310 struct i40e_aqc_vsi_properties_data *info,
5311 uint8_t enabled_tcmap)
5313 enum i40e_status_code ret;
5314 int i, total_tc = 0;
5315 uint16_t qpnum_per_tc, bsf, qp_idx;
5317 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
5318 if (ret != I40E_SUCCESS)
5321 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5322 if (enabled_tcmap & (1 << i))
5326 vsi->enabled_tc = enabled_tcmap;
5328 /* Number of queues per enabled TC */
5329 qpnum_per_tc = i40e_align_floor(vsi->nb_qps / total_tc);
5330 qpnum_per_tc = RTE_MIN(qpnum_per_tc, I40E_MAX_Q_PER_TC);
5331 bsf = rte_bsf32(qpnum_per_tc);
5333 /* Adjust the queue number to actual queues that can be applied */
5334 if (!(vsi->type == I40E_VSI_MAIN && total_tc == 1))
5335 vsi->nb_qps = qpnum_per_tc * total_tc;
5338 * Configure TC and queue mapping parameters, for enabled TC,
5339 * allocate qpnum_per_tc queues to this traffic. For disabled TC,
5340 * default queue will serve it.
5343 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5344 if (vsi->enabled_tc & (1 << i)) {
5345 info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
5346 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
5347 (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
5348 qp_idx += qpnum_per_tc;
5350 info->tc_mapping[i] = 0;
5353 /* Associate queue number with VSI */
5354 if (vsi->type == I40E_VSI_SRIOV) {
5355 info->mapping_flags |=
5356 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
5357 for (i = 0; i < vsi->nb_qps; i++)
5358 info->queue_mapping[i] =
5359 rte_cpu_to_le_16(vsi->base_queue + i);
5361 info->mapping_flags |=
5362 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
5363 info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
5365 info->valid_sections |=
5366 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
5368 return I40E_SUCCESS;
5372 i40e_veb_release(struct i40e_veb *veb)
5374 struct i40e_vsi *vsi;
5380 if (!TAILQ_EMPTY(&veb->head)) {
5381 PMD_DRV_LOG(ERR, "VEB still has VSI attached, can't remove");
5384 /* associate_vsi field is NULL for floating VEB */
5385 if (veb->associate_vsi != NULL) {
5386 vsi = veb->associate_vsi;
5387 hw = I40E_VSI_TO_HW(vsi);
5389 vsi->uplink_seid = veb->uplink_seid;
5392 veb->associate_pf->main_vsi->floating_veb = NULL;
5393 hw = I40E_VSI_TO_HW(veb->associate_pf->main_vsi);
5396 i40e_aq_delete_element(hw, veb->seid, NULL);
5398 return I40E_SUCCESS;
5402 static struct i40e_veb *
5403 i40e_veb_setup(struct i40e_pf *pf, struct i40e_vsi *vsi)
5405 struct i40e_veb *veb;
5411 "veb setup failed, associated PF shouldn't null");
5414 hw = I40E_PF_TO_HW(pf);
5416 veb = rte_zmalloc("i40e_veb", sizeof(struct i40e_veb), 0);
5418 PMD_DRV_LOG(ERR, "Failed to allocate memory for veb");
5422 veb->associate_vsi = vsi;
5423 veb->associate_pf = pf;
5424 TAILQ_INIT(&veb->head);
5425 veb->uplink_seid = vsi ? vsi->uplink_seid : 0;
5427 /* create floating veb if vsi is NULL */
5429 ret = i40e_aq_add_veb(hw, veb->uplink_seid, vsi->seid,
5430 I40E_DEFAULT_TCMAP, false,
5431 &veb->seid, false, NULL);
5433 ret = i40e_aq_add_veb(hw, 0, 0, I40E_DEFAULT_TCMAP,
5434 true, &veb->seid, false, NULL);
5437 if (ret != I40E_SUCCESS) {
5438 PMD_DRV_LOG(ERR, "Add veb failed, aq_err: %d",
5439 hw->aq.asq_last_status);
5442 veb->enabled_tc = I40E_DEFAULT_TCMAP;
5444 /* get statistics index */
5445 ret = i40e_aq_get_veb_parameters(hw, veb->seid, NULL, NULL,
5446 &veb->stats_idx, NULL, NULL, NULL);
5447 if (ret != I40E_SUCCESS) {
5448 PMD_DRV_LOG(ERR, "Get veb statistics index failed, aq_err: %d",
5449 hw->aq.asq_last_status);
5452 /* Get VEB bandwidth, to be implemented */
5453 /* Now associated vsi binding to the VEB, set uplink to this VEB */
5455 vsi->uplink_seid = veb->seid;
5464 i40e_vsi_release(struct i40e_vsi *vsi)
5468 struct i40e_vsi_list *vsi_list;
5471 struct i40e_mac_filter *f;
5472 uint16_t user_param;
5475 return I40E_SUCCESS;
5480 user_param = vsi->user_param;
5482 pf = I40E_VSI_TO_PF(vsi);
5483 hw = I40E_VSI_TO_HW(vsi);
5485 /* VSI has child to attach, release child first */
5487 RTE_TAILQ_FOREACH_SAFE(vsi_list, &vsi->veb->head, list, temp) {
5488 if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
5491 i40e_veb_release(vsi->veb);
5494 if (vsi->floating_veb) {
5495 RTE_TAILQ_FOREACH_SAFE(vsi_list, &vsi->floating_veb->head,
5497 if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
5502 /* Remove all macvlan filters of the VSI */
5503 i40e_vsi_remove_all_macvlan_filter(vsi);
5504 RTE_TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp)
5507 if (vsi->type != I40E_VSI_MAIN &&
5508 ((vsi->type != I40E_VSI_SRIOV) ||
5509 !pf->floating_veb_list[user_param])) {
5510 /* Remove vsi from parent's sibling list */
5511 if (vsi->parent_vsi == NULL || vsi->parent_vsi->veb == NULL) {
5512 PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
5513 return I40E_ERR_PARAM;
5515 TAILQ_REMOVE(&vsi->parent_vsi->veb->head,
5516 &vsi->sib_vsi_list, list);
5518 /* Remove all switch element of the VSI */
5519 ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
5520 if (ret != I40E_SUCCESS)
5521 PMD_DRV_LOG(ERR, "Failed to delete element");
5524 if ((vsi->type == I40E_VSI_SRIOV) &&
5525 pf->floating_veb_list[user_param]) {
5526 /* Remove vsi from parent's sibling list */
5527 if (vsi->parent_vsi == NULL ||
5528 vsi->parent_vsi->floating_veb == NULL) {
5529 PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
5530 return I40E_ERR_PARAM;
5532 TAILQ_REMOVE(&vsi->parent_vsi->floating_veb->head,
5533 &vsi->sib_vsi_list, list);
5535 /* Remove all switch element of the VSI */
5536 ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
5537 if (ret != I40E_SUCCESS)
5538 PMD_DRV_LOG(ERR, "Failed to delete element");
5541 i40e_res_pool_free(&pf->qp_pool, vsi->base_queue);
5543 if (vsi->type != I40E_VSI_SRIOV)
5544 i40e_res_pool_free(&pf->msix_pool, vsi->msix_intr);
5547 return I40E_SUCCESS;
5551 i40e_update_default_filter_setting(struct i40e_vsi *vsi)
5553 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5554 struct i40e_aqc_remove_macvlan_element_data def_filter;
5555 struct i40e_mac_filter_info filter;
5558 if (vsi->type != I40E_VSI_MAIN)
5559 return I40E_ERR_CONFIG;
5560 memset(&def_filter, 0, sizeof(def_filter));
5561 rte_memcpy(def_filter.mac_addr, hw->mac.perm_addr,
5563 def_filter.vlan_tag = 0;
5564 def_filter.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
5565 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
5566 ret = i40e_aq_remove_macvlan(hw, vsi->seid, &def_filter, 1, NULL);
5567 if (ret != I40E_SUCCESS) {
5568 struct i40e_mac_filter *f;
5569 struct rte_ether_addr *mac;
5572 "Cannot remove the default macvlan filter");
5573 /* It needs to add the permanent mac into mac list */
5574 f = rte_zmalloc("macv_filter", sizeof(*f), 0);
5576 PMD_DRV_LOG(ERR, "failed to allocate memory");
5577 return I40E_ERR_NO_MEMORY;
5579 mac = &f->mac_info.mac_addr;
5580 rte_memcpy(&mac->addr_bytes, hw->mac.perm_addr,
5582 f->mac_info.filter_type = I40E_MACVLAN_PERFECT_MATCH;
5583 TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
5588 rte_memcpy(&filter.mac_addr,
5589 (struct rte_ether_addr *)(hw->mac.perm_addr), ETH_ADDR_LEN);
5590 filter.filter_type = I40E_MACVLAN_PERFECT_MATCH;
5591 return i40e_vsi_add_mac(vsi, &filter);
5595 * i40e_vsi_get_bw_config - Query VSI BW Information
5596 * @vsi: the VSI to be queried
5598 * Returns 0 on success, negative value on failure
5600 static enum i40e_status_code
5601 i40e_vsi_get_bw_config(struct i40e_vsi *vsi)
5603 struct i40e_aqc_query_vsi_bw_config_resp bw_config;
5604 struct i40e_aqc_query_vsi_ets_sla_config_resp ets_sla_config;
5605 struct i40e_hw *hw = &vsi->adapter->hw;
5610 memset(&bw_config, 0, sizeof(bw_config));
5611 ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
5612 if (ret != I40E_SUCCESS) {
5613 PMD_DRV_LOG(ERR, "VSI failed to get bandwidth configuration %u",
5614 hw->aq.asq_last_status);
5618 memset(&ets_sla_config, 0, sizeof(ets_sla_config));
5619 ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid,
5620 &ets_sla_config, NULL);
5621 if (ret != I40E_SUCCESS) {
5623 "VSI failed to get TC bandwidth configuration %u",
5624 hw->aq.asq_last_status);
5628 /* store and print out BW info */
5629 vsi->bw_info.bw_limit = rte_le_to_cpu_16(bw_config.port_bw_limit);
5630 vsi->bw_info.bw_max = bw_config.max_bw;
5631 PMD_DRV_LOG(DEBUG, "VSI bw limit:%u", vsi->bw_info.bw_limit);
5632 PMD_DRV_LOG(DEBUG, "VSI max_bw:%u", vsi->bw_info.bw_max);
5633 bw_max = rte_le_to_cpu_16(ets_sla_config.tc_bw_max[0]) |
5634 (rte_le_to_cpu_16(ets_sla_config.tc_bw_max[1]) <<
5636 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5637 vsi->bw_info.bw_ets_share_credits[i] =
5638 ets_sla_config.share_credits[i];
5639 vsi->bw_info.bw_ets_credits[i] =
5640 rte_le_to_cpu_16(ets_sla_config.credits[i]);
5641 /* 4 bits per TC, 4th bit is reserved */
5642 vsi->bw_info.bw_ets_max[i] =
5643 (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
5644 RTE_LEN2MASK(3, uint8_t));
5645 PMD_DRV_LOG(DEBUG, "\tVSI TC%u:share credits %u", i,
5646 vsi->bw_info.bw_ets_share_credits[i]);
5647 PMD_DRV_LOG(DEBUG, "\tVSI TC%u:credits %u", i,
5648 vsi->bw_info.bw_ets_credits[i]);
5649 PMD_DRV_LOG(DEBUG, "\tVSI TC%u: max credits: %u", i,
5650 vsi->bw_info.bw_ets_max[i]);
5653 return I40E_SUCCESS;
5656 /* i40e_enable_pf_lb
5657 * @pf: pointer to the pf structure
5659 * allow loopback on pf
5662 i40e_enable_pf_lb(struct i40e_pf *pf)
5664 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5665 struct i40e_vsi_context ctxt;
5668 /* Use the FW API if FW >= v5.0 */
5669 if (hw->aq.fw_maj_ver < 5 && hw->mac.type != I40E_MAC_X722) {
5670 PMD_INIT_LOG(ERR, "FW < v5.0, cannot enable loopback");
5674 memset(&ctxt, 0, sizeof(ctxt));
5675 ctxt.seid = pf->main_vsi_seid;
5676 ctxt.pf_num = hw->pf_id;
5677 ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5679 PMD_DRV_LOG(ERR, "cannot get pf vsi config, err %d, aq_err %d",
5680 ret, hw->aq.asq_last_status);
5683 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
5684 ctxt.info.valid_sections =
5685 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5686 ctxt.info.switch_id |=
5687 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5689 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5691 PMD_DRV_LOG(ERR, "update vsi switch failed, aq_err=%d",
5692 hw->aq.asq_last_status);
5697 i40e_vsi_setup(struct i40e_pf *pf,
5698 enum i40e_vsi_type type,
5699 struct i40e_vsi *uplink_vsi,
5700 uint16_t user_param)
5702 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5703 struct i40e_vsi *vsi;
5704 struct i40e_mac_filter_info filter;
5706 struct i40e_vsi_context ctxt;
5707 struct rte_ether_addr broadcast =
5708 {.addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
5710 if (type != I40E_VSI_MAIN && type != I40E_VSI_SRIOV &&
5711 uplink_vsi == NULL) {
5713 "VSI setup failed, VSI link shouldn't be NULL");
5717 if (type == I40E_VSI_MAIN && uplink_vsi != NULL) {
5719 "VSI setup failed, MAIN VSI uplink VSI should be NULL");
5724 * 1.type is not MAIN and uplink vsi is not NULL
5725 * If uplink vsi didn't setup VEB, create one first under veb field
5726 * 2.type is SRIOV and the uplink is NULL
5727 * If floating VEB is NULL, create one veb under floating veb field
5730 if (type != I40E_VSI_MAIN && uplink_vsi != NULL &&
5731 uplink_vsi->veb == NULL) {
5732 uplink_vsi->veb = i40e_veb_setup(pf, uplink_vsi);
5734 if (uplink_vsi->veb == NULL) {
5735 PMD_DRV_LOG(ERR, "VEB setup failed");
5738 /* set ALLOWLOOPBACk on pf, when veb is created */
5739 i40e_enable_pf_lb(pf);
5742 if (type == I40E_VSI_SRIOV && uplink_vsi == NULL &&
5743 pf->main_vsi->floating_veb == NULL) {
5744 pf->main_vsi->floating_veb = i40e_veb_setup(pf, uplink_vsi);
5746 if (pf->main_vsi->floating_veb == NULL) {
5747 PMD_DRV_LOG(ERR, "VEB setup failed");
5752 vsi = rte_zmalloc("i40e_vsi", sizeof(struct i40e_vsi), 0);
5754 PMD_DRV_LOG(ERR, "Failed to allocate memory for vsi");
5757 TAILQ_INIT(&vsi->mac_list);
5759 vsi->adapter = I40E_PF_TO_ADAPTER(pf);
5760 vsi->max_macaddrs = I40E_NUM_MACADDR_MAX;
5761 vsi->parent_vsi = uplink_vsi ? uplink_vsi : pf->main_vsi;
5762 vsi->user_param = user_param;
5763 vsi->vlan_anti_spoof_on = 0;
5764 vsi->vlan_filter_on = 0;
5765 /* Allocate queues */
5766 switch (vsi->type) {
5767 case I40E_VSI_MAIN :
5768 vsi->nb_qps = pf->lan_nb_qps;
5770 case I40E_VSI_SRIOV :
5771 vsi->nb_qps = pf->vf_nb_qps;
5773 case I40E_VSI_VMDQ2:
5774 vsi->nb_qps = pf->vmdq_nb_qps;
5777 vsi->nb_qps = pf->fdir_nb_qps;
5783 * The filter status descriptor is reported in rx queue 0,
5784 * while the tx queue for fdir filter programming has no
5785 * such constraints, can be non-zero queues.
5786 * To simplify it, choose FDIR vsi use queue 0 pair.
5787 * To make sure it will use queue 0 pair, queue allocation
5788 * need be done before this function is called
5790 if (type != I40E_VSI_FDIR) {
5791 ret = i40e_res_pool_alloc(&pf->qp_pool, vsi->nb_qps);
5793 PMD_DRV_LOG(ERR, "VSI %d allocate queue failed %d",
5797 vsi->base_queue = ret;
5799 vsi->base_queue = I40E_FDIR_QUEUE_ID;
5801 /* VF has MSIX interrupt in VF range, don't allocate here */
5802 if (type == I40E_VSI_MAIN) {
5803 if (pf->support_multi_driver) {
5804 /* If support multi-driver, need to use INT0 instead of
5805 * allocating from msix pool. The Msix pool is init from
5806 * INT1, so it's OK just set msix_intr to 0 and nb_msix
5807 * to 1 without calling i40e_res_pool_alloc.
5812 ret = i40e_res_pool_alloc(&pf->msix_pool,
5813 RTE_MIN(vsi->nb_qps,
5814 RTE_MAX_RXTX_INTR_VEC_ID));
5817 "VSI MAIN %d get heap failed %d",
5819 goto fail_queue_alloc;
5821 vsi->msix_intr = ret;
5822 vsi->nb_msix = RTE_MIN(vsi->nb_qps,
5823 RTE_MAX_RXTX_INTR_VEC_ID);
5825 } else if (type != I40E_VSI_SRIOV) {
5826 ret = i40e_res_pool_alloc(&pf->msix_pool, 1);
5828 PMD_DRV_LOG(ERR, "VSI %d get heap failed %d", vsi->seid, ret);
5829 if (type != I40E_VSI_FDIR)
5830 goto fail_queue_alloc;
5834 vsi->msix_intr = ret;
5843 if (type == I40E_VSI_MAIN) {
5844 /* For main VSI, no need to add since it's default one */
5845 vsi->uplink_seid = pf->mac_seid;
5846 vsi->seid = pf->main_vsi_seid;
5847 /* Bind queues with specific MSIX interrupt */
5849 * Needs 2 interrupt at least, one for misc cause which will
5850 * enabled from OS side, Another for queues binding the
5851 * interrupt from device side only.
5854 /* Get default VSI parameters from hardware */
5855 memset(&ctxt, 0, sizeof(ctxt));
5856 ctxt.seid = vsi->seid;
5857 ctxt.pf_num = hw->pf_id;
5858 ctxt.uplink_seid = vsi->uplink_seid;
5860 ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5861 if (ret != I40E_SUCCESS) {
5862 PMD_DRV_LOG(ERR, "Failed to get VSI params");
5863 goto fail_msix_alloc;
5865 rte_memcpy(&vsi->info, &ctxt.info,
5866 sizeof(struct i40e_aqc_vsi_properties_data));
5867 vsi->vsi_id = ctxt.vsi_number;
5868 vsi->info.valid_sections = 0;
5870 /* Configure tc, enabled TC0 only */
5871 if (i40e_vsi_update_tc_bandwidth(vsi, I40E_DEFAULT_TCMAP) !=
5873 PMD_DRV_LOG(ERR, "Failed to update TC bandwidth");
5874 goto fail_msix_alloc;
5877 /* TC, queue mapping */
5878 memset(&ctxt, 0, sizeof(ctxt));
5879 vsi->info.valid_sections |=
5880 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5881 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
5882 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
5883 rte_memcpy(&ctxt.info, &vsi->info,
5884 sizeof(struct i40e_aqc_vsi_properties_data));
5885 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
5886 I40E_DEFAULT_TCMAP);
5887 if (ret != I40E_SUCCESS) {
5889 "Failed to configure TC queue mapping");
5890 goto fail_msix_alloc;
5892 ctxt.seid = vsi->seid;
5893 ctxt.pf_num = hw->pf_id;
5894 ctxt.uplink_seid = vsi->uplink_seid;
5897 /* Update VSI parameters */
5898 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5899 if (ret != I40E_SUCCESS) {
5900 PMD_DRV_LOG(ERR, "Failed to update VSI params");
5901 goto fail_msix_alloc;
5904 rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
5905 sizeof(vsi->info.tc_mapping));
5906 rte_memcpy(&vsi->info.queue_mapping,
5907 &ctxt.info.queue_mapping,
5908 sizeof(vsi->info.queue_mapping));
5909 vsi->info.mapping_flags = ctxt.info.mapping_flags;
5910 vsi->info.valid_sections = 0;
5912 rte_memcpy(pf->dev_addr.addr_bytes, hw->mac.perm_addr,
5916 * Updating default filter settings are necessary to prevent
5917 * reception of tagged packets.
5918 * Some old firmware configurations load a default macvlan
5919 * filter which accepts both tagged and untagged packets.
5920 * The updating is to use a normal filter instead if needed.
5921 * For NVM 4.2.2 or after, the updating is not needed anymore.
5922 * The firmware with correct configurations load the default
5923 * macvlan filter which is expected and cannot be removed.
5925 i40e_update_default_filter_setting(vsi);
5926 i40e_config_qinq(hw, vsi);
5927 } else if (type == I40E_VSI_SRIOV) {
5928 memset(&ctxt, 0, sizeof(ctxt));
5930 * For other VSI, the uplink_seid equals to uplink VSI's
5931 * uplink_seid since they share same VEB
5933 if (uplink_vsi == NULL)
5934 vsi->uplink_seid = pf->main_vsi->floating_veb->seid;
5936 vsi->uplink_seid = uplink_vsi->uplink_seid;
5937 ctxt.pf_num = hw->pf_id;
5938 ctxt.vf_num = hw->func_caps.vf_base_id + user_param;
5939 ctxt.uplink_seid = vsi->uplink_seid;
5940 ctxt.connection_type = 0x1;
5941 ctxt.flags = I40E_AQ_VSI_TYPE_VF;
5943 /* Use the VEB configuration if FW >= v5.0 */
5944 if (hw->aq.fw_maj_ver >= 5 || hw->mac.type == I40E_MAC_X722) {
5945 /* Configure switch ID */
5946 ctxt.info.valid_sections |=
5947 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5948 ctxt.info.switch_id =
5949 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5952 /* Configure port/vlan */
5953 ctxt.info.valid_sections |=
5954 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5955 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
5956 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
5957 hw->func_caps.enabled_tcmap);
5958 if (ret != I40E_SUCCESS) {
5960 "Failed to configure TC queue mapping");
5961 goto fail_msix_alloc;
5964 ctxt.info.up_enable_bits = hw->func_caps.enabled_tcmap;
5965 ctxt.info.valid_sections |=
5966 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
5968 * Since VSI is not created yet, only configure parameter,
5969 * will add vsi below.
5972 i40e_config_qinq(hw, vsi);
5973 } else if (type == I40E_VSI_VMDQ2) {
5974 memset(&ctxt, 0, sizeof(ctxt));
5976 * For other VSI, the uplink_seid equals to uplink VSI's
5977 * uplink_seid since they share same VEB
5979 vsi->uplink_seid = uplink_vsi->uplink_seid;
5980 ctxt.pf_num = hw->pf_id;
5982 ctxt.uplink_seid = vsi->uplink_seid;
5983 ctxt.connection_type = 0x1;
5984 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
5986 ctxt.info.valid_sections |=
5987 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5988 /* user_param carries flag to enable loop back */
5990 ctxt.info.switch_id =
5991 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
5992 ctxt.info.switch_id |=
5993 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5996 /* Configure port/vlan */
5997 ctxt.info.valid_sections |=
5998 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5999 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
6000 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
6001 I40E_DEFAULT_TCMAP);
6002 if (ret != I40E_SUCCESS) {
6004 "Failed to configure TC queue mapping");
6005 goto fail_msix_alloc;
6007 ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
6008 ctxt.info.valid_sections |=
6009 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
6010 } else if (type == I40E_VSI_FDIR) {
6011 memset(&ctxt, 0, sizeof(ctxt));
6012 vsi->uplink_seid = uplink_vsi->uplink_seid;
6013 ctxt.pf_num = hw->pf_id;
6015 ctxt.uplink_seid = vsi->uplink_seid;
6016 ctxt.connection_type = 0x1; /* regular data port */
6017 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
6018 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
6019 I40E_DEFAULT_TCMAP);
6020 if (ret != I40E_SUCCESS) {
6022 "Failed to configure TC queue mapping.");
6023 goto fail_msix_alloc;
6025 ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
6026 ctxt.info.valid_sections |=
6027 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
6029 PMD_DRV_LOG(ERR, "VSI: Not support other type VSI yet");
6030 goto fail_msix_alloc;
6033 if (vsi->type != I40E_VSI_MAIN) {
6034 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
6035 if (ret != I40E_SUCCESS) {
6036 PMD_DRV_LOG(ERR, "add vsi failed, aq_err=%d",
6037 hw->aq.asq_last_status);
6038 goto fail_msix_alloc;
6040 memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
6041 vsi->info.valid_sections = 0;
6042 vsi->seid = ctxt.seid;
6043 vsi->vsi_id = ctxt.vsi_number;
6044 vsi->sib_vsi_list.vsi = vsi;
6045 if (vsi->type == I40E_VSI_SRIOV && uplink_vsi == NULL) {
6046 TAILQ_INSERT_TAIL(&pf->main_vsi->floating_veb->head,
6047 &vsi->sib_vsi_list, list);
6049 TAILQ_INSERT_TAIL(&uplink_vsi->veb->head,
6050 &vsi->sib_vsi_list, list);
6054 /* MAC/VLAN configuration */
6055 rte_memcpy(&filter.mac_addr, &broadcast, RTE_ETHER_ADDR_LEN);
6056 filter.filter_type = I40E_MACVLAN_PERFECT_MATCH;
6058 ret = i40e_vsi_add_mac(vsi, &filter);
6059 if (ret != I40E_SUCCESS) {
6060 PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
6061 goto fail_msix_alloc;
6064 /* Get VSI BW information */
6065 i40e_vsi_get_bw_config(vsi);
6068 i40e_res_pool_free(&pf->msix_pool,vsi->msix_intr);
6070 i40e_res_pool_free(&pf->qp_pool,vsi->base_queue);
6076 /* Configure vlan filter on or off */
6078 i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on)
6081 struct i40e_mac_filter *f;
6083 struct i40e_mac_filter_info *mac_filter;
6084 enum i40e_mac_filter_type desired_filter;
6085 int ret = I40E_SUCCESS;
6088 /* Filter to match MAC and VLAN */
6089 desired_filter = I40E_MACVLAN_PERFECT_MATCH;
6091 /* Filter to match only MAC */
6092 desired_filter = I40E_MAC_PERFECT_MATCH;
6097 mac_filter = rte_zmalloc("mac_filter_info_data",
6098 num * sizeof(*mac_filter), 0);
6099 if (mac_filter == NULL) {
6100 PMD_DRV_LOG(ERR, "failed to allocate memory");
6101 return I40E_ERR_NO_MEMORY;
6106 /* Remove all existing mac */
6107 RTE_TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
6108 mac_filter[i] = f->mac_info;
6109 ret = i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
6111 PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
6112 on ? "enable" : "disable");
6118 /* Override with new filter */
6119 for (i = 0; i < num; i++) {
6120 mac_filter[i].filter_type = desired_filter;
6121 ret = i40e_vsi_add_mac(vsi, &mac_filter[i]);
6123 PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
6124 on ? "enable" : "disable");
6130 rte_free(mac_filter);
6134 /* Configure vlan stripping on or off */
6136 i40e_vsi_config_vlan_stripping(struct i40e_vsi *vsi, bool on)
6138 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6139 struct i40e_vsi_context ctxt;
6141 int ret = I40E_SUCCESS;
6143 /* Check if it has been already on or off */
6144 if (vsi->info.valid_sections &
6145 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID)) {
6147 if ((vsi->info.port_vlan_flags &
6148 I40E_AQ_VSI_PVLAN_EMOD_MASK) == 0)
6149 return 0; /* already on */
6151 if ((vsi->info.port_vlan_flags &
6152 I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
6153 I40E_AQ_VSI_PVLAN_EMOD_MASK)
6154 return 0; /* already off */
6159 vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
6161 vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
6162 vsi->info.valid_sections =
6163 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
6164 vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_EMOD_MASK);
6165 vsi->info.port_vlan_flags |= vlan_flags;
6166 ctxt.seid = vsi->seid;
6167 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
6168 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
6170 PMD_DRV_LOG(INFO, "Update VSI failed to %s vlan stripping",
6171 on ? "enable" : "disable");
6177 i40e_dev_init_vlan(struct rte_eth_dev *dev)
6179 struct rte_eth_dev_data *data = dev->data;
6183 /* Apply vlan offload setting */
6184 mask = RTE_ETH_VLAN_STRIP_MASK |
6185 RTE_ETH_QINQ_STRIP_MASK |
6186 RTE_ETH_VLAN_FILTER_MASK |
6187 RTE_ETH_VLAN_EXTEND_MASK;
6188 ret = i40e_vlan_offload_set(dev, mask);
6190 PMD_DRV_LOG(INFO, "Failed to update vlan offload");
6194 /* Apply pvid setting */
6195 ret = i40e_vlan_pvid_set(dev, data->dev_conf.txmode.pvid,
6196 data->dev_conf.txmode.hw_vlan_insert_pvid);
6198 PMD_DRV_LOG(INFO, "Failed to update VSI params");
6204 i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on)
6206 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6208 return i40e_aq_set_port_parameters(hw, vsi->seid, 0, 1, on, NULL);
6212 i40e_update_flow_control(struct i40e_hw *hw)
6214 #define I40E_LINK_PAUSE_RXTX (I40E_AQ_LINK_PAUSE_RX | I40E_AQ_LINK_PAUSE_TX)
6215 struct i40e_link_status link_status;
6216 uint32_t rxfc = 0, txfc = 0, reg;
6220 memset(&link_status, 0, sizeof(link_status));
6221 ret = i40e_aq_get_link_info(hw, FALSE, &link_status, NULL);
6222 if (ret != I40E_SUCCESS) {
6223 PMD_DRV_LOG(ERR, "Failed to get link status information");
6224 goto write_reg; /* Disable flow control */
6227 an_info = hw->phy.link_info.an_info;
6228 if (!(an_info & I40E_AQ_AN_COMPLETED)) {
6229 PMD_DRV_LOG(INFO, "Link auto negotiation not completed");
6230 ret = I40E_ERR_NOT_READY;
6231 goto write_reg; /* Disable flow control */
6234 * If link auto negotiation is enabled, flow control needs to
6235 * be configured according to it
6237 switch (an_info & I40E_LINK_PAUSE_RXTX) {
6238 case I40E_LINK_PAUSE_RXTX:
6241 hw->fc.current_mode = I40E_FC_FULL;
6243 case I40E_AQ_LINK_PAUSE_RX:
6245 hw->fc.current_mode = I40E_FC_RX_PAUSE;
6247 case I40E_AQ_LINK_PAUSE_TX:
6249 hw->fc.current_mode = I40E_FC_TX_PAUSE;
6252 hw->fc.current_mode = I40E_FC_NONE;
6257 I40E_WRITE_REG(hw, I40E_PRTDCB_FCCFG,
6258 txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT);
6259 reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
6260 reg &= ~I40E_PRTDCB_MFLCN_RFCE_MASK;
6261 reg |= rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT;
6262 I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, reg);
6269 i40e_pf_setup(struct i40e_pf *pf)
6271 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6272 struct i40e_filter_control_settings settings;
6273 struct i40e_vsi *vsi;
6276 /* Clear all stats counters */
6277 pf->offset_loaded = FALSE;
6278 memset(&pf->stats, 0, sizeof(struct i40e_hw_port_stats));
6279 memset(&pf->stats_offset, 0, sizeof(struct i40e_hw_port_stats));
6280 memset(&pf->internal_stats, 0, sizeof(struct i40e_eth_stats));
6281 memset(&pf->internal_stats_offset, 0, sizeof(struct i40e_eth_stats));
6283 pf->rx_err1_offset = 0;
6285 ret = i40e_pf_get_switch_config(pf);
6286 if (ret != I40E_SUCCESS) {
6287 PMD_DRV_LOG(ERR, "Could not get switch config, err %d", ret);
6291 ret = rte_eth_switch_domain_alloc(&pf->switch_domain_id);
6293 PMD_INIT_LOG(WARNING,
6294 "failed to allocate switch domain for device %d", ret);
6296 if (pf->flags & I40E_FLAG_FDIR) {
6297 /* make queue allocated first, let FDIR use queue pair 0*/
6298 ret = i40e_res_pool_alloc(&pf->qp_pool, I40E_DEFAULT_QP_NUM_FDIR);
6299 if (ret != I40E_FDIR_QUEUE_ID) {
6301 "queue allocation fails for FDIR: ret =%d",
6303 pf->flags &= ~I40E_FLAG_FDIR;
6306 /* main VSI setup */
6307 vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, NULL, 0);
6309 PMD_DRV_LOG(ERR, "Setup of main vsi failed");
6310 return I40E_ERR_NOT_READY;
6314 /* Configure filter control */
6315 memset(&settings, 0, sizeof(settings));
6316 if (hw->func_caps.rss_table_size == RTE_ETH_RSS_RETA_SIZE_128)
6317 settings.hash_lut_size = I40E_HASH_LUT_SIZE_128;
6318 else if (hw->func_caps.rss_table_size == RTE_ETH_RSS_RETA_SIZE_512)
6319 settings.hash_lut_size = I40E_HASH_LUT_SIZE_512;
6321 PMD_DRV_LOG(ERR, "Hash lookup table size (%u) not supported",
6322 hw->func_caps.rss_table_size);
6323 return I40E_ERR_PARAM;
6325 PMD_DRV_LOG(INFO, "Hardware capability of hash lookup table size: %u",
6326 hw->func_caps.rss_table_size);
6327 pf->hash_lut_size = hw->func_caps.rss_table_size;
6329 /* Enable ethtype and macvlan filters */
6330 settings.enable_ethtype = TRUE;
6331 settings.enable_macvlan = TRUE;
6332 ret = i40e_set_filter_control(hw, &settings);
6334 PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
6337 /* Update flow control according to the auto negotiation */
6338 i40e_update_flow_control(hw);
6340 return I40E_SUCCESS;
6344 i40e_switch_tx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
6350 * Set or clear TX Queue Disable flags,
6351 * which is required by hardware.
6353 i40e_pre_tx_queue_cfg(hw, q_idx, on);
6354 rte_delay_us(I40E_PRE_TX_Q_CFG_WAIT_US);
6356 /* Wait until the request is finished */
6357 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6358 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6359 reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
6360 if (!(((reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 0x1) ^
6361 ((reg >> I40E_QTX_ENA_QENA_STAT_SHIFT)
6367 if (reg & I40E_QTX_ENA_QENA_STAT_MASK)
6368 return I40E_SUCCESS; /* already on, skip next steps */
6370 I40E_WRITE_REG(hw, I40E_QTX_HEAD(q_idx), 0);
6371 reg |= I40E_QTX_ENA_QENA_REQ_MASK;
6373 if (!(reg & I40E_QTX_ENA_QENA_STAT_MASK))
6374 return I40E_SUCCESS; /* already off, skip next steps */
6375 reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
6377 /* Write the register */
6378 I40E_WRITE_REG(hw, I40E_QTX_ENA(q_idx), reg);
6379 /* Check the result */
6380 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6381 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6382 reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
6384 if ((reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
6385 (reg & I40E_QTX_ENA_QENA_STAT_MASK))
6388 if (!(reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
6389 !(reg & I40E_QTX_ENA_QENA_STAT_MASK))
6393 /* Check if it is timeout */
6394 if (j >= I40E_CHK_Q_ENA_COUNT) {
6395 PMD_DRV_LOG(ERR, "Failed to %s tx queue[%u]",
6396 (on ? "enable" : "disable"), q_idx);
6397 return I40E_ERR_TIMEOUT;
6400 return I40E_SUCCESS;
6404 i40e_switch_rx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
6409 /* Wait until the request is finished */
6410 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6411 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6412 reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
6413 if (!((reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 0x1) ^
6414 ((reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 0x1))
6419 if (reg & I40E_QRX_ENA_QENA_STAT_MASK)
6420 return I40E_SUCCESS; /* Already on, skip next steps */
6421 reg |= I40E_QRX_ENA_QENA_REQ_MASK;
6423 if (!(reg & I40E_QRX_ENA_QENA_STAT_MASK))
6424 return I40E_SUCCESS; /* Already off, skip next steps */
6425 reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
6428 /* Write the register */
6429 I40E_WRITE_REG(hw, I40E_QRX_ENA(q_idx), reg);
6430 /* Check the result */
6431 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6432 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6433 reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
6435 if ((reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
6436 (reg & I40E_QRX_ENA_QENA_STAT_MASK))
6439 if (!(reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
6440 !(reg & I40E_QRX_ENA_QENA_STAT_MASK))
6445 /* Check if it is timeout */
6446 if (j >= I40E_CHK_Q_ENA_COUNT) {
6447 PMD_DRV_LOG(ERR, "Failed to %s rx queue[%u]",
6448 (on ? "enable" : "disable"), q_idx);
6449 return I40E_ERR_TIMEOUT;
6452 return I40E_SUCCESS;
6455 /* Initialize VSI for TX */
6457 i40e_dev_tx_init(struct i40e_pf *pf)
6459 struct rte_eth_dev_data *data = pf->dev_data;
6461 uint32_t ret = I40E_SUCCESS;
6462 struct i40e_tx_queue *txq;
6464 for (i = 0; i < data->nb_tx_queues; i++) {
6465 txq = data->tx_queues[i];
6466 if (!txq || !txq->q_set)
6468 ret = i40e_tx_queue_init(txq);
6469 if (ret != I40E_SUCCESS)
6472 if (ret == I40E_SUCCESS)
6473 i40e_set_tx_function(&rte_eth_devices[pf->dev_data->port_id]);
6478 /* Initialize VSI for RX */
6480 i40e_dev_rx_init(struct i40e_pf *pf)
6482 struct rte_eth_dev_data *data = pf->dev_data;
6483 int ret = I40E_SUCCESS;
6485 struct i40e_rx_queue *rxq;
6487 i40e_pf_config_rss(pf);
6488 for (i = 0; i < data->nb_rx_queues; i++) {
6489 rxq = data->rx_queues[i];
6490 if (!rxq || !rxq->q_set)
6493 ret = i40e_rx_queue_init(rxq);
6494 if (ret != I40E_SUCCESS) {
6496 "Failed to do RX queue initialization");
6500 if (ret == I40E_SUCCESS)
6501 i40e_set_rx_function(&rte_eth_devices[pf->dev_data->port_id]);
6507 i40e_dev_rxtx_init(struct i40e_pf *pf)
6511 err = i40e_dev_tx_init(pf);
6513 PMD_DRV_LOG(ERR, "Failed to do TX initialization");
6516 err = i40e_dev_rx_init(pf);
6518 PMD_DRV_LOG(ERR, "Failed to do RX initialization");
6526 i40e_vmdq_setup(struct rte_eth_dev *dev)
6528 struct rte_eth_conf *conf = &dev->data->dev_conf;
6529 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6530 int i, err, conf_vsis, j, loop;
6531 struct i40e_vsi *vsi;
6532 struct i40e_vmdq_info *vmdq_info;
6533 struct rte_eth_vmdq_rx_conf *vmdq_conf;
6534 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6537 * Disable interrupt to avoid message from VF. Furthermore, it will
6538 * avoid race condition in VSI creation/destroy.
6540 i40e_pf_disable_irq0(hw);
6542 if ((pf->flags & I40E_FLAG_VMDQ) == 0) {
6543 PMD_INIT_LOG(ERR, "FW doesn't support VMDQ");
6547 conf_vsis = conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools;
6548 if (conf_vsis > pf->max_nb_vmdq_vsi) {
6549 PMD_INIT_LOG(ERR, "VMDQ config: %u, max support:%u",
6550 conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools,
6551 pf->max_nb_vmdq_vsi);
6555 if (pf->vmdq != NULL) {
6556 PMD_INIT_LOG(INFO, "VMDQ already configured");
6560 pf->vmdq = rte_zmalloc("vmdq_info_struct",
6561 sizeof(*vmdq_info) * conf_vsis, 0);
6563 if (pf->vmdq == NULL) {
6564 PMD_INIT_LOG(ERR, "Failed to allocate memory");
6568 vmdq_conf = &conf->rx_adv_conf.vmdq_rx_conf;
6570 /* Create VMDQ VSI */
6571 for (i = 0; i < conf_vsis; i++) {
6572 vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, pf->main_vsi,
6573 vmdq_conf->enable_loop_back);
6575 PMD_INIT_LOG(ERR, "Failed to create VMDQ VSI");
6579 vmdq_info = &pf->vmdq[i];
6581 vmdq_info->vsi = vsi;
6583 pf->nb_cfg_vmdq_vsi = conf_vsis;
6585 /* Configure Vlan */
6586 loop = sizeof(vmdq_conf->pool_map[0].pools) * CHAR_BIT;
6587 for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
6588 for (j = 0; j < loop && j < pf->nb_cfg_vmdq_vsi; j++) {
6589 if (vmdq_conf->pool_map[i].pools & (1UL << j)) {
6590 PMD_INIT_LOG(INFO, "Add vlan %u to vmdq pool %u",
6591 vmdq_conf->pool_map[i].vlan_id, j);
6593 err = i40e_vsi_add_vlan(pf->vmdq[j].vsi,
6594 vmdq_conf->pool_map[i].vlan_id);
6596 PMD_INIT_LOG(ERR, "Failed to add vlan");
6604 i40e_pf_enable_irq0(hw);
6609 for (i = 0; i < conf_vsis; i++)
6610 if (pf->vmdq[i].vsi == NULL)
6613 i40e_vsi_release(pf->vmdq[i].vsi);
6617 i40e_pf_enable_irq0(hw);
6622 i40e_stat_update_32(struct i40e_hw *hw,
6630 new_data = (uint64_t)I40E_READ_REG(hw, reg);
6634 if (new_data >= *offset)
6635 *stat = (uint64_t)(new_data - *offset);
6637 *stat = (uint64_t)((new_data +
6638 ((uint64_t)1 << I40E_32_BIT_WIDTH)) - *offset);
6642 i40e_stat_update_48(struct i40e_hw *hw,
6651 if (hw->device_id == I40E_DEV_ID_QEMU) {
6652 new_data = (uint64_t)I40E_READ_REG(hw, loreg);
6653 new_data |= ((uint64_t)(I40E_READ_REG(hw, hireg) &
6654 I40E_16_BIT_MASK)) << I40E_32_BIT_WIDTH;
6656 new_data = I40E_READ_REG64(hw, loreg);
6662 if (new_data >= *offset)
6663 *stat = new_data - *offset;
6665 *stat = (uint64_t)((new_data +
6666 ((uint64_t)1 << I40E_48_BIT_WIDTH)) - *offset);
6668 *stat &= I40E_48_BIT_MASK;
6673 i40e_pf_disable_irq0(struct i40e_hw *hw)
6675 /* Disable all interrupt types */
6676 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
6677 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
6678 I40E_WRITE_FLUSH(hw);
6683 i40e_pf_enable_irq0(struct i40e_hw *hw)
6685 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
6686 I40E_PFINT_DYN_CTL0_INTENA_MASK |
6687 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
6688 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
6689 I40E_WRITE_FLUSH(hw);
6693 i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue)
6695 /* read pending request and disable first */
6696 i40e_pf_disable_irq0(hw);
6697 I40E_WRITE_REG(hw, I40E_PFINT_ICR0_ENA, I40E_PFINT_ICR0_ENA_MASK);
6698 I40E_WRITE_REG(hw, I40E_PFINT_STAT_CTL0,
6699 I40E_PFINT_STAT_CTL0_OTHER_ITR_INDX_MASK);
6702 /* Link no queues with irq0 */
6703 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
6704 I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
6708 i40e_dev_handle_vfr_event(struct rte_eth_dev *dev)
6710 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6711 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6714 uint32_t index, offset, val;
6719 * Try to find which VF trigger a reset, use absolute VF id to access
6720 * since the reg is global register.
6722 for (i = 0; i < pf->vf_num; i++) {
6723 abs_vf_id = hw->func_caps.vf_base_id + i;
6724 index = abs_vf_id / I40E_UINT32_BIT_SIZE;
6725 offset = abs_vf_id % I40E_UINT32_BIT_SIZE;
6726 val = I40E_READ_REG(hw, I40E_GLGEN_VFLRSTAT(index));
6727 /* VFR event occurred */
6728 if (val & (0x1 << offset)) {
6731 /* Clear the event first */
6732 I40E_WRITE_REG(hw, I40E_GLGEN_VFLRSTAT(index),
6734 PMD_DRV_LOG(INFO, "VF %u reset occurred", abs_vf_id);
6736 * Only notify a VF reset event occurred,
6737 * don't trigger another SW reset
6739 ret = i40e_pf_host_vf_reset(&pf->vfs[i], 0);
6740 if (ret != I40E_SUCCESS)
6741 PMD_DRV_LOG(ERR, "Failed to do VF reset");
6747 i40e_notify_all_vfs_link_status(struct rte_eth_dev *dev)
6749 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6752 for (i = 0; i < pf->vf_num; i++)
6753 i40e_notify_vf_link_status(dev, &pf->vfs[i]);
6757 i40e_dev_handle_aq_msg(struct rte_eth_dev *dev)
6759 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6760 struct i40e_arq_event_info info;
6761 uint16_t pending, opcode;
6764 info.buf_len = I40E_AQ_BUF_SZ;
6765 info.msg_buf = rte_zmalloc("msg_buffer", info.buf_len, 0);
6766 if (!info.msg_buf) {
6767 PMD_DRV_LOG(ERR, "Failed to allocate mem");
6773 ret = i40e_clean_arq_element(hw, &info, &pending);
6775 if (ret != I40E_SUCCESS) {
6777 "Failed to read msg from AdminQ, aq_err: %u",
6778 hw->aq.asq_last_status);
6781 opcode = rte_le_to_cpu_16(info.desc.opcode);
6784 case i40e_aqc_opc_send_msg_to_pf:
6785 /* Refer to i40e_aq_send_msg_to_pf() for argument layout*/
6786 i40e_pf_host_handle_vf_msg(dev,
6787 rte_le_to_cpu_16(info.desc.retval),
6788 rte_le_to_cpu_32(info.desc.cookie_high),
6789 rte_le_to_cpu_32(info.desc.cookie_low),
6793 case i40e_aqc_opc_get_link_status:
6794 ret = i40e_dev_link_update(dev, 0);
6796 rte_eth_dev_callback_process(dev,
6797 RTE_ETH_EVENT_INTR_LSC, NULL);
6801 PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
6806 rte_free(info.msg_buf);
6810 i40e_handle_mdd_event(struct rte_eth_dev *dev)
6812 #define I40E_MDD_CLEAR32 0xFFFFFFFF
6813 #define I40E_MDD_CLEAR16 0xFFFF
6814 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6815 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6816 bool mdd_detected = false;
6817 struct i40e_pf_vf *vf;
6821 /* find what triggered the MDD event */
6822 reg = I40E_READ_REG(hw, I40E_GL_MDET_TX);
6823 if (reg & I40E_GL_MDET_TX_VALID_MASK) {
6824 uint8_t pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
6825 I40E_GL_MDET_TX_PF_NUM_SHIFT;
6826 uint16_t vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
6827 I40E_GL_MDET_TX_VF_NUM_SHIFT;
6828 uint8_t event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
6829 I40E_GL_MDET_TX_EVENT_SHIFT;
6830 uint16_t queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
6831 I40E_GL_MDET_TX_QUEUE_SHIFT) -
6832 hw->func_caps.base_queue;
6833 PMD_DRV_LOG(WARNING, "Malicious Driver Detection event 0x%02x on TX "
6834 "queue %d PF number 0x%02x VF number 0x%02x device %s\n",
6835 event, queue, pf_num, vf_num, dev->data->name);
6836 I40E_WRITE_REG(hw, I40E_GL_MDET_TX, I40E_MDD_CLEAR32);
6837 mdd_detected = true;
6839 reg = I40E_READ_REG(hw, I40E_GL_MDET_RX);
6840 if (reg & I40E_GL_MDET_RX_VALID_MASK) {
6841 uint8_t func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
6842 I40E_GL_MDET_RX_FUNCTION_SHIFT;
6843 uint8_t event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
6844 I40E_GL_MDET_RX_EVENT_SHIFT;
6845 uint16_t queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
6846 I40E_GL_MDET_RX_QUEUE_SHIFT) -
6847 hw->func_caps.base_queue;
6849 PMD_DRV_LOG(WARNING, "Malicious Driver Detection event 0x%02x on RX "
6850 "queue %d of function 0x%02x device %s\n",
6851 event, queue, func, dev->data->name);
6852 I40E_WRITE_REG(hw, I40E_GL_MDET_RX, I40E_MDD_CLEAR32);
6853 mdd_detected = true;
6857 reg = I40E_READ_REG(hw, I40E_PF_MDET_TX);
6858 if (reg & I40E_PF_MDET_TX_VALID_MASK) {
6859 I40E_WRITE_REG(hw, I40E_PF_MDET_TX, I40E_MDD_CLEAR16);
6860 PMD_DRV_LOG(WARNING, "TX driver issue detected on PF\n");
6862 reg = I40E_READ_REG(hw, I40E_PF_MDET_RX);
6863 if (reg & I40E_PF_MDET_RX_VALID_MASK) {
6864 I40E_WRITE_REG(hw, I40E_PF_MDET_RX,
6866 PMD_DRV_LOG(WARNING, "RX driver issue detected on PF\n");
6870 /* see if one of the VFs needs its hand slapped */
6871 for (i = 0; i < pf->vf_num && mdd_detected; i++) {
6873 reg = I40E_READ_REG(hw, I40E_VP_MDET_TX(i));
6874 if (reg & I40E_VP_MDET_TX_VALID_MASK) {
6875 I40E_WRITE_REG(hw, I40E_VP_MDET_TX(i),
6877 vf->num_mdd_events++;
6878 PMD_DRV_LOG(WARNING, "TX driver issue detected on VF %d %-"
6880 i, vf->num_mdd_events);
6883 reg = I40E_READ_REG(hw, I40E_VP_MDET_RX(i));
6884 if (reg & I40E_VP_MDET_RX_VALID_MASK) {
6885 I40E_WRITE_REG(hw, I40E_VP_MDET_RX(i),
6887 vf->num_mdd_events++;
6888 PMD_DRV_LOG(WARNING, "RX driver issue detected on VF %d %-"
6890 i, vf->num_mdd_events);
6896 * Interrupt handler triggered by NIC for handling
6897 * specific interrupt.
6900 * Pointer to interrupt handle.
6902 * The address of parameter (struct rte_eth_dev *) registered before.
6908 i40e_dev_interrupt_handler(void *param)
6910 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
6911 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6914 /* Disable interrupt */
6915 i40e_pf_disable_irq0(hw);
6917 /* read out interrupt causes */
6918 icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
6920 /* No interrupt event indicated */
6921 if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK)) {
6922 PMD_DRV_LOG(INFO, "No interrupt event");
6925 if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
6926 PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
6927 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
6928 PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
6929 i40e_handle_mdd_event(dev);
6931 if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
6932 PMD_DRV_LOG(INFO, "ICR0: global reset requested");
6933 if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
6934 PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
6935 if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
6936 PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
6937 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
6938 PMD_DRV_LOG(ERR, "ICR0: HMC error");
6939 if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
6940 PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
6942 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
6943 PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
6944 i40e_dev_handle_vfr_event(dev);
6946 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
6947 PMD_DRV_LOG(INFO, "ICR0: adminq event");
6948 i40e_dev_handle_aq_msg(dev);
6952 /* Enable interrupt */
6953 i40e_pf_enable_irq0(hw);
6957 i40e_dev_alarm_handler(void *param)
6959 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
6960 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6963 /* Disable interrupt */
6964 i40e_pf_disable_irq0(hw);
6966 /* read out interrupt causes */
6967 icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
6969 /* No interrupt event indicated */
6970 if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK))
6972 if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
6973 PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
6974 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
6975 PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
6976 i40e_handle_mdd_event(dev);
6978 if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
6979 PMD_DRV_LOG(INFO, "ICR0: global reset requested");
6980 if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
6981 PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
6982 if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
6983 PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
6984 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
6985 PMD_DRV_LOG(ERR, "ICR0: HMC error");
6986 if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
6987 PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
6989 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
6990 PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
6991 i40e_dev_handle_vfr_event(dev);
6993 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
6994 PMD_DRV_LOG(INFO, "ICR0: adminq event");
6995 i40e_dev_handle_aq_msg(dev);
6999 /* Enable interrupt */
7000 i40e_pf_enable_irq0(hw);
7001 rte_eal_alarm_set(I40E_ALARM_INTERVAL,
7002 i40e_dev_alarm_handler, dev);
7006 i40e_add_macvlan_filters(struct i40e_vsi *vsi,
7007 struct i40e_macvlan_filter *filter,
7010 int ele_num, ele_buff_size;
7011 int num, actual_num, i;
7013 int ret = I40E_SUCCESS;
7014 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7015 struct i40e_aqc_add_macvlan_element_data *req_list;
7017 if (filter == NULL || total == 0)
7018 return I40E_ERR_PARAM;
7019 ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
7020 ele_buff_size = hw->aq.asq_buf_size;
7022 req_list = rte_zmalloc("macvlan_add", ele_buff_size, 0);
7023 if (req_list == NULL) {
7024 PMD_DRV_LOG(ERR, "Fail to allocate memory");
7025 return I40E_ERR_NO_MEMORY;
7030 actual_num = (num + ele_num > total) ? (total - num) : ele_num;
7031 memset(req_list, 0, ele_buff_size);
7033 for (i = 0; i < actual_num; i++) {
7034 rte_memcpy(req_list[i].mac_addr,
7035 &filter[num + i].macaddr, ETH_ADDR_LEN);
7036 req_list[i].vlan_tag =
7037 rte_cpu_to_le_16(filter[num + i].vlan_id);
7039 switch (filter[num + i].filter_type) {
7040 case I40E_MAC_PERFECT_MATCH:
7041 flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH |
7042 I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
7044 case I40E_MACVLAN_PERFECT_MATCH:
7045 flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
7047 case I40E_MAC_HASH_MATCH:
7048 flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH |
7049 I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
7051 case I40E_MACVLAN_HASH_MATCH:
7052 flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH;
7055 PMD_DRV_LOG(ERR, "Invalid MAC match type");
7056 ret = I40E_ERR_PARAM;
7060 req_list[i].queue_number = 0;
7062 req_list[i].flags = rte_cpu_to_le_16(flags);
7065 ret = i40e_aq_add_macvlan(hw, vsi->seid, req_list,
7067 if (ret != I40E_SUCCESS) {
7068 PMD_DRV_LOG(ERR, "Failed to add macvlan filter");
7072 } while (num < total);
7080 i40e_remove_macvlan_filters(struct i40e_vsi *vsi,
7081 struct i40e_macvlan_filter *filter,
7084 int ele_num, ele_buff_size;
7085 int num, actual_num, i;
7087 int ret = I40E_SUCCESS;
7088 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7089 struct i40e_aqc_remove_macvlan_element_data *req_list;
7090 enum i40e_admin_queue_err aq_status;
7092 if (filter == NULL || total == 0)
7093 return I40E_ERR_PARAM;
7095 ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
7096 ele_buff_size = hw->aq.asq_buf_size;
7098 req_list = rte_zmalloc("macvlan_remove", ele_buff_size, 0);
7099 if (req_list == NULL) {
7100 PMD_DRV_LOG(ERR, "Fail to allocate memory");
7101 return I40E_ERR_NO_MEMORY;
7106 actual_num = (num + ele_num > total) ? (total - num) : ele_num;
7107 memset(req_list, 0, ele_buff_size);
7109 for (i = 0; i < actual_num; i++) {
7110 rte_memcpy(req_list[i].mac_addr,
7111 &filter[num + i].macaddr, ETH_ADDR_LEN);
7112 req_list[i].vlan_tag =
7113 rte_cpu_to_le_16(filter[num + i].vlan_id);
7115 switch (filter[num + i].filter_type) {
7116 case I40E_MAC_PERFECT_MATCH:
7117 flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
7118 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
7120 case I40E_MACVLAN_PERFECT_MATCH:
7121 flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
7123 case I40E_MAC_HASH_MATCH:
7124 flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH |
7125 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
7127 case I40E_MACVLAN_HASH_MATCH:
7128 flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH;
7131 PMD_DRV_LOG(ERR, "Invalid MAC filter type");
7132 ret = I40E_ERR_PARAM;
7135 req_list[i].flags = rte_cpu_to_le_16(flags);
7138 ret = i40e_aq_remove_macvlan_v2(hw, vsi->seid, req_list,
7139 actual_num, NULL, &aq_status);
7141 if (ret != I40E_SUCCESS) {
7142 /* Do not report as an error when firmware returns ENOENT */
7143 if (aq_status == I40E_AQ_RC_ENOENT) {
7146 PMD_DRV_LOG(ERR, "Failed to remove macvlan filter");
7151 } while (num < total);
7158 /* Find out specific MAC filter */
7159 static struct i40e_mac_filter *
7160 i40e_find_mac_filter(struct i40e_vsi *vsi,
7161 struct rte_ether_addr *macaddr)
7163 struct i40e_mac_filter *f;
7165 TAILQ_FOREACH(f, &vsi->mac_list, next) {
7166 if (rte_is_same_ether_addr(macaddr, &f->mac_info.mac_addr))
7174 i40e_find_vlan_filter(struct i40e_vsi *vsi,
7177 uint32_t vid_idx, vid_bit;
7179 if (vlan_id > RTE_ETH_VLAN_ID_MAX)
7182 vid_idx = I40E_VFTA_IDX(vlan_id);
7183 vid_bit = I40E_VFTA_BIT(vlan_id);
7185 if (vsi->vfta[vid_idx] & vid_bit)
7192 i40e_store_vlan_filter(struct i40e_vsi *vsi,
7193 uint16_t vlan_id, bool on)
7195 uint32_t vid_idx, vid_bit;
7197 vid_idx = I40E_VFTA_IDX(vlan_id);
7198 vid_bit = I40E_VFTA_BIT(vlan_id);
7201 vsi->vfta[vid_idx] |= vid_bit;
7203 vsi->vfta[vid_idx] &= ~vid_bit;
7207 i40e_set_vlan_filter(struct i40e_vsi *vsi,
7208 uint16_t vlan_id, bool on)
7210 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7211 struct i40e_aqc_add_remove_vlan_element_data vlan_data = {0};
7214 if (vlan_id > RTE_ETH_VLAN_ID_MAX)
7217 i40e_store_vlan_filter(vsi, vlan_id, on);
7219 if ((!vsi->vlan_anti_spoof_on && !vsi->vlan_filter_on) || !vlan_id)
7222 vlan_data.vlan_tag = rte_cpu_to_le_16(vlan_id);
7225 ret = i40e_aq_add_vlan(hw, vsi->seid,
7226 &vlan_data, 1, NULL);
7227 if (ret != I40E_SUCCESS)
7228 PMD_DRV_LOG(ERR, "Failed to add vlan filter");
7230 ret = i40e_aq_remove_vlan(hw, vsi->seid,
7231 &vlan_data, 1, NULL);
7232 if (ret != I40E_SUCCESS)
7234 "Failed to remove vlan filter");
7239 * Find all vlan options for specific mac addr,
7240 * return with actual vlan found.
7243 i40e_find_all_vlan_for_mac(struct i40e_vsi *vsi,
7244 struct i40e_macvlan_filter *mv_f,
7245 int num, struct rte_ether_addr *addr)
7251 * Not to use i40e_find_vlan_filter to decrease the loop time,
7252 * although the code looks complex.
7254 if (num < vsi->vlan_num)
7255 return I40E_ERR_PARAM;
7258 for (j = 0; j < I40E_VFTA_SIZE; j++) {
7260 for (k = 0; k < I40E_UINT32_BIT_SIZE; k++) {
7261 if (vsi->vfta[j] & (1 << k)) {
7264 "vlan number doesn't match");
7265 return I40E_ERR_PARAM;
7267 rte_memcpy(&mv_f[i].macaddr,
7268 addr, ETH_ADDR_LEN);
7270 j * I40E_UINT32_BIT_SIZE + k;
7276 return I40E_SUCCESS;
7280 i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
7281 struct i40e_macvlan_filter *mv_f,
7286 struct i40e_mac_filter *f;
7288 if (num < vsi->mac_num)
7289 return I40E_ERR_PARAM;
7291 TAILQ_FOREACH(f, &vsi->mac_list, next) {
7293 PMD_DRV_LOG(ERR, "buffer number not match");
7294 return I40E_ERR_PARAM;
7296 rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
7298 mv_f[i].vlan_id = vlan;
7299 mv_f[i].filter_type = f->mac_info.filter_type;
7303 return I40E_SUCCESS;
7307 i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi)
7310 struct i40e_mac_filter *f;
7311 struct i40e_macvlan_filter *mv_f;
7312 int ret = I40E_SUCCESS;
7314 if (vsi == NULL || vsi->mac_num == 0)
7315 return I40E_ERR_PARAM;
7317 /* Case that no vlan is set */
7318 if (vsi->vlan_num == 0)
7321 num = vsi->mac_num * vsi->vlan_num;
7323 mv_f = rte_zmalloc("macvlan_data", num * sizeof(*mv_f), 0);
7325 PMD_DRV_LOG(ERR, "failed to allocate memory");
7326 return I40E_ERR_NO_MEMORY;
7330 if (vsi->vlan_num == 0) {
7331 TAILQ_FOREACH(f, &vsi->mac_list, next) {
7332 rte_memcpy(&mv_f[i].macaddr,
7333 &f->mac_info.mac_addr, ETH_ADDR_LEN);
7334 mv_f[i].filter_type = f->mac_info.filter_type;
7335 mv_f[i].vlan_id = 0;
7339 TAILQ_FOREACH(f, &vsi->mac_list, next) {
7340 ret = i40e_find_all_vlan_for_mac(vsi,&mv_f[i],
7341 vsi->vlan_num, &f->mac_info.mac_addr);
7342 if (ret != I40E_SUCCESS)
7344 for (j = i; j < i + vsi->vlan_num; j++)
7345 mv_f[j].filter_type = f->mac_info.filter_type;
7350 ret = i40e_remove_macvlan_filters(vsi, mv_f, num);
7358 i40e_vsi_add_vlan(struct i40e_vsi *vsi, uint16_t vlan)
7360 struct i40e_macvlan_filter *mv_f;
7362 int ret = I40E_SUCCESS;
7364 if (!vsi || vlan > RTE_ETHER_MAX_VLAN_ID)
7365 return I40E_ERR_PARAM;
7367 /* If it's already set, just return */
7368 if (i40e_find_vlan_filter(vsi,vlan))
7369 return I40E_SUCCESS;
7371 mac_num = vsi->mac_num;
7374 PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
7375 return I40E_ERR_PARAM;
7378 mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
7381 PMD_DRV_LOG(ERR, "failed to allocate memory");
7382 return I40E_ERR_NO_MEMORY;
7385 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
7387 if (ret != I40E_SUCCESS)
7390 ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
7392 if (ret != I40E_SUCCESS)
7395 i40e_set_vlan_filter(vsi, vlan, 1);
7405 i40e_vsi_delete_vlan(struct i40e_vsi *vsi, uint16_t vlan)
7407 struct i40e_macvlan_filter *mv_f;
7409 int ret = I40E_SUCCESS;
7412 * Vlan 0 is the generic filter for untagged packets
7413 * and can't be removed.
7415 if (!vsi || vlan == 0 || vlan > RTE_ETHER_MAX_VLAN_ID)
7416 return I40E_ERR_PARAM;
7418 /* If can't find it, just return */
7419 if (!i40e_find_vlan_filter(vsi, vlan))
7420 return I40E_ERR_PARAM;
7422 mac_num = vsi->mac_num;
7425 PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
7426 return I40E_ERR_PARAM;
7429 mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
7432 PMD_DRV_LOG(ERR, "failed to allocate memory");
7433 return I40E_ERR_NO_MEMORY;
7436 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
7438 if (ret != I40E_SUCCESS)
7441 ret = i40e_remove_macvlan_filters(vsi, mv_f, mac_num);
7443 if (ret != I40E_SUCCESS)
7446 /* This is last vlan to remove, replace all mac filter with vlan 0 */
7447 if (vsi->vlan_num == 1) {
7448 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, 0);
7449 if (ret != I40E_SUCCESS)
7452 ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
7453 if (ret != I40E_SUCCESS)
7457 i40e_set_vlan_filter(vsi, vlan, 0);
7467 i40e_vsi_add_mac(struct i40e_vsi *vsi, struct i40e_mac_filter_info *mac_filter)
7469 struct i40e_mac_filter *f;
7470 struct i40e_macvlan_filter *mv_f;
7471 int i, vlan_num = 0;
7472 int ret = I40E_SUCCESS;
7474 /* If it's add and we've config it, return */
7475 f = i40e_find_mac_filter(vsi, &mac_filter->mac_addr);
7477 return I40E_SUCCESS;
7478 if (mac_filter->filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7479 mac_filter->filter_type == I40E_MACVLAN_HASH_MATCH) {
7482 * If vlan_num is 0, that's the first time to add mac,
7483 * set mask for vlan_id 0.
7485 if (vsi->vlan_num == 0) {
7486 i40e_set_vlan_filter(vsi, 0, 1);
7489 vlan_num = vsi->vlan_num;
7490 } else if (mac_filter->filter_type == I40E_MAC_PERFECT_MATCH ||
7491 mac_filter->filter_type == I40E_MAC_HASH_MATCH)
7494 mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
7496 PMD_DRV_LOG(ERR, "failed to allocate memory");
7497 return I40E_ERR_NO_MEMORY;
7500 for (i = 0; i < vlan_num; i++) {
7501 mv_f[i].filter_type = mac_filter->filter_type;
7502 rte_memcpy(&mv_f[i].macaddr, &mac_filter->mac_addr,
7506 if (mac_filter->filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7507 mac_filter->filter_type == I40E_MACVLAN_HASH_MATCH) {
7508 ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
7509 &mac_filter->mac_addr);
7510 if (ret != I40E_SUCCESS)
7514 ret = i40e_add_macvlan_filters(vsi, mv_f, vlan_num);
7515 if (ret != I40E_SUCCESS)
7518 /* Add the mac addr into mac list */
7519 f = rte_zmalloc("macv_filter", sizeof(*f), 0);
7521 PMD_DRV_LOG(ERR, "failed to allocate memory");
7522 ret = I40E_ERR_NO_MEMORY;
7525 rte_memcpy(&f->mac_info.mac_addr, &mac_filter->mac_addr,
7527 f->mac_info.filter_type = mac_filter->filter_type;
7528 TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
7539 i40e_vsi_delete_mac(struct i40e_vsi *vsi, struct rte_ether_addr *addr)
7541 struct i40e_mac_filter *f;
7542 struct i40e_macvlan_filter *mv_f;
7544 enum i40e_mac_filter_type filter_type;
7545 int ret = I40E_SUCCESS;
7547 /* Can't find it, return an error */
7548 f = i40e_find_mac_filter(vsi, addr);
7550 return I40E_ERR_PARAM;
7552 vlan_num = vsi->vlan_num;
7553 filter_type = f->mac_info.filter_type;
7554 if (filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7555 filter_type == I40E_MACVLAN_HASH_MATCH) {
7556 if (vlan_num == 0) {
7557 PMD_DRV_LOG(ERR, "VLAN number shouldn't be 0");
7558 return I40E_ERR_PARAM;
7560 } else if (filter_type == I40E_MAC_PERFECT_MATCH ||
7561 filter_type == I40E_MAC_HASH_MATCH)
7564 mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
7566 PMD_DRV_LOG(ERR, "failed to allocate memory");
7567 return I40E_ERR_NO_MEMORY;
7570 for (i = 0; i < vlan_num; i++) {
7571 mv_f[i].filter_type = filter_type;
7572 rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
7575 if (filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7576 filter_type == I40E_MACVLAN_HASH_MATCH) {
7577 ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num, addr);
7578 if (ret != I40E_SUCCESS)
7582 ret = i40e_remove_macvlan_filters(vsi, mv_f, vlan_num);
7583 if (ret != I40E_SUCCESS)
7586 /* Remove the mac addr into mac list */
7587 TAILQ_REMOVE(&vsi->mac_list, f, next);
7597 /* Configure hash enable flags for RSS */
7599 i40e_config_hena(const struct i40e_adapter *adapter, uint64_t flags)
7607 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < I40E_FLOW_TYPE_MAX; i++) {
7608 if (flags & (1ULL << i))
7609 hena |= adapter->pctypes_tbl[i];
7615 /* Parse the hash enable flags */
7617 i40e_parse_hena(const struct i40e_adapter *adapter, uint64_t flags)
7619 uint64_t rss_hf = 0;
7625 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < I40E_FLOW_TYPE_MAX; i++) {
7626 if (flags & adapter->pctypes_tbl[i])
7627 rss_hf |= (1ULL << i);
7634 i40e_pf_disable_rss(struct i40e_pf *pf)
7636 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7638 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
7639 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
7640 I40E_WRITE_FLUSH(hw);
7644 i40e_set_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t key_len)
7646 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
7647 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7648 uint16_t key_idx = (vsi->type == I40E_VSI_SRIOV) ?
7649 I40E_VFQF_HKEY_MAX_INDEX :
7650 I40E_PFQF_HKEY_MAX_INDEX;
7652 if (!key || key_len == 0) {
7653 PMD_DRV_LOG(DEBUG, "No key to be configured");
7655 } else if (key_len != (key_idx + 1) *
7657 PMD_DRV_LOG(ERR, "Invalid key length %u", key_len);
7661 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
7662 struct i40e_aqc_get_set_rss_key_data *key_dw =
7663 (struct i40e_aqc_get_set_rss_key_data *)key;
7664 enum i40e_status_code status =
7665 i40e_aq_set_rss_key(hw, vsi->vsi_id, key_dw);
7669 "Failed to configure RSS key via AQ, error status: %d",
7674 uint32_t *hash_key = (uint32_t *)key;
7677 if (vsi->type == I40E_VSI_SRIOV) {
7678 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
7681 I40E_VFQF_HKEY1(i, vsi->user_param),
7685 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
7686 I40E_WRITE_REG(hw, I40E_PFQF_HKEY(i),
7689 I40E_WRITE_FLUSH(hw);
7696 i40e_get_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t *key_len)
7698 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
7699 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7703 if (!key || !key_len)
7706 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
7707 ret = i40e_aq_get_rss_key(hw, vsi->vsi_id,
7708 (struct i40e_aqc_get_set_rss_key_data *)key);
7710 PMD_INIT_LOG(ERR, "Failed to get RSS key via AQ");
7714 uint32_t *key_dw = (uint32_t *)key;
7717 if (vsi->type == I40E_VSI_SRIOV) {
7718 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++) {
7719 reg = I40E_VFQF_HKEY1(i, vsi->user_param);
7720 key_dw[i] = i40e_read_rx_ctl(hw, reg);
7722 *key_len = (I40E_VFQF_HKEY_MAX_INDEX + 1) *
7725 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
7726 reg = I40E_PFQF_HKEY(i);
7727 key_dw[i] = i40e_read_rx_ctl(hw, reg);
7729 *key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
7737 i40e_hw_rss_hash_set(struct i40e_pf *pf, struct rte_eth_rss_conf *rss_conf)
7739 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7743 ret = i40e_set_rss_key(pf->main_vsi, rss_conf->rss_key,
7744 rss_conf->rss_key_len);
7748 hena = i40e_config_hena(pf->adapter, rss_conf->rss_hf);
7749 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
7750 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
7751 I40E_WRITE_FLUSH(hw);
7757 i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
7758 struct rte_eth_rss_conf *rss_conf)
7760 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7761 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7762 uint64_t rss_hf = rss_conf->rss_hf & pf->adapter->flow_types_mask;
7765 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
7766 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
7768 if (!(hena & pf->adapter->pctypes_mask)) { /* RSS disabled */
7769 if (rss_hf != 0) /* Enable RSS */
7771 return 0; /* Nothing to do */
7774 if (rss_hf == 0) /* Disable RSS */
7777 return i40e_hw_rss_hash_set(pf, rss_conf);
7781 i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
7782 struct rte_eth_rss_conf *rss_conf)
7784 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7785 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7792 ret = i40e_get_rss_key(pf->main_vsi, rss_conf->rss_key,
7793 &rss_conf->rss_key_len);
7797 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
7798 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
7799 rss_conf->rss_hf = i40e_parse_hena(pf->adapter, hena);
7805 i40e_dev_get_filter_type(uint16_t filter_type, uint16_t *flag)
7807 switch (filter_type) {
7808 case RTE_ETH_TUNNEL_FILTER_IMAC_IVLAN:
7809 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
7811 case RTE_ETH_TUNNEL_FILTER_IMAC_IVLAN_TENID:
7812 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
7814 case RTE_ETH_TUNNEL_FILTER_IMAC_TENID:
7815 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID;
7817 case RTE_ETH_TUNNEL_FILTER_OMAC_TENID_IMAC:
7818 *flag = I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC;
7820 case RTE_ETH_TUNNEL_FILTER_IMAC:
7821 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
7823 case RTE_ETH_TUNNEL_FILTER_OIP:
7824 *flag = I40E_AQC_ADD_CLOUD_FILTER_OIP;
7826 case RTE_ETH_TUNNEL_FILTER_IIP:
7827 *flag = I40E_AQC_ADD_CLOUD_FILTER_IIP;
7830 PMD_DRV_LOG(ERR, "invalid tunnel filter type");
7837 /* Convert tunnel filter structure */
7839 i40e_tunnel_filter_convert(
7840 struct i40e_aqc_cloud_filters_element_bb *cld_filter,
7841 struct i40e_tunnel_filter *tunnel_filter)
7843 rte_ether_addr_copy((struct rte_ether_addr *)
7844 &cld_filter->element.outer_mac,
7845 (struct rte_ether_addr *)&tunnel_filter->input.outer_mac);
7846 rte_ether_addr_copy((struct rte_ether_addr *)
7847 &cld_filter->element.inner_mac,
7848 (struct rte_ether_addr *)&tunnel_filter->input.inner_mac);
7849 tunnel_filter->input.inner_vlan = cld_filter->element.inner_vlan;
7850 if ((rte_le_to_cpu_16(cld_filter->element.flags) &
7851 I40E_AQC_ADD_CLOUD_FLAGS_IPV6) ==
7852 I40E_AQC_ADD_CLOUD_FLAGS_IPV6)
7853 tunnel_filter->input.ip_type = I40E_TUNNEL_IPTYPE_IPV6;
7855 tunnel_filter->input.ip_type = I40E_TUNNEL_IPTYPE_IPV4;
7856 tunnel_filter->input.flags = cld_filter->element.flags;
7857 tunnel_filter->input.tenant_id = cld_filter->element.tenant_id;
7858 tunnel_filter->queue = cld_filter->element.queue_number;
7859 rte_memcpy(tunnel_filter->input.general_fields,
7860 cld_filter->general_fields,
7861 sizeof(cld_filter->general_fields));
7866 /* Check if there exists the tunnel filter */
7867 struct i40e_tunnel_filter *
7868 i40e_sw_tunnel_filter_lookup(struct i40e_tunnel_rule *tunnel_rule,
7869 const struct i40e_tunnel_filter_input *input)
7873 ret = rte_hash_lookup(tunnel_rule->hash_table, (const void *)input);
7877 return tunnel_rule->hash_map[ret];
7880 /* Add a tunnel filter into the SW list */
7882 i40e_sw_tunnel_filter_insert(struct i40e_pf *pf,
7883 struct i40e_tunnel_filter *tunnel_filter)
7885 struct i40e_tunnel_rule *rule = &pf->tunnel;
7888 ret = rte_hash_add_key(rule->hash_table, &tunnel_filter->input);
7891 "Failed to insert tunnel filter to hash table %d!",
7895 rule->hash_map[ret] = tunnel_filter;
7897 TAILQ_INSERT_TAIL(&rule->tunnel_list, tunnel_filter, rules);
7902 /* Delete a tunnel filter from the SW list */
7904 i40e_sw_tunnel_filter_del(struct i40e_pf *pf,
7905 struct i40e_tunnel_filter_input *input)
7907 struct i40e_tunnel_rule *rule = &pf->tunnel;
7908 struct i40e_tunnel_filter *tunnel_filter;
7911 ret = rte_hash_del_key(rule->hash_table, input);
7914 "Failed to delete tunnel filter to hash table %d!",
7918 tunnel_filter = rule->hash_map[ret];
7919 rule->hash_map[ret] = NULL;
7921 TAILQ_REMOVE(&rule->tunnel_list, tunnel_filter, rules);
7922 rte_free(tunnel_filter);
7927 #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_TR_WORD0 0x48
7928 #define I40E_TR_VXLAN_GRE_KEY_MASK 0x4
7929 #define I40E_TR_GENEVE_KEY_MASK 0x8
7930 #define I40E_TR_GENERIC_UDP_TUNNEL_MASK 0x40
7931 #define I40E_TR_GRE_KEY_MASK 0x400
7932 #define I40E_TR_GRE_KEY_WITH_XSUM_MASK 0x800
7933 #define I40E_TR_GRE_NO_KEY_MASK 0x8000
7934 #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_PORT_TR_WORD0 0x49
7935 #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_DIRECTION_WORD0 0x41
7936 #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_INGRESS_WORD0 0x80
7937 #define I40E_DIRECTION_INGRESS_KEY 0x8000
7938 #define I40E_TR_L4_TYPE_TCP 0x2
7939 #define I40E_TR_L4_TYPE_UDP 0x4
7940 #define I40E_TR_L4_TYPE_SCTP 0x8
7943 i40e_status_code i40e_replace_mpls_l1_filter(struct i40e_pf *pf)
7945 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
7946 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
7947 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7948 struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
7949 enum i40e_status_code status = I40E_SUCCESS;
7951 if (pf->support_multi_driver) {
7952 PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
7953 return I40E_NOT_SUPPORTED;
7956 memset(&filter_replace, 0,
7957 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
7958 memset(&filter_replace_buf, 0,
7959 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
7961 /* create L1 filter */
7962 filter_replace.old_filter_type =
7963 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_IMAC;
7964 filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X11;
7965 filter_replace.tr_bit = 0;
7967 /* Prepare the buffer, 3 entries */
7968 filter_replace_buf.data[0] =
7969 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
7970 filter_replace_buf.data[0] |=
7971 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7972 filter_replace_buf.data[2] = 0xFF;
7973 filter_replace_buf.data[3] = 0xFF;
7974 filter_replace_buf.data[4] =
7975 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
7976 filter_replace_buf.data[4] |=
7977 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7978 filter_replace_buf.data[7] = 0xF0;
7979 filter_replace_buf.data[8]
7980 = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_TR_WORD0;
7981 filter_replace_buf.data[8] |=
7982 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7983 filter_replace_buf.data[10] = I40E_TR_VXLAN_GRE_KEY_MASK |
7984 I40E_TR_GENEVE_KEY_MASK |
7985 I40E_TR_GENERIC_UDP_TUNNEL_MASK;
7986 filter_replace_buf.data[11] = (I40E_TR_GRE_KEY_MASK |
7987 I40E_TR_GRE_KEY_WITH_XSUM_MASK |
7988 I40E_TR_GRE_NO_KEY_MASK) >> 8;
7990 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
7991 &filter_replace_buf);
7992 if (!status && (filter_replace.old_filter_type !=
7993 filter_replace.new_filter_type))
7994 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
7995 " original: 0x%x, new: 0x%x",
7997 filter_replace.old_filter_type,
7998 filter_replace.new_filter_type);
8004 i40e_status_code i40e_replace_mpls_cloud_filter(struct i40e_pf *pf)
8006 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8007 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8008 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8009 struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8010 enum i40e_status_code status = I40E_SUCCESS;
8012 if (pf->support_multi_driver) {
8013 PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8014 return I40E_NOT_SUPPORTED;
8018 memset(&filter_replace, 0,
8019 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8020 memset(&filter_replace_buf, 0,
8021 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8022 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER |
8023 I40E_AQC_MIRROR_CLOUD_FILTER;
8024 filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IIP;
8025 filter_replace.new_filter_type =
8026 I40E_AQC_ADD_CLOUD_FILTER_0X11;
8027 /* Prepare the buffer, 2 entries */
8028 filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8029 filter_replace_buf.data[0] |=
8030 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8031 filter_replace_buf.data[4] = I40E_AQC_ADD_L1_FILTER_0X11;
8032 filter_replace_buf.data[4] |=
8033 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8034 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8035 &filter_replace_buf);
8038 if (filter_replace.old_filter_type !=
8039 filter_replace.new_filter_type)
8040 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8041 " original: 0x%x, new: 0x%x",
8043 filter_replace.old_filter_type,
8044 filter_replace.new_filter_type);
8047 memset(&filter_replace, 0,
8048 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8049 memset(&filter_replace_buf, 0,
8050 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8052 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER |
8053 I40E_AQC_MIRROR_CLOUD_FILTER;
8054 filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
8055 filter_replace.new_filter_type =
8056 I40E_AQC_ADD_CLOUD_FILTER_0X12;
8057 /* Prepare the buffer, 2 entries */
8058 filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8059 filter_replace_buf.data[0] |=
8060 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8061 filter_replace_buf.data[4] = I40E_AQC_ADD_L1_FILTER_0X11;
8062 filter_replace_buf.data[4] |=
8063 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8065 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8066 &filter_replace_buf);
8067 if (!status && (filter_replace.old_filter_type !=
8068 filter_replace.new_filter_type))
8069 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8070 " original: 0x%x, new: 0x%x",
8072 filter_replace.old_filter_type,
8073 filter_replace.new_filter_type);
8078 static enum i40e_status_code
8079 i40e_replace_gtp_l1_filter(struct i40e_pf *pf)
8081 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8082 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8083 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8084 struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8085 enum i40e_status_code status = I40E_SUCCESS;
8087 if (pf->support_multi_driver) {
8088 PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
8089 return I40E_NOT_SUPPORTED;
8093 memset(&filter_replace, 0,
8094 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8095 memset(&filter_replace_buf, 0,
8096 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8097 /* create L1 filter */
8098 filter_replace.old_filter_type =
8099 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_IMAC;
8100 filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X12;
8101 filter_replace.tr_bit = I40E_AQC_NEW_TR_22 |
8102 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8103 /* Prepare the buffer, 2 entries */
8104 filter_replace_buf.data[0] =
8105 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8106 filter_replace_buf.data[0] |=
8107 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8108 filter_replace_buf.data[2] = 0xFF;
8109 filter_replace_buf.data[3] = 0xFF;
8110 filter_replace_buf.data[4] =
8111 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8112 filter_replace_buf.data[4] |=
8113 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8114 filter_replace_buf.data[6] = 0xFF;
8115 filter_replace_buf.data[7] = 0xFF;
8116 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8117 &filter_replace_buf);
8120 if (filter_replace.old_filter_type !=
8121 filter_replace.new_filter_type)
8122 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8123 " original: 0x%x, new: 0x%x",
8125 filter_replace.old_filter_type,
8126 filter_replace.new_filter_type);
8129 memset(&filter_replace, 0,
8130 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8131 memset(&filter_replace_buf, 0,
8132 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8133 /* create L1 filter */
8134 filter_replace.old_filter_type =
8135 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TUNNLE_KEY;
8136 filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X13;
8137 filter_replace.tr_bit = I40E_AQC_NEW_TR_21 |
8138 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8139 /* Prepare the buffer, 2 entries */
8140 filter_replace_buf.data[0] =
8141 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8142 filter_replace_buf.data[0] |=
8143 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8144 filter_replace_buf.data[2] = 0xFF;
8145 filter_replace_buf.data[3] = 0xFF;
8146 filter_replace_buf.data[4] =
8147 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8148 filter_replace_buf.data[4] |=
8149 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8150 filter_replace_buf.data[6] = 0xFF;
8151 filter_replace_buf.data[7] = 0xFF;
8153 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8154 &filter_replace_buf);
8155 if (!status && (filter_replace.old_filter_type !=
8156 filter_replace.new_filter_type))
8157 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8158 " original: 0x%x, new: 0x%x",
8160 filter_replace.old_filter_type,
8161 filter_replace.new_filter_type);
8167 i40e_status_code i40e_replace_gtp_cloud_filter(struct i40e_pf *pf)
8169 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8170 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8171 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8172 struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8173 enum i40e_status_code status = I40E_SUCCESS;
8175 if (pf->support_multi_driver) {
8176 PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8177 return I40E_NOT_SUPPORTED;
8181 memset(&filter_replace, 0,
8182 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8183 memset(&filter_replace_buf, 0,
8184 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8185 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8186 filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
8187 filter_replace.new_filter_type =
8188 I40E_AQC_ADD_CLOUD_FILTER_0X11;
8189 /* Prepare the buffer, 2 entries */
8190 filter_replace_buf.data[0] = I40E_AQC_ADD_L1_FILTER_0X12;
8191 filter_replace_buf.data[0] |=
8192 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8193 filter_replace_buf.data[4] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8194 filter_replace_buf.data[4] |=
8195 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8196 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8197 &filter_replace_buf);
8200 if (filter_replace.old_filter_type !=
8201 filter_replace.new_filter_type)
8202 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8203 " original: 0x%x, new: 0x%x",
8205 filter_replace.old_filter_type,
8206 filter_replace.new_filter_type);
8209 memset(&filter_replace, 0,
8210 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8211 memset(&filter_replace_buf, 0,
8212 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8213 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8214 filter_replace.old_filter_type =
8215 I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
8216 filter_replace.new_filter_type =
8217 I40E_AQC_ADD_CLOUD_FILTER_0X12;
8218 /* Prepare the buffer, 2 entries */
8219 filter_replace_buf.data[0] = I40E_AQC_ADD_L1_FILTER_0X13;
8220 filter_replace_buf.data[0] |=
8221 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8222 filter_replace_buf.data[4] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8223 filter_replace_buf.data[4] |=
8224 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8226 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8227 &filter_replace_buf);
8228 if (!status && (filter_replace.old_filter_type !=
8229 filter_replace.new_filter_type))
8230 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8231 " original: 0x%x, new: 0x%x",
8233 filter_replace.old_filter_type,
8234 filter_replace.new_filter_type);
8239 static enum i40e_status_code
8240 i40e_replace_port_l1_filter(struct i40e_pf *pf,
8241 enum i40e_l4_port_type l4_port_type)
8243 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8244 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8245 enum i40e_status_code status = I40E_SUCCESS;
8246 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8247 struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8249 if (pf->support_multi_driver) {
8250 PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
8251 return I40E_NOT_SUPPORTED;
8254 memset(&filter_replace, 0,
8255 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8256 memset(&filter_replace_buf, 0,
8257 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8259 /* create L1 filter */
8260 if (l4_port_type == I40E_L4_PORT_TYPE_SRC) {
8261 filter_replace.old_filter_type =
8262 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TUNNLE_KEY;
8263 filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X11;
8264 filter_replace_buf.data[8] =
8265 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_SRC_PORT;
8267 filter_replace.old_filter_type =
8268 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG_IVLAN;
8269 filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X10;
8270 filter_replace_buf.data[8] =
8271 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_DST_PORT;
8274 filter_replace.tr_bit = 0;
8275 /* Prepare the buffer, 3 entries */
8276 filter_replace_buf.data[0] =
8277 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_DIRECTION_WORD0;
8278 filter_replace_buf.data[0] |=
8279 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8280 filter_replace_buf.data[2] = 0x00;
8281 filter_replace_buf.data[3] =
8282 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_INGRESS_WORD0;
8283 filter_replace_buf.data[4] =
8284 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_PORT_TR_WORD0;
8285 filter_replace_buf.data[4] |=
8286 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8287 filter_replace_buf.data[5] = 0x00;
8288 filter_replace_buf.data[6] = I40E_TR_L4_TYPE_UDP |
8289 I40E_TR_L4_TYPE_TCP |
8290 I40E_TR_L4_TYPE_SCTP;
8291 filter_replace_buf.data[7] = 0x00;
8292 filter_replace_buf.data[8] |=
8293 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8294 filter_replace_buf.data[9] = 0x00;
8295 filter_replace_buf.data[10] = 0xFF;
8296 filter_replace_buf.data[11] = 0xFF;
8298 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8299 &filter_replace_buf);
8300 if (!status && filter_replace.old_filter_type !=
8301 filter_replace.new_filter_type)
8302 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8303 " original: 0x%x, new: 0x%x",
8305 filter_replace.old_filter_type,
8306 filter_replace.new_filter_type);
8311 static enum i40e_status_code
8312 i40e_replace_port_cloud_filter(struct i40e_pf *pf,
8313 enum i40e_l4_port_type l4_port_type)
8315 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8316 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8317 enum i40e_status_code status = I40E_SUCCESS;
8318 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8319 struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8321 if (pf->support_multi_driver) {
8322 PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8323 return I40E_NOT_SUPPORTED;
8326 memset(&filter_replace, 0,
8327 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8328 memset(&filter_replace_buf, 0,
8329 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8331 if (l4_port_type == I40E_L4_PORT_TYPE_SRC) {
8332 filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IIP;
8333 filter_replace.new_filter_type =
8334 I40E_AQC_ADD_CLOUD_FILTER_0X11;
8335 filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X11;
8337 filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_OIP;
8338 filter_replace.new_filter_type =
8339 I40E_AQC_ADD_CLOUD_FILTER_0X10;
8340 filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X10;
8343 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8344 filter_replace.tr_bit = 0;
8345 /* Prepare the buffer, 2 entries */
8346 filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8347 filter_replace_buf.data[0] |=
8348 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8349 filter_replace_buf.data[4] |=
8350 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8351 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8352 &filter_replace_buf);
8354 if (!status && filter_replace.old_filter_type !=
8355 filter_replace.new_filter_type)
8356 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8357 " original: 0x%x, new: 0x%x",
8359 filter_replace.old_filter_type,
8360 filter_replace.new_filter_type);
8366 i40e_dev_consistent_tunnel_filter_set(struct i40e_pf *pf,
8367 struct i40e_tunnel_filter_conf *tunnel_filter,
8371 uint32_t ipv4_addr, ipv4_addr_le;
8372 uint8_t i, tun_type = 0;
8373 /* internal variable to convert ipv6 byte order */
8374 uint32_t convert_ipv6[4];
8376 struct i40e_pf_vf *vf = NULL;
8377 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8378 struct i40e_vsi *vsi;
8379 struct i40e_aqc_cloud_filters_element_bb *cld_filter;
8380 struct i40e_aqc_cloud_filters_element_bb *pfilter;
8381 struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
8382 struct i40e_tunnel_filter *tunnel, *node;
8383 struct i40e_tunnel_filter check_filter; /* Check if filter exists */
8385 bool big_buffer = 0;
8387 cld_filter = rte_zmalloc("tunnel_filter",
8388 sizeof(struct i40e_aqc_add_rm_cloud_filt_elem_ext),
8391 if (cld_filter == NULL) {
8392 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
8395 pfilter = cld_filter;
8397 rte_ether_addr_copy(&tunnel_filter->outer_mac,
8398 (struct rte_ether_addr *)&pfilter->element.outer_mac);
8399 rte_ether_addr_copy(&tunnel_filter->inner_mac,
8400 (struct rte_ether_addr *)&pfilter->element.inner_mac);
8402 pfilter->element.inner_vlan =
8403 rte_cpu_to_le_16(tunnel_filter->inner_vlan);
8404 if (tunnel_filter->ip_type == I40E_TUNNEL_IPTYPE_IPV4) {
8405 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV4;
8406 ipv4_addr = rte_be_to_cpu_32(tunnel_filter->ip_addr.ipv4_addr);
8407 ipv4_addr_le = rte_cpu_to_le_32(ipv4_addr);
8408 rte_memcpy(&pfilter->element.ipaddr.v4.data,
8410 sizeof(pfilter->element.ipaddr.v4.data));
8412 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV6;
8413 for (i = 0; i < 4; i++) {
8415 rte_cpu_to_le_32(rte_be_to_cpu_32(
8416 tunnel_filter->ip_addr.ipv6_addr[i]));
8418 rte_memcpy(&pfilter->element.ipaddr.v6.data,
8420 sizeof(pfilter->element.ipaddr.v6.data));
8423 /* check tunneled type */
8424 switch (tunnel_filter->tunnel_type) {
8425 case I40E_TUNNEL_TYPE_VXLAN:
8426 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_VXLAN;
8428 case I40E_TUNNEL_TYPE_NVGRE:
8429 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_NVGRE_OMAC;
8431 case I40E_TUNNEL_TYPE_IP_IN_GRE:
8432 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_IP;
8434 case I40E_TUNNEL_TYPE_MPLSoUDP:
8435 if (!pf->mpls_replace_flag) {
8436 i40e_replace_mpls_l1_filter(pf);
8437 i40e_replace_mpls_cloud_filter(pf);
8438 pf->mpls_replace_flag = 1;
8440 teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8441 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8443 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8444 (teid_le & 0xF) << 12;
8445 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8448 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_MPLSOUDP;
8450 case I40E_TUNNEL_TYPE_MPLSoGRE:
8451 if (!pf->mpls_replace_flag) {
8452 i40e_replace_mpls_l1_filter(pf);
8453 i40e_replace_mpls_cloud_filter(pf);
8454 pf->mpls_replace_flag = 1;
8456 teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8457 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8459 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8460 (teid_le & 0xF) << 12;
8461 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8464 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_MPLSOGRE;
8466 case I40E_TUNNEL_TYPE_GTPC:
8467 if (!pf->gtp_replace_flag) {
8468 i40e_replace_gtp_l1_filter(pf);
8469 i40e_replace_gtp_cloud_filter(pf);
8470 pf->gtp_replace_flag = 1;
8472 teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8473 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD0] =
8474 (teid_le >> 16) & 0xFFFF;
8475 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD1] =
8477 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD2] =
8481 case I40E_TUNNEL_TYPE_GTPU:
8482 if (!pf->gtp_replace_flag) {
8483 i40e_replace_gtp_l1_filter(pf);
8484 i40e_replace_gtp_cloud_filter(pf);
8485 pf->gtp_replace_flag = 1;
8487 teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8488 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD0] =
8489 (teid_le >> 16) & 0xFFFF;
8490 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD1] =
8492 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD2] =
8496 case I40E_TUNNEL_TYPE_QINQ:
8497 if (!pf->qinq_replace_flag) {
8498 ret = i40e_cloud_filter_qinq_create(pf);
8501 "QinQ tunnel filter already created.");
8502 pf->qinq_replace_flag = 1;
8504 /* Add in the General fields the values of
8505 * the Outer and Inner VLAN
8506 * Big Buffer should be set, see changes in
8507 * i40e_aq_add_cloud_filters
8509 pfilter->general_fields[0] = tunnel_filter->inner_vlan;
8510 pfilter->general_fields[1] = tunnel_filter->outer_vlan;
8513 case I40E_CLOUD_TYPE_UDP:
8514 case I40E_CLOUD_TYPE_TCP:
8515 case I40E_CLOUD_TYPE_SCTP:
8516 if (tunnel_filter->l4_port_type == I40E_L4_PORT_TYPE_SRC) {
8517 if (!pf->sport_replace_flag) {
8518 i40e_replace_port_l1_filter(pf,
8519 tunnel_filter->l4_port_type);
8520 i40e_replace_port_cloud_filter(pf,
8521 tunnel_filter->l4_port_type);
8522 pf->sport_replace_flag = 1;
8524 teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8525 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8526 I40E_DIRECTION_INGRESS_KEY;
8528 if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_UDP)
8529 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8530 I40E_TR_L4_TYPE_UDP;
8531 else if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_TCP)
8532 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8533 I40E_TR_L4_TYPE_TCP;
8535 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8536 I40E_TR_L4_TYPE_SCTP;
8538 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8539 (teid_le >> 16) & 0xFFFF;
8542 if (!pf->dport_replace_flag) {
8543 i40e_replace_port_l1_filter(pf,
8544 tunnel_filter->l4_port_type);
8545 i40e_replace_port_cloud_filter(pf,
8546 tunnel_filter->l4_port_type);
8547 pf->dport_replace_flag = 1;
8549 teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8550 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD0] =
8551 I40E_DIRECTION_INGRESS_KEY;
8553 if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_UDP)
8554 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD1] =
8555 I40E_TR_L4_TYPE_UDP;
8556 else if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_TCP)
8557 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD1] =
8558 I40E_TR_L4_TYPE_TCP;
8560 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD1] =
8561 I40E_TR_L4_TYPE_SCTP;
8563 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD2] =
8564 (teid_le >> 16) & 0xFFFF;
8570 /* Other tunnel types is not supported. */
8571 PMD_DRV_LOG(ERR, "tunnel type is not supported.");
8572 rte_free(cld_filter);
8576 if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_MPLSoUDP)
8577 pfilter->element.flags =
8578 I40E_AQC_ADD_CLOUD_FILTER_0X11;
8579 else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_MPLSoGRE)
8580 pfilter->element.flags =
8581 I40E_AQC_ADD_CLOUD_FILTER_0X12;
8582 else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_GTPC)
8583 pfilter->element.flags =
8584 I40E_AQC_ADD_CLOUD_FILTER_0X11;
8585 else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_GTPU)
8586 pfilter->element.flags =
8587 I40E_AQC_ADD_CLOUD_FILTER_0X12;
8588 else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_QINQ)
8589 pfilter->element.flags |=
8590 I40E_AQC_ADD_CLOUD_FILTER_0X10;
8591 else if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_UDP ||
8592 tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_TCP ||
8593 tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_SCTP) {
8594 if (tunnel_filter->l4_port_type == I40E_L4_PORT_TYPE_SRC)
8595 pfilter->element.flags |=
8596 I40E_AQC_ADD_CLOUD_FILTER_0X11;
8598 pfilter->element.flags |=
8599 I40E_AQC_ADD_CLOUD_FILTER_0X10;
8601 val = i40e_dev_get_filter_type(tunnel_filter->filter_type,
8602 &pfilter->element.flags);
8604 rte_free(cld_filter);
8609 pfilter->element.flags |= rte_cpu_to_le_16(
8610 I40E_AQC_ADD_CLOUD_FLAGS_TO_QUEUE |
8611 ip_type | (tun_type << I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT));
8612 pfilter->element.tenant_id = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8613 pfilter->element.queue_number =
8614 rte_cpu_to_le_16(tunnel_filter->queue_id);
8616 if (!tunnel_filter->is_to_vf)
8619 if (tunnel_filter->vf_id >= pf->vf_num) {
8620 PMD_DRV_LOG(ERR, "Invalid argument.");
8621 rte_free(cld_filter);
8624 vf = &pf->vfs[tunnel_filter->vf_id];
8628 /* Check if there is the filter in SW list */
8629 memset(&check_filter, 0, sizeof(check_filter));
8630 i40e_tunnel_filter_convert(cld_filter, &check_filter);
8631 check_filter.is_to_vf = tunnel_filter->is_to_vf;
8632 check_filter.vf_id = tunnel_filter->vf_id;
8633 node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
8635 PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
8636 rte_free(cld_filter);
8640 if (!add && !node) {
8641 PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
8642 rte_free(cld_filter);
8648 ret = i40e_aq_add_cloud_filters_bb(hw,
8649 vsi->seid, cld_filter, 1);
8651 ret = i40e_aq_add_cloud_filters(hw,
8652 vsi->seid, &cld_filter->element, 1);
8654 PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
8655 rte_free(cld_filter);
8658 tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
8659 if (tunnel == NULL) {
8660 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
8661 rte_free(cld_filter);
8665 rte_memcpy(tunnel, &check_filter, sizeof(check_filter));
8666 ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
8671 ret = i40e_aq_rem_cloud_filters_bb(
8672 hw, vsi->seid, cld_filter, 1);
8674 ret = i40e_aq_rem_cloud_filters(hw, vsi->seid,
8675 &cld_filter->element, 1);
8677 PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
8678 rte_free(cld_filter);
8681 ret = i40e_sw_tunnel_filter_del(pf, &node->input);
8684 rte_free(cld_filter);
8689 i40e_get_vxlan_port_idx(struct i40e_pf *pf, uint16_t port)
8693 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
8694 if (pf->vxlan_ports[i] == port)
8702 i40e_add_vxlan_port(struct i40e_pf *pf, uint16_t port, int udp_type)
8705 uint8_t filter_idx = 0;
8706 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8708 idx = i40e_get_vxlan_port_idx(pf, port);
8710 /* Check if port already exists */
8712 PMD_DRV_LOG(ERR, "Port %d already offloaded", port);
8716 /* Now check if there is space to add the new port */
8717 idx = i40e_get_vxlan_port_idx(pf, 0);
8720 "Maximum number of UDP ports reached, not adding port %d",
8725 ret = i40e_aq_add_udp_tunnel(hw, port, udp_type,
8728 PMD_DRV_LOG(ERR, "Failed to add VXLAN UDP port %d", port);
8732 PMD_DRV_LOG(INFO, "Added port %d with AQ command with index %d",
8735 /* New port: add it and mark its index in the bitmap */
8736 pf->vxlan_ports[idx] = port;
8737 pf->vxlan_bitmap |= (1 << idx);
8739 if (!(pf->flags & I40E_FLAG_VXLAN))
8740 pf->flags |= I40E_FLAG_VXLAN;
8746 i40e_del_vxlan_port(struct i40e_pf *pf, uint16_t port)
8749 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8751 if (!(pf->flags & I40E_FLAG_VXLAN)) {
8752 PMD_DRV_LOG(ERR, "VXLAN UDP port was not configured.");
8756 idx = i40e_get_vxlan_port_idx(pf, port);
8759 PMD_DRV_LOG(ERR, "Port %d doesn't exist", port);
8763 if (i40e_aq_del_udp_tunnel(hw, idx, NULL) < 0) {
8764 PMD_DRV_LOG(ERR, "Failed to delete VXLAN UDP port %d", port);
8768 PMD_DRV_LOG(INFO, "Deleted port %d with AQ command with index %d",
8771 pf->vxlan_ports[idx] = 0;
8772 pf->vxlan_bitmap &= ~(1 << idx);
8774 if (!pf->vxlan_bitmap)
8775 pf->flags &= ~I40E_FLAG_VXLAN;
8780 /* Add UDP tunneling port */
8782 i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
8783 struct rte_eth_udp_tunnel *udp_tunnel)
8786 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8788 if (udp_tunnel == NULL)
8791 switch (udp_tunnel->prot_type) {
8792 case RTE_ETH_TUNNEL_TYPE_VXLAN:
8793 ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port,
8794 I40E_AQC_TUNNEL_TYPE_VXLAN);
8796 case RTE_ETH_TUNNEL_TYPE_VXLAN_GPE:
8797 ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port,
8798 I40E_AQC_TUNNEL_TYPE_VXLAN_GPE);
8800 case RTE_ETH_TUNNEL_TYPE_GENEVE:
8801 case RTE_ETH_TUNNEL_TYPE_TEREDO:
8802 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8807 PMD_DRV_LOG(ERR, "Invalid tunnel type");
8815 /* Remove UDP tunneling port */
8817 i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
8818 struct rte_eth_udp_tunnel *udp_tunnel)
8821 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8823 if (udp_tunnel == NULL)
8826 switch (udp_tunnel->prot_type) {
8827 case RTE_ETH_TUNNEL_TYPE_VXLAN:
8828 case RTE_ETH_TUNNEL_TYPE_VXLAN_GPE:
8829 ret = i40e_del_vxlan_port(pf, udp_tunnel->udp_port);
8831 case RTE_ETH_TUNNEL_TYPE_GENEVE:
8832 case RTE_ETH_TUNNEL_TYPE_TEREDO:
8833 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8837 PMD_DRV_LOG(ERR, "Invalid tunnel type");
8845 /* Calculate the maximum number of contiguous PF queues that are configured */
8847 i40e_pf_calc_configured_queues_num(struct i40e_pf *pf)
8849 struct rte_eth_dev_data *data = pf->dev_data;
8851 struct i40e_rx_queue *rxq;
8854 for (i = 0; i < pf->lan_nb_qps; i++) {
8855 rxq = data->rx_queues[i];
8856 if (rxq && rxq->q_set)
8865 /* Reset the global configure of hash function and input sets */
8867 i40e_pf_global_rss_reset(struct i40e_pf *pf)
8869 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8870 uint32_t reg, reg_val;
8873 /* Reset global RSS function sets */
8874 reg_val = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
8875 if (!(reg_val & I40E_GLQF_CTL_HTOEP_MASK)) {
8876 reg_val |= I40E_GLQF_CTL_HTOEP_MASK;
8877 i40e_write_global_rx_ctl(hw, I40E_GLQF_CTL, reg_val);
8880 for (i = 0; i <= I40E_FILTER_PCTYPE_L2_PAYLOAD; i++) {
8884 if (hw->mac.type == I40E_MAC_X722)
8885 pctype = i40e_read_rx_ctl(hw, I40E_GLQF_FD_PCTYPES(i));
8889 /* Reset pctype insets */
8890 inset = i40e_get_default_input_set(i);
8892 pf->hash_input_set[pctype] = inset;
8893 inset = i40e_translate_input_set_reg(hw->mac.type,
8896 reg = I40E_GLQF_HASH_INSET(0, pctype);
8897 i40e_check_write_global_reg(hw, reg, (uint32_t)inset);
8898 reg = I40E_GLQF_HASH_INSET(1, pctype);
8899 i40e_check_write_global_reg(hw, reg,
8900 (uint32_t)(inset >> 32));
8902 /* Clear unused mask registers of the pctype */
8903 for (j = 0; j < I40E_INSET_MASK_NUM_REG; j++) {
8904 reg = I40E_GLQF_HASH_MSK(j, pctype);
8905 i40e_check_write_global_reg(hw, reg, 0);
8909 /* Reset pctype symmetric sets */
8910 reg = I40E_GLQF_HSYM(pctype);
8911 reg_val = i40e_read_rx_ctl(hw, reg);
8912 if (reg_val & I40E_GLQF_HSYM_SYMH_ENA_MASK) {
8913 reg_val &= ~I40E_GLQF_HSYM_SYMH_ENA_MASK;
8914 i40e_write_global_rx_ctl(hw, reg, reg_val);
8917 I40E_WRITE_FLUSH(hw);
8921 i40e_pf_reset_rss_reta(struct i40e_pf *pf)
8923 struct i40e_hw *hw = &pf->adapter->hw;
8924 uint8_t lut[RTE_ETH_RSS_RETA_SIZE_512];
8928 /* If both VMDQ and RSS enabled, not all of PF queues are
8929 * configured. It's necessary to calculate the actual PF
8930 * queues that are configured.
8932 if (pf->dev_data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG)
8933 num = i40e_pf_calc_configured_queues_num(pf);
8935 num = pf->dev_data->nb_rx_queues;
8937 num = RTE_MIN(num, I40E_MAX_Q_PER_TC);
8941 for (i = 0; i < hw->func_caps.rss_table_size; i++)
8942 lut[i] = (uint8_t)(i % (uint32_t)num);
8944 return i40e_set_rss_lut(pf->main_vsi, lut, (uint16_t)i);
8948 i40e_pf_reset_rss_key(struct i40e_pf *pf)
8950 const uint8_t key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
8955 rss_key = pf->dev_data->dev_conf.rx_adv_conf.rss_conf.rss_key;
8957 pf->dev_data->dev_conf.rx_adv_conf.rss_conf.rss_key_len < key_len) {
8958 static uint32_t rss_key_default[] = {0x6b793944,
8959 0x23504cb5, 0x5bea75b6, 0x309f4f12, 0x3dc0a2b8,
8960 0x024ddcdf, 0x339b8ca0, 0x4c4af64a, 0x34fac605,
8961 0x55d85839, 0x3a58997d, 0x2ec938e1, 0x66031581};
8963 rss_key = (uint8_t *)rss_key_default;
8966 return i40e_set_rss_key(pf->main_vsi, rss_key, key_len);
8970 i40e_pf_rss_reset(struct i40e_pf *pf)
8972 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8976 pf->hash_filter_enabled = 0;
8977 i40e_pf_disable_rss(pf);
8978 i40e_set_symmetric_hash_enable_per_port(hw, 0);
8980 if (!pf->support_multi_driver)
8981 i40e_pf_global_rss_reset(pf);
8983 /* Reset RETA table */
8984 if (pf->adapter->rss_reta_updated == 0) {
8985 ret = i40e_pf_reset_rss_reta(pf);
8990 return i40e_pf_reset_rss_key(pf);
8995 i40e_pf_config_rss(struct i40e_pf *pf)
8998 enum rte_eth_rx_mq_mode mq_mode;
8999 uint64_t rss_hf, hena;
9002 ret = i40e_pf_rss_reset(pf);
9004 PMD_DRV_LOG(ERR, "Reset RSS failed, RSS has been disabled");
9008 rss_hf = pf->dev_data->dev_conf.rx_adv_conf.rss_conf.rss_hf;
9009 mq_mode = pf->dev_data->dev_conf.rxmode.mq_mode;
9010 if (!(rss_hf & pf->adapter->flow_types_mask) ||
9011 !(mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
9014 hw = I40E_PF_TO_HW(pf);
9015 hena = i40e_config_hena(pf->adapter, rss_hf);
9016 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
9017 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
9018 I40E_WRITE_FLUSH(hw);
9023 #define I40E_GL_PRS_FVBM_MSK_ENA 0x80000000
9024 #define I40E_GL_PRS_FVBM(_i) (0x00269760 + ((_i) * 4))
9026 i40e_dev_set_gre_key_len(struct i40e_hw *hw, uint8_t len)
9028 struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
9032 if (pf->support_multi_driver) {
9033 PMD_DRV_LOG(ERR, "GRE key length configuration is unsupported");
9037 val = I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2));
9038 PMD_DRV_LOG(DEBUG, "Read original GL_PRS_FVBM with 0x%08x", val);
9041 reg = val | I40E_GL_PRS_FVBM_MSK_ENA;
9042 } else if (len == 4) {
9043 reg = val & ~I40E_GL_PRS_FVBM_MSK_ENA;
9045 PMD_DRV_LOG(ERR, "Unsupported GRE key length of %u", len);
9050 ret = i40e_aq_debug_write_global_register(hw,
9051 I40E_GL_PRS_FVBM(2),
9055 PMD_DRV_LOG(DEBUG, "Global register 0x%08x is changed "
9056 "with value 0x%08x",
9057 I40E_GL_PRS_FVBM(2), reg);
9061 PMD_DRV_LOG(DEBUG, "Read modified GL_PRS_FVBM with 0x%08x",
9062 I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2)));
9067 /* Set the symmetric hash enable configurations per port */
9069 i40e_set_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t enable)
9071 uint32_t reg = i40e_read_rx_ctl(hw, I40E_PRTQF_CTL_0);
9074 if (reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK)
9077 reg |= I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
9079 if (!(reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK))
9082 reg &= ~I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
9084 i40e_write_rx_ctl(hw, I40E_PRTQF_CTL_0, reg);
9085 I40E_WRITE_FLUSH(hw);
9089 * Valid input sets for hash and flow director filters per PCTYPE
9092 i40e_get_valid_input_set(enum i40e_filter_pctype pctype,
9093 enum rte_filter_type filter)
9097 static const uint64_t valid_hash_inset_table[] = {
9098 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9099 I40E_INSET_DMAC | I40E_INSET_SMAC |
9100 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9101 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_SRC |
9102 I40E_INSET_IPV4_DST | I40E_INSET_IPV4_TOS |
9103 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9104 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9105 I40E_INSET_FLEX_PAYLOAD,
9106 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9107 I40E_INSET_DMAC | I40E_INSET_SMAC |
9108 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9109 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9110 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9111 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9112 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9113 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9114 I40E_INSET_FLEX_PAYLOAD,
9115 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9116 I40E_INSET_DMAC | I40E_INSET_SMAC |
9117 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9118 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9119 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9120 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9121 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9122 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9123 I40E_INSET_FLEX_PAYLOAD,
9124 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9125 I40E_INSET_DMAC | I40E_INSET_SMAC |
9126 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9127 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9128 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9129 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9130 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9131 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9132 I40E_INSET_FLEX_PAYLOAD,
9133 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9134 I40E_INSET_DMAC | I40E_INSET_SMAC |
9135 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9136 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9137 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9138 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9139 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9140 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9141 I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
9142 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9143 I40E_INSET_DMAC | I40E_INSET_SMAC |
9144 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9145 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9146 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9147 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9148 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9149 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9150 I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
9151 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9152 I40E_INSET_DMAC | I40E_INSET_SMAC |
9153 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9154 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9155 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9156 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9157 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9158 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9159 I40E_INSET_SCTP_VT | I40E_INSET_FLEX_PAYLOAD,
9160 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9161 I40E_INSET_DMAC | I40E_INSET_SMAC |
9162 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9163 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9164 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9165 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9166 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9167 I40E_INSET_FLEX_PAYLOAD,
9168 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9169 I40E_INSET_DMAC | I40E_INSET_SMAC |
9170 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9171 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9172 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9173 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_TUNNEL_DMAC |
9174 I40E_INSET_TUNNEL_ID | I40E_INSET_IPV6_SRC |
9175 I40E_INSET_IPV6_DST | I40E_INSET_FLEX_PAYLOAD,
9176 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9177 I40E_INSET_DMAC | I40E_INSET_SMAC |
9178 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9179 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9180 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9181 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9182 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9183 I40E_INSET_DST_PORT | I40E_INSET_FLEX_PAYLOAD,
9184 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9185 I40E_INSET_DMAC | I40E_INSET_SMAC |
9186 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9187 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9188 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9189 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9190 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9191 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9192 I40E_INSET_FLEX_PAYLOAD,
9193 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9194 I40E_INSET_DMAC | I40E_INSET_SMAC |
9195 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9196 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9197 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9198 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9199 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9200 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9201 I40E_INSET_FLEX_PAYLOAD,
9202 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9203 I40E_INSET_DMAC | I40E_INSET_SMAC |
9204 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9205 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9206 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9207 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9208 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9209 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9210 I40E_INSET_FLEX_PAYLOAD,
9211 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9212 I40E_INSET_DMAC | I40E_INSET_SMAC |
9213 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9214 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9215 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9216 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9217 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9218 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9219 I40E_INSET_FLEX_PAYLOAD,
9220 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9221 I40E_INSET_DMAC | I40E_INSET_SMAC |
9222 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9223 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9224 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9225 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9226 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9227 I40E_INSET_DST_PORT | I40E_INSET_SCTP_VT |
9228 I40E_INSET_FLEX_PAYLOAD,
9229 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9230 I40E_INSET_DMAC | I40E_INSET_SMAC |
9231 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9232 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9233 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9234 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9235 I40E_INSET_IPV6_DST | I40E_INSET_TUNNEL_ID |
9236 I40E_INSET_FLEX_PAYLOAD,
9237 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9238 I40E_INSET_DMAC | I40E_INSET_SMAC |
9239 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9240 I40E_INSET_VLAN_TUNNEL | I40E_INSET_LAST_ETHER_TYPE |
9241 I40E_INSET_FLEX_PAYLOAD,
9245 * Flow director supports only fields defined in
9246 * union rte_eth_fdir_flow.
9248 static const uint64_t valid_fdir_inset_table[] = {
9249 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9250 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9251 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9252 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9253 I40E_INSET_IPV4_TTL,
9254 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9255 I40E_INSET_DMAC | I40E_INSET_SMAC |
9256 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9257 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9258 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9259 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9260 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9261 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9262 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9263 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9264 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9265 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9266 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9267 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9268 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9269 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9270 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9271 I40E_INSET_DMAC | I40E_INSET_SMAC |
9272 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9273 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9274 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9275 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9276 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9277 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9278 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9279 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9280 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9281 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
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_TTL |
9285 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9287 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9288 I40E_INSET_DMAC | I40E_INSET_SMAC |
9289 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9290 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9291 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9292 I40E_INSET_IPV4_TTL,
9293 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9294 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9295 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9296 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
9297 I40E_INSET_IPV6_HOP_LIMIT,
9298 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9299 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9300 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9301 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9302 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9303 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9304 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9305 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9306 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9307 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9308 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9309 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9310 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9311 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9312 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9313 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9314 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9315 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9316 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9317 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9318 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9319 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9320 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9321 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9322 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9323 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9324 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9325 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9326 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9327 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9329 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9330 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9331 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9332 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
9333 I40E_INSET_IPV6_HOP_LIMIT,
9334 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9335 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9336 I40E_INSET_LAST_ETHER_TYPE,
9339 if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
9341 if (filter == RTE_ETH_FILTER_HASH)
9342 valid = valid_hash_inset_table[pctype];
9344 valid = valid_fdir_inset_table[pctype];
9350 * Validate if the input set is allowed for a specific PCTYPE
9353 i40e_validate_input_set(enum i40e_filter_pctype pctype,
9354 enum rte_filter_type filter, uint64_t inset)
9358 valid = i40e_get_valid_input_set(pctype, filter);
9359 if (inset & (~valid))
9365 /* default input set fields combination per pctype */
9367 i40e_get_default_input_set(uint16_t pctype)
9369 static const uint64_t default_inset_table[] = {
9370 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9371 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
9372 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9373 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9374 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9375 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9376 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9377 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9378 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9379 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9380 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9381 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9382 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9383 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9384 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9385 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9386 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9387 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9388 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9389 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9391 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9392 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
9393 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9394 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
9395 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9396 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9397 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9398 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9399 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9400 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9401 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9402 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9403 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9404 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9405 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9406 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9407 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9408 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9409 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9410 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9411 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9412 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9414 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9415 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
9416 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9417 I40E_INSET_LAST_ETHER_TYPE,
9420 if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
9423 return default_inset_table[pctype];
9427 * Translate the input set from bit masks to register aware bit masks
9431 i40e_translate_input_set_reg(enum i40e_mac_type type, uint64_t input)
9441 static const struct inset_map inset_map_common[] = {
9442 {I40E_INSET_DMAC, I40E_REG_INSET_L2_DMAC},
9443 {I40E_INSET_SMAC, I40E_REG_INSET_L2_SMAC},
9444 {I40E_INSET_VLAN_OUTER, I40E_REG_INSET_L2_OUTER_VLAN},
9445 {I40E_INSET_VLAN_INNER, I40E_REG_INSET_L2_INNER_VLAN},
9446 {I40E_INSET_LAST_ETHER_TYPE, I40E_REG_INSET_LAST_ETHER_TYPE},
9447 {I40E_INSET_IPV4_TOS, I40E_REG_INSET_L3_IP4_TOS},
9448 {I40E_INSET_IPV6_SRC, I40E_REG_INSET_L3_SRC_IP6},
9449 {I40E_INSET_IPV6_DST, I40E_REG_INSET_L3_DST_IP6},
9450 {I40E_INSET_IPV6_TC, I40E_REG_INSET_L3_IP6_TC},
9451 {I40E_INSET_IPV6_NEXT_HDR, I40E_REG_INSET_L3_IP6_NEXT_HDR},
9452 {I40E_INSET_IPV6_HOP_LIMIT, I40E_REG_INSET_L3_IP6_HOP_LIMIT},
9453 {I40E_INSET_SRC_PORT, I40E_REG_INSET_L4_SRC_PORT},
9454 {I40E_INSET_DST_PORT, I40E_REG_INSET_L4_DST_PORT},
9455 {I40E_INSET_SCTP_VT, I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG},
9456 {I40E_INSET_TUNNEL_ID, I40E_REG_INSET_TUNNEL_ID},
9457 {I40E_INSET_TUNNEL_DMAC,
9458 I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC},
9459 {I40E_INSET_TUNNEL_IPV4_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP4},
9460 {I40E_INSET_TUNNEL_IPV6_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP6},
9461 {I40E_INSET_TUNNEL_SRC_PORT,
9462 I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT},
9463 {I40E_INSET_TUNNEL_DST_PORT,
9464 I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT},
9465 {I40E_INSET_VLAN_TUNNEL, I40E_REG_INSET_TUNNEL_VLAN},
9466 {I40E_INSET_FLEX_PAYLOAD_W1, I40E_REG_INSET_FLEX_PAYLOAD_WORD1},
9467 {I40E_INSET_FLEX_PAYLOAD_W2, I40E_REG_INSET_FLEX_PAYLOAD_WORD2},
9468 {I40E_INSET_FLEX_PAYLOAD_W3, I40E_REG_INSET_FLEX_PAYLOAD_WORD3},
9469 {I40E_INSET_FLEX_PAYLOAD_W4, I40E_REG_INSET_FLEX_PAYLOAD_WORD4},
9470 {I40E_INSET_FLEX_PAYLOAD_W5, I40E_REG_INSET_FLEX_PAYLOAD_WORD5},
9471 {I40E_INSET_FLEX_PAYLOAD_W6, I40E_REG_INSET_FLEX_PAYLOAD_WORD6},
9472 {I40E_INSET_FLEX_PAYLOAD_W7, I40E_REG_INSET_FLEX_PAYLOAD_WORD7},
9473 {I40E_INSET_FLEX_PAYLOAD_W8, I40E_REG_INSET_FLEX_PAYLOAD_WORD8},
9476 /* some different registers map in x722*/
9477 static const struct inset_map inset_map_diff_x722[] = {
9478 {I40E_INSET_IPV4_SRC, I40E_X722_REG_INSET_L3_SRC_IP4},
9479 {I40E_INSET_IPV4_DST, I40E_X722_REG_INSET_L3_DST_IP4},
9480 {I40E_INSET_IPV4_PROTO, I40E_X722_REG_INSET_L3_IP4_PROTO},
9481 {I40E_INSET_IPV4_TTL, I40E_X722_REG_INSET_L3_IP4_TTL},
9484 static const struct inset_map inset_map_diff_not_x722[] = {
9485 {I40E_INSET_IPV4_SRC, I40E_REG_INSET_L3_SRC_IP4},
9486 {I40E_INSET_IPV4_DST, I40E_REG_INSET_L3_DST_IP4},
9487 {I40E_INSET_IPV4_PROTO, I40E_REG_INSET_L3_IP4_PROTO},
9488 {I40E_INSET_IPV4_TTL, I40E_REG_INSET_L3_IP4_TTL},
9494 /* Translate input set to register aware inset */
9495 if (type == I40E_MAC_X722) {
9496 for (i = 0; i < RTE_DIM(inset_map_diff_x722); i++) {
9497 if (input & inset_map_diff_x722[i].inset)
9498 val |= inset_map_diff_x722[i].inset_reg;
9501 for (i = 0; i < RTE_DIM(inset_map_diff_not_x722); i++) {
9502 if (input & inset_map_diff_not_x722[i].inset)
9503 val |= inset_map_diff_not_x722[i].inset_reg;
9507 for (i = 0; i < RTE_DIM(inset_map_common); i++) {
9508 if (input & inset_map_common[i].inset)
9509 val |= inset_map_common[i].inset_reg;
9516 i40e_get_inset_field_offset(struct i40e_hw *hw, uint32_t pit_reg_start,
9517 uint32_t pit_reg_count, uint32_t hdr_off)
9519 const uint32_t pit_reg_end = pit_reg_start + pit_reg_count;
9520 uint32_t field_off = I40E_FDIR_FIELD_OFFSET(hdr_off);
9521 uint32_t i, reg_val, src_off, count;
9523 for (i = pit_reg_start; i < pit_reg_end; i++) {
9524 reg_val = i40e_read_rx_ctl(hw, I40E_GLQF_PIT(i));
9526 src_off = I40E_GLQF_PIT_SOURCE_OFF_GET(reg_val);
9527 count = I40E_GLQF_PIT_FSIZE_GET(reg_val);
9529 if (src_off <= field_off && (src_off + count) > field_off)
9533 if (i >= pit_reg_end) {
9535 "Hardware GLQF_PIT configuration does not support this field mask");
9539 return I40E_GLQF_PIT_DEST_OFF_GET(reg_val) + field_off - src_off;
9543 i40e_generate_inset_mask_reg(struct i40e_hw *hw, uint64_t inset,
9544 uint32_t *mask, uint8_t nb_elem)
9546 static const uint64_t mask_inset[] = {
9547 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL,
9548 I40E_INSET_IPV6_NEXT_HDR | I40E_INSET_IPV6_HOP_LIMIT };
9550 static const struct {
9554 } inset_mask_offset_map[] = {
9555 { I40E_INSET_IPV4_TOS, I40E_INSET_IPV4_TOS_MASK,
9556 offsetof(struct rte_ipv4_hdr, type_of_service) },
9558 { I40E_INSET_IPV4_PROTO, I40E_INSET_IPV4_PROTO_MASK,
9559 offsetof(struct rte_ipv4_hdr, next_proto_id) },
9561 { I40E_INSET_IPV4_TTL, I40E_INSET_IPV4_TTL_MASK,
9562 offsetof(struct rte_ipv4_hdr, time_to_live) },
9564 { I40E_INSET_IPV6_TC, I40E_INSET_IPV6_TC_MASK,
9565 offsetof(struct rte_ipv6_hdr, vtc_flow) },
9567 { I40E_INSET_IPV6_NEXT_HDR, I40E_INSET_IPV6_NEXT_HDR_MASK,
9568 offsetof(struct rte_ipv6_hdr, proto) },
9570 { I40E_INSET_IPV6_HOP_LIMIT, I40E_INSET_IPV6_HOP_LIMIT_MASK,
9571 offsetof(struct rte_ipv6_hdr, hop_limits) },
9581 for (i = 0; i < RTE_DIM(mask_inset); i++) {
9582 /* Clear the inset bit, if no MASK is required,
9583 * for example proto + ttl
9585 if ((mask_inset[i] & inset) == mask_inset[i]) {
9586 inset &= ~mask_inset[i];
9592 for (i = 0; i < RTE_DIM(inset_mask_offset_map); i++) {
9593 uint32_t pit_start, pit_count;
9596 if (!(inset_mask_offset_map[i].inset & inset))
9599 if (inset_mask_offset_map[i].inset &
9600 (I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9601 I40E_INSET_IPV4_TTL)) {
9602 pit_start = I40E_GLQF_PIT_IPV4_START;
9603 pit_count = I40E_GLQF_PIT_IPV4_COUNT;
9605 pit_start = I40E_GLQF_PIT_IPV6_START;
9606 pit_count = I40E_GLQF_PIT_IPV6_COUNT;
9609 offset = i40e_get_inset_field_offset(hw, pit_start, pit_count,
9610 inset_mask_offset_map[i].offset);
9615 if (idx >= nb_elem) {
9617 "Configuration of inset mask out of range %u",
9622 mask[idx] = I40E_GLQF_PIT_BUILD((uint32_t)offset,
9623 inset_mask_offset_map[i].mask);
9631 i40e_check_write_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
9633 uint32_t reg = i40e_read_rx_ctl(hw, addr);
9635 PMD_DRV_LOG(DEBUG, "[0x%08x] original: 0x%08x", addr, reg);
9637 i40e_write_rx_ctl(hw, addr, val);
9638 PMD_DRV_LOG(DEBUG, "[0x%08x] after: 0x%08x", addr,
9639 (uint32_t)i40e_read_rx_ctl(hw, addr));
9643 i40e_check_write_global_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
9645 uint32_t reg = i40e_read_rx_ctl(hw, addr);
9646 struct rte_eth_dev_data *dev_data =
9647 ((struct i40e_adapter *)hw->back)->pf.dev_data;
9648 struct rte_eth_dev *dev = &rte_eth_devices[dev_data->port_id];
9651 i40e_write_rx_ctl(hw, addr, val);
9652 PMD_DRV_LOG(WARNING,
9653 "i40e device %s changed global register [0x%08x]."
9654 " original: 0x%08x, new: 0x%08x",
9655 dev->device->name, addr, reg,
9656 (uint32_t)i40e_read_rx_ctl(hw, addr));
9661 i40e_filter_input_set_init(struct i40e_pf *pf)
9663 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9664 enum i40e_filter_pctype pctype;
9665 uint64_t input_set, inset_reg;
9666 uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9670 for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
9671 pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++) {
9672 flow_type = i40e_pctype_to_flowtype(pf->adapter, pctype);
9674 if (flow_type == RTE_ETH_FLOW_UNKNOWN)
9677 input_set = i40e_get_default_input_set(pctype);
9679 num = i40e_generate_inset_mask_reg(hw, input_set, mask_reg,
9680 I40E_INSET_MASK_NUM_REG);
9683 if (pf->support_multi_driver && num > 0) {
9684 PMD_DRV_LOG(ERR, "Input set setting is not supported.");
9687 inset_reg = i40e_translate_input_set_reg(hw->mac.type,
9690 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
9691 (uint32_t)(inset_reg & UINT32_MAX));
9692 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
9693 (uint32_t)((inset_reg >>
9694 I40E_32_BIT_WIDTH) & UINT32_MAX));
9695 if (!pf->support_multi_driver) {
9696 i40e_check_write_global_reg(hw,
9697 I40E_GLQF_HASH_INSET(0, pctype),
9698 (uint32_t)(inset_reg & UINT32_MAX));
9699 i40e_check_write_global_reg(hw,
9700 I40E_GLQF_HASH_INSET(1, pctype),
9701 (uint32_t)((inset_reg >>
9702 I40E_32_BIT_WIDTH) & UINT32_MAX));
9704 for (i = 0; i < num; i++) {
9705 i40e_check_write_global_reg(hw,
9706 I40E_GLQF_FD_MSK(i, pctype),
9708 i40e_check_write_global_reg(hw,
9709 I40E_GLQF_HASH_MSK(i, pctype),
9712 /*clear unused mask registers of the pctype */
9713 for (i = num; i < I40E_INSET_MASK_NUM_REG; i++) {
9714 i40e_check_write_global_reg(hw,
9715 I40E_GLQF_FD_MSK(i, pctype),
9717 i40e_check_write_global_reg(hw,
9718 I40E_GLQF_HASH_MSK(i, pctype),
9722 PMD_DRV_LOG(ERR, "Input set setting is not supported.");
9724 I40E_WRITE_FLUSH(hw);
9726 /* store the default input set */
9727 if (!pf->support_multi_driver)
9728 pf->hash_input_set[pctype] = input_set;
9729 pf->fdir.input_set[pctype] = input_set;
9734 i40e_set_hash_inset(struct i40e_hw *hw, uint64_t input_set,
9735 uint32_t pctype, bool add)
9737 struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
9738 uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9739 uint64_t inset_reg = 0;
9742 if (pf->support_multi_driver) {
9744 "Modify input set is not permitted when multi-driver enabled.");
9748 /* For X722, get translated pctype in fd pctype register */
9749 if (hw->mac.type == I40E_MAC_X722)
9750 pctype = i40e_read_rx_ctl(hw, I40E_GLQF_FD_PCTYPES(pctype));
9753 /* get inset value in register */
9754 inset_reg = i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, pctype));
9755 inset_reg <<= I40E_32_BIT_WIDTH;
9756 inset_reg |= i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, pctype));
9757 input_set |= pf->hash_input_set[pctype];
9759 num = i40e_generate_inset_mask_reg(hw, input_set, mask_reg,
9760 I40E_INSET_MASK_NUM_REG);
9764 inset_reg |= i40e_translate_input_set_reg(hw->mac.type, input_set);
9766 i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(0, pctype),
9767 (uint32_t)(inset_reg & UINT32_MAX));
9768 i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(1, pctype),
9769 (uint32_t)((inset_reg >>
9770 I40E_32_BIT_WIDTH) & UINT32_MAX));
9772 for (i = 0; i < num; i++)
9773 i40e_check_write_global_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
9775 /*clear unused mask registers of the pctype */
9776 for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
9777 i40e_check_write_global_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
9779 I40E_WRITE_FLUSH(hw);
9781 pf->hash_input_set[pctype] = input_set;
9785 /* Convert ethertype filter structure */
9787 i40e_ethertype_filter_convert(const struct rte_eth_ethertype_filter *input,
9788 struct i40e_ethertype_filter *filter)
9790 rte_memcpy(&filter->input.mac_addr, &input->mac_addr,
9791 RTE_ETHER_ADDR_LEN);
9792 filter->input.ether_type = input->ether_type;
9793 filter->flags = input->flags;
9794 filter->queue = input->queue;
9799 /* Check if there exists the ethertype filter */
9800 struct i40e_ethertype_filter *
9801 i40e_sw_ethertype_filter_lookup(struct i40e_ethertype_rule *ethertype_rule,
9802 const struct i40e_ethertype_filter_input *input)
9806 ret = rte_hash_lookup(ethertype_rule->hash_table, (const void *)input);
9810 return ethertype_rule->hash_map[ret];
9813 /* Add ethertype filter in SW list */
9815 i40e_sw_ethertype_filter_insert(struct i40e_pf *pf,
9816 struct i40e_ethertype_filter *filter)
9818 struct i40e_ethertype_rule *rule = &pf->ethertype;
9821 ret = rte_hash_add_key(rule->hash_table, &filter->input);
9824 "Failed to insert ethertype filter"
9825 " to hash table %d!",
9829 rule->hash_map[ret] = filter;
9831 TAILQ_INSERT_TAIL(&rule->ethertype_list, filter, rules);
9836 /* Delete ethertype filter in SW list */
9838 i40e_sw_ethertype_filter_del(struct i40e_pf *pf,
9839 struct i40e_ethertype_filter_input *input)
9841 struct i40e_ethertype_rule *rule = &pf->ethertype;
9842 struct i40e_ethertype_filter *filter;
9845 ret = rte_hash_del_key(rule->hash_table, input);
9848 "Failed to delete ethertype filter"
9849 " to hash table %d!",
9853 filter = rule->hash_map[ret];
9854 rule->hash_map[ret] = NULL;
9856 TAILQ_REMOVE(&rule->ethertype_list, filter, rules);
9863 * Configure ethertype filter, which can director packet by filtering
9864 * with mac address and ether_type or only ether_type
9867 i40e_ethertype_filter_set(struct i40e_pf *pf,
9868 struct rte_eth_ethertype_filter *filter,
9871 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9872 struct i40e_ethertype_rule *ethertype_rule = &pf->ethertype;
9873 struct i40e_ethertype_filter *ethertype_filter, *node;
9874 struct i40e_ethertype_filter check_filter;
9875 struct i40e_control_filter_stats stats;
9879 if (filter->queue >= pf->dev_data->nb_rx_queues) {
9880 PMD_DRV_LOG(ERR, "Invalid queue ID");
9883 if (filter->ether_type == RTE_ETHER_TYPE_IPV4 ||
9884 filter->ether_type == RTE_ETHER_TYPE_IPV6) {
9886 "unsupported ether_type(0x%04x) in control packet filter.",
9887 filter->ether_type);
9890 if (filter->ether_type == RTE_ETHER_TYPE_VLAN)
9891 PMD_DRV_LOG(WARNING,
9892 "filter vlan ether_type in first tag is not supported.");
9894 /* Check if there is the filter in SW list */
9895 memset(&check_filter, 0, sizeof(check_filter));
9896 i40e_ethertype_filter_convert(filter, &check_filter);
9897 node = i40e_sw_ethertype_filter_lookup(ethertype_rule,
9898 &check_filter.input);
9900 PMD_DRV_LOG(ERR, "Conflict with existing ethertype rules!");
9904 if (!add && !node) {
9905 PMD_DRV_LOG(ERR, "There's no corresponding ethertype filter!");
9909 if (!(filter->flags & RTE_ETHTYPE_FLAGS_MAC))
9910 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
9911 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP)
9912 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
9913 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
9915 memset(&stats, 0, sizeof(stats));
9916 ret = i40e_aq_add_rem_control_packet_filter(hw,
9917 filter->mac_addr.addr_bytes,
9918 filter->ether_type, flags,
9920 filter->queue, add, &stats, NULL);
9923 "add/rem control packet filter, return %d, mac_etype_used = %u, etype_used = %u, mac_etype_free = %u, etype_free = %u",
9924 ret, stats.mac_etype_used, stats.etype_used,
9925 stats.mac_etype_free, stats.etype_free);
9929 /* Add or delete a filter in SW list */
9931 ethertype_filter = rte_zmalloc("ethertype_filter",
9932 sizeof(*ethertype_filter), 0);
9933 if (ethertype_filter == NULL) {
9934 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
9938 rte_memcpy(ethertype_filter, &check_filter,
9939 sizeof(check_filter));
9940 ret = i40e_sw_ethertype_filter_insert(pf, ethertype_filter);
9942 rte_free(ethertype_filter);
9944 ret = i40e_sw_ethertype_filter_del(pf, &node->input);
9951 i40e_dev_flow_ops_get(struct rte_eth_dev *dev,
9952 const struct rte_flow_ops **ops)
9957 *ops = &i40e_flow_ops;
9962 * Check and enable Extended Tag.
9963 * Enabling Extended Tag is important for 40G performance.
9966 i40e_enable_extended_tag(struct rte_eth_dev *dev)
9968 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
9972 ret = rte_pci_read_config(pci_dev, &buf, sizeof(buf),
9975 PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
9979 if (!(buf & PCI_DEV_CAP_EXT_TAG_MASK)) {
9980 PMD_DRV_LOG(ERR, "Does not support Extended Tag");
9985 ret = rte_pci_read_config(pci_dev, &buf, sizeof(buf),
9988 PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
9992 if (buf & PCI_DEV_CTRL_EXT_TAG_MASK) {
9993 PMD_DRV_LOG(DEBUG, "Extended Tag has already been enabled");
9996 buf |= PCI_DEV_CTRL_EXT_TAG_MASK;
9997 ret = rte_pci_write_config(pci_dev, &buf, sizeof(buf),
10000 PMD_DRV_LOG(ERR, "Failed to write PCI offset 0x%x",
10007 * As some registers wouldn't be reset unless a global hardware reset,
10008 * hardware initialization is needed to put those registers into an
10009 * expected initial state.
10012 i40e_hw_init(struct rte_eth_dev *dev)
10014 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10016 i40e_enable_extended_tag(dev);
10018 /* clear the PF Queue Filter control register */
10019 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, 0);
10021 /* Disable symmetric hash per port */
10022 i40e_set_symmetric_hash_enable_per_port(hw, 0);
10026 * For X722 it is possible to have multiple pctypes mapped to the same flowtype
10027 * however this function will return only one highest pctype index,
10028 * which is not quite correct. This is known problem of i40e driver
10029 * and needs to be fixed later.
10031 enum i40e_filter_pctype
10032 i40e_flowtype_to_pctype(const struct i40e_adapter *adapter, uint16_t flow_type)
10035 uint64_t pctype_mask;
10037 if (flow_type < I40E_FLOW_TYPE_MAX) {
10038 pctype_mask = adapter->pctypes_tbl[flow_type];
10039 for (i = I40E_FILTER_PCTYPE_MAX - 1; i > 0; i--) {
10040 if (pctype_mask & (1ULL << i))
10041 return (enum i40e_filter_pctype)i;
10044 return I40E_FILTER_PCTYPE_INVALID;
10048 i40e_pctype_to_flowtype(const struct i40e_adapter *adapter,
10049 enum i40e_filter_pctype pctype)
10052 uint64_t pctype_mask = 1ULL << pctype;
10054 for (flowtype = RTE_ETH_FLOW_UNKNOWN + 1; flowtype < I40E_FLOW_TYPE_MAX;
10056 if (adapter->pctypes_tbl[flowtype] & pctype_mask)
10060 return RTE_ETH_FLOW_UNKNOWN;
10064 * On X710, performance number is far from the expectation on recent firmware
10065 * versions; on XL710, performance number is also far from the expectation on
10066 * recent firmware versions, if promiscuous mode is disabled, or promiscuous
10067 * mode is enabled and port MAC address is equal to the packet destination MAC
10068 * address. The fix for this issue may not be integrated in the following
10069 * firmware version. So the workaround in software driver is needed. It needs
10070 * to modify the initial values of 3 internal only registers for both X710 and
10071 * XL710. Note that the values for X710 or XL710 could be different, and the
10072 * workaround can be removed when it is fixed in firmware in the future.
10075 /* For both X710 and XL710 */
10076 #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1 0x10000200
10077 #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2 0x203F0200
10078 #define I40E_GL_SWR_PRI_JOIN_MAP_0 0x26CE00
10080 #define I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x011f0200
10081 #define I40E_GL_SWR_PRI_JOIN_MAP_2 0x26CE08
10084 #define I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE 0x20000200
10085 #define I40E_X722_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x013F0200
10088 #define I40E_GL_SWR_PM_UP_THR_EF_VALUE 0x03030303
10090 #define I40E_GL_SWR_PM_UP_THR_SF_VALUE 0x06060606
10091 #define I40E_GL_SWR_PM_UP_THR 0x269FBC
10094 * GL_SWR_PM_UP_THR:
10095 * The value is not impacted from the link speed, its value is set according
10096 * to the total number of ports for a better pipe-monitor configuration.
10099 i40e_get_swr_pm_cfg(struct i40e_hw *hw, uint32_t *value)
10101 #define I40E_GL_SWR_PM_EF_DEVICE(dev) \
10102 .device_id = (dev), \
10103 .val = I40E_GL_SWR_PM_UP_THR_EF_VALUE
10105 #define I40E_GL_SWR_PM_SF_DEVICE(dev) \
10106 .device_id = (dev), \
10107 .val = I40E_GL_SWR_PM_UP_THR_SF_VALUE
10109 static const struct {
10110 uint16_t device_id;
10112 } swr_pm_table[] = {
10113 { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_SFP_XL710) },
10114 { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_KX_C) },
10115 { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_10G_BASE_T) },
10116 { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_10G_BASE_T4) },
10117 { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_SFP_X722) },
10119 { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_KX_B) },
10120 { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_QSFP_A) },
10121 { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_QSFP_B) },
10122 { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_20G_KR2) },
10123 { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_20G_KR2_A) },
10124 { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_25G_B) },
10125 { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_25G_SFP28) },
10129 if (value == NULL) {
10130 PMD_DRV_LOG(ERR, "value is NULL");
10134 for (i = 0; i < RTE_DIM(swr_pm_table); i++) {
10135 if (hw->device_id == swr_pm_table[i].device_id) {
10136 *value = swr_pm_table[i].val;
10138 PMD_DRV_LOG(DEBUG, "Device 0x%x with GL_SWR_PM_UP_THR "
10140 hw->device_id, *value);
10149 i40e_dev_sync_phy_type(struct i40e_hw *hw)
10151 enum i40e_status_code status;
10152 struct i40e_aq_get_phy_abilities_resp phy_ab;
10153 int ret = -ENOTSUP;
10156 status = i40e_aq_get_phy_capabilities(hw, false, true, &phy_ab,
10160 PMD_INIT_LOG(WARNING, "Failed to sync phy type: status=%d",
10163 rte_delay_us(100000);
10165 status = i40e_aq_get_phy_capabilities(hw, false,
10166 true, &phy_ab, NULL);
10174 i40e_configure_registers(struct i40e_hw *hw)
10180 {I40E_GL_SWR_PRI_JOIN_MAP_0, 0},
10181 {I40E_GL_SWR_PRI_JOIN_MAP_2, 0},
10182 {I40E_GL_SWR_PM_UP_THR, 0}, /* Compute value dynamically */
10188 for (i = 0; i < RTE_DIM(reg_table); i++) {
10189 if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_0) {
10190 if (hw->mac.type == I40E_MAC_X722) /* For X722 */
10192 I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE;
10193 else /* For X710/XL710/XXV710 */
10194 if (hw->aq.fw_maj_ver < 6)
10196 I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1;
10199 I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2;
10202 if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_2) {
10203 if (hw->mac.type == I40E_MAC_X722) /* For X722 */
10205 I40E_X722_GL_SWR_PRI_JOIN_MAP_2_VALUE;
10206 else /* For X710/XL710/XXV710 */
10208 I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE;
10211 if (reg_table[i].addr == I40E_GL_SWR_PM_UP_THR) {
10214 if (!i40e_get_swr_pm_cfg(hw, &cfg_val)) {
10215 PMD_DRV_LOG(DEBUG, "Device 0x%x skips "
10216 "GL_SWR_PM_UP_THR value fixup",
10221 reg_table[i].val = cfg_val;
10224 ret = i40e_aq_debug_read_register(hw, reg_table[i].addr,
10227 PMD_DRV_LOG(ERR, "Failed to read from 0x%"PRIx32,
10228 reg_table[i].addr);
10231 PMD_DRV_LOG(DEBUG, "Read from 0x%"PRIx32": 0x%"PRIx64,
10232 reg_table[i].addr, reg);
10233 if (reg == reg_table[i].val)
10236 ret = i40e_aq_debug_write_register(hw, reg_table[i].addr,
10237 reg_table[i].val, NULL);
10240 "Failed to write 0x%"PRIx64" to the address of 0x%"PRIx32,
10241 reg_table[i].val, reg_table[i].addr);
10244 PMD_DRV_LOG(DEBUG, "Write 0x%"PRIx64" to the address of "
10245 "0x%"PRIx32, reg_table[i].val, reg_table[i].addr);
10249 #define I40E_VSI_TSR_QINQ_CONFIG 0xc030
10250 #define I40E_VSI_L2TAGSTXVALID(_i) (0x00042800 + ((_i) * 4))
10251 #define I40E_VSI_L2TAGSTXVALID_QINQ 0xab
10253 i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi)
10258 if (vsi->vsi_id >= I40E_MAX_NUM_VSIS) {
10259 PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
10263 /* Configure for double VLAN RX stripping */
10264 reg = I40E_READ_REG(hw, I40E_VSI_TSR(vsi->vsi_id));
10265 if ((reg & I40E_VSI_TSR_QINQ_CONFIG) != I40E_VSI_TSR_QINQ_CONFIG) {
10266 reg |= I40E_VSI_TSR_QINQ_CONFIG;
10267 ret = i40e_aq_debug_write_register(hw,
10268 I40E_VSI_TSR(vsi->vsi_id),
10271 PMD_DRV_LOG(ERR, "Failed to update VSI_TSR[%d]",
10273 return I40E_ERR_CONFIG;
10277 /* Configure for double VLAN TX insertion */
10278 reg = I40E_READ_REG(hw, I40E_VSI_L2TAGSTXVALID(vsi->vsi_id));
10279 if ((reg & 0xff) != I40E_VSI_L2TAGSTXVALID_QINQ) {
10280 reg = I40E_VSI_L2TAGSTXVALID_QINQ;
10281 ret = i40e_aq_debug_write_register(hw,
10282 I40E_VSI_L2TAGSTXVALID(
10283 vsi->vsi_id), reg, NULL);
10286 "Failed to update VSI_L2TAGSTXVALID[%d]",
10288 return I40E_ERR_CONFIG;
10296 i40e_read_systime_cyclecounter(struct rte_eth_dev *dev)
10298 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10299 uint64_t systim_cycles;
10301 systim_cycles = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_L);
10302 systim_cycles |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_H)
10305 return systim_cycles;
10309 i40e_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev, uint8_t index)
10311 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10312 uint64_t rx_tstamp;
10314 rx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_L(index));
10315 rx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(index))
10322 i40e_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
10324 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10325 uint64_t tx_tstamp;
10327 tx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_L);
10328 tx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H)
10335 i40e_start_timecounters(struct rte_eth_dev *dev)
10337 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10338 struct i40e_adapter *adapter = dev->data->dev_private;
10339 struct rte_eth_link link;
10340 uint32_t tsync_inc_l;
10341 uint32_t tsync_inc_h;
10343 /* Get current link speed. */
10344 i40e_dev_link_update(dev, 1);
10345 rte_eth_linkstatus_get(dev, &link);
10347 switch (link.link_speed) {
10348 case RTE_ETH_SPEED_NUM_40G:
10349 case RTE_ETH_SPEED_NUM_25G:
10350 tsync_inc_l = I40E_PTP_40GB_INCVAL & 0xFFFFFFFF;
10351 tsync_inc_h = I40E_PTP_40GB_INCVAL >> 32;
10353 case RTE_ETH_SPEED_NUM_10G:
10354 tsync_inc_l = I40E_PTP_10GB_INCVAL & 0xFFFFFFFF;
10355 tsync_inc_h = I40E_PTP_10GB_INCVAL >> 32;
10357 case RTE_ETH_SPEED_NUM_1G:
10358 tsync_inc_l = I40E_PTP_1GB_INCVAL & 0xFFFFFFFF;
10359 tsync_inc_h = I40E_PTP_1GB_INCVAL >> 32;
10366 /* Set the timesync increment value. */
10367 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, tsync_inc_l);
10368 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, tsync_inc_h);
10370 memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
10371 memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
10372 memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
10374 adapter->systime_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10375 adapter->systime_tc.cc_shift = 0;
10376 adapter->systime_tc.nsec_mask = 0;
10378 adapter->rx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10379 adapter->rx_tstamp_tc.cc_shift = 0;
10380 adapter->rx_tstamp_tc.nsec_mask = 0;
10382 adapter->tx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10383 adapter->tx_tstamp_tc.cc_shift = 0;
10384 adapter->tx_tstamp_tc.nsec_mask = 0;
10388 i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
10390 struct i40e_adapter *adapter = dev->data->dev_private;
10392 adapter->systime_tc.nsec += delta;
10393 adapter->rx_tstamp_tc.nsec += delta;
10394 adapter->tx_tstamp_tc.nsec += delta;
10400 i40e_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
10403 struct i40e_adapter *adapter = dev->data->dev_private;
10405 ns = rte_timespec_to_ns(ts);
10407 /* Set the timecounters to a new value. */
10408 adapter->systime_tc.nsec = ns;
10409 adapter->rx_tstamp_tc.nsec = ns;
10410 adapter->tx_tstamp_tc.nsec = ns;
10416 i40e_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
10418 uint64_t ns, systime_cycles;
10419 struct i40e_adapter *adapter = dev->data->dev_private;
10421 systime_cycles = i40e_read_systime_cyclecounter(dev);
10422 ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
10423 *ts = rte_ns_to_timespec(ns);
10429 i40e_timesync_enable(struct rte_eth_dev *dev)
10431 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10432 uint32_t tsync_ctl_l;
10433 uint32_t tsync_ctl_h;
10435 /* Stop the timesync system time. */
10436 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
10437 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
10438 /* Reset the timesync system time value. */
10439 I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_L, 0x0);
10440 I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_H, 0x0);
10442 i40e_start_timecounters(dev);
10444 /* Clear timesync registers. */
10445 I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
10446 I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H);
10447 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(0));
10448 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(1));
10449 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(2));
10450 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(3));
10452 /* Enable timestamping of PTP packets. */
10453 tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
10454 tsync_ctl_l |= I40E_PRTTSYN_TSYNENA;
10456 tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
10457 tsync_ctl_h |= I40E_PRTTSYN_TSYNENA;
10458 tsync_ctl_h |= I40E_PRTTSYN_TSYNTYPE;
10460 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
10461 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
10467 i40e_timesync_disable(struct rte_eth_dev *dev)
10469 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10470 uint32_t tsync_ctl_l;
10471 uint32_t tsync_ctl_h;
10473 /* Disable timestamping of transmitted PTP packets. */
10474 tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
10475 tsync_ctl_l &= ~I40E_PRTTSYN_TSYNENA;
10477 tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
10478 tsync_ctl_h &= ~I40E_PRTTSYN_TSYNENA;
10480 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
10481 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
10483 /* Reset the timesync increment value. */
10484 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
10485 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
10491 i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
10492 struct timespec *timestamp, uint32_t flags)
10494 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10495 struct i40e_adapter *adapter = dev->data->dev_private;
10496 uint32_t sync_status;
10497 uint32_t index = flags & 0x03;
10498 uint64_t rx_tstamp_cycles;
10501 sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_1);
10502 if ((sync_status & (1 << index)) == 0)
10505 rx_tstamp_cycles = i40e_read_rx_tstamp_cyclecounter(dev, index);
10506 ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
10507 *timestamp = rte_ns_to_timespec(ns);
10513 i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
10514 struct timespec *timestamp)
10516 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10517 struct i40e_adapter *adapter = dev->data->dev_private;
10518 uint32_t sync_status;
10519 uint64_t tx_tstamp_cycles;
10522 sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
10523 if ((sync_status & I40E_PRTTSYN_STAT_0_TXTIME_MASK) == 0)
10526 tx_tstamp_cycles = i40e_read_tx_tstamp_cyclecounter(dev);
10527 ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
10528 *timestamp = rte_ns_to_timespec(ns);
10534 * i40e_parse_dcb_configure - parse dcb configure from user
10535 * @dev: the device being configured
10536 * @dcb_cfg: pointer of the result of parse
10537 * @*tc_map: bit map of enabled traffic classes
10539 * Returns 0 on success, negative value on failure
10542 i40e_parse_dcb_configure(struct rte_eth_dev *dev,
10543 struct i40e_dcbx_config *dcb_cfg,
10546 struct rte_eth_dcb_rx_conf *dcb_rx_conf;
10547 uint8_t i, tc_bw, bw_lf;
10549 memset(dcb_cfg, 0, sizeof(struct i40e_dcbx_config));
10551 dcb_rx_conf = &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
10552 if (dcb_rx_conf->nb_tcs > I40E_MAX_TRAFFIC_CLASS) {
10553 PMD_INIT_LOG(ERR, "number of tc exceeds max.");
10557 /* assume each tc has the same bw */
10558 tc_bw = I40E_MAX_PERCENT / dcb_rx_conf->nb_tcs;
10559 for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
10560 dcb_cfg->etscfg.tcbwtable[i] = tc_bw;
10561 /* to ensure the sum of tcbw is equal to 100 */
10562 bw_lf = I40E_MAX_PERCENT % dcb_rx_conf->nb_tcs;
10563 for (i = 0; i < bw_lf; i++)
10564 dcb_cfg->etscfg.tcbwtable[i]++;
10566 /* assume each tc has the same Transmission Selection Algorithm */
10567 for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
10568 dcb_cfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
10570 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
10571 dcb_cfg->etscfg.prioritytable[i] =
10572 dcb_rx_conf->dcb_tc[i];
10574 /* FW needs one App to configure HW */
10575 dcb_cfg->numapps = I40E_DEFAULT_DCB_APP_NUM;
10576 dcb_cfg->app[0].selector = I40E_APP_SEL_ETHTYPE;
10577 dcb_cfg->app[0].priority = I40E_DEFAULT_DCB_APP_PRIO;
10578 dcb_cfg->app[0].protocolid = I40E_APP_PROTOID_FCOE;
10580 if (dcb_rx_conf->nb_tcs == 0)
10581 *tc_map = 1; /* tc0 only */
10583 *tc_map = RTE_LEN2MASK(dcb_rx_conf->nb_tcs, uint8_t);
10585 if (dev->data->dev_conf.dcb_capability_en & RTE_ETH_DCB_PFC_SUPPORT) {
10586 dcb_cfg->pfc.willing = 0;
10587 dcb_cfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
10588 dcb_cfg->pfc.pfcenable = *tc_map;
10594 static enum i40e_status_code
10595 i40e_vsi_update_queue_mapping(struct i40e_vsi *vsi,
10596 struct i40e_aqc_vsi_properties_data *info,
10597 uint8_t enabled_tcmap)
10599 enum i40e_status_code ret;
10600 int i, total_tc = 0;
10601 uint16_t qpnum_per_tc, bsf, qp_idx;
10602 struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(vsi);
10603 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
10604 uint16_t used_queues;
10606 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
10607 if (ret != I40E_SUCCESS)
10610 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10611 if (enabled_tcmap & (1 << i))
10616 vsi->enabled_tc = enabled_tcmap;
10618 /* different VSI has different queues assigned */
10619 if (vsi->type == I40E_VSI_MAIN)
10620 used_queues = dev_data->nb_rx_queues -
10621 pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
10622 else if (vsi->type == I40E_VSI_VMDQ2)
10623 used_queues = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
10625 PMD_INIT_LOG(ERR, "unsupported VSI type.");
10626 return I40E_ERR_NO_AVAILABLE_VSI;
10629 qpnum_per_tc = used_queues / total_tc;
10630 /* Number of queues per enabled TC */
10631 if (qpnum_per_tc == 0) {
10632 PMD_INIT_LOG(ERR, " number of queues is less that tcs.");
10633 return I40E_ERR_INVALID_QP_ID;
10635 qpnum_per_tc = RTE_MIN(i40e_align_floor(qpnum_per_tc),
10636 I40E_MAX_Q_PER_TC);
10637 bsf = rte_bsf32(qpnum_per_tc);
10640 * Configure TC and queue mapping parameters, for enabled TC,
10641 * allocate qpnum_per_tc queues to this traffic. For disabled TC,
10642 * default queue will serve it.
10645 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10646 if (vsi->enabled_tc & (1 << i)) {
10647 info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
10648 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
10649 (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
10650 qp_idx += qpnum_per_tc;
10652 info->tc_mapping[i] = 0;
10655 /* Associate queue number with VSI, Keep vsi->nb_qps unchanged */
10656 if (vsi->type == I40E_VSI_SRIOV) {
10657 info->mapping_flags |=
10658 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
10659 for (i = 0; i < vsi->nb_qps; i++)
10660 info->queue_mapping[i] =
10661 rte_cpu_to_le_16(vsi->base_queue + i);
10663 info->mapping_flags |=
10664 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
10665 info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
10667 info->valid_sections |=
10668 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
10670 return I40E_SUCCESS;
10674 * i40e_config_switch_comp_tc - Configure VEB tc setting for given TC map
10675 * @veb: VEB to be configured
10676 * @tc_map: enabled TC bitmap
10678 * Returns 0 on success, negative value on failure
10680 static enum i40e_status_code
10681 i40e_config_switch_comp_tc(struct i40e_veb *veb, uint8_t tc_map)
10683 struct i40e_aqc_configure_switching_comp_bw_config_data veb_bw;
10684 struct i40e_aqc_query_switching_comp_bw_config_resp bw_query;
10685 struct i40e_aqc_query_switching_comp_ets_config_resp ets_query;
10686 struct i40e_hw *hw = I40E_VSI_TO_HW(veb->associate_vsi);
10687 enum i40e_status_code ret = I40E_SUCCESS;
10691 /* Check if enabled_tc is same as existing or new TCs */
10692 if (veb->enabled_tc == tc_map)
10695 /* configure tc bandwidth */
10696 memset(&veb_bw, 0, sizeof(veb_bw));
10697 veb_bw.tc_valid_bits = tc_map;
10698 /* Enable ETS TCs with equal BW Share for now across all VSIs */
10699 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10700 if (tc_map & BIT_ULL(i))
10701 veb_bw.tc_bw_share_credits[i] = 1;
10703 ret = i40e_aq_config_switch_comp_bw_config(hw, veb->seid,
10707 "AQ command Config switch_comp BW allocation per TC failed = %d",
10708 hw->aq.asq_last_status);
10712 memset(&ets_query, 0, sizeof(ets_query));
10713 ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
10715 if (ret != I40E_SUCCESS) {
10717 "Failed to get switch_comp ETS configuration %u",
10718 hw->aq.asq_last_status);
10721 memset(&bw_query, 0, sizeof(bw_query));
10722 ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
10724 if (ret != I40E_SUCCESS) {
10726 "Failed to get switch_comp bandwidth configuration %u",
10727 hw->aq.asq_last_status);
10731 /* store and print out BW info */
10732 veb->bw_info.bw_limit = rte_le_to_cpu_16(ets_query.port_bw_limit);
10733 veb->bw_info.bw_max = ets_query.tc_bw_max;
10734 PMD_DRV_LOG(DEBUG, "switch_comp bw limit:%u", veb->bw_info.bw_limit);
10735 PMD_DRV_LOG(DEBUG, "switch_comp max_bw:%u", veb->bw_info.bw_max);
10736 bw_max = rte_le_to_cpu_16(bw_query.tc_bw_max[0]) |
10737 (rte_le_to_cpu_16(bw_query.tc_bw_max[1]) <<
10738 I40E_16_BIT_WIDTH);
10739 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10740 veb->bw_info.bw_ets_share_credits[i] =
10741 bw_query.tc_bw_share_credits[i];
10742 veb->bw_info.bw_ets_credits[i] =
10743 rte_le_to_cpu_16(bw_query.tc_bw_limits[i]);
10744 /* 4 bits per TC, 4th bit is reserved */
10745 veb->bw_info.bw_ets_max[i] =
10746 (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
10747 RTE_LEN2MASK(3, uint8_t));
10748 PMD_DRV_LOG(DEBUG, "\tVEB TC%u:share credits %u", i,
10749 veb->bw_info.bw_ets_share_credits[i]);
10750 PMD_DRV_LOG(DEBUG, "\tVEB TC%u:credits %u", i,
10751 veb->bw_info.bw_ets_credits[i]);
10752 PMD_DRV_LOG(DEBUG, "\tVEB TC%u: max credits: %u", i,
10753 veb->bw_info.bw_ets_max[i]);
10756 veb->enabled_tc = tc_map;
10763 * i40e_vsi_config_tc - Configure VSI tc setting for given TC map
10764 * @vsi: VSI to be configured
10765 * @tc_map: enabled TC bitmap
10767 * Returns 0 on success, negative value on failure
10769 static enum i40e_status_code
10770 i40e_vsi_config_tc(struct i40e_vsi *vsi, uint8_t tc_map)
10772 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
10773 struct i40e_vsi_context ctxt;
10774 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
10775 enum i40e_status_code ret = I40E_SUCCESS;
10778 /* Check if enabled_tc is same as existing or new TCs */
10779 if (vsi->enabled_tc == tc_map)
10782 /* configure tc bandwidth */
10783 memset(&bw_data, 0, sizeof(bw_data));
10784 bw_data.tc_valid_bits = tc_map;
10785 /* Enable ETS TCs with equal BW Share for now across all VSIs */
10786 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10787 if (tc_map & BIT_ULL(i))
10788 bw_data.tc_bw_credits[i] = 1;
10790 ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &bw_data, NULL);
10793 "AQ command Config VSI BW allocation per TC failed = %d",
10794 hw->aq.asq_last_status);
10797 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
10798 vsi->info.qs_handle[i] = bw_data.qs_handles[i];
10800 /* Update Queue Pairs Mapping for currently enabled UPs */
10801 ctxt.seid = vsi->seid;
10802 ctxt.pf_num = hw->pf_id;
10804 ctxt.uplink_seid = vsi->uplink_seid;
10805 ctxt.info = vsi->info;
10807 ret = i40e_vsi_update_queue_mapping(vsi, &ctxt.info, tc_map);
10811 /* Update the VSI after updating the VSI queue-mapping information */
10812 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
10814 PMD_INIT_LOG(ERR, "Failed to configure TC queue mapping = %d",
10815 hw->aq.asq_last_status);
10818 /* update the local VSI info with updated queue map */
10819 rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
10820 sizeof(vsi->info.tc_mapping));
10821 rte_memcpy(&vsi->info.queue_mapping,
10822 &ctxt.info.queue_mapping,
10823 sizeof(vsi->info.queue_mapping));
10824 vsi->info.mapping_flags = ctxt.info.mapping_flags;
10825 vsi->info.valid_sections = 0;
10827 /* query and update current VSI BW information */
10828 ret = i40e_vsi_get_bw_config(vsi);
10831 "Failed updating vsi bw info, err %s aq_err %s",
10832 i40e_stat_str(hw, ret),
10833 i40e_aq_str(hw, hw->aq.asq_last_status));
10837 vsi->enabled_tc = tc_map;
10844 * i40e_dcb_hw_configure - program the dcb setting to hw
10845 * @pf: pf the configuration is taken on
10846 * @new_cfg: new configuration
10847 * @tc_map: enabled TC bitmap
10849 * Returns 0 on success, negative value on failure
10851 static enum i40e_status_code
10852 i40e_dcb_hw_configure(struct i40e_pf *pf,
10853 struct i40e_dcbx_config *new_cfg,
10856 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
10857 struct i40e_dcbx_config *old_cfg = &hw->local_dcbx_config;
10858 struct i40e_vsi *main_vsi = pf->main_vsi;
10859 struct i40e_vsi_list *vsi_list;
10860 enum i40e_status_code ret;
10864 /* Use the FW API if FW > v4.4*/
10865 if (!(((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver >= 4)) ||
10866 (hw->aq.fw_maj_ver >= 5))) {
10868 "FW < v4.4, can not use FW LLDP API to configure DCB");
10869 return I40E_ERR_FIRMWARE_API_VERSION;
10872 /* Check if need reconfiguration */
10873 if (!memcmp(new_cfg, old_cfg, sizeof(struct i40e_dcbx_config))) {
10874 PMD_INIT_LOG(ERR, "No Change in DCB Config required.");
10875 return I40E_SUCCESS;
10878 /* Copy the new config to the current config */
10879 *old_cfg = *new_cfg;
10880 old_cfg->etsrec = old_cfg->etscfg;
10881 ret = i40e_set_dcb_config(hw);
10883 PMD_INIT_LOG(ERR, "Set DCB Config failed, err %s aq_err %s",
10884 i40e_stat_str(hw, ret),
10885 i40e_aq_str(hw, hw->aq.asq_last_status));
10888 /* set receive Arbiter to RR mode and ETS scheme by default */
10889 for (i = 0; i <= I40E_PRTDCB_RETSTCC_MAX_INDEX; i++) {
10890 val = I40E_READ_REG(hw, I40E_PRTDCB_RETSTCC(i));
10891 val &= ~(I40E_PRTDCB_RETSTCC_BWSHARE_MASK |
10892 I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK |
10893 I40E_PRTDCB_RETSTCC_ETSTC_SHIFT);
10894 val |= ((uint32_t)old_cfg->etscfg.tcbwtable[i] <<
10895 I40E_PRTDCB_RETSTCC_BWSHARE_SHIFT) &
10896 I40E_PRTDCB_RETSTCC_BWSHARE_MASK;
10897 val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_UPINTC_MODE_SHIFT) &
10898 I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK;
10899 val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_ETSTC_SHIFT) &
10900 I40E_PRTDCB_RETSTCC_ETSTC_MASK;
10901 I40E_WRITE_REG(hw, I40E_PRTDCB_RETSTCC(i), val);
10903 /* get local mib to check whether it is configured correctly */
10905 hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_IEEE;
10906 /* Get Local DCB Config */
10907 i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
10908 &hw->local_dcbx_config);
10910 /* if Veb is created, need to update TC of it at first */
10911 if (main_vsi->veb) {
10912 ret = i40e_config_switch_comp_tc(main_vsi->veb, tc_map);
10914 PMD_INIT_LOG(WARNING,
10915 "Failed configuring TC for VEB seid=%d",
10916 main_vsi->veb->seid);
10918 /* Update each VSI */
10919 i40e_vsi_config_tc(main_vsi, tc_map);
10920 if (main_vsi->veb) {
10921 TAILQ_FOREACH(vsi_list, &main_vsi->veb->head, list) {
10922 /* Beside main VSI and VMDQ VSIs, only enable default
10923 * TC for other VSIs
10925 if (vsi_list->vsi->type == I40E_VSI_VMDQ2)
10926 ret = i40e_vsi_config_tc(vsi_list->vsi,
10929 ret = i40e_vsi_config_tc(vsi_list->vsi,
10930 I40E_DEFAULT_TCMAP);
10932 PMD_INIT_LOG(WARNING,
10933 "Failed configuring TC for VSI seid=%d",
10934 vsi_list->vsi->seid);
10938 return I40E_SUCCESS;
10942 * i40e_dcb_init_configure - initial dcb config
10943 * @dev: device being configured
10944 * @sw_dcb: indicate whether dcb is sw configured or hw offload
10946 * Returns 0 on success, negative value on failure
10949 i40e_dcb_init_configure(struct rte_eth_dev *dev, bool sw_dcb)
10951 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
10952 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10955 if ((pf->flags & I40E_FLAG_DCB) == 0) {
10956 PMD_INIT_LOG(ERR, "HW doesn't support DCB");
10960 /* DCB initialization:
10961 * Update DCB configuration from the Firmware and configure
10962 * LLDP MIB change event.
10964 if (sw_dcb == TRUE) {
10965 /* Stopping lldp is necessary for DPDK, but it will cause
10966 * DCB init failed. For i40e_init_dcb(), the prerequisite
10967 * for successful initialization of DCB is that LLDP is
10968 * enabled. So it is needed to start lldp before DCB init
10969 * and stop it after initialization.
10971 ret = i40e_aq_start_lldp(hw, true, NULL);
10972 if (ret != I40E_SUCCESS)
10973 PMD_INIT_LOG(DEBUG, "Failed to start lldp");
10975 ret = i40e_init_dcb(hw, true);
10976 /* If lldp agent is stopped, the return value from
10977 * i40e_init_dcb we expect is failure with I40E_AQ_RC_EPERM
10978 * adminq status. Otherwise, it should return success.
10980 if ((ret == I40E_SUCCESS) || (ret != I40E_SUCCESS &&
10981 hw->aq.asq_last_status == I40E_AQ_RC_EPERM)) {
10982 memset(&hw->local_dcbx_config, 0,
10983 sizeof(struct i40e_dcbx_config));
10984 /* set dcb default configuration */
10985 hw->local_dcbx_config.etscfg.willing = 0;
10986 hw->local_dcbx_config.etscfg.maxtcs = 0;
10987 hw->local_dcbx_config.etscfg.tcbwtable[0] = 100;
10988 hw->local_dcbx_config.etscfg.tsatable[0] =
10990 /* all UPs mapping to TC0 */
10991 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
10992 hw->local_dcbx_config.etscfg.prioritytable[i] = 0;
10993 hw->local_dcbx_config.etsrec =
10994 hw->local_dcbx_config.etscfg;
10995 hw->local_dcbx_config.pfc.willing = 0;
10996 hw->local_dcbx_config.pfc.pfccap =
10997 I40E_MAX_TRAFFIC_CLASS;
10998 /* FW needs one App to configure HW */
10999 hw->local_dcbx_config.numapps = 1;
11000 hw->local_dcbx_config.app[0].selector =
11001 I40E_APP_SEL_ETHTYPE;
11002 hw->local_dcbx_config.app[0].priority = 3;
11003 hw->local_dcbx_config.app[0].protocolid =
11004 I40E_APP_PROTOID_FCOE;
11005 ret = i40e_set_dcb_config(hw);
11008 "default dcb config fails. err = %d, aq_err = %d.",
11009 ret, hw->aq.asq_last_status);
11014 "DCB initialization in FW fails, err = %d, aq_err = %d.",
11015 ret, hw->aq.asq_last_status);
11019 if (i40e_need_stop_lldp(dev)) {
11020 ret = i40e_aq_stop_lldp(hw, true, true, NULL);
11021 if (ret != I40E_SUCCESS)
11022 PMD_INIT_LOG(DEBUG, "Failed to stop lldp");
11025 ret = i40e_aq_start_lldp(hw, true, NULL);
11026 if (ret != I40E_SUCCESS)
11027 PMD_INIT_LOG(DEBUG, "Failed to start lldp");
11029 ret = i40e_init_dcb(hw, true);
11031 if (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED) {
11033 "HW doesn't support DCBX offload.");
11038 "DCBX configuration failed, err = %d, aq_err = %d.",
11039 ret, hw->aq.asq_last_status);
11047 * i40e_dcb_setup - setup dcb related config
11048 * @dev: device being configured
11050 * Returns 0 on success, negative value on failure
11053 i40e_dcb_setup(struct rte_eth_dev *dev)
11055 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11056 struct i40e_dcbx_config dcb_cfg;
11057 uint8_t tc_map = 0;
11060 if ((pf->flags & I40E_FLAG_DCB) == 0) {
11061 PMD_INIT_LOG(ERR, "HW doesn't support DCB");
11065 if (pf->vf_num != 0)
11066 PMD_INIT_LOG(DEBUG, " DCB only works on pf and vmdq vsis.");
11068 ret = i40e_parse_dcb_configure(dev, &dcb_cfg, &tc_map);
11070 PMD_INIT_LOG(ERR, "invalid dcb config");
11073 ret = i40e_dcb_hw_configure(pf, &dcb_cfg, tc_map);
11075 PMD_INIT_LOG(ERR, "dcb sw configure fails");
11083 i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
11084 struct rte_eth_dcb_info *dcb_info)
11086 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11087 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11088 struct i40e_vsi *vsi = pf->main_vsi;
11089 struct i40e_dcbx_config *dcb_cfg = &hw->local_dcbx_config;
11090 uint16_t bsf, tc_mapping;
11093 if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_DCB_FLAG)
11094 dcb_info->nb_tcs = rte_bsf32(vsi->enabled_tc + 1);
11096 dcb_info->nb_tcs = 1;
11097 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
11098 dcb_info->prio_tc[i] = dcb_cfg->etscfg.prioritytable[i];
11099 for (i = 0; i < dcb_info->nb_tcs; i++)
11100 dcb_info->tc_bws[i] = dcb_cfg->etscfg.tcbwtable[i];
11102 /* get queue mapping if vmdq is disabled */
11103 if (!pf->nb_cfg_vmdq_vsi) {
11104 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11105 if (!(vsi->enabled_tc & (1 << i)))
11107 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
11108 dcb_info->tc_queue.tc_rxq[j][i].base =
11109 (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
11110 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
11111 dcb_info->tc_queue.tc_txq[j][i].base =
11112 dcb_info->tc_queue.tc_rxq[j][i].base;
11113 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
11114 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
11115 dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
11116 dcb_info->tc_queue.tc_txq[j][i].nb_queue =
11117 dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
11122 /* get queue mapping if vmdq is enabled */
11124 vsi = pf->vmdq[j].vsi;
11125 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11126 if (!(vsi->enabled_tc & (1 << i)))
11128 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
11129 dcb_info->tc_queue.tc_rxq[j][i].base =
11130 (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
11131 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
11132 dcb_info->tc_queue.tc_txq[j][i].base =
11133 dcb_info->tc_queue.tc_rxq[j][i].base;
11134 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
11135 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
11136 dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
11137 dcb_info->tc_queue.tc_txq[j][i].nb_queue =
11138 dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
11141 } while (j < RTE_MIN(pf->nb_cfg_vmdq_vsi, RTE_ETH_MAX_VMDQ_POOL));
11146 i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
11148 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
11149 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
11150 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11151 uint16_t msix_intr;
11153 msix_intr = rte_intr_vec_list_index_get(intr_handle, queue_id);
11154 if (msix_intr == I40E_MISC_VEC_ID)
11155 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
11156 I40E_PFINT_DYN_CTL0_INTENA_MASK |
11157 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
11158 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
11161 I40E_PFINT_DYN_CTLN(msix_intr -
11162 I40E_RX_VEC_START),
11163 I40E_PFINT_DYN_CTLN_INTENA_MASK |
11164 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
11165 I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
11167 I40E_WRITE_FLUSH(hw);
11168 rte_intr_ack(pci_dev->intr_handle);
11174 i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
11176 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
11177 struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
11178 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11179 uint16_t msix_intr;
11181 msix_intr = rte_intr_vec_list_index_get(intr_handle, queue_id);
11182 if (msix_intr == I40E_MISC_VEC_ID)
11183 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
11184 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
11187 I40E_PFINT_DYN_CTLN(msix_intr -
11188 I40E_RX_VEC_START),
11189 I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
11190 I40E_WRITE_FLUSH(hw);
11196 * This function is used to check if the register is valid.
11197 * Below is the valid registers list for X722 only:
11201 * 0x208e00--0x209000
11202 * 0x20be00--0x20c000
11203 * 0x263c00--0x264000
11204 * 0x265c00--0x266000
11206 static inline int i40e_valid_regs(enum i40e_mac_type type, uint32_t reg_offset)
11208 if ((type != I40E_MAC_X722) &&
11209 ((reg_offset >= 0x2b800 && reg_offset <= 0x2bb00) ||
11210 (reg_offset >= 0x38700 && reg_offset <= 0x38a00) ||
11211 (reg_offset >= 0x3d800 && reg_offset <= 0x3db00) ||
11212 (reg_offset >= 0x208e00 && reg_offset <= 0x209000) ||
11213 (reg_offset >= 0x20be00 && reg_offset <= 0x20c000) ||
11214 (reg_offset >= 0x263c00 && reg_offset <= 0x264000) ||
11215 (reg_offset >= 0x265c00 && reg_offset <= 0x266000)))
11221 static int i40e_get_regs(struct rte_eth_dev *dev,
11222 struct rte_dev_reg_info *regs)
11224 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11225 uint32_t *ptr_data = regs->data;
11226 uint32_t reg_idx, arr_idx, arr_idx2, reg_offset;
11227 const struct i40e_reg_info *reg_info;
11229 if (ptr_data == NULL) {
11230 regs->length = I40E_GLGEN_STAT_CLEAR + 4;
11231 regs->width = sizeof(uint32_t);
11235 /* The first few registers have to be read using AQ operations */
11237 while (i40e_regs_adminq[reg_idx].name) {
11238 reg_info = &i40e_regs_adminq[reg_idx++];
11239 for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
11241 arr_idx2 <= reg_info->count2;
11243 reg_offset = arr_idx * reg_info->stride1 +
11244 arr_idx2 * reg_info->stride2;
11245 reg_offset += reg_info->base_addr;
11246 ptr_data[reg_offset >> 2] =
11247 i40e_read_rx_ctl(hw, reg_offset);
11251 /* The remaining registers can be read using primitives */
11253 while (i40e_regs_others[reg_idx].name) {
11254 reg_info = &i40e_regs_others[reg_idx++];
11255 for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
11257 arr_idx2 <= reg_info->count2;
11259 reg_offset = arr_idx * reg_info->stride1 +
11260 arr_idx2 * reg_info->stride2;
11261 reg_offset += reg_info->base_addr;
11262 if (!i40e_valid_regs(hw->mac.type, reg_offset))
11263 ptr_data[reg_offset >> 2] = 0;
11265 ptr_data[reg_offset >> 2] =
11266 I40E_READ_REG(hw, reg_offset);
11273 static int i40e_get_eeprom_length(struct rte_eth_dev *dev)
11275 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11277 /* Convert word count to byte count */
11278 return hw->nvm.sr_size << 1;
11281 static int i40e_get_eeprom(struct rte_eth_dev *dev,
11282 struct rte_dev_eeprom_info *eeprom)
11284 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11285 uint16_t *data = eeprom->data;
11286 uint16_t offset, length, cnt_words;
11289 offset = eeprom->offset >> 1;
11290 length = eeprom->length >> 1;
11291 cnt_words = length;
11293 if (offset > hw->nvm.sr_size ||
11294 offset + length > hw->nvm.sr_size) {
11295 PMD_DRV_LOG(ERR, "Requested EEPROM bytes out of range.");
11299 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
11301 ret_code = i40e_read_nvm_buffer(hw, offset, &cnt_words, data);
11302 if (ret_code != I40E_SUCCESS || cnt_words != length) {
11303 PMD_DRV_LOG(ERR, "EEPROM read failed.");
11310 static int i40e_get_module_info(struct rte_eth_dev *dev,
11311 struct rte_eth_dev_module_info *modinfo)
11313 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11314 uint32_t sff8472_comp = 0;
11315 uint32_t sff8472_swap = 0;
11316 uint32_t sff8636_rev = 0;
11317 i40e_status status;
11320 /* Check if firmware supports reading module EEPROM. */
11321 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
11323 "Module EEPROM memory read not supported. "
11324 "Please update the NVM image.\n");
11328 status = i40e_update_link_info(hw);
11332 if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
11334 "Cannot read module EEPROM memory. "
11335 "No module connected.\n");
11339 type = hw->phy.link_info.module_type[0];
11342 case I40E_MODULE_TYPE_SFP:
11343 status = i40e_aq_get_phy_register(hw,
11344 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11345 I40E_I2C_EEPROM_DEV_ADDR, 1,
11346 I40E_MODULE_SFF_8472_COMP,
11347 &sff8472_comp, NULL);
11351 status = i40e_aq_get_phy_register(hw,
11352 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11353 I40E_I2C_EEPROM_DEV_ADDR, 1,
11354 I40E_MODULE_SFF_8472_SWAP,
11355 &sff8472_swap, NULL);
11359 /* Check if the module requires address swap to access
11360 * the other EEPROM memory page.
11362 if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
11363 PMD_DRV_LOG(WARNING,
11364 "Module address swap to access "
11365 "page 0xA2 is not supported.\n");
11366 modinfo->type = RTE_ETH_MODULE_SFF_8079;
11367 modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
11368 } else if (sff8472_comp == 0x00) {
11369 /* Module is not SFF-8472 compliant */
11370 modinfo->type = RTE_ETH_MODULE_SFF_8079;
11371 modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
11373 modinfo->type = RTE_ETH_MODULE_SFF_8472;
11374 modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8472_LEN;
11377 case I40E_MODULE_TYPE_QSFP_PLUS:
11378 /* Read from memory page 0. */
11379 status = i40e_aq_get_phy_register(hw,
11380 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11382 I40E_MODULE_REVISION_ADDR,
11383 &sff8636_rev, NULL);
11386 /* Determine revision compliance byte */
11387 if (sff8636_rev > 0x02) {
11388 /* Module is SFF-8636 compliant */
11389 modinfo->type = RTE_ETH_MODULE_SFF_8636;
11390 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
11392 modinfo->type = RTE_ETH_MODULE_SFF_8436;
11393 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
11396 case I40E_MODULE_TYPE_QSFP28:
11397 modinfo->type = RTE_ETH_MODULE_SFF_8636;
11398 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
11401 PMD_DRV_LOG(ERR, "Module type unrecognized\n");
11407 static int i40e_get_module_eeprom(struct rte_eth_dev *dev,
11408 struct rte_dev_eeprom_info *info)
11410 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11411 bool is_sfp = false;
11412 i40e_status status;
11414 uint32_t value = 0;
11417 if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
11421 for (i = 0; i < info->length; i++) {
11422 u32 offset = i + info->offset;
11423 u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
11425 /* Check if we need to access the other memory page */
11427 if (offset >= RTE_ETH_MODULE_SFF_8079_LEN) {
11428 offset -= RTE_ETH_MODULE_SFF_8079_LEN;
11429 addr = I40E_I2C_EEPROM_DEV_ADDR2;
11432 while (offset >= RTE_ETH_MODULE_SFF_8436_LEN) {
11433 /* Compute memory page number and offset. */
11434 offset -= RTE_ETH_MODULE_SFF_8436_LEN / 2;
11438 status = i40e_aq_get_phy_register(hw,
11439 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11440 addr, 1, offset, &value, NULL);
11443 data[i] = (uint8_t)value;
11448 static int i40e_set_default_mac_addr(struct rte_eth_dev *dev,
11449 struct rte_ether_addr *mac_addr)
11451 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11452 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11453 struct i40e_vsi *vsi = pf->main_vsi;
11454 struct i40e_mac_filter_info mac_filter;
11455 struct i40e_mac_filter *f;
11458 if (!rte_is_valid_assigned_ether_addr(mac_addr)) {
11459 PMD_DRV_LOG(ERR, "Tried to set invalid MAC address.");
11463 TAILQ_FOREACH(f, &vsi->mac_list, next) {
11464 if (rte_is_same_ether_addr(&pf->dev_addr,
11465 &f->mac_info.mac_addr))
11470 PMD_DRV_LOG(ERR, "Failed to find filter for default mac");
11474 mac_filter = f->mac_info;
11475 ret = i40e_vsi_delete_mac(vsi, &mac_filter.mac_addr);
11476 if (ret != I40E_SUCCESS) {
11477 PMD_DRV_LOG(ERR, "Failed to delete mac filter");
11480 memcpy(&mac_filter.mac_addr, mac_addr, ETH_ADDR_LEN);
11481 ret = i40e_vsi_add_mac(vsi, &mac_filter);
11482 if (ret != I40E_SUCCESS) {
11483 PMD_DRV_LOG(ERR, "Failed to add mac filter");
11486 memcpy(&pf->dev_addr, mac_addr, ETH_ADDR_LEN);
11488 ret = i40e_aq_mac_address_write(hw, I40E_AQC_WRITE_TYPE_LAA_WOL,
11489 mac_addr->addr_bytes, NULL);
11490 if (ret != I40E_SUCCESS) {
11491 PMD_DRV_LOG(ERR, "Failed to change mac");
11499 i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu __rte_unused)
11501 /* mtu setting is forbidden if port is start */
11502 if (dev->data->dev_started != 0) {
11503 PMD_DRV_LOG(ERR, "port %d must be stopped before configuration",
11504 dev->data->port_id);
11511 /* Restore ethertype filter */
11513 i40e_ethertype_filter_restore(struct i40e_pf *pf)
11515 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11516 struct i40e_ethertype_filter_list
11517 *ethertype_list = &pf->ethertype.ethertype_list;
11518 struct i40e_ethertype_filter *f;
11519 struct i40e_control_filter_stats stats;
11522 TAILQ_FOREACH(f, ethertype_list, rules) {
11524 if (!(f->flags & RTE_ETHTYPE_FLAGS_MAC))
11525 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
11526 if (f->flags & RTE_ETHTYPE_FLAGS_DROP)
11527 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
11528 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
11530 memset(&stats, 0, sizeof(stats));
11531 i40e_aq_add_rem_control_packet_filter(hw,
11532 f->input.mac_addr.addr_bytes,
11533 f->input.ether_type,
11534 flags, pf->main_vsi->seid,
11535 f->queue, 1, &stats, NULL);
11537 PMD_DRV_LOG(INFO, "Ethertype filter:"
11538 " mac_etype_used = %u, etype_used = %u,"
11539 " mac_etype_free = %u, etype_free = %u",
11540 stats.mac_etype_used, stats.etype_used,
11541 stats.mac_etype_free, stats.etype_free);
11544 /* Restore tunnel filter */
11546 i40e_tunnel_filter_restore(struct i40e_pf *pf)
11548 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11549 struct i40e_vsi *vsi;
11550 struct i40e_pf_vf *vf;
11551 struct i40e_tunnel_filter_list
11552 *tunnel_list = &pf->tunnel.tunnel_list;
11553 struct i40e_tunnel_filter *f;
11554 struct i40e_aqc_cloud_filters_element_bb cld_filter;
11555 bool big_buffer = 0;
11557 TAILQ_FOREACH(f, tunnel_list, rules) {
11559 vsi = pf->main_vsi;
11561 vf = &pf->vfs[f->vf_id];
11564 memset(&cld_filter, 0, sizeof(cld_filter));
11565 rte_ether_addr_copy((struct rte_ether_addr *)
11566 &f->input.outer_mac,
11567 (struct rte_ether_addr *)&cld_filter.element.outer_mac);
11568 rte_ether_addr_copy((struct rte_ether_addr *)
11569 &f->input.inner_mac,
11570 (struct rte_ether_addr *)&cld_filter.element.inner_mac);
11571 cld_filter.element.inner_vlan = f->input.inner_vlan;
11572 cld_filter.element.flags = f->input.flags;
11573 cld_filter.element.tenant_id = f->input.tenant_id;
11574 cld_filter.element.queue_number = f->queue;
11575 rte_memcpy(cld_filter.general_fields,
11576 f->input.general_fields,
11577 sizeof(f->input.general_fields));
11579 if (((f->input.flags &
11580 I40E_AQC_ADD_CLOUD_FILTER_0X11) ==
11581 I40E_AQC_ADD_CLOUD_FILTER_0X11) ||
11583 I40E_AQC_ADD_CLOUD_FILTER_0X12) ==
11584 I40E_AQC_ADD_CLOUD_FILTER_0X12) ||
11586 I40E_AQC_ADD_CLOUD_FILTER_0X10) ==
11587 I40E_AQC_ADD_CLOUD_FILTER_0X10))
11591 i40e_aq_add_cloud_filters_bb(hw,
11592 vsi->seid, &cld_filter, 1);
11594 i40e_aq_add_cloud_filters(hw, vsi->seid,
11595 &cld_filter.element, 1);
11600 i40e_filter_restore(struct i40e_pf *pf)
11602 i40e_ethertype_filter_restore(pf);
11603 i40e_tunnel_filter_restore(pf);
11604 i40e_fdir_filter_restore(pf);
11605 (void)i40e_hash_filter_restore(pf);
11609 is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
11611 if (strcmp(dev->device->driver->name, drv->driver.name))
11618 is_i40e_supported(struct rte_eth_dev *dev)
11620 return is_device_supported(dev, &rte_i40e_pmd);
11623 struct i40e_customized_pctype*
11624 i40e_find_customized_pctype(struct i40e_pf *pf, uint8_t index)
11628 for (i = 0; i < I40E_CUSTOMIZED_MAX; i++) {
11629 if (pf->customized_pctype[i].index == index)
11630 return &pf->customized_pctype[i];
11636 i40e_update_customized_pctype(struct rte_eth_dev *dev, uint8_t *pkg,
11637 uint32_t pkg_size, uint32_t proto_num,
11638 struct rte_pmd_i40e_proto_info *proto,
11639 enum rte_pmd_i40e_package_op op)
11641 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11642 uint32_t pctype_num;
11643 struct rte_pmd_i40e_ptype_info *pctype;
11644 uint32_t buff_size;
11645 struct i40e_customized_pctype *new_pctype = NULL;
11647 uint8_t pctype_value;
11652 if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
11653 op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
11654 PMD_DRV_LOG(ERR, "Unsupported operation.");
11658 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11659 (uint8_t *)&pctype_num, sizeof(pctype_num),
11660 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
11662 PMD_DRV_LOG(ERR, "Failed to get pctype number");
11666 PMD_DRV_LOG(INFO, "No new pctype added");
11670 buff_size = pctype_num * sizeof(struct rte_pmd_i40e_proto_info);
11671 pctype = rte_zmalloc("new_pctype", buff_size, 0);
11673 PMD_DRV_LOG(ERR, "Failed to allocate memory");
11676 /* get information about new pctype list */
11677 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11678 (uint8_t *)pctype, buff_size,
11679 RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
11681 PMD_DRV_LOG(ERR, "Failed to get pctype list");
11686 /* Update customized pctype. */
11687 for (i = 0; i < pctype_num; i++) {
11688 pctype_value = pctype[i].ptype_id;
11689 memset(name, 0, sizeof(name));
11690 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
11691 proto_id = pctype[i].protocols[j];
11692 if (proto_id == RTE_PMD_I40E_PROTO_UNUSED)
11694 for (n = 0; n < proto_num; n++) {
11695 if (proto[n].proto_id != proto_id)
11697 strlcat(name, proto[n].name, sizeof(name));
11698 strlcat(name, "_", sizeof(name));
11702 name[strlen(name) - 1] = '\0';
11703 PMD_DRV_LOG(INFO, "name = %s\n", name);
11704 if (!strcmp(name, "GTPC"))
11706 i40e_find_customized_pctype(pf,
11707 I40E_CUSTOMIZED_GTPC);
11708 else if (!strcmp(name, "GTPU_IPV4"))
11710 i40e_find_customized_pctype(pf,
11711 I40E_CUSTOMIZED_GTPU_IPV4);
11712 else if (!strcmp(name, "GTPU_IPV6"))
11714 i40e_find_customized_pctype(pf,
11715 I40E_CUSTOMIZED_GTPU_IPV6);
11716 else if (!strcmp(name, "GTPU"))
11718 i40e_find_customized_pctype(pf,
11719 I40E_CUSTOMIZED_GTPU);
11720 else if (!strcmp(name, "IPV4_L2TPV3"))
11722 i40e_find_customized_pctype(pf,
11723 I40E_CUSTOMIZED_IPV4_L2TPV3);
11724 else if (!strcmp(name, "IPV6_L2TPV3"))
11726 i40e_find_customized_pctype(pf,
11727 I40E_CUSTOMIZED_IPV6_L2TPV3);
11728 else if (!strcmp(name, "IPV4_ESP"))
11730 i40e_find_customized_pctype(pf,
11731 I40E_CUSTOMIZED_ESP_IPV4);
11732 else if (!strcmp(name, "IPV6_ESP"))
11734 i40e_find_customized_pctype(pf,
11735 I40E_CUSTOMIZED_ESP_IPV6);
11736 else if (!strcmp(name, "IPV4_UDP_ESP"))
11738 i40e_find_customized_pctype(pf,
11739 I40E_CUSTOMIZED_ESP_IPV4_UDP);
11740 else if (!strcmp(name, "IPV6_UDP_ESP"))
11742 i40e_find_customized_pctype(pf,
11743 I40E_CUSTOMIZED_ESP_IPV6_UDP);
11744 else if (!strcmp(name, "IPV4_AH"))
11746 i40e_find_customized_pctype(pf,
11747 I40E_CUSTOMIZED_AH_IPV4);
11748 else if (!strcmp(name, "IPV6_AH"))
11750 i40e_find_customized_pctype(pf,
11751 I40E_CUSTOMIZED_AH_IPV6);
11753 if (op == RTE_PMD_I40E_PKG_OP_WR_ADD) {
11754 new_pctype->pctype = pctype_value;
11755 new_pctype->valid = true;
11757 new_pctype->pctype = I40E_FILTER_PCTYPE_INVALID;
11758 new_pctype->valid = false;
11768 i40e_update_customized_ptype(struct rte_eth_dev *dev, uint8_t *pkg,
11769 uint32_t pkg_size, uint32_t proto_num,
11770 struct rte_pmd_i40e_proto_info *proto,
11771 enum rte_pmd_i40e_package_op op)
11773 struct rte_pmd_i40e_ptype_mapping *ptype_mapping;
11774 uint16_t port_id = dev->data->port_id;
11775 uint32_t ptype_num;
11776 struct rte_pmd_i40e_ptype_info *ptype;
11777 uint32_t buff_size;
11779 char name[RTE_PMD_I40E_DDP_NAME_SIZE];
11784 if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
11785 op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
11786 PMD_DRV_LOG(ERR, "Unsupported operation.");
11790 if (op == RTE_PMD_I40E_PKG_OP_WR_DEL) {
11791 rte_pmd_i40e_ptype_mapping_reset(port_id);
11795 /* get information about new ptype num */
11796 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11797 (uint8_t *)&ptype_num, sizeof(ptype_num),
11798 RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
11800 PMD_DRV_LOG(ERR, "Failed to get ptype number");
11804 PMD_DRV_LOG(INFO, "No new ptype added");
11808 buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
11809 ptype = rte_zmalloc("new_ptype", buff_size, 0);
11811 PMD_DRV_LOG(ERR, "Failed to allocate memory");
11815 /* get information about new ptype list */
11816 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11817 (uint8_t *)ptype, buff_size,
11818 RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
11820 PMD_DRV_LOG(ERR, "Failed to get ptype list");
11825 buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_mapping);
11826 ptype_mapping = rte_zmalloc("ptype_mapping", buff_size, 0);
11827 if (!ptype_mapping) {
11828 PMD_DRV_LOG(ERR, "Failed to allocate memory");
11833 /* Update ptype mapping table. */
11834 for (i = 0; i < ptype_num; i++) {
11835 ptype_mapping[i].hw_ptype = ptype[i].ptype_id;
11836 ptype_mapping[i].sw_ptype = 0;
11838 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
11839 proto_id = ptype[i].protocols[j];
11840 if (proto_id == RTE_PMD_I40E_PROTO_UNUSED)
11842 for (n = 0; n < proto_num; n++) {
11843 if (proto[n].proto_id != proto_id)
11845 memset(name, 0, sizeof(name));
11846 strcpy(name, proto[n].name);
11847 PMD_DRV_LOG(INFO, "name = %s\n", name);
11848 if (!strncasecmp(name, "PPPOE", 5))
11849 ptype_mapping[i].sw_ptype |=
11850 RTE_PTYPE_L2_ETHER_PPPOE;
11851 else if (!strncasecmp(name, "IPV4FRAG", 8) &&
11853 ptype_mapping[i].sw_ptype |=
11854 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11855 ptype_mapping[i].sw_ptype |=
11857 } else if (!strncasecmp(name, "IPV4FRAG", 8) &&
11859 ptype_mapping[i].sw_ptype |=
11860 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
11861 ptype_mapping[i].sw_ptype |=
11862 RTE_PTYPE_INNER_L4_FRAG;
11863 } else if (!strncasecmp(name, "OIPV4", 5)) {
11864 ptype_mapping[i].sw_ptype |=
11865 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11867 } else if (!strncasecmp(name, "IPV4", 4) &&
11869 ptype_mapping[i].sw_ptype |=
11870 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11871 else if (!strncasecmp(name, "IPV4", 4) &&
11873 ptype_mapping[i].sw_ptype |=
11874 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
11875 else if (!strncasecmp(name, "IPV6FRAG", 8) &&
11877 ptype_mapping[i].sw_ptype |=
11878 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11879 ptype_mapping[i].sw_ptype |=
11881 } else if (!strncasecmp(name, "IPV6FRAG", 8) &&
11883 ptype_mapping[i].sw_ptype |=
11884 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
11885 ptype_mapping[i].sw_ptype |=
11886 RTE_PTYPE_INNER_L4_FRAG;
11887 } else if (!strncasecmp(name, "OIPV6", 5)) {
11888 ptype_mapping[i].sw_ptype |=
11889 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11891 } else if (!strncasecmp(name, "IPV6", 4) &&
11893 ptype_mapping[i].sw_ptype |=
11894 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11895 else if (!strncasecmp(name, "IPV6", 4) &&
11897 ptype_mapping[i].sw_ptype |=
11898 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
11899 else if (!strncasecmp(name, "UDP", 3) &&
11901 ptype_mapping[i].sw_ptype |=
11903 else if (!strncasecmp(name, "UDP", 3) &&
11905 ptype_mapping[i].sw_ptype |=
11906 RTE_PTYPE_INNER_L4_UDP;
11907 else if (!strncasecmp(name, "TCP", 3) &&
11909 ptype_mapping[i].sw_ptype |=
11911 else if (!strncasecmp(name, "TCP", 3) &&
11913 ptype_mapping[i].sw_ptype |=
11914 RTE_PTYPE_INNER_L4_TCP;
11915 else if (!strncasecmp(name, "SCTP", 4) &&
11917 ptype_mapping[i].sw_ptype |=
11919 else if (!strncasecmp(name, "SCTP", 4) &&
11921 ptype_mapping[i].sw_ptype |=
11922 RTE_PTYPE_INNER_L4_SCTP;
11923 else if ((!strncasecmp(name, "ICMP", 4) ||
11924 !strncasecmp(name, "ICMPV6", 6)) &&
11926 ptype_mapping[i].sw_ptype |=
11928 else if ((!strncasecmp(name, "ICMP", 4) ||
11929 !strncasecmp(name, "ICMPV6", 6)) &&
11931 ptype_mapping[i].sw_ptype |=
11932 RTE_PTYPE_INNER_L4_ICMP;
11933 else if (!strncasecmp(name, "GTPC", 4)) {
11934 ptype_mapping[i].sw_ptype |=
11935 RTE_PTYPE_TUNNEL_GTPC;
11937 } else if (!strncasecmp(name, "GTPU", 4)) {
11938 ptype_mapping[i].sw_ptype |=
11939 RTE_PTYPE_TUNNEL_GTPU;
11941 } else if (!strncasecmp(name, "ESP", 3)) {
11942 ptype_mapping[i].sw_ptype |=
11943 RTE_PTYPE_TUNNEL_ESP;
11945 } else if (!strncasecmp(name, "GRENAT", 6)) {
11946 ptype_mapping[i].sw_ptype |=
11947 RTE_PTYPE_TUNNEL_GRENAT;
11949 } else if (!strncasecmp(name, "L2TPV2CTL", 9) ||
11950 !strncasecmp(name, "L2TPV2", 6) ||
11951 !strncasecmp(name, "L2TPV3", 6)) {
11952 ptype_mapping[i].sw_ptype |=
11953 RTE_PTYPE_TUNNEL_L2TP;
11962 ret = rte_pmd_i40e_ptype_mapping_update(port_id, ptype_mapping,
11965 PMD_DRV_LOG(ERR, "Failed to update ptype mapping table.");
11967 rte_free(ptype_mapping);
11973 i40e_update_customized_info(struct rte_eth_dev *dev, uint8_t *pkg,
11974 uint32_t pkg_size, enum rte_pmd_i40e_package_op op)
11976 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11977 uint32_t proto_num;
11978 struct rte_pmd_i40e_proto_info *proto;
11979 uint32_t buff_size;
11983 if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
11984 op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
11985 PMD_DRV_LOG(ERR, "Unsupported operation.");
11989 /* get information about protocol number */
11990 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11991 (uint8_t *)&proto_num, sizeof(proto_num),
11992 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
11994 PMD_DRV_LOG(ERR, "Failed to get protocol number");
11998 PMD_DRV_LOG(INFO, "No new protocol added");
12002 buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
12003 proto = rte_zmalloc("new_proto", buff_size, 0);
12005 PMD_DRV_LOG(ERR, "Failed to allocate memory");
12009 /* get information about protocol list */
12010 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12011 (uint8_t *)proto, buff_size,
12012 RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
12014 PMD_DRV_LOG(ERR, "Failed to get protocol list");
12019 /* Check if GTP is supported. */
12020 for (i = 0; i < proto_num; i++) {
12021 if (!strncmp(proto[i].name, "GTP", 3)) {
12022 if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
12023 pf->gtp_support = true;
12025 pf->gtp_support = false;
12030 /* Check if ESP is supported. */
12031 for (i = 0; i < proto_num; i++) {
12032 if (!strncmp(proto[i].name, "ESP", 3)) {
12033 if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
12034 pf->esp_support = true;
12036 pf->esp_support = false;
12041 /* Update customized pctype info */
12042 ret = i40e_update_customized_pctype(dev, pkg, pkg_size,
12043 proto_num, proto, op);
12045 PMD_DRV_LOG(INFO, "No pctype is updated.");
12047 /* Update customized ptype info */
12048 ret = i40e_update_customized_ptype(dev, pkg, pkg_size,
12049 proto_num, proto, op);
12051 PMD_DRV_LOG(INFO, "No ptype is updated.");
12056 /* Create a QinQ cloud filter
12058 * The Fortville NIC has limited resources for tunnel filters,
12059 * so we can only reuse existing filters.
12061 * In step 1 we define which Field Vector fields can be used for
12063 * As we do not have the inner tag defined as a field,
12064 * we have to define it first, by reusing one of L1 entries.
12066 * In step 2 we are replacing one of existing filter types with
12067 * a new one for QinQ.
12068 * As we reusing L1 and replacing L2, some of the default filter
12069 * types will disappear,which depends on L1 and L2 entries we reuse.
12071 * Step 1: Create L1 filter of outer vlan (12b) + inner vlan (12b)
12073 * 1. Create L1 filter of outer vlan (12b) which will be in use
12074 * later when we define the cloud filter.
12075 * a. Valid_flags.replace_cloud = 0
12076 * b. Old_filter = 10 (Stag_Inner_Vlan)
12077 * c. New_filter = 0x10
12078 * d. TR bit = 0xff (optional, not used here)
12079 * e. Buffer – 2 entries:
12080 * i. Byte 0 = 8 (outer vlan FV index).
12082 * Byte 2-3 = 0x0fff
12083 * ii. Byte 0 = 37 (inner vlan FV index).
12085 * Byte 2-3 = 0x0fff
12088 * 2. Create cloud filter using two L1 filters entries: stag and
12089 * new filter(outer vlan+ inner vlan)
12090 * a. Valid_flags.replace_cloud = 1
12091 * b. Old_filter = 1 (instead of outer IP)
12092 * c. New_filter = 0x10
12093 * d. Buffer – 2 entries:
12094 * i. Byte 0 = 0x80 | 7 (valid | Stag).
12095 * Byte 1-3 = 0 (rsv)
12096 * ii. Byte 8 = 0x80 | 0x10 (valid | new l1 filter step1)
12097 * Byte 9-11 = 0 (rsv)
12100 i40e_cloud_filter_qinq_create(struct i40e_pf *pf)
12102 int ret = -ENOTSUP;
12103 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
12104 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
12105 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
12106 struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
12108 if (pf->support_multi_driver) {
12109 PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
12114 memset(&filter_replace, 0,
12115 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
12116 memset(&filter_replace_buf, 0,
12117 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
12119 /* create L1 filter */
12120 filter_replace.old_filter_type =
12121 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG_IVLAN;
12122 filter_replace.new_filter_type = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12123 filter_replace.tr_bit = 0;
12125 /* Prepare the buffer, 2 entries */
12126 filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_VLAN;
12127 filter_replace_buf.data[0] |=
12128 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12129 /* Field Vector 12b mask */
12130 filter_replace_buf.data[2] = 0xff;
12131 filter_replace_buf.data[3] = 0x0f;
12132 filter_replace_buf.data[4] =
12133 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_INNER_VLAN;
12134 filter_replace_buf.data[4] |=
12135 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12136 /* Field Vector 12b mask */
12137 filter_replace_buf.data[6] = 0xff;
12138 filter_replace_buf.data[7] = 0x0f;
12139 ret = i40e_aq_replace_cloud_filters(hw, &filter_replace,
12140 &filter_replace_buf);
12141 if (ret != I40E_SUCCESS)
12144 if (filter_replace.old_filter_type !=
12145 filter_replace.new_filter_type)
12146 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
12147 " original: 0x%x, new: 0x%x",
12149 filter_replace.old_filter_type,
12150 filter_replace.new_filter_type);
12152 /* Apply the second L2 cloud filter */
12153 memset(&filter_replace, 0,
12154 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
12155 memset(&filter_replace_buf, 0,
12156 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
12158 /* create L2 filter, input for L2 filter will be L1 filter */
12159 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
12160 filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_OIP;
12161 filter_replace.new_filter_type = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12163 /* Prepare the buffer, 2 entries */
12164 filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
12165 filter_replace_buf.data[0] |=
12166 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12167 filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12168 filter_replace_buf.data[4] |=
12169 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12170 ret = i40e_aq_replace_cloud_filters(hw, &filter_replace,
12171 &filter_replace_buf);
12172 if (!ret && (filter_replace.old_filter_type !=
12173 filter_replace.new_filter_type))
12174 PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
12175 " original: 0x%x, new: 0x%x",
12177 filter_replace.old_filter_type,
12178 filter_replace.new_filter_type);
12184 i40e_set_mac_max_frame(struct rte_eth_dev *dev, uint16_t size)
12186 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
12187 uint32_t rep_cnt = MAX_REPEAT_TIME;
12188 struct rte_eth_link link;
12189 enum i40e_status_code status;
12190 bool can_be_set = true;
12192 /* I40E_MEDIA_TYPE_BASET link up can be ignored */
12193 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET) {
12195 update_link_reg(hw, &link);
12196 if (link.link_status)
12198 rte_delay_ms(CHECK_INTERVAL);
12199 } while (--rep_cnt);
12200 can_be_set = !!link.link_status;
12204 status = i40e_aq_set_mac_config(hw, size, TRUE, 0, false, NULL);
12205 if (status != I40E_SUCCESS)
12206 PMD_DRV_LOG(ERR, "Failed to set max frame size at port level");
12208 PMD_DRV_LOG(ERR, "Set max frame size at port level not applicable on link down");
12212 RTE_LOG_REGISTER_SUFFIX(i40e_logtype_init, init, NOTICE);
12213 RTE_LOG_REGISTER_SUFFIX(i40e_logtype_driver, driver, NOTICE);
12214 #ifdef RTE_ETHDEV_DEBUG_RX
12215 RTE_LOG_REGISTER_SUFFIX(i40e_logtype_rx, rx, DEBUG);
12217 #ifdef RTE_ETHDEV_DEBUG_TX
12218 RTE_LOG_REGISTER_SUFFIX(i40e_logtype_tx, tx, DEBUG);
12221 RTE_PMD_REGISTER_PARAM_STRING(net_i40e,
12222 ETH_I40E_FLOATING_VEB_ARG "=1"
12223 ETH_I40E_FLOATING_VEB_LIST_ARG "=<string>"
12224 ETH_I40E_QUEUE_NUM_PER_VF_ARG "=1|2|4|8|16"
12225 ETH_I40E_SUPPORT_MULTI_DRIVER "=1");