1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2017 Intel Corporation
15 #include <rte_string_fns.h>
17 #include <rte_bus_pci.h>
18 #include <rte_ether.h>
19 #include <rte_ethdev_driver.h>
20 #include <rte_ethdev_pci.h>
21 #include <rte_memzone.h>
22 #include <rte_malloc.h>
23 #include <rte_memcpy.h>
24 #include <rte_alarm.h>
26 #include <rte_eth_ctrl.h>
27 #include <rte_tailq.h>
28 #include <rte_hash_crc.h>
30 #include "i40e_logs.h"
31 #include "base/i40e_prototype.h"
32 #include "base/i40e_adminq_cmd.h"
33 #include "base/i40e_type.h"
34 #include "base/i40e_register.h"
35 #include "base/i40e_dcb.h"
36 #include "i40e_ethdev.h"
37 #include "i40e_rxtx.h"
39 #include "i40e_regs.h"
40 #include "rte_pmd_i40e.h"
42 #define ETH_I40E_FLOATING_VEB_ARG "enable_floating_veb"
43 #define ETH_I40E_FLOATING_VEB_LIST_ARG "floating_veb_list"
45 #define I40E_CLEAR_PXE_WAIT_MS 200
47 /* Maximun number of capability elements */
48 #define I40E_MAX_CAP_ELE_NUM 128
50 /* Wait count and interval */
51 #define I40E_CHK_Q_ENA_COUNT 1000
52 #define I40E_CHK_Q_ENA_INTERVAL_US 1000
54 /* Maximun number of VSI */
55 #define I40E_MAX_NUM_VSIS (384UL)
57 #define I40E_PRE_TX_Q_CFG_WAIT_US 10 /* 10 us */
59 /* Flow control default timer */
60 #define I40E_DEFAULT_PAUSE_TIME 0xFFFFU
62 /* Flow control enable fwd bit */
63 #define I40E_PRTMAC_FWD_CTRL 0x00000001
65 /* Receive Packet Buffer size */
66 #define I40E_RXPBSIZE (968 * 1024)
69 #define I40E_KILOSHIFT 10
71 /* Flow control default high water */
72 #define I40E_DEFAULT_HIGH_WATER (0xF2000 >> I40E_KILOSHIFT)
74 /* Flow control default low water */
75 #define I40E_DEFAULT_LOW_WATER (0xF2000 >> I40E_KILOSHIFT)
77 /* Receive Average Packet Size in Byte*/
78 #define I40E_PACKET_AVERAGE_SIZE 128
80 /* Mask of PF interrupt causes */
81 #define I40E_PFINT_ICR0_ENA_MASK ( \
82 I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | \
83 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | \
84 I40E_PFINT_ICR0_ENA_GRST_MASK | \
85 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | \
86 I40E_PFINT_ICR0_ENA_STORM_DETECT_MASK | \
87 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | \
88 I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK | \
89 I40E_PFINT_ICR0_ENA_VFLR_MASK | \
90 I40E_PFINT_ICR0_ENA_ADMINQ_MASK)
92 #define I40E_FLOW_TYPES ( \
93 (1UL << RTE_ETH_FLOW_FRAG_IPV4) | \
94 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_TCP) | \
95 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_UDP) | \
96 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_SCTP) | \
97 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_OTHER) | \
98 (1UL << RTE_ETH_FLOW_FRAG_IPV6) | \
99 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_TCP) | \
100 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_UDP) | \
101 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_SCTP) | \
102 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_OTHER) | \
103 (1UL << RTE_ETH_FLOW_L2_PAYLOAD))
105 /* Additional timesync values. */
106 #define I40E_PTP_40GB_INCVAL 0x0199999999ULL
107 #define I40E_PTP_10GB_INCVAL 0x0333333333ULL
108 #define I40E_PTP_1GB_INCVAL 0x2000000000ULL
109 #define I40E_PRTTSYN_TSYNENA 0x80000000
110 #define I40E_PRTTSYN_TSYNTYPE 0x0e000000
111 #define I40E_CYCLECOUNTER_MASK 0xffffffffffffffffULL
114 * Below are values for writing un-exposed registers suggested
117 /* Destination MAC address */
118 #define I40E_REG_INSET_L2_DMAC 0xE000000000000000ULL
119 /* Source MAC address */
120 #define I40E_REG_INSET_L2_SMAC 0x1C00000000000000ULL
121 /* Outer (S-Tag) VLAN tag in the outer L2 header */
122 #define I40E_REG_INSET_L2_OUTER_VLAN 0x0000000004000000ULL
123 /* Inner (C-Tag) or single VLAN tag in the outer L2 header */
124 #define I40E_REG_INSET_L2_INNER_VLAN 0x0080000000000000ULL
125 /* Single VLAN tag in the inner L2 header */
126 #define I40E_REG_INSET_TUNNEL_VLAN 0x0100000000000000ULL
127 /* Source IPv4 address */
128 #define I40E_REG_INSET_L3_SRC_IP4 0x0001800000000000ULL
129 /* Destination IPv4 address */
130 #define I40E_REG_INSET_L3_DST_IP4 0x0000001800000000ULL
131 /* Source IPv4 address for X722 */
132 #define I40E_X722_REG_INSET_L3_SRC_IP4 0x0006000000000000ULL
133 /* Destination IPv4 address for X722 */
134 #define I40E_X722_REG_INSET_L3_DST_IP4 0x0000060000000000ULL
135 /* IPv4 Protocol for X722 */
136 #define I40E_X722_REG_INSET_L3_IP4_PROTO 0x0010000000000000ULL
137 /* IPv4 Time to Live for X722 */
138 #define I40E_X722_REG_INSET_L3_IP4_TTL 0x0010000000000000ULL
139 /* IPv4 Type of Service (TOS) */
140 #define I40E_REG_INSET_L3_IP4_TOS 0x0040000000000000ULL
142 #define I40E_REG_INSET_L3_IP4_PROTO 0x0004000000000000ULL
143 /* IPv4 Time to Live */
144 #define I40E_REG_INSET_L3_IP4_TTL 0x0004000000000000ULL
145 /* Source IPv6 address */
146 #define I40E_REG_INSET_L3_SRC_IP6 0x0007F80000000000ULL
147 /* Destination IPv6 address */
148 #define I40E_REG_INSET_L3_DST_IP6 0x000007F800000000ULL
149 /* IPv6 Traffic Class (TC) */
150 #define I40E_REG_INSET_L3_IP6_TC 0x0040000000000000ULL
151 /* IPv6 Next Header */
152 #define I40E_REG_INSET_L3_IP6_NEXT_HDR 0x0008000000000000ULL
154 #define I40E_REG_INSET_L3_IP6_HOP_LIMIT 0x0008000000000000ULL
156 #define I40E_REG_INSET_L4_SRC_PORT 0x0000000400000000ULL
157 /* Destination L4 port */
158 #define I40E_REG_INSET_L4_DST_PORT 0x0000000200000000ULL
159 /* SCTP verification tag */
160 #define I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG 0x0000000180000000ULL
161 /* Inner destination MAC address (MAC-in-UDP/MAC-in-GRE)*/
162 #define I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC 0x0000000001C00000ULL
163 /* Source port of tunneling UDP */
164 #define I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT 0x0000000000200000ULL
165 /* Destination port of tunneling UDP */
166 #define I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT 0x0000000000100000ULL
167 /* UDP Tunneling ID, NVGRE/GRE key */
168 #define I40E_REG_INSET_TUNNEL_ID 0x00000000000C0000ULL
169 /* Last ether type */
170 #define I40E_REG_INSET_LAST_ETHER_TYPE 0x0000000000004000ULL
171 /* Tunneling outer destination IPv4 address */
172 #define I40E_REG_INSET_TUNNEL_L3_DST_IP4 0x00000000000000C0ULL
173 /* Tunneling outer destination IPv6 address */
174 #define I40E_REG_INSET_TUNNEL_L3_DST_IP6 0x0000000000003FC0ULL
175 /* 1st word of flex payload */
176 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD1 0x0000000000002000ULL
177 /* 2nd word of flex payload */
178 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD2 0x0000000000001000ULL
179 /* 3rd word of flex payload */
180 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD3 0x0000000000000800ULL
181 /* 4th word of flex payload */
182 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD4 0x0000000000000400ULL
183 /* 5th word of flex payload */
184 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD5 0x0000000000000200ULL
185 /* 6th word of flex payload */
186 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD6 0x0000000000000100ULL
187 /* 7th word of flex payload */
188 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD7 0x0000000000000080ULL
189 /* 8th word of flex payload */
190 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD8 0x0000000000000040ULL
191 /* all 8 words flex payload */
192 #define I40E_REG_INSET_FLEX_PAYLOAD_WORDS 0x0000000000003FC0ULL
193 #define I40E_REG_INSET_MASK_DEFAULT 0x0000000000000000ULL
195 #define I40E_TRANSLATE_INSET 0
196 #define I40E_TRANSLATE_REG 1
198 #define I40E_INSET_IPV4_TOS_MASK 0x0009FF00UL
199 #define I40E_INSET_IPv4_TTL_MASK 0x000D00FFUL
200 #define I40E_INSET_IPV4_PROTO_MASK 0x000DFF00UL
201 #define I40E_INSET_IPV6_TC_MASK 0x0009F00FUL
202 #define I40E_INSET_IPV6_HOP_LIMIT_MASK 0x000CFF00UL
203 #define I40E_INSET_IPV6_NEXT_HDR_MASK 0x000C00FFUL
205 /* PCI offset for querying capability */
206 #define PCI_DEV_CAP_REG 0xA4
207 /* PCI offset for enabling/disabling Extended Tag */
208 #define PCI_DEV_CTRL_REG 0xA8
209 /* Bit mask of Extended Tag capability */
210 #define PCI_DEV_CAP_EXT_TAG_MASK 0x20
211 /* Bit shift of Extended Tag enable/disable */
212 #define PCI_DEV_CTRL_EXT_TAG_SHIFT 8
213 /* Bit mask of Extended Tag enable/disable */
214 #define PCI_DEV_CTRL_EXT_TAG_MASK (1 << PCI_DEV_CTRL_EXT_TAG_SHIFT)
216 static int eth_i40e_dev_init(struct rte_eth_dev *eth_dev);
217 static int eth_i40e_dev_uninit(struct rte_eth_dev *eth_dev);
218 static int i40e_dev_configure(struct rte_eth_dev *dev);
219 static int i40e_dev_start(struct rte_eth_dev *dev);
220 static void i40e_dev_stop(struct rte_eth_dev *dev);
221 static void i40e_dev_close(struct rte_eth_dev *dev);
222 static int i40e_dev_reset(struct rte_eth_dev *dev);
223 static void i40e_dev_promiscuous_enable(struct rte_eth_dev *dev);
224 static void i40e_dev_promiscuous_disable(struct rte_eth_dev *dev);
225 static void i40e_dev_allmulticast_enable(struct rte_eth_dev *dev);
226 static void i40e_dev_allmulticast_disable(struct rte_eth_dev *dev);
227 static int i40e_dev_set_link_up(struct rte_eth_dev *dev);
228 static int i40e_dev_set_link_down(struct rte_eth_dev *dev);
229 static int i40e_dev_stats_get(struct rte_eth_dev *dev,
230 struct rte_eth_stats *stats);
231 static int i40e_dev_xstats_get(struct rte_eth_dev *dev,
232 struct rte_eth_xstat *xstats, unsigned n);
233 static int i40e_dev_xstats_get_names(struct rte_eth_dev *dev,
234 struct rte_eth_xstat_name *xstats_names,
236 static void i40e_dev_stats_reset(struct rte_eth_dev *dev);
237 static int i40e_dev_queue_stats_mapping_set(struct rte_eth_dev *dev,
241 static int i40e_fw_version_get(struct rte_eth_dev *dev,
242 char *fw_version, size_t fw_size);
243 static void i40e_dev_info_get(struct rte_eth_dev *dev,
244 struct rte_eth_dev_info *dev_info);
245 static int i40e_vlan_filter_set(struct rte_eth_dev *dev,
248 static int i40e_vlan_tpid_set(struct rte_eth_dev *dev,
249 enum rte_vlan_type vlan_type,
251 static int i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask);
252 static void i40e_vlan_strip_queue_set(struct rte_eth_dev *dev,
255 static int i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on);
256 static int i40e_dev_led_on(struct rte_eth_dev *dev);
257 static int i40e_dev_led_off(struct rte_eth_dev *dev);
258 static int i40e_flow_ctrl_get(struct rte_eth_dev *dev,
259 struct rte_eth_fc_conf *fc_conf);
260 static int i40e_flow_ctrl_set(struct rte_eth_dev *dev,
261 struct rte_eth_fc_conf *fc_conf);
262 static int i40e_priority_flow_ctrl_set(struct rte_eth_dev *dev,
263 struct rte_eth_pfc_conf *pfc_conf);
264 static int i40e_macaddr_add(struct rte_eth_dev *dev,
265 struct ether_addr *mac_addr,
268 static void i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index);
269 static int i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
270 struct rte_eth_rss_reta_entry64 *reta_conf,
272 static int i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
273 struct rte_eth_rss_reta_entry64 *reta_conf,
276 static int i40e_get_cap(struct i40e_hw *hw);
277 static int i40e_pf_parameter_init(struct rte_eth_dev *dev);
278 static int i40e_pf_setup(struct i40e_pf *pf);
279 static int i40e_dev_rxtx_init(struct i40e_pf *pf);
280 static int i40e_vmdq_setup(struct rte_eth_dev *dev);
281 static int i40e_dcb_setup(struct rte_eth_dev *dev);
282 static void i40e_stat_update_32(struct i40e_hw *hw, uint32_t reg,
283 bool offset_loaded, uint64_t *offset, uint64_t *stat);
284 static void i40e_stat_update_48(struct i40e_hw *hw,
290 static void i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue);
291 static void i40e_dev_interrupt_handler(void *param);
292 static int i40e_res_pool_init(struct i40e_res_pool_info *pool,
293 uint32_t base, uint32_t num);
294 static void i40e_res_pool_destroy(struct i40e_res_pool_info *pool);
295 static int i40e_res_pool_free(struct i40e_res_pool_info *pool,
297 static int i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
299 static int i40e_dev_init_vlan(struct rte_eth_dev *dev);
300 static int i40e_veb_release(struct i40e_veb *veb);
301 static struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf,
302 struct i40e_vsi *vsi);
303 static int i40e_pf_config_mq_rx(struct i40e_pf *pf);
304 static int i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on);
305 static inline int i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
306 struct i40e_macvlan_filter *mv_f,
309 static int i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi);
310 static int i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
311 struct rte_eth_rss_conf *rss_conf);
312 static int i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
313 struct rte_eth_rss_conf *rss_conf);
314 static int i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
315 struct rte_eth_udp_tunnel *udp_tunnel);
316 static int i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
317 struct rte_eth_udp_tunnel *udp_tunnel);
318 static void i40e_filter_input_set_init(struct i40e_pf *pf);
319 static int i40e_ethertype_filter_handle(struct rte_eth_dev *dev,
320 enum rte_filter_op filter_op,
322 static int i40e_dev_filter_ctrl(struct rte_eth_dev *dev,
323 enum rte_filter_type filter_type,
324 enum rte_filter_op filter_op,
326 static int i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
327 struct rte_eth_dcb_info *dcb_info);
328 static int i40e_dev_sync_phy_type(struct i40e_hw *hw);
329 static void i40e_configure_registers(struct i40e_hw *hw);
330 static void i40e_hw_init(struct rte_eth_dev *dev);
331 static int i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi);
332 static enum i40e_status_code i40e_aq_del_mirror_rule(struct i40e_hw *hw,
338 static int i40e_mirror_rule_set(struct rte_eth_dev *dev,
339 struct rte_eth_mirror_conf *mirror_conf,
340 uint8_t sw_id, uint8_t on);
341 static int i40e_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t sw_id);
343 static int i40e_timesync_enable(struct rte_eth_dev *dev);
344 static int i40e_timesync_disable(struct rte_eth_dev *dev);
345 static int i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
346 struct timespec *timestamp,
348 static int i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
349 struct timespec *timestamp);
350 static void i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw);
352 static int i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
354 static int i40e_timesync_read_time(struct rte_eth_dev *dev,
355 struct timespec *timestamp);
356 static int i40e_timesync_write_time(struct rte_eth_dev *dev,
357 const struct timespec *timestamp);
359 static int i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
361 static int i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
364 static int i40e_get_regs(struct rte_eth_dev *dev,
365 struct rte_dev_reg_info *regs);
367 static int i40e_get_eeprom_length(struct rte_eth_dev *dev);
369 static int i40e_get_eeprom(struct rte_eth_dev *dev,
370 struct rte_dev_eeprom_info *eeprom);
372 static int i40e_set_default_mac_addr(struct rte_eth_dev *dev,
373 struct ether_addr *mac_addr);
375 static int i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
377 static int i40e_ethertype_filter_convert(
378 const struct rte_eth_ethertype_filter *input,
379 struct i40e_ethertype_filter *filter);
380 static int i40e_sw_ethertype_filter_insert(struct i40e_pf *pf,
381 struct i40e_ethertype_filter *filter);
383 static int i40e_tunnel_filter_convert(
384 struct i40e_aqc_add_rm_cloud_filt_elem_ext *cld_filter,
385 struct i40e_tunnel_filter *tunnel_filter);
386 static int i40e_sw_tunnel_filter_insert(struct i40e_pf *pf,
387 struct i40e_tunnel_filter *tunnel_filter);
388 static int i40e_cloud_filter_qinq_create(struct i40e_pf *pf);
390 static void i40e_ethertype_filter_restore(struct i40e_pf *pf);
391 static void i40e_tunnel_filter_restore(struct i40e_pf *pf);
392 static void i40e_filter_restore(struct i40e_pf *pf);
393 static void i40e_notify_all_vfs_link_status(struct rte_eth_dev *dev);
395 int i40e_logtype_init;
396 int i40e_logtype_driver;
398 static const struct rte_pci_id pci_id_i40e_map[] = {
399 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_XL710) },
400 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QEMU) },
401 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_B) },
402 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_C) },
403 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_A) },
404 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_B) },
405 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_C) },
406 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T) },
407 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_20G_KR2) },
408 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_20G_KR2_A) },
409 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T4) },
410 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_B) },
411 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_SFP28) },
412 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_X722_A0) },
413 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_X722) },
414 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_X722) },
415 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_X722) },
416 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_1G_BASE_T_X722) },
417 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_X722) },
418 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_I_X722) },
419 { .vendor_id = 0, /* sentinel */ },
422 static const struct eth_dev_ops i40e_eth_dev_ops = {
423 .dev_configure = i40e_dev_configure,
424 .dev_start = i40e_dev_start,
425 .dev_stop = i40e_dev_stop,
426 .dev_close = i40e_dev_close,
427 .dev_reset = i40e_dev_reset,
428 .promiscuous_enable = i40e_dev_promiscuous_enable,
429 .promiscuous_disable = i40e_dev_promiscuous_disable,
430 .allmulticast_enable = i40e_dev_allmulticast_enable,
431 .allmulticast_disable = i40e_dev_allmulticast_disable,
432 .dev_set_link_up = i40e_dev_set_link_up,
433 .dev_set_link_down = i40e_dev_set_link_down,
434 .link_update = i40e_dev_link_update,
435 .stats_get = i40e_dev_stats_get,
436 .xstats_get = i40e_dev_xstats_get,
437 .xstats_get_names = i40e_dev_xstats_get_names,
438 .stats_reset = i40e_dev_stats_reset,
439 .xstats_reset = i40e_dev_stats_reset,
440 .queue_stats_mapping_set = i40e_dev_queue_stats_mapping_set,
441 .fw_version_get = i40e_fw_version_get,
442 .dev_infos_get = i40e_dev_info_get,
443 .dev_supported_ptypes_get = i40e_dev_supported_ptypes_get,
444 .vlan_filter_set = i40e_vlan_filter_set,
445 .vlan_tpid_set = i40e_vlan_tpid_set,
446 .vlan_offload_set = i40e_vlan_offload_set,
447 .vlan_strip_queue_set = i40e_vlan_strip_queue_set,
448 .vlan_pvid_set = i40e_vlan_pvid_set,
449 .rx_queue_start = i40e_dev_rx_queue_start,
450 .rx_queue_stop = i40e_dev_rx_queue_stop,
451 .tx_queue_start = i40e_dev_tx_queue_start,
452 .tx_queue_stop = i40e_dev_tx_queue_stop,
453 .rx_queue_setup = i40e_dev_rx_queue_setup,
454 .rx_queue_intr_enable = i40e_dev_rx_queue_intr_enable,
455 .rx_queue_intr_disable = i40e_dev_rx_queue_intr_disable,
456 .rx_queue_release = i40e_dev_rx_queue_release,
457 .rx_queue_count = i40e_dev_rx_queue_count,
458 .rx_descriptor_done = i40e_dev_rx_descriptor_done,
459 .rx_descriptor_status = i40e_dev_rx_descriptor_status,
460 .tx_descriptor_status = i40e_dev_tx_descriptor_status,
461 .tx_queue_setup = i40e_dev_tx_queue_setup,
462 .tx_queue_release = i40e_dev_tx_queue_release,
463 .dev_led_on = i40e_dev_led_on,
464 .dev_led_off = i40e_dev_led_off,
465 .flow_ctrl_get = i40e_flow_ctrl_get,
466 .flow_ctrl_set = i40e_flow_ctrl_set,
467 .priority_flow_ctrl_set = i40e_priority_flow_ctrl_set,
468 .mac_addr_add = i40e_macaddr_add,
469 .mac_addr_remove = i40e_macaddr_remove,
470 .reta_update = i40e_dev_rss_reta_update,
471 .reta_query = i40e_dev_rss_reta_query,
472 .rss_hash_update = i40e_dev_rss_hash_update,
473 .rss_hash_conf_get = i40e_dev_rss_hash_conf_get,
474 .udp_tunnel_port_add = i40e_dev_udp_tunnel_port_add,
475 .udp_tunnel_port_del = i40e_dev_udp_tunnel_port_del,
476 .filter_ctrl = i40e_dev_filter_ctrl,
477 .rxq_info_get = i40e_rxq_info_get,
478 .txq_info_get = i40e_txq_info_get,
479 .mirror_rule_set = i40e_mirror_rule_set,
480 .mirror_rule_reset = i40e_mirror_rule_reset,
481 .timesync_enable = i40e_timesync_enable,
482 .timesync_disable = i40e_timesync_disable,
483 .timesync_read_rx_timestamp = i40e_timesync_read_rx_timestamp,
484 .timesync_read_tx_timestamp = i40e_timesync_read_tx_timestamp,
485 .get_dcb_info = i40e_dev_get_dcb_info,
486 .timesync_adjust_time = i40e_timesync_adjust_time,
487 .timesync_read_time = i40e_timesync_read_time,
488 .timesync_write_time = i40e_timesync_write_time,
489 .get_reg = i40e_get_regs,
490 .get_eeprom_length = i40e_get_eeprom_length,
491 .get_eeprom = i40e_get_eeprom,
492 .mac_addr_set = i40e_set_default_mac_addr,
493 .mtu_set = i40e_dev_mtu_set,
494 .tm_ops_get = i40e_tm_ops_get,
497 /* store statistics names and its offset in stats structure */
498 struct rte_i40e_xstats_name_off {
499 char name[RTE_ETH_XSTATS_NAME_SIZE];
503 static const struct rte_i40e_xstats_name_off rte_i40e_stats_strings[] = {
504 {"rx_unicast_packets", offsetof(struct i40e_eth_stats, rx_unicast)},
505 {"rx_multicast_packets", offsetof(struct i40e_eth_stats, rx_multicast)},
506 {"rx_broadcast_packets", offsetof(struct i40e_eth_stats, rx_broadcast)},
507 {"rx_dropped", offsetof(struct i40e_eth_stats, rx_discards)},
508 {"rx_unknown_protocol_packets", offsetof(struct i40e_eth_stats,
509 rx_unknown_protocol)},
510 {"tx_unicast_packets", offsetof(struct i40e_eth_stats, tx_unicast)},
511 {"tx_multicast_packets", offsetof(struct i40e_eth_stats, tx_multicast)},
512 {"tx_broadcast_packets", offsetof(struct i40e_eth_stats, tx_broadcast)},
513 {"tx_dropped", offsetof(struct i40e_eth_stats, tx_discards)},
516 #define I40E_NB_ETH_XSTATS (sizeof(rte_i40e_stats_strings) / \
517 sizeof(rte_i40e_stats_strings[0]))
519 static const struct rte_i40e_xstats_name_off rte_i40e_hw_port_strings[] = {
520 {"tx_link_down_dropped", offsetof(struct i40e_hw_port_stats,
521 tx_dropped_link_down)},
522 {"rx_crc_errors", offsetof(struct i40e_hw_port_stats, crc_errors)},
523 {"rx_illegal_byte_errors", offsetof(struct i40e_hw_port_stats,
525 {"rx_error_bytes", offsetof(struct i40e_hw_port_stats, error_bytes)},
526 {"mac_local_errors", offsetof(struct i40e_hw_port_stats,
528 {"mac_remote_errors", offsetof(struct i40e_hw_port_stats,
530 {"rx_length_errors", offsetof(struct i40e_hw_port_stats,
532 {"tx_xon_packets", offsetof(struct i40e_hw_port_stats, link_xon_tx)},
533 {"rx_xon_packets", offsetof(struct i40e_hw_port_stats, link_xon_rx)},
534 {"tx_xoff_packets", offsetof(struct i40e_hw_port_stats, link_xoff_tx)},
535 {"rx_xoff_packets", offsetof(struct i40e_hw_port_stats, link_xoff_rx)},
536 {"rx_size_64_packets", offsetof(struct i40e_hw_port_stats, rx_size_64)},
537 {"rx_size_65_to_127_packets", offsetof(struct i40e_hw_port_stats,
539 {"rx_size_128_to_255_packets", offsetof(struct i40e_hw_port_stats,
541 {"rx_size_256_to_511_packets", offsetof(struct i40e_hw_port_stats,
543 {"rx_size_512_to_1023_packets", offsetof(struct i40e_hw_port_stats,
545 {"rx_size_1024_to_1522_packets", offsetof(struct i40e_hw_port_stats,
547 {"rx_size_1523_to_max_packets", offsetof(struct i40e_hw_port_stats,
549 {"rx_undersized_errors", offsetof(struct i40e_hw_port_stats,
551 {"rx_oversize_errors", offsetof(struct i40e_hw_port_stats,
553 {"rx_mac_short_dropped", offsetof(struct i40e_hw_port_stats,
554 mac_short_packet_dropped)},
555 {"rx_fragmented_errors", offsetof(struct i40e_hw_port_stats,
557 {"rx_jabber_errors", offsetof(struct i40e_hw_port_stats, rx_jabber)},
558 {"tx_size_64_packets", offsetof(struct i40e_hw_port_stats, tx_size_64)},
559 {"tx_size_65_to_127_packets", offsetof(struct i40e_hw_port_stats,
561 {"tx_size_128_to_255_packets", offsetof(struct i40e_hw_port_stats,
563 {"tx_size_256_to_511_packets", offsetof(struct i40e_hw_port_stats,
565 {"tx_size_512_to_1023_packets", offsetof(struct i40e_hw_port_stats,
567 {"tx_size_1024_to_1522_packets", offsetof(struct i40e_hw_port_stats,
569 {"tx_size_1523_to_max_packets", offsetof(struct i40e_hw_port_stats,
571 {"rx_flow_director_atr_match_packets",
572 offsetof(struct i40e_hw_port_stats, fd_atr_match)},
573 {"rx_flow_director_sb_match_packets",
574 offsetof(struct i40e_hw_port_stats, fd_sb_match)},
575 {"tx_low_power_idle_status", offsetof(struct i40e_hw_port_stats,
577 {"rx_low_power_idle_status", offsetof(struct i40e_hw_port_stats,
579 {"tx_low_power_idle_count", offsetof(struct i40e_hw_port_stats,
581 {"rx_low_power_idle_count", offsetof(struct i40e_hw_port_stats,
585 #define I40E_NB_HW_PORT_XSTATS (sizeof(rte_i40e_hw_port_strings) / \
586 sizeof(rte_i40e_hw_port_strings[0]))
588 static const struct rte_i40e_xstats_name_off rte_i40e_rxq_prio_strings[] = {
589 {"xon_packets", offsetof(struct i40e_hw_port_stats,
591 {"xoff_packets", offsetof(struct i40e_hw_port_stats,
595 #define I40E_NB_RXQ_PRIO_XSTATS (sizeof(rte_i40e_rxq_prio_strings) / \
596 sizeof(rte_i40e_rxq_prio_strings[0]))
598 static const struct rte_i40e_xstats_name_off rte_i40e_txq_prio_strings[] = {
599 {"xon_packets", offsetof(struct i40e_hw_port_stats,
601 {"xoff_packets", offsetof(struct i40e_hw_port_stats,
603 {"xon_to_xoff_packets", offsetof(struct i40e_hw_port_stats,
604 priority_xon_2_xoff)},
607 #define I40E_NB_TXQ_PRIO_XSTATS (sizeof(rte_i40e_txq_prio_strings) / \
608 sizeof(rte_i40e_txq_prio_strings[0]))
610 static int eth_i40e_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
611 struct rte_pci_device *pci_dev)
613 return rte_eth_dev_pci_generic_probe(pci_dev,
614 sizeof(struct i40e_adapter), eth_i40e_dev_init);
617 static int eth_i40e_pci_remove(struct rte_pci_device *pci_dev)
619 return rte_eth_dev_pci_generic_remove(pci_dev, eth_i40e_dev_uninit);
622 static struct rte_pci_driver rte_i40e_pmd = {
623 .id_table = pci_id_i40e_map,
624 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
625 RTE_PCI_DRV_IOVA_AS_VA,
626 .probe = eth_i40e_pci_probe,
627 .remove = eth_i40e_pci_remove,
631 i40e_write_global_rx_ctl(struct i40e_hw *hw, u32 reg_addr, u32 reg_val)
633 i40e_write_rx_ctl(hw, reg_addr, reg_val);
634 PMD_DRV_LOG(DEBUG, "Global register 0x%08x is modified "
639 RTE_PMD_REGISTER_PCI(net_i40e, rte_i40e_pmd);
640 RTE_PMD_REGISTER_PCI_TABLE(net_i40e, pci_id_i40e_map);
641 RTE_PMD_REGISTER_KMOD_DEP(net_i40e, "* igb_uio | uio_pci_generic | vfio-pci");
643 #ifndef I40E_GLQF_ORT
644 #define I40E_GLQF_ORT(_i) (0x00268900 + ((_i) * 4))
646 #ifndef I40E_GLQF_PIT
647 #define I40E_GLQF_PIT(_i) (0x00268C80 + ((_i) * 4))
649 #ifndef I40E_GLQF_L3_MAP
650 #define I40E_GLQF_L3_MAP(_i) (0x0026C700 + ((_i) * 4))
653 static inline void i40e_GLQF_reg_init(struct i40e_hw *hw)
656 * Initialize registers for parsing packet type of QinQ
657 * This should be removed from code once proper
658 * configuration API is added to avoid configuration conflicts
659 * between ports of the same device.
661 I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(40), 0x00000029);
662 I40E_WRITE_GLB_REG(hw, I40E_GLQF_PIT(9), 0x00009420);
663 i40e_global_cfg_warning(I40E_WARNING_QINQ_PARSER);
666 static inline void i40e_config_automask(struct i40e_pf *pf)
668 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
671 /* INTENA flag is not auto-cleared for interrupt */
672 val = I40E_READ_REG(hw, I40E_GLINT_CTL);
673 val |= I40E_GLINT_CTL_DIS_AUTOMASK_PF0_MASK |
674 I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK;
676 /* If support multi-driver, PF will use INT0. */
677 if (!pf->support_multi_driver)
678 val |= I40E_GLINT_CTL_DIS_AUTOMASK_N_MASK;
680 I40E_WRITE_REG(hw, I40E_GLINT_CTL, val);
683 #define I40E_FLOW_CONTROL_ETHERTYPE 0x8808
686 * Add a ethertype filter to drop all flow control frames transmitted
690 i40e_add_tx_flow_control_drop_filter(struct i40e_pf *pf)
692 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
693 uint16_t flags = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
694 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
695 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
698 ret = i40e_aq_add_rem_control_packet_filter(hw, NULL,
699 I40E_FLOW_CONTROL_ETHERTYPE, flags,
700 pf->main_vsi_seid, 0,
704 "Failed to add filter to drop flow control frames from VSIs.");
708 floating_veb_list_handler(__rte_unused const char *key,
709 const char *floating_veb_value,
713 unsigned int count = 0;
716 bool *vf_floating_veb = opaque;
718 while (isblank(*floating_veb_value))
719 floating_veb_value++;
721 /* Reset floating VEB configuration for VFs */
722 for (idx = 0; idx < I40E_MAX_VF; idx++)
723 vf_floating_veb[idx] = false;
727 while (isblank(*floating_veb_value))
728 floating_veb_value++;
729 if (*floating_veb_value == '\0')
732 idx = strtoul(floating_veb_value, &end, 10);
733 if (errno || end == NULL)
735 while (isblank(*end))
739 } else if ((*end == ';') || (*end == '\0')) {
741 if (min == I40E_MAX_VF)
743 if (max >= I40E_MAX_VF)
744 max = I40E_MAX_VF - 1;
745 for (idx = min; idx <= max; idx++) {
746 vf_floating_veb[idx] = true;
753 floating_veb_value = end + 1;
754 } while (*end != '\0');
763 config_vf_floating_veb(struct rte_devargs *devargs,
764 uint16_t floating_veb,
765 bool *vf_floating_veb)
767 struct rte_kvargs *kvlist;
769 const char *floating_veb_list = ETH_I40E_FLOATING_VEB_LIST_ARG;
773 /* All the VFs attach to the floating VEB by default
774 * when the floating VEB is enabled.
776 for (i = 0; i < I40E_MAX_VF; i++)
777 vf_floating_veb[i] = true;
782 kvlist = rte_kvargs_parse(devargs->args, NULL);
786 if (!rte_kvargs_count(kvlist, floating_veb_list)) {
787 rte_kvargs_free(kvlist);
790 /* When the floating_veb_list parameter exists, all the VFs
791 * will attach to the legacy VEB firstly, then configure VFs
792 * to the floating VEB according to the floating_veb_list.
794 if (rte_kvargs_process(kvlist, floating_veb_list,
795 floating_veb_list_handler,
796 vf_floating_veb) < 0) {
797 rte_kvargs_free(kvlist);
800 rte_kvargs_free(kvlist);
804 i40e_check_floating_handler(__rte_unused const char *key,
806 __rte_unused void *opaque)
808 if (strcmp(value, "1"))
815 is_floating_veb_supported(struct rte_devargs *devargs)
817 struct rte_kvargs *kvlist;
818 const char *floating_veb_key = ETH_I40E_FLOATING_VEB_ARG;
823 kvlist = rte_kvargs_parse(devargs->args, NULL);
827 if (!rte_kvargs_count(kvlist, floating_veb_key)) {
828 rte_kvargs_free(kvlist);
831 /* Floating VEB is enabled when there's key-value:
832 * enable_floating_veb=1
834 if (rte_kvargs_process(kvlist, floating_veb_key,
835 i40e_check_floating_handler, NULL) < 0) {
836 rte_kvargs_free(kvlist);
839 rte_kvargs_free(kvlist);
845 config_floating_veb(struct rte_eth_dev *dev)
847 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
848 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
849 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
851 memset(pf->floating_veb_list, 0, sizeof(pf->floating_veb_list));
853 if (hw->aq.fw_maj_ver >= FLOATING_VEB_SUPPORTED_FW_MAJ) {
855 is_floating_veb_supported(pci_dev->device.devargs);
856 config_vf_floating_veb(pci_dev->device.devargs,
858 pf->floating_veb_list);
860 pf->floating_veb = false;
864 #define I40E_L2_TAGS_S_TAG_SHIFT 1
865 #define I40E_L2_TAGS_S_TAG_MASK I40E_MASK(0x1, I40E_L2_TAGS_S_TAG_SHIFT)
868 i40e_init_ethtype_filter_list(struct rte_eth_dev *dev)
870 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
871 struct i40e_ethertype_rule *ethertype_rule = &pf->ethertype;
872 char ethertype_hash_name[RTE_HASH_NAMESIZE];
875 struct rte_hash_parameters ethertype_hash_params = {
876 .name = ethertype_hash_name,
877 .entries = I40E_MAX_ETHERTYPE_FILTER_NUM,
878 .key_len = sizeof(struct i40e_ethertype_filter_input),
879 .hash_func = rte_hash_crc,
880 .hash_func_init_val = 0,
881 .socket_id = rte_socket_id(),
884 /* Initialize ethertype filter rule list and hash */
885 TAILQ_INIT(ðertype_rule->ethertype_list);
886 snprintf(ethertype_hash_name, RTE_HASH_NAMESIZE,
887 "ethertype_%s", dev->device->name);
888 ethertype_rule->hash_table = rte_hash_create(ðertype_hash_params);
889 if (!ethertype_rule->hash_table) {
890 PMD_INIT_LOG(ERR, "Failed to create ethertype hash table!");
893 ethertype_rule->hash_map = rte_zmalloc("i40e_ethertype_hash_map",
894 sizeof(struct i40e_ethertype_filter *) *
895 I40E_MAX_ETHERTYPE_FILTER_NUM,
897 if (!ethertype_rule->hash_map) {
899 "Failed to allocate memory for ethertype hash map!");
901 goto err_ethertype_hash_map_alloc;
906 err_ethertype_hash_map_alloc:
907 rte_hash_free(ethertype_rule->hash_table);
913 i40e_init_tunnel_filter_list(struct rte_eth_dev *dev)
915 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
916 struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
917 char tunnel_hash_name[RTE_HASH_NAMESIZE];
920 struct rte_hash_parameters tunnel_hash_params = {
921 .name = tunnel_hash_name,
922 .entries = I40E_MAX_TUNNEL_FILTER_NUM,
923 .key_len = sizeof(struct i40e_tunnel_filter_input),
924 .hash_func = rte_hash_crc,
925 .hash_func_init_val = 0,
926 .socket_id = rte_socket_id(),
929 /* Initialize tunnel filter rule list and hash */
930 TAILQ_INIT(&tunnel_rule->tunnel_list);
931 snprintf(tunnel_hash_name, RTE_HASH_NAMESIZE,
932 "tunnel_%s", dev->device->name);
933 tunnel_rule->hash_table = rte_hash_create(&tunnel_hash_params);
934 if (!tunnel_rule->hash_table) {
935 PMD_INIT_LOG(ERR, "Failed to create tunnel hash table!");
938 tunnel_rule->hash_map = rte_zmalloc("i40e_tunnel_hash_map",
939 sizeof(struct i40e_tunnel_filter *) *
940 I40E_MAX_TUNNEL_FILTER_NUM,
942 if (!tunnel_rule->hash_map) {
944 "Failed to allocate memory for tunnel hash map!");
946 goto err_tunnel_hash_map_alloc;
951 err_tunnel_hash_map_alloc:
952 rte_hash_free(tunnel_rule->hash_table);
958 i40e_init_fdir_filter_list(struct rte_eth_dev *dev)
960 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
961 struct i40e_fdir_info *fdir_info = &pf->fdir;
962 char fdir_hash_name[RTE_HASH_NAMESIZE];
965 struct rte_hash_parameters fdir_hash_params = {
966 .name = fdir_hash_name,
967 .entries = I40E_MAX_FDIR_FILTER_NUM,
968 .key_len = sizeof(struct i40e_fdir_input),
969 .hash_func = rte_hash_crc,
970 .hash_func_init_val = 0,
971 .socket_id = rte_socket_id(),
974 /* Initialize flow director filter rule list and hash */
975 TAILQ_INIT(&fdir_info->fdir_list);
976 snprintf(fdir_hash_name, RTE_HASH_NAMESIZE,
977 "fdir_%s", dev->device->name);
978 fdir_info->hash_table = rte_hash_create(&fdir_hash_params);
979 if (!fdir_info->hash_table) {
980 PMD_INIT_LOG(ERR, "Failed to create fdir hash table!");
983 fdir_info->hash_map = rte_zmalloc("i40e_fdir_hash_map",
984 sizeof(struct i40e_fdir_filter *) *
985 I40E_MAX_FDIR_FILTER_NUM,
987 if (!fdir_info->hash_map) {
989 "Failed to allocate memory for fdir hash map!");
991 goto err_fdir_hash_map_alloc;
995 err_fdir_hash_map_alloc:
996 rte_hash_free(fdir_info->hash_table);
1002 i40e_init_customized_info(struct i40e_pf *pf)
1006 /* Initialize customized pctype */
1007 for (i = I40E_CUSTOMIZED_GTPC; i < I40E_CUSTOMIZED_MAX; i++) {
1008 pf->customized_pctype[i].index = i;
1009 pf->customized_pctype[i].pctype = I40E_FILTER_PCTYPE_INVALID;
1010 pf->customized_pctype[i].valid = false;
1013 pf->gtp_support = false;
1017 i40e_init_queue_region_conf(struct rte_eth_dev *dev)
1019 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1020 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1021 struct i40e_queue_regions *info = &pf->queue_region;
1024 for (i = 0; i < I40E_PFQF_HREGION_MAX_INDEX; i++)
1025 i40e_write_rx_ctl(hw, I40E_PFQF_HREGION(i), 0);
1027 memset(info, 0, sizeof(struct i40e_queue_regions));
1030 #define ETH_I40E_SUPPORT_MULTI_DRIVER "support-multi-driver"
1033 i40e_parse_multi_drv_handler(__rte_unused const char *key,
1038 unsigned long support_multi_driver;
1041 pf = (struct i40e_pf *)opaque;
1044 support_multi_driver = strtoul(value, &end, 10);
1045 if (errno != 0 || end == value || *end != 0) {
1046 PMD_DRV_LOG(WARNING, "Wrong global configuration");
1050 if (support_multi_driver == 1 || support_multi_driver == 0)
1051 pf->support_multi_driver = (bool)support_multi_driver;
1053 PMD_DRV_LOG(WARNING, "%s must be 1 or 0,",
1054 "enable global configuration by default."
1055 ETH_I40E_SUPPORT_MULTI_DRIVER);
1060 i40e_support_multi_driver(struct rte_eth_dev *dev)
1062 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1063 static const char *const valid_keys[] = {
1064 ETH_I40E_SUPPORT_MULTI_DRIVER, NULL};
1065 struct rte_kvargs *kvlist;
1067 /* Enable global configuration by default */
1068 pf->support_multi_driver = false;
1070 if (!dev->device->devargs)
1073 kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
1077 if (rte_kvargs_count(kvlist, ETH_I40E_SUPPORT_MULTI_DRIVER) > 1)
1078 PMD_DRV_LOG(WARNING, "More than one argument \"%s\" and only "
1079 "the first invalid or last valid one is used !",
1080 ETH_I40E_SUPPORT_MULTI_DRIVER);
1082 if (rte_kvargs_process(kvlist, ETH_I40E_SUPPORT_MULTI_DRIVER,
1083 i40e_parse_multi_drv_handler, pf) < 0) {
1084 rte_kvargs_free(kvlist);
1088 rte_kvargs_free(kvlist);
1093 eth_i40e_dev_init(struct rte_eth_dev *dev)
1095 struct rte_pci_device *pci_dev;
1096 struct rte_intr_handle *intr_handle;
1097 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1098 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1099 struct i40e_vsi *vsi;
1102 uint8_t aq_fail = 0;
1104 PMD_INIT_FUNC_TRACE();
1106 dev->dev_ops = &i40e_eth_dev_ops;
1107 dev->rx_pkt_burst = i40e_recv_pkts;
1108 dev->tx_pkt_burst = i40e_xmit_pkts;
1109 dev->tx_pkt_prepare = i40e_prep_pkts;
1111 /* for secondary processes, we don't initialise any further as primary
1112 * has already done this work. Only check we don't need a different
1114 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
1115 i40e_set_rx_function(dev);
1116 i40e_set_tx_function(dev);
1119 i40e_set_default_ptype_table(dev);
1120 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1121 intr_handle = &pci_dev->intr_handle;
1123 rte_eth_copy_pci_info(dev, pci_dev);
1125 pf->adapter = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1126 pf->adapter->eth_dev = dev;
1127 pf->dev_data = dev->data;
1129 hw->back = I40E_PF_TO_ADAPTER(pf);
1130 hw->hw_addr = (uint8_t *)(pci_dev->mem_resource[0].addr);
1133 "Hardware is not available, as address is NULL");
1137 hw->vendor_id = pci_dev->id.vendor_id;
1138 hw->device_id = pci_dev->id.device_id;
1139 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
1140 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
1141 hw->bus.device = pci_dev->addr.devid;
1142 hw->bus.func = pci_dev->addr.function;
1143 hw->adapter_stopped = 0;
1145 /* Check if need to support multi-driver */
1146 i40e_support_multi_driver(dev);
1148 /* Make sure all is clean before doing PF reset */
1151 /* Initialize the hardware */
1154 /* Reset here to make sure all is clean for each PF */
1155 ret = i40e_pf_reset(hw);
1157 PMD_INIT_LOG(ERR, "Failed to reset pf: %d", ret);
1161 /* Initialize the shared code (base driver) */
1162 ret = i40e_init_shared_code(hw);
1164 PMD_INIT_LOG(ERR, "Failed to init shared code (base driver): %d", ret);
1168 i40e_config_automask(pf);
1170 i40e_set_default_pctype_table(dev);
1173 * To work around the NVM issue, initialize registers
1174 * for packet type of QinQ by software.
1175 * It should be removed once issues are fixed in NVM.
1177 if (!pf->support_multi_driver)
1178 i40e_GLQF_reg_init(hw);
1180 /* Initialize the input set for filters (hash and fd) to default value */
1181 i40e_filter_input_set_init(pf);
1183 /* Initialize the parameters for adminq */
1184 i40e_init_adminq_parameter(hw);
1185 ret = i40e_init_adminq(hw);
1186 if (ret != I40E_SUCCESS) {
1187 PMD_INIT_LOG(ERR, "Failed to init adminq: %d", ret);
1190 PMD_INIT_LOG(INFO, "FW %d.%d API %d.%d NVM %02d.%02d.%02d eetrack %04x",
1191 hw->aq.fw_maj_ver, hw->aq.fw_min_ver,
1192 hw->aq.api_maj_ver, hw->aq.api_min_ver,
1193 ((hw->nvm.version >> 12) & 0xf),
1194 ((hw->nvm.version >> 4) & 0xff),
1195 (hw->nvm.version & 0xf), hw->nvm.eetrack);
1197 /* initialise the L3_MAP register */
1198 if (!pf->support_multi_driver) {
1199 ret = i40e_aq_debug_write_register(hw, I40E_GLQF_L3_MAP(40),
1202 PMD_INIT_LOG(ERR, "Failed to write L3 MAP register %d",
1205 "Global register 0x%08x is changed with 0x28",
1206 I40E_GLQF_L3_MAP(40));
1207 i40e_global_cfg_warning(I40E_WARNING_QINQ_CLOUD_FILTER);
1210 /* Need the special FW version to support floating VEB */
1211 config_floating_veb(dev);
1212 /* Clear PXE mode */
1213 i40e_clear_pxe_mode(hw);
1214 i40e_dev_sync_phy_type(hw);
1217 * On X710, performance number is far from the expectation on recent
1218 * firmware versions. The fix for this issue may not be integrated in
1219 * the following firmware version. So the workaround in software driver
1220 * is needed. It needs to modify the initial values of 3 internal only
1221 * registers. Note that the workaround can be removed when it is fixed
1222 * in firmware in the future.
1224 i40e_configure_registers(hw);
1226 /* Get hw capabilities */
1227 ret = i40e_get_cap(hw);
1228 if (ret != I40E_SUCCESS) {
1229 PMD_INIT_LOG(ERR, "Failed to get capabilities: %d", ret);
1230 goto err_get_capabilities;
1233 /* Initialize parameters for PF */
1234 ret = i40e_pf_parameter_init(dev);
1236 PMD_INIT_LOG(ERR, "Failed to do parameter init: %d", ret);
1237 goto err_parameter_init;
1240 /* Initialize the queue management */
1241 ret = i40e_res_pool_init(&pf->qp_pool, 0, hw->func_caps.num_tx_qp);
1243 PMD_INIT_LOG(ERR, "Failed to init queue pool");
1244 goto err_qp_pool_init;
1246 ret = i40e_res_pool_init(&pf->msix_pool, 1,
1247 hw->func_caps.num_msix_vectors - 1);
1249 PMD_INIT_LOG(ERR, "Failed to init MSIX pool");
1250 goto err_msix_pool_init;
1253 /* Initialize lan hmc */
1254 ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
1255 hw->func_caps.num_rx_qp, 0, 0);
1256 if (ret != I40E_SUCCESS) {
1257 PMD_INIT_LOG(ERR, "Failed to init lan hmc: %d", ret);
1258 goto err_init_lan_hmc;
1261 /* Configure lan hmc */
1262 ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
1263 if (ret != I40E_SUCCESS) {
1264 PMD_INIT_LOG(ERR, "Failed to configure lan hmc: %d", ret);
1265 goto err_configure_lan_hmc;
1268 /* Get and check the mac address */
1269 i40e_get_mac_addr(hw, hw->mac.addr);
1270 if (i40e_validate_mac_addr(hw->mac.addr) != I40E_SUCCESS) {
1271 PMD_INIT_LOG(ERR, "mac address is not valid");
1273 goto err_get_mac_addr;
1275 /* Copy the permanent MAC address */
1276 ether_addr_copy((struct ether_addr *) hw->mac.addr,
1277 (struct ether_addr *) hw->mac.perm_addr);
1279 /* Disable flow control */
1280 hw->fc.requested_mode = I40E_FC_NONE;
1281 i40e_set_fc(hw, &aq_fail, TRUE);
1283 /* Set the global registers with default ether type value */
1284 if (!pf->support_multi_driver) {
1285 ret = i40e_vlan_tpid_set(dev, ETH_VLAN_TYPE_OUTER,
1287 if (ret != I40E_SUCCESS) {
1289 "Failed to set the default outer "
1291 goto err_setup_pf_switch;
1295 /* PF setup, which includes VSI setup */
1296 ret = i40e_pf_setup(pf);
1298 PMD_INIT_LOG(ERR, "Failed to setup pf switch: %d", ret);
1299 goto err_setup_pf_switch;
1302 /* reset all stats of the device, including pf and main vsi */
1303 i40e_dev_stats_reset(dev);
1307 /* Disable double vlan by default */
1308 i40e_vsi_config_double_vlan(vsi, FALSE);
1310 /* Disable S-TAG identification when floating_veb is disabled */
1311 if (!pf->floating_veb) {
1312 ret = I40E_READ_REG(hw, I40E_PRT_L2TAGSEN);
1313 if (ret & I40E_L2_TAGS_S_TAG_MASK) {
1314 ret &= ~I40E_L2_TAGS_S_TAG_MASK;
1315 I40E_WRITE_REG(hw, I40E_PRT_L2TAGSEN, ret);
1319 if (!vsi->max_macaddrs)
1320 len = ETHER_ADDR_LEN;
1322 len = ETHER_ADDR_LEN * vsi->max_macaddrs;
1324 /* Should be after VSI initialized */
1325 dev->data->mac_addrs = rte_zmalloc("i40e", len, 0);
1326 if (!dev->data->mac_addrs) {
1328 "Failed to allocated memory for storing mac address");
1331 ether_addr_copy((struct ether_addr *)hw->mac.perm_addr,
1332 &dev->data->mac_addrs[0]);
1334 /* Init dcb to sw mode by default */
1335 ret = i40e_dcb_init_configure(dev, TRUE);
1336 if (ret != I40E_SUCCESS) {
1337 PMD_INIT_LOG(INFO, "Failed to init dcb.");
1338 pf->flags &= ~I40E_FLAG_DCB;
1340 /* Update HW struct after DCB configuration */
1343 /* initialize pf host driver to setup SRIOV resource if applicable */
1344 i40e_pf_host_init(dev);
1346 /* register callback func to eal lib */
1347 rte_intr_callback_register(intr_handle,
1348 i40e_dev_interrupt_handler, dev);
1350 /* configure and enable device interrupt */
1351 i40e_pf_config_irq0(hw, TRUE);
1352 i40e_pf_enable_irq0(hw);
1354 /* enable uio intr after callback register */
1355 rte_intr_enable(intr_handle);
1357 /* By default disable flexible payload in global configuration */
1358 if (!pf->support_multi_driver)
1359 i40e_flex_payload_reg_set_default(hw);
1362 * Add an ethertype filter to drop all flow control frames transmitted
1363 * from VSIs. By doing so, we stop VF from sending out PAUSE or PFC
1366 i40e_add_tx_flow_control_drop_filter(pf);
1368 /* Set the max frame size to 0x2600 by default,
1369 * in case other drivers changed the default value.
1371 i40e_aq_set_mac_config(hw, I40E_FRAME_SIZE_MAX, TRUE, 0, NULL);
1373 /* initialize mirror rule list */
1374 TAILQ_INIT(&pf->mirror_list);
1376 /* initialize Traffic Manager configuration */
1377 i40e_tm_conf_init(dev);
1379 /* Initialize customized information */
1380 i40e_init_customized_info(pf);
1382 ret = i40e_init_ethtype_filter_list(dev);
1384 goto err_init_ethtype_filter_list;
1385 ret = i40e_init_tunnel_filter_list(dev);
1387 goto err_init_tunnel_filter_list;
1388 ret = i40e_init_fdir_filter_list(dev);
1390 goto err_init_fdir_filter_list;
1392 /* initialize queue region configuration */
1393 i40e_init_queue_region_conf(dev);
1395 /* initialize rss configuration from rte_flow */
1396 memset(&pf->rss_info, 0,
1397 sizeof(struct i40e_rte_flow_rss_conf));
1401 err_init_fdir_filter_list:
1402 rte_free(pf->tunnel.hash_table);
1403 rte_free(pf->tunnel.hash_map);
1404 err_init_tunnel_filter_list:
1405 rte_free(pf->ethertype.hash_table);
1406 rte_free(pf->ethertype.hash_map);
1407 err_init_ethtype_filter_list:
1408 rte_free(dev->data->mac_addrs);
1410 i40e_vsi_release(pf->main_vsi);
1411 err_setup_pf_switch:
1413 err_configure_lan_hmc:
1414 (void)i40e_shutdown_lan_hmc(hw);
1416 i40e_res_pool_destroy(&pf->msix_pool);
1418 i40e_res_pool_destroy(&pf->qp_pool);
1421 err_get_capabilities:
1422 (void)i40e_shutdown_adminq(hw);
1428 i40e_rm_ethtype_filter_list(struct i40e_pf *pf)
1430 struct i40e_ethertype_filter *p_ethertype;
1431 struct i40e_ethertype_rule *ethertype_rule;
1433 ethertype_rule = &pf->ethertype;
1434 /* Remove all ethertype filter rules and hash */
1435 if (ethertype_rule->hash_map)
1436 rte_free(ethertype_rule->hash_map);
1437 if (ethertype_rule->hash_table)
1438 rte_hash_free(ethertype_rule->hash_table);
1440 while ((p_ethertype = TAILQ_FIRST(ðertype_rule->ethertype_list))) {
1441 TAILQ_REMOVE(ðertype_rule->ethertype_list,
1442 p_ethertype, rules);
1443 rte_free(p_ethertype);
1448 i40e_rm_tunnel_filter_list(struct i40e_pf *pf)
1450 struct i40e_tunnel_filter *p_tunnel;
1451 struct i40e_tunnel_rule *tunnel_rule;
1453 tunnel_rule = &pf->tunnel;
1454 /* Remove all tunnel director rules and hash */
1455 if (tunnel_rule->hash_map)
1456 rte_free(tunnel_rule->hash_map);
1457 if (tunnel_rule->hash_table)
1458 rte_hash_free(tunnel_rule->hash_table);
1460 while ((p_tunnel = TAILQ_FIRST(&tunnel_rule->tunnel_list))) {
1461 TAILQ_REMOVE(&tunnel_rule->tunnel_list, p_tunnel, rules);
1467 i40e_rm_fdir_filter_list(struct i40e_pf *pf)
1469 struct i40e_fdir_filter *p_fdir;
1470 struct i40e_fdir_info *fdir_info;
1472 fdir_info = &pf->fdir;
1473 /* Remove all flow director rules and hash */
1474 if (fdir_info->hash_map)
1475 rte_free(fdir_info->hash_map);
1476 if (fdir_info->hash_table)
1477 rte_hash_free(fdir_info->hash_table);
1479 while ((p_fdir = TAILQ_FIRST(&fdir_info->fdir_list))) {
1480 TAILQ_REMOVE(&fdir_info->fdir_list, p_fdir, rules);
1485 void i40e_flex_payload_reg_set_default(struct i40e_hw *hw)
1488 * Disable by default flexible payload
1489 * for corresponding L2/L3/L4 layers.
1491 I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(33), 0x00000000);
1492 I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(34), 0x00000000);
1493 I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(35), 0x00000000);
1494 i40e_global_cfg_warning(I40E_WARNING_DIS_FLX_PLD);
1498 eth_i40e_dev_uninit(struct rte_eth_dev *dev)
1501 struct rte_pci_device *pci_dev;
1502 struct rte_intr_handle *intr_handle;
1504 struct i40e_filter_control_settings settings;
1505 struct rte_flow *p_flow;
1507 uint8_t aq_fail = 0;
1510 PMD_INIT_FUNC_TRACE();
1512 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1515 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1516 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1517 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1518 intr_handle = &pci_dev->intr_handle;
1520 if (hw->adapter_stopped == 0)
1521 i40e_dev_close(dev);
1523 dev->dev_ops = NULL;
1524 dev->rx_pkt_burst = NULL;
1525 dev->tx_pkt_burst = NULL;
1527 /* Clear PXE mode */
1528 i40e_clear_pxe_mode(hw);
1530 /* Unconfigure filter control */
1531 memset(&settings, 0, sizeof(settings));
1532 ret = i40e_set_filter_control(hw, &settings);
1534 PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
1537 /* Disable flow control */
1538 hw->fc.requested_mode = I40E_FC_NONE;
1539 i40e_set_fc(hw, &aq_fail, TRUE);
1541 /* uninitialize pf host driver */
1542 i40e_pf_host_uninit(dev);
1544 rte_free(dev->data->mac_addrs);
1545 dev->data->mac_addrs = NULL;
1547 /* disable uio intr before callback unregister */
1548 rte_intr_disable(intr_handle);
1550 /* unregister callback func to eal lib */
1552 ret = rte_intr_callback_unregister(intr_handle,
1553 i40e_dev_interrupt_handler, dev);
1556 } else if (ret != -EAGAIN) {
1558 "intr callback unregister failed: %d",
1562 i40e_msec_delay(500);
1563 } while (retries++ < 5);
1565 i40e_rm_ethtype_filter_list(pf);
1566 i40e_rm_tunnel_filter_list(pf);
1567 i40e_rm_fdir_filter_list(pf);
1569 /* Remove all flows */
1570 while ((p_flow = TAILQ_FIRST(&pf->flow_list))) {
1571 TAILQ_REMOVE(&pf->flow_list, p_flow, node);
1575 /* Remove all Traffic Manager configuration */
1576 i40e_tm_conf_uninit(dev);
1582 i40e_dev_configure(struct rte_eth_dev *dev)
1584 struct i40e_adapter *ad =
1585 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1586 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1587 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1588 enum rte_eth_rx_mq_mode mq_mode = dev->data->dev_conf.rxmode.mq_mode;
1591 ret = i40e_dev_sync_phy_type(hw);
1595 /* Initialize to TRUE. If any of Rx queues doesn't meet the
1596 * bulk allocation or vector Rx preconditions we will reset it.
1598 ad->rx_bulk_alloc_allowed = true;
1599 ad->rx_vec_allowed = true;
1600 ad->tx_simple_allowed = true;
1601 ad->tx_vec_allowed = true;
1603 if (dev->data->dev_conf.fdir_conf.mode == RTE_FDIR_MODE_PERFECT) {
1604 ret = i40e_fdir_setup(pf);
1605 if (ret != I40E_SUCCESS) {
1606 PMD_DRV_LOG(ERR, "Failed to setup flow director.");
1609 ret = i40e_fdir_configure(dev);
1611 PMD_DRV_LOG(ERR, "failed to configure fdir.");
1615 i40e_fdir_teardown(pf);
1617 ret = i40e_dev_init_vlan(dev);
1622 * Needs to move VMDQ setting out of i40e_pf_config_mq_rx() as VMDQ and
1623 * RSS setting have different requirements.
1624 * General PMD driver call sequence are NIC init, configure,
1625 * rx/tx_queue_setup and dev_start. In rx/tx_queue_setup() function, it
1626 * will try to lookup the VSI that specific queue belongs to if VMDQ
1627 * applicable. So, VMDQ setting has to be done before
1628 * rx/tx_queue_setup(). This function is good to place vmdq_setup.
1629 * For RSS setting, it will try to calculate actual configured RX queue
1630 * number, which will be available after rx_queue_setup(). dev_start()
1631 * function is good to place RSS setup.
1633 if (mq_mode & ETH_MQ_RX_VMDQ_FLAG) {
1634 ret = i40e_vmdq_setup(dev);
1639 if (mq_mode & ETH_MQ_RX_DCB_FLAG) {
1640 ret = i40e_dcb_setup(dev);
1642 PMD_DRV_LOG(ERR, "failed to configure DCB.");
1647 TAILQ_INIT(&pf->flow_list);
1652 /* need to release vmdq resource if exists */
1653 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1654 i40e_vsi_release(pf->vmdq[i].vsi);
1655 pf->vmdq[i].vsi = NULL;
1660 /* need to release fdir resource if exists */
1661 i40e_fdir_teardown(pf);
1666 i40e_vsi_queues_unbind_intr(struct i40e_vsi *vsi)
1668 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1669 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1670 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1671 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1672 uint16_t msix_vect = vsi->msix_intr;
1675 for (i = 0; i < vsi->nb_qps; i++) {
1676 I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
1677 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
1681 if (vsi->type != I40E_VSI_SRIOV) {
1682 if (!rte_intr_allow_others(intr_handle)) {
1683 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
1684 I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
1686 I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
1689 I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
1690 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
1692 I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
1697 reg = (hw->func_caps.num_msix_vectors_vf - 1) *
1698 vsi->user_param + (msix_vect - 1);
1700 I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
1701 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
1703 I40E_WRITE_FLUSH(hw);
1707 __vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t msix_vect,
1708 int base_queue, int nb_queue,
1713 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1714 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
1716 /* Bind all RX queues to allocated MSIX interrupt */
1717 for (i = 0; i < nb_queue; i++) {
1718 val = (msix_vect << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
1719 itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT |
1720 ((base_queue + i + 1) <<
1721 I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
1722 (0 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
1723 I40E_QINT_RQCTL_CAUSE_ENA_MASK;
1725 if (i == nb_queue - 1)
1726 val |= I40E_QINT_RQCTL_NEXTQ_INDX_MASK;
1727 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(base_queue + i), val);
1730 /* Write first RX queue to Link list register as the head element */
1731 if (vsi->type != I40E_VSI_SRIOV) {
1733 i40e_calc_itr_interval(RTE_LIBRTE_I40E_ITR_INTERVAL, 1,
1734 pf->support_multi_driver);
1736 if (msix_vect == I40E_MISC_VEC_ID) {
1737 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
1739 I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
1741 I40E_PFINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
1743 I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
1746 I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
1748 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
1750 I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
1752 I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
1759 if (msix_vect == I40E_MISC_VEC_ID) {
1761 I40E_VPINT_LNKLST0(vsi->user_param),
1763 I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
1765 I40E_VPINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
1767 /* num_msix_vectors_vf needs to minus irq0 */
1768 reg = (hw->func_caps.num_msix_vectors_vf - 1) *
1769 vsi->user_param + (msix_vect - 1);
1771 I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
1773 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
1775 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
1779 I40E_WRITE_FLUSH(hw);
1783 i40e_vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t itr_idx)
1785 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1786 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1787 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1788 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1789 uint16_t msix_vect = vsi->msix_intr;
1790 uint16_t nb_msix = RTE_MIN(vsi->nb_msix, intr_handle->nb_efd);
1791 uint16_t queue_idx = 0;
1795 for (i = 0; i < vsi->nb_qps; i++) {
1796 I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
1797 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
1800 /* VF bind interrupt */
1801 if (vsi->type == I40E_VSI_SRIOV) {
1802 __vsi_queues_bind_intr(vsi, msix_vect,
1803 vsi->base_queue, vsi->nb_qps,
1808 /* PF & VMDq bind interrupt */
1809 if (rte_intr_dp_is_en(intr_handle)) {
1810 if (vsi->type == I40E_VSI_MAIN) {
1813 } else if (vsi->type == I40E_VSI_VMDQ2) {
1814 struct i40e_vsi *main_vsi =
1815 I40E_DEV_PRIVATE_TO_MAIN_VSI(vsi->adapter);
1816 queue_idx = vsi->base_queue - main_vsi->nb_qps;
1821 for (i = 0; i < vsi->nb_used_qps; i++) {
1823 if (!rte_intr_allow_others(intr_handle))
1824 /* allow to share MISC_VEC_ID */
1825 msix_vect = I40E_MISC_VEC_ID;
1827 /* no enough msix_vect, map all to one */
1828 __vsi_queues_bind_intr(vsi, msix_vect,
1829 vsi->base_queue + i,
1830 vsi->nb_used_qps - i,
1832 for (; !!record && i < vsi->nb_used_qps; i++)
1833 intr_handle->intr_vec[queue_idx + i] =
1837 /* 1:1 queue/msix_vect mapping */
1838 __vsi_queues_bind_intr(vsi, msix_vect,
1839 vsi->base_queue + i, 1,
1842 intr_handle->intr_vec[queue_idx + i] = msix_vect;
1850 i40e_vsi_enable_queues_intr(struct i40e_vsi *vsi)
1852 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1853 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1854 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1855 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1856 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
1857 uint16_t msix_intr, i;
1859 if (rte_intr_allow_others(intr_handle) && !pf->support_multi_driver)
1860 for (i = 0; i < vsi->nb_msix; i++) {
1861 msix_intr = vsi->msix_intr + i;
1862 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
1863 I40E_PFINT_DYN_CTLN_INTENA_MASK |
1864 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
1865 I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
1868 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
1869 I40E_PFINT_DYN_CTL0_INTENA_MASK |
1870 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
1871 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
1873 I40E_WRITE_FLUSH(hw);
1877 i40e_vsi_disable_queues_intr(struct i40e_vsi *vsi)
1879 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1880 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1881 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1882 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1883 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
1884 uint16_t msix_intr, i;
1886 if (rte_intr_allow_others(intr_handle) && !pf->support_multi_driver)
1887 for (i = 0; i < vsi->nb_msix; i++) {
1888 msix_intr = vsi->msix_intr + i;
1889 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
1890 I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
1893 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
1894 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
1896 I40E_WRITE_FLUSH(hw);
1899 static inline uint8_t
1900 i40e_parse_link_speeds(uint16_t link_speeds)
1902 uint8_t link_speed = I40E_LINK_SPEED_UNKNOWN;
1904 if (link_speeds & ETH_LINK_SPEED_40G)
1905 link_speed |= I40E_LINK_SPEED_40GB;
1906 if (link_speeds & ETH_LINK_SPEED_25G)
1907 link_speed |= I40E_LINK_SPEED_25GB;
1908 if (link_speeds & ETH_LINK_SPEED_20G)
1909 link_speed |= I40E_LINK_SPEED_20GB;
1910 if (link_speeds & ETH_LINK_SPEED_10G)
1911 link_speed |= I40E_LINK_SPEED_10GB;
1912 if (link_speeds & ETH_LINK_SPEED_1G)
1913 link_speed |= I40E_LINK_SPEED_1GB;
1914 if (link_speeds & ETH_LINK_SPEED_100M)
1915 link_speed |= I40E_LINK_SPEED_100MB;
1921 i40e_phy_conf_link(struct i40e_hw *hw,
1923 uint8_t force_speed,
1926 enum i40e_status_code status;
1927 struct i40e_aq_get_phy_abilities_resp phy_ab;
1928 struct i40e_aq_set_phy_config phy_conf;
1929 enum i40e_aq_phy_type cnt;
1930 uint32_t phy_type_mask = 0;
1932 const uint8_t mask = I40E_AQ_PHY_FLAG_PAUSE_TX |
1933 I40E_AQ_PHY_FLAG_PAUSE_RX |
1934 I40E_AQ_PHY_FLAG_PAUSE_RX |
1935 I40E_AQ_PHY_FLAG_LOW_POWER;
1936 const uint8_t advt = I40E_LINK_SPEED_40GB |
1937 I40E_LINK_SPEED_25GB |
1938 I40E_LINK_SPEED_10GB |
1939 I40E_LINK_SPEED_1GB |
1940 I40E_LINK_SPEED_100MB;
1944 status = i40e_aq_get_phy_capabilities(hw, false, false, &phy_ab,
1949 /* If link already up, no need to set up again */
1950 if (is_up && phy_ab.phy_type != 0)
1951 return I40E_SUCCESS;
1953 memset(&phy_conf, 0, sizeof(phy_conf));
1955 /* bits 0-2 use the values from get_phy_abilities_resp */
1957 abilities |= phy_ab.abilities & mask;
1959 /* update ablities and speed */
1960 if (abilities & I40E_AQ_PHY_AN_ENABLED)
1961 phy_conf.link_speed = advt;
1963 phy_conf.link_speed = is_up ? force_speed : phy_ab.link_speed;
1965 phy_conf.abilities = abilities;
1969 /* To enable link, phy_type mask needs to include each type */
1970 for (cnt = I40E_PHY_TYPE_SGMII; cnt < I40E_PHY_TYPE_MAX; cnt++)
1971 phy_type_mask |= 1 << cnt;
1973 /* use get_phy_abilities_resp value for the rest */
1974 phy_conf.phy_type = is_up ? cpu_to_le32(phy_type_mask) : 0;
1975 phy_conf.phy_type_ext = is_up ? (I40E_AQ_PHY_TYPE_EXT_25G_KR |
1976 I40E_AQ_PHY_TYPE_EXT_25G_CR | I40E_AQ_PHY_TYPE_EXT_25G_SR |
1977 I40E_AQ_PHY_TYPE_EXT_25G_LR) : 0;
1978 phy_conf.fec_config = phy_ab.fec_cfg_curr_mod_ext_info;
1979 phy_conf.eee_capability = phy_ab.eee_capability;
1980 phy_conf.eeer = phy_ab.eeer_val;
1981 phy_conf.low_power_ctrl = phy_ab.d3_lpan;
1983 PMD_DRV_LOG(DEBUG, "\tCurrent: abilities %x, link_speed %x",
1984 phy_ab.abilities, phy_ab.link_speed);
1985 PMD_DRV_LOG(DEBUG, "\tConfig: abilities %x, link_speed %x",
1986 phy_conf.abilities, phy_conf.link_speed);
1988 status = i40e_aq_set_phy_config(hw, &phy_conf, NULL);
1992 return I40E_SUCCESS;
1996 i40e_apply_link_speed(struct rte_eth_dev *dev)
1999 uint8_t abilities = 0;
2000 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2001 struct rte_eth_conf *conf = &dev->data->dev_conf;
2003 speed = i40e_parse_link_speeds(conf->link_speeds);
2004 abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
2005 if (!(conf->link_speeds & ETH_LINK_SPEED_FIXED))
2006 abilities |= I40E_AQ_PHY_AN_ENABLED;
2007 abilities |= I40E_AQ_PHY_LINK_ENABLED;
2009 return i40e_phy_conf_link(hw, abilities, speed, true);
2013 i40e_dev_start(struct rte_eth_dev *dev)
2015 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2016 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2017 struct i40e_vsi *main_vsi = pf->main_vsi;
2019 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2020 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2021 uint32_t intr_vector = 0;
2022 struct i40e_vsi *vsi;
2024 hw->adapter_stopped = 0;
2026 if (dev->data->dev_conf.link_speeds & ETH_LINK_SPEED_FIXED) {
2028 "Invalid link_speeds for port %u, autonegotiation disabled",
2029 dev->data->port_id);
2033 rte_intr_disable(intr_handle);
2035 if ((rte_intr_cap_multiple(intr_handle) ||
2036 !RTE_ETH_DEV_SRIOV(dev).active) &&
2037 dev->data->dev_conf.intr_conf.rxq != 0) {
2038 intr_vector = dev->data->nb_rx_queues;
2039 ret = rte_intr_efd_enable(intr_handle, intr_vector);
2044 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
2045 intr_handle->intr_vec =
2046 rte_zmalloc("intr_vec",
2047 dev->data->nb_rx_queues * sizeof(int),
2049 if (!intr_handle->intr_vec) {
2051 "Failed to allocate %d rx_queues intr_vec",
2052 dev->data->nb_rx_queues);
2057 /* Initialize VSI */
2058 ret = i40e_dev_rxtx_init(pf);
2059 if (ret != I40E_SUCCESS) {
2060 PMD_DRV_LOG(ERR, "Failed to init rx/tx queues");
2064 /* Map queues with MSIX interrupt */
2065 main_vsi->nb_used_qps = dev->data->nb_rx_queues -
2066 pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
2067 i40e_vsi_queues_bind_intr(main_vsi, I40E_ITR_INDEX_DEFAULT);
2068 i40e_vsi_enable_queues_intr(main_vsi);
2070 /* Map VMDQ VSI queues with MSIX interrupt */
2071 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2072 pf->vmdq[i].vsi->nb_used_qps = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
2073 i40e_vsi_queues_bind_intr(pf->vmdq[i].vsi,
2074 I40E_ITR_INDEX_DEFAULT);
2075 i40e_vsi_enable_queues_intr(pf->vmdq[i].vsi);
2078 /* enable FDIR MSIX interrupt */
2079 if (pf->fdir.fdir_vsi) {
2080 i40e_vsi_queues_bind_intr(pf->fdir.fdir_vsi,
2081 I40E_ITR_INDEX_NONE);
2082 i40e_vsi_enable_queues_intr(pf->fdir.fdir_vsi);
2085 /* Enable all queues which have been configured */
2086 ret = i40e_dev_switch_queues(pf, TRUE);
2087 if (ret != I40E_SUCCESS) {
2088 PMD_DRV_LOG(ERR, "Failed to enable VSI");
2092 /* Enable receiving broadcast packets */
2093 ret = i40e_aq_set_vsi_broadcast(hw, main_vsi->seid, true, NULL);
2094 if (ret != I40E_SUCCESS)
2095 PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
2097 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2098 ret = i40e_aq_set_vsi_broadcast(hw, pf->vmdq[i].vsi->seid,
2100 if (ret != I40E_SUCCESS)
2101 PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
2104 /* Enable the VLAN promiscuous mode. */
2106 for (i = 0; i < pf->vf_num; i++) {
2107 vsi = pf->vfs[i].vsi;
2108 i40e_aq_set_vsi_vlan_promisc(hw, vsi->seid,
2113 /* Enable mac loopback mode */
2114 if (dev->data->dev_conf.lpbk_mode == I40E_AQ_LB_MODE_NONE ||
2115 dev->data->dev_conf.lpbk_mode == I40E_AQ_LB_PHY_LOCAL) {
2116 ret = i40e_aq_set_lb_modes(hw, dev->data->dev_conf.lpbk_mode, NULL);
2117 if (ret != I40E_SUCCESS) {
2118 PMD_DRV_LOG(ERR, "fail to set loopback link");
2123 /* Apply link configure */
2124 if (dev->data->dev_conf.link_speeds & ~(ETH_LINK_SPEED_100M |
2125 ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G |
2126 ETH_LINK_SPEED_20G | ETH_LINK_SPEED_25G |
2127 ETH_LINK_SPEED_40G)) {
2128 PMD_DRV_LOG(ERR, "Invalid link setting");
2131 ret = i40e_apply_link_speed(dev);
2132 if (I40E_SUCCESS != ret) {
2133 PMD_DRV_LOG(ERR, "Fail to apply link setting");
2137 if (!rte_intr_allow_others(intr_handle)) {
2138 rte_intr_callback_unregister(intr_handle,
2139 i40e_dev_interrupt_handler,
2141 /* configure and enable device interrupt */
2142 i40e_pf_config_irq0(hw, FALSE);
2143 i40e_pf_enable_irq0(hw);
2145 if (dev->data->dev_conf.intr_conf.lsc != 0)
2147 "lsc won't enable because of no intr multiplex");
2149 ret = i40e_aq_set_phy_int_mask(hw,
2150 ~(I40E_AQ_EVENT_LINK_UPDOWN |
2151 I40E_AQ_EVENT_MODULE_QUAL_FAIL |
2152 I40E_AQ_EVENT_MEDIA_NA), NULL);
2153 if (ret != I40E_SUCCESS)
2154 PMD_DRV_LOG(WARNING, "Fail to set phy mask");
2156 /* Call get_link_info aq commond to enable/disable LSE */
2157 i40e_dev_link_update(dev, 0);
2160 /* enable uio intr after callback register */
2161 rte_intr_enable(intr_handle);
2163 i40e_filter_restore(pf);
2165 if (pf->tm_conf.root && !pf->tm_conf.committed)
2166 PMD_DRV_LOG(WARNING,
2167 "please call hierarchy_commit() "
2168 "before starting the port");
2170 return I40E_SUCCESS;
2173 i40e_dev_switch_queues(pf, FALSE);
2174 i40e_dev_clear_queues(dev);
2180 i40e_dev_stop(struct rte_eth_dev *dev)
2182 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2183 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2184 struct i40e_vsi *main_vsi = pf->main_vsi;
2185 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2186 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2189 if (hw->adapter_stopped == 1)
2191 /* Disable all queues */
2192 i40e_dev_switch_queues(pf, FALSE);
2194 /* un-map queues with interrupt registers */
2195 i40e_vsi_disable_queues_intr(main_vsi);
2196 i40e_vsi_queues_unbind_intr(main_vsi);
2198 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2199 i40e_vsi_disable_queues_intr(pf->vmdq[i].vsi);
2200 i40e_vsi_queues_unbind_intr(pf->vmdq[i].vsi);
2203 if (pf->fdir.fdir_vsi) {
2204 i40e_vsi_queues_unbind_intr(pf->fdir.fdir_vsi);
2205 i40e_vsi_disable_queues_intr(pf->fdir.fdir_vsi);
2207 /* Clear all queues and release memory */
2208 i40e_dev_clear_queues(dev);
2211 i40e_dev_set_link_down(dev);
2213 if (!rte_intr_allow_others(intr_handle))
2214 /* resume to the default handler */
2215 rte_intr_callback_register(intr_handle,
2216 i40e_dev_interrupt_handler,
2219 /* Clean datapath event and queue/vec mapping */
2220 rte_intr_efd_disable(intr_handle);
2221 if (intr_handle->intr_vec) {
2222 rte_free(intr_handle->intr_vec);
2223 intr_handle->intr_vec = NULL;
2226 /* reset hierarchy commit */
2227 pf->tm_conf.committed = false;
2229 hw->adapter_stopped = 1;
2233 i40e_dev_close(struct rte_eth_dev *dev)
2235 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2236 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2237 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2238 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2239 struct i40e_mirror_rule *p_mirror;
2244 PMD_INIT_FUNC_TRACE();
2248 /* Remove all mirror rules */
2249 while ((p_mirror = TAILQ_FIRST(&pf->mirror_list))) {
2250 ret = i40e_aq_del_mirror_rule(hw,
2251 pf->main_vsi->veb->seid,
2252 p_mirror->rule_type,
2254 p_mirror->num_entries,
2257 PMD_DRV_LOG(ERR, "failed to remove mirror rule: "
2258 "status = %d, aq_err = %d.", ret,
2259 hw->aq.asq_last_status);
2261 /* remove mirror software resource anyway */
2262 TAILQ_REMOVE(&pf->mirror_list, p_mirror, rules);
2264 pf->nb_mirror_rule--;
2267 i40e_dev_free_queues(dev);
2269 /* Disable interrupt */
2270 i40e_pf_disable_irq0(hw);
2271 rte_intr_disable(intr_handle);
2273 /* shutdown and destroy the HMC */
2274 i40e_shutdown_lan_hmc(hw);
2276 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2277 i40e_vsi_release(pf->vmdq[i].vsi);
2278 pf->vmdq[i].vsi = NULL;
2283 /* release all the existing VSIs and VEBs */
2284 i40e_fdir_teardown(pf);
2285 i40e_vsi_release(pf->main_vsi);
2287 /* shutdown the adminq */
2288 i40e_aq_queue_shutdown(hw, true);
2289 i40e_shutdown_adminq(hw);
2291 i40e_res_pool_destroy(&pf->qp_pool);
2292 i40e_res_pool_destroy(&pf->msix_pool);
2294 /* Disable flexible payload in global configuration */
2295 if (!pf->support_multi_driver)
2296 i40e_flex_payload_reg_set_default(hw);
2298 /* force a PF reset to clean anything leftover */
2299 reg = I40E_READ_REG(hw, I40E_PFGEN_CTRL);
2300 I40E_WRITE_REG(hw, I40E_PFGEN_CTRL,
2301 (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
2302 I40E_WRITE_FLUSH(hw);
2306 * Reset PF device only to re-initialize resources in PMD layer
2309 i40e_dev_reset(struct rte_eth_dev *dev)
2313 /* When a DPDK PMD PF begin to reset PF port, it should notify all
2314 * its VF to make them align with it. The detailed notification
2315 * mechanism is PMD specific. As to i40e PF, it is rather complex.
2316 * To avoid unexpected behavior in VF, currently reset of PF with
2317 * SR-IOV activation is not supported. It might be supported later.
2319 if (dev->data->sriov.active)
2322 ret = eth_i40e_dev_uninit(dev);
2326 ret = eth_i40e_dev_init(dev);
2332 i40e_dev_promiscuous_enable(struct rte_eth_dev *dev)
2334 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2335 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2336 struct i40e_vsi *vsi = pf->main_vsi;
2339 status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2341 if (status != I40E_SUCCESS)
2342 PMD_DRV_LOG(ERR, "Failed to enable unicast promiscuous");
2344 status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
2346 if (status != I40E_SUCCESS)
2347 PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
2352 i40e_dev_promiscuous_disable(struct rte_eth_dev *dev)
2354 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2355 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2356 struct i40e_vsi *vsi = pf->main_vsi;
2359 status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2361 if (status != I40E_SUCCESS)
2362 PMD_DRV_LOG(ERR, "Failed to disable unicast promiscuous");
2364 status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
2366 if (status != I40E_SUCCESS)
2367 PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
2371 i40e_dev_allmulticast_enable(struct rte_eth_dev *dev)
2373 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2374 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2375 struct i40e_vsi *vsi = pf->main_vsi;
2378 ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid, TRUE, NULL);
2379 if (ret != I40E_SUCCESS)
2380 PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
2384 i40e_dev_allmulticast_disable(struct rte_eth_dev *dev)
2386 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2387 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2388 struct i40e_vsi *vsi = pf->main_vsi;
2391 if (dev->data->promiscuous == 1)
2392 return; /* must remain in all_multicast mode */
2394 ret = i40e_aq_set_vsi_multicast_promiscuous(hw,
2395 vsi->seid, FALSE, NULL);
2396 if (ret != I40E_SUCCESS)
2397 PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
2401 * Set device link up.
2404 i40e_dev_set_link_up(struct rte_eth_dev *dev)
2406 /* re-apply link speed setting */
2407 return i40e_apply_link_speed(dev);
2411 * Set device link down.
2414 i40e_dev_set_link_down(struct rte_eth_dev *dev)
2416 uint8_t speed = I40E_LINK_SPEED_UNKNOWN;
2417 uint8_t abilities = 0;
2418 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2420 abilities = I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
2421 return i40e_phy_conf_link(hw, abilities, speed, false);
2424 static __rte_always_inline void
2425 update_link_no_wait(struct i40e_hw *hw, struct rte_eth_link *link)
2427 /* Link status registers and values*/
2428 #define I40E_PRTMAC_LINKSTA 0x001E2420
2429 #define I40E_REG_LINK_UP 0x40000080
2430 #define I40E_PRTMAC_MACC 0x001E24E0
2431 #define I40E_REG_MACC_25GB 0x00020000
2432 #define I40E_REG_SPEED_MASK 0x38000000
2433 #define I40E_REG_SPEED_100MB 0x00000000
2434 #define I40E_REG_SPEED_1GB 0x08000000
2435 #define I40E_REG_SPEED_10GB 0x10000000
2436 #define I40E_REG_SPEED_20GB 0x20000000
2437 #define I40E_REG_SPEED_25_40GB 0x18000000
2438 uint32_t link_speed;
2441 reg_val = I40E_READ_REG(hw, I40E_PRTMAC_LINKSTA);
2442 link_speed = reg_val & I40E_REG_SPEED_MASK;
2443 reg_val &= I40E_REG_LINK_UP;
2444 link->link_status = (reg_val == I40E_REG_LINK_UP) ? 1 : 0;
2446 if (unlikely(link->link_status != 0))
2449 /* Parse the link status */
2450 switch (link_speed) {
2451 case I40E_REG_SPEED_100MB:
2452 link->link_speed = ETH_SPEED_NUM_100M;
2454 case I40E_REG_SPEED_1GB:
2455 link->link_speed = ETH_SPEED_NUM_1G;
2457 case I40E_REG_SPEED_10GB:
2458 link->link_speed = ETH_SPEED_NUM_10G;
2460 case I40E_REG_SPEED_20GB:
2461 link->link_speed = ETH_SPEED_NUM_20G;
2463 case I40E_REG_SPEED_25_40GB:
2464 reg_val = I40E_READ_REG(hw, I40E_PRTMAC_MACC);
2466 if (reg_val & I40E_REG_MACC_25GB)
2467 link->link_speed = ETH_SPEED_NUM_25G;
2469 link->link_speed = ETH_SPEED_NUM_40G;
2473 PMD_DRV_LOG(ERR, "Unknown link speed info %u", link_speed);
2478 static __rte_always_inline void
2479 update_link_wait(struct i40e_hw *hw, struct rte_eth_link *link,
2482 #define CHECK_INTERVAL 100 /* 100ms */
2483 #define MAX_REPEAT_TIME 10 /* 1s (10 * 100ms) in total */
2484 uint32_t rep_cnt = MAX_REPEAT_TIME;
2485 struct i40e_link_status link_status;
2488 memset(&link_status, 0, sizeof(link_status));
2491 memset(&link_status, 0, sizeof(link_status));
2493 /* Get link status information from hardware */
2494 status = i40e_aq_get_link_info(hw, enable_lse,
2495 &link_status, NULL);
2496 if (unlikely(status != I40E_SUCCESS)) {
2497 link->link_speed = ETH_SPEED_NUM_100M;
2498 link->link_duplex = ETH_LINK_FULL_DUPLEX;
2499 PMD_DRV_LOG(ERR, "Failed to get link info");
2503 link->link_status = link_status.link_info & I40E_AQ_LINK_UP;
2504 if (unlikely(link->link_status != 0))
2507 rte_delay_ms(CHECK_INTERVAL);
2508 } while (--rep_cnt);
2510 /* Parse the link status */
2511 switch (link_status.link_speed) {
2512 case I40E_LINK_SPEED_100MB:
2513 link->link_speed = ETH_SPEED_NUM_100M;
2515 case I40E_LINK_SPEED_1GB:
2516 link->link_speed = ETH_SPEED_NUM_1G;
2518 case I40E_LINK_SPEED_10GB:
2519 link->link_speed = ETH_SPEED_NUM_10G;
2521 case I40E_LINK_SPEED_20GB:
2522 link->link_speed = ETH_SPEED_NUM_20G;
2524 case I40E_LINK_SPEED_25GB:
2525 link->link_speed = ETH_SPEED_NUM_25G;
2527 case I40E_LINK_SPEED_40GB:
2528 link->link_speed = ETH_SPEED_NUM_40G;
2531 link->link_speed = ETH_SPEED_NUM_100M;
2537 i40e_dev_link_update(struct rte_eth_dev *dev,
2538 int wait_to_complete)
2540 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2541 struct rte_eth_link link;
2542 bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
2545 memset(&link, 0, sizeof(link));
2547 /* i40e uses full duplex only */
2548 link.link_duplex = ETH_LINK_FULL_DUPLEX;
2549 link.link_autoneg = !(dev->data->dev_conf.link_speeds &
2550 ETH_LINK_SPEED_FIXED);
2552 if (!wait_to_complete)
2553 update_link_no_wait(hw, &link);
2555 update_link_wait(hw, &link, enable_lse);
2557 ret = rte_eth_linkstatus_set(dev, &link);
2558 i40e_notify_all_vfs_link_status(dev);
2563 /* Get all the statistics of a VSI */
2565 i40e_update_vsi_stats(struct i40e_vsi *vsi)
2567 struct i40e_eth_stats *oes = &vsi->eth_stats_offset;
2568 struct i40e_eth_stats *nes = &vsi->eth_stats;
2569 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2570 int idx = rte_le_to_cpu_16(vsi->info.stat_counter_idx);
2572 i40e_stat_update_48(hw, I40E_GLV_GORCH(idx), I40E_GLV_GORCL(idx),
2573 vsi->offset_loaded, &oes->rx_bytes,
2575 i40e_stat_update_48(hw, I40E_GLV_UPRCH(idx), I40E_GLV_UPRCL(idx),
2576 vsi->offset_loaded, &oes->rx_unicast,
2578 i40e_stat_update_48(hw, I40E_GLV_MPRCH(idx), I40E_GLV_MPRCL(idx),
2579 vsi->offset_loaded, &oes->rx_multicast,
2580 &nes->rx_multicast);
2581 i40e_stat_update_48(hw, I40E_GLV_BPRCH(idx), I40E_GLV_BPRCL(idx),
2582 vsi->offset_loaded, &oes->rx_broadcast,
2583 &nes->rx_broadcast);
2584 /* exclude CRC bytes */
2585 nes->rx_bytes -= (nes->rx_unicast + nes->rx_multicast +
2586 nes->rx_broadcast) * ETHER_CRC_LEN;
2588 i40e_stat_update_32(hw, I40E_GLV_RDPC(idx), vsi->offset_loaded,
2589 &oes->rx_discards, &nes->rx_discards);
2590 /* GLV_REPC not supported */
2591 /* GLV_RMPC not supported */
2592 i40e_stat_update_32(hw, I40E_GLV_RUPP(idx), vsi->offset_loaded,
2593 &oes->rx_unknown_protocol,
2594 &nes->rx_unknown_protocol);
2595 i40e_stat_update_48(hw, I40E_GLV_GOTCH(idx), I40E_GLV_GOTCL(idx),
2596 vsi->offset_loaded, &oes->tx_bytes,
2598 i40e_stat_update_48(hw, I40E_GLV_UPTCH(idx), I40E_GLV_UPTCL(idx),
2599 vsi->offset_loaded, &oes->tx_unicast,
2601 i40e_stat_update_48(hw, I40E_GLV_MPTCH(idx), I40E_GLV_MPTCL(idx),
2602 vsi->offset_loaded, &oes->tx_multicast,
2603 &nes->tx_multicast);
2604 i40e_stat_update_48(hw, I40E_GLV_BPTCH(idx), I40E_GLV_BPTCL(idx),
2605 vsi->offset_loaded, &oes->tx_broadcast,
2606 &nes->tx_broadcast);
2607 /* GLV_TDPC not supported */
2608 i40e_stat_update_32(hw, I40E_GLV_TEPC(idx), vsi->offset_loaded,
2609 &oes->tx_errors, &nes->tx_errors);
2610 vsi->offset_loaded = true;
2612 PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats start *******************",
2614 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", nes->rx_bytes);
2615 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", nes->rx_unicast);
2616 PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", nes->rx_multicast);
2617 PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", nes->rx_broadcast);
2618 PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", nes->rx_discards);
2619 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
2620 nes->rx_unknown_protocol);
2621 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", nes->tx_bytes);
2622 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", nes->tx_unicast);
2623 PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", nes->tx_multicast);
2624 PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", nes->tx_broadcast);
2625 PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", nes->tx_discards);
2626 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", nes->tx_errors);
2627 PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats end *******************",
2632 i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw)
2635 struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
2636 struct i40e_hw_port_stats *os = &pf->stats_offset; /* old stats */
2638 /* Get rx/tx bytes of internal transfer packets */
2639 i40e_stat_update_48(hw, I40E_GLV_GORCH(hw->port),
2640 I40E_GLV_GORCL(hw->port),
2642 &pf->internal_stats_offset.rx_bytes,
2643 &pf->internal_stats.rx_bytes);
2645 i40e_stat_update_48(hw, I40E_GLV_GOTCH(hw->port),
2646 I40E_GLV_GOTCL(hw->port),
2648 &pf->internal_stats_offset.tx_bytes,
2649 &pf->internal_stats.tx_bytes);
2650 /* Get total internal rx packet count */
2651 i40e_stat_update_48(hw, I40E_GLV_UPRCH(hw->port),
2652 I40E_GLV_UPRCL(hw->port),
2654 &pf->internal_stats_offset.rx_unicast,
2655 &pf->internal_stats.rx_unicast);
2656 i40e_stat_update_48(hw, I40E_GLV_MPRCH(hw->port),
2657 I40E_GLV_MPRCL(hw->port),
2659 &pf->internal_stats_offset.rx_multicast,
2660 &pf->internal_stats.rx_multicast);
2661 i40e_stat_update_48(hw, I40E_GLV_BPRCH(hw->port),
2662 I40E_GLV_BPRCL(hw->port),
2664 &pf->internal_stats_offset.rx_broadcast,
2665 &pf->internal_stats.rx_broadcast);
2666 /* Get total internal tx packet count */
2667 i40e_stat_update_48(hw, I40E_GLV_UPTCH(hw->port),
2668 I40E_GLV_UPTCL(hw->port),
2670 &pf->internal_stats_offset.tx_unicast,
2671 &pf->internal_stats.tx_unicast);
2672 i40e_stat_update_48(hw, I40E_GLV_MPTCH(hw->port),
2673 I40E_GLV_MPTCL(hw->port),
2675 &pf->internal_stats_offset.tx_multicast,
2676 &pf->internal_stats.tx_multicast);
2677 i40e_stat_update_48(hw, I40E_GLV_BPTCH(hw->port),
2678 I40E_GLV_BPTCL(hw->port),
2680 &pf->internal_stats_offset.tx_broadcast,
2681 &pf->internal_stats.tx_broadcast);
2683 /* exclude CRC size */
2684 pf->internal_stats.rx_bytes -= (pf->internal_stats.rx_unicast +
2685 pf->internal_stats.rx_multicast +
2686 pf->internal_stats.rx_broadcast) * ETHER_CRC_LEN;
2688 /* Get statistics of struct i40e_eth_stats */
2689 i40e_stat_update_48(hw, I40E_GLPRT_GORCH(hw->port),
2690 I40E_GLPRT_GORCL(hw->port),
2691 pf->offset_loaded, &os->eth.rx_bytes,
2693 i40e_stat_update_48(hw, I40E_GLPRT_UPRCH(hw->port),
2694 I40E_GLPRT_UPRCL(hw->port),
2695 pf->offset_loaded, &os->eth.rx_unicast,
2696 &ns->eth.rx_unicast);
2697 i40e_stat_update_48(hw, I40E_GLPRT_MPRCH(hw->port),
2698 I40E_GLPRT_MPRCL(hw->port),
2699 pf->offset_loaded, &os->eth.rx_multicast,
2700 &ns->eth.rx_multicast);
2701 i40e_stat_update_48(hw, I40E_GLPRT_BPRCH(hw->port),
2702 I40E_GLPRT_BPRCL(hw->port),
2703 pf->offset_loaded, &os->eth.rx_broadcast,
2704 &ns->eth.rx_broadcast);
2705 /* Workaround: CRC size should not be included in byte statistics,
2706 * so subtract ETHER_CRC_LEN from the byte counter for each rx packet.
2708 ns->eth.rx_bytes -= (ns->eth.rx_unicast + ns->eth.rx_multicast +
2709 ns->eth.rx_broadcast) * ETHER_CRC_LEN;
2711 /* exclude internal rx bytes
2712 * Workaround: it is possible I40E_GLV_GORCH[H/L] is updated before
2713 * I40E_GLPRT_GORCH[H/L], so there is a small window that cause negative
2715 * same to I40E_GLV_UPRC[H/L], I40E_GLV_MPRC[H/L], I40E_GLV_BPRC[H/L].
2717 if (ns->eth.rx_bytes < pf->internal_stats.rx_bytes)
2718 ns->eth.rx_bytes = 0;
2720 ns->eth.rx_bytes -= pf->internal_stats.rx_bytes;
2722 if (ns->eth.rx_unicast < pf->internal_stats.rx_unicast)
2723 ns->eth.rx_unicast = 0;
2725 ns->eth.rx_unicast -= pf->internal_stats.rx_unicast;
2727 if (ns->eth.rx_multicast < pf->internal_stats.rx_multicast)
2728 ns->eth.rx_multicast = 0;
2730 ns->eth.rx_multicast -= pf->internal_stats.rx_multicast;
2732 if (ns->eth.rx_broadcast < pf->internal_stats.rx_broadcast)
2733 ns->eth.rx_broadcast = 0;
2735 ns->eth.rx_broadcast -= pf->internal_stats.rx_broadcast;
2737 i40e_stat_update_32(hw, I40E_GLPRT_RDPC(hw->port),
2738 pf->offset_loaded, &os->eth.rx_discards,
2739 &ns->eth.rx_discards);
2740 /* GLPRT_REPC not supported */
2741 /* GLPRT_RMPC not supported */
2742 i40e_stat_update_32(hw, I40E_GLPRT_RUPP(hw->port),
2744 &os->eth.rx_unknown_protocol,
2745 &ns->eth.rx_unknown_protocol);
2746 i40e_stat_update_48(hw, I40E_GLPRT_GOTCH(hw->port),
2747 I40E_GLPRT_GOTCL(hw->port),
2748 pf->offset_loaded, &os->eth.tx_bytes,
2750 i40e_stat_update_48(hw, I40E_GLPRT_UPTCH(hw->port),
2751 I40E_GLPRT_UPTCL(hw->port),
2752 pf->offset_loaded, &os->eth.tx_unicast,
2753 &ns->eth.tx_unicast);
2754 i40e_stat_update_48(hw, I40E_GLPRT_MPTCH(hw->port),
2755 I40E_GLPRT_MPTCL(hw->port),
2756 pf->offset_loaded, &os->eth.tx_multicast,
2757 &ns->eth.tx_multicast);
2758 i40e_stat_update_48(hw, I40E_GLPRT_BPTCH(hw->port),
2759 I40E_GLPRT_BPTCL(hw->port),
2760 pf->offset_loaded, &os->eth.tx_broadcast,
2761 &ns->eth.tx_broadcast);
2762 ns->eth.tx_bytes -= (ns->eth.tx_unicast + ns->eth.tx_multicast +
2763 ns->eth.tx_broadcast) * ETHER_CRC_LEN;
2765 /* exclude internal tx bytes
2766 * Workaround: it is possible I40E_GLV_GOTCH[H/L] is updated before
2767 * I40E_GLPRT_GOTCH[H/L], so there is a small window that cause negative
2769 * same to I40E_GLV_UPTC[H/L], I40E_GLV_MPTC[H/L], I40E_GLV_BPTC[H/L].
2771 if (ns->eth.tx_bytes < pf->internal_stats.tx_bytes)
2772 ns->eth.tx_bytes = 0;
2774 ns->eth.tx_bytes -= pf->internal_stats.tx_bytes;
2776 if (ns->eth.tx_unicast < pf->internal_stats.tx_unicast)
2777 ns->eth.tx_unicast = 0;
2779 ns->eth.tx_unicast -= pf->internal_stats.tx_unicast;
2781 if (ns->eth.tx_multicast < pf->internal_stats.tx_multicast)
2782 ns->eth.tx_multicast = 0;
2784 ns->eth.tx_multicast -= pf->internal_stats.tx_multicast;
2786 if (ns->eth.tx_broadcast < pf->internal_stats.tx_broadcast)
2787 ns->eth.tx_broadcast = 0;
2789 ns->eth.tx_broadcast -= pf->internal_stats.tx_broadcast;
2791 /* GLPRT_TEPC not supported */
2793 /* additional port specific stats */
2794 i40e_stat_update_32(hw, I40E_GLPRT_TDOLD(hw->port),
2795 pf->offset_loaded, &os->tx_dropped_link_down,
2796 &ns->tx_dropped_link_down);
2797 i40e_stat_update_32(hw, I40E_GLPRT_CRCERRS(hw->port),
2798 pf->offset_loaded, &os->crc_errors,
2800 i40e_stat_update_32(hw, I40E_GLPRT_ILLERRC(hw->port),
2801 pf->offset_loaded, &os->illegal_bytes,
2802 &ns->illegal_bytes);
2803 /* GLPRT_ERRBC not supported */
2804 i40e_stat_update_32(hw, I40E_GLPRT_MLFC(hw->port),
2805 pf->offset_loaded, &os->mac_local_faults,
2806 &ns->mac_local_faults);
2807 i40e_stat_update_32(hw, I40E_GLPRT_MRFC(hw->port),
2808 pf->offset_loaded, &os->mac_remote_faults,
2809 &ns->mac_remote_faults);
2810 i40e_stat_update_32(hw, I40E_GLPRT_RLEC(hw->port),
2811 pf->offset_loaded, &os->rx_length_errors,
2812 &ns->rx_length_errors);
2813 i40e_stat_update_32(hw, I40E_GLPRT_LXONRXC(hw->port),
2814 pf->offset_loaded, &os->link_xon_rx,
2816 i40e_stat_update_32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
2817 pf->offset_loaded, &os->link_xoff_rx,
2819 for (i = 0; i < 8; i++) {
2820 i40e_stat_update_32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
2822 &os->priority_xon_rx[i],
2823 &ns->priority_xon_rx[i]);
2824 i40e_stat_update_32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
2826 &os->priority_xoff_rx[i],
2827 &ns->priority_xoff_rx[i]);
2829 i40e_stat_update_32(hw, I40E_GLPRT_LXONTXC(hw->port),
2830 pf->offset_loaded, &os->link_xon_tx,
2832 i40e_stat_update_32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
2833 pf->offset_loaded, &os->link_xoff_tx,
2835 for (i = 0; i < 8; i++) {
2836 i40e_stat_update_32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
2838 &os->priority_xon_tx[i],
2839 &ns->priority_xon_tx[i]);
2840 i40e_stat_update_32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
2842 &os->priority_xoff_tx[i],
2843 &ns->priority_xoff_tx[i]);
2844 i40e_stat_update_32(hw, I40E_GLPRT_RXON2OFFCNT(hw->port, i),
2846 &os->priority_xon_2_xoff[i],
2847 &ns->priority_xon_2_xoff[i]);
2849 i40e_stat_update_48(hw, I40E_GLPRT_PRC64H(hw->port),
2850 I40E_GLPRT_PRC64L(hw->port),
2851 pf->offset_loaded, &os->rx_size_64,
2853 i40e_stat_update_48(hw, I40E_GLPRT_PRC127H(hw->port),
2854 I40E_GLPRT_PRC127L(hw->port),
2855 pf->offset_loaded, &os->rx_size_127,
2857 i40e_stat_update_48(hw, I40E_GLPRT_PRC255H(hw->port),
2858 I40E_GLPRT_PRC255L(hw->port),
2859 pf->offset_loaded, &os->rx_size_255,
2861 i40e_stat_update_48(hw, I40E_GLPRT_PRC511H(hw->port),
2862 I40E_GLPRT_PRC511L(hw->port),
2863 pf->offset_loaded, &os->rx_size_511,
2865 i40e_stat_update_48(hw, I40E_GLPRT_PRC1023H(hw->port),
2866 I40E_GLPRT_PRC1023L(hw->port),
2867 pf->offset_loaded, &os->rx_size_1023,
2869 i40e_stat_update_48(hw, I40E_GLPRT_PRC1522H(hw->port),
2870 I40E_GLPRT_PRC1522L(hw->port),
2871 pf->offset_loaded, &os->rx_size_1522,
2873 i40e_stat_update_48(hw, I40E_GLPRT_PRC9522H(hw->port),
2874 I40E_GLPRT_PRC9522L(hw->port),
2875 pf->offset_loaded, &os->rx_size_big,
2877 i40e_stat_update_32(hw, I40E_GLPRT_RUC(hw->port),
2878 pf->offset_loaded, &os->rx_undersize,
2880 i40e_stat_update_32(hw, I40E_GLPRT_RFC(hw->port),
2881 pf->offset_loaded, &os->rx_fragments,
2883 i40e_stat_update_32(hw, I40E_GLPRT_ROC(hw->port),
2884 pf->offset_loaded, &os->rx_oversize,
2886 i40e_stat_update_32(hw, I40E_GLPRT_RJC(hw->port),
2887 pf->offset_loaded, &os->rx_jabber,
2889 i40e_stat_update_48(hw, I40E_GLPRT_PTC64H(hw->port),
2890 I40E_GLPRT_PTC64L(hw->port),
2891 pf->offset_loaded, &os->tx_size_64,
2893 i40e_stat_update_48(hw, I40E_GLPRT_PTC127H(hw->port),
2894 I40E_GLPRT_PTC127L(hw->port),
2895 pf->offset_loaded, &os->tx_size_127,
2897 i40e_stat_update_48(hw, I40E_GLPRT_PTC255H(hw->port),
2898 I40E_GLPRT_PTC255L(hw->port),
2899 pf->offset_loaded, &os->tx_size_255,
2901 i40e_stat_update_48(hw, I40E_GLPRT_PTC511H(hw->port),
2902 I40E_GLPRT_PTC511L(hw->port),
2903 pf->offset_loaded, &os->tx_size_511,
2905 i40e_stat_update_48(hw, I40E_GLPRT_PTC1023H(hw->port),
2906 I40E_GLPRT_PTC1023L(hw->port),
2907 pf->offset_loaded, &os->tx_size_1023,
2909 i40e_stat_update_48(hw, I40E_GLPRT_PTC1522H(hw->port),
2910 I40E_GLPRT_PTC1522L(hw->port),
2911 pf->offset_loaded, &os->tx_size_1522,
2913 i40e_stat_update_48(hw, I40E_GLPRT_PTC9522H(hw->port),
2914 I40E_GLPRT_PTC9522L(hw->port),
2915 pf->offset_loaded, &os->tx_size_big,
2917 i40e_stat_update_32(hw, I40E_GLQF_PCNT(pf->fdir.match_counter_index),
2919 &os->fd_sb_match, &ns->fd_sb_match);
2920 /* GLPRT_MSPDC not supported */
2921 /* GLPRT_XEC not supported */
2923 pf->offset_loaded = true;
2926 i40e_update_vsi_stats(pf->main_vsi);
2929 /* Get all statistics of a port */
2931 i40e_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
2933 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2934 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2935 struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
2938 /* call read registers - updates values, now write them to struct */
2939 i40e_read_stats_registers(pf, hw);
2941 stats->ipackets = ns->eth.rx_unicast +
2942 ns->eth.rx_multicast +
2943 ns->eth.rx_broadcast -
2944 ns->eth.rx_discards -
2945 pf->main_vsi->eth_stats.rx_discards;
2946 stats->opackets = ns->eth.tx_unicast +
2947 ns->eth.tx_multicast +
2948 ns->eth.tx_broadcast;
2949 stats->ibytes = ns->eth.rx_bytes;
2950 stats->obytes = ns->eth.tx_bytes;
2951 stats->oerrors = ns->eth.tx_errors +
2952 pf->main_vsi->eth_stats.tx_errors;
2955 stats->imissed = ns->eth.rx_discards +
2956 pf->main_vsi->eth_stats.rx_discards;
2957 stats->ierrors = ns->crc_errors +
2958 ns->rx_length_errors + ns->rx_undersize +
2959 ns->rx_oversize + ns->rx_fragments + ns->rx_jabber;
2961 PMD_DRV_LOG(DEBUG, "***************** PF stats start *******************");
2962 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", ns->eth.rx_bytes);
2963 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", ns->eth.rx_unicast);
2964 PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", ns->eth.rx_multicast);
2965 PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", ns->eth.rx_broadcast);
2966 PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", ns->eth.rx_discards);
2967 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
2968 ns->eth.rx_unknown_protocol);
2969 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", ns->eth.tx_bytes);
2970 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", ns->eth.tx_unicast);
2971 PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", ns->eth.tx_multicast);
2972 PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", ns->eth.tx_broadcast);
2973 PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", ns->eth.tx_discards);
2974 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", ns->eth.tx_errors);
2976 PMD_DRV_LOG(DEBUG, "tx_dropped_link_down: %"PRIu64"",
2977 ns->tx_dropped_link_down);
2978 PMD_DRV_LOG(DEBUG, "crc_errors: %"PRIu64"", ns->crc_errors);
2979 PMD_DRV_LOG(DEBUG, "illegal_bytes: %"PRIu64"",
2981 PMD_DRV_LOG(DEBUG, "error_bytes: %"PRIu64"", ns->error_bytes);
2982 PMD_DRV_LOG(DEBUG, "mac_local_faults: %"PRIu64"",
2983 ns->mac_local_faults);
2984 PMD_DRV_LOG(DEBUG, "mac_remote_faults: %"PRIu64"",
2985 ns->mac_remote_faults);
2986 PMD_DRV_LOG(DEBUG, "rx_length_errors: %"PRIu64"",
2987 ns->rx_length_errors);
2988 PMD_DRV_LOG(DEBUG, "link_xon_rx: %"PRIu64"", ns->link_xon_rx);
2989 PMD_DRV_LOG(DEBUG, "link_xoff_rx: %"PRIu64"", ns->link_xoff_rx);
2990 for (i = 0; i < 8; i++) {
2991 PMD_DRV_LOG(DEBUG, "priority_xon_rx[%d]: %"PRIu64"",
2992 i, ns->priority_xon_rx[i]);
2993 PMD_DRV_LOG(DEBUG, "priority_xoff_rx[%d]: %"PRIu64"",
2994 i, ns->priority_xoff_rx[i]);
2996 PMD_DRV_LOG(DEBUG, "link_xon_tx: %"PRIu64"", ns->link_xon_tx);
2997 PMD_DRV_LOG(DEBUG, "link_xoff_tx: %"PRIu64"", ns->link_xoff_tx);
2998 for (i = 0; i < 8; i++) {
2999 PMD_DRV_LOG(DEBUG, "priority_xon_tx[%d]: %"PRIu64"",
3000 i, ns->priority_xon_tx[i]);
3001 PMD_DRV_LOG(DEBUG, "priority_xoff_tx[%d]: %"PRIu64"",
3002 i, ns->priority_xoff_tx[i]);
3003 PMD_DRV_LOG(DEBUG, "priority_xon_2_xoff[%d]: %"PRIu64"",
3004 i, ns->priority_xon_2_xoff[i]);
3006 PMD_DRV_LOG(DEBUG, "rx_size_64: %"PRIu64"", ns->rx_size_64);
3007 PMD_DRV_LOG(DEBUG, "rx_size_127: %"PRIu64"", ns->rx_size_127);
3008 PMD_DRV_LOG(DEBUG, "rx_size_255: %"PRIu64"", ns->rx_size_255);
3009 PMD_DRV_LOG(DEBUG, "rx_size_511: %"PRIu64"", ns->rx_size_511);
3010 PMD_DRV_LOG(DEBUG, "rx_size_1023: %"PRIu64"", ns->rx_size_1023);
3011 PMD_DRV_LOG(DEBUG, "rx_size_1522: %"PRIu64"", ns->rx_size_1522);
3012 PMD_DRV_LOG(DEBUG, "rx_size_big: %"PRIu64"", ns->rx_size_big);
3013 PMD_DRV_LOG(DEBUG, "rx_undersize: %"PRIu64"", ns->rx_undersize);
3014 PMD_DRV_LOG(DEBUG, "rx_fragments: %"PRIu64"", ns->rx_fragments);
3015 PMD_DRV_LOG(DEBUG, "rx_oversize: %"PRIu64"", ns->rx_oversize);
3016 PMD_DRV_LOG(DEBUG, "rx_jabber: %"PRIu64"", ns->rx_jabber);
3017 PMD_DRV_LOG(DEBUG, "tx_size_64: %"PRIu64"", ns->tx_size_64);
3018 PMD_DRV_LOG(DEBUG, "tx_size_127: %"PRIu64"", ns->tx_size_127);
3019 PMD_DRV_LOG(DEBUG, "tx_size_255: %"PRIu64"", ns->tx_size_255);
3020 PMD_DRV_LOG(DEBUG, "tx_size_511: %"PRIu64"", ns->tx_size_511);
3021 PMD_DRV_LOG(DEBUG, "tx_size_1023: %"PRIu64"", ns->tx_size_1023);
3022 PMD_DRV_LOG(DEBUG, "tx_size_1522: %"PRIu64"", ns->tx_size_1522);
3023 PMD_DRV_LOG(DEBUG, "tx_size_big: %"PRIu64"", ns->tx_size_big);
3024 PMD_DRV_LOG(DEBUG, "mac_short_packet_dropped: %"PRIu64"",
3025 ns->mac_short_packet_dropped);
3026 PMD_DRV_LOG(DEBUG, "checksum_error: %"PRIu64"",
3027 ns->checksum_error);
3028 PMD_DRV_LOG(DEBUG, "fdir_match: %"PRIu64"", ns->fd_sb_match);
3029 PMD_DRV_LOG(DEBUG, "***************** PF stats end ********************");
3033 /* Reset the statistics */
3035 i40e_dev_stats_reset(struct rte_eth_dev *dev)
3037 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3038 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3040 /* Mark PF and VSI stats to update the offset, aka "reset" */
3041 pf->offset_loaded = false;
3043 pf->main_vsi->offset_loaded = false;
3045 /* read the stats, reading current register values into offset */
3046 i40e_read_stats_registers(pf, hw);
3050 i40e_xstats_calc_num(void)
3052 return I40E_NB_ETH_XSTATS + I40E_NB_HW_PORT_XSTATS +
3053 (I40E_NB_RXQ_PRIO_XSTATS * 8) +
3054 (I40E_NB_TXQ_PRIO_XSTATS * 8);
3057 static int i40e_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
3058 struct rte_eth_xstat_name *xstats_names,
3059 __rte_unused unsigned limit)
3064 if (xstats_names == NULL)
3065 return i40e_xstats_calc_num();
3067 /* Note: limit checked in rte_eth_xstats_names() */
3069 /* Get stats from i40e_eth_stats struct */
3070 for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
3071 snprintf(xstats_names[count].name,
3072 sizeof(xstats_names[count].name),
3073 "%s", rte_i40e_stats_strings[i].name);
3077 /* Get individiual stats from i40e_hw_port struct */
3078 for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
3079 snprintf(xstats_names[count].name,
3080 sizeof(xstats_names[count].name),
3081 "%s", rte_i40e_hw_port_strings[i].name);
3085 for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
3086 for (prio = 0; prio < 8; prio++) {
3087 snprintf(xstats_names[count].name,
3088 sizeof(xstats_names[count].name),
3089 "rx_priority%u_%s", prio,
3090 rte_i40e_rxq_prio_strings[i].name);
3095 for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
3096 for (prio = 0; prio < 8; prio++) {
3097 snprintf(xstats_names[count].name,
3098 sizeof(xstats_names[count].name),
3099 "tx_priority%u_%s", prio,
3100 rte_i40e_txq_prio_strings[i].name);
3108 i40e_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
3111 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3112 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3113 unsigned i, count, prio;
3114 struct i40e_hw_port_stats *hw_stats = &pf->stats;
3116 count = i40e_xstats_calc_num();
3120 i40e_read_stats_registers(pf, hw);
3127 /* Get stats from i40e_eth_stats struct */
3128 for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
3129 xstats[count].value = *(uint64_t *)(((char *)&hw_stats->eth) +
3130 rte_i40e_stats_strings[i].offset);
3131 xstats[count].id = count;
3135 /* Get individiual stats from i40e_hw_port struct */
3136 for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
3137 xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
3138 rte_i40e_hw_port_strings[i].offset);
3139 xstats[count].id = count;
3143 for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
3144 for (prio = 0; prio < 8; prio++) {
3145 xstats[count].value =
3146 *(uint64_t *)(((char *)hw_stats) +
3147 rte_i40e_rxq_prio_strings[i].offset +
3148 (sizeof(uint64_t) * prio));
3149 xstats[count].id = count;
3154 for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
3155 for (prio = 0; prio < 8; prio++) {
3156 xstats[count].value =
3157 *(uint64_t *)(((char *)hw_stats) +
3158 rte_i40e_txq_prio_strings[i].offset +
3159 (sizeof(uint64_t) * prio));
3160 xstats[count].id = count;
3169 i40e_dev_queue_stats_mapping_set(__rte_unused struct rte_eth_dev *dev,
3170 __rte_unused uint16_t queue_id,
3171 __rte_unused uint8_t stat_idx,
3172 __rte_unused uint8_t is_rx)
3174 PMD_INIT_FUNC_TRACE();
3180 i40e_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
3182 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3188 full_ver = hw->nvm.oem_ver;
3189 ver = (u8)(full_ver >> 24);
3190 build = (u16)((full_ver >> 8) & 0xffff);
3191 patch = (u8)(full_ver & 0xff);
3193 ret = snprintf(fw_version, fw_size,
3194 "%d.%d%d 0x%08x %d.%d.%d",
3195 ((hw->nvm.version >> 12) & 0xf),
3196 ((hw->nvm.version >> 4) & 0xff),
3197 (hw->nvm.version & 0xf), hw->nvm.eetrack,
3200 ret += 1; /* add the size of '\0' */
3201 if (fw_size < (u32)ret)
3208 i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
3210 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3211 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3212 struct i40e_vsi *vsi = pf->main_vsi;
3213 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3215 dev_info->max_rx_queues = vsi->nb_qps;
3216 dev_info->max_tx_queues = vsi->nb_qps;
3217 dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
3218 dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
3219 dev_info->max_mac_addrs = vsi->max_macaddrs;
3220 dev_info->max_vfs = pci_dev->max_vfs;
3221 dev_info->rx_queue_offload_capa = 0;
3222 dev_info->rx_offload_capa =
3223 DEV_RX_OFFLOAD_VLAN_STRIP |
3224 DEV_RX_OFFLOAD_QINQ_STRIP |
3225 DEV_RX_OFFLOAD_IPV4_CKSUM |
3226 DEV_RX_OFFLOAD_UDP_CKSUM |
3227 DEV_RX_OFFLOAD_TCP_CKSUM |
3228 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
3229 DEV_RX_OFFLOAD_CRC_STRIP |
3230 DEV_RX_OFFLOAD_VLAN_EXTEND |
3231 DEV_RX_OFFLOAD_VLAN_FILTER;
3233 dev_info->tx_queue_offload_capa = 0;
3234 dev_info->tx_offload_capa =
3235 DEV_TX_OFFLOAD_VLAN_INSERT |
3236 DEV_TX_OFFLOAD_QINQ_INSERT |
3237 DEV_TX_OFFLOAD_IPV4_CKSUM |
3238 DEV_TX_OFFLOAD_UDP_CKSUM |
3239 DEV_TX_OFFLOAD_TCP_CKSUM |
3240 DEV_TX_OFFLOAD_SCTP_CKSUM |
3241 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
3242 DEV_TX_OFFLOAD_TCP_TSO |
3243 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
3244 DEV_TX_OFFLOAD_GRE_TNL_TSO |
3245 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
3246 DEV_TX_OFFLOAD_GENEVE_TNL_TSO;
3247 dev_info->dev_capa =
3248 RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
3249 RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
3251 dev_info->hash_key_size = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
3253 dev_info->reta_size = pf->hash_lut_size;
3254 dev_info->flow_type_rss_offloads = pf->adapter->flow_types_mask;
3256 dev_info->default_rxconf = (struct rte_eth_rxconf) {
3258 .pthresh = I40E_DEFAULT_RX_PTHRESH,
3259 .hthresh = I40E_DEFAULT_RX_HTHRESH,
3260 .wthresh = I40E_DEFAULT_RX_WTHRESH,
3262 .rx_free_thresh = I40E_DEFAULT_RX_FREE_THRESH,
3267 dev_info->default_txconf = (struct rte_eth_txconf) {
3269 .pthresh = I40E_DEFAULT_TX_PTHRESH,
3270 .hthresh = I40E_DEFAULT_TX_HTHRESH,
3271 .wthresh = I40E_DEFAULT_TX_WTHRESH,
3273 .tx_free_thresh = I40E_DEFAULT_TX_FREE_THRESH,
3274 .tx_rs_thresh = I40E_DEFAULT_TX_RSBIT_THRESH,
3275 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
3276 ETH_TXQ_FLAGS_NOOFFLOADS,
3279 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
3280 .nb_max = I40E_MAX_RING_DESC,
3281 .nb_min = I40E_MIN_RING_DESC,
3282 .nb_align = I40E_ALIGN_RING_DESC,
3285 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
3286 .nb_max = I40E_MAX_RING_DESC,
3287 .nb_min = I40E_MIN_RING_DESC,
3288 .nb_align = I40E_ALIGN_RING_DESC,
3289 .nb_seg_max = I40E_TX_MAX_SEG,
3290 .nb_mtu_seg_max = I40E_TX_MAX_MTU_SEG,
3293 if (pf->flags & I40E_FLAG_VMDQ) {
3294 dev_info->max_vmdq_pools = pf->max_nb_vmdq_vsi;
3295 dev_info->vmdq_queue_base = dev_info->max_rx_queues;
3296 dev_info->vmdq_queue_num = pf->vmdq_nb_qps *
3297 pf->max_nb_vmdq_vsi;
3298 dev_info->vmdq_pool_base = I40E_VMDQ_POOL_BASE;
3299 dev_info->max_rx_queues += dev_info->vmdq_queue_num;
3300 dev_info->max_tx_queues += dev_info->vmdq_queue_num;
3303 if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
3305 dev_info->speed_capa = ETH_LINK_SPEED_40G;
3306 dev_info->default_rxportconf.nb_queues = 2;
3307 dev_info->default_txportconf.nb_queues = 2;
3308 if (dev->data->nb_rx_queues == 1)
3309 dev_info->default_rxportconf.ring_size = 2048;
3311 dev_info->default_rxportconf.ring_size = 1024;
3312 if (dev->data->nb_tx_queues == 1)
3313 dev_info->default_txportconf.ring_size = 1024;
3315 dev_info->default_txportconf.ring_size = 512;
3317 } else if (I40E_PHY_TYPE_SUPPORT_25G(hw->phy.phy_types)) {
3319 dev_info->speed_capa = ETH_LINK_SPEED_25G;
3320 dev_info->default_rxportconf.nb_queues = 1;
3321 dev_info->default_txportconf.nb_queues = 1;
3322 dev_info->default_rxportconf.ring_size = 256;
3323 dev_info->default_txportconf.ring_size = 256;
3326 dev_info->speed_capa = ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G;
3327 dev_info->default_rxportconf.nb_queues = 1;
3328 dev_info->default_txportconf.nb_queues = 1;
3329 if (dev->data->dev_conf.link_speeds & ETH_LINK_SPEED_10G) {
3330 dev_info->default_rxportconf.ring_size = 512;
3331 dev_info->default_txportconf.ring_size = 256;
3333 dev_info->default_rxportconf.ring_size = 256;
3334 dev_info->default_txportconf.ring_size = 256;
3337 dev_info->default_rxportconf.burst_size = 32;
3338 dev_info->default_txportconf.burst_size = 32;
3342 i40e_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
3344 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3345 struct i40e_vsi *vsi = pf->main_vsi;
3346 PMD_INIT_FUNC_TRACE();
3349 return i40e_vsi_add_vlan(vsi, vlan_id);
3351 return i40e_vsi_delete_vlan(vsi, vlan_id);
3355 i40e_vlan_tpid_set_by_registers(struct rte_eth_dev *dev,
3356 enum rte_vlan_type vlan_type,
3357 uint16_t tpid, int qinq)
3359 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3362 uint16_t reg_id = 3;
3366 if (vlan_type == ETH_VLAN_TYPE_OUTER)
3370 ret = i40e_aq_debug_read_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
3372 if (ret != I40E_SUCCESS) {
3374 "Fail to debug read from I40E_GL_SWT_L2TAGCTRL[%d]",
3379 "Debug read from I40E_GL_SWT_L2TAGCTRL[%d]: 0x%08"PRIx64,
3382 reg_w = reg_r & (~(I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_MASK));
3383 reg_w |= ((uint64_t)tpid << I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT);
3384 if (reg_r == reg_w) {
3385 PMD_DRV_LOG(DEBUG, "No need to write");
3389 ret = i40e_aq_debug_write_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
3391 if (ret != I40E_SUCCESS) {
3393 "Fail to debug write to I40E_GL_SWT_L2TAGCTRL[%d]",
3398 "Global register 0x%08x is changed with value 0x%08x",
3399 I40E_GL_SWT_L2TAGCTRL(reg_id), (uint32_t)reg_w);
3405 i40e_vlan_tpid_set(struct rte_eth_dev *dev,
3406 enum rte_vlan_type vlan_type,
3409 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3410 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3411 int qinq = dev->data->dev_conf.rxmode.offloads &
3412 DEV_RX_OFFLOAD_VLAN_EXTEND;
3415 if ((vlan_type != ETH_VLAN_TYPE_INNER &&
3416 vlan_type != ETH_VLAN_TYPE_OUTER) ||
3417 (!qinq && vlan_type == ETH_VLAN_TYPE_INNER)) {
3419 "Unsupported vlan type.");
3423 if (pf->support_multi_driver) {
3424 PMD_DRV_LOG(ERR, "Setting TPID is not supported.");
3428 /* 802.1ad frames ability is added in NVM API 1.7*/
3429 if (hw->flags & I40E_HW_FLAG_802_1AD_CAPABLE) {
3431 if (vlan_type == ETH_VLAN_TYPE_OUTER)
3432 hw->first_tag = rte_cpu_to_le_16(tpid);
3433 else if (vlan_type == ETH_VLAN_TYPE_INNER)
3434 hw->second_tag = rte_cpu_to_le_16(tpid);
3436 if (vlan_type == ETH_VLAN_TYPE_OUTER)
3437 hw->second_tag = rte_cpu_to_le_16(tpid);
3439 ret = i40e_aq_set_switch_config(hw, 0, 0, NULL);
3440 if (ret != I40E_SUCCESS) {
3442 "Set switch config failed aq_err: %d",
3443 hw->aq.asq_last_status);
3447 /* If NVM API < 1.7, keep the register setting */
3448 ret = i40e_vlan_tpid_set_by_registers(dev, vlan_type,
3450 i40e_global_cfg_warning(I40E_WARNING_TPID);
3456 i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask)
3458 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3459 struct i40e_vsi *vsi = pf->main_vsi;
3460 struct rte_eth_rxmode *rxmode;
3462 rxmode = &dev->data->dev_conf.rxmode;
3463 if (mask & ETH_VLAN_FILTER_MASK) {
3464 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
3465 i40e_vsi_config_vlan_filter(vsi, TRUE);
3467 i40e_vsi_config_vlan_filter(vsi, FALSE);
3470 if (mask & ETH_VLAN_STRIP_MASK) {
3471 /* Enable or disable VLAN stripping */
3472 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
3473 i40e_vsi_config_vlan_stripping(vsi, TRUE);
3475 i40e_vsi_config_vlan_stripping(vsi, FALSE);
3478 if (mask & ETH_VLAN_EXTEND_MASK) {
3479 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_EXTEND) {
3480 i40e_vsi_config_double_vlan(vsi, TRUE);
3481 /* Set global registers with default ethertype. */
3482 i40e_vlan_tpid_set(dev, ETH_VLAN_TYPE_OUTER,
3484 i40e_vlan_tpid_set(dev, ETH_VLAN_TYPE_INNER,
3488 i40e_vsi_config_double_vlan(vsi, FALSE);
3495 i40e_vlan_strip_queue_set(__rte_unused struct rte_eth_dev *dev,
3496 __rte_unused uint16_t queue,
3497 __rte_unused int on)
3499 PMD_INIT_FUNC_TRACE();
3503 i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
3505 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3506 struct i40e_vsi *vsi = pf->main_vsi;
3507 struct rte_eth_dev_data *data = I40E_VSI_TO_DEV_DATA(vsi);
3508 struct i40e_vsi_vlan_pvid_info info;
3510 memset(&info, 0, sizeof(info));
3513 info.config.pvid = pvid;
3515 info.config.reject.tagged =
3516 data->dev_conf.txmode.hw_vlan_reject_tagged;
3517 info.config.reject.untagged =
3518 data->dev_conf.txmode.hw_vlan_reject_untagged;
3521 return i40e_vsi_vlan_pvid_set(vsi, &info);
3525 i40e_dev_led_on(struct rte_eth_dev *dev)
3527 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3528 uint32_t mode = i40e_led_get(hw);
3531 i40e_led_set(hw, 0xf, true); /* 0xf means led always true */
3537 i40e_dev_led_off(struct rte_eth_dev *dev)
3539 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3540 uint32_t mode = i40e_led_get(hw);
3543 i40e_led_set(hw, 0, false);
3549 i40e_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
3551 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3552 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3554 fc_conf->pause_time = pf->fc_conf.pause_time;
3556 /* read out from register, in case they are modified by other port */
3557 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] =
3558 I40E_READ_REG(hw, I40E_GLRPB_GHW) >> I40E_KILOSHIFT;
3559 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] =
3560 I40E_READ_REG(hw, I40E_GLRPB_GLW) >> I40E_KILOSHIFT;
3562 fc_conf->high_water = pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS];
3563 fc_conf->low_water = pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS];
3565 /* Return current mode according to actual setting*/
3566 switch (hw->fc.current_mode) {
3568 fc_conf->mode = RTE_FC_FULL;
3570 case I40E_FC_TX_PAUSE:
3571 fc_conf->mode = RTE_FC_TX_PAUSE;
3573 case I40E_FC_RX_PAUSE:
3574 fc_conf->mode = RTE_FC_RX_PAUSE;
3578 fc_conf->mode = RTE_FC_NONE;
3585 i40e_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
3587 uint32_t mflcn_reg, fctrl_reg, reg;
3588 uint32_t max_high_water;
3589 uint8_t i, aq_failure;
3593 enum i40e_fc_mode rte_fcmode_2_i40e_fcmode[] = {
3594 [RTE_FC_NONE] = I40E_FC_NONE,
3595 [RTE_FC_RX_PAUSE] = I40E_FC_RX_PAUSE,
3596 [RTE_FC_TX_PAUSE] = I40E_FC_TX_PAUSE,
3597 [RTE_FC_FULL] = I40E_FC_FULL
3600 /* high_water field in the rte_eth_fc_conf using the kilobytes unit */
3602 max_high_water = I40E_RXPBSIZE >> I40E_KILOSHIFT;
3603 if ((fc_conf->high_water > max_high_water) ||
3604 (fc_conf->high_water < fc_conf->low_water)) {
3606 "Invalid high/low water setup value in KB, High_water must be <= %d.",
3611 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3612 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3613 hw->fc.requested_mode = rte_fcmode_2_i40e_fcmode[fc_conf->mode];
3615 pf->fc_conf.pause_time = fc_conf->pause_time;
3616 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->high_water;
3617 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->low_water;
3619 PMD_INIT_FUNC_TRACE();
3621 /* All the link flow control related enable/disable register
3622 * configuration is handle by the F/W
3624 err = i40e_set_fc(hw, &aq_failure, true);
3628 if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
3629 /* Configure flow control refresh threshold,
3630 * the value for stat_tx_pause_refresh_timer[8]
3631 * is used for global pause operation.
3635 I40E_PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER(8),
3636 pf->fc_conf.pause_time);
3638 /* configure the timer value included in transmitted pause
3640 * the value for stat_tx_pause_quanta[8] is used for global
3643 I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA(8),
3644 pf->fc_conf.pause_time);
3646 fctrl_reg = I40E_READ_REG(hw,
3647 I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL);
3649 if (fc_conf->mac_ctrl_frame_fwd != 0)
3650 fctrl_reg |= I40E_PRTMAC_FWD_CTRL;
3652 fctrl_reg &= ~I40E_PRTMAC_FWD_CTRL;
3654 I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL,
3657 /* Configure pause time (2 TCs per register) */
3658 reg = (uint32_t)pf->fc_conf.pause_time * (uint32_t)0x00010001;
3659 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS / 2; i++)
3660 I40E_WRITE_REG(hw, I40E_PRTDCB_FCTTVN(i), reg);
3662 /* Configure flow control refresh threshold value */
3663 I40E_WRITE_REG(hw, I40E_PRTDCB_FCRTV,
3664 pf->fc_conf.pause_time / 2);
3666 mflcn_reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
3668 /* set or clear MFLCN.PMCF & MFLCN.DPF bits
3669 *depending on configuration
3671 if (fc_conf->mac_ctrl_frame_fwd != 0) {
3672 mflcn_reg |= I40E_PRTDCB_MFLCN_PMCF_MASK;
3673 mflcn_reg &= ~I40E_PRTDCB_MFLCN_DPF_MASK;
3675 mflcn_reg &= ~I40E_PRTDCB_MFLCN_PMCF_MASK;
3676 mflcn_reg |= I40E_PRTDCB_MFLCN_DPF_MASK;
3679 I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, mflcn_reg);
3682 if (!pf->support_multi_driver) {
3683 /* config water marker both based on the packets and bytes */
3684 I40E_WRITE_GLB_REG(hw, I40E_GLRPB_PHW,
3685 (pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
3686 << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
3687 I40E_WRITE_GLB_REG(hw, I40E_GLRPB_PLW,
3688 (pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
3689 << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
3690 I40E_WRITE_GLB_REG(hw, I40E_GLRPB_GHW,
3691 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
3693 I40E_WRITE_GLB_REG(hw, I40E_GLRPB_GLW,
3694 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
3696 i40e_global_cfg_warning(I40E_WARNING_FLOW_CTL);
3699 "Water marker configuration is not supported.");
3702 I40E_WRITE_FLUSH(hw);
3708 i40e_priority_flow_ctrl_set(__rte_unused struct rte_eth_dev *dev,
3709 __rte_unused struct rte_eth_pfc_conf *pfc_conf)
3711 PMD_INIT_FUNC_TRACE();
3716 /* Add a MAC address, and update filters */
3718 i40e_macaddr_add(struct rte_eth_dev *dev,
3719 struct ether_addr *mac_addr,
3720 __rte_unused uint32_t index,
3723 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3724 struct i40e_mac_filter_info mac_filter;
3725 struct i40e_vsi *vsi;
3726 struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
3729 /* If VMDQ not enabled or configured, return */
3730 if (pool != 0 && (!(pf->flags & I40E_FLAG_VMDQ) ||
3731 !pf->nb_cfg_vmdq_vsi)) {
3732 PMD_DRV_LOG(ERR, "VMDQ not %s, can't set mac to pool %u",
3733 pf->flags & I40E_FLAG_VMDQ ? "configured" : "enabled",
3738 if (pool > pf->nb_cfg_vmdq_vsi) {
3739 PMD_DRV_LOG(ERR, "Pool number %u invalid. Max pool is %u",
3740 pool, pf->nb_cfg_vmdq_vsi);
3744 rte_memcpy(&mac_filter.mac_addr, mac_addr, ETHER_ADDR_LEN);
3745 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
3746 mac_filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
3748 mac_filter.filter_type = RTE_MAC_PERFECT_MATCH;
3753 vsi = pf->vmdq[pool - 1].vsi;
3755 ret = i40e_vsi_add_mac(vsi, &mac_filter);
3756 if (ret != I40E_SUCCESS) {
3757 PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
3763 /* Remove a MAC address, and update filters */
3765 i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
3767 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3768 struct i40e_vsi *vsi;
3769 struct rte_eth_dev_data *data = dev->data;
3770 struct ether_addr *macaddr;
3775 macaddr = &(data->mac_addrs[index]);
3777 pool_sel = dev->data->mac_pool_sel[index];
3779 for (i = 0; i < sizeof(pool_sel) * CHAR_BIT; i++) {
3780 if (pool_sel & (1ULL << i)) {
3784 /* No VMDQ pool enabled or configured */
3785 if (!(pf->flags & I40E_FLAG_VMDQ) ||
3786 (i > pf->nb_cfg_vmdq_vsi)) {
3788 "No VMDQ pool enabled/configured");
3791 vsi = pf->vmdq[i - 1].vsi;
3793 ret = i40e_vsi_delete_mac(vsi, macaddr);
3796 PMD_DRV_LOG(ERR, "Failed to remove MACVLAN filter");
3803 /* Set perfect match or hash match of MAC and VLAN for a VF */
3805 i40e_vf_mac_filter_set(struct i40e_pf *pf,
3806 struct rte_eth_mac_filter *filter,
3810 struct i40e_mac_filter_info mac_filter;
3811 struct ether_addr old_mac;
3812 struct ether_addr *new_mac;
3813 struct i40e_pf_vf *vf = NULL;
3818 PMD_DRV_LOG(ERR, "Invalid PF argument.");
3821 hw = I40E_PF_TO_HW(pf);
3823 if (filter == NULL) {
3824 PMD_DRV_LOG(ERR, "Invalid mac filter argument.");
3828 new_mac = &filter->mac_addr;
3830 if (is_zero_ether_addr(new_mac)) {
3831 PMD_DRV_LOG(ERR, "Invalid ethernet address.");
3835 vf_id = filter->dst_id;
3837 if (vf_id > pf->vf_num - 1 || !pf->vfs) {
3838 PMD_DRV_LOG(ERR, "Invalid argument.");
3841 vf = &pf->vfs[vf_id];
3843 if (add && is_same_ether_addr(new_mac, &(pf->dev_addr))) {
3844 PMD_DRV_LOG(INFO, "Ignore adding permanent MAC address.");
3849 rte_memcpy(&old_mac, hw->mac.addr, ETHER_ADDR_LEN);
3850 rte_memcpy(hw->mac.addr, new_mac->addr_bytes,
3852 rte_memcpy(&mac_filter.mac_addr, &filter->mac_addr,
3855 mac_filter.filter_type = filter->filter_type;
3856 ret = i40e_vsi_add_mac(vf->vsi, &mac_filter);
3857 if (ret != I40E_SUCCESS) {
3858 PMD_DRV_LOG(ERR, "Failed to add MAC filter.");
3861 ether_addr_copy(new_mac, &pf->dev_addr);
3863 rte_memcpy(hw->mac.addr, hw->mac.perm_addr,
3865 ret = i40e_vsi_delete_mac(vf->vsi, &filter->mac_addr);
3866 if (ret != I40E_SUCCESS) {
3867 PMD_DRV_LOG(ERR, "Failed to delete MAC filter.");
3871 /* Clear device address as it has been removed */
3872 if (is_same_ether_addr(&(pf->dev_addr), new_mac))
3873 memset(&pf->dev_addr, 0, sizeof(struct ether_addr));
3879 /* MAC filter handle */
3881 i40e_mac_filter_handle(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
3884 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3885 struct rte_eth_mac_filter *filter;
3886 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
3887 int ret = I40E_NOT_SUPPORTED;
3889 filter = (struct rte_eth_mac_filter *)(arg);
3891 switch (filter_op) {
3892 case RTE_ETH_FILTER_NOP:
3895 case RTE_ETH_FILTER_ADD:
3896 i40e_pf_disable_irq0(hw);
3898 ret = i40e_vf_mac_filter_set(pf, filter, 1);
3899 i40e_pf_enable_irq0(hw);
3901 case RTE_ETH_FILTER_DELETE:
3902 i40e_pf_disable_irq0(hw);
3904 ret = i40e_vf_mac_filter_set(pf, filter, 0);
3905 i40e_pf_enable_irq0(hw);
3908 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
3909 ret = I40E_ERR_PARAM;
3917 i40e_get_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
3919 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
3920 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3927 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
3928 ret = i40e_aq_get_rss_lut(hw, vsi->vsi_id, TRUE,
3931 PMD_DRV_LOG(ERR, "Failed to get RSS lookup table");
3935 uint32_t *lut_dw = (uint32_t *)lut;
3936 uint16_t i, lut_size_dw = lut_size / 4;
3938 if (vsi->type == I40E_VSI_SRIOV) {
3939 for (i = 0; i <= lut_size_dw; i++) {
3940 reg = I40E_VFQF_HLUT1(i, vsi->user_param);
3941 lut_dw[i] = i40e_read_rx_ctl(hw, reg);
3944 for (i = 0; i < lut_size_dw; i++)
3945 lut_dw[i] = I40E_READ_REG(hw,
3954 i40e_set_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
3963 pf = I40E_VSI_TO_PF(vsi);
3964 hw = I40E_VSI_TO_HW(vsi);
3966 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
3967 ret = i40e_aq_set_rss_lut(hw, vsi->vsi_id, TRUE,
3970 PMD_DRV_LOG(ERR, "Failed to set RSS lookup table");
3974 uint32_t *lut_dw = (uint32_t *)lut;
3975 uint16_t i, lut_size_dw = lut_size / 4;
3977 if (vsi->type == I40E_VSI_SRIOV) {
3978 for (i = 0; i < lut_size_dw; i++)
3981 I40E_VFQF_HLUT1(i, vsi->user_param),
3984 for (i = 0; i < lut_size_dw; i++)
3985 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i),
3988 I40E_WRITE_FLUSH(hw);
3995 i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
3996 struct rte_eth_rss_reta_entry64 *reta_conf,
3999 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4000 uint16_t i, lut_size = pf->hash_lut_size;
4001 uint16_t idx, shift;
4005 if (reta_size != lut_size ||
4006 reta_size > ETH_RSS_RETA_SIZE_512) {
4008 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)",
4009 reta_size, lut_size);
4013 lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
4015 PMD_DRV_LOG(ERR, "No memory can be allocated");
4018 ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
4021 for (i = 0; i < reta_size; i++) {
4022 idx = i / RTE_RETA_GROUP_SIZE;
4023 shift = i % RTE_RETA_GROUP_SIZE;
4024 if (reta_conf[idx].mask & (1ULL << shift))
4025 lut[i] = reta_conf[idx].reta[shift];
4027 ret = i40e_set_rss_lut(pf->main_vsi, lut, reta_size);
4036 i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
4037 struct rte_eth_rss_reta_entry64 *reta_conf,
4040 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4041 uint16_t i, lut_size = pf->hash_lut_size;
4042 uint16_t idx, shift;
4046 if (reta_size != lut_size ||
4047 reta_size > ETH_RSS_RETA_SIZE_512) {
4049 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)",
4050 reta_size, lut_size);
4054 lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
4056 PMD_DRV_LOG(ERR, "No memory can be allocated");
4060 ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
4063 for (i = 0; i < reta_size; i++) {
4064 idx = i / RTE_RETA_GROUP_SIZE;
4065 shift = i % RTE_RETA_GROUP_SIZE;
4066 if (reta_conf[idx].mask & (1ULL << shift))
4067 reta_conf[idx].reta[shift] = lut[i];
4077 * i40e_allocate_dma_mem_d - specific memory alloc for shared code (base driver)
4078 * @hw: pointer to the HW structure
4079 * @mem: pointer to mem struct to fill out
4080 * @size: size of memory requested
4081 * @alignment: what to align the allocation to
4083 enum i40e_status_code
4084 i40e_allocate_dma_mem_d(__attribute__((unused)) struct i40e_hw *hw,
4085 struct i40e_dma_mem *mem,
4089 const struct rte_memzone *mz = NULL;
4090 char z_name[RTE_MEMZONE_NAMESIZE];
4093 return I40E_ERR_PARAM;
4095 snprintf(z_name, sizeof(z_name), "i40e_dma_%"PRIu64, rte_rand());
4096 mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY,
4097 RTE_MEMZONE_IOVA_CONTIG, alignment, RTE_PGSIZE_2M);
4099 return I40E_ERR_NO_MEMORY;
4104 mem->zone = (const void *)mz;
4106 "memzone %s allocated with physical address: %"PRIu64,
4109 return I40E_SUCCESS;
4113 * i40e_free_dma_mem_d - specific memory free for shared code (base driver)
4114 * @hw: pointer to the HW structure
4115 * @mem: ptr to mem struct to free
4117 enum i40e_status_code
4118 i40e_free_dma_mem_d(__attribute__((unused)) struct i40e_hw *hw,
4119 struct i40e_dma_mem *mem)
4122 return I40E_ERR_PARAM;
4125 "memzone %s to be freed with physical address: %"PRIu64,
4126 ((const struct rte_memzone *)mem->zone)->name, mem->pa);
4127 rte_memzone_free((const struct rte_memzone *)mem->zone);
4132 return I40E_SUCCESS;
4136 * i40e_allocate_virt_mem_d - specific memory alloc for shared code (base driver)
4137 * @hw: pointer to the HW structure
4138 * @mem: pointer to mem struct to fill out
4139 * @size: size of memory requested
4141 enum i40e_status_code
4142 i40e_allocate_virt_mem_d(__attribute__((unused)) struct i40e_hw *hw,
4143 struct i40e_virt_mem *mem,
4147 return I40E_ERR_PARAM;
4150 mem->va = rte_zmalloc("i40e", size, 0);
4153 return I40E_SUCCESS;
4155 return I40E_ERR_NO_MEMORY;
4159 * i40e_free_virt_mem_d - specific memory free for shared code (base driver)
4160 * @hw: pointer to the HW structure
4161 * @mem: pointer to mem struct to free
4163 enum i40e_status_code
4164 i40e_free_virt_mem_d(__attribute__((unused)) struct i40e_hw *hw,
4165 struct i40e_virt_mem *mem)
4168 return I40E_ERR_PARAM;
4173 return I40E_SUCCESS;
4177 i40e_init_spinlock_d(struct i40e_spinlock *sp)
4179 rte_spinlock_init(&sp->spinlock);
4183 i40e_acquire_spinlock_d(struct i40e_spinlock *sp)
4185 rte_spinlock_lock(&sp->spinlock);
4189 i40e_release_spinlock_d(struct i40e_spinlock *sp)
4191 rte_spinlock_unlock(&sp->spinlock);
4195 i40e_destroy_spinlock_d(__attribute__((unused)) struct i40e_spinlock *sp)
4201 * Get the hardware capabilities, which will be parsed
4202 * and saved into struct i40e_hw.
4205 i40e_get_cap(struct i40e_hw *hw)
4207 struct i40e_aqc_list_capabilities_element_resp *buf;
4208 uint16_t len, size = 0;
4211 /* Calculate a huge enough buff for saving response data temporarily */
4212 len = sizeof(struct i40e_aqc_list_capabilities_element_resp) *
4213 I40E_MAX_CAP_ELE_NUM;
4214 buf = rte_zmalloc("i40e", len, 0);
4216 PMD_DRV_LOG(ERR, "Failed to allocate memory");
4217 return I40E_ERR_NO_MEMORY;
4220 /* Get, parse the capabilities and save it to hw */
4221 ret = i40e_aq_discover_capabilities(hw, buf, len, &size,
4222 i40e_aqc_opc_list_func_capabilities, NULL);
4223 if (ret != I40E_SUCCESS)
4224 PMD_DRV_LOG(ERR, "Failed to discover capabilities");
4226 /* Free the temporary buffer after being used */
4232 #define RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF 4
4233 #define QUEUE_NUM_PER_VF_ARG "queue-num-per-vf"
4235 static int i40e_pf_parse_vf_queue_number_handler(const char *key,
4243 pf = (struct i40e_pf *)opaque;
4247 num = strtoul(value, &end, 0);
4248 if (errno != 0 || end == value || *end != 0) {
4249 PMD_DRV_LOG(WARNING, "Wrong VF queue number = %s, Now it is "
4250 "kept the value = %hu", value, pf->vf_nb_qp_max);
4254 if (num <= I40E_MAX_QP_NUM_PER_VF && rte_is_power_of_2(num))
4255 pf->vf_nb_qp_max = (uint16_t)num;
4257 /* here return 0 to make next valid same argument work */
4258 PMD_DRV_LOG(WARNING, "Wrong VF queue number = %lu, it must be "
4259 "power of 2 and equal or less than 16 !, Now it is "
4260 "kept the value = %hu", num, pf->vf_nb_qp_max);
4265 static int i40e_pf_config_vf_rxq_number(struct rte_eth_dev *dev)
4267 static const char * const valid_keys[] = {QUEUE_NUM_PER_VF_ARG, NULL};
4268 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4269 struct rte_kvargs *kvlist;
4271 /* set default queue number per VF as 4 */
4272 pf->vf_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF;
4274 if (dev->device->devargs == NULL)
4277 kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
4281 if (rte_kvargs_count(kvlist, QUEUE_NUM_PER_VF_ARG) > 1)
4282 PMD_DRV_LOG(WARNING, "More than one argument \"%s\" and only "
4283 "the first invalid or last valid one is used !",
4284 QUEUE_NUM_PER_VF_ARG);
4286 rte_kvargs_process(kvlist, QUEUE_NUM_PER_VF_ARG,
4287 i40e_pf_parse_vf_queue_number_handler, pf);
4289 rte_kvargs_free(kvlist);
4295 i40e_pf_parameter_init(struct rte_eth_dev *dev)
4297 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4298 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4299 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
4300 uint16_t qp_count = 0, vsi_count = 0;
4302 if (pci_dev->max_vfs && !hw->func_caps.sr_iov_1_1) {
4303 PMD_INIT_LOG(ERR, "HW configuration doesn't support SRIOV");
4307 i40e_pf_config_vf_rxq_number(dev);
4309 /* Add the parameter init for LFC */
4310 pf->fc_conf.pause_time = I40E_DEFAULT_PAUSE_TIME;
4311 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_HIGH_WATER;
4312 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_LOW_WATER;
4314 pf->flags = I40E_FLAG_HEADER_SPLIT_DISABLED;
4315 pf->max_num_vsi = hw->func_caps.num_vsis;
4316 pf->lan_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_PF;
4317 pf->vmdq_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
4319 /* FDir queue/VSI allocation */
4320 pf->fdir_qp_offset = 0;
4321 if (hw->func_caps.fd) {
4322 pf->flags |= I40E_FLAG_FDIR;
4323 pf->fdir_nb_qps = I40E_DEFAULT_QP_NUM_FDIR;
4325 pf->fdir_nb_qps = 0;
4327 qp_count += pf->fdir_nb_qps;
4330 /* LAN queue/VSI allocation */
4331 pf->lan_qp_offset = pf->fdir_qp_offset + pf->fdir_nb_qps;
4332 if (!hw->func_caps.rss) {
4335 pf->flags |= I40E_FLAG_RSS;
4336 if (hw->mac.type == I40E_MAC_X722)
4337 pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE;
4338 pf->lan_nb_qps = pf->lan_nb_qp_max;
4340 qp_count += pf->lan_nb_qps;
4343 /* VF queue/VSI allocation */
4344 pf->vf_qp_offset = pf->lan_qp_offset + pf->lan_nb_qps;
4345 if (hw->func_caps.sr_iov_1_1 && pci_dev->max_vfs) {
4346 pf->flags |= I40E_FLAG_SRIOV;
4347 pf->vf_nb_qps = pf->vf_nb_qp_max;
4348 pf->vf_num = pci_dev->max_vfs;
4350 "%u VF VSIs, %u queues per VF VSI, in total %u queues",
4351 pf->vf_num, pf->vf_nb_qps, pf->vf_nb_qps * pf->vf_num);
4356 qp_count += pf->vf_nb_qps * pf->vf_num;
4357 vsi_count += pf->vf_num;
4359 /* VMDq queue/VSI allocation */
4360 pf->vmdq_qp_offset = pf->vf_qp_offset + pf->vf_nb_qps * pf->vf_num;
4361 pf->vmdq_nb_qps = 0;
4362 pf->max_nb_vmdq_vsi = 0;
4363 if (hw->func_caps.vmdq) {
4364 if (qp_count < hw->func_caps.num_tx_qp &&
4365 vsi_count < hw->func_caps.num_vsis) {
4366 pf->max_nb_vmdq_vsi = (hw->func_caps.num_tx_qp -
4367 qp_count) / pf->vmdq_nb_qp_max;
4369 /* Limit the maximum number of VMDq vsi to the maximum
4370 * ethdev can support
4372 pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
4373 hw->func_caps.num_vsis - vsi_count);
4374 pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
4376 if (pf->max_nb_vmdq_vsi) {
4377 pf->flags |= I40E_FLAG_VMDQ;
4378 pf->vmdq_nb_qps = pf->vmdq_nb_qp_max;
4380 "%u VMDQ VSIs, %u queues per VMDQ VSI, in total %u queues",
4381 pf->max_nb_vmdq_vsi, pf->vmdq_nb_qps,
4382 pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi);
4385 "No enough queues left for VMDq");
4388 PMD_DRV_LOG(INFO, "No queue or VSI left for VMDq");
4391 qp_count += pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi;
4392 vsi_count += pf->max_nb_vmdq_vsi;
4394 if (hw->func_caps.dcb)
4395 pf->flags |= I40E_FLAG_DCB;
4397 if (qp_count > hw->func_caps.num_tx_qp) {
4399 "Failed to allocate %u queues, which exceeds the hardware maximum %u",
4400 qp_count, hw->func_caps.num_tx_qp);
4403 if (vsi_count > hw->func_caps.num_vsis) {
4405 "Failed to allocate %u VSIs, which exceeds the hardware maximum %u",
4406 vsi_count, hw->func_caps.num_vsis);
4414 i40e_pf_get_switch_config(struct i40e_pf *pf)
4416 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4417 struct i40e_aqc_get_switch_config_resp *switch_config;
4418 struct i40e_aqc_switch_config_element_resp *element;
4419 uint16_t start_seid = 0, num_reported;
4422 switch_config = (struct i40e_aqc_get_switch_config_resp *)\
4423 rte_zmalloc("i40e", I40E_AQ_LARGE_BUF, 0);
4424 if (!switch_config) {
4425 PMD_DRV_LOG(ERR, "Failed to allocated memory");
4429 /* Get the switch configurations */
4430 ret = i40e_aq_get_switch_config(hw, switch_config,
4431 I40E_AQ_LARGE_BUF, &start_seid, NULL);
4432 if (ret != I40E_SUCCESS) {
4433 PMD_DRV_LOG(ERR, "Failed to get switch configurations");
4436 num_reported = rte_le_to_cpu_16(switch_config->header.num_reported);
4437 if (num_reported != 1) { /* The number should be 1 */
4438 PMD_DRV_LOG(ERR, "Wrong number of switch config reported");
4442 /* Parse the switch configuration elements */
4443 element = &(switch_config->element[0]);
4444 if (element->element_type == I40E_SWITCH_ELEMENT_TYPE_VSI) {
4445 pf->mac_seid = rte_le_to_cpu_16(element->uplink_seid);
4446 pf->main_vsi_seid = rte_le_to_cpu_16(element->seid);
4448 PMD_DRV_LOG(INFO, "Unknown element type");
4451 rte_free(switch_config);
4457 i40e_res_pool_init (struct i40e_res_pool_info *pool, uint32_t base,
4460 struct pool_entry *entry;
4462 if (pool == NULL || num == 0)
4465 entry = rte_zmalloc("i40e", sizeof(*entry), 0);
4466 if (entry == NULL) {
4467 PMD_DRV_LOG(ERR, "Failed to allocate memory for resource pool");
4471 /* queue heap initialize */
4472 pool->num_free = num;
4473 pool->num_alloc = 0;
4475 LIST_INIT(&pool->alloc_list);
4476 LIST_INIT(&pool->free_list);
4478 /* Initialize element */
4482 LIST_INSERT_HEAD(&pool->free_list, entry, next);
4487 i40e_res_pool_destroy(struct i40e_res_pool_info *pool)
4489 struct pool_entry *entry, *next_entry;
4494 for (entry = LIST_FIRST(&pool->alloc_list);
4495 entry && (next_entry = LIST_NEXT(entry, next), 1);
4496 entry = next_entry) {
4497 LIST_REMOVE(entry, next);
4501 for (entry = LIST_FIRST(&pool->free_list);
4502 entry && (next_entry = LIST_NEXT(entry, next), 1);
4503 entry = next_entry) {
4504 LIST_REMOVE(entry, next);
4509 pool->num_alloc = 0;
4511 LIST_INIT(&pool->alloc_list);
4512 LIST_INIT(&pool->free_list);
4516 i40e_res_pool_free(struct i40e_res_pool_info *pool,
4519 struct pool_entry *entry, *next, *prev, *valid_entry = NULL;
4520 uint32_t pool_offset;
4524 PMD_DRV_LOG(ERR, "Invalid parameter");
4528 pool_offset = base - pool->base;
4529 /* Lookup in alloc list */
4530 LIST_FOREACH(entry, &pool->alloc_list, next) {
4531 if (entry->base == pool_offset) {
4532 valid_entry = entry;
4533 LIST_REMOVE(entry, next);
4538 /* Not find, return */
4539 if (valid_entry == NULL) {
4540 PMD_DRV_LOG(ERR, "Failed to find entry");
4545 * Found it, move it to free list and try to merge.
4546 * In order to make merge easier, always sort it by qbase.
4547 * Find adjacent prev and last entries.
4550 LIST_FOREACH(entry, &pool->free_list, next) {
4551 if (entry->base > valid_entry->base) {
4559 /* Try to merge with next one*/
4561 /* Merge with next one */
4562 if (valid_entry->base + valid_entry->len == next->base) {
4563 next->base = valid_entry->base;
4564 next->len += valid_entry->len;
4565 rte_free(valid_entry);
4572 /* Merge with previous one */
4573 if (prev->base + prev->len == valid_entry->base) {
4574 prev->len += valid_entry->len;
4575 /* If it merge with next one, remove next node */
4577 LIST_REMOVE(valid_entry, next);
4578 rte_free(valid_entry);
4580 rte_free(valid_entry);
4586 /* Not find any entry to merge, insert */
4589 LIST_INSERT_AFTER(prev, valid_entry, next);
4590 else if (next != NULL)
4591 LIST_INSERT_BEFORE(next, valid_entry, next);
4592 else /* It's empty list, insert to head */
4593 LIST_INSERT_HEAD(&pool->free_list, valid_entry, next);
4596 pool->num_free += valid_entry->len;
4597 pool->num_alloc -= valid_entry->len;
4603 i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
4606 struct pool_entry *entry, *valid_entry;
4608 if (pool == NULL || num == 0) {
4609 PMD_DRV_LOG(ERR, "Invalid parameter");
4613 if (pool->num_free < num) {
4614 PMD_DRV_LOG(ERR, "No resource. ask:%u, available:%u",
4615 num, pool->num_free);
4620 /* Lookup in free list and find most fit one */
4621 LIST_FOREACH(entry, &pool->free_list, next) {
4622 if (entry->len >= num) {
4624 if (entry->len == num) {
4625 valid_entry = entry;
4628 if (valid_entry == NULL || valid_entry->len > entry->len)
4629 valid_entry = entry;
4633 /* Not find one to satisfy the request, return */
4634 if (valid_entry == NULL) {
4635 PMD_DRV_LOG(ERR, "No valid entry found");
4639 * The entry have equal queue number as requested,
4640 * remove it from alloc_list.
4642 if (valid_entry->len == num) {
4643 LIST_REMOVE(valid_entry, next);
4646 * The entry have more numbers than requested,
4647 * create a new entry for alloc_list and minus its
4648 * queue base and number in free_list.
4650 entry = rte_zmalloc("res_pool", sizeof(*entry), 0);
4651 if (entry == NULL) {
4653 "Failed to allocate memory for resource pool");
4656 entry->base = valid_entry->base;
4658 valid_entry->base += num;
4659 valid_entry->len -= num;
4660 valid_entry = entry;
4663 /* Insert it into alloc list, not sorted */
4664 LIST_INSERT_HEAD(&pool->alloc_list, valid_entry, next);
4666 pool->num_free -= valid_entry->len;
4667 pool->num_alloc += valid_entry->len;
4669 return valid_entry->base + pool->base;
4673 * bitmap_is_subset - Check whether src2 is subset of src1
4676 bitmap_is_subset(uint8_t src1, uint8_t src2)
4678 return !((src1 ^ src2) & src2);
4681 static enum i40e_status_code
4682 validate_tcmap_parameter(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
4684 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4686 /* If DCB is not supported, only default TC is supported */
4687 if (!hw->func_caps.dcb && enabled_tcmap != I40E_DEFAULT_TCMAP) {
4688 PMD_DRV_LOG(ERR, "DCB is not enabled, only TC0 is supported");
4689 return I40E_NOT_SUPPORTED;
4692 if (!bitmap_is_subset(hw->func_caps.enabled_tcmap, enabled_tcmap)) {
4694 "Enabled TC map 0x%x not applicable to HW support 0x%x",
4695 hw->func_caps.enabled_tcmap, enabled_tcmap);
4696 return I40E_NOT_SUPPORTED;
4698 return I40E_SUCCESS;
4702 i40e_vsi_vlan_pvid_set(struct i40e_vsi *vsi,
4703 struct i40e_vsi_vlan_pvid_info *info)
4706 struct i40e_vsi_context ctxt;
4707 uint8_t vlan_flags = 0;
4710 if (vsi == NULL || info == NULL) {
4711 PMD_DRV_LOG(ERR, "invalid parameters");
4712 return I40E_ERR_PARAM;
4716 vsi->info.pvid = info->config.pvid;
4718 * If insert pvid is enabled, only tagged pkts are
4719 * allowed to be sent out.
4721 vlan_flags |= I40E_AQ_VSI_PVLAN_INSERT_PVID |
4722 I40E_AQ_VSI_PVLAN_MODE_TAGGED;
4725 if (info->config.reject.tagged == 0)
4726 vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_TAGGED;
4728 if (info->config.reject.untagged == 0)
4729 vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_UNTAGGED;
4731 vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_INSERT_PVID |
4732 I40E_AQ_VSI_PVLAN_MODE_MASK);
4733 vsi->info.port_vlan_flags |= vlan_flags;
4734 vsi->info.valid_sections =
4735 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
4736 memset(&ctxt, 0, sizeof(ctxt));
4737 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
4738 ctxt.seid = vsi->seid;
4740 hw = I40E_VSI_TO_HW(vsi);
4741 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
4742 if (ret != I40E_SUCCESS)
4743 PMD_DRV_LOG(ERR, "Failed to update VSI params");
4749 i40e_vsi_update_tc_bandwidth(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
4751 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4753 struct i40e_aqc_configure_vsi_tc_bw_data tc_bw_data;
4755 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
4756 if (ret != I40E_SUCCESS)
4760 PMD_DRV_LOG(ERR, "seid not valid");
4764 memset(&tc_bw_data, 0, sizeof(tc_bw_data));
4765 tc_bw_data.tc_valid_bits = enabled_tcmap;
4766 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
4767 tc_bw_data.tc_bw_credits[i] =
4768 (enabled_tcmap & (1 << i)) ? 1 : 0;
4770 ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &tc_bw_data, NULL);
4771 if (ret != I40E_SUCCESS) {
4772 PMD_DRV_LOG(ERR, "Failed to configure TC BW");
4776 rte_memcpy(vsi->info.qs_handle, tc_bw_data.qs_handles,
4777 sizeof(vsi->info.qs_handle));
4778 return I40E_SUCCESS;
4781 static enum i40e_status_code
4782 i40e_vsi_config_tc_queue_mapping(struct i40e_vsi *vsi,
4783 struct i40e_aqc_vsi_properties_data *info,
4784 uint8_t enabled_tcmap)
4786 enum i40e_status_code ret;
4787 int i, total_tc = 0;
4788 uint16_t qpnum_per_tc, bsf, qp_idx;
4790 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
4791 if (ret != I40E_SUCCESS)
4794 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
4795 if (enabled_tcmap & (1 << i))
4799 vsi->enabled_tc = enabled_tcmap;
4801 /* Number of queues per enabled TC */
4802 qpnum_per_tc = i40e_align_floor(vsi->nb_qps / total_tc);
4803 qpnum_per_tc = RTE_MIN(qpnum_per_tc, I40E_MAX_Q_PER_TC);
4804 bsf = rte_bsf32(qpnum_per_tc);
4806 /* Adjust the queue number to actual queues that can be applied */
4807 if (!(vsi->type == I40E_VSI_MAIN && total_tc == 1))
4808 vsi->nb_qps = qpnum_per_tc * total_tc;
4811 * Configure TC and queue mapping parameters, for enabled TC,
4812 * allocate qpnum_per_tc queues to this traffic. For disabled TC,
4813 * default queue will serve it.
4816 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4817 if (vsi->enabled_tc & (1 << i)) {
4818 info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
4819 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
4820 (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
4821 qp_idx += qpnum_per_tc;
4823 info->tc_mapping[i] = 0;
4826 /* Associate queue number with VSI */
4827 if (vsi->type == I40E_VSI_SRIOV) {
4828 info->mapping_flags |=
4829 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
4830 for (i = 0; i < vsi->nb_qps; i++)
4831 info->queue_mapping[i] =
4832 rte_cpu_to_le_16(vsi->base_queue + i);
4834 info->mapping_flags |=
4835 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
4836 info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
4838 info->valid_sections |=
4839 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
4841 return I40E_SUCCESS;
4845 i40e_veb_release(struct i40e_veb *veb)
4847 struct i40e_vsi *vsi;
4853 if (!TAILQ_EMPTY(&veb->head)) {
4854 PMD_DRV_LOG(ERR, "VEB still has VSI attached, can't remove");
4857 /* associate_vsi field is NULL for floating VEB */
4858 if (veb->associate_vsi != NULL) {
4859 vsi = veb->associate_vsi;
4860 hw = I40E_VSI_TO_HW(vsi);
4862 vsi->uplink_seid = veb->uplink_seid;
4865 veb->associate_pf->main_vsi->floating_veb = NULL;
4866 hw = I40E_VSI_TO_HW(veb->associate_pf->main_vsi);
4869 i40e_aq_delete_element(hw, veb->seid, NULL);
4871 return I40E_SUCCESS;
4875 static struct i40e_veb *
4876 i40e_veb_setup(struct i40e_pf *pf, struct i40e_vsi *vsi)
4878 struct i40e_veb *veb;
4884 "veb setup failed, associated PF shouldn't null");
4887 hw = I40E_PF_TO_HW(pf);
4889 veb = rte_zmalloc("i40e_veb", sizeof(struct i40e_veb), 0);
4891 PMD_DRV_LOG(ERR, "Failed to allocate memory for veb");
4895 veb->associate_vsi = vsi;
4896 veb->associate_pf = pf;
4897 TAILQ_INIT(&veb->head);
4898 veb->uplink_seid = vsi ? vsi->uplink_seid : 0;
4900 /* create floating veb if vsi is NULL */
4902 ret = i40e_aq_add_veb(hw, veb->uplink_seid, vsi->seid,
4903 I40E_DEFAULT_TCMAP, false,
4904 &veb->seid, false, NULL);
4906 ret = i40e_aq_add_veb(hw, 0, 0, I40E_DEFAULT_TCMAP,
4907 true, &veb->seid, false, NULL);
4910 if (ret != I40E_SUCCESS) {
4911 PMD_DRV_LOG(ERR, "Add veb failed, aq_err: %d",
4912 hw->aq.asq_last_status);
4915 veb->enabled_tc = I40E_DEFAULT_TCMAP;
4917 /* get statistics index */
4918 ret = i40e_aq_get_veb_parameters(hw, veb->seid, NULL, NULL,
4919 &veb->stats_idx, NULL, NULL, NULL);
4920 if (ret != I40E_SUCCESS) {
4921 PMD_DRV_LOG(ERR, "Get veb statistics index failed, aq_err: %d",
4922 hw->aq.asq_last_status);
4925 /* Get VEB bandwidth, to be implemented */
4926 /* Now associated vsi binding to the VEB, set uplink to this VEB */
4928 vsi->uplink_seid = veb->seid;
4937 i40e_vsi_release(struct i40e_vsi *vsi)
4941 struct i40e_vsi_list *vsi_list;
4944 struct i40e_mac_filter *f;
4945 uint16_t user_param;
4948 return I40E_SUCCESS;
4953 user_param = vsi->user_param;
4955 pf = I40E_VSI_TO_PF(vsi);
4956 hw = I40E_VSI_TO_HW(vsi);
4958 /* VSI has child to attach, release child first */
4960 TAILQ_FOREACH_SAFE(vsi_list, &vsi->veb->head, list, temp) {
4961 if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
4964 i40e_veb_release(vsi->veb);
4967 if (vsi->floating_veb) {
4968 TAILQ_FOREACH_SAFE(vsi_list, &vsi->floating_veb->head, list, temp) {
4969 if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
4974 /* Remove all macvlan filters of the VSI */
4975 i40e_vsi_remove_all_macvlan_filter(vsi);
4976 TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp)
4979 if (vsi->type != I40E_VSI_MAIN &&
4980 ((vsi->type != I40E_VSI_SRIOV) ||
4981 !pf->floating_veb_list[user_param])) {
4982 /* Remove vsi from parent's sibling list */
4983 if (vsi->parent_vsi == NULL || vsi->parent_vsi->veb == NULL) {
4984 PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
4985 return I40E_ERR_PARAM;
4987 TAILQ_REMOVE(&vsi->parent_vsi->veb->head,
4988 &vsi->sib_vsi_list, list);
4990 /* Remove all switch element of the VSI */
4991 ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
4992 if (ret != I40E_SUCCESS)
4993 PMD_DRV_LOG(ERR, "Failed to delete element");
4996 if ((vsi->type == I40E_VSI_SRIOV) &&
4997 pf->floating_veb_list[user_param]) {
4998 /* Remove vsi from parent's sibling list */
4999 if (vsi->parent_vsi == NULL ||
5000 vsi->parent_vsi->floating_veb == NULL) {
5001 PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
5002 return I40E_ERR_PARAM;
5004 TAILQ_REMOVE(&vsi->parent_vsi->floating_veb->head,
5005 &vsi->sib_vsi_list, list);
5007 /* Remove all switch element of the VSI */
5008 ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
5009 if (ret != I40E_SUCCESS)
5010 PMD_DRV_LOG(ERR, "Failed to delete element");
5013 i40e_res_pool_free(&pf->qp_pool, vsi->base_queue);
5015 if (vsi->type != I40E_VSI_SRIOV)
5016 i40e_res_pool_free(&pf->msix_pool, vsi->msix_intr);
5019 return I40E_SUCCESS;
5023 i40e_update_default_filter_setting(struct i40e_vsi *vsi)
5025 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5026 struct i40e_aqc_remove_macvlan_element_data def_filter;
5027 struct i40e_mac_filter_info filter;
5030 if (vsi->type != I40E_VSI_MAIN)
5031 return I40E_ERR_CONFIG;
5032 memset(&def_filter, 0, sizeof(def_filter));
5033 rte_memcpy(def_filter.mac_addr, hw->mac.perm_addr,
5035 def_filter.vlan_tag = 0;
5036 def_filter.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
5037 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
5038 ret = i40e_aq_remove_macvlan(hw, vsi->seid, &def_filter, 1, NULL);
5039 if (ret != I40E_SUCCESS) {
5040 struct i40e_mac_filter *f;
5041 struct ether_addr *mac;
5044 "Cannot remove the default macvlan filter");
5045 /* It needs to add the permanent mac into mac list */
5046 f = rte_zmalloc("macv_filter", sizeof(*f), 0);
5048 PMD_DRV_LOG(ERR, "failed to allocate memory");
5049 return I40E_ERR_NO_MEMORY;
5051 mac = &f->mac_info.mac_addr;
5052 rte_memcpy(&mac->addr_bytes, hw->mac.perm_addr,
5054 f->mac_info.filter_type = RTE_MACVLAN_PERFECT_MATCH;
5055 TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
5060 rte_memcpy(&filter.mac_addr,
5061 (struct ether_addr *)(hw->mac.perm_addr), ETH_ADDR_LEN);
5062 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
5063 return i40e_vsi_add_mac(vsi, &filter);
5067 * i40e_vsi_get_bw_config - Query VSI BW Information
5068 * @vsi: the VSI to be queried
5070 * Returns 0 on success, negative value on failure
5072 static enum i40e_status_code
5073 i40e_vsi_get_bw_config(struct i40e_vsi *vsi)
5075 struct i40e_aqc_query_vsi_bw_config_resp bw_config;
5076 struct i40e_aqc_query_vsi_ets_sla_config_resp ets_sla_config;
5077 struct i40e_hw *hw = &vsi->adapter->hw;
5082 memset(&bw_config, 0, sizeof(bw_config));
5083 ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
5084 if (ret != I40E_SUCCESS) {
5085 PMD_DRV_LOG(ERR, "VSI failed to get bandwidth configuration %u",
5086 hw->aq.asq_last_status);
5090 memset(&ets_sla_config, 0, sizeof(ets_sla_config));
5091 ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid,
5092 &ets_sla_config, NULL);
5093 if (ret != I40E_SUCCESS) {
5095 "VSI failed to get TC bandwdith configuration %u",
5096 hw->aq.asq_last_status);
5100 /* store and print out BW info */
5101 vsi->bw_info.bw_limit = rte_le_to_cpu_16(bw_config.port_bw_limit);
5102 vsi->bw_info.bw_max = bw_config.max_bw;
5103 PMD_DRV_LOG(DEBUG, "VSI bw limit:%u", vsi->bw_info.bw_limit);
5104 PMD_DRV_LOG(DEBUG, "VSI max_bw:%u", vsi->bw_info.bw_max);
5105 bw_max = rte_le_to_cpu_16(ets_sla_config.tc_bw_max[0]) |
5106 (rte_le_to_cpu_16(ets_sla_config.tc_bw_max[1]) <<
5108 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5109 vsi->bw_info.bw_ets_share_credits[i] =
5110 ets_sla_config.share_credits[i];
5111 vsi->bw_info.bw_ets_credits[i] =
5112 rte_le_to_cpu_16(ets_sla_config.credits[i]);
5113 /* 4 bits per TC, 4th bit is reserved */
5114 vsi->bw_info.bw_ets_max[i] =
5115 (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
5116 RTE_LEN2MASK(3, uint8_t));
5117 PMD_DRV_LOG(DEBUG, "\tVSI TC%u:share credits %u", i,
5118 vsi->bw_info.bw_ets_share_credits[i]);
5119 PMD_DRV_LOG(DEBUG, "\tVSI TC%u:credits %u", i,
5120 vsi->bw_info.bw_ets_credits[i]);
5121 PMD_DRV_LOG(DEBUG, "\tVSI TC%u: max credits: %u", i,
5122 vsi->bw_info.bw_ets_max[i]);
5125 return I40E_SUCCESS;
5128 /* i40e_enable_pf_lb
5129 * @pf: pointer to the pf structure
5131 * allow loopback on pf
5134 i40e_enable_pf_lb(struct i40e_pf *pf)
5136 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5137 struct i40e_vsi_context ctxt;
5140 /* Use the FW API if FW >= v5.0 */
5141 if (hw->aq.fw_maj_ver < 5) {
5142 PMD_INIT_LOG(ERR, "FW < v5.0, cannot enable loopback");
5146 memset(&ctxt, 0, sizeof(ctxt));
5147 ctxt.seid = pf->main_vsi_seid;
5148 ctxt.pf_num = hw->pf_id;
5149 ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5151 PMD_DRV_LOG(ERR, "cannot get pf vsi config, err %d, aq_err %d",
5152 ret, hw->aq.asq_last_status);
5155 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
5156 ctxt.info.valid_sections =
5157 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5158 ctxt.info.switch_id |=
5159 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5161 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5163 PMD_DRV_LOG(ERR, "update vsi switch failed, aq_err=%d",
5164 hw->aq.asq_last_status);
5169 i40e_vsi_setup(struct i40e_pf *pf,
5170 enum i40e_vsi_type type,
5171 struct i40e_vsi *uplink_vsi,
5172 uint16_t user_param)
5174 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5175 struct i40e_vsi *vsi;
5176 struct i40e_mac_filter_info filter;
5178 struct i40e_vsi_context ctxt;
5179 struct ether_addr broadcast =
5180 {.addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
5182 if (type != I40E_VSI_MAIN && type != I40E_VSI_SRIOV &&
5183 uplink_vsi == NULL) {
5185 "VSI setup failed, VSI link shouldn't be NULL");
5189 if (type == I40E_VSI_MAIN && uplink_vsi != NULL) {
5191 "VSI setup failed, MAIN VSI uplink VSI should be NULL");
5196 * 1.type is not MAIN and uplink vsi is not NULL
5197 * If uplink vsi didn't setup VEB, create one first under veb field
5198 * 2.type is SRIOV and the uplink is NULL
5199 * If floating VEB is NULL, create one veb under floating veb field
5202 if (type != I40E_VSI_MAIN && uplink_vsi != NULL &&
5203 uplink_vsi->veb == NULL) {
5204 uplink_vsi->veb = i40e_veb_setup(pf, uplink_vsi);
5206 if (uplink_vsi->veb == NULL) {
5207 PMD_DRV_LOG(ERR, "VEB setup failed");
5210 /* set ALLOWLOOPBACk on pf, when veb is created */
5211 i40e_enable_pf_lb(pf);
5214 if (type == I40E_VSI_SRIOV && uplink_vsi == NULL &&
5215 pf->main_vsi->floating_veb == NULL) {
5216 pf->main_vsi->floating_veb = i40e_veb_setup(pf, uplink_vsi);
5218 if (pf->main_vsi->floating_veb == NULL) {
5219 PMD_DRV_LOG(ERR, "VEB setup failed");
5224 vsi = rte_zmalloc("i40e_vsi", sizeof(struct i40e_vsi), 0);
5226 PMD_DRV_LOG(ERR, "Failed to allocate memory for vsi");
5229 TAILQ_INIT(&vsi->mac_list);
5231 vsi->adapter = I40E_PF_TO_ADAPTER(pf);
5232 vsi->max_macaddrs = I40E_NUM_MACADDR_MAX;
5233 vsi->parent_vsi = uplink_vsi ? uplink_vsi : pf->main_vsi;
5234 vsi->user_param = user_param;
5235 vsi->vlan_anti_spoof_on = 0;
5236 vsi->vlan_filter_on = 0;
5237 /* Allocate queues */
5238 switch (vsi->type) {
5239 case I40E_VSI_MAIN :
5240 vsi->nb_qps = pf->lan_nb_qps;
5242 case I40E_VSI_SRIOV :
5243 vsi->nb_qps = pf->vf_nb_qps;
5245 case I40E_VSI_VMDQ2:
5246 vsi->nb_qps = pf->vmdq_nb_qps;
5249 vsi->nb_qps = pf->fdir_nb_qps;
5255 * The filter status descriptor is reported in rx queue 0,
5256 * while the tx queue for fdir filter programming has no
5257 * such constraints, can be non-zero queues.
5258 * To simplify it, choose FDIR vsi use queue 0 pair.
5259 * To make sure it will use queue 0 pair, queue allocation
5260 * need be done before this function is called
5262 if (type != I40E_VSI_FDIR) {
5263 ret = i40e_res_pool_alloc(&pf->qp_pool, vsi->nb_qps);
5265 PMD_DRV_LOG(ERR, "VSI %d allocate queue failed %d",
5269 vsi->base_queue = ret;
5271 vsi->base_queue = I40E_FDIR_QUEUE_ID;
5273 /* VF has MSIX interrupt in VF range, don't allocate here */
5274 if (type == I40E_VSI_MAIN) {
5275 if (pf->support_multi_driver) {
5276 /* If support multi-driver, need to use INT0 instead of
5277 * allocating from msix pool. The Msix pool is init from
5278 * INT1, so it's OK just set msix_intr to 0 and nb_msix
5279 * to 1 without calling i40e_res_pool_alloc.
5284 ret = i40e_res_pool_alloc(&pf->msix_pool,
5285 RTE_MIN(vsi->nb_qps,
5286 RTE_MAX_RXTX_INTR_VEC_ID));
5289 "VSI MAIN %d get heap failed %d",
5291 goto fail_queue_alloc;
5293 vsi->msix_intr = ret;
5294 vsi->nb_msix = RTE_MIN(vsi->nb_qps,
5295 RTE_MAX_RXTX_INTR_VEC_ID);
5297 } else if (type != I40E_VSI_SRIOV) {
5298 ret = i40e_res_pool_alloc(&pf->msix_pool, 1);
5300 PMD_DRV_LOG(ERR, "VSI %d get heap failed %d", vsi->seid, ret);
5301 goto fail_queue_alloc;
5303 vsi->msix_intr = ret;
5311 if (type == I40E_VSI_MAIN) {
5312 /* For main VSI, no need to add since it's default one */
5313 vsi->uplink_seid = pf->mac_seid;
5314 vsi->seid = pf->main_vsi_seid;
5315 /* Bind queues with specific MSIX interrupt */
5317 * Needs 2 interrupt at least, one for misc cause which will
5318 * enabled from OS side, Another for queues binding the
5319 * interrupt from device side only.
5322 /* Get default VSI parameters from hardware */
5323 memset(&ctxt, 0, sizeof(ctxt));
5324 ctxt.seid = vsi->seid;
5325 ctxt.pf_num = hw->pf_id;
5326 ctxt.uplink_seid = vsi->uplink_seid;
5328 ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5329 if (ret != I40E_SUCCESS) {
5330 PMD_DRV_LOG(ERR, "Failed to get VSI params");
5331 goto fail_msix_alloc;
5333 rte_memcpy(&vsi->info, &ctxt.info,
5334 sizeof(struct i40e_aqc_vsi_properties_data));
5335 vsi->vsi_id = ctxt.vsi_number;
5336 vsi->info.valid_sections = 0;
5338 /* Configure tc, enabled TC0 only */
5339 if (i40e_vsi_update_tc_bandwidth(vsi, I40E_DEFAULT_TCMAP) !=
5341 PMD_DRV_LOG(ERR, "Failed to update TC bandwidth");
5342 goto fail_msix_alloc;
5345 /* TC, queue mapping */
5346 memset(&ctxt, 0, sizeof(ctxt));
5347 vsi->info.valid_sections |=
5348 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5349 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
5350 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
5351 rte_memcpy(&ctxt.info, &vsi->info,
5352 sizeof(struct i40e_aqc_vsi_properties_data));
5353 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
5354 I40E_DEFAULT_TCMAP);
5355 if (ret != I40E_SUCCESS) {
5357 "Failed to configure TC queue mapping");
5358 goto fail_msix_alloc;
5360 ctxt.seid = vsi->seid;
5361 ctxt.pf_num = hw->pf_id;
5362 ctxt.uplink_seid = vsi->uplink_seid;
5365 /* Update VSI parameters */
5366 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5367 if (ret != I40E_SUCCESS) {
5368 PMD_DRV_LOG(ERR, "Failed to update VSI params");
5369 goto fail_msix_alloc;
5372 rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
5373 sizeof(vsi->info.tc_mapping));
5374 rte_memcpy(&vsi->info.queue_mapping,
5375 &ctxt.info.queue_mapping,
5376 sizeof(vsi->info.queue_mapping));
5377 vsi->info.mapping_flags = ctxt.info.mapping_flags;
5378 vsi->info.valid_sections = 0;
5380 rte_memcpy(pf->dev_addr.addr_bytes, hw->mac.perm_addr,
5384 * Updating default filter settings are necessary to prevent
5385 * reception of tagged packets.
5386 * Some old firmware configurations load a default macvlan
5387 * filter which accepts both tagged and untagged packets.
5388 * The updating is to use a normal filter instead if needed.
5389 * For NVM 4.2.2 or after, the updating is not needed anymore.
5390 * The firmware with correct configurations load the default
5391 * macvlan filter which is expected and cannot be removed.
5393 i40e_update_default_filter_setting(vsi);
5394 i40e_config_qinq(hw, vsi);
5395 } else if (type == I40E_VSI_SRIOV) {
5396 memset(&ctxt, 0, sizeof(ctxt));
5398 * For other VSI, the uplink_seid equals to uplink VSI's
5399 * uplink_seid since they share same VEB
5401 if (uplink_vsi == NULL)
5402 vsi->uplink_seid = pf->main_vsi->floating_veb->seid;
5404 vsi->uplink_seid = uplink_vsi->uplink_seid;
5405 ctxt.pf_num = hw->pf_id;
5406 ctxt.vf_num = hw->func_caps.vf_base_id + user_param;
5407 ctxt.uplink_seid = vsi->uplink_seid;
5408 ctxt.connection_type = 0x1;
5409 ctxt.flags = I40E_AQ_VSI_TYPE_VF;
5411 /* Use the VEB configuration if FW >= v5.0 */
5412 if (hw->aq.fw_maj_ver >= 5) {
5413 /* Configure switch ID */
5414 ctxt.info.valid_sections |=
5415 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5416 ctxt.info.switch_id =
5417 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5420 /* Configure port/vlan */
5421 ctxt.info.valid_sections |=
5422 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5423 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
5424 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
5425 hw->func_caps.enabled_tcmap);
5426 if (ret != I40E_SUCCESS) {
5428 "Failed to configure TC queue mapping");
5429 goto fail_msix_alloc;
5432 ctxt.info.up_enable_bits = hw->func_caps.enabled_tcmap;
5433 ctxt.info.valid_sections |=
5434 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
5436 * Since VSI is not created yet, only configure parameter,
5437 * will add vsi below.
5440 i40e_config_qinq(hw, vsi);
5441 } else if (type == I40E_VSI_VMDQ2) {
5442 memset(&ctxt, 0, sizeof(ctxt));
5444 * For other VSI, the uplink_seid equals to uplink VSI's
5445 * uplink_seid since they share same VEB
5447 vsi->uplink_seid = uplink_vsi->uplink_seid;
5448 ctxt.pf_num = hw->pf_id;
5450 ctxt.uplink_seid = vsi->uplink_seid;
5451 ctxt.connection_type = 0x1;
5452 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
5454 ctxt.info.valid_sections |=
5455 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5456 /* user_param carries flag to enable loop back */
5458 ctxt.info.switch_id =
5459 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
5460 ctxt.info.switch_id |=
5461 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5464 /* Configure port/vlan */
5465 ctxt.info.valid_sections |=
5466 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5467 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
5468 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
5469 I40E_DEFAULT_TCMAP);
5470 if (ret != I40E_SUCCESS) {
5472 "Failed to configure TC queue mapping");
5473 goto fail_msix_alloc;
5475 ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
5476 ctxt.info.valid_sections |=
5477 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
5478 } else if (type == I40E_VSI_FDIR) {
5479 memset(&ctxt, 0, sizeof(ctxt));
5480 vsi->uplink_seid = uplink_vsi->uplink_seid;
5481 ctxt.pf_num = hw->pf_id;
5483 ctxt.uplink_seid = vsi->uplink_seid;
5484 ctxt.connection_type = 0x1; /* regular data port */
5485 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
5486 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
5487 I40E_DEFAULT_TCMAP);
5488 if (ret != I40E_SUCCESS) {
5490 "Failed to configure TC queue mapping.");
5491 goto fail_msix_alloc;
5493 ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
5494 ctxt.info.valid_sections |=
5495 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
5497 PMD_DRV_LOG(ERR, "VSI: Not support other type VSI yet");
5498 goto fail_msix_alloc;
5501 if (vsi->type != I40E_VSI_MAIN) {
5502 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
5503 if (ret != I40E_SUCCESS) {
5504 PMD_DRV_LOG(ERR, "add vsi failed, aq_err=%d",
5505 hw->aq.asq_last_status);
5506 goto fail_msix_alloc;
5508 memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
5509 vsi->info.valid_sections = 0;
5510 vsi->seid = ctxt.seid;
5511 vsi->vsi_id = ctxt.vsi_number;
5512 vsi->sib_vsi_list.vsi = vsi;
5513 if (vsi->type == I40E_VSI_SRIOV && uplink_vsi == NULL) {
5514 TAILQ_INSERT_TAIL(&pf->main_vsi->floating_veb->head,
5515 &vsi->sib_vsi_list, list);
5517 TAILQ_INSERT_TAIL(&uplink_vsi->veb->head,
5518 &vsi->sib_vsi_list, list);
5522 /* MAC/VLAN configuration */
5523 rte_memcpy(&filter.mac_addr, &broadcast, ETHER_ADDR_LEN);
5524 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
5526 ret = i40e_vsi_add_mac(vsi, &filter);
5527 if (ret != I40E_SUCCESS) {
5528 PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
5529 goto fail_msix_alloc;
5532 /* Get VSI BW information */
5533 i40e_vsi_get_bw_config(vsi);
5536 i40e_res_pool_free(&pf->msix_pool,vsi->msix_intr);
5538 i40e_res_pool_free(&pf->qp_pool,vsi->base_queue);
5544 /* Configure vlan filter on or off */
5546 i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on)
5549 struct i40e_mac_filter *f;
5551 struct i40e_mac_filter_info *mac_filter;
5552 enum rte_mac_filter_type desired_filter;
5553 int ret = I40E_SUCCESS;
5556 /* Filter to match MAC and VLAN */
5557 desired_filter = RTE_MACVLAN_PERFECT_MATCH;
5559 /* Filter to match only MAC */
5560 desired_filter = RTE_MAC_PERFECT_MATCH;
5565 mac_filter = rte_zmalloc("mac_filter_info_data",
5566 num * sizeof(*mac_filter), 0);
5567 if (mac_filter == NULL) {
5568 PMD_DRV_LOG(ERR, "failed to allocate memory");
5569 return I40E_ERR_NO_MEMORY;
5574 /* Remove all existing mac */
5575 TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
5576 mac_filter[i] = f->mac_info;
5577 ret = i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
5579 PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
5580 on ? "enable" : "disable");
5586 /* Override with new filter */
5587 for (i = 0; i < num; i++) {
5588 mac_filter[i].filter_type = desired_filter;
5589 ret = i40e_vsi_add_mac(vsi, &mac_filter[i]);
5591 PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
5592 on ? "enable" : "disable");
5598 rte_free(mac_filter);
5602 /* Configure vlan stripping on or off */
5604 i40e_vsi_config_vlan_stripping(struct i40e_vsi *vsi, bool on)
5606 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5607 struct i40e_vsi_context ctxt;
5609 int ret = I40E_SUCCESS;
5611 /* Check if it has been already on or off */
5612 if (vsi->info.valid_sections &
5613 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID)) {
5615 if ((vsi->info.port_vlan_flags &
5616 I40E_AQ_VSI_PVLAN_EMOD_MASK) == 0)
5617 return 0; /* already on */
5619 if ((vsi->info.port_vlan_flags &
5620 I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
5621 I40E_AQ_VSI_PVLAN_EMOD_MASK)
5622 return 0; /* already off */
5627 vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
5629 vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
5630 vsi->info.valid_sections =
5631 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5632 vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_EMOD_MASK);
5633 vsi->info.port_vlan_flags |= vlan_flags;
5634 ctxt.seid = vsi->seid;
5635 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
5636 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5638 PMD_DRV_LOG(INFO, "Update VSI failed to %s vlan stripping",
5639 on ? "enable" : "disable");
5645 i40e_dev_init_vlan(struct rte_eth_dev *dev)
5647 struct rte_eth_dev_data *data = dev->data;
5651 /* Apply vlan offload setting */
5652 mask = ETH_VLAN_STRIP_MASK |
5653 ETH_VLAN_FILTER_MASK |
5654 ETH_VLAN_EXTEND_MASK;
5655 ret = i40e_vlan_offload_set(dev, mask);
5657 PMD_DRV_LOG(INFO, "Failed to update vlan offload");
5661 /* Apply pvid setting */
5662 ret = i40e_vlan_pvid_set(dev, data->dev_conf.txmode.pvid,
5663 data->dev_conf.txmode.hw_vlan_insert_pvid);
5665 PMD_DRV_LOG(INFO, "Failed to update VSI params");
5671 i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on)
5673 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5675 return i40e_aq_set_port_parameters(hw, vsi->seid, 0, 1, on, NULL);
5679 i40e_update_flow_control(struct i40e_hw *hw)
5681 #define I40E_LINK_PAUSE_RXTX (I40E_AQ_LINK_PAUSE_RX | I40E_AQ_LINK_PAUSE_TX)
5682 struct i40e_link_status link_status;
5683 uint32_t rxfc = 0, txfc = 0, reg;
5687 memset(&link_status, 0, sizeof(link_status));
5688 ret = i40e_aq_get_link_info(hw, FALSE, &link_status, NULL);
5689 if (ret != I40E_SUCCESS) {
5690 PMD_DRV_LOG(ERR, "Failed to get link status information");
5691 goto write_reg; /* Disable flow control */
5694 an_info = hw->phy.link_info.an_info;
5695 if (!(an_info & I40E_AQ_AN_COMPLETED)) {
5696 PMD_DRV_LOG(INFO, "Link auto negotiation not completed");
5697 ret = I40E_ERR_NOT_READY;
5698 goto write_reg; /* Disable flow control */
5701 * If link auto negotiation is enabled, flow control needs to
5702 * be configured according to it
5704 switch (an_info & I40E_LINK_PAUSE_RXTX) {
5705 case I40E_LINK_PAUSE_RXTX:
5708 hw->fc.current_mode = I40E_FC_FULL;
5710 case I40E_AQ_LINK_PAUSE_RX:
5712 hw->fc.current_mode = I40E_FC_RX_PAUSE;
5714 case I40E_AQ_LINK_PAUSE_TX:
5716 hw->fc.current_mode = I40E_FC_TX_PAUSE;
5719 hw->fc.current_mode = I40E_FC_NONE;
5724 I40E_WRITE_REG(hw, I40E_PRTDCB_FCCFG,
5725 txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT);
5726 reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
5727 reg &= ~I40E_PRTDCB_MFLCN_RFCE_MASK;
5728 reg |= rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT;
5729 I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, reg);
5736 i40e_pf_setup(struct i40e_pf *pf)
5738 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5739 struct i40e_filter_control_settings settings;
5740 struct i40e_vsi *vsi;
5743 /* Clear all stats counters */
5744 pf->offset_loaded = FALSE;
5745 memset(&pf->stats, 0, sizeof(struct i40e_hw_port_stats));
5746 memset(&pf->stats_offset, 0, sizeof(struct i40e_hw_port_stats));
5747 memset(&pf->internal_stats, 0, sizeof(struct i40e_eth_stats));
5748 memset(&pf->internal_stats_offset, 0, sizeof(struct i40e_eth_stats));
5750 ret = i40e_pf_get_switch_config(pf);
5751 if (ret != I40E_SUCCESS) {
5752 PMD_DRV_LOG(ERR, "Could not get switch config, err %d", ret);
5755 if (pf->flags & I40E_FLAG_FDIR) {
5756 /* make queue allocated first, let FDIR use queue pair 0*/
5757 ret = i40e_res_pool_alloc(&pf->qp_pool, I40E_DEFAULT_QP_NUM_FDIR);
5758 if (ret != I40E_FDIR_QUEUE_ID) {
5760 "queue allocation fails for FDIR: ret =%d",
5762 pf->flags &= ~I40E_FLAG_FDIR;
5765 /* main VSI setup */
5766 vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, NULL, 0);
5768 PMD_DRV_LOG(ERR, "Setup of main vsi failed");
5769 return I40E_ERR_NOT_READY;
5773 /* Configure filter control */
5774 memset(&settings, 0, sizeof(settings));
5775 if (hw->func_caps.rss_table_size == ETH_RSS_RETA_SIZE_128)
5776 settings.hash_lut_size = I40E_HASH_LUT_SIZE_128;
5777 else if (hw->func_caps.rss_table_size == ETH_RSS_RETA_SIZE_512)
5778 settings.hash_lut_size = I40E_HASH_LUT_SIZE_512;
5780 PMD_DRV_LOG(ERR, "Hash lookup table size (%u) not supported",
5781 hw->func_caps.rss_table_size);
5782 return I40E_ERR_PARAM;
5784 PMD_DRV_LOG(INFO, "Hardware capability of hash lookup table size: %u",
5785 hw->func_caps.rss_table_size);
5786 pf->hash_lut_size = hw->func_caps.rss_table_size;
5788 /* Enable ethtype and macvlan filters */
5789 settings.enable_ethtype = TRUE;
5790 settings.enable_macvlan = TRUE;
5791 ret = i40e_set_filter_control(hw, &settings);
5793 PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
5796 /* Update flow control according to the auto negotiation */
5797 i40e_update_flow_control(hw);
5799 return I40E_SUCCESS;
5803 i40e_switch_tx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
5809 * Set or clear TX Queue Disable flags,
5810 * which is required by hardware.
5812 i40e_pre_tx_queue_cfg(hw, q_idx, on);
5813 rte_delay_us(I40E_PRE_TX_Q_CFG_WAIT_US);
5815 /* Wait until the request is finished */
5816 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
5817 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
5818 reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
5819 if (!(((reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 0x1) ^
5820 ((reg >> I40E_QTX_ENA_QENA_STAT_SHIFT)
5826 if (reg & I40E_QTX_ENA_QENA_STAT_MASK)
5827 return I40E_SUCCESS; /* already on, skip next steps */
5829 I40E_WRITE_REG(hw, I40E_QTX_HEAD(q_idx), 0);
5830 reg |= I40E_QTX_ENA_QENA_REQ_MASK;
5832 if (!(reg & I40E_QTX_ENA_QENA_STAT_MASK))
5833 return I40E_SUCCESS; /* already off, skip next steps */
5834 reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
5836 /* Write the register */
5837 I40E_WRITE_REG(hw, I40E_QTX_ENA(q_idx), reg);
5838 /* Check the result */
5839 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
5840 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
5841 reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
5843 if ((reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
5844 (reg & I40E_QTX_ENA_QENA_STAT_MASK))
5847 if (!(reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
5848 !(reg & I40E_QTX_ENA_QENA_STAT_MASK))
5852 /* Check if it is timeout */
5853 if (j >= I40E_CHK_Q_ENA_COUNT) {
5854 PMD_DRV_LOG(ERR, "Failed to %s tx queue[%u]",
5855 (on ? "enable" : "disable"), q_idx);
5856 return I40E_ERR_TIMEOUT;
5859 return I40E_SUCCESS;
5862 /* Swith on or off the tx queues */
5864 i40e_dev_switch_tx_queues(struct i40e_pf *pf, bool on)
5866 struct rte_eth_dev_data *dev_data = pf->dev_data;
5867 struct i40e_tx_queue *txq;
5868 struct rte_eth_dev *dev = pf->adapter->eth_dev;
5872 for (i = 0; i < dev_data->nb_tx_queues; i++) {
5873 txq = dev_data->tx_queues[i];
5874 /* Don't operate the queue if not configured or
5875 * if starting only per queue */
5876 if (!txq || !txq->q_set || (on && txq->tx_deferred_start))
5879 ret = i40e_dev_tx_queue_start(dev, i);
5881 ret = i40e_dev_tx_queue_stop(dev, i);
5882 if ( ret != I40E_SUCCESS)
5886 return I40E_SUCCESS;
5890 i40e_switch_rx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
5895 /* Wait until the request is finished */
5896 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
5897 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
5898 reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
5899 if (!((reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 0x1) ^
5900 ((reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 0x1))
5905 if (reg & I40E_QRX_ENA_QENA_STAT_MASK)
5906 return I40E_SUCCESS; /* Already on, skip next steps */
5907 reg |= I40E_QRX_ENA_QENA_REQ_MASK;
5909 if (!(reg & I40E_QRX_ENA_QENA_STAT_MASK))
5910 return I40E_SUCCESS; /* Already off, skip next steps */
5911 reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
5914 /* Write the register */
5915 I40E_WRITE_REG(hw, I40E_QRX_ENA(q_idx), reg);
5916 /* Check the result */
5917 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
5918 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
5919 reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
5921 if ((reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
5922 (reg & I40E_QRX_ENA_QENA_STAT_MASK))
5925 if (!(reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
5926 !(reg & I40E_QRX_ENA_QENA_STAT_MASK))
5931 /* Check if it is timeout */
5932 if (j >= I40E_CHK_Q_ENA_COUNT) {
5933 PMD_DRV_LOG(ERR, "Failed to %s rx queue[%u]",
5934 (on ? "enable" : "disable"), q_idx);
5935 return I40E_ERR_TIMEOUT;
5938 return I40E_SUCCESS;
5940 /* Switch on or off the rx queues */
5942 i40e_dev_switch_rx_queues(struct i40e_pf *pf, bool on)
5944 struct rte_eth_dev_data *dev_data = pf->dev_data;
5945 struct i40e_rx_queue *rxq;
5946 struct rte_eth_dev *dev = pf->adapter->eth_dev;
5950 for (i = 0; i < dev_data->nb_rx_queues; i++) {
5951 rxq = dev_data->rx_queues[i];
5952 /* Don't operate the queue if not configured or
5953 * if starting only per queue */
5954 if (!rxq || !rxq->q_set || (on && rxq->rx_deferred_start))
5957 ret = i40e_dev_rx_queue_start(dev, i);
5959 ret = i40e_dev_rx_queue_stop(dev, i);
5960 if (ret != I40E_SUCCESS)
5964 return I40E_SUCCESS;
5967 /* Switch on or off all the rx/tx queues */
5969 i40e_dev_switch_queues(struct i40e_pf *pf, bool on)
5974 /* enable rx queues before enabling tx queues */
5975 ret = i40e_dev_switch_rx_queues(pf, on);
5977 PMD_DRV_LOG(ERR, "Failed to switch rx queues");
5980 ret = i40e_dev_switch_tx_queues(pf, on);
5982 /* Stop tx queues before stopping rx queues */
5983 ret = i40e_dev_switch_tx_queues(pf, on);
5985 PMD_DRV_LOG(ERR, "Failed to switch tx queues");
5988 ret = i40e_dev_switch_rx_queues(pf, on);
5994 /* Initialize VSI for TX */
5996 i40e_dev_tx_init(struct i40e_pf *pf)
5998 struct rte_eth_dev_data *data = pf->dev_data;
6000 uint32_t ret = I40E_SUCCESS;
6001 struct i40e_tx_queue *txq;
6003 for (i = 0; i < data->nb_tx_queues; i++) {
6004 txq = data->tx_queues[i];
6005 if (!txq || !txq->q_set)
6007 ret = i40e_tx_queue_init(txq);
6008 if (ret != I40E_SUCCESS)
6011 if (ret == I40E_SUCCESS)
6012 i40e_set_tx_function(container_of(pf, struct i40e_adapter, pf)
6018 /* Initialize VSI for RX */
6020 i40e_dev_rx_init(struct i40e_pf *pf)
6022 struct rte_eth_dev_data *data = pf->dev_data;
6023 int ret = I40E_SUCCESS;
6025 struct i40e_rx_queue *rxq;
6027 i40e_pf_config_mq_rx(pf);
6028 for (i = 0; i < data->nb_rx_queues; i++) {
6029 rxq = data->rx_queues[i];
6030 if (!rxq || !rxq->q_set)
6033 ret = i40e_rx_queue_init(rxq);
6034 if (ret != I40E_SUCCESS) {
6036 "Failed to do RX queue initialization");
6040 if (ret == I40E_SUCCESS)
6041 i40e_set_rx_function(container_of(pf, struct i40e_adapter, pf)
6048 i40e_dev_rxtx_init(struct i40e_pf *pf)
6052 err = i40e_dev_tx_init(pf);
6054 PMD_DRV_LOG(ERR, "Failed to do TX initialization");
6057 err = i40e_dev_rx_init(pf);
6059 PMD_DRV_LOG(ERR, "Failed to do RX initialization");
6067 i40e_vmdq_setup(struct rte_eth_dev *dev)
6069 struct rte_eth_conf *conf = &dev->data->dev_conf;
6070 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6071 int i, err, conf_vsis, j, loop;
6072 struct i40e_vsi *vsi;
6073 struct i40e_vmdq_info *vmdq_info;
6074 struct rte_eth_vmdq_rx_conf *vmdq_conf;
6075 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6078 * Disable interrupt to avoid message from VF. Furthermore, it will
6079 * avoid race condition in VSI creation/destroy.
6081 i40e_pf_disable_irq0(hw);
6083 if ((pf->flags & I40E_FLAG_VMDQ) == 0) {
6084 PMD_INIT_LOG(ERR, "FW doesn't support VMDQ");
6088 conf_vsis = conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools;
6089 if (conf_vsis > pf->max_nb_vmdq_vsi) {
6090 PMD_INIT_LOG(ERR, "VMDQ config: %u, max support:%u",
6091 conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools,
6092 pf->max_nb_vmdq_vsi);
6096 if (pf->vmdq != NULL) {
6097 PMD_INIT_LOG(INFO, "VMDQ already configured");
6101 pf->vmdq = rte_zmalloc("vmdq_info_struct",
6102 sizeof(*vmdq_info) * conf_vsis, 0);
6104 if (pf->vmdq == NULL) {
6105 PMD_INIT_LOG(ERR, "Failed to allocate memory");
6109 vmdq_conf = &conf->rx_adv_conf.vmdq_rx_conf;
6111 /* Create VMDQ VSI */
6112 for (i = 0; i < conf_vsis; i++) {
6113 vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, pf->main_vsi,
6114 vmdq_conf->enable_loop_back);
6116 PMD_INIT_LOG(ERR, "Failed to create VMDQ VSI");
6120 vmdq_info = &pf->vmdq[i];
6122 vmdq_info->vsi = vsi;
6124 pf->nb_cfg_vmdq_vsi = conf_vsis;
6126 /* Configure Vlan */
6127 loop = sizeof(vmdq_conf->pool_map[0].pools) * CHAR_BIT;
6128 for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
6129 for (j = 0; j < loop && j < pf->nb_cfg_vmdq_vsi; j++) {
6130 if (vmdq_conf->pool_map[i].pools & (1UL << j)) {
6131 PMD_INIT_LOG(INFO, "Add vlan %u to vmdq pool %u",
6132 vmdq_conf->pool_map[i].vlan_id, j);
6134 err = i40e_vsi_add_vlan(pf->vmdq[j].vsi,
6135 vmdq_conf->pool_map[i].vlan_id);
6137 PMD_INIT_LOG(ERR, "Failed to add vlan");
6145 i40e_pf_enable_irq0(hw);
6150 for (i = 0; i < conf_vsis; i++)
6151 if (pf->vmdq[i].vsi == NULL)
6154 i40e_vsi_release(pf->vmdq[i].vsi);
6158 i40e_pf_enable_irq0(hw);
6163 i40e_stat_update_32(struct i40e_hw *hw,
6171 new_data = (uint64_t)I40E_READ_REG(hw, reg);
6175 if (new_data >= *offset)
6176 *stat = (uint64_t)(new_data - *offset);
6178 *stat = (uint64_t)((new_data +
6179 ((uint64_t)1 << I40E_32_BIT_WIDTH)) - *offset);
6183 i40e_stat_update_48(struct i40e_hw *hw,
6192 new_data = (uint64_t)I40E_READ_REG(hw, loreg);
6193 new_data |= ((uint64_t)(I40E_READ_REG(hw, hireg) &
6194 I40E_16_BIT_MASK)) << I40E_32_BIT_WIDTH;
6199 if (new_data >= *offset)
6200 *stat = new_data - *offset;
6202 *stat = (uint64_t)((new_data +
6203 ((uint64_t)1 << I40E_48_BIT_WIDTH)) - *offset);
6205 *stat &= I40E_48_BIT_MASK;
6210 i40e_pf_disable_irq0(struct i40e_hw *hw)
6212 /* Disable all interrupt types */
6213 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
6214 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
6215 I40E_WRITE_FLUSH(hw);
6220 i40e_pf_enable_irq0(struct i40e_hw *hw)
6222 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
6223 I40E_PFINT_DYN_CTL0_INTENA_MASK |
6224 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
6225 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
6226 I40E_WRITE_FLUSH(hw);
6230 i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue)
6232 /* read pending request and disable first */
6233 i40e_pf_disable_irq0(hw);
6234 I40E_WRITE_REG(hw, I40E_PFINT_ICR0_ENA, I40E_PFINT_ICR0_ENA_MASK);
6235 I40E_WRITE_REG(hw, I40E_PFINT_STAT_CTL0,
6236 I40E_PFINT_STAT_CTL0_OTHER_ITR_INDX_MASK);
6239 /* Link no queues with irq0 */
6240 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
6241 I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
6245 i40e_dev_handle_vfr_event(struct rte_eth_dev *dev)
6247 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6248 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6251 uint32_t index, offset, val;
6256 * Try to find which VF trigger a reset, use absolute VF id to access
6257 * since the reg is global register.
6259 for (i = 0; i < pf->vf_num; i++) {
6260 abs_vf_id = hw->func_caps.vf_base_id + i;
6261 index = abs_vf_id / I40E_UINT32_BIT_SIZE;
6262 offset = abs_vf_id % I40E_UINT32_BIT_SIZE;
6263 val = I40E_READ_REG(hw, I40E_GLGEN_VFLRSTAT(index));
6264 /* VFR event occurred */
6265 if (val & (0x1 << offset)) {
6268 /* Clear the event first */
6269 I40E_WRITE_REG(hw, I40E_GLGEN_VFLRSTAT(index),
6271 PMD_DRV_LOG(INFO, "VF %u reset occurred", abs_vf_id);
6273 * Only notify a VF reset event occurred,
6274 * don't trigger another SW reset
6276 ret = i40e_pf_host_vf_reset(&pf->vfs[i], 0);
6277 if (ret != I40E_SUCCESS)
6278 PMD_DRV_LOG(ERR, "Failed to do VF reset");
6284 i40e_notify_all_vfs_link_status(struct rte_eth_dev *dev)
6286 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6289 for (i = 0; i < pf->vf_num; i++)
6290 i40e_notify_vf_link_status(dev, &pf->vfs[i]);
6294 i40e_dev_handle_aq_msg(struct rte_eth_dev *dev)
6296 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6297 struct i40e_arq_event_info info;
6298 uint16_t pending, opcode;
6301 info.buf_len = I40E_AQ_BUF_SZ;
6302 info.msg_buf = rte_zmalloc("msg_buffer", info.buf_len, 0);
6303 if (!info.msg_buf) {
6304 PMD_DRV_LOG(ERR, "Failed to allocate mem");
6310 ret = i40e_clean_arq_element(hw, &info, &pending);
6312 if (ret != I40E_SUCCESS) {
6314 "Failed to read msg from AdminQ, aq_err: %u",
6315 hw->aq.asq_last_status);
6318 opcode = rte_le_to_cpu_16(info.desc.opcode);
6321 case i40e_aqc_opc_send_msg_to_pf:
6322 /* Refer to i40e_aq_send_msg_to_pf() for argument layout*/
6323 i40e_pf_host_handle_vf_msg(dev,
6324 rte_le_to_cpu_16(info.desc.retval),
6325 rte_le_to_cpu_32(info.desc.cookie_high),
6326 rte_le_to_cpu_32(info.desc.cookie_low),
6330 case i40e_aqc_opc_get_link_status:
6331 ret = i40e_dev_link_update(dev, 0);
6333 _rte_eth_dev_callback_process(dev,
6334 RTE_ETH_EVENT_INTR_LSC, NULL);
6337 PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
6342 rte_free(info.msg_buf);
6346 * Interrupt handler triggered by NIC for handling
6347 * specific interrupt.
6350 * Pointer to interrupt handle.
6352 * The address of parameter (struct rte_eth_dev *) regsitered before.
6358 i40e_dev_interrupt_handler(void *param)
6360 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
6361 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6364 /* Disable interrupt */
6365 i40e_pf_disable_irq0(hw);
6367 /* read out interrupt causes */
6368 icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
6370 /* No interrupt event indicated */
6371 if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK)) {
6372 PMD_DRV_LOG(INFO, "No interrupt event");
6375 if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
6376 PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
6377 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK)
6378 PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
6379 if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
6380 PMD_DRV_LOG(INFO, "ICR0: global reset requested");
6381 if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
6382 PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
6383 if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
6384 PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
6385 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
6386 PMD_DRV_LOG(ERR, "ICR0: HMC error");
6387 if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
6388 PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
6390 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
6391 PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
6392 i40e_dev_handle_vfr_event(dev);
6394 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
6395 PMD_DRV_LOG(INFO, "ICR0: adminq event");
6396 i40e_dev_handle_aq_msg(dev);
6400 /* Enable interrupt */
6401 i40e_pf_enable_irq0(hw);
6402 rte_intr_enable(dev->intr_handle);
6406 i40e_add_macvlan_filters(struct i40e_vsi *vsi,
6407 struct i40e_macvlan_filter *filter,
6410 int ele_num, ele_buff_size;
6411 int num, actual_num, i;
6413 int ret = I40E_SUCCESS;
6414 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6415 struct i40e_aqc_add_macvlan_element_data *req_list;
6417 if (filter == NULL || total == 0)
6418 return I40E_ERR_PARAM;
6419 ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
6420 ele_buff_size = hw->aq.asq_buf_size;
6422 req_list = rte_zmalloc("macvlan_add", ele_buff_size, 0);
6423 if (req_list == NULL) {
6424 PMD_DRV_LOG(ERR, "Fail to allocate memory");
6425 return I40E_ERR_NO_MEMORY;
6430 actual_num = (num + ele_num > total) ? (total - num) : ele_num;
6431 memset(req_list, 0, ele_buff_size);
6433 for (i = 0; i < actual_num; i++) {
6434 rte_memcpy(req_list[i].mac_addr,
6435 &filter[num + i].macaddr, ETH_ADDR_LEN);
6436 req_list[i].vlan_tag =
6437 rte_cpu_to_le_16(filter[num + i].vlan_id);
6439 switch (filter[num + i].filter_type) {
6440 case RTE_MAC_PERFECT_MATCH:
6441 flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH |
6442 I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
6444 case RTE_MACVLAN_PERFECT_MATCH:
6445 flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
6447 case RTE_MAC_HASH_MATCH:
6448 flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH |
6449 I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
6451 case RTE_MACVLAN_HASH_MATCH:
6452 flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH;
6455 PMD_DRV_LOG(ERR, "Invalid MAC match type");
6456 ret = I40E_ERR_PARAM;
6460 req_list[i].queue_number = 0;
6462 req_list[i].flags = rte_cpu_to_le_16(flags);
6465 ret = i40e_aq_add_macvlan(hw, vsi->seid, req_list,
6467 if (ret != I40E_SUCCESS) {
6468 PMD_DRV_LOG(ERR, "Failed to add macvlan filter");
6472 } while (num < total);
6480 i40e_remove_macvlan_filters(struct i40e_vsi *vsi,
6481 struct i40e_macvlan_filter *filter,
6484 int ele_num, ele_buff_size;
6485 int num, actual_num, i;
6487 int ret = I40E_SUCCESS;
6488 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6489 struct i40e_aqc_remove_macvlan_element_data *req_list;
6491 if (filter == NULL || total == 0)
6492 return I40E_ERR_PARAM;
6494 ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
6495 ele_buff_size = hw->aq.asq_buf_size;
6497 req_list = rte_zmalloc("macvlan_remove", ele_buff_size, 0);
6498 if (req_list == NULL) {
6499 PMD_DRV_LOG(ERR, "Fail to allocate memory");
6500 return I40E_ERR_NO_MEMORY;
6505 actual_num = (num + ele_num > total) ? (total - num) : ele_num;
6506 memset(req_list, 0, ele_buff_size);
6508 for (i = 0; i < actual_num; i++) {
6509 rte_memcpy(req_list[i].mac_addr,
6510 &filter[num + i].macaddr, ETH_ADDR_LEN);
6511 req_list[i].vlan_tag =
6512 rte_cpu_to_le_16(filter[num + i].vlan_id);
6514 switch (filter[num + i].filter_type) {
6515 case RTE_MAC_PERFECT_MATCH:
6516 flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
6517 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
6519 case RTE_MACVLAN_PERFECT_MATCH:
6520 flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
6522 case RTE_MAC_HASH_MATCH:
6523 flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH |
6524 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
6526 case RTE_MACVLAN_HASH_MATCH:
6527 flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH;
6530 PMD_DRV_LOG(ERR, "Invalid MAC filter type");
6531 ret = I40E_ERR_PARAM;
6534 req_list[i].flags = rte_cpu_to_le_16(flags);
6537 ret = i40e_aq_remove_macvlan(hw, vsi->seid, req_list,
6539 if (ret != I40E_SUCCESS) {
6540 PMD_DRV_LOG(ERR, "Failed to remove macvlan filter");
6544 } while (num < total);
6551 /* Find out specific MAC filter */
6552 static struct i40e_mac_filter *
6553 i40e_find_mac_filter(struct i40e_vsi *vsi,
6554 struct ether_addr *macaddr)
6556 struct i40e_mac_filter *f;
6558 TAILQ_FOREACH(f, &vsi->mac_list, next) {
6559 if (is_same_ether_addr(macaddr, &f->mac_info.mac_addr))
6567 i40e_find_vlan_filter(struct i40e_vsi *vsi,
6570 uint32_t vid_idx, vid_bit;
6572 if (vlan_id > ETH_VLAN_ID_MAX)
6575 vid_idx = I40E_VFTA_IDX(vlan_id);
6576 vid_bit = I40E_VFTA_BIT(vlan_id);
6578 if (vsi->vfta[vid_idx] & vid_bit)
6585 i40e_store_vlan_filter(struct i40e_vsi *vsi,
6586 uint16_t vlan_id, bool on)
6588 uint32_t vid_idx, vid_bit;
6590 vid_idx = I40E_VFTA_IDX(vlan_id);
6591 vid_bit = I40E_VFTA_BIT(vlan_id);
6594 vsi->vfta[vid_idx] |= vid_bit;
6596 vsi->vfta[vid_idx] &= ~vid_bit;
6600 i40e_set_vlan_filter(struct i40e_vsi *vsi,
6601 uint16_t vlan_id, bool on)
6603 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6604 struct i40e_aqc_add_remove_vlan_element_data vlan_data = {0};
6607 if (vlan_id > ETH_VLAN_ID_MAX)
6610 i40e_store_vlan_filter(vsi, vlan_id, on);
6612 if ((!vsi->vlan_anti_spoof_on && !vsi->vlan_filter_on) || !vlan_id)
6615 vlan_data.vlan_tag = rte_cpu_to_le_16(vlan_id);
6618 ret = i40e_aq_add_vlan(hw, vsi->seid,
6619 &vlan_data, 1, NULL);
6620 if (ret != I40E_SUCCESS)
6621 PMD_DRV_LOG(ERR, "Failed to add vlan filter");
6623 ret = i40e_aq_remove_vlan(hw, vsi->seid,
6624 &vlan_data, 1, NULL);
6625 if (ret != I40E_SUCCESS)
6627 "Failed to remove vlan filter");
6632 * Find all vlan options for specific mac addr,
6633 * return with actual vlan found.
6636 i40e_find_all_vlan_for_mac(struct i40e_vsi *vsi,
6637 struct i40e_macvlan_filter *mv_f,
6638 int num, struct ether_addr *addr)
6644 * Not to use i40e_find_vlan_filter to decrease the loop time,
6645 * although the code looks complex.
6647 if (num < vsi->vlan_num)
6648 return I40E_ERR_PARAM;
6651 for (j = 0; j < I40E_VFTA_SIZE; j++) {
6653 for (k = 0; k < I40E_UINT32_BIT_SIZE; k++) {
6654 if (vsi->vfta[j] & (1 << k)) {
6657 "vlan number doesn't match");
6658 return I40E_ERR_PARAM;
6660 rte_memcpy(&mv_f[i].macaddr,
6661 addr, ETH_ADDR_LEN);
6663 j * I40E_UINT32_BIT_SIZE + k;
6669 return I40E_SUCCESS;
6673 i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
6674 struct i40e_macvlan_filter *mv_f,
6679 struct i40e_mac_filter *f;
6681 if (num < vsi->mac_num)
6682 return I40E_ERR_PARAM;
6684 TAILQ_FOREACH(f, &vsi->mac_list, next) {
6686 PMD_DRV_LOG(ERR, "buffer number not match");
6687 return I40E_ERR_PARAM;
6689 rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
6691 mv_f[i].vlan_id = vlan;
6692 mv_f[i].filter_type = f->mac_info.filter_type;
6696 return I40E_SUCCESS;
6700 i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi)
6703 struct i40e_mac_filter *f;
6704 struct i40e_macvlan_filter *mv_f;
6705 int ret = I40E_SUCCESS;
6707 if (vsi == NULL || vsi->mac_num == 0)
6708 return I40E_ERR_PARAM;
6710 /* Case that no vlan is set */
6711 if (vsi->vlan_num == 0)
6714 num = vsi->mac_num * vsi->vlan_num;
6716 mv_f = rte_zmalloc("macvlan_data", num * sizeof(*mv_f), 0);
6718 PMD_DRV_LOG(ERR, "failed to allocate memory");
6719 return I40E_ERR_NO_MEMORY;
6723 if (vsi->vlan_num == 0) {
6724 TAILQ_FOREACH(f, &vsi->mac_list, next) {
6725 rte_memcpy(&mv_f[i].macaddr,
6726 &f->mac_info.mac_addr, ETH_ADDR_LEN);
6727 mv_f[i].filter_type = f->mac_info.filter_type;
6728 mv_f[i].vlan_id = 0;
6732 TAILQ_FOREACH(f, &vsi->mac_list, next) {
6733 ret = i40e_find_all_vlan_for_mac(vsi,&mv_f[i],
6734 vsi->vlan_num, &f->mac_info.mac_addr);
6735 if (ret != I40E_SUCCESS)
6737 for (j = i; j < i + vsi->vlan_num; j++)
6738 mv_f[j].filter_type = f->mac_info.filter_type;
6743 ret = i40e_remove_macvlan_filters(vsi, mv_f, num);
6751 i40e_vsi_add_vlan(struct i40e_vsi *vsi, uint16_t vlan)
6753 struct i40e_macvlan_filter *mv_f;
6755 int ret = I40E_SUCCESS;
6757 if (!vsi || vlan > ETHER_MAX_VLAN_ID)
6758 return I40E_ERR_PARAM;
6760 /* If it's already set, just return */
6761 if (i40e_find_vlan_filter(vsi,vlan))
6762 return I40E_SUCCESS;
6764 mac_num = vsi->mac_num;
6767 PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
6768 return I40E_ERR_PARAM;
6771 mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
6774 PMD_DRV_LOG(ERR, "failed to allocate memory");
6775 return I40E_ERR_NO_MEMORY;
6778 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
6780 if (ret != I40E_SUCCESS)
6783 ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
6785 if (ret != I40E_SUCCESS)
6788 i40e_set_vlan_filter(vsi, vlan, 1);
6798 i40e_vsi_delete_vlan(struct i40e_vsi *vsi, uint16_t vlan)
6800 struct i40e_macvlan_filter *mv_f;
6802 int ret = I40E_SUCCESS;
6805 * Vlan 0 is the generic filter for untagged packets
6806 * and can't be removed.
6808 if (!vsi || vlan == 0 || vlan > ETHER_MAX_VLAN_ID)
6809 return I40E_ERR_PARAM;
6811 /* If can't find it, just return */
6812 if (!i40e_find_vlan_filter(vsi, vlan))
6813 return I40E_ERR_PARAM;
6815 mac_num = vsi->mac_num;
6818 PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
6819 return I40E_ERR_PARAM;
6822 mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
6825 PMD_DRV_LOG(ERR, "failed to allocate memory");
6826 return I40E_ERR_NO_MEMORY;
6829 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
6831 if (ret != I40E_SUCCESS)
6834 ret = i40e_remove_macvlan_filters(vsi, mv_f, mac_num);
6836 if (ret != I40E_SUCCESS)
6839 /* This is last vlan to remove, replace all mac filter with vlan 0 */
6840 if (vsi->vlan_num == 1) {
6841 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, 0);
6842 if (ret != I40E_SUCCESS)
6845 ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
6846 if (ret != I40E_SUCCESS)
6850 i40e_set_vlan_filter(vsi, vlan, 0);
6860 i40e_vsi_add_mac(struct i40e_vsi *vsi, struct i40e_mac_filter_info *mac_filter)
6862 struct i40e_mac_filter *f;
6863 struct i40e_macvlan_filter *mv_f;
6864 int i, vlan_num = 0;
6865 int ret = I40E_SUCCESS;
6867 /* If it's add and we've config it, return */
6868 f = i40e_find_mac_filter(vsi, &mac_filter->mac_addr);
6870 return I40E_SUCCESS;
6871 if ((mac_filter->filter_type == RTE_MACVLAN_PERFECT_MATCH) ||
6872 (mac_filter->filter_type == RTE_MACVLAN_HASH_MATCH)) {
6875 * If vlan_num is 0, that's the first time to add mac,
6876 * set mask for vlan_id 0.
6878 if (vsi->vlan_num == 0) {
6879 i40e_set_vlan_filter(vsi, 0, 1);
6882 vlan_num = vsi->vlan_num;
6883 } else if ((mac_filter->filter_type == RTE_MAC_PERFECT_MATCH) ||
6884 (mac_filter->filter_type == RTE_MAC_HASH_MATCH))
6887 mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
6889 PMD_DRV_LOG(ERR, "failed to allocate memory");
6890 return I40E_ERR_NO_MEMORY;
6893 for (i = 0; i < vlan_num; i++) {
6894 mv_f[i].filter_type = mac_filter->filter_type;
6895 rte_memcpy(&mv_f[i].macaddr, &mac_filter->mac_addr,
6899 if (mac_filter->filter_type == RTE_MACVLAN_PERFECT_MATCH ||
6900 mac_filter->filter_type == RTE_MACVLAN_HASH_MATCH) {
6901 ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
6902 &mac_filter->mac_addr);
6903 if (ret != I40E_SUCCESS)
6907 ret = i40e_add_macvlan_filters(vsi, mv_f, vlan_num);
6908 if (ret != I40E_SUCCESS)
6911 /* Add the mac addr into mac list */
6912 f = rte_zmalloc("macv_filter", sizeof(*f), 0);
6914 PMD_DRV_LOG(ERR, "failed to allocate memory");
6915 ret = I40E_ERR_NO_MEMORY;
6918 rte_memcpy(&f->mac_info.mac_addr, &mac_filter->mac_addr,
6920 f->mac_info.filter_type = mac_filter->filter_type;
6921 TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
6932 i40e_vsi_delete_mac(struct i40e_vsi *vsi, struct ether_addr *addr)
6934 struct i40e_mac_filter *f;
6935 struct i40e_macvlan_filter *mv_f;
6937 enum rte_mac_filter_type filter_type;
6938 int ret = I40E_SUCCESS;
6940 /* Can't find it, return an error */
6941 f = i40e_find_mac_filter(vsi, addr);
6943 return I40E_ERR_PARAM;
6945 vlan_num = vsi->vlan_num;
6946 filter_type = f->mac_info.filter_type;
6947 if (filter_type == RTE_MACVLAN_PERFECT_MATCH ||
6948 filter_type == RTE_MACVLAN_HASH_MATCH) {
6949 if (vlan_num == 0) {
6950 PMD_DRV_LOG(ERR, "VLAN number shouldn't be 0");
6951 return I40E_ERR_PARAM;
6953 } else if (filter_type == RTE_MAC_PERFECT_MATCH ||
6954 filter_type == RTE_MAC_HASH_MATCH)
6957 mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
6959 PMD_DRV_LOG(ERR, "failed to allocate memory");
6960 return I40E_ERR_NO_MEMORY;
6963 for (i = 0; i < vlan_num; i++) {
6964 mv_f[i].filter_type = filter_type;
6965 rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
6968 if (filter_type == RTE_MACVLAN_PERFECT_MATCH ||
6969 filter_type == RTE_MACVLAN_HASH_MATCH) {
6970 ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num, addr);
6971 if (ret != I40E_SUCCESS)
6975 ret = i40e_remove_macvlan_filters(vsi, mv_f, vlan_num);
6976 if (ret != I40E_SUCCESS)
6979 /* Remove the mac addr into mac list */
6980 TAILQ_REMOVE(&vsi->mac_list, f, next);
6990 /* Configure hash enable flags for RSS */
6992 i40e_config_hena(const struct i40e_adapter *adapter, uint64_t flags)
7000 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < I40E_FLOW_TYPE_MAX; i++) {
7001 if (flags & (1ULL << i))
7002 hena |= adapter->pctypes_tbl[i];
7008 /* Parse the hash enable flags */
7010 i40e_parse_hena(const struct i40e_adapter *adapter, uint64_t flags)
7012 uint64_t rss_hf = 0;
7018 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < I40E_FLOW_TYPE_MAX; i++) {
7019 if (flags & adapter->pctypes_tbl[i])
7020 rss_hf |= (1ULL << i);
7027 i40e_pf_disable_rss(struct i40e_pf *pf)
7029 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7031 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
7032 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
7033 I40E_WRITE_FLUSH(hw);
7037 i40e_set_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t key_len)
7039 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
7040 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7041 uint16_t key_idx = (vsi->type == I40E_VSI_SRIOV) ?
7042 I40E_VFQF_HKEY_MAX_INDEX :
7043 I40E_PFQF_HKEY_MAX_INDEX;
7046 if (!key || key_len == 0) {
7047 PMD_DRV_LOG(DEBUG, "No key to be configured");
7049 } else if (key_len != (key_idx + 1) *
7051 PMD_DRV_LOG(ERR, "Invalid key length %u", key_len);
7055 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
7056 struct i40e_aqc_get_set_rss_key_data *key_dw =
7057 (struct i40e_aqc_get_set_rss_key_data *)key;
7059 ret = i40e_aq_set_rss_key(hw, vsi->vsi_id, key_dw);
7061 PMD_INIT_LOG(ERR, "Failed to configure RSS key via AQ");
7063 uint32_t *hash_key = (uint32_t *)key;
7066 if (vsi->type == I40E_VSI_SRIOV) {
7067 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
7070 I40E_VFQF_HKEY1(i, vsi->user_param),
7074 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
7075 I40E_WRITE_REG(hw, I40E_PFQF_HKEY(i),
7078 I40E_WRITE_FLUSH(hw);
7085 i40e_get_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t *key_len)
7087 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
7088 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7092 if (!key || !key_len)
7095 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
7096 ret = i40e_aq_get_rss_key(hw, vsi->vsi_id,
7097 (struct i40e_aqc_get_set_rss_key_data *)key);
7099 PMD_INIT_LOG(ERR, "Failed to get RSS key via AQ");
7103 uint32_t *key_dw = (uint32_t *)key;
7106 if (vsi->type == I40E_VSI_SRIOV) {
7107 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++) {
7108 reg = I40E_VFQF_HKEY1(i, vsi->user_param);
7109 key_dw[i] = i40e_read_rx_ctl(hw, reg);
7111 *key_len = (I40E_VFQF_HKEY_MAX_INDEX + 1) *
7114 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
7115 reg = I40E_PFQF_HKEY(i);
7116 key_dw[i] = i40e_read_rx_ctl(hw, reg);
7118 *key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
7126 i40e_hw_rss_hash_set(struct i40e_pf *pf, struct rte_eth_rss_conf *rss_conf)
7128 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7132 ret = i40e_set_rss_key(pf->main_vsi, rss_conf->rss_key,
7133 rss_conf->rss_key_len);
7137 hena = i40e_config_hena(pf->adapter, rss_conf->rss_hf);
7138 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
7139 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
7140 I40E_WRITE_FLUSH(hw);
7146 i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
7147 struct rte_eth_rss_conf *rss_conf)
7149 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7150 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7151 uint64_t rss_hf = rss_conf->rss_hf & pf->adapter->flow_types_mask;
7154 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
7155 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
7157 if (!(hena & pf->adapter->pctypes_mask)) { /* RSS disabled */
7158 if (rss_hf != 0) /* Enable RSS */
7160 return 0; /* Nothing to do */
7163 if (rss_hf == 0) /* Disable RSS */
7166 return i40e_hw_rss_hash_set(pf, rss_conf);
7170 i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
7171 struct rte_eth_rss_conf *rss_conf)
7173 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7174 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7177 i40e_get_rss_key(pf->main_vsi, rss_conf->rss_key,
7178 &rss_conf->rss_key_len);
7180 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
7181 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
7182 rss_conf->rss_hf = i40e_parse_hena(pf->adapter, hena);
7188 i40e_dev_get_filter_type(uint16_t filter_type, uint16_t *flag)
7190 switch (filter_type) {
7191 case RTE_TUNNEL_FILTER_IMAC_IVLAN:
7192 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
7194 case RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID:
7195 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
7197 case RTE_TUNNEL_FILTER_IMAC_TENID:
7198 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID;
7200 case RTE_TUNNEL_FILTER_OMAC_TENID_IMAC:
7201 *flag = I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC;
7203 case ETH_TUNNEL_FILTER_IMAC:
7204 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
7206 case ETH_TUNNEL_FILTER_OIP:
7207 *flag = I40E_AQC_ADD_CLOUD_FILTER_OIP;
7209 case ETH_TUNNEL_FILTER_IIP:
7210 *flag = I40E_AQC_ADD_CLOUD_FILTER_IIP;
7213 PMD_DRV_LOG(ERR, "invalid tunnel filter type");
7220 /* Convert tunnel filter structure */
7222 i40e_tunnel_filter_convert(
7223 struct i40e_aqc_add_rm_cloud_filt_elem_ext *cld_filter,
7224 struct i40e_tunnel_filter *tunnel_filter)
7226 ether_addr_copy((struct ether_addr *)&cld_filter->element.outer_mac,
7227 (struct ether_addr *)&tunnel_filter->input.outer_mac);
7228 ether_addr_copy((struct ether_addr *)&cld_filter->element.inner_mac,
7229 (struct ether_addr *)&tunnel_filter->input.inner_mac);
7230 tunnel_filter->input.inner_vlan = cld_filter->element.inner_vlan;
7231 if ((rte_le_to_cpu_16(cld_filter->element.flags) &
7232 I40E_AQC_ADD_CLOUD_FLAGS_IPV6) ==
7233 I40E_AQC_ADD_CLOUD_FLAGS_IPV6)
7234 tunnel_filter->input.ip_type = I40E_TUNNEL_IPTYPE_IPV6;
7236 tunnel_filter->input.ip_type = I40E_TUNNEL_IPTYPE_IPV4;
7237 tunnel_filter->input.flags = cld_filter->element.flags;
7238 tunnel_filter->input.tenant_id = cld_filter->element.tenant_id;
7239 tunnel_filter->queue = cld_filter->element.queue_number;
7240 rte_memcpy(tunnel_filter->input.general_fields,
7241 cld_filter->general_fields,
7242 sizeof(cld_filter->general_fields));
7247 /* Check if there exists the tunnel filter */
7248 struct i40e_tunnel_filter *
7249 i40e_sw_tunnel_filter_lookup(struct i40e_tunnel_rule *tunnel_rule,
7250 const struct i40e_tunnel_filter_input *input)
7254 ret = rte_hash_lookup(tunnel_rule->hash_table, (const void *)input);
7258 return tunnel_rule->hash_map[ret];
7261 /* Add a tunnel filter into the SW list */
7263 i40e_sw_tunnel_filter_insert(struct i40e_pf *pf,
7264 struct i40e_tunnel_filter *tunnel_filter)
7266 struct i40e_tunnel_rule *rule = &pf->tunnel;
7269 ret = rte_hash_add_key(rule->hash_table, &tunnel_filter->input);
7272 "Failed to insert tunnel filter to hash table %d!",
7276 rule->hash_map[ret] = tunnel_filter;
7278 TAILQ_INSERT_TAIL(&rule->tunnel_list, tunnel_filter, rules);
7283 /* Delete a tunnel filter from the SW list */
7285 i40e_sw_tunnel_filter_del(struct i40e_pf *pf,
7286 struct i40e_tunnel_filter_input *input)
7288 struct i40e_tunnel_rule *rule = &pf->tunnel;
7289 struct i40e_tunnel_filter *tunnel_filter;
7292 ret = rte_hash_del_key(rule->hash_table, input);
7295 "Failed to delete tunnel filter to hash table %d!",
7299 tunnel_filter = rule->hash_map[ret];
7300 rule->hash_map[ret] = NULL;
7302 TAILQ_REMOVE(&rule->tunnel_list, tunnel_filter, rules);
7303 rte_free(tunnel_filter);
7309 i40e_dev_tunnel_filter_set(struct i40e_pf *pf,
7310 struct rte_eth_tunnel_filter_conf *tunnel_filter,
7314 uint32_t ipv4_addr, ipv4_addr_le;
7315 uint8_t i, tun_type = 0;
7316 /* internal varialbe to convert ipv6 byte order */
7317 uint32_t convert_ipv6[4];
7319 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7320 struct i40e_vsi *vsi = pf->main_vsi;
7321 struct i40e_aqc_add_rm_cloud_filt_elem_ext *cld_filter;
7322 struct i40e_aqc_add_rm_cloud_filt_elem_ext *pfilter;
7323 struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
7324 struct i40e_tunnel_filter *tunnel, *node;
7325 struct i40e_tunnel_filter check_filter; /* Check if filter exists */
7327 cld_filter = rte_zmalloc("tunnel_filter",
7328 sizeof(struct i40e_aqc_add_rm_cloud_filt_elem_ext),
7331 if (NULL == cld_filter) {
7332 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
7335 pfilter = cld_filter;
7337 ether_addr_copy(&tunnel_filter->outer_mac,
7338 (struct ether_addr *)&pfilter->element.outer_mac);
7339 ether_addr_copy(&tunnel_filter->inner_mac,
7340 (struct ether_addr *)&pfilter->element.inner_mac);
7342 pfilter->element.inner_vlan =
7343 rte_cpu_to_le_16(tunnel_filter->inner_vlan);
7344 if (tunnel_filter->ip_type == RTE_TUNNEL_IPTYPE_IPV4) {
7345 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV4;
7346 ipv4_addr = rte_be_to_cpu_32(tunnel_filter->ip_addr.ipv4_addr);
7347 ipv4_addr_le = rte_cpu_to_le_32(ipv4_addr);
7348 rte_memcpy(&pfilter->element.ipaddr.v4.data,
7350 sizeof(pfilter->element.ipaddr.v4.data));
7352 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV6;
7353 for (i = 0; i < 4; i++) {
7355 rte_cpu_to_le_32(rte_be_to_cpu_32(tunnel_filter->ip_addr.ipv6_addr[i]));
7357 rte_memcpy(&pfilter->element.ipaddr.v6.data,
7359 sizeof(pfilter->element.ipaddr.v6.data));
7362 /* check tunneled type */
7363 switch (tunnel_filter->tunnel_type) {
7364 case RTE_TUNNEL_TYPE_VXLAN:
7365 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_VXLAN;
7367 case RTE_TUNNEL_TYPE_NVGRE:
7368 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_NVGRE_OMAC;
7370 case RTE_TUNNEL_TYPE_IP_IN_GRE:
7371 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_IP;
7374 /* Other tunnel types is not supported. */
7375 PMD_DRV_LOG(ERR, "tunnel type is not supported.");
7376 rte_free(cld_filter);
7380 val = i40e_dev_get_filter_type(tunnel_filter->filter_type,
7381 &pfilter->element.flags);
7383 rte_free(cld_filter);
7387 pfilter->element.flags |= rte_cpu_to_le_16(
7388 I40E_AQC_ADD_CLOUD_FLAGS_TO_QUEUE |
7389 ip_type | (tun_type << I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT));
7390 pfilter->element.tenant_id = rte_cpu_to_le_32(tunnel_filter->tenant_id);
7391 pfilter->element.queue_number =
7392 rte_cpu_to_le_16(tunnel_filter->queue_id);
7394 /* Check if there is the filter in SW list */
7395 memset(&check_filter, 0, sizeof(check_filter));
7396 i40e_tunnel_filter_convert(cld_filter, &check_filter);
7397 node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
7399 PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
7400 rte_free(cld_filter);
7404 if (!add && !node) {
7405 PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
7406 rte_free(cld_filter);
7411 ret = i40e_aq_add_cloud_filters(hw,
7412 vsi->seid, &cld_filter->element, 1);
7414 PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
7415 rte_free(cld_filter);
7418 tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
7419 if (tunnel == NULL) {
7420 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
7421 rte_free(cld_filter);
7425 rte_memcpy(tunnel, &check_filter, sizeof(check_filter));
7426 ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
7430 ret = i40e_aq_remove_cloud_filters(hw, vsi->seid,
7431 &cld_filter->element, 1);
7433 PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
7434 rte_free(cld_filter);
7437 ret = i40e_sw_tunnel_filter_del(pf, &node->input);
7440 rte_free(cld_filter);
7444 #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_TR_WORD0 0x48
7445 #define I40E_TR_VXLAN_GRE_KEY_MASK 0x4
7446 #define I40E_TR_GENEVE_KEY_MASK 0x8
7447 #define I40E_TR_GENERIC_UDP_TUNNEL_MASK 0x40
7448 #define I40E_TR_GRE_KEY_MASK 0x400
7449 #define I40E_TR_GRE_KEY_WITH_XSUM_MASK 0x800
7450 #define I40E_TR_GRE_NO_KEY_MASK 0x8000
7453 i40e_status_code i40e_replace_mpls_l1_filter(struct i40e_pf *pf)
7455 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
7456 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
7457 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7458 enum i40e_status_code status = I40E_SUCCESS;
7460 if (pf->support_multi_driver) {
7461 PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
7462 return I40E_NOT_SUPPORTED;
7465 memset(&filter_replace, 0,
7466 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
7467 memset(&filter_replace_buf, 0,
7468 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
7470 /* create L1 filter */
7471 filter_replace.old_filter_type =
7472 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_IMAC;
7473 filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X11;
7474 filter_replace.tr_bit = 0;
7476 /* Prepare the buffer, 3 entries */
7477 filter_replace_buf.data[0] =
7478 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
7479 filter_replace_buf.data[0] |=
7480 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7481 filter_replace_buf.data[2] = 0xFF;
7482 filter_replace_buf.data[3] = 0xFF;
7483 filter_replace_buf.data[4] =
7484 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
7485 filter_replace_buf.data[4] |=
7486 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7487 filter_replace_buf.data[7] = 0xF0;
7488 filter_replace_buf.data[8]
7489 = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_TR_WORD0;
7490 filter_replace_buf.data[8] |=
7491 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7492 filter_replace_buf.data[10] = I40E_TR_VXLAN_GRE_KEY_MASK |
7493 I40E_TR_GENEVE_KEY_MASK |
7494 I40E_TR_GENERIC_UDP_TUNNEL_MASK;
7495 filter_replace_buf.data[11] = (I40E_TR_GRE_KEY_MASK |
7496 I40E_TR_GRE_KEY_WITH_XSUM_MASK |
7497 I40E_TR_GRE_NO_KEY_MASK) >> 8;
7499 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
7500 &filter_replace_buf);
7502 i40e_global_cfg_warning(I40E_WARNING_RPL_CLD_FILTER);
7503 PMD_DRV_LOG(DEBUG, "Global configuration modification: "
7504 "cloud l1 type is changed from 0x%x to 0x%x",
7505 filter_replace.old_filter_type,
7506 filter_replace.new_filter_type);
7512 i40e_status_code i40e_replace_mpls_cloud_filter(struct i40e_pf *pf)
7514 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
7515 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
7516 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7517 enum i40e_status_code status = I40E_SUCCESS;
7519 if (pf->support_multi_driver) {
7520 PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
7521 return I40E_NOT_SUPPORTED;
7525 memset(&filter_replace, 0,
7526 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
7527 memset(&filter_replace_buf, 0,
7528 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
7529 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER |
7530 I40E_AQC_MIRROR_CLOUD_FILTER;
7531 filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IIP;
7532 filter_replace.new_filter_type =
7533 I40E_AQC_ADD_CLOUD_FILTER_0X11;
7534 /* Prepare the buffer, 2 entries */
7535 filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
7536 filter_replace_buf.data[0] |=
7537 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7538 filter_replace_buf.data[4] = I40E_AQC_ADD_L1_FILTER_0X11;
7539 filter_replace_buf.data[4] |=
7540 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7541 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
7542 &filter_replace_buf);
7545 PMD_DRV_LOG(DEBUG, "Global configuration modification: "
7546 "cloud filter type is changed from 0x%x to 0x%x",
7547 filter_replace.old_filter_type,
7548 filter_replace.new_filter_type);
7551 memset(&filter_replace, 0,
7552 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
7553 memset(&filter_replace_buf, 0,
7554 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
7556 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER |
7557 I40E_AQC_MIRROR_CLOUD_FILTER;
7558 filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
7559 filter_replace.new_filter_type =
7560 I40E_AQC_ADD_CLOUD_FILTER_0X12;
7561 /* Prepare the buffer, 2 entries */
7562 filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
7563 filter_replace_buf.data[0] |=
7564 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7565 filter_replace_buf.data[4] = I40E_AQC_ADD_L1_FILTER_0X11;
7566 filter_replace_buf.data[4] |=
7567 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7569 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
7570 &filter_replace_buf);
7572 i40e_global_cfg_warning(I40E_WARNING_RPL_CLD_FILTER);
7573 PMD_DRV_LOG(DEBUG, "Global configuration modification: "
7574 "cloud filter type is changed from 0x%x to 0x%x",
7575 filter_replace.old_filter_type,
7576 filter_replace.new_filter_type);
7581 static enum i40e_status_code
7582 i40e_replace_gtp_l1_filter(struct i40e_pf *pf)
7584 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
7585 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
7586 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7587 enum i40e_status_code status = I40E_SUCCESS;
7589 if (pf->support_multi_driver) {
7590 PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
7591 return I40E_NOT_SUPPORTED;
7595 memset(&filter_replace, 0,
7596 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
7597 memset(&filter_replace_buf, 0,
7598 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
7599 /* create L1 filter */
7600 filter_replace.old_filter_type =
7601 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_IMAC;
7602 filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X12;
7603 filter_replace.tr_bit = I40E_AQC_NEW_TR_22 |
7604 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7605 /* Prepare the buffer, 2 entries */
7606 filter_replace_buf.data[0] =
7607 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
7608 filter_replace_buf.data[0] |=
7609 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7610 filter_replace_buf.data[2] = 0xFF;
7611 filter_replace_buf.data[3] = 0xFF;
7612 filter_replace_buf.data[4] =
7613 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
7614 filter_replace_buf.data[4] |=
7615 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7616 filter_replace_buf.data[6] = 0xFF;
7617 filter_replace_buf.data[7] = 0xFF;
7618 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
7619 &filter_replace_buf);
7622 PMD_DRV_LOG(DEBUG, "Global configuration modification: "
7623 "cloud l1 type is changed from 0x%x to 0x%x",
7624 filter_replace.old_filter_type,
7625 filter_replace.new_filter_type);
7628 memset(&filter_replace, 0,
7629 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
7630 memset(&filter_replace_buf, 0,
7631 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
7632 /* create L1 filter */
7633 filter_replace.old_filter_type =
7634 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TUNNLE_KEY;
7635 filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X13;
7636 filter_replace.tr_bit = I40E_AQC_NEW_TR_21 |
7637 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7638 /* Prepare the buffer, 2 entries */
7639 filter_replace_buf.data[0] =
7640 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
7641 filter_replace_buf.data[0] |=
7642 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7643 filter_replace_buf.data[2] = 0xFF;
7644 filter_replace_buf.data[3] = 0xFF;
7645 filter_replace_buf.data[4] =
7646 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
7647 filter_replace_buf.data[4] |=
7648 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7649 filter_replace_buf.data[6] = 0xFF;
7650 filter_replace_buf.data[7] = 0xFF;
7652 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
7653 &filter_replace_buf);
7655 i40e_global_cfg_warning(I40E_WARNING_RPL_CLD_FILTER);
7656 PMD_DRV_LOG(DEBUG, "Global configuration modification: "
7657 "cloud l1 type is changed from 0x%x to 0x%x",
7658 filter_replace.old_filter_type,
7659 filter_replace.new_filter_type);
7665 i40e_status_code i40e_replace_gtp_cloud_filter(struct i40e_pf *pf)
7667 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
7668 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
7669 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7670 enum i40e_status_code status = I40E_SUCCESS;
7672 if (pf->support_multi_driver) {
7673 PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
7674 return I40E_NOT_SUPPORTED;
7678 memset(&filter_replace, 0,
7679 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
7680 memset(&filter_replace_buf, 0,
7681 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
7682 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
7683 filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
7684 filter_replace.new_filter_type =
7685 I40E_AQC_ADD_CLOUD_FILTER_0X11;
7686 /* Prepare the buffer, 2 entries */
7687 filter_replace_buf.data[0] = I40E_AQC_ADD_L1_FILTER_0X12;
7688 filter_replace_buf.data[0] |=
7689 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7690 filter_replace_buf.data[4] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
7691 filter_replace_buf.data[4] |=
7692 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7693 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
7694 &filter_replace_buf);
7697 PMD_DRV_LOG(DEBUG, "Global configuration modification: "
7698 "cloud filter type is changed from 0x%x to 0x%x",
7699 filter_replace.old_filter_type,
7700 filter_replace.new_filter_type);
7703 memset(&filter_replace, 0,
7704 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
7705 memset(&filter_replace_buf, 0,
7706 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
7707 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
7708 filter_replace.old_filter_type =
7709 I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
7710 filter_replace.new_filter_type =
7711 I40E_AQC_ADD_CLOUD_FILTER_0X12;
7712 /* Prepare the buffer, 2 entries */
7713 filter_replace_buf.data[0] = I40E_AQC_ADD_L1_FILTER_0X13;
7714 filter_replace_buf.data[0] |=
7715 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7716 filter_replace_buf.data[4] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
7717 filter_replace_buf.data[4] |=
7718 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7720 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
7721 &filter_replace_buf);
7723 i40e_global_cfg_warning(I40E_WARNING_RPL_CLD_FILTER);
7724 PMD_DRV_LOG(DEBUG, "Global configuration modification: "
7725 "cloud filter type is changed from 0x%x to 0x%x",
7726 filter_replace.old_filter_type,
7727 filter_replace.new_filter_type);
7733 i40e_dev_consistent_tunnel_filter_set(struct i40e_pf *pf,
7734 struct i40e_tunnel_filter_conf *tunnel_filter,
7738 uint32_t ipv4_addr, ipv4_addr_le;
7739 uint8_t i, tun_type = 0;
7740 /* internal variable to convert ipv6 byte order */
7741 uint32_t convert_ipv6[4];
7743 struct i40e_pf_vf *vf = NULL;
7744 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7745 struct i40e_vsi *vsi;
7746 struct i40e_aqc_add_rm_cloud_filt_elem_ext *cld_filter;
7747 struct i40e_aqc_add_rm_cloud_filt_elem_ext *pfilter;
7748 struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
7749 struct i40e_tunnel_filter *tunnel, *node;
7750 struct i40e_tunnel_filter check_filter; /* Check if filter exists */
7752 bool big_buffer = 0;
7754 cld_filter = rte_zmalloc("tunnel_filter",
7755 sizeof(struct i40e_aqc_add_rm_cloud_filt_elem_ext),
7758 if (cld_filter == NULL) {
7759 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
7762 pfilter = cld_filter;
7764 ether_addr_copy(&tunnel_filter->outer_mac,
7765 (struct ether_addr *)&pfilter->element.outer_mac);
7766 ether_addr_copy(&tunnel_filter->inner_mac,
7767 (struct ether_addr *)&pfilter->element.inner_mac);
7769 pfilter->element.inner_vlan =
7770 rte_cpu_to_le_16(tunnel_filter->inner_vlan);
7771 if (tunnel_filter->ip_type == I40E_TUNNEL_IPTYPE_IPV4) {
7772 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV4;
7773 ipv4_addr = rte_be_to_cpu_32(tunnel_filter->ip_addr.ipv4_addr);
7774 ipv4_addr_le = rte_cpu_to_le_32(ipv4_addr);
7775 rte_memcpy(&pfilter->element.ipaddr.v4.data,
7777 sizeof(pfilter->element.ipaddr.v4.data));
7779 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV6;
7780 for (i = 0; i < 4; i++) {
7782 rte_cpu_to_le_32(rte_be_to_cpu_32(
7783 tunnel_filter->ip_addr.ipv6_addr[i]));
7785 rte_memcpy(&pfilter->element.ipaddr.v6.data,
7787 sizeof(pfilter->element.ipaddr.v6.data));
7790 /* check tunneled type */
7791 switch (tunnel_filter->tunnel_type) {
7792 case I40E_TUNNEL_TYPE_VXLAN:
7793 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_VXLAN;
7795 case I40E_TUNNEL_TYPE_NVGRE:
7796 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_NVGRE_OMAC;
7798 case I40E_TUNNEL_TYPE_IP_IN_GRE:
7799 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_IP;
7801 case I40E_TUNNEL_TYPE_MPLSoUDP:
7802 if (!pf->mpls_replace_flag) {
7803 i40e_replace_mpls_l1_filter(pf);
7804 i40e_replace_mpls_cloud_filter(pf);
7805 pf->mpls_replace_flag = 1;
7807 teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
7808 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
7810 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
7811 (teid_le & 0xF) << 12;
7812 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
7815 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_MPLSOUDP;
7817 case I40E_TUNNEL_TYPE_MPLSoGRE:
7818 if (!pf->mpls_replace_flag) {
7819 i40e_replace_mpls_l1_filter(pf);
7820 i40e_replace_mpls_cloud_filter(pf);
7821 pf->mpls_replace_flag = 1;
7823 teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
7824 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
7826 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
7827 (teid_le & 0xF) << 12;
7828 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
7831 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_MPLSOGRE;
7833 case I40E_TUNNEL_TYPE_GTPC:
7834 if (!pf->gtp_replace_flag) {
7835 i40e_replace_gtp_l1_filter(pf);
7836 i40e_replace_gtp_cloud_filter(pf);
7837 pf->gtp_replace_flag = 1;
7839 teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
7840 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD0] =
7841 (teid_le >> 16) & 0xFFFF;
7842 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD1] =
7844 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD2] =
7848 case I40E_TUNNEL_TYPE_GTPU:
7849 if (!pf->gtp_replace_flag) {
7850 i40e_replace_gtp_l1_filter(pf);
7851 i40e_replace_gtp_cloud_filter(pf);
7852 pf->gtp_replace_flag = 1;
7854 teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
7855 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD0] =
7856 (teid_le >> 16) & 0xFFFF;
7857 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD1] =
7859 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD2] =
7863 case I40E_TUNNEL_TYPE_QINQ:
7864 if (!pf->qinq_replace_flag) {
7865 ret = i40e_cloud_filter_qinq_create(pf);
7868 "QinQ tunnel filter already created.");
7869 pf->qinq_replace_flag = 1;
7871 /* Add in the General fields the values of
7872 * the Outer and Inner VLAN
7873 * Big Buffer should be set, see changes in
7874 * i40e_aq_add_cloud_filters
7876 pfilter->general_fields[0] = tunnel_filter->inner_vlan;
7877 pfilter->general_fields[1] = tunnel_filter->outer_vlan;
7881 /* Other tunnel types is not supported. */
7882 PMD_DRV_LOG(ERR, "tunnel type is not supported.");
7883 rte_free(cld_filter);
7887 if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_MPLSoUDP)
7888 pfilter->element.flags =
7889 I40E_AQC_ADD_CLOUD_FILTER_0X11;
7890 else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_MPLSoGRE)
7891 pfilter->element.flags =
7892 I40E_AQC_ADD_CLOUD_FILTER_0X12;
7893 else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_GTPC)
7894 pfilter->element.flags =
7895 I40E_AQC_ADD_CLOUD_FILTER_0X11;
7896 else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_GTPU)
7897 pfilter->element.flags =
7898 I40E_AQC_ADD_CLOUD_FILTER_0X12;
7899 else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_QINQ)
7900 pfilter->element.flags |=
7901 I40E_AQC_ADD_CLOUD_FILTER_0X10;
7903 val = i40e_dev_get_filter_type(tunnel_filter->filter_type,
7904 &pfilter->element.flags);
7906 rte_free(cld_filter);
7911 pfilter->element.flags |= rte_cpu_to_le_16(
7912 I40E_AQC_ADD_CLOUD_FLAGS_TO_QUEUE |
7913 ip_type | (tun_type << I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT));
7914 pfilter->element.tenant_id = rte_cpu_to_le_32(tunnel_filter->tenant_id);
7915 pfilter->element.queue_number =
7916 rte_cpu_to_le_16(tunnel_filter->queue_id);
7918 if (!tunnel_filter->is_to_vf)
7921 if (tunnel_filter->vf_id >= pf->vf_num) {
7922 PMD_DRV_LOG(ERR, "Invalid argument.");
7923 rte_free(cld_filter);
7926 vf = &pf->vfs[tunnel_filter->vf_id];
7930 /* Check if there is the filter in SW list */
7931 memset(&check_filter, 0, sizeof(check_filter));
7932 i40e_tunnel_filter_convert(cld_filter, &check_filter);
7933 check_filter.is_to_vf = tunnel_filter->is_to_vf;
7934 check_filter.vf_id = tunnel_filter->vf_id;
7935 node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
7937 PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
7938 rte_free(cld_filter);
7942 if (!add && !node) {
7943 PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
7944 rte_free(cld_filter);
7950 ret = i40e_aq_add_cloud_filters_big_buffer(hw,
7951 vsi->seid, cld_filter, 1);
7953 ret = i40e_aq_add_cloud_filters(hw,
7954 vsi->seid, &cld_filter->element, 1);
7956 PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
7957 rte_free(cld_filter);
7960 tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
7961 if (tunnel == NULL) {
7962 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
7963 rte_free(cld_filter);
7967 rte_memcpy(tunnel, &check_filter, sizeof(check_filter));
7968 ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
7973 ret = i40e_aq_remove_cloud_filters_big_buffer(
7974 hw, vsi->seid, cld_filter, 1);
7976 ret = i40e_aq_remove_cloud_filters(hw, vsi->seid,
7977 &cld_filter->element, 1);
7979 PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
7980 rte_free(cld_filter);
7983 ret = i40e_sw_tunnel_filter_del(pf, &node->input);
7986 rte_free(cld_filter);
7991 i40e_get_vxlan_port_idx(struct i40e_pf *pf, uint16_t port)
7995 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
7996 if (pf->vxlan_ports[i] == port)
8004 i40e_add_vxlan_port(struct i40e_pf *pf, uint16_t port)
8008 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8010 idx = i40e_get_vxlan_port_idx(pf, port);
8012 /* Check if port already exists */
8014 PMD_DRV_LOG(ERR, "Port %d already offloaded", port);
8018 /* Now check if there is space to add the new port */
8019 idx = i40e_get_vxlan_port_idx(pf, 0);
8022 "Maximum number of UDP ports reached, not adding port %d",
8027 ret = i40e_aq_add_udp_tunnel(hw, port, I40E_AQC_TUNNEL_TYPE_VXLAN,
8030 PMD_DRV_LOG(ERR, "Failed to add VXLAN UDP port %d", port);
8034 PMD_DRV_LOG(INFO, "Added port %d with AQ command with index %d",
8037 /* New port: add it and mark its index in the bitmap */
8038 pf->vxlan_ports[idx] = port;
8039 pf->vxlan_bitmap |= (1 << idx);
8041 if (!(pf->flags & I40E_FLAG_VXLAN))
8042 pf->flags |= I40E_FLAG_VXLAN;
8048 i40e_del_vxlan_port(struct i40e_pf *pf, uint16_t port)
8051 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8053 if (!(pf->flags & I40E_FLAG_VXLAN)) {
8054 PMD_DRV_LOG(ERR, "VXLAN UDP port was not configured.");
8058 idx = i40e_get_vxlan_port_idx(pf, port);
8061 PMD_DRV_LOG(ERR, "Port %d doesn't exist", port);
8065 if (i40e_aq_del_udp_tunnel(hw, idx, NULL) < 0) {
8066 PMD_DRV_LOG(ERR, "Failed to delete VXLAN UDP port %d", port);
8070 PMD_DRV_LOG(INFO, "Deleted port %d with AQ command with index %d",
8073 pf->vxlan_ports[idx] = 0;
8074 pf->vxlan_bitmap &= ~(1 << idx);
8076 if (!pf->vxlan_bitmap)
8077 pf->flags &= ~I40E_FLAG_VXLAN;
8082 /* Add UDP tunneling port */
8084 i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
8085 struct rte_eth_udp_tunnel *udp_tunnel)
8088 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8090 if (udp_tunnel == NULL)
8093 switch (udp_tunnel->prot_type) {
8094 case RTE_TUNNEL_TYPE_VXLAN:
8095 ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port);
8098 case RTE_TUNNEL_TYPE_GENEVE:
8099 case RTE_TUNNEL_TYPE_TEREDO:
8100 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8105 PMD_DRV_LOG(ERR, "Invalid tunnel type");
8113 /* Remove UDP tunneling port */
8115 i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
8116 struct rte_eth_udp_tunnel *udp_tunnel)
8119 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8121 if (udp_tunnel == NULL)
8124 switch (udp_tunnel->prot_type) {
8125 case RTE_TUNNEL_TYPE_VXLAN:
8126 ret = i40e_del_vxlan_port(pf, udp_tunnel->udp_port);
8128 case RTE_TUNNEL_TYPE_GENEVE:
8129 case RTE_TUNNEL_TYPE_TEREDO:
8130 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8134 PMD_DRV_LOG(ERR, "Invalid tunnel type");
8142 /* Calculate the maximum number of contiguous PF queues that are configured */
8144 i40e_pf_calc_configured_queues_num(struct i40e_pf *pf)
8146 struct rte_eth_dev_data *data = pf->dev_data;
8148 struct i40e_rx_queue *rxq;
8151 for (i = 0; i < pf->lan_nb_qps; i++) {
8152 rxq = data->rx_queues[i];
8153 if (rxq && rxq->q_set)
8164 i40e_pf_config_rss(struct i40e_pf *pf)
8166 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8167 struct rte_eth_rss_conf rss_conf;
8168 uint32_t i, lut = 0;
8172 * If both VMDQ and RSS enabled, not all of PF queues are configured.
8173 * It's necessary to calculate the actual PF queues that are configured.
8175 if (pf->dev_data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG)
8176 num = i40e_pf_calc_configured_queues_num(pf);
8178 num = pf->dev_data->nb_rx_queues;
8180 num = RTE_MIN(num, I40E_MAX_Q_PER_TC);
8181 PMD_INIT_LOG(INFO, "Max of contiguous %u PF queues are configured",
8185 PMD_INIT_LOG(ERR, "No PF queues are configured to enable RSS");
8189 for (i = 0, j = 0; i < hw->func_caps.rss_table_size; i++, j++) {
8192 lut = (lut << 8) | (j & ((0x1 <<
8193 hw->func_caps.rss_table_entry_width) - 1));
8195 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i >> 2), lut);
8198 rss_conf = pf->dev_data->dev_conf.rx_adv_conf.rss_conf;
8199 if ((rss_conf.rss_hf & pf->adapter->flow_types_mask) == 0) {
8200 i40e_pf_disable_rss(pf);
8203 if (rss_conf.rss_key == NULL || rss_conf.rss_key_len <
8204 (I40E_PFQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t)) {
8205 /* Random default keys */
8206 static uint32_t rss_key_default[] = {0x6b793944,
8207 0x23504cb5, 0x5bea75b6, 0x309f4f12, 0x3dc0a2b8,
8208 0x024ddcdf, 0x339b8ca0, 0x4c4af64a, 0x34fac605,
8209 0x55d85839, 0x3a58997d, 0x2ec938e1, 0x66031581};
8211 rss_conf.rss_key = (uint8_t *)rss_key_default;
8212 rss_conf.rss_key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
8216 return i40e_hw_rss_hash_set(pf, &rss_conf);
8220 i40e_tunnel_filter_param_check(struct i40e_pf *pf,
8221 struct rte_eth_tunnel_filter_conf *filter)
8223 if (pf == NULL || filter == NULL) {
8224 PMD_DRV_LOG(ERR, "Invalid parameter");
8228 if (filter->queue_id >= pf->dev_data->nb_rx_queues) {
8229 PMD_DRV_LOG(ERR, "Invalid queue ID");
8233 if (filter->inner_vlan > ETHER_MAX_VLAN_ID) {
8234 PMD_DRV_LOG(ERR, "Invalid inner VLAN ID");
8238 if ((filter->filter_type & ETH_TUNNEL_FILTER_OMAC) &&
8239 (is_zero_ether_addr(&filter->outer_mac))) {
8240 PMD_DRV_LOG(ERR, "Cannot add NULL outer MAC address");
8244 if ((filter->filter_type & ETH_TUNNEL_FILTER_IMAC) &&
8245 (is_zero_ether_addr(&filter->inner_mac))) {
8246 PMD_DRV_LOG(ERR, "Cannot add NULL inner MAC address");
8253 #define I40E_GL_PRS_FVBM_MSK_ENA 0x80000000
8254 #define I40E_GL_PRS_FVBM(_i) (0x00269760 + ((_i) * 4))
8256 i40e_dev_set_gre_key_len(struct i40e_hw *hw, uint8_t len)
8258 struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
8262 if (pf->support_multi_driver) {
8263 PMD_DRV_LOG(ERR, "GRE key length configuration is unsupported");
8267 val = I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2));
8268 PMD_DRV_LOG(DEBUG, "Read original GL_PRS_FVBM with 0x%08x", val);
8271 reg = val | I40E_GL_PRS_FVBM_MSK_ENA;
8272 } else if (len == 4) {
8273 reg = val & ~I40E_GL_PRS_FVBM_MSK_ENA;
8275 PMD_DRV_LOG(ERR, "Unsupported GRE key length of %u", len);
8280 ret = i40e_aq_debug_write_register(hw, I40E_GL_PRS_FVBM(2),
8284 PMD_DRV_LOG(DEBUG, "Global register 0x%08x is changed "
8285 "with value 0x%08x",
8286 I40E_GL_PRS_FVBM(2), reg);
8287 i40e_global_cfg_warning(I40E_WARNING_GRE_KEY_LEN);
8291 PMD_DRV_LOG(DEBUG, "Read modified GL_PRS_FVBM with 0x%08x",
8292 I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2)));
8298 i40e_dev_global_config_set(struct i40e_hw *hw, struct rte_eth_global_cfg *cfg)
8305 switch (cfg->cfg_type) {
8306 case RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN:
8307 ret = i40e_dev_set_gre_key_len(hw, cfg->cfg.gre_key_len);
8310 PMD_DRV_LOG(ERR, "Unknown config type %u", cfg->cfg_type);
8318 i40e_filter_ctrl_global_config(struct rte_eth_dev *dev,
8319 enum rte_filter_op filter_op,
8322 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8323 int ret = I40E_ERR_PARAM;
8325 switch (filter_op) {
8326 case RTE_ETH_FILTER_SET:
8327 ret = i40e_dev_global_config_set(hw,
8328 (struct rte_eth_global_cfg *)arg);
8331 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
8339 i40e_tunnel_filter_handle(struct rte_eth_dev *dev,
8340 enum rte_filter_op filter_op,
8343 struct rte_eth_tunnel_filter_conf *filter;
8344 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8345 int ret = I40E_SUCCESS;
8347 filter = (struct rte_eth_tunnel_filter_conf *)(arg);
8349 if (i40e_tunnel_filter_param_check(pf, filter) < 0)
8350 return I40E_ERR_PARAM;
8352 switch (filter_op) {
8353 case RTE_ETH_FILTER_NOP:
8354 if (!(pf->flags & I40E_FLAG_VXLAN))
8355 ret = I40E_NOT_SUPPORTED;
8357 case RTE_ETH_FILTER_ADD:
8358 ret = i40e_dev_tunnel_filter_set(pf, filter, 1);
8360 case RTE_ETH_FILTER_DELETE:
8361 ret = i40e_dev_tunnel_filter_set(pf, filter, 0);
8364 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
8365 ret = I40E_ERR_PARAM;
8373 i40e_pf_config_mq_rx(struct i40e_pf *pf)
8376 enum rte_eth_rx_mq_mode mq_mode = pf->dev_data->dev_conf.rxmode.mq_mode;
8379 if (mq_mode & ETH_MQ_RX_RSS_FLAG)
8380 ret = i40e_pf_config_rss(pf);
8382 i40e_pf_disable_rss(pf);
8387 /* Get the symmetric hash enable configurations per port */
8389 i40e_get_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t *enable)
8391 uint32_t reg = i40e_read_rx_ctl(hw, I40E_PRTQF_CTL_0);
8393 *enable = reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK ? 1 : 0;
8396 /* Set the symmetric hash enable configurations per port */
8398 i40e_set_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t enable)
8400 uint32_t reg = i40e_read_rx_ctl(hw, I40E_PRTQF_CTL_0);
8403 if (reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK) {
8405 "Symmetric hash has already been enabled");
8408 reg |= I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
8410 if (!(reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK)) {
8412 "Symmetric hash has already been disabled");
8415 reg &= ~I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
8417 i40e_write_rx_ctl(hw, I40E_PRTQF_CTL_0, reg);
8418 I40E_WRITE_FLUSH(hw);
8422 * Get global configurations of hash function type and symmetric hash enable
8423 * per flow type (pctype). Note that global configuration means it affects all
8424 * the ports on the same NIC.
8427 i40e_get_hash_filter_global_config(struct i40e_hw *hw,
8428 struct rte_eth_hash_global_conf *g_cfg)
8430 struct i40e_adapter *adapter = (struct i40e_adapter *)hw->back;
8434 memset(g_cfg, 0, sizeof(*g_cfg));
8435 reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
8436 if (reg & I40E_GLQF_CTL_HTOEP_MASK)
8437 g_cfg->hash_func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
8439 g_cfg->hash_func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
8440 PMD_DRV_LOG(DEBUG, "Hash function is %s",
8441 (reg & I40E_GLQF_CTL_HTOEP_MASK) ? "Toeplitz" : "Simple XOR");
8444 * As i40e supports less than 64 flow types, only first 64 bits need to
8447 for (i = 1; i < RTE_SYM_HASH_MASK_ARRAY_SIZE; i++) {
8448 g_cfg->valid_bit_mask[i] = 0ULL;
8449 g_cfg->sym_hash_enable_mask[i] = 0ULL;
8452 g_cfg->valid_bit_mask[0] = adapter->flow_types_mask;
8454 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < UINT64_BIT; i++) {
8455 if (!adapter->pctypes_tbl[i])
8457 for (j = I40E_FILTER_PCTYPE_INVALID + 1;
8458 j < I40E_FILTER_PCTYPE_MAX; j++) {
8459 if (adapter->pctypes_tbl[i] & (1ULL << j)) {
8460 reg = i40e_read_rx_ctl(hw, I40E_GLQF_HSYM(j));
8461 if (reg & I40E_GLQF_HSYM_SYMH_ENA_MASK) {
8462 g_cfg->sym_hash_enable_mask[0] |=
8473 i40e_hash_global_config_check(const struct i40e_adapter *adapter,
8474 const struct rte_eth_hash_global_conf *g_cfg)
8477 uint64_t mask0, i40e_mask = adapter->flow_types_mask;
8479 if (g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_TOEPLITZ &&
8480 g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_SIMPLE_XOR &&
8481 g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_DEFAULT) {
8482 PMD_DRV_LOG(ERR, "Unsupported hash function type %d",
8488 * As i40e supports less than 64 flow types, only first 64 bits need to
8491 mask0 = g_cfg->valid_bit_mask[0];
8492 for (i = 0; i < RTE_SYM_HASH_MASK_ARRAY_SIZE; i++) {
8494 /* Check if any unsupported flow type configured */
8495 if ((mask0 | i40e_mask) ^ i40e_mask)
8498 if (g_cfg->valid_bit_mask[i])
8506 PMD_DRV_LOG(ERR, "i40e unsupported flow type bit(s) configured");
8512 * Set global configurations of hash function type and symmetric hash enable
8513 * per flow type (pctype). Note any modifying global configuration will affect
8514 * all the ports on the same NIC.
8517 i40e_set_hash_filter_global_config(struct i40e_hw *hw,
8518 struct rte_eth_hash_global_conf *g_cfg)
8520 struct i40e_adapter *adapter = (struct i40e_adapter *)hw->back;
8521 struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
8525 uint64_t mask0 = g_cfg->valid_bit_mask[0] & adapter->flow_types_mask;
8527 if (pf->support_multi_driver) {
8528 PMD_DRV_LOG(ERR, "Hash global configuration is not supported.");
8532 /* Check the input parameters */
8533 ret = i40e_hash_global_config_check(adapter, g_cfg);
8538 * As i40e supports less than 64 flow types, only first 64 bits need to
8541 for (i = RTE_ETH_FLOW_UNKNOWN + 1; mask0 && i < UINT64_BIT; i++) {
8542 if (mask0 & (1UL << i)) {
8543 reg = (g_cfg->sym_hash_enable_mask[0] & (1ULL << i)) ?
8544 I40E_GLQF_HSYM_SYMH_ENA_MASK : 0;
8546 for (j = I40E_FILTER_PCTYPE_INVALID + 1;
8547 j < I40E_FILTER_PCTYPE_MAX; j++) {
8548 if (adapter->pctypes_tbl[i] & (1ULL << j))
8549 i40e_write_global_rx_ctl(hw,
8553 i40e_global_cfg_warning(I40E_WARNING_HSYM);
8557 reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
8558 if (g_cfg->hash_func == RTE_ETH_HASH_FUNCTION_TOEPLITZ) {
8560 if (reg & I40E_GLQF_CTL_HTOEP_MASK) {
8562 "Hash function already set to Toeplitz");
8565 reg |= I40E_GLQF_CTL_HTOEP_MASK;
8566 } else if (g_cfg->hash_func == RTE_ETH_HASH_FUNCTION_SIMPLE_XOR) {
8568 if (!(reg & I40E_GLQF_CTL_HTOEP_MASK)) {
8570 "Hash function already set to Simple XOR");
8573 reg &= ~I40E_GLQF_CTL_HTOEP_MASK;
8575 /* Use the default, and keep it as it is */
8578 i40e_write_global_rx_ctl(hw, I40E_GLQF_CTL, reg);
8579 i40e_global_cfg_warning(I40E_WARNING_QF_CTL);
8582 I40E_WRITE_FLUSH(hw);
8588 * Valid input sets for hash and flow director filters per PCTYPE
8591 i40e_get_valid_input_set(enum i40e_filter_pctype pctype,
8592 enum rte_filter_type filter)
8596 static const uint64_t valid_hash_inset_table[] = {
8597 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
8598 I40E_INSET_DMAC | I40E_INSET_SMAC |
8599 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8600 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_SRC |
8601 I40E_INSET_IPV4_DST | I40E_INSET_IPV4_TOS |
8602 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
8603 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
8604 I40E_INSET_FLEX_PAYLOAD,
8605 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
8606 I40E_INSET_DMAC | I40E_INSET_SMAC |
8607 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8608 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
8609 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
8610 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
8611 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8612 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
8613 I40E_INSET_FLEX_PAYLOAD,
8614 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
8615 I40E_INSET_DMAC | I40E_INSET_SMAC |
8616 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8617 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
8618 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
8619 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
8620 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8621 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
8622 I40E_INSET_FLEX_PAYLOAD,
8623 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
8624 I40E_INSET_DMAC | I40E_INSET_SMAC |
8625 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8626 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
8627 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
8628 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
8629 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8630 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
8631 I40E_INSET_FLEX_PAYLOAD,
8632 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
8633 I40E_INSET_DMAC | I40E_INSET_SMAC |
8634 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8635 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
8636 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
8637 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
8638 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8639 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
8640 I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
8641 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
8642 I40E_INSET_DMAC | I40E_INSET_SMAC |
8643 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8644 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
8645 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
8646 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
8647 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8648 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
8649 I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
8650 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
8651 I40E_INSET_DMAC | I40E_INSET_SMAC |
8652 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8653 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
8654 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
8655 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
8656 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8657 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
8658 I40E_INSET_SCTP_VT | I40E_INSET_FLEX_PAYLOAD,
8659 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
8660 I40E_INSET_DMAC | I40E_INSET_SMAC |
8661 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8662 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
8663 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
8664 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
8665 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8666 I40E_INSET_FLEX_PAYLOAD,
8667 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
8668 I40E_INSET_DMAC | I40E_INSET_SMAC |
8669 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8670 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
8671 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
8672 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_TUNNEL_DMAC |
8673 I40E_INSET_TUNNEL_ID | I40E_INSET_IPV6_SRC |
8674 I40E_INSET_IPV6_DST | I40E_INSET_FLEX_PAYLOAD,
8675 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
8676 I40E_INSET_DMAC | I40E_INSET_SMAC |
8677 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8678 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
8679 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
8680 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
8681 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
8682 I40E_INSET_DST_PORT | I40E_INSET_FLEX_PAYLOAD,
8683 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
8684 I40E_INSET_DMAC | I40E_INSET_SMAC |
8685 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8686 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
8687 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
8688 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
8689 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
8690 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
8691 I40E_INSET_FLEX_PAYLOAD,
8692 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
8693 I40E_INSET_DMAC | I40E_INSET_SMAC |
8694 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8695 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
8696 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
8697 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
8698 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
8699 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
8700 I40E_INSET_FLEX_PAYLOAD,
8701 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
8702 I40E_INSET_DMAC | I40E_INSET_SMAC |
8703 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8704 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
8705 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
8706 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
8707 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
8708 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
8709 I40E_INSET_FLEX_PAYLOAD,
8710 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
8711 I40E_INSET_DMAC | I40E_INSET_SMAC |
8712 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8713 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
8714 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
8715 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
8716 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
8717 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
8718 I40E_INSET_FLEX_PAYLOAD,
8719 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
8720 I40E_INSET_DMAC | I40E_INSET_SMAC |
8721 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8722 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
8723 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
8724 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
8725 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
8726 I40E_INSET_DST_PORT | I40E_INSET_SCTP_VT |
8727 I40E_INSET_FLEX_PAYLOAD,
8728 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
8729 I40E_INSET_DMAC | I40E_INSET_SMAC |
8730 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8731 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
8732 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
8733 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
8734 I40E_INSET_IPV6_DST | I40E_INSET_TUNNEL_ID |
8735 I40E_INSET_FLEX_PAYLOAD,
8736 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
8737 I40E_INSET_DMAC | I40E_INSET_SMAC |
8738 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8739 I40E_INSET_VLAN_TUNNEL | I40E_INSET_LAST_ETHER_TYPE |
8740 I40E_INSET_FLEX_PAYLOAD,
8744 * Flow director supports only fields defined in
8745 * union rte_eth_fdir_flow.
8747 static const uint64_t valid_fdir_inset_table[] = {
8748 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
8749 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8750 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8751 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
8752 I40E_INSET_IPV4_TTL,
8753 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
8754 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8755 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8756 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
8757 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8758 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
8759 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8760 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8761 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
8762 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8763 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
8764 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8765 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8766 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
8767 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8768 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
8769 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8770 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8771 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
8772 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8773 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
8774 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8775 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8776 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
8777 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8778 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
8779 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8780 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8781 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
8782 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
8784 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
8785 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8786 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8787 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
8788 I40E_INSET_IPV4_TTL,
8789 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
8790 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8791 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8792 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
8793 I40E_INSET_IPV6_HOP_LIMIT,
8794 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
8795 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8796 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8797 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
8798 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8799 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
8800 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8801 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8802 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
8803 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8804 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
8805 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8806 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8807 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
8808 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8809 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
8810 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8811 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8812 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
8813 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8814 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
8815 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8816 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8817 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
8818 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8819 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
8820 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8821 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8822 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
8823 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
8825 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
8826 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8827 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8828 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
8829 I40E_INSET_IPV6_HOP_LIMIT,
8830 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
8831 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8832 I40E_INSET_LAST_ETHER_TYPE,
8835 if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
8837 if (filter == RTE_ETH_FILTER_HASH)
8838 valid = valid_hash_inset_table[pctype];
8840 valid = valid_fdir_inset_table[pctype];
8846 * Validate if the input set is allowed for a specific PCTYPE
8849 i40e_validate_input_set(enum i40e_filter_pctype pctype,
8850 enum rte_filter_type filter, uint64_t inset)
8854 valid = i40e_get_valid_input_set(pctype, filter);
8855 if (inset & (~valid))
8861 /* default input set fields combination per pctype */
8863 i40e_get_default_input_set(uint16_t pctype)
8865 static const uint64_t default_inset_table[] = {
8866 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
8867 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
8868 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
8869 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8870 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8871 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
8872 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8873 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8874 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
8875 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8876 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8877 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
8878 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8879 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8880 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
8881 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8882 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8883 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
8884 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8885 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
8887 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
8888 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
8889 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
8890 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
8891 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
8892 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8893 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8894 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
8895 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8896 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8897 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
8898 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8899 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8900 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
8901 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8902 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8903 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
8904 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8905 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8906 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
8907 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8908 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
8910 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
8911 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
8912 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
8913 I40E_INSET_LAST_ETHER_TYPE,
8916 if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
8919 return default_inset_table[pctype];
8923 * Parse the input set from index to logical bit masks
8926 i40e_parse_input_set(uint64_t *inset,
8927 enum i40e_filter_pctype pctype,
8928 enum rte_eth_input_set_field *field,
8934 static const struct {
8935 enum rte_eth_input_set_field field;
8937 } inset_convert_table[] = {
8938 {RTE_ETH_INPUT_SET_NONE, I40E_INSET_NONE},
8939 {RTE_ETH_INPUT_SET_L2_SRC_MAC, I40E_INSET_SMAC},
8940 {RTE_ETH_INPUT_SET_L2_DST_MAC, I40E_INSET_DMAC},
8941 {RTE_ETH_INPUT_SET_L2_OUTER_VLAN, I40E_INSET_VLAN_OUTER},
8942 {RTE_ETH_INPUT_SET_L2_INNER_VLAN, I40E_INSET_VLAN_INNER},
8943 {RTE_ETH_INPUT_SET_L2_ETHERTYPE, I40E_INSET_LAST_ETHER_TYPE},
8944 {RTE_ETH_INPUT_SET_L3_SRC_IP4, I40E_INSET_IPV4_SRC},
8945 {RTE_ETH_INPUT_SET_L3_DST_IP4, I40E_INSET_IPV4_DST},
8946 {RTE_ETH_INPUT_SET_L3_IP4_TOS, I40E_INSET_IPV4_TOS},
8947 {RTE_ETH_INPUT_SET_L3_IP4_PROTO, I40E_INSET_IPV4_PROTO},
8948 {RTE_ETH_INPUT_SET_L3_IP4_TTL, I40E_INSET_IPV4_TTL},
8949 {RTE_ETH_INPUT_SET_L3_SRC_IP6, I40E_INSET_IPV6_SRC},
8950 {RTE_ETH_INPUT_SET_L3_DST_IP6, I40E_INSET_IPV6_DST},
8951 {RTE_ETH_INPUT_SET_L3_IP6_TC, I40E_INSET_IPV6_TC},
8952 {RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER,
8953 I40E_INSET_IPV6_NEXT_HDR},
8954 {RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS,
8955 I40E_INSET_IPV6_HOP_LIMIT},
8956 {RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT, I40E_INSET_SRC_PORT},
8957 {RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT, I40E_INSET_SRC_PORT},
8958 {RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT, I40E_INSET_SRC_PORT},
8959 {RTE_ETH_INPUT_SET_L4_UDP_DST_PORT, I40E_INSET_DST_PORT},
8960 {RTE_ETH_INPUT_SET_L4_TCP_DST_PORT, I40E_INSET_DST_PORT},
8961 {RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT, I40E_INSET_DST_PORT},
8962 {RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG,
8963 I40E_INSET_SCTP_VT},
8964 {RTE_ETH_INPUT_SET_TUNNEL_L2_INNER_DST_MAC,
8965 I40E_INSET_TUNNEL_DMAC},
8966 {RTE_ETH_INPUT_SET_TUNNEL_L2_INNER_VLAN,
8967 I40E_INSET_VLAN_TUNNEL},
8968 {RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY,
8969 I40E_INSET_TUNNEL_ID},
8970 {RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY, I40E_INSET_TUNNEL_ID},
8971 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD,
8972 I40E_INSET_FLEX_PAYLOAD_W1},
8973 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD,
8974 I40E_INSET_FLEX_PAYLOAD_W2},
8975 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD,
8976 I40E_INSET_FLEX_PAYLOAD_W3},
8977 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD,
8978 I40E_INSET_FLEX_PAYLOAD_W4},
8979 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD,
8980 I40E_INSET_FLEX_PAYLOAD_W5},
8981 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD,
8982 I40E_INSET_FLEX_PAYLOAD_W6},
8983 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD,
8984 I40E_INSET_FLEX_PAYLOAD_W7},
8985 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD,
8986 I40E_INSET_FLEX_PAYLOAD_W8},
8989 if (!inset || !field || size > RTE_ETH_INSET_SIZE_MAX)
8992 /* Only one item allowed for default or all */
8994 if (field[0] == RTE_ETH_INPUT_SET_DEFAULT) {
8995 *inset = i40e_get_default_input_set(pctype);
8997 } else if (field[0] == RTE_ETH_INPUT_SET_NONE) {
8998 *inset = I40E_INSET_NONE;
9003 for (i = 0, *inset = 0; i < size; i++) {
9004 for (j = 0; j < RTE_DIM(inset_convert_table); j++) {
9005 if (field[i] == inset_convert_table[j].field) {
9006 *inset |= inset_convert_table[j].inset;
9011 /* It contains unsupported input set, return immediately */
9012 if (j == RTE_DIM(inset_convert_table))
9020 * Translate the input set from bit masks to register aware bit masks
9024 i40e_translate_input_set_reg(enum i40e_mac_type type, uint64_t input)
9034 static const struct inset_map inset_map_common[] = {
9035 {I40E_INSET_DMAC, I40E_REG_INSET_L2_DMAC},
9036 {I40E_INSET_SMAC, I40E_REG_INSET_L2_SMAC},
9037 {I40E_INSET_VLAN_OUTER, I40E_REG_INSET_L2_OUTER_VLAN},
9038 {I40E_INSET_VLAN_INNER, I40E_REG_INSET_L2_INNER_VLAN},
9039 {I40E_INSET_LAST_ETHER_TYPE, I40E_REG_INSET_LAST_ETHER_TYPE},
9040 {I40E_INSET_IPV4_TOS, I40E_REG_INSET_L3_IP4_TOS},
9041 {I40E_INSET_IPV6_SRC, I40E_REG_INSET_L3_SRC_IP6},
9042 {I40E_INSET_IPV6_DST, I40E_REG_INSET_L3_DST_IP6},
9043 {I40E_INSET_IPV6_TC, I40E_REG_INSET_L3_IP6_TC},
9044 {I40E_INSET_IPV6_NEXT_HDR, I40E_REG_INSET_L3_IP6_NEXT_HDR},
9045 {I40E_INSET_IPV6_HOP_LIMIT, I40E_REG_INSET_L3_IP6_HOP_LIMIT},
9046 {I40E_INSET_SRC_PORT, I40E_REG_INSET_L4_SRC_PORT},
9047 {I40E_INSET_DST_PORT, I40E_REG_INSET_L4_DST_PORT},
9048 {I40E_INSET_SCTP_VT, I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG},
9049 {I40E_INSET_TUNNEL_ID, I40E_REG_INSET_TUNNEL_ID},
9050 {I40E_INSET_TUNNEL_DMAC,
9051 I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC},
9052 {I40E_INSET_TUNNEL_IPV4_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP4},
9053 {I40E_INSET_TUNNEL_IPV6_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP6},
9054 {I40E_INSET_TUNNEL_SRC_PORT,
9055 I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT},
9056 {I40E_INSET_TUNNEL_DST_PORT,
9057 I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT},
9058 {I40E_INSET_VLAN_TUNNEL, I40E_REG_INSET_TUNNEL_VLAN},
9059 {I40E_INSET_FLEX_PAYLOAD_W1, I40E_REG_INSET_FLEX_PAYLOAD_WORD1},
9060 {I40E_INSET_FLEX_PAYLOAD_W2, I40E_REG_INSET_FLEX_PAYLOAD_WORD2},
9061 {I40E_INSET_FLEX_PAYLOAD_W3, I40E_REG_INSET_FLEX_PAYLOAD_WORD3},
9062 {I40E_INSET_FLEX_PAYLOAD_W4, I40E_REG_INSET_FLEX_PAYLOAD_WORD4},
9063 {I40E_INSET_FLEX_PAYLOAD_W5, I40E_REG_INSET_FLEX_PAYLOAD_WORD5},
9064 {I40E_INSET_FLEX_PAYLOAD_W6, I40E_REG_INSET_FLEX_PAYLOAD_WORD6},
9065 {I40E_INSET_FLEX_PAYLOAD_W7, I40E_REG_INSET_FLEX_PAYLOAD_WORD7},
9066 {I40E_INSET_FLEX_PAYLOAD_W8, I40E_REG_INSET_FLEX_PAYLOAD_WORD8},
9069 /* some different registers map in x722*/
9070 static const struct inset_map inset_map_diff_x722[] = {
9071 {I40E_INSET_IPV4_SRC, I40E_X722_REG_INSET_L3_SRC_IP4},
9072 {I40E_INSET_IPV4_DST, I40E_X722_REG_INSET_L3_DST_IP4},
9073 {I40E_INSET_IPV4_PROTO, I40E_X722_REG_INSET_L3_IP4_PROTO},
9074 {I40E_INSET_IPV4_TTL, I40E_X722_REG_INSET_L3_IP4_TTL},
9077 static const struct inset_map inset_map_diff_not_x722[] = {
9078 {I40E_INSET_IPV4_SRC, I40E_REG_INSET_L3_SRC_IP4},
9079 {I40E_INSET_IPV4_DST, I40E_REG_INSET_L3_DST_IP4},
9080 {I40E_INSET_IPV4_PROTO, I40E_REG_INSET_L3_IP4_PROTO},
9081 {I40E_INSET_IPV4_TTL, I40E_REG_INSET_L3_IP4_TTL},
9087 /* Translate input set to register aware inset */
9088 if (type == I40E_MAC_X722) {
9089 for (i = 0; i < RTE_DIM(inset_map_diff_x722); i++) {
9090 if (input & inset_map_diff_x722[i].inset)
9091 val |= inset_map_diff_x722[i].inset_reg;
9094 for (i = 0; i < RTE_DIM(inset_map_diff_not_x722); i++) {
9095 if (input & inset_map_diff_not_x722[i].inset)
9096 val |= inset_map_diff_not_x722[i].inset_reg;
9100 for (i = 0; i < RTE_DIM(inset_map_common); i++) {
9101 if (input & inset_map_common[i].inset)
9102 val |= inset_map_common[i].inset_reg;
9109 i40e_generate_inset_mask_reg(uint64_t inset, uint32_t *mask, uint8_t nb_elem)
9112 uint64_t inset_need_mask = inset;
9114 static const struct {
9117 } inset_mask_map[] = {
9118 {I40E_INSET_IPV4_TOS, I40E_INSET_IPV4_TOS_MASK},
9119 {I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL, 0},
9120 {I40E_INSET_IPV4_PROTO, I40E_INSET_IPV4_PROTO_MASK},
9121 {I40E_INSET_IPV4_TTL, I40E_INSET_IPv4_TTL_MASK},
9122 {I40E_INSET_IPV6_TC, I40E_INSET_IPV6_TC_MASK},
9123 {I40E_INSET_IPV6_NEXT_HDR | I40E_INSET_IPV6_HOP_LIMIT, 0},
9124 {I40E_INSET_IPV6_NEXT_HDR, I40E_INSET_IPV6_NEXT_HDR_MASK},
9125 {I40E_INSET_IPV6_HOP_LIMIT, I40E_INSET_IPV6_HOP_LIMIT_MASK},
9128 if (!inset || !mask || !nb_elem)
9131 for (i = 0, idx = 0; i < RTE_DIM(inset_mask_map); i++) {
9132 /* Clear the inset bit, if no MASK is required,
9133 * for example proto + ttl
9135 if ((inset & inset_mask_map[i].inset) ==
9136 inset_mask_map[i].inset && inset_mask_map[i].mask == 0)
9137 inset_need_mask &= ~inset_mask_map[i].inset;
9138 if (!inset_need_mask)
9141 for (i = 0, idx = 0; i < RTE_DIM(inset_mask_map); i++) {
9142 if ((inset_need_mask & inset_mask_map[i].inset) ==
9143 inset_mask_map[i].inset) {
9144 if (idx >= nb_elem) {
9145 PMD_DRV_LOG(ERR, "exceed maximal number of bitmasks");
9148 mask[idx] = inset_mask_map[i].mask;
9157 i40e_check_write_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
9159 uint32_t reg = i40e_read_rx_ctl(hw, addr);
9161 PMD_DRV_LOG(DEBUG, "[0x%08x] original: 0x%08x", addr, reg);
9163 i40e_write_rx_ctl(hw, addr, val);
9164 PMD_DRV_LOG(DEBUG, "[0x%08x] after: 0x%08x", addr,
9165 (uint32_t)i40e_read_rx_ctl(hw, addr));
9169 i40e_check_write_global_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
9171 uint32_t reg = i40e_read_rx_ctl(hw, addr);
9173 PMD_DRV_LOG(DEBUG, "[0x%08x] original: 0x%08x", addr, reg);
9175 i40e_write_global_rx_ctl(hw, addr, val);
9176 PMD_DRV_LOG(DEBUG, "[0x%08x] after: 0x%08x", addr,
9177 (uint32_t)i40e_read_rx_ctl(hw, addr));
9181 i40e_filter_input_set_init(struct i40e_pf *pf)
9183 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9184 enum i40e_filter_pctype pctype;
9185 uint64_t input_set, inset_reg;
9186 uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9190 for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
9191 pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++) {
9192 flow_type = i40e_pctype_to_flowtype(pf->adapter, pctype);
9194 if (flow_type == RTE_ETH_FLOW_UNKNOWN)
9197 input_set = i40e_get_default_input_set(pctype);
9199 num = i40e_generate_inset_mask_reg(input_set, mask_reg,
9200 I40E_INSET_MASK_NUM_REG);
9203 if (pf->support_multi_driver && num > 0) {
9204 PMD_DRV_LOG(ERR, "Input set setting is not supported.");
9207 inset_reg = i40e_translate_input_set_reg(hw->mac.type,
9210 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
9211 (uint32_t)(inset_reg & UINT32_MAX));
9212 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
9213 (uint32_t)((inset_reg >>
9214 I40E_32_BIT_WIDTH) & UINT32_MAX));
9215 if (!pf->support_multi_driver) {
9216 i40e_check_write_global_reg(hw,
9217 I40E_GLQF_HASH_INSET(0, pctype),
9218 (uint32_t)(inset_reg & UINT32_MAX));
9219 i40e_check_write_global_reg(hw,
9220 I40E_GLQF_HASH_INSET(1, pctype),
9221 (uint32_t)((inset_reg >>
9222 I40E_32_BIT_WIDTH) & UINT32_MAX));
9224 for (i = 0; i < num; i++) {
9225 i40e_check_write_global_reg(hw,
9226 I40E_GLQF_FD_MSK(i, pctype),
9228 i40e_check_write_global_reg(hw,
9229 I40E_GLQF_HASH_MSK(i, pctype),
9232 /*clear unused mask registers of the pctype */
9233 for (i = num; i < I40E_INSET_MASK_NUM_REG; i++) {
9234 i40e_check_write_global_reg(hw,
9235 I40E_GLQF_FD_MSK(i, pctype),
9237 i40e_check_write_global_reg(hw,
9238 I40E_GLQF_HASH_MSK(i, pctype),
9242 PMD_DRV_LOG(ERR, "Input set setting is not supported.");
9244 I40E_WRITE_FLUSH(hw);
9246 /* store the default input set */
9247 if (!pf->support_multi_driver)
9248 pf->hash_input_set[pctype] = input_set;
9249 pf->fdir.input_set[pctype] = input_set;
9252 if (!pf->support_multi_driver) {
9253 i40e_global_cfg_warning(I40E_WARNING_HASH_INSET);
9254 i40e_global_cfg_warning(I40E_WARNING_FD_MSK);
9255 i40e_global_cfg_warning(I40E_WARNING_HASH_MSK);
9260 i40e_hash_filter_inset_select(struct i40e_hw *hw,
9261 struct rte_eth_input_set_conf *conf)
9263 struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
9264 enum i40e_filter_pctype pctype;
9265 uint64_t input_set, inset_reg = 0;
9266 uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9270 PMD_DRV_LOG(ERR, "Invalid pointer");
9273 if (conf->op != RTE_ETH_INPUT_SET_SELECT &&
9274 conf->op != RTE_ETH_INPUT_SET_ADD) {
9275 PMD_DRV_LOG(ERR, "Unsupported input set operation");
9279 if (pf->support_multi_driver) {
9280 PMD_DRV_LOG(ERR, "Hash input set setting is not supported.");
9284 pctype = i40e_flowtype_to_pctype(pf->adapter, conf->flow_type);
9285 if (pctype == I40E_FILTER_PCTYPE_INVALID) {
9286 PMD_DRV_LOG(ERR, "invalid flow_type input.");
9290 if (hw->mac.type == I40E_MAC_X722) {
9291 /* get translated pctype value in fd pctype register */
9292 pctype = (enum i40e_filter_pctype)i40e_read_rx_ctl(hw,
9293 I40E_GLQF_FD_PCTYPES((int)pctype));
9296 ret = i40e_parse_input_set(&input_set, pctype, conf->field,
9299 PMD_DRV_LOG(ERR, "Failed to parse input set");
9303 if (conf->op == RTE_ETH_INPUT_SET_ADD) {
9304 /* get inset value in register */
9305 inset_reg = i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, pctype));
9306 inset_reg <<= I40E_32_BIT_WIDTH;
9307 inset_reg |= i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, pctype));
9308 input_set |= pf->hash_input_set[pctype];
9310 num = i40e_generate_inset_mask_reg(input_set, mask_reg,
9311 I40E_INSET_MASK_NUM_REG);
9315 inset_reg |= i40e_translate_input_set_reg(hw->mac.type, input_set);
9317 i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(0, pctype),
9318 (uint32_t)(inset_reg & UINT32_MAX));
9319 i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(1, pctype),
9320 (uint32_t)((inset_reg >>
9321 I40E_32_BIT_WIDTH) & UINT32_MAX));
9322 i40e_global_cfg_warning(I40E_WARNING_HASH_INSET);
9324 for (i = 0; i < num; i++)
9325 i40e_check_write_global_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
9327 /*clear unused mask registers of the pctype */
9328 for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
9329 i40e_check_write_global_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
9331 i40e_global_cfg_warning(I40E_WARNING_HASH_MSK);
9332 I40E_WRITE_FLUSH(hw);
9334 pf->hash_input_set[pctype] = input_set;
9339 i40e_fdir_filter_inset_select(struct i40e_pf *pf,
9340 struct rte_eth_input_set_conf *conf)
9342 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9343 enum i40e_filter_pctype pctype;
9344 uint64_t input_set, inset_reg = 0;
9345 uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9349 PMD_DRV_LOG(ERR, "Invalid pointer");
9352 if (conf->op != RTE_ETH_INPUT_SET_SELECT &&
9353 conf->op != RTE_ETH_INPUT_SET_ADD) {
9354 PMD_DRV_LOG(ERR, "Unsupported input set operation");
9358 pctype = i40e_flowtype_to_pctype(pf->adapter, conf->flow_type);
9360 if (pctype == I40E_FILTER_PCTYPE_INVALID) {
9361 PMD_DRV_LOG(ERR, "invalid flow_type input.");
9365 ret = i40e_parse_input_set(&input_set, pctype, conf->field,
9368 PMD_DRV_LOG(ERR, "Failed to parse input set");
9372 /* get inset value in register */
9373 inset_reg = i40e_read_rx_ctl(hw, I40E_PRTQF_FD_INSET(pctype, 1));
9374 inset_reg <<= I40E_32_BIT_WIDTH;
9375 inset_reg |= i40e_read_rx_ctl(hw, I40E_PRTQF_FD_INSET(pctype, 0));
9377 /* Can not change the inset reg for flex payload for fdir,
9378 * it is done by writing I40E_PRTQF_FD_FLXINSET
9379 * in i40e_set_flex_mask_on_pctype.
9381 if (conf->op == RTE_ETH_INPUT_SET_SELECT)
9382 inset_reg &= I40E_REG_INSET_FLEX_PAYLOAD_WORDS;
9384 input_set |= pf->fdir.input_set[pctype];
9385 num = i40e_generate_inset_mask_reg(input_set, mask_reg,
9386 I40E_INSET_MASK_NUM_REG);
9389 if (pf->support_multi_driver && num > 0) {
9390 PMD_DRV_LOG(ERR, "FDIR bit mask is not supported.");
9394 inset_reg |= i40e_translate_input_set_reg(hw->mac.type, input_set);
9396 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
9397 (uint32_t)(inset_reg & UINT32_MAX));
9398 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
9399 (uint32_t)((inset_reg >>
9400 I40E_32_BIT_WIDTH) & UINT32_MAX));
9402 if (!pf->support_multi_driver) {
9403 for (i = 0; i < num; i++)
9404 i40e_check_write_global_reg(hw,
9405 I40E_GLQF_FD_MSK(i, pctype),
9407 /*clear unused mask registers of the pctype */
9408 for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
9409 i40e_check_write_global_reg(hw,
9410 I40E_GLQF_FD_MSK(i, pctype),
9412 i40e_global_cfg_warning(I40E_WARNING_FD_MSK);
9414 PMD_DRV_LOG(ERR, "FDIR bit mask is not supported.");
9416 I40E_WRITE_FLUSH(hw);
9418 pf->fdir.input_set[pctype] = input_set;
9423 i40e_hash_filter_get(struct i40e_hw *hw, struct rte_eth_hash_filter_info *info)
9428 PMD_DRV_LOG(ERR, "Invalid pointer");
9432 switch (info->info_type) {
9433 case RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT:
9434 i40e_get_symmetric_hash_enable_per_port(hw,
9435 &(info->info.enable));
9437 case RTE_ETH_HASH_FILTER_GLOBAL_CONFIG:
9438 ret = i40e_get_hash_filter_global_config(hw,
9439 &(info->info.global_conf));
9442 PMD_DRV_LOG(ERR, "Hash filter info type (%d) not supported",
9452 i40e_hash_filter_set(struct i40e_hw *hw, struct rte_eth_hash_filter_info *info)
9457 PMD_DRV_LOG(ERR, "Invalid pointer");
9461 switch (info->info_type) {
9462 case RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT:
9463 i40e_set_symmetric_hash_enable_per_port(hw, info->info.enable);
9465 case RTE_ETH_HASH_FILTER_GLOBAL_CONFIG:
9466 ret = i40e_set_hash_filter_global_config(hw,
9467 &(info->info.global_conf));
9469 case RTE_ETH_HASH_FILTER_INPUT_SET_SELECT:
9470 ret = i40e_hash_filter_inset_select(hw,
9471 &(info->info.input_set_conf));
9475 PMD_DRV_LOG(ERR, "Hash filter info type (%d) not supported",
9484 /* Operations for hash function */
9486 i40e_hash_filter_ctrl(struct rte_eth_dev *dev,
9487 enum rte_filter_op filter_op,
9490 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
9493 switch (filter_op) {
9494 case RTE_ETH_FILTER_NOP:
9496 case RTE_ETH_FILTER_GET:
9497 ret = i40e_hash_filter_get(hw,
9498 (struct rte_eth_hash_filter_info *)arg);
9500 case RTE_ETH_FILTER_SET:
9501 ret = i40e_hash_filter_set(hw,
9502 (struct rte_eth_hash_filter_info *)arg);
9505 PMD_DRV_LOG(WARNING, "Filter operation (%d) not supported",
9514 /* Convert ethertype filter structure */
9516 i40e_ethertype_filter_convert(const struct rte_eth_ethertype_filter *input,
9517 struct i40e_ethertype_filter *filter)
9519 rte_memcpy(&filter->input.mac_addr, &input->mac_addr, ETHER_ADDR_LEN);
9520 filter->input.ether_type = input->ether_type;
9521 filter->flags = input->flags;
9522 filter->queue = input->queue;
9527 /* Check if there exists the ehtertype filter */
9528 struct i40e_ethertype_filter *
9529 i40e_sw_ethertype_filter_lookup(struct i40e_ethertype_rule *ethertype_rule,
9530 const struct i40e_ethertype_filter_input *input)
9534 ret = rte_hash_lookup(ethertype_rule->hash_table, (const void *)input);
9538 return ethertype_rule->hash_map[ret];
9541 /* Add ethertype filter in SW list */
9543 i40e_sw_ethertype_filter_insert(struct i40e_pf *pf,
9544 struct i40e_ethertype_filter *filter)
9546 struct i40e_ethertype_rule *rule = &pf->ethertype;
9549 ret = rte_hash_add_key(rule->hash_table, &filter->input);
9552 "Failed to insert ethertype filter"
9553 " to hash table %d!",
9557 rule->hash_map[ret] = filter;
9559 TAILQ_INSERT_TAIL(&rule->ethertype_list, filter, rules);
9564 /* Delete ethertype filter in SW list */
9566 i40e_sw_ethertype_filter_del(struct i40e_pf *pf,
9567 struct i40e_ethertype_filter_input *input)
9569 struct i40e_ethertype_rule *rule = &pf->ethertype;
9570 struct i40e_ethertype_filter *filter;
9573 ret = rte_hash_del_key(rule->hash_table, input);
9576 "Failed to delete ethertype filter"
9577 " to hash table %d!",
9581 filter = rule->hash_map[ret];
9582 rule->hash_map[ret] = NULL;
9584 TAILQ_REMOVE(&rule->ethertype_list, filter, rules);
9591 * Configure ethertype filter, which can director packet by filtering
9592 * with mac address and ether_type or only ether_type
9595 i40e_ethertype_filter_set(struct i40e_pf *pf,
9596 struct rte_eth_ethertype_filter *filter,
9599 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9600 struct i40e_ethertype_rule *ethertype_rule = &pf->ethertype;
9601 struct i40e_ethertype_filter *ethertype_filter, *node;
9602 struct i40e_ethertype_filter check_filter;
9603 struct i40e_control_filter_stats stats;
9607 if (filter->queue >= pf->dev_data->nb_rx_queues) {
9608 PMD_DRV_LOG(ERR, "Invalid queue ID");
9611 if (filter->ether_type == ETHER_TYPE_IPv4 ||
9612 filter->ether_type == ETHER_TYPE_IPv6) {
9614 "unsupported ether_type(0x%04x) in control packet filter.",
9615 filter->ether_type);
9618 if (filter->ether_type == ETHER_TYPE_VLAN)
9619 PMD_DRV_LOG(WARNING,
9620 "filter vlan ether_type in first tag is not supported.");
9622 /* Check if there is the filter in SW list */
9623 memset(&check_filter, 0, sizeof(check_filter));
9624 i40e_ethertype_filter_convert(filter, &check_filter);
9625 node = i40e_sw_ethertype_filter_lookup(ethertype_rule,
9626 &check_filter.input);
9628 PMD_DRV_LOG(ERR, "Conflict with existing ethertype rules!");
9632 if (!add && !node) {
9633 PMD_DRV_LOG(ERR, "There's no corresponding ethertype filter!");
9637 if (!(filter->flags & RTE_ETHTYPE_FLAGS_MAC))
9638 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
9639 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP)
9640 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
9641 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
9643 memset(&stats, 0, sizeof(stats));
9644 ret = i40e_aq_add_rem_control_packet_filter(hw,
9645 filter->mac_addr.addr_bytes,
9646 filter->ether_type, flags,
9648 filter->queue, add, &stats, NULL);
9651 "add/rem control packet filter, return %d, mac_etype_used = %u, etype_used = %u, mac_etype_free = %u, etype_free = %u",
9652 ret, stats.mac_etype_used, stats.etype_used,
9653 stats.mac_etype_free, stats.etype_free);
9657 /* Add or delete a filter in SW list */
9659 ethertype_filter = rte_zmalloc("ethertype_filter",
9660 sizeof(*ethertype_filter), 0);
9661 if (ethertype_filter == NULL) {
9662 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
9666 rte_memcpy(ethertype_filter, &check_filter,
9667 sizeof(check_filter));
9668 ret = i40e_sw_ethertype_filter_insert(pf, ethertype_filter);
9670 rte_free(ethertype_filter);
9672 ret = i40e_sw_ethertype_filter_del(pf, &node->input);
9679 * Handle operations for ethertype filter.
9682 i40e_ethertype_filter_handle(struct rte_eth_dev *dev,
9683 enum rte_filter_op filter_op,
9686 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
9689 if (filter_op == RTE_ETH_FILTER_NOP)
9693 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
9698 switch (filter_op) {
9699 case RTE_ETH_FILTER_ADD:
9700 ret = i40e_ethertype_filter_set(pf,
9701 (struct rte_eth_ethertype_filter *)arg,
9704 case RTE_ETH_FILTER_DELETE:
9705 ret = i40e_ethertype_filter_set(pf,
9706 (struct rte_eth_ethertype_filter *)arg,
9710 PMD_DRV_LOG(ERR, "unsupported operation %u", filter_op);
9718 i40e_dev_filter_ctrl(struct rte_eth_dev *dev,
9719 enum rte_filter_type filter_type,
9720 enum rte_filter_op filter_op,
9728 switch (filter_type) {
9729 case RTE_ETH_FILTER_NONE:
9730 /* For global configuration */
9731 ret = i40e_filter_ctrl_global_config(dev, filter_op, arg);
9733 case RTE_ETH_FILTER_HASH:
9734 ret = i40e_hash_filter_ctrl(dev, filter_op, arg);
9736 case RTE_ETH_FILTER_MACVLAN:
9737 ret = i40e_mac_filter_handle(dev, filter_op, arg);
9739 case RTE_ETH_FILTER_ETHERTYPE:
9740 ret = i40e_ethertype_filter_handle(dev, filter_op, arg);
9742 case RTE_ETH_FILTER_TUNNEL:
9743 ret = i40e_tunnel_filter_handle(dev, filter_op, arg);
9745 case RTE_ETH_FILTER_FDIR:
9746 ret = i40e_fdir_ctrl_func(dev, filter_op, arg);
9748 case RTE_ETH_FILTER_GENERIC:
9749 if (filter_op != RTE_ETH_FILTER_GET)
9751 *(const void **)arg = &i40e_flow_ops;
9754 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
9764 * Check and enable Extended Tag.
9765 * Enabling Extended Tag is important for 40G performance.
9768 i40e_enable_extended_tag(struct rte_eth_dev *dev)
9770 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
9774 ret = rte_pci_read_config(pci_dev, &buf, sizeof(buf),
9777 PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
9781 if (!(buf & PCI_DEV_CAP_EXT_TAG_MASK)) {
9782 PMD_DRV_LOG(ERR, "Does not support Extended Tag");
9787 ret = rte_pci_read_config(pci_dev, &buf, sizeof(buf),
9790 PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
9794 if (buf & PCI_DEV_CTRL_EXT_TAG_MASK) {
9795 PMD_DRV_LOG(DEBUG, "Extended Tag has already been enabled");
9798 buf |= PCI_DEV_CTRL_EXT_TAG_MASK;
9799 ret = rte_pci_write_config(pci_dev, &buf, sizeof(buf),
9802 PMD_DRV_LOG(ERR, "Failed to write PCI offset 0x%x",
9809 * As some registers wouldn't be reset unless a global hardware reset,
9810 * hardware initialization is needed to put those registers into an
9811 * expected initial state.
9814 i40e_hw_init(struct rte_eth_dev *dev)
9816 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
9818 i40e_enable_extended_tag(dev);
9820 /* clear the PF Queue Filter control register */
9821 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, 0);
9823 /* Disable symmetric hash per port */
9824 i40e_set_symmetric_hash_enable_per_port(hw, 0);
9828 * For X722 it is possible to have multiple pctypes mapped to the same flowtype
9829 * however this function will return only one highest pctype index,
9830 * which is not quite correct. This is known problem of i40e driver
9831 * and needs to be fixed later.
9833 enum i40e_filter_pctype
9834 i40e_flowtype_to_pctype(const struct i40e_adapter *adapter, uint16_t flow_type)
9837 uint64_t pctype_mask;
9839 if (flow_type < I40E_FLOW_TYPE_MAX) {
9840 pctype_mask = adapter->pctypes_tbl[flow_type];
9841 for (i = I40E_FILTER_PCTYPE_MAX - 1; i > 0; i--) {
9842 if (pctype_mask & (1ULL << i))
9843 return (enum i40e_filter_pctype)i;
9846 return I40E_FILTER_PCTYPE_INVALID;
9850 i40e_pctype_to_flowtype(const struct i40e_adapter *adapter,
9851 enum i40e_filter_pctype pctype)
9854 uint64_t pctype_mask = 1ULL << pctype;
9856 for (flowtype = RTE_ETH_FLOW_UNKNOWN + 1; flowtype < I40E_FLOW_TYPE_MAX;
9858 if (adapter->pctypes_tbl[flowtype] & pctype_mask)
9862 return RTE_ETH_FLOW_UNKNOWN;
9866 * On X710, performance number is far from the expectation on recent firmware
9867 * versions; on XL710, performance number is also far from the expectation on
9868 * recent firmware versions, if promiscuous mode is disabled, or promiscuous
9869 * mode is enabled and port MAC address is equal to the packet destination MAC
9870 * address. The fix for this issue may not be integrated in the following
9871 * firmware version. So the workaround in software driver is needed. It needs
9872 * to modify the initial values of 3 internal only registers for both X710 and
9873 * XL710. Note that the values for X710 or XL710 could be different, and the
9874 * workaround can be removed when it is fixed in firmware in the future.
9877 /* For both X710 and XL710 */
9878 #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1 0x10000200
9879 #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2 0x203F0200
9880 #define I40E_GL_SWR_PRI_JOIN_MAP_0 0x26CE00
9882 #define I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x011f0200
9883 #define I40E_GL_SWR_PRI_JOIN_MAP_2 0x26CE08
9886 #define I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE 0x20000200
9887 #define I40E_X722_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x013F0200
9890 #define I40E_GL_SWR_PM_UP_THR_EF_VALUE 0x03030303
9892 #define I40E_GL_SWR_PM_UP_THR_SF_VALUE 0x06060606
9893 #define I40E_GL_SWR_PM_UP_THR 0x269FBC
9896 i40e_dev_sync_phy_type(struct i40e_hw *hw)
9898 enum i40e_status_code status;
9899 struct i40e_aq_get_phy_abilities_resp phy_ab;
9903 status = i40e_aq_get_phy_capabilities(hw, false, true, &phy_ab,
9907 PMD_INIT_LOG(WARNING, "Failed to sync phy type: status=%d",
9910 rte_delay_us(100000);
9912 status = i40e_aq_get_phy_capabilities(hw, false,
9913 true, &phy_ab, NULL);
9921 i40e_configure_registers(struct i40e_hw *hw)
9927 {I40E_GL_SWR_PRI_JOIN_MAP_0, 0},
9928 {I40E_GL_SWR_PRI_JOIN_MAP_2, 0},
9929 {I40E_GL_SWR_PM_UP_THR, 0}, /* Compute value dynamically */
9935 for (i = 0; i < RTE_DIM(reg_table); i++) {
9936 if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_0) {
9937 if (hw->mac.type == I40E_MAC_X722) /* For X722 */
9939 I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE;
9940 else /* For X710/XL710/XXV710 */
9941 if (hw->aq.fw_maj_ver < 6)
9943 I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1;
9946 I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2;
9949 if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_2) {
9950 if (hw->mac.type == I40E_MAC_X722) /* For X722 */
9952 I40E_X722_GL_SWR_PRI_JOIN_MAP_2_VALUE;
9953 else /* For X710/XL710/XXV710 */
9955 I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE;
9958 if (reg_table[i].addr == I40E_GL_SWR_PM_UP_THR) {
9959 if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types) || /* For XL710 */
9960 I40E_PHY_TYPE_SUPPORT_25G(hw->phy.phy_types)) /* For XXV710 */
9962 I40E_GL_SWR_PM_UP_THR_SF_VALUE;
9965 I40E_GL_SWR_PM_UP_THR_EF_VALUE;
9968 ret = i40e_aq_debug_read_register(hw, reg_table[i].addr,
9971 PMD_DRV_LOG(ERR, "Failed to read from 0x%"PRIx32,
9975 PMD_DRV_LOG(DEBUG, "Read from 0x%"PRIx32": 0x%"PRIx64,
9976 reg_table[i].addr, reg);
9977 if (reg == reg_table[i].val)
9980 ret = i40e_aq_debug_write_register(hw, reg_table[i].addr,
9981 reg_table[i].val, NULL);
9984 "Failed to write 0x%"PRIx64" to the address of 0x%"PRIx32,
9985 reg_table[i].val, reg_table[i].addr);
9988 PMD_DRV_LOG(DEBUG, "Write 0x%"PRIx64" to the address of "
9989 "0x%"PRIx32, reg_table[i].val, reg_table[i].addr);
9993 #define I40E_VSI_TSR(_i) (0x00050800 + ((_i) * 4))
9994 #define I40E_VSI_TSR_QINQ_CONFIG 0xc030
9995 #define I40E_VSI_L2TAGSTXVALID(_i) (0x00042800 + ((_i) * 4))
9996 #define I40E_VSI_L2TAGSTXVALID_QINQ 0xab
9998 i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi)
10003 if (vsi->vsi_id >= I40E_MAX_NUM_VSIS) {
10004 PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
10008 /* Configure for double VLAN RX stripping */
10009 reg = I40E_READ_REG(hw, I40E_VSI_TSR(vsi->vsi_id));
10010 if ((reg & I40E_VSI_TSR_QINQ_CONFIG) != I40E_VSI_TSR_QINQ_CONFIG) {
10011 reg |= I40E_VSI_TSR_QINQ_CONFIG;
10012 ret = i40e_aq_debug_write_register(hw,
10013 I40E_VSI_TSR(vsi->vsi_id),
10016 PMD_DRV_LOG(ERR, "Failed to update VSI_TSR[%d]",
10018 return I40E_ERR_CONFIG;
10022 /* Configure for double VLAN TX insertion */
10023 reg = I40E_READ_REG(hw, I40E_VSI_L2TAGSTXVALID(vsi->vsi_id));
10024 if ((reg & 0xff) != I40E_VSI_L2TAGSTXVALID_QINQ) {
10025 reg = I40E_VSI_L2TAGSTXVALID_QINQ;
10026 ret = i40e_aq_debug_write_register(hw,
10027 I40E_VSI_L2TAGSTXVALID(
10028 vsi->vsi_id), reg, NULL);
10031 "Failed to update VSI_L2TAGSTXVALID[%d]",
10033 return I40E_ERR_CONFIG;
10041 * i40e_aq_add_mirror_rule
10042 * @hw: pointer to the hardware structure
10043 * @seid: VEB seid to add mirror rule to
10044 * @dst_id: destination vsi seid
10045 * @entries: Buffer which contains the entities to be mirrored
10046 * @count: number of entities contained in the buffer
10047 * @rule_id:the rule_id of the rule to be added
10049 * Add a mirror rule for a given veb.
10052 static enum i40e_status_code
10053 i40e_aq_add_mirror_rule(struct i40e_hw *hw,
10054 uint16_t seid, uint16_t dst_id,
10055 uint16_t rule_type, uint16_t *entries,
10056 uint16_t count, uint16_t *rule_id)
10058 struct i40e_aq_desc desc;
10059 struct i40e_aqc_add_delete_mirror_rule cmd;
10060 struct i40e_aqc_add_delete_mirror_rule_completion *resp =
10061 (struct i40e_aqc_add_delete_mirror_rule_completion *)
10064 enum i40e_status_code status;
10066 i40e_fill_default_direct_cmd_desc(&desc,
10067 i40e_aqc_opc_add_mirror_rule);
10068 memset(&cmd, 0, sizeof(cmd));
10070 buff_len = sizeof(uint16_t) * count;
10071 desc.datalen = rte_cpu_to_le_16(buff_len);
10073 desc.flags |= rte_cpu_to_le_16(
10074 (uint16_t)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
10075 cmd.rule_type = rte_cpu_to_le_16(rule_type <<
10076 I40E_AQC_MIRROR_RULE_TYPE_SHIFT);
10077 cmd.num_entries = rte_cpu_to_le_16(count);
10078 cmd.seid = rte_cpu_to_le_16(seid);
10079 cmd.destination = rte_cpu_to_le_16(dst_id);
10081 rte_memcpy(&desc.params.raw, &cmd, sizeof(cmd));
10082 status = i40e_asq_send_command(hw, &desc, entries, buff_len, NULL);
10084 "i40e_aq_add_mirror_rule, aq_status %d, rule_id = %u mirror_rules_used = %u, mirror_rules_free = %u,",
10085 hw->aq.asq_last_status, resp->rule_id,
10086 resp->mirror_rules_used, resp->mirror_rules_free);
10087 *rule_id = rte_le_to_cpu_16(resp->rule_id);
10093 * i40e_aq_del_mirror_rule
10094 * @hw: pointer to the hardware structure
10095 * @seid: VEB seid to add mirror rule to
10096 * @entries: Buffer which contains the entities to be mirrored
10097 * @count: number of entities contained in the buffer
10098 * @rule_id:the rule_id of the rule to be delete
10100 * Delete a mirror rule for a given veb.
10103 static enum i40e_status_code
10104 i40e_aq_del_mirror_rule(struct i40e_hw *hw,
10105 uint16_t seid, uint16_t rule_type, uint16_t *entries,
10106 uint16_t count, uint16_t rule_id)
10108 struct i40e_aq_desc desc;
10109 struct i40e_aqc_add_delete_mirror_rule cmd;
10110 uint16_t buff_len = 0;
10111 enum i40e_status_code status;
10114 i40e_fill_default_direct_cmd_desc(&desc,
10115 i40e_aqc_opc_delete_mirror_rule);
10116 memset(&cmd, 0, sizeof(cmd));
10117 if (rule_type == I40E_AQC_MIRROR_RULE_TYPE_VLAN) {
10118 desc.flags |= rte_cpu_to_le_16((uint16_t)(I40E_AQ_FLAG_BUF |
10120 cmd.num_entries = count;
10121 buff_len = sizeof(uint16_t) * count;
10122 desc.datalen = rte_cpu_to_le_16(buff_len);
10123 buff = (void *)entries;
10125 /* rule id is filled in destination field for deleting mirror rule */
10126 cmd.destination = rte_cpu_to_le_16(rule_id);
10128 cmd.rule_type = rte_cpu_to_le_16(rule_type <<
10129 I40E_AQC_MIRROR_RULE_TYPE_SHIFT);
10130 cmd.seid = rte_cpu_to_le_16(seid);
10132 rte_memcpy(&desc.params.raw, &cmd, sizeof(cmd));
10133 status = i40e_asq_send_command(hw, &desc, buff, buff_len, NULL);
10139 * i40e_mirror_rule_set
10140 * @dev: pointer to the hardware structure
10141 * @mirror_conf: mirror rule info
10142 * @sw_id: mirror rule's sw_id
10143 * @on: enable/disable
10145 * set a mirror rule.
10149 i40e_mirror_rule_set(struct rte_eth_dev *dev,
10150 struct rte_eth_mirror_conf *mirror_conf,
10151 uint8_t sw_id, uint8_t on)
10153 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
10154 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10155 struct i40e_mirror_rule *it, *mirr_rule = NULL;
10156 struct i40e_mirror_rule *parent = NULL;
10157 uint16_t seid, dst_seid, rule_id;
10161 PMD_DRV_LOG(DEBUG, "i40e_mirror_rule_set: sw_id = %d.", sw_id);
10163 if (pf->main_vsi->veb == NULL || pf->vfs == NULL) {
10165 "mirror rule can not be configured without veb or vfs.");
10168 if (pf->nb_mirror_rule > I40E_MAX_MIRROR_RULES) {
10169 PMD_DRV_LOG(ERR, "mirror table is full.");
10172 if (mirror_conf->dst_pool > pf->vf_num) {
10173 PMD_DRV_LOG(ERR, "invalid destination pool %u.",
10174 mirror_conf->dst_pool);
10178 seid = pf->main_vsi->veb->seid;
10180 TAILQ_FOREACH(it, &pf->mirror_list, rules) {
10181 if (sw_id <= it->index) {
10187 if (mirr_rule && sw_id == mirr_rule->index) {
10189 PMD_DRV_LOG(ERR, "mirror rule exists.");
10192 ret = i40e_aq_del_mirror_rule(hw, seid,
10193 mirr_rule->rule_type,
10194 mirr_rule->entries,
10195 mirr_rule->num_entries, mirr_rule->id);
10198 "failed to remove mirror rule: ret = %d, aq_err = %d.",
10199 ret, hw->aq.asq_last_status);
10202 TAILQ_REMOVE(&pf->mirror_list, mirr_rule, rules);
10203 rte_free(mirr_rule);
10204 pf->nb_mirror_rule--;
10208 PMD_DRV_LOG(ERR, "mirror rule doesn't exist.");
10212 mirr_rule = rte_zmalloc("i40e_mirror_rule",
10213 sizeof(struct i40e_mirror_rule) , 0);
10215 PMD_DRV_LOG(ERR, "failed to allocate memory");
10216 return I40E_ERR_NO_MEMORY;
10218 switch (mirror_conf->rule_type) {
10219 case ETH_MIRROR_VLAN:
10220 for (i = 0, j = 0; i < ETH_MIRROR_MAX_VLANS; i++) {
10221 if (mirror_conf->vlan.vlan_mask & (1ULL << i)) {
10222 mirr_rule->entries[j] =
10223 mirror_conf->vlan.vlan_id[i];
10228 PMD_DRV_LOG(ERR, "vlan is not specified.");
10229 rte_free(mirr_rule);
10232 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_VLAN;
10234 case ETH_MIRROR_VIRTUAL_POOL_UP:
10235 case ETH_MIRROR_VIRTUAL_POOL_DOWN:
10236 /* check if the specified pool bit is out of range */
10237 if (mirror_conf->pool_mask > (uint64_t)(1ULL << (pf->vf_num + 1))) {
10238 PMD_DRV_LOG(ERR, "pool mask is out of range.");
10239 rte_free(mirr_rule);
10242 for (i = 0, j = 0; i < pf->vf_num; i++) {
10243 if (mirror_conf->pool_mask & (1ULL << i)) {
10244 mirr_rule->entries[j] = pf->vfs[i].vsi->seid;
10248 if (mirror_conf->pool_mask & (1ULL << pf->vf_num)) {
10249 /* add pf vsi to entries */
10250 mirr_rule->entries[j] = pf->main_vsi_seid;
10254 PMD_DRV_LOG(ERR, "pool is not specified.");
10255 rte_free(mirr_rule);
10258 /* egress and ingress in aq commands means from switch but not port */
10259 mirr_rule->rule_type =
10260 (mirror_conf->rule_type == ETH_MIRROR_VIRTUAL_POOL_UP) ?
10261 I40E_AQC_MIRROR_RULE_TYPE_VPORT_EGRESS :
10262 I40E_AQC_MIRROR_RULE_TYPE_VPORT_INGRESS;
10264 case ETH_MIRROR_UPLINK_PORT:
10265 /* egress and ingress in aq commands means from switch but not port*/
10266 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_ALL_EGRESS;
10268 case ETH_MIRROR_DOWNLINK_PORT:
10269 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_ALL_INGRESS;
10272 PMD_DRV_LOG(ERR, "unsupported mirror type %d.",
10273 mirror_conf->rule_type);
10274 rte_free(mirr_rule);
10278 /* If the dst_pool is equal to vf_num, consider it as PF */
10279 if (mirror_conf->dst_pool == pf->vf_num)
10280 dst_seid = pf->main_vsi_seid;
10282 dst_seid = pf->vfs[mirror_conf->dst_pool].vsi->seid;
10284 ret = i40e_aq_add_mirror_rule(hw, seid, dst_seid,
10285 mirr_rule->rule_type, mirr_rule->entries,
10289 "failed to add mirror rule: ret = %d, aq_err = %d.",
10290 ret, hw->aq.asq_last_status);
10291 rte_free(mirr_rule);
10295 mirr_rule->index = sw_id;
10296 mirr_rule->num_entries = j;
10297 mirr_rule->id = rule_id;
10298 mirr_rule->dst_vsi_seid = dst_seid;
10301 TAILQ_INSERT_AFTER(&pf->mirror_list, parent, mirr_rule, rules);
10303 TAILQ_INSERT_HEAD(&pf->mirror_list, mirr_rule, rules);
10305 pf->nb_mirror_rule++;
10310 * i40e_mirror_rule_reset
10311 * @dev: pointer to the device
10312 * @sw_id: mirror rule's sw_id
10314 * reset a mirror rule.
10318 i40e_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t sw_id)
10320 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
10321 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10322 struct i40e_mirror_rule *it, *mirr_rule = NULL;
10326 PMD_DRV_LOG(DEBUG, "i40e_mirror_rule_reset: sw_id = %d.", sw_id);
10328 seid = pf->main_vsi->veb->seid;
10330 TAILQ_FOREACH(it, &pf->mirror_list, rules) {
10331 if (sw_id == it->index) {
10337 ret = i40e_aq_del_mirror_rule(hw, seid,
10338 mirr_rule->rule_type,
10339 mirr_rule->entries,
10340 mirr_rule->num_entries, mirr_rule->id);
10343 "failed to remove mirror rule: status = %d, aq_err = %d.",
10344 ret, hw->aq.asq_last_status);
10347 TAILQ_REMOVE(&pf->mirror_list, mirr_rule, rules);
10348 rte_free(mirr_rule);
10349 pf->nb_mirror_rule--;
10351 PMD_DRV_LOG(ERR, "mirror rule doesn't exist.");
10358 i40e_read_systime_cyclecounter(struct rte_eth_dev *dev)
10360 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10361 uint64_t systim_cycles;
10363 systim_cycles = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_L);
10364 systim_cycles |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_H)
10367 return systim_cycles;
10371 i40e_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev, uint8_t index)
10373 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10374 uint64_t rx_tstamp;
10376 rx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_L(index));
10377 rx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(index))
10384 i40e_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
10386 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10387 uint64_t tx_tstamp;
10389 tx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_L);
10390 tx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H)
10397 i40e_start_timecounters(struct rte_eth_dev *dev)
10399 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10400 struct i40e_adapter *adapter =
10401 (struct i40e_adapter *)dev->data->dev_private;
10402 struct rte_eth_link link;
10403 uint32_t tsync_inc_l;
10404 uint32_t tsync_inc_h;
10406 /* Get current link speed. */
10407 i40e_dev_link_update(dev, 1);
10408 rte_eth_linkstatus_get(dev, &link);
10410 switch (link.link_speed) {
10411 case ETH_SPEED_NUM_40G:
10412 tsync_inc_l = I40E_PTP_40GB_INCVAL & 0xFFFFFFFF;
10413 tsync_inc_h = I40E_PTP_40GB_INCVAL >> 32;
10415 case ETH_SPEED_NUM_10G:
10416 tsync_inc_l = I40E_PTP_10GB_INCVAL & 0xFFFFFFFF;
10417 tsync_inc_h = I40E_PTP_10GB_INCVAL >> 32;
10419 case ETH_SPEED_NUM_1G:
10420 tsync_inc_l = I40E_PTP_1GB_INCVAL & 0xFFFFFFFF;
10421 tsync_inc_h = I40E_PTP_1GB_INCVAL >> 32;
10428 /* Set the timesync increment value. */
10429 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, tsync_inc_l);
10430 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, tsync_inc_h);
10432 memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
10433 memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
10434 memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
10436 adapter->systime_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10437 adapter->systime_tc.cc_shift = 0;
10438 adapter->systime_tc.nsec_mask = 0;
10440 adapter->rx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10441 adapter->rx_tstamp_tc.cc_shift = 0;
10442 adapter->rx_tstamp_tc.nsec_mask = 0;
10444 adapter->tx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10445 adapter->tx_tstamp_tc.cc_shift = 0;
10446 adapter->tx_tstamp_tc.nsec_mask = 0;
10450 i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
10452 struct i40e_adapter *adapter =
10453 (struct i40e_adapter *)dev->data->dev_private;
10455 adapter->systime_tc.nsec += delta;
10456 adapter->rx_tstamp_tc.nsec += delta;
10457 adapter->tx_tstamp_tc.nsec += delta;
10463 i40e_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
10466 struct i40e_adapter *adapter =
10467 (struct i40e_adapter *)dev->data->dev_private;
10469 ns = rte_timespec_to_ns(ts);
10471 /* Set the timecounters to a new value. */
10472 adapter->systime_tc.nsec = ns;
10473 adapter->rx_tstamp_tc.nsec = ns;
10474 adapter->tx_tstamp_tc.nsec = ns;
10480 i40e_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
10482 uint64_t ns, systime_cycles;
10483 struct i40e_adapter *adapter =
10484 (struct i40e_adapter *)dev->data->dev_private;
10486 systime_cycles = i40e_read_systime_cyclecounter(dev);
10487 ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
10488 *ts = rte_ns_to_timespec(ns);
10494 i40e_timesync_enable(struct rte_eth_dev *dev)
10496 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10497 uint32_t tsync_ctl_l;
10498 uint32_t tsync_ctl_h;
10500 /* Stop the timesync system time. */
10501 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
10502 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
10503 /* Reset the timesync system time value. */
10504 I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_L, 0x0);
10505 I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_H, 0x0);
10507 i40e_start_timecounters(dev);
10509 /* Clear timesync registers. */
10510 I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
10511 I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H);
10512 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(0));
10513 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(1));
10514 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(2));
10515 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(3));
10517 /* Enable timestamping of PTP packets. */
10518 tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
10519 tsync_ctl_l |= I40E_PRTTSYN_TSYNENA;
10521 tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
10522 tsync_ctl_h |= I40E_PRTTSYN_TSYNENA;
10523 tsync_ctl_h |= I40E_PRTTSYN_TSYNTYPE;
10525 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
10526 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
10532 i40e_timesync_disable(struct rte_eth_dev *dev)
10534 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10535 uint32_t tsync_ctl_l;
10536 uint32_t tsync_ctl_h;
10538 /* Disable timestamping of transmitted PTP packets. */
10539 tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
10540 tsync_ctl_l &= ~I40E_PRTTSYN_TSYNENA;
10542 tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
10543 tsync_ctl_h &= ~I40E_PRTTSYN_TSYNENA;
10545 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
10546 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
10548 /* Reset the timesync increment value. */
10549 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
10550 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
10556 i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
10557 struct timespec *timestamp, uint32_t flags)
10559 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10560 struct i40e_adapter *adapter =
10561 (struct i40e_adapter *)dev->data->dev_private;
10563 uint32_t sync_status;
10564 uint32_t index = flags & 0x03;
10565 uint64_t rx_tstamp_cycles;
10568 sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_1);
10569 if ((sync_status & (1 << index)) == 0)
10572 rx_tstamp_cycles = i40e_read_rx_tstamp_cyclecounter(dev, index);
10573 ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
10574 *timestamp = rte_ns_to_timespec(ns);
10580 i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
10581 struct timespec *timestamp)
10583 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10584 struct i40e_adapter *adapter =
10585 (struct i40e_adapter *)dev->data->dev_private;
10587 uint32_t sync_status;
10588 uint64_t tx_tstamp_cycles;
10591 sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
10592 if ((sync_status & I40E_PRTTSYN_STAT_0_TXTIME_MASK) == 0)
10595 tx_tstamp_cycles = i40e_read_tx_tstamp_cyclecounter(dev);
10596 ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
10597 *timestamp = rte_ns_to_timespec(ns);
10603 * i40e_parse_dcb_configure - parse dcb configure from user
10604 * @dev: the device being configured
10605 * @dcb_cfg: pointer of the result of parse
10606 * @*tc_map: bit map of enabled traffic classes
10608 * Returns 0 on success, negative value on failure
10611 i40e_parse_dcb_configure(struct rte_eth_dev *dev,
10612 struct i40e_dcbx_config *dcb_cfg,
10615 struct rte_eth_dcb_rx_conf *dcb_rx_conf;
10616 uint8_t i, tc_bw, bw_lf;
10618 memset(dcb_cfg, 0, sizeof(struct i40e_dcbx_config));
10620 dcb_rx_conf = &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
10621 if (dcb_rx_conf->nb_tcs > I40E_MAX_TRAFFIC_CLASS) {
10622 PMD_INIT_LOG(ERR, "number of tc exceeds max.");
10626 /* assume each tc has the same bw */
10627 tc_bw = I40E_MAX_PERCENT / dcb_rx_conf->nb_tcs;
10628 for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
10629 dcb_cfg->etscfg.tcbwtable[i] = tc_bw;
10630 /* to ensure the sum of tcbw is equal to 100 */
10631 bw_lf = I40E_MAX_PERCENT % dcb_rx_conf->nb_tcs;
10632 for (i = 0; i < bw_lf; i++)
10633 dcb_cfg->etscfg.tcbwtable[i]++;
10635 /* assume each tc has the same Transmission Selection Algorithm */
10636 for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
10637 dcb_cfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
10639 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
10640 dcb_cfg->etscfg.prioritytable[i] =
10641 dcb_rx_conf->dcb_tc[i];
10643 /* FW needs one App to configure HW */
10644 dcb_cfg->numapps = I40E_DEFAULT_DCB_APP_NUM;
10645 dcb_cfg->app[0].selector = I40E_APP_SEL_ETHTYPE;
10646 dcb_cfg->app[0].priority = I40E_DEFAULT_DCB_APP_PRIO;
10647 dcb_cfg->app[0].protocolid = I40E_APP_PROTOID_FCOE;
10649 if (dcb_rx_conf->nb_tcs == 0)
10650 *tc_map = 1; /* tc0 only */
10652 *tc_map = RTE_LEN2MASK(dcb_rx_conf->nb_tcs, uint8_t);
10654 if (dev->data->dev_conf.dcb_capability_en & ETH_DCB_PFC_SUPPORT) {
10655 dcb_cfg->pfc.willing = 0;
10656 dcb_cfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
10657 dcb_cfg->pfc.pfcenable = *tc_map;
10663 static enum i40e_status_code
10664 i40e_vsi_update_queue_mapping(struct i40e_vsi *vsi,
10665 struct i40e_aqc_vsi_properties_data *info,
10666 uint8_t enabled_tcmap)
10668 enum i40e_status_code ret;
10669 int i, total_tc = 0;
10670 uint16_t qpnum_per_tc, bsf, qp_idx;
10671 struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(vsi);
10672 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
10673 uint16_t used_queues;
10675 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
10676 if (ret != I40E_SUCCESS)
10679 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10680 if (enabled_tcmap & (1 << i))
10685 vsi->enabled_tc = enabled_tcmap;
10687 /* different VSI has different queues assigned */
10688 if (vsi->type == I40E_VSI_MAIN)
10689 used_queues = dev_data->nb_rx_queues -
10690 pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
10691 else if (vsi->type == I40E_VSI_VMDQ2)
10692 used_queues = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
10694 PMD_INIT_LOG(ERR, "unsupported VSI type.");
10695 return I40E_ERR_NO_AVAILABLE_VSI;
10698 qpnum_per_tc = used_queues / total_tc;
10699 /* Number of queues per enabled TC */
10700 if (qpnum_per_tc == 0) {
10701 PMD_INIT_LOG(ERR, " number of queues is less that tcs.");
10702 return I40E_ERR_INVALID_QP_ID;
10704 qpnum_per_tc = RTE_MIN(i40e_align_floor(qpnum_per_tc),
10705 I40E_MAX_Q_PER_TC);
10706 bsf = rte_bsf32(qpnum_per_tc);
10709 * Configure TC and queue mapping parameters, for enabled TC,
10710 * allocate qpnum_per_tc queues to this traffic. For disabled TC,
10711 * default queue will serve it.
10714 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10715 if (vsi->enabled_tc & (1 << i)) {
10716 info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
10717 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
10718 (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
10719 qp_idx += qpnum_per_tc;
10721 info->tc_mapping[i] = 0;
10724 /* Associate queue number with VSI, Keep vsi->nb_qps unchanged */
10725 if (vsi->type == I40E_VSI_SRIOV) {
10726 info->mapping_flags |=
10727 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
10728 for (i = 0; i < vsi->nb_qps; i++)
10729 info->queue_mapping[i] =
10730 rte_cpu_to_le_16(vsi->base_queue + i);
10732 info->mapping_flags |=
10733 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
10734 info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
10736 info->valid_sections |=
10737 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
10739 return I40E_SUCCESS;
10743 * i40e_config_switch_comp_tc - Configure VEB tc setting for given TC map
10744 * @veb: VEB to be configured
10745 * @tc_map: enabled TC bitmap
10747 * Returns 0 on success, negative value on failure
10749 static enum i40e_status_code
10750 i40e_config_switch_comp_tc(struct i40e_veb *veb, uint8_t tc_map)
10752 struct i40e_aqc_configure_switching_comp_bw_config_data veb_bw;
10753 struct i40e_aqc_query_switching_comp_bw_config_resp bw_query;
10754 struct i40e_aqc_query_switching_comp_ets_config_resp ets_query;
10755 struct i40e_hw *hw = I40E_VSI_TO_HW(veb->associate_vsi);
10756 enum i40e_status_code ret = I40E_SUCCESS;
10760 /* Check if enabled_tc is same as existing or new TCs */
10761 if (veb->enabled_tc == tc_map)
10764 /* configure tc bandwidth */
10765 memset(&veb_bw, 0, sizeof(veb_bw));
10766 veb_bw.tc_valid_bits = tc_map;
10767 /* Enable ETS TCs with equal BW Share for now across all VSIs */
10768 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10769 if (tc_map & BIT_ULL(i))
10770 veb_bw.tc_bw_share_credits[i] = 1;
10772 ret = i40e_aq_config_switch_comp_bw_config(hw, veb->seid,
10776 "AQ command Config switch_comp BW allocation per TC failed = %d",
10777 hw->aq.asq_last_status);
10781 memset(&ets_query, 0, sizeof(ets_query));
10782 ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
10784 if (ret != I40E_SUCCESS) {
10786 "Failed to get switch_comp ETS configuration %u",
10787 hw->aq.asq_last_status);
10790 memset(&bw_query, 0, sizeof(bw_query));
10791 ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
10793 if (ret != I40E_SUCCESS) {
10795 "Failed to get switch_comp bandwidth configuration %u",
10796 hw->aq.asq_last_status);
10800 /* store and print out BW info */
10801 veb->bw_info.bw_limit = rte_le_to_cpu_16(ets_query.port_bw_limit);
10802 veb->bw_info.bw_max = ets_query.tc_bw_max;
10803 PMD_DRV_LOG(DEBUG, "switch_comp bw limit:%u", veb->bw_info.bw_limit);
10804 PMD_DRV_LOG(DEBUG, "switch_comp max_bw:%u", veb->bw_info.bw_max);
10805 bw_max = rte_le_to_cpu_16(bw_query.tc_bw_max[0]) |
10806 (rte_le_to_cpu_16(bw_query.tc_bw_max[1]) <<
10807 I40E_16_BIT_WIDTH);
10808 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10809 veb->bw_info.bw_ets_share_credits[i] =
10810 bw_query.tc_bw_share_credits[i];
10811 veb->bw_info.bw_ets_credits[i] =
10812 rte_le_to_cpu_16(bw_query.tc_bw_limits[i]);
10813 /* 4 bits per TC, 4th bit is reserved */
10814 veb->bw_info.bw_ets_max[i] =
10815 (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
10816 RTE_LEN2MASK(3, uint8_t));
10817 PMD_DRV_LOG(DEBUG, "\tVEB TC%u:share credits %u", i,
10818 veb->bw_info.bw_ets_share_credits[i]);
10819 PMD_DRV_LOG(DEBUG, "\tVEB TC%u:credits %u", i,
10820 veb->bw_info.bw_ets_credits[i]);
10821 PMD_DRV_LOG(DEBUG, "\tVEB TC%u: max credits: %u", i,
10822 veb->bw_info.bw_ets_max[i]);
10825 veb->enabled_tc = tc_map;
10832 * i40e_vsi_config_tc - Configure VSI tc setting for given TC map
10833 * @vsi: VSI to be configured
10834 * @tc_map: enabled TC bitmap
10836 * Returns 0 on success, negative value on failure
10838 static enum i40e_status_code
10839 i40e_vsi_config_tc(struct i40e_vsi *vsi, uint8_t tc_map)
10841 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
10842 struct i40e_vsi_context ctxt;
10843 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
10844 enum i40e_status_code ret = I40E_SUCCESS;
10847 /* Check if enabled_tc is same as existing or new TCs */
10848 if (vsi->enabled_tc == tc_map)
10851 /* configure tc bandwidth */
10852 memset(&bw_data, 0, sizeof(bw_data));
10853 bw_data.tc_valid_bits = tc_map;
10854 /* Enable ETS TCs with equal BW Share for now across all VSIs */
10855 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10856 if (tc_map & BIT_ULL(i))
10857 bw_data.tc_bw_credits[i] = 1;
10859 ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &bw_data, NULL);
10862 "AQ command Config VSI BW allocation per TC failed = %d",
10863 hw->aq.asq_last_status);
10866 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
10867 vsi->info.qs_handle[i] = bw_data.qs_handles[i];
10869 /* Update Queue Pairs Mapping for currently enabled UPs */
10870 ctxt.seid = vsi->seid;
10871 ctxt.pf_num = hw->pf_id;
10873 ctxt.uplink_seid = vsi->uplink_seid;
10874 ctxt.info = vsi->info;
10876 ret = i40e_vsi_update_queue_mapping(vsi, &ctxt.info, tc_map);
10880 /* Update the VSI after updating the VSI queue-mapping information */
10881 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
10883 PMD_INIT_LOG(ERR, "Failed to configure TC queue mapping = %d",
10884 hw->aq.asq_last_status);
10887 /* update the local VSI info with updated queue map */
10888 rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
10889 sizeof(vsi->info.tc_mapping));
10890 rte_memcpy(&vsi->info.queue_mapping,
10891 &ctxt.info.queue_mapping,
10892 sizeof(vsi->info.queue_mapping));
10893 vsi->info.mapping_flags = ctxt.info.mapping_flags;
10894 vsi->info.valid_sections = 0;
10896 /* query and update current VSI BW information */
10897 ret = i40e_vsi_get_bw_config(vsi);
10900 "Failed updating vsi bw info, err %s aq_err %s",
10901 i40e_stat_str(hw, ret),
10902 i40e_aq_str(hw, hw->aq.asq_last_status));
10906 vsi->enabled_tc = tc_map;
10913 * i40e_dcb_hw_configure - program the dcb setting to hw
10914 * @pf: pf the configuration is taken on
10915 * @new_cfg: new configuration
10916 * @tc_map: enabled TC bitmap
10918 * Returns 0 on success, negative value on failure
10920 static enum i40e_status_code
10921 i40e_dcb_hw_configure(struct i40e_pf *pf,
10922 struct i40e_dcbx_config *new_cfg,
10925 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
10926 struct i40e_dcbx_config *old_cfg = &hw->local_dcbx_config;
10927 struct i40e_vsi *main_vsi = pf->main_vsi;
10928 struct i40e_vsi_list *vsi_list;
10929 enum i40e_status_code ret;
10933 /* Use the FW API if FW > v4.4*/
10934 if (!(((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver >= 4)) ||
10935 (hw->aq.fw_maj_ver >= 5))) {
10937 "FW < v4.4, can not use FW LLDP API to configure DCB");
10938 return I40E_ERR_FIRMWARE_API_VERSION;
10941 /* Check if need reconfiguration */
10942 if (!memcmp(new_cfg, old_cfg, sizeof(struct i40e_dcbx_config))) {
10943 PMD_INIT_LOG(ERR, "No Change in DCB Config required.");
10944 return I40E_SUCCESS;
10947 /* Copy the new config to the current config */
10948 *old_cfg = *new_cfg;
10949 old_cfg->etsrec = old_cfg->etscfg;
10950 ret = i40e_set_dcb_config(hw);
10952 PMD_INIT_LOG(ERR, "Set DCB Config failed, err %s aq_err %s",
10953 i40e_stat_str(hw, ret),
10954 i40e_aq_str(hw, hw->aq.asq_last_status));
10957 /* set receive Arbiter to RR mode and ETS scheme by default */
10958 for (i = 0; i <= I40E_PRTDCB_RETSTCC_MAX_INDEX; i++) {
10959 val = I40E_READ_REG(hw, I40E_PRTDCB_RETSTCC(i));
10960 val &= ~(I40E_PRTDCB_RETSTCC_BWSHARE_MASK |
10961 I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK |
10962 I40E_PRTDCB_RETSTCC_ETSTC_SHIFT);
10963 val |= ((uint32_t)old_cfg->etscfg.tcbwtable[i] <<
10964 I40E_PRTDCB_RETSTCC_BWSHARE_SHIFT) &
10965 I40E_PRTDCB_RETSTCC_BWSHARE_MASK;
10966 val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_UPINTC_MODE_SHIFT) &
10967 I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK;
10968 val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_ETSTC_SHIFT) &
10969 I40E_PRTDCB_RETSTCC_ETSTC_MASK;
10970 I40E_WRITE_REG(hw, I40E_PRTDCB_RETSTCC(i), val);
10972 /* get local mib to check whether it is configured correctly */
10974 hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_IEEE;
10975 /* Get Local DCB Config */
10976 i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
10977 &hw->local_dcbx_config);
10979 /* if Veb is created, need to update TC of it at first */
10980 if (main_vsi->veb) {
10981 ret = i40e_config_switch_comp_tc(main_vsi->veb, tc_map);
10983 PMD_INIT_LOG(WARNING,
10984 "Failed configuring TC for VEB seid=%d",
10985 main_vsi->veb->seid);
10987 /* Update each VSI */
10988 i40e_vsi_config_tc(main_vsi, tc_map);
10989 if (main_vsi->veb) {
10990 TAILQ_FOREACH(vsi_list, &main_vsi->veb->head, list) {
10991 /* Beside main VSI and VMDQ VSIs, only enable default
10992 * TC for other VSIs
10994 if (vsi_list->vsi->type == I40E_VSI_VMDQ2)
10995 ret = i40e_vsi_config_tc(vsi_list->vsi,
10998 ret = i40e_vsi_config_tc(vsi_list->vsi,
10999 I40E_DEFAULT_TCMAP);
11001 PMD_INIT_LOG(WARNING,
11002 "Failed configuring TC for VSI seid=%d",
11003 vsi_list->vsi->seid);
11007 return I40E_SUCCESS;
11011 * i40e_dcb_init_configure - initial dcb config
11012 * @dev: device being configured
11013 * @sw_dcb: indicate whether dcb is sw configured or hw offload
11015 * Returns 0 on success, negative value on failure
11018 i40e_dcb_init_configure(struct rte_eth_dev *dev, bool sw_dcb)
11020 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11021 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11024 if ((pf->flags & I40E_FLAG_DCB) == 0) {
11025 PMD_INIT_LOG(ERR, "HW doesn't support DCB");
11029 /* DCB initialization:
11030 * Update DCB configuration from the Firmware and configure
11031 * LLDP MIB change event.
11033 if (sw_dcb == TRUE) {
11034 ret = i40e_init_dcb(hw);
11035 /* If lldp agent is stopped, the return value from
11036 * i40e_init_dcb we expect is failure with I40E_AQ_RC_EPERM
11037 * adminq status. Otherwise, it should return success.
11039 if ((ret == I40E_SUCCESS) || (ret != I40E_SUCCESS &&
11040 hw->aq.asq_last_status == I40E_AQ_RC_EPERM)) {
11041 memset(&hw->local_dcbx_config, 0,
11042 sizeof(struct i40e_dcbx_config));
11043 /* set dcb default configuration */
11044 hw->local_dcbx_config.etscfg.willing = 0;
11045 hw->local_dcbx_config.etscfg.maxtcs = 0;
11046 hw->local_dcbx_config.etscfg.tcbwtable[0] = 100;
11047 hw->local_dcbx_config.etscfg.tsatable[0] =
11049 /* all UPs mapping to TC0 */
11050 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
11051 hw->local_dcbx_config.etscfg.prioritytable[i] = 0;
11052 hw->local_dcbx_config.etsrec =
11053 hw->local_dcbx_config.etscfg;
11054 hw->local_dcbx_config.pfc.willing = 0;
11055 hw->local_dcbx_config.pfc.pfccap =
11056 I40E_MAX_TRAFFIC_CLASS;
11057 /* FW needs one App to configure HW */
11058 hw->local_dcbx_config.numapps = 1;
11059 hw->local_dcbx_config.app[0].selector =
11060 I40E_APP_SEL_ETHTYPE;
11061 hw->local_dcbx_config.app[0].priority = 3;
11062 hw->local_dcbx_config.app[0].protocolid =
11063 I40E_APP_PROTOID_FCOE;
11064 ret = i40e_set_dcb_config(hw);
11067 "default dcb config fails. err = %d, aq_err = %d.",
11068 ret, hw->aq.asq_last_status);
11073 "DCB initialization in FW fails, err = %d, aq_err = %d.",
11074 ret, hw->aq.asq_last_status);
11078 ret = i40e_aq_start_lldp(hw, NULL);
11079 if (ret != I40E_SUCCESS)
11080 PMD_INIT_LOG(DEBUG, "Failed to start lldp");
11082 ret = i40e_init_dcb(hw);
11084 if (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED) {
11086 "HW doesn't support DCBX offload.");
11091 "DCBX configuration failed, err = %d, aq_err = %d.",
11092 ret, hw->aq.asq_last_status);
11100 * i40e_dcb_setup - setup dcb related config
11101 * @dev: device being configured
11103 * Returns 0 on success, negative value on failure
11106 i40e_dcb_setup(struct rte_eth_dev *dev)
11108 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11109 struct i40e_dcbx_config dcb_cfg;
11110 uint8_t tc_map = 0;
11113 if ((pf->flags & I40E_FLAG_DCB) == 0) {
11114 PMD_INIT_LOG(ERR, "HW doesn't support DCB");
11118 if (pf->vf_num != 0)
11119 PMD_INIT_LOG(DEBUG, " DCB only works on pf and vmdq vsis.");
11121 ret = i40e_parse_dcb_configure(dev, &dcb_cfg, &tc_map);
11123 PMD_INIT_LOG(ERR, "invalid dcb config");
11126 ret = i40e_dcb_hw_configure(pf, &dcb_cfg, tc_map);
11128 PMD_INIT_LOG(ERR, "dcb sw configure fails");
11136 i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
11137 struct rte_eth_dcb_info *dcb_info)
11139 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11140 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11141 struct i40e_vsi *vsi = pf->main_vsi;
11142 struct i40e_dcbx_config *dcb_cfg = &hw->local_dcbx_config;
11143 uint16_t bsf, tc_mapping;
11146 if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_DCB_FLAG)
11147 dcb_info->nb_tcs = rte_bsf32(vsi->enabled_tc + 1);
11149 dcb_info->nb_tcs = 1;
11150 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
11151 dcb_info->prio_tc[i] = dcb_cfg->etscfg.prioritytable[i];
11152 for (i = 0; i < dcb_info->nb_tcs; i++)
11153 dcb_info->tc_bws[i] = dcb_cfg->etscfg.tcbwtable[i];
11155 /* get queue mapping if vmdq is disabled */
11156 if (!pf->nb_cfg_vmdq_vsi) {
11157 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11158 if (!(vsi->enabled_tc & (1 << i)))
11160 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
11161 dcb_info->tc_queue.tc_rxq[j][i].base =
11162 (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
11163 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
11164 dcb_info->tc_queue.tc_txq[j][i].base =
11165 dcb_info->tc_queue.tc_rxq[j][i].base;
11166 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
11167 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
11168 dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
11169 dcb_info->tc_queue.tc_txq[j][i].nb_queue =
11170 dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
11175 /* get queue mapping if vmdq is enabled */
11177 vsi = pf->vmdq[j].vsi;
11178 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11179 if (!(vsi->enabled_tc & (1 << i)))
11181 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
11182 dcb_info->tc_queue.tc_rxq[j][i].base =
11183 (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
11184 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
11185 dcb_info->tc_queue.tc_txq[j][i].base =
11186 dcb_info->tc_queue.tc_rxq[j][i].base;
11187 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
11188 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
11189 dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
11190 dcb_info->tc_queue.tc_txq[j][i].nb_queue =
11191 dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
11194 } while (j < RTE_MIN(pf->nb_cfg_vmdq_vsi, ETH_MAX_VMDQ_POOL));
11199 i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
11201 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
11202 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
11203 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11204 uint16_t msix_intr;
11206 msix_intr = intr_handle->intr_vec[queue_id];
11207 if (msix_intr == I40E_MISC_VEC_ID)
11208 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
11209 I40E_PFINT_DYN_CTL0_INTENA_MASK |
11210 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
11211 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
11214 I40E_PFINT_DYN_CTLN(msix_intr -
11215 I40E_RX_VEC_START),
11216 I40E_PFINT_DYN_CTLN_INTENA_MASK |
11217 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
11218 I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
11220 I40E_WRITE_FLUSH(hw);
11221 rte_intr_enable(&pci_dev->intr_handle);
11227 i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
11229 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
11230 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
11231 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11232 uint16_t msix_intr;
11234 msix_intr = intr_handle->intr_vec[queue_id];
11235 if (msix_intr == I40E_MISC_VEC_ID)
11236 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
11237 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
11240 I40E_PFINT_DYN_CTLN(msix_intr -
11241 I40E_RX_VEC_START),
11242 I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
11243 I40E_WRITE_FLUSH(hw);
11248 static int i40e_get_regs(struct rte_eth_dev *dev,
11249 struct rte_dev_reg_info *regs)
11251 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11252 uint32_t *ptr_data = regs->data;
11253 uint32_t reg_idx, arr_idx, arr_idx2, reg_offset;
11254 const struct i40e_reg_info *reg_info;
11256 if (ptr_data == NULL) {
11257 regs->length = I40E_GLGEN_STAT_CLEAR + 4;
11258 regs->width = sizeof(uint32_t);
11262 /* The first few registers have to be read using AQ operations */
11264 while (i40e_regs_adminq[reg_idx].name) {
11265 reg_info = &i40e_regs_adminq[reg_idx++];
11266 for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
11268 arr_idx2 <= reg_info->count2;
11270 reg_offset = arr_idx * reg_info->stride1 +
11271 arr_idx2 * reg_info->stride2;
11272 reg_offset += reg_info->base_addr;
11273 ptr_data[reg_offset >> 2] =
11274 i40e_read_rx_ctl(hw, reg_offset);
11278 /* The remaining registers can be read using primitives */
11280 while (i40e_regs_others[reg_idx].name) {
11281 reg_info = &i40e_regs_others[reg_idx++];
11282 for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
11284 arr_idx2 <= reg_info->count2;
11286 reg_offset = arr_idx * reg_info->stride1 +
11287 arr_idx2 * reg_info->stride2;
11288 reg_offset += reg_info->base_addr;
11289 ptr_data[reg_offset >> 2] =
11290 I40E_READ_REG(hw, reg_offset);
11297 static int i40e_get_eeprom_length(struct rte_eth_dev *dev)
11299 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11301 /* Convert word count to byte count */
11302 return hw->nvm.sr_size << 1;
11305 static int i40e_get_eeprom(struct rte_eth_dev *dev,
11306 struct rte_dev_eeprom_info *eeprom)
11308 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11309 uint16_t *data = eeprom->data;
11310 uint16_t offset, length, cnt_words;
11313 offset = eeprom->offset >> 1;
11314 length = eeprom->length >> 1;
11315 cnt_words = length;
11317 if (offset > hw->nvm.sr_size ||
11318 offset + length > hw->nvm.sr_size) {
11319 PMD_DRV_LOG(ERR, "Requested EEPROM bytes out of range.");
11323 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
11325 ret_code = i40e_read_nvm_buffer(hw, offset, &cnt_words, data);
11326 if (ret_code != I40E_SUCCESS || cnt_words != length) {
11327 PMD_DRV_LOG(ERR, "EEPROM read failed.");
11334 static int i40e_set_default_mac_addr(struct rte_eth_dev *dev,
11335 struct ether_addr *mac_addr)
11337 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11338 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11339 struct i40e_vsi *vsi = pf->main_vsi;
11340 struct i40e_mac_filter_info mac_filter;
11341 struct i40e_mac_filter *f;
11344 if (!is_valid_assigned_ether_addr(mac_addr)) {
11345 PMD_DRV_LOG(ERR, "Tried to set invalid MAC address.");
11349 TAILQ_FOREACH(f, &vsi->mac_list, next) {
11350 if (is_same_ether_addr(&pf->dev_addr, &f->mac_info.mac_addr))
11355 PMD_DRV_LOG(ERR, "Failed to find filter for default mac");
11359 mac_filter = f->mac_info;
11360 ret = i40e_vsi_delete_mac(vsi, &mac_filter.mac_addr);
11361 if (ret != I40E_SUCCESS) {
11362 PMD_DRV_LOG(ERR, "Failed to delete mac filter");
11365 memcpy(&mac_filter.mac_addr, mac_addr, ETH_ADDR_LEN);
11366 ret = i40e_vsi_add_mac(vsi, &mac_filter);
11367 if (ret != I40E_SUCCESS) {
11368 PMD_DRV_LOG(ERR, "Failed to add mac filter");
11371 memcpy(&pf->dev_addr, mac_addr, ETH_ADDR_LEN);
11373 ret = i40e_aq_mac_address_write(hw, I40E_AQC_WRITE_TYPE_LAA_WOL,
11374 mac_addr->addr_bytes, NULL);
11375 if (ret != I40E_SUCCESS) {
11376 PMD_DRV_LOG(ERR, "Failed to change mac");
11384 i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
11386 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11387 struct rte_eth_dev_data *dev_data = pf->dev_data;
11388 uint32_t frame_size = mtu + I40E_ETH_OVERHEAD;
11391 /* check if mtu is within the allowed range */
11392 if ((mtu < ETHER_MIN_MTU) || (frame_size > I40E_FRAME_SIZE_MAX))
11395 /* mtu setting is forbidden if port is start */
11396 if (dev_data->dev_started) {
11397 PMD_DRV_LOG(ERR, "port %d must be stopped before configuration",
11398 dev_data->port_id);
11402 if (frame_size > ETHER_MAX_LEN)
11403 dev_data->dev_conf.rxmode.offloads |=
11404 DEV_RX_OFFLOAD_JUMBO_FRAME;
11406 dev_data->dev_conf.rxmode.offloads &=
11407 ~DEV_RX_OFFLOAD_JUMBO_FRAME;
11409 dev_data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
11414 /* Restore ethertype filter */
11416 i40e_ethertype_filter_restore(struct i40e_pf *pf)
11418 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11419 struct i40e_ethertype_filter_list
11420 *ethertype_list = &pf->ethertype.ethertype_list;
11421 struct i40e_ethertype_filter *f;
11422 struct i40e_control_filter_stats stats;
11425 TAILQ_FOREACH(f, ethertype_list, rules) {
11427 if (!(f->flags & RTE_ETHTYPE_FLAGS_MAC))
11428 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
11429 if (f->flags & RTE_ETHTYPE_FLAGS_DROP)
11430 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
11431 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
11433 memset(&stats, 0, sizeof(stats));
11434 i40e_aq_add_rem_control_packet_filter(hw,
11435 f->input.mac_addr.addr_bytes,
11436 f->input.ether_type,
11437 flags, pf->main_vsi->seid,
11438 f->queue, 1, &stats, NULL);
11440 PMD_DRV_LOG(INFO, "Ethertype filter:"
11441 " mac_etype_used = %u, etype_used = %u,"
11442 " mac_etype_free = %u, etype_free = %u",
11443 stats.mac_etype_used, stats.etype_used,
11444 stats.mac_etype_free, stats.etype_free);
11447 /* Restore tunnel filter */
11449 i40e_tunnel_filter_restore(struct i40e_pf *pf)
11451 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11452 struct i40e_vsi *vsi;
11453 struct i40e_pf_vf *vf;
11454 struct i40e_tunnel_filter_list
11455 *tunnel_list = &pf->tunnel.tunnel_list;
11456 struct i40e_tunnel_filter *f;
11457 struct i40e_aqc_add_rm_cloud_filt_elem_ext cld_filter;
11458 bool big_buffer = 0;
11460 TAILQ_FOREACH(f, tunnel_list, rules) {
11462 vsi = pf->main_vsi;
11464 vf = &pf->vfs[f->vf_id];
11467 memset(&cld_filter, 0, sizeof(cld_filter));
11468 ether_addr_copy((struct ether_addr *)&f->input.outer_mac,
11469 (struct ether_addr *)&cld_filter.element.outer_mac);
11470 ether_addr_copy((struct ether_addr *)&f->input.inner_mac,
11471 (struct ether_addr *)&cld_filter.element.inner_mac);
11472 cld_filter.element.inner_vlan = f->input.inner_vlan;
11473 cld_filter.element.flags = f->input.flags;
11474 cld_filter.element.tenant_id = f->input.tenant_id;
11475 cld_filter.element.queue_number = f->queue;
11476 rte_memcpy(cld_filter.general_fields,
11477 f->input.general_fields,
11478 sizeof(f->input.general_fields));
11480 if (((f->input.flags &
11481 I40E_AQC_ADD_CLOUD_FILTER_0X11) ==
11482 I40E_AQC_ADD_CLOUD_FILTER_0X11) ||
11484 I40E_AQC_ADD_CLOUD_FILTER_0X12) ==
11485 I40E_AQC_ADD_CLOUD_FILTER_0X12) ||
11487 I40E_AQC_ADD_CLOUD_FILTER_0X10) ==
11488 I40E_AQC_ADD_CLOUD_FILTER_0X10))
11492 i40e_aq_add_cloud_filters_big_buffer(hw,
11493 vsi->seid, &cld_filter, 1);
11495 i40e_aq_add_cloud_filters(hw, vsi->seid,
11496 &cld_filter.element, 1);
11500 /* Restore rss filter */
11502 i40e_rss_filter_restore(struct i40e_pf *pf)
11504 struct i40e_rte_flow_rss_conf *conf =
11507 i40e_config_rss_filter(pf, conf, TRUE);
11511 i40e_filter_restore(struct i40e_pf *pf)
11513 i40e_ethertype_filter_restore(pf);
11514 i40e_tunnel_filter_restore(pf);
11515 i40e_fdir_filter_restore(pf);
11516 i40e_rss_filter_restore(pf);
11520 is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
11522 if (strcmp(dev->device->driver->name, drv->driver.name))
11529 is_i40e_supported(struct rte_eth_dev *dev)
11531 return is_device_supported(dev, &rte_i40e_pmd);
11534 struct i40e_customized_pctype*
11535 i40e_find_customized_pctype(struct i40e_pf *pf, uint8_t index)
11539 for (i = 0; i < I40E_CUSTOMIZED_MAX; i++) {
11540 if (pf->customized_pctype[i].index == index)
11541 return &pf->customized_pctype[i];
11547 i40e_update_customized_pctype(struct rte_eth_dev *dev, uint8_t *pkg,
11548 uint32_t pkg_size, uint32_t proto_num,
11549 struct rte_pmd_i40e_proto_info *proto,
11550 enum rte_pmd_i40e_package_op op)
11552 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11553 uint32_t pctype_num;
11554 struct rte_pmd_i40e_ptype_info *pctype;
11555 uint32_t buff_size;
11556 struct i40e_customized_pctype *new_pctype = NULL;
11558 uint8_t pctype_value;
11563 if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
11564 op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
11565 PMD_DRV_LOG(ERR, "Unsupported operation.");
11569 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11570 (uint8_t *)&pctype_num, sizeof(pctype_num),
11571 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
11573 PMD_DRV_LOG(ERR, "Failed to get pctype number");
11577 PMD_DRV_LOG(INFO, "No new pctype added");
11581 buff_size = pctype_num * sizeof(struct rte_pmd_i40e_proto_info);
11582 pctype = rte_zmalloc("new_pctype", buff_size, 0);
11584 PMD_DRV_LOG(ERR, "Failed to allocate memory");
11587 /* get information about new pctype list */
11588 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11589 (uint8_t *)pctype, buff_size,
11590 RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
11592 PMD_DRV_LOG(ERR, "Failed to get pctype list");
11597 /* Update customized pctype. */
11598 for (i = 0; i < pctype_num; i++) {
11599 pctype_value = pctype[i].ptype_id;
11600 memset(name, 0, sizeof(name));
11601 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
11602 proto_id = pctype[i].protocols[j];
11603 if (proto_id == RTE_PMD_I40E_PROTO_UNUSED)
11605 for (n = 0; n < proto_num; n++) {
11606 if (proto[n].proto_id != proto_id)
11608 strcat(name, proto[n].name);
11613 name[strlen(name) - 1] = '\0';
11614 if (!strcmp(name, "GTPC"))
11616 i40e_find_customized_pctype(pf,
11617 I40E_CUSTOMIZED_GTPC);
11618 else if (!strcmp(name, "GTPU_IPV4"))
11620 i40e_find_customized_pctype(pf,
11621 I40E_CUSTOMIZED_GTPU_IPV4);
11622 else if (!strcmp(name, "GTPU_IPV6"))
11624 i40e_find_customized_pctype(pf,
11625 I40E_CUSTOMIZED_GTPU_IPV6);
11626 else if (!strcmp(name, "GTPU"))
11628 i40e_find_customized_pctype(pf,
11629 I40E_CUSTOMIZED_GTPU);
11631 if (op == RTE_PMD_I40E_PKG_OP_WR_ADD) {
11632 new_pctype->pctype = pctype_value;
11633 new_pctype->valid = true;
11635 new_pctype->pctype = I40E_FILTER_PCTYPE_INVALID;
11636 new_pctype->valid = false;
11646 i40e_update_customized_ptype(struct rte_eth_dev *dev, uint8_t *pkg,
11647 uint32_t pkg_size, uint32_t proto_num,
11648 struct rte_pmd_i40e_proto_info *proto,
11649 enum rte_pmd_i40e_package_op op)
11651 struct rte_pmd_i40e_ptype_mapping *ptype_mapping;
11652 uint16_t port_id = dev->data->port_id;
11653 uint32_t ptype_num;
11654 struct rte_pmd_i40e_ptype_info *ptype;
11655 uint32_t buff_size;
11657 char name[RTE_PMD_I40E_DDP_NAME_SIZE];
11662 if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
11663 op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
11664 PMD_DRV_LOG(ERR, "Unsupported operation.");
11668 if (op == RTE_PMD_I40E_PKG_OP_WR_DEL) {
11669 rte_pmd_i40e_ptype_mapping_reset(port_id);
11673 /* get information about new ptype num */
11674 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11675 (uint8_t *)&ptype_num, sizeof(ptype_num),
11676 RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
11678 PMD_DRV_LOG(ERR, "Failed to get ptype number");
11682 PMD_DRV_LOG(INFO, "No new ptype added");
11686 buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
11687 ptype = rte_zmalloc("new_ptype", buff_size, 0);
11689 PMD_DRV_LOG(ERR, "Failed to allocate memory");
11693 /* get information about new ptype list */
11694 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11695 (uint8_t *)ptype, buff_size,
11696 RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
11698 PMD_DRV_LOG(ERR, "Failed to get ptype list");
11703 buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_mapping);
11704 ptype_mapping = rte_zmalloc("ptype_mapping", buff_size, 0);
11705 if (!ptype_mapping) {
11706 PMD_DRV_LOG(ERR, "Failed to allocate memory");
11711 /* Update ptype mapping table. */
11712 for (i = 0; i < ptype_num; i++) {
11713 ptype_mapping[i].hw_ptype = ptype[i].ptype_id;
11714 ptype_mapping[i].sw_ptype = 0;
11716 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
11717 proto_id = ptype[i].protocols[j];
11718 if (proto_id == RTE_PMD_I40E_PROTO_UNUSED)
11720 for (n = 0; n < proto_num; n++) {
11721 if (proto[n].proto_id != proto_id)
11723 memset(name, 0, sizeof(name));
11724 strcpy(name, proto[n].name);
11725 if (!strncasecmp(name, "PPPOE", 5))
11726 ptype_mapping[i].sw_ptype |=
11727 RTE_PTYPE_L2_ETHER_PPPOE;
11728 else if (!strncasecmp(name, "IPV4FRAG", 8) &&
11730 ptype_mapping[i].sw_ptype |=
11731 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11732 ptype_mapping[i].sw_ptype |=
11734 } else if (!strncasecmp(name, "IPV4FRAG", 8) &&
11736 ptype_mapping[i].sw_ptype |=
11737 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
11738 ptype_mapping[i].sw_ptype |=
11739 RTE_PTYPE_INNER_L4_FRAG;
11740 } else if (!strncasecmp(name, "OIPV4", 5)) {
11741 ptype_mapping[i].sw_ptype |=
11742 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11744 } else if (!strncasecmp(name, "IPV4", 4) &&
11746 ptype_mapping[i].sw_ptype |=
11747 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11748 else if (!strncasecmp(name, "IPV4", 4) &&
11750 ptype_mapping[i].sw_ptype |=
11751 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
11752 else if (!strncasecmp(name, "IPV6FRAG", 8) &&
11754 ptype_mapping[i].sw_ptype |=
11755 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11756 ptype_mapping[i].sw_ptype |=
11758 } else if (!strncasecmp(name, "IPV6FRAG", 8) &&
11760 ptype_mapping[i].sw_ptype |=
11761 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
11762 ptype_mapping[i].sw_ptype |=
11763 RTE_PTYPE_INNER_L4_FRAG;
11764 } else if (!strncasecmp(name, "OIPV6", 5)) {
11765 ptype_mapping[i].sw_ptype |=
11766 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11768 } else if (!strncasecmp(name, "IPV6", 4) &&
11770 ptype_mapping[i].sw_ptype |=
11771 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11772 else if (!strncasecmp(name, "IPV6", 4) &&
11774 ptype_mapping[i].sw_ptype |=
11775 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
11776 else if (!strncasecmp(name, "UDP", 3) &&
11778 ptype_mapping[i].sw_ptype |=
11780 else if (!strncasecmp(name, "UDP", 3) &&
11782 ptype_mapping[i].sw_ptype |=
11783 RTE_PTYPE_INNER_L4_UDP;
11784 else if (!strncasecmp(name, "TCP", 3) &&
11786 ptype_mapping[i].sw_ptype |=
11788 else if (!strncasecmp(name, "TCP", 3) &&
11790 ptype_mapping[i].sw_ptype |=
11791 RTE_PTYPE_INNER_L4_TCP;
11792 else if (!strncasecmp(name, "SCTP", 4) &&
11794 ptype_mapping[i].sw_ptype |=
11796 else if (!strncasecmp(name, "SCTP", 4) &&
11798 ptype_mapping[i].sw_ptype |=
11799 RTE_PTYPE_INNER_L4_SCTP;
11800 else if ((!strncasecmp(name, "ICMP", 4) ||
11801 !strncasecmp(name, "ICMPV6", 6)) &&
11803 ptype_mapping[i].sw_ptype |=
11805 else if ((!strncasecmp(name, "ICMP", 4) ||
11806 !strncasecmp(name, "ICMPV6", 6)) &&
11808 ptype_mapping[i].sw_ptype |=
11809 RTE_PTYPE_INNER_L4_ICMP;
11810 else if (!strncasecmp(name, "GTPC", 4)) {
11811 ptype_mapping[i].sw_ptype |=
11812 RTE_PTYPE_TUNNEL_GTPC;
11814 } else if (!strncasecmp(name, "GTPU", 4)) {
11815 ptype_mapping[i].sw_ptype |=
11816 RTE_PTYPE_TUNNEL_GTPU;
11818 } else if (!strncasecmp(name, "GRENAT", 6)) {
11819 ptype_mapping[i].sw_ptype |=
11820 RTE_PTYPE_TUNNEL_GRENAT;
11822 } else if (!strncasecmp(name, "L2TPV2CTL", 9)) {
11823 ptype_mapping[i].sw_ptype |=
11824 RTE_PTYPE_TUNNEL_L2TP;
11833 ret = rte_pmd_i40e_ptype_mapping_update(port_id, ptype_mapping,
11836 PMD_DRV_LOG(ERR, "Failed to update mapping table.");
11838 rte_free(ptype_mapping);
11844 i40e_update_customized_info(struct rte_eth_dev *dev, uint8_t *pkg,
11845 uint32_t pkg_size, enum rte_pmd_i40e_package_op op)
11847 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11848 uint32_t proto_num;
11849 struct rte_pmd_i40e_proto_info *proto;
11850 uint32_t buff_size;
11854 if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
11855 op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
11856 PMD_DRV_LOG(ERR, "Unsupported operation.");
11860 /* get information about protocol number */
11861 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11862 (uint8_t *)&proto_num, sizeof(proto_num),
11863 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
11865 PMD_DRV_LOG(ERR, "Failed to get protocol number");
11869 PMD_DRV_LOG(INFO, "No new protocol added");
11873 buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
11874 proto = rte_zmalloc("new_proto", buff_size, 0);
11876 PMD_DRV_LOG(ERR, "Failed to allocate memory");
11880 /* get information about protocol list */
11881 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11882 (uint8_t *)proto, buff_size,
11883 RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
11885 PMD_DRV_LOG(ERR, "Failed to get protocol list");
11890 /* Check if GTP is supported. */
11891 for (i = 0; i < proto_num; i++) {
11892 if (!strncmp(proto[i].name, "GTP", 3)) {
11893 if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
11894 pf->gtp_support = true;
11896 pf->gtp_support = false;
11901 /* Update customized pctype info */
11902 ret = i40e_update_customized_pctype(dev, pkg, pkg_size,
11903 proto_num, proto, op);
11905 PMD_DRV_LOG(INFO, "No pctype is updated.");
11907 /* Update customized ptype info */
11908 ret = i40e_update_customized_ptype(dev, pkg, pkg_size,
11909 proto_num, proto, op);
11911 PMD_DRV_LOG(INFO, "No ptype is updated.");
11916 /* Create a QinQ cloud filter
11918 * The Fortville NIC has limited resources for tunnel filters,
11919 * so we can only reuse existing filters.
11921 * In step 1 we define which Field Vector fields can be used for
11923 * As we do not have the inner tag defined as a field,
11924 * we have to define it first, by reusing one of L1 entries.
11926 * In step 2 we are replacing one of existing filter types with
11927 * a new one for QinQ.
11928 * As we reusing L1 and replacing L2, some of the default filter
11929 * types will disappear,which depends on L1 and L2 entries we reuse.
11931 * Step 1: Create L1 filter of outer vlan (12b) + inner vlan (12b)
11933 * 1. Create L1 filter of outer vlan (12b) which will be in use
11934 * later when we define the cloud filter.
11935 * a. Valid_flags.replace_cloud = 0
11936 * b. Old_filter = 10 (Stag_Inner_Vlan)
11937 * c. New_filter = 0x10
11938 * d. TR bit = 0xff (optional, not used here)
11939 * e. Buffer – 2 entries:
11940 * i. Byte 0 = 8 (outer vlan FV index).
11942 * Byte 2-3 = 0x0fff
11943 * ii. Byte 0 = 37 (inner vlan FV index).
11945 * Byte 2-3 = 0x0fff
11948 * 2. Create cloud filter using two L1 filters entries: stag and
11949 * new filter(outer vlan+ inner vlan)
11950 * a. Valid_flags.replace_cloud = 1
11951 * b. Old_filter = 1 (instead of outer IP)
11952 * c. New_filter = 0x10
11953 * d. Buffer – 2 entries:
11954 * i. Byte 0 = 0x80 | 7 (valid | Stag).
11955 * Byte 1-3 = 0 (rsv)
11956 * ii. Byte 8 = 0x80 | 0x10 (valid | new l1 filter step1)
11957 * Byte 9-11 = 0 (rsv)
11960 i40e_cloud_filter_qinq_create(struct i40e_pf *pf)
11962 int ret = -ENOTSUP;
11963 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
11964 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
11965 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11967 if (pf->support_multi_driver) {
11968 PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
11973 memset(&filter_replace, 0,
11974 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
11975 memset(&filter_replace_buf, 0,
11976 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
11978 /* create L1 filter */
11979 filter_replace.old_filter_type =
11980 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG_IVLAN;
11981 filter_replace.new_filter_type = I40E_AQC_ADD_CLOUD_FILTER_0X10;
11982 filter_replace.tr_bit = 0;
11984 /* Prepare the buffer, 2 entries */
11985 filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_VLAN;
11986 filter_replace_buf.data[0] |=
11987 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
11988 /* Field Vector 12b mask */
11989 filter_replace_buf.data[2] = 0xff;
11990 filter_replace_buf.data[3] = 0x0f;
11991 filter_replace_buf.data[4] =
11992 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_INNER_VLAN;
11993 filter_replace_buf.data[4] |=
11994 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
11995 /* Field Vector 12b mask */
11996 filter_replace_buf.data[6] = 0xff;
11997 filter_replace_buf.data[7] = 0x0f;
11998 ret = i40e_aq_replace_cloud_filters(hw, &filter_replace,
11999 &filter_replace_buf);
12000 if (ret != I40E_SUCCESS)
12002 PMD_DRV_LOG(DEBUG, "Global configuration modification: "
12003 "cloud l1 type is changed from 0x%x to 0x%x",
12004 filter_replace.old_filter_type,
12005 filter_replace.new_filter_type);
12007 /* Apply the second L2 cloud filter */
12008 memset(&filter_replace, 0,
12009 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
12010 memset(&filter_replace_buf, 0,
12011 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
12013 /* create L2 filter, input for L2 filter will be L1 filter */
12014 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
12015 filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_OIP;
12016 filter_replace.new_filter_type = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12018 /* Prepare the buffer, 2 entries */
12019 filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
12020 filter_replace_buf.data[0] |=
12021 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12022 filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12023 filter_replace_buf.data[4] |=
12024 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12025 ret = i40e_aq_replace_cloud_filters(hw, &filter_replace,
12026 &filter_replace_buf);
12028 i40e_global_cfg_warning(I40E_WARNING_RPL_CLD_FILTER);
12029 PMD_DRV_LOG(DEBUG, "Global configuration modification: "
12030 "cloud filter type is changed from 0x%x to 0x%x",
12031 filter_replace.old_filter_type,
12032 filter_replace.new_filter_type);
12038 i40e_config_rss_filter(struct i40e_pf *pf,
12039 struct i40e_rte_flow_rss_conf *conf, bool add)
12041 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
12042 uint32_t i, lut = 0;
12044 struct rte_eth_rss_conf rss_conf = conf->rss_conf;
12045 struct i40e_rte_flow_rss_conf *rss_info = &pf->rss_info;
12048 if (memcmp(conf, rss_info,
12049 sizeof(struct i40e_rte_flow_rss_conf)) == 0) {
12050 i40e_pf_disable_rss(pf);
12051 memset(rss_info, 0,
12052 sizeof(struct i40e_rte_flow_rss_conf));
12061 /* If both VMDQ and RSS enabled, not all of PF queues are configured.
12062 * It's necessary to calculate the actual PF queues that are configured.
12064 if (pf->dev_data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG)
12065 num = i40e_pf_calc_configured_queues_num(pf);
12067 num = pf->dev_data->nb_rx_queues;
12069 num = RTE_MIN(num, conf->num);
12070 PMD_DRV_LOG(INFO, "Max of contiguous %u PF queues are configured",
12074 PMD_DRV_LOG(ERR, "No PF queues are configured to enable RSS");
12078 /* Fill in redirection table */
12079 for (i = 0, j = 0; i < hw->func_caps.rss_table_size; i++, j++) {
12082 lut = (lut << 8) | (conf->queue[j] & ((0x1 <<
12083 hw->func_caps.rss_table_entry_width) - 1));
12085 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i >> 2), lut);
12088 if ((rss_conf.rss_hf & pf->adapter->flow_types_mask) == 0) {
12089 i40e_pf_disable_rss(pf);
12092 if (rss_conf.rss_key == NULL || rss_conf.rss_key_len <
12093 (I40E_PFQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t)) {
12094 /* Random default keys */
12095 static uint32_t rss_key_default[] = {0x6b793944,
12096 0x23504cb5, 0x5bea75b6, 0x309f4f12, 0x3dc0a2b8,
12097 0x024ddcdf, 0x339b8ca0, 0x4c4af64a, 0x34fac605,
12098 0x55d85839, 0x3a58997d, 0x2ec938e1, 0x66031581};
12100 rss_conf.rss_key = (uint8_t *)rss_key_default;
12101 rss_conf.rss_key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
12105 i40e_hw_rss_hash_set(pf, &rss_conf);
12107 rte_memcpy(rss_info,
12108 conf, sizeof(struct i40e_rte_flow_rss_conf));
12113 RTE_INIT(i40e_init_log);
12115 i40e_init_log(void)
12117 i40e_logtype_init = rte_log_register("pmd.net.i40e.init");
12118 if (i40e_logtype_init >= 0)
12119 rte_log_set_level(i40e_logtype_init, RTE_LOG_NOTICE);
12120 i40e_logtype_driver = rte_log_register("pmd.net.i40e.driver");
12121 if (i40e_logtype_driver >= 0)
12122 rte_log_set_level(i40e_logtype_driver, RTE_LOG_NOTICE);
12125 RTE_PMD_REGISTER_PARAM_STRING(net_i40e,
12126 QUEUE_NUM_PER_VF_ARG "=1|2|4|8|16"
12127 ETH_I40E_SUPPORT_MULTI_DRIVER "=1");