4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 #include <rte_string_fns.h>
45 #include <rte_ether.h>
46 #include <rte_ethdev.h>
47 #include <rte_memzone.h>
48 #include <rte_malloc.h>
49 #include <rte_memcpy.h>
50 #include <rte_alarm.h>
52 #include <rte_eth_ctrl.h>
53 #include <rte_tailq.h>
55 #include "i40e_logs.h"
56 #include "base/i40e_prototype.h"
57 #include "base/i40e_adminq_cmd.h"
58 #include "base/i40e_type.h"
59 #include "base/i40e_register.h"
60 #include "base/i40e_dcb.h"
61 #include "i40e_ethdev.h"
62 #include "i40e_rxtx.h"
64 #include "i40e_regs.h"
66 #define ETH_I40E_FLOATING_VEB_ARG "enable_floating_veb"
67 #define ETH_I40E_FLOATING_VEB_LIST_ARG "floating_veb_list"
69 #define I40E_CLEAR_PXE_WAIT_MS 200
71 /* Maximun number of capability elements */
72 #define I40E_MAX_CAP_ELE_NUM 128
74 /* Wait count and inteval */
75 #define I40E_CHK_Q_ENA_COUNT 1000
76 #define I40E_CHK_Q_ENA_INTERVAL_US 1000
78 /* Maximun number of VSI */
79 #define I40E_MAX_NUM_VSIS (384UL)
81 #define I40E_PRE_TX_Q_CFG_WAIT_US 10 /* 10 us */
83 /* Flow control default timer */
84 #define I40E_DEFAULT_PAUSE_TIME 0xFFFFU
86 /* Flow control default high water */
87 #define I40E_DEFAULT_HIGH_WATER (0x1C40/1024)
89 /* Flow control default low water */
90 #define I40E_DEFAULT_LOW_WATER (0x1A40/1024)
92 /* Flow control enable fwd bit */
93 #define I40E_PRTMAC_FWD_CTRL 0x00000001
95 /* Receive Packet Buffer size */
96 #define I40E_RXPBSIZE (968 * 1024)
99 #define I40E_KILOSHIFT 10
101 /* Receive Average Packet Size in Byte*/
102 #define I40E_PACKET_AVERAGE_SIZE 128
104 /* Mask of PF interrupt causes */
105 #define I40E_PFINT_ICR0_ENA_MASK ( \
106 I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | \
107 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | \
108 I40E_PFINT_ICR0_ENA_GRST_MASK | \
109 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | \
110 I40E_PFINT_ICR0_ENA_STORM_DETECT_MASK | \
111 I40E_PFINT_ICR0_ENA_LINK_STAT_CHANGE_MASK | \
112 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | \
113 I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK | \
114 I40E_PFINT_ICR0_ENA_VFLR_MASK | \
115 I40E_PFINT_ICR0_ENA_ADMINQ_MASK)
117 #define I40E_FLOW_TYPES ( \
118 (1UL << RTE_ETH_FLOW_FRAG_IPV4) | \
119 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_TCP) | \
120 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_UDP) | \
121 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_SCTP) | \
122 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_OTHER) | \
123 (1UL << RTE_ETH_FLOW_FRAG_IPV6) | \
124 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_TCP) | \
125 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_UDP) | \
126 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_SCTP) | \
127 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_OTHER) | \
128 (1UL << RTE_ETH_FLOW_L2_PAYLOAD))
130 /* Additional timesync values. */
131 #define I40E_PTP_40GB_INCVAL 0x0199999999ULL
132 #define I40E_PTP_10GB_INCVAL 0x0333333333ULL
133 #define I40E_PTP_1GB_INCVAL 0x2000000000ULL
134 #define I40E_PRTTSYN_TSYNENA 0x80000000
135 #define I40E_PRTTSYN_TSYNTYPE 0x0e000000
136 #define I40E_CYCLECOUNTER_MASK 0xffffffffffffffffULL
138 #define I40E_MAX_PERCENT 100
139 #define I40E_DEFAULT_DCB_APP_NUM 1
140 #define I40E_DEFAULT_DCB_APP_PRIO 3
142 #define I40E_INSET_NONE 0x00000000000000000ULL
145 #define I40E_INSET_DMAC 0x0000000000000001ULL
146 #define I40E_INSET_SMAC 0x0000000000000002ULL
147 #define I40E_INSET_VLAN_OUTER 0x0000000000000004ULL
148 #define I40E_INSET_VLAN_INNER 0x0000000000000008ULL
149 #define I40E_INSET_VLAN_TUNNEL 0x0000000000000010ULL
152 #define I40E_INSET_IPV4_SRC 0x0000000000000100ULL
153 #define I40E_INSET_IPV4_DST 0x0000000000000200ULL
154 #define I40E_INSET_IPV6_SRC 0x0000000000000400ULL
155 #define I40E_INSET_IPV6_DST 0x0000000000000800ULL
156 #define I40E_INSET_SRC_PORT 0x0000000000001000ULL
157 #define I40E_INSET_DST_PORT 0x0000000000002000ULL
158 #define I40E_INSET_SCTP_VT 0x0000000000004000ULL
160 /* bit 16 ~ bit 31 */
161 #define I40E_INSET_IPV4_TOS 0x0000000000010000ULL
162 #define I40E_INSET_IPV4_PROTO 0x0000000000020000ULL
163 #define I40E_INSET_IPV4_TTL 0x0000000000040000ULL
164 #define I40E_INSET_IPV6_TC 0x0000000000080000ULL
165 #define I40E_INSET_IPV6_FLOW 0x0000000000100000ULL
166 #define I40E_INSET_IPV6_NEXT_HDR 0x0000000000200000ULL
167 #define I40E_INSET_IPV6_HOP_LIMIT 0x0000000000400000ULL
168 #define I40E_INSET_TCP_FLAGS 0x0000000000800000ULL
170 /* bit 32 ~ bit 47, tunnel fields */
171 #define I40E_INSET_TUNNEL_IPV4_DST 0x0000000100000000ULL
172 #define I40E_INSET_TUNNEL_IPV6_DST 0x0000000200000000ULL
173 #define I40E_INSET_TUNNEL_DMAC 0x0000000400000000ULL
174 #define I40E_INSET_TUNNEL_SRC_PORT 0x0000000800000000ULL
175 #define I40E_INSET_TUNNEL_DST_PORT 0x0000001000000000ULL
176 #define I40E_INSET_TUNNEL_ID 0x0000002000000000ULL
178 /* bit 48 ~ bit 55 */
179 #define I40E_INSET_LAST_ETHER_TYPE 0x0001000000000000ULL
181 /* bit 56 ~ bit 63, Flex Payload */
182 #define I40E_INSET_FLEX_PAYLOAD_W1 0x0100000000000000ULL
183 #define I40E_INSET_FLEX_PAYLOAD_W2 0x0200000000000000ULL
184 #define I40E_INSET_FLEX_PAYLOAD_W3 0x0400000000000000ULL
185 #define I40E_INSET_FLEX_PAYLOAD_W4 0x0800000000000000ULL
186 #define I40E_INSET_FLEX_PAYLOAD_W5 0x1000000000000000ULL
187 #define I40E_INSET_FLEX_PAYLOAD_W6 0x2000000000000000ULL
188 #define I40E_INSET_FLEX_PAYLOAD_W7 0x4000000000000000ULL
189 #define I40E_INSET_FLEX_PAYLOAD_W8 0x8000000000000000ULL
190 #define I40E_INSET_FLEX_PAYLOAD \
191 (I40E_INSET_FLEX_PAYLOAD_W1 | I40E_INSET_FLEX_PAYLOAD_W2 | \
192 I40E_INSET_FLEX_PAYLOAD_W3 | I40E_INSET_FLEX_PAYLOAD_W4 | \
193 I40E_INSET_FLEX_PAYLOAD_W5 | I40E_INSET_FLEX_PAYLOAD_W6 | \
194 I40E_INSET_FLEX_PAYLOAD_W7 | I40E_INSET_FLEX_PAYLOAD_W8)
197 * Below are values for writing un-exposed registers suggested
200 /* Destination MAC address */
201 #define I40E_REG_INSET_L2_DMAC 0xE000000000000000ULL
202 /* Source MAC address */
203 #define I40E_REG_INSET_L2_SMAC 0x1C00000000000000ULL
204 /* Outer (S-Tag) VLAN tag in the outer L2 header */
205 #define I40E_REG_INSET_L2_OUTER_VLAN 0x0000000004000000ULL
206 /* Inner (C-Tag) or single VLAN tag in the outer L2 header */
207 #define I40E_REG_INSET_L2_INNER_VLAN 0x0080000000000000ULL
208 /* Single VLAN tag in the inner L2 header */
209 #define I40E_REG_INSET_TUNNEL_VLAN 0x0100000000000000ULL
210 /* Source IPv4 address */
211 #define I40E_REG_INSET_L3_SRC_IP4 0x0001800000000000ULL
212 /* Destination IPv4 address */
213 #define I40E_REG_INSET_L3_DST_IP4 0x0000001800000000ULL
214 /* IPv4 Type of Service (TOS) */
215 #define I40E_REG_INSET_L3_IP4_TOS 0x0040000000000000ULL
217 #define I40E_REG_INSET_L3_IP4_PROTO 0x0004000000000000ULL
218 /* IPv4 Time to Live */
219 #define I40E_REG_INSET_L3_IP4_TTL 0x0004000000000000ULL
220 /* Source IPv6 address */
221 #define I40E_REG_INSET_L3_SRC_IP6 0x0007F80000000000ULL
222 /* Destination IPv6 address */
223 #define I40E_REG_INSET_L3_DST_IP6 0x000007F800000000ULL
224 /* IPv6 Traffic Class (TC) */
225 #define I40E_REG_INSET_L3_IP6_TC 0x0040000000000000ULL
226 /* IPv6 Next Header */
227 #define I40E_REG_INSET_L3_IP6_NEXT_HDR 0x0008000000000000ULL
229 #define I40E_REG_INSET_L3_IP6_HOP_LIMIT 0x0008000000000000ULL
231 #define I40E_REG_INSET_L4_SRC_PORT 0x0000000400000000ULL
232 /* Destination L4 port */
233 #define I40E_REG_INSET_L4_DST_PORT 0x0000000200000000ULL
234 /* SCTP verification tag */
235 #define I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG 0x0000000180000000ULL
236 /* Inner destination MAC address (MAC-in-UDP/MAC-in-GRE)*/
237 #define I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC 0x0000000001C00000ULL
238 /* Source port of tunneling UDP */
239 #define I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT 0x0000000000200000ULL
240 /* Destination port of tunneling UDP */
241 #define I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT 0x0000000000100000ULL
242 /* UDP Tunneling ID, NVGRE/GRE key */
243 #define I40E_REG_INSET_TUNNEL_ID 0x00000000000C0000ULL
244 /* Last ether type */
245 #define I40E_REG_INSET_LAST_ETHER_TYPE 0x0000000000004000ULL
246 /* Tunneling outer destination IPv4 address */
247 #define I40E_REG_INSET_TUNNEL_L3_DST_IP4 0x00000000000000C0ULL
248 /* Tunneling outer destination IPv6 address */
249 #define I40E_REG_INSET_TUNNEL_L3_DST_IP6 0x0000000000003FC0ULL
250 /* 1st word of flex payload */
251 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD1 0x0000000000002000ULL
252 /* 2nd word of flex payload */
253 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD2 0x0000000000001000ULL
254 /* 3rd word of flex payload */
255 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD3 0x0000000000000800ULL
256 /* 4th word of flex payload */
257 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD4 0x0000000000000400ULL
258 /* 5th word of flex payload */
259 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD5 0x0000000000000200ULL
260 /* 6th word of flex payload */
261 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD6 0x0000000000000100ULL
262 /* 7th word of flex payload */
263 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD7 0x0000000000000080ULL
264 /* 8th word of flex payload */
265 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD8 0x0000000000000040ULL
266 /* all 8 words flex payload */
267 #define I40E_REG_INSET_FLEX_PAYLOAD_WORDS 0x0000000000003FC0ULL
268 #define I40E_REG_INSET_MASK_DEFAULT 0x0000000000000000ULL
270 #define I40E_TRANSLATE_INSET 0
271 #define I40E_TRANSLATE_REG 1
273 #define I40E_INSET_IPV4_TOS_MASK 0x0009FF00UL
274 #define I40E_INSET_IPv4_TTL_MASK 0x000D00FFUL
275 #define I40E_INSET_IPV4_PROTO_MASK 0x000DFF00UL
276 #define I40E_INSET_IPV6_TC_MASK 0x0009F00FUL
277 #define I40E_INSET_IPV6_HOP_LIMIT_MASK 0x000CFF00UL
278 #define I40E_INSET_IPV6_NEXT_HDR_MASK 0x000C00FFUL
280 #define I40E_GL_SWT_L2TAGCTRL(_i) (0x001C0A70 + ((_i) * 4))
281 #define I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT 16
282 #define I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_MASK \
283 I40E_MASK(0xFFFF, I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT)
285 /* PCI offset for querying capability */
286 #define PCI_DEV_CAP_REG 0xA4
287 /* PCI offset for enabling/disabling Extended Tag */
288 #define PCI_DEV_CTRL_REG 0xA8
289 /* Bit mask of Extended Tag capability */
290 #define PCI_DEV_CAP_EXT_TAG_MASK 0x20
291 /* Bit shift of Extended Tag enable/disable */
292 #define PCI_DEV_CTRL_EXT_TAG_SHIFT 8
293 /* Bit mask of Extended Tag enable/disable */
294 #define PCI_DEV_CTRL_EXT_TAG_MASK (1 << PCI_DEV_CTRL_EXT_TAG_SHIFT)
296 static int eth_i40e_dev_init(struct rte_eth_dev *eth_dev);
297 static int eth_i40e_dev_uninit(struct rte_eth_dev *eth_dev);
298 static int i40e_dev_configure(struct rte_eth_dev *dev);
299 static int i40e_dev_start(struct rte_eth_dev *dev);
300 static void i40e_dev_stop(struct rte_eth_dev *dev);
301 static void i40e_dev_close(struct rte_eth_dev *dev);
302 static void i40e_dev_promiscuous_enable(struct rte_eth_dev *dev);
303 static void i40e_dev_promiscuous_disable(struct rte_eth_dev *dev);
304 static void i40e_dev_allmulticast_enable(struct rte_eth_dev *dev);
305 static void i40e_dev_allmulticast_disable(struct rte_eth_dev *dev);
306 static int i40e_dev_set_link_up(struct rte_eth_dev *dev);
307 static int i40e_dev_set_link_down(struct rte_eth_dev *dev);
308 static void i40e_dev_stats_get(struct rte_eth_dev *dev,
309 struct rte_eth_stats *stats);
310 static int i40e_dev_xstats_get(struct rte_eth_dev *dev,
311 struct rte_eth_xstat *xstats, unsigned n);
312 static int i40e_dev_xstats_get_names(struct rte_eth_dev *dev,
313 struct rte_eth_xstat_name *xstats_names,
315 static void i40e_dev_stats_reset(struct rte_eth_dev *dev);
316 static int i40e_dev_queue_stats_mapping_set(struct rte_eth_dev *dev,
320 static void i40e_dev_info_get(struct rte_eth_dev *dev,
321 struct rte_eth_dev_info *dev_info);
322 static int i40e_vlan_filter_set(struct rte_eth_dev *dev,
325 static int i40e_vlan_tpid_set(struct rte_eth_dev *dev,
326 enum rte_vlan_type vlan_type,
328 static void i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask);
329 static void i40e_vlan_strip_queue_set(struct rte_eth_dev *dev,
332 static int i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on);
333 static int i40e_dev_led_on(struct rte_eth_dev *dev);
334 static int i40e_dev_led_off(struct rte_eth_dev *dev);
335 static int i40e_flow_ctrl_get(struct rte_eth_dev *dev,
336 struct rte_eth_fc_conf *fc_conf);
337 static int i40e_flow_ctrl_set(struct rte_eth_dev *dev,
338 struct rte_eth_fc_conf *fc_conf);
339 static int i40e_priority_flow_ctrl_set(struct rte_eth_dev *dev,
340 struct rte_eth_pfc_conf *pfc_conf);
341 static void i40e_macaddr_add(struct rte_eth_dev *dev,
342 struct ether_addr *mac_addr,
345 static void i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index);
346 static int i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
347 struct rte_eth_rss_reta_entry64 *reta_conf,
349 static int i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
350 struct rte_eth_rss_reta_entry64 *reta_conf,
353 static int i40e_get_cap(struct i40e_hw *hw);
354 static int i40e_pf_parameter_init(struct rte_eth_dev *dev);
355 static int i40e_pf_setup(struct i40e_pf *pf);
356 static int i40e_dev_rxtx_init(struct i40e_pf *pf);
357 static int i40e_vmdq_setup(struct rte_eth_dev *dev);
358 static int i40e_dcb_init_configure(struct rte_eth_dev *dev, bool sw_dcb);
359 static int i40e_dcb_setup(struct rte_eth_dev *dev);
360 static void i40e_stat_update_32(struct i40e_hw *hw, uint32_t reg,
361 bool offset_loaded, uint64_t *offset, uint64_t *stat);
362 static void i40e_stat_update_48(struct i40e_hw *hw,
368 static void i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue);
369 static void i40e_dev_interrupt_handler(
370 __rte_unused struct rte_intr_handle *handle, void *param);
371 static int i40e_res_pool_init(struct i40e_res_pool_info *pool,
372 uint32_t base, uint32_t num);
373 static void i40e_res_pool_destroy(struct i40e_res_pool_info *pool);
374 static int i40e_res_pool_free(struct i40e_res_pool_info *pool,
376 static int i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
378 static int i40e_dev_init_vlan(struct rte_eth_dev *dev);
379 static int i40e_veb_release(struct i40e_veb *veb);
380 static struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf,
381 struct i40e_vsi *vsi);
382 static int i40e_pf_config_mq_rx(struct i40e_pf *pf);
383 static int i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on);
384 static inline int i40e_find_all_vlan_for_mac(struct i40e_vsi *vsi,
385 struct i40e_macvlan_filter *mv_f,
387 struct ether_addr *addr);
388 static inline int i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
389 struct i40e_macvlan_filter *mv_f,
392 static int i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi);
393 static int i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
394 struct rte_eth_rss_conf *rss_conf);
395 static int i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
396 struct rte_eth_rss_conf *rss_conf);
397 static int i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
398 struct rte_eth_udp_tunnel *udp_tunnel);
399 static int i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
400 struct rte_eth_udp_tunnel *udp_tunnel);
401 static void i40e_filter_input_set_init(struct i40e_pf *pf);
402 static int i40e_ethertype_filter_set(struct i40e_pf *pf,
403 struct rte_eth_ethertype_filter *filter,
405 static int i40e_ethertype_filter_handle(struct rte_eth_dev *dev,
406 enum rte_filter_op filter_op,
408 static int i40e_dev_filter_ctrl(struct rte_eth_dev *dev,
409 enum rte_filter_type filter_type,
410 enum rte_filter_op filter_op,
412 static int i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
413 struct rte_eth_dcb_info *dcb_info);
414 static int i40e_dev_sync_phy_type(struct i40e_hw *hw);
415 static void i40e_configure_registers(struct i40e_hw *hw);
416 static void i40e_hw_init(struct rte_eth_dev *dev);
417 static int i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi);
418 static int i40e_mirror_rule_set(struct rte_eth_dev *dev,
419 struct rte_eth_mirror_conf *mirror_conf,
420 uint8_t sw_id, uint8_t on);
421 static int i40e_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t sw_id);
423 static int i40e_timesync_enable(struct rte_eth_dev *dev);
424 static int i40e_timesync_disable(struct rte_eth_dev *dev);
425 static int i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
426 struct timespec *timestamp,
428 static int i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
429 struct timespec *timestamp);
430 static void i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw);
432 static int i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
434 static int i40e_timesync_read_time(struct rte_eth_dev *dev,
435 struct timespec *timestamp);
436 static int i40e_timesync_write_time(struct rte_eth_dev *dev,
437 const struct timespec *timestamp);
439 static int i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
441 static int i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
444 static int i40e_get_regs(struct rte_eth_dev *dev,
445 struct rte_dev_reg_info *regs);
447 static int i40e_get_eeprom_length(struct rte_eth_dev *dev);
449 static int i40e_get_eeprom(struct rte_eth_dev *dev,
450 struct rte_dev_eeprom_info *eeprom);
452 static void i40e_set_default_mac_addr(struct rte_eth_dev *dev,
453 struct ether_addr *mac_addr);
455 static int i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
457 static const struct rte_pci_id pci_id_i40e_map[] = {
458 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_XL710) },
459 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QEMU) },
460 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_B) },
461 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_C) },
462 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_A) },
463 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_B) },
464 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_C) },
465 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T) },
466 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_20G_KR2) },
467 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_20G_KR2_A) },
468 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T4) },
469 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_B) },
470 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_SFP28) },
471 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_X722_A0) },
472 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_X722) },
473 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_X722) },
474 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_X722) },
475 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_1G_BASE_T_X722) },
476 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_X722) },
477 { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_I_X722) },
478 { .vendor_id = 0, /* sentinel */ },
481 static const struct eth_dev_ops i40e_eth_dev_ops = {
482 .dev_configure = i40e_dev_configure,
483 .dev_start = i40e_dev_start,
484 .dev_stop = i40e_dev_stop,
485 .dev_close = i40e_dev_close,
486 .promiscuous_enable = i40e_dev_promiscuous_enable,
487 .promiscuous_disable = i40e_dev_promiscuous_disable,
488 .allmulticast_enable = i40e_dev_allmulticast_enable,
489 .allmulticast_disable = i40e_dev_allmulticast_disable,
490 .dev_set_link_up = i40e_dev_set_link_up,
491 .dev_set_link_down = i40e_dev_set_link_down,
492 .link_update = i40e_dev_link_update,
493 .stats_get = i40e_dev_stats_get,
494 .xstats_get = i40e_dev_xstats_get,
495 .xstats_get_names = i40e_dev_xstats_get_names,
496 .stats_reset = i40e_dev_stats_reset,
497 .xstats_reset = i40e_dev_stats_reset,
498 .queue_stats_mapping_set = i40e_dev_queue_stats_mapping_set,
499 .dev_infos_get = i40e_dev_info_get,
500 .dev_supported_ptypes_get = i40e_dev_supported_ptypes_get,
501 .vlan_filter_set = i40e_vlan_filter_set,
502 .vlan_tpid_set = i40e_vlan_tpid_set,
503 .vlan_offload_set = i40e_vlan_offload_set,
504 .vlan_strip_queue_set = i40e_vlan_strip_queue_set,
505 .vlan_pvid_set = i40e_vlan_pvid_set,
506 .rx_queue_start = i40e_dev_rx_queue_start,
507 .rx_queue_stop = i40e_dev_rx_queue_stop,
508 .tx_queue_start = i40e_dev_tx_queue_start,
509 .tx_queue_stop = i40e_dev_tx_queue_stop,
510 .rx_queue_setup = i40e_dev_rx_queue_setup,
511 .rx_queue_intr_enable = i40e_dev_rx_queue_intr_enable,
512 .rx_queue_intr_disable = i40e_dev_rx_queue_intr_disable,
513 .rx_queue_release = i40e_dev_rx_queue_release,
514 .rx_queue_count = i40e_dev_rx_queue_count,
515 .rx_descriptor_done = i40e_dev_rx_descriptor_done,
516 .tx_queue_setup = i40e_dev_tx_queue_setup,
517 .tx_queue_release = i40e_dev_tx_queue_release,
518 .dev_led_on = i40e_dev_led_on,
519 .dev_led_off = i40e_dev_led_off,
520 .flow_ctrl_get = i40e_flow_ctrl_get,
521 .flow_ctrl_set = i40e_flow_ctrl_set,
522 .priority_flow_ctrl_set = i40e_priority_flow_ctrl_set,
523 .mac_addr_add = i40e_macaddr_add,
524 .mac_addr_remove = i40e_macaddr_remove,
525 .reta_update = i40e_dev_rss_reta_update,
526 .reta_query = i40e_dev_rss_reta_query,
527 .rss_hash_update = i40e_dev_rss_hash_update,
528 .rss_hash_conf_get = i40e_dev_rss_hash_conf_get,
529 .udp_tunnel_port_add = i40e_dev_udp_tunnel_port_add,
530 .udp_tunnel_port_del = i40e_dev_udp_tunnel_port_del,
531 .filter_ctrl = i40e_dev_filter_ctrl,
532 .rxq_info_get = i40e_rxq_info_get,
533 .txq_info_get = i40e_txq_info_get,
534 .mirror_rule_set = i40e_mirror_rule_set,
535 .mirror_rule_reset = i40e_mirror_rule_reset,
536 .timesync_enable = i40e_timesync_enable,
537 .timesync_disable = i40e_timesync_disable,
538 .timesync_read_rx_timestamp = i40e_timesync_read_rx_timestamp,
539 .timesync_read_tx_timestamp = i40e_timesync_read_tx_timestamp,
540 .get_dcb_info = i40e_dev_get_dcb_info,
541 .timesync_adjust_time = i40e_timesync_adjust_time,
542 .timesync_read_time = i40e_timesync_read_time,
543 .timesync_write_time = i40e_timesync_write_time,
544 .get_reg = i40e_get_regs,
545 .get_eeprom_length = i40e_get_eeprom_length,
546 .get_eeprom = i40e_get_eeprom,
547 .mac_addr_set = i40e_set_default_mac_addr,
548 .mtu_set = i40e_dev_mtu_set,
551 /* store statistics names and its offset in stats structure */
552 struct rte_i40e_xstats_name_off {
553 char name[RTE_ETH_XSTATS_NAME_SIZE];
557 static const struct rte_i40e_xstats_name_off rte_i40e_stats_strings[] = {
558 {"rx_unicast_packets", offsetof(struct i40e_eth_stats, rx_unicast)},
559 {"rx_multicast_packets", offsetof(struct i40e_eth_stats, rx_multicast)},
560 {"rx_broadcast_packets", offsetof(struct i40e_eth_stats, rx_broadcast)},
561 {"rx_dropped", offsetof(struct i40e_eth_stats, rx_discards)},
562 {"rx_unknown_protocol_packets", offsetof(struct i40e_eth_stats,
563 rx_unknown_protocol)},
564 {"tx_unicast_packets", offsetof(struct i40e_eth_stats, tx_unicast)},
565 {"tx_multicast_packets", offsetof(struct i40e_eth_stats, tx_multicast)},
566 {"tx_broadcast_packets", offsetof(struct i40e_eth_stats, tx_broadcast)},
567 {"tx_dropped", offsetof(struct i40e_eth_stats, tx_discards)},
570 #define I40E_NB_ETH_XSTATS (sizeof(rte_i40e_stats_strings) / \
571 sizeof(rte_i40e_stats_strings[0]))
573 static const struct rte_i40e_xstats_name_off rte_i40e_hw_port_strings[] = {
574 {"tx_link_down_dropped", offsetof(struct i40e_hw_port_stats,
575 tx_dropped_link_down)},
576 {"rx_crc_errors", offsetof(struct i40e_hw_port_stats, crc_errors)},
577 {"rx_illegal_byte_errors", offsetof(struct i40e_hw_port_stats,
579 {"rx_error_bytes", offsetof(struct i40e_hw_port_stats, error_bytes)},
580 {"mac_local_errors", offsetof(struct i40e_hw_port_stats,
582 {"mac_remote_errors", offsetof(struct i40e_hw_port_stats,
584 {"rx_length_errors", offsetof(struct i40e_hw_port_stats,
586 {"tx_xon_packets", offsetof(struct i40e_hw_port_stats, link_xon_tx)},
587 {"rx_xon_packets", offsetof(struct i40e_hw_port_stats, link_xon_rx)},
588 {"tx_xoff_packets", offsetof(struct i40e_hw_port_stats, link_xoff_tx)},
589 {"rx_xoff_packets", offsetof(struct i40e_hw_port_stats, link_xoff_rx)},
590 {"rx_size_64_packets", offsetof(struct i40e_hw_port_stats, rx_size_64)},
591 {"rx_size_65_to_127_packets", offsetof(struct i40e_hw_port_stats,
593 {"rx_size_128_to_255_packets", offsetof(struct i40e_hw_port_stats,
595 {"rx_size_256_to_511_packets", offsetof(struct i40e_hw_port_stats,
597 {"rx_size_512_to_1023_packets", offsetof(struct i40e_hw_port_stats,
599 {"rx_size_1024_to_1522_packets", offsetof(struct i40e_hw_port_stats,
601 {"rx_size_1523_to_max_packets", offsetof(struct i40e_hw_port_stats,
603 {"rx_undersized_errors", offsetof(struct i40e_hw_port_stats,
605 {"rx_oversize_errors", offsetof(struct i40e_hw_port_stats,
607 {"rx_mac_short_dropped", offsetof(struct i40e_hw_port_stats,
608 mac_short_packet_dropped)},
609 {"rx_fragmented_errors", offsetof(struct i40e_hw_port_stats,
611 {"rx_jabber_errors", offsetof(struct i40e_hw_port_stats, rx_jabber)},
612 {"tx_size_64_packets", offsetof(struct i40e_hw_port_stats, tx_size_64)},
613 {"tx_size_65_to_127_packets", offsetof(struct i40e_hw_port_stats,
615 {"tx_size_128_to_255_packets", offsetof(struct i40e_hw_port_stats,
617 {"tx_size_256_to_511_packets", offsetof(struct i40e_hw_port_stats,
619 {"tx_size_512_to_1023_packets", offsetof(struct i40e_hw_port_stats,
621 {"tx_size_1024_to_1522_packets", offsetof(struct i40e_hw_port_stats,
623 {"tx_size_1523_to_max_packets", offsetof(struct i40e_hw_port_stats,
625 {"rx_flow_director_atr_match_packets",
626 offsetof(struct i40e_hw_port_stats, fd_atr_match)},
627 {"rx_flow_director_sb_match_packets",
628 offsetof(struct i40e_hw_port_stats, fd_sb_match)},
629 {"tx_low_power_idle_status", offsetof(struct i40e_hw_port_stats,
631 {"rx_low_power_idle_status", offsetof(struct i40e_hw_port_stats,
633 {"tx_low_power_idle_count", offsetof(struct i40e_hw_port_stats,
635 {"rx_low_power_idle_count", offsetof(struct i40e_hw_port_stats,
639 #define I40E_NB_HW_PORT_XSTATS (sizeof(rte_i40e_hw_port_strings) / \
640 sizeof(rte_i40e_hw_port_strings[0]))
642 static const struct rte_i40e_xstats_name_off rte_i40e_rxq_prio_strings[] = {
643 {"xon_packets", offsetof(struct i40e_hw_port_stats,
645 {"xoff_packets", offsetof(struct i40e_hw_port_stats,
649 #define I40E_NB_RXQ_PRIO_XSTATS (sizeof(rte_i40e_rxq_prio_strings) / \
650 sizeof(rte_i40e_rxq_prio_strings[0]))
652 static const struct rte_i40e_xstats_name_off rte_i40e_txq_prio_strings[] = {
653 {"xon_packets", offsetof(struct i40e_hw_port_stats,
655 {"xoff_packets", offsetof(struct i40e_hw_port_stats,
657 {"xon_to_xoff_packets", offsetof(struct i40e_hw_port_stats,
658 priority_xon_2_xoff)},
661 #define I40E_NB_TXQ_PRIO_XSTATS (sizeof(rte_i40e_txq_prio_strings) / \
662 sizeof(rte_i40e_txq_prio_strings[0]))
664 static struct eth_driver rte_i40e_pmd = {
666 .id_table = pci_id_i40e_map,
667 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
668 RTE_PCI_DRV_DETACHABLE,
669 .probe = rte_eth_dev_pci_probe,
670 .remove = rte_eth_dev_pci_remove,
672 .eth_dev_init = eth_i40e_dev_init,
673 .eth_dev_uninit = eth_i40e_dev_uninit,
674 .dev_private_size = sizeof(struct i40e_adapter),
678 rte_i40e_dev_atomic_read_link_status(struct rte_eth_dev *dev,
679 struct rte_eth_link *link)
681 struct rte_eth_link *dst = link;
682 struct rte_eth_link *src = &(dev->data->dev_link);
684 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
685 *(uint64_t *)src) == 0)
692 rte_i40e_dev_atomic_write_link_status(struct rte_eth_dev *dev,
693 struct rte_eth_link *link)
695 struct rte_eth_link *dst = &(dev->data->dev_link);
696 struct rte_eth_link *src = link;
698 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
699 *(uint64_t *)src) == 0)
705 DRIVER_REGISTER_PCI(net_i40e, rte_i40e_pmd.pci_drv);
706 DRIVER_REGISTER_PCI_TABLE(net_i40e, pci_id_i40e_map);
708 #ifndef I40E_GLQF_ORT
709 #define I40E_GLQF_ORT(_i) (0x00268900 + ((_i) * 4))
711 #ifndef I40E_GLQF_PIT
712 #define I40E_GLQF_PIT(_i) (0x00268C80 + ((_i) * 4))
715 static inline void i40e_GLQF_reg_init(struct i40e_hw *hw)
718 * Initialize registers for flexible payload, which should be set by NVM.
719 * This should be removed from code once it is fixed in NVM.
721 I40E_WRITE_REG(hw, I40E_GLQF_ORT(18), 0x00000030);
722 I40E_WRITE_REG(hw, I40E_GLQF_ORT(19), 0x00000030);
723 I40E_WRITE_REG(hw, I40E_GLQF_ORT(26), 0x0000002B);
724 I40E_WRITE_REG(hw, I40E_GLQF_ORT(30), 0x0000002B);
725 I40E_WRITE_REG(hw, I40E_GLQF_ORT(33), 0x000000E0);
726 I40E_WRITE_REG(hw, I40E_GLQF_ORT(34), 0x000000E3);
727 I40E_WRITE_REG(hw, I40E_GLQF_ORT(35), 0x000000E6);
728 I40E_WRITE_REG(hw, I40E_GLQF_ORT(20), 0x00000031);
729 I40E_WRITE_REG(hw, I40E_GLQF_ORT(23), 0x00000031);
730 I40E_WRITE_REG(hw, I40E_GLQF_ORT(63), 0x0000002D);
731 I40E_WRITE_REG(hw, I40E_GLQF_PIT(16), 0x00007480);
732 I40E_WRITE_REG(hw, I40E_GLQF_PIT(17), 0x00007440);
734 /* Initialize registers for parsing packet type of QinQ */
735 I40E_WRITE_REG(hw, I40E_GLQF_ORT(40), 0x00000029);
736 I40E_WRITE_REG(hw, I40E_GLQF_PIT(9), 0x00009420);
739 #define I40E_FLOW_CONTROL_ETHERTYPE 0x8808
742 * Add a ethertype filter to drop all flow control frames transmitted
746 i40e_add_tx_flow_control_drop_filter(struct i40e_pf *pf)
748 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
749 uint16_t flags = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
750 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
751 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
754 ret = i40e_aq_add_rem_control_packet_filter(hw, NULL,
755 I40E_FLOW_CONTROL_ETHERTYPE, flags,
756 pf->main_vsi_seid, 0,
759 PMD_INIT_LOG(ERR, "Failed to add filter to drop flow control "
760 " frames from VSIs.");
764 floating_veb_list_handler(__rte_unused const char *key,
765 const char *floating_veb_value,
769 unsigned int count = 0;
772 bool *vf_floating_veb = opaque;
774 while (isblank(*floating_veb_value))
775 floating_veb_value++;
777 /* Reset floating VEB configuration for VFs */
778 for (idx = 0; idx < I40E_MAX_VF; idx++)
779 vf_floating_veb[idx] = false;
783 while (isblank(*floating_veb_value))
784 floating_veb_value++;
785 if (*floating_veb_value == '\0')
788 idx = strtoul(floating_veb_value, &end, 10);
789 if (errno || end == NULL)
791 while (isblank(*end))
795 } else if ((*end == ';') || (*end == '\0')) {
797 if (min == I40E_MAX_VF)
799 if (max >= I40E_MAX_VF)
800 max = I40E_MAX_VF - 1;
801 for (idx = min; idx <= max; idx++) {
802 vf_floating_veb[idx] = true;
809 floating_veb_value = end + 1;
810 } while (*end != '\0');
819 config_vf_floating_veb(struct rte_devargs *devargs,
820 uint16_t floating_veb,
821 bool *vf_floating_veb)
823 struct rte_kvargs *kvlist;
825 const char *floating_veb_list = ETH_I40E_FLOATING_VEB_LIST_ARG;
829 /* All the VFs attach to the floating VEB by default
830 * when the floating VEB is enabled.
832 for (i = 0; i < I40E_MAX_VF; i++)
833 vf_floating_veb[i] = true;
838 kvlist = rte_kvargs_parse(devargs->args, NULL);
842 if (!rte_kvargs_count(kvlist, floating_veb_list)) {
843 rte_kvargs_free(kvlist);
846 /* When the floating_veb_list parameter exists, all the VFs
847 * will attach to the legacy VEB firstly, then configure VFs
848 * to the floating VEB according to the floating_veb_list.
850 if (rte_kvargs_process(kvlist, floating_veb_list,
851 floating_veb_list_handler,
852 vf_floating_veb) < 0) {
853 rte_kvargs_free(kvlist);
856 rte_kvargs_free(kvlist);
860 i40e_check_floating_handler(__rte_unused const char *key,
862 __rte_unused void *opaque)
864 if (strcmp(value, "1"))
871 is_floating_veb_supported(struct rte_devargs *devargs)
873 struct rte_kvargs *kvlist;
874 const char *floating_veb_key = ETH_I40E_FLOATING_VEB_ARG;
879 kvlist = rte_kvargs_parse(devargs->args, NULL);
883 if (!rte_kvargs_count(kvlist, floating_veb_key)) {
884 rte_kvargs_free(kvlist);
887 /* Floating VEB is enabled when there's key-value:
888 * enable_floating_veb=1
890 if (rte_kvargs_process(kvlist, floating_veb_key,
891 i40e_check_floating_handler, NULL) < 0) {
892 rte_kvargs_free(kvlist);
895 rte_kvargs_free(kvlist);
901 config_floating_veb(struct rte_eth_dev *dev)
903 struct rte_pci_device *pci_dev = dev->pci_dev;
904 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
905 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
907 memset(pf->floating_veb_list, 0, sizeof(pf->floating_veb_list));
909 if (hw->aq.fw_maj_ver >= FLOATING_VEB_SUPPORTED_FW_MAJ) {
911 is_floating_veb_supported(pci_dev->device.devargs);
912 config_vf_floating_veb(pci_dev->device.devargs,
914 pf->floating_veb_list);
916 pf->floating_veb = false;
920 #define I40E_L2_TAGS_S_TAG_SHIFT 1
921 #define I40E_L2_TAGS_S_TAG_MASK I40E_MASK(0x1, I40E_L2_TAGS_S_TAG_SHIFT)
924 eth_i40e_dev_init(struct rte_eth_dev *dev)
926 struct rte_pci_device *pci_dev;
927 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
928 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
929 struct i40e_vsi *vsi;
934 PMD_INIT_FUNC_TRACE();
936 dev->dev_ops = &i40e_eth_dev_ops;
937 dev->rx_pkt_burst = i40e_recv_pkts;
938 dev->tx_pkt_burst = i40e_xmit_pkts;
940 /* for secondary processes, we don't initialise any further as primary
941 * has already done this work. Only check we don't need a different
943 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
944 i40e_set_rx_function(dev);
945 i40e_set_tx_function(dev);
948 pci_dev = dev->pci_dev;
950 rte_eth_copy_pci_info(dev, pci_dev);
952 pf->adapter = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
953 pf->adapter->eth_dev = dev;
954 pf->dev_data = dev->data;
956 hw->back = I40E_PF_TO_ADAPTER(pf);
957 hw->hw_addr = (uint8_t *)(pci_dev->mem_resource[0].addr);
959 PMD_INIT_LOG(ERR, "Hardware is not available, "
960 "as address is NULL");
964 hw->vendor_id = pci_dev->id.vendor_id;
965 hw->device_id = pci_dev->id.device_id;
966 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
967 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
968 hw->bus.device = pci_dev->addr.devid;
969 hw->bus.func = pci_dev->addr.function;
970 hw->adapter_stopped = 0;
972 /* Make sure all is clean before doing PF reset */
975 /* Initialize the hardware */
978 /* Reset here to make sure all is clean for each PF */
979 ret = i40e_pf_reset(hw);
981 PMD_INIT_LOG(ERR, "Failed to reset pf: %d", ret);
985 /* Initialize the shared code (base driver) */
986 ret = i40e_init_shared_code(hw);
988 PMD_INIT_LOG(ERR, "Failed to init shared code (base driver): %d", ret);
993 * To work around the NVM issue, initialize registers
994 * for flexible payload and packet type of QinQ by
995 * software. It should be removed once issues are fixed
998 i40e_GLQF_reg_init(hw);
1000 /* Initialize the input set for filters (hash and fd) to default value */
1001 i40e_filter_input_set_init(pf);
1003 /* Initialize the parameters for adminq */
1004 i40e_init_adminq_parameter(hw);
1005 ret = i40e_init_adminq(hw);
1006 if (ret != I40E_SUCCESS) {
1007 PMD_INIT_LOG(ERR, "Failed to init adminq: %d", ret);
1010 PMD_INIT_LOG(INFO, "FW %d.%d API %d.%d NVM %02d.%02d.%02d eetrack %04x",
1011 hw->aq.fw_maj_ver, hw->aq.fw_min_ver,
1012 hw->aq.api_maj_ver, hw->aq.api_min_ver,
1013 ((hw->nvm.version >> 12) & 0xf),
1014 ((hw->nvm.version >> 4) & 0xff),
1015 (hw->nvm.version & 0xf), hw->nvm.eetrack);
1017 /* Need the special FW version to support floating VEB */
1018 config_floating_veb(dev);
1019 /* Clear PXE mode */
1020 i40e_clear_pxe_mode(hw);
1021 ret = i40e_dev_sync_phy_type(hw);
1023 PMD_INIT_LOG(ERR, "Failed to sync phy type: %d", ret);
1024 goto err_sync_phy_type;
1027 * On X710, performance number is far from the expectation on recent
1028 * firmware versions. The fix for this issue may not be integrated in
1029 * the following firmware version. So the workaround in software driver
1030 * is needed. It needs to modify the initial values of 3 internal only
1031 * registers. Note that the workaround can be removed when it is fixed
1032 * in firmware in the future.
1034 i40e_configure_registers(hw);
1036 /* Get hw capabilities */
1037 ret = i40e_get_cap(hw);
1038 if (ret != I40E_SUCCESS) {
1039 PMD_INIT_LOG(ERR, "Failed to get capabilities: %d", ret);
1040 goto err_get_capabilities;
1043 /* Initialize parameters for PF */
1044 ret = i40e_pf_parameter_init(dev);
1046 PMD_INIT_LOG(ERR, "Failed to do parameter init: %d", ret);
1047 goto err_parameter_init;
1050 /* Initialize the queue management */
1051 ret = i40e_res_pool_init(&pf->qp_pool, 0, hw->func_caps.num_tx_qp);
1053 PMD_INIT_LOG(ERR, "Failed to init queue pool");
1054 goto err_qp_pool_init;
1056 ret = i40e_res_pool_init(&pf->msix_pool, 1,
1057 hw->func_caps.num_msix_vectors - 1);
1059 PMD_INIT_LOG(ERR, "Failed to init MSIX pool");
1060 goto err_msix_pool_init;
1063 /* Initialize lan hmc */
1064 ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
1065 hw->func_caps.num_rx_qp, 0, 0);
1066 if (ret != I40E_SUCCESS) {
1067 PMD_INIT_LOG(ERR, "Failed to init lan hmc: %d", ret);
1068 goto err_init_lan_hmc;
1071 /* Configure lan hmc */
1072 ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
1073 if (ret != I40E_SUCCESS) {
1074 PMD_INIT_LOG(ERR, "Failed to configure lan hmc: %d", ret);
1075 goto err_configure_lan_hmc;
1078 /* Get and check the mac address */
1079 i40e_get_mac_addr(hw, hw->mac.addr);
1080 if (i40e_validate_mac_addr(hw->mac.addr) != I40E_SUCCESS) {
1081 PMD_INIT_LOG(ERR, "mac address is not valid");
1083 goto err_get_mac_addr;
1085 /* Copy the permanent MAC address */
1086 ether_addr_copy((struct ether_addr *) hw->mac.addr,
1087 (struct ether_addr *) hw->mac.perm_addr);
1089 /* Disable flow control */
1090 hw->fc.requested_mode = I40E_FC_NONE;
1091 i40e_set_fc(hw, &aq_fail, TRUE);
1093 /* Set the global registers with default ether type value */
1094 ret = i40e_vlan_tpid_set(dev, ETH_VLAN_TYPE_OUTER, ETHER_TYPE_VLAN);
1095 if (ret != I40E_SUCCESS) {
1096 PMD_INIT_LOG(ERR, "Failed to set the default outer "
1098 goto err_setup_pf_switch;
1101 /* PF setup, which includes VSI setup */
1102 ret = i40e_pf_setup(pf);
1104 PMD_INIT_LOG(ERR, "Failed to setup pf switch: %d", ret);
1105 goto err_setup_pf_switch;
1108 /* reset all stats of the device, including pf and main vsi */
1109 i40e_dev_stats_reset(dev);
1113 /* Disable double vlan by default */
1114 i40e_vsi_config_double_vlan(vsi, FALSE);
1116 /* Disable S-TAG identification by default */
1117 ret = I40E_READ_REG(hw, I40E_PRT_L2TAGSEN);
1118 if (ret & I40E_L2_TAGS_S_TAG_MASK) {
1119 ret &= ~I40E_L2_TAGS_S_TAG_MASK;
1120 I40E_WRITE_REG(hw, I40E_PRT_L2TAGSEN, ret);
1123 if (!vsi->max_macaddrs)
1124 len = ETHER_ADDR_LEN;
1126 len = ETHER_ADDR_LEN * vsi->max_macaddrs;
1128 /* Should be after VSI initialized */
1129 dev->data->mac_addrs = rte_zmalloc("i40e", len, 0);
1130 if (!dev->data->mac_addrs) {
1131 PMD_INIT_LOG(ERR, "Failed to allocated memory "
1132 "for storing mac address");
1135 ether_addr_copy((struct ether_addr *)hw->mac.perm_addr,
1136 &dev->data->mac_addrs[0]);
1138 /* initialize pf host driver to setup SRIOV resource if applicable */
1139 i40e_pf_host_init(dev);
1141 /* register callback func to eal lib */
1142 rte_intr_callback_register(&(pci_dev->intr_handle),
1143 i40e_dev_interrupt_handler, (void *)dev);
1145 /* configure and enable device interrupt */
1146 i40e_pf_config_irq0(hw, TRUE);
1147 i40e_pf_enable_irq0(hw);
1149 /* enable uio intr after callback register */
1150 rte_intr_enable(&(pci_dev->intr_handle));
1152 * Add an ethertype filter to drop all flow control frames transmitted
1153 * from VSIs. By doing so, we stop VF from sending out PAUSE or PFC
1156 i40e_add_tx_flow_control_drop_filter(pf);
1158 /* Set the max frame size to 0x2600 by default,
1159 * in case other drivers changed the default value.
1161 i40e_aq_set_mac_config(hw, I40E_FRAME_SIZE_MAX, TRUE, 0, NULL);
1163 /* initialize mirror rule list */
1164 TAILQ_INIT(&pf->mirror_list);
1166 /* Init dcb to sw mode by default */
1167 ret = i40e_dcb_init_configure(dev, TRUE);
1168 if (ret != I40E_SUCCESS) {
1169 PMD_INIT_LOG(INFO, "Failed to init dcb.");
1170 pf->flags &= ~I40E_FLAG_DCB;
1176 i40e_vsi_release(pf->main_vsi);
1177 err_setup_pf_switch:
1179 err_configure_lan_hmc:
1180 (void)i40e_shutdown_lan_hmc(hw);
1182 i40e_res_pool_destroy(&pf->msix_pool);
1184 i40e_res_pool_destroy(&pf->qp_pool);
1187 err_get_capabilities:
1189 (void)i40e_shutdown_adminq(hw);
1195 eth_i40e_dev_uninit(struct rte_eth_dev *dev)
1197 struct rte_pci_device *pci_dev;
1199 struct i40e_filter_control_settings settings;
1201 uint8_t aq_fail = 0;
1203 PMD_INIT_FUNC_TRACE();
1205 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1208 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1209 pci_dev = dev->pci_dev;
1211 if (hw->adapter_stopped == 0)
1212 i40e_dev_close(dev);
1214 dev->dev_ops = NULL;
1215 dev->rx_pkt_burst = NULL;
1216 dev->tx_pkt_burst = NULL;
1219 ret = i40e_aq_stop_lldp(hw, true, NULL);
1220 if (ret != I40E_SUCCESS) /* Its failure can be ignored */
1221 PMD_INIT_LOG(INFO, "Failed to stop lldp");
1223 /* Clear PXE mode */
1224 i40e_clear_pxe_mode(hw);
1226 /* Unconfigure filter control */
1227 memset(&settings, 0, sizeof(settings));
1228 ret = i40e_set_filter_control(hw, &settings);
1230 PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
1233 /* Disable flow control */
1234 hw->fc.requested_mode = I40E_FC_NONE;
1235 i40e_set_fc(hw, &aq_fail, TRUE);
1237 /* uninitialize pf host driver */
1238 i40e_pf_host_uninit(dev);
1240 rte_free(dev->data->mac_addrs);
1241 dev->data->mac_addrs = NULL;
1243 /* disable uio intr before callback unregister */
1244 rte_intr_disable(&(pci_dev->intr_handle));
1246 /* register callback func to eal lib */
1247 rte_intr_callback_unregister(&(pci_dev->intr_handle),
1248 i40e_dev_interrupt_handler, (void *)dev);
1254 i40e_dev_configure(struct rte_eth_dev *dev)
1256 struct i40e_adapter *ad =
1257 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1258 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1259 enum rte_eth_rx_mq_mode mq_mode = dev->data->dev_conf.rxmode.mq_mode;
1262 /* Initialize to TRUE. If any of Rx queues doesn't meet the
1263 * bulk allocation or vector Rx preconditions we will reset it.
1265 ad->rx_bulk_alloc_allowed = true;
1266 ad->rx_vec_allowed = true;
1267 ad->tx_simple_allowed = true;
1268 ad->tx_vec_allowed = true;
1270 if (dev->data->dev_conf.fdir_conf.mode == RTE_FDIR_MODE_PERFECT) {
1271 ret = i40e_fdir_setup(pf);
1272 if (ret != I40E_SUCCESS) {
1273 PMD_DRV_LOG(ERR, "Failed to setup flow director.");
1276 ret = i40e_fdir_configure(dev);
1278 PMD_DRV_LOG(ERR, "failed to configure fdir.");
1282 i40e_fdir_teardown(pf);
1284 ret = i40e_dev_init_vlan(dev);
1289 * Needs to move VMDQ setting out of i40e_pf_config_mq_rx() as VMDQ and
1290 * RSS setting have different requirements.
1291 * General PMD driver call sequence are NIC init, configure,
1292 * rx/tx_queue_setup and dev_start. In rx/tx_queue_setup() function, it
1293 * will try to lookup the VSI that specific queue belongs to if VMDQ
1294 * applicable. So, VMDQ setting has to be done before
1295 * rx/tx_queue_setup(). This function is good to place vmdq_setup.
1296 * For RSS setting, it will try to calculate actual configured RX queue
1297 * number, which will be available after rx_queue_setup(). dev_start()
1298 * function is good to place RSS setup.
1300 if (mq_mode & ETH_MQ_RX_VMDQ_FLAG) {
1301 ret = i40e_vmdq_setup(dev);
1306 if (mq_mode & ETH_MQ_RX_DCB_FLAG) {
1307 ret = i40e_dcb_setup(dev);
1309 PMD_DRV_LOG(ERR, "failed to configure DCB.");
1317 /* need to release vmdq resource if exists */
1318 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1319 i40e_vsi_release(pf->vmdq[i].vsi);
1320 pf->vmdq[i].vsi = NULL;
1325 /* need to release fdir resource if exists */
1326 i40e_fdir_teardown(pf);
1331 i40e_vsi_queues_unbind_intr(struct i40e_vsi *vsi)
1333 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1334 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1335 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1336 uint16_t msix_vect = vsi->msix_intr;
1339 for (i = 0; i < vsi->nb_qps; i++) {
1340 I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
1341 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
1345 if (vsi->type != I40E_VSI_SRIOV) {
1346 if (!rte_intr_allow_others(intr_handle)) {
1347 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
1348 I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
1350 I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
1353 I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
1354 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
1356 I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
1361 reg = (hw->func_caps.num_msix_vectors_vf - 1) *
1362 vsi->user_param + (msix_vect - 1);
1364 I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
1365 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
1367 I40E_WRITE_FLUSH(hw);
1371 __vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t msix_vect,
1372 int base_queue, int nb_queue)
1376 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1378 /* Bind all RX queues to allocated MSIX interrupt */
1379 for (i = 0; i < nb_queue; i++) {
1380 val = (msix_vect << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
1381 I40E_QINT_RQCTL_ITR_INDX_MASK |
1382 ((base_queue + i + 1) <<
1383 I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
1384 (0 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
1385 I40E_QINT_RQCTL_CAUSE_ENA_MASK;
1387 if (i == nb_queue - 1)
1388 val |= I40E_QINT_RQCTL_NEXTQ_INDX_MASK;
1389 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(base_queue + i), val);
1392 /* Write first RX queue to Link list register as the head element */
1393 if (vsi->type != I40E_VSI_SRIOV) {
1395 i40e_calc_itr_interval(RTE_LIBRTE_I40E_ITR_INTERVAL);
1397 if (msix_vect == I40E_MISC_VEC_ID) {
1398 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
1400 I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
1402 I40E_PFINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
1404 I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
1407 I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
1409 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
1411 I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
1413 I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
1420 if (msix_vect == I40E_MISC_VEC_ID) {
1422 I40E_VPINT_LNKLST0(vsi->user_param),
1424 I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
1426 I40E_VPINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
1428 /* num_msix_vectors_vf needs to minus irq0 */
1429 reg = (hw->func_caps.num_msix_vectors_vf - 1) *
1430 vsi->user_param + (msix_vect - 1);
1432 I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
1434 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
1436 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
1440 I40E_WRITE_FLUSH(hw);
1444 i40e_vsi_queues_bind_intr(struct i40e_vsi *vsi)
1446 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1447 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1448 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1449 uint16_t msix_vect = vsi->msix_intr;
1450 uint16_t nb_msix = RTE_MIN(vsi->nb_msix, intr_handle->nb_efd);
1451 uint16_t queue_idx = 0;
1456 for (i = 0; i < vsi->nb_qps; i++) {
1457 I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
1458 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
1461 /* INTENA flag is not auto-cleared for interrupt */
1462 val = I40E_READ_REG(hw, I40E_GLINT_CTL);
1463 val |= I40E_GLINT_CTL_DIS_AUTOMASK_PF0_MASK |
1464 I40E_GLINT_CTL_DIS_AUTOMASK_N_MASK |
1465 I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK;
1466 I40E_WRITE_REG(hw, I40E_GLINT_CTL, val);
1468 /* VF bind interrupt */
1469 if (vsi->type == I40E_VSI_SRIOV) {
1470 __vsi_queues_bind_intr(vsi, msix_vect,
1471 vsi->base_queue, vsi->nb_qps);
1475 /* PF & VMDq bind interrupt */
1476 if (rte_intr_dp_is_en(intr_handle)) {
1477 if (vsi->type == I40E_VSI_MAIN) {
1480 } else if (vsi->type == I40E_VSI_VMDQ2) {
1481 struct i40e_vsi *main_vsi =
1482 I40E_DEV_PRIVATE_TO_MAIN_VSI(vsi->adapter);
1483 queue_idx = vsi->base_queue - main_vsi->nb_qps;
1488 for (i = 0; i < vsi->nb_used_qps; i++) {
1490 if (!rte_intr_allow_others(intr_handle))
1491 /* allow to share MISC_VEC_ID */
1492 msix_vect = I40E_MISC_VEC_ID;
1494 /* no enough msix_vect, map all to one */
1495 __vsi_queues_bind_intr(vsi, msix_vect,
1496 vsi->base_queue + i,
1497 vsi->nb_used_qps - i);
1498 for (; !!record && i < vsi->nb_used_qps; i++)
1499 intr_handle->intr_vec[queue_idx + i] =
1503 /* 1:1 queue/msix_vect mapping */
1504 __vsi_queues_bind_intr(vsi, msix_vect,
1505 vsi->base_queue + i, 1);
1507 intr_handle->intr_vec[queue_idx + i] = msix_vect;
1515 i40e_vsi_enable_queues_intr(struct i40e_vsi *vsi)
1517 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1518 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1519 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1520 uint16_t interval = i40e_calc_itr_interval(\
1521 RTE_LIBRTE_I40E_ITR_INTERVAL);
1522 uint16_t msix_intr, i;
1524 if (rte_intr_allow_others(intr_handle))
1525 for (i = 0; i < vsi->nb_msix; i++) {
1526 msix_intr = vsi->msix_intr + i;
1527 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
1528 I40E_PFINT_DYN_CTLN_INTENA_MASK |
1529 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
1530 (0 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT) |
1532 I40E_PFINT_DYN_CTLN_INTERVAL_SHIFT));
1535 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
1536 I40E_PFINT_DYN_CTL0_INTENA_MASK |
1537 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
1538 (0 << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT) |
1540 I40E_PFINT_DYN_CTL0_INTERVAL_SHIFT));
1542 I40E_WRITE_FLUSH(hw);
1546 i40e_vsi_disable_queues_intr(struct i40e_vsi *vsi)
1548 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1549 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1550 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1551 uint16_t msix_intr, i;
1553 if (rte_intr_allow_others(intr_handle))
1554 for (i = 0; i < vsi->nb_msix; i++) {
1555 msix_intr = vsi->msix_intr + i;
1556 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
1560 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0, 0);
1562 I40E_WRITE_FLUSH(hw);
1565 static inline uint8_t
1566 i40e_parse_link_speeds(uint16_t link_speeds)
1568 uint8_t link_speed = I40E_LINK_SPEED_UNKNOWN;
1570 if (link_speeds & ETH_LINK_SPEED_40G)
1571 link_speed |= I40E_LINK_SPEED_40GB;
1572 if (link_speeds & ETH_LINK_SPEED_25G)
1573 link_speed |= I40E_LINK_SPEED_25GB;
1574 if (link_speeds & ETH_LINK_SPEED_20G)
1575 link_speed |= I40E_LINK_SPEED_20GB;
1576 if (link_speeds & ETH_LINK_SPEED_10G)
1577 link_speed |= I40E_LINK_SPEED_10GB;
1578 if (link_speeds & ETH_LINK_SPEED_1G)
1579 link_speed |= I40E_LINK_SPEED_1GB;
1580 if (link_speeds & ETH_LINK_SPEED_100M)
1581 link_speed |= I40E_LINK_SPEED_100MB;
1587 i40e_phy_conf_link(struct i40e_hw *hw,
1589 uint8_t force_speed)
1591 enum i40e_status_code status;
1592 struct i40e_aq_get_phy_abilities_resp phy_ab;
1593 struct i40e_aq_set_phy_config phy_conf;
1594 const uint8_t mask = I40E_AQ_PHY_FLAG_PAUSE_TX |
1595 I40E_AQ_PHY_FLAG_PAUSE_RX |
1596 I40E_AQ_PHY_FLAG_PAUSE_RX |
1597 I40E_AQ_PHY_FLAG_LOW_POWER;
1598 const uint8_t advt = I40E_LINK_SPEED_40GB |
1599 I40E_LINK_SPEED_25GB |
1600 I40E_LINK_SPEED_10GB |
1601 I40E_LINK_SPEED_1GB |
1602 I40E_LINK_SPEED_100MB;
1606 status = i40e_aq_get_phy_capabilities(hw, false, false, &phy_ab,
1611 memset(&phy_conf, 0, sizeof(phy_conf));
1613 /* bits 0-2 use the values from get_phy_abilities_resp */
1615 abilities |= phy_ab.abilities & mask;
1617 /* update ablities and speed */
1618 if (abilities & I40E_AQ_PHY_AN_ENABLED)
1619 phy_conf.link_speed = advt;
1621 phy_conf.link_speed = force_speed;
1623 phy_conf.abilities = abilities;
1625 /* use get_phy_abilities_resp value for the rest */
1626 phy_conf.phy_type = phy_ab.phy_type;
1627 phy_conf.eee_capability = phy_ab.eee_capability;
1628 phy_conf.eeer = phy_ab.eeer_val;
1629 phy_conf.low_power_ctrl = phy_ab.d3_lpan;
1631 PMD_DRV_LOG(DEBUG, "\tCurrent: abilities %x, link_speed %x",
1632 phy_ab.abilities, phy_ab.link_speed);
1633 PMD_DRV_LOG(DEBUG, "\tConfig: abilities %x, link_speed %x",
1634 phy_conf.abilities, phy_conf.link_speed);
1636 status = i40e_aq_set_phy_config(hw, &phy_conf, NULL);
1640 return I40E_SUCCESS;
1644 i40e_apply_link_speed(struct rte_eth_dev *dev)
1647 uint8_t abilities = 0;
1648 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1649 struct rte_eth_conf *conf = &dev->data->dev_conf;
1651 speed = i40e_parse_link_speeds(conf->link_speeds);
1652 if (!I40E_PHY_TYPE_SUPPORT_25G(hw->phy.phy_types))
1653 abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1654 if (!(conf->link_speeds & ETH_LINK_SPEED_FIXED))
1655 abilities |= I40E_AQ_PHY_AN_ENABLED;
1656 abilities |= I40E_AQ_PHY_LINK_ENABLED;
1658 /* Skip changing speed on 40G interfaces, FW does not support */
1659 if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
1660 speed = I40E_LINK_SPEED_UNKNOWN;
1661 abilities |= I40E_AQ_PHY_AN_ENABLED;
1664 return i40e_phy_conf_link(hw, abilities, speed);
1668 i40e_dev_start(struct rte_eth_dev *dev)
1670 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1671 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1672 struct i40e_vsi *main_vsi = pf->main_vsi;
1674 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1675 uint32_t intr_vector = 0;
1677 hw->adapter_stopped = 0;
1679 if (dev->data->dev_conf.link_speeds & ETH_LINK_SPEED_FIXED) {
1680 PMD_INIT_LOG(ERR, "Invalid link_speeds for port %hhu; autonegotiation disabled",
1681 dev->data->port_id);
1685 rte_intr_disable(intr_handle);
1687 if ((rte_intr_cap_multiple(intr_handle) ||
1688 !RTE_ETH_DEV_SRIOV(dev).active) &&
1689 dev->data->dev_conf.intr_conf.rxq != 0) {
1690 intr_vector = dev->data->nb_rx_queues;
1691 if (rte_intr_efd_enable(intr_handle, intr_vector))
1695 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
1696 intr_handle->intr_vec =
1697 rte_zmalloc("intr_vec",
1698 dev->data->nb_rx_queues * sizeof(int),
1700 if (!intr_handle->intr_vec) {
1701 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
1702 " intr_vec\n", dev->data->nb_rx_queues);
1707 /* Initialize VSI */
1708 ret = i40e_dev_rxtx_init(pf);
1709 if (ret != I40E_SUCCESS) {
1710 PMD_DRV_LOG(ERR, "Failed to init rx/tx queues");
1714 /* Map queues with MSIX interrupt */
1715 main_vsi->nb_used_qps = dev->data->nb_rx_queues -
1716 pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
1717 i40e_vsi_queues_bind_intr(main_vsi);
1718 i40e_vsi_enable_queues_intr(main_vsi);
1720 /* Map VMDQ VSI queues with MSIX interrupt */
1721 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1722 pf->vmdq[i].vsi->nb_used_qps = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
1723 i40e_vsi_queues_bind_intr(pf->vmdq[i].vsi);
1724 i40e_vsi_enable_queues_intr(pf->vmdq[i].vsi);
1727 /* enable FDIR MSIX interrupt */
1728 if (pf->fdir.fdir_vsi) {
1729 i40e_vsi_queues_bind_intr(pf->fdir.fdir_vsi);
1730 i40e_vsi_enable_queues_intr(pf->fdir.fdir_vsi);
1733 /* Enable all queues which have been configured */
1734 ret = i40e_dev_switch_queues(pf, TRUE);
1735 if (ret != I40E_SUCCESS) {
1736 PMD_DRV_LOG(ERR, "Failed to enable VSI");
1740 /* Enable receiving broadcast packets */
1741 ret = i40e_aq_set_vsi_broadcast(hw, main_vsi->seid, true, NULL);
1742 if (ret != I40E_SUCCESS)
1743 PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
1745 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1746 ret = i40e_aq_set_vsi_broadcast(hw, pf->vmdq[i].vsi->seid,
1748 if (ret != I40E_SUCCESS)
1749 PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
1752 /* Apply link configure */
1753 if (dev->data->dev_conf.link_speeds & ~(ETH_LINK_SPEED_100M |
1754 ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G |
1755 ETH_LINK_SPEED_20G | ETH_LINK_SPEED_25G |
1756 ETH_LINK_SPEED_40G)) {
1757 PMD_DRV_LOG(ERR, "Invalid link setting");
1760 ret = i40e_apply_link_speed(dev);
1761 if (I40E_SUCCESS != ret) {
1762 PMD_DRV_LOG(ERR, "Fail to apply link setting");
1766 if (!rte_intr_allow_others(intr_handle)) {
1767 rte_intr_callback_unregister(intr_handle,
1768 i40e_dev_interrupt_handler,
1770 /* configure and enable device interrupt */
1771 i40e_pf_config_irq0(hw, FALSE);
1772 i40e_pf_enable_irq0(hw);
1774 if (dev->data->dev_conf.intr_conf.lsc != 0)
1775 PMD_INIT_LOG(INFO, "lsc won't enable because of"
1776 " no intr multiplex\n");
1779 /* enable uio intr after callback register */
1780 rte_intr_enable(intr_handle);
1782 return I40E_SUCCESS;
1785 i40e_dev_switch_queues(pf, FALSE);
1786 i40e_dev_clear_queues(dev);
1792 i40e_dev_stop(struct rte_eth_dev *dev)
1794 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1795 struct i40e_vsi *main_vsi = pf->main_vsi;
1796 struct i40e_mirror_rule *p_mirror;
1797 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1800 /* Disable all queues */
1801 i40e_dev_switch_queues(pf, FALSE);
1803 /* un-map queues with interrupt registers */
1804 i40e_vsi_disable_queues_intr(main_vsi);
1805 i40e_vsi_queues_unbind_intr(main_vsi);
1807 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1808 i40e_vsi_disable_queues_intr(pf->vmdq[i].vsi);
1809 i40e_vsi_queues_unbind_intr(pf->vmdq[i].vsi);
1812 if (pf->fdir.fdir_vsi) {
1813 i40e_vsi_queues_unbind_intr(pf->fdir.fdir_vsi);
1814 i40e_vsi_disable_queues_intr(pf->fdir.fdir_vsi);
1816 /* Clear all queues and release memory */
1817 i40e_dev_clear_queues(dev);
1820 i40e_dev_set_link_down(dev);
1822 /* Remove all mirror rules */
1823 while ((p_mirror = TAILQ_FIRST(&pf->mirror_list))) {
1824 TAILQ_REMOVE(&pf->mirror_list, p_mirror, rules);
1827 pf->nb_mirror_rule = 0;
1829 if (!rte_intr_allow_others(intr_handle))
1830 /* resume to the default handler */
1831 rte_intr_callback_register(intr_handle,
1832 i40e_dev_interrupt_handler,
1835 /* Clean datapath event and queue/vec mapping */
1836 rte_intr_efd_disable(intr_handle);
1837 if (intr_handle->intr_vec) {
1838 rte_free(intr_handle->intr_vec);
1839 intr_handle->intr_vec = NULL;
1844 i40e_dev_close(struct rte_eth_dev *dev)
1846 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1847 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1851 PMD_INIT_FUNC_TRACE();
1854 hw->adapter_stopped = 1;
1855 i40e_dev_free_queues(dev);
1857 /* Disable interrupt */
1858 i40e_pf_disable_irq0(hw);
1859 rte_intr_disable(&(dev->pci_dev->intr_handle));
1861 /* shutdown and destroy the HMC */
1862 i40e_shutdown_lan_hmc(hw);
1864 /* release all the existing VSIs and VEBs */
1865 i40e_fdir_teardown(pf);
1866 i40e_vsi_release(pf->main_vsi);
1868 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1869 i40e_vsi_release(pf->vmdq[i].vsi);
1870 pf->vmdq[i].vsi = NULL;
1876 /* shutdown the adminq */
1877 i40e_aq_queue_shutdown(hw, true);
1878 i40e_shutdown_adminq(hw);
1880 i40e_res_pool_destroy(&pf->qp_pool);
1881 i40e_res_pool_destroy(&pf->msix_pool);
1883 /* force a PF reset to clean anything leftover */
1884 reg = I40E_READ_REG(hw, I40E_PFGEN_CTRL);
1885 I40E_WRITE_REG(hw, I40E_PFGEN_CTRL,
1886 (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
1887 I40E_WRITE_FLUSH(hw);
1891 i40e_dev_promiscuous_enable(struct rte_eth_dev *dev)
1893 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1894 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1895 struct i40e_vsi *vsi = pf->main_vsi;
1898 status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
1900 if (status != I40E_SUCCESS)
1901 PMD_DRV_LOG(ERR, "Failed to enable unicast promiscuous");
1903 status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
1905 if (status != I40E_SUCCESS)
1906 PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
1911 i40e_dev_promiscuous_disable(struct rte_eth_dev *dev)
1913 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1914 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1915 struct i40e_vsi *vsi = pf->main_vsi;
1918 status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
1920 if (status != I40E_SUCCESS)
1921 PMD_DRV_LOG(ERR, "Failed to disable unicast promiscuous");
1923 status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
1925 if (status != I40E_SUCCESS)
1926 PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
1930 i40e_dev_allmulticast_enable(struct rte_eth_dev *dev)
1932 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1933 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1934 struct i40e_vsi *vsi = pf->main_vsi;
1937 ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid, TRUE, NULL);
1938 if (ret != I40E_SUCCESS)
1939 PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
1943 i40e_dev_allmulticast_disable(struct rte_eth_dev *dev)
1945 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1946 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1947 struct i40e_vsi *vsi = pf->main_vsi;
1950 if (dev->data->promiscuous == 1)
1951 return; /* must remain in all_multicast mode */
1953 ret = i40e_aq_set_vsi_multicast_promiscuous(hw,
1954 vsi->seid, FALSE, NULL);
1955 if (ret != I40E_SUCCESS)
1956 PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
1960 * Set device link up.
1963 i40e_dev_set_link_up(struct rte_eth_dev *dev)
1965 /* re-apply link speed setting */
1966 return i40e_apply_link_speed(dev);
1970 * Set device link down.
1973 i40e_dev_set_link_down(struct rte_eth_dev *dev)
1975 uint8_t speed = I40E_LINK_SPEED_UNKNOWN;
1976 uint8_t abilities = 0;
1977 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1979 if (!I40E_PHY_TYPE_SUPPORT_25G(hw->phy.phy_types))
1980 abilities = I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1981 return i40e_phy_conf_link(hw, abilities, speed);
1985 i40e_dev_link_update(struct rte_eth_dev *dev,
1986 int wait_to_complete)
1988 #define CHECK_INTERVAL 100 /* 100ms */
1989 #define MAX_REPEAT_TIME 10 /* 1s (10 * 100ms) in total */
1990 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1991 struct i40e_link_status link_status;
1992 struct rte_eth_link link, old;
1994 unsigned rep_cnt = MAX_REPEAT_TIME;
1996 memset(&link, 0, sizeof(link));
1997 memset(&old, 0, sizeof(old));
1998 memset(&link_status, 0, sizeof(link_status));
1999 rte_i40e_dev_atomic_read_link_status(dev, &old);
2002 /* Get link status information from hardware */
2003 status = i40e_aq_get_link_info(hw, false, &link_status, NULL);
2004 if (status != I40E_SUCCESS) {
2005 link.link_speed = ETH_SPEED_NUM_100M;
2006 link.link_duplex = ETH_LINK_FULL_DUPLEX;
2007 PMD_DRV_LOG(ERR, "Failed to get link info");
2011 link.link_status = link_status.link_info & I40E_AQ_LINK_UP;
2012 if (!wait_to_complete)
2015 rte_delay_ms(CHECK_INTERVAL);
2016 } while (!link.link_status && rep_cnt--);
2018 if (!link.link_status)
2021 /* i40e uses full duplex only */
2022 link.link_duplex = ETH_LINK_FULL_DUPLEX;
2024 /* Parse the link status */
2025 switch (link_status.link_speed) {
2026 case I40E_LINK_SPEED_100MB:
2027 link.link_speed = ETH_SPEED_NUM_100M;
2029 case I40E_LINK_SPEED_1GB:
2030 link.link_speed = ETH_SPEED_NUM_1G;
2032 case I40E_LINK_SPEED_10GB:
2033 link.link_speed = ETH_SPEED_NUM_10G;
2035 case I40E_LINK_SPEED_20GB:
2036 link.link_speed = ETH_SPEED_NUM_20G;
2038 case I40E_LINK_SPEED_25GB:
2039 link.link_speed = ETH_SPEED_NUM_25G;
2041 case I40E_LINK_SPEED_40GB:
2042 link.link_speed = ETH_SPEED_NUM_40G;
2045 link.link_speed = ETH_SPEED_NUM_100M;
2049 link.link_autoneg = !(dev->data->dev_conf.link_speeds &
2050 ETH_LINK_SPEED_FIXED);
2053 rte_i40e_dev_atomic_write_link_status(dev, &link);
2054 if (link.link_status == old.link_status)
2060 /* Get all the statistics of a VSI */
2062 i40e_update_vsi_stats(struct i40e_vsi *vsi)
2064 struct i40e_eth_stats *oes = &vsi->eth_stats_offset;
2065 struct i40e_eth_stats *nes = &vsi->eth_stats;
2066 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2067 int idx = rte_le_to_cpu_16(vsi->info.stat_counter_idx);
2069 i40e_stat_update_48(hw, I40E_GLV_GORCH(idx), I40E_GLV_GORCL(idx),
2070 vsi->offset_loaded, &oes->rx_bytes,
2072 i40e_stat_update_48(hw, I40E_GLV_UPRCH(idx), I40E_GLV_UPRCL(idx),
2073 vsi->offset_loaded, &oes->rx_unicast,
2075 i40e_stat_update_48(hw, I40E_GLV_MPRCH(idx), I40E_GLV_MPRCL(idx),
2076 vsi->offset_loaded, &oes->rx_multicast,
2077 &nes->rx_multicast);
2078 i40e_stat_update_48(hw, I40E_GLV_BPRCH(idx), I40E_GLV_BPRCL(idx),
2079 vsi->offset_loaded, &oes->rx_broadcast,
2080 &nes->rx_broadcast);
2081 i40e_stat_update_32(hw, I40E_GLV_RDPC(idx), vsi->offset_loaded,
2082 &oes->rx_discards, &nes->rx_discards);
2083 /* GLV_REPC not supported */
2084 /* GLV_RMPC not supported */
2085 i40e_stat_update_32(hw, I40E_GLV_RUPP(idx), vsi->offset_loaded,
2086 &oes->rx_unknown_protocol,
2087 &nes->rx_unknown_protocol);
2088 i40e_stat_update_48(hw, I40E_GLV_GOTCH(idx), I40E_GLV_GOTCL(idx),
2089 vsi->offset_loaded, &oes->tx_bytes,
2091 i40e_stat_update_48(hw, I40E_GLV_UPTCH(idx), I40E_GLV_UPTCL(idx),
2092 vsi->offset_loaded, &oes->tx_unicast,
2094 i40e_stat_update_48(hw, I40E_GLV_MPTCH(idx), I40E_GLV_MPTCL(idx),
2095 vsi->offset_loaded, &oes->tx_multicast,
2096 &nes->tx_multicast);
2097 i40e_stat_update_48(hw, I40E_GLV_BPTCH(idx), I40E_GLV_BPTCL(idx),
2098 vsi->offset_loaded, &oes->tx_broadcast,
2099 &nes->tx_broadcast);
2100 /* GLV_TDPC not supported */
2101 i40e_stat_update_32(hw, I40E_GLV_TEPC(idx), vsi->offset_loaded,
2102 &oes->tx_errors, &nes->tx_errors);
2103 vsi->offset_loaded = true;
2105 PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats start *******************",
2107 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", nes->rx_bytes);
2108 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", nes->rx_unicast);
2109 PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", nes->rx_multicast);
2110 PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", nes->rx_broadcast);
2111 PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", nes->rx_discards);
2112 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
2113 nes->rx_unknown_protocol);
2114 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", nes->tx_bytes);
2115 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", nes->tx_unicast);
2116 PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", nes->tx_multicast);
2117 PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", nes->tx_broadcast);
2118 PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", nes->tx_discards);
2119 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", nes->tx_errors);
2120 PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats end *******************",
2125 i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw)
2128 struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
2129 struct i40e_hw_port_stats *os = &pf->stats_offset; /* old stats */
2131 /* Get statistics of struct i40e_eth_stats */
2132 i40e_stat_update_48(hw, I40E_GLPRT_GORCH(hw->port),
2133 I40E_GLPRT_GORCL(hw->port),
2134 pf->offset_loaded, &os->eth.rx_bytes,
2136 i40e_stat_update_48(hw, I40E_GLPRT_UPRCH(hw->port),
2137 I40E_GLPRT_UPRCL(hw->port),
2138 pf->offset_loaded, &os->eth.rx_unicast,
2139 &ns->eth.rx_unicast);
2140 i40e_stat_update_48(hw, I40E_GLPRT_MPRCH(hw->port),
2141 I40E_GLPRT_MPRCL(hw->port),
2142 pf->offset_loaded, &os->eth.rx_multicast,
2143 &ns->eth.rx_multicast);
2144 i40e_stat_update_48(hw, I40E_GLPRT_BPRCH(hw->port),
2145 I40E_GLPRT_BPRCL(hw->port),
2146 pf->offset_loaded, &os->eth.rx_broadcast,
2147 &ns->eth.rx_broadcast);
2148 /* Workaround: CRC size should not be included in byte statistics,
2149 * so subtract ETHER_CRC_LEN from the byte counter for each rx packet.
2151 ns->eth.rx_bytes -= (ns->eth.rx_unicast + ns->eth.rx_multicast +
2152 ns->eth.rx_broadcast) * ETHER_CRC_LEN;
2154 i40e_stat_update_32(hw, I40E_GLPRT_RDPC(hw->port),
2155 pf->offset_loaded, &os->eth.rx_discards,
2156 &ns->eth.rx_discards);
2157 /* GLPRT_REPC not supported */
2158 /* GLPRT_RMPC not supported */
2159 i40e_stat_update_32(hw, I40E_GLPRT_RUPP(hw->port),
2161 &os->eth.rx_unknown_protocol,
2162 &ns->eth.rx_unknown_protocol);
2163 i40e_stat_update_48(hw, I40E_GLPRT_GOTCH(hw->port),
2164 I40E_GLPRT_GOTCL(hw->port),
2165 pf->offset_loaded, &os->eth.tx_bytes,
2167 i40e_stat_update_48(hw, I40E_GLPRT_UPTCH(hw->port),
2168 I40E_GLPRT_UPTCL(hw->port),
2169 pf->offset_loaded, &os->eth.tx_unicast,
2170 &ns->eth.tx_unicast);
2171 i40e_stat_update_48(hw, I40E_GLPRT_MPTCH(hw->port),
2172 I40E_GLPRT_MPTCL(hw->port),
2173 pf->offset_loaded, &os->eth.tx_multicast,
2174 &ns->eth.tx_multicast);
2175 i40e_stat_update_48(hw, I40E_GLPRT_BPTCH(hw->port),
2176 I40E_GLPRT_BPTCL(hw->port),
2177 pf->offset_loaded, &os->eth.tx_broadcast,
2178 &ns->eth.tx_broadcast);
2179 ns->eth.tx_bytes -= (ns->eth.tx_unicast + ns->eth.tx_multicast +
2180 ns->eth.tx_broadcast) * ETHER_CRC_LEN;
2181 /* GLPRT_TEPC not supported */
2183 /* additional port specific stats */
2184 i40e_stat_update_32(hw, I40E_GLPRT_TDOLD(hw->port),
2185 pf->offset_loaded, &os->tx_dropped_link_down,
2186 &ns->tx_dropped_link_down);
2187 i40e_stat_update_32(hw, I40E_GLPRT_CRCERRS(hw->port),
2188 pf->offset_loaded, &os->crc_errors,
2190 i40e_stat_update_32(hw, I40E_GLPRT_ILLERRC(hw->port),
2191 pf->offset_loaded, &os->illegal_bytes,
2192 &ns->illegal_bytes);
2193 /* GLPRT_ERRBC not supported */
2194 i40e_stat_update_32(hw, I40E_GLPRT_MLFC(hw->port),
2195 pf->offset_loaded, &os->mac_local_faults,
2196 &ns->mac_local_faults);
2197 i40e_stat_update_32(hw, I40E_GLPRT_MRFC(hw->port),
2198 pf->offset_loaded, &os->mac_remote_faults,
2199 &ns->mac_remote_faults);
2200 i40e_stat_update_32(hw, I40E_GLPRT_RLEC(hw->port),
2201 pf->offset_loaded, &os->rx_length_errors,
2202 &ns->rx_length_errors);
2203 i40e_stat_update_32(hw, I40E_GLPRT_LXONRXC(hw->port),
2204 pf->offset_loaded, &os->link_xon_rx,
2206 i40e_stat_update_32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
2207 pf->offset_loaded, &os->link_xoff_rx,
2209 for (i = 0; i < 8; i++) {
2210 i40e_stat_update_32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
2212 &os->priority_xon_rx[i],
2213 &ns->priority_xon_rx[i]);
2214 i40e_stat_update_32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
2216 &os->priority_xoff_rx[i],
2217 &ns->priority_xoff_rx[i]);
2219 i40e_stat_update_32(hw, I40E_GLPRT_LXONTXC(hw->port),
2220 pf->offset_loaded, &os->link_xon_tx,
2222 i40e_stat_update_32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
2223 pf->offset_loaded, &os->link_xoff_tx,
2225 for (i = 0; i < 8; i++) {
2226 i40e_stat_update_32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
2228 &os->priority_xon_tx[i],
2229 &ns->priority_xon_tx[i]);
2230 i40e_stat_update_32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
2232 &os->priority_xoff_tx[i],
2233 &ns->priority_xoff_tx[i]);
2234 i40e_stat_update_32(hw, I40E_GLPRT_RXON2OFFCNT(hw->port, i),
2236 &os->priority_xon_2_xoff[i],
2237 &ns->priority_xon_2_xoff[i]);
2239 i40e_stat_update_48(hw, I40E_GLPRT_PRC64H(hw->port),
2240 I40E_GLPRT_PRC64L(hw->port),
2241 pf->offset_loaded, &os->rx_size_64,
2243 i40e_stat_update_48(hw, I40E_GLPRT_PRC127H(hw->port),
2244 I40E_GLPRT_PRC127L(hw->port),
2245 pf->offset_loaded, &os->rx_size_127,
2247 i40e_stat_update_48(hw, I40E_GLPRT_PRC255H(hw->port),
2248 I40E_GLPRT_PRC255L(hw->port),
2249 pf->offset_loaded, &os->rx_size_255,
2251 i40e_stat_update_48(hw, I40E_GLPRT_PRC511H(hw->port),
2252 I40E_GLPRT_PRC511L(hw->port),
2253 pf->offset_loaded, &os->rx_size_511,
2255 i40e_stat_update_48(hw, I40E_GLPRT_PRC1023H(hw->port),
2256 I40E_GLPRT_PRC1023L(hw->port),
2257 pf->offset_loaded, &os->rx_size_1023,
2259 i40e_stat_update_48(hw, I40E_GLPRT_PRC1522H(hw->port),
2260 I40E_GLPRT_PRC1522L(hw->port),
2261 pf->offset_loaded, &os->rx_size_1522,
2263 i40e_stat_update_48(hw, I40E_GLPRT_PRC9522H(hw->port),
2264 I40E_GLPRT_PRC9522L(hw->port),
2265 pf->offset_loaded, &os->rx_size_big,
2267 i40e_stat_update_32(hw, I40E_GLPRT_RUC(hw->port),
2268 pf->offset_loaded, &os->rx_undersize,
2270 i40e_stat_update_32(hw, I40E_GLPRT_RFC(hw->port),
2271 pf->offset_loaded, &os->rx_fragments,
2273 i40e_stat_update_32(hw, I40E_GLPRT_ROC(hw->port),
2274 pf->offset_loaded, &os->rx_oversize,
2276 i40e_stat_update_32(hw, I40E_GLPRT_RJC(hw->port),
2277 pf->offset_loaded, &os->rx_jabber,
2279 i40e_stat_update_48(hw, I40E_GLPRT_PTC64H(hw->port),
2280 I40E_GLPRT_PTC64L(hw->port),
2281 pf->offset_loaded, &os->tx_size_64,
2283 i40e_stat_update_48(hw, I40E_GLPRT_PTC127H(hw->port),
2284 I40E_GLPRT_PTC127L(hw->port),
2285 pf->offset_loaded, &os->tx_size_127,
2287 i40e_stat_update_48(hw, I40E_GLPRT_PTC255H(hw->port),
2288 I40E_GLPRT_PTC255L(hw->port),
2289 pf->offset_loaded, &os->tx_size_255,
2291 i40e_stat_update_48(hw, I40E_GLPRT_PTC511H(hw->port),
2292 I40E_GLPRT_PTC511L(hw->port),
2293 pf->offset_loaded, &os->tx_size_511,
2295 i40e_stat_update_48(hw, I40E_GLPRT_PTC1023H(hw->port),
2296 I40E_GLPRT_PTC1023L(hw->port),
2297 pf->offset_loaded, &os->tx_size_1023,
2299 i40e_stat_update_48(hw, I40E_GLPRT_PTC1522H(hw->port),
2300 I40E_GLPRT_PTC1522L(hw->port),
2301 pf->offset_loaded, &os->tx_size_1522,
2303 i40e_stat_update_48(hw, I40E_GLPRT_PTC9522H(hw->port),
2304 I40E_GLPRT_PTC9522L(hw->port),
2305 pf->offset_loaded, &os->tx_size_big,
2307 i40e_stat_update_32(hw, I40E_GLQF_PCNT(pf->fdir.match_counter_index),
2309 &os->fd_sb_match, &ns->fd_sb_match);
2310 /* GLPRT_MSPDC not supported */
2311 /* GLPRT_XEC not supported */
2313 pf->offset_loaded = true;
2316 i40e_update_vsi_stats(pf->main_vsi);
2319 /* Get all statistics of a port */
2321 i40e_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
2323 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2324 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2325 struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
2328 /* call read registers - updates values, now write them to struct */
2329 i40e_read_stats_registers(pf, hw);
2331 stats->ipackets = pf->main_vsi->eth_stats.rx_unicast +
2332 pf->main_vsi->eth_stats.rx_multicast +
2333 pf->main_vsi->eth_stats.rx_broadcast -
2334 pf->main_vsi->eth_stats.rx_discards;
2335 stats->opackets = pf->main_vsi->eth_stats.tx_unicast +
2336 pf->main_vsi->eth_stats.tx_multicast +
2337 pf->main_vsi->eth_stats.tx_broadcast;
2338 stats->ibytes = ns->eth.rx_bytes;
2339 stats->obytes = ns->eth.tx_bytes;
2340 stats->oerrors = ns->eth.tx_errors +
2341 pf->main_vsi->eth_stats.tx_errors;
2344 stats->imissed = ns->eth.rx_discards +
2345 pf->main_vsi->eth_stats.rx_discards;
2346 stats->ierrors = ns->crc_errors +
2347 ns->rx_length_errors + ns->rx_undersize +
2348 ns->rx_oversize + ns->rx_fragments + ns->rx_jabber;
2350 PMD_DRV_LOG(DEBUG, "***************** PF stats start *******************");
2351 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", ns->eth.rx_bytes);
2352 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", ns->eth.rx_unicast);
2353 PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", ns->eth.rx_multicast);
2354 PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", ns->eth.rx_broadcast);
2355 PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", ns->eth.rx_discards);
2356 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
2357 ns->eth.rx_unknown_protocol);
2358 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", ns->eth.tx_bytes);
2359 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", ns->eth.tx_unicast);
2360 PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", ns->eth.tx_multicast);
2361 PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", ns->eth.tx_broadcast);
2362 PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", ns->eth.tx_discards);
2363 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", ns->eth.tx_errors);
2365 PMD_DRV_LOG(DEBUG, "tx_dropped_link_down: %"PRIu64"",
2366 ns->tx_dropped_link_down);
2367 PMD_DRV_LOG(DEBUG, "crc_errors: %"PRIu64"", ns->crc_errors);
2368 PMD_DRV_LOG(DEBUG, "illegal_bytes: %"PRIu64"",
2370 PMD_DRV_LOG(DEBUG, "error_bytes: %"PRIu64"", ns->error_bytes);
2371 PMD_DRV_LOG(DEBUG, "mac_local_faults: %"PRIu64"",
2372 ns->mac_local_faults);
2373 PMD_DRV_LOG(DEBUG, "mac_remote_faults: %"PRIu64"",
2374 ns->mac_remote_faults);
2375 PMD_DRV_LOG(DEBUG, "rx_length_errors: %"PRIu64"",
2376 ns->rx_length_errors);
2377 PMD_DRV_LOG(DEBUG, "link_xon_rx: %"PRIu64"", ns->link_xon_rx);
2378 PMD_DRV_LOG(DEBUG, "link_xoff_rx: %"PRIu64"", ns->link_xoff_rx);
2379 for (i = 0; i < 8; i++) {
2380 PMD_DRV_LOG(DEBUG, "priority_xon_rx[%d]: %"PRIu64"",
2381 i, ns->priority_xon_rx[i]);
2382 PMD_DRV_LOG(DEBUG, "priority_xoff_rx[%d]: %"PRIu64"",
2383 i, ns->priority_xoff_rx[i]);
2385 PMD_DRV_LOG(DEBUG, "link_xon_tx: %"PRIu64"", ns->link_xon_tx);
2386 PMD_DRV_LOG(DEBUG, "link_xoff_tx: %"PRIu64"", ns->link_xoff_tx);
2387 for (i = 0; i < 8; i++) {
2388 PMD_DRV_LOG(DEBUG, "priority_xon_tx[%d]: %"PRIu64"",
2389 i, ns->priority_xon_tx[i]);
2390 PMD_DRV_LOG(DEBUG, "priority_xoff_tx[%d]: %"PRIu64"",
2391 i, ns->priority_xoff_tx[i]);
2392 PMD_DRV_LOG(DEBUG, "priority_xon_2_xoff[%d]: %"PRIu64"",
2393 i, ns->priority_xon_2_xoff[i]);
2395 PMD_DRV_LOG(DEBUG, "rx_size_64: %"PRIu64"", ns->rx_size_64);
2396 PMD_DRV_LOG(DEBUG, "rx_size_127: %"PRIu64"", ns->rx_size_127);
2397 PMD_DRV_LOG(DEBUG, "rx_size_255: %"PRIu64"", ns->rx_size_255);
2398 PMD_DRV_LOG(DEBUG, "rx_size_511: %"PRIu64"", ns->rx_size_511);
2399 PMD_DRV_LOG(DEBUG, "rx_size_1023: %"PRIu64"", ns->rx_size_1023);
2400 PMD_DRV_LOG(DEBUG, "rx_size_1522: %"PRIu64"", ns->rx_size_1522);
2401 PMD_DRV_LOG(DEBUG, "rx_size_big: %"PRIu64"", ns->rx_size_big);
2402 PMD_DRV_LOG(DEBUG, "rx_undersize: %"PRIu64"", ns->rx_undersize);
2403 PMD_DRV_LOG(DEBUG, "rx_fragments: %"PRIu64"", ns->rx_fragments);
2404 PMD_DRV_LOG(DEBUG, "rx_oversize: %"PRIu64"", ns->rx_oversize);
2405 PMD_DRV_LOG(DEBUG, "rx_jabber: %"PRIu64"", ns->rx_jabber);
2406 PMD_DRV_LOG(DEBUG, "tx_size_64: %"PRIu64"", ns->tx_size_64);
2407 PMD_DRV_LOG(DEBUG, "tx_size_127: %"PRIu64"", ns->tx_size_127);
2408 PMD_DRV_LOG(DEBUG, "tx_size_255: %"PRIu64"", ns->tx_size_255);
2409 PMD_DRV_LOG(DEBUG, "tx_size_511: %"PRIu64"", ns->tx_size_511);
2410 PMD_DRV_LOG(DEBUG, "tx_size_1023: %"PRIu64"", ns->tx_size_1023);
2411 PMD_DRV_LOG(DEBUG, "tx_size_1522: %"PRIu64"", ns->tx_size_1522);
2412 PMD_DRV_LOG(DEBUG, "tx_size_big: %"PRIu64"", ns->tx_size_big);
2413 PMD_DRV_LOG(DEBUG, "mac_short_packet_dropped: %"PRIu64"",
2414 ns->mac_short_packet_dropped);
2415 PMD_DRV_LOG(DEBUG, "checksum_error: %"PRIu64"",
2416 ns->checksum_error);
2417 PMD_DRV_LOG(DEBUG, "fdir_match: %"PRIu64"", ns->fd_sb_match);
2418 PMD_DRV_LOG(DEBUG, "***************** PF stats end ********************");
2421 /* Reset the statistics */
2423 i40e_dev_stats_reset(struct rte_eth_dev *dev)
2425 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2426 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2428 /* Mark PF and VSI stats to update the offset, aka "reset" */
2429 pf->offset_loaded = false;
2431 pf->main_vsi->offset_loaded = false;
2433 /* read the stats, reading current register values into offset */
2434 i40e_read_stats_registers(pf, hw);
2438 i40e_xstats_calc_num(void)
2440 return I40E_NB_ETH_XSTATS + I40E_NB_HW_PORT_XSTATS +
2441 (I40E_NB_RXQ_PRIO_XSTATS * 8) +
2442 (I40E_NB_TXQ_PRIO_XSTATS * 8);
2445 static int i40e_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
2446 struct rte_eth_xstat_name *xstats_names,
2447 __rte_unused unsigned limit)
2452 if (xstats_names == NULL)
2453 return i40e_xstats_calc_num();
2455 /* Note: limit checked in rte_eth_xstats_names() */
2457 /* Get stats from i40e_eth_stats struct */
2458 for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
2459 snprintf(xstats_names[count].name,
2460 sizeof(xstats_names[count].name),
2461 "%s", rte_i40e_stats_strings[i].name);
2465 /* Get individiual stats from i40e_hw_port struct */
2466 for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
2467 snprintf(xstats_names[count].name,
2468 sizeof(xstats_names[count].name),
2469 "%s", rte_i40e_hw_port_strings[i].name);
2473 for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
2474 for (prio = 0; prio < 8; prio++) {
2475 snprintf(xstats_names[count].name,
2476 sizeof(xstats_names[count].name),
2477 "rx_priority%u_%s", prio,
2478 rte_i40e_rxq_prio_strings[i].name);
2483 for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
2484 for (prio = 0; prio < 8; prio++) {
2485 snprintf(xstats_names[count].name,
2486 sizeof(xstats_names[count].name),
2487 "tx_priority%u_%s", prio,
2488 rte_i40e_txq_prio_strings[i].name);
2496 i40e_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
2499 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2500 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2501 unsigned i, count, prio;
2502 struct i40e_hw_port_stats *hw_stats = &pf->stats;
2504 count = i40e_xstats_calc_num();
2508 i40e_read_stats_registers(pf, hw);
2515 /* Get stats from i40e_eth_stats struct */
2516 for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
2517 xstats[count].value = *(uint64_t *)(((char *)&hw_stats->eth) +
2518 rte_i40e_stats_strings[i].offset);
2522 /* Get individiual stats from i40e_hw_port struct */
2523 for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
2524 xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
2525 rte_i40e_hw_port_strings[i].offset);
2529 for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
2530 for (prio = 0; prio < 8; prio++) {
2531 xstats[count].value =
2532 *(uint64_t *)(((char *)hw_stats) +
2533 rte_i40e_rxq_prio_strings[i].offset +
2534 (sizeof(uint64_t) * prio));
2539 for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
2540 for (prio = 0; prio < 8; prio++) {
2541 xstats[count].value =
2542 *(uint64_t *)(((char *)hw_stats) +
2543 rte_i40e_txq_prio_strings[i].offset +
2544 (sizeof(uint64_t) * prio));
2553 i40e_dev_queue_stats_mapping_set(__rte_unused struct rte_eth_dev *dev,
2554 __rte_unused uint16_t queue_id,
2555 __rte_unused uint8_t stat_idx,
2556 __rte_unused uint8_t is_rx)
2558 PMD_INIT_FUNC_TRACE();
2564 i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2566 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2567 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2568 struct i40e_vsi *vsi = pf->main_vsi;
2570 dev_info->max_rx_queues = vsi->nb_qps;
2571 dev_info->max_tx_queues = vsi->nb_qps;
2572 dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
2573 dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
2574 dev_info->max_mac_addrs = vsi->max_macaddrs;
2575 dev_info->max_vfs = dev->pci_dev->max_vfs;
2576 dev_info->rx_offload_capa =
2577 DEV_RX_OFFLOAD_VLAN_STRIP |
2578 DEV_RX_OFFLOAD_QINQ_STRIP |
2579 DEV_RX_OFFLOAD_IPV4_CKSUM |
2580 DEV_RX_OFFLOAD_UDP_CKSUM |
2581 DEV_RX_OFFLOAD_TCP_CKSUM;
2582 dev_info->tx_offload_capa =
2583 DEV_TX_OFFLOAD_VLAN_INSERT |
2584 DEV_TX_OFFLOAD_QINQ_INSERT |
2585 DEV_TX_OFFLOAD_IPV4_CKSUM |
2586 DEV_TX_OFFLOAD_UDP_CKSUM |
2587 DEV_TX_OFFLOAD_TCP_CKSUM |
2588 DEV_TX_OFFLOAD_SCTP_CKSUM |
2589 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
2590 DEV_TX_OFFLOAD_TCP_TSO |
2591 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
2592 DEV_TX_OFFLOAD_GRE_TNL_TSO |
2593 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
2594 DEV_TX_OFFLOAD_GENEVE_TNL_TSO;
2595 dev_info->hash_key_size = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
2597 dev_info->reta_size = pf->hash_lut_size;
2598 dev_info->flow_type_rss_offloads = I40E_RSS_OFFLOAD_ALL;
2600 dev_info->default_rxconf = (struct rte_eth_rxconf) {
2602 .pthresh = I40E_DEFAULT_RX_PTHRESH,
2603 .hthresh = I40E_DEFAULT_RX_HTHRESH,
2604 .wthresh = I40E_DEFAULT_RX_WTHRESH,
2606 .rx_free_thresh = I40E_DEFAULT_RX_FREE_THRESH,
2610 dev_info->default_txconf = (struct rte_eth_txconf) {
2612 .pthresh = I40E_DEFAULT_TX_PTHRESH,
2613 .hthresh = I40E_DEFAULT_TX_HTHRESH,
2614 .wthresh = I40E_DEFAULT_TX_WTHRESH,
2616 .tx_free_thresh = I40E_DEFAULT_TX_FREE_THRESH,
2617 .tx_rs_thresh = I40E_DEFAULT_TX_RSBIT_THRESH,
2618 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
2619 ETH_TXQ_FLAGS_NOOFFLOADS,
2622 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
2623 .nb_max = I40E_MAX_RING_DESC,
2624 .nb_min = I40E_MIN_RING_DESC,
2625 .nb_align = I40E_ALIGN_RING_DESC,
2628 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
2629 .nb_max = I40E_MAX_RING_DESC,
2630 .nb_min = I40E_MIN_RING_DESC,
2631 .nb_align = I40E_ALIGN_RING_DESC,
2634 if (pf->flags & I40E_FLAG_VMDQ) {
2635 dev_info->max_vmdq_pools = pf->max_nb_vmdq_vsi;
2636 dev_info->vmdq_queue_base = dev_info->max_rx_queues;
2637 dev_info->vmdq_queue_num = pf->vmdq_nb_qps *
2638 pf->max_nb_vmdq_vsi;
2639 dev_info->vmdq_pool_base = I40E_VMDQ_POOL_BASE;
2640 dev_info->max_rx_queues += dev_info->vmdq_queue_num;
2641 dev_info->max_tx_queues += dev_info->vmdq_queue_num;
2644 if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types))
2646 dev_info->speed_capa = ETH_LINK_SPEED_40G;
2647 else if (I40E_PHY_TYPE_SUPPORT_25G(hw->phy.phy_types))
2649 dev_info->speed_capa = ETH_LINK_SPEED_25G;
2652 dev_info->speed_capa = ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G;
2656 i40e_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
2658 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2659 struct i40e_vsi *vsi = pf->main_vsi;
2660 PMD_INIT_FUNC_TRACE();
2663 return i40e_vsi_add_vlan(vsi, vlan_id);
2665 return i40e_vsi_delete_vlan(vsi, vlan_id);
2669 i40e_vlan_tpid_set(struct rte_eth_dev *dev,
2670 enum rte_vlan_type vlan_type,
2673 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2674 uint64_t reg_r = 0, reg_w = 0;
2675 uint16_t reg_id = 0;
2677 int qinq = dev->data->dev_conf.rxmode.hw_vlan_extend;
2679 switch (vlan_type) {
2680 case ETH_VLAN_TYPE_OUTER:
2686 case ETH_VLAN_TYPE_INNER:
2692 "Unsupported vlan type in single vlan.\n");
2698 PMD_DRV_LOG(ERR, "Unsupported vlan type %d", vlan_type);
2701 ret = i40e_aq_debug_read_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
2703 if (ret != I40E_SUCCESS) {
2704 PMD_DRV_LOG(ERR, "Fail to debug read from "
2705 "I40E_GL_SWT_L2TAGCTRL[%d]", reg_id);
2709 PMD_DRV_LOG(DEBUG, "Debug read from I40E_GL_SWT_L2TAGCTRL[%d]: "
2710 "0x%08"PRIx64"", reg_id, reg_r);
2712 reg_w = reg_r & (~(I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_MASK));
2713 reg_w |= ((uint64_t)tpid << I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT);
2714 if (reg_r == reg_w) {
2716 PMD_DRV_LOG(DEBUG, "No need to write");
2720 ret = i40e_aq_debug_write_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
2722 if (ret != I40E_SUCCESS) {
2724 PMD_DRV_LOG(ERR, "Fail to debug write to "
2725 "I40E_GL_SWT_L2TAGCTRL[%d]", reg_id);
2728 PMD_DRV_LOG(DEBUG, "Debug write 0x%08"PRIx64" to "
2729 "I40E_GL_SWT_L2TAGCTRL[%d]", reg_w, reg_id);
2735 i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask)
2737 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2738 struct i40e_vsi *vsi = pf->main_vsi;
2740 if (mask & ETH_VLAN_FILTER_MASK) {
2741 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
2742 i40e_vsi_config_vlan_filter(vsi, TRUE);
2744 i40e_vsi_config_vlan_filter(vsi, FALSE);
2747 if (mask & ETH_VLAN_STRIP_MASK) {
2748 /* Enable or disable VLAN stripping */
2749 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
2750 i40e_vsi_config_vlan_stripping(vsi, TRUE);
2752 i40e_vsi_config_vlan_stripping(vsi, FALSE);
2755 if (mask & ETH_VLAN_EXTEND_MASK) {
2756 if (dev->data->dev_conf.rxmode.hw_vlan_extend) {
2757 i40e_vsi_config_double_vlan(vsi, TRUE);
2758 /* Set global registers with default ether type value */
2759 i40e_vlan_tpid_set(dev, ETH_VLAN_TYPE_OUTER,
2761 i40e_vlan_tpid_set(dev, ETH_VLAN_TYPE_INNER,
2765 i40e_vsi_config_double_vlan(vsi, FALSE);
2770 i40e_vlan_strip_queue_set(__rte_unused struct rte_eth_dev *dev,
2771 __rte_unused uint16_t queue,
2772 __rte_unused int on)
2774 PMD_INIT_FUNC_TRACE();
2778 i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
2780 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2781 struct i40e_vsi *vsi = pf->main_vsi;
2782 struct rte_eth_dev_data *data = I40E_VSI_TO_DEV_DATA(vsi);
2783 struct i40e_vsi_vlan_pvid_info info;
2785 memset(&info, 0, sizeof(info));
2788 info.config.pvid = pvid;
2790 info.config.reject.tagged =
2791 data->dev_conf.txmode.hw_vlan_reject_tagged;
2792 info.config.reject.untagged =
2793 data->dev_conf.txmode.hw_vlan_reject_untagged;
2796 return i40e_vsi_vlan_pvid_set(vsi, &info);
2800 i40e_dev_led_on(struct rte_eth_dev *dev)
2802 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2803 uint32_t mode = i40e_led_get(hw);
2806 i40e_led_set(hw, 0xf, true); /* 0xf means led always true */
2812 i40e_dev_led_off(struct rte_eth_dev *dev)
2814 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2815 uint32_t mode = i40e_led_get(hw);
2818 i40e_led_set(hw, 0, false);
2824 i40e_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2826 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2827 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2829 fc_conf->pause_time = pf->fc_conf.pause_time;
2830 fc_conf->high_water = pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS];
2831 fc_conf->low_water = pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS];
2833 /* Return current mode according to actual setting*/
2834 switch (hw->fc.current_mode) {
2836 fc_conf->mode = RTE_FC_FULL;
2838 case I40E_FC_TX_PAUSE:
2839 fc_conf->mode = RTE_FC_TX_PAUSE;
2841 case I40E_FC_RX_PAUSE:
2842 fc_conf->mode = RTE_FC_RX_PAUSE;
2846 fc_conf->mode = RTE_FC_NONE;
2853 i40e_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2855 uint32_t mflcn_reg, fctrl_reg, reg;
2856 uint32_t max_high_water;
2857 uint8_t i, aq_failure;
2861 enum i40e_fc_mode rte_fcmode_2_i40e_fcmode[] = {
2862 [RTE_FC_NONE] = I40E_FC_NONE,
2863 [RTE_FC_RX_PAUSE] = I40E_FC_RX_PAUSE,
2864 [RTE_FC_TX_PAUSE] = I40E_FC_TX_PAUSE,
2865 [RTE_FC_FULL] = I40E_FC_FULL
2868 /* high_water field in the rte_eth_fc_conf using the kilobytes unit */
2870 max_high_water = I40E_RXPBSIZE >> I40E_KILOSHIFT;
2871 if ((fc_conf->high_water > max_high_water) ||
2872 (fc_conf->high_water < fc_conf->low_water)) {
2873 PMD_INIT_LOG(ERR, "Invalid high/low water setup value in KB, "
2874 "High_water must <= %d.", max_high_water);
2878 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2879 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2880 hw->fc.requested_mode = rte_fcmode_2_i40e_fcmode[fc_conf->mode];
2882 pf->fc_conf.pause_time = fc_conf->pause_time;
2883 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->high_water;
2884 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->low_water;
2886 PMD_INIT_FUNC_TRACE();
2888 /* All the link flow control related enable/disable register
2889 * configuration is handle by the F/W
2891 err = i40e_set_fc(hw, &aq_failure, true);
2895 if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
2896 /* Configure flow control refresh threshold,
2897 * the value for stat_tx_pause_refresh_timer[8]
2898 * is used for global pause operation.
2902 I40E_PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER(8),
2903 pf->fc_conf.pause_time);
2905 /* configure the timer value included in transmitted pause
2907 * the value for stat_tx_pause_quanta[8] is used for global
2910 I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA(8),
2911 pf->fc_conf.pause_time);
2913 fctrl_reg = I40E_READ_REG(hw,
2914 I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL);
2916 if (fc_conf->mac_ctrl_frame_fwd != 0)
2917 fctrl_reg |= I40E_PRTMAC_FWD_CTRL;
2919 fctrl_reg &= ~I40E_PRTMAC_FWD_CTRL;
2921 I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL,
2924 /* Configure pause time (2 TCs per register) */
2925 reg = (uint32_t)pf->fc_conf.pause_time * (uint32_t)0x00010001;
2926 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS / 2; i++)
2927 I40E_WRITE_REG(hw, I40E_PRTDCB_FCTTVN(i), reg);
2929 /* Configure flow control refresh threshold value */
2930 I40E_WRITE_REG(hw, I40E_PRTDCB_FCRTV,
2931 pf->fc_conf.pause_time / 2);
2933 mflcn_reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
2935 /* set or clear MFLCN.PMCF & MFLCN.DPF bits
2936 *depending on configuration
2938 if (fc_conf->mac_ctrl_frame_fwd != 0) {
2939 mflcn_reg |= I40E_PRTDCB_MFLCN_PMCF_MASK;
2940 mflcn_reg &= ~I40E_PRTDCB_MFLCN_DPF_MASK;
2942 mflcn_reg &= ~I40E_PRTDCB_MFLCN_PMCF_MASK;
2943 mflcn_reg |= I40E_PRTDCB_MFLCN_DPF_MASK;
2946 I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, mflcn_reg);
2949 /* config the water marker both based on the packets and bytes */
2950 I40E_WRITE_REG(hw, I40E_GLRPB_PHW,
2951 (pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
2952 << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
2953 I40E_WRITE_REG(hw, I40E_GLRPB_PLW,
2954 (pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
2955 << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
2956 I40E_WRITE_REG(hw, I40E_GLRPB_GHW,
2957 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
2959 I40E_WRITE_REG(hw, I40E_GLRPB_GLW,
2960 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
2963 I40E_WRITE_FLUSH(hw);
2969 i40e_priority_flow_ctrl_set(__rte_unused struct rte_eth_dev *dev,
2970 __rte_unused struct rte_eth_pfc_conf *pfc_conf)
2972 PMD_INIT_FUNC_TRACE();
2977 /* Add a MAC address, and update filters */
2979 i40e_macaddr_add(struct rte_eth_dev *dev,
2980 struct ether_addr *mac_addr,
2981 __rte_unused uint32_t index,
2984 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2985 struct i40e_mac_filter_info mac_filter;
2986 struct i40e_vsi *vsi;
2989 /* If VMDQ not enabled or configured, return */
2990 if (pool != 0 && (!(pf->flags & I40E_FLAG_VMDQ) ||
2991 !pf->nb_cfg_vmdq_vsi)) {
2992 PMD_DRV_LOG(ERR, "VMDQ not %s, can't set mac to pool %u",
2993 pf->flags & I40E_FLAG_VMDQ ? "configured" : "enabled",
2998 if (pool > pf->nb_cfg_vmdq_vsi) {
2999 PMD_DRV_LOG(ERR, "Pool number %u invalid. Max pool is %u",
3000 pool, pf->nb_cfg_vmdq_vsi);
3004 (void)rte_memcpy(&mac_filter.mac_addr, mac_addr, ETHER_ADDR_LEN);
3005 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
3006 mac_filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
3008 mac_filter.filter_type = RTE_MAC_PERFECT_MATCH;
3013 vsi = pf->vmdq[pool - 1].vsi;
3015 ret = i40e_vsi_add_mac(vsi, &mac_filter);
3016 if (ret != I40E_SUCCESS) {
3017 PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
3022 /* Remove a MAC address, and update filters */
3024 i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
3026 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3027 struct i40e_vsi *vsi;
3028 struct rte_eth_dev_data *data = dev->data;
3029 struct ether_addr *macaddr;
3034 macaddr = &(data->mac_addrs[index]);
3036 pool_sel = dev->data->mac_pool_sel[index];
3038 for (i = 0; i < sizeof(pool_sel) * CHAR_BIT; i++) {
3039 if (pool_sel & (1ULL << i)) {
3043 /* No VMDQ pool enabled or configured */
3044 if (!(pf->flags & I40E_FLAG_VMDQ) ||
3045 (i > pf->nb_cfg_vmdq_vsi)) {
3046 PMD_DRV_LOG(ERR, "No VMDQ pool enabled"
3050 vsi = pf->vmdq[i - 1].vsi;
3052 ret = i40e_vsi_delete_mac(vsi, macaddr);
3055 PMD_DRV_LOG(ERR, "Failed to remove MACVLAN filter");
3062 /* Set perfect match or hash match of MAC and VLAN for a VF */
3064 i40e_vf_mac_filter_set(struct i40e_pf *pf,
3065 struct rte_eth_mac_filter *filter,
3069 struct i40e_mac_filter_info mac_filter;
3070 struct ether_addr old_mac;
3071 struct ether_addr *new_mac;
3072 struct i40e_pf_vf *vf = NULL;
3077 PMD_DRV_LOG(ERR, "Invalid PF argument.");
3080 hw = I40E_PF_TO_HW(pf);
3082 if (filter == NULL) {
3083 PMD_DRV_LOG(ERR, "Invalid mac filter argument.");
3087 new_mac = &filter->mac_addr;
3089 if (is_zero_ether_addr(new_mac)) {
3090 PMD_DRV_LOG(ERR, "Invalid ethernet address.");
3094 vf_id = filter->dst_id;
3096 if (vf_id > pf->vf_num - 1 || !pf->vfs) {
3097 PMD_DRV_LOG(ERR, "Invalid argument.");
3100 vf = &pf->vfs[vf_id];
3102 if (add && is_same_ether_addr(new_mac, &(pf->dev_addr))) {
3103 PMD_DRV_LOG(INFO, "Ignore adding permanent MAC address.");
3108 (void)rte_memcpy(&old_mac, hw->mac.addr, ETHER_ADDR_LEN);
3109 (void)rte_memcpy(hw->mac.addr, new_mac->addr_bytes,
3111 (void)rte_memcpy(&mac_filter.mac_addr, &filter->mac_addr,
3114 mac_filter.filter_type = filter->filter_type;
3115 ret = i40e_vsi_add_mac(vf->vsi, &mac_filter);
3116 if (ret != I40E_SUCCESS) {
3117 PMD_DRV_LOG(ERR, "Failed to add MAC filter.");
3120 ether_addr_copy(new_mac, &pf->dev_addr);
3122 (void)rte_memcpy(hw->mac.addr, hw->mac.perm_addr,
3124 ret = i40e_vsi_delete_mac(vf->vsi, &filter->mac_addr);
3125 if (ret != I40E_SUCCESS) {
3126 PMD_DRV_LOG(ERR, "Failed to delete MAC filter.");
3130 /* Clear device address as it has been removed */
3131 if (is_same_ether_addr(&(pf->dev_addr), new_mac))
3132 memset(&pf->dev_addr, 0, sizeof(struct ether_addr));
3138 /* MAC filter handle */
3140 i40e_mac_filter_handle(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
3143 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3144 struct rte_eth_mac_filter *filter;
3145 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
3146 int ret = I40E_NOT_SUPPORTED;
3148 filter = (struct rte_eth_mac_filter *)(arg);
3150 switch (filter_op) {
3151 case RTE_ETH_FILTER_NOP:
3154 case RTE_ETH_FILTER_ADD:
3155 i40e_pf_disable_irq0(hw);
3157 ret = i40e_vf_mac_filter_set(pf, filter, 1);
3158 i40e_pf_enable_irq0(hw);
3160 case RTE_ETH_FILTER_DELETE:
3161 i40e_pf_disable_irq0(hw);
3163 ret = i40e_vf_mac_filter_set(pf, filter, 0);
3164 i40e_pf_enable_irq0(hw);
3167 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
3168 ret = I40E_ERR_PARAM;
3176 i40e_get_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
3178 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
3179 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3185 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
3186 ret = i40e_aq_get_rss_lut(hw, vsi->vsi_id, TRUE,
3189 PMD_DRV_LOG(ERR, "Failed to get RSS lookup table");
3193 uint32_t *lut_dw = (uint32_t *)lut;
3194 uint16_t i, lut_size_dw = lut_size / 4;
3196 for (i = 0; i < lut_size_dw; i++)
3197 lut_dw[i] = I40E_READ_REG(hw, I40E_PFQF_HLUT(i));
3204 i40e_set_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
3213 pf = I40E_VSI_TO_PF(vsi);
3214 hw = I40E_VSI_TO_HW(vsi);
3216 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
3217 ret = i40e_aq_set_rss_lut(hw, vsi->vsi_id, TRUE,
3220 PMD_DRV_LOG(ERR, "Failed to set RSS lookup table");
3224 uint32_t *lut_dw = (uint32_t *)lut;
3225 uint16_t i, lut_size_dw = lut_size / 4;
3227 for (i = 0; i < lut_size_dw; i++)
3228 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
3229 I40E_WRITE_FLUSH(hw);
3236 i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
3237 struct rte_eth_rss_reta_entry64 *reta_conf,
3240 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3241 uint16_t i, lut_size = pf->hash_lut_size;
3242 uint16_t idx, shift;
3246 if (reta_size != lut_size ||
3247 reta_size > ETH_RSS_RETA_SIZE_512) {
3248 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
3249 "(%d) doesn't match the number hardware can supported "
3250 "(%d)\n", reta_size, lut_size);
3254 lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
3256 PMD_DRV_LOG(ERR, "No memory can be allocated");
3259 ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
3262 for (i = 0; i < reta_size; i++) {
3263 idx = i / RTE_RETA_GROUP_SIZE;
3264 shift = i % RTE_RETA_GROUP_SIZE;
3265 if (reta_conf[idx].mask & (1ULL << shift))
3266 lut[i] = reta_conf[idx].reta[shift];
3268 ret = i40e_set_rss_lut(pf->main_vsi, lut, reta_size);
3277 i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
3278 struct rte_eth_rss_reta_entry64 *reta_conf,
3281 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3282 uint16_t i, lut_size = pf->hash_lut_size;
3283 uint16_t idx, shift;
3287 if (reta_size != lut_size ||
3288 reta_size > ETH_RSS_RETA_SIZE_512) {
3289 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
3290 "(%d) doesn't match the number hardware can supported "
3291 "(%d)\n", reta_size, lut_size);
3295 lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
3297 PMD_DRV_LOG(ERR, "No memory can be allocated");
3301 ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
3304 for (i = 0; i < reta_size; i++) {
3305 idx = i / RTE_RETA_GROUP_SIZE;
3306 shift = i % RTE_RETA_GROUP_SIZE;
3307 if (reta_conf[idx].mask & (1ULL << shift))
3308 reta_conf[idx].reta[shift] = lut[i];
3318 * i40e_allocate_dma_mem_d - specific memory alloc for shared code (base driver)
3319 * @hw: pointer to the HW structure
3320 * @mem: pointer to mem struct to fill out
3321 * @size: size of memory requested
3322 * @alignment: what to align the allocation to
3324 enum i40e_status_code
3325 i40e_allocate_dma_mem_d(__attribute__((unused)) struct i40e_hw *hw,
3326 struct i40e_dma_mem *mem,
3330 const struct rte_memzone *mz = NULL;
3331 char z_name[RTE_MEMZONE_NAMESIZE];
3334 return I40E_ERR_PARAM;
3336 snprintf(z_name, sizeof(z_name), "i40e_dma_%"PRIu64, rte_rand());
3337 mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY, 0,
3338 alignment, RTE_PGSIZE_2M);
3340 return I40E_ERR_NO_MEMORY;
3344 mem->pa = rte_mem_phy2mch(mz->memseg_id, mz->phys_addr);
3345 mem->zone = (const void *)mz;
3346 PMD_DRV_LOG(DEBUG, "memzone %s allocated with physical address: "
3347 "%"PRIu64, mz->name, mem->pa);
3349 return I40E_SUCCESS;
3353 * i40e_free_dma_mem_d - specific memory free for shared code (base driver)
3354 * @hw: pointer to the HW structure
3355 * @mem: ptr to mem struct to free
3357 enum i40e_status_code
3358 i40e_free_dma_mem_d(__attribute__((unused)) struct i40e_hw *hw,
3359 struct i40e_dma_mem *mem)
3362 return I40E_ERR_PARAM;
3364 PMD_DRV_LOG(DEBUG, "memzone %s to be freed with physical address: "
3365 "%"PRIu64, ((const struct rte_memzone *)mem->zone)->name,
3367 rte_memzone_free((const struct rte_memzone *)mem->zone);
3372 return I40E_SUCCESS;
3376 * i40e_allocate_virt_mem_d - specific memory alloc for shared code (base driver)
3377 * @hw: pointer to the HW structure
3378 * @mem: pointer to mem struct to fill out
3379 * @size: size of memory requested
3381 enum i40e_status_code
3382 i40e_allocate_virt_mem_d(__attribute__((unused)) struct i40e_hw *hw,
3383 struct i40e_virt_mem *mem,
3387 return I40E_ERR_PARAM;
3390 mem->va = rte_zmalloc("i40e", size, 0);
3393 return I40E_SUCCESS;
3395 return I40E_ERR_NO_MEMORY;
3399 * i40e_free_virt_mem_d - specific memory free for shared code (base driver)
3400 * @hw: pointer to the HW structure
3401 * @mem: pointer to mem struct to free
3403 enum i40e_status_code
3404 i40e_free_virt_mem_d(__attribute__((unused)) struct i40e_hw *hw,
3405 struct i40e_virt_mem *mem)
3408 return I40E_ERR_PARAM;
3413 return I40E_SUCCESS;
3417 i40e_init_spinlock_d(struct i40e_spinlock *sp)
3419 rte_spinlock_init(&sp->spinlock);
3423 i40e_acquire_spinlock_d(struct i40e_spinlock *sp)
3425 rte_spinlock_lock(&sp->spinlock);
3429 i40e_release_spinlock_d(struct i40e_spinlock *sp)
3431 rte_spinlock_unlock(&sp->spinlock);
3435 i40e_destroy_spinlock_d(__attribute__((unused)) struct i40e_spinlock *sp)
3441 * Get the hardware capabilities, which will be parsed
3442 * and saved into struct i40e_hw.
3445 i40e_get_cap(struct i40e_hw *hw)
3447 struct i40e_aqc_list_capabilities_element_resp *buf;
3448 uint16_t len, size = 0;
3451 /* Calculate a huge enough buff for saving response data temporarily */
3452 len = sizeof(struct i40e_aqc_list_capabilities_element_resp) *
3453 I40E_MAX_CAP_ELE_NUM;
3454 buf = rte_zmalloc("i40e", len, 0);
3456 PMD_DRV_LOG(ERR, "Failed to allocate memory");
3457 return I40E_ERR_NO_MEMORY;
3460 /* Get, parse the capabilities and save it to hw */
3461 ret = i40e_aq_discover_capabilities(hw, buf, len, &size,
3462 i40e_aqc_opc_list_func_capabilities, NULL);
3463 if (ret != I40E_SUCCESS)
3464 PMD_DRV_LOG(ERR, "Failed to discover capabilities");
3466 /* Free the temporary buffer after being used */
3473 i40e_pf_parameter_init(struct rte_eth_dev *dev)
3475 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3476 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
3477 uint16_t qp_count = 0, vsi_count = 0;
3479 if (dev->pci_dev->max_vfs && !hw->func_caps.sr_iov_1_1) {
3480 PMD_INIT_LOG(ERR, "HW configuration doesn't support SRIOV");
3483 /* Add the parameter init for LFC */
3484 pf->fc_conf.pause_time = I40E_DEFAULT_PAUSE_TIME;
3485 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_HIGH_WATER;
3486 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_LOW_WATER;
3488 pf->flags = I40E_FLAG_HEADER_SPLIT_DISABLED;
3489 pf->max_num_vsi = hw->func_caps.num_vsis;
3490 pf->lan_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_PF;
3491 pf->vmdq_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
3492 pf->vf_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF;
3494 /* FDir queue/VSI allocation */
3495 pf->fdir_qp_offset = 0;
3496 if (hw->func_caps.fd) {
3497 pf->flags |= I40E_FLAG_FDIR;
3498 pf->fdir_nb_qps = I40E_DEFAULT_QP_NUM_FDIR;
3500 pf->fdir_nb_qps = 0;
3502 qp_count += pf->fdir_nb_qps;
3505 /* LAN queue/VSI allocation */
3506 pf->lan_qp_offset = pf->fdir_qp_offset + pf->fdir_nb_qps;
3507 if (!hw->func_caps.rss) {
3510 pf->flags |= I40E_FLAG_RSS;
3511 if (hw->mac.type == I40E_MAC_X722)
3512 pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE;
3513 pf->lan_nb_qps = pf->lan_nb_qp_max;
3515 qp_count += pf->lan_nb_qps;
3518 /* VF queue/VSI allocation */
3519 pf->vf_qp_offset = pf->lan_qp_offset + pf->lan_nb_qps;
3520 if (hw->func_caps.sr_iov_1_1 && dev->pci_dev->max_vfs) {
3521 pf->flags |= I40E_FLAG_SRIOV;
3522 pf->vf_nb_qps = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF;
3523 pf->vf_num = dev->pci_dev->max_vfs;
3524 PMD_DRV_LOG(DEBUG, "%u VF VSIs, %u queues per VF VSI, "
3525 "in total %u queues", pf->vf_num, pf->vf_nb_qps,
3526 pf->vf_nb_qps * pf->vf_num);
3531 qp_count += pf->vf_nb_qps * pf->vf_num;
3532 vsi_count += pf->vf_num;
3534 /* VMDq queue/VSI allocation */
3535 pf->vmdq_qp_offset = pf->vf_qp_offset + pf->vf_nb_qps * pf->vf_num;
3536 pf->vmdq_nb_qps = 0;
3537 pf->max_nb_vmdq_vsi = 0;
3538 if (hw->func_caps.vmdq) {
3539 if (qp_count < hw->func_caps.num_tx_qp &&
3540 vsi_count < hw->func_caps.num_vsis) {
3541 pf->max_nb_vmdq_vsi = (hw->func_caps.num_tx_qp -
3542 qp_count) / pf->vmdq_nb_qp_max;
3544 /* Limit the maximum number of VMDq vsi to the maximum
3545 * ethdev can support
3547 pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
3548 hw->func_caps.num_vsis - vsi_count);
3549 pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
3551 if (pf->max_nb_vmdq_vsi) {
3552 pf->flags |= I40E_FLAG_VMDQ;
3553 pf->vmdq_nb_qps = pf->vmdq_nb_qp_max;
3554 PMD_DRV_LOG(DEBUG, "%u VMDQ VSIs, %u queues "
3555 "per VMDQ VSI, in total %u queues",
3556 pf->max_nb_vmdq_vsi,
3557 pf->vmdq_nb_qps, pf->vmdq_nb_qps *
3558 pf->max_nb_vmdq_vsi);
3560 PMD_DRV_LOG(INFO, "No enough queues left for "
3564 PMD_DRV_LOG(INFO, "No queue or VSI left for VMDq");
3567 qp_count += pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi;
3568 vsi_count += pf->max_nb_vmdq_vsi;
3570 if (hw->func_caps.dcb)
3571 pf->flags |= I40E_FLAG_DCB;
3573 if (qp_count > hw->func_caps.num_tx_qp) {
3574 PMD_DRV_LOG(ERR, "Failed to allocate %u queues, which exceeds "
3575 "the hardware maximum %u", qp_count,
3576 hw->func_caps.num_tx_qp);
3579 if (vsi_count > hw->func_caps.num_vsis) {
3580 PMD_DRV_LOG(ERR, "Failed to allocate %u VSIs, which exceeds "
3581 "the hardware maximum %u", vsi_count,
3582 hw->func_caps.num_vsis);
3590 i40e_pf_get_switch_config(struct i40e_pf *pf)
3592 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
3593 struct i40e_aqc_get_switch_config_resp *switch_config;
3594 struct i40e_aqc_switch_config_element_resp *element;
3595 uint16_t start_seid = 0, num_reported;
3598 switch_config = (struct i40e_aqc_get_switch_config_resp *)\
3599 rte_zmalloc("i40e", I40E_AQ_LARGE_BUF, 0);
3600 if (!switch_config) {
3601 PMD_DRV_LOG(ERR, "Failed to allocated memory");
3605 /* Get the switch configurations */
3606 ret = i40e_aq_get_switch_config(hw, switch_config,
3607 I40E_AQ_LARGE_BUF, &start_seid, NULL);
3608 if (ret != I40E_SUCCESS) {
3609 PMD_DRV_LOG(ERR, "Failed to get switch configurations");
3612 num_reported = rte_le_to_cpu_16(switch_config->header.num_reported);
3613 if (num_reported != 1) { /* The number should be 1 */
3614 PMD_DRV_LOG(ERR, "Wrong number of switch config reported");
3618 /* Parse the switch configuration elements */
3619 element = &(switch_config->element[0]);
3620 if (element->element_type == I40E_SWITCH_ELEMENT_TYPE_VSI) {
3621 pf->mac_seid = rte_le_to_cpu_16(element->uplink_seid);
3622 pf->main_vsi_seid = rte_le_to_cpu_16(element->seid);
3624 PMD_DRV_LOG(INFO, "Unknown element type");
3627 rte_free(switch_config);
3633 i40e_res_pool_init (struct i40e_res_pool_info *pool, uint32_t base,
3636 struct pool_entry *entry;
3638 if (pool == NULL || num == 0)
3641 entry = rte_zmalloc("i40e", sizeof(*entry), 0);
3642 if (entry == NULL) {
3643 PMD_DRV_LOG(ERR, "Failed to allocate memory for resource pool");
3647 /* queue heap initialize */
3648 pool->num_free = num;
3649 pool->num_alloc = 0;
3651 LIST_INIT(&pool->alloc_list);
3652 LIST_INIT(&pool->free_list);
3654 /* Initialize element */
3658 LIST_INSERT_HEAD(&pool->free_list, entry, next);
3663 i40e_res_pool_destroy(struct i40e_res_pool_info *pool)
3665 struct pool_entry *entry, *next_entry;
3670 for (entry = LIST_FIRST(&pool->alloc_list);
3671 entry && (next_entry = LIST_NEXT(entry, next), 1);
3672 entry = next_entry) {
3673 LIST_REMOVE(entry, next);
3677 for (entry = LIST_FIRST(&pool->free_list);
3678 entry && (next_entry = LIST_NEXT(entry, next), 1);
3679 entry = next_entry) {
3680 LIST_REMOVE(entry, next);
3685 pool->num_alloc = 0;
3687 LIST_INIT(&pool->alloc_list);
3688 LIST_INIT(&pool->free_list);
3692 i40e_res_pool_free(struct i40e_res_pool_info *pool,
3695 struct pool_entry *entry, *next, *prev, *valid_entry = NULL;
3696 uint32_t pool_offset;
3700 PMD_DRV_LOG(ERR, "Invalid parameter");
3704 pool_offset = base - pool->base;
3705 /* Lookup in alloc list */
3706 LIST_FOREACH(entry, &pool->alloc_list, next) {
3707 if (entry->base == pool_offset) {
3708 valid_entry = entry;
3709 LIST_REMOVE(entry, next);
3714 /* Not find, return */
3715 if (valid_entry == NULL) {
3716 PMD_DRV_LOG(ERR, "Failed to find entry");
3721 * Found it, move it to free list and try to merge.
3722 * In order to make merge easier, always sort it by qbase.
3723 * Find adjacent prev and last entries.
3726 LIST_FOREACH(entry, &pool->free_list, next) {
3727 if (entry->base > valid_entry->base) {
3735 /* Try to merge with next one*/
3737 /* Merge with next one */
3738 if (valid_entry->base + valid_entry->len == next->base) {
3739 next->base = valid_entry->base;
3740 next->len += valid_entry->len;
3741 rte_free(valid_entry);
3748 /* Merge with previous one */
3749 if (prev->base + prev->len == valid_entry->base) {
3750 prev->len += valid_entry->len;
3751 /* If it merge with next one, remove next node */
3753 LIST_REMOVE(valid_entry, next);
3754 rte_free(valid_entry);
3756 rte_free(valid_entry);
3762 /* Not find any entry to merge, insert */
3765 LIST_INSERT_AFTER(prev, valid_entry, next);
3766 else if (next != NULL)
3767 LIST_INSERT_BEFORE(next, valid_entry, next);
3768 else /* It's empty list, insert to head */
3769 LIST_INSERT_HEAD(&pool->free_list, valid_entry, next);
3772 pool->num_free += valid_entry->len;
3773 pool->num_alloc -= valid_entry->len;
3779 i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
3782 struct pool_entry *entry, *valid_entry;
3784 if (pool == NULL || num == 0) {
3785 PMD_DRV_LOG(ERR, "Invalid parameter");
3789 if (pool->num_free < num) {
3790 PMD_DRV_LOG(ERR, "No resource. ask:%u, available:%u",
3791 num, pool->num_free);
3796 /* Lookup in free list and find most fit one */
3797 LIST_FOREACH(entry, &pool->free_list, next) {
3798 if (entry->len >= num) {
3800 if (entry->len == num) {
3801 valid_entry = entry;
3804 if (valid_entry == NULL || valid_entry->len > entry->len)
3805 valid_entry = entry;
3809 /* Not find one to satisfy the request, return */
3810 if (valid_entry == NULL) {
3811 PMD_DRV_LOG(ERR, "No valid entry found");
3815 * The entry have equal queue number as requested,
3816 * remove it from alloc_list.
3818 if (valid_entry->len == num) {
3819 LIST_REMOVE(valid_entry, next);
3822 * The entry have more numbers than requested,
3823 * create a new entry for alloc_list and minus its
3824 * queue base and number in free_list.
3826 entry = rte_zmalloc("res_pool", sizeof(*entry), 0);
3827 if (entry == NULL) {
3828 PMD_DRV_LOG(ERR, "Failed to allocate memory for "
3832 entry->base = valid_entry->base;
3834 valid_entry->base += num;
3835 valid_entry->len -= num;
3836 valid_entry = entry;
3839 /* Insert it into alloc list, not sorted */
3840 LIST_INSERT_HEAD(&pool->alloc_list, valid_entry, next);
3842 pool->num_free -= valid_entry->len;
3843 pool->num_alloc += valid_entry->len;
3845 return valid_entry->base + pool->base;
3849 * bitmap_is_subset - Check whether src2 is subset of src1
3852 bitmap_is_subset(uint8_t src1, uint8_t src2)
3854 return !((src1 ^ src2) & src2);
3857 static enum i40e_status_code
3858 validate_tcmap_parameter(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
3860 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3862 /* If DCB is not supported, only default TC is supported */
3863 if (!hw->func_caps.dcb && enabled_tcmap != I40E_DEFAULT_TCMAP) {
3864 PMD_DRV_LOG(ERR, "DCB is not enabled, only TC0 is supported");
3865 return I40E_NOT_SUPPORTED;
3868 if (!bitmap_is_subset(hw->func_caps.enabled_tcmap, enabled_tcmap)) {
3869 PMD_DRV_LOG(ERR, "Enabled TC map 0x%x not applicable to "
3870 "HW support 0x%x", hw->func_caps.enabled_tcmap,
3872 return I40E_NOT_SUPPORTED;
3874 return I40E_SUCCESS;
3878 i40e_vsi_vlan_pvid_set(struct i40e_vsi *vsi,
3879 struct i40e_vsi_vlan_pvid_info *info)
3882 struct i40e_vsi_context ctxt;
3883 uint8_t vlan_flags = 0;
3886 if (vsi == NULL || info == NULL) {
3887 PMD_DRV_LOG(ERR, "invalid parameters");
3888 return I40E_ERR_PARAM;
3892 vsi->info.pvid = info->config.pvid;
3894 * If insert pvid is enabled, only tagged pkts are
3895 * allowed to be sent out.
3897 vlan_flags |= I40E_AQ_VSI_PVLAN_INSERT_PVID |
3898 I40E_AQ_VSI_PVLAN_MODE_TAGGED;
3901 if (info->config.reject.tagged == 0)
3902 vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_TAGGED;
3904 if (info->config.reject.untagged == 0)
3905 vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_UNTAGGED;
3907 vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_INSERT_PVID |
3908 I40E_AQ_VSI_PVLAN_MODE_MASK);
3909 vsi->info.port_vlan_flags |= vlan_flags;
3910 vsi->info.valid_sections =
3911 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
3912 memset(&ctxt, 0, sizeof(ctxt));
3913 (void)rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
3914 ctxt.seid = vsi->seid;
3916 hw = I40E_VSI_TO_HW(vsi);
3917 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
3918 if (ret != I40E_SUCCESS)
3919 PMD_DRV_LOG(ERR, "Failed to update VSI params");
3925 i40e_vsi_update_tc_bandwidth(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
3927 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3929 struct i40e_aqc_configure_vsi_tc_bw_data tc_bw_data;
3931 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
3932 if (ret != I40E_SUCCESS)
3936 PMD_DRV_LOG(ERR, "seid not valid");
3940 memset(&tc_bw_data, 0, sizeof(tc_bw_data));
3941 tc_bw_data.tc_valid_bits = enabled_tcmap;
3942 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
3943 tc_bw_data.tc_bw_credits[i] =
3944 (enabled_tcmap & (1 << i)) ? 1 : 0;
3946 ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &tc_bw_data, NULL);
3947 if (ret != I40E_SUCCESS) {
3948 PMD_DRV_LOG(ERR, "Failed to configure TC BW");
3952 (void)rte_memcpy(vsi->info.qs_handle, tc_bw_data.qs_handles,
3953 sizeof(vsi->info.qs_handle));
3954 return I40E_SUCCESS;
3957 static enum i40e_status_code
3958 i40e_vsi_config_tc_queue_mapping(struct i40e_vsi *vsi,
3959 struct i40e_aqc_vsi_properties_data *info,
3960 uint8_t enabled_tcmap)
3962 enum i40e_status_code ret;
3963 int i, total_tc = 0;
3964 uint16_t qpnum_per_tc, bsf, qp_idx;
3966 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
3967 if (ret != I40E_SUCCESS)
3970 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
3971 if (enabled_tcmap & (1 << i))
3973 vsi->enabled_tc = enabled_tcmap;
3975 /* Number of queues per enabled TC */
3976 qpnum_per_tc = i40e_align_floor(vsi->nb_qps / total_tc);
3977 qpnum_per_tc = RTE_MIN(qpnum_per_tc, I40E_MAX_Q_PER_TC);
3978 bsf = rte_bsf32(qpnum_per_tc);
3980 /* Adjust the queue number to actual queues that can be applied */
3981 if (!(vsi->type == I40E_VSI_MAIN && total_tc == 1))
3982 vsi->nb_qps = qpnum_per_tc * total_tc;
3985 * Configure TC and queue mapping parameters, for enabled TC,
3986 * allocate qpnum_per_tc queues to this traffic. For disabled TC,
3987 * default queue will serve it.
3990 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
3991 if (vsi->enabled_tc & (1 << i)) {
3992 info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
3993 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
3994 (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
3995 qp_idx += qpnum_per_tc;
3997 info->tc_mapping[i] = 0;
4000 /* Associate queue number with VSI */
4001 if (vsi->type == I40E_VSI_SRIOV) {
4002 info->mapping_flags |=
4003 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
4004 for (i = 0; i < vsi->nb_qps; i++)
4005 info->queue_mapping[i] =
4006 rte_cpu_to_le_16(vsi->base_queue + i);
4008 info->mapping_flags |=
4009 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
4010 info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
4012 info->valid_sections |=
4013 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
4015 return I40E_SUCCESS;
4019 i40e_veb_release(struct i40e_veb *veb)
4021 struct i40e_vsi *vsi;
4027 if (!TAILQ_EMPTY(&veb->head)) {
4028 PMD_DRV_LOG(ERR, "VEB still has VSI attached, can't remove");
4031 /* associate_vsi field is NULL for floating VEB */
4032 if (veb->associate_vsi != NULL) {
4033 vsi = veb->associate_vsi;
4034 hw = I40E_VSI_TO_HW(vsi);
4036 vsi->uplink_seid = veb->uplink_seid;
4039 veb->associate_pf->main_vsi->floating_veb = NULL;
4040 hw = I40E_VSI_TO_HW(veb->associate_pf->main_vsi);
4043 i40e_aq_delete_element(hw, veb->seid, NULL);
4045 return I40E_SUCCESS;
4049 static struct i40e_veb *
4050 i40e_veb_setup(struct i40e_pf *pf, struct i40e_vsi *vsi)
4052 struct i40e_veb *veb;
4058 "veb setup failed, associated PF shouldn't null");
4061 hw = I40E_PF_TO_HW(pf);
4063 veb = rte_zmalloc("i40e_veb", sizeof(struct i40e_veb), 0);
4065 PMD_DRV_LOG(ERR, "Failed to allocate memory for veb");
4069 veb->associate_vsi = vsi;
4070 veb->associate_pf = pf;
4071 TAILQ_INIT(&veb->head);
4072 veb->uplink_seid = vsi ? vsi->uplink_seid : 0;
4074 /* create floating veb if vsi is NULL */
4076 ret = i40e_aq_add_veb(hw, veb->uplink_seid, vsi->seid,
4077 I40E_DEFAULT_TCMAP, false,
4078 &veb->seid, false, NULL);
4080 ret = i40e_aq_add_veb(hw, 0, 0, I40E_DEFAULT_TCMAP,
4081 true, &veb->seid, false, NULL);
4084 if (ret != I40E_SUCCESS) {
4085 PMD_DRV_LOG(ERR, "Add veb failed, aq_err: %d",
4086 hw->aq.asq_last_status);
4090 /* get statistics index */
4091 ret = i40e_aq_get_veb_parameters(hw, veb->seid, NULL, NULL,
4092 &veb->stats_idx, NULL, NULL, NULL);
4093 if (ret != I40E_SUCCESS) {
4094 PMD_DRV_LOG(ERR, "Get veb statics index failed, aq_err: %d",
4095 hw->aq.asq_last_status);
4098 /* Get VEB bandwidth, to be implemented */
4099 /* Now associated vsi binding to the VEB, set uplink to this VEB */
4101 vsi->uplink_seid = veb->seid;
4110 i40e_vsi_release(struct i40e_vsi *vsi)
4114 struct i40e_vsi_list *vsi_list;
4117 struct i40e_mac_filter *f;
4118 uint16_t user_param = vsi->user_param;
4121 return I40E_SUCCESS;
4123 pf = I40E_VSI_TO_PF(vsi);
4124 hw = I40E_VSI_TO_HW(vsi);
4126 /* VSI has child to attach, release child first */
4128 TAILQ_FOREACH_SAFE(vsi_list, &vsi->veb->head, list, temp) {
4129 if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
4132 i40e_veb_release(vsi->veb);
4135 if (vsi->floating_veb) {
4136 TAILQ_FOREACH_SAFE(vsi_list, &vsi->floating_veb->head, list, temp) {
4137 if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
4142 /* Remove all macvlan filters of the VSI */
4143 i40e_vsi_remove_all_macvlan_filter(vsi);
4144 TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp)
4147 if (vsi->type != I40E_VSI_MAIN &&
4148 ((vsi->type != I40E_VSI_SRIOV) ||
4149 !pf->floating_veb_list[user_param])) {
4150 /* Remove vsi from parent's sibling list */
4151 if (vsi->parent_vsi == NULL || vsi->parent_vsi->veb == NULL) {
4152 PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
4153 return I40E_ERR_PARAM;
4155 TAILQ_REMOVE(&vsi->parent_vsi->veb->head,
4156 &vsi->sib_vsi_list, list);
4158 /* Remove all switch element of the VSI */
4159 ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
4160 if (ret != I40E_SUCCESS)
4161 PMD_DRV_LOG(ERR, "Failed to delete element");
4164 if ((vsi->type == I40E_VSI_SRIOV) &&
4165 pf->floating_veb_list[user_param]) {
4166 /* Remove vsi from parent's sibling list */
4167 if (vsi->parent_vsi == NULL ||
4168 vsi->parent_vsi->floating_veb == NULL) {
4169 PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
4170 return I40E_ERR_PARAM;
4172 TAILQ_REMOVE(&vsi->parent_vsi->floating_veb->head,
4173 &vsi->sib_vsi_list, list);
4175 /* Remove all switch element of the VSI */
4176 ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
4177 if (ret != I40E_SUCCESS)
4178 PMD_DRV_LOG(ERR, "Failed to delete element");
4181 i40e_res_pool_free(&pf->qp_pool, vsi->base_queue);
4183 if (vsi->type != I40E_VSI_SRIOV)
4184 i40e_res_pool_free(&pf->msix_pool, vsi->msix_intr);
4187 return I40E_SUCCESS;
4191 i40e_update_default_filter_setting(struct i40e_vsi *vsi)
4193 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4194 struct i40e_aqc_remove_macvlan_element_data def_filter;
4195 struct i40e_mac_filter_info filter;
4198 if (vsi->type != I40E_VSI_MAIN)
4199 return I40E_ERR_CONFIG;
4200 memset(&def_filter, 0, sizeof(def_filter));
4201 (void)rte_memcpy(def_filter.mac_addr, hw->mac.perm_addr,
4203 def_filter.vlan_tag = 0;
4204 def_filter.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
4205 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
4206 ret = i40e_aq_remove_macvlan(hw, vsi->seid, &def_filter, 1, NULL);
4207 if (ret != I40E_SUCCESS) {
4208 struct i40e_mac_filter *f;
4209 struct ether_addr *mac;
4211 PMD_DRV_LOG(WARNING, "Cannot remove the default "
4213 /* It needs to add the permanent mac into mac list */
4214 f = rte_zmalloc("macv_filter", sizeof(*f), 0);
4216 PMD_DRV_LOG(ERR, "failed to allocate memory");
4217 return I40E_ERR_NO_MEMORY;
4219 mac = &f->mac_info.mac_addr;
4220 (void)rte_memcpy(&mac->addr_bytes, hw->mac.perm_addr,
4222 f->mac_info.filter_type = RTE_MACVLAN_PERFECT_MATCH;
4223 TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
4228 (void)rte_memcpy(&filter.mac_addr,
4229 (struct ether_addr *)(hw->mac.perm_addr), ETH_ADDR_LEN);
4230 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
4231 return i40e_vsi_add_mac(vsi, &filter);
4235 * i40e_vsi_get_bw_config - Query VSI BW Information
4236 * @vsi: the VSI to be queried
4238 * Returns 0 on success, negative value on failure
4240 static enum i40e_status_code
4241 i40e_vsi_get_bw_config(struct i40e_vsi *vsi)
4243 struct i40e_aqc_query_vsi_bw_config_resp bw_config;
4244 struct i40e_aqc_query_vsi_ets_sla_config_resp ets_sla_config;
4245 struct i40e_hw *hw = &vsi->adapter->hw;
4250 memset(&bw_config, 0, sizeof(bw_config));
4251 ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
4252 if (ret != I40E_SUCCESS) {
4253 PMD_DRV_LOG(ERR, "VSI failed to get bandwidth configuration %u",
4254 hw->aq.asq_last_status);
4258 memset(&ets_sla_config, 0, sizeof(ets_sla_config));
4259 ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid,
4260 &ets_sla_config, NULL);
4261 if (ret != I40E_SUCCESS) {
4262 PMD_DRV_LOG(ERR, "VSI failed to get TC bandwdith "
4263 "configuration %u", hw->aq.asq_last_status);
4267 /* store and print out BW info */
4268 vsi->bw_info.bw_limit = rte_le_to_cpu_16(bw_config.port_bw_limit);
4269 vsi->bw_info.bw_max = bw_config.max_bw;
4270 PMD_DRV_LOG(DEBUG, "VSI bw limit:%u", vsi->bw_info.bw_limit);
4271 PMD_DRV_LOG(DEBUG, "VSI max_bw:%u", vsi->bw_info.bw_max);
4272 bw_max = rte_le_to_cpu_16(ets_sla_config.tc_bw_max[0]) |
4273 (rte_le_to_cpu_16(ets_sla_config.tc_bw_max[1]) <<
4275 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
4276 vsi->bw_info.bw_ets_share_credits[i] =
4277 ets_sla_config.share_credits[i];
4278 vsi->bw_info.bw_ets_credits[i] =
4279 rte_le_to_cpu_16(ets_sla_config.credits[i]);
4280 /* 4 bits per TC, 4th bit is reserved */
4281 vsi->bw_info.bw_ets_max[i] =
4282 (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
4283 RTE_LEN2MASK(3, uint8_t));
4284 PMD_DRV_LOG(DEBUG, "\tVSI TC%u:share credits %u", i,
4285 vsi->bw_info.bw_ets_share_credits[i]);
4286 PMD_DRV_LOG(DEBUG, "\tVSI TC%u:credits %u", i,
4287 vsi->bw_info.bw_ets_credits[i]);
4288 PMD_DRV_LOG(DEBUG, "\tVSI TC%u: max credits: %u", i,
4289 vsi->bw_info.bw_ets_max[i]);
4292 return I40E_SUCCESS;
4295 /* i40e_enable_pf_lb
4296 * @pf: pointer to the pf structure
4298 * allow loopback on pf
4301 i40e_enable_pf_lb(struct i40e_pf *pf)
4303 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4304 struct i40e_vsi_context ctxt;
4307 /* Use the FW API if FW >= v5.0 */
4308 if (hw->aq.fw_maj_ver < 5) {
4309 PMD_INIT_LOG(ERR, "FW < v5.0, cannot enable loopback");
4313 memset(&ctxt, 0, sizeof(ctxt));
4314 ctxt.seid = pf->main_vsi_seid;
4315 ctxt.pf_num = hw->pf_id;
4316 ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
4318 PMD_DRV_LOG(ERR, "cannot get pf vsi config, err %d, aq_err %d",
4319 ret, hw->aq.asq_last_status);
4322 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
4323 ctxt.info.valid_sections =
4324 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
4325 ctxt.info.switch_id |=
4326 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
4328 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
4330 PMD_DRV_LOG(ERR, "update vsi switch failed, aq_err=%d\n",
4331 hw->aq.asq_last_status);
4336 i40e_vsi_setup(struct i40e_pf *pf,
4337 enum i40e_vsi_type type,
4338 struct i40e_vsi *uplink_vsi,
4339 uint16_t user_param)
4341 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4342 struct i40e_vsi *vsi;
4343 struct i40e_mac_filter_info filter;
4345 struct i40e_vsi_context ctxt;
4346 struct ether_addr broadcast =
4347 {.addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
4349 if (type != I40E_VSI_MAIN && type != I40E_VSI_SRIOV &&
4350 uplink_vsi == NULL) {
4351 PMD_DRV_LOG(ERR, "VSI setup failed, "
4352 "VSI link shouldn't be NULL");
4356 if (type == I40E_VSI_MAIN && uplink_vsi != NULL) {
4357 PMD_DRV_LOG(ERR, "VSI setup failed, MAIN VSI "
4358 "uplink VSI should be NULL");
4363 * 1.type is not MAIN and uplink vsi is not NULL
4364 * If uplink vsi didn't setup VEB, create one first under veb field
4365 * 2.type is SRIOV and the uplink is NULL
4366 * If floating VEB is NULL, create one veb under floating veb field
4369 if (type != I40E_VSI_MAIN && uplink_vsi != NULL &&
4370 uplink_vsi->veb == NULL) {
4371 uplink_vsi->veb = i40e_veb_setup(pf, uplink_vsi);
4373 if (uplink_vsi->veb == NULL) {
4374 PMD_DRV_LOG(ERR, "VEB setup failed");
4377 /* set ALLOWLOOPBACk on pf, when veb is created */
4378 i40e_enable_pf_lb(pf);
4381 if (type == I40E_VSI_SRIOV && uplink_vsi == NULL &&
4382 pf->main_vsi->floating_veb == NULL) {
4383 pf->main_vsi->floating_veb = i40e_veb_setup(pf, uplink_vsi);
4385 if (pf->main_vsi->floating_veb == NULL) {
4386 PMD_DRV_LOG(ERR, "VEB setup failed");
4391 vsi = rte_zmalloc("i40e_vsi", sizeof(struct i40e_vsi), 0);
4393 PMD_DRV_LOG(ERR, "Failed to allocate memory for vsi");
4396 TAILQ_INIT(&vsi->mac_list);
4398 vsi->adapter = I40E_PF_TO_ADAPTER(pf);
4399 vsi->max_macaddrs = I40E_NUM_MACADDR_MAX;
4400 vsi->parent_vsi = uplink_vsi ? uplink_vsi : pf->main_vsi;
4401 vsi->user_param = user_param;
4402 /* Allocate queues */
4403 switch (vsi->type) {
4404 case I40E_VSI_MAIN :
4405 vsi->nb_qps = pf->lan_nb_qps;
4407 case I40E_VSI_SRIOV :
4408 vsi->nb_qps = pf->vf_nb_qps;
4410 case I40E_VSI_VMDQ2:
4411 vsi->nb_qps = pf->vmdq_nb_qps;
4414 vsi->nb_qps = pf->fdir_nb_qps;
4420 * The filter status descriptor is reported in rx queue 0,
4421 * while the tx queue for fdir filter programming has no
4422 * such constraints, can be non-zero queues.
4423 * To simplify it, choose FDIR vsi use queue 0 pair.
4424 * To make sure it will use queue 0 pair, queue allocation
4425 * need be done before this function is called
4427 if (type != I40E_VSI_FDIR) {
4428 ret = i40e_res_pool_alloc(&pf->qp_pool, vsi->nb_qps);
4430 PMD_DRV_LOG(ERR, "VSI %d allocate queue failed %d",
4434 vsi->base_queue = ret;
4436 vsi->base_queue = I40E_FDIR_QUEUE_ID;
4438 /* VF has MSIX interrupt in VF range, don't allocate here */
4439 if (type == I40E_VSI_MAIN) {
4440 ret = i40e_res_pool_alloc(&pf->msix_pool,
4441 RTE_MIN(vsi->nb_qps,
4442 RTE_MAX_RXTX_INTR_VEC_ID));
4444 PMD_DRV_LOG(ERR, "VSI MAIN %d get heap failed %d",
4446 goto fail_queue_alloc;
4448 vsi->msix_intr = ret;
4449 vsi->nb_msix = RTE_MIN(vsi->nb_qps, RTE_MAX_RXTX_INTR_VEC_ID);
4450 } else if (type != I40E_VSI_SRIOV) {
4451 ret = i40e_res_pool_alloc(&pf->msix_pool, 1);
4453 PMD_DRV_LOG(ERR, "VSI %d get heap failed %d", vsi->seid, ret);
4454 goto fail_queue_alloc;
4456 vsi->msix_intr = ret;
4464 if (type == I40E_VSI_MAIN) {
4465 /* For main VSI, no need to add since it's default one */
4466 vsi->uplink_seid = pf->mac_seid;
4467 vsi->seid = pf->main_vsi_seid;
4468 /* Bind queues with specific MSIX interrupt */
4470 * Needs 2 interrupt at least, one for misc cause which will
4471 * enabled from OS side, Another for queues binding the
4472 * interrupt from device side only.
4475 /* Get default VSI parameters from hardware */
4476 memset(&ctxt, 0, sizeof(ctxt));
4477 ctxt.seid = vsi->seid;
4478 ctxt.pf_num = hw->pf_id;
4479 ctxt.uplink_seid = vsi->uplink_seid;
4481 ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
4482 if (ret != I40E_SUCCESS) {
4483 PMD_DRV_LOG(ERR, "Failed to get VSI params");
4484 goto fail_msix_alloc;
4486 (void)rte_memcpy(&vsi->info, &ctxt.info,
4487 sizeof(struct i40e_aqc_vsi_properties_data));
4488 vsi->vsi_id = ctxt.vsi_number;
4489 vsi->info.valid_sections = 0;
4491 /* Configure tc, enabled TC0 only */
4492 if (i40e_vsi_update_tc_bandwidth(vsi, I40E_DEFAULT_TCMAP) !=
4494 PMD_DRV_LOG(ERR, "Failed to update TC bandwidth");
4495 goto fail_msix_alloc;
4498 /* TC, queue mapping */
4499 memset(&ctxt, 0, sizeof(ctxt));
4500 vsi->info.valid_sections |=
4501 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
4502 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
4503 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
4504 (void)rte_memcpy(&ctxt.info, &vsi->info,
4505 sizeof(struct i40e_aqc_vsi_properties_data));
4506 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
4507 I40E_DEFAULT_TCMAP);
4508 if (ret != I40E_SUCCESS) {
4509 PMD_DRV_LOG(ERR, "Failed to configure "
4510 "TC queue mapping");
4511 goto fail_msix_alloc;
4513 ctxt.seid = vsi->seid;
4514 ctxt.pf_num = hw->pf_id;
4515 ctxt.uplink_seid = vsi->uplink_seid;
4518 /* Update VSI parameters */
4519 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
4520 if (ret != I40E_SUCCESS) {
4521 PMD_DRV_LOG(ERR, "Failed to update VSI params");
4522 goto fail_msix_alloc;
4525 (void)rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
4526 sizeof(vsi->info.tc_mapping));
4527 (void)rte_memcpy(&vsi->info.queue_mapping,
4528 &ctxt.info.queue_mapping,
4529 sizeof(vsi->info.queue_mapping));
4530 vsi->info.mapping_flags = ctxt.info.mapping_flags;
4531 vsi->info.valid_sections = 0;
4533 (void)rte_memcpy(pf->dev_addr.addr_bytes, hw->mac.perm_addr,
4537 * Updating default filter settings are necessary to prevent
4538 * reception of tagged packets.
4539 * Some old firmware configurations load a default macvlan
4540 * filter which accepts both tagged and untagged packets.
4541 * The updating is to use a normal filter instead if needed.
4542 * For NVM 4.2.2 or after, the updating is not needed anymore.
4543 * The firmware with correct configurations load the default
4544 * macvlan filter which is expected and cannot be removed.
4546 i40e_update_default_filter_setting(vsi);
4547 i40e_config_qinq(hw, vsi);
4548 } else if (type == I40E_VSI_SRIOV) {
4549 memset(&ctxt, 0, sizeof(ctxt));
4551 * For other VSI, the uplink_seid equals to uplink VSI's
4552 * uplink_seid since they share same VEB
4554 if (uplink_vsi == NULL)
4555 vsi->uplink_seid = pf->main_vsi->floating_veb->seid;
4557 vsi->uplink_seid = uplink_vsi->uplink_seid;
4558 ctxt.pf_num = hw->pf_id;
4559 ctxt.vf_num = hw->func_caps.vf_base_id + user_param;
4560 ctxt.uplink_seid = vsi->uplink_seid;
4561 ctxt.connection_type = 0x1;
4562 ctxt.flags = I40E_AQ_VSI_TYPE_VF;
4564 /* Use the VEB configuration if FW >= v5.0 */
4565 if (hw->aq.fw_maj_ver >= 5) {
4566 /* Configure switch ID */
4567 ctxt.info.valid_sections |=
4568 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
4569 ctxt.info.switch_id =
4570 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
4573 /* Configure port/vlan */
4574 ctxt.info.valid_sections |=
4575 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
4576 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
4577 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
4578 I40E_DEFAULT_TCMAP);
4579 if (ret != I40E_SUCCESS) {
4580 PMD_DRV_LOG(ERR, "Failed to configure "
4581 "TC queue mapping");
4582 goto fail_msix_alloc;
4584 ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
4585 ctxt.info.valid_sections |=
4586 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
4588 * Since VSI is not created yet, only configure parameter,
4589 * will add vsi below.
4592 i40e_config_qinq(hw, vsi);
4593 } else if (type == I40E_VSI_VMDQ2) {
4594 memset(&ctxt, 0, sizeof(ctxt));
4596 * For other VSI, the uplink_seid equals to uplink VSI's
4597 * uplink_seid since they share same VEB
4599 vsi->uplink_seid = uplink_vsi->uplink_seid;
4600 ctxt.pf_num = hw->pf_id;
4602 ctxt.uplink_seid = vsi->uplink_seid;
4603 ctxt.connection_type = 0x1;
4604 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
4606 ctxt.info.valid_sections |=
4607 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
4608 /* user_param carries flag to enable loop back */
4610 ctxt.info.switch_id =
4611 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
4612 ctxt.info.switch_id |=
4613 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
4616 /* Configure port/vlan */
4617 ctxt.info.valid_sections |=
4618 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
4619 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
4620 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
4621 I40E_DEFAULT_TCMAP);
4622 if (ret != I40E_SUCCESS) {
4623 PMD_DRV_LOG(ERR, "Failed to configure "
4624 "TC queue mapping");
4625 goto fail_msix_alloc;
4627 ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
4628 ctxt.info.valid_sections |=
4629 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
4630 } else if (type == I40E_VSI_FDIR) {
4631 memset(&ctxt, 0, sizeof(ctxt));
4632 vsi->uplink_seid = uplink_vsi->uplink_seid;
4633 ctxt.pf_num = hw->pf_id;
4635 ctxt.uplink_seid = vsi->uplink_seid;
4636 ctxt.connection_type = 0x1; /* regular data port */
4637 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
4638 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
4639 I40E_DEFAULT_TCMAP);
4640 if (ret != I40E_SUCCESS) {
4641 PMD_DRV_LOG(ERR, "Failed to configure "
4642 "TC queue mapping.");
4643 goto fail_msix_alloc;
4645 ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
4646 ctxt.info.valid_sections |=
4647 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
4649 PMD_DRV_LOG(ERR, "VSI: Not support other type VSI yet");
4650 goto fail_msix_alloc;
4653 if (vsi->type != I40E_VSI_MAIN) {
4654 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
4655 if (ret != I40E_SUCCESS) {
4656 PMD_DRV_LOG(ERR, "add vsi failed, aq_err=%d",
4657 hw->aq.asq_last_status);
4658 goto fail_msix_alloc;
4660 memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
4661 vsi->info.valid_sections = 0;
4662 vsi->seid = ctxt.seid;
4663 vsi->vsi_id = ctxt.vsi_number;
4664 vsi->sib_vsi_list.vsi = vsi;
4665 if (vsi->type == I40E_VSI_SRIOV && uplink_vsi == NULL) {
4666 TAILQ_INSERT_TAIL(&pf->main_vsi->floating_veb->head,
4667 &vsi->sib_vsi_list, list);
4669 TAILQ_INSERT_TAIL(&uplink_vsi->veb->head,
4670 &vsi->sib_vsi_list, list);
4674 /* MAC/VLAN configuration */
4675 (void)rte_memcpy(&filter.mac_addr, &broadcast, ETHER_ADDR_LEN);
4676 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
4678 ret = i40e_vsi_add_mac(vsi, &filter);
4679 if (ret != I40E_SUCCESS) {
4680 PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
4681 goto fail_msix_alloc;
4684 /* Get VSI BW information */
4685 i40e_vsi_get_bw_config(vsi);
4688 i40e_res_pool_free(&pf->msix_pool,vsi->msix_intr);
4690 i40e_res_pool_free(&pf->qp_pool,vsi->base_queue);
4696 /* Configure vlan filter on or off */
4698 i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on)
4701 struct i40e_mac_filter *f;
4703 struct i40e_mac_filter_info *mac_filter;
4704 enum rte_mac_filter_type desired_filter;
4705 int ret = I40E_SUCCESS;
4708 /* Filter to match MAC and VLAN */
4709 desired_filter = RTE_MACVLAN_PERFECT_MATCH;
4711 /* Filter to match only MAC */
4712 desired_filter = RTE_MAC_PERFECT_MATCH;
4717 mac_filter = rte_zmalloc("mac_filter_info_data",
4718 num * sizeof(*mac_filter), 0);
4719 if (mac_filter == NULL) {
4720 PMD_DRV_LOG(ERR, "failed to allocate memory");
4721 return I40E_ERR_NO_MEMORY;
4726 /* Remove all existing mac */
4727 TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
4728 mac_filter[i] = f->mac_info;
4729 ret = i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
4731 PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
4732 on ? "enable" : "disable");
4738 /* Override with new filter */
4739 for (i = 0; i < num; i++) {
4740 mac_filter[i].filter_type = desired_filter;
4741 ret = i40e_vsi_add_mac(vsi, &mac_filter[i]);
4743 PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
4744 on ? "enable" : "disable");
4750 rte_free(mac_filter);
4754 /* Configure vlan stripping on or off */
4756 i40e_vsi_config_vlan_stripping(struct i40e_vsi *vsi, bool on)
4758 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4759 struct i40e_vsi_context ctxt;
4761 int ret = I40E_SUCCESS;
4763 /* Check if it has been already on or off */
4764 if (vsi->info.valid_sections &
4765 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID)) {
4767 if ((vsi->info.port_vlan_flags &
4768 I40E_AQ_VSI_PVLAN_EMOD_MASK) == 0)
4769 return 0; /* already on */
4771 if ((vsi->info.port_vlan_flags &
4772 I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
4773 I40E_AQ_VSI_PVLAN_EMOD_MASK)
4774 return 0; /* already off */
4779 vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
4781 vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
4782 vsi->info.valid_sections =
4783 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
4784 vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_EMOD_MASK);
4785 vsi->info.port_vlan_flags |= vlan_flags;
4786 ctxt.seid = vsi->seid;
4787 (void)rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
4788 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
4790 PMD_DRV_LOG(INFO, "Update VSI failed to %s vlan stripping",
4791 on ? "enable" : "disable");
4797 i40e_dev_init_vlan(struct rte_eth_dev *dev)
4799 struct rte_eth_dev_data *data = dev->data;
4803 /* Apply vlan offload setting */
4804 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK;
4805 i40e_vlan_offload_set(dev, mask);
4807 /* Apply double-vlan setting, not implemented yet */
4809 /* Apply pvid setting */
4810 ret = i40e_vlan_pvid_set(dev, data->dev_conf.txmode.pvid,
4811 data->dev_conf.txmode.hw_vlan_insert_pvid);
4813 PMD_DRV_LOG(INFO, "Failed to update VSI params");
4819 i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on)
4821 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4823 return i40e_aq_set_port_parameters(hw, vsi->seid, 0, 1, on, NULL);
4827 i40e_update_flow_control(struct i40e_hw *hw)
4829 #define I40E_LINK_PAUSE_RXTX (I40E_AQ_LINK_PAUSE_RX | I40E_AQ_LINK_PAUSE_TX)
4830 struct i40e_link_status link_status;
4831 uint32_t rxfc = 0, txfc = 0, reg;
4835 memset(&link_status, 0, sizeof(link_status));
4836 ret = i40e_aq_get_link_info(hw, FALSE, &link_status, NULL);
4837 if (ret != I40E_SUCCESS) {
4838 PMD_DRV_LOG(ERR, "Failed to get link status information");
4839 goto write_reg; /* Disable flow control */
4842 an_info = hw->phy.link_info.an_info;
4843 if (!(an_info & I40E_AQ_AN_COMPLETED)) {
4844 PMD_DRV_LOG(INFO, "Link auto negotiation not completed");
4845 ret = I40E_ERR_NOT_READY;
4846 goto write_reg; /* Disable flow control */
4849 * If link auto negotiation is enabled, flow control needs to
4850 * be configured according to it
4852 switch (an_info & I40E_LINK_PAUSE_RXTX) {
4853 case I40E_LINK_PAUSE_RXTX:
4856 hw->fc.current_mode = I40E_FC_FULL;
4858 case I40E_AQ_LINK_PAUSE_RX:
4860 hw->fc.current_mode = I40E_FC_RX_PAUSE;
4862 case I40E_AQ_LINK_PAUSE_TX:
4864 hw->fc.current_mode = I40E_FC_TX_PAUSE;
4867 hw->fc.current_mode = I40E_FC_NONE;
4872 I40E_WRITE_REG(hw, I40E_PRTDCB_FCCFG,
4873 txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT);
4874 reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
4875 reg &= ~I40E_PRTDCB_MFLCN_RFCE_MASK;
4876 reg |= rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT;
4877 I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, reg);
4884 i40e_pf_setup(struct i40e_pf *pf)
4886 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4887 struct i40e_filter_control_settings settings;
4888 struct i40e_vsi *vsi;
4891 /* Clear all stats counters */
4892 pf->offset_loaded = FALSE;
4893 memset(&pf->stats, 0, sizeof(struct i40e_hw_port_stats));
4894 memset(&pf->stats_offset, 0, sizeof(struct i40e_hw_port_stats));
4896 ret = i40e_pf_get_switch_config(pf);
4897 if (ret != I40E_SUCCESS) {
4898 PMD_DRV_LOG(ERR, "Could not get switch config, err %d", ret);
4901 if (pf->flags & I40E_FLAG_FDIR) {
4902 /* make queue allocated first, let FDIR use queue pair 0*/
4903 ret = i40e_res_pool_alloc(&pf->qp_pool, I40E_DEFAULT_QP_NUM_FDIR);
4904 if (ret != I40E_FDIR_QUEUE_ID) {
4905 PMD_DRV_LOG(ERR, "queue allocation fails for FDIR :"
4907 pf->flags &= ~I40E_FLAG_FDIR;
4910 /* main VSI setup */
4911 vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, NULL, 0);
4913 PMD_DRV_LOG(ERR, "Setup of main vsi failed");
4914 return I40E_ERR_NOT_READY;
4918 /* Configure filter control */
4919 memset(&settings, 0, sizeof(settings));
4920 if (hw->func_caps.rss_table_size == ETH_RSS_RETA_SIZE_128)
4921 settings.hash_lut_size = I40E_HASH_LUT_SIZE_128;
4922 else if (hw->func_caps.rss_table_size == ETH_RSS_RETA_SIZE_512)
4923 settings.hash_lut_size = I40E_HASH_LUT_SIZE_512;
4925 PMD_DRV_LOG(ERR, "Hash lookup table size (%u) not supported\n",
4926 hw->func_caps.rss_table_size);
4927 return I40E_ERR_PARAM;
4929 PMD_DRV_LOG(INFO, "Hardware capability of hash lookup table "
4930 "size: %u\n", hw->func_caps.rss_table_size);
4931 pf->hash_lut_size = hw->func_caps.rss_table_size;
4933 /* Enable ethtype and macvlan filters */
4934 settings.enable_ethtype = TRUE;
4935 settings.enable_macvlan = TRUE;
4936 ret = i40e_set_filter_control(hw, &settings);
4938 PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
4941 /* Update flow control according to the auto negotiation */
4942 i40e_update_flow_control(hw);
4944 return I40E_SUCCESS;
4948 i40e_switch_tx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
4954 * Set or clear TX Queue Disable flags,
4955 * which is required by hardware.
4957 i40e_pre_tx_queue_cfg(hw, q_idx, on);
4958 rte_delay_us(I40E_PRE_TX_Q_CFG_WAIT_US);
4960 /* Wait until the request is finished */
4961 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
4962 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
4963 reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
4964 if (!(((reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 0x1) ^
4965 ((reg >> I40E_QTX_ENA_QENA_STAT_SHIFT)
4971 if (reg & I40E_QTX_ENA_QENA_STAT_MASK)
4972 return I40E_SUCCESS; /* already on, skip next steps */
4974 I40E_WRITE_REG(hw, I40E_QTX_HEAD(q_idx), 0);
4975 reg |= I40E_QTX_ENA_QENA_REQ_MASK;
4977 if (!(reg & I40E_QTX_ENA_QENA_STAT_MASK))
4978 return I40E_SUCCESS; /* already off, skip next steps */
4979 reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
4981 /* Write the register */
4982 I40E_WRITE_REG(hw, I40E_QTX_ENA(q_idx), reg);
4983 /* Check the result */
4984 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
4985 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
4986 reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
4988 if ((reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
4989 (reg & I40E_QTX_ENA_QENA_STAT_MASK))
4992 if (!(reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
4993 !(reg & I40E_QTX_ENA_QENA_STAT_MASK))
4997 /* Check if it is timeout */
4998 if (j >= I40E_CHK_Q_ENA_COUNT) {
4999 PMD_DRV_LOG(ERR, "Failed to %s tx queue[%u]",
5000 (on ? "enable" : "disable"), q_idx);
5001 return I40E_ERR_TIMEOUT;
5004 return I40E_SUCCESS;
5007 /* Swith on or off the tx queues */
5009 i40e_dev_switch_tx_queues(struct i40e_pf *pf, bool on)
5011 struct rte_eth_dev_data *dev_data = pf->dev_data;
5012 struct i40e_tx_queue *txq;
5013 struct rte_eth_dev *dev = pf->adapter->eth_dev;
5017 for (i = 0; i < dev_data->nb_tx_queues; i++) {
5018 txq = dev_data->tx_queues[i];
5019 /* Don't operate the queue if not configured or
5020 * if starting only per queue */
5021 if (!txq || !txq->q_set || (on && txq->tx_deferred_start))
5024 ret = i40e_dev_tx_queue_start(dev, i);
5026 ret = i40e_dev_tx_queue_stop(dev, i);
5027 if ( ret != I40E_SUCCESS)
5031 return I40E_SUCCESS;
5035 i40e_switch_rx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
5040 /* Wait until the request is finished */
5041 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
5042 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
5043 reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
5044 if (!((reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 0x1) ^
5045 ((reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 0x1))
5050 if (reg & I40E_QRX_ENA_QENA_STAT_MASK)
5051 return I40E_SUCCESS; /* Already on, skip next steps */
5052 reg |= I40E_QRX_ENA_QENA_REQ_MASK;
5054 if (!(reg & I40E_QRX_ENA_QENA_STAT_MASK))
5055 return I40E_SUCCESS; /* Already off, skip next steps */
5056 reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
5059 /* Write the register */
5060 I40E_WRITE_REG(hw, I40E_QRX_ENA(q_idx), reg);
5061 /* Check the result */
5062 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
5063 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
5064 reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
5066 if ((reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
5067 (reg & I40E_QRX_ENA_QENA_STAT_MASK))
5070 if (!(reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
5071 !(reg & I40E_QRX_ENA_QENA_STAT_MASK))
5076 /* Check if it is timeout */
5077 if (j >= I40E_CHK_Q_ENA_COUNT) {
5078 PMD_DRV_LOG(ERR, "Failed to %s rx queue[%u]",
5079 (on ? "enable" : "disable"), q_idx);
5080 return I40E_ERR_TIMEOUT;
5083 return I40E_SUCCESS;
5085 /* Switch on or off the rx queues */
5087 i40e_dev_switch_rx_queues(struct i40e_pf *pf, bool on)
5089 struct rte_eth_dev_data *dev_data = pf->dev_data;
5090 struct i40e_rx_queue *rxq;
5091 struct rte_eth_dev *dev = pf->adapter->eth_dev;
5095 for (i = 0; i < dev_data->nb_rx_queues; i++) {
5096 rxq = dev_data->rx_queues[i];
5097 /* Don't operate the queue if not configured or
5098 * if starting only per queue */
5099 if (!rxq || !rxq->q_set || (on && rxq->rx_deferred_start))
5102 ret = i40e_dev_rx_queue_start(dev, i);
5104 ret = i40e_dev_rx_queue_stop(dev, i);
5105 if (ret != I40E_SUCCESS)
5109 return I40E_SUCCESS;
5112 /* Switch on or off all the rx/tx queues */
5114 i40e_dev_switch_queues(struct i40e_pf *pf, bool on)
5119 /* enable rx queues before enabling tx queues */
5120 ret = i40e_dev_switch_rx_queues(pf, on);
5122 PMD_DRV_LOG(ERR, "Failed to switch rx queues");
5125 ret = i40e_dev_switch_tx_queues(pf, on);
5127 /* Stop tx queues before stopping rx queues */
5128 ret = i40e_dev_switch_tx_queues(pf, on);
5130 PMD_DRV_LOG(ERR, "Failed to switch tx queues");
5133 ret = i40e_dev_switch_rx_queues(pf, on);
5139 /* Initialize VSI for TX */
5141 i40e_dev_tx_init(struct i40e_pf *pf)
5143 struct rte_eth_dev_data *data = pf->dev_data;
5145 uint32_t ret = I40E_SUCCESS;
5146 struct i40e_tx_queue *txq;
5148 for (i = 0; i < data->nb_tx_queues; i++) {
5149 txq = data->tx_queues[i];
5150 if (!txq || !txq->q_set)
5152 ret = i40e_tx_queue_init(txq);
5153 if (ret != I40E_SUCCESS)
5156 if (ret == I40E_SUCCESS)
5157 i40e_set_tx_function(container_of(pf, struct i40e_adapter, pf)
5163 /* Initialize VSI for RX */
5165 i40e_dev_rx_init(struct i40e_pf *pf)
5167 struct rte_eth_dev_data *data = pf->dev_data;
5168 int ret = I40E_SUCCESS;
5170 struct i40e_rx_queue *rxq;
5172 i40e_pf_config_mq_rx(pf);
5173 for (i = 0; i < data->nb_rx_queues; i++) {
5174 rxq = data->rx_queues[i];
5175 if (!rxq || !rxq->q_set)
5178 ret = i40e_rx_queue_init(rxq);
5179 if (ret != I40E_SUCCESS) {
5180 PMD_DRV_LOG(ERR, "Failed to do RX queue "
5185 if (ret == I40E_SUCCESS)
5186 i40e_set_rx_function(container_of(pf, struct i40e_adapter, pf)
5193 i40e_dev_rxtx_init(struct i40e_pf *pf)
5197 err = i40e_dev_tx_init(pf);
5199 PMD_DRV_LOG(ERR, "Failed to do TX initialization");
5202 err = i40e_dev_rx_init(pf);
5204 PMD_DRV_LOG(ERR, "Failed to do RX initialization");
5212 i40e_vmdq_setup(struct rte_eth_dev *dev)
5214 struct rte_eth_conf *conf = &dev->data->dev_conf;
5215 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5216 int i, err, conf_vsis, j, loop;
5217 struct i40e_vsi *vsi;
5218 struct i40e_vmdq_info *vmdq_info;
5219 struct rte_eth_vmdq_rx_conf *vmdq_conf;
5220 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5223 * Disable interrupt to avoid message from VF. Furthermore, it will
5224 * avoid race condition in VSI creation/destroy.
5226 i40e_pf_disable_irq0(hw);
5228 if ((pf->flags & I40E_FLAG_VMDQ) == 0) {
5229 PMD_INIT_LOG(ERR, "FW doesn't support VMDQ");
5233 conf_vsis = conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools;
5234 if (conf_vsis > pf->max_nb_vmdq_vsi) {
5235 PMD_INIT_LOG(ERR, "VMDQ config: %u, max support:%u",
5236 conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools,
5237 pf->max_nb_vmdq_vsi);
5241 if (pf->vmdq != NULL) {
5242 PMD_INIT_LOG(INFO, "VMDQ already configured");
5246 pf->vmdq = rte_zmalloc("vmdq_info_struct",
5247 sizeof(*vmdq_info) * conf_vsis, 0);
5249 if (pf->vmdq == NULL) {
5250 PMD_INIT_LOG(ERR, "Failed to allocate memory");
5254 vmdq_conf = &conf->rx_adv_conf.vmdq_rx_conf;
5256 /* Create VMDQ VSI */
5257 for (i = 0; i < conf_vsis; i++) {
5258 vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, pf->main_vsi,
5259 vmdq_conf->enable_loop_back);
5261 PMD_INIT_LOG(ERR, "Failed to create VMDQ VSI");
5265 vmdq_info = &pf->vmdq[i];
5267 vmdq_info->vsi = vsi;
5269 pf->nb_cfg_vmdq_vsi = conf_vsis;
5271 /* Configure Vlan */
5272 loop = sizeof(vmdq_conf->pool_map[0].pools) * CHAR_BIT;
5273 for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
5274 for (j = 0; j < loop && j < pf->nb_cfg_vmdq_vsi; j++) {
5275 if (vmdq_conf->pool_map[i].pools & (1UL << j)) {
5276 PMD_INIT_LOG(INFO, "Add vlan %u to vmdq pool %u",
5277 vmdq_conf->pool_map[i].vlan_id, j);
5279 err = i40e_vsi_add_vlan(pf->vmdq[j].vsi,
5280 vmdq_conf->pool_map[i].vlan_id);
5282 PMD_INIT_LOG(ERR, "Failed to add vlan");
5290 i40e_pf_enable_irq0(hw);
5295 for (i = 0; i < conf_vsis; i++)
5296 if (pf->vmdq[i].vsi == NULL)
5299 i40e_vsi_release(pf->vmdq[i].vsi);
5303 i40e_pf_enable_irq0(hw);
5308 i40e_stat_update_32(struct i40e_hw *hw,
5316 new_data = (uint64_t)I40E_READ_REG(hw, reg);
5320 if (new_data >= *offset)
5321 *stat = (uint64_t)(new_data - *offset);
5323 *stat = (uint64_t)((new_data +
5324 ((uint64_t)1 << I40E_32_BIT_WIDTH)) - *offset);
5328 i40e_stat_update_48(struct i40e_hw *hw,
5337 new_data = (uint64_t)I40E_READ_REG(hw, loreg);
5338 new_data |= ((uint64_t)(I40E_READ_REG(hw, hireg) &
5339 I40E_16_BIT_MASK)) << I40E_32_BIT_WIDTH;
5344 if (new_data >= *offset)
5345 *stat = new_data - *offset;
5347 *stat = (uint64_t)((new_data +
5348 ((uint64_t)1 << I40E_48_BIT_WIDTH)) - *offset);
5350 *stat &= I40E_48_BIT_MASK;
5355 i40e_pf_disable_irq0(struct i40e_hw *hw)
5357 /* Disable all interrupt types */
5358 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0, 0);
5359 I40E_WRITE_FLUSH(hw);
5364 i40e_pf_enable_irq0(struct i40e_hw *hw)
5366 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
5367 I40E_PFINT_DYN_CTL0_INTENA_MASK |
5368 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
5369 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
5370 I40E_WRITE_FLUSH(hw);
5374 i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue)
5376 /* read pending request and disable first */
5377 i40e_pf_disable_irq0(hw);
5378 I40E_WRITE_REG(hw, I40E_PFINT_ICR0_ENA, I40E_PFINT_ICR0_ENA_MASK);
5379 I40E_WRITE_REG(hw, I40E_PFINT_STAT_CTL0,
5380 I40E_PFINT_STAT_CTL0_OTHER_ITR_INDX_MASK);
5383 /* Link no queues with irq0 */
5384 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
5385 I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
5389 i40e_dev_handle_vfr_event(struct rte_eth_dev *dev)
5391 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5392 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5395 uint32_t index, offset, val;
5400 * Try to find which VF trigger a reset, use absolute VF id to access
5401 * since the reg is global register.
5403 for (i = 0; i < pf->vf_num; i++) {
5404 abs_vf_id = hw->func_caps.vf_base_id + i;
5405 index = abs_vf_id / I40E_UINT32_BIT_SIZE;
5406 offset = abs_vf_id % I40E_UINT32_BIT_SIZE;
5407 val = I40E_READ_REG(hw, I40E_GLGEN_VFLRSTAT(index));
5408 /* VFR event occured */
5409 if (val & (0x1 << offset)) {
5412 /* Clear the event first */
5413 I40E_WRITE_REG(hw, I40E_GLGEN_VFLRSTAT(index),
5415 PMD_DRV_LOG(INFO, "VF %u reset occured", abs_vf_id);
5417 * Only notify a VF reset event occured,
5418 * don't trigger another SW reset
5420 ret = i40e_pf_host_vf_reset(&pf->vfs[i], 0);
5421 if (ret != I40E_SUCCESS)
5422 PMD_DRV_LOG(ERR, "Failed to do VF reset");
5428 i40e_dev_handle_aq_msg(struct rte_eth_dev *dev)
5430 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5431 struct i40e_arq_event_info info;
5432 uint16_t pending, opcode;
5435 info.buf_len = I40E_AQ_BUF_SZ;
5436 info.msg_buf = rte_zmalloc("msg_buffer", info.buf_len, 0);
5437 if (!info.msg_buf) {
5438 PMD_DRV_LOG(ERR, "Failed to allocate mem");
5444 ret = i40e_clean_arq_element(hw, &info, &pending);
5446 if (ret != I40E_SUCCESS) {
5447 PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ, "
5448 "aq_err: %u", hw->aq.asq_last_status);
5451 opcode = rte_le_to_cpu_16(info.desc.opcode);
5454 case i40e_aqc_opc_send_msg_to_pf:
5455 /* Refer to i40e_aq_send_msg_to_pf() for argument layout*/
5456 i40e_pf_host_handle_vf_msg(dev,
5457 rte_le_to_cpu_16(info.desc.retval),
5458 rte_le_to_cpu_32(info.desc.cookie_high),
5459 rte_le_to_cpu_32(info.desc.cookie_low),
5464 PMD_DRV_LOG(ERR, "Request %u is not supported yet",
5469 rte_free(info.msg_buf);
5473 * Interrupt handler is registered as the alarm callback for handling LSC
5474 * interrupt in a definite of time, in order to wait the NIC into a stable
5475 * state. Currently it waits 1 sec in i40e for the link up interrupt, and
5476 * no need for link down interrupt.
5479 i40e_dev_interrupt_delayed_handler(void *param)
5481 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
5482 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5485 /* read interrupt causes again */
5486 icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
5488 #ifdef RTE_LIBRTE_I40E_DEBUG_DRIVER
5489 if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
5490 PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error\n");
5491 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK)
5492 PMD_DRV_LOG(ERR, "ICR0: malicious programming detected\n");
5493 if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
5494 PMD_DRV_LOG(INFO, "ICR0: global reset requested\n");
5495 if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
5496 PMD_DRV_LOG(INFO, "ICR0: PCI exception\n activated\n");
5497 if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
5498 PMD_DRV_LOG(INFO, "ICR0: a change in the storm control "
5500 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
5501 PMD_DRV_LOG(ERR, "ICR0: HMC error\n");
5502 if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
5503 PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error\n");
5504 #endif /* RTE_LIBRTE_I40E_DEBUG_DRIVER */
5506 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
5507 PMD_DRV_LOG(INFO, "INT:VF reset detected\n");
5508 i40e_dev_handle_vfr_event(dev);
5510 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
5511 PMD_DRV_LOG(INFO, "INT:ADMINQ event\n");
5512 i40e_dev_handle_aq_msg(dev);
5515 /* handle the link up interrupt in an alarm callback */
5516 i40e_dev_link_update(dev, 0);
5517 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC);
5519 i40e_pf_enable_irq0(hw);
5520 rte_intr_enable(&(dev->pci_dev->intr_handle));
5524 * Interrupt handler triggered by NIC for handling
5525 * specific interrupt.
5528 * Pointer to interrupt handle.
5530 * The address of parameter (struct rte_eth_dev *) regsitered before.
5536 i40e_dev_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
5539 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
5540 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5543 /* Disable interrupt */
5544 i40e_pf_disable_irq0(hw);
5546 /* read out interrupt causes */
5547 icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
5549 /* No interrupt event indicated */
5550 if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK)) {
5551 PMD_DRV_LOG(INFO, "No interrupt event");
5554 #ifdef RTE_LIBRTE_I40E_DEBUG_DRIVER
5555 if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
5556 PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
5557 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK)
5558 PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
5559 if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
5560 PMD_DRV_LOG(INFO, "ICR0: global reset requested");
5561 if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
5562 PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
5563 if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
5564 PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
5565 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
5566 PMD_DRV_LOG(ERR, "ICR0: HMC error");
5567 if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
5568 PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
5569 #endif /* RTE_LIBRTE_I40E_DEBUG_DRIVER */
5571 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
5572 PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
5573 i40e_dev_handle_vfr_event(dev);
5575 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
5576 PMD_DRV_LOG(INFO, "ICR0: adminq event");
5577 i40e_dev_handle_aq_msg(dev);
5580 /* Link Status Change interrupt */
5581 if (icr0 & I40E_PFINT_ICR0_LINK_STAT_CHANGE_MASK) {
5582 #define I40E_US_PER_SECOND 1000000
5583 struct rte_eth_link link;
5585 PMD_DRV_LOG(INFO, "ICR0: link status changed\n");
5586 memset(&link, 0, sizeof(link));
5587 rte_i40e_dev_atomic_read_link_status(dev, &link);
5588 i40e_dev_link_update(dev, 0);
5591 * For link up interrupt, it needs to wait 1 second to let the
5592 * hardware be a stable state. Otherwise several consecutive
5593 * interrupts can be observed.
5594 * For link down interrupt, no need to wait.
5596 if (!link.link_status && rte_eal_alarm_set(I40E_US_PER_SECOND,
5597 i40e_dev_interrupt_delayed_handler, (void *)dev) >= 0)
5600 _rte_eth_dev_callback_process(dev,
5601 RTE_ETH_EVENT_INTR_LSC);
5605 /* Enable interrupt */
5606 i40e_pf_enable_irq0(hw);
5607 rte_intr_enable(&(dev->pci_dev->intr_handle));
5611 i40e_add_macvlan_filters(struct i40e_vsi *vsi,
5612 struct i40e_macvlan_filter *filter,
5615 int ele_num, ele_buff_size;
5616 int num, actual_num, i;
5618 int ret = I40E_SUCCESS;
5619 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5620 struct i40e_aqc_add_macvlan_element_data *req_list;
5622 if (filter == NULL || total == 0)
5623 return I40E_ERR_PARAM;
5624 ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
5625 ele_buff_size = hw->aq.asq_buf_size;
5627 req_list = rte_zmalloc("macvlan_add", ele_buff_size, 0);
5628 if (req_list == NULL) {
5629 PMD_DRV_LOG(ERR, "Fail to allocate memory");
5630 return I40E_ERR_NO_MEMORY;
5635 actual_num = (num + ele_num > total) ? (total - num) : ele_num;
5636 memset(req_list, 0, ele_buff_size);
5638 for (i = 0; i < actual_num; i++) {
5639 (void)rte_memcpy(req_list[i].mac_addr,
5640 &filter[num + i].macaddr, ETH_ADDR_LEN);
5641 req_list[i].vlan_tag =
5642 rte_cpu_to_le_16(filter[num + i].vlan_id);
5644 switch (filter[num + i].filter_type) {
5645 case RTE_MAC_PERFECT_MATCH:
5646 flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH |
5647 I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
5649 case RTE_MACVLAN_PERFECT_MATCH:
5650 flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
5652 case RTE_MAC_HASH_MATCH:
5653 flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH |
5654 I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
5656 case RTE_MACVLAN_HASH_MATCH:
5657 flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH;
5660 PMD_DRV_LOG(ERR, "Invalid MAC match type\n");
5661 ret = I40E_ERR_PARAM;
5665 req_list[i].queue_number = 0;
5667 req_list[i].flags = rte_cpu_to_le_16(flags);
5670 ret = i40e_aq_add_macvlan(hw, vsi->seid, req_list,
5672 if (ret != I40E_SUCCESS) {
5673 PMD_DRV_LOG(ERR, "Failed to add macvlan filter");
5677 } while (num < total);
5685 i40e_remove_macvlan_filters(struct i40e_vsi *vsi,
5686 struct i40e_macvlan_filter *filter,
5689 int ele_num, ele_buff_size;
5690 int num, actual_num, i;
5692 int ret = I40E_SUCCESS;
5693 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5694 struct i40e_aqc_remove_macvlan_element_data *req_list;
5696 if (filter == NULL || total == 0)
5697 return I40E_ERR_PARAM;
5699 ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
5700 ele_buff_size = hw->aq.asq_buf_size;
5702 req_list = rte_zmalloc("macvlan_remove", ele_buff_size, 0);
5703 if (req_list == NULL) {
5704 PMD_DRV_LOG(ERR, "Fail to allocate memory");
5705 return I40E_ERR_NO_MEMORY;
5710 actual_num = (num + ele_num > total) ? (total - num) : ele_num;
5711 memset(req_list, 0, ele_buff_size);
5713 for (i = 0; i < actual_num; i++) {
5714 (void)rte_memcpy(req_list[i].mac_addr,
5715 &filter[num + i].macaddr, ETH_ADDR_LEN);
5716 req_list[i].vlan_tag =
5717 rte_cpu_to_le_16(filter[num + i].vlan_id);
5719 switch (filter[num + i].filter_type) {
5720 case RTE_MAC_PERFECT_MATCH:
5721 flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
5722 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
5724 case RTE_MACVLAN_PERFECT_MATCH:
5725 flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
5727 case RTE_MAC_HASH_MATCH:
5728 flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH |
5729 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
5731 case RTE_MACVLAN_HASH_MATCH:
5732 flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH;
5735 PMD_DRV_LOG(ERR, "Invalid MAC filter type\n");
5736 ret = I40E_ERR_PARAM;
5739 req_list[i].flags = rte_cpu_to_le_16(flags);
5742 ret = i40e_aq_remove_macvlan(hw, vsi->seid, req_list,
5744 if (ret != I40E_SUCCESS) {
5745 PMD_DRV_LOG(ERR, "Failed to remove macvlan filter");
5749 } while (num < total);
5756 /* Find out specific MAC filter */
5757 static struct i40e_mac_filter *
5758 i40e_find_mac_filter(struct i40e_vsi *vsi,
5759 struct ether_addr *macaddr)
5761 struct i40e_mac_filter *f;
5763 TAILQ_FOREACH(f, &vsi->mac_list, next) {
5764 if (is_same_ether_addr(macaddr, &f->mac_info.mac_addr))
5772 i40e_find_vlan_filter(struct i40e_vsi *vsi,
5775 uint32_t vid_idx, vid_bit;
5777 if (vlan_id > ETH_VLAN_ID_MAX)
5780 vid_idx = I40E_VFTA_IDX(vlan_id);
5781 vid_bit = I40E_VFTA_BIT(vlan_id);
5783 if (vsi->vfta[vid_idx] & vid_bit)
5790 i40e_set_vlan_filter(struct i40e_vsi *vsi,
5791 uint16_t vlan_id, bool on)
5793 uint32_t vid_idx, vid_bit;
5795 if (vlan_id > ETH_VLAN_ID_MAX)
5798 vid_idx = I40E_VFTA_IDX(vlan_id);
5799 vid_bit = I40E_VFTA_BIT(vlan_id);
5802 vsi->vfta[vid_idx] |= vid_bit;
5804 vsi->vfta[vid_idx] &= ~vid_bit;
5808 * Find all vlan options for specific mac addr,
5809 * return with actual vlan found.
5812 i40e_find_all_vlan_for_mac(struct i40e_vsi *vsi,
5813 struct i40e_macvlan_filter *mv_f,
5814 int num, struct ether_addr *addr)
5820 * Not to use i40e_find_vlan_filter to decrease the loop time,
5821 * although the code looks complex.
5823 if (num < vsi->vlan_num)
5824 return I40E_ERR_PARAM;
5827 for (j = 0; j < I40E_VFTA_SIZE; j++) {
5829 for (k = 0; k < I40E_UINT32_BIT_SIZE; k++) {
5830 if (vsi->vfta[j] & (1 << k)) {
5832 PMD_DRV_LOG(ERR, "vlan number "
5834 return I40E_ERR_PARAM;
5836 (void)rte_memcpy(&mv_f[i].macaddr,
5837 addr, ETH_ADDR_LEN);
5839 j * I40E_UINT32_BIT_SIZE + k;
5845 return I40E_SUCCESS;
5849 i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
5850 struct i40e_macvlan_filter *mv_f,
5855 struct i40e_mac_filter *f;
5857 if (num < vsi->mac_num)
5858 return I40E_ERR_PARAM;
5860 TAILQ_FOREACH(f, &vsi->mac_list, next) {
5862 PMD_DRV_LOG(ERR, "buffer number not match");
5863 return I40E_ERR_PARAM;
5865 (void)rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
5867 mv_f[i].vlan_id = vlan;
5868 mv_f[i].filter_type = f->mac_info.filter_type;
5872 return I40E_SUCCESS;
5876 i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi)
5879 struct i40e_mac_filter *f;
5880 struct i40e_macvlan_filter *mv_f;
5881 int ret = I40E_SUCCESS;
5883 if (vsi == NULL || vsi->mac_num == 0)
5884 return I40E_ERR_PARAM;
5886 /* Case that no vlan is set */
5887 if (vsi->vlan_num == 0)
5890 num = vsi->mac_num * vsi->vlan_num;
5892 mv_f = rte_zmalloc("macvlan_data", num * sizeof(*mv_f), 0);
5894 PMD_DRV_LOG(ERR, "failed to allocate memory");
5895 return I40E_ERR_NO_MEMORY;
5899 if (vsi->vlan_num == 0) {
5900 TAILQ_FOREACH(f, &vsi->mac_list, next) {
5901 (void)rte_memcpy(&mv_f[i].macaddr,
5902 &f->mac_info.mac_addr, ETH_ADDR_LEN);
5903 mv_f[i].vlan_id = 0;
5907 TAILQ_FOREACH(f, &vsi->mac_list, next) {
5908 ret = i40e_find_all_vlan_for_mac(vsi,&mv_f[i],
5909 vsi->vlan_num, &f->mac_info.mac_addr);
5910 if (ret != I40E_SUCCESS)
5916 ret = i40e_remove_macvlan_filters(vsi, mv_f, num);
5924 i40e_vsi_add_vlan(struct i40e_vsi *vsi, uint16_t vlan)
5926 struct i40e_macvlan_filter *mv_f;
5928 int ret = I40E_SUCCESS;
5930 if (!vsi || vlan > ETHER_MAX_VLAN_ID)
5931 return I40E_ERR_PARAM;
5933 /* If it's already set, just return */
5934 if (i40e_find_vlan_filter(vsi,vlan))
5935 return I40E_SUCCESS;
5937 mac_num = vsi->mac_num;
5940 PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
5941 return I40E_ERR_PARAM;
5944 mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
5947 PMD_DRV_LOG(ERR, "failed to allocate memory");
5948 return I40E_ERR_NO_MEMORY;
5951 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
5953 if (ret != I40E_SUCCESS)
5956 ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
5958 if (ret != I40E_SUCCESS)
5961 i40e_set_vlan_filter(vsi, vlan, 1);
5971 i40e_vsi_delete_vlan(struct i40e_vsi *vsi, uint16_t vlan)
5973 struct i40e_macvlan_filter *mv_f;
5975 int ret = I40E_SUCCESS;
5978 * Vlan 0 is the generic filter for untagged packets
5979 * and can't be removed.
5981 if (!vsi || vlan == 0 || vlan > ETHER_MAX_VLAN_ID)
5982 return I40E_ERR_PARAM;
5984 /* If can't find it, just return */
5985 if (!i40e_find_vlan_filter(vsi, vlan))
5986 return I40E_ERR_PARAM;
5988 mac_num = vsi->mac_num;
5991 PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
5992 return I40E_ERR_PARAM;
5995 mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
5998 PMD_DRV_LOG(ERR, "failed to allocate memory");
5999 return I40E_ERR_NO_MEMORY;
6002 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
6004 if (ret != I40E_SUCCESS)
6007 ret = i40e_remove_macvlan_filters(vsi, mv_f, mac_num);
6009 if (ret != I40E_SUCCESS)
6012 /* This is last vlan to remove, replace all mac filter with vlan 0 */
6013 if (vsi->vlan_num == 1) {
6014 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, 0);
6015 if (ret != I40E_SUCCESS)
6018 ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
6019 if (ret != I40E_SUCCESS)
6023 i40e_set_vlan_filter(vsi, vlan, 0);
6033 i40e_vsi_add_mac(struct i40e_vsi *vsi, struct i40e_mac_filter_info *mac_filter)
6035 struct i40e_mac_filter *f;
6036 struct i40e_macvlan_filter *mv_f;
6037 int i, vlan_num = 0;
6038 int ret = I40E_SUCCESS;
6040 /* If it's add and we've config it, return */
6041 f = i40e_find_mac_filter(vsi, &mac_filter->mac_addr);
6043 return I40E_SUCCESS;
6044 if ((mac_filter->filter_type == RTE_MACVLAN_PERFECT_MATCH) ||
6045 (mac_filter->filter_type == RTE_MACVLAN_HASH_MATCH)) {
6048 * If vlan_num is 0, that's the first time to add mac,
6049 * set mask for vlan_id 0.
6051 if (vsi->vlan_num == 0) {
6052 i40e_set_vlan_filter(vsi, 0, 1);
6055 vlan_num = vsi->vlan_num;
6056 } else if ((mac_filter->filter_type == RTE_MAC_PERFECT_MATCH) ||
6057 (mac_filter->filter_type == RTE_MAC_HASH_MATCH))
6060 mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
6062 PMD_DRV_LOG(ERR, "failed to allocate memory");
6063 return I40E_ERR_NO_MEMORY;
6066 for (i = 0; i < vlan_num; i++) {
6067 mv_f[i].filter_type = mac_filter->filter_type;
6068 (void)rte_memcpy(&mv_f[i].macaddr, &mac_filter->mac_addr,
6072 if (mac_filter->filter_type == RTE_MACVLAN_PERFECT_MATCH ||
6073 mac_filter->filter_type == RTE_MACVLAN_HASH_MATCH) {
6074 ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
6075 &mac_filter->mac_addr);
6076 if (ret != I40E_SUCCESS)
6080 ret = i40e_add_macvlan_filters(vsi, mv_f, vlan_num);
6081 if (ret != I40E_SUCCESS)
6084 /* Add the mac addr into mac list */
6085 f = rte_zmalloc("macv_filter", sizeof(*f), 0);
6087 PMD_DRV_LOG(ERR, "failed to allocate memory");
6088 ret = I40E_ERR_NO_MEMORY;
6091 (void)rte_memcpy(&f->mac_info.mac_addr, &mac_filter->mac_addr,
6093 f->mac_info.filter_type = mac_filter->filter_type;
6094 TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
6105 i40e_vsi_delete_mac(struct i40e_vsi *vsi, struct ether_addr *addr)
6107 struct i40e_mac_filter *f;
6108 struct i40e_macvlan_filter *mv_f;
6110 enum rte_mac_filter_type filter_type;
6111 int ret = I40E_SUCCESS;
6113 /* Can't find it, return an error */
6114 f = i40e_find_mac_filter(vsi, addr);
6116 return I40E_ERR_PARAM;
6118 vlan_num = vsi->vlan_num;
6119 filter_type = f->mac_info.filter_type;
6120 if (filter_type == RTE_MACVLAN_PERFECT_MATCH ||
6121 filter_type == RTE_MACVLAN_HASH_MATCH) {
6122 if (vlan_num == 0) {
6123 PMD_DRV_LOG(ERR, "VLAN number shouldn't be 0\n");
6124 return I40E_ERR_PARAM;
6126 } else if (filter_type == RTE_MAC_PERFECT_MATCH ||
6127 filter_type == RTE_MAC_HASH_MATCH)
6130 mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
6132 PMD_DRV_LOG(ERR, "failed to allocate memory");
6133 return I40E_ERR_NO_MEMORY;
6136 for (i = 0; i < vlan_num; i++) {
6137 mv_f[i].filter_type = filter_type;
6138 (void)rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
6141 if (filter_type == RTE_MACVLAN_PERFECT_MATCH ||
6142 filter_type == RTE_MACVLAN_HASH_MATCH) {
6143 ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num, addr);
6144 if (ret != I40E_SUCCESS)
6148 ret = i40e_remove_macvlan_filters(vsi, mv_f, vlan_num);
6149 if (ret != I40E_SUCCESS)
6152 /* Remove the mac addr into mac list */
6153 TAILQ_REMOVE(&vsi->mac_list, f, next);
6163 /* Configure hash enable flags for RSS */
6165 i40e_config_hena(uint64_t flags)
6172 if (flags & ETH_RSS_FRAG_IPV4)
6173 hena |= 1ULL << I40E_FILTER_PCTYPE_FRAG_IPV4;
6174 if (flags & ETH_RSS_NONFRAG_IPV4_TCP)
6176 hena |= (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP) |
6177 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
6179 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
6181 if (flags & ETH_RSS_NONFRAG_IPV4_UDP)
6183 hena |= (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
6184 (1ULL << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
6185 (1ULL << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
6187 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
6189 if (flags & ETH_RSS_NONFRAG_IPV4_SCTP)
6190 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
6191 if (flags & ETH_RSS_NONFRAG_IPV4_OTHER)
6192 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
6193 if (flags & ETH_RSS_FRAG_IPV6)
6194 hena |= 1ULL << I40E_FILTER_PCTYPE_FRAG_IPV6;
6195 if (flags & ETH_RSS_NONFRAG_IPV6_TCP)
6197 hena |= (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP) |
6198 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
6200 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
6202 if (flags & ETH_RSS_NONFRAG_IPV6_UDP)
6204 hena |= (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
6205 (1ULL << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
6206 (1ULL << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
6208 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
6210 if (flags & ETH_RSS_NONFRAG_IPV6_SCTP)
6211 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_SCTP;
6212 if (flags & ETH_RSS_NONFRAG_IPV6_OTHER)
6213 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER;
6214 if (flags & ETH_RSS_L2_PAYLOAD)
6215 hena |= 1ULL << I40E_FILTER_PCTYPE_L2_PAYLOAD;
6220 /* Parse the hash enable flags */
6222 i40e_parse_hena(uint64_t flags)
6224 uint64_t rss_hf = 0;
6228 if (flags & (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV4))
6229 rss_hf |= ETH_RSS_FRAG_IPV4;
6230 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP))
6231 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
6233 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK))
6234 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
6236 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_UDP))
6237 rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
6239 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP))
6240 rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
6241 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP))
6242 rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
6244 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_SCTP))
6245 rss_hf |= ETH_RSS_NONFRAG_IPV4_SCTP;
6246 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER))
6247 rss_hf |= ETH_RSS_NONFRAG_IPV4_OTHER;
6248 if (flags & (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV6))
6249 rss_hf |= ETH_RSS_FRAG_IPV6;
6250 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP))
6251 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
6253 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK))
6254 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
6256 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_UDP))
6257 rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP;
6259 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP))
6260 rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP;
6261 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP))
6262 rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP;
6264 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_SCTP))
6265 rss_hf |= ETH_RSS_NONFRAG_IPV6_SCTP;
6266 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER))
6267 rss_hf |= ETH_RSS_NONFRAG_IPV6_OTHER;
6268 if (flags & (1ULL << I40E_FILTER_PCTYPE_L2_PAYLOAD))
6269 rss_hf |= ETH_RSS_L2_PAYLOAD;
6276 i40e_pf_disable_rss(struct i40e_pf *pf)
6278 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6281 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
6282 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
6283 hena &= ~I40E_RSS_HENA_ALL;
6284 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
6285 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
6286 I40E_WRITE_FLUSH(hw);
6290 i40e_set_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t key_len)
6292 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
6293 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6296 if (!key || key_len == 0) {
6297 PMD_DRV_LOG(DEBUG, "No key to be configured");
6299 } else if (key_len != (I40E_PFQF_HKEY_MAX_INDEX + 1) *
6301 PMD_DRV_LOG(ERR, "Invalid key length %u", key_len);
6305 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
6306 struct i40e_aqc_get_set_rss_key_data *key_dw =
6307 (struct i40e_aqc_get_set_rss_key_data *)key;
6309 ret = i40e_aq_set_rss_key(hw, vsi->vsi_id, key_dw);
6311 PMD_INIT_LOG(ERR, "Failed to configure RSS key "
6314 uint32_t *hash_key = (uint32_t *)key;
6317 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
6318 i40e_write_rx_ctl(hw, I40E_PFQF_HKEY(i), hash_key[i]);
6319 I40E_WRITE_FLUSH(hw);
6326 i40e_get_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t *key_len)
6328 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
6329 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6332 if (!key || !key_len)
6335 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
6336 ret = i40e_aq_get_rss_key(hw, vsi->vsi_id,
6337 (struct i40e_aqc_get_set_rss_key_data *)key);
6339 PMD_INIT_LOG(ERR, "Failed to get RSS key via AQ");
6343 uint32_t *key_dw = (uint32_t *)key;
6346 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
6347 key_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i));
6349 *key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t);
6355 i40e_hw_rss_hash_set(struct i40e_pf *pf, struct rte_eth_rss_conf *rss_conf)
6357 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6362 ret = i40e_set_rss_key(pf->main_vsi, rss_conf->rss_key,
6363 rss_conf->rss_key_len);
6367 rss_hf = rss_conf->rss_hf;
6368 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
6369 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
6370 hena &= ~I40E_RSS_HENA_ALL;
6371 hena |= i40e_config_hena(rss_hf);
6372 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
6373 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
6374 I40E_WRITE_FLUSH(hw);
6380 i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
6381 struct rte_eth_rss_conf *rss_conf)
6383 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6384 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6385 uint64_t rss_hf = rss_conf->rss_hf & I40E_RSS_OFFLOAD_ALL;
6388 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
6389 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
6390 if (!(hena & I40E_RSS_HENA_ALL)) { /* RSS disabled */
6391 if (rss_hf != 0) /* Enable RSS */
6393 return 0; /* Nothing to do */
6396 if (rss_hf == 0) /* Disable RSS */
6399 return i40e_hw_rss_hash_set(pf, rss_conf);
6403 i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
6404 struct rte_eth_rss_conf *rss_conf)
6406 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6407 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6410 i40e_get_rss_key(pf->main_vsi, rss_conf->rss_key,
6411 &rss_conf->rss_key_len);
6413 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
6414 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
6415 rss_conf->rss_hf = i40e_parse_hena(hena);
6421 i40e_dev_get_filter_type(uint16_t filter_type, uint16_t *flag)
6423 switch (filter_type) {
6424 case RTE_TUNNEL_FILTER_IMAC_IVLAN:
6425 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
6427 case RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID:
6428 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
6430 case RTE_TUNNEL_FILTER_IMAC_TENID:
6431 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID;
6433 case RTE_TUNNEL_FILTER_OMAC_TENID_IMAC:
6434 *flag = I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC;
6436 case ETH_TUNNEL_FILTER_IMAC:
6437 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
6439 case ETH_TUNNEL_FILTER_OIP:
6440 *flag = I40E_AQC_ADD_CLOUD_FILTER_OIP;
6442 case ETH_TUNNEL_FILTER_IIP:
6443 *flag = I40E_AQC_ADD_CLOUD_FILTER_IIP;
6446 PMD_DRV_LOG(ERR, "invalid tunnel filter type");
6454 i40e_dev_tunnel_filter_set(struct i40e_pf *pf,
6455 struct rte_eth_tunnel_filter_conf *tunnel_filter,
6460 uint8_t i, tun_type = 0;
6461 /* internal varialbe to convert ipv6 byte order */
6462 uint32_t convert_ipv6[4];
6464 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6465 struct i40e_vsi *vsi = pf->main_vsi;
6466 struct i40e_aqc_add_remove_cloud_filters_element_data *cld_filter;
6467 struct i40e_aqc_add_remove_cloud_filters_element_data *pfilter;
6469 cld_filter = rte_zmalloc("tunnel_filter",
6470 sizeof(struct i40e_aqc_add_remove_cloud_filters_element_data),
6473 if (NULL == cld_filter) {
6474 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
6477 pfilter = cld_filter;
6479 ether_addr_copy(&tunnel_filter->outer_mac, (struct ether_addr*)&pfilter->outer_mac);
6480 ether_addr_copy(&tunnel_filter->inner_mac, (struct ether_addr*)&pfilter->inner_mac);
6482 pfilter->inner_vlan = rte_cpu_to_le_16(tunnel_filter->inner_vlan);
6483 if (tunnel_filter->ip_type == RTE_TUNNEL_IPTYPE_IPV4) {
6484 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV4;
6485 ipv4_addr = rte_be_to_cpu_32(tunnel_filter->ip_addr.ipv4_addr);
6486 rte_memcpy(&pfilter->ipaddr.v4.data,
6487 &rte_cpu_to_le_32(ipv4_addr),
6488 sizeof(pfilter->ipaddr.v4.data));
6490 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV6;
6491 for (i = 0; i < 4; i++) {
6493 rte_cpu_to_le_32(rte_be_to_cpu_32(tunnel_filter->ip_addr.ipv6_addr[i]));
6495 rte_memcpy(&pfilter->ipaddr.v6.data, &convert_ipv6,
6496 sizeof(pfilter->ipaddr.v6.data));
6499 /* check tunneled type */
6500 switch (tunnel_filter->tunnel_type) {
6501 case RTE_TUNNEL_TYPE_VXLAN:
6502 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_VXLAN;
6504 case RTE_TUNNEL_TYPE_NVGRE:
6505 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_NVGRE_OMAC;
6507 case RTE_TUNNEL_TYPE_IP_IN_GRE:
6508 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_IP;
6511 /* Other tunnel types is not supported. */
6512 PMD_DRV_LOG(ERR, "tunnel type is not supported.");
6513 rte_free(cld_filter);
6517 val = i40e_dev_get_filter_type(tunnel_filter->filter_type,
6520 rte_free(cld_filter);
6524 pfilter->flags |= rte_cpu_to_le_16(
6525 I40E_AQC_ADD_CLOUD_FLAGS_TO_QUEUE |
6526 ip_type | (tun_type << I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT));
6527 pfilter->tenant_id = rte_cpu_to_le_32(tunnel_filter->tenant_id);
6528 pfilter->queue_number = rte_cpu_to_le_16(tunnel_filter->queue_id);
6531 ret = i40e_aq_add_cloud_filters(hw, vsi->seid, cld_filter, 1);
6533 ret = i40e_aq_remove_cloud_filters(hw, vsi->seid,
6536 rte_free(cld_filter);
6541 i40e_get_vxlan_port_idx(struct i40e_pf *pf, uint16_t port)
6545 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
6546 if (pf->vxlan_ports[i] == port)
6554 i40e_add_vxlan_port(struct i40e_pf *pf, uint16_t port)
6558 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6560 idx = i40e_get_vxlan_port_idx(pf, port);
6562 /* Check if port already exists */
6564 PMD_DRV_LOG(ERR, "Port %d already offloaded", port);
6568 /* Now check if there is space to add the new port */
6569 idx = i40e_get_vxlan_port_idx(pf, 0);
6571 PMD_DRV_LOG(ERR, "Maximum number of UDP ports reached,"
6572 "not adding port %d", port);
6576 ret = i40e_aq_add_udp_tunnel(hw, port, I40E_AQC_TUNNEL_TYPE_VXLAN,
6579 PMD_DRV_LOG(ERR, "Failed to add VXLAN UDP port %d", port);
6583 PMD_DRV_LOG(INFO, "Added port %d with AQ command with index %d",
6586 /* New port: add it and mark its index in the bitmap */
6587 pf->vxlan_ports[idx] = port;
6588 pf->vxlan_bitmap |= (1 << idx);
6590 if (!(pf->flags & I40E_FLAG_VXLAN))
6591 pf->flags |= I40E_FLAG_VXLAN;
6597 i40e_del_vxlan_port(struct i40e_pf *pf, uint16_t port)
6600 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6602 if (!(pf->flags & I40E_FLAG_VXLAN)) {
6603 PMD_DRV_LOG(ERR, "VXLAN UDP port was not configured.");
6607 idx = i40e_get_vxlan_port_idx(pf, port);
6610 PMD_DRV_LOG(ERR, "Port %d doesn't exist", port);
6614 if (i40e_aq_del_udp_tunnel(hw, idx, NULL) < 0) {
6615 PMD_DRV_LOG(ERR, "Failed to delete VXLAN UDP port %d", port);
6619 PMD_DRV_LOG(INFO, "Deleted port %d with AQ command with index %d",
6622 pf->vxlan_ports[idx] = 0;
6623 pf->vxlan_bitmap &= ~(1 << idx);
6625 if (!pf->vxlan_bitmap)
6626 pf->flags &= ~I40E_FLAG_VXLAN;
6631 /* Add UDP tunneling port */
6633 i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
6634 struct rte_eth_udp_tunnel *udp_tunnel)
6637 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6639 if (udp_tunnel == NULL)
6642 switch (udp_tunnel->prot_type) {
6643 case RTE_TUNNEL_TYPE_VXLAN:
6644 ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port);
6647 case RTE_TUNNEL_TYPE_GENEVE:
6648 case RTE_TUNNEL_TYPE_TEREDO:
6649 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
6654 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6662 /* Remove UDP tunneling port */
6664 i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
6665 struct rte_eth_udp_tunnel *udp_tunnel)
6668 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6670 if (udp_tunnel == NULL)
6673 switch (udp_tunnel->prot_type) {
6674 case RTE_TUNNEL_TYPE_VXLAN:
6675 ret = i40e_del_vxlan_port(pf, udp_tunnel->udp_port);
6677 case RTE_TUNNEL_TYPE_GENEVE:
6678 case RTE_TUNNEL_TYPE_TEREDO:
6679 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
6683 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6691 /* Calculate the maximum number of contiguous PF queues that are configured */
6693 i40e_pf_calc_configured_queues_num(struct i40e_pf *pf)
6695 struct rte_eth_dev_data *data = pf->dev_data;
6697 struct i40e_rx_queue *rxq;
6700 for (i = 0; i < pf->lan_nb_qps; i++) {
6701 rxq = data->rx_queues[i];
6702 if (rxq && rxq->q_set)
6713 i40e_pf_config_rss(struct i40e_pf *pf)
6715 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6716 struct rte_eth_rss_conf rss_conf;
6717 uint32_t i, lut = 0;
6721 * If both VMDQ and RSS enabled, not all of PF queues are configured.
6722 * It's necessary to calulate the actual PF queues that are configured.
6724 if (pf->dev_data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG)
6725 num = i40e_pf_calc_configured_queues_num(pf);
6727 num = pf->dev_data->nb_rx_queues;
6729 num = RTE_MIN(num, I40E_MAX_Q_PER_TC);
6730 PMD_INIT_LOG(INFO, "Max of contiguous %u PF queues are configured",
6734 PMD_INIT_LOG(ERR, "No PF queues are configured to enable RSS");
6738 for (i = 0, j = 0; i < hw->func_caps.rss_table_size; i++, j++) {
6741 lut = (lut << 8) | (j & ((0x1 <<
6742 hw->func_caps.rss_table_entry_width) - 1));
6744 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i >> 2), lut);
6747 rss_conf = pf->dev_data->dev_conf.rx_adv_conf.rss_conf;
6748 if ((rss_conf.rss_hf & I40E_RSS_OFFLOAD_ALL) == 0) {
6749 i40e_pf_disable_rss(pf);
6752 if (rss_conf.rss_key == NULL || rss_conf.rss_key_len <
6753 (I40E_PFQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t)) {
6754 /* Random default keys */
6755 static uint32_t rss_key_default[] = {0x6b793944,
6756 0x23504cb5, 0x5bea75b6, 0x309f4f12, 0x3dc0a2b8,
6757 0x024ddcdf, 0x339b8ca0, 0x4c4af64a, 0x34fac605,
6758 0x55d85839, 0x3a58997d, 0x2ec938e1, 0x66031581};
6760 rss_conf.rss_key = (uint8_t *)rss_key_default;
6761 rss_conf.rss_key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
6765 return i40e_hw_rss_hash_set(pf, &rss_conf);
6769 i40e_tunnel_filter_param_check(struct i40e_pf *pf,
6770 struct rte_eth_tunnel_filter_conf *filter)
6772 if (pf == NULL || filter == NULL) {
6773 PMD_DRV_LOG(ERR, "Invalid parameter");
6777 if (filter->queue_id >= pf->dev_data->nb_rx_queues) {
6778 PMD_DRV_LOG(ERR, "Invalid queue ID");
6782 if (filter->inner_vlan > ETHER_MAX_VLAN_ID) {
6783 PMD_DRV_LOG(ERR, "Invalid inner VLAN ID");
6787 if ((filter->filter_type & ETH_TUNNEL_FILTER_OMAC) &&
6788 (is_zero_ether_addr(&filter->outer_mac))) {
6789 PMD_DRV_LOG(ERR, "Cannot add NULL outer MAC address");
6793 if ((filter->filter_type & ETH_TUNNEL_FILTER_IMAC) &&
6794 (is_zero_ether_addr(&filter->inner_mac))) {
6795 PMD_DRV_LOG(ERR, "Cannot add NULL inner MAC address");
6802 #define I40E_GL_PRS_FVBM_MSK_ENA 0x80000000
6803 #define I40E_GL_PRS_FVBM(_i) (0x00269760 + ((_i) * 4))
6805 i40e_dev_set_gre_key_len(struct i40e_hw *hw, uint8_t len)
6810 val = I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2));
6811 PMD_DRV_LOG(DEBUG, "Read original GL_PRS_FVBM with 0x%08x\n", val);
6814 reg = val | I40E_GL_PRS_FVBM_MSK_ENA;
6815 } else if (len == 4) {
6816 reg = val & ~I40E_GL_PRS_FVBM_MSK_ENA;
6818 PMD_DRV_LOG(ERR, "Unsupported GRE key length of %u", len);
6823 ret = i40e_aq_debug_write_register(hw, I40E_GL_PRS_FVBM(2),
6830 PMD_DRV_LOG(DEBUG, "Read modified GL_PRS_FVBM with 0x%08x\n",
6831 I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2)));
6837 i40e_dev_global_config_set(struct i40e_hw *hw, struct rte_eth_global_cfg *cfg)
6844 switch (cfg->cfg_type) {
6845 case RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN:
6846 ret = i40e_dev_set_gre_key_len(hw, cfg->cfg.gre_key_len);
6849 PMD_DRV_LOG(ERR, "Unknown config type %u", cfg->cfg_type);
6857 i40e_filter_ctrl_global_config(struct rte_eth_dev *dev,
6858 enum rte_filter_op filter_op,
6861 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6862 int ret = I40E_ERR_PARAM;
6864 switch (filter_op) {
6865 case RTE_ETH_FILTER_SET:
6866 ret = i40e_dev_global_config_set(hw,
6867 (struct rte_eth_global_cfg *)arg);
6870 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
6878 i40e_tunnel_filter_handle(struct rte_eth_dev *dev,
6879 enum rte_filter_op filter_op,
6882 struct rte_eth_tunnel_filter_conf *filter;
6883 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6884 int ret = I40E_SUCCESS;
6886 filter = (struct rte_eth_tunnel_filter_conf *)(arg);
6888 if (i40e_tunnel_filter_param_check(pf, filter) < 0)
6889 return I40E_ERR_PARAM;
6891 switch (filter_op) {
6892 case RTE_ETH_FILTER_NOP:
6893 if (!(pf->flags & I40E_FLAG_VXLAN))
6894 ret = I40E_NOT_SUPPORTED;
6896 case RTE_ETH_FILTER_ADD:
6897 ret = i40e_dev_tunnel_filter_set(pf, filter, 1);
6899 case RTE_ETH_FILTER_DELETE:
6900 ret = i40e_dev_tunnel_filter_set(pf, filter, 0);
6903 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
6904 ret = I40E_ERR_PARAM;
6912 i40e_pf_config_mq_rx(struct i40e_pf *pf)
6915 enum rte_eth_rx_mq_mode mq_mode = pf->dev_data->dev_conf.rxmode.mq_mode;
6918 if (mq_mode & ETH_MQ_RX_RSS_FLAG)
6919 ret = i40e_pf_config_rss(pf);
6921 i40e_pf_disable_rss(pf);
6926 /* Get the symmetric hash enable configurations per port */
6928 i40e_get_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t *enable)
6930 uint32_t reg = i40e_read_rx_ctl(hw, I40E_PRTQF_CTL_0);
6932 *enable = reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK ? 1 : 0;
6935 /* Set the symmetric hash enable configurations per port */
6937 i40e_set_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t enable)
6939 uint32_t reg = i40e_read_rx_ctl(hw, I40E_PRTQF_CTL_0);
6942 if (reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK) {
6943 PMD_DRV_LOG(INFO, "Symmetric hash has already "
6947 reg |= I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
6949 if (!(reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK)) {
6950 PMD_DRV_LOG(INFO, "Symmetric hash has already "
6954 reg &= ~I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
6956 i40e_write_rx_ctl(hw, I40E_PRTQF_CTL_0, reg);
6957 I40E_WRITE_FLUSH(hw);
6961 * Get global configurations of hash function type and symmetric hash enable
6962 * per flow type (pctype). Note that global configuration means it affects all
6963 * the ports on the same NIC.
6966 i40e_get_hash_filter_global_config(struct i40e_hw *hw,
6967 struct rte_eth_hash_global_conf *g_cfg)
6969 uint32_t reg, mask = I40E_FLOW_TYPES;
6971 enum i40e_filter_pctype pctype;
6973 memset(g_cfg, 0, sizeof(*g_cfg));
6974 reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
6975 if (reg & I40E_GLQF_CTL_HTOEP_MASK)
6976 g_cfg->hash_func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
6978 g_cfg->hash_func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
6979 PMD_DRV_LOG(DEBUG, "Hash function is %s",
6980 (reg & I40E_GLQF_CTL_HTOEP_MASK) ? "Toeplitz" : "Simple XOR");
6982 for (i = 0; mask && i < RTE_ETH_FLOW_MAX; i++) {
6983 if (!(mask & (1UL << i)))
6985 mask &= ~(1UL << i);
6986 /* Bit set indicats the coresponding flow type is supported */
6987 g_cfg->valid_bit_mask[0] |= (1UL << i);
6988 /* if flowtype is invalid, continue */
6989 if (!I40E_VALID_FLOW(i))
6991 pctype = i40e_flowtype_to_pctype(i);
6992 reg = i40e_read_rx_ctl(hw, I40E_GLQF_HSYM(pctype));
6993 if (reg & I40E_GLQF_HSYM_SYMH_ENA_MASK)
6994 g_cfg->sym_hash_enable_mask[0] |= (1UL << i);
7001 i40e_hash_global_config_check(struct rte_eth_hash_global_conf *g_cfg)
7004 uint32_t mask0, i40e_mask = I40E_FLOW_TYPES;
7006 if (g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_TOEPLITZ &&
7007 g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_SIMPLE_XOR &&
7008 g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_DEFAULT) {
7009 PMD_DRV_LOG(ERR, "Unsupported hash function type %d",
7015 * As i40e supports less than 32 flow types, only first 32 bits need to
7018 mask0 = g_cfg->valid_bit_mask[0];
7019 for (i = 0; i < RTE_SYM_HASH_MASK_ARRAY_SIZE; i++) {
7021 /* Check if any unsupported flow type configured */
7022 if ((mask0 | i40e_mask) ^ i40e_mask)
7025 if (g_cfg->valid_bit_mask[i])
7033 PMD_DRV_LOG(ERR, "i40e unsupported flow type bit(s) configured");
7039 * Set global configurations of hash function type and symmetric hash enable
7040 * per flow type (pctype). Note any modifying global configuration will affect
7041 * all the ports on the same NIC.
7044 i40e_set_hash_filter_global_config(struct i40e_hw *hw,
7045 struct rte_eth_hash_global_conf *g_cfg)
7050 uint32_t mask0 = g_cfg->valid_bit_mask[0];
7051 enum i40e_filter_pctype pctype;
7053 /* Check the input parameters */
7054 ret = i40e_hash_global_config_check(g_cfg);
7058 for (i = 0; mask0 && i < UINT32_BIT; i++) {
7059 if (!(mask0 & (1UL << i)))
7061 mask0 &= ~(1UL << i);
7062 /* if flowtype is invalid, continue */
7063 if (!I40E_VALID_FLOW(i))
7065 pctype = i40e_flowtype_to_pctype(i);
7066 reg = (g_cfg->sym_hash_enable_mask[0] & (1UL << i)) ?
7067 I40E_GLQF_HSYM_SYMH_ENA_MASK : 0;
7068 i40e_write_rx_ctl(hw, I40E_GLQF_HSYM(pctype), reg);
7071 reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
7072 if (g_cfg->hash_func == RTE_ETH_HASH_FUNCTION_TOEPLITZ) {
7074 if (reg & I40E_GLQF_CTL_HTOEP_MASK) {
7075 PMD_DRV_LOG(DEBUG, "Hash function already set to "
7079 reg |= I40E_GLQF_CTL_HTOEP_MASK;
7080 } else if (g_cfg->hash_func == RTE_ETH_HASH_FUNCTION_SIMPLE_XOR) {
7082 if (!(reg & I40E_GLQF_CTL_HTOEP_MASK)) {
7083 PMD_DRV_LOG(DEBUG, "Hash function already set to "
7087 reg &= ~I40E_GLQF_CTL_HTOEP_MASK;
7089 /* Use the default, and keep it as it is */
7092 i40e_write_rx_ctl(hw, I40E_GLQF_CTL, reg);
7095 I40E_WRITE_FLUSH(hw);
7101 * Valid input sets for hash and flow director filters per PCTYPE
7104 i40e_get_valid_input_set(enum i40e_filter_pctype pctype,
7105 enum rte_filter_type filter)
7109 static const uint64_t valid_hash_inset_table[] = {
7110 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
7111 I40E_INSET_DMAC | I40E_INSET_SMAC |
7112 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7113 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_SRC |
7114 I40E_INSET_IPV4_DST | I40E_INSET_IPV4_TOS |
7115 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
7116 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
7117 I40E_INSET_FLEX_PAYLOAD,
7118 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
7119 I40E_INSET_DMAC | I40E_INSET_SMAC |
7120 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7121 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
7122 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
7123 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
7124 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
7125 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
7126 I40E_INSET_FLEX_PAYLOAD,
7128 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
7129 I40E_INSET_DMAC | I40E_INSET_SMAC |
7130 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7131 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
7132 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
7133 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
7134 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
7135 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
7136 I40E_INSET_FLEX_PAYLOAD,
7137 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
7138 I40E_INSET_DMAC | I40E_INSET_SMAC |
7139 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7140 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
7141 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
7142 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
7143 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
7144 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
7145 I40E_INSET_FLEX_PAYLOAD,
7147 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
7148 I40E_INSET_DMAC | I40E_INSET_SMAC |
7149 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7150 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
7151 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
7152 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
7153 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
7154 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
7155 I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
7157 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
7158 I40E_INSET_DMAC | I40E_INSET_SMAC |
7159 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7160 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
7161 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
7162 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
7163 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
7164 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
7165 I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
7167 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
7168 I40E_INSET_DMAC | I40E_INSET_SMAC |
7169 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7170 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
7171 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
7172 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
7173 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
7174 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
7175 I40E_INSET_SCTP_VT | I40E_INSET_FLEX_PAYLOAD,
7176 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
7177 I40E_INSET_DMAC | I40E_INSET_SMAC |
7178 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7179 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
7180 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
7181 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
7182 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
7183 I40E_INSET_FLEX_PAYLOAD,
7184 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
7185 I40E_INSET_DMAC | I40E_INSET_SMAC |
7186 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7187 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
7188 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
7189 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_TUNNEL_DMAC |
7190 I40E_INSET_TUNNEL_ID | I40E_INSET_IPV6_SRC |
7191 I40E_INSET_IPV6_DST | I40E_INSET_FLEX_PAYLOAD,
7192 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
7193 I40E_INSET_DMAC | I40E_INSET_SMAC |
7194 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7195 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
7196 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
7197 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
7198 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
7199 I40E_INSET_DST_PORT | I40E_INSET_FLEX_PAYLOAD,
7201 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
7202 I40E_INSET_DMAC | I40E_INSET_SMAC |
7203 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7204 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
7205 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
7206 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
7207 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
7208 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
7209 I40E_INSET_FLEX_PAYLOAD,
7210 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
7211 I40E_INSET_DMAC | I40E_INSET_SMAC |
7212 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7213 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
7214 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
7215 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
7216 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
7217 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
7218 I40E_INSET_FLEX_PAYLOAD,
7220 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
7221 I40E_INSET_DMAC | I40E_INSET_SMAC |
7222 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7223 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
7224 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
7225 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
7226 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
7227 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
7228 I40E_INSET_FLEX_PAYLOAD,
7230 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
7231 I40E_INSET_DMAC | I40E_INSET_SMAC |
7232 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7233 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
7234 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
7235 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
7236 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
7237 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
7238 I40E_INSET_FLEX_PAYLOAD,
7240 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
7241 I40E_INSET_DMAC | I40E_INSET_SMAC |
7242 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7243 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
7244 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
7245 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
7246 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
7247 I40E_INSET_DST_PORT | I40E_INSET_SCTP_VT |
7248 I40E_INSET_FLEX_PAYLOAD,
7249 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
7250 I40E_INSET_DMAC | I40E_INSET_SMAC |
7251 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7252 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
7253 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
7254 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
7255 I40E_INSET_IPV6_DST | I40E_INSET_TUNNEL_ID |
7256 I40E_INSET_FLEX_PAYLOAD,
7257 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
7258 I40E_INSET_DMAC | I40E_INSET_SMAC |
7259 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7260 I40E_INSET_VLAN_TUNNEL | I40E_INSET_LAST_ETHER_TYPE |
7261 I40E_INSET_FLEX_PAYLOAD,
7265 * Flow director supports only fields defined in
7266 * union rte_eth_fdir_flow.
7268 static const uint64_t valid_fdir_inset_table[] = {
7269 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
7270 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7271 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
7272 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
7273 I40E_INSET_IPV4_TTL,
7274 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
7275 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7276 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
7277 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
7278 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
7280 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
7281 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7282 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
7283 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
7284 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
7285 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
7286 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7287 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
7288 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
7289 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
7291 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
7292 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7293 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
7294 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
7295 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
7297 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
7298 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7299 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
7300 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
7301 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
7303 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
7304 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7305 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
7306 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
7307 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
7309 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
7310 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7311 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
7312 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
7313 I40E_INSET_IPV4_TTL,
7314 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
7315 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7316 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
7317 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
7318 I40E_INSET_IPV6_HOP_LIMIT,
7319 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
7320 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7321 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
7322 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
7323 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
7325 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
7326 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7327 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
7328 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
7329 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
7330 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
7331 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7332 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
7333 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
7334 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
7336 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
7337 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7338 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
7339 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
7340 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
7342 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
7343 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7344 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
7345 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
7346 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
7348 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
7349 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7350 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
7351 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
7352 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
7354 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
7355 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7356 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
7357 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
7358 I40E_INSET_IPV6_HOP_LIMIT,
7359 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
7360 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
7361 I40E_INSET_LAST_ETHER_TYPE,
7364 if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
7366 if (filter == RTE_ETH_FILTER_HASH)
7367 valid = valid_hash_inset_table[pctype];
7369 valid = valid_fdir_inset_table[pctype];
7375 * Validate if the input set is allowed for a specific PCTYPE
7378 i40e_validate_input_set(enum i40e_filter_pctype pctype,
7379 enum rte_filter_type filter, uint64_t inset)
7383 valid = i40e_get_valid_input_set(pctype, filter);
7384 if (inset & (~valid))
7390 /* default input set fields combination per pctype */
7392 i40e_get_default_input_set(uint16_t pctype)
7394 static const uint64_t default_inset_table[] = {
7395 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
7396 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
7397 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
7398 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
7399 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
7401 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
7402 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
7403 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
7404 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
7405 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
7406 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
7408 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
7409 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
7410 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
7412 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
7413 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
7414 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
7416 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
7417 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
7418 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
7420 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
7421 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
7422 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
7423 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
7424 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
7425 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
7426 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
7428 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
7429 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
7430 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
7431 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
7432 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
7433 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
7435 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
7436 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
7437 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
7439 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
7440 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
7441 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
7443 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
7444 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
7445 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
7447 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
7448 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
7449 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
7450 I40E_INSET_LAST_ETHER_TYPE,
7453 if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
7456 return default_inset_table[pctype];
7460 * Parse the input set from index to logical bit masks
7463 i40e_parse_input_set(uint64_t *inset,
7464 enum i40e_filter_pctype pctype,
7465 enum rte_eth_input_set_field *field,
7471 static const struct {
7472 enum rte_eth_input_set_field field;
7474 } inset_convert_table[] = {
7475 {RTE_ETH_INPUT_SET_NONE, I40E_INSET_NONE},
7476 {RTE_ETH_INPUT_SET_L2_SRC_MAC, I40E_INSET_SMAC},
7477 {RTE_ETH_INPUT_SET_L2_DST_MAC, I40E_INSET_DMAC},
7478 {RTE_ETH_INPUT_SET_L2_OUTER_VLAN, I40E_INSET_VLAN_OUTER},
7479 {RTE_ETH_INPUT_SET_L2_INNER_VLAN, I40E_INSET_VLAN_INNER},
7480 {RTE_ETH_INPUT_SET_L2_ETHERTYPE, I40E_INSET_LAST_ETHER_TYPE},
7481 {RTE_ETH_INPUT_SET_L3_SRC_IP4, I40E_INSET_IPV4_SRC},
7482 {RTE_ETH_INPUT_SET_L3_DST_IP4, I40E_INSET_IPV4_DST},
7483 {RTE_ETH_INPUT_SET_L3_IP4_TOS, I40E_INSET_IPV4_TOS},
7484 {RTE_ETH_INPUT_SET_L3_IP4_PROTO, I40E_INSET_IPV4_PROTO},
7485 {RTE_ETH_INPUT_SET_L3_IP4_TTL, I40E_INSET_IPV4_TTL},
7486 {RTE_ETH_INPUT_SET_L3_SRC_IP6, I40E_INSET_IPV6_SRC},
7487 {RTE_ETH_INPUT_SET_L3_DST_IP6, I40E_INSET_IPV6_DST},
7488 {RTE_ETH_INPUT_SET_L3_IP6_TC, I40E_INSET_IPV6_TC},
7489 {RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER,
7490 I40E_INSET_IPV6_NEXT_HDR},
7491 {RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS,
7492 I40E_INSET_IPV6_HOP_LIMIT},
7493 {RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT, I40E_INSET_SRC_PORT},
7494 {RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT, I40E_INSET_SRC_PORT},
7495 {RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT, I40E_INSET_SRC_PORT},
7496 {RTE_ETH_INPUT_SET_L4_UDP_DST_PORT, I40E_INSET_DST_PORT},
7497 {RTE_ETH_INPUT_SET_L4_TCP_DST_PORT, I40E_INSET_DST_PORT},
7498 {RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT, I40E_INSET_DST_PORT},
7499 {RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG,
7500 I40E_INSET_SCTP_VT},
7501 {RTE_ETH_INPUT_SET_TUNNEL_L2_INNER_DST_MAC,
7502 I40E_INSET_TUNNEL_DMAC},
7503 {RTE_ETH_INPUT_SET_TUNNEL_L2_INNER_VLAN,
7504 I40E_INSET_VLAN_TUNNEL},
7505 {RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY,
7506 I40E_INSET_TUNNEL_ID},
7507 {RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY, I40E_INSET_TUNNEL_ID},
7508 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD,
7509 I40E_INSET_FLEX_PAYLOAD_W1},
7510 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD,
7511 I40E_INSET_FLEX_PAYLOAD_W2},
7512 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD,
7513 I40E_INSET_FLEX_PAYLOAD_W3},
7514 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD,
7515 I40E_INSET_FLEX_PAYLOAD_W4},
7516 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD,
7517 I40E_INSET_FLEX_PAYLOAD_W5},
7518 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD,
7519 I40E_INSET_FLEX_PAYLOAD_W6},
7520 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD,
7521 I40E_INSET_FLEX_PAYLOAD_W7},
7522 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD,
7523 I40E_INSET_FLEX_PAYLOAD_W8},
7526 if (!inset || !field || size > RTE_ETH_INSET_SIZE_MAX)
7529 /* Only one item allowed for default or all */
7531 if (field[0] == RTE_ETH_INPUT_SET_DEFAULT) {
7532 *inset = i40e_get_default_input_set(pctype);
7534 } else if (field[0] == RTE_ETH_INPUT_SET_NONE) {
7535 *inset = I40E_INSET_NONE;
7540 for (i = 0, *inset = 0; i < size; i++) {
7541 for (j = 0; j < RTE_DIM(inset_convert_table); j++) {
7542 if (field[i] == inset_convert_table[j].field) {
7543 *inset |= inset_convert_table[j].inset;
7548 /* It contains unsupported input set, return immediately */
7549 if (j == RTE_DIM(inset_convert_table))
7557 * Translate the input set from bit masks to register aware bit masks
7561 i40e_translate_input_set_reg(uint64_t input)
7566 static const struct {
7570 {I40E_INSET_DMAC, I40E_REG_INSET_L2_DMAC},
7571 {I40E_INSET_SMAC, I40E_REG_INSET_L2_SMAC},
7572 {I40E_INSET_VLAN_OUTER, I40E_REG_INSET_L2_OUTER_VLAN},
7573 {I40E_INSET_VLAN_INNER, I40E_REG_INSET_L2_INNER_VLAN},
7574 {I40E_INSET_LAST_ETHER_TYPE, I40E_REG_INSET_LAST_ETHER_TYPE},
7575 {I40E_INSET_IPV4_SRC, I40E_REG_INSET_L3_SRC_IP4},
7576 {I40E_INSET_IPV4_DST, I40E_REG_INSET_L3_DST_IP4},
7577 {I40E_INSET_IPV4_TOS, I40E_REG_INSET_L3_IP4_TOS},
7578 {I40E_INSET_IPV4_PROTO, I40E_REG_INSET_L3_IP4_PROTO},
7579 {I40E_INSET_IPV4_TTL, I40E_REG_INSET_L3_IP4_TTL},
7580 {I40E_INSET_IPV6_SRC, I40E_REG_INSET_L3_SRC_IP6},
7581 {I40E_INSET_IPV6_DST, I40E_REG_INSET_L3_DST_IP6},
7582 {I40E_INSET_IPV6_TC, I40E_REG_INSET_L3_IP6_TC},
7583 {I40E_INSET_IPV6_NEXT_HDR, I40E_REG_INSET_L3_IP6_NEXT_HDR},
7584 {I40E_INSET_IPV6_HOP_LIMIT, I40E_REG_INSET_L3_IP6_HOP_LIMIT},
7585 {I40E_INSET_SRC_PORT, I40E_REG_INSET_L4_SRC_PORT},
7586 {I40E_INSET_DST_PORT, I40E_REG_INSET_L4_DST_PORT},
7587 {I40E_INSET_SCTP_VT, I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG},
7588 {I40E_INSET_TUNNEL_ID, I40E_REG_INSET_TUNNEL_ID},
7589 {I40E_INSET_TUNNEL_DMAC,
7590 I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC},
7591 {I40E_INSET_TUNNEL_IPV4_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP4},
7592 {I40E_INSET_TUNNEL_IPV6_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP6},
7593 {I40E_INSET_TUNNEL_SRC_PORT,
7594 I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT},
7595 {I40E_INSET_TUNNEL_DST_PORT,
7596 I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT},
7597 {I40E_INSET_VLAN_TUNNEL, I40E_REG_INSET_TUNNEL_VLAN},
7598 {I40E_INSET_FLEX_PAYLOAD_W1, I40E_REG_INSET_FLEX_PAYLOAD_WORD1},
7599 {I40E_INSET_FLEX_PAYLOAD_W2, I40E_REG_INSET_FLEX_PAYLOAD_WORD2},
7600 {I40E_INSET_FLEX_PAYLOAD_W3, I40E_REG_INSET_FLEX_PAYLOAD_WORD3},
7601 {I40E_INSET_FLEX_PAYLOAD_W4, I40E_REG_INSET_FLEX_PAYLOAD_WORD4},
7602 {I40E_INSET_FLEX_PAYLOAD_W5, I40E_REG_INSET_FLEX_PAYLOAD_WORD5},
7603 {I40E_INSET_FLEX_PAYLOAD_W6, I40E_REG_INSET_FLEX_PAYLOAD_WORD6},
7604 {I40E_INSET_FLEX_PAYLOAD_W7, I40E_REG_INSET_FLEX_PAYLOAD_WORD7},
7605 {I40E_INSET_FLEX_PAYLOAD_W8, I40E_REG_INSET_FLEX_PAYLOAD_WORD8},
7611 /* Translate input set to register aware inset */
7612 for (i = 0; i < RTE_DIM(inset_map); i++) {
7613 if (input & inset_map[i].inset)
7614 val |= inset_map[i].inset_reg;
7621 i40e_generate_inset_mask_reg(uint64_t inset, uint32_t *mask, uint8_t nb_elem)
7624 uint64_t inset_need_mask = inset;
7626 static const struct {
7629 } inset_mask_map[] = {
7630 {I40E_INSET_IPV4_TOS, I40E_INSET_IPV4_TOS_MASK},
7631 {I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL, 0},
7632 {I40E_INSET_IPV4_PROTO, I40E_INSET_IPV4_PROTO_MASK},
7633 {I40E_INSET_IPV4_TTL, I40E_INSET_IPv4_TTL_MASK},
7634 {I40E_INSET_IPV6_TC, I40E_INSET_IPV6_TC_MASK},
7635 {I40E_INSET_IPV6_NEXT_HDR | I40E_INSET_IPV6_HOP_LIMIT, 0},
7636 {I40E_INSET_IPV6_NEXT_HDR, I40E_INSET_IPV6_NEXT_HDR_MASK},
7637 {I40E_INSET_IPV6_HOP_LIMIT, I40E_INSET_IPV6_HOP_LIMIT_MASK},
7640 if (!inset || !mask || !nb_elem)
7643 for (i = 0, idx = 0; i < RTE_DIM(inset_mask_map); i++) {
7644 /* Clear the inset bit, if no MASK is required,
7645 * for example proto + ttl
7647 if ((inset & inset_mask_map[i].inset) ==
7648 inset_mask_map[i].inset && inset_mask_map[i].mask == 0)
7649 inset_need_mask &= ~inset_mask_map[i].inset;
7650 if (!inset_need_mask)
7653 for (i = 0, idx = 0; i < RTE_DIM(inset_mask_map); i++) {
7654 if ((inset_need_mask & inset_mask_map[i].inset) ==
7655 inset_mask_map[i].inset) {
7656 if (idx >= nb_elem) {
7657 PMD_DRV_LOG(ERR, "exceed maximal number of bitmasks");
7660 mask[idx] = inset_mask_map[i].mask;
7669 i40e_check_write_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
7671 uint32_t reg = i40e_read_rx_ctl(hw, addr);
7673 PMD_DRV_LOG(DEBUG, "[0x%08x] original: 0x%08x\n", addr, reg);
7675 i40e_write_rx_ctl(hw, addr, val);
7676 PMD_DRV_LOG(DEBUG, "[0x%08x] after: 0x%08x\n", addr,
7677 (uint32_t)i40e_read_rx_ctl(hw, addr));
7681 i40e_filter_input_set_init(struct i40e_pf *pf)
7683 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7684 enum i40e_filter_pctype pctype;
7685 uint64_t input_set, inset_reg;
7686 uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
7689 for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
7690 pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++) {
7691 if (!I40E_VALID_PCTYPE(pctype))
7693 input_set = i40e_get_default_input_set(pctype);
7695 num = i40e_generate_inset_mask_reg(input_set, mask_reg,
7696 I40E_INSET_MASK_NUM_REG);
7699 inset_reg = i40e_translate_input_set_reg(input_set);
7701 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
7702 (uint32_t)(inset_reg & UINT32_MAX));
7703 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
7704 (uint32_t)((inset_reg >>
7705 I40E_32_BIT_WIDTH) & UINT32_MAX));
7706 i40e_check_write_reg(hw, I40E_GLQF_HASH_INSET(0, pctype),
7707 (uint32_t)(inset_reg & UINT32_MAX));
7708 i40e_check_write_reg(hw, I40E_GLQF_HASH_INSET(1, pctype),
7709 (uint32_t)((inset_reg >>
7710 I40E_32_BIT_WIDTH) & UINT32_MAX));
7712 for (i = 0; i < num; i++) {
7713 i40e_check_write_reg(hw, I40E_GLQF_FD_MSK(i, pctype),
7715 i40e_check_write_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
7718 /*clear unused mask registers of the pctype */
7719 for (i = num; i < I40E_INSET_MASK_NUM_REG; i++) {
7720 i40e_check_write_reg(hw, I40E_GLQF_FD_MSK(i, pctype),
7722 i40e_check_write_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
7725 I40E_WRITE_FLUSH(hw);
7727 /* store the default input set */
7728 pf->hash_input_set[pctype] = input_set;
7729 pf->fdir.input_set[pctype] = input_set;
7734 i40e_hash_filter_inset_select(struct i40e_hw *hw,
7735 struct rte_eth_input_set_conf *conf)
7737 struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
7738 enum i40e_filter_pctype pctype;
7739 uint64_t input_set, inset_reg = 0;
7740 uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
7744 PMD_DRV_LOG(ERR, "Invalid pointer");
7747 if (conf->op != RTE_ETH_INPUT_SET_SELECT &&
7748 conf->op != RTE_ETH_INPUT_SET_ADD) {
7749 PMD_DRV_LOG(ERR, "Unsupported input set operation");
7753 if (!I40E_VALID_FLOW(conf->flow_type)) {
7754 PMD_DRV_LOG(ERR, "invalid flow_type input.");
7759 /* get translated pctype value in fd pctype register */
7760 pctype = (enum i40e_filter_pctype)i40e_read_rx_ctl(hw,
7761 I40E_GLQF_FD_PCTYPES((int)i40e_flowtype_to_pctype(
7764 pctype = i40e_flowtype_to_pctype(conf->flow_type);
7767 ret = i40e_parse_input_set(&input_set, pctype, conf->field,
7770 PMD_DRV_LOG(ERR, "Failed to parse input set");
7773 if (i40e_validate_input_set(pctype, RTE_ETH_FILTER_HASH,
7775 PMD_DRV_LOG(ERR, "Invalid input set");
7778 if (conf->op == RTE_ETH_INPUT_SET_ADD) {
7779 /* get inset value in register */
7780 inset_reg = i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, pctype));
7781 inset_reg <<= I40E_32_BIT_WIDTH;
7782 inset_reg |= i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, pctype));
7783 input_set |= pf->hash_input_set[pctype];
7785 num = i40e_generate_inset_mask_reg(input_set, mask_reg,
7786 I40E_INSET_MASK_NUM_REG);
7790 inset_reg |= i40e_translate_input_set_reg(input_set);
7792 i40e_check_write_reg(hw, I40E_GLQF_HASH_INSET(0, pctype),
7793 (uint32_t)(inset_reg & UINT32_MAX));
7794 i40e_check_write_reg(hw, I40E_GLQF_HASH_INSET(1, pctype),
7795 (uint32_t)((inset_reg >>
7796 I40E_32_BIT_WIDTH) & UINT32_MAX));
7798 for (i = 0; i < num; i++)
7799 i40e_check_write_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
7801 /*clear unused mask registers of the pctype */
7802 for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
7803 i40e_check_write_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
7805 I40E_WRITE_FLUSH(hw);
7807 pf->hash_input_set[pctype] = input_set;
7812 i40e_fdir_filter_inset_select(struct i40e_pf *pf,
7813 struct rte_eth_input_set_conf *conf)
7815 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7816 enum i40e_filter_pctype pctype;
7817 uint64_t input_set, inset_reg = 0;
7818 uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
7822 PMD_DRV_LOG(ERR, "Invalid pointer");
7825 if (conf->op != RTE_ETH_INPUT_SET_SELECT &&
7826 conf->op != RTE_ETH_INPUT_SET_ADD) {
7827 PMD_DRV_LOG(ERR, "Unsupported input set operation");
7831 if (!I40E_VALID_FLOW(conf->flow_type)) {
7832 PMD_DRV_LOG(ERR, "invalid flow_type input.");
7836 pctype = i40e_flowtype_to_pctype(conf->flow_type);
7838 ret = i40e_parse_input_set(&input_set, pctype, conf->field,
7841 PMD_DRV_LOG(ERR, "Failed to parse input set");
7844 if (i40e_validate_input_set(pctype, RTE_ETH_FILTER_FDIR,
7846 PMD_DRV_LOG(ERR, "Invalid input set");
7850 /* get inset value in register */
7851 inset_reg = i40e_read_rx_ctl(hw, I40E_PRTQF_FD_INSET(pctype, 1));
7852 inset_reg <<= I40E_32_BIT_WIDTH;
7853 inset_reg |= i40e_read_rx_ctl(hw, I40E_PRTQF_FD_INSET(pctype, 0));
7855 /* Can not change the inset reg for flex payload for fdir,
7856 * it is done by writing I40E_PRTQF_FD_FLXINSET
7857 * in i40e_set_flex_mask_on_pctype.
7859 if (conf->op == RTE_ETH_INPUT_SET_SELECT)
7860 inset_reg &= I40E_REG_INSET_FLEX_PAYLOAD_WORDS;
7862 input_set |= pf->fdir.input_set[pctype];
7863 num = i40e_generate_inset_mask_reg(input_set, mask_reg,
7864 I40E_INSET_MASK_NUM_REG);
7868 inset_reg |= i40e_translate_input_set_reg(input_set);
7870 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
7871 (uint32_t)(inset_reg & UINT32_MAX));
7872 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
7873 (uint32_t)((inset_reg >>
7874 I40E_32_BIT_WIDTH) & UINT32_MAX));
7876 for (i = 0; i < num; i++)
7877 i40e_check_write_reg(hw, I40E_GLQF_FD_MSK(i, pctype),
7879 /*clear unused mask registers of the pctype */
7880 for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
7881 i40e_check_write_reg(hw, I40E_GLQF_FD_MSK(i, pctype),
7883 I40E_WRITE_FLUSH(hw);
7885 pf->fdir.input_set[pctype] = input_set;
7890 i40e_hash_filter_get(struct i40e_hw *hw, struct rte_eth_hash_filter_info *info)
7895 PMD_DRV_LOG(ERR, "Invalid pointer");
7899 switch (info->info_type) {
7900 case RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT:
7901 i40e_get_symmetric_hash_enable_per_port(hw,
7902 &(info->info.enable));
7904 case RTE_ETH_HASH_FILTER_GLOBAL_CONFIG:
7905 ret = i40e_get_hash_filter_global_config(hw,
7906 &(info->info.global_conf));
7909 PMD_DRV_LOG(ERR, "Hash filter info type (%d) not supported",
7919 i40e_hash_filter_set(struct i40e_hw *hw, struct rte_eth_hash_filter_info *info)
7924 PMD_DRV_LOG(ERR, "Invalid pointer");
7928 switch (info->info_type) {
7929 case RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT:
7930 i40e_set_symmetric_hash_enable_per_port(hw, info->info.enable);
7932 case RTE_ETH_HASH_FILTER_GLOBAL_CONFIG:
7933 ret = i40e_set_hash_filter_global_config(hw,
7934 &(info->info.global_conf));
7936 case RTE_ETH_HASH_FILTER_INPUT_SET_SELECT:
7937 ret = i40e_hash_filter_inset_select(hw,
7938 &(info->info.input_set_conf));
7942 PMD_DRV_LOG(ERR, "Hash filter info type (%d) not supported",
7951 /* Operations for hash function */
7953 i40e_hash_filter_ctrl(struct rte_eth_dev *dev,
7954 enum rte_filter_op filter_op,
7957 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7960 switch (filter_op) {
7961 case RTE_ETH_FILTER_NOP:
7963 case RTE_ETH_FILTER_GET:
7964 ret = i40e_hash_filter_get(hw,
7965 (struct rte_eth_hash_filter_info *)arg);
7967 case RTE_ETH_FILTER_SET:
7968 ret = i40e_hash_filter_set(hw,
7969 (struct rte_eth_hash_filter_info *)arg);
7972 PMD_DRV_LOG(WARNING, "Filter operation (%d) not supported",
7982 * Configure ethertype filter, which can director packet by filtering
7983 * with mac address and ether_type or only ether_type
7986 i40e_ethertype_filter_set(struct i40e_pf *pf,
7987 struct rte_eth_ethertype_filter *filter,
7990 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7991 struct i40e_control_filter_stats stats;
7995 if (filter->queue >= pf->dev_data->nb_rx_queues) {
7996 PMD_DRV_LOG(ERR, "Invalid queue ID");
7999 if (filter->ether_type == ETHER_TYPE_IPv4 ||
8000 filter->ether_type == ETHER_TYPE_IPv6) {
8001 PMD_DRV_LOG(ERR, "unsupported ether_type(0x%04x) in"
8002 " control packet filter.", filter->ether_type);
8005 if (filter->ether_type == ETHER_TYPE_VLAN)
8006 PMD_DRV_LOG(WARNING, "filter vlan ether_type in first tag is"
8009 if (!(filter->flags & RTE_ETHTYPE_FLAGS_MAC))
8010 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
8011 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP)
8012 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
8013 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
8015 memset(&stats, 0, sizeof(stats));
8016 ret = i40e_aq_add_rem_control_packet_filter(hw,
8017 filter->mac_addr.addr_bytes,
8018 filter->ether_type, flags,
8020 filter->queue, add, &stats, NULL);
8022 PMD_DRV_LOG(INFO, "add/rem control packet filter, return %d,"
8023 " mac_etype_used = %u, etype_used = %u,"
8024 " mac_etype_free = %u, etype_free = %u\n",
8025 ret, stats.mac_etype_used, stats.etype_used,
8026 stats.mac_etype_free, stats.etype_free);
8033 * Handle operations for ethertype filter.
8036 i40e_ethertype_filter_handle(struct rte_eth_dev *dev,
8037 enum rte_filter_op filter_op,
8040 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8043 if (filter_op == RTE_ETH_FILTER_NOP)
8047 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
8052 switch (filter_op) {
8053 case RTE_ETH_FILTER_ADD:
8054 ret = i40e_ethertype_filter_set(pf,
8055 (struct rte_eth_ethertype_filter *)arg,
8058 case RTE_ETH_FILTER_DELETE:
8059 ret = i40e_ethertype_filter_set(pf,
8060 (struct rte_eth_ethertype_filter *)arg,
8064 PMD_DRV_LOG(ERR, "unsupported operation %u\n", filter_op);
8072 i40e_dev_filter_ctrl(struct rte_eth_dev *dev,
8073 enum rte_filter_type filter_type,
8074 enum rte_filter_op filter_op,
8082 switch (filter_type) {
8083 case RTE_ETH_FILTER_NONE:
8084 /* For global configuration */
8085 ret = i40e_filter_ctrl_global_config(dev, filter_op, arg);
8087 case RTE_ETH_FILTER_HASH:
8088 ret = i40e_hash_filter_ctrl(dev, filter_op, arg);
8090 case RTE_ETH_FILTER_MACVLAN:
8091 ret = i40e_mac_filter_handle(dev, filter_op, arg);
8093 case RTE_ETH_FILTER_ETHERTYPE:
8094 ret = i40e_ethertype_filter_handle(dev, filter_op, arg);
8096 case RTE_ETH_FILTER_TUNNEL:
8097 ret = i40e_tunnel_filter_handle(dev, filter_op, arg);
8099 case RTE_ETH_FILTER_FDIR:
8100 ret = i40e_fdir_ctrl_func(dev, filter_op, arg);
8103 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
8113 * Check and enable Extended Tag.
8114 * Enabling Extended Tag is important for 40G performance.
8117 i40e_enable_extended_tag(struct rte_eth_dev *dev)
8122 ret = rte_eal_pci_read_config(dev->pci_dev, &buf, sizeof(buf),
8125 PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
8129 if (!(buf & PCI_DEV_CAP_EXT_TAG_MASK)) {
8130 PMD_DRV_LOG(ERR, "Does not support Extended Tag");
8135 ret = rte_eal_pci_read_config(dev->pci_dev, &buf, sizeof(buf),
8138 PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
8142 if (buf & PCI_DEV_CTRL_EXT_TAG_MASK) {
8143 PMD_DRV_LOG(DEBUG, "Extended Tag has already been enabled");
8146 buf |= PCI_DEV_CTRL_EXT_TAG_MASK;
8147 ret = rte_eal_pci_write_config(dev->pci_dev, &buf, sizeof(buf),
8150 PMD_DRV_LOG(ERR, "Failed to write PCI offset 0x%x",
8157 * As some registers wouldn't be reset unless a global hardware reset,
8158 * hardware initialization is needed to put those registers into an
8159 * expected initial state.
8162 i40e_hw_init(struct rte_eth_dev *dev)
8164 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8166 i40e_enable_extended_tag(dev);
8168 /* clear the PF Queue Filter control register */
8169 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, 0);
8171 /* Disable symmetric hash per port */
8172 i40e_set_symmetric_hash_enable_per_port(hw, 0);
8175 enum i40e_filter_pctype
8176 i40e_flowtype_to_pctype(uint16_t flow_type)
8178 static const enum i40e_filter_pctype pctype_table[] = {
8179 [RTE_ETH_FLOW_FRAG_IPV4] = I40E_FILTER_PCTYPE_FRAG_IPV4,
8180 [RTE_ETH_FLOW_NONFRAG_IPV4_UDP] =
8181 I40E_FILTER_PCTYPE_NONF_IPV4_UDP,
8182 [RTE_ETH_FLOW_NONFRAG_IPV4_TCP] =
8183 I40E_FILTER_PCTYPE_NONF_IPV4_TCP,
8184 [RTE_ETH_FLOW_NONFRAG_IPV4_SCTP] =
8185 I40E_FILTER_PCTYPE_NONF_IPV4_SCTP,
8186 [RTE_ETH_FLOW_NONFRAG_IPV4_OTHER] =
8187 I40E_FILTER_PCTYPE_NONF_IPV4_OTHER,
8188 [RTE_ETH_FLOW_FRAG_IPV6] = I40E_FILTER_PCTYPE_FRAG_IPV6,
8189 [RTE_ETH_FLOW_NONFRAG_IPV6_UDP] =
8190 I40E_FILTER_PCTYPE_NONF_IPV6_UDP,
8191 [RTE_ETH_FLOW_NONFRAG_IPV6_TCP] =
8192 I40E_FILTER_PCTYPE_NONF_IPV6_TCP,
8193 [RTE_ETH_FLOW_NONFRAG_IPV6_SCTP] =
8194 I40E_FILTER_PCTYPE_NONF_IPV6_SCTP,
8195 [RTE_ETH_FLOW_NONFRAG_IPV6_OTHER] =
8196 I40E_FILTER_PCTYPE_NONF_IPV6_OTHER,
8197 [RTE_ETH_FLOW_L2_PAYLOAD] = I40E_FILTER_PCTYPE_L2_PAYLOAD,
8200 return pctype_table[flow_type];
8204 i40e_pctype_to_flowtype(enum i40e_filter_pctype pctype)
8206 static const uint16_t flowtype_table[] = {
8207 [I40E_FILTER_PCTYPE_FRAG_IPV4] = RTE_ETH_FLOW_FRAG_IPV4,
8208 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
8209 RTE_ETH_FLOW_NONFRAG_IPV4_UDP,
8211 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
8212 RTE_ETH_FLOW_NONFRAG_IPV4_UDP,
8213 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
8214 RTE_ETH_FLOW_NONFRAG_IPV4_UDP,
8216 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
8217 RTE_ETH_FLOW_NONFRAG_IPV4_TCP,
8219 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
8220 RTE_ETH_FLOW_NONFRAG_IPV4_TCP,
8222 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
8223 RTE_ETH_FLOW_NONFRAG_IPV4_SCTP,
8224 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
8225 RTE_ETH_FLOW_NONFRAG_IPV4_OTHER,
8226 [I40E_FILTER_PCTYPE_FRAG_IPV6] = RTE_ETH_FLOW_FRAG_IPV6,
8227 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
8228 RTE_ETH_FLOW_NONFRAG_IPV6_UDP,
8230 [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
8231 RTE_ETH_FLOW_NONFRAG_IPV6_UDP,
8232 [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
8233 RTE_ETH_FLOW_NONFRAG_IPV6_UDP,
8235 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
8236 RTE_ETH_FLOW_NONFRAG_IPV6_TCP,
8238 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
8239 RTE_ETH_FLOW_NONFRAG_IPV6_TCP,
8241 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
8242 RTE_ETH_FLOW_NONFRAG_IPV6_SCTP,
8243 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
8244 RTE_ETH_FLOW_NONFRAG_IPV6_OTHER,
8245 [I40E_FILTER_PCTYPE_L2_PAYLOAD] = RTE_ETH_FLOW_L2_PAYLOAD,
8248 return flowtype_table[pctype];
8252 * On X710, performance number is far from the expectation on recent firmware
8253 * versions; on XL710, performance number is also far from the expectation on
8254 * recent firmware versions, if promiscuous mode is disabled, or promiscuous
8255 * mode is enabled and port MAC address is equal to the packet destination MAC
8256 * address. The fix for this issue may not be integrated in the following
8257 * firmware version. So the workaround in software driver is needed. It needs
8258 * to modify the initial values of 3 internal only registers for both X710 and
8259 * XL710. Note that the values for X710 or XL710 could be different, and the
8260 * workaround can be removed when it is fixed in firmware in the future.
8263 /* For both X710 and XL710 */
8264 #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE 0x10000200
8265 #define I40E_GL_SWR_PRI_JOIN_MAP_0 0x26CE00
8267 #define I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x011f0200
8268 #define I40E_GL_SWR_PRI_JOIN_MAP_2 0x26CE08
8271 #define I40E_GL_SWR_PM_UP_THR_EF_VALUE 0x03030303
8273 #define I40E_GL_SWR_PM_UP_THR_SF_VALUE 0x06060606
8274 #define I40E_GL_SWR_PM_UP_THR 0x269FBC
8277 i40e_dev_sync_phy_type(struct i40e_hw *hw)
8279 enum i40e_status_code status;
8280 struct i40e_aq_get_phy_abilities_resp phy_ab;
8283 status = i40e_aq_get_phy_capabilities(hw, false, true, &phy_ab,
8294 i40e_configure_registers(struct i40e_hw *hw)
8300 {I40E_GL_SWR_PRI_JOIN_MAP_0, I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE},
8301 {I40E_GL_SWR_PRI_JOIN_MAP_2, I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE},
8302 {I40E_GL_SWR_PM_UP_THR, 0}, /* Compute value dynamically */
8308 for (i = 0; i < RTE_DIM(reg_table); i++) {
8309 if (reg_table[i].addr == I40E_GL_SWR_PM_UP_THR) {
8310 if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types) || /* For XL710 */
8311 I40E_PHY_TYPE_SUPPORT_25G(hw->phy.phy_types)) /* For XXV710 */
8313 I40E_GL_SWR_PM_UP_THR_SF_VALUE;
8316 I40E_GL_SWR_PM_UP_THR_EF_VALUE;
8319 ret = i40e_aq_debug_read_register(hw, reg_table[i].addr,
8322 PMD_DRV_LOG(ERR, "Failed to read from 0x%"PRIx32,
8326 PMD_DRV_LOG(DEBUG, "Read from 0x%"PRIx32": 0x%"PRIx64,
8327 reg_table[i].addr, reg);
8328 if (reg == reg_table[i].val)
8331 ret = i40e_aq_debug_write_register(hw, reg_table[i].addr,
8332 reg_table[i].val, NULL);
8334 PMD_DRV_LOG(ERR, "Failed to write 0x%"PRIx64" to the "
8335 "address of 0x%"PRIx32, reg_table[i].val,
8339 PMD_DRV_LOG(DEBUG, "Write 0x%"PRIx64" to the address of "
8340 "0x%"PRIx32, reg_table[i].val, reg_table[i].addr);
8344 #define I40E_VSI_TSR(_i) (0x00050800 + ((_i) * 4))
8345 #define I40E_VSI_TSR_QINQ_CONFIG 0xc030
8346 #define I40E_VSI_L2TAGSTXVALID(_i) (0x00042800 + ((_i) * 4))
8347 #define I40E_VSI_L2TAGSTXVALID_QINQ 0xab
8349 i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi)
8354 if (vsi->vsi_id >= I40E_MAX_NUM_VSIS) {
8355 PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
8359 /* Configure for double VLAN RX stripping */
8360 reg = I40E_READ_REG(hw, I40E_VSI_TSR(vsi->vsi_id));
8361 if ((reg & I40E_VSI_TSR_QINQ_CONFIG) != I40E_VSI_TSR_QINQ_CONFIG) {
8362 reg |= I40E_VSI_TSR_QINQ_CONFIG;
8363 ret = i40e_aq_debug_write_register(hw,
8364 I40E_VSI_TSR(vsi->vsi_id),
8367 PMD_DRV_LOG(ERR, "Failed to update VSI_TSR[%d]",
8369 return I40E_ERR_CONFIG;
8373 /* Configure for double VLAN TX insertion */
8374 reg = I40E_READ_REG(hw, I40E_VSI_L2TAGSTXVALID(vsi->vsi_id));
8375 if ((reg & 0xff) != I40E_VSI_L2TAGSTXVALID_QINQ) {
8376 reg = I40E_VSI_L2TAGSTXVALID_QINQ;
8377 ret = i40e_aq_debug_write_register(hw,
8378 I40E_VSI_L2TAGSTXVALID(
8379 vsi->vsi_id), reg, NULL);
8381 PMD_DRV_LOG(ERR, "Failed to update "
8382 "VSI_L2TAGSTXVALID[%d]", vsi->vsi_id);
8383 return I40E_ERR_CONFIG;
8391 * i40e_aq_add_mirror_rule
8392 * @hw: pointer to the hardware structure
8393 * @seid: VEB seid to add mirror rule to
8394 * @dst_id: destination vsi seid
8395 * @entries: Buffer which contains the entities to be mirrored
8396 * @count: number of entities contained in the buffer
8397 * @rule_id:the rule_id of the rule to be added
8399 * Add a mirror rule for a given veb.
8402 static enum i40e_status_code
8403 i40e_aq_add_mirror_rule(struct i40e_hw *hw,
8404 uint16_t seid, uint16_t dst_id,
8405 uint16_t rule_type, uint16_t *entries,
8406 uint16_t count, uint16_t *rule_id)
8408 struct i40e_aq_desc desc;
8409 struct i40e_aqc_add_delete_mirror_rule cmd;
8410 struct i40e_aqc_add_delete_mirror_rule_completion *resp =
8411 (struct i40e_aqc_add_delete_mirror_rule_completion *)
8414 enum i40e_status_code status;
8416 i40e_fill_default_direct_cmd_desc(&desc,
8417 i40e_aqc_opc_add_mirror_rule);
8418 memset(&cmd, 0, sizeof(cmd));
8420 buff_len = sizeof(uint16_t) * count;
8421 desc.datalen = rte_cpu_to_le_16(buff_len);
8423 desc.flags |= rte_cpu_to_le_16(
8424 (uint16_t)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
8425 cmd.rule_type = rte_cpu_to_le_16(rule_type <<
8426 I40E_AQC_MIRROR_RULE_TYPE_SHIFT);
8427 cmd.num_entries = rte_cpu_to_le_16(count);
8428 cmd.seid = rte_cpu_to_le_16(seid);
8429 cmd.destination = rte_cpu_to_le_16(dst_id);
8431 rte_memcpy(&desc.params.raw, &cmd, sizeof(cmd));
8432 status = i40e_asq_send_command(hw, &desc, entries, buff_len, NULL);
8433 PMD_DRV_LOG(INFO, "i40e_aq_add_mirror_rule, aq_status %d,"
8435 " mirror_rules_used = %u, mirror_rules_free = %u,",
8436 hw->aq.asq_last_status, resp->rule_id,
8437 resp->mirror_rules_used, resp->mirror_rules_free);
8438 *rule_id = rte_le_to_cpu_16(resp->rule_id);
8444 * i40e_aq_del_mirror_rule
8445 * @hw: pointer to the hardware structure
8446 * @seid: VEB seid to add mirror rule to
8447 * @entries: Buffer which contains the entities to be mirrored
8448 * @count: number of entities contained in the buffer
8449 * @rule_id:the rule_id of the rule to be delete
8451 * Delete a mirror rule for a given veb.
8454 static enum i40e_status_code
8455 i40e_aq_del_mirror_rule(struct i40e_hw *hw,
8456 uint16_t seid, uint16_t rule_type, uint16_t *entries,
8457 uint16_t count, uint16_t rule_id)
8459 struct i40e_aq_desc desc;
8460 struct i40e_aqc_add_delete_mirror_rule cmd;
8461 uint16_t buff_len = 0;
8462 enum i40e_status_code status;
8465 i40e_fill_default_direct_cmd_desc(&desc,
8466 i40e_aqc_opc_delete_mirror_rule);
8467 memset(&cmd, 0, sizeof(cmd));
8468 if (rule_type == I40E_AQC_MIRROR_RULE_TYPE_VLAN) {
8469 desc.flags |= rte_cpu_to_le_16((uint16_t)(I40E_AQ_FLAG_BUF |
8471 cmd.num_entries = count;
8472 buff_len = sizeof(uint16_t) * count;
8473 desc.datalen = rte_cpu_to_le_16(buff_len);
8474 buff = (void *)entries;
8476 /* rule id is filled in destination field for deleting mirror rule */
8477 cmd.destination = rte_cpu_to_le_16(rule_id);
8479 cmd.rule_type = rte_cpu_to_le_16(rule_type <<
8480 I40E_AQC_MIRROR_RULE_TYPE_SHIFT);
8481 cmd.seid = rte_cpu_to_le_16(seid);
8483 rte_memcpy(&desc.params.raw, &cmd, sizeof(cmd));
8484 status = i40e_asq_send_command(hw, &desc, buff, buff_len, NULL);
8490 * i40e_mirror_rule_set
8491 * @dev: pointer to the hardware structure
8492 * @mirror_conf: mirror rule info
8493 * @sw_id: mirror rule's sw_id
8494 * @on: enable/disable
8496 * set a mirror rule.
8500 i40e_mirror_rule_set(struct rte_eth_dev *dev,
8501 struct rte_eth_mirror_conf *mirror_conf,
8502 uint8_t sw_id, uint8_t on)
8504 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8505 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8506 struct i40e_mirror_rule *it, *mirr_rule = NULL;
8507 struct i40e_mirror_rule *parent = NULL;
8508 uint16_t seid, dst_seid, rule_id;
8512 PMD_DRV_LOG(DEBUG, "i40e_mirror_rule_set: sw_id = %d.", sw_id);
8514 if (pf->main_vsi->veb == NULL || pf->vfs == NULL) {
8515 PMD_DRV_LOG(ERR, "mirror rule can not be configured"
8516 " without veb or vfs.");
8519 if (pf->nb_mirror_rule > I40E_MAX_MIRROR_RULES) {
8520 PMD_DRV_LOG(ERR, "mirror table is full.");
8523 if (mirror_conf->dst_pool > pf->vf_num) {
8524 PMD_DRV_LOG(ERR, "invalid destination pool %u.",
8525 mirror_conf->dst_pool);
8529 seid = pf->main_vsi->veb->seid;
8531 TAILQ_FOREACH(it, &pf->mirror_list, rules) {
8532 if (sw_id <= it->index) {
8538 if (mirr_rule && sw_id == mirr_rule->index) {
8540 PMD_DRV_LOG(ERR, "mirror rule exists.");
8543 ret = i40e_aq_del_mirror_rule(hw, seid,
8544 mirr_rule->rule_type,
8546 mirr_rule->num_entries, mirr_rule->id);
8548 PMD_DRV_LOG(ERR, "failed to remove mirror rule:"
8549 " ret = %d, aq_err = %d.",
8550 ret, hw->aq.asq_last_status);
8553 TAILQ_REMOVE(&pf->mirror_list, mirr_rule, rules);
8554 rte_free(mirr_rule);
8555 pf->nb_mirror_rule--;
8559 PMD_DRV_LOG(ERR, "mirror rule doesn't exist.");
8563 mirr_rule = rte_zmalloc("i40e_mirror_rule",
8564 sizeof(struct i40e_mirror_rule) , 0);
8566 PMD_DRV_LOG(ERR, "failed to allocate memory");
8567 return I40E_ERR_NO_MEMORY;
8569 switch (mirror_conf->rule_type) {
8570 case ETH_MIRROR_VLAN:
8571 for (i = 0, j = 0; i < ETH_MIRROR_MAX_VLANS; i++) {
8572 if (mirror_conf->vlan.vlan_mask & (1ULL << i)) {
8573 mirr_rule->entries[j] =
8574 mirror_conf->vlan.vlan_id[i];
8579 PMD_DRV_LOG(ERR, "vlan is not specified.");
8580 rte_free(mirr_rule);
8583 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_VLAN;
8585 case ETH_MIRROR_VIRTUAL_POOL_UP:
8586 case ETH_MIRROR_VIRTUAL_POOL_DOWN:
8587 /* check if the specified pool bit is out of range */
8588 if (mirror_conf->pool_mask > (uint64_t)(1ULL << (pf->vf_num + 1))) {
8589 PMD_DRV_LOG(ERR, "pool mask is out of range.");
8590 rte_free(mirr_rule);
8593 for (i = 0, j = 0; i < pf->vf_num; i++) {
8594 if (mirror_conf->pool_mask & (1ULL << i)) {
8595 mirr_rule->entries[j] = pf->vfs[i].vsi->seid;
8599 if (mirror_conf->pool_mask & (1ULL << pf->vf_num)) {
8600 /* add pf vsi to entries */
8601 mirr_rule->entries[j] = pf->main_vsi_seid;
8605 PMD_DRV_LOG(ERR, "pool is not specified.");
8606 rte_free(mirr_rule);
8609 /* egress and ingress in aq commands means from switch but not port */
8610 mirr_rule->rule_type =
8611 (mirror_conf->rule_type == ETH_MIRROR_VIRTUAL_POOL_UP) ?
8612 I40E_AQC_MIRROR_RULE_TYPE_VPORT_EGRESS :
8613 I40E_AQC_MIRROR_RULE_TYPE_VPORT_INGRESS;
8615 case ETH_MIRROR_UPLINK_PORT:
8616 /* egress and ingress in aq commands means from switch but not port*/
8617 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_ALL_EGRESS;
8619 case ETH_MIRROR_DOWNLINK_PORT:
8620 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_ALL_INGRESS;
8623 PMD_DRV_LOG(ERR, "unsupported mirror type %d.",
8624 mirror_conf->rule_type);
8625 rte_free(mirr_rule);
8629 /* If the dst_pool is equal to vf_num, consider it as PF */
8630 if (mirror_conf->dst_pool == pf->vf_num)
8631 dst_seid = pf->main_vsi_seid;
8633 dst_seid = pf->vfs[mirror_conf->dst_pool].vsi->seid;
8635 ret = i40e_aq_add_mirror_rule(hw, seid, dst_seid,
8636 mirr_rule->rule_type, mirr_rule->entries,
8639 PMD_DRV_LOG(ERR, "failed to add mirror rule:"
8640 " ret = %d, aq_err = %d.",
8641 ret, hw->aq.asq_last_status);
8642 rte_free(mirr_rule);
8646 mirr_rule->index = sw_id;
8647 mirr_rule->num_entries = j;
8648 mirr_rule->id = rule_id;
8649 mirr_rule->dst_vsi_seid = dst_seid;
8652 TAILQ_INSERT_AFTER(&pf->mirror_list, parent, mirr_rule, rules);
8654 TAILQ_INSERT_HEAD(&pf->mirror_list, mirr_rule, rules);
8656 pf->nb_mirror_rule++;
8661 * i40e_mirror_rule_reset
8662 * @dev: pointer to the device
8663 * @sw_id: mirror rule's sw_id
8665 * reset a mirror rule.
8669 i40e_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t sw_id)
8671 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8672 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8673 struct i40e_mirror_rule *it, *mirr_rule = NULL;
8677 PMD_DRV_LOG(DEBUG, "i40e_mirror_rule_reset: sw_id = %d.", sw_id);
8679 seid = pf->main_vsi->veb->seid;
8681 TAILQ_FOREACH(it, &pf->mirror_list, rules) {
8682 if (sw_id == it->index) {
8688 ret = i40e_aq_del_mirror_rule(hw, seid,
8689 mirr_rule->rule_type,
8691 mirr_rule->num_entries, mirr_rule->id);
8693 PMD_DRV_LOG(ERR, "failed to remove mirror rule:"
8694 " status = %d, aq_err = %d.",
8695 ret, hw->aq.asq_last_status);
8698 TAILQ_REMOVE(&pf->mirror_list, mirr_rule, rules);
8699 rte_free(mirr_rule);
8700 pf->nb_mirror_rule--;
8702 PMD_DRV_LOG(ERR, "mirror rule doesn't exist.");
8709 i40e_read_systime_cyclecounter(struct rte_eth_dev *dev)
8711 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8712 uint64_t systim_cycles;
8714 systim_cycles = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_L);
8715 systim_cycles |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_H)
8718 return systim_cycles;
8722 i40e_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev, uint8_t index)
8724 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8727 rx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_L(index));
8728 rx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(index))
8735 i40e_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
8737 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8740 tx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_L);
8741 tx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H)
8748 i40e_start_timecounters(struct rte_eth_dev *dev)
8750 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8751 struct i40e_adapter *adapter =
8752 (struct i40e_adapter *)dev->data->dev_private;
8753 struct rte_eth_link link;
8754 uint32_t tsync_inc_l;
8755 uint32_t tsync_inc_h;
8757 /* Get current link speed. */
8758 memset(&link, 0, sizeof(link));
8759 i40e_dev_link_update(dev, 1);
8760 rte_i40e_dev_atomic_read_link_status(dev, &link);
8762 switch (link.link_speed) {
8763 case ETH_SPEED_NUM_40G:
8764 tsync_inc_l = I40E_PTP_40GB_INCVAL & 0xFFFFFFFF;
8765 tsync_inc_h = I40E_PTP_40GB_INCVAL >> 32;
8767 case ETH_SPEED_NUM_10G:
8768 tsync_inc_l = I40E_PTP_10GB_INCVAL & 0xFFFFFFFF;
8769 tsync_inc_h = I40E_PTP_10GB_INCVAL >> 32;
8771 case ETH_SPEED_NUM_1G:
8772 tsync_inc_l = I40E_PTP_1GB_INCVAL & 0xFFFFFFFF;
8773 tsync_inc_h = I40E_PTP_1GB_INCVAL >> 32;
8780 /* Set the timesync increment value. */
8781 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, tsync_inc_l);
8782 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, tsync_inc_h);
8784 memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
8785 memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
8786 memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
8788 adapter->systime_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
8789 adapter->systime_tc.cc_shift = 0;
8790 adapter->systime_tc.nsec_mask = 0;
8792 adapter->rx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
8793 adapter->rx_tstamp_tc.cc_shift = 0;
8794 adapter->rx_tstamp_tc.nsec_mask = 0;
8796 adapter->tx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
8797 adapter->tx_tstamp_tc.cc_shift = 0;
8798 adapter->tx_tstamp_tc.nsec_mask = 0;
8802 i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
8804 struct i40e_adapter *adapter =
8805 (struct i40e_adapter *)dev->data->dev_private;
8807 adapter->systime_tc.nsec += delta;
8808 adapter->rx_tstamp_tc.nsec += delta;
8809 adapter->tx_tstamp_tc.nsec += delta;
8815 i40e_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
8818 struct i40e_adapter *adapter =
8819 (struct i40e_adapter *)dev->data->dev_private;
8821 ns = rte_timespec_to_ns(ts);
8823 /* Set the timecounters to a new value. */
8824 adapter->systime_tc.nsec = ns;
8825 adapter->rx_tstamp_tc.nsec = ns;
8826 adapter->tx_tstamp_tc.nsec = ns;
8832 i40e_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
8834 uint64_t ns, systime_cycles;
8835 struct i40e_adapter *adapter =
8836 (struct i40e_adapter *)dev->data->dev_private;
8838 systime_cycles = i40e_read_systime_cyclecounter(dev);
8839 ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
8840 *ts = rte_ns_to_timespec(ns);
8846 i40e_timesync_enable(struct rte_eth_dev *dev)
8848 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8849 uint32_t tsync_ctl_l;
8850 uint32_t tsync_ctl_h;
8852 /* Stop the timesync system time. */
8853 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
8854 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
8855 /* Reset the timesync system time value. */
8856 I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_L, 0x0);
8857 I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_H, 0x0);
8859 i40e_start_timecounters(dev);
8861 /* Clear timesync registers. */
8862 I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
8863 I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H);
8864 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(0));
8865 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(1));
8866 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(2));
8867 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(3));
8869 /* Enable timestamping of PTP packets. */
8870 tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
8871 tsync_ctl_l |= I40E_PRTTSYN_TSYNENA;
8873 tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
8874 tsync_ctl_h |= I40E_PRTTSYN_TSYNENA;
8875 tsync_ctl_h |= I40E_PRTTSYN_TSYNTYPE;
8877 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
8878 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
8884 i40e_timesync_disable(struct rte_eth_dev *dev)
8886 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8887 uint32_t tsync_ctl_l;
8888 uint32_t tsync_ctl_h;
8890 /* Disable timestamping of transmitted PTP packets. */
8891 tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
8892 tsync_ctl_l &= ~I40E_PRTTSYN_TSYNENA;
8894 tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
8895 tsync_ctl_h &= ~I40E_PRTTSYN_TSYNENA;
8897 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
8898 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
8900 /* Reset the timesync increment value. */
8901 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
8902 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
8908 i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
8909 struct timespec *timestamp, uint32_t flags)
8911 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8912 struct i40e_adapter *adapter =
8913 (struct i40e_adapter *)dev->data->dev_private;
8915 uint32_t sync_status;
8916 uint32_t index = flags & 0x03;
8917 uint64_t rx_tstamp_cycles;
8920 sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_1);
8921 if ((sync_status & (1 << index)) == 0)
8924 rx_tstamp_cycles = i40e_read_rx_tstamp_cyclecounter(dev, index);
8925 ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
8926 *timestamp = rte_ns_to_timespec(ns);
8932 i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
8933 struct timespec *timestamp)
8935 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8936 struct i40e_adapter *adapter =
8937 (struct i40e_adapter *)dev->data->dev_private;
8939 uint32_t sync_status;
8940 uint64_t tx_tstamp_cycles;
8943 sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
8944 if ((sync_status & I40E_PRTTSYN_STAT_0_TXTIME_MASK) == 0)
8947 tx_tstamp_cycles = i40e_read_tx_tstamp_cyclecounter(dev);
8948 ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
8949 *timestamp = rte_ns_to_timespec(ns);
8955 * i40e_parse_dcb_configure - parse dcb configure from user
8956 * @dev: the device being configured
8957 * @dcb_cfg: pointer of the result of parse
8958 * @*tc_map: bit map of enabled traffic classes
8960 * Returns 0 on success, negative value on failure
8963 i40e_parse_dcb_configure(struct rte_eth_dev *dev,
8964 struct i40e_dcbx_config *dcb_cfg,
8967 struct rte_eth_dcb_rx_conf *dcb_rx_conf;
8968 uint8_t i, tc_bw, bw_lf;
8970 memset(dcb_cfg, 0, sizeof(struct i40e_dcbx_config));
8972 dcb_rx_conf = &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
8973 if (dcb_rx_conf->nb_tcs > I40E_MAX_TRAFFIC_CLASS) {
8974 PMD_INIT_LOG(ERR, "number of tc exceeds max.");
8978 /* assume each tc has the same bw */
8979 tc_bw = I40E_MAX_PERCENT / dcb_rx_conf->nb_tcs;
8980 for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
8981 dcb_cfg->etscfg.tcbwtable[i] = tc_bw;
8982 /* to ensure the sum of tcbw is equal to 100 */
8983 bw_lf = I40E_MAX_PERCENT % dcb_rx_conf->nb_tcs;
8984 for (i = 0; i < bw_lf; i++)
8985 dcb_cfg->etscfg.tcbwtable[i]++;
8987 /* assume each tc has the same Transmission Selection Algorithm */
8988 for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
8989 dcb_cfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
8991 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
8992 dcb_cfg->etscfg.prioritytable[i] =
8993 dcb_rx_conf->dcb_tc[i];
8995 /* FW needs one App to configure HW */
8996 dcb_cfg->numapps = I40E_DEFAULT_DCB_APP_NUM;
8997 dcb_cfg->app[0].selector = I40E_APP_SEL_ETHTYPE;
8998 dcb_cfg->app[0].priority = I40E_DEFAULT_DCB_APP_PRIO;
8999 dcb_cfg->app[0].protocolid = I40E_APP_PROTOID_FCOE;
9001 if (dcb_rx_conf->nb_tcs == 0)
9002 *tc_map = 1; /* tc0 only */
9004 *tc_map = RTE_LEN2MASK(dcb_rx_conf->nb_tcs, uint8_t);
9006 if (dev->data->dev_conf.dcb_capability_en & ETH_DCB_PFC_SUPPORT) {
9007 dcb_cfg->pfc.willing = 0;
9008 dcb_cfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
9009 dcb_cfg->pfc.pfcenable = *tc_map;
9015 static enum i40e_status_code
9016 i40e_vsi_update_queue_mapping(struct i40e_vsi *vsi,
9017 struct i40e_aqc_vsi_properties_data *info,
9018 uint8_t enabled_tcmap)
9020 enum i40e_status_code ret;
9021 int i, total_tc = 0;
9022 uint16_t qpnum_per_tc, bsf, qp_idx;
9023 struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(vsi);
9024 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
9025 uint16_t used_queues;
9027 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
9028 if (ret != I40E_SUCCESS)
9031 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
9032 if (enabled_tcmap & (1 << i))
9037 vsi->enabled_tc = enabled_tcmap;
9039 /* different VSI has different queues assigned */
9040 if (vsi->type == I40E_VSI_MAIN)
9041 used_queues = dev_data->nb_rx_queues -
9042 pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
9043 else if (vsi->type == I40E_VSI_VMDQ2)
9044 used_queues = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
9046 PMD_INIT_LOG(ERR, "unsupported VSI type.");
9047 return I40E_ERR_NO_AVAILABLE_VSI;
9050 qpnum_per_tc = used_queues / total_tc;
9051 /* Number of queues per enabled TC */
9052 if (qpnum_per_tc == 0) {
9053 PMD_INIT_LOG(ERR, " number of queues is less that tcs.");
9054 return I40E_ERR_INVALID_QP_ID;
9056 qpnum_per_tc = RTE_MIN(i40e_align_floor(qpnum_per_tc),
9058 bsf = rte_bsf32(qpnum_per_tc);
9061 * Configure TC and queue mapping parameters, for enabled TC,
9062 * allocate qpnum_per_tc queues to this traffic. For disabled TC,
9063 * default queue will serve it.
9066 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
9067 if (vsi->enabled_tc & (1 << i)) {
9068 info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
9069 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
9070 (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
9071 qp_idx += qpnum_per_tc;
9073 info->tc_mapping[i] = 0;
9076 /* Associate queue number with VSI, Keep vsi->nb_qps unchanged */
9077 if (vsi->type == I40E_VSI_SRIOV) {
9078 info->mapping_flags |=
9079 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
9080 for (i = 0; i < vsi->nb_qps; i++)
9081 info->queue_mapping[i] =
9082 rte_cpu_to_le_16(vsi->base_queue + i);
9084 info->mapping_flags |=
9085 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
9086 info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
9088 info->valid_sections |=
9089 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
9091 return I40E_SUCCESS;
9095 * i40e_config_switch_comp_tc - Configure VEB tc setting for given TC map
9096 * @veb: VEB to be configured
9097 * @tc_map: enabled TC bitmap
9099 * Returns 0 on success, negative value on failure
9101 static enum i40e_status_code
9102 i40e_config_switch_comp_tc(struct i40e_veb *veb, uint8_t tc_map)
9104 struct i40e_aqc_configure_switching_comp_bw_config_data veb_bw;
9105 struct i40e_aqc_query_switching_comp_bw_config_resp bw_query;
9106 struct i40e_aqc_query_switching_comp_ets_config_resp ets_query;
9107 struct i40e_hw *hw = I40E_VSI_TO_HW(veb->associate_vsi);
9108 enum i40e_status_code ret = I40E_SUCCESS;
9112 /* Check if enabled_tc is same as existing or new TCs */
9113 if (veb->enabled_tc == tc_map)
9116 /* configure tc bandwidth */
9117 memset(&veb_bw, 0, sizeof(veb_bw));
9118 veb_bw.tc_valid_bits = tc_map;
9119 /* Enable ETS TCs with equal BW Share for now across all VSIs */
9120 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
9121 if (tc_map & BIT_ULL(i))
9122 veb_bw.tc_bw_share_credits[i] = 1;
9124 ret = i40e_aq_config_switch_comp_bw_config(hw, veb->seid,
9127 PMD_INIT_LOG(ERR, "AQ command Config switch_comp BW allocation"
9128 " per TC failed = %d",
9129 hw->aq.asq_last_status);
9133 memset(&ets_query, 0, sizeof(ets_query));
9134 ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
9136 if (ret != I40E_SUCCESS) {
9137 PMD_DRV_LOG(ERR, "Failed to get switch_comp ETS"
9138 " configuration %u", hw->aq.asq_last_status);
9141 memset(&bw_query, 0, sizeof(bw_query));
9142 ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
9144 if (ret != I40E_SUCCESS) {
9145 PMD_DRV_LOG(ERR, "Failed to get switch_comp bandwidth"
9146 " configuration %u", hw->aq.asq_last_status);
9150 /* store and print out BW info */
9151 veb->bw_info.bw_limit = rte_le_to_cpu_16(ets_query.port_bw_limit);
9152 veb->bw_info.bw_max = ets_query.tc_bw_max;
9153 PMD_DRV_LOG(DEBUG, "switch_comp bw limit:%u", veb->bw_info.bw_limit);
9154 PMD_DRV_LOG(DEBUG, "switch_comp max_bw:%u", veb->bw_info.bw_max);
9155 bw_max = rte_le_to_cpu_16(bw_query.tc_bw_max[0]) |
9156 (rte_le_to_cpu_16(bw_query.tc_bw_max[1]) <<
9158 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
9159 veb->bw_info.bw_ets_share_credits[i] =
9160 bw_query.tc_bw_share_credits[i];
9161 veb->bw_info.bw_ets_credits[i] =
9162 rte_le_to_cpu_16(bw_query.tc_bw_limits[i]);
9163 /* 4 bits per TC, 4th bit is reserved */
9164 veb->bw_info.bw_ets_max[i] =
9165 (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
9166 RTE_LEN2MASK(3, uint8_t));
9167 PMD_DRV_LOG(DEBUG, "\tVEB TC%u:share credits %u", i,
9168 veb->bw_info.bw_ets_share_credits[i]);
9169 PMD_DRV_LOG(DEBUG, "\tVEB TC%u:credits %u", i,
9170 veb->bw_info.bw_ets_credits[i]);
9171 PMD_DRV_LOG(DEBUG, "\tVEB TC%u: max credits: %u", i,
9172 veb->bw_info.bw_ets_max[i]);
9175 veb->enabled_tc = tc_map;
9182 * i40e_vsi_config_tc - Configure VSI tc setting for given TC map
9183 * @vsi: VSI to be configured
9184 * @tc_map: enabled TC bitmap
9186 * Returns 0 on success, negative value on failure
9188 static enum i40e_status_code
9189 i40e_vsi_config_tc(struct i40e_vsi *vsi, uint8_t tc_map)
9191 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
9192 struct i40e_vsi_context ctxt;
9193 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
9194 enum i40e_status_code ret = I40E_SUCCESS;
9197 /* Check if enabled_tc is same as existing or new TCs */
9198 if (vsi->enabled_tc == tc_map)
9201 /* configure tc bandwidth */
9202 memset(&bw_data, 0, sizeof(bw_data));
9203 bw_data.tc_valid_bits = tc_map;
9204 /* Enable ETS TCs with equal BW Share for now across all VSIs */
9205 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
9206 if (tc_map & BIT_ULL(i))
9207 bw_data.tc_bw_credits[i] = 1;
9209 ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &bw_data, NULL);
9211 PMD_INIT_LOG(ERR, "AQ command Config VSI BW allocation"
9212 " per TC failed = %d",
9213 hw->aq.asq_last_status);
9216 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
9217 vsi->info.qs_handle[i] = bw_data.qs_handles[i];
9219 /* Update Queue Pairs Mapping for currently enabled UPs */
9220 ctxt.seid = vsi->seid;
9221 ctxt.pf_num = hw->pf_id;
9223 ctxt.uplink_seid = vsi->uplink_seid;
9224 ctxt.info = vsi->info;
9226 ret = i40e_vsi_update_queue_mapping(vsi, &ctxt.info, tc_map);
9230 /* Update the VSI after updating the VSI queue-mapping information */
9231 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
9233 PMD_INIT_LOG(ERR, "Failed to configure "
9234 "TC queue mapping = %d",
9235 hw->aq.asq_last_status);
9238 /* update the local VSI info with updated queue map */
9239 (void)rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
9240 sizeof(vsi->info.tc_mapping));
9241 (void)rte_memcpy(&vsi->info.queue_mapping,
9242 &ctxt.info.queue_mapping,
9243 sizeof(vsi->info.queue_mapping));
9244 vsi->info.mapping_flags = ctxt.info.mapping_flags;
9245 vsi->info.valid_sections = 0;
9247 /* query and update current VSI BW information */
9248 ret = i40e_vsi_get_bw_config(vsi);
9251 "Failed updating vsi bw info, err %s aq_err %s",
9252 i40e_stat_str(hw, ret),
9253 i40e_aq_str(hw, hw->aq.asq_last_status));
9257 vsi->enabled_tc = tc_map;
9264 * i40e_dcb_hw_configure - program the dcb setting to hw
9265 * @pf: pf the configuration is taken on
9266 * @new_cfg: new configuration
9267 * @tc_map: enabled TC bitmap
9269 * Returns 0 on success, negative value on failure
9271 static enum i40e_status_code
9272 i40e_dcb_hw_configure(struct i40e_pf *pf,
9273 struct i40e_dcbx_config *new_cfg,
9276 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9277 struct i40e_dcbx_config *old_cfg = &hw->local_dcbx_config;
9278 struct i40e_vsi *main_vsi = pf->main_vsi;
9279 struct i40e_vsi_list *vsi_list;
9280 enum i40e_status_code ret;
9284 /* Use the FW API if FW > v4.4*/
9285 if (!(((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver >= 4)) ||
9286 (hw->aq.fw_maj_ver >= 5))) {
9287 PMD_INIT_LOG(ERR, "FW < v4.4, can not use FW LLDP API"
9288 " to configure DCB");
9289 return I40E_ERR_FIRMWARE_API_VERSION;
9292 /* Check if need reconfiguration */
9293 if (!memcmp(new_cfg, old_cfg, sizeof(struct i40e_dcbx_config))) {
9294 PMD_INIT_LOG(ERR, "No Change in DCB Config required.");
9295 return I40E_SUCCESS;
9298 /* Copy the new config to the current config */
9299 *old_cfg = *new_cfg;
9300 old_cfg->etsrec = old_cfg->etscfg;
9301 ret = i40e_set_dcb_config(hw);
9304 "Set DCB Config failed, err %s aq_err %s\n",
9305 i40e_stat_str(hw, ret),
9306 i40e_aq_str(hw, hw->aq.asq_last_status));
9309 /* set receive Arbiter to RR mode and ETS scheme by default */
9310 for (i = 0; i <= I40E_PRTDCB_RETSTCC_MAX_INDEX; i++) {
9311 val = I40E_READ_REG(hw, I40E_PRTDCB_RETSTCC(i));
9312 val &= ~(I40E_PRTDCB_RETSTCC_BWSHARE_MASK |
9313 I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK |
9314 I40E_PRTDCB_RETSTCC_ETSTC_SHIFT);
9315 val |= ((uint32_t)old_cfg->etscfg.tcbwtable[i] <<
9316 I40E_PRTDCB_RETSTCC_BWSHARE_SHIFT) &
9317 I40E_PRTDCB_RETSTCC_BWSHARE_MASK;
9318 val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_UPINTC_MODE_SHIFT) &
9319 I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK;
9320 val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_ETSTC_SHIFT) &
9321 I40E_PRTDCB_RETSTCC_ETSTC_MASK;
9322 I40E_WRITE_REG(hw, I40E_PRTDCB_RETSTCC(i), val);
9324 /* get local mib to check whether it is configured correctly */
9326 hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_IEEE;
9327 /* Get Local DCB Config */
9328 i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
9329 &hw->local_dcbx_config);
9331 /* if Veb is created, need to update TC of it at first */
9332 if (main_vsi->veb) {
9333 ret = i40e_config_switch_comp_tc(main_vsi->veb, tc_map);
9335 PMD_INIT_LOG(WARNING,
9336 "Failed configuring TC for VEB seid=%d\n",
9337 main_vsi->veb->seid);
9339 /* Update each VSI */
9340 i40e_vsi_config_tc(main_vsi, tc_map);
9341 if (main_vsi->veb) {
9342 TAILQ_FOREACH(vsi_list, &main_vsi->veb->head, list) {
9343 /* Beside main VSI and VMDQ VSIs, only enable default
9346 if (vsi_list->vsi->type == I40E_VSI_VMDQ2)
9347 ret = i40e_vsi_config_tc(vsi_list->vsi,
9350 ret = i40e_vsi_config_tc(vsi_list->vsi,
9351 I40E_DEFAULT_TCMAP);
9353 PMD_INIT_LOG(WARNING,
9354 "Failed configuring TC for VSI seid=%d\n",
9355 vsi_list->vsi->seid);
9359 return I40E_SUCCESS;
9363 * i40e_dcb_init_configure - initial dcb config
9364 * @dev: device being configured
9365 * @sw_dcb: indicate whether dcb is sw configured or hw offload
9367 * Returns 0 on success, negative value on failure
9370 i40e_dcb_init_configure(struct rte_eth_dev *dev, bool sw_dcb)
9372 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
9373 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
9376 if ((pf->flags & I40E_FLAG_DCB) == 0) {
9377 PMD_INIT_LOG(ERR, "HW doesn't support DCB");
9381 /* DCB initialization:
9382 * Update DCB configuration from the Firmware and configure
9383 * LLDP MIB change event.
9385 if (sw_dcb == TRUE) {
9386 ret = i40e_aq_stop_lldp(hw, TRUE, NULL);
9387 if (ret != I40E_SUCCESS)
9388 PMD_INIT_LOG(DEBUG, "Failed to stop lldp");
9390 ret = i40e_init_dcb(hw);
9391 /* if sw_dcb, lldp agent is stopped, the return from
9392 * i40e_init_dcb we expect is failure with I40E_AQ_RC_EPERM
9395 if (ret != I40E_SUCCESS &&
9396 hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
9397 memset(&hw->local_dcbx_config, 0,
9398 sizeof(struct i40e_dcbx_config));
9399 /* set dcb default configuration */
9400 hw->local_dcbx_config.etscfg.willing = 0;
9401 hw->local_dcbx_config.etscfg.maxtcs = 0;
9402 hw->local_dcbx_config.etscfg.tcbwtable[0] = 100;
9403 hw->local_dcbx_config.etscfg.tsatable[0] =
9405 hw->local_dcbx_config.etsrec =
9406 hw->local_dcbx_config.etscfg;
9407 hw->local_dcbx_config.pfc.willing = 0;
9408 hw->local_dcbx_config.pfc.pfccap =
9409 I40E_MAX_TRAFFIC_CLASS;
9410 /* FW needs one App to configure HW */
9411 hw->local_dcbx_config.numapps = 1;
9412 hw->local_dcbx_config.app[0].selector =
9413 I40E_APP_SEL_ETHTYPE;
9414 hw->local_dcbx_config.app[0].priority = 3;
9415 hw->local_dcbx_config.app[0].protocolid =
9416 I40E_APP_PROTOID_FCOE;
9417 ret = i40e_set_dcb_config(hw);
9419 PMD_INIT_LOG(ERR, "default dcb config fails."
9420 " err = %d, aq_err = %d.", ret,
9421 hw->aq.asq_last_status);
9425 PMD_INIT_LOG(ERR, "DCBX configuration failed, err = %d,"
9426 " aq_err = %d.", ret,
9427 hw->aq.asq_last_status);
9431 ret = i40e_aq_start_lldp(hw, NULL);
9432 if (ret != I40E_SUCCESS)
9433 PMD_INIT_LOG(DEBUG, "Failed to start lldp");
9435 ret = i40e_init_dcb(hw);
9437 if (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED) {
9438 PMD_INIT_LOG(ERR, "HW doesn't support"
9443 PMD_INIT_LOG(ERR, "DCBX configuration failed, err = %d,"
9444 " aq_err = %d.", ret,
9445 hw->aq.asq_last_status);
9453 * i40e_dcb_setup - setup dcb related config
9454 * @dev: device being configured
9456 * Returns 0 on success, negative value on failure
9459 i40e_dcb_setup(struct rte_eth_dev *dev)
9461 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
9462 struct i40e_dcbx_config dcb_cfg;
9466 if ((pf->flags & I40E_FLAG_DCB) == 0) {
9467 PMD_INIT_LOG(ERR, "HW doesn't support DCB");
9471 if (pf->vf_num != 0)
9472 PMD_INIT_LOG(DEBUG, " DCB only works on pf and vmdq vsis.");
9474 ret = i40e_parse_dcb_configure(dev, &dcb_cfg, &tc_map);
9476 PMD_INIT_LOG(ERR, "invalid dcb config");
9479 ret = i40e_dcb_hw_configure(pf, &dcb_cfg, tc_map);
9481 PMD_INIT_LOG(ERR, "dcb sw configure fails");
9489 i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
9490 struct rte_eth_dcb_info *dcb_info)
9492 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
9493 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
9494 struct i40e_vsi *vsi = pf->main_vsi;
9495 struct i40e_dcbx_config *dcb_cfg = &hw->local_dcbx_config;
9496 uint16_t bsf, tc_mapping;
9499 if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_DCB_FLAG)
9500 dcb_info->nb_tcs = rte_bsf32(vsi->enabled_tc + 1);
9502 dcb_info->nb_tcs = 1;
9503 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
9504 dcb_info->prio_tc[i] = dcb_cfg->etscfg.prioritytable[i];
9505 for (i = 0; i < dcb_info->nb_tcs; i++)
9506 dcb_info->tc_bws[i] = dcb_cfg->etscfg.tcbwtable[i];
9508 /* get queue mapping if vmdq is disabled */
9509 if (!pf->nb_cfg_vmdq_vsi) {
9510 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
9511 if (!(vsi->enabled_tc & (1 << i)))
9513 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
9514 dcb_info->tc_queue.tc_rxq[j][i].base =
9515 (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
9516 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
9517 dcb_info->tc_queue.tc_txq[j][i].base =
9518 dcb_info->tc_queue.tc_rxq[j][i].base;
9519 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
9520 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
9521 dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
9522 dcb_info->tc_queue.tc_txq[j][i].nb_queue =
9523 dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
9528 /* get queue mapping if vmdq is enabled */
9530 vsi = pf->vmdq[j].vsi;
9531 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
9532 if (!(vsi->enabled_tc & (1 << i)))
9534 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
9535 dcb_info->tc_queue.tc_rxq[j][i].base =
9536 (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
9537 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
9538 dcb_info->tc_queue.tc_txq[j][i].base =
9539 dcb_info->tc_queue.tc_rxq[j][i].base;
9540 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
9541 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
9542 dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
9543 dcb_info->tc_queue.tc_txq[j][i].nb_queue =
9544 dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
9547 } while (j < RTE_MIN(pf->nb_cfg_vmdq_vsi, ETH_MAX_VMDQ_POOL));
9552 i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
9554 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
9555 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
9557 i40e_calc_itr_interval(RTE_LIBRTE_I40E_ITR_INTERVAL);
9560 msix_intr = intr_handle->intr_vec[queue_id];
9561 if (msix_intr == I40E_MISC_VEC_ID)
9562 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
9563 I40E_PFINT_DYN_CTLN_INTENA_MASK |
9564 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
9565 (0 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT) |
9567 I40E_PFINT_DYN_CTLN_INTERVAL_SHIFT));
9570 I40E_PFINT_DYN_CTLN(msix_intr -
9572 I40E_PFINT_DYN_CTLN_INTENA_MASK |
9573 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
9574 (0 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT) |
9576 I40E_PFINT_DYN_CTLN_INTERVAL_SHIFT));
9578 I40E_WRITE_FLUSH(hw);
9579 rte_intr_enable(&dev->pci_dev->intr_handle);
9585 i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
9587 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
9588 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
9591 msix_intr = intr_handle->intr_vec[queue_id];
9592 if (msix_intr == I40E_MISC_VEC_ID)
9593 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0, 0);
9596 I40E_PFINT_DYN_CTLN(msix_intr -
9599 I40E_WRITE_FLUSH(hw);
9604 static int i40e_get_regs(struct rte_eth_dev *dev,
9605 struct rte_dev_reg_info *regs)
9607 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
9608 uint32_t *ptr_data = regs->data;
9609 uint32_t reg_idx, arr_idx, arr_idx2, reg_offset;
9610 const struct i40e_reg_info *reg_info;
9612 if (ptr_data == NULL) {
9613 regs->length = I40E_GLGEN_STAT_CLEAR + 4;
9614 regs->width = sizeof(uint32_t);
9618 /* The first few registers have to be read using AQ operations */
9620 while (i40e_regs_adminq[reg_idx].name) {
9621 reg_info = &i40e_regs_adminq[reg_idx++];
9622 for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
9624 arr_idx2 <= reg_info->count2;
9626 reg_offset = arr_idx * reg_info->stride1 +
9627 arr_idx2 * reg_info->stride2;
9628 reg_offset += reg_info->base_addr;
9629 ptr_data[reg_offset >> 2] =
9630 i40e_read_rx_ctl(hw, reg_offset);
9634 /* The remaining registers can be read using primitives */
9636 while (i40e_regs_others[reg_idx].name) {
9637 reg_info = &i40e_regs_others[reg_idx++];
9638 for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
9640 arr_idx2 <= reg_info->count2;
9642 reg_offset = arr_idx * reg_info->stride1 +
9643 arr_idx2 * reg_info->stride2;
9644 reg_offset += reg_info->base_addr;
9645 ptr_data[reg_offset >> 2] =
9646 I40E_READ_REG(hw, reg_offset);
9653 static int i40e_get_eeprom_length(struct rte_eth_dev *dev)
9655 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
9657 /* Convert word count to byte count */
9658 return hw->nvm.sr_size << 1;
9661 static int i40e_get_eeprom(struct rte_eth_dev *dev,
9662 struct rte_dev_eeprom_info *eeprom)
9664 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
9665 uint16_t *data = eeprom->data;
9666 uint16_t offset, length, cnt_words;
9669 offset = eeprom->offset >> 1;
9670 length = eeprom->length >> 1;
9673 if (offset > hw->nvm.sr_size ||
9674 offset + length > hw->nvm.sr_size) {
9675 PMD_DRV_LOG(ERR, "Requested EEPROM bytes out of range.");
9679 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
9681 ret_code = i40e_read_nvm_buffer(hw, offset, &cnt_words, data);
9682 if (ret_code != I40E_SUCCESS || cnt_words != length) {
9683 PMD_DRV_LOG(ERR, "EEPROM read failed.");
9690 static void i40e_set_default_mac_addr(struct rte_eth_dev *dev,
9691 struct ether_addr *mac_addr)
9693 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
9695 if (!is_valid_assigned_ether_addr(mac_addr)) {
9696 PMD_DRV_LOG(ERR, "Tried to set invalid MAC address.");
9700 /* Flags: 0x3 updates port address */
9701 i40e_aq_mac_address_write(hw, 0x3, mac_addr->addr_bytes, NULL);
9705 i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
9707 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
9708 struct rte_eth_dev_data *dev_data = pf->dev_data;
9709 uint32_t frame_size = mtu + ETHER_HDR_LEN
9710 + ETHER_CRC_LEN + I40E_VLAN_TAG_SIZE;
9713 /* check if mtu is within the allowed range */
9714 if ((mtu < ETHER_MIN_MTU) || (frame_size > I40E_FRAME_SIZE_MAX))
9717 /* mtu setting is forbidden if port is start */
9718 if (dev_data->dev_started) {
9720 "port %d must be stopped before configuration\n",
9725 if (frame_size > ETHER_MAX_LEN)
9726 dev_data->dev_conf.rxmode.jumbo_frame = 1;
9728 dev_data->dev_conf.rxmode.jumbo_frame = 0;
9730 dev_data->dev_conf.rxmode.max_rx_pkt_len = frame_size;