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 void 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 rte_i40e_dev_atomic_read_link_status(struct rte_eth_dev *dev,
632 struct rte_eth_link *link)
634 struct rte_eth_link *dst = link;
635 struct rte_eth_link *src = &(dev->data->dev_link);
637 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
638 *(uint64_t *)src) == 0)
645 rte_i40e_dev_atomic_write_link_status(struct rte_eth_dev *dev,
646 struct rte_eth_link *link)
648 struct rte_eth_link *dst = &(dev->data->dev_link);
649 struct rte_eth_link *src = link;
651 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
652 *(uint64_t *)src) == 0)
659 i40e_write_global_rx_ctl(struct i40e_hw *hw, u32 reg_addr, u32 reg_val)
661 i40e_write_rx_ctl(hw, reg_addr, reg_val);
662 PMD_DRV_LOG(DEBUG, "Global register 0x%08x is modified "
667 RTE_PMD_REGISTER_PCI(net_i40e, rte_i40e_pmd);
668 RTE_PMD_REGISTER_PCI_TABLE(net_i40e, pci_id_i40e_map);
669 RTE_PMD_REGISTER_KMOD_DEP(net_i40e, "* igb_uio | uio_pci_generic | vfio-pci");
671 #ifndef I40E_GLQF_ORT
672 #define I40E_GLQF_ORT(_i) (0x00268900 + ((_i) * 4))
674 #ifndef I40E_GLQF_PIT
675 #define I40E_GLQF_PIT(_i) (0x00268C80 + ((_i) * 4))
677 #ifndef I40E_GLQF_L3_MAP
678 #define I40E_GLQF_L3_MAP(_i) (0x0026C700 + ((_i) * 4))
681 static inline void i40e_GLQF_reg_init(struct i40e_hw *hw)
684 * Initialize registers for parsing packet type of QinQ
685 * This should be removed from code once proper
686 * configuration API is added to avoid configuration conflicts
687 * between ports of the same device.
689 I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(40), 0x00000029);
690 I40E_WRITE_GLB_REG(hw, I40E_GLQF_PIT(9), 0x00009420);
691 i40e_global_cfg_warning(I40E_WARNING_QINQ_PARSER);
694 static inline void i40e_config_automask(struct i40e_pf *pf)
696 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
699 /* INTENA flag is not auto-cleared for interrupt */
700 val = I40E_READ_REG(hw, I40E_GLINT_CTL);
701 val |= I40E_GLINT_CTL_DIS_AUTOMASK_PF0_MASK |
702 I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK;
704 /* If support multi-driver, PF will use INT0. */
705 if (!pf->support_multi_driver)
706 val |= I40E_GLINT_CTL_DIS_AUTOMASK_N_MASK;
708 I40E_WRITE_REG(hw, I40E_GLINT_CTL, val);
711 #define I40E_FLOW_CONTROL_ETHERTYPE 0x8808
714 * Add a ethertype filter to drop all flow control frames transmitted
718 i40e_add_tx_flow_control_drop_filter(struct i40e_pf *pf)
720 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
721 uint16_t flags = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
722 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
723 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
726 ret = i40e_aq_add_rem_control_packet_filter(hw, NULL,
727 I40E_FLOW_CONTROL_ETHERTYPE, flags,
728 pf->main_vsi_seid, 0,
732 "Failed to add filter to drop flow control frames from VSIs.");
736 floating_veb_list_handler(__rte_unused const char *key,
737 const char *floating_veb_value,
741 unsigned int count = 0;
744 bool *vf_floating_veb = opaque;
746 while (isblank(*floating_veb_value))
747 floating_veb_value++;
749 /* Reset floating VEB configuration for VFs */
750 for (idx = 0; idx < I40E_MAX_VF; idx++)
751 vf_floating_veb[idx] = false;
755 while (isblank(*floating_veb_value))
756 floating_veb_value++;
757 if (*floating_veb_value == '\0')
760 idx = strtoul(floating_veb_value, &end, 10);
761 if (errno || end == NULL)
763 while (isblank(*end))
767 } else if ((*end == ';') || (*end == '\0')) {
769 if (min == I40E_MAX_VF)
771 if (max >= I40E_MAX_VF)
772 max = I40E_MAX_VF - 1;
773 for (idx = min; idx <= max; idx++) {
774 vf_floating_veb[idx] = true;
781 floating_veb_value = end + 1;
782 } while (*end != '\0');
791 config_vf_floating_veb(struct rte_devargs *devargs,
792 uint16_t floating_veb,
793 bool *vf_floating_veb)
795 struct rte_kvargs *kvlist;
797 const char *floating_veb_list = ETH_I40E_FLOATING_VEB_LIST_ARG;
801 /* All the VFs attach to the floating VEB by default
802 * when the floating VEB is enabled.
804 for (i = 0; i < I40E_MAX_VF; i++)
805 vf_floating_veb[i] = true;
810 kvlist = rte_kvargs_parse(devargs->args, NULL);
814 if (!rte_kvargs_count(kvlist, floating_veb_list)) {
815 rte_kvargs_free(kvlist);
818 /* When the floating_veb_list parameter exists, all the VFs
819 * will attach to the legacy VEB firstly, then configure VFs
820 * to the floating VEB according to the floating_veb_list.
822 if (rte_kvargs_process(kvlist, floating_veb_list,
823 floating_veb_list_handler,
824 vf_floating_veb) < 0) {
825 rte_kvargs_free(kvlist);
828 rte_kvargs_free(kvlist);
832 i40e_check_floating_handler(__rte_unused const char *key,
834 __rte_unused void *opaque)
836 if (strcmp(value, "1"))
843 is_floating_veb_supported(struct rte_devargs *devargs)
845 struct rte_kvargs *kvlist;
846 const char *floating_veb_key = ETH_I40E_FLOATING_VEB_ARG;
851 kvlist = rte_kvargs_parse(devargs->args, NULL);
855 if (!rte_kvargs_count(kvlist, floating_veb_key)) {
856 rte_kvargs_free(kvlist);
859 /* Floating VEB is enabled when there's key-value:
860 * enable_floating_veb=1
862 if (rte_kvargs_process(kvlist, floating_veb_key,
863 i40e_check_floating_handler, NULL) < 0) {
864 rte_kvargs_free(kvlist);
867 rte_kvargs_free(kvlist);
873 config_floating_veb(struct rte_eth_dev *dev)
875 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
876 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
877 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
879 memset(pf->floating_veb_list, 0, sizeof(pf->floating_veb_list));
881 if (hw->aq.fw_maj_ver >= FLOATING_VEB_SUPPORTED_FW_MAJ) {
883 is_floating_veb_supported(pci_dev->device.devargs);
884 config_vf_floating_veb(pci_dev->device.devargs,
886 pf->floating_veb_list);
888 pf->floating_veb = false;
892 #define I40E_L2_TAGS_S_TAG_SHIFT 1
893 #define I40E_L2_TAGS_S_TAG_MASK I40E_MASK(0x1, I40E_L2_TAGS_S_TAG_SHIFT)
896 i40e_init_ethtype_filter_list(struct rte_eth_dev *dev)
898 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
899 struct i40e_ethertype_rule *ethertype_rule = &pf->ethertype;
900 char ethertype_hash_name[RTE_HASH_NAMESIZE];
903 struct rte_hash_parameters ethertype_hash_params = {
904 .name = ethertype_hash_name,
905 .entries = I40E_MAX_ETHERTYPE_FILTER_NUM,
906 .key_len = sizeof(struct i40e_ethertype_filter_input),
907 .hash_func = rte_hash_crc,
908 .hash_func_init_val = 0,
909 .socket_id = rte_socket_id(),
912 /* Initialize ethertype filter rule list and hash */
913 TAILQ_INIT(ðertype_rule->ethertype_list);
914 snprintf(ethertype_hash_name, RTE_HASH_NAMESIZE,
915 "ethertype_%s", dev->device->name);
916 ethertype_rule->hash_table = rte_hash_create(ðertype_hash_params);
917 if (!ethertype_rule->hash_table) {
918 PMD_INIT_LOG(ERR, "Failed to create ethertype hash table!");
921 ethertype_rule->hash_map = rte_zmalloc("i40e_ethertype_hash_map",
922 sizeof(struct i40e_ethertype_filter *) *
923 I40E_MAX_ETHERTYPE_FILTER_NUM,
925 if (!ethertype_rule->hash_map) {
927 "Failed to allocate memory for ethertype hash map!");
929 goto err_ethertype_hash_map_alloc;
934 err_ethertype_hash_map_alloc:
935 rte_hash_free(ethertype_rule->hash_table);
941 i40e_init_tunnel_filter_list(struct rte_eth_dev *dev)
943 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
944 struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
945 char tunnel_hash_name[RTE_HASH_NAMESIZE];
948 struct rte_hash_parameters tunnel_hash_params = {
949 .name = tunnel_hash_name,
950 .entries = I40E_MAX_TUNNEL_FILTER_NUM,
951 .key_len = sizeof(struct i40e_tunnel_filter_input),
952 .hash_func = rte_hash_crc,
953 .hash_func_init_val = 0,
954 .socket_id = rte_socket_id(),
957 /* Initialize tunnel filter rule list and hash */
958 TAILQ_INIT(&tunnel_rule->tunnel_list);
959 snprintf(tunnel_hash_name, RTE_HASH_NAMESIZE,
960 "tunnel_%s", dev->device->name);
961 tunnel_rule->hash_table = rte_hash_create(&tunnel_hash_params);
962 if (!tunnel_rule->hash_table) {
963 PMD_INIT_LOG(ERR, "Failed to create tunnel hash table!");
966 tunnel_rule->hash_map = rte_zmalloc("i40e_tunnel_hash_map",
967 sizeof(struct i40e_tunnel_filter *) *
968 I40E_MAX_TUNNEL_FILTER_NUM,
970 if (!tunnel_rule->hash_map) {
972 "Failed to allocate memory for tunnel hash map!");
974 goto err_tunnel_hash_map_alloc;
979 err_tunnel_hash_map_alloc:
980 rte_hash_free(tunnel_rule->hash_table);
986 i40e_init_fdir_filter_list(struct rte_eth_dev *dev)
988 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
989 struct i40e_fdir_info *fdir_info = &pf->fdir;
990 char fdir_hash_name[RTE_HASH_NAMESIZE];
993 struct rte_hash_parameters fdir_hash_params = {
994 .name = fdir_hash_name,
995 .entries = I40E_MAX_FDIR_FILTER_NUM,
996 .key_len = sizeof(struct i40e_fdir_input),
997 .hash_func = rte_hash_crc,
998 .hash_func_init_val = 0,
999 .socket_id = rte_socket_id(),
1002 /* Initialize flow director filter rule list and hash */
1003 TAILQ_INIT(&fdir_info->fdir_list);
1004 snprintf(fdir_hash_name, RTE_HASH_NAMESIZE,
1005 "fdir_%s", dev->device->name);
1006 fdir_info->hash_table = rte_hash_create(&fdir_hash_params);
1007 if (!fdir_info->hash_table) {
1008 PMD_INIT_LOG(ERR, "Failed to create fdir hash table!");
1011 fdir_info->hash_map = rte_zmalloc("i40e_fdir_hash_map",
1012 sizeof(struct i40e_fdir_filter *) *
1013 I40E_MAX_FDIR_FILTER_NUM,
1015 if (!fdir_info->hash_map) {
1017 "Failed to allocate memory for fdir hash map!");
1019 goto err_fdir_hash_map_alloc;
1023 err_fdir_hash_map_alloc:
1024 rte_hash_free(fdir_info->hash_table);
1030 i40e_init_customized_info(struct i40e_pf *pf)
1034 /* Initialize customized pctype */
1035 for (i = I40E_CUSTOMIZED_GTPC; i < I40E_CUSTOMIZED_MAX; i++) {
1036 pf->customized_pctype[i].index = i;
1037 pf->customized_pctype[i].pctype = I40E_FILTER_PCTYPE_INVALID;
1038 pf->customized_pctype[i].valid = false;
1041 pf->gtp_support = false;
1045 i40e_init_queue_region_conf(struct rte_eth_dev *dev)
1047 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1048 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1049 struct i40e_queue_regions *info = &pf->queue_region;
1052 for (i = 0; i < I40E_PFQF_HREGION_MAX_INDEX; i++)
1053 i40e_write_rx_ctl(hw, I40E_PFQF_HREGION(i), 0);
1055 memset(info, 0, sizeof(struct i40e_queue_regions));
1058 #define ETH_I40E_SUPPORT_MULTI_DRIVER "support-multi-driver"
1061 i40e_parse_multi_drv_handler(__rte_unused const char *key,
1066 unsigned long support_multi_driver;
1069 pf = (struct i40e_pf *)opaque;
1072 support_multi_driver = strtoul(value, &end, 10);
1073 if (errno != 0 || end == value || *end != 0) {
1074 PMD_DRV_LOG(WARNING, "Wrong global configuration");
1078 if (support_multi_driver == 1 || support_multi_driver == 0)
1079 pf->support_multi_driver = (bool)support_multi_driver;
1081 PMD_DRV_LOG(WARNING, "%s must be 1 or 0,",
1082 "enable global configuration by default."
1083 ETH_I40E_SUPPORT_MULTI_DRIVER);
1088 i40e_support_multi_driver(struct rte_eth_dev *dev)
1090 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1091 static const char *const valid_keys[] = {
1092 ETH_I40E_SUPPORT_MULTI_DRIVER, NULL};
1093 struct rte_kvargs *kvlist;
1095 /* Enable global configuration by default */
1096 pf->support_multi_driver = false;
1098 if (!dev->device->devargs)
1101 kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
1105 if (rte_kvargs_count(kvlist, ETH_I40E_SUPPORT_MULTI_DRIVER) > 1)
1106 PMD_DRV_LOG(WARNING, "More than one argument \"%s\" and only "
1107 "the first invalid or last valid one is used !",
1108 ETH_I40E_SUPPORT_MULTI_DRIVER);
1110 if (rte_kvargs_process(kvlist, ETH_I40E_SUPPORT_MULTI_DRIVER,
1111 i40e_parse_multi_drv_handler, pf) < 0) {
1112 rte_kvargs_free(kvlist);
1116 rte_kvargs_free(kvlist);
1121 eth_i40e_dev_init(struct rte_eth_dev *dev)
1123 struct rte_pci_device *pci_dev;
1124 struct rte_intr_handle *intr_handle;
1125 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1126 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1127 struct i40e_vsi *vsi;
1130 uint8_t aq_fail = 0;
1132 PMD_INIT_FUNC_TRACE();
1134 dev->dev_ops = &i40e_eth_dev_ops;
1135 dev->rx_pkt_burst = i40e_recv_pkts;
1136 dev->tx_pkt_burst = i40e_xmit_pkts;
1137 dev->tx_pkt_prepare = i40e_prep_pkts;
1139 /* for secondary processes, we don't initialise any further as primary
1140 * has already done this work. Only check we don't need a different
1142 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
1143 i40e_set_rx_function(dev);
1144 i40e_set_tx_function(dev);
1147 i40e_set_default_ptype_table(dev);
1148 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1149 intr_handle = &pci_dev->intr_handle;
1151 rte_eth_copy_pci_info(dev, pci_dev);
1153 pf->adapter = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1154 pf->adapter->eth_dev = dev;
1155 pf->dev_data = dev->data;
1157 hw->back = I40E_PF_TO_ADAPTER(pf);
1158 hw->hw_addr = (uint8_t *)(pci_dev->mem_resource[0].addr);
1161 "Hardware is not available, as address is NULL");
1165 hw->vendor_id = pci_dev->id.vendor_id;
1166 hw->device_id = pci_dev->id.device_id;
1167 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
1168 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
1169 hw->bus.device = pci_dev->addr.devid;
1170 hw->bus.func = pci_dev->addr.function;
1171 hw->adapter_stopped = 0;
1173 /* Check if need to support multi-driver */
1174 i40e_support_multi_driver(dev);
1176 /* Make sure all is clean before doing PF reset */
1179 /* Initialize the hardware */
1182 /* Reset here to make sure all is clean for each PF */
1183 ret = i40e_pf_reset(hw);
1185 PMD_INIT_LOG(ERR, "Failed to reset pf: %d", ret);
1189 /* Initialize the shared code (base driver) */
1190 ret = i40e_init_shared_code(hw);
1192 PMD_INIT_LOG(ERR, "Failed to init shared code (base driver): %d", ret);
1196 i40e_config_automask(pf);
1198 i40e_set_default_pctype_table(dev);
1201 * To work around the NVM issue, initialize registers
1202 * for packet type of QinQ by software.
1203 * It should be removed once issues are fixed in NVM.
1205 if (!pf->support_multi_driver)
1206 i40e_GLQF_reg_init(hw);
1208 /* Initialize the input set for filters (hash and fd) to default value */
1209 i40e_filter_input_set_init(pf);
1211 /* Initialize the parameters for adminq */
1212 i40e_init_adminq_parameter(hw);
1213 ret = i40e_init_adminq(hw);
1214 if (ret != I40E_SUCCESS) {
1215 PMD_INIT_LOG(ERR, "Failed to init adminq: %d", ret);
1218 PMD_INIT_LOG(INFO, "FW %d.%d API %d.%d NVM %02d.%02d.%02d eetrack %04x",
1219 hw->aq.fw_maj_ver, hw->aq.fw_min_ver,
1220 hw->aq.api_maj_ver, hw->aq.api_min_ver,
1221 ((hw->nvm.version >> 12) & 0xf),
1222 ((hw->nvm.version >> 4) & 0xff),
1223 (hw->nvm.version & 0xf), hw->nvm.eetrack);
1225 /* initialise the L3_MAP register */
1226 if (!pf->support_multi_driver) {
1227 ret = i40e_aq_debug_write_register(hw, I40E_GLQF_L3_MAP(40),
1230 PMD_INIT_LOG(ERR, "Failed to write L3 MAP register %d",
1233 "Global register 0x%08x is changed with 0x28",
1234 I40E_GLQF_L3_MAP(40));
1235 i40e_global_cfg_warning(I40E_WARNING_QINQ_CLOUD_FILTER);
1238 /* Need the special FW version to support floating VEB */
1239 config_floating_veb(dev);
1240 /* Clear PXE mode */
1241 i40e_clear_pxe_mode(hw);
1242 i40e_dev_sync_phy_type(hw);
1245 * On X710, performance number is far from the expectation on recent
1246 * firmware versions. The fix for this issue may not be integrated in
1247 * the following firmware version. So the workaround in software driver
1248 * is needed. It needs to modify the initial values of 3 internal only
1249 * registers. Note that the workaround can be removed when it is fixed
1250 * in firmware in the future.
1252 i40e_configure_registers(hw);
1254 /* Get hw capabilities */
1255 ret = i40e_get_cap(hw);
1256 if (ret != I40E_SUCCESS) {
1257 PMD_INIT_LOG(ERR, "Failed to get capabilities: %d", ret);
1258 goto err_get_capabilities;
1261 /* Initialize parameters for PF */
1262 ret = i40e_pf_parameter_init(dev);
1264 PMD_INIT_LOG(ERR, "Failed to do parameter init: %d", ret);
1265 goto err_parameter_init;
1268 /* Initialize the queue management */
1269 ret = i40e_res_pool_init(&pf->qp_pool, 0, hw->func_caps.num_tx_qp);
1271 PMD_INIT_LOG(ERR, "Failed to init queue pool");
1272 goto err_qp_pool_init;
1274 ret = i40e_res_pool_init(&pf->msix_pool, 1,
1275 hw->func_caps.num_msix_vectors - 1);
1277 PMD_INIT_LOG(ERR, "Failed to init MSIX pool");
1278 goto err_msix_pool_init;
1281 /* Initialize lan hmc */
1282 ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
1283 hw->func_caps.num_rx_qp, 0, 0);
1284 if (ret != I40E_SUCCESS) {
1285 PMD_INIT_LOG(ERR, "Failed to init lan hmc: %d", ret);
1286 goto err_init_lan_hmc;
1289 /* Configure lan hmc */
1290 ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
1291 if (ret != I40E_SUCCESS) {
1292 PMD_INIT_LOG(ERR, "Failed to configure lan hmc: %d", ret);
1293 goto err_configure_lan_hmc;
1296 /* Get and check the mac address */
1297 i40e_get_mac_addr(hw, hw->mac.addr);
1298 if (i40e_validate_mac_addr(hw->mac.addr) != I40E_SUCCESS) {
1299 PMD_INIT_LOG(ERR, "mac address is not valid");
1301 goto err_get_mac_addr;
1303 /* Copy the permanent MAC address */
1304 ether_addr_copy((struct ether_addr *) hw->mac.addr,
1305 (struct ether_addr *) hw->mac.perm_addr);
1307 /* Disable flow control */
1308 hw->fc.requested_mode = I40E_FC_NONE;
1309 i40e_set_fc(hw, &aq_fail, TRUE);
1311 /* Set the global registers with default ether type value */
1312 if (!pf->support_multi_driver) {
1313 ret = i40e_vlan_tpid_set(dev, ETH_VLAN_TYPE_OUTER,
1315 if (ret != I40E_SUCCESS) {
1317 "Failed to set the default outer "
1319 goto err_setup_pf_switch;
1323 /* PF setup, which includes VSI setup */
1324 ret = i40e_pf_setup(pf);
1326 PMD_INIT_LOG(ERR, "Failed to setup pf switch: %d", ret);
1327 goto err_setup_pf_switch;
1330 /* reset all stats of the device, including pf and main vsi */
1331 i40e_dev_stats_reset(dev);
1335 /* Disable double vlan by default */
1336 i40e_vsi_config_double_vlan(vsi, FALSE);
1338 /* Disable S-TAG identification when floating_veb is disabled */
1339 if (!pf->floating_veb) {
1340 ret = I40E_READ_REG(hw, I40E_PRT_L2TAGSEN);
1341 if (ret & I40E_L2_TAGS_S_TAG_MASK) {
1342 ret &= ~I40E_L2_TAGS_S_TAG_MASK;
1343 I40E_WRITE_REG(hw, I40E_PRT_L2TAGSEN, ret);
1347 if (!vsi->max_macaddrs)
1348 len = ETHER_ADDR_LEN;
1350 len = ETHER_ADDR_LEN * vsi->max_macaddrs;
1352 /* Should be after VSI initialized */
1353 dev->data->mac_addrs = rte_zmalloc("i40e", len, 0);
1354 if (!dev->data->mac_addrs) {
1356 "Failed to allocated memory for storing mac address");
1359 ether_addr_copy((struct ether_addr *)hw->mac.perm_addr,
1360 &dev->data->mac_addrs[0]);
1362 /* Init dcb to sw mode by default */
1363 ret = i40e_dcb_init_configure(dev, TRUE);
1364 if (ret != I40E_SUCCESS) {
1365 PMD_INIT_LOG(INFO, "Failed to init dcb.");
1366 pf->flags &= ~I40E_FLAG_DCB;
1368 /* Update HW struct after DCB configuration */
1371 /* initialize pf host driver to setup SRIOV resource if applicable */
1372 i40e_pf_host_init(dev);
1374 /* register callback func to eal lib */
1375 rte_intr_callback_register(intr_handle,
1376 i40e_dev_interrupt_handler, dev);
1378 /* configure and enable device interrupt */
1379 i40e_pf_config_irq0(hw, TRUE);
1380 i40e_pf_enable_irq0(hw);
1382 /* enable uio intr after callback register */
1383 rte_intr_enable(intr_handle);
1385 /* By default disable flexible payload in global configuration */
1386 if (!pf->support_multi_driver)
1387 i40e_flex_payload_reg_set_default(hw);
1390 * Add an ethertype filter to drop all flow control frames transmitted
1391 * from VSIs. By doing so, we stop VF from sending out PAUSE or PFC
1394 i40e_add_tx_flow_control_drop_filter(pf);
1396 /* Set the max frame size to 0x2600 by default,
1397 * in case other drivers changed the default value.
1399 i40e_aq_set_mac_config(hw, I40E_FRAME_SIZE_MAX, TRUE, 0, NULL);
1401 /* initialize mirror rule list */
1402 TAILQ_INIT(&pf->mirror_list);
1404 /* initialize Traffic Manager configuration */
1405 i40e_tm_conf_init(dev);
1407 /* Initialize customized information */
1408 i40e_init_customized_info(pf);
1410 ret = i40e_init_ethtype_filter_list(dev);
1412 goto err_init_ethtype_filter_list;
1413 ret = i40e_init_tunnel_filter_list(dev);
1415 goto err_init_tunnel_filter_list;
1416 ret = i40e_init_fdir_filter_list(dev);
1418 goto err_init_fdir_filter_list;
1420 /* initialize queue region configuration */
1421 i40e_init_queue_region_conf(dev);
1423 /* initialize rss configuration from rte_flow */
1424 memset(&pf->rss_info, 0,
1425 sizeof(struct i40e_rte_flow_rss_conf));
1429 err_init_fdir_filter_list:
1430 rte_free(pf->tunnel.hash_table);
1431 rte_free(pf->tunnel.hash_map);
1432 err_init_tunnel_filter_list:
1433 rte_free(pf->ethertype.hash_table);
1434 rte_free(pf->ethertype.hash_map);
1435 err_init_ethtype_filter_list:
1436 rte_free(dev->data->mac_addrs);
1438 i40e_vsi_release(pf->main_vsi);
1439 err_setup_pf_switch:
1441 err_configure_lan_hmc:
1442 (void)i40e_shutdown_lan_hmc(hw);
1444 i40e_res_pool_destroy(&pf->msix_pool);
1446 i40e_res_pool_destroy(&pf->qp_pool);
1449 err_get_capabilities:
1450 (void)i40e_shutdown_adminq(hw);
1456 i40e_rm_ethtype_filter_list(struct i40e_pf *pf)
1458 struct i40e_ethertype_filter *p_ethertype;
1459 struct i40e_ethertype_rule *ethertype_rule;
1461 ethertype_rule = &pf->ethertype;
1462 /* Remove all ethertype filter rules and hash */
1463 if (ethertype_rule->hash_map)
1464 rte_free(ethertype_rule->hash_map);
1465 if (ethertype_rule->hash_table)
1466 rte_hash_free(ethertype_rule->hash_table);
1468 while ((p_ethertype = TAILQ_FIRST(ðertype_rule->ethertype_list))) {
1469 TAILQ_REMOVE(ðertype_rule->ethertype_list,
1470 p_ethertype, rules);
1471 rte_free(p_ethertype);
1476 i40e_rm_tunnel_filter_list(struct i40e_pf *pf)
1478 struct i40e_tunnel_filter *p_tunnel;
1479 struct i40e_tunnel_rule *tunnel_rule;
1481 tunnel_rule = &pf->tunnel;
1482 /* Remove all tunnel director rules and hash */
1483 if (tunnel_rule->hash_map)
1484 rte_free(tunnel_rule->hash_map);
1485 if (tunnel_rule->hash_table)
1486 rte_hash_free(tunnel_rule->hash_table);
1488 while ((p_tunnel = TAILQ_FIRST(&tunnel_rule->tunnel_list))) {
1489 TAILQ_REMOVE(&tunnel_rule->tunnel_list, p_tunnel, rules);
1495 i40e_rm_fdir_filter_list(struct i40e_pf *pf)
1497 struct i40e_fdir_filter *p_fdir;
1498 struct i40e_fdir_info *fdir_info;
1500 fdir_info = &pf->fdir;
1501 /* Remove all flow director rules and hash */
1502 if (fdir_info->hash_map)
1503 rte_free(fdir_info->hash_map);
1504 if (fdir_info->hash_table)
1505 rte_hash_free(fdir_info->hash_table);
1507 while ((p_fdir = TAILQ_FIRST(&fdir_info->fdir_list))) {
1508 TAILQ_REMOVE(&fdir_info->fdir_list, p_fdir, rules);
1513 void i40e_flex_payload_reg_set_default(struct i40e_hw *hw)
1516 * Disable by default flexible payload
1517 * for corresponding L2/L3/L4 layers.
1519 I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(33), 0x00000000);
1520 I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(34), 0x00000000);
1521 I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(35), 0x00000000);
1522 i40e_global_cfg_warning(I40E_WARNING_DIS_FLX_PLD);
1526 eth_i40e_dev_uninit(struct rte_eth_dev *dev)
1529 struct rte_pci_device *pci_dev;
1530 struct rte_intr_handle *intr_handle;
1532 struct i40e_filter_control_settings settings;
1533 struct rte_flow *p_flow;
1535 uint8_t aq_fail = 0;
1537 PMD_INIT_FUNC_TRACE();
1539 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1542 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1543 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1544 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1545 intr_handle = &pci_dev->intr_handle;
1547 if (hw->adapter_stopped == 0)
1548 i40e_dev_close(dev);
1550 dev->dev_ops = NULL;
1551 dev->rx_pkt_burst = NULL;
1552 dev->tx_pkt_burst = NULL;
1554 /* Clear PXE mode */
1555 i40e_clear_pxe_mode(hw);
1557 /* Unconfigure filter control */
1558 memset(&settings, 0, sizeof(settings));
1559 ret = i40e_set_filter_control(hw, &settings);
1561 PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
1564 /* Disable flow control */
1565 hw->fc.requested_mode = I40E_FC_NONE;
1566 i40e_set_fc(hw, &aq_fail, TRUE);
1568 /* uninitialize pf host driver */
1569 i40e_pf_host_uninit(dev);
1571 rte_free(dev->data->mac_addrs);
1572 dev->data->mac_addrs = NULL;
1574 /* disable uio intr before callback unregister */
1575 rte_intr_disable(intr_handle);
1577 /* register callback func to eal lib */
1578 rte_intr_callback_unregister(intr_handle,
1579 i40e_dev_interrupt_handler, dev);
1581 i40e_rm_ethtype_filter_list(pf);
1582 i40e_rm_tunnel_filter_list(pf);
1583 i40e_rm_fdir_filter_list(pf);
1585 /* Remove all flows */
1586 while ((p_flow = TAILQ_FIRST(&pf->flow_list))) {
1587 TAILQ_REMOVE(&pf->flow_list, p_flow, node);
1591 /* Remove all Traffic Manager configuration */
1592 i40e_tm_conf_uninit(dev);
1598 i40e_dev_configure(struct rte_eth_dev *dev)
1600 struct i40e_adapter *ad =
1601 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1602 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1603 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1604 enum rte_eth_rx_mq_mode mq_mode = dev->data->dev_conf.rxmode.mq_mode;
1607 ret = i40e_dev_sync_phy_type(hw);
1611 /* Initialize to TRUE. If any of Rx queues doesn't meet the
1612 * bulk allocation or vector Rx preconditions we will reset it.
1614 ad->rx_bulk_alloc_allowed = true;
1615 ad->rx_vec_allowed = true;
1616 ad->tx_simple_allowed = true;
1617 ad->tx_vec_allowed = true;
1619 if (dev->data->dev_conf.fdir_conf.mode == RTE_FDIR_MODE_PERFECT) {
1620 ret = i40e_fdir_setup(pf);
1621 if (ret != I40E_SUCCESS) {
1622 PMD_DRV_LOG(ERR, "Failed to setup flow director.");
1625 ret = i40e_fdir_configure(dev);
1627 PMD_DRV_LOG(ERR, "failed to configure fdir.");
1631 i40e_fdir_teardown(pf);
1633 ret = i40e_dev_init_vlan(dev);
1638 * Needs to move VMDQ setting out of i40e_pf_config_mq_rx() as VMDQ and
1639 * RSS setting have different requirements.
1640 * General PMD driver call sequence are NIC init, configure,
1641 * rx/tx_queue_setup and dev_start. In rx/tx_queue_setup() function, it
1642 * will try to lookup the VSI that specific queue belongs to if VMDQ
1643 * applicable. So, VMDQ setting has to be done before
1644 * rx/tx_queue_setup(). This function is good to place vmdq_setup.
1645 * For RSS setting, it will try to calculate actual configured RX queue
1646 * number, which will be available after rx_queue_setup(). dev_start()
1647 * function is good to place RSS setup.
1649 if (mq_mode & ETH_MQ_RX_VMDQ_FLAG) {
1650 ret = i40e_vmdq_setup(dev);
1655 if (mq_mode & ETH_MQ_RX_DCB_FLAG) {
1656 ret = i40e_dcb_setup(dev);
1658 PMD_DRV_LOG(ERR, "failed to configure DCB.");
1663 TAILQ_INIT(&pf->flow_list);
1668 /* need to release vmdq resource if exists */
1669 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1670 i40e_vsi_release(pf->vmdq[i].vsi);
1671 pf->vmdq[i].vsi = NULL;
1676 /* need to release fdir resource if exists */
1677 i40e_fdir_teardown(pf);
1682 i40e_vsi_queues_unbind_intr(struct i40e_vsi *vsi)
1684 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1685 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1686 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1687 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1688 uint16_t msix_vect = vsi->msix_intr;
1691 for (i = 0; i < vsi->nb_qps; i++) {
1692 I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
1693 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
1697 if (vsi->type != I40E_VSI_SRIOV) {
1698 if (!rte_intr_allow_others(intr_handle)) {
1699 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
1700 I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
1702 I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
1705 I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
1706 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
1708 I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
1713 reg = (hw->func_caps.num_msix_vectors_vf - 1) *
1714 vsi->user_param + (msix_vect - 1);
1716 I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
1717 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
1719 I40E_WRITE_FLUSH(hw);
1723 __vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t msix_vect,
1724 int base_queue, int nb_queue,
1729 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1730 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
1732 /* Bind all RX queues to allocated MSIX interrupt */
1733 for (i = 0; i < nb_queue; i++) {
1734 val = (msix_vect << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
1735 itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT |
1736 ((base_queue + i + 1) <<
1737 I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
1738 (0 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
1739 I40E_QINT_RQCTL_CAUSE_ENA_MASK;
1741 if (i == nb_queue - 1)
1742 val |= I40E_QINT_RQCTL_NEXTQ_INDX_MASK;
1743 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(base_queue + i), val);
1746 /* Write first RX queue to Link list register as the head element */
1747 if (vsi->type != I40E_VSI_SRIOV) {
1749 i40e_calc_itr_interval(RTE_LIBRTE_I40E_ITR_INTERVAL, 1,
1750 pf->support_multi_driver);
1752 if (msix_vect == I40E_MISC_VEC_ID) {
1753 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
1755 I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
1757 I40E_PFINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
1759 I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
1762 I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
1764 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
1766 I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
1768 I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
1775 if (msix_vect == I40E_MISC_VEC_ID) {
1777 I40E_VPINT_LNKLST0(vsi->user_param),
1779 I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
1781 I40E_VPINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
1783 /* num_msix_vectors_vf needs to minus irq0 */
1784 reg = (hw->func_caps.num_msix_vectors_vf - 1) *
1785 vsi->user_param + (msix_vect - 1);
1787 I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
1789 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
1791 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
1795 I40E_WRITE_FLUSH(hw);
1799 i40e_vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t itr_idx)
1801 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1802 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1803 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1804 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1805 uint16_t msix_vect = vsi->msix_intr;
1806 uint16_t nb_msix = RTE_MIN(vsi->nb_msix, intr_handle->nb_efd);
1807 uint16_t queue_idx = 0;
1811 for (i = 0; i < vsi->nb_qps; i++) {
1812 I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
1813 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
1816 /* VF bind interrupt */
1817 if (vsi->type == I40E_VSI_SRIOV) {
1818 __vsi_queues_bind_intr(vsi, msix_vect,
1819 vsi->base_queue, vsi->nb_qps,
1824 /* PF & VMDq bind interrupt */
1825 if (rte_intr_dp_is_en(intr_handle)) {
1826 if (vsi->type == I40E_VSI_MAIN) {
1829 } else if (vsi->type == I40E_VSI_VMDQ2) {
1830 struct i40e_vsi *main_vsi =
1831 I40E_DEV_PRIVATE_TO_MAIN_VSI(vsi->adapter);
1832 queue_idx = vsi->base_queue - main_vsi->nb_qps;
1837 for (i = 0; i < vsi->nb_used_qps; i++) {
1839 if (!rte_intr_allow_others(intr_handle))
1840 /* allow to share MISC_VEC_ID */
1841 msix_vect = I40E_MISC_VEC_ID;
1843 /* no enough msix_vect, map all to one */
1844 __vsi_queues_bind_intr(vsi, msix_vect,
1845 vsi->base_queue + i,
1846 vsi->nb_used_qps - i,
1848 for (; !!record && i < vsi->nb_used_qps; i++)
1849 intr_handle->intr_vec[queue_idx + i] =
1853 /* 1:1 queue/msix_vect mapping */
1854 __vsi_queues_bind_intr(vsi, msix_vect,
1855 vsi->base_queue + i, 1,
1858 intr_handle->intr_vec[queue_idx + i] = msix_vect;
1866 i40e_vsi_enable_queues_intr(struct i40e_vsi *vsi)
1868 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1869 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1870 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1871 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1872 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
1873 uint16_t msix_intr, i;
1875 if (rte_intr_allow_others(intr_handle) && !pf->support_multi_driver)
1876 for (i = 0; i < vsi->nb_msix; i++) {
1877 msix_intr = vsi->msix_intr + i;
1878 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
1879 I40E_PFINT_DYN_CTLN_INTENA_MASK |
1880 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
1881 I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
1884 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
1885 I40E_PFINT_DYN_CTL0_INTENA_MASK |
1886 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
1887 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
1889 I40E_WRITE_FLUSH(hw);
1893 i40e_vsi_disable_queues_intr(struct i40e_vsi *vsi)
1895 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1896 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1897 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
1898 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1899 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
1900 uint16_t msix_intr, i;
1902 if (rte_intr_allow_others(intr_handle) && !pf->support_multi_driver)
1903 for (i = 0; i < vsi->nb_msix; i++) {
1904 msix_intr = vsi->msix_intr + i;
1905 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
1906 I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
1909 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
1910 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
1912 I40E_WRITE_FLUSH(hw);
1915 static inline uint8_t
1916 i40e_parse_link_speeds(uint16_t link_speeds)
1918 uint8_t link_speed = I40E_LINK_SPEED_UNKNOWN;
1920 if (link_speeds & ETH_LINK_SPEED_40G)
1921 link_speed |= I40E_LINK_SPEED_40GB;
1922 if (link_speeds & ETH_LINK_SPEED_25G)
1923 link_speed |= I40E_LINK_SPEED_25GB;
1924 if (link_speeds & ETH_LINK_SPEED_20G)
1925 link_speed |= I40E_LINK_SPEED_20GB;
1926 if (link_speeds & ETH_LINK_SPEED_10G)
1927 link_speed |= I40E_LINK_SPEED_10GB;
1928 if (link_speeds & ETH_LINK_SPEED_1G)
1929 link_speed |= I40E_LINK_SPEED_1GB;
1930 if (link_speeds & ETH_LINK_SPEED_100M)
1931 link_speed |= I40E_LINK_SPEED_100MB;
1937 i40e_phy_conf_link(struct i40e_hw *hw,
1939 uint8_t force_speed,
1942 enum i40e_status_code status;
1943 struct i40e_aq_get_phy_abilities_resp phy_ab;
1944 struct i40e_aq_set_phy_config phy_conf;
1945 enum i40e_aq_phy_type cnt;
1946 uint32_t phy_type_mask = 0;
1948 const uint8_t mask = I40E_AQ_PHY_FLAG_PAUSE_TX |
1949 I40E_AQ_PHY_FLAG_PAUSE_RX |
1950 I40E_AQ_PHY_FLAG_PAUSE_RX |
1951 I40E_AQ_PHY_FLAG_LOW_POWER;
1952 const uint8_t advt = I40E_LINK_SPEED_40GB |
1953 I40E_LINK_SPEED_25GB |
1954 I40E_LINK_SPEED_10GB |
1955 I40E_LINK_SPEED_1GB |
1956 I40E_LINK_SPEED_100MB;
1960 status = i40e_aq_get_phy_capabilities(hw, false, false, &phy_ab,
1965 /* If link already up, no need to set up again */
1966 if (is_up && phy_ab.phy_type != 0)
1967 return I40E_SUCCESS;
1969 memset(&phy_conf, 0, sizeof(phy_conf));
1971 /* bits 0-2 use the values from get_phy_abilities_resp */
1973 abilities |= phy_ab.abilities & mask;
1975 /* update ablities and speed */
1976 if (abilities & I40E_AQ_PHY_AN_ENABLED)
1977 phy_conf.link_speed = advt;
1979 phy_conf.link_speed = is_up ? force_speed : phy_ab.link_speed;
1981 phy_conf.abilities = abilities;
1985 /* To enable link, phy_type mask needs to include each type */
1986 for (cnt = I40E_PHY_TYPE_SGMII; cnt < I40E_PHY_TYPE_MAX; cnt++)
1987 phy_type_mask |= 1 << cnt;
1989 /* use get_phy_abilities_resp value for the rest */
1990 phy_conf.phy_type = is_up ? cpu_to_le32(phy_type_mask) : 0;
1991 phy_conf.phy_type_ext = is_up ? (I40E_AQ_PHY_TYPE_EXT_25G_KR |
1992 I40E_AQ_PHY_TYPE_EXT_25G_CR | I40E_AQ_PHY_TYPE_EXT_25G_SR |
1993 I40E_AQ_PHY_TYPE_EXT_25G_LR) : 0;
1994 phy_conf.fec_config = phy_ab.fec_cfg_curr_mod_ext_info;
1995 phy_conf.eee_capability = phy_ab.eee_capability;
1996 phy_conf.eeer = phy_ab.eeer_val;
1997 phy_conf.low_power_ctrl = phy_ab.d3_lpan;
1999 PMD_DRV_LOG(DEBUG, "\tCurrent: abilities %x, link_speed %x",
2000 phy_ab.abilities, phy_ab.link_speed);
2001 PMD_DRV_LOG(DEBUG, "\tConfig: abilities %x, link_speed %x",
2002 phy_conf.abilities, phy_conf.link_speed);
2004 status = i40e_aq_set_phy_config(hw, &phy_conf, NULL);
2008 return I40E_SUCCESS;
2012 i40e_apply_link_speed(struct rte_eth_dev *dev)
2015 uint8_t abilities = 0;
2016 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2017 struct rte_eth_conf *conf = &dev->data->dev_conf;
2019 speed = i40e_parse_link_speeds(conf->link_speeds);
2020 abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
2021 if (!(conf->link_speeds & ETH_LINK_SPEED_FIXED))
2022 abilities |= I40E_AQ_PHY_AN_ENABLED;
2023 abilities |= I40E_AQ_PHY_LINK_ENABLED;
2025 return i40e_phy_conf_link(hw, abilities, speed, true);
2029 i40e_dev_start(struct rte_eth_dev *dev)
2031 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2032 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2033 struct i40e_vsi *main_vsi = pf->main_vsi;
2035 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2036 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2037 uint32_t intr_vector = 0;
2038 struct i40e_vsi *vsi;
2040 hw->adapter_stopped = 0;
2042 if (dev->data->dev_conf.link_speeds & ETH_LINK_SPEED_FIXED) {
2044 "Invalid link_speeds for port %u, autonegotiation disabled",
2045 dev->data->port_id);
2049 rte_intr_disable(intr_handle);
2051 if ((rte_intr_cap_multiple(intr_handle) ||
2052 !RTE_ETH_DEV_SRIOV(dev).active) &&
2053 dev->data->dev_conf.intr_conf.rxq != 0) {
2054 intr_vector = dev->data->nb_rx_queues;
2055 ret = rte_intr_efd_enable(intr_handle, intr_vector);
2060 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
2061 intr_handle->intr_vec =
2062 rte_zmalloc("intr_vec",
2063 dev->data->nb_rx_queues * sizeof(int),
2065 if (!intr_handle->intr_vec) {
2067 "Failed to allocate %d rx_queues intr_vec",
2068 dev->data->nb_rx_queues);
2073 /* Initialize VSI */
2074 ret = i40e_dev_rxtx_init(pf);
2075 if (ret != I40E_SUCCESS) {
2076 PMD_DRV_LOG(ERR, "Failed to init rx/tx queues");
2080 /* Map queues with MSIX interrupt */
2081 main_vsi->nb_used_qps = dev->data->nb_rx_queues -
2082 pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
2083 i40e_vsi_queues_bind_intr(main_vsi, I40E_ITR_INDEX_DEFAULT);
2084 i40e_vsi_enable_queues_intr(main_vsi);
2086 /* Map VMDQ VSI queues with MSIX interrupt */
2087 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2088 pf->vmdq[i].vsi->nb_used_qps = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
2089 i40e_vsi_queues_bind_intr(pf->vmdq[i].vsi,
2090 I40E_ITR_INDEX_DEFAULT);
2091 i40e_vsi_enable_queues_intr(pf->vmdq[i].vsi);
2094 /* enable FDIR MSIX interrupt */
2095 if (pf->fdir.fdir_vsi) {
2096 i40e_vsi_queues_bind_intr(pf->fdir.fdir_vsi,
2097 I40E_ITR_INDEX_NONE);
2098 i40e_vsi_enable_queues_intr(pf->fdir.fdir_vsi);
2101 /* Enable all queues which have been configured */
2102 ret = i40e_dev_switch_queues(pf, TRUE);
2103 if (ret != I40E_SUCCESS) {
2104 PMD_DRV_LOG(ERR, "Failed to enable VSI");
2108 /* Enable receiving broadcast packets */
2109 ret = i40e_aq_set_vsi_broadcast(hw, main_vsi->seid, true, NULL);
2110 if (ret != I40E_SUCCESS)
2111 PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
2113 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2114 ret = i40e_aq_set_vsi_broadcast(hw, pf->vmdq[i].vsi->seid,
2116 if (ret != I40E_SUCCESS)
2117 PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
2120 /* Enable the VLAN promiscuous mode. */
2122 for (i = 0; i < pf->vf_num; i++) {
2123 vsi = pf->vfs[i].vsi;
2124 i40e_aq_set_vsi_vlan_promisc(hw, vsi->seid,
2129 /* Enable mac loopback mode */
2130 if (dev->data->dev_conf.lpbk_mode == I40E_AQ_LB_MODE_NONE ||
2131 dev->data->dev_conf.lpbk_mode == I40E_AQ_LB_PHY_LOCAL) {
2132 ret = i40e_aq_set_lb_modes(hw, dev->data->dev_conf.lpbk_mode, NULL);
2133 if (ret != I40E_SUCCESS) {
2134 PMD_DRV_LOG(ERR, "fail to set loopback link");
2139 /* Apply link configure */
2140 if (dev->data->dev_conf.link_speeds & ~(ETH_LINK_SPEED_100M |
2141 ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G |
2142 ETH_LINK_SPEED_20G | ETH_LINK_SPEED_25G |
2143 ETH_LINK_SPEED_40G)) {
2144 PMD_DRV_LOG(ERR, "Invalid link setting");
2147 ret = i40e_apply_link_speed(dev);
2148 if (I40E_SUCCESS != ret) {
2149 PMD_DRV_LOG(ERR, "Fail to apply link setting");
2153 if (!rte_intr_allow_others(intr_handle)) {
2154 rte_intr_callback_unregister(intr_handle,
2155 i40e_dev_interrupt_handler,
2157 /* configure and enable device interrupt */
2158 i40e_pf_config_irq0(hw, FALSE);
2159 i40e_pf_enable_irq0(hw);
2161 if (dev->data->dev_conf.intr_conf.lsc != 0)
2163 "lsc won't enable because of no intr multiplex");
2165 ret = i40e_aq_set_phy_int_mask(hw,
2166 ~(I40E_AQ_EVENT_LINK_UPDOWN |
2167 I40E_AQ_EVENT_MODULE_QUAL_FAIL |
2168 I40E_AQ_EVENT_MEDIA_NA), NULL);
2169 if (ret != I40E_SUCCESS)
2170 PMD_DRV_LOG(WARNING, "Fail to set phy mask");
2172 /* Call get_link_info aq commond to enable/disable LSE */
2173 i40e_dev_link_update(dev, 0);
2176 /* enable uio intr after callback register */
2177 rte_intr_enable(intr_handle);
2179 i40e_filter_restore(pf);
2181 if (pf->tm_conf.root && !pf->tm_conf.committed)
2182 PMD_DRV_LOG(WARNING,
2183 "please call hierarchy_commit() "
2184 "before starting the port");
2186 return I40E_SUCCESS;
2189 i40e_dev_switch_queues(pf, FALSE);
2190 i40e_dev_clear_queues(dev);
2196 i40e_dev_stop(struct rte_eth_dev *dev)
2198 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2199 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2200 struct i40e_vsi *main_vsi = pf->main_vsi;
2201 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2202 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2205 if (hw->adapter_stopped == 1)
2207 /* Disable all queues */
2208 i40e_dev_switch_queues(pf, FALSE);
2210 /* un-map queues with interrupt registers */
2211 i40e_vsi_disable_queues_intr(main_vsi);
2212 i40e_vsi_queues_unbind_intr(main_vsi);
2214 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2215 i40e_vsi_disable_queues_intr(pf->vmdq[i].vsi);
2216 i40e_vsi_queues_unbind_intr(pf->vmdq[i].vsi);
2219 if (pf->fdir.fdir_vsi) {
2220 i40e_vsi_queues_unbind_intr(pf->fdir.fdir_vsi);
2221 i40e_vsi_disable_queues_intr(pf->fdir.fdir_vsi);
2223 /* Clear all queues and release memory */
2224 i40e_dev_clear_queues(dev);
2227 i40e_dev_set_link_down(dev);
2229 if (!rte_intr_allow_others(intr_handle))
2230 /* resume to the default handler */
2231 rte_intr_callback_register(intr_handle,
2232 i40e_dev_interrupt_handler,
2235 /* Clean datapath event and queue/vec mapping */
2236 rte_intr_efd_disable(intr_handle);
2237 if (intr_handle->intr_vec) {
2238 rte_free(intr_handle->intr_vec);
2239 intr_handle->intr_vec = NULL;
2242 /* reset hierarchy commit */
2243 pf->tm_conf.committed = false;
2245 hw->adapter_stopped = 1;
2249 i40e_dev_close(struct rte_eth_dev *dev)
2251 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2252 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2253 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2254 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
2255 struct i40e_mirror_rule *p_mirror;
2260 PMD_INIT_FUNC_TRACE();
2264 /* Remove all mirror rules */
2265 while ((p_mirror = TAILQ_FIRST(&pf->mirror_list))) {
2266 ret = i40e_aq_del_mirror_rule(hw,
2267 pf->main_vsi->veb->seid,
2268 p_mirror->rule_type,
2270 p_mirror->num_entries,
2273 PMD_DRV_LOG(ERR, "failed to remove mirror rule: "
2274 "status = %d, aq_err = %d.", ret,
2275 hw->aq.asq_last_status);
2277 /* remove mirror software resource anyway */
2278 TAILQ_REMOVE(&pf->mirror_list, p_mirror, rules);
2280 pf->nb_mirror_rule--;
2283 i40e_dev_free_queues(dev);
2285 /* Disable interrupt */
2286 i40e_pf_disable_irq0(hw);
2287 rte_intr_disable(intr_handle);
2289 /* shutdown and destroy the HMC */
2290 i40e_shutdown_lan_hmc(hw);
2292 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2293 i40e_vsi_release(pf->vmdq[i].vsi);
2294 pf->vmdq[i].vsi = NULL;
2299 /* release all the existing VSIs and VEBs */
2300 i40e_fdir_teardown(pf);
2301 i40e_vsi_release(pf->main_vsi);
2303 /* shutdown the adminq */
2304 i40e_aq_queue_shutdown(hw, true);
2305 i40e_shutdown_adminq(hw);
2307 i40e_res_pool_destroy(&pf->qp_pool);
2308 i40e_res_pool_destroy(&pf->msix_pool);
2310 /* Disable flexible payload in global configuration */
2311 if (!pf->support_multi_driver)
2312 i40e_flex_payload_reg_set_default(hw);
2314 /* force a PF reset to clean anything leftover */
2315 reg = I40E_READ_REG(hw, I40E_PFGEN_CTRL);
2316 I40E_WRITE_REG(hw, I40E_PFGEN_CTRL,
2317 (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
2318 I40E_WRITE_FLUSH(hw);
2322 * Reset PF device only to re-initialize resources in PMD layer
2325 i40e_dev_reset(struct rte_eth_dev *dev)
2329 /* When a DPDK PMD PF begin to reset PF port, it should notify all
2330 * its VF to make them align with it. The detailed notification
2331 * mechanism is PMD specific. As to i40e PF, it is rather complex.
2332 * To avoid unexpected behavior in VF, currently reset of PF with
2333 * SR-IOV activation is not supported. It might be supported later.
2335 if (dev->data->sriov.active)
2338 ret = eth_i40e_dev_uninit(dev);
2342 ret = eth_i40e_dev_init(dev);
2348 i40e_dev_promiscuous_enable(struct rte_eth_dev *dev)
2350 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2351 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2352 struct i40e_vsi *vsi = pf->main_vsi;
2355 status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2357 if (status != I40E_SUCCESS)
2358 PMD_DRV_LOG(ERR, "Failed to enable unicast promiscuous");
2360 status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
2362 if (status != I40E_SUCCESS)
2363 PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
2368 i40e_dev_promiscuous_disable(struct rte_eth_dev *dev)
2370 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2371 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2372 struct i40e_vsi *vsi = pf->main_vsi;
2375 status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2377 if (status != I40E_SUCCESS)
2378 PMD_DRV_LOG(ERR, "Failed to disable unicast promiscuous");
2380 status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
2382 if (status != I40E_SUCCESS)
2383 PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
2387 i40e_dev_allmulticast_enable(struct rte_eth_dev *dev)
2389 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2390 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2391 struct i40e_vsi *vsi = pf->main_vsi;
2394 ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid, TRUE, NULL);
2395 if (ret != I40E_SUCCESS)
2396 PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
2400 i40e_dev_allmulticast_disable(struct rte_eth_dev *dev)
2402 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2403 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2404 struct i40e_vsi *vsi = pf->main_vsi;
2407 if (dev->data->promiscuous == 1)
2408 return; /* must remain in all_multicast mode */
2410 ret = i40e_aq_set_vsi_multicast_promiscuous(hw,
2411 vsi->seid, FALSE, NULL);
2412 if (ret != I40E_SUCCESS)
2413 PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
2417 * Set device link up.
2420 i40e_dev_set_link_up(struct rte_eth_dev *dev)
2422 /* re-apply link speed setting */
2423 return i40e_apply_link_speed(dev);
2427 * Set device link down.
2430 i40e_dev_set_link_down(struct rte_eth_dev *dev)
2432 uint8_t speed = I40E_LINK_SPEED_UNKNOWN;
2433 uint8_t abilities = 0;
2434 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2436 abilities = I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
2437 return i40e_phy_conf_link(hw, abilities, speed, false);
2441 i40e_dev_link_update(struct rte_eth_dev *dev,
2442 int wait_to_complete)
2444 #define CHECK_INTERVAL 100 /* 100ms */
2445 #define MAX_REPEAT_TIME 10 /* 1s (10 * 100ms) in total */
2446 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2447 struct i40e_link_status link_status;
2448 struct rte_eth_link link, old;
2450 unsigned rep_cnt = MAX_REPEAT_TIME;
2451 bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
2453 memset(&link, 0, sizeof(link));
2454 memset(&old, 0, sizeof(old));
2455 memset(&link_status, 0, sizeof(link_status));
2456 rte_i40e_dev_atomic_read_link_status(dev, &old);
2459 /* Get link status information from hardware */
2460 status = i40e_aq_get_link_info(hw, enable_lse,
2461 &link_status, NULL);
2462 if (status != I40E_SUCCESS) {
2463 link.link_speed = ETH_SPEED_NUM_100M;
2464 link.link_duplex = ETH_LINK_FULL_DUPLEX;
2465 PMD_DRV_LOG(ERR, "Failed to get link info");
2469 link.link_status = link_status.link_info & I40E_AQ_LINK_UP;
2470 if (!wait_to_complete || link.link_status)
2473 rte_delay_ms(CHECK_INTERVAL);
2474 } while (--rep_cnt);
2476 if (!link.link_status)
2479 /* i40e uses full duplex only */
2480 link.link_duplex = ETH_LINK_FULL_DUPLEX;
2482 /* Parse the link status */
2483 switch (link_status.link_speed) {
2484 case I40E_LINK_SPEED_100MB:
2485 link.link_speed = ETH_SPEED_NUM_100M;
2487 case I40E_LINK_SPEED_1GB:
2488 link.link_speed = ETH_SPEED_NUM_1G;
2490 case I40E_LINK_SPEED_10GB:
2491 link.link_speed = ETH_SPEED_NUM_10G;
2493 case I40E_LINK_SPEED_20GB:
2494 link.link_speed = ETH_SPEED_NUM_20G;
2496 case I40E_LINK_SPEED_25GB:
2497 link.link_speed = ETH_SPEED_NUM_25G;
2499 case I40E_LINK_SPEED_40GB:
2500 link.link_speed = ETH_SPEED_NUM_40G;
2503 link.link_speed = ETH_SPEED_NUM_100M;
2507 link.link_autoneg = !(dev->data->dev_conf.link_speeds &
2508 ETH_LINK_SPEED_FIXED);
2511 rte_i40e_dev_atomic_write_link_status(dev, &link);
2512 if (link.link_status == old.link_status)
2515 i40e_notify_all_vfs_link_status(dev);
2520 /* Get all the statistics of a VSI */
2522 i40e_update_vsi_stats(struct i40e_vsi *vsi)
2524 struct i40e_eth_stats *oes = &vsi->eth_stats_offset;
2525 struct i40e_eth_stats *nes = &vsi->eth_stats;
2526 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2527 int idx = rte_le_to_cpu_16(vsi->info.stat_counter_idx);
2529 i40e_stat_update_48(hw, I40E_GLV_GORCH(idx), I40E_GLV_GORCL(idx),
2530 vsi->offset_loaded, &oes->rx_bytes,
2532 i40e_stat_update_48(hw, I40E_GLV_UPRCH(idx), I40E_GLV_UPRCL(idx),
2533 vsi->offset_loaded, &oes->rx_unicast,
2535 i40e_stat_update_48(hw, I40E_GLV_MPRCH(idx), I40E_GLV_MPRCL(idx),
2536 vsi->offset_loaded, &oes->rx_multicast,
2537 &nes->rx_multicast);
2538 i40e_stat_update_48(hw, I40E_GLV_BPRCH(idx), I40E_GLV_BPRCL(idx),
2539 vsi->offset_loaded, &oes->rx_broadcast,
2540 &nes->rx_broadcast);
2541 /* exclude CRC bytes */
2542 nes->rx_bytes -= (nes->rx_unicast + nes->rx_multicast +
2543 nes->rx_broadcast) * ETHER_CRC_LEN;
2545 i40e_stat_update_32(hw, I40E_GLV_RDPC(idx), vsi->offset_loaded,
2546 &oes->rx_discards, &nes->rx_discards);
2547 /* GLV_REPC not supported */
2548 /* GLV_RMPC not supported */
2549 i40e_stat_update_32(hw, I40E_GLV_RUPP(idx), vsi->offset_loaded,
2550 &oes->rx_unknown_protocol,
2551 &nes->rx_unknown_protocol);
2552 i40e_stat_update_48(hw, I40E_GLV_GOTCH(idx), I40E_GLV_GOTCL(idx),
2553 vsi->offset_loaded, &oes->tx_bytes,
2555 i40e_stat_update_48(hw, I40E_GLV_UPTCH(idx), I40E_GLV_UPTCL(idx),
2556 vsi->offset_loaded, &oes->tx_unicast,
2558 i40e_stat_update_48(hw, I40E_GLV_MPTCH(idx), I40E_GLV_MPTCL(idx),
2559 vsi->offset_loaded, &oes->tx_multicast,
2560 &nes->tx_multicast);
2561 i40e_stat_update_48(hw, I40E_GLV_BPTCH(idx), I40E_GLV_BPTCL(idx),
2562 vsi->offset_loaded, &oes->tx_broadcast,
2563 &nes->tx_broadcast);
2564 /* GLV_TDPC not supported */
2565 i40e_stat_update_32(hw, I40E_GLV_TEPC(idx), vsi->offset_loaded,
2566 &oes->tx_errors, &nes->tx_errors);
2567 vsi->offset_loaded = true;
2569 PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats start *******************",
2571 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", nes->rx_bytes);
2572 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", nes->rx_unicast);
2573 PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", nes->rx_multicast);
2574 PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", nes->rx_broadcast);
2575 PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", nes->rx_discards);
2576 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
2577 nes->rx_unknown_protocol);
2578 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", nes->tx_bytes);
2579 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", nes->tx_unicast);
2580 PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", nes->tx_multicast);
2581 PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", nes->tx_broadcast);
2582 PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", nes->tx_discards);
2583 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", nes->tx_errors);
2584 PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats end *******************",
2589 i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw)
2592 struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
2593 struct i40e_hw_port_stats *os = &pf->stats_offset; /* old stats */
2595 /* Get rx/tx bytes of internal transfer packets */
2596 i40e_stat_update_48(hw, I40E_GLV_GORCH(hw->port),
2597 I40E_GLV_GORCL(hw->port),
2599 &pf->internal_stats_offset.rx_bytes,
2600 &pf->internal_stats.rx_bytes);
2602 i40e_stat_update_48(hw, I40E_GLV_GOTCH(hw->port),
2603 I40E_GLV_GOTCL(hw->port),
2605 &pf->internal_stats_offset.tx_bytes,
2606 &pf->internal_stats.tx_bytes);
2607 /* Get total internal rx packet count */
2608 i40e_stat_update_48(hw, I40E_GLV_UPRCH(hw->port),
2609 I40E_GLV_UPRCL(hw->port),
2611 &pf->internal_stats_offset.rx_unicast,
2612 &pf->internal_stats.rx_unicast);
2613 i40e_stat_update_48(hw, I40E_GLV_MPRCH(hw->port),
2614 I40E_GLV_MPRCL(hw->port),
2616 &pf->internal_stats_offset.rx_multicast,
2617 &pf->internal_stats.rx_multicast);
2618 i40e_stat_update_48(hw, I40E_GLV_BPRCH(hw->port),
2619 I40E_GLV_BPRCL(hw->port),
2621 &pf->internal_stats_offset.rx_broadcast,
2622 &pf->internal_stats.rx_broadcast);
2623 /* Get total internal tx packet count */
2624 i40e_stat_update_48(hw, I40E_GLV_UPTCH(hw->port),
2625 I40E_GLV_UPTCL(hw->port),
2627 &pf->internal_stats_offset.tx_unicast,
2628 &pf->internal_stats.tx_unicast);
2629 i40e_stat_update_48(hw, I40E_GLV_MPTCH(hw->port),
2630 I40E_GLV_MPTCL(hw->port),
2632 &pf->internal_stats_offset.tx_multicast,
2633 &pf->internal_stats.tx_multicast);
2634 i40e_stat_update_48(hw, I40E_GLV_BPTCH(hw->port),
2635 I40E_GLV_BPTCL(hw->port),
2637 &pf->internal_stats_offset.tx_broadcast,
2638 &pf->internal_stats.tx_broadcast);
2640 /* exclude CRC size */
2641 pf->internal_stats.rx_bytes -= (pf->internal_stats.rx_unicast +
2642 pf->internal_stats.rx_multicast +
2643 pf->internal_stats.rx_broadcast) * ETHER_CRC_LEN;
2645 /* Get statistics of struct i40e_eth_stats */
2646 i40e_stat_update_48(hw, I40E_GLPRT_GORCH(hw->port),
2647 I40E_GLPRT_GORCL(hw->port),
2648 pf->offset_loaded, &os->eth.rx_bytes,
2650 i40e_stat_update_48(hw, I40E_GLPRT_UPRCH(hw->port),
2651 I40E_GLPRT_UPRCL(hw->port),
2652 pf->offset_loaded, &os->eth.rx_unicast,
2653 &ns->eth.rx_unicast);
2654 i40e_stat_update_48(hw, I40E_GLPRT_MPRCH(hw->port),
2655 I40E_GLPRT_MPRCL(hw->port),
2656 pf->offset_loaded, &os->eth.rx_multicast,
2657 &ns->eth.rx_multicast);
2658 i40e_stat_update_48(hw, I40E_GLPRT_BPRCH(hw->port),
2659 I40E_GLPRT_BPRCL(hw->port),
2660 pf->offset_loaded, &os->eth.rx_broadcast,
2661 &ns->eth.rx_broadcast);
2662 /* Workaround: CRC size should not be included in byte statistics,
2663 * so subtract ETHER_CRC_LEN from the byte counter for each rx packet.
2665 ns->eth.rx_bytes -= (ns->eth.rx_unicast + ns->eth.rx_multicast +
2666 ns->eth.rx_broadcast) * ETHER_CRC_LEN;
2668 /* exclude internal rx bytes
2669 * Workaround: it is possible I40E_GLV_GORCH[H/L] is updated before
2670 * I40E_GLPRT_GORCH[H/L], so there is a small window that cause negative
2672 * same to I40E_GLV_UPRC[H/L], I40E_GLV_MPRC[H/L], I40E_GLV_BPRC[H/L].
2674 if (ns->eth.rx_bytes < pf->internal_stats.rx_bytes)
2675 ns->eth.rx_bytes = 0;
2677 ns->eth.rx_bytes -= pf->internal_stats.rx_bytes;
2679 if (ns->eth.rx_unicast < pf->internal_stats.rx_unicast)
2680 ns->eth.rx_unicast = 0;
2682 ns->eth.rx_unicast -= pf->internal_stats.rx_unicast;
2684 if (ns->eth.rx_multicast < pf->internal_stats.rx_multicast)
2685 ns->eth.rx_multicast = 0;
2687 ns->eth.rx_multicast -= pf->internal_stats.rx_multicast;
2689 if (ns->eth.rx_broadcast < pf->internal_stats.rx_broadcast)
2690 ns->eth.rx_broadcast = 0;
2692 ns->eth.rx_broadcast -= pf->internal_stats.rx_broadcast;
2694 i40e_stat_update_32(hw, I40E_GLPRT_RDPC(hw->port),
2695 pf->offset_loaded, &os->eth.rx_discards,
2696 &ns->eth.rx_discards);
2697 /* GLPRT_REPC not supported */
2698 /* GLPRT_RMPC not supported */
2699 i40e_stat_update_32(hw, I40E_GLPRT_RUPP(hw->port),
2701 &os->eth.rx_unknown_protocol,
2702 &ns->eth.rx_unknown_protocol);
2703 i40e_stat_update_48(hw, I40E_GLPRT_GOTCH(hw->port),
2704 I40E_GLPRT_GOTCL(hw->port),
2705 pf->offset_loaded, &os->eth.tx_bytes,
2707 i40e_stat_update_48(hw, I40E_GLPRT_UPTCH(hw->port),
2708 I40E_GLPRT_UPTCL(hw->port),
2709 pf->offset_loaded, &os->eth.tx_unicast,
2710 &ns->eth.tx_unicast);
2711 i40e_stat_update_48(hw, I40E_GLPRT_MPTCH(hw->port),
2712 I40E_GLPRT_MPTCL(hw->port),
2713 pf->offset_loaded, &os->eth.tx_multicast,
2714 &ns->eth.tx_multicast);
2715 i40e_stat_update_48(hw, I40E_GLPRT_BPTCH(hw->port),
2716 I40E_GLPRT_BPTCL(hw->port),
2717 pf->offset_loaded, &os->eth.tx_broadcast,
2718 &ns->eth.tx_broadcast);
2719 ns->eth.tx_bytes -= (ns->eth.tx_unicast + ns->eth.tx_multicast +
2720 ns->eth.tx_broadcast) * ETHER_CRC_LEN;
2722 /* exclude internal tx bytes
2723 * Workaround: it is possible I40E_GLV_GOTCH[H/L] is updated before
2724 * I40E_GLPRT_GOTCH[H/L], so there is a small window that cause negative
2726 * same to I40E_GLV_UPTC[H/L], I40E_GLV_MPTC[H/L], I40E_GLV_BPTC[H/L].
2728 if (ns->eth.tx_bytes < pf->internal_stats.tx_bytes)
2729 ns->eth.tx_bytes = 0;
2731 ns->eth.tx_bytes -= pf->internal_stats.tx_bytes;
2733 if (ns->eth.tx_unicast < pf->internal_stats.tx_unicast)
2734 ns->eth.tx_unicast = 0;
2736 ns->eth.tx_unicast -= pf->internal_stats.tx_unicast;
2738 if (ns->eth.tx_multicast < pf->internal_stats.tx_multicast)
2739 ns->eth.tx_multicast = 0;
2741 ns->eth.tx_multicast -= pf->internal_stats.tx_multicast;
2743 if (ns->eth.tx_broadcast < pf->internal_stats.tx_broadcast)
2744 ns->eth.tx_broadcast = 0;
2746 ns->eth.tx_broadcast -= pf->internal_stats.tx_broadcast;
2748 /* GLPRT_TEPC not supported */
2750 /* additional port specific stats */
2751 i40e_stat_update_32(hw, I40E_GLPRT_TDOLD(hw->port),
2752 pf->offset_loaded, &os->tx_dropped_link_down,
2753 &ns->tx_dropped_link_down);
2754 i40e_stat_update_32(hw, I40E_GLPRT_CRCERRS(hw->port),
2755 pf->offset_loaded, &os->crc_errors,
2757 i40e_stat_update_32(hw, I40E_GLPRT_ILLERRC(hw->port),
2758 pf->offset_loaded, &os->illegal_bytes,
2759 &ns->illegal_bytes);
2760 /* GLPRT_ERRBC not supported */
2761 i40e_stat_update_32(hw, I40E_GLPRT_MLFC(hw->port),
2762 pf->offset_loaded, &os->mac_local_faults,
2763 &ns->mac_local_faults);
2764 i40e_stat_update_32(hw, I40E_GLPRT_MRFC(hw->port),
2765 pf->offset_loaded, &os->mac_remote_faults,
2766 &ns->mac_remote_faults);
2767 i40e_stat_update_32(hw, I40E_GLPRT_RLEC(hw->port),
2768 pf->offset_loaded, &os->rx_length_errors,
2769 &ns->rx_length_errors);
2770 i40e_stat_update_32(hw, I40E_GLPRT_LXONRXC(hw->port),
2771 pf->offset_loaded, &os->link_xon_rx,
2773 i40e_stat_update_32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
2774 pf->offset_loaded, &os->link_xoff_rx,
2776 for (i = 0; i < 8; i++) {
2777 i40e_stat_update_32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
2779 &os->priority_xon_rx[i],
2780 &ns->priority_xon_rx[i]);
2781 i40e_stat_update_32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
2783 &os->priority_xoff_rx[i],
2784 &ns->priority_xoff_rx[i]);
2786 i40e_stat_update_32(hw, I40E_GLPRT_LXONTXC(hw->port),
2787 pf->offset_loaded, &os->link_xon_tx,
2789 i40e_stat_update_32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
2790 pf->offset_loaded, &os->link_xoff_tx,
2792 for (i = 0; i < 8; i++) {
2793 i40e_stat_update_32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
2795 &os->priority_xon_tx[i],
2796 &ns->priority_xon_tx[i]);
2797 i40e_stat_update_32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
2799 &os->priority_xoff_tx[i],
2800 &ns->priority_xoff_tx[i]);
2801 i40e_stat_update_32(hw, I40E_GLPRT_RXON2OFFCNT(hw->port, i),
2803 &os->priority_xon_2_xoff[i],
2804 &ns->priority_xon_2_xoff[i]);
2806 i40e_stat_update_48(hw, I40E_GLPRT_PRC64H(hw->port),
2807 I40E_GLPRT_PRC64L(hw->port),
2808 pf->offset_loaded, &os->rx_size_64,
2810 i40e_stat_update_48(hw, I40E_GLPRT_PRC127H(hw->port),
2811 I40E_GLPRT_PRC127L(hw->port),
2812 pf->offset_loaded, &os->rx_size_127,
2814 i40e_stat_update_48(hw, I40E_GLPRT_PRC255H(hw->port),
2815 I40E_GLPRT_PRC255L(hw->port),
2816 pf->offset_loaded, &os->rx_size_255,
2818 i40e_stat_update_48(hw, I40E_GLPRT_PRC511H(hw->port),
2819 I40E_GLPRT_PRC511L(hw->port),
2820 pf->offset_loaded, &os->rx_size_511,
2822 i40e_stat_update_48(hw, I40E_GLPRT_PRC1023H(hw->port),
2823 I40E_GLPRT_PRC1023L(hw->port),
2824 pf->offset_loaded, &os->rx_size_1023,
2826 i40e_stat_update_48(hw, I40E_GLPRT_PRC1522H(hw->port),
2827 I40E_GLPRT_PRC1522L(hw->port),
2828 pf->offset_loaded, &os->rx_size_1522,
2830 i40e_stat_update_48(hw, I40E_GLPRT_PRC9522H(hw->port),
2831 I40E_GLPRT_PRC9522L(hw->port),
2832 pf->offset_loaded, &os->rx_size_big,
2834 i40e_stat_update_32(hw, I40E_GLPRT_RUC(hw->port),
2835 pf->offset_loaded, &os->rx_undersize,
2837 i40e_stat_update_32(hw, I40E_GLPRT_RFC(hw->port),
2838 pf->offset_loaded, &os->rx_fragments,
2840 i40e_stat_update_32(hw, I40E_GLPRT_ROC(hw->port),
2841 pf->offset_loaded, &os->rx_oversize,
2843 i40e_stat_update_32(hw, I40E_GLPRT_RJC(hw->port),
2844 pf->offset_loaded, &os->rx_jabber,
2846 i40e_stat_update_48(hw, I40E_GLPRT_PTC64H(hw->port),
2847 I40E_GLPRT_PTC64L(hw->port),
2848 pf->offset_loaded, &os->tx_size_64,
2850 i40e_stat_update_48(hw, I40E_GLPRT_PTC127H(hw->port),
2851 I40E_GLPRT_PTC127L(hw->port),
2852 pf->offset_loaded, &os->tx_size_127,
2854 i40e_stat_update_48(hw, I40E_GLPRT_PTC255H(hw->port),
2855 I40E_GLPRT_PTC255L(hw->port),
2856 pf->offset_loaded, &os->tx_size_255,
2858 i40e_stat_update_48(hw, I40E_GLPRT_PTC511H(hw->port),
2859 I40E_GLPRT_PTC511L(hw->port),
2860 pf->offset_loaded, &os->tx_size_511,
2862 i40e_stat_update_48(hw, I40E_GLPRT_PTC1023H(hw->port),
2863 I40E_GLPRT_PTC1023L(hw->port),
2864 pf->offset_loaded, &os->tx_size_1023,
2866 i40e_stat_update_48(hw, I40E_GLPRT_PTC1522H(hw->port),
2867 I40E_GLPRT_PTC1522L(hw->port),
2868 pf->offset_loaded, &os->tx_size_1522,
2870 i40e_stat_update_48(hw, I40E_GLPRT_PTC9522H(hw->port),
2871 I40E_GLPRT_PTC9522L(hw->port),
2872 pf->offset_loaded, &os->tx_size_big,
2874 i40e_stat_update_32(hw, I40E_GLQF_PCNT(pf->fdir.match_counter_index),
2876 &os->fd_sb_match, &ns->fd_sb_match);
2877 /* GLPRT_MSPDC not supported */
2878 /* GLPRT_XEC not supported */
2880 pf->offset_loaded = true;
2883 i40e_update_vsi_stats(pf->main_vsi);
2886 /* Get all statistics of a port */
2888 i40e_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
2890 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2891 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2892 struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
2895 /* call read registers - updates values, now write them to struct */
2896 i40e_read_stats_registers(pf, hw);
2898 stats->ipackets = ns->eth.rx_unicast +
2899 ns->eth.rx_multicast +
2900 ns->eth.rx_broadcast -
2901 ns->eth.rx_discards -
2902 pf->main_vsi->eth_stats.rx_discards;
2903 stats->opackets = ns->eth.tx_unicast +
2904 ns->eth.tx_multicast +
2905 ns->eth.tx_broadcast;
2906 stats->ibytes = ns->eth.rx_bytes;
2907 stats->obytes = ns->eth.tx_bytes;
2908 stats->oerrors = ns->eth.tx_errors +
2909 pf->main_vsi->eth_stats.tx_errors;
2912 stats->imissed = ns->eth.rx_discards +
2913 pf->main_vsi->eth_stats.rx_discards;
2914 stats->ierrors = ns->crc_errors +
2915 ns->rx_length_errors + ns->rx_undersize +
2916 ns->rx_oversize + ns->rx_fragments + ns->rx_jabber;
2918 PMD_DRV_LOG(DEBUG, "***************** PF stats start *******************");
2919 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", ns->eth.rx_bytes);
2920 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", ns->eth.rx_unicast);
2921 PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", ns->eth.rx_multicast);
2922 PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", ns->eth.rx_broadcast);
2923 PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", ns->eth.rx_discards);
2924 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
2925 ns->eth.rx_unknown_protocol);
2926 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", ns->eth.tx_bytes);
2927 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", ns->eth.tx_unicast);
2928 PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", ns->eth.tx_multicast);
2929 PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", ns->eth.tx_broadcast);
2930 PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", ns->eth.tx_discards);
2931 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", ns->eth.tx_errors);
2933 PMD_DRV_LOG(DEBUG, "tx_dropped_link_down: %"PRIu64"",
2934 ns->tx_dropped_link_down);
2935 PMD_DRV_LOG(DEBUG, "crc_errors: %"PRIu64"", ns->crc_errors);
2936 PMD_DRV_LOG(DEBUG, "illegal_bytes: %"PRIu64"",
2938 PMD_DRV_LOG(DEBUG, "error_bytes: %"PRIu64"", ns->error_bytes);
2939 PMD_DRV_LOG(DEBUG, "mac_local_faults: %"PRIu64"",
2940 ns->mac_local_faults);
2941 PMD_DRV_LOG(DEBUG, "mac_remote_faults: %"PRIu64"",
2942 ns->mac_remote_faults);
2943 PMD_DRV_LOG(DEBUG, "rx_length_errors: %"PRIu64"",
2944 ns->rx_length_errors);
2945 PMD_DRV_LOG(DEBUG, "link_xon_rx: %"PRIu64"", ns->link_xon_rx);
2946 PMD_DRV_LOG(DEBUG, "link_xoff_rx: %"PRIu64"", ns->link_xoff_rx);
2947 for (i = 0; i < 8; i++) {
2948 PMD_DRV_LOG(DEBUG, "priority_xon_rx[%d]: %"PRIu64"",
2949 i, ns->priority_xon_rx[i]);
2950 PMD_DRV_LOG(DEBUG, "priority_xoff_rx[%d]: %"PRIu64"",
2951 i, ns->priority_xoff_rx[i]);
2953 PMD_DRV_LOG(DEBUG, "link_xon_tx: %"PRIu64"", ns->link_xon_tx);
2954 PMD_DRV_LOG(DEBUG, "link_xoff_tx: %"PRIu64"", ns->link_xoff_tx);
2955 for (i = 0; i < 8; i++) {
2956 PMD_DRV_LOG(DEBUG, "priority_xon_tx[%d]: %"PRIu64"",
2957 i, ns->priority_xon_tx[i]);
2958 PMD_DRV_LOG(DEBUG, "priority_xoff_tx[%d]: %"PRIu64"",
2959 i, ns->priority_xoff_tx[i]);
2960 PMD_DRV_LOG(DEBUG, "priority_xon_2_xoff[%d]: %"PRIu64"",
2961 i, ns->priority_xon_2_xoff[i]);
2963 PMD_DRV_LOG(DEBUG, "rx_size_64: %"PRIu64"", ns->rx_size_64);
2964 PMD_DRV_LOG(DEBUG, "rx_size_127: %"PRIu64"", ns->rx_size_127);
2965 PMD_DRV_LOG(DEBUG, "rx_size_255: %"PRIu64"", ns->rx_size_255);
2966 PMD_DRV_LOG(DEBUG, "rx_size_511: %"PRIu64"", ns->rx_size_511);
2967 PMD_DRV_LOG(DEBUG, "rx_size_1023: %"PRIu64"", ns->rx_size_1023);
2968 PMD_DRV_LOG(DEBUG, "rx_size_1522: %"PRIu64"", ns->rx_size_1522);
2969 PMD_DRV_LOG(DEBUG, "rx_size_big: %"PRIu64"", ns->rx_size_big);
2970 PMD_DRV_LOG(DEBUG, "rx_undersize: %"PRIu64"", ns->rx_undersize);
2971 PMD_DRV_LOG(DEBUG, "rx_fragments: %"PRIu64"", ns->rx_fragments);
2972 PMD_DRV_LOG(DEBUG, "rx_oversize: %"PRIu64"", ns->rx_oversize);
2973 PMD_DRV_LOG(DEBUG, "rx_jabber: %"PRIu64"", ns->rx_jabber);
2974 PMD_DRV_LOG(DEBUG, "tx_size_64: %"PRIu64"", ns->tx_size_64);
2975 PMD_DRV_LOG(DEBUG, "tx_size_127: %"PRIu64"", ns->tx_size_127);
2976 PMD_DRV_LOG(DEBUG, "tx_size_255: %"PRIu64"", ns->tx_size_255);
2977 PMD_DRV_LOG(DEBUG, "tx_size_511: %"PRIu64"", ns->tx_size_511);
2978 PMD_DRV_LOG(DEBUG, "tx_size_1023: %"PRIu64"", ns->tx_size_1023);
2979 PMD_DRV_LOG(DEBUG, "tx_size_1522: %"PRIu64"", ns->tx_size_1522);
2980 PMD_DRV_LOG(DEBUG, "tx_size_big: %"PRIu64"", ns->tx_size_big);
2981 PMD_DRV_LOG(DEBUG, "mac_short_packet_dropped: %"PRIu64"",
2982 ns->mac_short_packet_dropped);
2983 PMD_DRV_LOG(DEBUG, "checksum_error: %"PRIu64"",
2984 ns->checksum_error);
2985 PMD_DRV_LOG(DEBUG, "fdir_match: %"PRIu64"", ns->fd_sb_match);
2986 PMD_DRV_LOG(DEBUG, "***************** PF stats end ********************");
2990 /* Reset the statistics */
2992 i40e_dev_stats_reset(struct rte_eth_dev *dev)
2994 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2995 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2997 /* Mark PF and VSI stats to update the offset, aka "reset" */
2998 pf->offset_loaded = false;
3000 pf->main_vsi->offset_loaded = false;
3002 /* read the stats, reading current register values into offset */
3003 i40e_read_stats_registers(pf, hw);
3007 i40e_xstats_calc_num(void)
3009 return I40E_NB_ETH_XSTATS + I40E_NB_HW_PORT_XSTATS +
3010 (I40E_NB_RXQ_PRIO_XSTATS * 8) +
3011 (I40E_NB_TXQ_PRIO_XSTATS * 8);
3014 static int i40e_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
3015 struct rte_eth_xstat_name *xstats_names,
3016 __rte_unused unsigned limit)
3021 if (xstats_names == NULL)
3022 return i40e_xstats_calc_num();
3024 /* Note: limit checked in rte_eth_xstats_names() */
3026 /* Get stats from i40e_eth_stats struct */
3027 for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
3028 snprintf(xstats_names[count].name,
3029 sizeof(xstats_names[count].name),
3030 "%s", rte_i40e_stats_strings[i].name);
3034 /* Get individiual stats from i40e_hw_port struct */
3035 for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
3036 snprintf(xstats_names[count].name,
3037 sizeof(xstats_names[count].name),
3038 "%s", rte_i40e_hw_port_strings[i].name);
3042 for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
3043 for (prio = 0; prio < 8; prio++) {
3044 snprintf(xstats_names[count].name,
3045 sizeof(xstats_names[count].name),
3046 "rx_priority%u_%s", prio,
3047 rte_i40e_rxq_prio_strings[i].name);
3052 for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
3053 for (prio = 0; prio < 8; prio++) {
3054 snprintf(xstats_names[count].name,
3055 sizeof(xstats_names[count].name),
3056 "tx_priority%u_%s", prio,
3057 rte_i40e_txq_prio_strings[i].name);
3065 i40e_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
3068 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3069 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3070 unsigned i, count, prio;
3071 struct i40e_hw_port_stats *hw_stats = &pf->stats;
3073 count = i40e_xstats_calc_num();
3077 i40e_read_stats_registers(pf, hw);
3084 /* Get stats from i40e_eth_stats struct */
3085 for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
3086 xstats[count].value = *(uint64_t *)(((char *)&hw_stats->eth) +
3087 rte_i40e_stats_strings[i].offset);
3088 xstats[count].id = count;
3092 /* Get individiual stats from i40e_hw_port struct */
3093 for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
3094 xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
3095 rte_i40e_hw_port_strings[i].offset);
3096 xstats[count].id = count;
3100 for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
3101 for (prio = 0; prio < 8; prio++) {
3102 xstats[count].value =
3103 *(uint64_t *)(((char *)hw_stats) +
3104 rte_i40e_rxq_prio_strings[i].offset +
3105 (sizeof(uint64_t) * prio));
3106 xstats[count].id = count;
3111 for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
3112 for (prio = 0; prio < 8; prio++) {
3113 xstats[count].value =
3114 *(uint64_t *)(((char *)hw_stats) +
3115 rte_i40e_txq_prio_strings[i].offset +
3116 (sizeof(uint64_t) * prio));
3117 xstats[count].id = count;
3126 i40e_dev_queue_stats_mapping_set(__rte_unused struct rte_eth_dev *dev,
3127 __rte_unused uint16_t queue_id,
3128 __rte_unused uint8_t stat_idx,
3129 __rte_unused uint8_t is_rx)
3131 PMD_INIT_FUNC_TRACE();
3137 i40e_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
3139 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3145 full_ver = hw->nvm.oem_ver;
3146 ver = (u8)(full_ver >> 24);
3147 build = (u16)((full_ver >> 8) & 0xffff);
3148 patch = (u8)(full_ver & 0xff);
3150 ret = snprintf(fw_version, fw_size,
3151 "%d.%d%d 0x%08x %d.%d.%d",
3152 ((hw->nvm.version >> 12) & 0xf),
3153 ((hw->nvm.version >> 4) & 0xff),
3154 (hw->nvm.version & 0xf), hw->nvm.eetrack,
3157 ret += 1; /* add the size of '\0' */
3158 if (fw_size < (u32)ret)
3165 i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
3167 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3168 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3169 struct i40e_vsi *vsi = pf->main_vsi;
3170 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3172 dev_info->pci_dev = pci_dev;
3173 dev_info->max_rx_queues = vsi->nb_qps;
3174 dev_info->max_tx_queues = vsi->nb_qps;
3175 dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
3176 dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
3177 dev_info->max_mac_addrs = vsi->max_macaddrs;
3178 dev_info->max_vfs = pci_dev->max_vfs;
3179 dev_info->rx_offload_capa =
3180 DEV_RX_OFFLOAD_VLAN_STRIP |
3181 DEV_RX_OFFLOAD_QINQ_STRIP |
3182 DEV_RX_OFFLOAD_IPV4_CKSUM |
3183 DEV_RX_OFFLOAD_UDP_CKSUM |
3184 DEV_RX_OFFLOAD_TCP_CKSUM |
3185 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
3186 DEV_RX_OFFLOAD_CRC_STRIP;
3187 dev_info->tx_offload_capa =
3188 DEV_TX_OFFLOAD_VLAN_INSERT |
3189 DEV_TX_OFFLOAD_QINQ_INSERT |
3190 DEV_TX_OFFLOAD_IPV4_CKSUM |
3191 DEV_TX_OFFLOAD_UDP_CKSUM |
3192 DEV_TX_OFFLOAD_TCP_CKSUM |
3193 DEV_TX_OFFLOAD_SCTP_CKSUM |
3194 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
3195 DEV_TX_OFFLOAD_TCP_TSO |
3196 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
3197 DEV_TX_OFFLOAD_GRE_TNL_TSO |
3198 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
3199 DEV_TX_OFFLOAD_GENEVE_TNL_TSO;
3200 dev_info->hash_key_size = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
3202 dev_info->reta_size = pf->hash_lut_size;
3203 dev_info->flow_type_rss_offloads = pf->adapter->flow_types_mask;
3205 dev_info->default_rxconf = (struct rte_eth_rxconf) {
3207 .pthresh = I40E_DEFAULT_RX_PTHRESH,
3208 .hthresh = I40E_DEFAULT_RX_HTHRESH,
3209 .wthresh = I40E_DEFAULT_RX_WTHRESH,
3211 .rx_free_thresh = I40E_DEFAULT_RX_FREE_THRESH,
3215 dev_info->default_txconf = (struct rte_eth_txconf) {
3217 .pthresh = I40E_DEFAULT_TX_PTHRESH,
3218 .hthresh = I40E_DEFAULT_TX_HTHRESH,
3219 .wthresh = I40E_DEFAULT_TX_WTHRESH,
3221 .tx_free_thresh = I40E_DEFAULT_TX_FREE_THRESH,
3222 .tx_rs_thresh = I40E_DEFAULT_TX_RSBIT_THRESH,
3223 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
3224 ETH_TXQ_FLAGS_NOOFFLOADS,
3227 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
3228 .nb_max = I40E_MAX_RING_DESC,
3229 .nb_min = I40E_MIN_RING_DESC,
3230 .nb_align = I40E_ALIGN_RING_DESC,
3233 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
3234 .nb_max = I40E_MAX_RING_DESC,
3235 .nb_min = I40E_MIN_RING_DESC,
3236 .nb_align = I40E_ALIGN_RING_DESC,
3237 .nb_seg_max = I40E_TX_MAX_SEG,
3238 .nb_mtu_seg_max = I40E_TX_MAX_MTU_SEG,
3241 if (pf->flags & I40E_FLAG_VMDQ) {
3242 dev_info->max_vmdq_pools = pf->max_nb_vmdq_vsi;
3243 dev_info->vmdq_queue_base = dev_info->max_rx_queues;
3244 dev_info->vmdq_queue_num = pf->vmdq_nb_qps *
3245 pf->max_nb_vmdq_vsi;
3246 dev_info->vmdq_pool_base = I40E_VMDQ_POOL_BASE;
3247 dev_info->max_rx_queues += dev_info->vmdq_queue_num;
3248 dev_info->max_tx_queues += dev_info->vmdq_queue_num;
3251 if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types))
3253 dev_info->speed_capa = ETH_LINK_SPEED_40G;
3254 else if (I40E_PHY_TYPE_SUPPORT_25G(hw->phy.phy_types))
3256 dev_info->speed_capa = ETH_LINK_SPEED_25G;
3259 dev_info->speed_capa = ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G;
3263 i40e_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
3265 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3266 struct i40e_vsi *vsi = pf->main_vsi;
3267 PMD_INIT_FUNC_TRACE();
3270 return i40e_vsi_add_vlan(vsi, vlan_id);
3272 return i40e_vsi_delete_vlan(vsi, vlan_id);
3276 i40e_vlan_tpid_set_by_registers(struct rte_eth_dev *dev,
3277 enum rte_vlan_type vlan_type,
3278 uint16_t tpid, int qinq)
3280 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3283 uint16_t reg_id = 3;
3287 if (vlan_type == ETH_VLAN_TYPE_OUTER)
3291 ret = i40e_aq_debug_read_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
3293 if (ret != I40E_SUCCESS) {
3295 "Fail to debug read from I40E_GL_SWT_L2TAGCTRL[%d]",
3300 "Debug read from I40E_GL_SWT_L2TAGCTRL[%d]: 0x%08"PRIx64,
3303 reg_w = reg_r & (~(I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_MASK));
3304 reg_w |= ((uint64_t)tpid << I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT);
3305 if (reg_r == reg_w) {
3306 PMD_DRV_LOG(DEBUG, "No need to write");
3310 ret = i40e_aq_debug_write_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
3312 if (ret != I40E_SUCCESS) {
3314 "Fail to debug write to I40E_GL_SWT_L2TAGCTRL[%d]",
3319 "Global register 0x%08x is changed with value 0x%08x",
3320 I40E_GL_SWT_L2TAGCTRL(reg_id), (uint32_t)reg_w);
3326 i40e_vlan_tpid_set(struct rte_eth_dev *dev,
3327 enum rte_vlan_type vlan_type,
3330 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3331 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3332 int qinq = dev->data->dev_conf.rxmode.hw_vlan_extend;
3335 if ((vlan_type != ETH_VLAN_TYPE_INNER &&
3336 vlan_type != ETH_VLAN_TYPE_OUTER) ||
3337 (!qinq && vlan_type == ETH_VLAN_TYPE_INNER)) {
3339 "Unsupported vlan type.");
3343 if (pf->support_multi_driver) {
3344 PMD_DRV_LOG(ERR, "Setting TPID is not supported.");
3348 /* 802.1ad frames ability is added in NVM API 1.7*/
3349 if (hw->flags & I40E_HW_FLAG_802_1AD_CAPABLE) {
3351 if (vlan_type == ETH_VLAN_TYPE_OUTER)
3352 hw->first_tag = rte_cpu_to_le_16(tpid);
3353 else if (vlan_type == ETH_VLAN_TYPE_INNER)
3354 hw->second_tag = rte_cpu_to_le_16(tpid);
3356 if (vlan_type == ETH_VLAN_TYPE_OUTER)
3357 hw->second_tag = rte_cpu_to_le_16(tpid);
3359 ret = i40e_aq_set_switch_config(hw, 0, 0, NULL);
3360 if (ret != I40E_SUCCESS) {
3362 "Set switch config failed aq_err: %d",
3363 hw->aq.asq_last_status);
3367 /* If NVM API < 1.7, keep the register setting */
3368 ret = i40e_vlan_tpid_set_by_registers(dev, vlan_type,
3370 i40e_global_cfg_warning(I40E_WARNING_TPID);
3376 i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask)
3378 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3379 struct i40e_vsi *vsi = pf->main_vsi;
3381 if (mask & ETH_VLAN_FILTER_MASK) {
3382 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
3383 i40e_vsi_config_vlan_filter(vsi, TRUE);
3385 i40e_vsi_config_vlan_filter(vsi, FALSE);
3388 if (mask & ETH_VLAN_STRIP_MASK) {
3389 /* Enable or disable VLAN stripping */
3390 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
3391 i40e_vsi_config_vlan_stripping(vsi, TRUE);
3393 i40e_vsi_config_vlan_stripping(vsi, FALSE);
3396 if (mask & ETH_VLAN_EXTEND_MASK) {
3397 if (dev->data->dev_conf.rxmode.hw_vlan_extend) {
3398 i40e_vsi_config_double_vlan(vsi, TRUE);
3399 /* Set global registers with default ethertype. */
3400 i40e_vlan_tpid_set(dev, ETH_VLAN_TYPE_OUTER,
3402 i40e_vlan_tpid_set(dev, ETH_VLAN_TYPE_INNER,
3406 i40e_vsi_config_double_vlan(vsi, FALSE);
3413 i40e_vlan_strip_queue_set(__rte_unused struct rte_eth_dev *dev,
3414 __rte_unused uint16_t queue,
3415 __rte_unused int on)
3417 PMD_INIT_FUNC_TRACE();
3421 i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
3423 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3424 struct i40e_vsi *vsi = pf->main_vsi;
3425 struct rte_eth_dev_data *data = I40E_VSI_TO_DEV_DATA(vsi);
3426 struct i40e_vsi_vlan_pvid_info info;
3428 memset(&info, 0, sizeof(info));
3431 info.config.pvid = pvid;
3433 info.config.reject.tagged =
3434 data->dev_conf.txmode.hw_vlan_reject_tagged;
3435 info.config.reject.untagged =
3436 data->dev_conf.txmode.hw_vlan_reject_untagged;
3439 return i40e_vsi_vlan_pvid_set(vsi, &info);
3443 i40e_dev_led_on(struct rte_eth_dev *dev)
3445 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3446 uint32_t mode = i40e_led_get(hw);
3449 i40e_led_set(hw, 0xf, true); /* 0xf means led always true */
3455 i40e_dev_led_off(struct rte_eth_dev *dev)
3457 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3458 uint32_t mode = i40e_led_get(hw);
3461 i40e_led_set(hw, 0, false);
3467 i40e_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
3469 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3470 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3472 fc_conf->pause_time = pf->fc_conf.pause_time;
3474 /* read out from register, in case they are modified by other port */
3475 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] =
3476 I40E_READ_REG(hw, I40E_GLRPB_GHW) >> I40E_KILOSHIFT;
3477 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] =
3478 I40E_READ_REG(hw, I40E_GLRPB_GLW) >> I40E_KILOSHIFT;
3480 fc_conf->high_water = pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS];
3481 fc_conf->low_water = pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS];
3483 /* Return current mode according to actual setting*/
3484 switch (hw->fc.current_mode) {
3486 fc_conf->mode = RTE_FC_FULL;
3488 case I40E_FC_TX_PAUSE:
3489 fc_conf->mode = RTE_FC_TX_PAUSE;
3491 case I40E_FC_RX_PAUSE:
3492 fc_conf->mode = RTE_FC_RX_PAUSE;
3496 fc_conf->mode = RTE_FC_NONE;
3503 i40e_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
3505 uint32_t mflcn_reg, fctrl_reg, reg;
3506 uint32_t max_high_water;
3507 uint8_t i, aq_failure;
3511 enum i40e_fc_mode rte_fcmode_2_i40e_fcmode[] = {
3512 [RTE_FC_NONE] = I40E_FC_NONE,
3513 [RTE_FC_RX_PAUSE] = I40E_FC_RX_PAUSE,
3514 [RTE_FC_TX_PAUSE] = I40E_FC_TX_PAUSE,
3515 [RTE_FC_FULL] = I40E_FC_FULL
3518 /* high_water field in the rte_eth_fc_conf using the kilobytes unit */
3520 max_high_water = I40E_RXPBSIZE >> I40E_KILOSHIFT;
3521 if ((fc_conf->high_water > max_high_water) ||
3522 (fc_conf->high_water < fc_conf->low_water)) {
3524 "Invalid high/low water setup value in KB, High_water must be <= %d.",
3529 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3530 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3531 hw->fc.requested_mode = rte_fcmode_2_i40e_fcmode[fc_conf->mode];
3533 pf->fc_conf.pause_time = fc_conf->pause_time;
3534 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->high_water;
3535 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->low_water;
3537 PMD_INIT_FUNC_TRACE();
3539 /* All the link flow control related enable/disable register
3540 * configuration is handle by the F/W
3542 err = i40e_set_fc(hw, &aq_failure, true);
3546 if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
3547 /* Configure flow control refresh threshold,
3548 * the value for stat_tx_pause_refresh_timer[8]
3549 * is used for global pause operation.
3553 I40E_PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER(8),
3554 pf->fc_conf.pause_time);
3556 /* configure the timer value included in transmitted pause
3558 * the value for stat_tx_pause_quanta[8] is used for global
3561 I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA(8),
3562 pf->fc_conf.pause_time);
3564 fctrl_reg = I40E_READ_REG(hw,
3565 I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL);
3567 if (fc_conf->mac_ctrl_frame_fwd != 0)
3568 fctrl_reg |= I40E_PRTMAC_FWD_CTRL;
3570 fctrl_reg &= ~I40E_PRTMAC_FWD_CTRL;
3572 I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL,
3575 /* Configure pause time (2 TCs per register) */
3576 reg = (uint32_t)pf->fc_conf.pause_time * (uint32_t)0x00010001;
3577 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS / 2; i++)
3578 I40E_WRITE_REG(hw, I40E_PRTDCB_FCTTVN(i), reg);
3580 /* Configure flow control refresh threshold value */
3581 I40E_WRITE_REG(hw, I40E_PRTDCB_FCRTV,
3582 pf->fc_conf.pause_time / 2);
3584 mflcn_reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
3586 /* set or clear MFLCN.PMCF & MFLCN.DPF bits
3587 *depending on configuration
3589 if (fc_conf->mac_ctrl_frame_fwd != 0) {
3590 mflcn_reg |= I40E_PRTDCB_MFLCN_PMCF_MASK;
3591 mflcn_reg &= ~I40E_PRTDCB_MFLCN_DPF_MASK;
3593 mflcn_reg &= ~I40E_PRTDCB_MFLCN_PMCF_MASK;
3594 mflcn_reg |= I40E_PRTDCB_MFLCN_DPF_MASK;
3597 I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, mflcn_reg);
3600 if (!pf->support_multi_driver) {
3601 /* config water marker both based on the packets and bytes */
3602 I40E_WRITE_GLB_REG(hw, I40E_GLRPB_PHW,
3603 (pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
3604 << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
3605 I40E_WRITE_GLB_REG(hw, I40E_GLRPB_PLW,
3606 (pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
3607 << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
3608 I40E_WRITE_GLB_REG(hw, I40E_GLRPB_GHW,
3609 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
3611 I40E_WRITE_GLB_REG(hw, I40E_GLRPB_GLW,
3612 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
3614 i40e_global_cfg_warning(I40E_WARNING_FLOW_CTL);
3617 "Water marker configuration is not supported.");
3620 I40E_WRITE_FLUSH(hw);
3626 i40e_priority_flow_ctrl_set(__rte_unused struct rte_eth_dev *dev,
3627 __rte_unused struct rte_eth_pfc_conf *pfc_conf)
3629 PMD_INIT_FUNC_TRACE();
3634 /* Add a MAC address, and update filters */
3636 i40e_macaddr_add(struct rte_eth_dev *dev,
3637 struct ether_addr *mac_addr,
3638 __rte_unused uint32_t index,
3641 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3642 struct i40e_mac_filter_info mac_filter;
3643 struct i40e_vsi *vsi;
3646 /* If VMDQ not enabled or configured, return */
3647 if (pool != 0 && (!(pf->flags & I40E_FLAG_VMDQ) ||
3648 !pf->nb_cfg_vmdq_vsi)) {
3649 PMD_DRV_LOG(ERR, "VMDQ not %s, can't set mac to pool %u",
3650 pf->flags & I40E_FLAG_VMDQ ? "configured" : "enabled",
3655 if (pool > pf->nb_cfg_vmdq_vsi) {
3656 PMD_DRV_LOG(ERR, "Pool number %u invalid. Max pool is %u",
3657 pool, pf->nb_cfg_vmdq_vsi);
3661 rte_memcpy(&mac_filter.mac_addr, mac_addr, ETHER_ADDR_LEN);
3662 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
3663 mac_filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
3665 mac_filter.filter_type = RTE_MAC_PERFECT_MATCH;
3670 vsi = pf->vmdq[pool - 1].vsi;
3672 ret = i40e_vsi_add_mac(vsi, &mac_filter);
3673 if (ret != I40E_SUCCESS) {
3674 PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
3680 /* Remove a MAC address, and update filters */
3682 i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
3684 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3685 struct i40e_vsi *vsi;
3686 struct rte_eth_dev_data *data = dev->data;
3687 struct ether_addr *macaddr;
3692 macaddr = &(data->mac_addrs[index]);
3694 pool_sel = dev->data->mac_pool_sel[index];
3696 for (i = 0; i < sizeof(pool_sel) * CHAR_BIT; i++) {
3697 if (pool_sel & (1ULL << i)) {
3701 /* No VMDQ pool enabled or configured */
3702 if (!(pf->flags & I40E_FLAG_VMDQ) ||
3703 (i > pf->nb_cfg_vmdq_vsi)) {
3705 "No VMDQ pool enabled/configured");
3708 vsi = pf->vmdq[i - 1].vsi;
3710 ret = i40e_vsi_delete_mac(vsi, macaddr);
3713 PMD_DRV_LOG(ERR, "Failed to remove MACVLAN filter");
3720 /* Set perfect match or hash match of MAC and VLAN for a VF */
3722 i40e_vf_mac_filter_set(struct i40e_pf *pf,
3723 struct rte_eth_mac_filter *filter,
3727 struct i40e_mac_filter_info mac_filter;
3728 struct ether_addr old_mac;
3729 struct ether_addr *new_mac;
3730 struct i40e_pf_vf *vf = NULL;
3735 PMD_DRV_LOG(ERR, "Invalid PF argument.");
3738 hw = I40E_PF_TO_HW(pf);
3740 if (filter == NULL) {
3741 PMD_DRV_LOG(ERR, "Invalid mac filter argument.");
3745 new_mac = &filter->mac_addr;
3747 if (is_zero_ether_addr(new_mac)) {
3748 PMD_DRV_LOG(ERR, "Invalid ethernet address.");
3752 vf_id = filter->dst_id;
3754 if (vf_id > pf->vf_num - 1 || !pf->vfs) {
3755 PMD_DRV_LOG(ERR, "Invalid argument.");
3758 vf = &pf->vfs[vf_id];
3760 if (add && is_same_ether_addr(new_mac, &(pf->dev_addr))) {
3761 PMD_DRV_LOG(INFO, "Ignore adding permanent MAC address.");
3766 rte_memcpy(&old_mac, hw->mac.addr, ETHER_ADDR_LEN);
3767 rte_memcpy(hw->mac.addr, new_mac->addr_bytes,
3769 rte_memcpy(&mac_filter.mac_addr, &filter->mac_addr,
3772 mac_filter.filter_type = filter->filter_type;
3773 ret = i40e_vsi_add_mac(vf->vsi, &mac_filter);
3774 if (ret != I40E_SUCCESS) {
3775 PMD_DRV_LOG(ERR, "Failed to add MAC filter.");
3778 ether_addr_copy(new_mac, &pf->dev_addr);
3780 rte_memcpy(hw->mac.addr, hw->mac.perm_addr,
3782 ret = i40e_vsi_delete_mac(vf->vsi, &filter->mac_addr);
3783 if (ret != I40E_SUCCESS) {
3784 PMD_DRV_LOG(ERR, "Failed to delete MAC filter.");
3788 /* Clear device address as it has been removed */
3789 if (is_same_ether_addr(&(pf->dev_addr), new_mac))
3790 memset(&pf->dev_addr, 0, sizeof(struct ether_addr));
3796 /* MAC filter handle */
3798 i40e_mac_filter_handle(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
3801 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3802 struct rte_eth_mac_filter *filter;
3803 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
3804 int ret = I40E_NOT_SUPPORTED;
3806 filter = (struct rte_eth_mac_filter *)(arg);
3808 switch (filter_op) {
3809 case RTE_ETH_FILTER_NOP:
3812 case RTE_ETH_FILTER_ADD:
3813 i40e_pf_disable_irq0(hw);
3815 ret = i40e_vf_mac_filter_set(pf, filter, 1);
3816 i40e_pf_enable_irq0(hw);
3818 case RTE_ETH_FILTER_DELETE:
3819 i40e_pf_disable_irq0(hw);
3821 ret = i40e_vf_mac_filter_set(pf, filter, 0);
3822 i40e_pf_enable_irq0(hw);
3825 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
3826 ret = I40E_ERR_PARAM;
3834 i40e_get_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
3836 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
3837 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3844 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
3845 ret = i40e_aq_get_rss_lut(hw, vsi->vsi_id, TRUE,
3848 PMD_DRV_LOG(ERR, "Failed to get RSS lookup table");
3852 uint32_t *lut_dw = (uint32_t *)lut;
3853 uint16_t i, lut_size_dw = lut_size / 4;
3855 if (vsi->type == I40E_VSI_SRIOV) {
3856 for (i = 0; i <= lut_size_dw; i++) {
3857 reg = I40E_VFQF_HLUT1(i, vsi->user_param);
3858 lut_dw[i] = i40e_read_rx_ctl(hw, reg);
3861 for (i = 0; i < lut_size_dw; i++)
3862 lut_dw[i] = I40E_READ_REG(hw,
3871 i40e_set_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
3880 pf = I40E_VSI_TO_PF(vsi);
3881 hw = I40E_VSI_TO_HW(vsi);
3883 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
3884 ret = i40e_aq_set_rss_lut(hw, vsi->vsi_id, TRUE,
3887 PMD_DRV_LOG(ERR, "Failed to set RSS lookup table");
3891 uint32_t *lut_dw = (uint32_t *)lut;
3892 uint16_t i, lut_size_dw = lut_size / 4;
3894 if (vsi->type == I40E_VSI_SRIOV) {
3895 for (i = 0; i < lut_size_dw; i++)
3898 I40E_VFQF_HLUT1(i, vsi->user_param),
3901 for (i = 0; i < lut_size_dw; i++)
3902 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i),
3905 I40E_WRITE_FLUSH(hw);
3912 i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
3913 struct rte_eth_rss_reta_entry64 *reta_conf,
3916 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3917 uint16_t i, lut_size = pf->hash_lut_size;
3918 uint16_t idx, shift;
3922 if (reta_size != lut_size ||
3923 reta_size > ETH_RSS_RETA_SIZE_512) {
3925 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)",
3926 reta_size, lut_size);
3930 lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
3932 PMD_DRV_LOG(ERR, "No memory can be allocated");
3935 ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
3938 for (i = 0; i < reta_size; i++) {
3939 idx = i / RTE_RETA_GROUP_SIZE;
3940 shift = i % RTE_RETA_GROUP_SIZE;
3941 if (reta_conf[idx].mask & (1ULL << shift))
3942 lut[i] = reta_conf[idx].reta[shift];
3944 ret = i40e_set_rss_lut(pf->main_vsi, lut, reta_size);
3953 i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
3954 struct rte_eth_rss_reta_entry64 *reta_conf,
3957 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3958 uint16_t i, lut_size = pf->hash_lut_size;
3959 uint16_t idx, shift;
3963 if (reta_size != lut_size ||
3964 reta_size > ETH_RSS_RETA_SIZE_512) {
3966 "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)",
3967 reta_size, lut_size);
3971 lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
3973 PMD_DRV_LOG(ERR, "No memory can be allocated");
3977 ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
3980 for (i = 0; i < reta_size; i++) {
3981 idx = i / RTE_RETA_GROUP_SIZE;
3982 shift = i % RTE_RETA_GROUP_SIZE;
3983 if (reta_conf[idx].mask & (1ULL << shift))
3984 reta_conf[idx].reta[shift] = lut[i];
3994 * i40e_allocate_dma_mem_d - specific memory alloc for shared code (base driver)
3995 * @hw: pointer to the HW structure
3996 * @mem: pointer to mem struct to fill out
3997 * @size: size of memory requested
3998 * @alignment: what to align the allocation to
4000 enum i40e_status_code
4001 i40e_allocate_dma_mem_d(__attribute__((unused)) struct i40e_hw *hw,
4002 struct i40e_dma_mem *mem,
4006 const struct rte_memzone *mz = NULL;
4007 char z_name[RTE_MEMZONE_NAMESIZE];
4010 return I40E_ERR_PARAM;
4012 snprintf(z_name, sizeof(z_name), "i40e_dma_%"PRIu64, rte_rand());
4013 mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY, 0,
4014 alignment, RTE_PGSIZE_2M);
4016 return I40E_ERR_NO_MEMORY;
4021 mem->zone = (const void *)mz;
4023 "memzone %s allocated with physical address: %"PRIu64,
4026 return I40E_SUCCESS;
4030 * i40e_free_dma_mem_d - specific memory free for shared code (base driver)
4031 * @hw: pointer to the HW structure
4032 * @mem: ptr to mem struct to free
4034 enum i40e_status_code
4035 i40e_free_dma_mem_d(__attribute__((unused)) struct i40e_hw *hw,
4036 struct i40e_dma_mem *mem)
4039 return I40E_ERR_PARAM;
4042 "memzone %s to be freed with physical address: %"PRIu64,
4043 ((const struct rte_memzone *)mem->zone)->name, mem->pa);
4044 rte_memzone_free((const struct rte_memzone *)mem->zone);
4049 return I40E_SUCCESS;
4053 * i40e_allocate_virt_mem_d - specific memory alloc for shared code (base driver)
4054 * @hw: pointer to the HW structure
4055 * @mem: pointer to mem struct to fill out
4056 * @size: size of memory requested
4058 enum i40e_status_code
4059 i40e_allocate_virt_mem_d(__attribute__((unused)) struct i40e_hw *hw,
4060 struct i40e_virt_mem *mem,
4064 return I40E_ERR_PARAM;
4067 mem->va = rte_zmalloc("i40e", size, 0);
4070 return I40E_SUCCESS;
4072 return I40E_ERR_NO_MEMORY;
4076 * i40e_free_virt_mem_d - specific memory free for shared code (base driver)
4077 * @hw: pointer to the HW structure
4078 * @mem: pointer to mem struct to free
4080 enum i40e_status_code
4081 i40e_free_virt_mem_d(__attribute__((unused)) struct i40e_hw *hw,
4082 struct i40e_virt_mem *mem)
4085 return I40E_ERR_PARAM;
4090 return I40E_SUCCESS;
4094 i40e_init_spinlock_d(struct i40e_spinlock *sp)
4096 rte_spinlock_init(&sp->spinlock);
4100 i40e_acquire_spinlock_d(struct i40e_spinlock *sp)
4102 rte_spinlock_lock(&sp->spinlock);
4106 i40e_release_spinlock_d(struct i40e_spinlock *sp)
4108 rte_spinlock_unlock(&sp->spinlock);
4112 i40e_destroy_spinlock_d(__attribute__((unused)) struct i40e_spinlock *sp)
4118 * Get the hardware capabilities, which will be parsed
4119 * and saved into struct i40e_hw.
4122 i40e_get_cap(struct i40e_hw *hw)
4124 struct i40e_aqc_list_capabilities_element_resp *buf;
4125 uint16_t len, size = 0;
4128 /* Calculate a huge enough buff for saving response data temporarily */
4129 len = sizeof(struct i40e_aqc_list_capabilities_element_resp) *
4130 I40E_MAX_CAP_ELE_NUM;
4131 buf = rte_zmalloc("i40e", len, 0);
4133 PMD_DRV_LOG(ERR, "Failed to allocate memory");
4134 return I40E_ERR_NO_MEMORY;
4137 /* Get, parse the capabilities and save it to hw */
4138 ret = i40e_aq_discover_capabilities(hw, buf, len, &size,
4139 i40e_aqc_opc_list_func_capabilities, NULL);
4140 if (ret != I40E_SUCCESS)
4141 PMD_DRV_LOG(ERR, "Failed to discover capabilities");
4143 /* Free the temporary buffer after being used */
4149 #define RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF 4
4150 #define QUEUE_NUM_PER_VF_ARG "queue-num-per-vf"
4152 static int i40e_pf_parse_vf_queue_number_handler(const char *key,
4160 pf = (struct i40e_pf *)opaque;
4164 num = strtoul(value, &end, 0);
4165 if (errno != 0 || end == value || *end != 0) {
4166 PMD_DRV_LOG(WARNING, "Wrong VF queue number = %s, Now it is "
4167 "kept the value = %hu", value, pf->vf_nb_qp_max);
4171 if (num <= I40E_MAX_QP_NUM_PER_VF && rte_is_power_of_2(num))
4172 pf->vf_nb_qp_max = (uint16_t)num;
4174 /* here return 0 to make next valid same argument work */
4175 PMD_DRV_LOG(WARNING, "Wrong VF queue number = %lu, it must be "
4176 "power of 2 and equal or less than 16 !, Now it is "
4177 "kept the value = %hu", num, pf->vf_nb_qp_max);
4182 static int i40e_pf_config_vf_rxq_number(struct rte_eth_dev *dev)
4184 static const char * const valid_keys[] = {QUEUE_NUM_PER_VF_ARG, NULL};
4185 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4186 struct rte_kvargs *kvlist;
4188 /* set default queue number per VF as 4 */
4189 pf->vf_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF;
4191 if (dev->device->devargs == NULL)
4194 kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
4198 if (rte_kvargs_count(kvlist, QUEUE_NUM_PER_VF_ARG) > 1)
4199 PMD_DRV_LOG(WARNING, "More than one argument \"%s\" and only "
4200 "the first invalid or last valid one is used !",
4201 QUEUE_NUM_PER_VF_ARG);
4203 rte_kvargs_process(kvlist, QUEUE_NUM_PER_VF_ARG,
4204 i40e_pf_parse_vf_queue_number_handler, pf);
4206 rte_kvargs_free(kvlist);
4212 i40e_pf_parameter_init(struct rte_eth_dev *dev)
4214 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4215 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4216 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
4217 uint16_t qp_count = 0, vsi_count = 0;
4219 if (pci_dev->max_vfs && !hw->func_caps.sr_iov_1_1) {
4220 PMD_INIT_LOG(ERR, "HW configuration doesn't support SRIOV");
4224 i40e_pf_config_vf_rxq_number(dev);
4226 /* Add the parameter init for LFC */
4227 pf->fc_conf.pause_time = I40E_DEFAULT_PAUSE_TIME;
4228 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_HIGH_WATER;
4229 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_LOW_WATER;
4231 pf->flags = I40E_FLAG_HEADER_SPLIT_DISABLED;
4232 pf->max_num_vsi = hw->func_caps.num_vsis;
4233 pf->lan_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_PF;
4234 pf->vmdq_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
4236 /* FDir queue/VSI allocation */
4237 pf->fdir_qp_offset = 0;
4238 if (hw->func_caps.fd) {
4239 pf->flags |= I40E_FLAG_FDIR;
4240 pf->fdir_nb_qps = I40E_DEFAULT_QP_NUM_FDIR;
4242 pf->fdir_nb_qps = 0;
4244 qp_count += pf->fdir_nb_qps;
4247 /* LAN queue/VSI allocation */
4248 pf->lan_qp_offset = pf->fdir_qp_offset + pf->fdir_nb_qps;
4249 if (!hw->func_caps.rss) {
4252 pf->flags |= I40E_FLAG_RSS;
4253 if (hw->mac.type == I40E_MAC_X722)
4254 pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE;
4255 pf->lan_nb_qps = pf->lan_nb_qp_max;
4257 qp_count += pf->lan_nb_qps;
4260 /* VF queue/VSI allocation */
4261 pf->vf_qp_offset = pf->lan_qp_offset + pf->lan_nb_qps;
4262 if (hw->func_caps.sr_iov_1_1 && pci_dev->max_vfs) {
4263 pf->flags |= I40E_FLAG_SRIOV;
4264 pf->vf_nb_qps = pf->vf_nb_qp_max;
4265 pf->vf_num = pci_dev->max_vfs;
4267 "%u VF VSIs, %u queues per VF VSI, in total %u queues",
4268 pf->vf_num, pf->vf_nb_qps, pf->vf_nb_qps * pf->vf_num);
4273 qp_count += pf->vf_nb_qps * pf->vf_num;
4274 vsi_count += pf->vf_num;
4276 /* VMDq queue/VSI allocation */
4277 pf->vmdq_qp_offset = pf->vf_qp_offset + pf->vf_nb_qps * pf->vf_num;
4278 pf->vmdq_nb_qps = 0;
4279 pf->max_nb_vmdq_vsi = 0;
4280 if (hw->func_caps.vmdq) {
4281 if (qp_count < hw->func_caps.num_tx_qp &&
4282 vsi_count < hw->func_caps.num_vsis) {
4283 pf->max_nb_vmdq_vsi = (hw->func_caps.num_tx_qp -
4284 qp_count) / pf->vmdq_nb_qp_max;
4286 /* Limit the maximum number of VMDq vsi to the maximum
4287 * ethdev can support
4289 pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
4290 hw->func_caps.num_vsis - vsi_count);
4291 pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
4293 if (pf->max_nb_vmdq_vsi) {
4294 pf->flags |= I40E_FLAG_VMDQ;
4295 pf->vmdq_nb_qps = pf->vmdq_nb_qp_max;
4297 "%u VMDQ VSIs, %u queues per VMDQ VSI, in total %u queues",
4298 pf->max_nb_vmdq_vsi, pf->vmdq_nb_qps,
4299 pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi);
4302 "No enough queues left for VMDq");
4305 PMD_DRV_LOG(INFO, "No queue or VSI left for VMDq");
4308 qp_count += pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi;
4309 vsi_count += pf->max_nb_vmdq_vsi;
4311 if (hw->func_caps.dcb)
4312 pf->flags |= I40E_FLAG_DCB;
4314 if (qp_count > hw->func_caps.num_tx_qp) {
4316 "Failed to allocate %u queues, which exceeds the hardware maximum %u",
4317 qp_count, hw->func_caps.num_tx_qp);
4320 if (vsi_count > hw->func_caps.num_vsis) {
4322 "Failed to allocate %u VSIs, which exceeds the hardware maximum %u",
4323 vsi_count, hw->func_caps.num_vsis);
4331 i40e_pf_get_switch_config(struct i40e_pf *pf)
4333 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4334 struct i40e_aqc_get_switch_config_resp *switch_config;
4335 struct i40e_aqc_switch_config_element_resp *element;
4336 uint16_t start_seid = 0, num_reported;
4339 switch_config = (struct i40e_aqc_get_switch_config_resp *)\
4340 rte_zmalloc("i40e", I40E_AQ_LARGE_BUF, 0);
4341 if (!switch_config) {
4342 PMD_DRV_LOG(ERR, "Failed to allocated memory");
4346 /* Get the switch configurations */
4347 ret = i40e_aq_get_switch_config(hw, switch_config,
4348 I40E_AQ_LARGE_BUF, &start_seid, NULL);
4349 if (ret != I40E_SUCCESS) {
4350 PMD_DRV_LOG(ERR, "Failed to get switch configurations");
4353 num_reported = rte_le_to_cpu_16(switch_config->header.num_reported);
4354 if (num_reported != 1) { /* The number should be 1 */
4355 PMD_DRV_LOG(ERR, "Wrong number of switch config reported");
4359 /* Parse the switch configuration elements */
4360 element = &(switch_config->element[0]);
4361 if (element->element_type == I40E_SWITCH_ELEMENT_TYPE_VSI) {
4362 pf->mac_seid = rte_le_to_cpu_16(element->uplink_seid);
4363 pf->main_vsi_seid = rte_le_to_cpu_16(element->seid);
4365 PMD_DRV_LOG(INFO, "Unknown element type");
4368 rte_free(switch_config);
4374 i40e_res_pool_init (struct i40e_res_pool_info *pool, uint32_t base,
4377 struct pool_entry *entry;
4379 if (pool == NULL || num == 0)
4382 entry = rte_zmalloc("i40e", sizeof(*entry), 0);
4383 if (entry == NULL) {
4384 PMD_DRV_LOG(ERR, "Failed to allocate memory for resource pool");
4388 /* queue heap initialize */
4389 pool->num_free = num;
4390 pool->num_alloc = 0;
4392 LIST_INIT(&pool->alloc_list);
4393 LIST_INIT(&pool->free_list);
4395 /* Initialize element */
4399 LIST_INSERT_HEAD(&pool->free_list, entry, next);
4404 i40e_res_pool_destroy(struct i40e_res_pool_info *pool)
4406 struct pool_entry *entry, *next_entry;
4411 for (entry = LIST_FIRST(&pool->alloc_list);
4412 entry && (next_entry = LIST_NEXT(entry, next), 1);
4413 entry = next_entry) {
4414 LIST_REMOVE(entry, next);
4418 for (entry = LIST_FIRST(&pool->free_list);
4419 entry && (next_entry = LIST_NEXT(entry, next), 1);
4420 entry = next_entry) {
4421 LIST_REMOVE(entry, next);
4426 pool->num_alloc = 0;
4428 LIST_INIT(&pool->alloc_list);
4429 LIST_INIT(&pool->free_list);
4433 i40e_res_pool_free(struct i40e_res_pool_info *pool,
4436 struct pool_entry *entry, *next, *prev, *valid_entry = NULL;
4437 uint32_t pool_offset;
4441 PMD_DRV_LOG(ERR, "Invalid parameter");
4445 pool_offset = base - pool->base;
4446 /* Lookup in alloc list */
4447 LIST_FOREACH(entry, &pool->alloc_list, next) {
4448 if (entry->base == pool_offset) {
4449 valid_entry = entry;
4450 LIST_REMOVE(entry, next);
4455 /* Not find, return */
4456 if (valid_entry == NULL) {
4457 PMD_DRV_LOG(ERR, "Failed to find entry");
4462 * Found it, move it to free list and try to merge.
4463 * In order to make merge easier, always sort it by qbase.
4464 * Find adjacent prev and last entries.
4467 LIST_FOREACH(entry, &pool->free_list, next) {
4468 if (entry->base > valid_entry->base) {
4476 /* Try to merge with next one*/
4478 /* Merge with next one */
4479 if (valid_entry->base + valid_entry->len == next->base) {
4480 next->base = valid_entry->base;
4481 next->len += valid_entry->len;
4482 rte_free(valid_entry);
4489 /* Merge with previous one */
4490 if (prev->base + prev->len == valid_entry->base) {
4491 prev->len += valid_entry->len;
4492 /* If it merge with next one, remove next node */
4494 LIST_REMOVE(valid_entry, next);
4495 rte_free(valid_entry);
4497 rte_free(valid_entry);
4503 /* Not find any entry to merge, insert */
4506 LIST_INSERT_AFTER(prev, valid_entry, next);
4507 else if (next != NULL)
4508 LIST_INSERT_BEFORE(next, valid_entry, next);
4509 else /* It's empty list, insert to head */
4510 LIST_INSERT_HEAD(&pool->free_list, valid_entry, next);
4513 pool->num_free += valid_entry->len;
4514 pool->num_alloc -= valid_entry->len;
4520 i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
4523 struct pool_entry *entry, *valid_entry;
4525 if (pool == NULL || num == 0) {
4526 PMD_DRV_LOG(ERR, "Invalid parameter");
4530 if (pool->num_free < num) {
4531 PMD_DRV_LOG(ERR, "No resource. ask:%u, available:%u",
4532 num, pool->num_free);
4537 /* Lookup in free list and find most fit one */
4538 LIST_FOREACH(entry, &pool->free_list, next) {
4539 if (entry->len >= num) {
4541 if (entry->len == num) {
4542 valid_entry = entry;
4545 if (valid_entry == NULL || valid_entry->len > entry->len)
4546 valid_entry = entry;
4550 /* Not find one to satisfy the request, return */
4551 if (valid_entry == NULL) {
4552 PMD_DRV_LOG(ERR, "No valid entry found");
4556 * The entry have equal queue number as requested,
4557 * remove it from alloc_list.
4559 if (valid_entry->len == num) {
4560 LIST_REMOVE(valid_entry, next);
4563 * The entry have more numbers than requested,
4564 * create a new entry for alloc_list and minus its
4565 * queue base and number in free_list.
4567 entry = rte_zmalloc("res_pool", sizeof(*entry), 0);
4568 if (entry == NULL) {
4570 "Failed to allocate memory for resource pool");
4573 entry->base = valid_entry->base;
4575 valid_entry->base += num;
4576 valid_entry->len -= num;
4577 valid_entry = entry;
4580 /* Insert it into alloc list, not sorted */
4581 LIST_INSERT_HEAD(&pool->alloc_list, valid_entry, next);
4583 pool->num_free -= valid_entry->len;
4584 pool->num_alloc += valid_entry->len;
4586 return valid_entry->base + pool->base;
4590 * bitmap_is_subset - Check whether src2 is subset of src1
4593 bitmap_is_subset(uint8_t src1, uint8_t src2)
4595 return !((src1 ^ src2) & src2);
4598 static enum i40e_status_code
4599 validate_tcmap_parameter(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
4601 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4603 /* If DCB is not supported, only default TC is supported */
4604 if (!hw->func_caps.dcb && enabled_tcmap != I40E_DEFAULT_TCMAP) {
4605 PMD_DRV_LOG(ERR, "DCB is not enabled, only TC0 is supported");
4606 return I40E_NOT_SUPPORTED;
4609 if (!bitmap_is_subset(hw->func_caps.enabled_tcmap, enabled_tcmap)) {
4611 "Enabled TC map 0x%x not applicable to HW support 0x%x",
4612 hw->func_caps.enabled_tcmap, enabled_tcmap);
4613 return I40E_NOT_SUPPORTED;
4615 return I40E_SUCCESS;
4619 i40e_vsi_vlan_pvid_set(struct i40e_vsi *vsi,
4620 struct i40e_vsi_vlan_pvid_info *info)
4623 struct i40e_vsi_context ctxt;
4624 uint8_t vlan_flags = 0;
4627 if (vsi == NULL || info == NULL) {
4628 PMD_DRV_LOG(ERR, "invalid parameters");
4629 return I40E_ERR_PARAM;
4633 vsi->info.pvid = info->config.pvid;
4635 * If insert pvid is enabled, only tagged pkts are
4636 * allowed to be sent out.
4638 vlan_flags |= I40E_AQ_VSI_PVLAN_INSERT_PVID |
4639 I40E_AQ_VSI_PVLAN_MODE_TAGGED;
4642 if (info->config.reject.tagged == 0)
4643 vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_TAGGED;
4645 if (info->config.reject.untagged == 0)
4646 vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_UNTAGGED;
4648 vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_INSERT_PVID |
4649 I40E_AQ_VSI_PVLAN_MODE_MASK);
4650 vsi->info.port_vlan_flags |= vlan_flags;
4651 vsi->info.valid_sections =
4652 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
4653 memset(&ctxt, 0, sizeof(ctxt));
4654 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
4655 ctxt.seid = vsi->seid;
4657 hw = I40E_VSI_TO_HW(vsi);
4658 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
4659 if (ret != I40E_SUCCESS)
4660 PMD_DRV_LOG(ERR, "Failed to update VSI params");
4666 i40e_vsi_update_tc_bandwidth(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
4668 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4670 struct i40e_aqc_configure_vsi_tc_bw_data tc_bw_data;
4672 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
4673 if (ret != I40E_SUCCESS)
4677 PMD_DRV_LOG(ERR, "seid not valid");
4681 memset(&tc_bw_data, 0, sizeof(tc_bw_data));
4682 tc_bw_data.tc_valid_bits = enabled_tcmap;
4683 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
4684 tc_bw_data.tc_bw_credits[i] =
4685 (enabled_tcmap & (1 << i)) ? 1 : 0;
4687 ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &tc_bw_data, NULL);
4688 if (ret != I40E_SUCCESS) {
4689 PMD_DRV_LOG(ERR, "Failed to configure TC BW");
4693 rte_memcpy(vsi->info.qs_handle, tc_bw_data.qs_handles,
4694 sizeof(vsi->info.qs_handle));
4695 return I40E_SUCCESS;
4698 static enum i40e_status_code
4699 i40e_vsi_config_tc_queue_mapping(struct i40e_vsi *vsi,
4700 struct i40e_aqc_vsi_properties_data *info,
4701 uint8_t enabled_tcmap)
4703 enum i40e_status_code ret;
4704 int i, total_tc = 0;
4705 uint16_t qpnum_per_tc, bsf, qp_idx;
4707 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
4708 if (ret != I40E_SUCCESS)
4711 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
4712 if (enabled_tcmap & (1 << i))
4716 vsi->enabled_tc = enabled_tcmap;
4718 /* Number of queues per enabled TC */
4719 qpnum_per_tc = i40e_align_floor(vsi->nb_qps / total_tc);
4720 qpnum_per_tc = RTE_MIN(qpnum_per_tc, I40E_MAX_Q_PER_TC);
4721 bsf = rte_bsf32(qpnum_per_tc);
4723 /* Adjust the queue number to actual queues that can be applied */
4724 if (!(vsi->type == I40E_VSI_MAIN && total_tc == 1))
4725 vsi->nb_qps = qpnum_per_tc * total_tc;
4728 * Configure TC and queue mapping parameters, for enabled TC,
4729 * allocate qpnum_per_tc queues to this traffic. For disabled TC,
4730 * default queue will serve it.
4733 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4734 if (vsi->enabled_tc & (1 << i)) {
4735 info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
4736 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
4737 (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
4738 qp_idx += qpnum_per_tc;
4740 info->tc_mapping[i] = 0;
4743 /* Associate queue number with VSI */
4744 if (vsi->type == I40E_VSI_SRIOV) {
4745 info->mapping_flags |=
4746 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
4747 for (i = 0; i < vsi->nb_qps; i++)
4748 info->queue_mapping[i] =
4749 rte_cpu_to_le_16(vsi->base_queue + i);
4751 info->mapping_flags |=
4752 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
4753 info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
4755 info->valid_sections |=
4756 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
4758 return I40E_SUCCESS;
4762 i40e_veb_release(struct i40e_veb *veb)
4764 struct i40e_vsi *vsi;
4770 if (!TAILQ_EMPTY(&veb->head)) {
4771 PMD_DRV_LOG(ERR, "VEB still has VSI attached, can't remove");
4774 /* associate_vsi field is NULL for floating VEB */
4775 if (veb->associate_vsi != NULL) {
4776 vsi = veb->associate_vsi;
4777 hw = I40E_VSI_TO_HW(vsi);
4779 vsi->uplink_seid = veb->uplink_seid;
4782 veb->associate_pf->main_vsi->floating_veb = NULL;
4783 hw = I40E_VSI_TO_HW(veb->associate_pf->main_vsi);
4786 i40e_aq_delete_element(hw, veb->seid, NULL);
4788 return I40E_SUCCESS;
4792 static struct i40e_veb *
4793 i40e_veb_setup(struct i40e_pf *pf, struct i40e_vsi *vsi)
4795 struct i40e_veb *veb;
4801 "veb setup failed, associated PF shouldn't null");
4804 hw = I40E_PF_TO_HW(pf);
4806 veb = rte_zmalloc("i40e_veb", sizeof(struct i40e_veb), 0);
4808 PMD_DRV_LOG(ERR, "Failed to allocate memory for veb");
4812 veb->associate_vsi = vsi;
4813 veb->associate_pf = pf;
4814 TAILQ_INIT(&veb->head);
4815 veb->uplink_seid = vsi ? vsi->uplink_seid : 0;
4817 /* create floating veb if vsi is NULL */
4819 ret = i40e_aq_add_veb(hw, veb->uplink_seid, vsi->seid,
4820 I40E_DEFAULT_TCMAP, false,
4821 &veb->seid, false, NULL);
4823 ret = i40e_aq_add_veb(hw, 0, 0, I40E_DEFAULT_TCMAP,
4824 true, &veb->seid, false, NULL);
4827 if (ret != I40E_SUCCESS) {
4828 PMD_DRV_LOG(ERR, "Add veb failed, aq_err: %d",
4829 hw->aq.asq_last_status);
4832 veb->enabled_tc = I40E_DEFAULT_TCMAP;
4834 /* get statistics index */
4835 ret = i40e_aq_get_veb_parameters(hw, veb->seid, NULL, NULL,
4836 &veb->stats_idx, NULL, NULL, NULL);
4837 if (ret != I40E_SUCCESS) {
4838 PMD_DRV_LOG(ERR, "Get veb statistics index failed, aq_err: %d",
4839 hw->aq.asq_last_status);
4842 /* Get VEB bandwidth, to be implemented */
4843 /* Now associated vsi binding to the VEB, set uplink to this VEB */
4845 vsi->uplink_seid = veb->seid;
4854 i40e_vsi_release(struct i40e_vsi *vsi)
4858 struct i40e_vsi_list *vsi_list;
4861 struct i40e_mac_filter *f;
4862 uint16_t user_param;
4865 return I40E_SUCCESS;
4870 user_param = vsi->user_param;
4872 pf = I40E_VSI_TO_PF(vsi);
4873 hw = I40E_VSI_TO_HW(vsi);
4875 /* VSI has child to attach, release child first */
4877 TAILQ_FOREACH_SAFE(vsi_list, &vsi->veb->head, list, temp) {
4878 if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
4881 i40e_veb_release(vsi->veb);
4884 if (vsi->floating_veb) {
4885 TAILQ_FOREACH_SAFE(vsi_list, &vsi->floating_veb->head, list, temp) {
4886 if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
4891 /* Remove all macvlan filters of the VSI */
4892 i40e_vsi_remove_all_macvlan_filter(vsi);
4893 TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp)
4896 if (vsi->type != I40E_VSI_MAIN &&
4897 ((vsi->type != I40E_VSI_SRIOV) ||
4898 !pf->floating_veb_list[user_param])) {
4899 /* Remove vsi from parent's sibling list */
4900 if (vsi->parent_vsi == NULL || vsi->parent_vsi->veb == NULL) {
4901 PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
4902 return I40E_ERR_PARAM;
4904 TAILQ_REMOVE(&vsi->parent_vsi->veb->head,
4905 &vsi->sib_vsi_list, list);
4907 /* Remove all switch element of the VSI */
4908 ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
4909 if (ret != I40E_SUCCESS)
4910 PMD_DRV_LOG(ERR, "Failed to delete element");
4913 if ((vsi->type == I40E_VSI_SRIOV) &&
4914 pf->floating_veb_list[user_param]) {
4915 /* Remove vsi from parent's sibling list */
4916 if (vsi->parent_vsi == NULL ||
4917 vsi->parent_vsi->floating_veb == NULL) {
4918 PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
4919 return I40E_ERR_PARAM;
4921 TAILQ_REMOVE(&vsi->parent_vsi->floating_veb->head,
4922 &vsi->sib_vsi_list, list);
4924 /* Remove all switch element of the VSI */
4925 ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
4926 if (ret != I40E_SUCCESS)
4927 PMD_DRV_LOG(ERR, "Failed to delete element");
4930 i40e_res_pool_free(&pf->qp_pool, vsi->base_queue);
4932 if (vsi->type != I40E_VSI_SRIOV)
4933 i40e_res_pool_free(&pf->msix_pool, vsi->msix_intr);
4936 return I40E_SUCCESS;
4940 i40e_update_default_filter_setting(struct i40e_vsi *vsi)
4942 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4943 struct i40e_aqc_remove_macvlan_element_data def_filter;
4944 struct i40e_mac_filter_info filter;
4947 if (vsi->type != I40E_VSI_MAIN)
4948 return I40E_ERR_CONFIG;
4949 memset(&def_filter, 0, sizeof(def_filter));
4950 rte_memcpy(def_filter.mac_addr, hw->mac.perm_addr,
4952 def_filter.vlan_tag = 0;
4953 def_filter.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
4954 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
4955 ret = i40e_aq_remove_macvlan(hw, vsi->seid, &def_filter, 1, NULL);
4956 if (ret != I40E_SUCCESS) {
4957 struct i40e_mac_filter *f;
4958 struct ether_addr *mac;
4961 "Cannot remove the default macvlan filter");
4962 /* It needs to add the permanent mac into mac list */
4963 f = rte_zmalloc("macv_filter", sizeof(*f), 0);
4965 PMD_DRV_LOG(ERR, "failed to allocate memory");
4966 return I40E_ERR_NO_MEMORY;
4968 mac = &f->mac_info.mac_addr;
4969 rte_memcpy(&mac->addr_bytes, hw->mac.perm_addr,
4971 f->mac_info.filter_type = RTE_MACVLAN_PERFECT_MATCH;
4972 TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
4977 rte_memcpy(&filter.mac_addr,
4978 (struct ether_addr *)(hw->mac.perm_addr), ETH_ADDR_LEN);
4979 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
4980 return i40e_vsi_add_mac(vsi, &filter);
4984 * i40e_vsi_get_bw_config - Query VSI BW Information
4985 * @vsi: the VSI to be queried
4987 * Returns 0 on success, negative value on failure
4989 static enum i40e_status_code
4990 i40e_vsi_get_bw_config(struct i40e_vsi *vsi)
4992 struct i40e_aqc_query_vsi_bw_config_resp bw_config;
4993 struct i40e_aqc_query_vsi_ets_sla_config_resp ets_sla_config;
4994 struct i40e_hw *hw = &vsi->adapter->hw;
4999 memset(&bw_config, 0, sizeof(bw_config));
5000 ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
5001 if (ret != I40E_SUCCESS) {
5002 PMD_DRV_LOG(ERR, "VSI failed to get bandwidth configuration %u",
5003 hw->aq.asq_last_status);
5007 memset(&ets_sla_config, 0, sizeof(ets_sla_config));
5008 ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid,
5009 &ets_sla_config, NULL);
5010 if (ret != I40E_SUCCESS) {
5012 "VSI failed to get TC bandwdith configuration %u",
5013 hw->aq.asq_last_status);
5017 /* store and print out BW info */
5018 vsi->bw_info.bw_limit = rte_le_to_cpu_16(bw_config.port_bw_limit);
5019 vsi->bw_info.bw_max = bw_config.max_bw;
5020 PMD_DRV_LOG(DEBUG, "VSI bw limit:%u", vsi->bw_info.bw_limit);
5021 PMD_DRV_LOG(DEBUG, "VSI max_bw:%u", vsi->bw_info.bw_max);
5022 bw_max = rte_le_to_cpu_16(ets_sla_config.tc_bw_max[0]) |
5023 (rte_le_to_cpu_16(ets_sla_config.tc_bw_max[1]) <<
5025 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5026 vsi->bw_info.bw_ets_share_credits[i] =
5027 ets_sla_config.share_credits[i];
5028 vsi->bw_info.bw_ets_credits[i] =
5029 rte_le_to_cpu_16(ets_sla_config.credits[i]);
5030 /* 4 bits per TC, 4th bit is reserved */
5031 vsi->bw_info.bw_ets_max[i] =
5032 (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
5033 RTE_LEN2MASK(3, uint8_t));
5034 PMD_DRV_LOG(DEBUG, "\tVSI TC%u:share credits %u", i,
5035 vsi->bw_info.bw_ets_share_credits[i]);
5036 PMD_DRV_LOG(DEBUG, "\tVSI TC%u:credits %u", i,
5037 vsi->bw_info.bw_ets_credits[i]);
5038 PMD_DRV_LOG(DEBUG, "\tVSI TC%u: max credits: %u", i,
5039 vsi->bw_info.bw_ets_max[i]);
5042 return I40E_SUCCESS;
5045 /* i40e_enable_pf_lb
5046 * @pf: pointer to the pf structure
5048 * allow loopback on pf
5051 i40e_enable_pf_lb(struct i40e_pf *pf)
5053 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5054 struct i40e_vsi_context ctxt;
5057 /* Use the FW API if FW >= v5.0 */
5058 if (hw->aq.fw_maj_ver < 5) {
5059 PMD_INIT_LOG(ERR, "FW < v5.0, cannot enable loopback");
5063 memset(&ctxt, 0, sizeof(ctxt));
5064 ctxt.seid = pf->main_vsi_seid;
5065 ctxt.pf_num = hw->pf_id;
5066 ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5068 PMD_DRV_LOG(ERR, "cannot get pf vsi config, err %d, aq_err %d",
5069 ret, hw->aq.asq_last_status);
5072 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
5073 ctxt.info.valid_sections =
5074 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5075 ctxt.info.switch_id |=
5076 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5078 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5080 PMD_DRV_LOG(ERR, "update vsi switch failed, aq_err=%d",
5081 hw->aq.asq_last_status);
5086 i40e_vsi_setup(struct i40e_pf *pf,
5087 enum i40e_vsi_type type,
5088 struct i40e_vsi *uplink_vsi,
5089 uint16_t user_param)
5091 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5092 struct i40e_vsi *vsi;
5093 struct i40e_mac_filter_info filter;
5095 struct i40e_vsi_context ctxt;
5096 struct ether_addr broadcast =
5097 {.addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
5099 if (type != I40E_VSI_MAIN && type != I40E_VSI_SRIOV &&
5100 uplink_vsi == NULL) {
5102 "VSI setup failed, VSI link shouldn't be NULL");
5106 if (type == I40E_VSI_MAIN && uplink_vsi != NULL) {
5108 "VSI setup failed, MAIN VSI uplink VSI should be NULL");
5113 * 1.type is not MAIN and uplink vsi is not NULL
5114 * If uplink vsi didn't setup VEB, create one first under veb field
5115 * 2.type is SRIOV and the uplink is NULL
5116 * If floating VEB is NULL, create one veb under floating veb field
5119 if (type != I40E_VSI_MAIN && uplink_vsi != NULL &&
5120 uplink_vsi->veb == NULL) {
5121 uplink_vsi->veb = i40e_veb_setup(pf, uplink_vsi);
5123 if (uplink_vsi->veb == NULL) {
5124 PMD_DRV_LOG(ERR, "VEB setup failed");
5127 /* set ALLOWLOOPBACk on pf, when veb is created */
5128 i40e_enable_pf_lb(pf);
5131 if (type == I40E_VSI_SRIOV && uplink_vsi == NULL &&
5132 pf->main_vsi->floating_veb == NULL) {
5133 pf->main_vsi->floating_veb = i40e_veb_setup(pf, uplink_vsi);
5135 if (pf->main_vsi->floating_veb == NULL) {
5136 PMD_DRV_LOG(ERR, "VEB setup failed");
5141 vsi = rte_zmalloc("i40e_vsi", sizeof(struct i40e_vsi), 0);
5143 PMD_DRV_LOG(ERR, "Failed to allocate memory for vsi");
5146 TAILQ_INIT(&vsi->mac_list);
5148 vsi->adapter = I40E_PF_TO_ADAPTER(pf);
5149 vsi->max_macaddrs = I40E_NUM_MACADDR_MAX;
5150 vsi->parent_vsi = uplink_vsi ? uplink_vsi : pf->main_vsi;
5151 vsi->user_param = user_param;
5152 vsi->vlan_anti_spoof_on = 0;
5153 vsi->vlan_filter_on = 0;
5154 /* Allocate queues */
5155 switch (vsi->type) {
5156 case I40E_VSI_MAIN :
5157 vsi->nb_qps = pf->lan_nb_qps;
5159 case I40E_VSI_SRIOV :
5160 vsi->nb_qps = pf->vf_nb_qps;
5162 case I40E_VSI_VMDQ2:
5163 vsi->nb_qps = pf->vmdq_nb_qps;
5166 vsi->nb_qps = pf->fdir_nb_qps;
5172 * The filter status descriptor is reported in rx queue 0,
5173 * while the tx queue for fdir filter programming has no
5174 * such constraints, can be non-zero queues.
5175 * To simplify it, choose FDIR vsi use queue 0 pair.
5176 * To make sure it will use queue 0 pair, queue allocation
5177 * need be done before this function is called
5179 if (type != I40E_VSI_FDIR) {
5180 ret = i40e_res_pool_alloc(&pf->qp_pool, vsi->nb_qps);
5182 PMD_DRV_LOG(ERR, "VSI %d allocate queue failed %d",
5186 vsi->base_queue = ret;
5188 vsi->base_queue = I40E_FDIR_QUEUE_ID;
5190 /* VF has MSIX interrupt in VF range, don't allocate here */
5191 if (type == I40E_VSI_MAIN) {
5192 if (pf->support_multi_driver) {
5193 /* If support multi-driver, need to use INT0 instead of
5194 * allocating from msix pool. The Msix pool is init from
5195 * INT1, so it's OK just set msix_intr to 0 and nb_msix
5196 * to 1 without calling i40e_res_pool_alloc.
5201 ret = i40e_res_pool_alloc(&pf->msix_pool,
5202 RTE_MIN(vsi->nb_qps,
5203 RTE_MAX_RXTX_INTR_VEC_ID));
5206 "VSI MAIN %d get heap failed %d",
5208 goto fail_queue_alloc;
5210 vsi->msix_intr = ret;
5211 vsi->nb_msix = RTE_MIN(vsi->nb_qps,
5212 RTE_MAX_RXTX_INTR_VEC_ID);
5214 } else if (type != I40E_VSI_SRIOV) {
5215 ret = i40e_res_pool_alloc(&pf->msix_pool, 1);
5217 PMD_DRV_LOG(ERR, "VSI %d get heap failed %d", vsi->seid, ret);
5218 goto fail_queue_alloc;
5220 vsi->msix_intr = ret;
5228 if (type == I40E_VSI_MAIN) {
5229 /* For main VSI, no need to add since it's default one */
5230 vsi->uplink_seid = pf->mac_seid;
5231 vsi->seid = pf->main_vsi_seid;
5232 /* Bind queues with specific MSIX interrupt */
5234 * Needs 2 interrupt at least, one for misc cause which will
5235 * enabled from OS side, Another for queues binding the
5236 * interrupt from device side only.
5239 /* Get default VSI parameters from hardware */
5240 memset(&ctxt, 0, sizeof(ctxt));
5241 ctxt.seid = vsi->seid;
5242 ctxt.pf_num = hw->pf_id;
5243 ctxt.uplink_seid = vsi->uplink_seid;
5245 ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5246 if (ret != I40E_SUCCESS) {
5247 PMD_DRV_LOG(ERR, "Failed to get VSI params");
5248 goto fail_msix_alloc;
5250 rte_memcpy(&vsi->info, &ctxt.info,
5251 sizeof(struct i40e_aqc_vsi_properties_data));
5252 vsi->vsi_id = ctxt.vsi_number;
5253 vsi->info.valid_sections = 0;
5255 /* Configure tc, enabled TC0 only */
5256 if (i40e_vsi_update_tc_bandwidth(vsi, I40E_DEFAULT_TCMAP) !=
5258 PMD_DRV_LOG(ERR, "Failed to update TC bandwidth");
5259 goto fail_msix_alloc;
5262 /* TC, queue mapping */
5263 memset(&ctxt, 0, sizeof(ctxt));
5264 vsi->info.valid_sections |=
5265 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5266 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
5267 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
5268 rte_memcpy(&ctxt.info, &vsi->info,
5269 sizeof(struct i40e_aqc_vsi_properties_data));
5270 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
5271 I40E_DEFAULT_TCMAP);
5272 if (ret != I40E_SUCCESS) {
5274 "Failed to configure TC queue mapping");
5275 goto fail_msix_alloc;
5277 ctxt.seid = vsi->seid;
5278 ctxt.pf_num = hw->pf_id;
5279 ctxt.uplink_seid = vsi->uplink_seid;
5282 /* Update VSI parameters */
5283 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5284 if (ret != I40E_SUCCESS) {
5285 PMD_DRV_LOG(ERR, "Failed to update VSI params");
5286 goto fail_msix_alloc;
5289 rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
5290 sizeof(vsi->info.tc_mapping));
5291 rte_memcpy(&vsi->info.queue_mapping,
5292 &ctxt.info.queue_mapping,
5293 sizeof(vsi->info.queue_mapping));
5294 vsi->info.mapping_flags = ctxt.info.mapping_flags;
5295 vsi->info.valid_sections = 0;
5297 rte_memcpy(pf->dev_addr.addr_bytes, hw->mac.perm_addr,
5301 * Updating default filter settings are necessary to prevent
5302 * reception of tagged packets.
5303 * Some old firmware configurations load a default macvlan
5304 * filter which accepts both tagged and untagged packets.
5305 * The updating is to use a normal filter instead if needed.
5306 * For NVM 4.2.2 or after, the updating is not needed anymore.
5307 * The firmware with correct configurations load the default
5308 * macvlan filter which is expected and cannot be removed.
5310 i40e_update_default_filter_setting(vsi);
5311 i40e_config_qinq(hw, vsi);
5312 } else if (type == I40E_VSI_SRIOV) {
5313 memset(&ctxt, 0, sizeof(ctxt));
5315 * For other VSI, the uplink_seid equals to uplink VSI's
5316 * uplink_seid since they share same VEB
5318 if (uplink_vsi == NULL)
5319 vsi->uplink_seid = pf->main_vsi->floating_veb->seid;
5321 vsi->uplink_seid = uplink_vsi->uplink_seid;
5322 ctxt.pf_num = hw->pf_id;
5323 ctxt.vf_num = hw->func_caps.vf_base_id + user_param;
5324 ctxt.uplink_seid = vsi->uplink_seid;
5325 ctxt.connection_type = 0x1;
5326 ctxt.flags = I40E_AQ_VSI_TYPE_VF;
5328 /* Use the VEB configuration if FW >= v5.0 */
5329 if (hw->aq.fw_maj_ver >= 5) {
5330 /* Configure switch ID */
5331 ctxt.info.valid_sections |=
5332 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5333 ctxt.info.switch_id =
5334 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5337 /* Configure port/vlan */
5338 ctxt.info.valid_sections |=
5339 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5340 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
5341 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
5342 hw->func_caps.enabled_tcmap);
5343 if (ret != I40E_SUCCESS) {
5345 "Failed to configure TC queue mapping");
5346 goto fail_msix_alloc;
5349 ctxt.info.up_enable_bits = hw->func_caps.enabled_tcmap;
5350 ctxt.info.valid_sections |=
5351 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
5353 * Since VSI is not created yet, only configure parameter,
5354 * will add vsi below.
5357 i40e_config_qinq(hw, vsi);
5358 } else if (type == I40E_VSI_VMDQ2) {
5359 memset(&ctxt, 0, sizeof(ctxt));
5361 * For other VSI, the uplink_seid equals to uplink VSI's
5362 * uplink_seid since they share same VEB
5364 vsi->uplink_seid = uplink_vsi->uplink_seid;
5365 ctxt.pf_num = hw->pf_id;
5367 ctxt.uplink_seid = vsi->uplink_seid;
5368 ctxt.connection_type = 0x1;
5369 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
5371 ctxt.info.valid_sections |=
5372 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5373 /* user_param carries flag to enable loop back */
5375 ctxt.info.switch_id =
5376 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
5377 ctxt.info.switch_id |=
5378 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5381 /* Configure port/vlan */
5382 ctxt.info.valid_sections |=
5383 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5384 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
5385 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
5386 I40E_DEFAULT_TCMAP);
5387 if (ret != I40E_SUCCESS) {
5389 "Failed to configure TC queue mapping");
5390 goto fail_msix_alloc;
5392 ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
5393 ctxt.info.valid_sections |=
5394 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
5395 } else if (type == I40E_VSI_FDIR) {
5396 memset(&ctxt, 0, sizeof(ctxt));
5397 vsi->uplink_seid = uplink_vsi->uplink_seid;
5398 ctxt.pf_num = hw->pf_id;
5400 ctxt.uplink_seid = vsi->uplink_seid;
5401 ctxt.connection_type = 0x1; /* regular data port */
5402 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
5403 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
5404 I40E_DEFAULT_TCMAP);
5405 if (ret != I40E_SUCCESS) {
5407 "Failed to configure TC queue mapping.");
5408 goto fail_msix_alloc;
5410 ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
5411 ctxt.info.valid_sections |=
5412 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
5414 PMD_DRV_LOG(ERR, "VSI: Not support other type VSI yet");
5415 goto fail_msix_alloc;
5418 if (vsi->type != I40E_VSI_MAIN) {
5419 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
5420 if (ret != I40E_SUCCESS) {
5421 PMD_DRV_LOG(ERR, "add vsi failed, aq_err=%d",
5422 hw->aq.asq_last_status);
5423 goto fail_msix_alloc;
5425 memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
5426 vsi->info.valid_sections = 0;
5427 vsi->seid = ctxt.seid;
5428 vsi->vsi_id = ctxt.vsi_number;
5429 vsi->sib_vsi_list.vsi = vsi;
5430 if (vsi->type == I40E_VSI_SRIOV && uplink_vsi == NULL) {
5431 TAILQ_INSERT_TAIL(&pf->main_vsi->floating_veb->head,
5432 &vsi->sib_vsi_list, list);
5434 TAILQ_INSERT_TAIL(&uplink_vsi->veb->head,
5435 &vsi->sib_vsi_list, list);
5439 /* MAC/VLAN configuration */
5440 rte_memcpy(&filter.mac_addr, &broadcast, ETHER_ADDR_LEN);
5441 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
5443 ret = i40e_vsi_add_mac(vsi, &filter);
5444 if (ret != I40E_SUCCESS) {
5445 PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
5446 goto fail_msix_alloc;
5449 /* Get VSI BW information */
5450 i40e_vsi_get_bw_config(vsi);
5453 i40e_res_pool_free(&pf->msix_pool,vsi->msix_intr);
5455 i40e_res_pool_free(&pf->qp_pool,vsi->base_queue);
5461 /* Configure vlan filter on or off */
5463 i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on)
5466 struct i40e_mac_filter *f;
5468 struct i40e_mac_filter_info *mac_filter;
5469 enum rte_mac_filter_type desired_filter;
5470 int ret = I40E_SUCCESS;
5473 /* Filter to match MAC and VLAN */
5474 desired_filter = RTE_MACVLAN_PERFECT_MATCH;
5476 /* Filter to match only MAC */
5477 desired_filter = RTE_MAC_PERFECT_MATCH;
5482 mac_filter = rte_zmalloc("mac_filter_info_data",
5483 num * sizeof(*mac_filter), 0);
5484 if (mac_filter == NULL) {
5485 PMD_DRV_LOG(ERR, "failed to allocate memory");
5486 return I40E_ERR_NO_MEMORY;
5491 /* Remove all existing mac */
5492 TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
5493 mac_filter[i] = f->mac_info;
5494 ret = i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
5496 PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
5497 on ? "enable" : "disable");
5503 /* Override with new filter */
5504 for (i = 0; i < num; i++) {
5505 mac_filter[i].filter_type = desired_filter;
5506 ret = i40e_vsi_add_mac(vsi, &mac_filter[i]);
5508 PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
5509 on ? "enable" : "disable");
5515 rte_free(mac_filter);
5519 /* Configure vlan stripping on or off */
5521 i40e_vsi_config_vlan_stripping(struct i40e_vsi *vsi, bool on)
5523 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5524 struct i40e_vsi_context ctxt;
5526 int ret = I40E_SUCCESS;
5528 /* Check if it has been already on or off */
5529 if (vsi->info.valid_sections &
5530 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID)) {
5532 if ((vsi->info.port_vlan_flags &
5533 I40E_AQ_VSI_PVLAN_EMOD_MASK) == 0)
5534 return 0; /* already on */
5536 if ((vsi->info.port_vlan_flags &
5537 I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
5538 I40E_AQ_VSI_PVLAN_EMOD_MASK)
5539 return 0; /* already off */
5544 vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
5546 vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
5547 vsi->info.valid_sections =
5548 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5549 vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_EMOD_MASK);
5550 vsi->info.port_vlan_flags |= vlan_flags;
5551 ctxt.seid = vsi->seid;
5552 rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
5553 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5555 PMD_DRV_LOG(INFO, "Update VSI failed to %s vlan stripping",
5556 on ? "enable" : "disable");
5562 i40e_dev_init_vlan(struct rte_eth_dev *dev)
5564 struct rte_eth_dev_data *data = dev->data;
5568 /* Apply vlan offload setting */
5569 mask = ETH_VLAN_STRIP_MASK |
5570 ETH_VLAN_FILTER_MASK |
5571 ETH_VLAN_EXTEND_MASK;
5572 ret = i40e_vlan_offload_set(dev, mask);
5574 PMD_DRV_LOG(INFO, "Failed to update vlan offload");
5578 /* Apply pvid setting */
5579 ret = i40e_vlan_pvid_set(dev, data->dev_conf.txmode.pvid,
5580 data->dev_conf.txmode.hw_vlan_insert_pvid);
5582 PMD_DRV_LOG(INFO, "Failed to update VSI params");
5588 i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on)
5590 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5592 return i40e_aq_set_port_parameters(hw, vsi->seid, 0, 1, on, NULL);
5596 i40e_update_flow_control(struct i40e_hw *hw)
5598 #define I40E_LINK_PAUSE_RXTX (I40E_AQ_LINK_PAUSE_RX | I40E_AQ_LINK_PAUSE_TX)
5599 struct i40e_link_status link_status;
5600 uint32_t rxfc = 0, txfc = 0, reg;
5604 memset(&link_status, 0, sizeof(link_status));
5605 ret = i40e_aq_get_link_info(hw, FALSE, &link_status, NULL);
5606 if (ret != I40E_SUCCESS) {
5607 PMD_DRV_LOG(ERR, "Failed to get link status information");
5608 goto write_reg; /* Disable flow control */
5611 an_info = hw->phy.link_info.an_info;
5612 if (!(an_info & I40E_AQ_AN_COMPLETED)) {
5613 PMD_DRV_LOG(INFO, "Link auto negotiation not completed");
5614 ret = I40E_ERR_NOT_READY;
5615 goto write_reg; /* Disable flow control */
5618 * If link auto negotiation is enabled, flow control needs to
5619 * be configured according to it
5621 switch (an_info & I40E_LINK_PAUSE_RXTX) {
5622 case I40E_LINK_PAUSE_RXTX:
5625 hw->fc.current_mode = I40E_FC_FULL;
5627 case I40E_AQ_LINK_PAUSE_RX:
5629 hw->fc.current_mode = I40E_FC_RX_PAUSE;
5631 case I40E_AQ_LINK_PAUSE_TX:
5633 hw->fc.current_mode = I40E_FC_TX_PAUSE;
5636 hw->fc.current_mode = I40E_FC_NONE;
5641 I40E_WRITE_REG(hw, I40E_PRTDCB_FCCFG,
5642 txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT);
5643 reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
5644 reg &= ~I40E_PRTDCB_MFLCN_RFCE_MASK;
5645 reg |= rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT;
5646 I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, reg);
5653 i40e_pf_setup(struct i40e_pf *pf)
5655 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5656 struct i40e_filter_control_settings settings;
5657 struct i40e_vsi *vsi;
5660 /* Clear all stats counters */
5661 pf->offset_loaded = FALSE;
5662 memset(&pf->stats, 0, sizeof(struct i40e_hw_port_stats));
5663 memset(&pf->stats_offset, 0, sizeof(struct i40e_hw_port_stats));
5664 memset(&pf->internal_stats, 0, sizeof(struct i40e_eth_stats));
5665 memset(&pf->internal_stats_offset, 0, sizeof(struct i40e_eth_stats));
5667 ret = i40e_pf_get_switch_config(pf);
5668 if (ret != I40E_SUCCESS) {
5669 PMD_DRV_LOG(ERR, "Could not get switch config, err %d", ret);
5672 if (pf->flags & I40E_FLAG_FDIR) {
5673 /* make queue allocated first, let FDIR use queue pair 0*/
5674 ret = i40e_res_pool_alloc(&pf->qp_pool, I40E_DEFAULT_QP_NUM_FDIR);
5675 if (ret != I40E_FDIR_QUEUE_ID) {
5677 "queue allocation fails for FDIR: ret =%d",
5679 pf->flags &= ~I40E_FLAG_FDIR;
5682 /* main VSI setup */
5683 vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, NULL, 0);
5685 PMD_DRV_LOG(ERR, "Setup of main vsi failed");
5686 return I40E_ERR_NOT_READY;
5690 /* Configure filter control */
5691 memset(&settings, 0, sizeof(settings));
5692 if (hw->func_caps.rss_table_size == ETH_RSS_RETA_SIZE_128)
5693 settings.hash_lut_size = I40E_HASH_LUT_SIZE_128;
5694 else if (hw->func_caps.rss_table_size == ETH_RSS_RETA_SIZE_512)
5695 settings.hash_lut_size = I40E_HASH_LUT_SIZE_512;
5697 PMD_DRV_LOG(ERR, "Hash lookup table size (%u) not supported",
5698 hw->func_caps.rss_table_size);
5699 return I40E_ERR_PARAM;
5701 PMD_DRV_LOG(INFO, "Hardware capability of hash lookup table size: %u",
5702 hw->func_caps.rss_table_size);
5703 pf->hash_lut_size = hw->func_caps.rss_table_size;
5705 /* Enable ethtype and macvlan filters */
5706 settings.enable_ethtype = TRUE;
5707 settings.enable_macvlan = TRUE;
5708 ret = i40e_set_filter_control(hw, &settings);
5710 PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
5713 /* Update flow control according to the auto negotiation */
5714 i40e_update_flow_control(hw);
5716 return I40E_SUCCESS;
5720 i40e_switch_tx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
5726 * Set or clear TX Queue Disable flags,
5727 * which is required by hardware.
5729 i40e_pre_tx_queue_cfg(hw, q_idx, on);
5730 rte_delay_us(I40E_PRE_TX_Q_CFG_WAIT_US);
5732 /* Wait until the request is finished */
5733 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
5734 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
5735 reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
5736 if (!(((reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 0x1) ^
5737 ((reg >> I40E_QTX_ENA_QENA_STAT_SHIFT)
5743 if (reg & I40E_QTX_ENA_QENA_STAT_MASK)
5744 return I40E_SUCCESS; /* already on, skip next steps */
5746 I40E_WRITE_REG(hw, I40E_QTX_HEAD(q_idx), 0);
5747 reg |= I40E_QTX_ENA_QENA_REQ_MASK;
5749 if (!(reg & I40E_QTX_ENA_QENA_STAT_MASK))
5750 return I40E_SUCCESS; /* already off, skip next steps */
5751 reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
5753 /* Write the register */
5754 I40E_WRITE_REG(hw, I40E_QTX_ENA(q_idx), reg);
5755 /* Check the result */
5756 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
5757 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
5758 reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
5760 if ((reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
5761 (reg & I40E_QTX_ENA_QENA_STAT_MASK))
5764 if (!(reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
5765 !(reg & I40E_QTX_ENA_QENA_STAT_MASK))
5769 /* Check if it is timeout */
5770 if (j >= I40E_CHK_Q_ENA_COUNT) {
5771 PMD_DRV_LOG(ERR, "Failed to %s tx queue[%u]",
5772 (on ? "enable" : "disable"), q_idx);
5773 return I40E_ERR_TIMEOUT;
5776 return I40E_SUCCESS;
5779 /* Swith on or off the tx queues */
5781 i40e_dev_switch_tx_queues(struct i40e_pf *pf, bool on)
5783 struct rte_eth_dev_data *dev_data = pf->dev_data;
5784 struct i40e_tx_queue *txq;
5785 struct rte_eth_dev *dev = pf->adapter->eth_dev;
5789 for (i = 0; i < dev_data->nb_tx_queues; i++) {
5790 txq = dev_data->tx_queues[i];
5791 /* Don't operate the queue if not configured or
5792 * if starting only per queue */
5793 if (!txq || !txq->q_set || (on && txq->tx_deferred_start))
5796 ret = i40e_dev_tx_queue_start(dev, i);
5798 ret = i40e_dev_tx_queue_stop(dev, i);
5799 if ( ret != I40E_SUCCESS)
5803 return I40E_SUCCESS;
5807 i40e_switch_rx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
5812 /* Wait until the request is finished */
5813 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
5814 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
5815 reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
5816 if (!((reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 0x1) ^
5817 ((reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 0x1))
5822 if (reg & I40E_QRX_ENA_QENA_STAT_MASK)
5823 return I40E_SUCCESS; /* Already on, skip next steps */
5824 reg |= I40E_QRX_ENA_QENA_REQ_MASK;
5826 if (!(reg & I40E_QRX_ENA_QENA_STAT_MASK))
5827 return I40E_SUCCESS; /* Already off, skip next steps */
5828 reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
5831 /* Write the register */
5832 I40E_WRITE_REG(hw, I40E_QRX_ENA(q_idx), reg);
5833 /* Check the result */
5834 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
5835 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
5836 reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
5838 if ((reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
5839 (reg & I40E_QRX_ENA_QENA_STAT_MASK))
5842 if (!(reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
5843 !(reg & I40E_QRX_ENA_QENA_STAT_MASK))
5848 /* Check if it is timeout */
5849 if (j >= I40E_CHK_Q_ENA_COUNT) {
5850 PMD_DRV_LOG(ERR, "Failed to %s rx queue[%u]",
5851 (on ? "enable" : "disable"), q_idx);
5852 return I40E_ERR_TIMEOUT;
5855 return I40E_SUCCESS;
5857 /* Switch on or off the rx queues */
5859 i40e_dev_switch_rx_queues(struct i40e_pf *pf, bool on)
5861 struct rte_eth_dev_data *dev_data = pf->dev_data;
5862 struct i40e_rx_queue *rxq;
5863 struct rte_eth_dev *dev = pf->adapter->eth_dev;
5867 for (i = 0; i < dev_data->nb_rx_queues; i++) {
5868 rxq = dev_data->rx_queues[i];
5869 /* Don't operate the queue if not configured or
5870 * if starting only per queue */
5871 if (!rxq || !rxq->q_set || (on && rxq->rx_deferred_start))
5874 ret = i40e_dev_rx_queue_start(dev, i);
5876 ret = i40e_dev_rx_queue_stop(dev, i);
5877 if (ret != I40E_SUCCESS)
5881 return I40E_SUCCESS;
5884 /* Switch on or off all the rx/tx queues */
5886 i40e_dev_switch_queues(struct i40e_pf *pf, bool on)
5891 /* enable rx queues before enabling tx queues */
5892 ret = i40e_dev_switch_rx_queues(pf, on);
5894 PMD_DRV_LOG(ERR, "Failed to switch rx queues");
5897 ret = i40e_dev_switch_tx_queues(pf, on);
5899 /* Stop tx queues before stopping rx queues */
5900 ret = i40e_dev_switch_tx_queues(pf, on);
5902 PMD_DRV_LOG(ERR, "Failed to switch tx queues");
5905 ret = i40e_dev_switch_rx_queues(pf, on);
5911 /* Initialize VSI for TX */
5913 i40e_dev_tx_init(struct i40e_pf *pf)
5915 struct rte_eth_dev_data *data = pf->dev_data;
5917 uint32_t ret = I40E_SUCCESS;
5918 struct i40e_tx_queue *txq;
5920 for (i = 0; i < data->nb_tx_queues; i++) {
5921 txq = data->tx_queues[i];
5922 if (!txq || !txq->q_set)
5924 ret = i40e_tx_queue_init(txq);
5925 if (ret != I40E_SUCCESS)
5928 if (ret == I40E_SUCCESS)
5929 i40e_set_tx_function(container_of(pf, struct i40e_adapter, pf)
5935 /* Initialize VSI for RX */
5937 i40e_dev_rx_init(struct i40e_pf *pf)
5939 struct rte_eth_dev_data *data = pf->dev_data;
5940 int ret = I40E_SUCCESS;
5942 struct i40e_rx_queue *rxq;
5944 i40e_pf_config_mq_rx(pf);
5945 for (i = 0; i < data->nb_rx_queues; i++) {
5946 rxq = data->rx_queues[i];
5947 if (!rxq || !rxq->q_set)
5950 ret = i40e_rx_queue_init(rxq);
5951 if (ret != I40E_SUCCESS) {
5953 "Failed to do RX queue initialization");
5957 if (ret == I40E_SUCCESS)
5958 i40e_set_rx_function(container_of(pf, struct i40e_adapter, pf)
5965 i40e_dev_rxtx_init(struct i40e_pf *pf)
5969 err = i40e_dev_tx_init(pf);
5971 PMD_DRV_LOG(ERR, "Failed to do TX initialization");
5974 err = i40e_dev_rx_init(pf);
5976 PMD_DRV_LOG(ERR, "Failed to do RX initialization");
5984 i40e_vmdq_setup(struct rte_eth_dev *dev)
5986 struct rte_eth_conf *conf = &dev->data->dev_conf;
5987 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5988 int i, err, conf_vsis, j, loop;
5989 struct i40e_vsi *vsi;
5990 struct i40e_vmdq_info *vmdq_info;
5991 struct rte_eth_vmdq_rx_conf *vmdq_conf;
5992 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5995 * Disable interrupt to avoid message from VF. Furthermore, it will
5996 * avoid race condition in VSI creation/destroy.
5998 i40e_pf_disable_irq0(hw);
6000 if ((pf->flags & I40E_FLAG_VMDQ) == 0) {
6001 PMD_INIT_LOG(ERR, "FW doesn't support VMDQ");
6005 conf_vsis = conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools;
6006 if (conf_vsis > pf->max_nb_vmdq_vsi) {
6007 PMD_INIT_LOG(ERR, "VMDQ config: %u, max support:%u",
6008 conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools,
6009 pf->max_nb_vmdq_vsi);
6013 if (pf->vmdq != NULL) {
6014 PMD_INIT_LOG(INFO, "VMDQ already configured");
6018 pf->vmdq = rte_zmalloc("vmdq_info_struct",
6019 sizeof(*vmdq_info) * conf_vsis, 0);
6021 if (pf->vmdq == NULL) {
6022 PMD_INIT_LOG(ERR, "Failed to allocate memory");
6026 vmdq_conf = &conf->rx_adv_conf.vmdq_rx_conf;
6028 /* Create VMDQ VSI */
6029 for (i = 0; i < conf_vsis; i++) {
6030 vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, pf->main_vsi,
6031 vmdq_conf->enable_loop_back);
6033 PMD_INIT_LOG(ERR, "Failed to create VMDQ VSI");
6037 vmdq_info = &pf->vmdq[i];
6039 vmdq_info->vsi = vsi;
6041 pf->nb_cfg_vmdq_vsi = conf_vsis;
6043 /* Configure Vlan */
6044 loop = sizeof(vmdq_conf->pool_map[0].pools) * CHAR_BIT;
6045 for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
6046 for (j = 0; j < loop && j < pf->nb_cfg_vmdq_vsi; j++) {
6047 if (vmdq_conf->pool_map[i].pools & (1UL << j)) {
6048 PMD_INIT_LOG(INFO, "Add vlan %u to vmdq pool %u",
6049 vmdq_conf->pool_map[i].vlan_id, j);
6051 err = i40e_vsi_add_vlan(pf->vmdq[j].vsi,
6052 vmdq_conf->pool_map[i].vlan_id);
6054 PMD_INIT_LOG(ERR, "Failed to add vlan");
6062 i40e_pf_enable_irq0(hw);
6067 for (i = 0; i < conf_vsis; i++)
6068 if (pf->vmdq[i].vsi == NULL)
6071 i40e_vsi_release(pf->vmdq[i].vsi);
6075 i40e_pf_enable_irq0(hw);
6080 i40e_stat_update_32(struct i40e_hw *hw,
6088 new_data = (uint64_t)I40E_READ_REG(hw, reg);
6092 if (new_data >= *offset)
6093 *stat = (uint64_t)(new_data - *offset);
6095 *stat = (uint64_t)((new_data +
6096 ((uint64_t)1 << I40E_32_BIT_WIDTH)) - *offset);
6100 i40e_stat_update_48(struct i40e_hw *hw,
6109 new_data = (uint64_t)I40E_READ_REG(hw, loreg);
6110 new_data |= ((uint64_t)(I40E_READ_REG(hw, hireg) &
6111 I40E_16_BIT_MASK)) << I40E_32_BIT_WIDTH;
6116 if (new_data >= *offset)
6117 *stat = new_data - *offset;
6119 *stat = (uint64_t)((new_data +
6120 ((uint64_t)1 << I40E_48_BIT_WIDTH)) - *offset);
6122 *stat &= I40E_48_BIT_MASK;
6127 i40e_pf_disable_irq0(struct i40e_hw *hw)
6129 /* Disable all interrupt types */
6130 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
6131 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
6132 I40E_WRITE_FLUSH(hw);
6137 i40e_pf_enable_irq0(struct i40e_hw *hw)
6139 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
6140 I40E_PFINT_DYN_CTL0_INTENA_MASK |
6141 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
6142 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
6143 I40E_WRITE_FLUSH(hw);
6147 i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue)
6149 /* read pending request and disable first */
6150 i40e_pf_disable_irq0(hw);
6151 I40E_WRITE_REG(hw, I40E_PFINT_ICR0_ENA, I40E_PFINT_ICR0_ENA_MASK);
6152 I40E_WRITE_REG(hw, I40E_PFINT_STAT_CTL0,
6153 I40E_PFINT_STAT_CTL0_OTHER_ITR_INDX_MASK);
6156 /* Link no queues with irq0 */
6157 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
6158 I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
6162 i40e_dev_handle_vfr_event(struct rte_eth_dev *dev)
6164 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6165 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6168 uint32_t index, offset, val;
6173 * Try to find which VF trigger a reset, use absolute VF id to access
6174 * since the reg is global register.
6176 for (i = 0; i < pf->vf_num; i++) {
6177 abs_vf_id = hw->func_caps.vf_base_id + i;
6178 index = abs_vf_id / I40E_UINT32_BIT_SIZE;
6179 offset = abs_vf_id % I40E_UINT32_BIT_SIZE;
6180 val = I40E_READ_REG(hw, I40E_GLGEN_VFLRSTAT(index));
6181 /* VFR event occurred */
6182 if (val & (0x1 << offset)) {
6185 /* Clear the event first */
6186 I40E_WRITE_REG(hw, I40E_GLGEN_VFLRSTAT(index),
6188 PMD_DRV_LOG(INFO, "VF %u reset occurred", abs_vf_id);
6190 * Only notify a VF reset event occurred,
6191 * don't trigger another SW reset
6193 ret = i40e_pf_host_vf_reset(&pf->vfs[i], 0);
6194 if (ret != I40E_SUCCESS)
6195 PMD_DRV_LOG(ERR, "Failed to do VF reset");
6201 i40e_notify_all_vfs_link_status(struct rte_eth_dev *dev)
6203 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6206 for (i = 0; i < pf->vf_num; i++)
6207 i40e_notify_vf_link_status(dev, &pf->vfs[i]);
6211 i40e_dev_handle_aq_msg(struct rte_eth_dev *dev)
6213 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6214 struct i40e_arq_event_info info;
6215 uint16_t pending, opcode;
6218 info.buf_len = I40E_AQ_BUF_SZ;
6219 info.msg_buf = rte_zmalloc("msg_buffer", info.buf_len, 0);
6220 if (!info.msg_buf) {
6221 PMD_DRV_LOG(ERR, "Failed to allocate mem");
6227 ret = i40e_clean_arq_element(hw, &info, &pending);
6229 if (ret != I40E_SUCCESS) {
6231 "Failed to read msg from AdminQ, aq_err: %u",
6232 hw->aq.asq_last_status);
6235 opcode = rte_le_to_cpu_16(info.desc.opcode);
6238 case i40e_aqc_opc_send_msg_to_pf:
6239 /* Refer to i40e_aq_send_msg_to_pf() for argument layout*/
6240 i40e_pf_host_handle_vf_msg(dev,
6241 rte_le_to_cpu_16(info.desc.retval),
6242 rte_le_to_cpu_32(info.desc.cookie_high),
6243 rte_le_to_cpu_32(info.desc.cookie_low),
6247 case i40e_aqc_opc_get_link_status:
6248 ret = i40e_dev_link_update(dev, 0);
6250 _rte_eth_dev_callback_process(dev,
6251 RTE_ETH_EVENT_INTR_LSC, NULL);
6254 PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
6259 rte_free(info.msg_buf);
6263 * Interrupt handler triggered by NIC for handling
6264 * specific interrupt.
6267 * Pointer to interrupt handle.
6269 * The address of parameter (struct rte_eth_dev *) regsitered before.
6275 i40e_dev_interrupt_handler(void *param)
6277 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
6278 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6281 /* Disable interrupt */
6282 i40e_pf_disable_irq0(hw);
6284 /* read out interrupt causes */
6285 icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
6287 /* No interrupt event indicated */
6288 if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK)) {
6289 PMD_DRV_LOG(INFO, "No interrupt event");
6292 if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
6293 PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
6294 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK)
6295 PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
6296 if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
6297 PMD_DRV_LOG(INFO, "ICR0: global reset requested");
6298 if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
6299 PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
6300 if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
6301 PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
6302 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
6303 PMD_DRV_LOG(ERR, "ICR0: HMC error");
6304 if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
6305 PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
6307 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
6308 PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
6309 i40e_dev_handle_vfr_event(dev);
6311 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
6312 PMD_DRV_LOG(INFO, "ICR0: adminq event");
6313 i40e_dev_handle_aq_msg(dev);
6317 /* Enable interrupt */
6318 i40e_pf_enable_irq0(hw);
6319 rte_intr_enable(dev->intr_handle);
6323 i40e_add_macvlan_filters(struct i40e_vsi *vsi,
6324 struct i40e_macvlan_filter *filter,
6327 int ele_num, ele_buff_size;
6328 int num, actual_num, i;
6330 int ret = I40E_SUCCESS;
6331 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6332 struct i40e_aqc_add_macvlan_element_data *req_list;
6334 if (filter == NULL || total == 0)
6335 return I40E_ERR_PARAM;
6336 ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
6337 ele_buff_size = hw->aq.asq_buf_size;
6339 req_list = rte_zmalloc("macvlan_add", ele_buff_size, 0);
6340 if (req_list == NULL) {
6341 PMD_DRV_LOG(ERR, "Fail to allocate memory");
6342 return I40E_ERR_NO_MEMORY;
6347 actual_num = (num + ele_num > total) ? (total - num) : ele_num;
6348 memset(req_list, 0, ele_buff_size);
6350 for (i = 0; i < actual_num; i++) {
6351 rte_memcpy(req_list[i].mac_addr,
6352 &filter[num + i].macaddr, ETH_ADDR_LEN);
6353 req_list[i].vlan_tag =
6354 rte_cpu_to_le_16(filter[num + i].vlan_id);
6356 switch (filter[num + i].filter_type) {
6357 case RTE_MAC_PERFECT_MATCH:
6358 flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH |
6359 I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
6361 case RTE_MACVLAN_PERFECT_MATCH:
6362 flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
6364 case RTE_MAC_HASH_MATCH:
6365 flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH |
6366 I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
6368 case RTE_MACVLAN_HASH_MATCH:
6369 flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH;
6372 PMD_DRV_LOG(ERR, "Invalid MAC match type");
6373 ret = I40E_ERR_PARAM;
6377 req_list[i].queue_number = 0;
6379 req_list[i].flags = rte_cpu_to_le_16(flags);
6382 ret = i40e_aq_add_macvlan(hw, vsi->seid, req_list,
6384 if (ret != I40E_SUCCESS) {
6385 PMD_DRV_LOG(ERR, "Failed to add macvlan filter");
6389 } while (num < total);
6397 i40e_remove_macvlan_filters(struct i40e_vsi *vsi,
6398 struct i40e_macvlan_filter *filter,
6401 int ele_num, ele_buff_size;
6402 int num, actual_num, i;
6404 int ret = I40E_SUCCESS;
6405 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6406 struct i40e_aqc_remove_macvlan_element_data *req_list;
6408 if (filter == NULL || total == 0)
6409 return I40E_ERR_PARAM;
6411 ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
6412 ele_buff_size = hw->aq.asq_buf_size;
6414 req_list = rte_zmalloc("macvlan_remove", ele_buff_size, 0);
6415 if (req_list == NULL) {
6416 PMD_DRV_LOG(ERR, "Fail to allocate memory");
6417 return I40E_ERR_NO_MEMORY;
6422 actual_num = (num + ele_num > total) ? (total - num) : ele_num;
6423 memset(req_list, 0, ele_buff_size);
6425 for (i = 0; i < actual_num; i++) {
6426 rte_memcpy(req_list[i].mac_addr,
6427 &filter[num + i].macaddr, ETH_ADDR_LEN);
6428 req_list[i].vlan_tag =
6429 rte_cpu_to_le_16(filter[num + i].vlan_id);
6431 switch (filter[num + i].filter_type) {
6432 case RTE_MAC_PERFECT_MATCH:
6433 flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
6434 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
6436 case RTE_MACVLAN_PERFECT_MATCH:
6437 flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
6439 case RTE_MAC_HASH_MATCH:
6440 flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH |
6441 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
6443 case RTE_MACVLAN_HASH_MATCH:
6444 flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH;
6447 PMD_DRV_LOG(ERR, "Invalid MAC filter type");
6448 ret = I40E_ERR_PARAM;
6451 req_list[i].flags = rte_cpu_to_le_16(flags);
6454 ret = i40e_aq_remove_macvlan(hw, vsi->seid, req_list,
6456 if (ret != I40E_SUCCESS) {
6457 PMD_DRV_LOG(ERR, "Failed to remove macvlan filter");
6461 } while (num < total);
6468 /* Find out specific MAC filter */
6469 static struct i40e_mac_filter *
6470 i40e_find_mac_filter(struct i40e_vsi *vsi,
6471 struct ether_addr *macaddr)
6473 struct i40e_mac_filter *f;
6475 TAILQ_FOREACH(f, &vsi->mac_list, next) {
6476 if (is_same_ether_addr(macaddr, &f->mac_info.mac_addr))
6484 i40e_find_vlan_filter(struct i40e_vsi *vsi,
6487 uint32_t vid_idx, vid_bit;
6489 if (vlan_id > ETH_VLAN_ID_MAX)
6492 vid_idx = I40E_VFTA_IDX(vlan_id);
6493 vid_bit = I40E_VFTA_BIT(vlan_id);
6495 if (vsi->vfta[vid_idx] & vid_bit)
6502 i40e_store_vlan_filter(struct i40e_vsi *vsi,
6503 uint16_t vlan_id, bool on)
6505 uint32_t vid_idx, vid_bit;
6507 vid_idx = I40E_VFTA_IDX(vlan_id);
6508 vid_bit = I40E_VFTA_BIT(vlan_id);
6511 vsi->vfta[vid_idx] |= vid_bit;
6513 vsi->vfta[vid_idx] &= ~vid_bit;
6517 i40e_set_vlan_filter(struct i40e_vsi *vsi,
6518 uint16_t vlan_id, bool on)
6520 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6521 struct i40e_aqc_add_remove_vlan_element_data vlan_data = {0};
6524 if (vlan_id > ETH_VLAN_ID_MAX)
6527 i40e_store_vlan_filter(vsi, vlan_id, on);
6529 if ((!vsi->vlan_anti_spoof_on && !vsi->vlan_filter_on) || !vlan_id)
6532 vlan_data.vlan_tag = rte_cpu_to_le_16(vlan_id);
6535 ret = i40e_aq_add_vlan(hw, vsi->seid,
6536 &vlan_data, 1, NULL);
6537 if (ret != I40E_SUCCESS)
6538 PMD_DRV_LOG(ERR, "Failed to add vlan filter");
6540 ret = i40e_aq_remove_vlan(hw, vsi->seid,
6541 &vlan_data, 1, NULL);
6542 if (ret != I40E_SUCCESS)
6544 "Failed to remove vlan filter");
6549 * Find all vlan options for specific mac addr,
6550 * return with actual vlan found.
6553 i40e_find_all_vlan_for_mac(struct i40e_vsi *vsi,
6554 struct i40e_macvlan_filter *mv_f,
6555 int num, struct ether_addr *addr)
6561 * Not to use i40e_find_vlan_filter to decrease the loop time,
6562 * although the code looks complex.
6564 if (num < vsi->vlan_num)
6565 return I40E_ERR_PARAM;
6568 for (j = 0; j < I40E_VFTA_SIZE; j++) {
6570 for (k = 0; k < I40E_UINT32_BIT_SIZE; k++) {
6571 if (vsi->vfta[j] & (1 << k)) {
6574 "vlan number doesn't match");
6575 return I40E_ERR_PARAM;
6577 rte_memcpy(&mv_f[i].macaddr,
6578 addr, ETH_ADDR_LEN);
6580 j * I40E_UINT32_BIT_SIZE + k;
6586 return I40E_SUCCESS;
6590 i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
6591 struct i40e_macvlan_filter *mv_f,
6596 struct i40e_mac_filter *f;
6598 if (num < vsi->mac_num)
6599 return I40E_ERR_PARAM;
6601 TAILQ_FOREACH(f, &vsi->mac_list, next) {
6603 PMD_DRV_LOG(ERR, "buffer number not match");
6604 return I40E_ERR_PARAM;
6606 rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
6608 mv_f[i].vlan_id = vlan;
6609 mv_f[i].filter_type = f->mac_info.filter_type;
6613 return I40E_SUCCESS;
6617 i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi)
6620 struct i40e_mac_filter *f;
6621 struct i40e_macvlan_filter *mv_f;
6622 int ret = I40E_SUCCESS;
6624 if (vsi == NULL || vsi->mac_num == 0)
6625 return I40E_ERR_PARAM;
6627 /* Case that no vlan is set */
6628 if (vsi->vlan_num == 0)
6631 num = vsi->mac_num * vsi->vlan_num;
6633 mv_f = rte_zmalloc("macvlan_data", num * sizeof(*mv_f), 0);
6635 PMD_DRV_LOG(ERR, "failed to allocate memory");
6636 return I40E_ERR_NO_MEMORY;
6640 if (vsi->vlan_num == 0) {
6641 TAILQ_FOREACH(f, &vsi->mac_list, next) {
6642 rte_memcpy(&mv_f[i].macaddr,
6643 &f->mac_info.mac_addr, ETH_ADDR_LEN);
6644 mv_f[i].filter_type = f->mac_info.filter_type;
6645 mv_f[i].vlan_id = 0;
6649 TAILQ_FOREACH(f, &vsi->mac_list, next) {
6650 ret = i40e_find_all_vlan_for_mac(vsi,&mv_f[i],
6651 vsi->vlan_num, &f->mac_info.mac_addr);
6652 if (ret != I40E_SUCCESS)
6654 for (j = i; j < i + vsi->vlan_num; j++)
6655 mv_f[j].filter_type = f->mac_info.filter_type;
6660 ret = i40e_remove_macvlan_filters(vsi, mv_f, num);
6668 i40e_vsi_add_vlan(struct i40e_vsi *vsi, uint16_t vlan)
6670 struct i40e_macvlan_filter *mv_f;
6672 int ret = I40E_SUCCESS;
6674 if (!vsi || vlan > ETHER_MAX_VLAN_ID)
6675 return I40E_ERR_PARAM;
6677 /* If it's already set, just return */
6678 if (i40e_find_vlan_filter(vsi,vlan))
6679 return I40E_SUCCESS;
6681 mac_num = vsi->mac_num;
6684 PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
6685 return I40E_ERR_PARAM;
6688 mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
6691 PMD_DRV_LOG(ERR, "failed to allocate memory");
6692 return I40E_ERR_NO_MEMORY;
6695 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
6697 if (ret != I40E_SUCCESS)
6700 ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
6702 if (ret != I40E_SUCCESS)
6705 i40e_set_vlan_filter(vsi, vlan, 1);
6715 i40e_vsi_delete_vlan(struct i40e_vsi *vsi, uint16_t vlan)
6717 struct i40e_macvlan_filter *mv_f;
6719 int ret = I40E_SUCCESS;
6722 * Vlan 0 is the generic filter for untagged packets
6723 * and can't be removed.
6725 if (!vsi || vlan == 0 || vlan > ETHER_MAX_VLAN_ID)
6726 return I40E_ERR_PARAM;
6728 /* If can't find it, just return */
6729 if (!i40e_find_vlan_filter(vsi, vlan))
6730 return I40E_ERR_PARAM;
6732 mac_num = vsi->mac_num;
6735 PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
6736 return I40E_ERR_PARAM;
6739 mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
6742 PMD_DRV_LOG(ERR, "failed to allocate memory");
6743 return I40E_ERR_NO_MEMORY;
6746 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
6748 if (ret != I40E_SUCCESS)
6751 ret = i40e_remove_macvlan_filters(vsi, mv_f, mac_num);
6753 if (ret != I40E_SUCCESS)
6756 /* This is last vlan to remove, replace all mac filter with vlan 0 */
6757 if (vsi->vlan_num == 1) {
6758 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, 0);
6759 if (ret != I40E_SUCCESS)
6762 ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
6763 if (ret != I40E_SUCCESS)
6767 i40e_set_vlan_filter(vsi, vlan, 0);
6777 i40e_vsi_add_mac(struct i40e_vsi *vsi, struct i40e_mac_filter_info *mac_filter)
6779 struct i40e_mac_filter *f;
6780 struct i40e_macvlan_filter *mv_f;
6781 int i, vlan_num = 0;
6782 int ret = I40E_SUCCESS;
6784 /* If it's add and we've config it, return */
6785 f = i40e_find_mac_filter(vsi, &mac_filter->mac_addr);
6787 return I40E_SUCCESS;
6788 if ((mac_filter->filter_type == RTE_MACVLAN_PERFECT_MATCH) ||
6789 (mac_filter->filter_type == RTE_MACVLAN_HASH_MATCH)) {
6792 * If vlan_num is 0, that's the first time to add mac,
6793 * set mask for vlan_id 0.
6795 if (vsi->vlan_num == 0) {
6796 i40e_set_vlan_filter(vsi, 0, 1);
6799 vlan_num = vsi->vlan_num;
6800 } else if ((mac_filter->filter_type == RTE_MAC_PERFECT_MATCH) ||
6801 (mac_filter->filter_type == RTE_MAC_HASH_MATCH))
6804 mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
6806 PMD_DRV_LOG(ERR, "failed to allocate memory");
6807 return I40E_ERR_NO_MEMORY;
6810 for (i = 0; i < vlan_num; i++) {
6811 mv_f[i].filter_type = mac_filter->filter_type;
6812 rte_memcpy(&mv_f[i].macaddr, &mac_filter->mac_addr,
6816 if (mac_filter->filter_type == RTE_MACVLAN_PERFECT_MATCH ||
6817 mac_filter->filter_type == RTE_MACVLAN_HASH_MATCH) {
6818 ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
6819 &mac_filter->mac_addr);
6820 if (ret != I40E_SUCCESS)
6824 ret = i40e_add_macvlan_filters(vsi, mv_f, vlan_num);
6825 if (ret != I40E_SUCCESS)
6828 /* Add the mac addr into mac list */
6829 f = rte_zmalloc("macv_filter", sizeof(*f), 0);
6831 PMD_DRV_LOG(ERR, "failed to allocate memory");
6832 ret = I40E_ERR_NO_MEMORY;
6835 rte_memcpy(&f->mac_info.mac_addr, &mac_filter->mac_addr,
6837 f->mac_info.filter_type = mac_filter->filter_type;
6838 TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
6849 i40e_vsi_delete_mac(struct i40e_vsi *vsi, struct ether_addr *addr)
6851 struct i40e_mac_filter *f;
6852 struct i40e_macvlan_filter *mv_f;
6854 enum rte_mac_filter_type filter_type;
6855 int ret = I40E_SUCCESS;
6857 /* Can't find it, return an error */
6858 f = i40e_find_mac_filter(vsi, addr);
6860 return I40E_ERR_PARAM;
6862 vlan_num = vsi->vlan_num;
6863 filter_type = f->mac_info.filter_type;
6864 if (filter_type == RTE_MACVLAN_PERFECT_MATCH ||
6865 filter_type == RTE_MACVLAN_HASH_MATCH) {
6866 if (vlan_num == 0) {
6867 PMD_DRV_LOG(ERR, "VLAN number shouldn't be 0");
6868 return I40E_ERR_PARAM;
6870 } else if (filter_type == RTE_MAC_PERFECT_MATCH ||
6871 filter_type == RTE_MAC_HASH_MATCH)
6874 mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
6876 PMD_DRV_LOG(ERR, "failed to allocate memory");
6877 return I40E_ERR_NO_MEMORY;
6880 for (i = 0; i < vlan_num; i++) {
6881 mv_f[i].filter_type = filter_type;
6882 rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
6885 if (filter_type == RTE_MACVLAN_PERFECT_MATCH ||
6886 filter_type == RTE_MACVLAN_HASH_MATCH) {
6887 ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num, addr);
6888 if (ret != I40E_SUCCESS)
6892 ret = i40e_remove_macvlan_filters(vsi, mv_f, vlan_num);
6893 if (ret != I40E_SUCCESS)
6896 /* Remove the mac addr into mac list */
6897 TAILQ_REMOVE(&vsi->mac_list, f, next);
6907 /* Configure hash enable flags for RSS */
6909 i40e_config_hena(const struct i40e_adapter *adapter, uint64_t flags)
6917 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < I40E_FLOW_TYPE_MAX; i++) {
6918 if (flags & (1ULL << i))
6919 hena |= adapter->pctypes_tbl[i];
6925 /* Parse the hash enable flags */
6927 i40e_parse_hena(const struct i40e_adapter *adapter, uint64_t flags)
6929 uint64_t rss_hf = 0;
6935 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < I40E_FLOW_TYPE_MAX; i++) {
6936 if (flags & adapter->pctypes_tbl[i])
6937 rss_hf |= (1ULL << i);
6944 i40e_pf_disable_rss(struct i40e_pf *pf)
6946 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6948 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
6949 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
6950 I40E_WRITE_FLUSH(hw);
6954 i40e_set_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t key_len)
6956 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
6957 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6958 uint16_t key_idx = (vsi->type == I40E_VSI_SRIOV) ?
6959 I40E_VFQF_HKEY_MAX_INDEX :
6960 I40E_PFQF_HKEY_MAX_INDEX;
6963 if (!key || key_len == 0) {
6964 PMD_DRV_LOG(DEBUG, "No key to be configured");
6966 } else if (key_len != (key_idx + 1) *
6968 PMD_DRV_LOG(ERR, "Invalid key length %u", key_len);
6972 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
6973 struct i40e_aqc_get_set_rss_key_data *key_dw =
6974 (struct i40e_aqc_get_set_rss_key_data *)key;
6976 ret = i40e_aq_set_rss_key(hw, vsi->vsi_id, key_dw);
6978 PMD_INIT_LOG(ERR, "Failed to configure RSS key via AQ");
6980 uint32_t *hash_key = (uint32_t *)key;
6983 if (vsi->type == I40E_VSI_SRIOV) {
6984 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
6987 I40E_VFQF_HKEY1(i, vsi->user_param),
6991 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
6992 I40E_WRITE_REG(hw, I40E_PFQF_HKEY(i),
6995 I40E_WRITE_FLUSH(hw);
7002 i40e_get_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t *key_len)
7004 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
7005 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7009 if (!key || !key_len)
7012 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
7013 ret = i40e_aq_get_rss_key(hw, vsi->vsi_id,
7014 (struct i40e_aqc_get_set_rss_key_data *)key);
7016 PMD_INIT_LOG(ERR, "Failed to get RSS key via AQ");
7020 uint32_t *key_dw = (uint32_t *)key;
7023 if (vsi->type == I40E_VSI_SRIOV) {
7024 for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++) {
7025 reg = I40E_VFQF_HKEY1(i, vsi->user_param);
7026 key_dw[i] = i40e_read_rx_ctl(hw, reg);
7028 *key_len = (I40E_VFQF_HKEY_MAX_INDEX + 1) *
7031 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
7032 reg = I40E_PFQF_HKEY(i);
7033 key_dw[i] = i40e_read_rx_ctl(hw, reg);
7035 *key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
7043 i40e_hw_rss_hash_set(struct i40e_pf *pf, struct rte_eth_rss_conf *rss_conf)
7045 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7049 ret = i40e_set_rss_key(pf->main_vsi, rss_conf->rss_key,
7050 rss_conf->rss_key_len);
7054 hena = i40e_config_hena(pf->adapter, rss_conf->rss_hf);
7055 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
7056 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
7057 I40E_WRITE_FLUSH(hw);
7063 i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
7064 struct rte_eth_rss_conf *rss_conf)
7066 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7067 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7068 uint64_t rss_hf = rss_conf->rss_hf & pf->adapter->flow_types_mask;
7071 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
7072 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
7074 if (!(hena & pf->adapter->pctypes_mask)) { /* RSS disabled */
7075 if (rss_hf != 0) /* Enable RSS */
7077 return 0; /* Nothing to do */
7080 if (rss_hf == 0) /* Disable RSS */
7083 return i40e_hw_rss_hash_set(pf, rss_conf);
7087 i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
7088 struct rte_eth_rss_conf *rss_conf)
7090 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7091 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7094 i40e_get_rss_key(pf->main_vsi, rss_conf->rss_key,
7095 &rss_conf->rss_key_len);
7097 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
7098 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
7099 rss_conf->rss_hf = i40e_parse_hena(pf->adapter, hena);
7105 i40e_dev_get_filter_type(uint16_t filter_type, uint16_t *flag)
7107 switch (filter_type) {
7108 case RTE_TUNNEL_FILTER_IMAC_IVLAN:
7109 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
7111 case RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID:
7112 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
7114 case RTE_TUNNEL_FILTER_IMAC_TENID:
7115 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID;
7117 case RTE_TUNNEL_FILTER_OMAC_TENID_IMAC:
7118 *flag = I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC;
7120 case ETH_TUNNEL_FILTER_IMAC:
7121 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
7123 case ETH_TUNNEL_FILTER_OIP:
7124 *flag = I40E_AQC_ADD_CLOUD_FILTER_OIP;
7126 case ETH_TUNNEL_FILTER_IIP:
7127 *flag = I40E_AQC_ADD_CLOUD_FILTER_IIP;
7130 PMD_DRV_LOG(ERR, "invalid tunnel filter type");
7137 /* Convert tunnel filter structure */
7139 i40e_tunnel_filter_convert(
7140 struct i40e_aqc_add_rm_cloud_filt_elem_ext *cld_filter,
7141 struct i40e_tunnel_filter *tunnel_filter)
7143 ether_addr_copy((struct ether_addr *)&cld_filter->element.outer_mac,
7144 (struct ether_addr *)&tunnel_filter->input.outer_mac);
7145 ether_addr_copy((struct ether_addr *)&cld_filter->element.inner_mac,
7146 (struct ether_addr *)&tunnel_filter->input.inner_mac);
7147 tunnel_filter->input.inner_vlan = cld_filter->element.inner_vlan;
7148 if ((rte_le_to_cpu_16(cld_filter->element.flags) &
7149 I40E_AQC_ADD_CLOUD_FLAGS_IPV6) ==
7150 I40E_AQC_ADD_CLOUD_FLAGS_IPV6)
7151 tunnel_filter->input.ip_type = I40E_TUNNEL_IPTYPE_IPV6;
7153 tunnel_filter->input.ip_type = I40E_TUNNEL_IPTYPE_IPV4;
7154 tunnel_filter->input.flags = cld_filter->element.flags;
7155 tunnel_filter->input.tenant_id = cld_filter->element.tenant_id;
7156 tunnel_filter->queue = cld_filter->element.queue_number;
7157 rte_memcpy(tunnel_filter->input.general_fields,
7158 cld_filter->general_fields,
7159 sizeof(cld_filter->general_fields));
7164 /* Check if there exists the tunnel filter */
7165 struct i40e_tunnel_filter *
7166 i40e_sw_tunnel_filter_lookup(struct i40e_tunnel_rule *tunnel_rule,
7167 const struct i40e_tunnel_filter_input *input)
7171 ret = rte_hash_lookup(tunnel_rule->hash_table, (const void *)input);
7175 return tunnel_rule->hash_map[ret];
7178 /* Add a tunnel filter into the SW list */
7180 i40e_sw_tunnel_filter_insert(struct i40e_pf *pf,
7181 struct i40e_tunnel_filter *tunnel_filter)
7183 struct i40e_tunnel_rule *rule = &pf->tunnel;
7186 ret = rte_hash_add_key(rule->hash_table, &tunnel_filter->input);
7189 "Failed to insert tunnel filter to hash table %d!",
7193 rule->hash_map[ret] = tunnel_filter;
7195 TAILQ_INSERT_TAIL(&rule->tunnel_list, tunnel_filter, rules);
7200 /* Delete a tunnel filter from the SW list */
7202 i40e_sw_tunnel_filter_del(struct i40e_pf *pf,
7203 struct i40e_tunnel_filter_input *input)
7205 struct i40e_tunnel_rule *rule = &pf->tunnel;
7206 struct i40e_tunnel_filter *tunnel_filter;
7209 ret = rte_hash_del_key(rule->hash_table, input);
7212 "Failed to delete tunnel filter to hash table %d!",
7216 tunnel_filter = rule->hash_map[ret];
7217 rule->hash_map[ret] = NULL;
7219 TAILQ_REMOVE(&rule->tunnel_list, tunnel_filter, rules);
7220 rte_free(tunnel_filter);
7226 i40e_dev_tunnel_filter_set(struct i40e_pf *pf,
7227 struct rte_eth_tunnel_filter_conf *tunnel_filter,
7231 uint32_t ipv4_addr, ipv4_addr_le;
7232 uint8_t i, tun_type = 0;
7233 /* internal varialbe to convert ipv6 byte order */
7234 uint32_t convert_ipv6[4];
7236 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7237 struct i40e_vsi *vsi = pf->main_vsi;
7238 struct i40e_aqc_add_rm_cloud_filt_elem_ext *cld_filter;
7239 struct i40e_aqc_add_rm_cloud_filt_elem_ext *pfilter;
7240 struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
7241 struct i40e_tunnel_filter *tunnel, *node;
7242 struct i40e_tunnel_filter check_filter; /* Check if filter exists */
7244 cld_filter = rte_zmalloc("tunnel_filter",
7245 sizeof(struct i40e_aqc_add_rm_cloud_filt_elem_ext),
7248 if (NULL == cld_filter) {
7249 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
7252 pfilter = cld_filter;
7254 ether_addr_copy(&tunnel_filter->outer_mac,
7255 (struct ether_addr *)&pfilter->element.outer_mac);
7256 ether_addr_copy(&tunnel_filter->inner_mac,
7257 (struct ether_addr *)&pfilter->element.inner_mac);
7259 pfilter->element.inner_vlan =
7260 rte_cpu_to_le_16(tunnel_filter->inner_vlan);
7261 if (tunnel_filter->ip_type == RTE_TUNNEL_IPTYPE_IPV4) {
7262 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV4;
7263 ipv4_addr = rte_be_to_cpu_32(tunnel_filter->ip_addr.ipv4_addr);
7264 ipv4_addr_le = rte_cpu_to_le_32(ipv4_addr);
7265 rte_memcpy(&pfilter->element.ipaddr.v4.data,
7267 sizeof(pfilter->element.ipaddr.v4.data));
7269 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV6;
7270 for (i = 0; i < 4; i++) {
7272 rte_cpu_to_le_32(rte_be_to_cpu_32(tunnel_filter->ip_addr.ipv6_addr[i]));
7274 rte_memcpy(&pfilter->element.ipaddr.v6.data,
7276 sizeof(pfilter->element.ipaddr.v6.data));
7279 /* check tunneled type */
7280 switch (tunnel_filter->tunnel_type) {
7281 case RTE_TUNNEL_TYPE_VXLAN:
7282 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_VXLAN;
7284 case RTE_TUNNEL_TYPE_NVGRE:
7285 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_NVGRE_OMAC;
7287 case RTE_TUNNEL_TYPE_IP_IN_GRE:
7288 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_IP;
7291 /* Other tunnel types is not supported. */
7292 PMD_DRV_LOG(ERR, "tunnel type is not supported.");
7293 rte_free(cld_filter);
7297 val = i40e_dev_get_filter_type(tunnel_filter->filter_type,
7298 &pfilter->element.flags);
7300 rte_free(cld_filter);
7304 pfilter->element.flags |= rte_cpu_to_le_16(
7305 I40E_AQC_ADD_CLOUD_FLAGS_TO_QUEUE |
7306 ip_type | (tun_type << I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT));
7307 pfilter->element.tenant_id = rte_cpu_to_le_32(tunnel_filter->tenant_id);
7308 pfilter->element.queue_number =
7309 rte_cpu_to_le_16(tunnel_filter->queue_id);
7311 /* Check if there is the filter in SW list */
7312 memset(&check_filter, 0, sizeof(check_filter));
7313 i40e_tunnel_filter_convert(cld_filter, &check_filter);
7314 node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
7316 PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
7317 rte_free(cld_filter);
7321 if (!add && !node) {
7322 PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
7323 rte_free(cld_filter);
7328 ret = i40e_aq_add_cloud_filters(hw,
7329 vsi->seid, &cld_filter->element, 1);
7331 PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
7332 rte_free(cld_filter);
7335 tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
7336 if (tunnel == NULL) {
7337 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
7338 rte_free(cld_filter);
7342 rte_memcpy(tunnel, &check_filter, sizeof(check_filter));
7343 ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
7347 ret = i40e_aq_remove_cloud_filters(hw, vsi->seid,
7348 &cld_filter->element, 1);
7350 PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
7351 rte_free(cld_filter);
7354 ret = i40e_sw_tunnel_filter_del(pf, &node->input);
7357 rte_free(cld_filter);
7361 #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_TR_WORD0 0x48
7362 #define I40E_TR_VXLAN_GRE_KEY_MASK 0x4
7363 #define I40E_TR_GENEVE_KEY_MASK 0x8
7364 #define I40E_TR_GENERIC_UDP_TUNNEL_MASK 0x40
7365 #define I40E_TR_GRE_KEY_MASK 0x400
7366 #define I40E_TR_GRE_KEY_WITH_XSUM_MASK 0x800
7367 #define I40E_TR_GRE_NO_KEY_MASK 0x8000
7370 i40e_status_code i40e_replace_mpls_l1_filter(struct i40e_pf *pf)
7372 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
7373 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
7374 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7375 enum i40e_status_code status = I40E_SUCCESS;
7377 if (pf->support_multi_driver) {
7378 PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
7379 return I40E_NOT_SUPPORTED;
7382 memset(&filter_replace, 0,
7383 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
7384 memset(&filter_replace_buf, 0,
7385 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
7387 /* create L1 filter */
7388 filter_replace.old_filter_type =
7389 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_IMAC;
7390 filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X11;
7391 filter_replace.tr_bit = 0;
7393 /* Prepare the buffer, 3 entries */
7394 filter_replace_buf.data[0] =
7395 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
7396 filter_replace_buf.data[0] |=
7397 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7398 filter_replace_buf.data[2] = 0xFF;
7399 filter_replace_buf.data[3] = 0xFF;
7400 filter_replace_buf.data[4] =
7401 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
7402 filter_replace_buf.data[4] |=
7403 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7404 filter_replace_buf.data[7] = 0xF0;
7405 filter_replace_buf.data[8]
7406 = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_TR_WORD0;
7407 filter_replace_buf.data[8] |=
7408 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7409 filter_replace_buf.data[10] = I40E_TR_VXLAN_GRE_KEY_MASK |
7410 I40E_TR_GENEVE_KEY_MASK |
7411 I40E_TR_GENERIC_UDP_TUNNEL_MASK;
7412 filter_replace_buf.data[11] = (I40E_TR_GRE_KEY_MASK |
7413 I40E_TR_GRE_KEY_WITH_XSUM_MASK |
7414 I40E_TR_GRE_NO_KEY_MASK) >> 8;
7416 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
7417 &filter_replace_buf);
7419 i40e_global_cfg_warning(I40E_WARNING_RPL_CLD_FILTER);
7420 PMD_DRV_LOG(DEBUG, "Global configuration modification: "
7421 "cloud l1 type is changed from 0x%x to 0x%x",
7422 filter_replace.old_filter_type,
7423 filter_replace.new_filter_type);
7429 i40e_status_code i40e_replace_mpls_cloud_filter(struct i40e_pf *pf)
7431 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
7432 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
7433 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7434 enum i40e_status_code status = I40E_SUCCESS;
7436 if (pf->support_multi_driver) {
7437 PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
7438 return I40E_NOT_SUPPORTED;
7442 memset(&filter_replace, 0,
7443 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
7444 memset(&filter_replace_buf, 0,
7445 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
7446 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER |
7447 I40E_AQC_MIRROR_CLOUD_FILTER;
7448 filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IIP;
7449 filter_replace.new_filter_type =
7450 I40E_AQC_ADD_CLOUD_FILTER_0X11;
7451 /* Prepare the buffer, 2 entries */
7452 filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
7453 filter_replace_buf.data[0] |=
7454 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7455 filter_replace_buf.data[4] = I40E_AQC_ADD_L1_FILTER_0X11;
7456 filter_replace_buf.data[4] |=
7457 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7458 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
7459 &filter_replace_buf);
7462 PMD_DRV_LOG(DEBUG, "Global configuration modification: "
7463 "cloud filter type is changed from 0x%x to 0x%x",
7464 filter_replace.old_filter_type,
7465 filter_replace.new_filter_type);
7468 memset(&filter_replace, 0,
7469 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
7470 memset(&filter_replace_buf, 0,
7471 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
7473 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER |
7474 I40E_AQC_MIRROR_CLOUD_FILTER;
7475 filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
7476 filter_replace.new_filter_type =
7477 I40E_AQC_ADD_CLOUD_FILTER_0X12;
7478 /* Prepare the buffer, 2 entries */
7479 filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
7480 filter_replace_buf.data[0] |=
7481 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7482 filter_replace_buf.data[4] = I40E_AQC_ADD_L1_FILTER_0X11;
7483 filter_replace_buf.data[4] |=
7484 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7486 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
7487 &filter_replace_buf);
7489 i40e_global_cfg_warning(I40E_WARNING_RPL_CLD_FILTER);
7490 PMD_DRV_LOG(DEBUG, "Global configuration modification: "
7491 "cloud filter type is changed from 0x%x to 0x%x",
7492 filter_replace.old_filter_type,
7493 filter_replace.new_filter_type);
7498 static enum i40e_status_code
7499 i40e_replace_gtp_l1_filter(struct i40e_pf *pf)
7501 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
7502 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
7503 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7504 enum i40e_status_code status = I40E_SUCCESS;
7506 if (pf->support_multi_driver) {
7507 PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
7508 return I40E_NOT_SUPPORTED;
7512 memset(&filter_replace, 0,
7513 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
7514 memset(&filter_replace_buf, 0,
7515 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
7516 /* create L1 filter */
7517 filter_replace.old_filter_type =
7518 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_IMAC;
7519 filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X12;
7520 filter_replace.tr_bit = I40E_AQC_NEW_TR_22 |
7521 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7522 /* Prepare the buffer, 2 entries */
7523 filter_replace_buf.data[0] =
7524 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
7525 filter_replace_buf.data[0] |=
7526 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7527 filter_replace_buf.data[2] = 0xFF;
7528 filter_replace_buf.data[3] = 0xFF;
7529 filter_replace_buf.data[4] =
7530 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
7531 filter_replace_buf.data[4] |=
7532 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7533 filter_replace_buf.data[6] = 0xFF;
7534 filter_replace_buf.data[7] = 0xFF;
7535 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
7536 &filter_replace_buf);
7539 PMD_DRV_LOG(DEBUG, "Global configuration modification: "
7540 "cloud l1 type is changed from 0x%x to 0x%x",
7541 filter_replace.old_filter_type,
7542 filter_replace.new_filter_type);
7545 memset(&filter_replace, 0,
7546 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
7547 memset(&filter_replace_buf, 0,
7548 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
7549 /* create L1 filter */
7550 filter_replace.old_filter_type =
7551 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TUNNLE_KEY;
7552 filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X13;
7553 filter_replace.tr_bit = I40E_AQC_NEW_TR_21 |
7554 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7555 /* Prepare the buffer, 2 entries */
7556 filter_replace_buf.data[0] =
7557 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
7558 filter_replace_buf.data[0] |=
7559 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7560 filter_replace_buf.data[2] = 0xFF;
7561 filter_replace_buf.data[3] = 0xFF;
7562 filter_replace_buf.data[4] =
7563 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
7564 filter_replace_buf.data[4] |=
7565 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7566 filter_replace_buf.data[6] = 0xFF;
7567 filter_replace_buf.data[7] = 0xFF;
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 l1 type is changed from 0x%x to 0x%x",
7575 filter_replace.old_filter_type,
7576 filter_replace.new_filter_type);
7582 i40e_status_code i40e_replace_gtp_cloud_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 cloud 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 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
7600 filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
7601 filter_replace.new_filter_type =
7602 I40E_AQC_ADD_CLOUD_FILTER_0X11;
7603 /* Prepare the buffer, 2 entries */
7604 filter_replace_buf.data[0] = I40E_AQC_ADD_L1_FILTER_0X12;
7605 filter_replace_buf.data[0] |=
7606 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7607 filter_replace_buf.data[4] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
7608 filter_replace_buf.data[4] |=
7609 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7610 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
7611 &filter_replace_buf);
7614 PMD_DRV_LOG(DEBUG, "Global configuration modification: "
7615 "cloud filter type is changed from 0x%x to 0x%x",
7616 filter_replace.old_filter_type,
7617 filter_replace.new_filter_type);
7620 memset(&filter_replace, 0,
7621 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
7622 memset(&filter_replace_buf, 0,
7623 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
7624 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
7625 filter_replace.old_filter_type =
7626 I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
7627 filter_replace.new_filter_type =
7628 I40E_AQC_ADD_CLOUD_FILTER_0X12;
7629 /* Prepare the buffer, 2 entries */
7630 filter_replace_buf.data[0] = I40E_AQC_ADD_L1_FILTER_0X13;
7631 filter_replace_buf.data[0] |=
7632 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7633 filter_replace_buf.data[4] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
7634 filter_replace_buf.data[4] |=
7635 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
7637 status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
7638 &filter_replace_buf);
7640 i40e_global_cfg_warning(I40E_WARNING_RPL_CLD_FILTER);
7641 PMD_DRV_LOG(DEBUG, "Global configuration modification: "
7642 "cloud filter type is changed from 0x%x to 0x%x",
7643 filter_replace.old_filter_type,
7644 filter_replace.new_filter_type);
7650 i40e_dev_consistent_tunnel_filter_set(struct i40e_pf *pf,
7651 struct i40e_tunnel_filter_conf *tunnel_filter,
7655 uint32_t ipv4_addr, ipv4_addr_le;
7656 uint8_t i, tun_type = 0;
7657 /* internal variable to convert ipv6 byte order */
7658 uint32_t convert_ipv6[4];
7660 struct i40e_pf_vf *vf = NULL;
7661 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7662 struct i40e_vsi *vsi;
7663 struct i40e_aqc_add_rm_cloud_filt_elem_ext *cld_filter;
7664 struct i40e_aqc_add_rm_cloud_filt_elem_ext *pfilter;
7665 struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
7666 struct i40e_tunnel_filter *tunnel, *node;
7667 struct i40e_tunnel_filter check_filter; /* Check if filter exists */
7669 bool big_buffer = 0;
7671 cld_filter = rte_zmalloc("tunnel_filter",
7672 sizeof(struct i40e_aqc_add_rm_cloud_filt_elem_ext),
7675 if (cld_filter == NULL) {
7676 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
7679 pfilter = cld_filter;
7681 ether_addr_copy(&tunnel_filter->outer_mac,
7682 (struct ether_addr *)&pfilter->element.outer_mac);
7683 ether_addr_copy(&tunnel_filter->inner_mac,
7684 (struct ether_addr *)&pfilter->element.inner_mac);
7686 pfilter->element.inner_vlan =
7687 rte_cpu_to_le_16(tunnel_filter->inner_vlan);
7688 if (tunnel_filter->ip_type == I40E_TUNNEL_IPTYPE_IPV4) {
7689 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV4;
7690 ipv4_addr = rte_be_to_cpu_32(tunnel_filter->ip_addr.ipv4_addr);
7691 ipv4_addr_le = rte_cpu_to_le_32(ipv4_addr);
7692 rte_memcpy(&pfilter->element.ipaddr.v4.data,
7694 sizeof(pfilter->element.ipaddr.v4.data));
7696 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV6;
7697 for (i = 0; i < 4; i++) {
7699 rte_cpu_to_le_32(rte_be_to_cpu_32(
7700 tunnel_filter->ip_addr.ipv6_addr[i]));
7702 rte_memcpy(&pfilter->element.ipaddr.v6.data,
7704 sizeof(pfilter->element.ipaddr.v6.data));
7707 /* check tunneled type */
7708 switch (tunnel_filter->tunnel_type) {
7709 case I40E_TUNNEL_TYPE_VXLAN:
7710 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_VXLAN;
7712 case I40E_TUNNEL_TYPE_NVGRE:
7713 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_NVGRE_OMAC;
7715 case I40E_TUNNEL_TYPE_IP_IN_GRE:
7716 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_IP;
7718 case I40E_TUNNEL_TYPE_MPLSoUDP:
7719 if (!pf->mpls_replace_flag) {
7720 i40e_replace_mpls_l1_filter(pf);
7721 i40e_replace_mpls_cloud_filter(pf);
7722 pf->mpls_replace_flag = 1;
7724 teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
7725 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
7727 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
7728 (teid_le & 0xF) << 12;
7729 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
7732 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_MPLSOUDP;
7734 case I40E_TUNNEL_TYPE_MPLSoGRE:
7735 if (!pf->mpls_replace_flag) {
7736 i40e_replace_mpls_l1_filter(pf);
7737 i40e_replace_mpls_cloud_filter(pf);
7738 pf->mpls_replace_flag = 1;
7740 teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
7741 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
7743 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
7744 (teid_le & 0xF) << 12;
7745 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
7748 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_MPLSOGRE;
7750 case I40E_TUNNEL_TYPE_GTPC:
7751 if (!pf->gtp_replace_flag) {
7752 i40e_replace_gtp_l1_filter(pf);
7753 i40e_replace_gtp_cloud_filter(pf);
7754 pf->gtp_replace_flag = 1;
7756 teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
7757 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD0] =
7758 (teid_le >> 16) & 0xFFFF;
7759 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD1] =
7761 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD2] =
7765 case I40E_TUNNEL_TYPE_GTPU:
7766 if (!pf->gtp_replace_flag) {
7767 i40e_replace_gtp_l1_filter(pf);
7768 i40e_replace_gtp_cloud_filter(pf);
7769 pf->gtp_replace_flag = 1;
7771 teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
7772 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD0] =
7773 (teid_le >> 16) & 0xFFFF;
7774 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD1] =
7776 pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD2] =
7780 case I40E_TUNNEL_TYPE_QINQ:
7781 if (!pf->qinq_replace_flag) {
7782 ret = i40e_cloud_filter_qinq_create(pf);
7785 "QinQ tunnel filter already created.");
7786 pf->qinq_replace_flag = 1;
7788 /* Add in the General fields the values of
7789 * the Outer and Inner VLAN
7790 * Big Buffer should be set, see changes in
7791 * i40e_aq_add_cloud_filters
7793 pfilter->general_fields[0] = tunnel_filter->inner_vlan;
7794 pfilter->general_fields[1] = tunnel_filter->outer_vlan;
7798 /* Other tunnel types is not supported. */
7799 PMD_DRV_LOG(ERR, "tunnel type is not supported.");
7800 rte_free(cld_filter);
7804 if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_MPLSoUDP)
7805 pfilter->element.flags =
7806 I40E_AQC_ADD_CLOUD_FILTER_0X11;
7807 else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_MPLSoGRE)
7808 pfilter->element.flags =
7809 I40E_AQC_ADD_CLOUD_FILTER_0X12;
7810 else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_GTPC)
7811 pfilter->element.flags =
7812 I40E_AQC_ADD_CLOUD_FILTER_0X11;
7813 else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_GTPU)
7814 pfilter->element.flags =
7815 I40E_AQC_ADD_CLOUD_FILTER_0X12;
7816 else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_QINQ)
7817 pfilter->element.flags |=
7818 I40E_AQC_ADD_CLOUD_FILTER_0X10;
7820 val = i40e_dev_get_filter_type(tunnel_filter->filter_type,
7821 &pfilter->element.flags);
7823 rte_free(cld_filter);
7828 pfilter->element.flags |= rte_cpu_to_le_16(
7829 I40E_AQC_ADD_CLOUD_FLAGS_TO_QUEUE |
7830 ip_type | (tun_type << I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT));
7831 pfilter->element.tenant_id = rte_cpu_to_le_32(tunnel_filter->tenant_id);
7832 pfilter->element.queue_number =
7833 rte_cpu_to_le_16(tunnel_filter->queue_id);
7835 if (!tunnel_filter->is_to_vf)
7838 if (tunnel_filter->vf_id >= pf->vf_num) {
7839 PMD_DRV_LOG(ERR, "Invalid argument.");
7840 rte_free(cld_filter);
7843 vf = &pf->vfs[tunnel_filter->vf_id];
7847 /* Check if there is the filter in SW list */
7848 memset(&check_filter, 0, sizeof(check_filter));
7849 i40e_tunnel_filter_convert(cld_filter, &check_filter);
7850 check_filter.is_to_vf = tunnel_filter->is_to_vf;
7851 check_filter.vf_id = tunnel_filter->vf_id;
7852 node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
7854 PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
7855 rte_free(cld_filter);
7859 if (!add && !node) {
7860 PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
7861 rte_free(cld_filter);
7867 ret = i40e_aq_add_cloud_filters_big_buffer(hw,
7868 vsi->seid, cld_filter, 1);
7870 ret = i40e_aq_add_cloud_filters(hw,
7871 vsi->seid, &cld_filter->element, 1);
7873 PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
7874 rte_free(cld_filter);
7877 tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
7878 if (tunnel == NULL) {
7879 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
7880 rte_free(cld_filter);
7884 rte_memcpy(tunnel, &check_filter, sizeof(check_filter));
7885 ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
7890 ret = i40e_aq_remove_cloud_filters_big_buffer(
7891 hw, vsi->seid, cld_filter, 1);
7893 ret = i40e_aq_remove_cloud_filters(hw, vsi->seid,
7894 &cld_filter->element, 1);
7896 PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
7897 rte_free(cld_filter);
7900 ret = i40e_sw_tunnel_filter_del(pf, &node->input);
7903 rte_free(cld_filter);
7908 i40e_get_vxlan_port_idx(struct i40e_pf *pf, uint16_t port)
7912 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
7913 if (pf->vxlan_ports[i] == port)
7921 i40e_add_vxlan_port(struct i40e_pf *pf, uint16_t port)
7925 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7927 idx = i40e_get_vxlan_port_idx(pf, port);
7929 /* Check if port already exists */
7931 PMD_DRV_LOG(ERR, "Port %d already offloaded", port);
7935 /* Now check if there is space to add the new port */
7936 idx = i40e_get_vxlan_port_idx(pf, 0);
7939 "Maximum number of UDP ports reached, not adding port %d",
7944 ret = i40e_aq_add_udp_tunnel(hw, port, I40E_AQC_TUNNEL_TYPE_VXLAN,
7947 PMD_DRV_LOG(ERR, "Failed to add VXLAN UDP port %d", port);
7951 PMD_DRV_LOG(INFO, "Added port %d with AQ command with index %d",
7954 /* New port: add it and mark its index in the bitmap */
7955 pf->vxlan_ports[idx] = port;
7956 pf->vxlan_bitmap |= (1 << idx);
7958 if (!(pf->flags & I40E_FLAG_VXLAN))
7959 pf->flags |= I40E_FLAG_VXLAN;
7965 i40e_del_vxlan_port(struct i40e_pf *pf, uint16_t port)
7968 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7970 if (!(pf->flags & I40E_FLAG_VXLAN)) {
7971 PMD_DRV_LOG(ERR, "VXLAN UDP port was not configured.");
7975 idx = i40e_get_vxlan_port_idx(pf, port);
7978 PMD_DRV_LOG(ERR, "Port %d doesn't exist", port);
7982 if (i40e_aq_del_udp_tunnel(hw, idx, NULL) < 0) {
7983 PMD_DRV_LOG(ERR, "Failed to delete VXLAN UDP port %d", port);
7987 PMD_DRV_LOG(INFO, "Deleted port %d with AQ command with index %d",
7990 pf->vxlan_ports[idx] = 0;
7991 pf->vxlan_bitmap &= ~(1 << idx);
7993 if (!pf->vxlan_bitmap)
7994 pf->flags &= ~I40E_FLAG_VXLAN;
7999 /* Add UDP tunneling port */
8001 i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
8002 struct rte_eth_udp_tunnel *udp_tunnel)
8005 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8007 if (udp_tunnel == NULL)
8010 switch (udp_tunnel->prot_type) {
8011 case RTE_TUNNEL_TYPE_VXLAN:
8012 ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port);
8015 case RTE_TUNNEL_TYPE_GENEVE:
8016 case RTE_TUNNEL_TYPE_TEREDO:
8017 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8022 PMD_DRV_LOG(ERR, "Invalid tunnel type");
8030 /* Remove UDP tunneling port */
8032 i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
8033 struct rte_eth_udp_tunnel *udp_tunnel)
8036 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8038 if (udp_tunnel == NULL)
8041 switch (udp_tunnel->prot_type) {
8042 case RTE_TUNNEL_TYPE_VXLAN:
8043 ret = i40e_del_vxlan_port(pf, udp_tunnel->udp_port);
8045 case RTE_TUNNEL_TYPE_GENEVE:
8046 case RTE_TUNNEL_TYPE_TEREDO:
8047 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8051 PMD_DRV_LOG(ERR, "Invalid tunnel type");
8059 /* Calculate the maximum number of contiguous PF queues that are configured */
8061 i40e_pf_calc_configured_queues_num(struct i40e_pf *pf)
8063 struct rte_eth_dev_data *data = pf->dev_data;
8065 struct i40e_rx_queue *rxq;
8068 for (i = 0; i < pf->lan_nb_qps; i++) {
8069 rxq = data->rx_queues[i];
8070 if (rxq && rxq->q_set)
8081 i40e_pf_config_rss(struct i40e_pf *pf)
8083 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8084 struct rte_eth_rss_conf rss_conf;
8085 uint32_t i, lut = 0;
8089 * If both VMDQ and RSS enabled, not all of PF queues are configured.
8090 * It's necessary to calculate the actual PF queues that are configured.
8092 if (pf->dev_data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG)
8093 num = i40e_pf_calc_configured_queues_num(pf);
8095 num = pf->dev_data->nb_rx_queues;
8097 num = RTE_MIN(num, I40E_MAX_Q_PER_TC);
8098 PMD_INIT_LOG(INFO, "Max of contiguous %u PF queues are configured",
8102 PMD_INIT_LOG(ERR, "No PF queues are configured to enable RSS");
8106 for (i = 0, j = 0; i < hw->func_caps.rss_table_size; i++, j++) {
8109 lut = (lut << 8) | (j & ((0x1 <<
8110 hw->func_caps.rss_table_entry_width) - 1));
8112 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i >> 2), lut);
8115 rss_conf = pf->dev_data->dev_conf.rx_adv_conf.rss_conf;
8116 if ((rss_conf.rss_hf & pf->adapter->flow_types_mask) == 0) {
8117 i40e_pf_disable_rss(pf);
8120 if (rss_conf.rss_key == NULL || rss_conf.rss_key_len <
8121 (I40E_PFQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t)) {
8122 /* Random default keys */
8123 static uint32_t rss_key_default[] = {0x6b793944,
8124 0x23504cb5, 0x5bea75b6, 0x309f4f12, 0x3dc0a2b8,
8125 0x024ddcdf, 0x339b8ca0, 0x4c4af64a, 0x34fac605,
8126 0x55d85839, 0x3a58997d, 0x2ec938e1, 0x66031581};
8128 rss_conf.rss_key = (uint8_t *)rss_key_default;
8129 rss_conf.rss_key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
8133 return i40e_hw_rss_hash_set(pf, &rss_conf);
8137 i40e_tunnel_filter_param_check(struct i40e_pf *pf,
8138 struct rte_eth_tunnel_filter_conf *filter)
8140 if (pf == NULL || filter == NULL) {
8141 PMD_DRV_LOG(ERR, "Invalid parameter");
8145 if (filter->queue_id >= pf->dev_data->nb_rx_queues) {
8146 PMD_DRV_LOG(ERR, "Invalid queue ID");
8150 if (filter->inner_vlan > ETHER_MAX_VLAN_ID) {
8151 PMD_DRV_LOG(ERR, "Invalid inner VLAN ID");
8155 if ((filter->filter_type & ETH_TUNNEL_FILTER_OMAC) &&
8156 (is_zero_ether_addr(&filter->outer_mac))) {
8157 PMD_DRV_LOG(ERR, "Cannot add NULL outer MAC address");
8161 if ((filter->filter_type & ETH_TUNNEL_FILTER_IMAC) &&
8162 (is_zero_ether_addr(&filter->inner_mac))) {
8163 PMD_DRV_LOG(ERR, "Cannot add NULL inner MAC address");
8170 #define I40E_GL_PRS_FVBM_MSK_ENA 0x80000000
8171 #define I40E_GL_PRS_FVBM(_i) (0x00269760 + ((_i) * 4))
8173 i40e_dev_set_gre_key_len(struct i40e_hw *hw, uint8_t len)
8175 struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
8179 if (pf->support_multi_driver) {
8180 PMD_DRV_LOG(ERR, "GRE key length configuration is unsupported");
8184 val = I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2));
8185 PMD_DRV_LOG(DEBUG, "Read original GL_PRS_FVBM with 0x%08x", val);
8188 reg = val | I40E_GL_PRS_FVBM_MSK_ENA;
8189 } else if (len == 4) {
8190 reg = val & ~I40E_GL_PRS_FVBM_MSK_ENA;
8192 PMD_DRV_LOG(ERR, "Unsupported GRE key length of %u", len);
8197 ret = i40e_aq_debug_write_register(hw, I40E_GL_PRS_FVBM(2),
8201 PMD_DRV_LOG(DEBUG, "Global register 0x%08x is changed "
8202 "with value 0x%08x",
8203 I40E_GL_PRS_FVBM(2), reg);
8204 i40e_global_cfg_warning(I40E_WARNING_GRE_KEY_LEN);
8208 PMD_DRV_LOG(DEBUG, "Read modified GL_PRS_FVBM with 0x%08x",
8209 I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2)));
8215 i40e_dev_global_config_set(struct i40e_hw *hw, struct rte_eth_global_cfg *cfg)
8222 switch (cfg->cfg_type) {
8223 case RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN:
8224 ret = i40e_dev_set_gre_key_len(hw, cfg->cfg.gre_key_len);
8227 PMD_DRV_LOG(ERR, "Unknown config type %u", cfg->cfg_type);
8235 i40e_filter_ctrl_global_config(struct rte_eth_dev *dev,
8236 enum rte_filter_op filter_op,
8239 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8240 int ret = I40E_ERR_PARAM;
8242 switch (filter_op) {
8243 case RTE_ETH_FILTER_SET:
8244 ret = i40e_dev_global_config_set(hw,
8245 (struct rte_eth_global_cfg *)arg);
8248 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
8256 i40e_tunnel_filter_handle(struct rte_eth_dev *dev,
8257 enum rte_filter_op filter_op,
8260 struct rte_eth_tunnel_filter_conf *filter;
8261 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8262 int ret = I40E_SUCCESS;
8264 filter = (struct rte_eth_tunnel_filter_conf *)(arg);
8266 if (i40e_tunnel_filter_param_check(pf, filter) < 0)
8267 return I40E_ERR_PARAM;
8269 switch (filter_op) {
8270 case RTE_ETH_FILTER_NOP:
8271 if (!(pf->flags & I40E_FLAG_VXLAN))
8272 ret = I40E_NOT_SUPPORTED;
8274 case RTE_ETH_FILTER_ADD:
8275 ret = i40e_dev_tunnel_filter_set(pf, filter, 1);
8277 case RTE_ETH_FILTER_DELETE:
8278 ret = i40e_dev_tunnel_filter_set(pf, filter, 0);
8281 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
8282 ret = I40E_ERR_PARAM;
8290 i40e_pf_config_mq_rx(struct i40e_pf *pf)
8293 enum rte_eth_rx_mq_mode mq_mode = pf->dev_data->dev_conf.rxmode.mq_mode;
8296 if (mq_mode & ETH_MQ_RX_RSS_FLAG)
8297 ret = i40e_pf_config_rss(pf);
8299 i40e_pf_disable_rss(pf);
8304 /* Get the symmetric hash enable configurations per port */
8306 i40e_get_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t *enable)
8308 uint32_t reg = i40e_read_rx_ctl(hw, I40E_PRTQF_CTL_0);
8310 *enable = reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK ? 1 : 0;
8313 /* Set the symmetric hash enable configurations per port */
8315 i40e_set_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t enable)
8317 uint32_t reg = i40e_read_rx_ctl(hw, I40E_PRTQF_CTL_0);
8320 if (reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK) {
8322 "Symmetric hash has already been enabled");
8325 reg |= I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
8327 if (!(reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK)) {
8329 "Symmetric hash has already been disabled");
8332 reg &= ~I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
8334 i40e_write_rx_ctl(hw, I40E_PRTQF_CTL_0, reg);
8335 I40E_WRITE_FLUSH(hw);
8339 * Get global configurations of hash function type and symmetric hash enable
8340 * per flow type (pctype). Note that global configuration means it affects all
8341 * the ports on the same NIC.
8344 i40e_get_hash_filter_global_config(struct i40e_hw *hw,
8345 struct rte_eth_hash_global_conf *g_cfg)
8347 struct i40e_adapter *adapter = (struct i40e_adapter *)hw->back;
8351 memset(g_cfg, 0, sizeof(*g_cfg));
8352 reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
8353 if (reg & I40E_GLQF_CTL_HTOEP_MASK)
8354 g_cfg->hash_func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
8356 g_cfg->hash_func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
8357 PMD_DRV_LOG(DEBUG, "Hash function is %s",
8358 (reg & I40E_GLQF_CTL_HTOEP_MASK) ? "Toeplitz" : "Simple XOR");
8361 * As i40e supports less than 64 flow types, only first 64 bits need to
8364 for (i = 1; i < RTE_SYM_HASH_MASK_ARRAY_SIZE; i++) {
8365 g_cfg->valid_bit_mask[i] = 0ULL;
8366 g_cfg->sym_hash_enable_mask[i] = 0ULL;
8369 g_cfg->valid_bit_mask[0] = adapter->flow_types_mask;
8371 for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < UINT64_BIT; i++) {
8372 if (!adapter->pctypes_tbl[i])
8374 for (j = I40E_FILTER_PCTYPE_INVALID + 1;
8375 j < I40E_FILTER_PCTYPE_MAX; j++) {
8376 if (adapter->pctypes_tbl[i] & (1ULL << j)) {
8377 reg = i40e_read_rx_ctl(hw, I40E_GLQF_HSYM(j));
8378 if (reg & I40E_GLQF_HSYM_SYMH_ENA_MASK) {
8379 g_cfg->sym_hash_enable_mask[0] |=
8390 i40e_hash_global_config_check(const struct i40e_adapter *adapter,
8391 const struct rte_eth_hash_global_conf *g_cfg)
8394 uint64_t mask0, i40e_mask = adapter->flow_types_mask;
8396 if (g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_TOEPLITZ &&
8397 g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_SIMPLE_XOR &&
8398 g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_DEFAULT) {
8399 PMD_DRV_LOG(ERR, "Unsupported hash function type %d",
8405 * As i40e supports less than 64 flow types, only first 64 bits need to
8408 mask0 = g_cfg->valid_bit_mask[0];
8409 for (i = 0; i < RTE_SYM_HASH_MASK_ARRAY_SIZE; i++) {
8411 /* Check if any unsupported flow type configured */
8412 if ((mask0 | i40e_mask) ^ i40e_mask)
8415 if (g_cfg->valid_bit_mask[i])
8423 PMD_DRV_LOG(ERR, "i40e unsupported flow type bit(s) configured");
8429 * Set global configurations of hash function type and symmetric hash enable
8430 * per flow type (pctype). Note any modifying global configuration will affect
8431 * all the ports on the same NIC.
8434 i40e_set_hash_filter_global_config(struct i40e_hw *hw,
8435 struct rte_eth_hash_global_conf *g_cfg)
8437 struct i40e_adapter *adapter = (struct i40e_adapter *)hw->back;
8438 struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
8442 uint64_t mask0 = g_cfg->valid_bit_mask[0] & adapter->flow_types_mask;
8444 if (pf->support_multi_driver) {
8445 PMD_DRV_LOG(ERR, "Hash global configuration is not supported.");
8449 /* Check the input parameters */
8450 ret = i40e_hash_global_config_check(adapter, g_cfg);
8455 * As i40e supports less than 64 flow types, only first 64 bits need to
8458 for (i = RTE_ETH_FLOW_UNKNOWN + 1; mask0 && i < UINT64_BIT; i++) {
8459 if (mask0 & (1UL << i)) {
8460 reg = (g_cfg->sym_hash_enable_mask[0] & (1ULL << i)) ?
8461 I40E_GLQF_HSYM_SYMH_ENA_MASK : 0;
8463 for (j = I40E_FILTER_PCTYPE_INVALID + 1;
8464 j < I40E_FILTER_PCTYPE_MAX; j++) {
8465 if (adapter->pctypes_tbl[i] & (1ULL << j))
8466 i40e_write_global_rx_ctl(hw,
8470 i40e_global_cfg_warning(I40E_WARNING_HSYM);
8474 reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
8475 if (g_cfg->hash_func == RTE_ETH_HASH_FUNCTION_TOEPLITZ) {
8477 if (reg & I40E_GLQF_CTL_HTOEP_MASK) {
8479 "Hash function already set to Toeplitz");
8482 reg |= I40E_GLQF_CTL_HTOEP_MASK;
8483 } else if (g_cfg->hash_func == RTE_ETH_HASH_FUNCTION_SIMPLE_XOR) {
8485 if (!(reg & I40E_GLQF_CTL_HTOEP_MASK)) {
8487 "Hash function already set to Simple XOR");
8490 reg &= ~I40E_GLQF_CTL_HTOEP_MASK;
8492 /* Use the default, and keep it as it is */
8495 i40e_write_global_rx_ctl(hw, I40E_GLQF_CTL, reg);
8496 i40e_global_cfg_warning(I40E_WARNING_QF_CTL);
8499 I40E_WRITE_FLUSH(hw);
8505 * Valid input sets for hash and flow director filters per PCTYPE
8508 i40e_get_valid_input_set(enum i40e_filter_pctype pctype,
8509 enum rte_filter_type filter)
8513 static const uint64_t valid_hash_inset_table[] = {
8514 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
8515 I40E_INSET_DMAC | I40E_INSET_SMAC |
8516 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8517 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_SRC |
8518 I40E_INSET_IPV4_DST | I40E_INSET_IPV4_TOS |
8519 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
8520 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
8521 I40E_INSET_FLEX_PAYLOAD,
8522 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
8523 I40E_INSET_DMAC | I40E_INSET_SMAC |
8524 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8525 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
8526 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
8527 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
8528 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8529 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
8530 I40E_INSET_FLEX_PAYLOAD,
8531 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
8532 I40E_INSET_DMAC | I40E_INSET_SMAC |
8533 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8534 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
8535 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
8536 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
8537 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8538 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
8539 I40E_INSET_FLEX_PAYLOAD,
8540 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
8541 I40E_INSET_DMAC | I40E_INSET_SMAC |
8542 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8543 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
8544 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
8545 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
8546 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8547 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
8548 I40E_INSET_FLEX_PAYLOAD,
8549 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
8550 I40E_INSET_DMAC | I40E_INSET_SMAC |
8551 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8552 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
8553 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
8554 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
8555 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8556 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
8557 I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
8558 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
8559 I40E_INSET_DMAC | I40E_INSET_SMAC |
8560 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8561 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
8562 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
8563 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
8564 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8565 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
8566 I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
8567 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
8568 I40E_INSET_DMAC | I40E_INSET_SMAC |
8569 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8570 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
8571 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
8572 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
8573 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8574 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
8575 I40E_INSET_SCTP_VT | I40E_INSET_FLEX_PAYLOAD,
8576 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
8577 I40E_INSET_DMAC | I40E_INSET_SMAC |
8578 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8579 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
8580 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
8581 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
8582 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8583 I40E_INSET_FLEX_PAYLOAD,
8584 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
8585 I40E_INSET_DMAC | I40E_INSET_SMAC |
8586 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8587 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
8588 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
8589 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_TUNNEL_DMAC |
8590 I40E_INSET_TUNNEL_ID | I40E_INSET_IPV6_SRC |
8591 I40E_INSET_IPV6_DST | I40E_INSET_FLEX_PAYLOAD,
8592 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
8593 I40E_INSET_DMAC | I40E_INSET_SMAC |
8594 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8595 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
8596 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
8597 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
8598 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
8599 I40E_INSET_DST_PORT | I40E_INSET_FLEX_PAYLOAD,
8600 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
8601 I40E_INSET_DMAC | I40E_INSET_SMAC |
8602 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8603 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
8604 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
8605 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
8606 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
8607 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
8608 I40E_INSET_FLEX_PAYLOAD,
8609 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
8610 I40E_INSET_DMAC | I40E_INSET_SMAC |
8611 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8612 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
8613 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
8614 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
8615 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
8616 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
8617 I40E_INSET_FLEX_PAYLOAD,
8618 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
8619 I40E_INSET_DMAC | I40E_INSET_SMAC |
8620 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8621 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
8622 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
8623 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
8624 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
8625 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
8626 I40E_INSET_FLEX_PAYLOAD,
8627 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
8628 I40E_INSET_DMAC | I40E_INSET_SMAC |
8629 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8630 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
8631 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
8632 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
8633 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
8634 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
8635 I40E_INSET_FLEX_PAYLOAD,
8636 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
8637 I40E_INSET_DMAC | I40E_INSET_SMAC |
8638 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8639 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
8640 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
8641 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
8642 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
8643 I40E_INSET_DST_PORT | I40E_INSET_SCTP_VT |
8644 I40E_INSET_FLEX_PAYLOAD,
8645 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
8646 I40E_INSET_DMAC | I40E_INSET_SMAC |
8647 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8648 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
8649 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
8650 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
8651 I40E_INSET_IPV6_DST | I40E_INSET_TUNNEL_ID |
8652 I40E_INSET_FLEX_PAYLOAD,
8653 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
8654 I40E_INSET_DMAC | I40E_INSET_SMAC |
8655 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8656 I40E_INSET_VLAN_TUNNEL | I40E_INSET_LAST_ETHER_TYPE |
8657 I40E_INSET_FLEX_PAYLOAD,
8661 * Flow director supports only fields defined in
8662 * union rte_eth_fdir_flow.
8664 static const uint64_t valid_fdir_inset_table[] = {
8665 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
8666 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8667 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8668 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
8669 I40E_INSET_IPV4_TTL,
8670 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
8671 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8672 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8673 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
8674 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8675 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
8676 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8677 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8678 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
8679 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8680 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
8681 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8682 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8683 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
8684 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8685 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
8686 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8687 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8688 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
8689 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8690 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
8691 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8692 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8693 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
8694 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8695 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
8696 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8697 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8698 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
8699 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
8701 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
8702 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8703 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8704 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
8705 I40E_INSET_IPV4_TTL,
8706 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
8707 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8708 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8709 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
8710 I40E_INSET_IPV6_HOP_LIMIT,
8711 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
8712 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8713 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8714 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
8715 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8716 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
8717 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8718 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8719 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
8720 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8721 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
8722 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8723 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8724 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
8725 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8726 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
8727 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8728 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8729 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
8730 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8731 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
8732 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8733 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8734 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
8735 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8736 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
8737 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8738 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8739 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
8740 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
8742 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
8743 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8744 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8745 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
8746 I40E_INSET_IPV6_HOP_LIMIT,
8747 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
8748 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
8749 I40E_INSET_LAST_ETHER_TYPE,
8752 if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
8754 if (filter == RTE_ETH_FILTER_HASH)
8755 valid = valid_hash_inset_table[pctype];
8757 valid = valid_fdir_inset_table[pctype];
8763 * Validate if the input set is allowed for a specific PCTYPE
8766 i40e_validate_input_set(enum i40e_filter_pctype pctype,
8767 enum rte_filter_type filter, uint64_t inset)
8771 valid = i40e_get_valid_input_set(pctype, filter);
8772 if (inset & (~valid))
8778 /* default input set fields combination per pctype */
8780 i40e_get_default_input_set(uint16_t pctype)
8782 static const uint64_t default_inset_table[] = {
8783 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
8784 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
8785 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
8786 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8787 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8788 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
8789 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8790 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8791 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
8792 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8793 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8794 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
8795 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8796 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8797 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
8798 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8799 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8800 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
8801 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
8802 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
8804 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
8805 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
8806 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
8807 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
8808 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
8809 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8810 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8811 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
8812 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8813 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8814 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
8815 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8816 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8817 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
8818 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8819 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8820 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
8821 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8822 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
8823 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
8824 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
8825 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
8827 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
8828 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
8829 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
8830 I40E_INSET_LAST_ETHER_TYPE,
8833 if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
8836 return default_inset_table[pctype];
8840 * Parse the input set from index to logical bit masks
8843 i40e_parse_input_set(uint64_t *inset,
8844 enum i40e_filter_pctype pctype,
8845 enum rte_eth_input_set_field *field,
8851 static const struct {
8852 enum rte_eth_input_set_field field;
8854 } inset_convert_table[] = {
8855 {RTE_ETH_INPUT_SET_NONE, I40E_INSET_NONE},
8856 {RTE_ETH_INPUT_SET_L2_SRC_MAC, I40E_INSET_SMAC},
8857 {RTE_ETH_INPUT_SET_L2_DST_MAC, I40E_INSET_DMAC},
8858 {RTE_ETH_INPUT_SET_L2_OUTER_VLAN, I40E_INSET_VLAN_OUTER},
8859 {RTE_ETH_INPUT_SET_L2_INNER_VLAN, I40E_INSET_VLAN_INNER},
8860 {RTE_ETH_INPUT_SET_L2_ETHERTYPE, I40E_INSET_LAST_ETHER_TYPE},
8861 {RTE_ETH_INPUT_SET_L3_SRC_IP4, I40E_INSET_IPV4_SRC},
8862 {RTE_ETH_INPUT_SET_L3_DST_IP4, I40E_INSET_IPV4_DST},
8863 {RTE_ETH_INPUT_SET_L3_IP4_TOS, I40E_INSET_IPV4_TOS},
8864 {RTE_ETH_INPUT_SET_L3_IP4_PROTO, I40E_INSET_IPV4_PROTO},
8865 {RTE_ETH_INPUT_SET_L3_IP4_TTL, I40E_INSET_IPV4_TTL},
8866 {RTE_ETH_INPUT_SET_L3_SRC_IP6, I40E_INSET_IPV6_SRC},
8867 {RTE_ETH_INPUT_SET_L3_DST_IP6, I40E_INSET_IPV6_DST},
8868 {RTE_ETH_INPUT_SET_L3_IP6_TC, I40E_INSET_IPV6_TC},
8869 {RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER,
8870 I40E_INSET_IPV6_NEXT_HDR},
8871 {RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS,
8872 I40E_INSET_IPV6_HOP_LIMIT},
8873 {RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT, I40E_INSET_SRC_PORT},
8874 {RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT, I40E_INSET_SRC_PORT},
8875 {RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT, I40E_INSET_SRC_PORT},
8876 {RTE_ETH_INPUT_SET_L4_UDP_DST_PORT, I40E_INSET_DST_PORT},
8877 {RTE_ETH_INPUT_SET_L4_TCP_DST_PORT, I40E_INSET_DST_PORT},
8878 {RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT, I40E_INSET_DST_PORT},
8879 {RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG,
8880 I40E_INSET_SCTP_VT},
8881 {RTE_ETH_INPUT_SET_TUNNEL_L2_INNER_DST_MAC,
8882 I40E_INSET_TUNNEL_DMAC},
8883 {RTE_ETH_INPUT_SET_TUNNEL_L2_INNER_VLAN,
8884 I40E_INSET_VLAN_TUNNEL},
8885 {RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY,
8886 I40E_INSET_TUNNEL_ID},
8887 {RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY, I40E_INSET_TUNNEL_ID},
8888 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD,
8889 I40E_INSET_FLEX_PAYLOAD_W1},
8890 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD,
8891 I40E_INSET_FLEX_PAYLOAD_W2},
8892 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD,
8893 I40E_INSET_FLEX_PAYLOAD_W3},
8894 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD,
8895 I40E_INSET_FLEX_PAYLOAD_W4},
8896 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD,
8897 I40E_INSET_FLEX_PAYLOAD_W5},
8898 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD,
8899 I40E_INSET_FLEX_PAYLOAD_W6},
8900 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD,
8901 I40E_INSET_FLEX_PAYLOAD_W7},
8902 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD,
8903 I40E_INSET_FLEX_PAYLOAD_W8},
8906 if (!inset || !field || size > RTE_ETH_INSET_SIZE_MAX)
8909 /* Only one item allowed for default or all */
8911 if (field[0] == RTE_ETH_INPUT_SET_DEFAULT) {
8912 *inset = i40e_get_default_input_set(pctype);
8914 } else if (field[0] == RTE_ETH_INPUT_SET_NONE) {
8915 *inset = I40E_INSET_NONE;
8920 for (i = 0, *inset = 0; i < size; i++) {
8921 for (j = 0; j < RTE_DIM(inset_convert_table); j++) {
8922 if (field[i] == inset_convert_table[j].field) {
8923 *inset |= inset_convert_table[j].inset;
8928 /* It contains unsupported input set, return immediately */
8929 if (j == RTE_DIM(inset_convert_table))
8937 * Translate the input set from bit masks to register aware bit masks
8941 i40e_translate_input_set_reg(enum i40e_mac_type type, uint64_t input)
8951 static const struct inset_map inset_map_common[] = {
8952 {I40E_INSET_DMAC, I40E_REG_INSET_L2_DMAC},
8953 {I40E_INSET_SMAC, I40E_REG_INSET_L2_SMAC},
8954 {I40E_INSET_VLAN_OUTER, I40E_REG_INSET_L2_OUTER_VLAN},
8955 {I40E_INSET_VLAN_INNER, I40E_REG_INSET_L2_INNER_VLAN},
8956 {I40E_INSET_LAST_ETHER_TYPE, I40E_REG_INSET_LAST_ETHER_TYPE},
8957 {I40E_INSET_IPV4_TOS, I40E_REG_INSET_L3_IP4_TOS},
8958 {I40E_INSET_IPV6_SRC, I40E_REG_INSET_L3_SRC_IP6},
8959 {I40E_INSET_IPV6_DST, I40E_REG_INSET_L3_DST_IP6},
8960 {I40E_INSET_IPV6_TC, I40E_REG_INSET_L3_IP6_TC},
8961 {I40E_INSET_IPV6_NEXT_HDR, I40E_REG_INSET_L3_IP6_NEXT_HDR},
8962 {I40E_INSET_IPV6_HOP_LIMIT, I40E_REG_INSET_L3_IP6_HOP_LIMIT},
8963 {I40E_INSET_SRC_PORT, I40E_REG_INSET_L4_SRC_PORT},
8964 {I40E_INSET_DST_PORT, I40E_REG_INSET_L4_DST_PORT},
8965 {I40E_INSET_SCTP_VT, I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG},
8966 {I40E_INSET_TUNNEL_ID, I40E_REG_INSET_TUNNEL_ID},
8967 {I40E_INSET_TUNNEL_DMAC,
8968 I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC},
8969 {I40E_INSET_TUNNEL_IPV4_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP4},
8970 {I40E_INSET_TUNNEL_IPV6_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP6},
8971 {I40E_INSET_TUNNEL_SRC_PORT,
8972 I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT},
8973 {I40E_INSET_TUNNEL_DST_PORT,
8974 I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT},
8975 {I40E_INSET_VLAN_TUNNEL, I40E_REG_INSET_TUNNEL_VLAN},
8976 {I40E_INSET_FLEX_PAYLOAD_W1, I40E_REG_INSET_FLEX_PAYLOAD_WORD1},
8977 {I40E_INSET_FLEX_PAYLOAD_W2, I40E_REG_INSET_FLEX_PAYLOAD_WORD2},
8978 {I40E_INSET_FLEX_PAYLOAD_W3, I40E_REG_INSET_FLEX_PAYLOAD_WORD3},
8979 {I40E_INSET_FLEX_PAYLOAD_W4, I40E_REG_INSET_FLEX_PAYLOAD_WORD4},
8980 {I40E_INSET_FLEX_PAYLOAD_W5, I40E_REG_INSET_FLEX_PAYLOAD_WORD5},
8981 {I40E_INSET_FLEX_PAYLOAD_W6, I40E_REG_INSET_FLEX_PAYLOAD_WORD6},
8982 {I40E_INSET_FLEX_PAYLOAD_W7, I40E_REG_INSET_FLEX_PAYLOAD_WORD7},
8983 {I40E_INSET_FLEX_PAYLOAD_W8, I40E_REG_INSET_FLEX_PAYLOAD_WORD8},
8986 /* some different registers map in x722*/
8987 static const struct inset_map inset_map_diff_x722[] = {
8988 {I40E_INSET_IPV4_SRC, I40E_X722_REG_INSET_L3_SRC_IP4},
8989 {I40E_INSET_IPV4_DST, I40E_X722_REG_INSET_L3_DST_IP4},
8990 {I40E_INSET_IPV4_PROTO, I40E_X722_REG_INSET_L3_IP4_PROTO},
8991 {I40E_INSET_IPV4_TTL, I40E_X722_REG_INSET_L3_IP4_TTL},
8994 static const struct inset_map inset_map_diff_not_x722[] = {
8995 {I40E_INSET_IPV4_SRC, I40E_REG_INSET_L3_SRC_IP4},
8996 {I40E_INSET_IPV4_DST, I40E_REG_INSET_L3_DST_IP4},
8997 {I40E_INSET_IPV4_PROTO, I40E_REG_INSET_L3_IP4_PROTO},
8998 {I40E_INSET_IPV4_TTL, I40E_REG_INSET_L3_IP4_TTL},
9004 /* Translate input set to register aware inset */
9005 if (type == I40E_MAC_X722) {
9006 for (i = 0; i < RTE_DIM(inset_map_diff_x722); i++) {
9007 if (input & inset_map_diff_x722[i].inset)
9008 val |= inset_map_diff_x722[i].inset_reg;
9011 for (i = 0; i < RTE_DIM(inset_map_diff_not_x722); i++) {
9012 if (input & inset_map_diff_not_x722[i].inset)
9013 val |= inset_map_diff_not_x722[i].inset_reg;
9017 for (i = 0; i < RTE_DIM(inset_map_common); i++) {
9018 if (input & inset_map_common[i].inset)
9019 val |= inset_map_common[i].inset_reg;
9026 i40e_generate_inset_mask_reg(uint64_t inset, uint32_t *mask, uint8_t nb_elem)
9029 uint64_t inset_need_mask = inset;
9031 static const struct {
9034 } inset_mask_map[] = {
9035 {I40E_INSET_IPV4_TOS, I40E_INSET_IPV4_TOS_MASK},
9036 {I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL, 0},
9037 {I40E_INSET_IPV4_PROTO, I40E_INSET_IPV4_PROTO_MASK},
9038 {I40E_INSET_IPV4_TTL, I40E_INSET_IPv4_TTL_MASK},
9039 {I40E_INSET_IPV6_TC, I40E_INSET_IPV6_TC_MASK},
9040 {I40E_INSET_IPV6_NEXT_HDR | I40E_INSET_IPV6_HOP_LIMIT, 0},
9041 {I40E_INSET_IPV6_NEXT_HDR, I40E_INSET_IPV6_NEXT_HDR_MASK},
9042 {I40E_INSET_IPV6_HOP_LIMIT, I40E_INSET_IPV6_HOP_LIMIT_MASK},
9045 if (!inset || !mask || !nb_elem)
9048 for (i = 0, idx = 0; i < RTE_DIM(inset_mask_map); i++) {
9049 /* Clear the inset bit, if no MASK is required,
9050 * for example proto + ttl
9052 if ((inset & inset_mask_map[i].inset) ==
9053 inset_mask_map[i].inset && inset_mask_map[i].mask == 0)
9054 inset_need_mask &= ~inset_mask_map[i].inset;
9055 if (!inset_need_mask)
9058 for (i = 0, idx = 0; i < RTE_DIM(inset_mask_map); i++) {
9059 if ((inset_need_mask & inset_mask_map[i].inset) ==
9060 inset_mask_map[i].inset) {
9061 if (idx >= nb_elem) {
9062 PMD_DRV_LOG(ERR, "exceed maximal number of bitmasks");
9065 mask[idx] = inset_mask_map[i].mask;
9074 i40e_check_write_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
9076 uint32_t reg = i40e_read_rx_ctl(hw, addr);
9078 PMD_DRV_LOG(DEBUG, "[0x%08x] original: 0x%08x", addr, reg);
9080 i40e_write_rx_ctl(hw, addr, val);
9081 PMD_DRV_LOG(DEBUG, "[0x%08x] after: 0x%08x", addr,
9082 (uint32_t)i40e_read_rx_ctl(hw, addr));
9086 i40e_check_write_global_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
9088 uint32_t reg = i40e_read_rx_ctl(hw, addr);
9090 PMD_DRV_LOG(DEBUG, "[0x%08x] original: 0x%08x", addr, reg);
9092 i40e_write_global_rx_ctl(hw, addr, val);
9093 PMD_DRV_LOG(DEBUG, "[0x%08x] after: 0x%08x", addr,
9094 (uint32_t)i40e_read_rx_ctl(hw, addr));
9098 i40e_filter_input_set_init(struct i40e_pf *pf)
9100 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9101 enum i40e_filter_pctype pctype;
9102 uint64_t input_set, inset_reg;
9103 uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9107 for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
9108 pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++) {
9109 flow_type = i40e_pctype_to_flowtype(pf->adapter, pctype);
9111 if (flow_type == RTE_ETH_FLOW_UNKNOWN)
9114 input_set = i40e_get_default_input_set(pctype);
9116 num = i40e_generate_inset_mask_reg(input_set, mask_reg,
9117 I40E_INSET_MASK_NUM_REG);
9120 if (pf->support_multi_driver && num > 0) {
9121 PMD_DRV_LOG(ERR, "Input set setting is not supported.");
9124 inset_reg = i40e_translate_input_set_reg(hw->mac.type,
9127 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
9128 (uint32_t)(inset_reg & UINT32_MAX));
9129 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
9130 (uint32_t)((inset_reg >>
9131 I40E_32_BIT_WIDTH) & UINT32_MAX));
9132 if (!pf->support_multi_driver) {
9133 i40e_check_write_global_reg(hw,
9134 I40E_GLQF_HASH_INSET(0, pctype),
9135 (uint32_t)(inset_reg & UINT32_MAX));
9136 i40e_check_write_global_reg(hw,
9137 I40E_GLQF_HASH_INSET(1, pctype),
9138 (uint32_t)((inset_reg >>
9139 I40E_32_BIT_WIDTH) & UINT32_MAX));
9141 for (i = 0; i < num; i++) {
9142 i40e_check_write_global_reg(hw,
9143 I40E_GLQF_FD_MSK(i, pctype),
9145 i40e_check_write_global_reg(hw,
9146 I40E_GLQF_HASH_MSK(i, pctype),
9149 /*clear unused mask registers of the pctype */
9150 for (i = num; i < I40E_INSET_MASK_NUM_REG; i++) {
9151 i40e_check_write_global_reg(hw,
9152 I40E_GLQF_FD_MSK(i, pctype),
9154 i40e_check_write_global_reg(hw,
9155 I40E_GLQF_HASH_MSK(i, pctype),
9159 PMD_DRV_LOG(ERR, "Input set setting is not supported.");
9161 I40E_WRITE_FLUSH(hw);
9163 /* store the default input set */
9164 if (!pf->support_multi_driver)
9165 pf->hash_input_set[pctype] = input_set;
9166 pf->fdir.input_set[pctype] = input_set;
9169 if (!pf->support_multi_driver) {
9170 i40e_global_cfg_warning(I40E_WARNING_HASH_INSET);
9171 i40e_global_cfg_warning(I40E_WARNING_FD_MSK);
9172 i40e_global_cfg_warning(I40E_WARNING_HASH_MSK);
9177 i40e_hash_filter_inset_select(struct i40e_hw *hw,
9178 struct rte_eth_input_set_conf *conf)
9180 struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
9181 enum i40e_filter_pctype pctype;
9182 uint64_t input_set, inset_reg = 0;
9183 uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9187 PMD_DRV_LOG(ERR, "Invalid pointer");
9190 if (conf->op != RTE_ETH_INPUT_SET_SELECT &&
9191 conf->op != RTE_ETH_INPUT_SET_ADD) {
9192 PMD_DRV_LOG(ERR, "Unsupported input set operation");
9196 if (pf->support_multi_driver) {
9197 PMD_DRV_LOG(ERR, "Hash input set setting is not supported.");
9201 pctype = i40e_flowtype_to_pctype(pf->adapter, conf->flow_type);
9202 if (pctype == I40E_FILTER_PCTYPE_INVALID) {
9203 PMD_DRV_LOG(ERR, "invalid flow_type input.");
9207 if (hw->mac.type == I40E_MAC_X722) {
9208 /* get translated pctype value in fd pctype register */
9209 pctype = (enum i40e_filter_pctype)i40e_read_rx_ctl(hw,
9210 I40E_GLQF_FD_PCTYPES((int)pctype));
9213 ret = i40e_parse_input_set(&input_set, pctype, conf->field,
9216 PMD_DRV_LOG(ERR, "Failed to parse input set");
9220 if (conf->op == RTE_ETH_INPUT_SET_ADD) {
9221 /* get inset value in register */
9222 inset_reg = i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, pctype));
9223 inset_reg <<= I40E_32_BIT_WIDTH;
9224 inset_reg |= i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, pctype));
9225 input_set |= pf->hash_input_set[pctype];
9227 num = i40e_generate_inset_mask_reg(input_set, mask_reg,
9228 I40E_INSET_MASK_NUM_REG);
9232 inset_reg |= i40e_translate_input_set_reg(hw->mac.type, input_set);
9234 i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(0, pctype),
9235 (uint32_t)(inset_reg & UINT32_MAX));
9236 i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(1, pctype),
9237 (uint32_t)((inset_reg >>
9238 I40E_32_BIT_WIDTH) & UINT32_MAX));
9239 i40e_global_cfg_warning(I40E_WARNING_HASH_INSET);
9241 for (i = 0; i < num; i++)
9242 i40e_check_write_global_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
9244 /*clear unused mask registers of the pctype */
9245 for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
9246 i40e_check_write_global_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
9248 i40e_global_cfg_warning(I40E_WARNING_HASH_MSK);
9249 I40E_WRITE_FLUSH(hw);
9251 pf->hash_input_set[pctype] = input_set;
9256 i40e_fdir_filter_inset_select(struct i40e_pf *pf,
9257 struct rte_eth_input_set_conf *conf)
9259 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9260 enum i40e_filter_pctype pctype;
9261 uint64_t input_set, inset_reg = 0;
9262 uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9266 PMD_DRV_LOG(ERR, "Invalid pointer");
9269 if (conf->op != RTE_ETH_INPUT_SET_SELECT &&
9270 conf->op != RTE_ETH_INPUT_SET_ADD) {
9271 PMD_DRV_LOG(ERR, "Unsupported input set operation");
9275 pctype = i40e_flowtype_to_pctype(pf->adapter, conf->flow_type);
9277 if (pctype == I40E_FILTER_PCTYPE_INVALID) {
9278 PMD_DRV_LOG(ERR, "invalid flow_type input.");
9282 ret = i40e_parse_input_set(&input_set, pctype, conf->field,
9285 PMD_DRV_LOG(ERR, "Failed to parse input set");
9289 /* get inset value in register */
9290 inset_reg = i40e_read_rx_ctl(hw, I40E_PRTQF_FD_INSET(pctype, 1));
9291 inset_reg <<= I40E_32_BIT_WIDTH;
9292 inset_reg |= i40e_read_rx_ctl(hw, I40E_PRTQF_FD_INSET(pctype, 0));
9294 /* Can not change the inset reg for flex payload for fdir,
9295 * it is done by writing I40E_PRTQF_FD_FLXINSET
9296 * in i40e_set_flex_mask_on_pctype.
9298 if (conf->op == RTE_ETH_INPUT_SET_SELECT)
9299 inset_reg &= I40E_REG_INSET_FLEX_PAYLOAD_WORDS;
9301 input_set |= pf->fdir.input_set[pctype];
9302 num = i40e_generate_inset_mask_reg(input_set, mask_reg,
9303 I40E_INSET_MASK_NUM_REG);
9306 if (pf->support_multi_driver && num > 0) {
9307 PMD_DRV_LOG(ERR, "FDIR bit mask is not supported.");
9311 inset_reg |= i40e_translate_input_set_reg(hw->mac.type, input_set);
9313 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
9314 (uint32_t)(inset_reg & UINT32_MAX));
9315 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
9316 (uint32_t)((inset_reg >>
9317 I40E_32_BIT_WIDTH) & UINT32_MAX));
9319 if (!pf->support_multi_driver) {
9320 for (i = 0; i < num; i++)
9321 i40e_check_write_global_reg(hw,
9322 I40E_GLQF_FD_MSK(i, pctype),
9324 /*clear unused mask registers of the pctype */
9325 for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
9326 i40e_check_write_global_reg(hw,
9327 I40E_GLQF_FD_MSK(i, pctype),
9329 i40e_global_cfg_warning(I40E_WARNING_FD_MSK);
9331 PMD_DRV_LOG(ERR, "FDIR bit mask is not supported.");
9333 I40E_WRITE_FLUSH(hw);
9335 pf->fdir.input_set[pctype] = input_set;
9340 i40e_hash_filter_get(struct i40e_hw *hw, struct rte_eth_hash_filter_info *info)
9345 PMD_DRV_LOG(ERR, "Invalid pointer");
9349 switch (info->info_type) {
9350 case RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT:
9351 i40e_get_symmetric_hash_enable_per_port(hw,
9352 &(info->info.enable));
9354 case RTE_ETH_HASH_FILTER_GLOBAL_CONFIG:
9355 ret = i40e_get_hash_filter_global_config(hw,
9356 &(info->info.global_conf));
9359 PMD_DRV_LOG(ERR, "Hash filter info type (%d) not supported",
9369 i40e_hash_filter_set(struct i40e_hw *hw, struct rte_eth_hash_filter_info *info)
9374 PMD_DRV_LOG(ERR, "Invalid pointer");
9378 switch (info->info_type) {
9379 case RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT:
9380 i40e_set_symmetric_hash_enable_per_port(hw, info->info.enable);
9382 case RTE_ETH_HASH_FILTER_GLOBAL_CONFIG:
9383 ret = i40e_set_hash_filter_global_config(hw,
9384 &(info->info.global_conf));
9386 case RTE_ETH_HASH_FILTER_INPUT_SET_SELECT:
9387 ret = i40e_hash_filter_inset_select(hw,
9388 &(info->info.input_set_conf));
9392 PMD_DRV_LOG(ERR, "Hash filter info type (%d) not supported",
9401 /* Operations for hash function */
9403 i40e_hash_filter_ctrl(struct rte_eth_dev *dev,
9404 enum rte_filter_op filter_op,
9407 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
9410 switch (filter_op) {
9411 case RTE_ETH_FILTER_NOP:
9413 case RTE_ETH_FILTER_GET:
9414 ret = i40e_hash_filter_get(hw,
9415 (struct rte_eth_hash_filter_info *)arg);
9417 case RTE_ETH_FILTER_SET:
9418 ret = i40e_hash_filter_set(hw,
9419 (struct rte_eth_hash_filter_info *)arg);
9422 PMD_DRV_LOG(WARNING, "Filter operation (%d) not supported",
9431 /* Convert ethertype filter structure */
9433 i40e_ethertype_filter_convert(const struct rte_eth_ethertype_filter *input,
9434 struct i40e_ethertype_filter *filter)
9436 rte_memcpy(&filter->input.mac_addr, &input->mac_addr, ETHER_ADDR_LEN);
9437 filter->input.ether_type = input->ether_type;
9438 filter->flags = input->flags;
9439 filter->queue = input->queue;
9444 /* Check if there exists the ehtertype filter */
9445 struct i40e_ethertype_filter *
9446 i40e_sw_ethertype_filter_lookup(struct i40e_ethertype_rule *ethertype_rule,
9447 const struct i40e_ethertype_filter_input *input)
9451 ret = rte_hash_lookup(ethertype_rule->hash_table, (const void *)input);
9455 return ethertype_rule->hash_map[ret];
9458 /* Add ethertype filter in SW list */
9460 i40e_sw_ethertype_filter_insert(struct i40e_pf *pf,
9461 struct i40e_ethertype_filter *filter)
9463 struct i40e_ethertype_rule *rule = &pf->ethertype;
9466 ret = rte_hash_add_key(rule->hash_table, &filter->input);
9469 "Failed to insert ethertype filter"
9470 " to hash table %d!",
9474 rule->hash_map[ret] = filter;
9476 TAILQ_INSERT_TAIL(&rule->ethertype_list, filter, rules);
9481 /* Delete ethertype filter in SW list */
9483 i40e_sw_ethertype_filter_del(struct i40e_pf *pf,
9484 struct i40e_ethertype_filter_input *input)
9486 struct i40e_ethertype_rule *rule = &pf->ethertype;
9487 struct i40e_ethertype_filter *filter;
9490 ret = rte_hash_del_key(rule->hash_table, input);
9493 "Failed to delete ethertype filter"
9494 " to hash table %d!",
9498 filter = rule->hash_map[ret];
9499 rule->hash_map[ret] = NULL;
9501 TAILQ_REMOVE(&rule->ethertype_list, filter, rules);
9508 * Configure ethertype filter, which can director packet by filtering
9509 * with mac address and ether_type or only ether_type
9512 i40e_ethertype_filter_set(struct i40e_pf *pf,
9513 struct rte_eth_ethertype_filter *filter,
9516 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9517 struct i40e_ethertype_rule *ethertype_rule = &pf->ethertype;
9518 struct i40e_ethertype_filter *ethertype_filter, *node;
9519 struct i40e_ethertype_filter check_filter;
9520 struct i40e_control_filter_stats stats;
9524 if (filter->queue >= pf->dev_data->nb_rx_queues) {
9525 PMD_DRV_LOG(ERR, "Invalid queue ID");
9528 if (filter->ether_type == ETHER_TYPE_IPv4 ||
9529 filter->ether_type == ETHER_TYPE_IPv6) {
9531 "unsupported ether_type(0x%04x) in control packet filter.",
9532 filter->ether_type);
9535 if (filter->ether_type == ETHER_TYPE_VLAN)
9536 PMD_DRV_LOG(WARNING,
9537 "filter vlan ether_type in first tag is not supported.");
9539 /* Check if there is the filter in SW list */
9540 memset(&check_filter, 0, sizeof(check_filter));
9541 i40e_ethertype_filter_convert(filter, &check_filter);
9542 node = i40e_sw_ethertype_filter_lookup(ethertype_rule,
9543 &check_filter.input);
9545 PMD_DRV_LOG(ERR, "Conflict with existing ethertype rules!");
9549 if (!add && !node) {
9550 PMD_DRV_LOG(ERR, "There's no corresponding ethertype filter!");
9554 if (!(filter->flags & RTE_ETHTYPE_FLAGS_MAC))
9555 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
9556 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP)
9557 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
9558 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
9560 memset(&stats, 0, sizeof(stats));
9561 ret = i40e_aq_add_rem_control_packet_filter(hw,
9562 filter->mac_addr.addr_bytes,
9563 filter->ether_type, flags,
9565 filter->queue, add, &stats, NULL);
9568 "add/rem control packet filter, return %d, mac_etype_used = %u, etype_used = %u, mac_etype_free = %u, etype_free = %u",
9569 ret, stats.mac_etype_used, stats.etype_used,
9570 stats.mac_etype_free, stats.etype_free);
9574 /* Add or delete a filter in SW list */
9576 ethertype_filter = rte_zmalloc("ethertype_filter",
9577 sizeof(*ethertype_filter), 0);
9578 if (ethertype_filter == NULL) {
9579 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
9583 rte_memcpy(ethertype_filter, &check_filter,
9584 sizeof(check_filter));
9585 ret = i40e_sw_ethertype_filter_insert(pf, ethertype_filter);
9587 rte_free(ethertype_filter);
9589 ret = i40e_sw_ethertype_filter_del(pf, &node->input);
9596 * Handle operations for ethertype filter.
9599 i40e_ethertype_filter_handle(struct rte_eth_dev *dev,
9600 enum rte_filter_op filter_op,
9603 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
9606 if (filter_op == RTE_ETH_FILTER_NOP)
9610 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
9615 switch (filter_op) {
9616 case RTE_ETH_FILTER_ADD:
9617 ret = i40e_ethertype_filter_set(pf,
9618 (struct rte_eth_ethertype_filter *)arg,
9621 case RTE_ETH_FILTER_DELETE:
9622 ret = i40e_ethertype_filter_set(pf,
9623 (struct rte_eth_ethertype_filter *)arg,
9627 PMD_DRV_LOG(ERR, "unsupported operation %u", filter_op);
9635 i40e_dev_filter_ctrl(struct rte_eth_dev *dev,
9636 enum rte_filter_type filter_type,
9637 enum rte_filter_op filter_op,
9645 switch (filter_type) {
9646 case RTE_ETH_FILTER_NONE:
9647 /* For global configuration */
9648 ret = i40e_filter_ctrl_global_config(dev, filter_op, arg);
9650 case RTE_ETH_FILTER_HASH:
9651 ret = i40e_hash_filter_ctrl(dev, filter_op, arg);
9653 case RTE_ETH_FILTER_MACVLAN:
9654 ret = i40e_mac_filter_handle(dev, filter_op, arg);
9656 case RTE_ETH_FILTER_ETHERTYPE:
9657 ret = i40e_ethertype_filter_handle(dev, filter_op, arg);
9659 case RTE_ETH_FILTER_TUNNEL:
9660 ret = i40e_tunnel_filter_handle(dev, filter_op, arg);
9662 case RTE_ETH_FILTER_FDIR:
9663 ret = i40e_fdir_ctrl_func(dev, filter_op, arg);
9665 case RTE_ETH_FILTER_GENERIC:
9666 if (filter_op != RTE_ETH_FILTER_GET)
9668 *(const void **)arg = &i40e_flow_ops;
9671 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
9681 * Check and enable Extended Tag.
9682 * Enabling Extended Tag is important for 40G performance.
9685 i40e_enable_extended_tag(struct rte_eth_dev *dev)
9687 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
9691 ret = rte_pci_read_config(pci_dev, &buf, sizeof(buf),
9694 PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
9698 if (!(buf & PCI_DEV_CAP_EXT_TAG_MASK)) {
9699 PMD_DRV_LOG(ERR, "Does not support Extended Tag");
9704 ret = rte_pci_read_config(pci_dev, &buf, sizeof(buf),
9707 PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
9711 if (buf & PCI_DEV_CTRL_EXT_TAG_MASK) {
9712 PMD_DRV_LOG(DEBUG, "Extended Tag has already been enabled");
9715 buf |= PCI_DEV_CTRL_EXT_TAG_MASK;
9716 ret = rte_pci_write_config(pci_dev, &buf, sizeof(buf),
9719 PMD_DRV_LOG(ERR, "Failed to write PCI offset 0x%x",
9726 * As some registers wouldn't be reset unless a global hardware reset,
9727 * hardware initialization is needed to put those registers into an
9728 * expected initial state.
9731 i40e_hw_init(struct rte_eth_dev *dev)
9733 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
9735 i40e_enable_extended_tag(dev);
9737 /* clear the PF Queue Filter control register */
9738 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, 0);
9740 /* Disable symmetric hash per port */
9741 i40e_set_symmetric_hash_enable_per_port(hw, 0);
9745 * For X722 it is possible to have multiple pctypes mapped to the same flowtype
9746 * however this function will return only one highest pctype index,
9747 * which is not quite correct. This is known problem of i40e driver
9748 * and needs to be fixed later.
9750 enum i40e_filter_pctype
9751 i40e_flowtype_to_pctype(const struct i40e_adapter *adapter, uint16_t flow_type)
9754 uint64_t pctype_mask;
9756 if (flow_type < I40E_FLOW_TYPE_MAX) {
9757 pctype_mask = adapter->pctypes_tbl[flow_type];
9758 for (i = I40E_FILTER_PCTYPE_MAX - 1; i > 0; i--) {
9759 if (pctype_mask & (1ULL << i))
9760 return (enum i40e_filter_pctype)i;
9763 return I40E_FILTER_PCTYPE_INVALID;
9767 i40e_pctype_to_flowtype(const struct i40e_adapter *adapter,
9768 enum i40e_filter_pctype pctype)
9771 uint64_t pctype_mask = 1ULL << pctype;
9773 for (flowtype = RTE_ETH_FLOW_UNKNOWN + 1; flowtype < I40E_FLOW_TYPE_MAX;
9775 if (adapter->pctypes_tbl[flowtype] & pctype_mask)
9779 return RTE_ETH_FLOW_UNKNOWN;
9783 * On X710, performance number is far from the expectation on recent firmware
9784 * versions; on XL710, performance number is also far from the expectation on
9785 * recent firmware versions, if promiscuous mode is disabled, or promiscuous
9786 * mode is enabled and port MAC address is equal to the packet destination MAC
9787 * address. The fix for this issue may not be integrated in the following
9788 * firmware version. So the workaround in software driver is needed. It needs
9789 * to modify the initial values of 3 internal only registers for both X710 and
9790 * XL710. Note that the values for X710 or XL710 could be different, and the
9791 * workaround can be removed when it is fixed in firmware in the future.
9794 /* For both X710 and XL710 */
9795 #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1 0x10000200
9796 #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2 0x203F0200
9797 #define I40E_GL_SWR_PRI_JOIN_MAP_0 0x26CE00
9799 #define I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x011f0200
9800 #define I40E_GL_SWR_PRI_JOIN_MAP_2 0x26CE08
9803 #define I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE 0x20000200
9804 #define I40E_X722_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x013F0200
9807 #define I40E_GL_SWR_PM_UP_THR_EF_VALUE 0x03030303
9809 #define I40E_GL_SWR_PM_UP_THR_SF_VALUE 0x06060606
9810 #define I40E_GL_SWR_PM_UP_THR 0x269FBC
9813 i40e_dev_sync_phy_type(struct i40e_hw *hw)
9815 enum i40e_status_code status;
9816 struct i40e_aq_get_phy_abilities_resp phy_ab;
9820 status = i40e_aq_get_phy_capabilities(hw, false, true, &phy_ab,
9824 PMD_INIT_LOG(WARNING, "Failed to sync phy type: status=%d",
9827 rte_delay_us(100000);
9829 status = i40e_aq_get_phy_capabilities(hw, false,
9830 true, &phy_ab, NULL);
9838 i40e_configure_registers(struct i40e_hw *hw)
9844 {I40E_GL_SWR_PRI_JOIN_MAP_0, 0},
9845 {I40E_GL_SWR_PRI_JOIN_MAP_2, 0},
9846 {I40E_GL_SWR_PM_UP_THR, 0}, /* Compute value dynamically */
9852 for (i = 0; i < RTE_DIM(reg_table); i++) {
9853 if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_0) {
9854 if (hw->mac.type == I40E_MAC_X722) /* For X722 */
9856 I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE;
9857 else /* For X710/XL710/XXV710 */
9858 if (hw->aq.fw_maj_ver < 6)
9860 I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1;
9863 I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2;
9866 if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_2) {
9867 if (hw->mac.type == I40E_MAC_X722) /* For X722 */
9869 I40E_X722_GL_SWR_PRI_JOIN_MAP_2_VALUE;
9870 else /* For X710/XL710/XXV710 */
9872 I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE;
9875 if (reg_table[i].addr == I40E_GL_SWR_PM_UP_THR) {
9876 if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types) || /* For XL710 */
9877 I40E_PHY_TYPE_SUPPORT_25G(hw->phy.phy_types)) /* For XXV710 */
9879 I40E_GL_SWR_PM_UP_THR_SF_VALUE;
9882 I40E_GL_SWR_PM_UP_THR_EF_VALUE;
9885 ret = i40e_aq_debug_read_register(hw, reg_table[i].addr,
9888 PMD_DRV_LOG(ERR, "Failed to read from 0x%"PRIx32,
9892 PMD_DRV_LOG(DEBUG, "Read from 0x%"PRIx32": 0x%"PRIx64,
9893 reg_table[i].addr, reg);
9894 if (reg == reg_table[i].val)
9897 ret = i40e_aq_debug_write_register(hw, reg_table[i].addr,
9898 reg_table[i].val, NULL);
9901 "Failed to write 0x%"PRIx64" to the address of 0x%"PRIx32,
9902 reg_table[i].val, reg_table[i].addr);
9905 PMD_DRV_LOG(DEBUG, "Write 0x%"PRIx64" to the address of "
9906 "0x%"PRIx32, reg_table[i].val, reg_table[i].addr);
9910 #define I40E_VSI_TSR(_i) (0x00050800 + ((_i) * 4))
9911 #define I40E_VSI_TSR_QINQ_CONFIG 0xc030
9912 #define I40E_VSI_L2TAGSTXVALID(_i) (0x00042800 + ((_i) * 4))
9913 #define I40E_VSI_L2TAGSTXVALID_QINQ 0xab
9915 i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi)
9920 if (vsi->vsi_id >= I40E_MAX_NUM_VSIS) {
9921 PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
9925 /* Configure for double VLAN RX stripping */
9926 reg = I40E_READ_REG(hw, I40E_VSI_TSR(vsi->vsi_id));
9927 if ((reg & I40E_VSI_TSR_QINQ_CONFIG) != I40E_VSI_TSR_QINQ_CONFIG) {
9928 reg |= I40E_VSI_TSR_QINQ_CONFIG;
9929 ret = i40e_aq_debug_write_register(hw,
9930 I40E_VSI_TSR(vsi->vsi_id),
9933 PMD_DRV_LOG(ERR, "Failed to update VSI_TSR[%d]",
9935 return I40E_ERR_CONFIG;
9939 /* Configure for double VLAN TX insertion */
9940 reg = I40E_READ_REG(hw, I40E_VSI_L2TAGSTXVALID(vsi->vsi_id));
9941 if ((reg & 0xff) != I40E_VSI_L2TAGSTXVALID_QINQ) {
9942 reg = I40E_VSI_L2TAGSTXVALID_QINQ;
9943 ret = i40e_aq_debug_write_register(hw,
9944 I40E_VSI_L2TAGSTXVALID(
9945 vsi->vsi_id), reg, NULL);
9948 "Failed to update VSI_L2TAGSTXVALID[%d]",
9950 return I40E_ERR_CONFIG;
9958 * i40e_aq_add_mirror_rule
9959 * @hw: pointer to the hardware structure
9960 * @seid: VEB seid to add mirror rule to
9961 * @dst_id: destination vsi seid
9962 * @entries: Buffer which contains the entities to be mirrored
9963 * @count: number of entities contained in the buffer
9964 * @rule_id:the rule_id of the rule to be added
9966 * Add a mirror rule for a given veb.
9969 static enum i40e_status_code
9970 i40e_aq_add_mirror_rule(struct i40e_hw *hw,
9971 uint16_t seid, uint16_t dst_id,
9972 uint16_t rule_type, uint16_t *entries,
9973 uint16_t count, uint16_t *rule_id)
9975 struct i40e_aq_desc desc;
9976 struct i40e_aqc_add_delete_mirror_rule cmd;
9977 struct i40e_aqc_add_delete_mirror_rule_completion *resp =
9978 (struct i40e_aqc_add_delete_mirror_rule_completion *)
9981 enum i40e_status_code status;
9983 i40e_fill_default_direct_cmd_desc(&desc,
9984 i40e_aqc_opc_add_mirror_rule);
9985 memset(&cmd, 0, sizeof(cmd));
9987 buff_len = sizeof(uint16_t) * count;
9988 desc.datalen = rte_cpu_to_le_16(buff_len);
9990 desc.flags |= rte_cpu_to_le_16(
9991 (uint16_t)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
9992 cmd.rule_type = rte_cpu_to_le_16(rule_type <<
9993 I40E_AQC_MIRROR_RULE_TYPE_SHIFT);
9994 cmd.num_entries = rte_cpu_to_le_16(count);
9995 cmd.seid = rte_cpu_to_le_16(seid);
9996 cmd.destination = rte_cpu_to_le_16(dst_id);
9998 rte_memcpy(&desc.params.raw, &cmd, sizeof(cmd));
9999 status = i40e_asq_send_command(hw, &desc, entries, buff_len, NULL);
10001 "i40e_aq_add_mirror_rule, aq_status %d, rule_id = %u mirror_rules_used = %u, mirror_rules_free = %u,",
10002 hw->aq.asq_last_status, resp->rule_id,
10003 resp->mirror_rules_used, resp->mirror_rules_free);
10004 *rule_id = rte_le_to_cpu_16(resp->rule_id);
10010 * i40e_aq_del_mirror_rule
10011 * @hw: pointer to the hardware structure
10012 * @seid: VEB seid to add mirror rule to
10013 * @entries: Buffer which contains the entities to be mirrored
10014 * @count: number of entities contained in the buffer
10015 * @rule_id:the rule_id of the rule to be delete
10017 * Delete a mirror rule for a given veb.
10020 static enum i40e_status_code
10021 i40e_aq_del_mirror_rule(struct i40e_hw *hw,
10022 uint16_t seid, uint16_t rule_type, uint16_t *entries,
10023 uint16_t count, uint16_t rule_id)
10025 struct i40e_aq_desc desc;
10026 struct i40e_aqc_add_delete_mirror_rule cmd;
10027 uint16_t buff_len = 0;
10028 enum i40e_status_code status;
10031 i40e_fill_default_direct_cmd_desc(&desc,
10032 i40e_aqc_opc_delete_mirror_rule);
10033 memset(&cmd, 0, sizeof(cmd));
10034 if (rule_type == I40E_AQC_MIRROR_RULE_TYPE_VLAN) {
10035 desc.flags |= rte_cpu_to_le_16((uint16_t)(I40E_AQ_FLAG_BUF |
10037 cmd.num_entries = count;
10038 buff_len = sizeof(uint16_t) * count;
10039 desc.datalen = rte_cpu_to_le_16(buff_len);
10040 buff = (void *)entries;
10042 /* rule id is filled in destination field for deleting mirror rule */
10043 cmd.destination = rte_cpu_to_le_16(rule_id);
10045 cmd.rule_type = rte_cpu_to_le_16(rule_type <<
10046 I40E_AQC_MIRROR_RULE_TYPE_SHIFT);
10047 cmd.seid = rte_cpu_to_le_16(seid);
10049 rte_memcpy(&desc.params.raw, &cmd, sizeof(cmd));
10050 status = i40e_asq_send_command(hw, &desc, buff, buff_len, NULL);
10056 * i40e_mirror_rule_set
10057 * @dev: pointer to the hardware structure
10058 * @mirror_conf: mirror rule info
10059 * @sw_id: mirror rule's sw_id
10060 * @on: enable/disable
10062 * set a mirror rule.
10066 i40e_mirror_rule_set(struct rte_eth_dev *dev,
10067 struct rte_eth_mirror_conf *mirror_conf,
10068 uint8_t sw_id, uint8_t on)
10070 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
10071 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10072 struct i40e_mirror_rule *it, *mirr_rule = NULL;
10073 struct i40e_mirror_rule *parent = NULL;
10074 uint16_t seid, dst_seid, rule_id;
10078 PMD_DRV_LOG(DEBUG, "i40e_mirror_rule_set: sw_id = %d.", sw_id);
10080 if (pf->main_vsi->veb == NULL || pf->vfs == NULL) {
10082 "mirror rule can not be configured without veb or vfs.");
10085 if (pf->nb_mirror_rule > I40E_MAX_MIRROR_RULES) {
10086 PMD_DRV_LOG(ERR, "mirror table is full.");
10089 if (mirror_conf->dst_pool > pf->vf_num) {
10090 PMD_DRV_LOG(ERR, "invalid destination pool %u.",
10091 mirror_conf->dst_pool);
10095 seid = pf->main_vsi->veb->seid;
10097 TAILQ_FOREACH(it, &pf->mirror_list, rules) {
10098 if (sw_id <= it->index) {
10104 if (mirr_rule && sw_id == mirr_rule->index) {
10106 PMD_DRV_LOG(ERR, "mirror rule exists.");
10109 ret = i40e_aq_del_mirror_rule(hw, seid,
10110 mirr_rule->rule_type,
10111 mirr_rule->entries,
10112 mirr_rule->num_entries, mirr_rule->id);
10115 "failed to remove mirror rule: ret = %d, aq_err = %d.",
10116 ret, hw->aq.asq_last_status);
10119 TAILQ_REMOVE(&pf->mirror_list, mirr_rule, rules);
10120 rte_free(mirr_rule);
10121 pf->nb_mirror_rule--;
10125 PMD_DRV_LOG(ERR, "mirror rule doesn't exist.");
10129 mirr_rule = rte_zmalloc("i40e_mirror_rule",
10130 sizeof(struct i40e_mirror_rule) , 0);
10132 PMD_DRV_LOG(ERR, "failed to allocate memory");
10133 return I40E_ERR_NO_MEMORY;
10135 switch (mirror_conf->rule_type) {
10136 case ETH_MIRROR_VLAN:
10137 for (i = 0, j = 0; i < ETH_MIRROR_MAX_VLANS; i++) {
10138 if (mirror_conf->vlan.vlan_mask & (1ULL << i)) {
10139 mirr_rule->entries[j] =
10140 mirror_conf->vlan.vlan_id[i];
10145 PMD_DRV_LOG(ERR, "vlan is not specified.");
10146 rte_free(mirr_rule);
10149 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_VLAN;
10151 case ETH_MIRROR_VIRTUAL_POOL_UP:
10152 case ETH_MIRROR_VIRTUAL_POOL_DOWN:
10153 /* check if the specified pool bit is out of range */
10154 if (mirror_conf->pool_mask > (uint64_t)(1ULL << (pf->vf_num + 1))) {
10155 PMD_DRV_LOG(ERR, "pool mask is out of range.");
10156 rte_free(mirr_rule);
10159 for (i = 0, j = 0; i < pf->vf_num; i++) {
10160 if (mirror_conf->pool_mask & (1ULL << i)) {
10161 mirr_rule->entries[j] = pf->vfs[i].vsi->seid;
10165 if (mirror_conf->pool_mask & (1ULL << pf->vf_num)) {
10166 /* add pf vsi to entries */
10167 mirr_rule->entries[j] = pf->main_vsi_seid;
10171 PMD_DRV_LOG(ERR, "pool is not specified.");
10172 rte_free(mirr_rule);
10175 /* egress and ingress in aq commands means from switch but not port */
10176 mirr_rule->rule_type =
10177 (mirror_conf->rule_type == ETH_MIRROR_VIRTUAL_POOL_UP) ?
10178 I40E_AQC_MIRROR_RULE_TYPE_VPORT_EGRESS :
10179 I40E_AQC_MIRROR_RULE_TYPE_VPORT_INGRESS;
10181 case ETH_MIRROR_UPLINK_PORT:
10182 /* egress and ingress in aq commands means from switch but not port*/
10183 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_ALL_EGRESS;
10185 case ETH_MIRROR_DOWNLINK_PORT:
10186 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_ALL_INGRESS;
10189 PMD_DRV_LOG(ERR, "unsupported mirror type %d.",
10190 mirror_conf->rule_type);
10191 rte_free(mirr_rule);
10195 /* If the dst_pool is equal to vf_num, consider it as PF */
10196 if (mirror_conf->dst_pool == pf->vf_num)
10197 dst_seid = pf->main_vsi_seid;
10199 dst_seid = pf->vfs[mirror_conf->dst_pool].vsi->seid;
10201 ret = i40e_aq_add_mirror_rule(hw, seid, dst_seid,
10202 mirr_rule->rule_type, mirr_rule->entries,
10206 "failed to add mirror rule: ret = %d, aq_err = %d.",
10207 ret, hw->aq.asq_last_status);
10208 rte_free(mirr_rule);
10212 mirr_rule->index = sw_id;
10213 mirr_rule->num_entries = j;
10214 mirr_rule->id = rule_id;
10215 mirr_rule->dst_vsi_seid = dst_seid;
10218 TAILQ_INSERT_AFTER(&pf->mirror_list, parent, mirr_rule, rules);
10220 TAILQ_INSERT_HEAD(&pf->mirror_list, mirr_rule, rules);
10222 pf->nb_mirror_rule++;
10227 * i40e_mirror_rule_reset
10228 * @dev: pointer to the device
10229 * @sw_id: mirror rule's sw_id
10231 * reset a mirror rule.
10235 i40e_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t sw_id)
10237 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
10238 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10239 struct i40e_mirror_rule *it, *mirr_rule = NULL;
10243 PMD_DRV_LOG(DEBUG, "i40e_mirror_rule_reset: sw_id = %d.", sw_id);
10245 seid = pf->main_vsi->veb->seid;
10247 TAILQ_FOREACH(it, &pf->mirror_list, rules) {
10248 if (sw_id == it->index) {
10254 ret = i40e_aq_del_mirror_rule(hw, seid,
10255 mirr_rule->rule_type,
10256 mirr_rule->entries,
10257 mirr_rule->num_entries, mirr_rule->id);
10260 "failed to remove mirror rule: status = %d, aq_err = %d.",
10261 ret, hw->aq.asq_last_status);
10264 TAILQ_REMOVE(&pf->mirror_list, mirr_rule, rules);
10265 rte_free(mirr_rule);
10266 pf->nb_mirror_rule--;
10268 PMD_DRV_LOG(ERR, "mirror rule doesn't exist.");
10275 i40e_read_systime_cyclecounter(struct rte_eth_dev *dev)
10277 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10278 uint64_t systim_cycles;
10280 systim_cycles = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_L);
10281 systim_cycles |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_H)
10284 return systim_cycles;
10288 i40e_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev, uint8_t index)
10290 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10291 uint64_t rx_tstamp;
10293 rx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_L(index));
10294 rx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(index))
10301 i40e_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
10303 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10304 uint64_t tx_tstamp;
10306 tx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_L);
10307 tx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H)
10314 i40e_start_timecounters(struct rte_eth_dev *dev)
10316 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10317 struct i40e_adapter *adapter =
10318 (struct i40e_adapter *)dev->data->dev_private;
10319 struct rte_eth_link link;
10320 uint32_t tsync_inc_l;
10321 uint32_t tsync_inc_h;
10323 /* Get current link speed. */
10324 memset(&link, 0, sizeof(link));
10325 i40e_dev_link_update(dev, 1);
10326 rte_i40e_dev_atomic_read_link_status(dev, &link);
10328 switch (link.link_speed) {
10329 case ETH_SPEED_NUM_40G:
10330 tsync_inc_l = I40E_PTP_40GB_INCVAL & 0xFFFFFFFF;
10331 tsync_inc_h = I40E_PTP_40GB_INCVAL >> 32;
10333 case ETH_SPEED_NUM_10G:
10334 tsync_inc_l = I40E_PTP_10GB_INCVAL & 0xFFFFFFFF;
10335 tsync_inc_h = I40E_PTP_10GB_INCVAL >> 32;
10337 case ETH_SPEED_NUM_1G:
10338 tsync_inc_l = I40E_PTP_1GB_INCVAL & 0xFFFFFFFF;
10339 tsync_inc_h = I40E_PTP_1GB_INCVAL >> 32;
10346 /* Set the timesync increment value. */
10347 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, tsync_inc_l);
10348 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, tsync_inc_h);
10350 memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
10351 memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
10352 memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
10354 adapter->systime_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10355 adapter->systime_tc.cc_shift = 0;
10356 adapter->systime_tc.nsec_mask = 0;
10358 adapter->rx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10359 adapter->rx_tstamp_tc.cc_shift = 0;
10360 adapter->rx_tstamp_tc.nsec_mask = 0;
10362 adapter->tx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10363 adapter->tx_tstamp_tc.cc_shift = 0;
10364 adapter->tx_tstamp_tc.nsec_mask = 0;
10368 i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
10370 struct i40e_adapter *adapter =
10371 (struct i40e_adapter *)dev->data->dev_private;
10373 adapter->systime_tc.nsec += delta;
10374 adapter->rx_tstamp_tc.nsec += delta;
10375 adapter->tx_tstamp_tc.nsec += delta;
10381 i40e_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
10384 struct i40e_adapter *adapter =
10385 (struct i40e_adapter *)dev->data->dev_private;
10387 ns = rte_timespec_to_ns(ts);
10389 /* Set the timecounters to a new value. */
10390 adapter->systime_tc.nsec = ns;
10391 adapter->rx_tstamp_tc.nsec = ns;
10392 adapter->tx_tstamp_tc.nsec = ns;
10398 i40e_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
10400 uint64_t ns, systime_cycles;
10401 struct i40e_adapter *adapter =
10402 (struct i40e_adapter *)dev->data->dev_private;
10404 systime_cycles = i40e_read_systime_cyclecounter(dev);
10405 ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
10406 *ts = rte_ns_to_timespec(ns);
10412 i40e_timesync_enable(struct rte_eth_dev *dev)
10414 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10415 uint32_t tsync_ctl_l;
10416 uint32_t tsync_ctl_h;
10418 /* Stop the timesync system time. */
10419 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
10420 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
10421 /* Reset the timesync system time value. */
10422 I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_L, 0x0);
10423 I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_H, 0x0);
10425 i40e_start_timecounters(dev);
10427 /* Clear timesync registers. */
10428 I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
10429 I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H);
10430 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(0));
10431 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(1));
10432 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(2));
10433 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(3));
10435 /* Enable timestamping of PTP packets. */
10436 tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
10437 tsync_ctl_l |= I40E_PRTTSYN_TSYNENA;
10439 tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
10440 tsync_ctl_h |= I40E_PRTTSYN_TSYNENA;
10441 tsync_ctl_h |= I40E_PRTTSYN_TSYNTYPE;
10443 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
10444 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
10450 i40e_timesync_disable(struct rte_eth_dev *dev)
10452 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10453 uint32_t tsync_ctl_l;
10454 uint32_t tsync_ctl_h;
10456 /* Disable timestamping of transmitted PTP packets. */
10457 tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
10458 tsync_ctl_l &= ~I40E_PRTTSYN_TSYNENA;
10460 tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
10461 tsync_ctl_h &= ~I40E_PRTTSYN_TSYNENA;
10463 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
10464 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
10466 /* Reset the timesync increment value. */
10467 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
10468 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
10474 i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
10475 struct timespec *timestamp, uint32_t flags)
10477 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10478 struct i40e_adapter *adapter =
10479 (struct i40e_adapter *)dev->data->dev_private;
10481 uint32_t sync_status;
10482 uint32_t index = flags & 0x03;
10483 uint64_t rx_tstamp_cycles;
10486 sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_1);
10487 if ((sync_status & (1 << index)) == 0)
10490 rx_tstamp_cycles = i40e_read_rx_tstamp_cyclecounter(dev, index);
10491 ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
10492 *timestamp = rte_ns_to_timespec(ns);
10498 i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
10499 struct timespec *timestamp)
10501 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10502 struct i40e_adapter *adapter =
10503 (struct i40e_adapter *)dev->data->dev_private;
10505 uint32_t sync_status;
10506 uint64_t tx_tstamp_cycles;
10509 sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
10510 if ((sync_status & I40E_PRTTSYN_STAT_0_TXTIME_MASK) == 0)
10513 tx_tstamp_cycles = i40e_read_tx_tstamp_cyclecounter(dev);
10514 ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
10515 *timestamp = rte_ns_to_timespec(ns);
10521 * i40e_parse_dcb_configure - parse dcb configure from user
10522 * @dev: the device being configured
10523 * @dcb_cfg: pointer of the result of parse
10524 * @*tc_map: bit map of enabled traffic classes
10526 * Returns 0 on success, negative value on failure
10529 i40e_parse_dcb_configure(struct rte_eth_dev *dev,
10530 struct i40e_dcbx_config *dcb_cfg,
10533 struct rte_eth_dcb_rx_conf *dcb_rx_conf;
10534 uint8_t i, tc_bw, bw_lf;
10536 memset(dcb_cfg, 0, sizeof(struct i40e_dcbx_config));
10538 dcb_rx_conf = &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
10539 if (dcb_rx_conf->nb_tcs > I40E_MAX_TRAFFIC_CLASS) {
10540 PMD_INIT_LOG(ERR, "number of tc exceeds max.");
10544 /* assume each tc has the same bw */
10545 tc_bw = I40E_MAX_PERCENT / dcb_rx_conf->nb_tcs;
10546 for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
10547 dcb_cfg->etscfg.tcbwtable[i] = tc_bw;
10548 /* to ensure the sum of tcbw is equal to 100 */
10549 bw_lf = I40E_MAX_PERCENT % dcb_rx_conf->nb_tcs;
10550 for (i = 0; i < bw_lf; i++)
10551 dcb_cfg->etscfg.tcbwtable[i]++;
10553 /* assume each tc has the same Transmission Selection Algorithm */
10554 for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
10555 dcb_cfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
10557 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
10558 dcb_cfg->etscfg.prioritytable[i] =
10559 dcb_rx_conf->dcb_tc[i];
10561 /* FW needs one App to configure HW */
10562 dcb_cfg->numapps = I40E_DEFAULT_DCB_APP_NUM;
10563 dcb_cfg->app[0].selector = I40E_APP_SEL_ETHTYPE;
10564 dcb_cfg->app[0].priority = I40E_DEFAULT_DCB_APP_PRIO;
10565 dcb_cfg->app[0].protocolid = I40E_APP_PROTOID_FCOE;
10567 if (dcb_rx_conf->nb_tcs == 0)
10568 *tc_map = 1; /* tc0 only */
10570 *tc_map = RTE_LEN2MASK(dcb_rx_conf->nb_tcs, uint8_t);
10572 if (dev->data->dev_conf.dcb_capability_en & ETH_DCB_PFC_SUPPORT) {
10573 dcb_cfg->pfc.willing = 0;
10574 dcb_cfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
10575 dcb_cfg->pfc.pfcenable = *tc_map;
10581 static enum i40e_status_code
10582 i40e_vsi_update_queue_mapping(struct i40e_vsi *vsi,
10583 struct i40e_aqc_vsi_properties_data *info,
10584 uint8_t enabled_tcmap)
10586 enum i40e_status_code ret;
10587 int i, total_tc = 0;
10588 uint16_t qpnum_per_tc, bsf, qp_idx;
10589 struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(vsi);
10590 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
10591 uint16_t used_queues;
10593 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
10594 if (ret != I40E_SUCCESS)
10597 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10598 if (enabled_tcmap & (1 << i))
10603 vsi->enabled_tc = enabled_tcmap;
10605 /* different VSI has different queues assigned */
10606 if (vsi->type == I40E_VSI_MAIN)
10607 used_queues = dev_data->nb_rx_queues -
10608 pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
10609 else if (vsi->type == I40E_VSI_VMDQ2)
10610 used_queues = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
10612 PMD_INIT_LOG(ERR, "unsupported VSI type.");
10613 return I40E_ERR_NO_AVAILABLE_VSI;
10616 qpnum_per_tc = used_queues / total_tc;
10617 /* Number of queues per enabled TC */
10618 if (qpnum_per_tc == 0) {
10619 PMD_INIT_LOG(ERR, " number of queues is less that tcs.");
10620 return I40E_ERR_INVALID_QP_ID;
10622 qpnum_per_tc = RTE_MIN(i40e_align_floor(qpnum_per_tc),
10623 I40E_MAX_Q_PER_TC);
10624 bsf = rte_bsf32(qpnum_per_tc);
10627 * Configure TC and queue mapping parameters, for enabled TC,
10628 * allocate qpnum_per_tc queues to this traffic. For disabled TC,
10629 * default queue will serve it.
10632 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10633 if (vsi->enabled_tc & (1 << i)) {
10634 info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
10635 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
10636 (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
10637 qp_idx += qpnum_per_tc;
10639 info->tc_mapping[i] = 0;
10642 /* Associate queue number with VSI, Keep vsi->nb_qps unchanged */
10643 if (vsi->type == I40E_VSI_SRIOV) {
10644 info->mapping_flags |=
10645 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
10646 for (i = 0; i < vsi->nb_qps; i++)
10647 info->queue_mapping[i] =
10648 rte_cpu_to_le_16(vsi->base_queue + i);
10650 info->mapping_flags |=
10651 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
10652 info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
10654 info->valid_sections |=
10655 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
10657 return I40E_SUCCESS;
10661 * i40e_config_switch_comp_tc - Configure VEB tc setting for given TC map
10662 * @veb: VEB to be configured
10663 * @tc_map: enabled TC bitmap
10665 * Returns 0 on success, negative value on failure
10667 static enum i40e_status_code
10668 i40e_config_switch_comp_tc(struct i40e_veb *veb, uint8_t tc_map)
10670 struct i40e_aqc_configure_switching_comp_bw_config_data veb_bw;
10671 struct i40e_aqc_query_switching_comp_bw_config_resp bw_query;
10672 struct i40e_aqc_query_switching_comp_ets_config_resp ets_query;
10673 struct i40e_hw *hw = I40E_VSI_TO_HW(veb->associate_vsi);
10674 enum i40e_status_code ret = I40E_SUCCESS;
10678 /* Check if enabled_tc is same as existing or new TCs */
10679 if (veb->enabled_tc == tc_map)
10682 /* configure tc bandwidth */
10683 memset(&veb_bw, 0, sizeof(veb_bw));
10684 veb_bw.tc_valid_bits = tc_map;
10685 /* Enable ETS TCs with equal BW Share for now across all VSIs */
10686 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10687 if (tc_map & BIT_ULL(i))
10688 veb_bw.tc_bw_share_credits[i] = 1;
10690 ret = i40e_aq_config_switch_comp_bw_config(hw, veb->seid,
10694 "AQ command Config switch_comp BW allocation per TC failed = %d",
10695 hw->aq.asq_last_status);
10699 memset(&ets_query, 0, sizeof(ets_query));
10700 ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
10702 if (ret != I40E_SUCCESS) {
10704 "Failed to get switch_comp ETS configuration %u",
10705 hw->aq.asq_last_status);
10708 memset(&bw_query, 0, sizeof(bw_query));
10709 ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
10711 if (ret != I40E_SUCCESS) {
10713 "Failed to get switch_comp bandwidth configuration %u",
10714 hw->aq.asq_last_status);
10718 /* store and print out BW info */
10719 veb->bw_info.bw_limit = rte_le_to_cpu_16(ets_query.port_bw_limit);
10720 veb->bw_info.bw_max = ets_query.tc_bw_max;
10721 PMD_DRV_LOG(DEBUG, "switch_comp bw limit:%u", veb->bw_info.bw_limit);
10722 PMD_DRV_LOG(DEBUG, "switch_comp max_bw:%u", veb->bw_info.bw_max);
10723 bw_max = rte_le_to_cpu_16(bw_query.tc_bw_max[0]) |
10724 (rte_le_to_cpu_16(bw_query.tc_bw_max[1]) <<
10725 I40E_16_BIT_WIDTH);
10726 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10727 veb->bw_info.bw_ets_share_credits[i] =
10728 bw_query.tc_bw_share_credits[i];
10729 veb->bw_info.bw_ets_credits[i] =
10730 rte_le_to_cpu_16(bw_query.tc_bw_limits[i]);
10731 /* 4 bits per TC, 4th bit is reserved */
10732 veb->bw_info.bw_ets_max[i] =
10733 (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
10734 RTE_LEN2MASK(3, uint8_t));
10735 PMD_DRV_LOG(DEBUG, "\tVEB TC%u:share credits %u", i,
10736 veb->bw_info.bw_ets_share_credits[i]);
10737 PMD_DRV_LOG(DEBUG, "\tVEB TC%u:credits %u", i,
10738 veb->bw_info.bw_ets_credits[i]);
10739 PMD_DRV_LOG(DEBUG, "\tVEB TC%u: max credits: %u", i,
10740 veb->bw_info.bw_ets_max[i]);
10743 veb->enabled_tc = tc_map;
10750 * i40e_vsi_config_tc - Configure VSI tc setting for given TC map
10751 * @vsi: VSI to be configured
10752 * @tc_map: enabled TC bitmap
10754 * Returns 0 on success, negative value on failure
10756 static enum i40e_status_code
10757 i40e_vsi_config_tc(struct i40e_vsi *vsi, uint8_t tc_map)
10759 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
10760 struct i40e_vsi_context ctxt;
10761 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
10762 enum i40e_status_code ret = I40E_SUCCESS;
10765 /* Check if enabled_tc is same as existing or new TCs */
10766 if (vsi->enabled_tc == tc_map)
10769 /* configure tc bandwidth */
10770 memset(&bw_data, 0, sizeof(bw_data));
10771 bw_data.tc_valid_bits = tc_map;
10772 /* Enable ETS TCs with equal BW Share for now across all VSIs */
10773 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10774 if (tc_map & BIT_ULL(i))
10775 bw_data.tc_bw_credits[i] = 1;
10777 ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &bw_data, NULL);
10780 "AQ command Config VSI BW allocation per TC failed = %d",
10781 hw->aq.asq_last_status);
10784 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
10785 vsi->info.qs_handle[i] = bw_data.qs_handles[i];
10787 /* Update Queue Pairs Mapping for currently enabled UPs */
10788 ctxt.seid = vsi->seid;
10789 ctxt.pf_num = hw->pf_id;
10791 ctxt.uplink_seid = vsi->uplink_seid;
10792 ctxt.info = vsi->info;
10794 ret = i40e_vsi_update_queue_mapping(vsi, &ctxt.info, tc_map);
10798 /* Update the VSI after updating the VSI queue-mapping information */
10799 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
10801 PMD_INIT_LOG(ERR, "Failed to configure TC queue mapping = %d",
10802 hw->aq.asq_last_status);
10805 /* update the local VSI info with updated queue map */
10806 rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
10807 sizeof(vsi->info.tc_mapping));
10808 rte_memcpy(&vsi->info.queue_mapping,
10809 &ctxt.info.queue_mapping,
10810 sizeof(vsi->info.queue_mapping));
10811 vsi->info.mapping_flags = ctxt.info.mapping_flags;
10812 vsi->info.valid_sections = 0;
10814 /* query and update current VSI BW information */
10815 ret = i40e_vsi_get_bw_config(vsi);
10818 "Failed updating vsi bw info, err %s aq_err %s",
10819 i40e_stat_str(hw, ret),
10820 i40e_aq_str(hw, hw->aq.asq_last_status));
10824 vsi->enabled_tc = tc_map;
10831 * i40e_dcb_hw_configure - program the dcb setting to hw
10832 * @pf: pf the configuration is taken on
10833 * @new_cfg: new configuration
10834 * @tc_map: enabled TC bitmap
10836 * Returns 0 on success, negative value on failure
10838 static enum i40e_status_code
10839 i40e_dcb_hw_configure(struct i40e_pf *pf,
10840 struct i40e_dcbx_config *new_cfg,
10843 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
10844 struct i40e_dcbx_config *old_cfg = &hw->local_dcbx_config;
10845 struct i40e_vsi *main_vsi = pf->main_vsi;
10846 struct i40e_vsi_list *vsi_list;
10847 enum i40e_status_code ret;
10851 /* Use the FW API if FW > v4.4*/
10852 if (!(((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver >= 4)) ||
10853 (hw->aq.fw_maj_ver >= 5))) {
10855 "FW < v4.4, can not use FW LLDP API to configure DCB");
10856 return I40E_ERR_FIRMWARE_API_VERSION;
10859 /* Check if need reconfiguration */
10860 if (!memcmp(new_cfg, old_cfg, sizeof(struct i40e_dcbx_config))) {
10861 PMD_INIT_LOG(ERR, "No Change in DCB Config required.");
10862 return I40E_SUCCESS;
10865 /* Copy the new config to the current config */
10866 *old_cfg = *new_cfg;
10867 old_cfg->etsrec = old_cfg->etscfg;
10868 ret = i40e_set_dcb_config(hw);
10870 PMD_INIT_LOG(ERR, "Set DCB Config failed, err %s aq_err %s",
10871 i40e_stat_str(hw, ret),
10872 i40e_aq_str(hw, hw->aq.asq_last_status));
10875 /* set receive Arbiter to RR mode and ETS scheme by default */
10876 for (i = 0; i <= I40E_PRTDCB_RETSTCC_MAX_INDEX; i++) {
10877 val = I40E_READ_REG(hw, I40E_PRTDCB_RETSTCC(i));
10878 val &= ~(I40E_PRTDCB_RETSTCC_BWSHARE_MASK |
10879 I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK |
10880 I40E_PRTDCB_RETSTCC_ETSTC_SHIFT);
10881 val |= ((uint32_t)old_cfg->etscfg.tcbwtable[i] <<
10882 I40E_PRTDCB_RETSTCC_BWSHARE_SHIFT) &
10883 I40E_PRTDCB_RETSTCC_BWSHARE_MASK;
10884 val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_UPINTC_MODE_SHIFT) &
10885 I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK;
10886 val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_ETSTC_SHIFT) &
10887 I40E_PRTDCB_RETSTCC_ETSTC_MASK;
10888 I40E_WRITE_REG(hw, I40E_PRTDCB_RETSTCC(i), val);
10890 /* get local mib to check whether it is configured correctly */
10892 hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_IEEE;
10893 /* Get Local DCB Config */
10894 i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
10895 &hw->local_dcbx_config);
10897 /* if Veb is created, need to update TC of it at first */
10898 if (main_vsi->veb) {
10899 ret = i40e_config_switch_comp_tc(main_vsi->veb, tc_map);
10901 PMD_INIT_LOG(WARNING,
10902 "Failed configuring TC for VEB seid=%d",
10903 main_vsi->veb->seid);
10905 /* Update each VSI */
10906 i40e_vsi_config_tc(main_vsi, tc_map);
10907 if (main_vsi->veb) {
10908 TAILQ_FOREACH(vsi_list, &main_vsi->veb->head, list) {
10909 /* Beside main VSI and VMDQ VSIs, only enable default
10910 * TC for other VSIs
10912 if (vsi_list->vsi->type == I40E_VSI_VMDQ2)
10913 ret = i40e_vsi_config_tc(vsi_list->vsi,
10916 ret = i40e_vsi_config_tc(vsi_list->vsi,
10917 I40E_DEFAULT_TCMAP);
10919 PMD_INIT_LOG(WARNING,
10920 "Failed configuring TC for VSI seid=%d",
10921 vsi_list->vsi->seid);
10925 return I40E_SUCCESS;
10929 * i40e_dcb_init_configure - initial dcb config
10930 * @dev: device being configured
10931 * @sw_dcb: indicate whether dcb is sw configured or hw offload
10933 * Returns 0 on success, negative value on failure
10936 i40e_dcb_init_configure(struct rte_eth_dev *dev, bool sw_dcb)
10938 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
10939 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10942 if ((pf->flags & I40E_FLAG_DCB) == 0) {
10943 PMD_INIT_LOG(ERR, "HW doesn't support DCB");
10947 /* DCB initialization:
10948 * Update DCB configuration from the Firmware and configure
10949 * LLDP MIB change event.
10951 if (sw_dcb == TRUE) {
10952 ret = i40e_init_dcb(hw);
10953 /* If lldp agent is stopped, the return value from
10954 * i40e_init_dcb we expect is failure with I40E_AQ_RC_EPERM
10955 * adminq status. Otherwise, it should return success.
10957 if ((ret == I40E_SUCCESS) || (ret != I40E_SUCCESS &&
10958 hw->aq.asq_last_status == I40E_AQ_RC_EPERM)) {
10959 memset(&hw->local_dcbx_config, 0,
10960 sizeof(struct i40e_dcbx_config));
10961 /* set dcb default configuration */
10962 hw->local_dcbx_config.etscfg.willing = 0;
10963 hw->local_dcbx_config.etscfg.maxtcs = 0;
10964 hw->local_dcbx_config.etscfg.tcbwtable[0] = 100;
10965 hw->local_dcbx_config.etscfg.tsatable[0] =
10967 /* all UPs mapping to TC0 */
10968 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
10969 hw->local_dcbx_config.etscfg.prioritytable[i] = 0;
10970 hw->local_dcbx_config.etsrec =
10971 hw->local_dcbx_config.etscfg;
10972 hw->local_dcbx_config.pfc.willing = 0;
10973 hw->local_dcbx_config.pfc.pfccap =
10974 I40E_MAX_TRAFFIC_CLASS;
10975 /* FW needs one App to configure HW */
10976 hw->local_dcbx_config.numapps = 1;
10977 hw->local_dcbx_config.app[0].selector =
10978 I40E_APP_SEL_ETHTYPE;
10979 hw->local_dcbx_config.app[0].priority = 3;
10980 hw->local_dcbx_config.app[0].protocolid =
10981 I40E_APP_PROTOID_FCOE;
10982 ret = i40e_set_dcb_config(hw);
10985 "default dcb config fails. err = %d, aq_err = %d.",
10986 ret, hw->aq.asq_last_status);
10991 "DCB initialization in FW fails, err = %d, aq_err = %d.",
10992 ret, hw->aq.asq_last_status);
10996 ret = i40e_aq_start_lldp(hw, NULL);
10997 if (ret != I40E_SUCCESS)
10998 PMD_INIT_LOG(DEBUG, "Failed to start lldp");
11000 ret = i40e_init_dcb(hw);
11002 if (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED) {
11004 "HW doesn't support DCBX offload.");
11009 "DCBX configuration failed, err = %d, aq_err = %d.",
11010 ret, hw->aq.asq_last_status);
11018 * i40e_dcb_setup - setup dcb related config
11019 * @dev: device being configured
11021 * Returns 0 on success, negative value on failure
11024 i40e_dcb_setup(struct rte_eth_dev *dev)
11026 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11027 struct i40e_dcbx_config dcb_cfg;
11028 uint8_t tc_map = 0;
11031 if ((pf->flags & I40E_FLAG_DCB) == 0) {
11032 PMD_INIT_LOG(ERR, "HW doesn't support DCB");
11036 if (pf->vf_num != 0)
11037 PMD_INIT_LOG(DEBUG, " DCB only works on pf and vmdq vsis.");
11039 ret = i40e_parse_dcb_configure(dev, &dcb_cfg, &tc_map);
11041 PMD_INIT_LOG(ERR, "invalid dcb config");
11044 ret = i40e_dcb_hw_configure(pf, &dcb_cfg, tc_map);
11046 PMD_INIT_LOG(ERR, "dcb sw configure fails");
11054 i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
11055 struct rte_eth_dcb_info *dcb_info)
11057 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11058 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11059 struct i40e_vsi *vsi = pf->main_vsi;
11060 struct i40e_dcbx_config *dcb_cfg = &hw->local_dcbx_config;
11061 uint16_t bsf, tc_mapping;
11064 if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_DCB_FLAG)
11065 dcb_info->nb_tcs = rte_bsf32(vsi->enabled_tc + 1);
11067 dcb_info->nb_tcs = 1;
11068 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
11069 dcb_info->prio_tc[i] = dcb_cfg->etscfg.prioritytable[i];
11070 for (i = 0; i < dcb_info->nb_tcs; i++)
11071 dcb_info->tc_bws[i] = dcb_cfg->etscfg.tcbwtable[i];
11073 /* get queue mapping if vmdq is disabled */
11074 if (!pf->nb_cfg_vmdq_vsi) {
11075 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11076 if (!(vsi->enabled_tc & (1 << i)))
11078 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
11079 dcb_info->tc_queue.tc_rxq[j][i].base =
11080 (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
11081 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
11082 dcb_info->tc_queue.tc_txq[j][i].base =
11083 dcb_info->tc_queue.tc_rxq[j][i].base;
11084 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
11085 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
11086 dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
11087 dcb_info->tc_queue.tc_txq[j][i].nb_queue =
11088 dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
11093 /* get queue mapping if vmdq is enabled */
11095 vsi = pf->vmdq[j].vsi;
11096 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11097 if (!(vsi->enabled_tc & (1 << i)))
11099 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
11100 dcb_info->tc_queue.tc_rxq[j][i].base =
11101 (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
11102 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
11103 dcb_info->tc_queue.tc_txq[j][i].base =
11104 dcb_info->tc_queue.tc_rxq[j][i].base;
11105 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
11106 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
11107 dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
11108 dcb_info->tc_queue.tc_txq[j][i].nb_queue =
11109 dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
11112 } while (j < RTE_MIN(pf->nb_cfg_vmdq_vsi, ETH_MAX_VMDQ_POOL));
11117 i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
11119 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
11120 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
11121 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11122 uint16_t msix_intr;
11124 msix_intr = intr_handle->intr_vec[queue_id];
11125 if (msix_intr == I40E_MISC_VEC_ID)
11126 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
11127 I40E_PFINT_DYN_CTL0_INTENA_MASK |
11128 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
11129 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
11132 I40E_PFINT_DYN_CTLN(msix_intr -
11133 I40E_RX_VEC_START),
11134 I40E_PFINT_DYN_CTLN_INTENA_MASK |
11135 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
11136 I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
11138 I40E_WRITE_FLUSH(hw);
11139 rte_intr_enable(&pci_dev->intr_handle);
11145 i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
11147 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
11148 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
11149 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11150 uint16_t msix_intr;
11152 msix_intr = intr_handle->intr_vec[queue_id];
11153 if (msix_intr == I40E_MISC_VEC_ID)
11154 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
11155 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
11158 I40E_PFINT_DYN_CTLN(msix_intr -
11159 I40E_RX_VEC_START),
11160 I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
11161 I40E_WRITE_FLUSH(hw);
11166 static int i40e_get_regs(struct rte_eth_dev *dev,
11167 struct rte_dev_reg_info *regs)
11169 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11170 uint32_t *ptr_data = regs->data;
11171 uint32_t reg_idx, arr_idx, arr_idx2, reg_offset;
11172 const struct i40e_reg_info *reg_info;
11174 if (ptr_data == NULL) {
11175 regs->length = I40E_GLGEN_STAT_CLEAR + 4;
11176 regs->width = sizeof(uint32_t);
11180 /* The first few registers have to be read using AQ operations */
11182 while (i40e_regs_adminq[reg_idx].name) {
11183 reg_info = &i40e_regs_adminq[reg_idx++];
11184 for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
11186 arr_idx2 <= reg_info->count2;
11188 reg_offset = arr_idx * reg_info->stride1 +
11189 arr_idx2 * reg_info->stride2;
11190 reg_offset += reg_info->base_addr;
11191 ptr_data[reg_offset >> 2] =
11192 i40e_read_rx_ctl(hw, reg_offset);
11196 /* The remaining registers can be read using primitives */
11198 while (i40e_regs_others[reg_idx].name) {
11199 reg_info = &i40e_regs_others[reg_idx++];
11200 for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
11202 arr_idx2 <= reg_info->count2;
11204 reg_offset = arr_idx * reg_info->stride1 +
11205 arr_idx2 * reg_info->stride2;
11206 reg_offset += reg_info->base_addr;
11207 ptr_data[reg_offset >> 2] =
11208 I40E_READ_REG(hw, reg_offset);
11215 static int i40e_get_eeprom_length(struct rte_eth_dev *dev)
11217 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11219 /* Convert word count to byte count */
11220 return hw->nvm.sr_size << 1;
11223 static int i40e_get_eeprom(struct rte_eth_dev *dev,
11224 struct rte_dev_eeprom_info *eeprom)
11226 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11227 uint16_t *data = eeprom->data;
11228 uint16_t offset, length, cnt_words;
11231 offset = eeprom->offset >> 1;
11232 length = eeprom->length >> 1;
11233 cnt_words = length;
11235 if (offset > hw->nvm.sr_size ||
11236 offset + length > hw->nvm.sr_size) {
11237 PMD_DRV_LOG(ERR, "Requested EEPROM bytes out of range.");
11241 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
11243 ret_code = i40e_read_nvm_buffer(hw, offset, &cnt_words, data);
11244 if (ret_code != I40E_SUCCESS || cnt_words != length) {
11245 PMD_DRV_LOG(ERR, "EEPROM read failed.");
11252 static void i40e_set_default_mac_addr(struct rte_eth_dev *dev,
11253 struct ether_addr *mac_addr)
11255 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11256 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11257 struct i40e_vsi *vsi = pf->main_vsi;
11258 struct i40e_mac_filter_info mac_filter;
11259 struct i40e_mac_filter *f;
11262 if (!is_valid_assigned_ether_addr(mac_addr)) {
11263 PMD_DRV_LOG(ERR, "Tried to set invalid MAC address.");
11267 TAILQ_FOREACH(f, &vsi->mac_list, next) {
11268 if (is_same_ether_addr(&pf->dev_addr, &f->mac_info.mac_addr))
11273 PMD_DRV_LOG(ERR, "Failed to find filter for default mac");
11277 mac_filter = f->mac_info;
11278 ret = i40e_vsi_delete_mac(vsi, &mac_filter.mac_addr);
11279 if (ret != I40E_SUCCESS) {
11280 PMD_DRV_LOG(ERR, "Failed to delete mac filter");
11283 memcpy(&mac_filter.mac_addr, mac_addr, ETH_ADDR_LEN);
11284 ret = i40e_vsi_add_mac(vsi, &mac_filter);
11285 if (ret != I40E_SUCCESS) {
11286 PMD_DRV_LOG(ERR, "Failed to add mac filter");
11289 memcpy(&pf->dev_addr, mac_addr, ETH_ADDR_LEN);
11291 i40e_aq_mac_address_write(hw, I40E_AQC_WRITE_TYPE_LAA_WOL,
11292 mac_addr->addr_bytes, NULL);
11296 i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
11298 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11299 struct rte_eth_dev_data *dev_data = pf->dev_data;
11300 uint32_t frame_size = mtu + I40E_ETH_OVERHEAD;
11303 /* check if mtu is within the allowed range */
11304 if ((mtu < ETHER_MIN_MTU) || (frame_size > I40E_FRAME_SIZE_MAX))
11307 /* mtu setting is forbidden if port is start */
11308 if (dev_data->dev_started) {
11309 PMD_DRV_LOG(ERR, "port %d must be stopped before configuration",
11310 dev_data->port_id);
11314 if (frame_size > ETHER_MAX_LEN)
11315 dev_data->dev_conf.rxmode.jumbo_frame = 1;
11317 dev_data->dev_conf.rxmode.jumbo_frame = 0;
11319 dev_data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
11324 /* Restore ethertype filter */
11326 i40e_ethertype_filter_restore(struct i40e_pf *pf)
11328 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11329 struct i40e_ethertype_filter_list
11330 *ethertype_list = &pf->ethertype.ethertype_list;
11331 struct i40e_ethertype_filter *f;
11332 struct i40e_control_filter_stats stats;
11335 TAILQ_FOREACH(f, ethertype_list, rules) {
11337 if (!(f->flags & RTE_ETHTYPE_FLAGS_MAC))
11338 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
11339 if (f->flags & RTE_ETHTYPE_FLAGS_DROP)
11340 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
11341 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
11343 memset(&stats, 0, sizeof(stats));
11344 i40e_aq_add_rem_control_packet_filter(hw,
11345 f->input.mac_addr.addr_bytes,
11346 f->input.ether_type,
11347 flags, pf->main_vsi->seid,
11348 f->queue, 1, &stats, NULL);
11350 PMD_DRV_LOG(INFO, "Ethertype filter:"
11351 " mac_etype_used = %u, etype_used = %u,"
11352 " mac_etype_free = %u, etype_free = %u",
11353 stats.mac_etype_used, stats.etype_used,
11354 stats.mac_etype_free, stats.etype_free);
11357 /* Restore tunnel filter */
11359 i40e_tunnel_filter_restore(struct i40e_pf *pf)
11361 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11362 struct i40e_vsi *vsi;
11363 struct i40e_pf_vf *vf;
11364 struct i40e_tunnel_filter_list
11365 *tunnel_list = &pf->tunnel.tunnel_list;
11366 struct i40e_tunnel_filter *f;
11367 struct i40e_aqc_add_rm_cloud_filt_elem_ext cld_filter;
11368 bool big_buffer = 0;
11370 TAILQ_FOREACH(f, tunnel_list, rules) {
11372 vsi = pf->main_vsi;
11374 vf = &pf->vfs[f->vf_id];
11377 memset(&cld_filter, 0, sizeof(cld_filter));
11378 ether_addr_copy((struct ether_addr *)&f->input.outer_mac,
11379 (struct ether_addr *)&cld_filter.element.outer_mac);
11380 ether_addr_copy((struct ether_addr *)&f->input.inner_mac,
11381 (struct ether_addr *)&cld_filter.element.inner_mac);
11382 cld_filter.element.inner_vlan = f->input.inner_vlan;
11383 cld_filter.element.flags = f->input.flags;
11384 cld_filter.element.tenant_id = f->input.tenant_id;
11385 cld_filter.element.queue_number = f->queue;
11386 rte_memcpy(cld_filter.general_fields,
11387 f->input.general_fields,
11388 sizeof(f->input.general_fields));
11390 if (((f->input.flags &
11391 I40E_AQC_ADD_CLOUD_FILTER_0X11) ==
11392 I40E_AQC_ADD_CLOUD_FILTER_0X11) ||
11394 I40E_AQC_ADD_CLOUD_FILTER_0X12) ==
11395 I40E_AQC_ADD_CLOUD_FILTER_0X12) ||
11397 I40E_AQC_ADD_CLOUD_FILTER_0X10) ==
11398 I40E_AQC_ADD_CLOUD_FILTER_0X10))
11402 i40e_aq_add_cloud_filters_big_buffer(hw,
11403 vsi->seid, &cld_filter, 1);
11405 i40e_aq_add_cloud_filters(hw, vsi->seid,
11406 &cld_filter.element, 1);
11410 /* Restore rss filter */
11412 i40e_rss_filter_restore(struct i40e_pf *pf)
11414 struct i40e_rte_flow_rss_conf *conf =
11417 i40e_config_rss_filter(pf, conf, TRUE);
11421 i40e_filter_restore(struct i40e_pf *pf)
11423 i40e_ethertype_filter_restore(pf);
11424 i40e_tunnel_filter_restore(pf);
11425 i40e_fdir_filter_restore(pf);
11426 i40e_rss_filter_restore(pf);
11430 is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
11432 if (strcmp(dev->device->driver->name, drv->driver.name))
11439 is_i40e_supported(struct rte_eth_dev *dev)
11441 return is_device_supported(dev, &rte_i40e_pmd);
11444 struct i40e_customized_pctype*
11445 i40e_find_customized_pctype(struct i40e_pf *pf, uint8_t index)
11449 for (i = 0; i < I40E_CUSTOMIZED_MAX; i++) {
11450 if (pf->customized_pctype[i].index == index)
11451 return &pf->customized_pctype[i];
11457 i40e_update_customized_pctype(struct rte_eth_dev *dev, uint8_t *pkg,
11458 uint32_t pkg_size, uint32_t proto_num,
11459 struct rte_pmd_i40e_proto_info *proto)
11461 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11462 uint32_t pctype_num;
11463 struct rte_pmd_i40e_ptype_info *pctype;
11464 uint32_t buff_size;
11465 struct i40e_customized_pctype *new_pctype = NULL;
11467 uint8_t pctype_value;
11472 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11473 (uint8_t *)&pctype_num, sizeof(pctype_num),
11474 RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
11476 PMD_DRV_LOG(ERR, "Failed to get pctype number");
11480 PMD_DRV_LOG(INFO, "No new pctype added");
11484 buff_size = pctype_num * sizeof(struct rte_pmd_i40e_proto_info);
11485 pctype = rte_zmalloc("new_pctype", buff_size, 0);
11487 PMD_DRV_LOG(ERR, "Failed to allocate memory");
11490 /* get information about new pctype list */
11491 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11492 (uint8_t *)pctype, buff_size,
11493 RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
11495 PMD_DRV_LOG(ERR, "Failed to get pctype list");
11500 /* Update customized pctype. */
11501 for (i = 0; i < pctype_num; i++) {
11502 pctype_value = pctype[i].ptype_id;
11503 memset(name, 0, sizeof(name));
11504 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
11505 proto_id = pctype[i].protocols[j];
11506 if (proto_id == RTE_PMD_I40E_PROTO_UNUSED)
11508 for (n = 0; n < proto_num; n++) {
11509 if (proto[n].proto_id != proto_id)
11511 strcat(name, proto[n].name);
11516 name[strlen(name) - 1] = '\0';
11517 if (!strcmp(name, "GTPC"))
11519 i40e_find_customized_pctype(pf,
11520 I40E_CUSTOMIZED_GTPC);
11521 else if (!strcmp(name, "GTPU_IPV4"))
11523 i40e_find_customized_pctype(pf,
11524 I40E_CUSTOMIZED_GTPU_IPV4);
11525 else if (!strcmp(name, "GTPU_IPV6"))
11527 i40e_find_customized_pctype(pf,
11528 I40E_CUSTOMIZED_GTPU_IPV6);
11529 else if (!strcmp(name, "GTPU"))
11531 i40e_find_customized_pctype(pf,
11532 I40E_CUSTOMIZED_GTPU);
11534 new_pctype->pctype = pctype_value;
11535 new_pctype->valid = true;
11544 i40e_update_customized_ptype(struct rte_eth_dev *dev, uint8_t *pkg,
11545 uint32_t pkg_size, uint32_t proto_num,
11546 struct rte_pmd_i40e_proto_info *proto)
11548 struct rte_pmd_i40e_ptype_mapping *ptype_mapping;
11549 uint16_t port_id = dev->data->port_id;
11550 uint32_t ptype_num;
11551 struct rte_pmd_i40e_ptype_info *ptype;
11552 uint32_t buff_size;
11554 char name[RTE_PMD_I40E_DDP_NAME_SIZE];
11559 /* get information about new ptype num */
11560 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11561 (uint8_t *)&ptype_num, sizeof(ptype_num),
11562 RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
11564 PMD_DRV_LOG(ERR, "Failed to get ptype number");
11568 PMD_DRV_LOG(INFO, "No new ptype added");
11572 buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
11573 ptype = rte_zmalloc("new_ptype", buff_size, 0);
11575 PMD_DRV_LOG(ERR, "Failed to allocate memory");
11579 /* get information about new ptype list */
11580 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11581 (uint8_t *)ptype, buff_size,
11582 RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
11584 PMD_DRV_LOG(ERR, "Failed to get ptype list");
11589 buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_mapping);
11590 ptype_mapping = rte_zmalloc("ptype_mapping", buff_size, 0);
11591 if (!ptype_mapping) {
11592 PMD_DRV_LOG(ERR, "Failed to allocate memory");
11597 /* Update ptype mapping table. */
11598 for (i = 0; i < ptype_num; i++) {
11599 ptype_mapping[i].hw_ptype = ptype[i].ptype_id;
11600 ptype_mapping[i].sw_ptype = 0;
11602 for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
11603 proto_id = ptype[i].protocols[j];
11604 if (proto_id == RTE_PMD_I40E_PROTO_UNUSED)
11606 for (n = 0; n < proto_num; n++) {
11607 if (proto[n].proto_id != proto_id)
11609 memset(name, 0, sizeof(name));
11610 strcpy(name, proto[n].name);
11611 if (!strncasecmp(name, "PPPOE", 5))
11612 ptype_mapping[i].sw_ptype |=
11613 RTE_PTYPE_L2_ETHER_PPPOE;
11614 else if (!strncasecmp(name, "IPV4FRAG", 8) &&
11616 ptype_mapping[i].sw_ptype |=
11617 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11618 ptype_mapping[i].sw_ptype |=
11620 } else if (!strncasecmp(name, "IPV4FRAG", 8) &&
11622 ptype_mapping[i].sw_ptype |=
11623 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
11624 ptype_mapping[i].sw_ptype |=
11625 RTE_PTYPE_INNER_L4_FRAG;
11626 } else if (!strncasecmp(name, "OIPV4", 5)) {
11627 ptype_mapping[i].sw_ptype |=
11628 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11630 } else if (!strncasecmp(name, "IPV4", 4) &&
11632 ptype_mapping[i].sw_ptype |=
11633 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11634 else if (!strncasecmp(name, "IPV4", 4) &&
11636 ptype_mapping[i].sw_ptype |=
11637 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
11638 else if (!strncasecmp(name, "IPV6FRAG", 8) &&
11640 ptype_mapping[i].sw_ptype |=
11641 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11642 ptype_mapping[i].sw_ptype |=
11644 } else if (!strncasecmp(name, "IPV6FRAG", 8) &&
11646 ptype_mapping[i].sw_ptype |=
11647 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
11648 ptype_mapping[i].sw_ptype |=
11649 RTE_PTYPE_INNER_L4_FRAG;
11650 } else if (!strncasecmp(name, "OIPV6", 5)) {
11651 ptype_mapping[i].sw_ptype |=
11652 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11654 } else if (!strncasecmp(name, "IPV6", 4) &&
11656 ptype_mapping[i].sw_ptype |=
11657 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11658 else if (!strncasecmp(name, "IPV6", 4) &&
11660 ptype_mapping[i].sw_ptype |=
11661 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
11662 else if (!strncasecmp(name, "UDP", 3) &&
11664 ptype_mapping[i].sw_ptype |=
11666 else if (!strncasecmp(name, "UDP", 3) &&
11668 ptype_mapping[i].sw_ptype |=
11669 RTE_PTYPE_INNER_L4_UDP;
11670 else if (!strncasecmp(name, "TCP", 3) &&
11672 ptype_mapping[i].sw_ptype |=
11674 else if (!strncasecmp(name, "TCP", 3) &&
11676 ptype_mapping[i].sw_ptype |=
11677 RTE_PTYPE_INNER_L4_TCP;
11678 else if (!strncasecmp(name, "SCTP", 4) &&
11680 ptype_mapping[i].sw_ptype |=
11682 else if (!strncasecmp(name, "SCTP", 4) &&
11684 ptype_mapping[i].sw_ptype |=
11685 RTE_PTYPE_INNER_L4_SCTP;
11686 else if ((!strncasecmp(name, "ICMP", 4) ||
11687 !strncasecmp(name, "ICMPV6", 6)) &&
11689 ptype_mapping[i].sw_ptype |=
11691 else if ((!strncasecmp(name, "ICMP", 4) ||
11692 !strncasecmp(name, "ICMPV6", 6)) &&
11694 ptype_mapping[i].sw_ptype |=
11695 RTE_PTYPE_INNER_L4_ICMP;
11696 else if (!strncasecmp(name, "GTPC", 4)) {
11697 ptype_mapping[i].sw_ptype |=
11698 RTE_PTYPE_TUNNEL_GTPC;
11700 } else if (!strncasecmp(name, "GTPU", 4)) {
11701 ptype_mapping[i].sw_ptype |=
11702 RTE_PTYPE_TUNNEL_GTPU;
11704 } else if (!strncasecmp(name, "GRENAT", 6)) {
11705 ptype_mapping[i].sw_ptype |=
11706 RTE_PTYPE_TUNNEL_GRENAT;
11708 } else if (!strncasecmp(name, "L2TPV2CTL", 9)) {
11709 ptype_mapping[i].sw_ptype |=
11710 RTE_PTYPE_TUNNEL_L2TP;
11719 ret = rte_pmd_i40e_ptype_mapping_update(port_id, ptype_mapping,
11722 PMD_DRV_LOG(ERR, "Failed to update mapping table.");
11724 rte_free(ptype_mapping);
11730 i40e_update_customized_info(struct rte_eth_dev *dev, uint8_t *pkg,
11733 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11734 uint32_t proto_num;
11735 struct rte_pmd_i40e_proto_info *proto;
11736 uint32_t buff_size;
11740 /* get information about protocol number */
11741 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11742 (uint8_t *)&proto_num, sizeof(proto_num),
11743 RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
11745 PMD_DRV_LOG(ERR, "Failed to get protocol number");
11749 PMD_DRV_LOG(INFO, "No new protocol added");
11753 buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
11754 proto = rte_zmalloc("new_proto", buff_size, 0);
11756 PMD_DRV_LOG(ERR, "Failed to allocate memory");
11760 /* get information about protocol list */
11761 ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11762 (uint8_t *)proto, buff_size,
11763 RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
11765 PMD_DRV_LOG(ERR, "Failed to get protocol list");
11770 /* Check if GTP is supported. */
11771 for (i = 0; i < proto_num; i++) {
11772 if (!strncmp(proto[i].name, "GTP", 3)) {
11773 pf->gtp_support = true;
11778 /* Update customized pctype info */
11779 ret = i40e_update_customized_pctype(dev, pkg, pkg_size,
11782 PMD_DRV_LOG(INFO, "No pctype is updated.");
11784 /* Update customized ptype info */
11785 ret = i40e_update_customized_ptype(dev, pkg, pkg_size,
11788 PMD_DRV_LOG(INFO, "No ptype is updated.");
11793 /* Create a QinQ cloud filter
11795 * The Fortville NIC has limited resources for tunnel filters,
11796 * so we can only reuse existing filters.
11798 * In step 1 we define which Field Vector fields can be used for
11800 * As we do not have the inner tag defined as a field,
11801 * we have to define it first, by reusing one of L1 entries.
11803 * In step 2 we are replacing one of existing filter types with
11804 * a new one for QinQ.
11805 * As we reusing L1 and replacing L2, some of the default filter
11806 * types will disappear,which depends on L1 and L2 entries we reuse.
11808 * Step 1: Create L1 filter of outer vlan (12b) + inner vlan (12b)
11810 * 1. Create L1 filter of outer vlan (12b) which will be in use
11811 * later when we define the cloud filter.
11812 * a. Valid_flags.replace_cloud = 0
11813 * b. Old_filter = 10 (Stag_Inner_Vlan)
11814 * c. New_filter = 0x10
11815 * d. TR bit = 0xff (optional, not used here)
11816 * e. Buffer – 2 entries:
11817 * i. Byte 0 = 8 (outer vlan FV index).
11819 * Byte 2-3 = 0x0fff
11820 * ii. Byte 0 = 37 (inner vlan FV index).
11822 * Byte 2-3 = 0x0fff
11825 * 2. Create cloud filter using two L1 filters entries: stag and
11826 * new filter(outer vlan+ inner vlan)
11827 * a. Valid_flags.replace_cloud = 1
11828 * b. Old_filter = 1 (instead of outer IP)
11829 * c. New_filter = 0x10
11830 * d. Buffer – 2 entries:
11831 * i. Byte 0 = 0x80 | 7 (valid | Stag).
11832 * Byte 1-3 = 0 (rsv)
11833 * ii. Byte 8 = 0x80 | 0x10 (valid | new l1 filter step1)
11834 * Byte 9-11 = 0 (rsv)
11837 i40e_cloud_filter_qinq_create(struct i40e_pf *pf)
11839 int ret = -ENOTSUP;
11840 struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
11841 struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
11842 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11844 if (pf->support_multi_driver) {
11845 PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
11850 memset(&filter_replace, 0,
11851 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
11852 memset(&filter_replace_buf, 0,
11853 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
11855 /* create L1 filter */
11856 filter_replace.old_filter_type =
11857 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG_IVLAN;
11858 filter_replace.new_filter_type = I40E_AQC_ADD_CLOUD_FILTER_0X10;
11859 filter_replace.tr_bit = 0;
11861 /* Prepare the buffer, 2 entries */
11862 filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_VLAN;
11863 filter_replace_buf.data[0] |=
11864 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
11865 /* Field Vector 12b mask */
11866 filter_replace_buf.data[2] = 0xff;
11867 filter_replace_buf.data[3] = 0x0f;
11868 filter_replace_buf.data[4] =
11869 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_INNER_VLAN;
11870 filter_replace_buf.data[4] |=
11871 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
11872 /* Field Vector 12b mask */
11873 filter_replace_buf.data[6] = 0xff;
11874 filter_replace_buf.data[7] = 0x0f;
11875 ret = i40e_aq_replace_cloud_filters(hw, &filter_replace,
11876 &filter_replace_buf);
11877 if (ret != I40E_SUCCESS)
11879 PMD_DRV_LOG(DEBUG, "Global configuration modification: "
11880 "cloud l1 type is changed from 0x%x to 0x%x",
11881 filter_replace.old_filter_type,
11882 filter_replace.new_filter_type);
11884 /* Apply the second L2 cloud filter */
11885 memset(&filter_replace, 0,
11886 sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
11887 memset(&filter_replace_buf, 0,
11888 sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
11890 /* create L2 filter, input for L2 filter will be L1 filter */
11891 filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
11892 filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_OIP;
11893 filter_replace.new_filter_type = I40E_AQC_ADD_CLOUD_FILTER_0X10;
11895 /* Prepare the buffer, 2 entries */
11896 filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
11897 filter_replace_buf.data[0] |=
11898 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
11899 filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X10;
11900 filter_replace_buf.data[4] |=
11901 I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
11902 ret = i40e_aq_replace_cloud_filters(hw, &filter_replace,
11903 &filter_replace_buf);
11905 i40e_global_cfg_warning(I40E_WARNING_RPL_CLD_FILTER);
11906 PMD_DRV_LOG(DEBUG, "Global configuration modification: "
11907 "cloud filter type is changed from 0x%x to 0x%x",
11908 filter_replace.old_filter_type,
11909 filter_replace.new_filter_type);
11915 i40e_config_rss_filter(struct i40e_pf *pf,
11916 struct i40e_rte_flow_rss_conf *conf, bool add)
11918 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11919 uint32_t i, lut = 0;
11921 struct rte_eth_rss_conf rss_conf = conf->rss_conf;
11922 struct i40e_rte_flow_rss_conf *rss_info = &pf->rss_info;
11925 if (memcmp(conf, rss_info,
11926 sizeof(struct i40e_rte_flow_rss_conf)) == 0) {
11927 i40e_pf_disable_rss(pf);
11928 memset(rss_info, 0,
11929 sizeof(struct i40e_rte_flow_rss_conf));
11938 /* If both VMDQ and RSS enabled, not all of PF queues are configured.
11939 * It's necessary to calculate the actual PF queues that are configured.
11941 if (pf->dev_data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG)
11942 num = i40e_pf_calc_configured_queues_num(pf);
11944 num = pf->dev_data->nb_rx_queues;
11946 num = RTE_MIN(num, conf->num);
11947 PMD_DRV_LOG(INFO, "Max of contiguous %u PF queues are configured",
11951 PMD_DRV_LOG(ERR, "No PF queues are configured to enable RSS");
11955 /* Fill in redirection table */
11956 for (i = 0, j = 0; i < hw->func_caps.rss_table_size; i++, j++) {
11959 lut = (lut << 8) | (conf->queue[j] & ((0x1 <<
11960 hw->func_caps.rss_table_entry_width) - 1));
11962 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i >> 2), lut);
11965 if ((rss_conf.rss_hf & pf->adapter->flow_types_mask) == 0) {
11966 i40e_pf_disable_rss(pf);
11969 if (rss_conf.rss_key == NULL || rss_conf.rss_key_len <
11970 (I40E_PFQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t)) {
11971 /* Random default keys */
11972 static uint32_t rss_key_default[] = {0x6b793944,
11973 0x23504cb5, 0x5bea75b6, 0x309f4f12, 0x3dc0a2b8,
11974 0x024ddcdf, 0x339b8ca0, 0x4c4af64a, 0x34fac605,
11975 0x55d85839, 0x3a58997d, 0x2ec938e1, 0x66031581};
11977 rss_conf.rss_key = (uint8_t *)rss_key_default;
11978 rss_conf.rss_key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
11982 i40e_hw_rss_hash_set(pf, &rss_conf);
11984 rte_memcpy(rss_info,
11985 conf, sizeof(struct i40e_rte_flow_rss_conf));
11990 RTE_INIT(i40e_init_log);
11992 i40e_init_log(void)
11994 i40e_logtype_init = rte_log_register("pmd.net.i40e.init");
11995 if (i40e_logtype_init >= 0)
11996 rte_log_set_level(i40e_logtype_init, RTE_LOG_NOTICE);
11997 i40e_logtype_driver = rte_log_register("pmd.net.i40e.driver");
11998 if (i40e_logtype_driver >= 0)
11999 rte_log_set_level(i40e_logtype_driver, RTE_LOG_NOTICE);
12002 RTE_PMD_REGISTER_PARAM_STRING(net_i40e,
12003 QUEUE_NUM_PER_VF_ARG "=1|2|4|8|16"
12004 ETH_I40E_SUPPORT_MULTI_DRIVER "=1");