4 * Copyright(c) 2010-2015 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.
34 #include <sys/queue.h>
44 #include <rte_string_fns.h>
46 #include <rte_ether.h>
47 #include <rte_ethdev.h>
48 #include <rte_memzone.h>
49 #include <rte_malloc.h>
50 #include <rte_memcpy.h>
51 #include <rte_alarm.h>
53 #include <rte_eth_ctrl.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 I40E_CLEAR_PXE_WAIT_MS 200
68 /* Maximun number of capability elements */
69 #define I40E_MAX_CAP_ELE_NUM 128
71 /* Wait count and inteval */
72 #define I40E_CHK_Q_ENA_COUNT 1000
73 #define I40E_CHK_Q_ENA_INTERVAL_US 1000
75 /* Maximun number of VSI */
76 #define I40E_MAX_NUM_VSIS (384UL)
78 #define I40E_PRE_TX_Q_CFG_WAIT_US 10 /* 10 us */
80 /* Flow control default timer */
81 #define I40E_DEFAULT_PAUSE_TIME 0xFFFFU
83 /* Flow control default high water */
84 #define I40E_DEFAULT_HIGH_WATER (0x1C40/1024)
86 /* Flow control default low water */
87 #define I40E_DEFAULT_LOW_WATER (0x1A40/1024)
89 /* Flow control enable fwd bit */
90 #define I40E_PRTMAC_FWD_CTRL 0x00000001
92 /* Receive Packet Buffer size */
93 #define I40E_RXPBSIZE (968 * 1024)
96 #define I40E_KILOSHIFT 10
98 /* Receive Average Packet Size in Byte*/
99 #define I40E_PACKET_AVERAGE_SIZE 128
101 /* Mask of PF interrupt causes */
102 #define I40E_PFINT_ICR0_ENA_MASK ( \
103 I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | \
104 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | \
105 I40E_PFINT_ICR0_ENA_GRST_MASK | \
106 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | \
107 I40E_PFINT_ICR0_ENA_STORM_DETECT_MASK | \
108 I40E_PFINT_ICR0_ENA_LINK_STAT_CHANGE_MASK | \
109 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | \
110 I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK | \
111 I40E_PFINT_ICR0_ENA_VFLR_MASK | \
112 I40E_PFINT_ICR0_ENA_ADMINQ_MASK)
114 #define I40E_FLOW_TYPES ( \
115 (1UL << RTE_ETH_FLOW_FRAG_IPV4) | \
116 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_TCP) | \
117 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_UDP) | \
118 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_SCTP) | \
119 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_OTHER) | \
120 (1UL << RTE_ETH_FLOW_FRAG_IPV6) | \
121 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_TCP) | \
122 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_UDP) | \
123 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_SCTP) | \
124 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_OTHER) | \
125 (1UL << RTE_ETH_FLOW_L2_PAYLOAD))
127 /* Additional timesync values. */
128 #define I40E_PTP_40GB_INCVAL 0x0199999999ULL
129 #define I40E_PTP_10GB_INCVAL 0x0333333333ULL
130 #define I40E_PTP_1GB_INCVAL 0x2000000000ULL
131 #define I40E_PRTTSYN_TSYNENA 0x80000000
132 #define I40E_PRTTSYN_TSYNTYPE 0x0e000000
133 #define I40E_CYCLECOUNTER_MASK 0xffffffffffffffffULL
135 #define I40E_MAX_PERCENT 100
136 #define I40E_DEFAULT_DCB_APP_NUM 1
137 #define I40E_DEFAULT_DCB_APP_PRIO 3
139 #define I40E_INSET_NONE 0x00000000000000000ULL
142 #define I40E_INSET_DMAC 0x0000000000000001ULL
143 #define I40E_INSET_SMAC 0x0000000000000002ULL
144 #define I40E_INSET_VLAN_OUTER 0x0000000000000004ULL
145 #define I40E_INSET_VLAN_INNER 0x0000000000000008ULL
146 #define I40E_INSET_VLAN_TUNNEL 0x0000000000000010ULL
149 #define I40E_INSET_IPV4_SRC 0x0000000000000100ULL
150 #define I40E_INSET_IPV4_DST 0x0000000000000200ULL
151 #define I40E_INSET_IPV6_SRC 0x0000000000000400ULL
152 #define I40E_INSET_IPV6_DST 0x0000000000000800ULL
153 #define I40E_INSET_SRC_PORT 0x0000000000001000ULL
154 #define I40E_INSET_DST_PORT 0x0000000000002000ULL
155 #define I40E_INSET_SCTP_VT 0x0000000000004000ULL
157 /* bit 16 ~ bit 31 */
158 #define I40E_INSET_IPV4_TOS 0x0000000000010000ULL
159 #define I40E_INSET_IPV4_PROTO 0x0000000000020000ULL
160 #define I40E_INSET_IPV4_TTL 0x0000000000040000ULL
161 #define I40E_INSET_IPV6_TC 0x0000000000080000ULL
162 #define I40E_INSET_IPV6_FLOW 0x0000000000100000ULL
163 #define I40E_INSET_IPV6_NEXT_HDR 0x0000000000200000ULL
164 #define I40E_INSET_IPV6_HOP_LIMIT 0x0000000000400000ULL
165 #define I40E_INSET_TCP_FLAGS 0x0000000000800000ULL
167 /* bit 32 ~ bit 47, tunnel fields */
168 #define I40E_INSET_TUNNEL_IPV4_DST 0x0000000100000000ULL
169 #define I40E_INSET_TUNNEL_IPV6_DST 0x0000000200000000ULL
170 #define I40E_INSET_TUNNEL_DMAC 0x0000000400000000ULL
171 #define I40E_INSET_TUNNEL_SRC_PORT 0x0000000800000000ULL
172 #define I40E_INSET_TUNNEL_DST_PORT 0x0000001000000000ULL
173 #define I40E_INSET_TUNNEL_ID 0x0000002000000000ULL
175 /* bit 48 ~ bit 55 */
176 #define I40E_INSET_LAST_ETHER_TYPE 0x0001000000000000ULL
178 /* bit 56 ~ bit 63, Flex Payload */
179 #define I40E_INSET_FLEX_PAYLOAD_W1 0x0100000000000000ULL
180 #define I40E_INSET_FLEX_PAYLOAD_W2 0x0200000000000000ULL
181 #define I40E_INSET_FLEX_PAYLOAD_W3 0x0400000000000000ULL
182 #define I40E_INSET_FLEX_PAYLOAD_W4 0x0800000000000000ULL
183 #define I40E_INSET_FLEX_PAYLOAD_W5 0x1000000000000000ULL
184 #define I40E_INSET_FLEX_PAYLOAD_W6 0x2000000000000000ULL
185 #define I40E_INSET_FLEX_PAYLOAD_W7 0x4000000000000000ULL
186 #define I40E_INSET_FLEX_PAYLOAD_W8 0x8000000000000000ULL
187 #define I40E_INSET_FLEX_PAYLOAD \
188 (I40E_INSET_FLEX_PAYLOAD_W1 | I40E_INSET_FLEX_PAYLOAD_W2 | \
189 I40E_INSET_FLEX_PAYLOAD_W3 | I40E_INSET_FLEX_PAYLOAD_W4 | \
190 I40E_INSET_FLEX_PAYLOAD_W5 | I40E_INSET_FLEX_PAYLOAD_W6 | \
191 I40E_INSET_FLEX_PAYLOAD_W7 | I40E_INSET_FLEX_PAYLOAD_W8)
194 * Below are values for writing un-exposed registers suggested
197 /* Destination MAC address */
198 #define I40E_REG_INSET_L2_DMAC 0xE000000000000000ULL
199 /* Source MAC address */
200 #define I40E_REG_INSET_L2_SMAC 0x1C00000000000000ULL
201 /* Outer (S-Tag) VLAN tag in the outer L2 header */
202 #define I40E_REG_INSET_L2_OUTER_VLAN 0x0200000000000000ULL
203 /* Inner (C-Tag) or single VLAN tag in the outer L2 header */
204 #define I40E_REG_INSET_L2_INNER_VLAN 0x0080000000000000ULL
205 /* Single VLAN tag in the inner L2 header */
206 #define I40E_REG_INSET_TUNNEL_VLAN 0x0100000000000000ULL
207 /* Source IPv4 address */
208 #define I40E_REG_INSET_L3_SRC_IP4 0x0001800000000000ULL
209 /* Destination IPv4 address */
210 #define I40E_REG_INSET_L3_DST_IP4 0x0000001800000000ULL
211 /* IPv4 Type of Service (TOS) */
212 #define I40E_REG_INSET_L3_IP4_TOS 0x0040000000000000ULL
214 #define I40E_REG_INSET_L3_IP4_PROTO 0x0004000000000000ULL
215 /* IPv4 Time to Live */
216 #define I40E_REG_INSET_L3_IP4_TTL 0x0004000000000000ULL
217 /* Source IPv6 address */
218 #define I40E_REG_INSET_L3_SRC_IP6 0x0007F80000000000ULL
219 /* Destination IPv6 address */
220 #define I40E_REG_INSET_L3_DST_IP6 0x000007F800000000ULL
221 /* IPv6 Traffic Class (TC) */
222 #define I40E_REG_INSET_L3_IP6_TC 0x0040000000000000ULL
223 /* IPv6 Next Header */
224 #define I40E_REG_INSET_L3_IP6_NEXT_HDR 0x0008000000000000ULL
226 #define I40E_REG_INSET_L3_IP6_HOP_LIMIT 0x0008000000000000ULL
228 #define I40E_REG_INSET_L4_SRC_PORT 0x0000000400000000ULL
229 /* Destination L4 port */
230 #define I40E_REG_INSET_L4_DST_PORT 0x0000000200000000ULL
231 /* SCTP verification tag */
232 #define I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG 0x0000000180000000ULL
233 /* Inner destination MAC address (MAC-in-UDP/MAC-in-GRE)*/
234 #define I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC 0x0000000001C00000ULL
235 /* Source port of tunneling UDP */
236 #define I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT 0x0000000000200000ULL
237 /* Destination port of tunneling UDP */
238 #define I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT 0x0000000000100000ULL
239 /* UDP Tunneling ID, NVGRE/GRE key */
240 #define I40E_REG_INSET_TUNNEL_ID 0x00000000000C0000ULL
241 /* Last ether type */
242 #define I40E_REG_INSET_LAST_ETHER_TYPE 0x0000000000004000ULL
243 /* Tunneling outer destination IPv4 address */
244 #define I40E_REG_INSET_TUNNEL_L3_DST_IP4 0x00000000000000C0ULL
245 /* Tunneling outer destination IPv6 address */
246 #define I40E_REG_INSET_TUNNEL_L3_DST_IP6 0x0000000000003FC0ULL
247 /* 1st word of flex payload */
248 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD1 0x0000000000002000ULL
249 /* 2nd word of flex payload */
250 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD2 0x0000000000001000ULL
251 /* 3rd word of flex payload */
252 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD3 0x0000000000000800ULL
253 /* 4th word of flex payload */
254 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD4 0x0000000000000400ULL
255 /* 5th word of flex payload */
256 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD5 0x0000000000000200ULL
257 /* 6th word of flex payload */
258 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD6 0x0000000000000100ULL
259 /* 7th word of flex payload */
260 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD7 0x0000000000000080ULL
261 /* 8th word of flex payload */
262 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD8 0x0000000000000040ULL
263 /* all 8 words flex payload */
264 #define I40E_REG_INSET_FLEX_PAYLOAD_WORDS 0x0000000000003FC0ULL
265 #define I40E_REG_INSET_MASK_DEFAULT 0x0000000000000000ULL
267 #define I40E_TRANSLATE_INSET 0
268 #define I40E_TRANSLATE_REG 1
270 #define I40E_INSET_IPV4_TOS_MASK 0x0009FF00UL
271 #define I40E_INSET_IPv4_TTL_MASK 0x000D00FFUL
272 #define I40E_INSET_IPV4_PROTO_MASK 0x000DFF00UL
273 #define I40E_INSET_IPV6_TC_MASK 0x0009F00FUL
274 #define I40E_INSET_IPV6_HOP_LIMIT_MASK 0x000CFF00UL
275 #define I40E_INSET_IPV6_NEXT_HDR_MASK 0x000C00FFUL
277 #define I40E_GL_SWT_L2TAGCTRL(_i) (0x001C0A70 + ((_i) * 4))
278 #define I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT 16
279 #define I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_MASK \
280 I40E_MASK(0xFFFF, I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT)
282 /* PCI offset for querying capability */
283 #define PCI_DEV_CAP_REG 0xA4
284 /* PCI offset for enabling/disabling Extended Tag */
285 #define PCI_DEV_CTRL_REG 0xA8
286 /* Bit mask of Extended Tag capability */
287 #define PCI_DEV_CAP_EXT_TAG_MASK 0x20
288 /* Bit shift of Extended Tag enable/disable */
289 #define PCI_DEV_CTRL_EXT_TAG_SHIFT 8
290 /* Bit mask of Extended Tag enable/disable */
291 #define PCI_DEV_CTRL_EXT_TAG_MASK (1 << PCI_DEV_CTRL_EXT_TAG_SHIFT)
293 static int eth_i40e_dev_init(struct rte_eth_dev *eth_dev);
294 static int eth_i40e_dev_uninit(struct rte_eth_dev *eth_dev);
295 static int i40e_dev_configure(struct rte_eth_dev *dev);
296 static int i40e_dev_start(struct rte_eth_dev *dev);
297 static void i40e_dev_stop(struct rte_eth_dev *dev);
298 static void i40e_dev_close(struct rte_eth_dev *dev);
299 static void i40e_dev_promiscuous_enable(struct rte_eth_dev *dev);
300 static void i40e_dev_promiscuous_disable(struct rte_eth_dev *dev);
301 static void i40e_dev_allmulticast_enable(struct rte_eth_dev *dev);
302 static void i40e_dev_allmulticast_disable(struct rte_eth_dev *dev);
303 static int i40e_dev_set_link_up(struct rte_eth_dev *dev);
304 static int i40e_dev_set_link_down(struct rte_eth_dev *dev);
305 static void i40e_dev_stats_get(struct rte_eth_dev *dev,
306 struct rte_eth_stats *stats);
307 static int i40e_dev_xstats_get(struct rte_eth_dev *dev,
308 struct rte_eth_xstats *xstats, unsigned n);
309 static void i40e_dev_stats_reset(struct rte_eth_dev *dev);
310 static int i40e_dev_queue_stats_mapping_set(struct rte_eth_dev *dev,
314 static void i40e_dev_info_get(struct rte_eth_dev *dev,
315 struct rte_eth_dev_info *dev_info);
316 static int i40e_vlan_filter_set(struct rte_eth_dev *dev,
319 static int i40e_vlan_tpid_set(struct rte_eth_dev *dev,
320 enum rte_vlan_type vlan_type,
322 static void i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask);
323 static void i40e_vlan_strip_queue_set(struct rte_eth_dev *dev,
326 static int i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on);
327 static int i40e_dev_led_on(struct rte_eth_dev *dev);
328 static int i40e_dev_led_off(struct rte_eth_dev *dev);
329 static int i40e_flow_ctrl_get(struct rte_eth_dev *dev,
330 struct rte_eth_fc_conf *fc_conf);
331 static int i40e_flow_ctrl_set(struct rte_eth_dev *dev,
332 struct rte_eth_fc_conf *fc_conf);
333 static int i40e_priority_flow_ctrl_set(struct rte_eth_dev *dev,
334 struct rte_eth_pfc_conf *pfc_conf);
335 static void i40e_macaddr_add(struct rte_eth_dev *dev,
336 struct ether_addr *mac_addr,
339 static void i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index);
340 static int i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
341 struct rte_eth_rss_reta_entry64 *reta_conf,
343 static int i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
344 struct rte_eth_rss_reta_entry64 *reta_conf,
347 static int i40e_get_cap(struct i40e_hw *hw);
348 static int i40e_pf_parameter_init(struct rte_eth_dev *dev);
349 static int i40e_pf_setup(struct i40e_pf *pf);
350 static int i40e_dev_rxtx_init(struct i40e_pf *pf);
351 static int i40e_vmdq_setup(struct rte_eth_dev *dev);
352 static int i40e_dcb_init_configure(struct rte_eth_dev *dev, bool sw_dcb);
353 static int i40e_dcb_setup(struct rte_eth_dev *dev);
354 static void i40e_stat_update_32(struct i40e_hw *hw, uint32_t reg,
355 bool offset_loaded, uint64_t *offset, uint64_t *stat);
356 static void i40e_stat_update_48(struct i40e_hw *hw,
362 static void i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue);
363 static void i40e_dev_interrupt_handler(
364 __rte_unused struct rte_intr_handle *handle, void *param);
365 static int i40e_res_pool_init(struct i40e_res_pool_info *pool,
366 uint32_t base, uint32_t num);
367 static void i40e_res_pool_destroy(struct i40e_res_pool_info *pool);
368 static int i40e_res_pool_free(struct i40e_res_pool_info *pool,
370 static int i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
372 static int i40e_dev_init_vlan(struct rte_eth_dev *dev);
373 static int i40e_veb_release(struct i40e_veb *veb);
374 static struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf,
375 struct i40e_vsi *vsi);
376 static int i40e_pf_config_mq_rx(struct i40e_pf *pf);
377 static int i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on);
378 static inline int i40e_find_all_vlan_for_mac(struct i40e_vsi *vsi,
379 struct i40e_macvlan_filter *mv_f,
381 struct ether_addr *addr);
382 static inline int i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
383 struct i40e_macvlan_filter *mv_f,
386 static int i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi);
387 static int i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
388 struct rte_eth_rss_conf *rss_conf);
389 static int i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
390 struct rte_eth_rss_conf *rss_conf);
391 static int i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
392 struct rte_eth_udp_tunnel *udp_tunnel);
393 static int i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
394 struct rte_eth_udp_tunnel *udp_tunnel);
395 static void i40e_filter_input_set_init(struct i40e_pf *pf);
396 static int i40e_ethertype_filter_set(struct i40e_pf *pf,
397 struct rte_eth_ethertype_filter *filter,
399 static int i40e_ethertype_filter_handle(struct rte_eth_dev *dev,
400 enum rte_filter_op filter_op,
402 static int i40e_dev_filter_ctrl(struct rte_eth_dev *dev,
403 enum rte_filter_type filter_type,
404 enum rte_filter_op filter_op,
406 static int i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
407 struct rte_eth_dcb_info *dcb_info);
408 static void i40e_configure_registers(struct i40e_hw *hw);
409 static void i40e_hw_init(struct rte_eth_dev *dev);
410 static int i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi);
411 static int i40e_mirror_rule_set(struct rte_eth_dev *dev,
412 struct rte_eth_mirror_conf *mirror_conf,
413 uint8_t sw_id, uint8_t on);
414 static int i40e_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t sw_id);
416 static int i40e_timesync_enable(struct rte_eth_dev *dev);
417 static int i40e_timesync_disable(struct rte_eth_dev *dev);
418 static int i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
419 struct timespec *timestamp,
421 static int i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
422 struct timespec *timestamp);
423 static void i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw);
425 static int i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
427 static int i40e_timesync_read_time(struct rte_eth_dev *dev,
428 struct timespec *timestamp);
429 static int i40e_timesync_write_time(struct rte_eth_dev *dev,
430 const struct timespec *timestamp);
432 static int i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
434 static int i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
437 static int i40e_get_reg_length(struct rte_eth_dev *dev);
439 static int i40e_get_regs(struct rte_eth_dev *dev,
440 struct rte_dev_reg_info *regs);
442 static int i40e_get_eeprom_length(struct rte_eth_dev *dev);
444 static int i40e_get_eeprom(struct rte_eth_dev *dev,
445 struct rte_dev_eeprom_info *eeprom);
447 static void i40e_set_default_mac_addr(struct rte_eth_dev *dev,
448 struct ether_addr *mac_addr);
450 static const struct rte_pci_id pci_id_i40e_map[] = {
451 #define RTE_PCI_DEV_ID_DECL_I40E(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
452 #include "rte_pci_dev_ids.h"
453 { .vendor_id = 0, /* sentinel */ },
456 static const struct eth_dev_ops i40e_eth_dev_ops = {
457 .dev_configure = i40e_dev_configure,
458 .dev_start = i40e_dev_start,
459 .dev_stop = i40e_dev_stop,
460 .dev_close = i40e_dev_close,
461 .promiscuous_enable = i40e_dev_promiscuous_enable,
462 .promiscuous_disable = i40e_dev_promiscuous_disable,
463 .allmulticast_enable = i40e_dev_allmulticast_enable,
464 .allmulticast_disable = i40e_dev_allmulticast_disable,
465 .dev_set_link_up = i40e_dev_set_link_up,
466 .dev_set_link_down = i40e_dev_set_link_down,
467 .link_update = i40e_dev_link_update,
468 .stats_get = i40e_dev_stats_get,
469 .xstats_get = i40e_dev_xstats_get,
470 .stats_reset = i40e_dev_stats_reset,
471 .xstats_reset = i40e_dev_stats_reset,
472 .queue_stats_mapping_set = i40e_dev_queue_stats_mapping_set,
473 .dev_infos_get = i40e_dev_info_get,
474 .dev_supported_ptypes_get = i40e_dev_supported_ptypes_get,
475 .vlan_filter_set = i40e_vlan_filter_set,
476 .vlan_tpid_set = i40e_vlan_tpid_set,
477 .vlan_offload_set = i40e_vlan_offload_set,
478 .vlan_strip_queue_set = i40e_vlan_strip_queue_set,
479 .vlan_pvid_set = i40e_vlan_pvid_set,
480 .rx_queue_start = i40e_dev_rx_queue_start,
481 .rx_queue_stop = i40e_dev_rx_queue_stop,
482 .tx_queue_start = i40e_dev_tx_queue_start,
483 .tx_queue_stop = i40e_dev_tx_queue_stop,
484 .rx_queue_setup = i40e_dev_rx_queue_setup,
485 .rx_queue_intr_enable = i40e_dev_rx_queue_intr_enable,
486 .rx_queue_intr_disable = i40e_dev_rx_queue_intr_disable,
487 .rx_queue_release = i40e_dev_rx_queue_release,
488 .rx_queue_count = i40e_dev_rx_queue_count,
489 .rx_descriptor_done = i40e_dev_rx_descriptor_done,
490 .tx_queue_setup = i40e_dev_tx_queue_setup,
491 .tx_queue_release = i40e_dev_tx_queue_release,
492 .dev_led_on = i40e_dev_led_on,
493 .dev_led_off = i40e_dev_led_off,
494 .flow_ctrl_get = i40e_flow_ctrl_get,
495 .flow_ctrl_set = i40e_flow_ctrl_set,
496 .priority_flow_ctrl_set = i40e_priority_flow_ctrl_set,
497 .mac_addr_add = i40e_macaddr_add,
498 .mac_addr_remove = i40e_macaddr_remove,
499 .reta_update = i40e_dev_rss_reta_update,
500 .reta_query = i40e_dev_rss_reta_query,
501 .rss_hash_update = i40e_dev_rss_hash_update,
502 .rss_hash_conf_get = i40e_dev_rss_hash_conf_get,
503 .udp_tunnel_port_add = i40e_dev_udp_tunnel_port_add,
504 .udp_tunnel_port_del = i40e_dev_udp_tunnel_port_del,
505 .filter_ctrl = i40e_dev_filter_ctrl,
506 .rxq_info_get = i40e_rxq_info_get,
507 .txq_info_get = i40e_txq_info_get,
508 .mirror_rule_set = i40e_mirror_rule_set,
509 .mirror_rule_reset = i40e_mirror_rule_reset,
510 .timesync_enable = i40e_timesync_enable,
511 .timesync_disable = i40e_timesync_disable,
512 .timesync_read_rx_timestamp = i40e_timesync_read_rx_timestamp,
513 .timesync_read_tx_timestamp = i40e_timesync_read_tx_timestamp,
514 .get_dcb_info = i40e_dev_get_dcb_info,
515 .timesync_adjust_time = i40e_timesync_adjust_time,
516 .timesync_read_time = i40e_timesync_read_time,
517 .timesync_write_time = i40e_timesync_write_time,
518 .get_reg_length = i40e_get_reg_length,
519 .get_reg = i40e_get_regs,
520 .get_eeprom_length = i40e_get_eeprom_length,
521 .get_eeprom = i40e_get_eeprom,
522 .mac_addr_set = i40e_set_default_mac_addr,
525 /* store statistics names and its offset in stats structure */
526 struct rte_i40e_xstats_name_off {
527 char name[RTE_ETH_XSTATS_NAME_SIZE];
531 static const struct rte_i40e_xstats_name_off rte_i40e_stats_strings[] = {
532 {"rx_unicast_packets", offsetof(struct i40e_eth_stats, rx_unicast)},
533 {"rx_multicast_packets", offsetof(struct i40e_eth_stats, rx_multicast)},
534 {"rx_broadcast_packets", offsetof(struct i40e_eth_stats, rx_broadcast)},
535 {"rx_dropped", offsetof(struct i40e_eth_stats, rx_discards)},
536 {"rx_unknown_protocol_packets", offsetof(struct i40e_eth_stats,
537 rx_unknown_protocol)},
538 {"tx_unicast_packets", offsetof(struct i40e_eth_stats, tx_unicast)},
539 {"tx_multicast_packets", offsetof(struct i40e_eth_stats, tx_multicast)},
540 {"tx_broadcast_packets", offsetof(struct i40e_eth_stats, tx_broadcast)},
541 {"tx_dropped", offsetof(struct i40e_eth_stats, tx_discards)},
544 #define I40E_NB_ETH_XSTATS (sizeof(rte_i40e_stats_strings) / \
545 sizeof(rte_i40e_stats_strings[0]))
547 static const struct rte_i40e_xstats_name_off rte_i40e_hw_port_strings[] = {
548 {"tx_link_down_dropped", offsetof(struct i40e_hw_port_stats,
549 tx_dropped_link_down)},
550 {"rx_crc_errors", offsetof(struct i40e_hw_port_stats, crc_errors)},
551 {"rx_illegal_byte_errors", offsetof(struct i40e_hw_port_stats,
553 {"rx_error_bytes", offsetof(struct i40e_hw_port_stats, error_bytes)},
554 {"mac_local_errors", offsetof(struct i40e_hw_port_stats,
556 {"mac_remote_errors", offsetof(struct i40e_hw_port_stats,
558 {"rx_length_errors", offsetof(struct i40e_hw_port_stats,
560 {"tx_xon_packets", offsetof(struct i40e_hw_port_stats, link_xon_tx)},
561 {"rx_xon_packets", offsetof(struct i40e_hw_port_stats, link_xon_rx)},
562 {"tx_xoff_packets", offsetof(struct i40e_hw_port_stats, link_xoff_tx)},
563 {"rx_xoff_packets", offsetof(struct i40e_hw_port_stats, link_xoff_rx)},
564 {"rx_size_64_packets", offsetof(struct i40e_hw_port_stats, rx_size_64)},
565 {"rx_size_65_to_127_packets", offsetof(struct i40e_hw_port_stats,
567 {"rx_size_128_to_255_packets", offsetof(struct i40e_hw_port_stats,
569 {"rx_size_256_to_511_packets", offsetof(struct i40e_hw_port_stats,
571 {"rx_size_512_to_1023_packets", offsetof(struct i40e_hw_port_stats,
573 {"rx_size_1024_to_1522_packets", offsetof(struct i40e_hw_port_stats,
575 {"rx_size_1523_to_max_packets", offsetof(struct i40e_hw_port_stats,
577 {"rx_undersized_errors", offsetof(struct i40e_hw_port_stats,
579 {"rx_oversize_errors", offsetof(struct i40e_hw_port_stats,
581 {"rx_mac_short_dropped", offsetof(struct i40e_hw_port_stats,
582 mac_short_packet_dropped)},
583 {"rx_fragmented_errors", offsetof(struct i40e_hw_port_stats,
585 {"rx_jabber_errors", offsetof(struct i40e_hw_port_stats, rx_jabber)},
586 {"tx_size_64_packets", offsetof(struct i40e_hw_port_stats, tx_size_64)},
587 {"tx_size_65_to_127_packets", offsetof(struct i40e_hw_port_stats,
589 {"tx_size_128_to_255_packets", offsetof(struct i40e_hw_port_stats,
591 {"tx_size_256_to_511_packets", offsetof(struct i40e_hw_port_stats,
593 {"tx_size_512_to_1023_packets", offsetof(struct i40e_hw_port_stats,
595 {"tx_size_1024_to_1522_packets", offsetof(struct i40e_hw_port_stats,
597 {"tx_size_1523_to_max_packets", offsetof(struct i40e_hw_port_stats,
599 {"rx_flow_director_atr_match_packets",
600 offsetof(struct i40e_hw_port_stats, fd_atr_match)},
601 {"rx_flow_director_sb_match_packets",
602 offsetof(struct i40e_hw_port_stats, fd_sb_match)},
603 {"tx_low_power_idle_status", offsetof(struct i40e_hw_port_stats,
605 {"rx_low_power_idle_status", offsetof(struct i40e_hw_port_stats,
607 {"tx_low_power_idle_count", offsetof(struct i40e_hw_port_stats,
609 {"rx_low_power_idle_count", offsetof(struct i40e_hw_port_stats,
613 #define I40E_NB_HW_PORT_XSTATS (sizeof(rte_i40e_hw_port_strings) / \
614 sizeof(rte_i40e_hw_port_strings[0]))
616 static const struct rte_i40e_xstats_name_off rte_i40e_rxq_prio_strings[] = {
617 {"xon_packets", offsetof(struct i40e_hw_port_stats,
619 {"xoff_packets", offsetof(struct i40e_hw_port_stats,
623 #define I40E_NB_RXQ_PRIO_XSTATS (sizeof(rte_i40e_rxq_prio_strings) / \
624 sizeof(rte_i40e_rxq_prio_strings[0]))
626 static const struct rte_i40e_xstats_name_off rte_i40e_txq_prio_strings[] = {
627 {"xon_packets", offsetof(struct i40e_hw_port_stats,
629 {"xoff_packets", offsetof(struct i40e_hw_port_stats,
631 {"xon_to_xoff_packets", offsetof(struct i40e_hw_port_stats,
632 priority_xon_2_xoff)},
635 #define I40E_NB_TXQ_PRIO_XSTATS (sizeof(rte_i40e_txq_prio_strings) / \
636 sizeof(rte_i40e_txq_prio_strings[0]))
638 static struct eth_driver rte_i40e_pmd = {
640 .name = "rte_i40e_pmd",
641 .id_table = pci_id_i40e_map,
642 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
643 RTE_PCI_DRV_DETACHABLE,
645 .eth_dev_init = eth_i40e_dev_init,
646 .eth_dev_uninit = eth_i40e_dev_uninit,
647 .dev_private_size = sizeof(struct i40e_adapter),
651 rte_i40e_dev_atomic_read_link_status(struct rte_eth_dev *dev,
652 struct rte_eth_link *link)
654 struct rte_eth_link *dst = link;
655 struct rte_eth_link *src = &(dev->data->dev_link);
657 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
658 *(uint64_t *)src) == 0)
665 rte_i40e_dev_atomic_write_link_status(struct rte_eth_dev *dev,
666 struct rte_eth_link *link)
668 struct rte_eth_link *dst = &(dev->data->dev_link);
669 struct rte_eth_link *src = link;
671 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
672 *(uint64_t *)src) == 0)
679 * Driver initialization routine.
680 * Invoked once at EAL init time.
681 * Register itself as the [Poll Mode] Driver of PCI IXGBE devices.
684 rte_i40e_pmd_init(const char *name __rte_unused,
685 const char *params __rte_unused)
687 PMD_INIT_FUNC_TRACE();
688 rte_eth_driver_register(&rte_i40e_pmd);
693 static struct rte_driver rte_i40e_driver = {
695 .init = rte_i40e_pmd_init,
698 PMD_REGISTER_DRIVER(rte_i40e_driver);
701 * Initialize registers for flexible payload, which should be set by NVM.
702 * This should be removed from code once it is fixed in NVM.
704 #ifndef I40E_GLQF_ORT
705 #define I40E_GLQF_ORT(_i) (0x00268900 + ((_i) * 4))
707 #ifndef I40E_GLQF_PIT
708 #define I40E_GLQF_PIT(_i) (0x00268C80 + ((_i) * 4))
711 static inline void i40e_flex_payload_reg_init(struct i40e_hw *hw)
713 I40E_WRITE_REG(hw, I40E_GLQF_ORT(18), 0x00000030);
714 I40E_WRITE_REG(hw, I40E_GLQF_ORT(19), 0x00000030);
715 I40E_WRITE_REG(hw, I40E_GLQF_ORT(26), 0x0000002B);
716 I40E_WRITE_REG(hw, I40E_GLQF_ORT(30), 0x0000002B);
717 I40E_WRITE_REG(hw, I40E_GLQF_ORT(33), 0x000000E0);
718 I40E_WRITE_REG(hw, I40E_GLQF_ORT(34), 0x000000E3);
719 I40E_WRITE_REG(hw, I40E_GLQF_ORT(35), 0x000000E6);
720 I40E_WRITE_REG(hw, I40E_GLQF_ORT(20), 0x00000031);
721 I40E_WRITE_REG(hw, I40E_GLQF_ORT(23), 0x00000031);
722 I40E_WRITE_REG(hw, I40E_GLQF_ORT(63), 0x0000002D);
724 /* GLQF_PIT Registers */
725 I40E_WRITE_REG(hw, I40E_GLQF_PIT(16), 0x00007480);
726 I40E_WRITE_REG(hw, I40E_GLQF_PIT(17), 0x00007440);
729 #define I40E_FLOW_CONTROL_ETHERTYPE 0x8808
732 * Add a ethertype filter to drop all flow control frames transmitted
736 i40e_add_tx_flow_control_drop_filter(struct i40e_pf *pf)
738 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
739 uint16_t flags = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
740 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
741 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
744 ret = i40e_aq_add_rem_control_packet_filter(hw, NULL,
745 I40E_FLOW_CONTROL_ETHERTYPE, flags,
746 pf->main_vsi_seid, 0,
749 PMD_INIT_LOG(ERR, "Failed to add filter to drop flow control "
750 " frames from VSIs.");
754 eth_i40e_dev_init(struct rte_eth_dev *dev)
756 struct rte_pci_device *pci_dev;
757 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
758 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
759 struct i40e_vsi *vsi;
764 PMD_INIT_FUNC_TRACE();
766 dev->dev_ops = &i40e_eth_dev_ops;
767 dev->rx_pkt_burst = i40e_recv_pkts;
768 dev->tx_pkt_burst = i40e_xmit_pkts;
770 /* for secondary processes, we don't initialise any further as primary
771 * has already done this work. Only check we don't need a different
773 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
774 i40e_set_rx_function(dev);
775 i40e_set_tx_function(dev);
778 pci_dev = dev->pci_dev;
780 rte_eth_copy_pci_info(dev, pci_dev);
782 pf->adapter = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
783 pf->adapter->eth_dev = dev;
784 pf->dev_data = dev->data;
786 hw->back = I40E_PF_TO_ADAPTER(pf);
787 hw->hw_addr = (uint8_t *)(pci_dev->mem_resource[0].addr);
789 PMD_INIT_LOG(ERR, "Hardware is not available, "
790 "as address is NULL");
794 hw->vendor_id = pci_dev->id.vendor_id;
795 hw->device_id = pci_dev->id.device_id;
796 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
797 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
798 hw->bus.device = pci_dev->addr.devid;
799 hw->bus.func = pci_dev->addr.function;
800 hw->adapter_stopped = 0;
802 /* Make sure all is clean before doing PF reset */
805 /* Initialize the hardware */
808 /* Reset here to make sure all is clean for each PF */
809 ret = i40e_pf_reset(hw);
811 PMD_INIT_LOG(ERR, "Failed to reset pf: %d", ret);
815 /* Initialize the shared code (base driver) */
816 ret = i40e_init_shared_code(hw);
818 PMD_INIT_LOG(ERR, "Failed to init shared code (base driver): %d", ret);
823 * To work around the NVM issue,initialize registers
824 * for flexible payload by software.
825 * It should be removed once issues are fixed in NVM.
827 i40e_flex_payload_reg_init(hw);
829 /* Initialize the input set for filters (hash and fd) to default value */
830 i40e_filter_input_set_init(pf);
832 /* Initialize the parameters for adminq */
833 i40e_init_adminq_parameter(hw);
834 ret = i40e_init_adminq(hw);
835 if (ret != I40E_SUCCESS) {
836 PMD_INIT_LOG(ERR, "Failed to init adminq: %d", ret);
839 PMD_INIT_LOG(INFO, "FW %d.%d API %d.%d NVM %02d.%02d.%02d eetrack %04x",
840 hw->aq.fw_maj_ver, hw->aq.fw_min_ver,
841 hw->aq.api_maj_ver, hw->aq.api_min_ver,
842 ((hw->nvm.version >> 12) & 0xf),
843 ((hw->nvm.version >> 4) & 0xff),
844 (hw->nvm.version & 0xf), hw->nvm.eetrack);
847 i40e_clear_pxe_mode(hw);
850 * On X710, performance number is far from the expectation on recent
851 * firmware versions. The fix for this issue may not be integrated in
852 * the following firmware version. So the workaround in software driver
853 * is needed. It needs to modify the initial values of 3 internal only
854 * registers. Note that the workaround can be removed when it is fixed
855 * in firmware in the future.
857 i40e_configure_registers(hw);
859 /* Get hw capabilities */
860 ret = i40e_get_cap(hw);
861 if (ret != I40E_SUCCESS) {
862 PMD_INIT_LOG(ERR, "Failed to get capabilities: %d", ret);
863 goto err_get_capabilities;
866 /* Initialize parameters for PF */
867 ret = i40e_pf_parameter_init(dev);
869 PMD_INIT_LOG(ERR, "Failed to do parameter init: %d", ret);
870 goto err_parameter_init;
873 /* Initialize the queue management */
874 ret = i40e_res_pool_init(&pf->qp_pool, 0, hw->func_caps.num_tx_qp);
876 PMD_INIT_LOG(ERR, "Failed to init queue pool");
877 goto err_qp_pool_init;
879 ret = i40e_res_pool_init(&pf->msix_pool, 1,
880 hw->func_caps.num_msix_vectors - 1);
882 PMD_INIT_LOG(ERR, "Failed to init MSIX pool");
883 goto err_msix_pool_init;
886 /* Initialize lan hmc */
887 ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
888 hw->func_caps.num_rx_qp, 0, 0);
889 if (ret != I40E_SUCCESS) {
890 PMD_INIT_LOG(ERR, "Failed to init lan hmc: %d", ret);
891 goto err_init_lan_hmc;
894 /* Configure lan hmc */
895 ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
896 if (ret != I40E_SUCCESS) {
897 PMD_INIT_LOG(ERR, "Failed to configure lan hmc: %d", ret);
898 goto err_configure_lan_hmc;
901 /* Get and check the mac address */
902 i40e_get_mac_addr(hw, hw->mac.addr);
903 if (i40e_validate_mac_addr(hw->mac.addr) != I40E_SUCCESS) {
904 PMD_INIT_LOG(ERR, "mac address is not valid");
906 goto err_get_mac_addr;
908 /* Copy the permanent MAC address */
909 ether_addr_copy((struct ether_addr *) hw->mac.addr,
910 (struct ether_addr *) hw->mac.perm_addr);
912 /* Disable flow control */
913 hw->fc.requested_mode = I40E_FC_NONE;
914 i40e_set_fc(hw, &aq_fail, TRUE);
916 /* Set the global registers with default ether type value */
917 ret = i40e_vlan_tpid_set(dev, ETH_VLAN_TYPE_OUTER, ETHER_TYPE_VLAN);
918 if (ret != I40E_SUCCESS) {
919 PMD_INIT_LOG(ERR, "Failed to set the default outer "
921 goto err_setup_pf_switch;
923 ret = i40e_vlan_tpid_set(dev, ETH_VLAN_TYPE_INNER, ETHER_TYPE_VLAN);
924 if (ret != I40E_SUCCESS) {
925 PMD_INIT_LOG(ERR, "Failed to set the default outer "
927 goto err_setup_pf_switch;
930 /* PF setup, which includes VSI setup */
931 ret = i40e_pf_setup(pf);
933 PMD_INIT_LOG(ERR, "Failed to setup pf switch: %d", ret);
934 goto err_setup_pf_switch;
939 /* Disable double vlan by default */
940 i40e_vsi_config_double_vlan(vsi, FALSE);
942 if (!vsi->max_macaddrs)
943 len = ETHER_ADDR_LEN;
945 len = ETHER_ADDR_LEN * vsi->max_macaddrs;
947 /* Should be after VSI initialized */
948 dev->data->mac_addrs = rte_zmalloc("i40e", len, 0);
949 if (!dev->data->mac_addrs) {
950 PMD_INIT_LOG(ERR, "Failed to allocated memory "
951 "for storing mac address");
954 ether_addr_copy((struct ether_addr *)hw->mac.perm_addr,
955 &dev->data->mac_addrs[0]);
957 /* initialize pf host driver to setup SRIOV resource if applicable */
958 i40e_pf_host_init(dev);
960 /* register callback func to eal lib */
961 rte_intr_callback_register(&(pci_dev->intr_handle),
962 i40e_dev_interrupt_handler, (void *)dev);
964 /* configure and enable device interrupt */
965 i40e_pf_config_irq0(hw, TRUE);
966 i40e_pf_enable_irq0(hw);
968 /* enable uio intr after callback register */
969 rte_intr_enable(&(pci_dev->intr_handle));
971 * Add an ethertype filter to drop all flow control frames transmitted
972 * from VSIs. By doing so, we stop VF from sending out PAUSE or PFC
975 i40e_add_tx_flow_control_drop_filter(pf);
977 /* Set the max frame size to 0x2600 by default,
978 * in case other drivers changed the default value.
980 i40e_aq_set_mac_config(hw, I40E_FRAME_SIZE_MAX, TRUE, 0, NULL);
982 /* initialize mirror rule list */
983 TAILQ_INIT(&pf->mirror_list);
985 /* Init dcb to sw mode by default */
986 ret = i40e_dcb_init_configure(dev, TRUE);
987 if (ret != I40E_SUCCESS) {
988 PMD_INIT_LOG(INFO, "Failed to init dcb.");
989 pf->flags &= ~I40E_FLAG_DCB;
995 i40e_vsi_release(pf->main_vsi);
998 err_configure_lan_hmc:
999 (void)i40e_shutdown_lan_hmc(hw);
1001 i40e_res_pool_destroy(&pf->msix_pool);
1003 i40e_res_pool_destroy(&pf->qp_pool);
1006 err_get_capabilities:
1007 (void)i40e_shutdown_adminq(hw);
1013 eth_i40e_dev_uninit(struct rte_eth_dev *dev)
1015 struct rte_pci_device *pci_dev;
1017 struct i40e_filter_control_settings settings;
1019 uint8_t aq_fail = 0;
1021 PMD_INIT_FUNC_TRACE();
1023 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1026 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1027 pci_dev = dev->pci_dev;
1029 if (hw->adapter_stopped == 0)
1030 i40e_dev_close(dev);
1032 dev->dev_ops = NULL;
1033 dev->rx_pkt_burst = NULL;
1034 dev->tx_pkt_burst = NULL;
1037 ret = i40e_aq_stop_lldp(hw, true, NULL);
1038 if (ret != I40E_SUCCESS) /* Its failure can be ignored */
1039 PMD_INIT_LOG(INFO, "Failed to stop lldp");
1041 /* Clear PXE mode */
1042 i40e_clear_pxe_mode(hw);
1044 /* Unconfigure filter control */
1045 memset(&settings, 0, sizeof(settings));
1046 ret = i40e_set_filter_control(hw, &settings);
1048 PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
1051 /* Disable flow control */
1052 hw->fc.requested_mode = I40E_FC_NONE;
1053 i40e_set_fc(hw, &aq_fail, TRUE);
1055 /* uninitialize pf host driver */
1056 i40e_pf_host_uninit(dev);
1058 rte_free(dev->data->mac_addrs);
1059 dev->data->mac_addrs = NULL;
1061 /* disable uio intr before callback unregister */
1062 rte_intr_disable(&(pci_dev->intr_handle));
1064 /* register callback func to eal lib */
1065 rte_intr_callback_unregister(&(pci_dev->intr_handle),
1066 i40e_dev_interrupt_handler, (void *)dev);
1072 i40e_dev_configure(struct rte_eth_dev *dev)
1074 struct i40e_adapter *ad =
1075 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1076 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1077 enum rte_eth_rx_mq_mode mq_mode = dev->data->dev_conf.rxmode.mq_mode;
1080 /* Initialize to TRUE. If any of Rx queues doesn't meet the
1081 * bulk allocation or vector Rx preconditions we will reset it.
1083 ad->rx_bulk_alloc_allowed = true;
1084 ad->rx_vec_allowed = true;
1085 ad->tx_simple_allowed = true;
1086 ad->tx_vec_allowed = true;
1088 if (dev->data->dev_conf.fdir_conf.mode == RTE_FDIR_MODE_PERFECT) {
1089 ret = i40e_fdir_setup(pf);
1090 if (ret != I40E_SUCCESS) {
1091 PMD_DRV_LOG(ERR, "Failed to setup flow director.");
1094 ret = i40e_fdir_configure(dev);
1096 PMD_DRV_LOG(ERR, "failed to configure fdir.");
1100 i40e_fdir_teardown(pf);
1102 ret = i40e_dev_init_vlan(dev);
1107 * Needs to move VMDQ setting out of i40e_pf_config_mq_rx() as VMDQ and
1108 * RSS setting have different requirements.
1109 * General PMD driver call sequence are NIC init, configure,
1110 * rx/tx_queue_setup and dev_start. In rx/tx_queue_setup() function, it
1111 * will try to lookup the VSI that specific queue belongs to if VMDQ
1112 * applicable. So, VMDQ setting has to be done before
1113 * rx/tx_queue_setup(). This function is good to place vmdq_setup.
1114 * For RSS setting, it will try to calculate actual configured RX queue
1115 * number, which will be available after rx_queue_setup(). dev_start()
1116 * function is good to place RSS setup.
1118 if (mq_mode & ETH_MQ_RX_VMDQ_FLAG) {
1119 ret = i40e_vmdq_setup(dev);
1124 if (mq_mode & ETH_MQ_RX_DCB_FLAG) {
1125 ret = i40e_dcb_setup(dev);
1127 PMD_DRV_LOG(ERR, "failed to configure DCB.");
1135 /* need to release vmdq resource if exists */
1136 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1137 i40e_vsi_release(pf->vmdq[i].vsi);
1138 pf->vmdq[i].vsi = NULL;
1143 /* need to release fdir resource if exists */
1144 i40e_fdir_teardown(pf);
1149 i40e_vsi_queues_unbind_intr(struct i40e_vsi *vsi)
1151 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1152 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1153 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1154 uint16_t msix_vect = vsi->msix_intr;
1157 for (i = 0; i < vsi->nb_qps; i++) {
1158 I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
1159 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
1163 if (vsi->type != I40E_VSI_SRIOV) {
1164 if (!rte_intr_allow_others(intr_handle)) {
1165 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
1166 I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
1168 I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
1171 I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
1172 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
1174 I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
1179 reg = (hw->func_caps.num_msix_vectors_vf - 1) *
1180 vsi->user_param + (msix_vect - 1);
1182 I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
1183 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
1185 I40E_WRITE_FLUSH(hw);
1189 __vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t msix_vect,
1190 int base_queue, int nb_queue)
1194 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1196 /* Bind all RX queues to allocated MSIX interrupt */
1197 for (i = 0; i < nb_queue; i++) {
1198 val = (msix_vect << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
1199 I40E_QINT_RQCTL_ITR_INDX_MASK |
1200 ((base_queue + i + 1) <<
1201 I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
1202 (0 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
1203 I40E_QINT_RQCTL_CAUSE_ENA_MASK;
1205 if (i == nb_queue - 1)
1206 val |= I40E_QINT_RQCTL_NEXTQ_INDX_MASK;
1207 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(base_queue + i), val);
1210 /* Write first RX queue to Link list register as the head element */
1211 if (vsi->type != I40E_VSI_SRIOV) {
1213 i40e_calc_itr_interval(RTE_LIBRTE_I40E_ITR_INTERVAL);
1215 if (msix_vect == I40E_MISC_VEC_ID) {
1216 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
1218 I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
1220 I40E_PFINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
1222 I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
1225 I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
1227 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
1229 I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
1231 I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
1238 if (msix_vect == I40E_MISC_VEC_ID) {
1240 I40E_VPINT_LNKLST0(vsi->user_param),
1242 I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
1244 I40E_VPINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
1246 /* num_msix_vectors_vf needs to minus irq0 */
1247 reg = (hw->func_caps.num_msix_vectors_vf - 1) *
1248 vsi->user_param + (msix_vect - 1);
1250 I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
1252 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
1254 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
1258 I40E_WRITE_FLUSH(hw);
1262 i40e_vsi_queues_bind_intr(struct i40e_vsi *vsi)
1264 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1265 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1266 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1267 uint16_t msix_vect = vsi->msix_intr;
1268 uint16_t nb_msix = RTE_MIN(vsi->nb_msix, intr_handle->nb_efd);
1269 uint16_t queue_idx = 0;
1274 for (i = 0; i < vsi->nb_qps; i++) {
1275 I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
1276 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
1279 /* INTENA flag is not auto-cleared for interrupt */
1280 val = I40E_READ_REG(hw, I40E_GLINT_CTL);
1281 val |= I40E_GLINT_CTL_DIS_AUTOMASK_PF0_MASK |
1282 I40E_GLINT_CTL_DIS_AUTOMASK_N_MASK |
1283 I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK;
1284 I40E_WRITE_REG(hw, I40E_GLINT_CTL, val);
1286 /* VF bind interrupt */
1287 if (vsi->type == I40E_VSI_SRIOV) {
1288 __vsi_queues_bind_intr(vsi, msix_vect,
1289 vsi->base_queue, vsi->nb_qps);
1293 /* PF & VMDq bind interrupt */
1294 if (rte_intr_dp_is_en(intr_handle)) {
1295 if (vsi->type == I40E_VSI_MAIN) {
1298 } else if (vsi->type == I40E_VSI_VMDQ2) {
1299 struct i40e_vsi *main_vsi =
1300 I40E_DEV_PRIVATE_TO_MAIN_VSI(vsi->adapter);
1301 queue_idx = vsi->base_queue - main_vsi->nb_qps;
1306 for (i = 0; i < vsi->nb_used_qps; i++) {
1308 if (!rte_intr_allow_others(intr_handle))
1309 /* allow to share MISC_VEC_ID */
1310 msix_vect = I40E_MISC_VEC_ID;
1312 /* no enough msix_vect, map all to one */
1313 __vsi_queues_bind_intr(vsi, msix_vect,
1314 vsi->base_queue + i,
1315 vsi->nb_used_qps - i);
1316 for (; !!record && i < vsi->nb_used_qps; i++)
1317 intr_handle->intr_vec[queue_idx + i] =
1321 /* 1:1 queue/msix_vect mapping */
1322 __vsi_queues_bind_intr(vsi, msix_vect,
1323 vsi->base_queue + i, 1);
1325 intr_handle->intr_vec[queue_idx + i] = msix_vect;
1333 i40e_vsi_enable_queues_intr(struct i40e_vsi *vsi)
1335 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1336 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1337 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1338 uint16_t interval = i40e_calc_itr_interval(\
1339 RTE_LIBRTE_I40E_ITR_INTERVAL);
1340 uint16_t msix_intr, i;
1342 if (rte_intr_allow_others(intr_handle))
1343 for (i = 0; i < vsi->nb_msix; i++) {
1344 msix_intr = vsi->msix_intr + i;
1345 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
1346 I40E_PFINT_DYN_CTLN_INTENA_MASK |
1347 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
1348 (0 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT) |
1350 I40E_PFINT_DYN_CTLN_INTERVAL_SHIFT));
1353 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
1354 I40E_PFINT_DYN_CTL0_INTENA_MASK |
1355 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
1356 (0 << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT) |
1358 I40E_PFINT_DYN_CTL0_INTERVAL_SHIFT));
1360 I40E_WRITE_FLUSH(hw);
1364 i40e_vsi_disable_queues_intr(struct i40e_vsi *vsi)
1366 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1367 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1368 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1369 uint16_t msix_intr, i;
1371 if (rte_intr_allow_others(intr_handle))
1372 for (i = 0; i < vsi->nb_msix; i++) {
1373 msix_intr = vsi->msix_intr + i;
1374 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
1378 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0, 0);
1380 I40E_WRITE_FLUSH(hw);
1383 static inline uint8_t
1384 i40e_parse_link_speed(uint16_t eth_link_speed)
1386 uint8_t link_speed = I40E_LINK_SPEED_UNKNOWN;
1388 switch (eth_link_speed) {
1389 case ETH_LINK_SPEED_40G:
1390 link_speed = I40E_LINK_SPEED_40GB;
1392 case ETH_LINK_SPEED_20G:
1393 link_speed = I40E_LINK_SPEED_20GB;
1395 case ETH_LINK_SPEED_10G:
1396 link_speed = I40E_LINK_SPEED_10GB;
1398 case ETH_LINK_SPEED_1000:
1399 link_speed = I40E_LINK_SPEED_1GB;
1401 case ETH_LINK_SPEED_100:
1402 link_speed = I40E_LINK_SPEED_100MB;
1410 i40e_phy_conf_link(__rte_unused struct i40e_hw *hw,
1411 __rte_unused uint8_t abilities,
1412 __rte_unused uint8_t force_speed)
1414 /* Skip any phy config on both 10G and 40G interfaces, as a workaround
1415 * for the link control limitation of that all link control should be
1416 * handled by firmware. It should follow up if link control will be
1417 * opened to software driver in future firmware versions.
1419 return I40E_SUCCESS;
1423 i40e_apply_link_speed(struct rte_eth_dev *dev)
1426 uint8_t abilities = 0;
1427 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1428 struct rte_eth_conf *conf = &dev->data->dev_conf;
1430 speed = i40e_parse_link_speed(conf->link_speed);
1431 abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1432 if (conf->link_speed == ETH_LINK_SPEED_AUTONEG)
1433 abilities |= I40E_AQ_PHY_AN_ENABLED;
1435 abilities |= I40E_AQ_PHY_LINK_ENABLED;
1437 return i40e_phy_conf_link(hw, abilities, speed);
1441 i40e_dev_start(struct rte_eth_dev *dev)
1443 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1444 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1445 struct i40e_vsi *main_vsi = pf->main_vsi;
1447 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1448 uint32_t intr_vector = 0;
1450 hw->adapter_stopped = 0;
1452 if ((dev->data->dev_conf.link_duplex != ETH_LINK_AUTONEG_DUPLEX) &&
1453 (dev->data->dev_conf.link_duplex != ETH_LINK_FULL_DUPLEX)) {
1454 PMD_INIT_LOG(ERR, "Invalid link_duplex (%hu) for port %hhu",
1455 dev->data->dev_conf.link_duplex,
1456 dev->data->port_id);
1460 rte_intr_disable(intr_handle);
1462 if ((rte_intr_cap_multiple(intr_handle) ||
1463 !RTE_ETH_DEV_SRIOV(dev).active) &&
1464 dev->data->dev_conf.intr_conf.rxq != 0) {
1465 intr_vector = dev->data->nb_rx_queues;
1466 if (rte_intr_efd_enable(intr_handle, intr_vector))
1470 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
1471 intr_handle->intr_vec =
1472 rte_zmalloc("intr_vec",
1473 dev->data->nb_rx_queues * sizeof(int),
1475 if (!intr_handle->intr_vec) {
1476 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
1477 " intr_vec\n", dev->data->nb_rx_queues);
1482 /* Initialize VSI */
1483 ret = i40e_dev_rxtx_init(pf);
1484 if (ret != I40E_SUCCESS) {
1485 PMD_DRV_LOG(ERR, "Failed to init rx/tx queues");
1489 /* Map queues with MSIX interrupt */
1490 main_vsi->nb_used_qps = dev->data->nb_rx_queues -
1491 pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
1492 i40e_vsi_queues_bind_intr(main_vsi);
1493 i40e_vsi_enable_queues_intr(main_vsi);
1495 /* Map VMDQ VSI queues with MSIX interrupt */
1496 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1497 pf->vmdq[i].vsi->nb_used_qps = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
1498 i40e_vsi_queues_bind_intr(pf->vmdq[i].vsi);
1499 i40e_vsi_enable_queues_intr(pf->vmdq[i].vsi);
1502 /* enable FDIR MSIX interrupt */
1503 if (pf->fdir.fdir_vsi) {
1504 i40e_vsi_queues_bind_intr(pf->fdir.fdir_vsi);
1505 i40e_vsi_enable_queues_intr(pf->fdir.fdir_vsi);
1508 /* Enable all queues which have been configured */
1509 ret = i40e_dev_switch_queues(pf, TRUE);
1510 if (ret != I40E_SUCCESS) {
1511 PMD_DRV_LOG(ERR, "Failed to enable VSI");
1515 /* Enable receiving broadcast packets */
1516 ret = i40e_aq_set_vsi_broadcast(hw, main_vsi->seid, true, NULL);
1517 if (ret != I40E_SUCCESS)
1518 PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
1520 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1521 ret = i40e_aq_set_vsi_broadcast(hw, pf->vmdq[i].vsi->seid,
1523 if (ret != I40E_SUCCESS)
1524 PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
1527 /* Apply link configure */
1528 ret = i40e_apply_link_speed(dev);
1529 if (I40E_SUCCESS != ret) {
1530 PMD_DRV_LOG(ERR, "Fail to apply link setting");
1534 if (!rte_intr_allow_others(intr_handle)) {
1535 rte_intr_callback_unregister(intr_handle,
1536 i40e_dev_interrupt_handler,
1538 /* configure and enable device interrupt */
1539 i40e_pf_config_irq0(hw, FALSE);
1540 i40e_pf_enable_irq0(hw);
1542 if (dev->data->dev_conf.intr_conf.lsc != 0)
1543 PMD_INIT_LOG(INFO, "lsc won't enable because of"
1544 " no intr multiplex\n");
1547 /* enable uio intr after callback register */
1548 rte_intr_enable(intr_handle);
1550 return I40E_SUCCESS;
1553 i40e_dev_switch_queues(pf, FALSE);
1554 i40e_dev_clear_queues(dev);
1560 i40e_dev_stop(struct rte_eth_dev *dev)
1562 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1563 struct i40e_vsi *main_vsi = pf->main_vsi;
1564 struct i40e_mirror_rule *p_mirror;
1565 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1568 /* Disable all queues */
1569 i40e_dev_switch_queues(pf, FALSE);
1571 /* un-map queues with interrupt registers */
1572 i40e_vsi_disable_queues_intr(main_vsi);
1573 i40e_vsi_queues_unbind_intr(main_vsi);
1575 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1576 i40e_vsi_disable_queues_intr(pf->vmdq[i].vsi);
1577 i40e_vsi_queues_unbind_intr(pf->vmdq[i].vsi);
1580 if (pf->fdir.fdir_vsi) {
1581 i40e_vsi_queues_unbind_intr(pf->fdir.fdir_vsi);
1582 i40e_vsi_disable_queues_intr(pf->fdir.fdir_vsi);
1584 /* Clear all queues and release memory */
1585 i40e_dev_clear_queues(dev);
1588 i40e_dev_set_link_down(dev);
1590 /* Remove all mirror rules */
1591 while ((p_mirror = TAILQ_FIRST(&pf->mirror_list))) {
1592 TAILQ_REMOVE(&pf->mirror_list, p_mirror, rules);
1595 pf->nb_mirror_rule = 0;
1597 if (!rte_intr_allow_others(intr_handle))
1598 /* resume to the default handler */
1599 rte_intr_callback_register(intr_handle,
1600 i40e_dev_interrupt_handler,
1603 /* Clean datapath event and queue/vec mapping */
1604 rte_intr_efd_disable(intr_handle);
1605 if (intr_handle->intr_vec) {
1606 rte_free(intr_handle->intr_vec);
1607 intr_handle->intr_vec = NULL;
1612 i40e_dev_close(struct rte_eth_dev *dev)
1614 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1615 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1619 PMD_INIT_FUNC_TRACE();
1622 hw->adapter_stopped = 1;
1623 i40e_dev_free_queues(dev);
1625 /* Disable interrupt */
1626 i40e_pf_disable_irq0(hw);
1627 rte_intr_disable(&(dev->pci_dev->intr_handle));
1629 /* shutdown and destroy the HMC */
1630 i40e_shutdown_lan_hmc(hw);
1632 /* release all the existing VSIs and VEBs */
1633 i40e_fdir_teardown(pf);
1634 i40e_vsi_release(pf->main_vsi);
1636 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1637 i40e_vsi_release(pf->vmdq[i].vsi);
1638 pf->vmdq[i].vsi = NULL;
1644 /* shutdown the adminq */
1645 i40e_aq_queue_shutdown(hw, true);
1646 i40e_shutdown_adminq(hw);
1648 i40e_res_pool_destroy(&pf->qp_pool);
1649 i40e_res_pool_destroy(&pf->msix_pool);
1651 /* force a PF reset to clean anything leftover */
1652 reg = I40E_READ_REG(hw, I40E_PFGEN_CTRL);
1653 I40E_WRITE_REG(hw, I40E_PFGEN_CTRL,
1654 (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
1655 I40E_WRITE_FLUSH(hw);
1659 i40e_dev_promiscuous_enable(struct rte_eth_dev *dev)
1661 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1662 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1663 struct i40e_vsi *vsi = pf->main_vsi;
1666 status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
1668 if (status != I40E_SUCCESS)
1669 PMD_DRV_LOG(ERR, "Failed to enable unicast promiscuous");
1671 status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
1673 if (status != I40E_SUCCESS)
1674 PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
1679 i40e_dev_promiscuous_disable(struct rte_eth_dev *dev)
1681 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1682 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1683 struct i40e_vsi *vsi = pf->main_vsi;
1686 status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
1688 if (status != I40E_SUCCESS)
1689 PMD_DRV_LOG(ERR, "Failed to disable unicast promiscuous");
1691 status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
1693 if (status != I40E_SUCCESS)
1694 PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
1698 i40e_dev_allmulticast_enable(struct rte_eth_dev *dev)
1700 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1701 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1702 struct i40e_vsi *vsi = pf->main_vsi;
1705 ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid, TRUE, NULL);
1706 if (ret != I40E_SUCCESS)
1707 PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
1711 i40e_dev_allmulticast_disable(struct rte_eth_dev *dev)
1713 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1714 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1715 struct i40e_vsi *vsi = pf->main_vsi;
1718 if (dev->data->promiscuous == 1)
1719 return; /* must remain in all_multicast mode */
1721 ret = i40e_aq_set_vsi_multicast_promiscuous(hw,
1722 vsi->seid, FALSE, NULL);
1723 if (ret != I40E_SUCCESS)
1724 PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
1728 * Set device link up.
1731 i40e_dev_set_link_up(struct rte_eth_dev *dev)
1733 /* re-apply link speed setting */
1734 return i40e_apply_link_speed(dev);
1738 * Set device link down.
1741 i40e_dev_set_link_down(__rte_unused struct rte_eth_dev *dev)
1743 uint8_t speed = I40E_LINK_SPEED_UNKNOWN;
1744 uint8_t abilities = I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1745 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1747 return i40e_phy_conf_link(hw, abilities, speed);
1751 i40e_dev_link_update(struct rte_eth_dev *dev,
1752 int wait_to_complete)
1754 #define CHECK_INTERVAL 100 /* 100ms */
1755 #define MAX_REPEAT_TIME 10 /* 1s (10 * 100ms) in total */
1756 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1757 struct i40e_link_status link_status;
1758 struct rte_eth_link link, old;
1760 unsigned rep_cnt = MAX_REPEAT_TIME;
1762 memset(&link, 0, sizeof(link));
1763 memset(&old, 0, sizeof(old));
1764 memset(&link_status, 0, sizeof(link_status));
1765 rte_i40e_dev_atomic_read_link_status(dev, &old);
1768 /* Get link status information from hardware */
1769 status = i40e_aq_get_link_info(hw, false, &link_status, NULL);
1770 if (status != I40E_SUCCESS) {
1771 link.link_speed = ETH_LINK_SPEED_100;
1772 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1773 PMD_DRV_LOG(ERR, "Failed to get link info");
1777 link.link_status = link_status.link_info & I40E_AQ_LINK_UP;
1778 if (!wait_to_complete)
1781 rte_delay_ms(CHECK_INTERVAL);
1782 } while (!link.link_status && rep_cnt--);
1784 if (!link.link_status)
1787 /* i40e uses full duplex only */
1788 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1790 /* Parse the link status */
1791 switch (link_status.link_speed) {
1792 case I40E_LINK_SPEED_100MB:
1793 link.link_speed = ETH_LINK_SPEED_100;
1795 case I40E_LINK_SPEED_1GB:
1796 link.link_speed = ETH_LINK_SPEED_1000;
1798 case I40E_LINK_SPEED_10GB:
1799 link.link_speed = ETH_LINK_SPEED_10G;
1801 case I40E_LINK_SPEED_20GB:
1802 link.link_speed = ETH_LINK_SPEED_20G;
1804 case I40E_LINK_SPEED_40GB:
1805 link.link_speed = ETH_LINK_SPEED_40G;
1808 link.link_speed = ETH_LINK_SPEED_100;
1813 rte_i40e_dev_atomic_write_link_status(dev, &link);
1814 if (link.link_status == old.link_status)
1820 /* Get all the statistics of a VSI */
1822 i40e_update_vsi_stats(struct i40e_vsi *vsi)
1824 struct i40e_eth_stats *oes = &vsi->eth_stats_offset;
1825 struct i40e_eth_stats *nes = &vsi->eth_stats;
1826 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1827 int idx = rte_le_to_cpu_16(vsi->info.stat_counter_idx);
1829 i40e_stat_update_48(hw, I40E_GLV_GORCH(idx), I40E_GLV_GORCL(idx),
1830 vsi->offset_loaded, &oes->rx_bytes,
1832 i40e_stat_update_48(hw, I40E_GLV_UPRCH(idx), I40E_GLV_UPRCL(idx),
1833 vsi->offset_loaded, &oes->rx_unicast,
1835 i40e_stat_update_48(hw, I40E_GLV_MPRCH(idx), I40E_GLV_MPRCL(idx),
1836 vsi->offset_loaded, &oes->rx_multicast,
1837 &nes->rx_multicast);
1838 i40e_stat_update_48(hw, I40E_GLV_BPRCH(idx), I40E_GLV_BPRCL(idx),
1839 vsi->offset_loaded, &oes->rx_broadcast,
1840 &nes->rx_broadcast);
1841 i40e_stat_update_32(hw, I40E_GLV_RDPC(idx), vsi->offset_loaded,
1842 &oes->rx_discards, &nes->rx_discards);
1843 /* GLV_REPC not supported */
1844 /* GLV_RMPC not supported */
1845 i40e_stat_update_32(hw, I40E_GLV_RUPP(idx), vsi->offset_loaded,
1846 &oes->rx_unknown_protocol,
1847 &nes->rx_unknown_protocol);
1848 i40e_stat_update_48(hw, I40E_GLV_GOTCH(idx), I40E_GLV_GOTCL(idx),
1849 vsi->offset_loaded, &oes->tx_bytes,
1851 i40e_stat_update_48(hw, I40E_GLV_UPTCH(idx), I40E_GLV_UPTCL(idx),
1852 vsi->offset_loaded, &oes->tx_unicast,
1854 i40e_stat_update_48(hw, I40E_GLV_MPTCH(idx), I40E_GLV_MPTCL(idx),
1855 vsi->offset_loaded, &oes->tx_multicast,
1856 &nes->tx_multicast);
1857 i40e_stat_update_48(hw, I40E_GLV_BPTCH(idx), I40E_GLV_BPTCL(idx),
1858 vsi->offset_loaded, &oes->tx_broadcast,
1859 &nes->tx_broadcast);
1860 /* GLV_TDPC not supported */
1861 i40e_stat_update_32(hw, I40E_GLV_TEPC(idx), vsi->offset_loaded,
1862 &oes->tx_errors, &nes->tx_errors);
1863 vsi->offset_loaded = true;
1865 PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats start *******************",
1867 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", nes->rx_bytes);
1868 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", nes->rx_unicast);
1869 PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", nes->rx_multicast);
1870 PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", nes->rx_broadcast);
1871 PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", nes->rx_discards);
1872 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
1873 nes->rx_unknown_protocol);
1874 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", nes->tx_bytes);
1875 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", nes->tx_unicast);
1876 PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", nes->tx_multicast);
1877 PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", nes->tx_broadcast);
1878 PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", nes->tx_discards);
1879 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", nes->tx_errors);
1880 PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats end *******************",
1885 i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw)
1888 struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
1889 struct i40e_hw_port_stats *os = &pf->stats_offset; /* old stats */
1891 /* Get statistics of struct i40e_eth_stats */
1892 i40e_stat_update_48(hw, I40E_GLPRT_GORCH(hw->port),
1893 I40E_GLPRT_GORCL(hw->port),
1894 pf->offset_loaded, &os->eth.rx_bytes,
1896 i40e_stat_update_48(hw, I40E_GLPRT_UPRCH(hw->port),
1897 I40E_GLPRT_UPRCL(hw->port),
1898 pf->offset_loaded, &os->eth.rx_unicast,
1899 &ns->eth.rx_unicast);
1900 i40e_stat_update_48(hw, I40E_GLPRT_MPRCH(hw->port),
1901 I40E_GLPRT_MPRCL(hw->port),
1902 pf->offset_loaded, &os->eth.rx_multicast,
1903 &ns->eth.rx_multicast);
1904 i40e_stat_update_48(hw, I40E_GLPRT_BPRCH(hw->port),
1905 I40E_GLPRT_BPRCL(hw->port),
1906 pf->offset_loaded, &os->eth.rx_broadcast,
1907 &ns->eth.rx_broadcast);
1908 /* Workaround: CRC size should not be included in byte statistics,
1909 * so subtract ETHER_CRC_LEN from the byte counter for each rx packet.
1911 ns->eth.rx_bytes -= (ns->eth.rx_unicast + ns->eth.rx_multicast +
1912 ns->eth.rx_broadcast) * ETHER_CRC_LEN;
1914 i40e_stat_update_32(hw, I40E_GLPRT_RDPC(hw->port),
1915 pf->offset_loaded, &os->eth.rx_discards,
1916 &ns->eth.rx_discards);
1917 /* GLPRT_REPC not supported */
1918 /* GLPRT_RMPC not supported */
1919 i40e_stat_update_32(hw, I40E_GLPRT_RUPP(hw->port),
1921 &os->eth.rx_unknown_protocol,
1922 &ns->eth.rx_unknown_protocol);
1923 i40e_stat_update_48(hw, I40E_GLPRT_GOTCH(hw->port),
1924 I40E_GLPRT_GOTCL(hw->port),
1925 pf->offset_loaded, &os->eth.tx_bytes,
1927 i40e_stat_update_48(hw, I40E_GLPRT_UPTCH(hw->port),
1928 I40E_GLPRT_UPTCL(hw->port),
1929 pf->offset_loaded, &os->eth.tx_unicast,
1930 &ns->eth.tx_unicast);
1931 i40e_stat_update_48(hw, I40E_GLPRT_MPTCH(hw->port),
1932 I40E_GLPRT_MPTCL(hw->port),
1933 pf->offset_loaded, &os->eth.tx_multicast,
1934 &ns->eth.tx_multicast);
1935 i40e_stat_update_48(hw, I40E_GLPRT_BPTCH(hw->port),
1936 I40E_GLPRT_BPTCL(hw->port),
1937 pf->offset_loaded, &os->eth.tx_broadcast,
1938 &ns->eth.tx_broadcast);
1939 ns->eth.tx_bytes -= (ns->eth.tx_unicast + ns->eth.tx_multicast +
1940 ns->eth.tx_broadcast) * ETHER_CRC_LEN;
1941 /* GLPRT_TEPC not supported */
1943 /* additional port specific stats */
1944 i40e_stat_update_32(hw, I40E_GLPRT_TDOLD(hw->port),
1945 pf->offset_loaded, &os->tx_dropped_link_down,
1946 &ns->tx_dropped_link_down);
1947 i40e_stat_update_32(hw, I40E_GLPRT_CRCERRS(hw->port),
1948 pf->offset_loaded, &os->crc_errors,
1950 i40e_stat_update_32(hw, I40E_GLPRT_ILLERRC(hw->port),
1951 pf->offset_loaded, &os->illegal_bytes,
1952 &ns->illegal_bytes);
1953 /* GLPRT_ERRBC not supported */
1954 i40e_stat_update_32(hw, I40E_GLPRT_MLFC(hw->port),
1955 pf->offset_loaded, &os->mac_local_faults,
1956 &ns->mac_local_faults);
1957 i40e_stat_update_32(hw, I40E_GLPRT_MRFC(hw->port),
1958 pf->offset_loaded, &os->mac_remote_faults,
1959 &ns->mac_remote_faults);
1960 i40e_stat_update_32(hw, I40E_GLPRT_RLEC(hw->port),
1961 pf->offset_loaded, &os->rx_length_errors,
1962 &ns->rx_length_errors);
1963 i40e_stat_update_32(hw, I40E_GLPRT_LXONRXC(hw->port),
1964 pf->offset_loaded, &os->link_xon_rx,
1966 i40e_stat_update_32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
1967 pf->offset_loaded, &os->link_xoff_rx,
1969 for (i = 0; i < 8; i++) {
1970 i40e_stat_update_32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
1972 &os->priority_xon_rx[i],
1973 &ns->priority_xon_rx[i]);
1974 i40e_stat_update_32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
1976 &os->priority_xoff_rx[i],
1977 &ns->priority_xoff_rx[i]);
1979 i40e_stat_update_32(hw, I40E_GLPRT_LXONTXC(hw->port),
1980 pf->offset_loaded, &os->link_xon_tx,
1982 i40e_stat_update_32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
1983 pf->offset_loaded, &os->link_xoff_tx,
1985 for (i = 0; i < 8; i++) {
1986 i40e_stat_update_32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
1988 &os->priority_xon_tx[i],
1989 &ns->priority_xon_tx[i]);
1990 i40e_stat_update_32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
1992 &os->priority_xoff_tx[i],
1993 &ns->priority_xoff_tx[i]);
1994 i40e_stat_update_32(hw, I40E_GLPRT_RXON2OFFCNT(hw->port, i),
1996 &os->priority_xon_2_xoff[i],
1997 &ns->priority_xon_2_xoff[i]);
1999 i40e_stat_update_48(hw, I40E_GLPRT_PRC64H(hw->port),
2000 I40E_GLPRT_PRC64L(hw->port),
2001 pf->offset_loaded, &os->rx_size_64,
2003 i40e_stat_update_48(hw, I40E_GLPRT_PRC127H(hw->port),
2004 I40E_GLPRT_PRC127L(hw->port),
2005 pf->offset_loaded, &os->rx_size_127,
2007 i40e_stat_update_48(hw, I40E_GLPRT_PRC255H(hw->port),
2008 I40E_GLPRT_PRC255L(hw->port),
2009 pf->offset_loaded, &os->rx_size_255,
2011 i40e_stat_update_48(hw, I40E_GLPRT_PRC511H(hw->port),
2012 I40E_GLPRT_PRC511L(hw->port),
2013 pf->offset_loaded, &os->rx_size_511,
2015 i40e_stat_update_48(hw, I40E_GLPRT_PRC1023H(hw->port),
2016 I40E_GLPRT_PRC1023L(hw->port),
2017 pf->offset_loaded, &os->rx_size_1023,
2019 i40e_stat_update_48(hw, I40E_GLPRT_PRC1522H(hw->port),
2020 I40E_GLPRT_PRC1522L(hw->port),
2021 pf->offset_loaded, &os->rx_size_1522,
2023 i40e_stat_update_48(hw, I40E_GLPRT_PRC9522H(hw->port),
2024 I40E_GLPRT_PRC9522L(hw->port),
2025 pf->offset_loaded, &os->rx_size_big,
2027 i40e_stat_update_32(hw, I40E_GLPRT_RUC(hw->port),
2028 pf->offset_loaded, &os->rx_undersize,
2030 i40e_stat_update_32(hw, I40E_GLPRT_RFC(hw->port),
2031 pf->offset_loaded, &os->rx_fragments,
2033 i40e_stat_update_32(hw, I40E_GLPRT_ROC(hw->port),
2034 pf->offset_loaded, &os->rx_oversize,
2036 i40e_stat_update_32(hw, I40E_GLPRT_RJC(hw->port),
2037 pf->offset_loaded, &os->rx_jabber,
2039 i40e_stat_update_48(hw, I40E_GLPRT_PTC64H(hw->port),
2040 I40E_GLPRT_PTC64L(hw->port),
2041 pf->offset_loaded, &os->tx_size_64,
2043 i40e_stat_update_48(hw, I40E_GLPRT_PTC127H(hw->port),
2044 I40E_GLPRT_PTC127L(hw->port),
2045 pf->offset_loaded, &os->tx_size_127,
2047 i40e_stat_update_48(hw, I40E_GLPRT_PTC255H(hw->port),
2048 I40E_GLPRT_PTC255L(hw->port),
2049 pf->offset_loaded, &os->tx_size_255,
2051 i40e_stat_update_48(hw, I40E_GLPRT_PTC511H(hw->port),
2052 I40E_GLPRT_PTC511L(hw->port),
2053 pf->offset_loaded, &os->tx_size_511,
2055 i40e_stat_update_48(hw, I40E_GLPRT_PTC1023H(hw->port),
2056 I40E_GLPRT_PTC1023L(hw->port),
2057 pf->offset_loaded, &os->tx_size_1023,
2059 i40e_stat_update_48(hw, I40E_GLPRT_PTC1522H(hw->port),
2060 I40E_GLPRT_PTC1522L(hw->port),
2061 pf->offset_loaded, &os->tx_size_1522,
2063 i40e_stat_update_48(hw, I40E_GLPRT_PTC9522H(hw->port),
2064 I40E_GLPRT_PTC9522L(hw->port),
2065 pf->offset_loaded, &os->tx_size_big,
2067 i40e_stat_update_32(hw, I40E_GLQF_PCNT(pf->fdir.match_counter_index),
2069 &os->fd_sb_match, &ns->fd_sb_match);
2070 /* GLPRT_MSPDC not supported */
2071 /* GLPRT_XEC not supported */
2073 pf->offset_loaded = true;
2076 i40e_update_vsi_stats(pf->main_vsi);
2079 /* Get all statistics of a port */
2081 i40e_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
2083 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2084 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2085 struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
2088 /* call read registers - updates values, now write them to struct */
2089 i40e_read_stats_registers(pf, hw);
2091 stats->ipackets = pf->main_vsi->eth_stats.rx_unicast +
2092 pf->main_vsi->eth_stats.rx_multicast +
2093 pf->main_vsi->eth_stats.rx_broadcast -
2094 pf->main_vsi->eth_stats.rx_discards;
2095 stats->opackets = pf->main_vsi->eth_stats.tx_unicast +
2096 pf->main_vsi->eth_stats.tx_multicast +
2097 pf->main_vsi->eth_stats.tx_broadcast;
2098 stats->ibytes = ns->eth.rx_bytes;
2099 stats->obytes = ns->eth.tx_bytes;
2100 stats->oerrors = ns->eth.tx_errors +
2101 pf->main_vsi->eth_stats.tx_errors;
2102 stats->imcasts = pf->main_vsi->eth_stats.rx_multicast;
2105 stats->imissed = ns->eth.rx_discards +
2106 pf->main_vsi->eth_stats.rx_discards;
2107 stats->ierrors = ns->crc_errors +
2108 ns->rx_length_errors + ns->rx_undersize +
2109 ns->rx_oversize + ns->rx_fragments + ns->rx_jabber;
2111 PMD_DRV_LOG(DEBUG, "***************** PF stats start *******************");
2112 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", ns->eth.rx_bytes);
2113 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", ns->eth.rx_unicast);
2114 PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", ns->eth.rx_multicast);
2115 PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", ns->eth.rx_broadcast);
2116 PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", ns->eth.rx_discards);
2117 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
2118 ns->eth.rx_unknown_protocol);
2119 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", ns->eth.tx_bytes);
2120 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", ns->eth.tx_unicast);
2121 PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", ns->eth.tx_multicast);
2122 PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", ns->eth.tx_broadcast);
2123 PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", ns->eth.tx_discards);
2124 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", ns->eth.tx_errors);
2126 PMD_DRV_LOG(DEBUG, "tx_dropped_link_down: %"PRIu64"",
2127 ns->tx_dropped_link_down);
2128 PMD_DRV_LOG(DEBUG, "crc_errors: %"PRIu64"", ns->crc_errors);
2129 PMD_DRV_LOG(DEBUG, "illegal_bytes: %"PRIu64"",
2131 PMD_DRV_LOG(DEBUG, "error_bytes: %"PRIu64"", ns->error_bytes);
2132 PMD_DRV_LOG(DEBUG, "mac_local_faults: %"PRIu64"",
2133 ns->mac_local_faults);
2134 PMD_DRV_LOG(DEBUG, "mac_remote_faults: %"PRIu64"",
2135 ns->mac_remote_faults);
2136 PMD_DRV_LOG(DEBUG, "rx_length_errors: %"PRIu64"",
2137 ns->rx_length_errors);
2138 PMD_DRV_LOG(DEBUG, "link_xon_rx: %"PRIu64"", ns->link_xon_rx);
2139 PMD_DRV_LOG(DEBUG, "link_xoff_rx: %"PRIu64"", ns->link_xoff_rx);
2140 for (i = 0; i < 8; i++) {
2141 PMD_DRV_LOG(DEBUG, "priority_xon_rx[%d]: %"PRIu64"",
2142 i, ns->priority_xon_rx[i]);
2143 PMD_DRV_LOG(DEBUG, "priority_xoff_rx[%d]: %"PRIu64"",
2144 i, ns->priority_xoff_rx[i]);
2146 PMD_DRV_LOG(DEBUG, "link_xon_tx: %"PRIu64"", ns->link_xon_tx);
2147 PMD_DRV_LOG(DEBUG, "link_xoff_tx: %"PRIu64"", ns->link_xoff_tx);
2148 for (i = 0; i < 8; i++) {
2149 PMD_DRV_LOG(DEBUG, "priority_xon_tx[%d]: %"PRIu64"",
2150 i, ns->priority_xon_tx[i]);
2151 PMD_DRV_LOG(DEBUG, "priority_xoff_tx[%d]: %"PRIu64"",
2152 i, ns->priority_xoff_tx[i]);
2153 PMD_DRV_LOG(DEBUG, "priority_xon_2_xoff[%d]: %"PRIu64"",
2154 i, ns->priority_xon_2_xoff[i]);
2156 PMD_DRV_LOG(DEBUG, "rx_size_64: %"PRIu64"", ns->rx_size_64);
2157 PMD_DRV_LOG(DEBUG, "rx_size_127: %"PRIu64"", ns->rx_size_127);
2158 PMD_DRV_LOG(DEBUG, "rx_size_255: %"PRIu64"", ns->rx_size_255);
2159 PMD_DRV_LOG(DEBUG, "rx_size_511: %"PRIu64"", ns->rx_size_511);
2160 PMD_DRV_LOG(DEBUG, "rx_size_1023: %"PRIu64"", ns->rx_size_1023);
2161 PMD_DRV_LOG(DEBUG, "rx_size_1522: %"PRIu64"", ns->rx_size_1522);
2162 PMD_DRV_LOG(DEBUG, "rx_size_big: %"PRIu64"", ns->rx_size_big);
2163 PMD_DRV_LOG(DEBUG, "rx_undersize: %"PRIu64"", ns->rx_undersize);
2164 PMD_DRV_LOG(DEBUG, "rx_fragments: %"PRIu64"", ns->rx_fragments);
2165 PMD_DRV_LOG(DEBUG, "rx_oversize: %"PRIu64"", ns->rx_oversize);
2166 PMD_DRV_LOG(DEBUG, "rx_jabber: %"PRIu64"", ns->rx_jabber);
2167 PMD_DRV_LOG(DEBUG, "tx_size_64: %"PRIu64"", ns->tx_size_64);
2168 PMD_DRV_LOG(DEBUG, "tx_size_127: %"PRIu64"", ns->tx_size_127);
2169 PMD_DRV_LOG(DEBUG, "tx_size_255: %"PRIu64"", ns->tx_size_255);
2170 PMD_DRV_LOG(DEBUG, "tx_size_511: %"PRIu64"", ns->tx_size_511);
2171 PMD_DRV_LOG(DEBUG, "tx_size_1023: %"PRIu64"", ns->tx_size_1023);
2172 PMD_DRV_LOG(DEBUG, "tx_size_1522: %"PRIu64"", ns->tx_size_1522);
2173 PMD_DRV_LOG(DEBUG, "tx_size_big: %"PRIu64"", ns->tx_size_big);
2174 PMD_DRV_LOG(DEBUG, "mac_short_packet_dropped: %"PRIu64"",
2175 ns->mac_short_packet_dropped);
2176 PMD_DRV_LOG(DEBUG, "checksum_error: %"PRIu64"",
2177 ns->checksum_error);
2178 PMD_DRV_LOG(DEBUG, "fdir_match: %"PRIu64"", ns->fd_sb_match);
2179 PMD_DRV_LOG(DEBUG, "***************** PF stats end ********************");
2182 /* Reset the statistics */
2184 i40e_dev_stats_reset(struct rte_eth_dev *dev)
2186 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2187 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2189 /* Mark PF and VSI stats to update the offset, aka "reset" */
2190 pf->offset_loaded = false;
2192 pf->main_vsi->offset_loaded = false;
2194 /* read the stats, reading current register values into offset */
2195 i40e_read_stats_registers(pf, hw);
2199 i40e_xstats_calc_num(void)
2201 return I40E_NB_ETH_XSTATS + I40E_NB_HW_PORT_XSTATS +
2202 (I40E_NB_RXQ_PRIO_XSTATS * 8) +
2203 (I40E_NB_TXQ_PRIO_XSTATS * 8);
2207 i40e_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstats *xstats,
2210 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2211 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2212 unsigned i, count, prio;
2213 struct i40e_hw_port_stats *hw_stats = &pf->stats;
2215 count = i40e_xstats_calc_num();
2219 i40e_read_stats_registers(pf, hw);
2226 /* Get stats from i40e_eth_stats struct */
2227 for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
2228 snprintf(xstats[count].name, sizeof(xstats[count].name),
2229 "%s", rte_i40e_stats_strings[i].name);
2230 xstats[count].value = *(uint64_t *)(((char *)&hw_stats->eth) +
2231 rte_i40e_stats_strings[i].offset);
2235 /* Get individiual stats from i40e_hw_port struct */
2236 for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
2237 snprintf(xstats[count].name, sizeof(xstats[count].name),
2238 "%s", rte_i40e_hw_port_strings[i].name);
2239 xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
2240 rte_i40e_hw_port_strings[i].offset);
2244 for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
2245 for (prio = 0; prio < 8; prio++) {
2246 snprintf(xstats[count].name,
2247 sizeof(xstats[count].name),
2248 "rx_priority%u_%s", prio,
2249 rte_i40e_rxq_prio_strings[i].name);
2250 xstats[count].value =
2251 *(uint64_t *)(((char *)hw_stats) +
2252 rte_i40e_rxq_prio_strings[i].offset +
2253 (sizeof(uint64_t) * prio));
2258 for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
2259 for (prio = 0; prio < 8; prio++) {
2260 snprintf(xstats[count].name,
2261 sizeof(xstats[count].name),
2262 "tx_priority%u_%s", prio,
2263 rte_i40e_txq_prio_strings[i].name);
2264 xstats[count].value =
2265 *(uint64_t *)(((char *)hw_stats) +
2266 rte_i40e_txq_prio_strings[i].offset +
2267 (sizeof(uint64_t) * prio));
2276 i40e_dev_queue_stats_mapping_set(__rte_unused struct rte_eth_dev *dev,
2277 __rte_unused uint16_t queue_id,
2278 __rte_unused uint8_t stat_idx,
2279 __rte_unused uint8_t is_rx)
2281 PMD_INIT_FUNC_TRACE();
2287 i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2289 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2290 struct i40e_vsi *vsi = pf->main_vsi;
2292 dev_info->max_rx_queues = vsi->nb_qps;
2293 dev_info->max_tx_queues = vsi->nb_qps;
2294 dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
2295 dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
2296 dev_info->max_mac_addrs = vsi->max_macaddrs;
2297 dev_info->max_vfs = dev->pci_dev->max_vfs;
2298 dev_info->rx_offload_capa =
2299 DEV_RX_OFFLOAD_VLAN_STRIP |
2300 DEV_RX_OFFLOAD_QINQ_STRIP |
2301 DEV_RX_OFFLOAD_IPV4_CKSUM |
2302 DEV_RX_OFFLOAD_UDP_CKSUM |
2303 DEV_RX_OFFLOAD_TCP_CKSUM;
2304 dev_info->tx_offload_capa =
2305 DEV_TX_OFFLOAD_VLAN_INSERT |
2306 DEV_TX_OFFLOAD_QINQ_INSERT |
2307 DEV_TX_OFFLOAD_IPV4_CKSUM |
2308 DEV_TX_OFFLOAD_UDP_CKSUM |
2309 DEV_TX_OFFLOAD_TCP_CKSUM |
2310 DEV_TX_OFFLOAD_SCTP_CKSUM |
2311 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
2312 DEV_TX_OFFLOAD_TCP_TSO;
2313 dev_info->hash_key_size = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
2315 dev_info->reta_size = pf->hash_lut_size;
2316 dev_info->flow_type_rss_offloads = I40E_RSS_OFFLOAD_ALL;
2318 dev_info->default_rxconf = (struct rte_eth_rxconf) {
2320 .pthresh = I40E_DEFAULT_RX_PTHRESH,
2321 .hthresh = I40E_DEFAULT_RX_HTHRESH,
2322 .wthresh = I40E_DEFAULT_RX_WTHRESH,
2324 .rx_free_thresh = I40E_DEFAULT_RX_FREE_THRESH,
2328 dev_info->default_txconf = (struct rte_eth_txconf) {
2330 .pthresh = I40E_DEFAULT_TX_PTHRESH,
2331 .hthresh = I40E_DEFAULT_TX_HTHRESH,
2332 .wthresh = I40E_DEFAULT_TX_WTHRESH,
2334 .tx_free_thresh = I40E_DEFAULT_TX_FREE_THRESH,
2335 .tx_rs_thresh = I40E_DEFAULT_TX_RSBIT_THRESH,
2336 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
2337 ETH_TXQ_FLAGS_NOOFFLOADS,
2340 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
2341 .nb_max = I40E_MAX_RING_DESC,
2342 .nb_min = I40E_MIN_RING_DESC,
2343 .nb_align = I40E_ALIGN_RING_DESC,
2346 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
2347 .nb_max = I40E_MAX_RING_DESC,
2348 .nb_min = I40E_MIN_RING_DESC,
2349 .nb_align = I40E_ALIGN_RING_DESC,
2352 if (pf->flags & I40E_FLAG_VMDQ) {
2353 dev_info->max_vmdq_pools = pf->max_nb_vmdq_vsi;
2354 dev_info->vmdq_queue_base = dev_info->max_rx_queues;
2355 dev_info->vmdq_queue_num = pf->vmdq_nb_qps *
2356 pf->max_nb_vmdq_vsi;
2357 dev_info->vmdq_pool_base = I40E_VMDQ_POOL_BASE;
2358 dev_info->max_rx_queues += dev_info->vmdq_queue_num;
2359 dev_info->max_tx_queues += dev_info->vmdq_queue_num;
2364 i40e_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
2366 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2367 struct i40e_vsi *vsi = pf->main_vsi;
2368 PMD_INIT_FUNC_TRACE();
2371 return i40e_vsi_add_vlan(vsi, vlan_id);
2373 return i40e_vsi_delete_vlan(vsi, vlan_id);
2377 i40e_vlan_tpid_set(struct rte_eth_dev *dev,
2378 enum rte_vlan_type vlan_type,
2381 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2382 uint64_t reg_r = 0, reg_w = 0;
2383 uint16_t reg_id = 0;
2386 switch (vlan_type) {
2387 case ETH_VLAN_TYPE_OUTER:
2390 case ETH_VLAN_TYPE_INNER:
2395 PMD_DRV_LOG(ERR, "Unsupported vlan type %d", vlan_type);
2398 ret = i40e_aq_debug_read_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
2400 if (ret != I40E_SUCCESS) {
2401 PMD_DRV_LOG(ERR, "Fail to debug read from "
2402 "I40E_GL_SWT_L2TAGCTRL[%d]", reg_id);
2406 PMD_DRV_LOG(DEBUG, "Debug read from I40E_GL_SWT_L2TAGCTRL[%d]: "
2407 "0x%08"PRIx64"", reg_id, reg_r);
2409 reg_w = reg_r & (~(I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_MASK));
2410 reg_w |= ((uint64_t)tpid << I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT);
2411 if (reg_r == reg_w) {
2413 PMD_DRV_LOG(DEBUG, "No need to write");
2417 ret = i40e_aq_debug_write_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
2419 if (ret != I40E_SUCCESS) {
2421 PMD_DRV_LOG(ERR, "Fail to debug write to "
2422 "I40E_GL_SWT_L2TAGCTRL[%d]", reg_id);
2425 PMD_DRV_LOG(DEBUG, "Debug write 0x%08"PRIx64" to "
2426 "I40E_GL_SWT_L2TAGCTRL[%d]", reg_w, reg_id);
2432 i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask)
2434 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2435 struct i40e_vsi *vsi = pf->main_vsi;
2437 if (mask & ETH_VLAN_FILTER_MASK) {
2438 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
2439 i40e_vsi_config_vlan_filter(vsi, TRUE);
2441 i40e_vsi_config_vlan_filter(vsi, FALSE);
2444 if (mask & ETH_VLAN_STRIP_MASK) {
2445 /* Enable or disable VLAN stripping */
2446 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
2447 i40e_vsi_config_vlan_stripping(vsi, TRUE);
2449 i40e_vsi_config_vlan_stripping(vsi, FALSE);
2452 if (mask & ETH_VLAN_EXTEND_MASK) {
2453 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
2454 i40e_vsi_config_double_vlan(vsi, TRUE);
2456 i40e_vsi_config_double_vlan(vsi, FALSE);
2461 i40e_vlan_strip_queue_set(__rte_unused struct rte_eth_dev *dev,
2462 __rte_unused uint16_t queue,
2463 __rte_unused int on)
2465 PMD_INIT_FUNC_TRACE();
2469 i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
2471 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2472 struct i40e_vsi *vsi = pf->main_vsi;
2473 struct rte_eth_dev_data *data = I40E_VSI_TO_DEV_DATA(vsi);
2474 struct i40e_vsi_vlan_pvid_info info;
2476 memset(&info, 0, sizeof(info));
2479 info.config.pvid = pvid;
2481 info.config.reject.tagged =
2482 data->dev_conf.txmode.hw_vlan_reject_tagged;
2483 info.config.reject.untagged =
2484 data->dev_conf.txmode.hw_vlan_reject_untagged;
2487 return i40e_vsi_vlan_pvid_set(vsi, &info);
2491 i40e_dev_led_on(struct rte_eth_dev *dev)
2493 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2494 uint32_t mode = i40e_led_get(hw);
2497 i40e_led_set(hw, 0xf, true); /* 0xf means led always true */
2503 i40e_dev_led_off(struct rte_eth_dev *dev)
2505 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2506 uint32_t mode = i40e_led_get(hw);
2509 i40e_led_set(hw, 0, false);
2515 i40e_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2517 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2518 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2520 fc_conf->pause_time = pf->fc_conf.pause_time;
2521 fc_conf->high_water = pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS];
2522 fc_conf->low_water = pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS];
2524 /* Return current mode according to actual setting*/
2525 switch (hw->fc.current_mode) {
2527 fc_conf->mode = RTE_FC_FULL;
2529 case I40E_FC_TX_PAUSE:
2530 fc_conf->mode = RTE_FC_TX_PAUSE;
2532 case I40E_FC_RX_PAUSE:
2533 fc_conf->mode = RTE_FC_RX_PAUSE;
2537 fc_conf->mode = RTE_FC_NONE;
2544 i40e_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2546 uint32_t mflcn_reg, fctrl_reg, reg;
2547 uint32_t max_high_water;
2548 uint8_t i, aq_failure;
2552 enum i40e_fc_mode rte_fcmode_2_i40e_fcmode[] = {
2553 [RTE_FC_NONE] = I40E_FC_NONE,
2554 [RTE_FC_RX_PAUSE] = I40E_FC_RX_PAUSE,
2555 [RTE_FC_TX_PAUSE] = I40E_FC_TX_PAUSE,
2556 [RTE_FC_FULL] = I40E_FC_FULL
2559 /* high_water field in the rte_eth_fc_conf using the kilobytes unit */
2561 max_high_water = I40E_RXPBSIZE >> I40E_KILOSHIFT;
2562 if ((fc_conf->high_water > max_high_water) ||
2563 (fc_conf->high_water < fc_conf->low_water)) {
2564 PMD_INIT_LOG(ERR, "Invalid high/low water setup value in KB, "
2565 "High_water must <= %d.", max_high_water);
2569 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2570 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2571 hw->fc.requested_mode = rte_fcmode_2_i40e_fcmode[fc_conf->mode];
2573 pf->fc_conf.pause_time = fc_conf->pause_time;
2574 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->high_water;
2575 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->low_water;
2577 PMD_INIT_FUNC_TRACE();
2579 /* All the link flow control related enable/disable register
2580 * configuration is handle by the F/W
2582 err = i40e_set_fc(hw, &aq_failure, true);
2586 if (i40e_is_40G_device(hw->device_id)) {
2587 /* Configure flow control refresh threshold,
2588 * the value for stat_tx_pause_refresh_timer[8]
2589 * is used for global pause operation.
2593 I40E_PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER(8),
2594 pf->fc_conf.pause_time);
2596 /* configure the timer value included in transmitted pause
2598 * the value for stat_tx_pause_quanta[8] is used for global
2601 I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA(8),
2602 pf->fc_conf.pause_time);
2604 fctrl_reg = I40E_READ_REG(hw,
2605 I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL);
2607 if (fc_conf->mac_ctrl_frame_fwd != 0)
2608 fctrl_reg |= I40E_PRTMAC_FWD_CTRL;
2610 fctrl_reg &= ~I40E_PRTMAC_FWD_CTRL;
2612 I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL,
2615 /* Configure pause time (2 TCs per register) */
2616 reg = (uint32_t)pf->fc_conf.pause_time * (uint32_t)0x00010001;
2617 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS / 2; i++)
2618 I40E_WRITE_REG(hw, I40E_PRTDCB_FCTTVN(i), reg);
2620 /* Configure flow control refresh threshold value */
2621 I40E_WRITE_REG(hw, I40E_PRTDCB_FCRTV,
2622 pf->fc_conf.pause_time / 2);
2624 mflcn_reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
2626 /* set or clear MFLCN.PMCF & MFLCN.DPF bits
2627 *depending on configuration
2629 if (fc_conf->mac_ctrl_frame_fwd != 0) {
2630 mflcn_reg |= I40E_PRTDCB_MFLCN_PMCF_MASK;
2631 mflcn_reg &= ~I40E_PRTDCB_MFLCN_DPF_MASK;
2633 mflcn_reg &= ~I40E_PRTDCB_MFLCN_PMCF_MASK;
2634 mflcn_reg |= I40E_PRTDCB_MFLCN_DPF_MASK;
2637 I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, mflcn_reg);
2640 /* config the water marker both based on the packets and bytes */
2641 I40E_WRITE_REG(hw, I40E_GLRPB_PHW,
2642 (pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
2643 << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
2644 I40E_WRITE_REG(hw, I40E_GLRPB_PLW,
2645 (pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
2646 << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
2647 I40E_WRITE_REG(hw, I40E_GLRPB_GHW,
2648 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
2650 I40E_WRITE_REG(hw, I40E_GLRPB_GLW,
2651 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
2654 I40E_WRITE_FLUSH(hw);
2660 i40e_priority_flow_ctrl_set(__rte_unused struct rte_eth_dev *dev,
2661 __rte_unused struct rte_eth_pfc_conf *pfc_conf)
2663 PMD_INIT_FUNC_TRACE();
2668 /* Add a MAC address, and update filters */
2670 i40e_macaddr_add(struct rte_eth_dev *dev,
2671 struct ether_addr *mac_addr,
2672 __rte_unused uint32_t index,
2675 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2676 struct i40e_mac_filter_info mac_filter;
2677 struct i40e_vsi *vsi;
2680 /* If VMDQ not enabled or configured, return */
2681 if (pool != 0 && (!(pf->flags | I40E_FLAG_VMDQ) || !pf->nb_cfg_vmdq_vsi)) {
2682 PMD_DRV_LOG(ERR, "VMDQ not %s, can't set mac to pool %u",
2683 pf->flags | I40E_FLAG_VMDQ ? "configured" : "enabled",
2688 if (pool > pf->nb_cfg_vmdq_vsi) {
2689 PMD_DRV_LOG(ERR, "Pool number %u invalid. Max pool is %u",
2690 pool, pf->nb_cfg_vmdq_vsi);
2694 (void)rte_memcpy(&mac_filter.mac_addr, mac_addr, ETHER_ADDR_LEN);
2695 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
2696 mac_filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
2698 mac_filter.filter_type = RTE_MAC_PERFECT_MATCH;
2703 vsi = pf->vmdq[pool - 1].vsi;
2705 ret = i40e_vsi_add_mac(vsi, &mac_filter);
2706 if (ret != I40E_SUCCESS) {
2707 PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
2712 /* Remove a MAC address, and update filters */
2714 i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
2716 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2717 struct i40e_vsi *vsi;
2718 struct rte_eth_dev_data *data = dev->data;
2719 struct ether_addr *macaddr;
2724 macaddr = &(data->mac_addrs[index]);
2726 pool_sel = dev->data->mac_pool_sel[index];
2728 for (i = 0; i < sizeof(pool_sel) * CHAR_BIT; i++) {
2729 if (pool_sel & (1ULL << i)) {
2733 /* No VMDQ pool enabled or configured */
2734 if (!(pf->flags | I40E_FLAG_VMDQ) ||
2735 (i > pf->nb_cfg_vmdq_vsi)) {
2736 PMD_DRV_LOG(ERR, "No VMDQ pool enabled"
2740 vsi = pf->vmdq[i - 1].vsi;
2742 ret = i40e_vsi_delete_mac(vsi, macaddr);
2745 PMD_DRV_LOG(ERR, "Failed to remove MACVLAN filter");
2752 /* Set perfect match or hash match of MAC and VLAN for a VF */
2754 i40e_vf_mac_filter_set(struct i40e_pf *pf,
2755 struct rte_eth_mac_filter *filter,
2759 struct i40e_mac_filter_info mac_filter;
2760 struct ether_addr old_mac;
2761 struct ether_addr *new_mac;
2762 struct i40e_pf_vf *vf = NULL;
2767 PMD_DRV_LOG(ERR, "Invalid PF argument.");
2770 hw = I40E_PF_TO_HW(pf);
2772 if (filter == NULL) {
2773 PMD_DRV_LOG(ERR, "Invalid mac filter argument.");
2777 new_mac = &filter->mac_addr;
2779 if (is_zero_ether_addr(new_mac)) {
2780 PMD_DRV_LOG(ERR, "Invalid ethernet address.");
2784 vf_id = filter->dst_id;
2786 if (vf_id > pf->vf_num - 1 || !pf->vfs) {
2787 PMD_DRV_LOG(ERR, "Invalid argument.");
2790 vf = &pf->vfs[vf_id];
2792 if (add && is_same_ether_addr(new_mac, &(pf->dev_addr))) {
2793 PMD_DRV_LOG(INFO, "Ignore adding permanent MAC address.");
2798 (void)rte_memcpy(&old_mac, hw->mac.addr, ETHER_ADDR_LEN);
2799 (void)rte_memcpy(hw->mac.addr, new_mac->addr_bytes,
2801 (void)rte_memcpy(&mac_filter.mac_addr, &filter->mac_addr,
2804 mac_filter.filter_type = filter->filter_type;
2805 ret = i40e_vsi_add_mac(vf->vsi, &mac_filter);
2806 if (ret != I40E_SUCCESS) {
2807 PMD_DRV_LOG(ERR, "Failed to add MAC filter.");
2810 ether_addr_copy(new_mac, &pf->dev_addr);
2812 (void)rte_memcpy(hw->mac.addr, hw->mac.perm_addr,
2814 ret = i40e_vsi_delete_mac(vf->vsi, &filter->mac_addr);
2815 if (ret != I40E_SUCCESS) {
2816 PMD_DRV_LOG(ERR, "Failed to delete MAC filter.");
2820 /* Clear device address as it has been removed */
2821 if (is_same_ether_addr(&(pf->dev_addr), new_mac))
2822 memset(&pf->dev_addr, 0, sizeof(struct ether_addr));
2828 /* MAC filter handle */
2830 i40e_mac_filter_handle(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
2833 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2834 struct rte_eth_mac_filter *filter;
2835 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
2836 int ret = I40E_NOT_SUPPORTED;
2838 filter = (struct rte_eth_mac_filter *)(arg);
2840 switch (filter_op) {
2841 case RTE_ETH_FILTER_NOP:
2844 case RTE_ETH_FILTER_ADD:
2845 i40e_pf_disable_irq0(hw);
2847 ret = i40e_vf_mac_filter_set(pf, filter, 1);
2848 i40e_pf_enable_irq0(hw);
2850 case RTE_ETH_FILTER_DELETE:
2851 i40e_pf_disable_irq0(hw);
2853 ret = i40e_vf_mac_filter_set(pf, filter, 0);
2854 i40e_pf_enable_irq0(hw);
2857 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
2858 ret = I40E_ERR_PARAM;
2866 i40e_get_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
2868 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2869 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2875 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
2876 ret = i40e_aq_get_rss_lut(hw, vsi->vsi_id, TRUE,
2879 PMD_DRV_LOG(ERR, "Failed to get RSS lookup table");
2883 uint32_t *lut_dw = (uint32_t *)lut;
2884 uint16_t i, lut_size_dw = lut_size / 4;
2886 for (i = 0; i < lut_size_dw; i++)
2887 lut_dw[i] = I40E_READ_REG(hw, I40E_PFQF_HLUT(i));
2894 i40e_set_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
2896 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2897 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2903 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
2904 ret = i40e_aq_set_rss_lut(hw, vsi->vsi_id, TRUE,
2907 PMD_DRV_LOG(ERR, "Failed to set RSS lookup table");
2911 uint32_t *lut_dw = (uint32_t *)lut;
2912 uint16_t i, lut_size_dw = lut_size / 4;
2914 for (i = 0; i < lut_size_dw; i++)
2915 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
2916 I40E_WRITE_FLUSH(hw);
2923 i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
2924 struct rte_eth_rss_reta_entry64 *reta_conf,
2927 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2928 uint16_t i, lut_size = pf->hash_lut_size;
2929 uint16_t idx, shift;
2933 if (reta_size != lut_size ||
2934 reta_size > ETH_RSS_RETA_SIZE_512) {
2935 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2936 "(%d) doesn't match the number hardware can supported "
2937 "(%d)\n", reta_size, lut_size);
2941 lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
2943 PMD_DRV_LOG(ERR, "No memory can be allocated");
2946 ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
2949 for (i = 0; i < reta_size; i++) {
2950 idx = i / RTE_RETA_GROUP_SIZE;
2951 shift = i % RTE_RETA_GROUP_SIZE;
2952 if (reta_conf[idx].mask & (1ULL << shift))
2953 lut[i] = reta_conf[idx].reta[shift];
2955 ret = i40e_set_rss_lut(pf->main_vsi, lut, reta_size);
2964 i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
2965 struct rte_eth_rss_reta_entry64 *reta_conf,
2968 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2969 uint16_t i, lut_size = pf->hash_lut_size;
2970 uint16_t idx, shift;
2974 if (reta_size != lut_size ||
2975 reta_size > ETH_RSS_RETA_SIZE_512) {
2976 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2977 "(%d) doesn't match the number hardware can supported "
2978 "(%d)\n", reta_size, lut_size);
2982 lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
2984 PMD_DRV_LOG(ERR, "No memory can be allocated");
2988 ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
2991 for (i = 0; i < reta_size; i++) {
2992 idx = i / RTE_RETA_GROUP_SIZE;
2993 shift = i % RTE_RETA_GROUP_SIZE;
2994 if (reta_conf[idx].mask & (1ULL << shift))
2995 reta_conf[idx].reta[shift] = lut[i];
3005 * i40e_allocate_dma_mem_d - specific memory alloc for shared code (base driver)
3006 * @hw: pointer to the HW structure
3007 * @mem: pointer to mem struct to fill out
3008 * @size: size of memory requested
3009 * @alignment: what to align the allocation to
3011 enum i40e_status_code
3012 i40e_allocate_dma_mem_d(__attribute__((unused)) struct i40e_hw *hw,
3013 struct i40e_dma_mem *mem,
3017 const struct rte_memzone *mz = NULL;
3018 char z_name[RTE_MEMZONE_NAMESIZE];
3021 return I40E_ERR_PARAM;
3023 snprintf(z_name, sizeof(z_name), "i40e_dma_%"PRIu64, rte_rand());
3024 mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY, 0,
3025 alignment, RTE_PGSIZE_2M);
3027 return I40E_ERR_NO_MEMORY;
3031 mem->pa = rte_mem_phy2mch(mz->memseg_id, mz->phys_addr);
3032 mem->zone = (const void *)mz;
3033 PMD_DRV_LOG(DEBUG, "memzone %s allocated with physical address: "
3034 "%"PRIu64, mz->name, mem->pa);
3036 return I40E_SUCCESS;
3040 * i40e_free_dma_mem_d - specific memory free for shared code (base driver)
3041 * @hw: pointer to the HW structure
3042 * @mem: ptr to mem struct to free
3044 enum i40e_status_code
3045 i40e_free_dma_mem_d(__attribute__((unused)) struct i40e_hw *hw,
3046 struct i40e_dma_mem *mem)
3049 return I40E_ERR_PARAM;
3051 PMD_DRV_LOG(DEBUG, "memzone %s to be freed with physical address: "
3052 "%"PRIu64, ((const struct rte_memzone *)mem->zone)->name,
3054 rte_memzone_free((const struct rte_memzone *)mem->zone);
3059 return I40E_SUCCESS;
3063 * i40e_allocate_virt_mem_d - specific memory alloc for shared code (base driver)
3064 * @hw: pointer to the HW structure
3065 * @mem: pointer to mem struct to fill out
3066 * @size: size of memory requested
3068 enum i40e_status_code
3069 i40e_allocate_virt_mem_d(__attribute__((unused)) struct i40e_hw *hw,
3070 struct i40e_virt_mem *mem,
3074 return I40E_ERR_PARAM;
3077 mem->va = rte_zmalloc("i40e", size, 0);
3080 return I40E_SUCCESS;
3082 return I40E_ERR_NO_MEMORY;
3086 * i40e_free_virt_mem_d - specific memory free for shared code (base driver)
3087 * @hw: pointer to the HW structure
3088 * @mem: pointer to mem struct to free
3090 enum i40e_status_code
3091 i40e_free_virt_mem_d(__attribute__((unused)) struct i40e_hw *hw,
3092 struct i40e_virt_mem *mem)
3095 return I40E_ERR_PARAM;
3100 return I40E_SUCCESS;
3104 i40e_init_spinlock_d(struct i40e_spinlock *sp)
3106 rte_spinlock_init(&sp->spinlock);
3110 i40e_acquire_spinlock_d(struct i40e_spinlock *sp)
3112 rte_spinlock_lock(&sp->spinlock);
3116 i40e_release_spinlock_d(struct i40e_spinlock *sp)
3118 rte_spinlock_unlock(&sp->spinlock);
3122 i40e_destroy_spinlock_d(__attribute__((unused)) struct i40e_spinlock *sp)
3128 * Get the hardware capabilities, which will be parsed
3129 * and saved into struct i40e_hw.
3132 i40e_get_cap(struct i40e_hw *hw)
3134 struct i40e_aqc_list_capabilities_element_resp *buf;
3135 uint16_t len, size = 0;
3138 /* Calculate a huge enough buff for saving response data temporarily */
3139 len = sizeof(struct i40e_aqc_list_capabilities_element_resp) *
3140 I40E_MAX_CAP_ELE_NUM;
3141 buf = rte_zmalloc("i40e", len, 0);
3143 PMD_DRV_LOG(ERR, "Failed to allocate memory");
3144 return I40E_ERR_NO_MEMORY;
3147 /* Get, parse the capabilities and save it to hw */
3148 ret = i40e_aq_discover_capabilities(hw, buf, len, &size,
3149 i40e_aqc_opc_list_func_capabilities, NULL);
3150 if (ret != I40E_SUCCESS)
3151 PMD_DRV_LOG(ERR, "Failed to discover capabilities");
3153 /* Free the temporary buffer after being used */
3160 i40e_pf_parameter_init(struct rte_eth_dev *dev)
3162 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3163 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
3164 uint16_t qp_count = 0, vsi_count = 0;
3166 if (dev->pci_dev->max_vfs && !hw->func_caps.sr_iov_1_1) {
3167 PMD_INIT_LOG(ERR, "HW configuration doesn't support SRIOV");
3170 /* Add the parameter init for LFC */
3171 pf->fc_conf.pause_time = I40E_DEFAULT_PAUSE_TIME;
3172 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_HIGH_WATER;
3173 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_LOW_WATER;
3175 pf->flags = I40E_FLAG_HEADER_SPLIT_DISABLED;
3176 pf->max_num_vsi = hw->func_caps.num_vsis;
3177 pf->lan_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_PF;
3178 pf->vmdq_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
3179 pf->vf_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF;
3181 /* FDir queue/VSI allocation */
3182 pf->fdir_qp_offset = 0;
3183 if (hw->func_caps.fd) {
3184 pf->flags |= I40E_FLAG_FDIR;
3185 pf->fdir_nb_qps = I40E_DEFAULT_QP_NUM_FDIR;
3187 pf->fdir_nb_qps = 0;
3189 qp_count += pf->fdir_nb_qps;
3192 /* LAN queue/VSI allocation */
3193 pf->lan_qp_offset = pf->fdir_qp_offset + pf->fdir_nb_qps;
3194 if (!hw->func_caps.rss) {
3197 pf->flags |= I40E_FLAG_RSS;
3198 if (hw->mac.type == I40E_MAC_X722)
3199 pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE;
3200 pf->lan_nb_qps = pf->lan_nb_qp_max;
3202 qp_count += pf->lan_nb_qps;
3205 /* VF queue/VSI allocation */
3206 pf->vf_qp_offset = pf->lan_qp_offset + pf->lan_nb_qps;
3207 if (hw->func_caps.sr_iov_1_1 && dev->pci_dev->max_vfs) {
3208 pf->flags |= I40E_FLAG_SRIOV;
3209 pf->vf_nb_qps = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF;
3210 pf->vf_num = dev->pci_dev->max_vfs;
3211 PMD_DRV_LOG(DEBUG, "%u VF VSIs, %u queues per VF VSI, "
3212 "in total %u queues", pf->vf_num, pf->vf_nb_qps,
3213 pf->vf_nb_qps * pf->vf_num);
3218 qp_count += pf->vf_nb_qps * pf->vf_num;
3219 vsi_count += pf->vf_num;
3221 /* VMDq queue/VSI allocation */
3222 pf->vmdq_qp_offset = pf->vf_qp_offset + pf->vf_nb_qps * pf->vf_num;
3223 pf->vmdq_nb_qps = 0;
3224 pf->max_nb_vmdq_vsi = 0;
3225 if (hw->func_caps.vmdq) {
3226 if (qp_count < hw->func_caps.num_tx_qp &&
3227 vsi_count < hw->func_caps.num_vsis) {
3228 pf->max_nb_vmdq_vsi = (hw->func_caps.num_tx_qp -
3229 qp_count) / pf->vmdq_nb_qp_max;
3231 /* Limit the maximum number of VMDq vsi to the maximum
3232 * ethdev can support
3234 pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
3235 hw->func_caps.num_vsis - vsi_count);
3236 pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
3238 if (pf->max_nb_vmdq_vsi) {
3239 pf->flags |= I40E_FLAG_VMDQ;
3240 pf->vmdq_nb_qps = pf->vmdq_nb_qp_max;
3241 PMD_DRV_LOG(DEBUG, "%u VMDQ VSIs, %u queues "
3242 "per VMDQ VSI, in total %u queues",
3243 pf->max_nb_vmdq_vsi,
3244 pf->vmdq_nb_qps, pf->vmdq_nb_qps *
3245 pf->max_nb_vmdq_vsi);
3247 PMD_DRV_LOG(INFO, "No enough queues left for "
3251 PMD_DRV_LOG(INFO, "No queue or VSI left for VMDq");
3254 qp_count += pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi;
3255 vsi_count += pf->max_nb_vmdq_vsi;
3257 if (hw->func_caps.dcb)
3258 pf->flags |= I40E_FLAG_DCB;
3260 if (qp_count > hw->func_caps.num_tx_qp) {
3261 PMD_DRV_LOG(ERR, "Failed to allocate %u queues, which exceeds "
3262 "the hardware maximum %u", qp_count,
3263 hw->func_caps.num_tx_qp);
3266 if (vsi_count > hw->func_caps.num_vsis) {
3267 PMD_DRV_LOG(ERR, "Failed to allocate %u VSIs, which exceeds "
3268 "the hardware maximum %u", vsi_count,
3269 hw->func_caps.num_vsis);
3277 i40e_pf_get_switch_config(struct i40e_pf *pf)
3279 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
3280 struct i40e_aqc_get_switch_config_resp *switch_config;
3281 struct i40e_aqc_switch_config_element_resp *element;
3282 uint16_t start_seid = 0, num_reported;
3285 switch_config = (struct i40e_aqc_get_switch_config_resp *)\
3286 rte_zmalloc("i40e", I40E_AQ_LARGE_BUF, 0);
3287 if (!switch_config) {
3288 PMD_DRV_LOG(ERR, "Failed to allocated memory");
3292 /* Get the switch configurations */
3293 ret = i40e_aq_get_switch_config(hw, switch_config,
3294 I40E_AQ_LARGE_BUF, &start_seid, NULL);
3295 if (ret != I40E_SUCCESS) {
3296 PMD_DRV_LOG(ERR, "Failed to get switch configurations");
3299 num_reported = rte_le_to_cpu_16(switch_config->header.num_reported);
3300 if (num_reported != 1) { /* The number should be 1 */
3301 PMD_DRV_LOG(ERR, "Wrong number of switch config reported");
3305 /* Parse the switch configuration elements */
3306 element = &(switch_config->element[0]);
3307 if (element->element_type == I40E_SWITCH_ELEMENT_TYPE_VSI) {
3308 pf->mac_seid = rte_le_to_cpu_16(element->uplink_seid);
3309 pf->main_vsi_seid = rte_le_to_cpu_16(element->seid);
3311 PMD_DRV_LOG(INFO, "Unknown element type");
3314 rte_free(switch_config);
3320 i40e_res_pool_init (struct i40e_res_pool_info *pool, uint32_t base,
3323 struct pool_entry *entry;
3325 if (pool == NULL || num == 0)
3328 entry = rte_zmalloc("i40e", sizeof(*entry), 0);
3329 if (entry == NULL) {
3330 PMD_DRV_LOG(ERR, "Failed to allocate memory for resource pool");
3334 /* queue heap initialize */
3335 pool->num_free = num;
3336 pool->num_alloc = 0;
3338 LIST_INIT(&pool->alloc_list);
3339 LIST_INIT(&pool->free_list);
3341 /* Initialize element */
3345 LIST_INSERT_HEAD(&pool->free_list, entry, next);
3350 i40e_res_pool_destroy(struct i40e_res_pool_info *pool)
3352 struct pool_entry *entry;
3357 LIST_FOREACH(entry, &pool->alloc_list, next) {
3358 LIST_REMOVE(entry, next);
3362 LIST_FOREACH(entry, &pool->free_list, next) {
3363 LIST_REMOVE(entry, next);
3368 pool->num_alloc = 0;
3370 LIST_INIT(&pool->alloc_list);
3371 LIST_INIT(&pool->free_list);
3375 i40e_res_pool_free(struct i40e_res_pool_info *pool,
3378 struct pool_entry *entry, *next, *prev, *valid_entry = NULL;
3379 uint32_t pool_offset;
3383 PMD_DRV_LOG(ERR, "Invalid parameter");
3387 pool_offset = base - pool->base;
3388 /* Lookup in alloc list */
3389 LIST_FOREACH(entry, &pool->alloc_list, next) {
3390 if (entry->base == pool_offset) {
3391 valid_entry = entry;
3392 LIST_REMOVE(entry, next);
3397 /* Not find, return */
3398 if (valid_entry == NULL) {
3399 PMD_DRV_LOG(ERR, "Failed to find entry");
3404 * Found it, move it to free list and try to merge.
3405 * In order to make merge easier, always sort it by qbase.
3406 * Find adjacent prev and last entries.
3409 LIST_FOREACH(entry, &pool->free_list, next) {
3410 if (entry->base > valid_entry->base) {
3418 /* Try to merge with next one*/
3420 /* Merge with next one */
3421 if (valid_entry->base + valid_entry->len == next->base) {
3422 next->base = valid_entry->base;
3423 next->len += valid_entry->len;
3424 rte_free(valid_entry);
3431 /* Merge with previous one */
3432 if (prev->base + prev->len == valid_entry->base) {
3433 prev->len += valid_entry->len;
3434 /* If it merge with next one, remove next node */
3436 LIST_REMOVE(valid_entry, next);
3437 rte_free(valid_entry);
3439 rte_free(valid_entry);
3445 /* Not find any entry to merge, insert */
3448 LIST_INSERT_AFTER(prev, valid_entry, next);
3449 else if (next != NULL)
3450 LIST_INSERT_BEFORE(next, valid_entry, next);
3451 else /* It's empty list, insert to head */
3452 LIST_INSERT_HEAD(&pool->free_list, valid_entry, next);
3455 pool->num_free += valid_entry->len;
3456 pool->num_alloc -= valid_entry->len;
3462 i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
3465 struct pool_entry *entry, *valid_entry;
3467 if (pool == NULL || num == 0) {
3468 PMD_DRV_LOG(ERR, "Invalid parameter");
3472 if (pool->num_free < num) {
3473 PMD_DRV_LOG(ERR, "No resource. ask:%u, available:%u",
3474 num, pool->num_free);
3479 /* Lookup in free list and find most fit one */
3480 LIST_FOREACH(entry, &pool->free_list, next) {
3481 if (entry->len >= num) {
3483 if (entry->len == num) {
3484 valid_entry = entry;
3487 if (valid_entry == NULL || valid_entry->len > entry->len)
3488 valid_entry = entry;
3492 /* Not find one to satisfy the request, return */
3493 if (valid_entry == NULL) {
3494 PMD_DRV_LOG(ERR, "No valid entry found");
3498 * The entry have equal queue number as requested,
3499 * remove it from alloc_list.
3501 if (valid_entry->len == num) {
3502 LIST_REMOVE(valid_entry, next);
3505 * The entry have more numbers than requested,
3506 * create a new entry for alloc_list and minus its
3507 * queue base and number in free_list.
3509 entry = rte_zmalloc("res_pool", sizeof(*entry), 0);
3510 if (entry == NULL) {
3511 PMD_DRV_LOG(ERR, "Failed to allocate memory for "
3515 entry->base = valid_entry->base;
3517 valid_entry->base += num;
3518 valid_entry->len -= num;
3519 valid_entry = entry;
3522 /* Insert it into alloc list, not sorted */
3523 LIST_INSERT_HEAD(&pool->alloc_list, valid_entry, next);
3525 pool->num_free -= valid_entry->len;
3526 pool->num_alloc += valid_entry->len;
3528 return valid_entry->base + pool->base;
3532 * bitmap_is_subset - Check whether src2 is subset of src1
3535 bitmap_is_subset(uint8_t src1, uint8_t src2)
3537 return !((src1 ^ src2) & src2);
3540 static enum i40e_status_code
3541 validate_tcmap_parameter(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
3543 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3545 /* If DCB is not supported, only default TC is supported */
3546 if (!hw->func_caps.dcb && enabled_tcmap != I40E_DEFAULT_TCMAP) {
3547 PMD_DRV_LOG(ERR, "DCB is not enabled, only TC0 is supported");
3548 return I40E_NOT_SUPPORTED;
3551 if (!bitmap_is_subset(hw->func_caps.enabled_tcmap, enabled_tcmap)) {
3552 PMD_DRV_LOG(ERR, "Enabled TC map 0x%x not applicable to "
3553 "HW support 0x%x", hw->func_caps.enabled_tcmap,
3555 return I40E_NOT_SUPPORTED;
3557 return I40E_SUCCESS;
3561 i40e_vsi_vlan_pvid_set(struct i40e_vsi *vsi,
3562 struct i40e_vsi_vlan_pvid_info *info)
3565 struct i40e_vsi_context ctxt;
3566 uint8_t vlan_flags = 0;
3569 if (vsi == NULL || info == NULL) {
3570 PMD_DRV_LOG(ERR, "invalid parameters");
3571 return I40E_ERR_PARAM;
3575 vsi->info.pvid = info->config.pvid;
3577 * If insert pvid is enabled, only tagged pkts are
3578 * allowed to be sent out.
3580 vlan_flags |= I40E_AQ_VSI_PVLAN_INSERT_PVID |
3581 I40E_AQ_VSI_PVLAN_MODE_TAGGED;
3584 if (info->config.reject.tagged == 0)
3585 vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_TAGGED;
3587 if (info->config.reject.untagged == 0)
3588 vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_UNTAGGED;
3590 vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_INSERT_PVID |
3591 I40E_AQ_VSI_PVLAN_MODE_MASK);
3592 vsi->info.port_vlan_flags |= vlan_flags;
3593 vsi->info.valid_sections =
3594 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
3595 memset(&ctxt, 0, sizeof(ctxt));
3596 (void)rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
3597 ctxt.seid = vsi->seid;
3599 hw = I40E_VSI_TO_HW(vsi);
3600 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
3601 if (ret != I40E_SUCCESS)
3602 PMD_DRV_LOG(ERR, "Failed to update VSI params");
3608 i40e_vsi_update_tc_bandwidth(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
3610 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3612 struct i40e_aqc_configure_vsi_tc_bw_data tc_bw_data;
3614 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
3615 if (ret != I40E_SUCCESS)
3619 PMD_DRV_LOG(ERR, "seid not valid");
3623 memset(&tc_bw_data, 0, sizeof(tc_bw_data));
3624 tc_bw_data.tc_valid_bits = enabled_tcmap;
3625 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
3626 tc_bw_data.tc_bw_credits[i] =
3627 (enabled_tcmap & (1 << i)) ? 1 : 0;
3629 ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &tc_bw_data, NULL);
3630 if (ret != I40E_SUCCESS) {
3631 PMD_DRV_LOG(ERR, "Failed to configure TC BW");
3635 (void)rte_memcpy(vsi->info.qs_handle, tc_bw_data.qs_handles,
3636 sizeof(vsi->info.qs_handle));
3637 return I40E_SUCCESS;
3640 static enum i40e_status_code
3641 i40e_vsi_config_tc_queue_mapping(struct i40e_vsi *vsi,
3642 struct i40e_aqc_vsi_properties_data *info,
3643 uint8_t enabled_tcmap)
3645 enum i40e_status_code ret;
3646 int i, total_tc = 0;
3647 uint16_t qpnum_per_tc, bsf, qp_idx;
3649 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
3650 if (ret != I40E_SUCCESS)
3653 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
3654 if (enabled_tcmap & (1 << i))
3656 vsi->enabled_tc = enabled_tcmap;
3658 /* Number of queues per enabled TC */
3659 qpnum_per_tc = i40e_align_floor(vsi->nb_qps / total_tc);
3660 qpnum_per_tc = RTE_MIN(qpnum_per_tc, I40E_MAX_Q_PER_TC);
3661 bsf = rte_bsf32(qpnum_per_tc);
3663 /* Adjust the queue number to actual queues that can be applied */
3664 if (!(vsi->type == I40E_VSI_MAIN && total_tc == 1))
3665 vsi->nb_qps = qpnum_per_tc * total_tc;
3668 * Configure TC and queue mapping parameters, for enabled TC,
3669 * allocate qpnum_per_tc queues to this traffic. For disabled TC,
3670 * default queue will serve it.
3673 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
3674 if (vsi->enabled_tc & (1 << i)) {
3675 info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
3676 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
3677 (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
3678 qp_idx += qpnum_per_tc;
3680 info->tc_mapping[i] = 0;
3683 /* Associate queue number with VSI */
3684 if (vsi->type == I40E_VSI_SRIOV) {
3685 info->mapping_flags |=
3686 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
3687 for (i = 0; i < vsi->nb_qps; i++)
3688 info->queue_mapping[i] =
3689 rte_cpu_to_le_16(vsi->base_queue + i);
3691 info->mapping_flags |=
3692 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
3693 info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
3695 info->valid_sections |=
3696 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
3698 return I40E_SUCCESS;
3702 i40e_veb_release(struct i40e_veb *veb)
3704 struct i40e_vsi *vsi;
3707 if (veb == NULL || veb->associate_vsi == NULL)
3710 if (!TAILQ_EMPTY(&veb->head)) {
3711 PMD_DRV_LOG(ERR, "VEB still has VSI attached, can't remove");
3715 vsi = veb->associate_vsi;
3716 hw = I40E_VSI_TO_HW(vsi);
3718 vsi->uplink_seid = veb->uplink_seid;
3719 i40e_aq_delete_element(hw, veb->seid, NULL);
3722 return I40E_SUCCESS;
3726 static struct i40e_veb *
3727 i40e_veb_setup(struct i40e_pf *pf, struct i40e_vsi *vsi)
3729 struct i40e_veb *veb;
3733 if (NULL == pf || vsi == NULL) {
3734 PMD_DRV_LOG(ERR, "veb setup failed, "
3735 "associated VSI shouldn't null");
3738 hw = I40E_PF_TO_HW(pf);
3740 veb = rte_zmalloc("i40e_veb", sizeof(struct i40e_veb), 0);
3742 PMD_DRV_LOG(ERR, "Failed to allocate memory for veb");
3746 veb->associate_vsi = vsi;
3747 TAILQ_INIT(&veb->head);
3748 veb->uplink_seid = vsi->uplink_seid;
3750 ret = i40e_aq_add_veb(hw, veb->uplink_seid, vsi->seid,
3751 I40E_DEFAULT_TCMAP, false, &veb->seid, false, NULL);
3753 if (ret != I40E_SUCCESS) {
3754 PMD_DRV_LOG(ERR, "Add veb failed, aq_err: %d",
3755 hw->aq.asq_last_status);
3759 /* get statistics index */
3760 ret = i40e_aq_get_veb_parameters(hw, veb->seid, NULL, NULL,
3761 &veb->stats_idx, NULL, NULL, NULL);
3762 if (ret != I40E_SUCCESS) {
3763 PMD_DRV_LOG(ERR, "Get veb statics index failed, aq_err: %d",
3764 hw->aq.asq_last_status);
3768 /* Get VEB bandwidth, to be implemented */
3769 /* Now associated vsi binding to the VEB, set uplink to this VEB */
3770 vsi->uplink_seid = veb->seid;
3779 i40e_vsi_release(struct i40e_vsi *vsi)
3783 struct i40e_vsi_list *vsi_list;
3785 struct i40e_mac_filter *f;
3788 return I40E_SUCCESS;
3790 pf = I40E_VSI_TO_PF(vsi);
3791 hw = I40E_VSI_TO_HW(vsi);
3793 /* VSI has child to attach, release child first */
3795 TAILQ_FOREACH(vsi_list, &vsi->veb->head, list) {
3796 if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
3798 TAILQ_REMOVE(&vsi->veb->head, vsi_list, list);
3800 i40e_veb_release(vsi->veb);
3803 /* Remove all macvlan filters of the VSI */
3804 i40e_vsi_remove_all_macvlan_filter(vsi);
3805 TAILQ_FOREACH(f, &vsi->mac_list, next)
3808 if (vsi->type != I40E_VSI_MAIN) {
3809 /* Remove vsi from parent's sibling list */
3810 if (vsi->parent_vsi == NULL || vsi->parent_vsi->veb == NULL) {
3811 PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
3812 return I40E_ERR_PARAM;
3814 TAILQ_REMOVE(&vsi->parent_vsi->veb->head,
3815 &vsi->sib_vsi_list, list);
3817 /* Remove all switch element of the VSI */
3818 ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
3819 if (ret != I40E_SUCCESS)
3820 PMD_DRV_LOG(ERR, "Failed to delete element");
3822 i40e_res_pool_free(&pf->qp_pool, vsi->base_queue);
3824 if (vsi->type != I40E_VSI_SRIOV)
3825 i40e_res_pool_free(&pf->msix_pool, vsi->msix_intr);
3828 return I40E_SUCCESS;
3832 i40e_update_default_filter_setting(struct i40e_vsi *vsi)
3834 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3835 struct i40e_aqc_remove_macvlan_element_data def_filter;
3836 struct i40e_mac_filter_info filter;
3839 if (vsi->type != I40E_VSI_MAIN)
3840 return I40E_ERR_CONFIG;
3841 memset(&def_filter, 0, sizeof(def_filter));
3842 (void)rte_memcpy(def_filter.mac_addr, hw->mac.perm_addr,
3844 def_filter.vlan_tag = 0;
3845 def_filter.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
3846 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
3847 ret = i40e_aq_remove_macvlan(hw, vsi->seid, &def_filter, 1, NULL);
3848 if (ret != I40E_SUCCESS) {
3849 struct i40e_mac_filter *f;
3850 struct ether_addr *mac;
3852 PMD_DRV_LOG(WARNING, "Cannot remove the default "
3854 /* It needs to add the permanent mac into mac list */
3855 f = rte_zmalloc("macv_filter", sizeof(*f), 0);
3857 PMD_DRV_LOG(ERR, "failed to allocate memory");
3858 return I40E_ERR_NO_MEMORY;
3860 mac = &f->mac_info.mac_addr;
3861 (void)rte_memcpy(&mac->addr_bytes, hw->mac.perm_addr,
3863 f->mac_info.filter_type = RTE_MACVLAN_PERFECT_MATCH;
3864 TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
3869 (void)rte_memcpy(&filter.mac_addr,
3870 (struct ether_addr *)(hw->mac.perm_addr), ETH_ADDR_LEN);
3871 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
3872 return i40e_vsi_add_mac(vsi, &filter);
3876 * i40e_vsi_get_bw_config - Query VSI BW Information
3877 * @vsi: the VSI to be queried
3879 * Returns 0 on success, negative value on failure
3881 static enum i40e_status_code
3882 i40e_vsi_get_bw_config(struct i40e_vsi *vsi)
3884 struct i40e_aqc_query_vsi_bw_config_resp bw_config;
3885 struct i40e_aqc_query_vsi_ets_sla_config_resp ets_sla_config;
3886 struct i40e_hw *hw = &vsi->adapter->hw;
3891 memset(&bw_config, 0, sizeof(bw_config));
3892 ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
3893 if (ret != I40E_SUCCESS) {
3894 PMD_DRV_LOG(ERR, "VSI failed to get bandwidth configuration %u",
3895 hw->aq.asq_last_status);
3899 memset(&ets_sla_config, 0, sizeof(ets_sla_config));
3900 ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid,
3901 &ets_sla_config, NULL);
3902 if (ret != I40E_SUCCESS) {
3903 PMD_DRV_LOG(ERR, "VSI failed to get TC bandwdith "
3904 "configuration %u", hw->aq.asq_last_status);
3908 /* store and print out BW info */
3909 vsi->bw_info.bw_limit = rte_le_to_cpu_16(bw_config.port_bw_limit);
3910 vsi->bw_info.bw_max = bw_config.max_bw;
3911 PMD_DRV_LOG(DEBUG, "VSI bw limit:%u", vsi->bw_info.bw_limit);
3912 PMD_DRV_LOG(DEBUG, "VSI max_bw:%u", vsi->bw_info.bw_max);
3913 bw_max = rte_le_to_cpu_16(ets_sla_config.tc_bw_max[0]) |
3914 (rte_le_to_cpu_16(ets_sla_config.tc_bw_max[1]) <<
3916 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
3917 vsi->bw_info.bw_ets_share_credits[i] =
3918 ets_sla_config.share_credits[i];
3919 vsi->bw_info.bw_ets_credits[i] =
3920 rte_le_to_cpu_16(ets_sla_config.credits[i]);
3921 /* 4 bits per TC, 4th bit is reserved */
3922 vsi->bw_info.bw_ets_max[i] =
3923 (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
3924 RTE_LEN2MASK(3, uint8_t));
3925 PMD_DRV_LOG(DEBUG, "\tVSI TC%u:share credits %u", i,
3926 vsi->bw_info.bw_ets_share_credits[i]);
3927 PMD_DRV_LOG(DEBUG, "\tVSI TC%u:credits %u", i,
3928 vsi->bw_info.bw_ets_credits[i]);
3929 PMD_DRV_LOG(DEBUG, "\tVSI TC%u: max credits: %u", i,
3930 vsi->bw_info.bw_ets_max[i]);
3933 return I40E_SUCCESS;
3936 /* i40e_enable_pf_lb
3937 * @pf: pointer to the pf structure
3939 * allow loopback on pf
3942 i40e_enable_pf_lb(struct i40e_pf *pf)
3944 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
3945 struct i40e_vsi_context ctxt;
3948 /* Use the FW API if FW >= v5.0 */
3949 if (hw->aq.fw_maj_ver < 5) {
3950 PMD_INIT_LOG(ERR, "FW < v5.0, cannot enable loopback");
3954 memset(&ctxt, 0, sizeof(ctxt));
3955 ctxt.seid = pf->main_vsi_seid;
3956 ctxt.pf_num = hw->pf_id;
3957 ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
3959 PMD_DRV_LOG(ERR, "cannot get pf vsi config, err %d, aq_err %d",
3960 ret, hw->aq.asq_last_status);
3963 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
3964 ctxt.info.valid_sections =
3965 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
3966 ctxt.info.switch_id |=
3967 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
3969 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
3971 PMD_DRV_LOG(ERR, "update vsi switch failed, aq_err=%d\n",
3972 hw->aq.asq_last_status);
3977 i40e_vsi_setup(struct i40e_pf *pf,
3978 enum i40e_vsi_type type,
3979 struct i40e_vsi *uplink_vsi,
3980 uint16_t user_param)
3982 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
3983 struct i40e_vsi *vsi;
3984 struct i40e_mac_filter_info filter;
3986 struct i40e_vsi_context ctxt;
3987 struct ether_addr broadcast =
3988 {.addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
3990 if (type != I40E_VSI_MAIN && uplink_vsi == NULL) {
3991 PMD_DRV_LOG(ERR, "VSI setup failed, "
3992 "VSI link shouldn't be NULL");
3996 if (type == I40E_VSI_MAIN && uplink_vsi != NULL) {
3997 PMD_DRV_LOG(ERR, "VSI setup failed, MAIN VSI "
3998 "uplink VSI should be NULL");
4002 /* If uplink vsi didn't setup VEB, create one first */
4003 if (type != I40E_VSI_MAIN && uplink_vsi->veb == NULL) {
4004 uplink_vsi->veb = i40e_veb_setup(pf, uplink_vsi);
4006 if (NULL == uplink_vsi->veb) {
4007 PMD_DRV_LOG(ERR, "VEB setup failed");
4010 /* set ALLOWLOOPBACk on pf, when veb is created */
4011 i40e_enable_pf_lb(pf);
4014 vsi = rte_zmalloc("i40e_vsi", sizeof(struct i40e_vsi), 0);
4016 PMD_DRV_LOG(ERR, "Failed to allocate memory for vsi");
4019 TAILQ_INIT(&vsi->mac_list);
4021 vsi->adapter = I40E_PF_TO_ADAPTER(pf);
4022 vsi->max_macaddrs = I40E_NUM_MACADDR_MAX;
4023 vsi->parent_vsi = uplink_vsi;
4024 vsi->user_param = user_param;
4025 /* Allocate queues */
4026 switch (vsi->type) {
4027 case I40E_VSI_MAIN :
4028 vsi->nb_qps = pf->lan_nb_qps;
4030 case I40E_VSI_SRIOV :
4031 vsi->nb_qps = pf->vf_nb_qps;
4033 case I40E_VSI_VMDQ2:
4034 vsi->nb_qps = pf->vmdq_nb_qps;
4037 vsi->nb_qps = pf->fdir_nb_qps;
4043 * The filter status descriptor is reported in rx queue 0,
4044 * while the tx queue for fdir filter programming has no
4045 * such constraints, can be non-zero queues.
4046 * To simplify it, choose FDIR vsi use queue 0 pair.
4047 * To make sure it will use queue 0 pair, queue allocation
4048 * need be done before this function is called
4050 if (type != I40E_VSI_FDIR) {
4051 ret = i40e_res_pool_alloc(&pf->qp_pool, vsi->nb_qps);
4053 PMD_DRV_LOG(ERR, "VSI %d allocate queue failed %d",
4057 vsi->base_queue = ret;
4059 vsi->base_queue = I40E_FDIR_QUEUE_ID;
4061 /* VF has MSIX interrupt in VF range, don't allocate here */
4062 if (type == I40E_VSI_MAIN) {
4063 ret = i40e_res_pool_alloc(&pf->msix_pool,
4064 RTE_MIN(vsi->nb_qps,
4065 RTE_MAX_RXTX_INTR_VEC_ID));
4067 PMD_DRV_LOG(ERR, "VSI MAIN %d get heap failed %d",
4069 goto fail_queue_alloc;
4071 vsi->msix_intr = ret;
4072 vsi->nb_msix = RTE_MIN(vsi->nb_qps, RTE_MAX_RXTX_INTR_VEC_ID);
4073 } else if (type != I40E_VSI_SRIOV) {
4074 ret = i40e_res_pool_alloc(&pf->msix_pool, 1);
4076 PMD_DRV_LOG(ERR, "VSI %d get heap failed %d", vsi->seid, ret);
4077 goto fail_queue_alloc;
4079 vsi->msix_intr = ret;
4087 if (type == I40E_VSI_MAIN) {
4088 /* For main VSI, no need to add since it's default one */
4089 vsi->uplink_seid = pf->mac_seid;
4090 vsi->seid = pf->main_vsi_seid;
4091 /* Bind queues with specific MSIX interrupt */
4093 * Needs 2 interrupt at least, one for misc cause which will
4094 * enabled from OS side, Another for queues binding the
4095 * interrupt from device side only.
4098 /* Get default VSI parameters from hardware */
4099 memset(&ctxt, 0, sizeof(ctxt));
4100 ctxt.seid = vsi->seid;
4101 ctxt.pf_num = hw->pf_id;
4102 ctxt.uplink_seid = vsi->uplink_seid;
4104 ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
4105 if (ret != I40E_SUCCESS) {
4106 PMD_DRV_LOG(ERR, "Failed to get VSI params");
4107 goto fail_msix_alloc;
4109 (void)rte_memcpy(&vsi->info, &ctxt.info,
4110 sizeof(struct i40e_aqc_vsi_properties_data));
4111 vsi->vsi_id = ctxt.vsi_number;
4112 vsi->info.valid_sections = 0;
4114 /* Configure tc, enabled TC0 only */
4115 if (i40e_vsi_update_tc_bandwidth(vsi, I40E_DEFAULT_TCMAP) !=
4117 PMD_DRV_LOG(ERR, "Failed to update TC bandwidth");
4118 goto fail_msix_alloc;
4121 /* TC, queue mapping */
4122 memset(&ctxt, 0, sizeof(ctxt));
4123 vsi->info.valid_sections |=
4124 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
4125 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
4126 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
4127 (void)rte_memcpy(&ctxt.info, &vsi->info,
4128 sizeof(struct i40e_aqc_vsi_properties_data));
4129 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
4130 I40E_DEFAULT_TCMAP);
4131 if (ret != I40E_SUCCESS) {
4132 PMD_DRV_LOG(ERR, "Failed to configure "
4133 "TC queue mapping");
4134 goto fail_msix_alloc;
4136 ctxt.seid = vsi->seid;
4137 ctxt.pf_num = hw->pf_id;
4138 ctxt.uplink_seid = vsi->uplink_seid;
4141 /* Update VSI parameters */
4142 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
4143 if (ret != I40E_SUCCESS) {
4144 PMD_DRV_LOG(ERR, "Failed to update VSI params");
4145 goto fail_msix_alloc;
4148 (void)rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
4149 sizeof(vsi->info.tc_mapping));
4150 (void)rte_memcpy(&vsi->info.queue_mapping,
4151 &ctxt.info.queue_mapping,
4152 sizeof(vsi->info.queue_mapping));
4153 vsi->info.mapping_flags = ctxt.info.mapping_flags;
4154 vsi->info.valid_sections = 0;
4156 (void)rte_memcpy(pf->dev_addr.addr_bytes, hw->mac.perm_addr,
4160 * Updating default filter settings are necessary to prevent
4161 * reception of tagged packets.
4162 * Some old firmware configurations load a default macvlan
4163 * filter which accepts both tagged and untagged packets.
4164 * The updating is to use a normal filter instead if needed.
4165 * For NVM 4.2.2 or after, the updating is not needed anymore.
4166 * The firmware with correct configurations load the default
4167 * macvlan filter which is expected and cannot be removed.
4169 i40e_update_default_filter_setting(vsi);
4170 i40e_config_qinq(hw, vsi);
4171 } else if (type == I40E_VSI_SRIOV) {
4172 memset(&ctxt, 0, sizeof(ctxt));
4174 * For other VSI, the uplink_seid equals to uplink VSI's
4175 * uplink_seid since they share same VEB
4177 vsi->uplink_seid = uplink_vsi->uplink_seid;
4178 ctxt.pf_num = hw->pf_id;
4179 ctxt.vf_num = hw->func_caps.vf_base_id + user_param;
4180 ctxt.uplink_seid = vsi->uplink_seid;
4181 ctxt.connection_type = 0x1;
4182 ctxt.flags = I40E_AQ_VSI_TYPE_VF;
4184 /* Use the VEB configuration if FW >= v5.0 */
4185 if (hw->aq.fw_maj_ver >= 5) {
4186 /* Configure switch ID */
4187 ctxt.info.valid_sections |=
4188 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
4189 ctxt.info.switch_id =
4190 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
4193 /* Configure port/vlan */
4194 ctxt.info.valid_sections |=
4195 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
4196 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
4197 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
4198 I40E_DEFAULT_TCMAP);
4199 if (ret != I40E_SUCCESS) {
4200 PMD_DRV_LOG(ERR, "Failed to configure "
4201 "TC queue mapping");
4202 goto fail_msix_alloc;
4204 ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
4205 ctxt.info.valid_sections |=
4206 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
4208 * Since VSI is not created yet, only configure parameter,
4209 * will add vsi below.
4212 i40e_config_qinq(hw, vsi);
4213 } else if (type == I40E_VSI_VMDQ2) {
4214 memset(&ctxt, 0, sizeof(ctxt));
4216 * For other VSI, the uplink_seid equals to uplink VSI's
4217 * uplink_seid since they share same VEB
4219 vsi->uplink_seid = uplink_vsi->uplink_seid;
4220 ctxt.pf_num = hw->pf_id;
4222 ctxt.uplink_seid = vsi->uplink_seid;
4223 ctxt.connection_type = 0x1;
4224 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
4226 ctxt.info.valid_sections |=
4227 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
4228 /* user_param carries flag to enable loop back */
4230 ctxt.info.switch_id =
4231 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
4232 ctxt.info.switch_id |=
4233 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
4236 /* Configure port/vlan */
4237 ctxt.info.valid_sections |=
4238 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
4239 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
4240 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
4241 I40E_DEFAULT_TCMAP);
4242 if (ret != I40E_SUCCESS) {
4243 PMD_DRV_LOG(ERR, "Failed to configure "
4244 "TC queue mapping");
4245 goto fail_msix_alloc;
4247 ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
4248 ctxt.info.valid_sections |=
4249 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
4250 } else if (type == I40E_VSI_FDIR) {
4251 memset(&ctxt, 0, sizeof(ctxt));
4252 vsi->uplink_seid = uplink_vsi->uplink_seid;
4253 ctxt.pf_num = hw->pf_id;
4255 ctxt.uplink_seid = vsi->uplink_seid;
4256 ctxt.connection_type = 0x1; /* regular data port */
4257 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
4258 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
4259 I40E_DEFAULT_TCMAP);
4260 if (ret != I40E_SUCCESS) {
4261 PMD_DRV_LOG(ERR, "Failed to configure "
4262 "TC queue mapping.");
4263 goto fail_msix_alloc;
4265 ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
4266 ctxt.info.valid_sections |=
4267 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
4269 PMD_DRV_LOG(ERR, "VSI: Not support other type VSI yet");
4270 goto fail_msix_alloc;
4273 if (vsi->type != I40E_VSI_MAIN) {
4274 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
4275 if (ret != I40E_SUCCESS) {
4276 PMD_DRV_LOG(ERR, "add vsi failed, aq_err=%d",
4277 hw->aq.asq_last_status);
4278 goto fail_msix_alloc;
4280 memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
4281 vsi->info.valid_sections = 0;
4282 vsi->seid = ctxt.seid;
4283 vsi->vsi_id = ctxt.vsi_number;
4284 vsi->sib_vsi_list.vsi = vsi;
4285 TAILQ_INSERT_TAIL(&uplink_vsi->veb->head,
4286 &vsi->sib_vsi_list, list);
4289 /* MAC/VLAN configuration */
4290 (void)rte_memcpy(&filter.mac_addr, &broadcast, ETHER_ADDR_LEN);
4291 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
4293 ret = i40e_vsi_add_mac(vsi, &filter);
4294 if (ret != I40E_SUCCESS) {
4295 PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
4296 goto fail_msix_alloc;
4299 /* Get VSI BW information */
4300 i40e_vsi_get_bw_config(vsi);
4303 i40e_res_pool_free(&pf->msix_pool,vsi->msix_intr);
4305 i40e_res_pool_free(&pf->qp_pool,vsi->base_queue);
4311 /* Configure vlan filter on or off */
4313 i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on)
4316 struct i40e_mac_filter *f;
4317 struct i40e_mac_filter_info *mac_filter;
4318 enum rte_mac_filter_type desired_filter;
4319 int ret = I40E_SUCCESS;
4322 /* Filter to match MAC and VLAN */
4323 desired_filter = RTE_MACVLAN_PERFECT_MATCH;
4325 /* Filter to match only MAC */
4326 desired_filter = RTE_MAC_PERFECT_MATCH;
4331 mac_filter = rte_zmalloc("mac_filter_info_data",
4332 num * sizeof(*mac_filter), 0);
4333 if (mac_filter == NULL) {
4334 PMD_DRV_LOG(ERR, "failed to allocate memory");
4335 return I40E_ERR_NO_MEMORY;
4340 /* Remove all existing mac */
4341 TAILQ_FOREACH(f, &vsi->mac_list, next) {
4342 mac_filter[i] = f->mac_info;
4343 ret = i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
4345 PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
4346 on ? "enable" : "disable");
4352 /* Override with new filter */
4353 for (i = 0; i < num; i++) {
4354 mac_filter[i].filter_type = desired_filter;
4355 ret = i40e_vsi_add_mac(vsi, &mac_filter[i]);
4357 PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
4358 on ? "enable" : "disable");
4364 rte_free(mac_filter);
4368 /* Configure vlan stripping on or off */
4370 i40e_vsi_config_vlan_stripping(struct i40e_vsi *vsi, bool on)
4372 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4373 struct i40e_vsi_context ctxt;
4375 int ret = I40E_SUCCESS;
4377 /* Check if it has been already on or off */
4378 if (vsi->info.valid_sections &
4379 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID)) {
4381 if ((vsi->info.port_vlan_flags &
4382 I40E_AQ_VSI_PVLAN_EMOD_MASK) == 0)
4383 return 0; /* already on */
4385 if ((vsi->info.port_vlan_flags &
4386 I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
4387 I40E_AQ_VSI_PVLAN_EMOD_MASK)
4388 return 0; /* already off */
4393 vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
4395 vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
4396 vsi->info.valid_sections =
4397 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
4398 vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_EMOD_MASK);
4399 vsi->info.port_vlan_flags |= vlan_flags;
4400 ctxt.seid = vsi->seid;
4401 (void)rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
4402 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
4404 PMD_DRV_LOG(INFO, "Update VSI failed to %s vlan stripping",
4405 on ? "enable" : "disable");
4411 i40e_dev_init_vlan(struct rte_eth_dev *dev)
4413 struct rte_eth_dev_data *data = dev->data;
4417 /* Apply vlan offload setting */
4418 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK;
4419 i40e_vlan_offload_set(dev, mask);
4421 /* Apply double-vlan setting, not implemented yet */
4423 /* Apply pvid setting */
4424 ret = i40e_vlan_pvid_set(dev, data->dev_conf.txmode.pvid,
4425 data->dev_conf.txmode.hw_vlan_insert_pvid);
4427 PMD_DRV_LOG(INFO, "Failed to update VSI params");
4433 i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on)
4435 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4437 return i40e_aq_set_port_parameters(hw, vsi->seid, 0, 1, on, NULL);
4441 i40e_update_flow_control(struct i40e_hw *hw)
4443 #define I40E_LINK_PAUSE_RXTX (I40E_AQ_LINK_PAUSE_RX | I40E_AQ_LINK_PAUSE_TX)
4444 struct i40e_link_status link_status;
4445 uint32_t rxfc = 0, txfc = 0, reg;
4449 memset(&link_status, 0, sizeof(link_status));
4450 ret = i40e_aq_get_link_info(hw, FALSE, &link_status, NULL);
4451 if (ret != I40E_SUCCESS) {
4452 PMD_DRV_LOG(ERR, "Failed to get link status information");
4453 goto write_reg; /* Disable flow control */
4456 an_info = hw->phy.link_info.an_info;
4457 if (!(an_info & I40E_AQ_AN_COMPLETED)) {
4458 PMD_DRV_LOG(INFO, "Link auto negotiation not completed");
4459 ret = I40E_ERR_NOT_READY;
4460 goto write_reg; /* Disable flow control */
4463 * If link auto negotiation is enabled, flow control needs to
4464 * be configured according to it
4466 switch (an_info & I40E_LINK_PAUSE_RXTX) {
4467 case I40E_LINK_PAUSE_RXTX:
4470 hw->fc.current_mode = I40E_FC_FULL;
4472 case I40E_AQ_LINK_PAUSE_RX:
4474 hw->fc.current_mode = I40E_FC_RX_PAUSE;
4476 case I40E_AQ_LINK_PAUSE_TX:
4478 hw->fc.current_mode = I40E_FC_TX_PAUSE;
4481 hw->fc.current_mode = I40E_FC_NONE;
4486 I40E_WRITE_REG(hw, I40E_PRTDCB_FCCFG,
4487 txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT);
4488 reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
4489 reg &= ~I40E_PRTDCB_MFLCN_RFCE_MASK;
4490 reg |= rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT;
4491 I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, reg);
4498 i40e_pf_setup(struct i40e_pf *pf)
4500 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4501 struct i40e_filter_control_settings settings;
4502 struct i40e_vsi *vsi;
4505 /* Clear all stats counters */
4506 pf->offset_loaded = FALSE;
4507 memset(&pf->stats, 0, sizeof(struct i40e_hw_port_stats));
4508 memset(&pf->stats_offset, 0, sizeof(struct i40e_hw_port_stats));
4510 ret = i40e_pf_get_switch_config(pf);
4511 if (ret != I40E_SUCCESS) {
4512 PMD_DRV_LOG(ERR, "Could not get switch config, err %d", ret);
4515 if (pf->flags & I40E_FLAG_FDIR) {
4516 /* make queue allocated first, let FDIR use queue pair 0*/
4517 ret = i40e_res_pool_alloc(&pf->qp_pool, I40E_DEFAULT_QP_NUM_FDIR);
4518 if (ret != I40E_FDIR_QUEUE_ID) {
4519 PMD_DRV_LOG(ERR, "queue allocation fails for FDIR :"
4521 pf->flags &= ~I40E_FLAG_FDIR;
4524 /* main VSI setup */
4525 vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, NULL, 0);
4527 PMD_DRV_LOG(ERR, "Setup of main vsi failed");
4528 return I40E_ERR_NOT_READY;
4532 /* Configure filter control */
4533 memset(&settings, 0, sizeof(settings));
4534 if (hw->func_caps.rss_table_size == ETH_RSS_RETA_SIZE_128)
4535 settings.hash_lut_size = I40E_HASH_LUT_SIZE_128;
4536 else if (hw->func_caps.rss_table_size == ETH_RSS_RETA_SIZE_512)
4537 settings.hash_lut_size = I40E_HASH_LUT_SIZE_512;
4539 PMD_DRV_LOG(ERR, "Hash lookup table size (%u) not supported\n",
4540 hw->func_caps.rss_table_size);
4541 return I40E_ERR_PARAM;
4543 PMD_DRV_LOG(INFO, "Hardware capability of hash lookup table "
4544 "size: %u\n", hw->func_caps.rss_table_size);
4545 pf->hash_lut_size = hw->func_caps.rss_table_size;
4547 /* Enable ethtype and macvlan filters */
4548 settings.enable_ethtype = TRUE;
4549 settings.enable_macvlan = TRUE;
4550 ret = i40e_set_filter_control(hw, &settings);
4552 PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
4555 /* Update flow control according to the auto negotiation */
4556 i40e_update_flow_control(hw);
4558 return I40E_SUCCESS;
4562 i40e_switch_tx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
4568 * Set or clear TX Queue Disable flags,
4569 * which is required by hardware.
4571 i40e_pre_tx_queue_cfg(hw, q_idx, on);
4572 rte_delay_us(I40E_PRE_TX_Q_CFG_WAIT_US);
4574 /* Wait until the request is finished */
4575 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
4576 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
4577 reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
4578 if (!(((reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 0x1) ^
4579 ((reg >> I40E_QTX_ENA_QENA_STAT_SHIFT)
4585 if (reg & I40E_QTX_ENA_QENA_STAT_MASK)
4586 return I40E_SUCCESS; /* already on, skip next steps */
4588 I40E_WRITE_REG(hw, I40E_QTX_HEAD(q_idx), 0);
4589 reg |= I40E_QTX_ENA_QENA_REQ_MASK;
4591 if (!(reg & I40E_QTX_ENA_QENA_STAT_MASK))
4592 return I40E_SUCCESS; /* already off, skip next steps */
4593 reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
4595 /* Write the register */
4596 I40E_WRITE_REG(hw, I40E_QTX_ENA(q_idx), reg);
4597 /* Check the result */
4598 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
4599 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
4600 reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
4602 if ((reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
4603 (reg & I40E_QTX_ENA_QENA_STAT_MASK))
4606 if (!(reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
4607 !(reg & I40E_QTX_ENA_QENA_STAT_MASK))
4611 /* Check if it is timeout */
4612 if (j >= I40E_CHK_Q_ENA_COUNT) {
4613 PMD_DRV_LOG(ERR, "Failed to %s tx queue[%u]",
4614 (on ? "enable" : "disable"), q_idx);
4615 return I40E_ERR_TIMEOUT;
4618 return I40E_SUCCESS;
4621 /* Swith on or off the tx queues */
4623 i40e_dev_switch_tx_queues(struct i40e_pf *pf, bool on)
4625 struct rte_eth_dev_data *dev_data = pf->dev_data;
4626 struct i40e_tx_queue *txq;
4627 struct rte_eth_dev *dev = pf->adapter->eth_dev;
4631 for (i = 0; i < dev_data->nb_tx_queues; i++) {
4632 txq = dev_data->tx_queues[i];
4633 /* Don't operate the queue if not configured or
4634 * if starting only per queue */
4635 if (!txq || !txq->q_set || (on && txq->tx_deferred_start))
4638 ret = i40e_dev_tx_queue_start(dev, i);
4640 ret = i40e_dev_tx_queue_stop(dev, i);
4641 if ( ret != I40E_SUCCESS)
4645 return I40E_SUCCESS;
4649 i40e_switch_rx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
4654 /* Wait until the request is finished */
4655 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
4656 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
4657 reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
4658 if (!((reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 0x1) ^
4659 ((reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 0x1))
4664 if (reg & I40E_QRX_ENA_QENA_STAT_MASK)
4665 return I40E_SUCCESS; /* Already on, skip next steps */
4666 reg |= I40E_QRX_ENA_QENA_REQ_MASK;
4668 if (!(reg & I40E_QRX_ENA_QENA_STAT_MASK))
4669 return I40E_SUCCESS; /* Already off, skip next steps */
4670 reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
4673 /* Write the register */
4674 I40E_WRITE_REG(hw, I40E_QRX_ENA(q_idx), reg);
4675 /* Check the result */
4676 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
4677 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
4678 reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
4680 if ((reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
4681 (reg & I40E_QRX_ENA_QENA_STAT_MASK))
4684 if (!(reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
4685 !(reg & I40E_QRX_ENA_QENA_STAT_MASK))
4690 /* Check if it is timeout */
4691 if (j >= I40E_CHK_Q_ENA_COUNT) {
4692 PMD_DRV_LOG(ERR, "Failed to %s rx queue[%u]",
4693 (on ? "enable" : "disable"), q_idx);
4694 return I40E_ERR_TIMEOUT;
4697 return I40E_SUCCESS;
4699 /* Switch on or off the rx queues */
4701 i40e_dev_switch_rx_queues(struct i40e_pf *pf, bool on)
4703 struct rte_eth_dev_data *dev_data = pf->dev_data;
4704 struct i40e_rx_queue *rxq;
4705 struct rte_eth_dev *dev = pf->adapter->eth_dev;
4709 for (i = 0; i < dev_data->nb_rx_queues; i++) {
4710 rxq = dev_data->rx_queues[i];
4711 /* Don't operate the queue if not configured or
4712 * if starting only per queue */
4713 if (!rxq || !rxq->q_set || (on && rxq->rx_deferred_start))
4716 ret = i40e_dev_rx_queue_start(dev, i);
4718 ret = i40e_dev_rx_queue_stop(dev, i);
4719 if (ret != I40E_SUCCESS)
4723 return I40E_SUCCESS;
4726 /* Switch on or off all the rx/tx queues */
4728 i40e_dev_switch_queues(struct i40e_pf *pf, bool on)
4733 /* enable rx queues before enabling tx queues */
4734 ret = i40e_dev_switch_rx_queues(pf, on);
4736 PMD_DRV_LOG(ERR, "Failed to switch rx queues");
4739 ret = i40e_dev_switch_tx_queues(pf, on);
4741 /* Stop tx queues before stopping rx queues */
4742 ret = i40e_dev_switch_tx_queues(pf, on);
4744 PMD_DRV_LOG(ERR, "Failed to switch tx queues");
4747 ret = i40e_dev_switch_rx_queues(pf, on);
4753 /* Initialize VSI for TX */
4755 i40e_dev_tx_init(struct i40e_pf *pf)
4757 struct rte_eth_dev_data *data = pf->dev_data;
4759 uint32_t ret = I40E_SUCCESS;
4760 struct i40e_tx_queue *txq;
4762 for (i = 0; i < data->nb_tx_queues; i++) {
4763 txq = data->tx_queues[i];
4764 if (!txq || !txq->q_set)
4766 ret = i40e_tx_queue_init(txq);
4767 if (ret != I40E_SUCCESS)
4770 if (ret == I40E_SUCCESS)
4771 i40e_set_tx_function(container_of(pf, struct i40e_adapter, pf)
4777 /* Initialize VSI for RX */
4779 i40e_dev_rx_init(struct i40e_pf *pf)
4781 struct rte_eth_dev_data *data = pf->dev_data;
4782 int ret = I40E_SUCCESS;
4784 struct i40e_rx_queue *rxq;
4786 i40e_pf_config_mq_rx(pf);
4787 for (i = 0; i < data->nb_rx_queues; i++) {
4788 rxq = data->rx_queues[i];
4789 if (!rxq || !rxq->q_set)
4792 ret = i40e_rx_queue_init(rxq);
4793 if (ret != I40E_SUCCESS) {
4794 PMD_DRV_LOG(ERR, "Failed to do RX queue "
4799 if (ret == I40E_SUCCESS)
4800 i40e_set_rx_function(container_of(pf, struct i40e_adapter, pf)
4807 i40e_dev_rxtx_init(struct i40e_pf *pf)
4811 err = i40e_dev_tx_init(pf);
4813 PMD_DRV_LOG(ERR, "Failed to do TX initialization");
4816 err = i40e_dev_rx_init(pf);
4818 PMD_DRV_LOG(ERR, "Failed to do RX initialization");
4826 i40e_vmdq_setup(struct rte_eth_dev *dev)
4828 struct rte_eth_conf *conf = &dev->data->dev_conf;
4829 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4830 int i, err, conf_vsis, j, loop;
4831 struct i40e_vsi *vsi;
4832 struct i40e_vmdq_info *vmdq_info;
4833 struct rte_eth_vmdq_rx_conf *vmdq_conf;
4834 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4837 * Disable interrupt to avoid message from VF. Furthermore, it will
4838 * avoid race condition in VSI creation/destroy.
4840 i40e_pf_disable_irq0(hw);
4842 if ((pf->flags & I40E_FLAG_VMDQ) == 0) {
4843 PMD_INIT_LOG(ERR, "FW doesn't support VMDQ");
4847 conf_vsis = conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools;
4848 if (conf_vsis > pf->max_nb_vmdq_vsi) {
4849 PMD_INIT_LOG(ERR, "VMDQ config: %u, max support:%u",
4850 conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools,
4851 pf->max_nb_vmdq_vsi);
4855 if (pf->vmdq != NULL) {
4856 PMD_INIT_LOG(INFO, "VMDQ already configured");
4860 pf->vmdq = rte_zmalloc("vmdq_info_struct",
4861 sizeof(*vmdq_info) * conf_vsis, 0);
4863 if (pf->vmdq == NULL) {
4864 PMD_INIT_LOG(ERR, "Failed to allocate memory");
4868 vmdq_conf = &conf->rx_adv_conf.vmdq_rx_conf;
4870 /* Create VMDQ VSI */
4871 for (i = 0; i < conf_vsis; i++) {
4872 vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, pf->main_vsi,
4873 vmdq_conf->enable_loop_back);
4875 PMD_INIT_LOG(ERR, "Failed to create VMDQ VSI");
4879 vmdq_info = &pf->vmdq[i];
4881 vmdq_info->vsi = vsi;
4883 pf->nb_cfg_vmdq_vsi = conf_vsis;
4885 /* Configure Vlan */
4886 loop = sizeof(vmdq_conf->pool_map[0].pools) * CHAR_BIT;
4887 for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
4888 for (j = 0; j < loop && j < pf->nb_cfg_vmdq_vsi; j++) {
4889 if (vmdq_conf->pool_map[i].pools & (1UL << j)) {
4890 PMD_INIT_LOG(INFO, "Add vlan %u to vmdq pool %u",
4891 vmdq_conf->pool_map[i].vlan_id, j);
4893 err = i40e_vsi_add_vlan(pf->vmdq[j].vsi,
4894 vmdq_conf->pool_map[i].vlan_id);
4896 PMD_INIT_LOG(ERR, "Failed to add vlan");
4904 i40e_pf_enable_irq0(hw);
4909 for (i = 0; i < conf_vsis; i++)
4910 if (pf->vmdq[i].vsi == NULL)
4913 i40e_vsi_release(pf->vmdq[i].vsi);
4917 i40e_pf_enable_irq0(hw);
4922 i40e_stat_update_32(struct i40e_hw *hw,
4930 new_data = (uint64_t)I40E_READ_REG(hw, reg);
4934 if (new_data >= *offset)
4935 *stat = (uint64_t)(new_data - *offset);
4937 *stat = (uint64_t)((new_data +
4938 ((uint64_t)1 << I40E_32_BIT_WIDTH)) - *offset);
4942 i40e_stat_update_48(struct i40e_hw *hw,
4951 new_data = (uint64_t)I40E_READ_REG(hw, loreg);
4952 new_data |= ((uint64_t)(I40E_READ_REG(hw, hireg) &
4953 I40E_16_BIT_MASK)) << I40E_32_BIT_WIDTH;
4958 if (new_data >= *offset)
4959 *stat = new_data - *offset;
4961 *stat = (uint64_t)((new_data +
4962 ((uint64_t)1 << I40E_48_BIT_WIDTH)) - *offset);
4964 *stat &= I40E_48_BIT_MASK;
4969 i40e_pf_disable_irq0(struct i40e_hw *hw)
4971 /* Disable all interrupt types */
4972 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0, 0);
4973 I40E_WRITE_FLUSH(hw);
4978 i40e_pf_enable_irq0(struct i40e_hw *hw)
4980 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
4981 I40E_PFINT_DYN_CTL0_INTENA_MASK |
4982 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
4983 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
4984 I40E_WRITE_FLUSH(hw);
4988 i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue)
4990 /* read pending request and disable first */
4991 i40e_pf_disable_irq0(hw);
4992 I40E_WRITE_REG(hw, I40E_PFINT_ICR0_ENA, I40E_PFINT_ICR0_ENA_MASK);
4993 I40E_WRITE_REG(hw, I40E_PFINT_STAT_CTL0,
4994 I40E_PFINT_STAT_CTL0_OTHER_ITR_INDX_MASK);
4997 /* Link no queues with irq0 */
4998 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
4999 I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
5003 i40e_dev_handle_vfr_event(struct rte_eth_dev *dev)
5005 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5006 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5009 uint32_t index, offset, val;
5014 * Try to find which VF trigger a reset, use absolute VF id to access
5015 * since the reg is global register.
5017 for (i = 0; i < pf->vf_num; i++) {
5018 abs_vf_id = hw->func_caps.vf_base_id + i;
5019 index = abs_vf_id / I40E_UINT32_BIT_SIZE;
5020 offset = abs_vf_id % I40E_UINT32_BIT_SIZE;
5021 val = I40E_READ_REG(hw, I40E_GLGEN_VFLRSTAT(index));
5022 /* VFR event occured */
5023 if (val & (0x1 << offset)) {
5026 /* Clear the event first */
5027 I40E_WRITE_REG(hw, I40E_GLGEN_VFLRSTAT(index),
5029 PMD_DRV_LOG(INFO, "VF %u reset occured", abs_vf_id);
5031 * Only notify a VF reset event occured,
5032 * don't trigger another SW reset
5034 ret = i40e_pf_host_vf_reset(&pf->vfs[i], 0);
5035 if (ret != I40E_SUCCESS)
5036 PMD_DRV_LOG(ERR, "Failed to do VF reset");
5042 i40e_dev_handle_aq_msg(struct rte_eth_dev *dev)
5044 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5045 struct i40e_arq_event_info info;
5046 uint16_t pending, opcode;
5049 info.buf_len = I40E_AQ_BUF_SZ;
5050 info.msg_buf = rte_zmalloc("msg_buffer", info.buf_len, 0);
5051 if (!info.msg_buf) {
5052 PMD_DRV_LOG(ERR, "Failed to allocate mem");
5058 ret = i40e_clean_arq_element(hw, &info, &pending);
5060 if (ret != I40E_SUCCESS) {
5061 PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ, "
5062 "aq_err: %u", hw->aq.asq_last_status);
5065 opcode = rte_le_to_cpu_16(info.desc.opcode);
5068 case i40e_aqc_opc_send_msg_to_pf:
5069 /* Refer to i40e_aq_send_msg_to_pf() for argument layout*/
5070 i40e_pf_host_handle_vf_msg(dev,
5071 rte_le_to_cpu_16(info.desc.retval),
5072 rte_le_to_cpu_32(info.desc.cookie_high),
5073 rte_le_to_cpu_32(info.desc.cookie_low),
5078 PMD_DRV_LOG(ERR, "Request %u is not supported yet",
5083 rte_free(info.msg_buf);
5087 * Interrupt handler is registered as the alarm callback for handling LSC
5088 * interrupt in a definite of time, in order to wait the NIC into a stable
5089 * state. Currently it waits 1 sec in i40e for the link up interrupt, and
5090 * no need for link down interrupt.
5093 i40e_dev_interrupt_delayed_handler(void *param)
5095 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
5096 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5099 /* read interrupt causes again */
5100 icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
5102 #ifdef RTE_LIBRTE_I40E_DEBUG_DRIVER
5103 if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
5104 PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error\n");
5105 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK)
5106 PMD_DRV_LOG(ERR, "ICR0: malicious programming detected\n");
5107 if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
5108 PMD_DRV_LOG(INFO, "ICR0: global reset requested\n");
5109 if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
5110 PMD_DRV_LOG(INFO, "ICR0: PCI exception\n activated\n");
5111 if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
5112 PMD_DRV_LOG(INFO, "ICR0: a change in the storm control "
5114 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
5115 PMD_DRV_LOG(ERR, "ICR0: HMC error\n");
5116 if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
5117 PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error\n");
5118 #endif /* RTE_LIBRTE_I40E_DEBUG_DRIVER */
5120 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
5121 PMD_DRV_LOG(INFO, "INT:VF reset detected\n");
5122 i40e_dev_handle_vfr_event(dev);
5124 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
5125 PMD_DRV_LOG(INFO, "INT:ADMINQ event\n");
5126 i40e_dev_handle_aq_msg(dev);
5129 /* handle the link up interrupt in an alarm callback */
5130 i40e_dev_link_update(dev, 0);
5131 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC);
5133 i40e_pf_enable_irq0(hw);
5134 rte_intr_enable(&(dev->pci_dev->intr_handle));
5138 * Interrupt handler triggered by NIC for handling
5139 * specific interrupt.
5142 * Pointer to interrupt handle.
5144 * The address of parameter (struct rte_eth_dev *) regsitered before.
5150 i40e_dev_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
5153 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
5154 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5157 /* Disable interrupt */
5158 i40e_pf_disable_irq0(hw);
5160 /* read out interrupt causes */
5161 icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
5163 /* No interrupt event indicated */
5164 if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK)) {
5165 PMD_DRV_LOG(INFO, "No interrupt event");
5168 #ifdef RTE_LIBRTE_I40E_DEBUG_DRIVER
5169 if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
5170 PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
5171 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK)
5172 PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
5173 if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
5174 PMD_DRV_LOG(INFO, "ICR0: global reset requested");
5175 if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
5176 PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
5177 if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
5178 PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
5179 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
5180 PMD_DRV_LOG(ERR, "ICR0: HMC error");
5181 if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
5182 PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
5183 #endif /* RTE_LIBRTE_I40E_DEBUG_DRIVER */
5185 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
5186 PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
5187 i40e_dev_handle_vfr_event(dev);
5189 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
5190 PMD_DRV_LOG(INFO, "ICR0: adminq event");
5191 i40e_dev_handle_aq_msg(dev);
5194 /* Link Status Change interrupt */
5195 if (icr0 & I40E_PFINT_ICR0_LINK_STAT_CHANGE_MASK) {
5196 #define I40E_US_PER_SECOND 1000000
5197 struct rte_eth_link link;
5199 PMD_DRV_LOG(INFO, "ICR0: link status changed\n");
5200 memset(&link, 0, sizeof(link));
5201 rte_i40e_dev_atomic_read_link_status(dev, &link);
5202 i40e_dev_link_update(dev, 0);
5205 * For link up interrupt, it needs to wait 1 second to let the
5206 * hardware be a stable state. Otherwise several consecutive
5207 * interrupts can be observed.
5208 * For link down interrupt, no need to wait.
5210 if (!link.link_status && rte_eal_alarm_set(I40E_US_PER_SECOND,
5211 i40e_dev_interrupt_delayed_handler, (void *)dev) >= 0)
5214 _rte_eth_dev_callback_process(dev,
5215 RTE_ETH_EVENT_INTR_LSC);
5219 /* Enable interrupt */
5220 i40e_pf_enable_irq0(hw);
5221 rte_intr_enable(&(dev->pci_dev->intr_handle));
5225 i40e_add_macvlan_filters(struct i40e_vsi *vsi,
5226 struct i40e_macvlan_filter *filter,
5229 int ele_num, ele_buff_size;
5230 int num, actual_num, i;
5232 int ret = I40E_SUCCESS;
5233 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5234 struct i40e_aqc_add_macvlan_element_data *req_list;
5236 if (filter == NULL || total == 0)
5237 return I40E_ERR_PARAM;
5238 ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
5239 ele_buff_size = hw->aq.asq_buf_size;
5241 req_list = rte_zmalloc("macvlan_add", ele_buff_size, 0);
5242 if (req_list == NULL) {
5243 PMD_DRV_LOG(ERR, "Fail to allocate memory");
5244 return I40E_ERR_NO_MEMORY;
5249 actual_num = (num + ele_num > total) ? (total - num) : ele_num;
5250 memset(req_list, 0, ele_buff_size);
5252 for (i = 0; i < actual_num; i++) {
5253 (void)rte_memcpy(req_list[i].mac_addr,
5254 &filter[num + i].macaddr, ETH_ADDR_LEN);
5255 req_list[i].vlan_tag =
5256 rte_cpu_to_le_16(filter[num + i].vlan_id);
5258 switch (filter[num + i].filter_type) {
5259 case RTE_MAC_PERFECT_MATCH:
5260 flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH |
5261 I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
5263 case RTE_MACVLAN_PERFECT_MATCH:
5264 flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
5266 case RTE_MAC_HASH_MATCH:
5267 flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH |
5268 I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
5270 case RTE_MACVLAN_HASH_MATCH:
5271 flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH;
5274 PMD_DRV_LOG(ERR, "Invalid MAC match type\n");
5275 ret = I40E_ERR_PARAM;
5279 req_list[i].queue_number = 0;
5281 req_list[i].flags = rte_cpu_to_le_16(flags);
5284 ret = i40e_aq_add_macvlan(hw, vsi->seid, req_list,
5286 if (ret != I40E_SUCCESS) {
5287 PMD_DRV_LOG(ERR, "Failed to add macvlan filter");
5291 } while (num < total);
5299 i40e_remove_macvlan_filters(struct i40e_vsi *vsi,
5300 struct i40e_macvlan_filter *filter,
5303 int ele_num, ele_buff_size;
5304 int num, actual_num, i;
5306 int ret = I40E_SUCCESS;
5307 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5308 struct i40e_aqc_remove_macvlan_element_data *req_list;
5310 if (filter == NULL || total == 0)
5311 return I40E_ERR_PARAM;
5313 ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
5314 ele_buff_size = hw->aq.asq_buf_size;
5316 req_list = rte_zmalloc("macvlan_remove", ele_buff_size, 0);
5317 if (req_list == NULL) {
5318 PMD_DRV_LOG(ERR, "Fail to allocate memory");
5319 return I40E_ERR_NO_MEMORY;
5324 actual_num = (num + ele_num > total) ? (total - num) : ele_num;
5325 memset(req_list, 0, ele_buff_size);
5327 for (i = 0; i < actual_num; i++) {
5328 (void)rte_memcpy(req_list[i].mac_addr,
5329 &filter[num + i].macaddr, ETH_ADDR_LEN);
5330 req_list[i].vlan_tag =
5331 rte_cpu_to_le_16(filter[num + i].vlan_id);
5333 switch (filter[num + i].filter_type) {
5334 case RTE_MAC_PERFECT_MATCH:
5335 flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
5336 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
5338 case RTE_MACVLAN_PERFECT_MATCH:
5339 flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
5341 case RTE_MAC_HASH_MATCH:
5342 flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH |
5343 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
5345 case RTE_MACVLAN_HASH_MATCH:
5346 flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH;
5349 PMD_DRV_LOG(ERR, "Invalid MAC filter type\n");
5350 ret = I40E_ERR_PARAM;
5353 req_list[i].flags = rte_cpu_to_le_16(flags);
5356 ret = i40e_aq_remove_macvlan(hw, vsi->seid, req_list,
5358 if (ret != I40E_SUCCESS) {
5359 PMD_DRV_LOG(ERR, "Failed to remove macvlan filter");
5363 } while (num < total);
5370 /* Find out specific MAC filter */
5371 static struct i40e_mac_filter *
5372 i40e_find_mac_filter(struct i40e_vsi *vsi,
5373 struct ether_addr *macaddr)
5375 struct i40e_mac_filter *f;
5377 TAILQ_FOREACH(f, &vsi->mac_list, next) {
5378 if (is_same_ether_addr(macaddr, &f->mac_info.mac_addr))
5386 i40e_find_vlan_filter(struct i40e_vsi *vsi,
5389 uint32_t vid_idx, vid_bit;
5391 if (vlan_id > ETH_VLAN_ID_MAX)
5394 vid_idx = I40E_VFTA_IDX(vlan_id);
5395 vid_bit = I40E_VFTA_BIT(vlan_id);
5397 if (vsi->vfta[vid_idx] & vid_bit)
5404 i40e_set_vlan_filter(struct i40e_vsi *vsi,
5405 uint16_t vlan_id, bool on)
5407 uint32_t vid_idx, vid_bit;
5409 if (vlan_id > ETH_VLAN_ID_MAX)
5412 vid_idx = I40E_VFTA_IDX(vlan_id);
5413 vid_bit = I40E_VFTA_BIT(vlan_id);
5416 vsi->vfta[vid_idx] |= vid_bit;
5418 vsi->vfta[vid_idx] &= ~vid_bit;
5422 * Find all vlan options for specific mac addr,
5423 * return with actual vlan found.
5426 i40e_find_all_vlan_for_mac(struct i40e_vsi *vsi,
5427 struct i40e_macvlan_filter *mv_f,
5428 int num, struct ether_addr *addr)
5434 * Not to use i40e_find_vlan_filter to decrease the loop time,
5435 * although the code looks complex.
5437 if (num < vsi->vlan_num)
5438 return I40E_ERR_PARAM;
5441 for (j = 0; j < I40E_VFTA_SIZE; j++) {
5443 for (k = 0; k < I40E_UINT32_BIT_SIZE; k++) {
5444 if (vsi->vfta[j] & (1 << k)) {
5446 PMD_DRV_LOG(ERR, "vlan number "
5448 return I40E_ERR_PARAM;
5450 (void)rte_memcpy(&mv_f[i].macaddr,
5451 addr, ETH_ADDR_LEN);
5453 j * I40E_UINT32_BIT_SIZE + k;
5459 return I40E_SUCCESS;
5463 i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
5464 struct i40e_macvlan_filter *mv_f,
5469 struct i40e_mac_filter *f;
5471 if (num < vsi->mac_num)
5472 return I40E_ERR_PARAM;
5474 TAILQ_FOREACH(f, &vsi->mac_list, next) {
5476 PMD_DRV_LOG(ERR, "buffer number not match");
5477 return I40E_ERR_PARAM;
5479 (void)rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
5481 mv_f[i].vlan_id = vlan;
5482 mv_f[i].filter_type = f->mac_info.filter_type;
5486 return I40E_SUCCESS;
5490 i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi)
5493 struct i40e_mac_filter *f;
5494 struct i40e_macvlan_filter *mv_f;
5495 int ret = I40E_SUCCESS;
5497 if (vsi == NULL || vsi->mac_num == 0)
5498 return I40E_ERR_PARAM;
5500 /* Case that no vlan is set */
5501 if (vsi->vlan_num == 0)
5504 num = vsi->mac_num * vsi->vlan_num;
5506 mv_f = rte_zmalloc("macvlan_data", num * sizeof(*mv_f), 0);
5508 PMD_DRV_LOG(ERR, "failed to allocate memory");
5509 return I40E_ERR_NO_MEMORY;
5513 if (vsi->vlan_num == 0) {
5514 TAILQ_FOREACH(f, &vsi->mac_list, next) {
5515 (void)rte_memcpy(&mv_f[i].macaddr,
5516 &f->mac_info.mac_addr, ETH_ADDR_LEN);
5517 mv_f[i].vlan_id = 0;
5521 TAILQ_FOREACH(f, &vsi->mac_list, next) {
5522 ret = i40e_find_all_vlan_for_mac(vsi,&mv_f[i],
5523 vsi->vlan_num, &f->mac_info.mac_addr);
5524 if (ret != I40E_SUCCESS)
5530 ret = i40e_remove_macvlan_filters(vsi, mv_f, num);
5538 i40e_vsi_add_vlan(struct i40e_vsi *vsi, uint16_t vlan)
5540 struct i40e_macvlan_filter *mv_f;
5542 int ret = I40E_SUCCESS;
5544 if (!vsi || vlan > ETHER_MAX_VLAN_ID)
5545 return I40E_ERR_PARAM;
5547 /* If it's already set, just return */
5548 if (i40e_find_vlan_filter(vsi,vlan))
5549 return I40E_SUCCESS;
5551 mac_num = vsi->mac_num;
5554 PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
5555 return I40E_ERR_PARAM;
5558 mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
5561 PMD_DRV_LOG(ERR, "failed to allocate memory");
5562 return I40E_ERR_NO_MEMORY;
5565 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
5567 if (ret != I40E_SUCCESS)
5570 ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
5572 if (ret != I40E_SUCCESS)
5575 i40e_set_vlan_filter(vsi, vlan, 1);
5585 i40e_vsi_delete_vlan(struct i40e_vsi *vsi, uint16_t vlan)
5587 struct i40e_macvlan_filter *mv_f;
5589 int ret = I40E_SUCCESS;
5592 * Vlan 0 is the generic filter for untagged packets
5593 * and can't be removed.
5595 if (!vsi || vlan == 0 || vlan > ETHER_MAX_VLAN_ID)
5596 return I40E_ERR_PARAM;
5598 /* If can't find it, just return */
5599 if (!i40e_find_vlan_filter(vsi, vlan))
5600 return I40E_ERR_PARAM;
5602 mac_num = vsi->mac_num;
5605 PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
5606 return I40E_ERR_PARAM;
5609 mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
5612 PMD_DRV_LOG(ERR, "failed to allocate memory");
5613 return I40E_ERR_NO_MEMORY;
5616 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
5618 if (ret != I40E_SUCCESS)
5621 ret = i40e_remove_macvlan_filters(vsi, mv_f, mac_num);
5623 if (ret != I40E_SUCCESS)
5626 /* This is last vlan to remove, replace all mac filter with vlan 0 */
5627 if (vsi->vlan_num == 1) {
5628 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, 0);
5629 if (ret != I40E_SUCCESS)
5632 ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
5633 if (ret != I40E_SUCCESS)
5637 i40e_set_vlan_filter(vsi, vlan, 0);
5647 i40e_vsi_add_mac(struct i40e_vsi *vsi, struct i40e_mac_filter_info *mac_filter)
5649 struct i40e_mac_filter *f;
5650 struct i40e_macvlan_filter *mv_f;
5651 int i, vlan_num = 0;
5652 int ret = I40E_SUCCESS;
5654 /* If it's add and we've config it, return */
5655 f = i40e_find_mac_filter(vsi, &mac_filter->mac_addr);
5657 return I40E_SUCCESS;
5658 if ((mac_filter->filter_type == RTE_MACVLAN_PERFECT_MATCH) ||
5659 (mac_filter->filter_type == RTE_MACVLAN_HASH_MATCH)) {
5662 * If vlan_num is 0, that's the first time to add mac,
5663 * set mask for vlan_id 0.
5665 if (vsi->vlan_num == 0) {
5666 i40e_set_vlan_filter(vsi, 0, 1);
5669 vlan_num = vsi->vlan_num;
5670 } else if ((mac_filter->filter_type == RTE_MAC_PERFECT_MATCH) ||
5671 (mac_filter->filter_type == RTE_MAC_HASH_MATCH))
5674 mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
5676 PMD_DRV_LOG(ERR, "failed to allocate memory");
5677 return I40E_ERR_NO_MEMORY;
5680 for (i = 0; i < vlan_num; i++) {
5681 mv_f[i].filter_type = mac_filter->filter_type;
5682 (void)rte_memcpy(&mv_f[i].macaddr, &mac_filter->mac_addr,
5686 if (mac_filter->filter_type == RTE_MACVLAN_PERFECT_MATCH ||
5687 mac_filter->filter_type == RTE_MACVLAN_HASH_MATCH) {
5688 ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
5689 &mac_filter->mac_addr);
5690 if (ret != I40E_SUCCESS)
5694 ret = i40e_add_macvlan_filters(vsi, mv_f, vlan_num);
5695 if (ret != I40E_SUCCESS)
5698 /* Add the mac addr into mac list */
5699 f = rte_zmalloc("macv_filter", sizeof(*f), 0);
5701 PMD_DRV_LOG(ERR, "failed to allocate memory");
5702 ret = I40E_ERR_NO_MEMORY;
5705 (void)rte_memcpy(&f->mac_info.mac_addr, &mac_filter->mac_addr,
5707 f->mac_info.filter_type = mac_filter->filter_type;
5708 TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
5719 i40e_vsi_delete_mac(struct i40e_vsi *vsi, struct ether_addr *addr)
5721 struct i40e_mac_filter *f;
5722 struct i40e_macvlan_filter *mv_f;
5724 enum rte_mac_filter_type filter_type;
5725 int ret = I40E_SUCCESS;
5727 /* Can't find it, return an error */
5728 f = i40e_find_mac_filter(vsi, addr);
5730 return I40E_ERR_PARAM;
5732 vlan_num = vsi->vlan_num;
5733 filter_type = f->mac_info.filter_type;
5734 if (filter_type == RTE_MACVLAN_PERFECT_MATCH ||
5735 filter_type == RTE_MACVLAN_HASH_MATCH) {
5736 if (vlan_num == 0) {
5737 PMD_DRV_LOG(ERR, "VLAN number shouldn't be 0\n");
5738 return I40E_ERR_PARAM;
5740 } else if (filter_type == RTE_MAC_PERFECT_MATCH ||
5741 filter_type == RTE_MAC_HASH_MATCH)
5744 mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
5746 PMD_DRV_LOG(ERR, "failed to allocate memory");
5747 return I40E_ERR_NO_MEMORY;
5750 for (i = 0; i < vlan_num; i++) {
5751 mv_f[i].filter_type = filter_type;
5752 (void)rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
5755 if (filter_type == RTE_MACVLAN_PERFECT_MATCH ||
5756 filter_type == RTE_MACVLAN_HASH_MATCH) {
5757 ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num, addr);
5758 if (ret != I40E_SUCCESS)
5762 ret = i40e_remove_macvlan_filters(vsi, mv_f, vlan_num);
5763 if (ret != I40E_SUCCESS)
5766 /* Remove the mac addr into mac list */
5767 TAILQ_REMOVE(&vsi->mac_list, f, next);
5777 /* Configure hash enable flags for RSS */
5779 i40e_config_hena(uint64_t flags)
5786 if (flags & ETH_RSS_FRAG_IPV4)
5787 hena |= 1ULL << I40E_FILTER_PCTYPE_FRAG_IPV4;
5788 if (flags & ETH_RSS_NONFRAG_IPV4_TCP)
5789 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
5790 if (flags & ETH_RSS_NONFRAG_IPV4_UDP)
5791 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
5792 if (flags & ETH_RSS_NONFRAG_IPV4_SCTP)
5793 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
5794 if (flags & ETH_RSS_NONFRAG_IPV4_OTHER)
5795 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
5796 if (flags & ETH_RSS_FRAG_IPV6)
5797 hena |= 1ULL << I40E_FILTER_PCTYPE_FRAG_IPV6;
5798 if (flags & ETH_RSS_NONFRAG_IPV6_TCP)
5799 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
5800 if (flags & ETH_RSS_NONFRAG_IPV6_UDP)
5801 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
5802 if (flags & ETH_RSS_NONFRAG_IPV6_SCTP)
5803 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_SCTP;
5804 if (flags & ETH_RSS_NONFRAG_IPV6_OTHER)
5805 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER;
5806 if (flags & ETH_RSS_L2_PAYLOAD)
5807 hena |= 1ULL << I40E_FILTER_PCTYPE_L2_PAYLOAD;
5812 /* Parse the hash enable flags */
5814 i40e_parse_hena(uint64_t flags)
5816 uint64_t rss_hf = 0;
5820 if (flags & (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV4))
5821 rss_hf |= ETH_RSS_FRAG_IPV4;
5822 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP))
5823 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
5824 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_UDP))
5825 rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
5826 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_SCTP))
5827 rss_hf |= ETH_RSS_NONFRAG_IPV4_SCTP;
5828 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER))
5829 rss_hf |= ETH_RSS_NONFRAG_IPV4_OTHER;
5830 if (flags & (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV6))
5831 rss_hf |= ETH_RSS_FRAG_IPV6;
5832 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP))
5833 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
5834 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_UDP))
5835 rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP;
5836 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_SCTP))
5837 rss_hf |= ETH_RSS_NONFRAG_IPV6_SCTP;
5838 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER))
5839 rss_hf |= ETH_RSS_NONFRAG_IPV6_OTHER;
5840 if (flags & (1ULL << I40E_FILTER_PCTYPE_L2_PAYLOAD))
5841 rss_hf |= ETH_RSS_L2_PAYLOAD;
5848 i40e_pf_disable_rss(struct i40e_pf *pf)
5850 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5853 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
5854 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
5855 hena &= ~I40E_RSS_HENA_ALL;
5856 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
5857 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
5858 I40E_WRITE_FLUSH(hw);
5862 i40e_set_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t key_len)
5864 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
5865 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5868 if (!key || key_len == 0) {
5869 PMD_DRV_LOG(DEBUG, "No key to be configured");
5871 } else if (key_len != (I40E_PFQF_HKEY_MAX_INDEX + 1) *
5873 PMD_DRV_LOG(ERR, "Invalid key length %u", key_len);
5877 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
5878 struct i40e_aqc_get_set_rss_key_data *key_dw =
5879 (struct i40e_aqc_get_set_rss_key_data *)key;
5881 ret = i40e_aq_set_rss_key(hw, vsi->vsi_id, key_dw);
5883 PMD_INIT_LOG(ERR, "Failed to configure RSS key "
5886 uint32_t *hash_key = (uint32_t *)key;
5889 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
5890 i40e_write_rx_ctl(hw, I40E_PFQF_HKEY(i), hash_key[i]);
5891 I40E_WRITE_FLUSH(hw);
5898 i40e_get_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t *key_len)
5900 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
5901 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5904 if (!key || !key_len)
5907 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
5908 ret = i40e_aq_get_rss_key(hw, vsi->vsi_id,
5909 (struct i40e_aqc_get_set_rss_key_data *)key);
5911 PMD_INIT_LOG(ERR, "Failed to get RSS key via AQ");
5915 uint32_t *key_dw = (uint32_t *)key;
5918 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
5919 key_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i));
5921 *key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t);
5927 i40e_hw_rss_hash_set(struct i40e_pf *pf, struct rte_eth_rss_conf *rss_conf)
5929 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5934 ret = i40e_set_rss_key(pf->main_vsi, rss_conf->rss_key,
5935 rss_conf->rss_key_len);
5939 rss_hf = rss_conf->rss_hf;
5940 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
5941 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
5942 hena &= ~I40E_RSS_HENA_ALL;
5943 hena |= i40e_config_hena(rss_hf);
5944 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
5945 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
5946 I40E_WRITE_FLUSH(hw);
5952 i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
5953 struct rte_eth_rss_conf *rss_conf)
5955 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5956 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5957 uint64_t rss_hf = rss_conf->rss_hf & I40E_RSS_OFFLOAD_ALL;
5960 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
5961 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
5962 if (!(hena & I40E_RSS_HENA_ALL)) { /* RSS disabled */
5963 if (rss_hf != 0) /* Enable RSS */
5965 return 0; /* Nothing to do */
5968 if (rss_hf == 0) /* Disable RSS */
5971 return i40e_hw_rss_hash_set(pf, rss_conf);
5975 i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
5976 struct rte_eth_rss_conf *rss_conf)
5978 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5979 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5982 i40e_get_rss_key(pf->main_vsi, rss_conf->rss_key,
5983 &rss_conf->rss_key_len);
5985 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
5986 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
5987 rss_conf->rss_hf = i40e_parse_hena(hena);
5993 i40e_dev_get_filter_type(uint16_t filter_type, uint16_t *flag)
5995 switch (filter_type) {
5996 case RTE_TUNNEL_FILTER_IMAC_IVLAN:
5997 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
5999 case RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID:
6000 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
6002 case RTE_TUNNEL_FILTER_IMAC_TENID:
6003 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID;
6005 case RTE_TUNNEL_FILTER_OMAC_TENID_IMAC:
6006 *flag = I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC;
6008 case ETH_TUNNEL_FILTER_IMAC:
6009 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
6011 case ETH_TUNNEL_FILTER_OIP:
6012 *flag = I40E_AQC_ADD_CLOUD_FILTER_OIP;
6014 case ETH_TUNNEL_FILTER_IIP:
6015 *flag = I40E_AQC_ADD_CLOUD_FILTER_IIP;
6018 PMD_DRV_LOG(ERR, "invalid tunnel filter type");
6026 i40e_dev_tunnel_filter_set(struct i40e_pf *pf,
6027 struct rte_eth_tunnel_filter_conf *tunnel_filter,
6031 uint8_t i, tun_type = 0;
6032 /* internal varialbe to convert ipv6 byte order */
6033 uint32_t convert_ipv6[4];
6035 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6036 struct i40e_vsi *vsi = pf->main_vsi;
6037 struct i40e_aqc_add_remove_cloud_filters_element_data *cld_filter;
6038 struct i40e_aqc_add_remove_cloud_filters_element_data *pfilter;
6040 cld_filter = rte_zmalloc("tunnel_filter",
6041 sizeof(struct i40e_aqc_add_remove_cloud_filters_element_data),
6044 if (NULL == cld_filter) {
6045 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
6048 pfilter = cld_filter;
6050 ether_addr_copy(&tunnel_filter->outer_mac, (struct ether_addr*)&pfilter->outer_mac);
6051 ether_addr_copy(&tunnel_filter->inner_mac, (struct ether_addr*)&pfilter->inner_mac);
6053 pfilter->inner_vlan = rte_cpu_to_le_16(tunnel_filter->inner_vlan);
6054 if (tunnel_filter->ip_type == RTE_TUNNEL_IPTYPE_IPV4) {
6055 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV4;
6056 rte_memcpy(&pfilter->ipaddr.v4.data,
6057 &rte_cpu_to_le_32(tunnel_filter->ip_addr.ipv4_addr),
6058 sizeof(pfilter->ipaddr.v4.data));
6060 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV6;
6061 for (i = 0; i < 4; i++) {
6063 rte_cpu_to_le_32(tunnel_filter->ip_addr.ipv6_addr[i]);
6065 rte_memcpy(&pfilter->ipaddr.v6.data, &convert_ipv6,
6066 sizeof(pfilter->ipaddr.v6.data));
6069 /* check tunneled type */
6070 switch (tunnel_filter->tunnel_type) {
6071 case RTE_TUNNEL_TYPE_VXLAN:
6072 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_VXLAN;
6074 case RTE_TUNNEL_TYPE_NVGRE:
6075 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_NVGRE_OMAC;
6077 case RTE_TUNNEL_TYPE_IP_IN_GRE:
6078 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_IP;
6081 /* Other tunnel types is not supported. */
6082 PMD_DRV_LOG(ERR, "tunnel type is not supported.");
6083 rte_free(cld_filter);
6087 val = i40e_dev_get_filter_type(tunnel_filter->filter_type,
6090 rte_free(cld_filter);
6094 pfilter->flags |= rte_cpu_to_le_16(
6095 I40E_AQC_ADD_CLOUD_FLAGS_TO_QUEUE |
6096 ip_type | (tun_type << I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT));
6097 pfilter->tenant_id = rte_cpu_to_le_32(tunnel_filter->tenant_id);
6098 pfilter->queue_number = rte_cpu_to_le_16(tunnel_filter->queue_id);
6101 ret = i40e_aq_add_cloud_filters(hw, vsi->seid, cld_filter, 1);
6103 ret = i40e_aq_remove_cloud_filters(hw, vsi->seid,
6106 rte_free(cld_filter);
6111 i40e_get_vxlan_port_idx(struct i40e_pf *pf, uint16_t port)
6115 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
6116 if (pf->vxlan_ports[i] == port)
6124 i40e_add_vxlan_port(struct i40e_pf *pf, uint16_t port)
6128 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6130 idx = i40e_get_vxlan_port_idx(pf, port);
6132 /* Check if port already exists */
6134 PMD_DRV_LOG(ERR, "Port %d already offloaded", port);
6138 /* Now check if there is space to add the new port */
6139 idx = i40e_get_vxlan_port_idx(pf, 0);
6141 PMD_DRV_LOG(ERR, "Maximum number of UDP ports reached,"
6142 "not adding port %d", port);
6146 ret = i40e_aq_add_udp_tunnel(hw, port, I40E_AQC_TUNNEL_TYPE_VXLAN,
6149 PMD_DRV_LOG(ERR, "Failed to add VXLAN UDP port %d", port);
6153 PMD_DRV_LOG(INFO, "Added port %d with AQ command with index %d",
6156 /* New port: add it and mark its index in the bitmap */
6157 pf->vxlan_ports[idx] = port;
6158 pf->vxlan_bitmap |= (1 << idx);
6160 if (!(pf->flags & I40E_FLAG_VXLAN))
6161 pf->flags |= I40E_FLAG_VXLAN;
6167 i40e_del_vxlan_port(struct i40e_pf *pf, uint16_t port)
6170 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6172 if (!(pf->flags & I40E_FLAG_VXLAN)) {
6173 PMD_DRV_LOG(ERR, "VXLAN UDP port was not configured.");
6177 idx = i40e_get_vxlan_port_idx(pf, port);
6180 PMD_DRV_LOG(ERR, "Port %d doesn't exist", port);
6184 if (i40e_aq_del_udp_tunnel(hw, idx, NULL) < 0) {
6185 PMD_DRV_LOG(ERR, "Failed to delete VXLAN UDP port %d", port);
6189 PMD_DRV_LOG(INFO, "Deleted port %d with AQ command with index %d",
6192 pf->vxlan_ports[idx] = 0;
6193 pf->vxlan_bitmap &= ~(1 << idx);
6195 if (!pf->vxlan_bitmap)
6196 pf->flags &= ~I40E_FLAG_VXLAN;
6201 /* Add UDP tunneling port */
6203 i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
6204 struct rte_eth_udp_tunnel *udp_tunnel)
6207 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6209 if (udp_tunnel == NULL)
6212 switch (udp_tunnel->prot_type) {
6213 case RTE_TUNNEL_TYPE_VXLAN:
6214 ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port);
6217 case RTE_TUNNEL_TYPE_GENEVE:
6218 case RTE_TUNNEL_TYPE_TEREDO:
6219 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
6224 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6232 /* Remove UDP tunneling port */
6234 i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
6235 struct rte_eth_udp_tunnel *udp_tunnel)
6238 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6240 if (udp_tunnel == NULL)
6243 switch (udp_tunnel->prot_type) {
6244 case RTE_TUNNEL_TYPE_VXLAN:
6245 ret = i40e_del_vxlan_port(pf, udp_tunnel->udp_port);
6247 case RTE_TUNNEL_TYPE_GENEVE:
6248 case RTE_TUNNEL_TYPE_TEREDO:
6249 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
6253 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6261 /* Calculate the maximum number of contiguous PF queues that are configured */
6263 i40e_pf_calc_configured_queues_num(struct i40e_pf *pf)
6265 struct rte_eth_dev_data *data = pf->dev_data;
6267 struct i40e_rx_queue *rxq;
6270 for (i = 0; i < pf->lan_nb_qps; i++) {
6271 rxq = data->rx_queues[i];
6272 if (rxq && rxq->q_set)
6283 i40e_pf_config_rss(struct i40e_pf *pf)
6285 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6286 struct rte_eth_rss_conf rss_conf;
6287 uint32_t i, lut = 0;
6291 * If both VMDQ and RSS enabled, not all of PF queues are configured.
6292 * It's necessary to calulate the actual PF queues that are configured.
6294 if (pf->dev_data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG)
6295 num = i40e_pf_calc_configured_queues_num(pf);
6297 num = pf->dev_data->nb_rx_queues;
6299 num = RTE_MIN(num, I40E_MAX_Q_PER_TC);
6300 PMD_INIT_LOG(INFO, "Max of contiguous %u PF queues are configured",
6304 PMD_INIT_LOG(ERR, "No PF queues are configured to enable RSS");
6308 for (i = 0, j = 0; i < hw->func_caps.rss_table_size; i++, j++) {
6311 lut = (lut << 8) | (j & ((0x1 <<
6312 hw->func_caps.rss_table_entry_width) - 1));
6314 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i >> 2), lut);
6317 rss_conf = pf->dev_data->dev_conf.rx_adv_conf.rss_conf;
6318 if ((rss_conf.rss_hf & I40E_RSS_OFFLOAD_ALL) == 0) {
6319 i40e_pf_disable_rss(pf);
6322 if (rss_conf.rss_key == NULL || rss_conf.rss_key_len <
6323 (I40E_PFQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t)) {
6324 /* Random default keys */
6325 static uint32_t rss_key_default[] = {0x6b793944,
6326 0x23504cb5, 0x5bea75b6, 0x309f4f12, 0x3dc0a2b8,
6327 0x024ddcdf, 0x339b8ca0, 0x4c4af64a, 0x34fac605,
6328 0x55d85839, 0x3a58997d, 0x2ec938e1, 0x66031581};
6330 rss_conf.rss_key = (uint8_t *)rss_key_default;
6331 rss_conf.rss_key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
6335 return i40e_hw_rss_hash_set(pf, &rss_conf);
6339 i40e_tunnel_filter_param_check(struct i40e_pf *pf,
6340 struct rte_eth_tunnel_filter_conf *filter)
6342 if (pf == NULL || filter == NULL) {
6343 PMD_DRV_LOG(ERR, "Invalid parameter");
6347 if (filter->queue_id >= pf->dev_data->nb_rx_queues) {
6348 PMD_DRV_LOG(ERR, "Invalid queue ID");
6352 if (filter->inner_vlan > ETHER_MAX_VLAN_ID) {
6353 PMD_DRV_LOG(ERR, "Invalid inner VLAN ID");
6357 if ((filter->filter_type & ETH_TUNNEL_FILTER_OMAC) &&
6358 (is_zero_ether_addr(&filter->outer_mac))) {
6359 PMD_DRV_LOG(ERR, "Cannot add NULL outer MAC address");
6363 if ((filter->filter_type & ETH_TUNNEL_FILTER_IMAC) &&
6364 (is_zero_ether_addr(&filter->inner_mac))) {
6365 PMD_DRV_LOG(ERR, "Cannot add NULL inner MAC address");
6372 #define I40E_GL_PRS_FVBM_MSK_ENA 0x80000000
6373 #define I40E_GL_PRS_FVBM(_i) (0x00269760 + ((_i) * 4))
6375 i40e_dev_set_gre_key_len(struct i40e_hw *hw, uint8_t len)
6380 val = I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2));
6381 PMD_DRV_LOG(DEBUG, "Read original GL_PRS_FVBM with 0x%08x\n", val);
6384 reg = val | I40E_GL_PRS_FVBM_MSK_ENA;
6385 } else if (len == 4) {
6386 reg = val & ~I40E_GL_PRS_FVBM_MSK_ENA;
6388 PMD_DRV_LOG(ERR, "Unsupported GRE key length of %u", len);
6393 ret = i40e_aq_debug_write_register(hw, I40E_GL_PRS_FVBM(2),
6400 PMD_DRV_LOG(DEBUG, "Read modified GL_PRS_FVBM with 0x%08x\n",
6401 I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2)));
6407 i40e_dev_global_config_set(struct i40e_hw *hw, struct rte_eth_global_cfg *cfg)
6414 switch (cfg->cfg_type) {
6415 case RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN:
6416 ret = i40e_dev_set_gre_key_len(hw, cfg->cfg.gre_key_len);
6419 PMD_DRV_LOG(ERR, "Unknown config type %u", cfg->cfg_type);
6427 i40e_filter_ctrl_global_config(struct rte_eth_dev *dev,
6428 enum rte_filter_op filter_op,
6431 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6432 int ret = I40E_ERR_PARAM;
6434 switch (filter_op) {
6435 case RTE_ETH_FILTER_SET:
6436 ret = i40e_dev_global_config_set(hw,
6437 (struct rte_eth_global_cfg *)arg);
6440 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
6448 i40e_tunnel_filter_handle(struct rte_eth_dev *dev,
6449 enum rte_filter_op filter_op,
6452 struct rte_eth_tunnel_filter_conf *filter;
6453 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6454 int ret = I40E_SUCCESS;
6456 filter = (struct rte_eth_tunnel_filter_conf *)(arg);
6458 if (i40e_tunnel_filter_param_check(pf, filter) < 0)
6459 return I40E_ERR_PARAM;
6461 switch (filter_op) {
6462 case RTE_ETH_FILTER_NOP:
6463 if (!(pf->flags & I40E_FLAG_VXLAN))
6464 ret = I40E_NOT_SUPPORTED;
6466 case RTE_ETH_FILTER_ADD:
6467 ret = i40e_dev_tunnel_filter_set(pf, filter, 1);
6469 case RTE_ETH_FILTER_DELETE:
6470 ret = i40e_dev_tunnel_filter_set(pf, filter, 0);
6473 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
6474 ret = I40E_ERR_PARAM;
6482 i40e_pf_config_mq_rx(struct i40e_pf *pf)
6485 enum rte_eth_rx_mq_mode mq_mode = pf->dev_data->dev_conf.rxmode.mq_mode;
6488 if (mq_mode & ETH_MQ_RX_RSS_FLAG)
6489 ret = i40e_pf_config_rss(pf);
6491 i40e_pf_disable_rss(pf);
6496 /* Get the symmetric hash enable configurations per port */
6498 i40e_get_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t *enable)
6500 uint32_t reg = i40e_read_rx_ctl(hw, I40E_PRTQF_CTL_0);
6502 *enable = reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK ? 1 : 0;
6505 /* Set the symmetric hash enable configurations per port */
6507 i40e_set_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t enable)
6509 uint32_t reg = i40e_read_rx_ctl(hw, I40E_PRTQF_CTL_0);
6512 if (reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK) {
6513 PMD_DRV_LOG(INFO, "Symmetric hash has already "
6517 reg |= I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
6519 if (!(reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK)) {
6520 PMD_DRV_LOG(INFO, "Symmetric hash has already "
6524 reg &= ~I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
6526 i40e_write_rx_ctl(hw, I40E_PRTQF_CTL_0, reg);
6527 I40E_WRITE_FLUSH(hw);
6531 * Get global configurations of hash function type and symmetric hash enable
6532 * per flow type (pctype). Note that global configuration means it affects all
6533 * the ports on the same NIC.
6536 i40e_get_hash_filter_global_config(struct i40e_hw *hw,
6537 struct rte_eth_hash_global_conf *g_cfg)
6539 uint32_t reg, mask = I40E_FLOW_TYPES;
6541 enum i40e_filter_pctype pctype;
6543 memset(g_cfg, 0, sizeof(*g_cfg));
6544 reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
6545 if (reg & I40E_GLQF_CTL_HTOEP_MASK)
6546 g_cfg->hash_func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
6548 g_cfg->hash_func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
6549 PMD_DRV_LOG(DEBUG, "Hash function is %s",
6550 (reg & I40E_GLQF_CTL_HTOEP_MASK) ? "Toeplitz" : "Simple XOR");
6552 for (i = 0; mask && i < RTE_ETH_FLOW_MAX; i++) {
6553 if (!(mask & (1UL << i)))
6555 mask &= ~(1UL << i);
6556 /* Bit set indicats the coresponding flow type is supported */
6557 g_cfg->valid_bit_mask[0] |= (1UL << i);
6558 pctype = i40e_flowtype_to_pctype(i);
6559 reg = i40e_read_rx_ctl(hw, I40E_GLQF_HSYM(pctype));
6560 if (reg & I40E_GLQF_HSYM_SYMH_ENA_MASK)
6561 g_cfg->sym_hash_enable_mask[0] |= (1UL << i);
6568 i40e_hash_global_config_check(struct rte_eth_hash_global_conf *g_cfg)
6571 uint32_t mask0, i40e_mask = I40E_FLOW_TYPES;
6573 if (g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_TOEPLITZ &&
6574 g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_SIMPLE_XOR &&
6575 g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_DEFAULT) {
6576 PMD_DRV_LOG(ERR, "Unsupported hash function type %d",
6582 * As i40e supports less than 32 flow types, only first 32 bits need to
6585 mask0 = g_cfg->valid_bit_mask[0];
6586 for (i = 0; i < RTE_SYM_HASH_MASK_ARRAY_SIZE; i++) {
6588 /* Check if any unsupported flow type configured */
6589 if ((mask0 | i40e_mask) ^ i40e_mask)
6592 if (g_cfg->valid_bit_mask[i])
6600 PMD_DRV_LOG(ERR, "i40e unsupported flow type bit(s) configured");
6606 * Set global configurations of hash function type and symmetric hash enable
6607 * per flow type (pctype). Note any modifying global configuration will affect
6608 * all the ports on the same NIC.
6611 i40e_set_hash_filter_global_config(struct i40e_hw *hw,
6612 struct rte_eth_hash_global_conf *g_cfg)
6617 uint32_t mask0 = g_cfg->valid_bit_mask[0];
6618 enum i40e_filter_pctype pctype;
6620 /* Check the input parameters */
6621 ret = i40e_hash_global_config_check(g_cfg);
6625 for (i = 0; mask0 && i < UINT32_BIT; i++) {
6626 if (!(mask0 & (1UL << i)))
6628 mask0 &= ~(1UL << i);
6629 pctype = i40e_flowtype_to_pctype(i);
6630 reg = (g_cfg->sym_hash_enable_mask[0] & (1UL << i)) ?
6631 I40E_GLQF_HSYM_SYMH_ENA_MASK : 0;
6632 i40e_write_rx_ctl(hw, I40E_GLQF_HSYM(pctype), reg);
6635 reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
6636 if (g_cfg->hash_func == RTE_ETH_HASH_FUNCTION_TOEPLITZ) {
6638 if (reg & I40E_GLQF_CTL_HTOEP_MASK) {
6639 PMD_DRV_LOG(DEBUG, "Hash function already set to "
6643 reg |= I40E_GLQF_CTL_HTOEP_MASK;
6644 } else if (g_cfg->hash_func == RTE_ETH_HASH_FUNCTION_SIMPLE_XOR) {
6646 if (!(reg & I40E_GLQF_CTL_HTOEP_MASK)) {
6647 PMD_DRV_LOG(DEBUG, "Hash function already set to "
6651 reg &= ~I40E_GLQF_CTL_HTOEP_MASK;
6653 /* Use the default, and keep it as it is */
6656 i40e_write_rx_ctl(hw, I40E_GLQF_CTL, reg);
6659 I40E_WRITE_FLUSH(hw);
6665 * Valid input sets for hash and flow director filters per PCTYPE
6668 i40e_get_valid_input_set(enum i40e_filter_pctype pctype,
6669 enum rte_filter_type filter)
6673 static const uint64_t valid_hash_inset_table[] = {
6674 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
6675 I40E_INSET_DMAC | I40E_INSET_SMAC |
6676 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6677 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_SRC |
6678 I40E_INSET_IPV4_DST | I40E_INSET_IPV4_TOS |
6679 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
6680 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
6681 I40E_INSET_FLEX_PAYLOAD,
6682 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
6683 I40E_INSET_DMAC | I40E_INSET_SMAC |
6684 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6685 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
6686 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
6687 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
6688 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6689 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6690 I40E_INSET_FLEX_PAYLOAD,
6691 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
6692 I40E_INSET_DMAC | I40E_INSET_SMAC |
6693 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6694 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
6695 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
6696 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
6697 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6698 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6699 I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
6700 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
6701 I40E_INSET_DMAC | I40E_INSET_SMAC |
6702 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6703 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
6704 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
6705 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
6706 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6707 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6708 I40E_INSET_SCTP_VT | I40E_INSET_FLEX_PAYLOAD,
6709 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
6710 I40E_INSET_DMAC | I40E_INSET_SMAC |
6711 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6712 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
6713 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
6714 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
6715 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6716 I40E_INSET_FLEX_PAYLOAD,
6717 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
6718 I40E_INSET_DMAC | I40E_INSET_SMAC |
6719 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6720 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
6721 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
6722 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_TUNNEL_DMAC |
6723 I40E_INSET_TUNNEL_ID | I40E_INSET_IPV6_SRC |
6724 I40E_INSET_IPV6_DST | I40E_INSET_FLEX_PAYLOAD,
6725 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
6726 I40E_INSET_DMAC | I40E_INSET_SMAC |
6727 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6728 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
6729 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
6730 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
6731 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
6732 I40E_INSET_DST_PORT | I40E_INSET_FLEX_PAYLOAD,
6733 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
6734 I40E_INSET_DMAC | I40E_INSET_SMAC |
6735 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6736 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
6737 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
6738 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
6739 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
6740 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
6741 I40E_INSET_FLEX_PAYLOAD,
6742 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
6743 I40E_INSET_DMAC | I40E_INSET_SMAC |
6744 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6745 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
6746 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
6747 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
6748 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
6749 I40E_INSET_DST_PORT | I40E_INSET_SCTP_VT |
6750 I40E_INSET_FLEX_PAYLOAD,
6751 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
6752 I40E_INSET_DMAC | I40E_INSET_SMAC |
6753 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6754 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
6755 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
6756 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
6757 I40E_INSET_IPV6_DST | I40E_INSET_TUNNEL_ID |
6758 I40E_INSET_FLEX_PAYLOAD,
6759 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
6760 I40E_INSET_DMAC | I40E_INSET_SMAC |
6761 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6762 I40E_INSET_VLAN_TUNNEL | I40E_INSET_LAST_ETHER_TYPE |
6763 I40E_INSET_FLEX_PAYLOAD,
6767 * Flow director supports only fields defined in
6768 * union rte_eth_fdir_flow.
6770 static const uint64_t valid_fdir_inset_table[] = {
6771 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
6772 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6773 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6774 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
6775 I40E_INSET_IPV4_TTL,
6776 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
6777 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6778 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6779 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
6780 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
6781 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
6782 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6783 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6784 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
6785 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
6786 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
6787 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6788 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6789 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
6790 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6792 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
6793 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6794 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6795 I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
6796 I40E_INSET_IPV4_TTL,
6797 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
6798 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6799 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6800 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
6801 I40E_INSET_IPV6_HOP_LIMIT,
6802 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
6803 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6804 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6805 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
6806 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
6807 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
6808 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6809 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6810 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
6811 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
6812 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
6813 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6814 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6815 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
6816 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6818 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
6819 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6820 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6821 I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
6822 I40E_INSET_IPV6_HOP_LIMIT,
6823 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
6824 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6825 I40E_INSET_LAST_ETHER_TYPE,
6828 if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
6830 if (filter == RTE_ETH_FILTER_HASH)
6831 valid = valid_hash_inset_table[pctype];
6833 valid = valid_fdir_inset_table[pctype];
6839 * Validate if the input set is allowed for a specific PCTYPE
6842 i40e_validate_input_set(enum i40e_filter_pctype pctype,
6843 enum rte_filter_type filter, uint64_t inset)
6847 valid = i40e_get_valid_input_set(pctype, filter);
6848 if (inset & (~valid))
6854 /* default input set fields combination per pctype */
6856 i40e_get_default_input_set(uint16_t pctype)
6858 static const uint64_t default_inset_table[] = {
6859 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
6860 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
6861 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
6862 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6863 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
6864 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
6865 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6866 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
6867 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
6868 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6869 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6871 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
6872 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
6873 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
6874 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
6875 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
6876 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6877 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
6878 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
6879 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6880 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
6881 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
6882 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6883 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6885 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
6886 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
6887 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
6888 I40E_INSET_LAST_ETHER_TYPE,
6891 if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
6894 return default_inset_table[pctype];
6898 * Parse the input set from index to logical bit masks
6901 i40e_parse_input_set(uint64_t *inset,
6902 enum i40e_filter_pctype pctype,
6903 enum rte_eth_input_set_field *field,
6909 static const struct {
6910 enum rte_eth_input_set_field field;
6912 } inset_convert_table[] = {
6913 {RTE_ETH_INPUT_SET_NONE, I40E_INSET_NONE},
6914 {RTE_ETH_INPUT_SET_L2_SRC_MAC, I40E_INSET_SMAC},
6915 {RTE_ETH_INPUT_SET_L2_DST_MAC, I40E_INSET_DMAC},
6916 {RTE_ETH_INPUT_SET_L2_OUTER_VLAN, I40E_INSET_VLAN_OUTER},
6917 {RTE_ETH_INPUT_SET_L2_INNER_VLAN, I40E_INSET_VLAN_INNER},
6918 {RTE_ETH_INPUT_SET_L2_ETHERTYPE, I40E_INSET_LAST_ETHER_TYPE},
6919 {RTE_ETH_INPUT_SET_L3_SRC_IP4, I40E_INSET_IPV4_SRC},
6920 {RTE_ETH_INPUT_SET_L3_DST_IP4, I40E_INSET_IPV4_DST},
6921 {RTE_ETH_INPUT_SET_L3_IP4_TOS, I40E_INSET_IPV4_TOS},
6922 {RTE_ETH_INPUT_SET_L3_IP4_PROTO, I40E_INSET_IPV4_PROTO},
6923 {RTE_ETH_INPUT_SET_L3_IP4_TTL, I40E_INSET_IPV4_TTL},
6924 {RTE_ETH_INPUT_SET_L3_SRC_IP6, I40E_INSET_IPV6_SRC},
6925 {RTE_ETH_INPUT_SET_L3_DST_IP6, I40E_INSET_IPV6_DST},
6926 {RTE_ETH_INPUT_SET_L3_IP6_TC, I40E_INSET_IPV6_TC},
6927 {RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER,
6928 I40E_INSET_IPV6_NEXT_HDR},
6929 {RTE_ETH_INPUT_SET_L3_IP6_HOP_LIMITS,
6930 I40E_INSET_IPV6_HOP_LIMIT},
6931 {RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT, I40E_INSET_SRC_PORT},
6932 {RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT, I40E_INSET_SRC_PORT},
6933 {RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT, I40E_INSET_SRC_PORT},
6934 {RTE_ETH_INPUT_SET_L4_UDP_DST_PORT, I40E_INSET_DST_PORT},
6935 {RTE_ETH_INPUT_SET_L4_TCP_DST_PORT, I40E_INSET_DST_PORT},
6936 {RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT, I40E_INSET_DST_PORT},
6937 {RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG,
6938 I40E_INSET_SCTP_VT},
6939 {RTE_ETH_INPUT_SET_TUNNEL_L2_INNER_DST_MAC,
6940 I40E_INSET_TUNNEL_DMAC},
6941 {RTE_ETH_INPUT_SET_TUNNEL_L2_INNER_VLAN,
6942 I40E_INSET_VLAN_TUNNEL},
6943 {RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY,
6944 I40E_INSET_TUNNEL_ID},
6945 {RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY, I40E_INSET_TUNNEL_ID},
6946 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD,
6947 I40E_INSET_FLEX_PAYLOAD_W1},
6948 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD,
6949 I40E_INSET_FLEX_PAYLOAD_W2},
6950 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD,
6951 I40E_INSET_FLEX_PAYLOAD_W3},
6952 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD,
6953 I40E_INSET_FLEX_PAYLOAD_W4},
6954 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD,
6955 I40E_INSET_FLEX_PAYLOAD_W5},
6956 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD,
6957 I40E_INSET_FLEX_PAYLOAD_W6},
6958 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD,
6959 I40E_INSET_FLEX_PAYLOAD_W7},
6960 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD,
6961 I40E_INSET_FLEX_PAYLOAD_W8},
6964 if (!inset || !field || size > RTE_ETH_INSET_SIZE_MAX)
6967 /* Only one item allowed for default or all */
6969 if (field[0] == RTE_ETH_INPUT_SET_DEFAULT) {
6970 *inset = i40e_get_default_input_set(pctype);
6972 } else if (field[0] == RTE_ETH_INPUT_SET_NONE) {
6973 *inset = I40E_INSET_NONE;
6978 for (i = 0, *inset = 0; i < size; i++) {
6979 for (j = 0; j < RTE_DIM(inset_convert_table); j++) {
6980 if (field[i] == inset_convert_table[j].field) {
6981 *inset |= inset_convert_table[j].inset;
6986 /* It contains unsupported input set, return immediately */
6987 if (j == RTE_DIM(inset_convert_table))
6995 * Translate the input set from bit masks to register aware bit masks
6999 i40e_translate_input_set_reg(uint64_t input)
7004 static const struct {
7008 {I40E_INSET_DMAC, I40E_REG_INSET_L2_DMAC},
7009 {I40E_INSET_SMAC, I40E_REG_INSET_L2_SMAC},
7010 {I40E_INSET_VLAN_OUTER, I40E_REG_INSET_L2_OUTER_VLAN},
7011 {I40E_INSET_VLAN_INNER, I40E_REG_INSET_L2_INNER_VLAN},
7012 {I40E_INSET_LAST_ETHER_TYPE, I40E_REG_INSET_LAST_ETHER_TYPE},
7013 {I40E_INSET_IPV4_SRC, I40E_REG_INSET_L3_SRC_IP4},
7014 {I40E_INSET_IPV4_DST, I40E_REG_INSET_L3_DST_IP4},
7015 {I40E_INSET_IPV4_TOS, I40E_REG_INSET_L3_IP4_TOS},
7016 {I40E_INSET_IPV4_PROTO, I40E_REG_INSET_L3_IP4_PROTO},
7017 {I40E_INSET_IPV4_TTL, I40E_REG_INSET_L3_IP4_TTL},
7018 {I40E_INSET_IPV6_SRC, I40E_REG_INSET_L3_SRC_IP6},
7019 {I40E_INSET_IPV6_DST, I40E_REG_INSET_L3_DST_IP6},
7020 {I40E_INSET_IPV6_TC, I40E_REG_INSET_L3_IP6_TC},
7021 {I40E_INSET_IPV6_NEXT_HDR, I40E_REG_INSET_L3_IP6_NEXT_HDR},
7022 {I40E_INSET_IPV6_HOP_LIMIT, I40E_REG_INSET_L3_IP6_HOP_LIMIT},
7023 {I40E_INSET_SRC_PORT, I40E_REG_INSET_L4_SRC_PORT},
7024 {I40E_INSET_DST_PORT, I40E_REG_INSET_L4_DST_PORT},
7025 {I40E_INSET_SCTP_VT, I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG},
7026 {I40E_INSET_TUNNEL_ID, I40E_REG_INSET_TUNNEL_ID},
7027 {I40E_INSET_TUNNEL_DMAC,
7028 I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC},
7029 {I40E_INSET_TUNNEL_IPV4_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP4},
7030 {I40E_INSET_TUNNEL_IPV6_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP6},
7031 {I40E_INSET_TUNNEL_SRC_PORT,
7032 I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT},
7033 {I40E_INSET_TUNNEL_DST_PORT,
7034 I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT},
7035 {I40E_INSET_VLAN_TUNNEL, I40E_REG_INSET_TUNNEL_VLAN},
7036 {I40E_INSET_FLEX_PAYLOAD_W1, I40E_REG_INSET_FLEX_PAYLOAD_WORD1},
7037 {I40E_INSET_FLEX_PAYLOAD_W2, I40E_REG_INSET_FLEX_PAYLOAD_WORD2},
7038 {I40E_INSET_FLEX_PAYLOAD_W3, I40E_REG_INSET_FLEX_PAYLOAD_WORD3},
7039 {I40E_INSET_FLEX_PAYLOAD_W4, I40E_REG_INSET_FLEX_PAYLOAD_WORD4},
7040 {I40E_INSET_FLEX_PAYLOAD_W5, I40E_REG_INSET_FLEX_PAYLOAD_WORD5},
7041 {I40E_INSET_FLEX_PAYLOAD_W6, I40E_REG_INSET_FLEX_PAYLOAD_WORD6},
7042 {I40E_INSET_FLEX_PAYLOAD_W7, I40E_REG_INSET_FLEX_PAYLOAD_WORD7},
7043 {I40E_INSET_FLEX_PAYLOAD_W8, I40E_REG_INSET_FLEX_PAYLOAD_WORD8},
7049 /* Translate input set to register aware inset */
7050 for (i = 0; i < RTE_DIM(inset_map); i++) {
7051 if (input & inset_map[i].inset)
7052 val |= inset_map[i].inset_reg;
7059 i40e_generate_inset_mask_reg(uint64_t inset, uint32_t *mask, uint8_t nb_elem)
7062 uint64_t inset_need_mask = inset;
7064 static const struct {
7067 } inset_mask_map[] = {
7068 {I40E_INSET_IPV4_TOS, I40E_INSET_IPV4_TOS_MASK},
7069 {I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL, 0},
7070 {I40E_INSET_IPV4_PROTO, I40E_INSET_IPV4_PROTO_MASK},
7071 {I40E_INSET_IPV4_TTL, I40E_INSET_IPv4_TTL_MASK},
7072 {I40E_INSET_IPV6_TC, I40E_INSET_IPV6_TC_MASK},
7073 {I40E_INSET_IPV6_NEXT_HDR | I40E_INSET_IPV6_HOP_LIMIT, 0},
7074 {I40E_INSET_IPV6_NEXT_HDR, I40E_INSET_IPV6_NEXT_HDR_MASK},
7075 {I40E_INSET_IPV6_HOP_LIMIT, I40E_INSET_IPV6_HOP_LIMIT_MASK},
7078 if (!inset || !mask || !nb_elem)
7081 for (i = 0, idx = 0; i < RTE_DIM(inset_mask_map); i++) {
7082 /* Clear the inset bit, if no MASK is required,
7083 * for example proto + ttl
7085 if ((inset & inset_mask_map[i].inset) ==
7086 inset_mask_map[i].inset && inset_mask_map[i].mask == 0)
7087 inset_need_mask &= ~inset_mask_map[i].inset;
7088 if (!inset_need_mask)
7091 for (i = 0, idx = 0; i < RTE_DIM(inset_mask_map); i++) {
7092 if ((inset_need_mask & inset_mask_map[i].inset) ==
7093 inset_mask_map[i].inset) {
7094 if (idx >= nb_elem) {
7095 PMD_DRV_LOG(ERR, "exceed maximal number of bitmasks");
7098 mask[idx] = inset_mask_map[i].mask;
7107 i40e_check_write_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
7109 uint32_t reg = i40e_read_rx_ctl(hw, addr);
7111 PMD_DRV_LOG(DEBUG, "[0x%08x] original: 0x%08x\n", addr, reg);
7113 i40e_write_rx_ctl(hw, addr, val);
7114 PMD_DRV_LOG(DEBUG, "[0x%08x] after: 0x%08x\n", addr,
7115 (uint32_t)i40e_read_rx_ctl(hw, addr));
7119 i40e_filter_input_set_init(struct i40e_pf *pf)
7121 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7122 enum i40e_filter_pctype pctype;
7123 uint64_t input_set, inset_reg;
7124 uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
7127 for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
7128 pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++) {
7129 if (!I40E_VALID_PCTYPE(pctype))
7131 input_set = i40e_get_default_input_set(pctype);
7133 num = i40e_generate_inset_mask_reg(input_set, mask_reg,
7134 I40E_INSET_MASK_NUM_REG);
7137 inset_reg = i40e_translate_input_set_reg(input_set);
7139 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
7140 (uint32_t)(inset_reg & UINT32_MAX));
7141 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
7142 (uint32_t)((inset_reg >>
7143 I40E_32_BIT_WIDTH) & UINT32_MAX));
7144 i40e_check_write_reg(hw, I40E_GLQF_HASH_INSET(0, pctype),
7145 (uint32_t)(inset_reg & UINT32_MAX));
7146 i40e_check_write_reg(hw, I40E_GLQF_HASH_INSET(1, pctype),
7147 (uint32_t)((inset_reg >>
7148 I40E_32_BIT_WIDTH) & UINT32_MAX));
7150 for (i = 0; i < num; i++) {
7151 i40e_check_write_reg(hw, I40E_GLQF_FD_MSK(i, pctype),
7153 i40e_check_write_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
7156 /*clear unused mask registers of the pctype */
7157 for (i = num; i < I40E_INSET_MASK_NUM_REG; i++) {
7158 i40e_check_write_reg(hw, I40E_GLQF_FD_MSK(i, pctype),
7160 i40e_check_write_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
7163 I40E_WRITE_FLUSH(hw);
7165 /* store the default input set */
7166 pf->hash_input_set[pctype] = input_set;
7167 pf->fdir.input_set[pctype] = input_set;
7172 i40e_hash_filter_inset_select(struct i40e_hw *hw,
7173 struct rte_eth_input_set_conf *conf)
7175 struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
7176 enum i40e_filter_pctype pctype;
7177 uint64_t input_set, inset_reg = 0;
7178 uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
7182 PMD_DRV_LOG(ERR, "Invalid pointer");
7185 if (conf->op != RTE_ETH_INPUT_SET_SELECT &&
7186 conf->op != RTE_ETH_INPUT_SET_ADD) {
7187 PMD_DRV_LOG(ERR, "Unsupported input set operation");
7191 pctype = i40e_flowtype_to_pctype(conf->flow_type);
7192 if (pctype == 0 || pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD) {
7193 PMD_DRV_LOG(ERR, "Not supported flow type (%u)",
7198 ret = i40e_parse_input_set(&input_set, pctype, conf->field,
7201 PMD_DRV_LOG(ERR, "Failed to parse input set");
7204 if (i40e_validate_input_set(pctype, RTE_ETH_FILTER_HASH,
7206 PMD_DRV_LOG(ERR, "Invalid input set");
7209 if (conf->op == RTE_ETH_INPUT_SET_ADD) {
7210 /* get inset value in register */
7211 inset_reg = i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, pctype));
7212 inset_reg <<= I40E_32_BIT_WIDTH;
7213 inset_reg |= i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, pctype));
7214 input_set |= pf->hash_input_set[pctype];
7216 num = i40e_generate_inset_mask_reg(input_set, mask_reg,
7217 I40E_INSET_MASK_NUM_REG);
7221 inset_reg |= i40e_translate_input_set_reg(input_set);
7223 i40e_check_write_reg(hw, I40E_GLQF_HASH_INSET(0, pctype),
7224 (uint32_t)(inset_reg & UINT32_MAX));
7225 i40e_check_write_reg(hw, I40E_GLQF_HASH_INSET(1, pctype),
7226 (uint32_t)((inset_reg >>
7227 I40E_32_BIT_WIDTH) & UINT32_MAX));
7229 for (i = 0; i < num; i++)
7230 i40e_check_write_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
7232 /*clear unused mask registers of the pctype */
7233 for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
7234 i40e_check_write_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
7236 I40E_WRITE_FLUSH(hw);
7238 pf->hash_input_set[pctype] = input_set;
7243 i40e_fdir_filter_inset_select(struct i40e_pf *pf,
7244 struct rte_eth_input_set_conf *conf)
7246 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7247 enum i40e_filter_pctype pctype;
7248 uint64_t input_set, inset_reg = 0;
7249 uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
7253 PMD_DRV_LOG(ERR, "Invalid pointer");
7256 if (conf->op != RTE_ETH_INPUT_SET_SELECT &&
7257 conf->op != RTE_ETH_INPUT_SET_ADD) {
7258 PMD_DRV_LOG(ERR, "Unsupported input set operation");
7262 pctype = i40e_flowtype_to_pctype(conf->flow_type);
7263 if (pctype == 0 || pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD) {
7264 PMD_DRV_LOG(ERR, "Not supported flow type (%u)",
7268 ret = i40e_parse_input_set(&input_set, pctype, conf->field,
7271 PMD_DRV_LOG(ERR, "Failed to parse input set");
7274 if (i40e_validate_input_set(pctype, RTE_ETH_FILTER_FDIR,
7276 PMD_DRV_LOG(ERR, "Invalid input set");
7280 /* get inset value in register */
7281 inset_reg = i40e_read_rx_ctl(hw, I40E_PRTQF_FD_INSET(pctype, 1));
7282 inset_reg <<= I40E_32_BIT_WIDTH;
7283 inset_reg |= i40e_read_rx_ctl(hw, I40E_PRTQF_FD_INSET(pctype, 0));
7285 /* Can not change the inset reg for flex payload for fdir,
7286 * it is done by writing I40E_PRTQF_FD_FLXINSET
7287 * in i40e_set_flex_mask_on_pctype.
7289 if (conf->op == RTE_ETH_INPUT_SET_SELECT)
7290 inset_reg &= I40E_REG_INSET_FLEX_PAYLOAD_WORDS;
7292 input_set |= pf->fdir.input_set[pctype];
7293 num = i40e_generate_inset_mask_reg(input_set, mask_reg,
7294 I40E_INSET_MASK_NUM_REG);
7298 inset_reg |= i40e_translate_input_set_reg(input_set);
7300 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
7301 (uint32_t)(inset_reg & UINT32_MAX));
7302 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
7303 (uint32_t)((inset_reg >>
7304 I40E_32_BIT_WIDTH) & UINT32_MAX));
7306 for (i = 0; i < num; i++)
7307 i40e_check_write_reg(hw, I40E_GLQF_FD_MSK(i, pctype),
7309 /*clear unused mask registers of the pctype */
7310 for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
7311 i40e_check_write_reg(hw, I40E_GLQF_FD_MSK(i, pctype),
7313 I40E_WRITE_FLUSH(hw);
7315 pf->fdir.input_set[pctype] = input_set;
7320 i40e_hash_filter_get(struct i40e_hw *hw, struct rte_eth_hash_filter_info *info)
7325 PMD_DRV_LOG(ERR, "Invalid pointer");
7329 switch (info->info_type) {
7330 case RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT:
7331 i40e_get_symmetric_hash_enable_per_port(hw,
7332 &(info->info.enable));
7334 case RTE_ETH_HASH_FILTER_GLOBAL_CONFIG:
7335 ret = i40e_get_hash_filter_global_config(hw,
7336 &(info->info.global_conf));
7339 PMD_DRV_LOG(ERR, "Hash filter info type (%d) not supported",
7349 i40e_hash_filter_set(struct i40e_hw *hw, struct rte_eth_hash_filter_info *info)
7354 PMD_DRV_LOG(ERR, "Invalid pointer");
7358 switch (info->info_type) {
7359 case RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT:
7360 i40e_set_symmetric_hash_enable_per_port(hw, info->info.enable);
7362 case RTE_ETH_HASH_FILTER_GLOBAL_CONFIG:
7363 ret = i40e_set_hash_filter_global_config(hw,
7364 &(info->info.global_conf));
7366 case RTE_ETH_HASH_FILTER_INPUT_SET_SELECT:
7367 ret = i40e_hash_filter_inset_select(hw,
7368 &(info->info.input_set_conf));
7372 PMD_DRV_LOG(ERR, "Hash filter info type (%d) not supported",
7381 /* Operations for hash function */
7383 i40e_hash_filter_ctrl(struct rte_eth_dev *dev,
7384 enum rte_filter_op filter_op,
7387 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7390 switch (filter_op) {
7391 case RTE_ETH_FILTER_NOP:
7393 case RTE_ETH_FILTER_GET:
7394 ret = i40e_hash_filter_get(hw,
7395 (struct rte_eth_hash_filter_info *)arg);
7397 case RTE_ETH_FILTER_SET:
7398 ret = i40e_hash_filter_set(hw,
7399 (struct rte_eth_hash_filter_info *)arg);
7402 PMD_DRV_LOG(WARNING, "Filter operation (%d) not supported",
7412 * Configure ethertype filter, which can director packet by filtering
7413 * with mac address and ether_type or only ether_type
7416 i40e_ethertype_filter_set(struct i40e_pf *pf,
7417 struct rte_eth_ethertype_filter *filter,
7420 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7421 struct i40e_control_filter_stats stats;
7425 if (filter->queue >= pf->dev_data->nb_rx_queues) {
7426 PMD_DRV_LOG(ERR, "Invalid queue ID");
7429 if (filter->ether_type == ETHER_TYPE_IPv4 ||
7430 filter->ether_type == ETHER_TYPE_IPv6) {
7431 PMD_DRV_LOG(ERR, "unsupported ether_type(0x%04x) in"
7432 " control packet filter.", filter->ether_type);
7435 if (filter->ether_type == ETHER_TYPE_VLAN)
7436 PMD_DRV_LOG(WARNING, "filter vlan ether_type in first tag is"
7439 if (!(filter->flags & RTE_ETHTYPE_FLAGS_MAC))
7440 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
7441 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP)
7442 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
7443 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
7445 memset(&stats, 0, sizeof(stats));
7446 ret = i40e_aq_add_rem_control_packet_filter(hw,
7447 filter->mac_addr.addr_bytes,
7448 filter->ether_type, flags,
7450 filter->queue, add, &stats, NULL);
7452 PMD_DRV_LOG(INFO, "add/rem control packet filter, return %d,"
7453 " mac_etype_used = %u, etype_used = %u,"
7454 " mac_etype_free = %u, etype_free = %u\n",
7455 ret, stats.mac_etype_used, stats.etype_used,
7456 stats.mac_etype_free, stats.etype_free);
7463 * Handle operations for ethertype filter.
7466 i40e_ethertype_filter_handle(struct rte_eth_dev *dev,
7467 enum rte_filter_op filter_op,
7470 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7473 if (filter_op == RTE_ETH_FILTER_NOP)
7477 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
7482 switch (filter_op) {
7483 case RTE_ETH_FILTER_ADD:
7484 ret = i40e_ethertype_filter_set(pf,
7485 (struct rte_eth_ethertype_filter *)arg,
7488 case RTE_ETH_FILTER_DELETE:
7489 ret = i40e_ethertype_filter_set(pf,
7490 (struct rte_eth_ethertype_filter *)arg,
7494 PMD_DRV_LOG(ERR, "unsupported operation %u\n", filter_op);
7502 i40e_dev_filter_ctrl(struct rte_eth_dev *dev,
7503 enum rte_filter_type filter_type,
7504 enum rte_filter_op filter_op,
7512 switch (filter_type) {
7513 case RTE_ETH_FILTER_NONE:
7514 /* For global configuration */
7515 ret = i40e_filter_ctrl_global_config(dev, filter_op, arg);
7517 case RTE_ETH_FILTER_HASH:
7518 ret = i40e_hash_filter_ctrl(dev, filter_op, arg);
7520 case RTE_ETH_FILTER_MACVLAN:
7521 ret = i40e_mac_filter_handle(dev, filter_op, arg);
7523 case RTE_ETH_FILTER_ETHERTYPE:
7524 ret = i40e_ethertype_filter_handle(dev, filter_op, arg);
7526 case RTE_ETH_FILTER_TUNNEL:
7527 ret = i40e_tunnel_filter_handle(dev, filter_op, arg);
7529 case RTE_ETH_FILTER_FDIR:
7530 ret = i40e_fdir_ctrl_func(dev, filter_op, arg);
7533 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
7543 * Check and enable Extended Tag.
7544 * Enabling Extended Tag is important for 40G performance.
7547 i40e_enable_extended_tag(struct rte_eth_dev *dev)
7552 ret = rte_eal_pci_read_config(dev->pci_dev, &buf, sizeof(buf),
7555 PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
7559 if (!(buf & PCI_DEV_CAP_EXT_TAG_MASK)) {
7560 PMD_DRV_LOG(ERR, "Does not support Extended Tag");
7565 ret = rte_eal_pci_read_config(dev->pci_dev, &buf, sizeof(buf),
7568 PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
7572 if (buf & PCI_DEV_CTRL_EXT_TAG_MASK) {
7573 PMD_DRV_LOG(DEBUG, "Extended Tag has already been enabled");
7576 buf |= PCI_DEV_CTRL_EXT_TAG_MASK;
7577 ret = rte_eal_pci_write_config(dev->pci_dev, &buf, sizeof(buf),
7580 PMD_DRV_LOG(ERR, "Failed to write PCI offset 0x%x",
7587 * As some registers wouldn't be reset unless a global hardware reset,
7588 * hardware initialization is needed to put those registers into an
7589 * expected initial state.
7592 i40e_hw_init(struct rte_eth_dev *dev)
7594 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7596 i40e_enable_extended_tag(dev);
7598 /* clear the PF Queue Filter control register */
7599 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, 0);
7601 /* Disable symmetric hash per port */
7602 i40e_set_symmetric_hash_enable_per_port(hw, 0);
7605 enum i40e_filter_pctype
7606 i40e_flowtype_to_pctype(uint16_t flow_type)
7608 static const enum i40e_filter_pctype pctype_table[] = {
7609 [RTE_ETH_FLOW_FRAG_IPV4] = I40E_FILTER_PCTYPE_FRAG_IPV4,
7610 [RTE_ETH_FLOW_NONFRAG_IPV4_UDP] =
7611 I40E_FILTER_PCTYPE_NONF_IPV4_UDP,
7612 [RTE_ETH_FLOW_NONFRAG_IPV4_TCP] =
7613 I40E_FILTER_PCTYPE_NONF_IPV4_TCP,
7614 [RTE_ETH_FLOW_NONFRAG_IPV4_SCTP] =
7615 I40E_FILTER_PCTYPE_NONF_IPV4_SCTP,
7616 [RTE_ETH_FLOW_NONFRAG_IPV4_OTHER] =
7617 I40E_FILTER_PCTYPE_NONF_IPV4_OTHER,
7618 [RTE_ETH_FLOW_FRAG_IPV6] = I40E_FILTER_PCTYPE_FRAG_IPV6,
7619 [RTE_ETH_FLOW_NONFRAG_IPV6_UDP] =
7620 I40E_FILTER_PCTYPE_NONF_IPV6_UDP,
7621 [RTE_ETH_FLOW_NONFRAG_IPV6_TCP] =
7622 I40E_FILTER_PCTYPE_NONF_IPV6_TCP,
7623 [RTE_ETH_FLOW_NONFRAG_IPV6_SCTP] =
7624 I40E_FILTER_PCTYPE_NONF_IPV6_SCTP,
7625 [RTE_ETH_FLOW_NONFRAG_IPV6_OTHER] =
7626 I40E_FILTER_PCTYPE_NONF_IPV6_OTHER,
7627 [RTE_ETH_FLOW_L2_PAYLOAD] = I40E_FILTER_PCTYPE_L2_PAYLOAD,
7630 return pctype_table[flow_type];
7634 i40e_pctype_to_flowtype(enum i40e_filter_pctype pctype)
7636 static const uint16_t flowtype_table[] = {
7637 [I40E_FILTER_PCTYPE_FRAG_IPV4] = RTE_ETH_FLOW_FRAG_IPV4,
7638 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
7639 RTE_ETH_FLOW_NONFRAG_IPV4_UDP,
7640 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
7641 RTE_ETH_FLOW_NONFRAG_IPV4_TCP,
7642 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
7643 RTE_ETH_FLOW_NONFRAG_IPV4_SCTP,
7644 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
7645 RTE_ETH_FLOW_NONFRAG_IPV4_OTHER,
7646 [I40E_FILTER_PCTYPE_FRAG_IPV6] = RTE_ETH_FLOW_FRAG_IPV6,
7647 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
7648 RTE_ETH_FLOW_NONFRAG_IPV6_UDP,
7649 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
7650 RTE_ETH_FLOW_NONFRAG_IPV6_TCP,
7651 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
7652 RTE_ETH_FLOW_NONFRAG_IPV6_SCTP,
7653 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
7654 RTE_ETH_FLOW_NONFRAG_IPV6_OTHER,
7655 [I40E_FILTER_PCTYPE_L2_PAYLOAD] = RTE_ETH_FLOW_L2_PAYLOAD,
7658 return flowtype_table[pctype];
7662 * On X710, performance number is far from the expectation on recent firmware
7663 * versions; on XL710, performance number is also far from the expectation on
7664 * recent firmware versions, if promiscuous mode is disabled, or promiscuous
7665 * mode is enabled and port MAC address is equal to the packet destination MAC
7666 * address. The fix for this issue may not be integrated in the following
7667 * firmware version. So the workaround in software driver is needed. It needs
7668 * to modify the initial values of 3 internal only registers for both X710 and
7669 * XL710. Note that the values for X710 or XL710 could be different, and the
7670 * workaround can be removed when it is fixed in firmware in the future.
7673 /* For both X710 and XL710 */
7674 #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE 0x10000200
7675 #define I40E_GL_SWR_PRI_JOIN_MAP_0 0x26CE00
7677 #define I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x011f0200
7678 #define I40E_GL_SWR_PRI_JOIN_MAP_2 0x26CE08
7681 #define I40E_GL_SWR_PM_UP_THR_EF_VALUE 0x03030303
7683 #define I40E_GL_SWR_PM_UP_THR_SF_VALUE 0x06060606
7684 #define I40E_GL_SWR_PM_UP_THR 0x269FBC
7687 i40e_configure_registers(struct i40e_hw *hw)
7693 {I40E_GL_SWR_PRI_JOIN_MAP_0, I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE},
7694 {I40E_GL_SWR_PRI_JOIN_MAP_2, I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE},
7695 {I40E_GL_SWR_PM_UP_THR, 0}, /* Compute value dynamically */
7701 for (i = 0; i < RTE_DIM(reg_table); i++) {
7702 if (reg_table[i].addr == I40E_GL_SWR_PM_UP_THR) {
7703 if (i40e_is_40G_device(hw->device_id)) /* For XL710 */
7705 I40E_GL_SWR_PM_UP_THR_SF_VALUE;
7708 I40E_GL_SWR_PM_UP_THR_EF_VALUE;
7711 ret = i40e_aq_debug_read_register(hw, reg_table[i].addr,
7714 PMD_DRV_LOG(ERR, "Failed to read from 0x%"PRIx32,
7718 PMD_DRV_LOG(DEBUG, "Read from 0x%"PRIx32": 0x%"PRIx64,
7719 reg_table[i].addr, reg);
7720 if (reg == reg_table[i].val)
7723 ret = i40e_aq_debug_write_register(hw, reg_table[i].addr,
7724 reg_table[i].val, NULL);
7726 PMD_DRV_LOG(ERR, "Failed to write 0x%"PRIx64" to the "
7727 "address of 0x%"PRIx32, reg_table[i].val,
7731 PMD_DRV_LOG(DEBUG, "Write 0x%"PRIx64" to the address of "
7732 "0x%"PRIx32, reg_table[i].val, reg_table[i].addr);
7736 #define I40E_VSI_TSR(_i) (0x00050800 + ((_i) * 4))
7737 #define I40E_VSI_TSR_QINQ_CONFIG 0xc030
7738 #define I40E_VSI_L2TAGSTXVALID(_i) (0x00042800 + ((_i) * 4))
7739 #define I40E_VSI_L2TAGSTXVALID_QINQ 0xab
7741 i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi)
7746 if (vsi->vsi_id >= I40E_MAX_NUM_VSIS) {
7747 PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
7751 /* Configure for double VLAN RX stripping */
7752 reg = I40E_READ_REG(hw, I40E_VSI_TSR(vsi->vsi_id));
7753 if ((reg & I40E_VSI_TSR_QINQ_CONFIG) != I40E_VSI_TSR_QINQ_CONFIG) {
7754 reg |= I40E_VSI_TSR_QINQ_CONFIG;
7755 ret = i40e_aq_debug_write_register(hw,
7756 I40E_VSI_TSR(vsi->vsi_id),
7759 PMD_DRV_LOG(ERR, "Failed to update VSI_TSR[%d]",
7761 return I40E_ERR_CONFIG;
7765 /* Configure for double VLAN TX insertion */
7766 reg = I40E_READ_REG(hw, I40E_VSI_L2TAGSTXVALID(vsi->vsi_id));
7767 if ((reg & 0xff) != I40E_VSI_L2TAGSTXVALID_QINQ) {
7768 reg = I40E_VSI_L2TAGSTXVALID_QINQ;
7769 ret = i40e_aq_debug_write_register(hw,
7770 I40E_VSI_L2TAGSTXVALID(
7771 vsi->vsi_id), reg, NULL);
7773 PMD_DRV_LOG(ERR, "Failed to update "
7774 "VSI_L2TAGSTXVALID[%d]", vsi->vsi_id);
7775 return I40E_ERR_CONFIG;
7783 * i40e_aq_add_mirror_rule
7784 * @hw: pointer to the hardware structure
7785 * @seid: VEB seid to add mirror rule to
7786 * @dst_id: destination vsi seid
7787 * @entries: Buffer which contains the entities to be mirrored
7788 * @count: number of entities contained in the buffer
7789 * @rule_id:the rule_id of the rule to be added
7791 * Add a mirror rule for a given veb.
7794 static enum i40e_status_code
7795 i40e_aq_add_mirror_rule(struct i40e_hw *hw,
7796 uint16_t seid, uint16_t dst_id,
7797 uint16_t rule_type, uint16_t *entries,
7798 uint16_t count, uint16_t *rule_id)
7800 struct i40e_aq_desc desc;
7801 struct i40e_aqc_add_delete_mirror_rule cmd;
7802 struct i40e_aqc_add_delete_mirror_rule_completion *resp =
7803 (struct i40e_aqc_add_delete_mirror_rule_completion *)
7806 enum i40e_status_code status;
7808 i40e_fill_default_direct_cmd_desc(&desc,
7809 i40e_aqc_opc_add_mirror_rule);
7810 memset(&cmd, 0, sizeof(cmd));
7812 buff_len = sizeof(uint16_t) * count;
7813 desc.datalen = rte_cpu_to_le_16(buff_len);
7815 desc.flags |= rte_cpu_to_le_16(
7816 (uint16_t)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
7817 cmd.rule_type = rte_cpu_to_le_16(rule_type <<
7818 I40E_AQC_MIRROR_RULE_TYPE_SHIFT);
7819 cmd.num_entries = rte_cpu_to_le_16(count);
7820 cmd.seid = rte_cpu_to_le_16(seid);
7821 cmd.destination = rte_cpu_to_le_16(dst_id);
7823 rte_memcpy(&desc.params.raw, &cmd, sizeof(cmd));
7824 status = i40e_asq_send_command(hw, &desc, entries, buff_len, NULL);
7825 PMD_DRV_LOG(INFO, "i40e_aq_add_mirror_rule, aq_status %d,"
7827 " mirror_rules_used = %u, mirror_rules_free = %u,",
7828 hw->aq.asq_last_status, resp->rule_id,
7829 resp->mirror_rules_used, resp->mirror_rules_free);
7830 *rule_id = rte_le_to_cpu_16(resp->rule_id);
7836 * i40e_aq_del_mirror_rule
7837 * @hw: pointer to the hardware structure
7838 * @seid: VEB seid to add mirror rule to
7839 * @entries: Buffer which contains the entities to be mirrored
7840 * @count: number of entities contained in the buffer
7841 * @rule_id:the rule_id of the rule to be delete
7843 * Delete a mirror rule for a given veb.
7846 static enum i40e_status_code
7847 i40e_aq_del_mirror_rule(struct i40e_hw *hw,
7848 uint16_t seid, uint16_t rule_type, uint16_t *entries,
7849 uint16_t count, uint16_t rule_id)
7851 struct i40e_aq_desc desc;
7852 struct i40e_aqc_add_delete_mirror_rule cmd;
7853 uint16_t buff_len = 0;
7854 enum i40e_status_code status;
7857 i40e_fill_default_direct_cmd_desc(&desc,
7858 i40e_aqc_opc_delete_mirror_rule);
7859 memset(&cmd, 0, sizeof(cmd));
7860 if (rule_type == I40E_AQC_MIRROR_RULE_TYPE_VLAN) {
7861 desc.flags |= rte_cpu_to_le_16((uint16_t)(I40E_AQ_FLAG_BUF |
7863 cmd.num_entries = count;
7864 buff_len = sizeof(uint16_t) * count;
7865 desc.datalen = rte_cpu_to_le_16(buff_len);
7866 buff = (void *)entries;
7868 /* rule id is filled in destination field for deleting mirror rule */
7869 cmd.destination = rte_cpu_to_le_16(rule_id);
7871 cmd.rule_type = rte_cpu_to_le_16(rule_type <<
7872 I40E_AQC_MIRROR_RULE_TYPE_SHIFT);
7873 cmd.seid = rte_cpu_to_le_16(seid);
7875 rte_memcpy(&desc.params.raw, &cmd, sizeof(cmd));
7876 status = i40e_asq_send_command(hw, &desc, buff, buff_len, NULL);
7882 * i40e_mirror_rule_set
7883 * @dev: pointer to the hardware structure
7884 * @mirror_conf: mirror rule info
7885 * @sw_id: mirror rule's sw_id
7886 * @on: enable/disable
7888 * set a mirror rule.
7892 i40e_mirror_rule_set(struct rte_eth_dev *dev,
7893 struct rte_eth_mirror_conf *mirror_conf,
7894 uint8_t sw_id, uint8_t on)
7896 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7897 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7898 struct i40e_mirror_rule *it, *mirr_rule = NULL;
7899 struct i40e_mirror_rule *parent = NULL;
7900 uint16_t seid, dst_seid, rule_id;
7904 PMD_DRV_LOG(DEBUG, "i40e_mirror_rule_set: sw_id = %d.", sw_id);
7906 if (pf->main_vsi->veb == NULL || pf->vfs == NULL) {
7907 PMD_DRV_LOG(ERR, "mirror rule can not be configured"
7908 " without veb or vfs.");
7911 if (pf->nb_mirror_rule > I40E_MAX_MIRROR_RULES) {
7912 PMD_DRV_LOG(ERR, "mirror table is full.");
7915 if (mirror_conf->dst_pool > pf->vf_num) {
7916 PMD_DRV_LOG(ERR, "invalid destination pool %u.",
7917 mirror_conf->dst_pool);
7921 seid = pf->main_vsi->veb->seid;
7923 TAILQ_FOREACH(it, &pf->mirror_list, rules) {
7924 if (sw_id <= it->index) {
7930 if (mirr_rule && sw_id == mirr_rule->index) {
7932 PMD_DRV_LOG(ERR, "mirror rule exists.");
7935 ret = i40e_aq_del_mirror_rule(hw, seid,
7936 mirr_rule->rule_type,
7938 mirr_rule->num_entries, mirr_rule->id);
7940 PMD_DRV_LOG(ERR, "failed to remove mirror rule:"
7941 " ret = %d, aq_err = %d.",
7942 ret, hw->aq.asq_last_status);
7945 TAILQ_REMOVE(&pf->mirror_list, mirr_rule, rules);
7946 rte_free(mirr_rule);
7947 pf->nb_mirror_rule--;
7951 PMD_DRV_LOG(ERR, "mirror rule doesn't exist.");
7955 mirr_rule = rte_zmalloc("i40e_mirror_rule",
7956 sizeof(struct i40e_mirror_rule) , 0);
7958 PMD_DRV_LOG(ERR, "failed to allocate memory");
7959 return I40E_ERR_NO_MEMORY;
7961 switch (mirror_conf->rule_type) {
7962 case ETH_MIRROR_VLAN:
7963 for (i = 0, j = 0; i < ETH_MIRROR_MAX_VLANS; i++) {
7964 if (mirror_conf->vlan.vlan_mask & (1ULL << i)) {
7965 mirr_rule->entries[j] =
7966 mirror_conf->vlan.vlan_id[i];
7971 PMD_DRV_LOG(ERR, "vlan is not specified.");
7972 rte_free(mirr_rule);
7975 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_VLAN;
7977 case ETH_MIRROR_VIRTUAL_POOL_UP:
7978 case ETH_MIRROR_VIRTUAL_POOL_DOWN:
7979 /* check if the specified pool bit is out of range */
7980 if (mirror_conf->pool_mask > (uint64_t)(1ULL << (pf->vf_num + 1))) {
7981 PMD_DRV_LOG(ERR, "pool mask is out of range.");
7982 rte_free(mirr_rule);
7985 for (i = 0, j = 0; i < pf->vf_num; i++) {
7986 if (mirror_conf->pool_mask & (1ULL << i)) {
7987 mirr_rule->entries[j] = pf->vfs[i].vsi->seid;
7991 if (mirror_conf->pool_mask & (1ULL << pf->vf_num)) {
7992 /* add pf vsi to entries */
7993 mirr_rule->entries[j] = pf->main_vsi_seid;
7997 PMD_DRV_LOG(ERR, "pool is not specified.");
7998 rte_free(mirr_rule);
8001 /* egress and ingress in aq commands means from switch but not port */
8002 mirr_rule->rule_type =
8003 (mirror_conf->rule_type == ETH_MIRROR_VIRTUAL_POOL_UP) ?
8004 I40E_AQC_MIRROR_RULE_TYPE_VPORT_EGRESS :
8005 I40E_AQC_MIRROR_RULE_TYPE_VPORT_INGRESS;
8007 case ETH_MIRROR_UPLINK_PORT:
8008 /* egress and ingress in aq commands means from switch but not port*/
8009 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_ALL_EGRESS;
8011 case ETH_MIRROR_DOWNLINK_PORT:
8012 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_ALL_INGRESS;
8015 PMD_DRV_LOG(ERR, "unsupported mirror type %d.",
8016 mirror_conf->rule_type);
8017 rte_free(mirr_rule);
8021 /* If the dst_pool is equal to vf_num, consider it as PF */
8022 if (mirror_conf->dst_pool == pf->vf_num)
8023 dst_seid = pf->main_vsi_seid;
8025 dst_seid = pf->vfs[mirror_conf->dst_pool].vsi->seid;
8027 ret = i40e_aq_add_mirror_rule(hw, seid, dst_seid,
8028 mirr_rule->rule_type, mirr_rule->entries,
8031 PMD_DRV_LOG(ERR, "failed to add mirror rule:"
8032 " ret = %d, aq_err = %d.",
8033 ret, hw->aq.asq_last_status);
8034 rte_free(mirr_rule);
8038 mirr_rule->index = sw_id;
8039 mirr_rule->num_entries = j;
8040 mirr_rule->id = rule_id;
8041 mirr_rule->dst_vsi_seid = dst_seid;
8044 TAILQ_INSERT_AFTER(&pf->mirror_list, parent, mirr_rule, rules);
8046 TAILQ_INSERT_HEAD(&pf->mirror_list, mirr_rule, rules);
8048 pf->nb_mirror_rule++;
8053 * i40e_mirror_rule_reset
8054 * @dev: pointer to the device
8055 * @sw_id: mirror rule's sw_id
8057 * reset a mirror rule.
8061 i40e_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t sw_id)
8063 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8064 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8065 struct i40e_mirror_rule *it, *mirr_rule = NULL;
8069 PMD_DRV_LOG(DEBUG, "i40e_mirror_rule_reset: sw_id = %d.", sw_id);
8071 seid = pf->main_vsi->veb->seid;
8073 TAILQ_FOREACH(it, &pf->mirror_list, rules) {
8074 if (sw_id == it->index) {
8080 ret = i40e_aq_del_mirror_rule(hw, seid,
8081 mirr_rule->rule_type,
8083 mirr_rule->num_entries, mirr_rule->id);
8085 PMD_DRV_LOG(ERR, "failed to remove mirror rule:"
8086 " status = %d, aq_err = %d.",
8087 ret, hw->aq.asq_last_status);
8090 TAILQ_REMOVE(&pf->mirror_list, mirr_rule, rules);
8091 rte_free(mirr_rule);
8092 pf->nb_mirror_rule--;
8094 PMD_DRV_LOG(ERR, "mirror rule doesn't exist.");
8101 i40e_read_systime_cyclecounter(struct rte_eth_dev *dev)
8103 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8104 uint64_t systim_cycles;
8106 systim_cycles = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_L);
8107 systim_cycles |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_H)
8110 return systim_cycles;
8114 i40e_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev, uint8_t index)
8116 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8119 rx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_L(index));
8120 rx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(index))
8127 i40e_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
8129 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8132 tx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_L);
8133 tx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H)
8140 i40e_start_timecounters(struct rte_eth_dev *dev)
8142 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8143 struct i40e_adapter *adapter =
8144 (struct i40e_adapter *)dev->data->dev_private;
8145 struct rte_eth_link link;
8146 uint32_t tsync_inc_l;
8147 uint32_t tsync_inc_h;
8149 /* Get current link speed. */
8150 memset(&link, 0, sizeof(link));
8151 i40e_dev_link_update(dev, 1);
8152 rte_i40e_dev_atomic_read_link_status(dev, &link);
8154 switch (link.link_speed) {
8155 case ETH_LINK_SPEED_40G:
8156 tsync_inc_l = I40E_PTP_40GB_INCVAL & 0xFFFFFFFF;
8157 tsync_inc_h = I40E_PTP_40GB_INCVAL >> 32;
8159 case ETH_LINK_SPEED_10G:
8160 tsync_inc_l = I40E_PTP_10GB_INCVAL & 0xFFFFFFFF;
8161 tsync_inc_h = I40E_PTP_10GB_INCVAL >> 32;
8163 case ETH_LINK_SPEED_1000:
8164 tsync_inc_l = I40E_PTP_1GB_INCVAL & 0xFFFFFFFF;
8165 tsync_inc_h = I40E_PTP_1GB_INCVAL >> 32;
8172 /* Set the timesync increment value. */
8173 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, tsync_inc_l);
8174 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, tsync_inc_h);
8176 memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
8177 memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
8178 memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
8180 adapter->systime_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
8181 adapter->systime_tc.cc_shift = 0;
8182 adapter->systime_tc.nsec_mask = 0;
8184 adapter->rx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
8185 adapter->rx_tstamp_tc.cc_shift = 0;
8186 adapter->rx_tstamp_tc.nsec_mask = 0;
8188 adapter->tx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
8189 adapter->tx_tstamp_tc.cc_shift = 0;
8190 adapter->tx_tstamp_tc.nsec_mask = 0;
8194 i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
8196 struct i40e_adapter *adapter =
8197 (struct i40e_adapter *)dev->data->dev_private;
8199 adapter->systime_tc.nsec += delta;
8200 adapter->rx_tstamp_tc.nsec += delta;
8201 adapter->tx_tstamp_tc.nsec += delta;
8207 i40e_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
8210 struct i40e_adapter *adapter =
8211 (struct i40e_adapter *)dev->data->dev_private;
8213 ns = rte_timespec_to_ns(ts);
8215 /* Set the timecounters to a new value. */
8216 adapter->systime_tc.nsec = ns;
8217 adapter->rx_tstamp_tc.nsec = ns;
8218 adapter->tx_tstamp_tc.nsec = ns;
8224 i40e_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
8226 uint64_t ns, systime_cycles;
8227 struct i40e_adapter *adapter =
8228 (struct i40e_adapter *)dev->data->dev_private;
8230 systime_cycles = i40e_read_systime_cyclecounter(dev);
8231 ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
8232 *ts = rte_ns_to_timespec(ns);
8238 i40e_timesync_enable(struct rte_eth_dev *dev)
8240 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8241 uint32_t tsync_ctl_l;
8242 uint32_t tsync_ctl_h;
8244 /* Stop the timesync system time. */
8245 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
8246 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
8247 /* Reset the timesync system time value. */
8248 I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_L, 0x0);
8249 I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_H, 0x0);
8251 i40e_start_timecounters(dev);
8253 /* Clear timesync registers. */
8254 I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
8255 I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H);
8256 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(0));
8257 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(1));
8258 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(2));
8259 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(3));
8261 /* Enable timestamping of PTP packets. */
8262 tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
8263 tsync_ctl_l |= I40E_PRTTSYN_TSYNENA;
8265 tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
8266 tsync_ctl_h |= I40E_PRTTSYN_TSYNENA;
8267 tsync_ctl_h |= I40E_PRTTSYN_TSYNTYPE;
8269 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
8270 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
8276 i40e_timesync_disable(struct rte_eth_dev *dev)
8278 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8279 uint32_t tsync_ctl_l;
8280 uint32_t tsync_ctl_h;
8282 /* Disable timestamping of transmitted PTP packets. */
8283 tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
8284 tsync_ctl_l &= ~I40E_PRTTSYN_TSYNENA;
8286 tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
8287 tsync_ctl_h &= ~I40E_PRTTSYN_TSYNENA;
8289 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
8290 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
8292 /* Reset the timesync increment value. */
8293 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
8294 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
8300 i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
8301 struct timespec *timestamp, uint32_t flags)
8303 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8304 struct i40e_adapter *adapter =
8305 (struct i40e_adapter *)dev->data->dev_private;
8307 uint32_t sync_status;
8308 uint32_t index = flags & 0x03;
8309 uint64_t rx_tstamp_cycles;
8312 sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_1);
8313 if ((sync_status & (1 << index)) == 0)
8316 rx_tstamp_cycles = i40e_read_rx_tstamp_cyclecounter(dev, index);
8317 ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
8318 *timestamp = rte_ns_to_timespec(ns);
8324 i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
8325 struct timespec *timestamp)
8327 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8328 struct i40e_adapter *adapter =
8329 (struct i40e_adapter *)dev->data->dev_private;
8331 uint32_t sync_status;
8332 uint64_t tx_tstamp_cycles;
8335 sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
8336 if ((sync_status & I40E_PRTTSYN_STAT_0_TXTIME_MASK) == 0)
8339 tx_tstamp_cycles = i40e_read_tx_tstamp_cyclecounter(dev);
8340 ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
8341 *timestamp = rte_ns_to_timespec(ns);
8347 * i40e_parse_dcb_configure - parse dcb configure from user
8348 * @dev: the device being configured
8349 * @dcb_cfg: pointer of the result of parse
8350 * @*tc_map: bit map of enabled traffic classes
8352 * Returns 0 on success, negative value on failure
8355 i40e_parse_dcb_configure(struct rte_eth_dev *dev,
8356 struct i40e_dcbx_config *dcb_cfg,
8359 struct rte_eth_dcb_rx_conf *dcb_rx_conf;
8360 uint8_t i, tc_bw, bw_lf;
8362 memset(dcb_cfg, 0, sizeof(struct i40e_dcbx_config));
8364 dcb_rx_conf = &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
8365 if (dcb_rx_conf->nb_tcs > I40E_MAX_TRAFFIC_CLASS) {
8366 PMD_INIT_LOG(ERR, "number of tc exceeds max.");
8370 /* assume each tc has the same bw */
8371 tc_bw = I40E_MAX_PERCENT / dcb_rx_conf->nb_tcs;
8372 for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
8373 dcb_cfg->etscfg.tcbwtable[i] = tc_bw;
8374 /* to ensure the sum of tcbw is equal to 100 */
8375 bw_lf = I40E_MAX_PERCENT % dcb_rx_conf->nb_tcs;
8376 for (i = 0; i < bw_lf; i++)
8377 dcb_cfg->etscfg.tcbwtable[i]++;
8379 /* assume each tc has the same Transmission Selection Algorithm */
8380 for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
8381 dcb_cfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
8383 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
8384 dcb_cfg->etscfg.prioritytable[i] =
8385 dcb_rx_conf->dcb_tc[i];
8387 /* FW needs one App to configure HW */
8388 dcb_cfg->numapps = I40E_DEFAULT_DCB_APP_NUM;
8389 dcb_cfg->app[0].selector = I40E_APP_SEL_ETHTYPE;
8390 dcb_cfg->app[0].priority = I40E_DEFAULT_DCB_APP_PRIO;
8391 dcb_cfg->app[0].protocolid = I40E_APP_PROTOID_FCOE;
8393 if (dcb_rx_conf->nb_tcs == 0)
8394 *tc_map = 1; /* tc0 only */
8396 *tc_map = RTE_LEN2MASK(dcb_rx_conf->nb_tcs, uint8_t);
8398 if (dev->data->dev_conf.dcb_capability_en & ETH_DCB_PFC_SUPPORT) {
8399 dcb_cfg->pfc.willing = 0;
8400 dcb_cfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
8401 dcb_cfg->pfc.pfcenable = *tc_map;
8407 static enum i40e_status_code
8408 i40e_vsi_update_queue_mapping(struct i40e_vsi *vsi,
8409 struct i40e_aqc_vsi_properties_data *info,
8410 uint8_t enabled_tcmap)
8412 enum i40e_status_code ret;
8413 int i, total_tc = 0;
8414 uint16_t qpnum_per_tc, bsf, qp_idx;
8415 struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(vsi);
8416 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
8417 uint16_t used_queues;
8419 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
8420 if (ret != I40E_SUCCESS)
8423 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
8424 if (enabled_tcmap & (1 << i))
8429 vsi->enabled_tc = enabled_tcmap;
8431 /* different VSI has different queues assigned */
8432 if (vsi->type == I40E_VSI_MAIN)
8433 used_queues = dev_data->nb_rx_queues -
8434 pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
8435 else if (vsi->type == I40E_VSI_VMDQ2)
8436 used_queues = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
8438 PMD_INIT_LOG(ERR, "unsupported VSI type.");
8439 return I40E_ERR_NO_AVAILABLE_VSI;
8442 qpnum_per_tc = used_queues / total_tc;
8443 /* Number of queues per enabled TC */
8444 if (qpnum_per_tc == 0) {
8445 PMD_INIT_LOG(ERR, " number of queues is less that tcs.");
8446 return I40E_ERR_INVALID_QP_ID;
8448 qpnum_per_tc = RTE_MIN(i40e_align_floor(qpnum_per_tc),
8450 bsf = rte_bsf32(qpnum_per_tc);
8453 * Configure TC and queue mapping parameters, for enabled TC,
8454 * allocate qpnum_per_tc queues to this traffic. For disabled TC,
8455 * default queue will serve it.
8458 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
8459 if (vsi->enabled_tc & (1 << i)) {
8460 info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
8461 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
8462 (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
8463 qp_idx += qpnum_per_tc;
8465 info->tc_mapping[i] = 0;
8468 /* Associate queue number with VSI, Keep vsi->nb_qps unchanged */
8469 if (vsi->type == I40E_VSI_SRIOV) {
8470 info->mapping_flags |=
8471 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
8472 for (i = 0; i < vsi->nb_qps; i++)
8473 info->queue_mapping[i] =
8474 rte_cpu_to_le_16(vsi->base_queue + i);
8476 info->mapping_flags |=
8477 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
8478 info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
8480 info->valid_sections |=
8481 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
8483 return I40E_SUCCESS;
8487 * i40e_config_switch_comp_tc - Configure VEB tc setting for given TC map
8488 * @veb: VEB to be configured
8489 * @tc_map: enabled TC bitmap
8491 * Returns 0 on success, negative value on failure
8493 static enum i40e_status_code
8494 i40e_config_switch_comp_tc(struct i40e_veb *veb, uint8_t tc_map)
8496 struct i40e_aqc_configure_switching_comp_bw_config_data veb_bw;
8497 struct i40e_aqc_query_switching_comp_bw_config_resp bw_query;
8498 struct i40e_aqc_query_switching_comp_ets_config_resp ets_query;
8499 struct i40e_hw *hw = I40E_VSI_TO_HW(veb->associate_vsi);
8500 enum i40e_status_code ret = I40E_SUCCESS;
8504 /* Check if enabled_tc is same as existing or new TCs */
8505 if (veb->enabled_tc == tc_map)
8508 /* configure tc bandwidth */
8509 memset(&veb_bw, 0, sizeof(veb_bw));
8510 veb_bw.tc_valid_bits = tc_map;
8511 /* Enable ETS TCs with equal BW Share for now across all VSIs */
8512 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
8513 if (tc_map & BIT_ULL(i))
8514 veb_bw.tc_bw_share_credits[i] = 1;
8516 ret = i40e_aq_config_switch_comp_bw_config(hw, veb->seid,
8519 PMD_INIT_LOG(ERR, "AQ command Config switch_comp BW allocation"
8520 " per TC failed = %d",
8521 hw->aq.asq_last_status);
8525 memset(&ets_query, 0, sizeof(ets_query));
8526 ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
8528 if (ret != I40E_SUCCESS) {
8529 PMD_DRV_LOG(ERR, "Failed to get switch_comp ETS"
8530 " configuration %u", hw->aq.asq_last_status);
8533 memset(&bw_query, 0, sizeof(bw_query));
8534 ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
8536 if (ret != I40E_SUCCESS) {
8537 PMD_DRV_LOG(ERR, "Failed to get switch_comp bandwidth"
8538 " configuration %u", hw->aq.asq_last_status);
8542 /* store and print out BW info */
8543 veb->bw_info.bw_limit = rte_le_to_cpu_16(ets_query.port_bw_limit);
8544 veb->bw_info.bw_max = ets_query.tc_bw_max;
8545 PMD_DRV_LOG(DEBUG, "switch_comp bw limit:%u", veb->bw_info.bw_limit);
8546 PMD_DRV_LOG(DEBUG, "switch_comp max_bw:%u", veb->bw_info.bw_max);
8547 bw_max = rte_le_to_cpu_16(bw_query.tc_bw_max[0]) |
8548 (rte_le_to_cpu_16(bw_query.tc_bw_max[1]) <<
8550 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
8551 veb->bw_info.bw_ets_share_credits[i] =
8552 bw_query.tc_bw_share_credits[i];
8553 veb->bw_info.bw_ets_credits[i] =
8554 rte_le_to_cpu_16(bw_query.tc_bw_limits[i]);
8555 /* 4 bits per TC, 4th bit is reserved */
8556 veb->bw_info.bw_ets_max[i] =
8557 (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
8558 RTE_LEN2MASK(3, uint8_t));
8559 PMD_DRV_LOG(DEBUG, "\tVEB TC%u:share credits %u", i,
8560 veb->bw_info.bw_ets_share_credits[i]);
8561 PMD_DRV_LOG(DEBUG, "\tVEB TC%u:credits %u", i,
8562 veb->bw_info.bw_ets_credits[i]);
8563 PMD_DRV_LOG(DEBUG, "\tVEB TC%u: max credits: %u", i,
8564 veb->bw_info.bw_ets_max[i]);
8567 veb->enabled_tc = tc_map;
8574 * i40e_vsi_config_tc - Configure VSI tc setting for given TC map
8575 * @vsi: VSI to be configured
8576 * @tc_map: enabled TC bitmap
8578 * Returns 0 on success, negative value on failure
8580 static enum i40e_status_code
8581 i40e_vsi_config_tc(struct i40e_vsi *vsi, uint8_t tc_map)
8583 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
8584 struct i40e_vsi_context ctxt;
8585 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
8586 enum i40e_status_code ret = I40E_SUCCESS;
8589 /* Check if enabled_tc is same as existing or new TCs */
8590 if (vsi->enabled_tc == tc_map)
8593 /* configure tc bandwidth */
8594 memset(&bw_data, 0, sizeof(bw_data));
8595 bw_data.tc_valid_bits = tc_map;
8596 /* Enable ETS TCs with equal BW Share for now across all VSIs */
8597 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
8598 if (tc_map & BIT_ULL(i))
8599 bw_data.tc_bw_credits[i] = 1;
8601 ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &bw_data, NULL);
8603 PMD_INIT_LOG(ERR, "AQ command Config VSI BW allocation"
8604 " per TC failed = %d",
8605 hw->aq.asq_last_status);
8608 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
8609 vsi->info.qs_handle[i] = bw_data.qs_handles[i];
8611 /* Update Queue Pairs Mapping for currently enabled UPs */
8612 ctxt.seid = vsi->seid;
8613 ctxt.pf_num = hw->pf_id;
8615 ctxt.uplink_seid = vsi->uplink_seid;
8616 ctxt.info = vsi->info;
8618 ret = i40e_vsi_update_queue_mapping(vsi, &ctxt.info, tc_map);
8622 /* Update the VSI after updating the VSI queue-mapping information */
8623 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
8625 PMD_INIT_LOG(ERR, "Failed to configure "
8626 "TC queue mapping = %d",
8627 hw->aq.asq_last_status);
8630 /* update the local VSI info with updated queue map */
8631 (void)rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
8632 sizeof(vsi->info.tc_mapping));
8633 (void)rte_memcpy(&vsi->info.queue_mapping,
8634 &ctxt.info.queue_mapping,
8635 sizeof(vsi->info.queue_mapping));
8636 vsi->info.mapping_flags = ctxt.info.mapping_flags;
8637 vsi->info.valid_sections = 0;
8639 /* query and update current VSI BW information */
8640 ret = i40e_vsi_get_bw_config(vsi);
8643 "Failed updating vsi bw info, err %s aq_err %s",
8644 i40e_stat_str(hw, ret),
8645 i40e_aq_str(hw, hw->aq.asq_last_status));
8649 vsi->enabled_tc = tc_map;
8656 * i40e_dcb_hw_configure - program the dcb setting to hw
8657 * @pf: pf the configuration is taken on
8658 * @new_cfg: new configuration
8659 * @tc_map: enabled TC bitmap
8661 * Returns 0 on success, negative value on failure
8663 static enum i40e_status_code
8664 i40e_dcb_hw_configure(struct i40e_pf *pf,
8665 struct i40e_dcbx_config *new_cfg,
8668 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8669 struct i40e_dcbx_config *old_cfg = &hw->local_dcbx_config;
8670 struct i40e_vsi *main_vsi = pf->main_vsi;
8671 struct i40e_vsi_list *vsi_list;
8672 enum i40e_status_code ret;
8676 /* Use the FW API if FW > v4.4*/
8677 if (!(((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver >= 4)) ||
8678 (hw->aq.fw_maj_ver >= 5))) {
8679 PMD_INIT_LOG(ERR, "FW < v4.4, can not use FW LLDP API"
8680 " to configure DCB");
8681 return I40E_ERR_FIRMWARE_API_VERSION;
8684 /* Check if need reconfiguration */
8685 if (!memcmp(new_cfg, old_cfg, sizeof(struct i40e_dcbx_config))) {
8686 PMD_INIT_LOG(ERR, "No Change in DCB Config required.");
8687 return I40E_SUCCESS;
8690 /* Copy the new config to the current config */
8691 *old_cfg = *new_cfg;
8692 old_cfg->etsrec = old_cfg->etscfg;
8693 ret = i40e_set_dcb_config(hw);
8696 "Set DCB Config failed, err %s aq_err %s\n",
8697 i40e_stat_str(hw, ret),
8698 i40e_aq_str(hw, hw->aq.asq_last_status));
8701 /* set receive Arbiter to RR mode and ETS scheme by default */
8702 for (i = 0; i <= I40E_PRTDCB_RETSTCC_MAX_INDEX; i++) {
8703 val = I40E_READ_REG(hw, I40E_PRTDCB_RETSTCC(i));
8704 val &= ~(I40E_PRTDCB_RETSTCC_BWSHARE_MASK |
8705 I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK |
8706 I40E_PRTDCB_RETSTCC_ETSTC_SHIFT);
8707 val |= ((uint32_t)old_cfg->etscfg.tcbwtable[i] <<
8708 I40E_PRTDCB_RETSTCC_BWSHARE_SHIFT) &
8709 I40E_PRTDCB_RETSTCC_BWSHARE_MASK;
8710 val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_UPINTC_MODE_SHIFT) &
8711 I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK;
8712 val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_ETSTC_SHIFT) &
8713 I40E_PRTDCB_RETSTCC_ETSTC_MASK;
8714 I40E_WRITE_REG(hw, I40E_PRTDCB_RETSTCC(i), val);
8716 /* get local mib to check whether it is configured correctly */
8718 hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_IEEE;
8719 /* Get Local DCB Config */
8720 i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
8721 &hw->local_dcbx_config);
8723 /* if Veb is created, need to update TC of it at first */
8724 if (main_vsi->veb) {
8725 ret = i40e_config_switch_comp_tc(main_vsi->veb, tc_map);
8727 PMD_INIT_LOG(WARNING,
8728 "Failed configuring TC for VEB seid=%d\n",
8729 main_vsi->veb->seid);
8731 /* Update each VSI */
8732 i40e_vsi_config_tc(main_vsi, tc_map);
8733 if (main_vsi->veb) {
8734 TAILQ_FOREACH(vsi_list, &main_vsi->veb->head, list) {
8735 /* Beside main VSI and VMDQ VSIs, only enable default
8738 if (vsi_list->vsi->type == I40E_VSI_VMDQ2)
8739 ret = i40e_vsi_config_tc(vsi_list->vsi,
8742 ret = i40e_vsi_config_tc(vsi_list->vsi,
8743 I40E_DEFAULT_TCMAP);
8745 PMD_INIT_LOG(WARNING,
8746 "Failed configuring TC for VSI seid=%d\n",
8747 vsi_list->vsi->seid);
8751 return I40E_SUCCESS;
8755 * i40e_dcb_init_configure - initial dcb config
8756 * @dev: device being configured
8757 * @sw_dcb: indicate whether dcb is sw configured or hw offload
8759 * Returns 0 on success, negative value on failure
8762 i40e_dcb_init_configure(struct rte_eth_dev *dev, bool sw_dcb)
8764 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8765 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8768 if ((pf->flags & I40E_FLAG_DCB) == 0) {
8769 PMD_INIT_LOG(ERR, "HW doesn't support DCB");
8773 /* DCB initialization:
8774 * Update DCB configuration from the Firmware and configure
8775 * LLDP MIB change event.
8777 if (sw_dcb == TRUE) {
8778 ret = i40e_aq_stop_lldp(hw, TRUE, NULL);
8779 if (ret != I40E_SUCCESS)
8780 PMD_INIT_LOG(DEBUG, "Failed to stop lldp");
8782 ret = i40e_init_dcb(hw);
8783 /* if sw_dcb, lldp agent is stopped, the return from
8784 * i40e_init_dcb we expect is failure with I40E_AQ_RC_EPERM
8787 if (ret != I40E_SUCCESS &&
8788 hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
8789 memset(&hw->local_dcbx_config, 0,
8790 sizeof(struct i40e_dcbx_config));
8791 /* set dcb default configuration */
8792 hw->local_dcbx_config.etscfg.willing = 0;
8793 hw->local_dcbx_config.etscfg.maxtcs = 0;
8794 hw->local_dcbx_config.etscfg.tcbwtable[0] = 100;
8795 hw->local_dcbx_config.etscfg.tsatable[0] =
8797 hw->local_dcbx_config.etsrec =
8798 hw->local_dcbx_config.etscfg;
8799 hw->local_dcbx_config.pfc.willing = 0;
8800 hw->local_dcbx_config.pfc.pfccap =
8801 I40E_MAX_TRAFFIC_CLASS;
8802 /* FW needs one App to configure HW */
8803 hw->local_dcbx_config.numapps = 1;
8804 hw->local_dcbx_config.app[0].selector =
8805 I40E_APP_SEL_ETHTYPE;
8806 hw->local_dcbx_config.app[0].priority = 3;
8807 hw->local_dcbx_config.app[0].protocolid =
8808 I40E_APP_PROTOID_FCOE;
8809 ret = i40e_set_dcb_config(hw);
8811 PMD_INIT_LOG(ERR, "default dcb config fails."
8812 " err = %d, aq_err = %d.", ret,
8813 hw->aq.asq_last_status);
8817 PMD_INIT_LOG(ERR, "DCBX configuration failed, err = %d,"
8818 " aq_err = %d.", ret,
8819 hw->aq.asq_last_status);
8823 ret = i40e_aq_start_lldp(hw, NULL);
8824 if (ret != I40E_SUCCESS)
8825 PMD_INIT_LOG(DEBUG, "Failed to start lldp");
8827 ret = i40e_init_dcb(hw);
8829 if (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED) {
8830 PMD_INIT_LOG(ERR, "HW doesn't support"
8835 PMD_INIT_LOG(ERR, "DCBX configuration failed, err = %d,"
8836 " aq_err = %d.", ret,
8837 hw->aq.asq_last_status);
8845 * i40e_dcb_setup - setup dcb related config
8846 * @dev: device being configured
8848 * Returns 0 on success, negative value on failure
8851 i40e_dcb_setup(struct rte_eth_dev *dev)
8853 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8854 struct i40e_dcbx_config dcb_cfg;
8858 if ((pf->flags & I40E_FLAG_DCB) == 0) {
8859 PMD_INIT_LOG(ERR, "HW doesn't support DCB");
8863 if (pf->vf_num != 0)
8864 PMD_INIT_LOG(DEBUG, " DCB only works on pf and vmdq vsis.");
8866 ret = i40e_parse_dcb_configure(dev, &dcb_cfg, &tc_map);
8868 PMD_INIT_LOG(ERR, "invalid dcb config");
8871 ret = i40e_dcb_hw_configure(pf, &dcb_cfg, tc_map);
8873 PMD_INIT_LOG(ERR, "dcb sw configure fails");
8881 i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
8882 struct rte_eth_dcb_info *dcb_info)
8884 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8885 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8886 struct i40e_vsi *vsi = pf->main_vsi;
8887 struct i40e_dcbx_config *dcb_cfg = &hw->local_dcbx_config;
8888 uint16_t bsf, tc_mapping;
8891 if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_DCB_FLAG)
8892 dcb_info->nb_tcs = rte_bsf32(vsi->enabled_tc + 1);
8894 dcb_info->nb_tcs = 1;
8895 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
8896 dcb_info->prio_tc[i] = dcb_cfg->etscfg.prioritytable[i];
8897 for (i = 0; i < dcb_info->nb_tcs; i++)
8898 dcb_info->tc_bws[i] = dcb_cfg->etscfg.tcbwtable[i];
8902 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
8903 if (!(vsi->enabled_tc & (1 << i)))
8905 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
8906 /* only main vsi support multi TCs */
8907 dcb_info->tc_queue.tc_rxq[j][i].base =
8908 (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
8909 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
8910 dcb_info->tc_queue.tc_txq[j][i].base =
8911 dcb_info->tc_queue.tc_rxq[j][i].base;
8912 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
8913 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
8914 dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
8915 dcb_info->tc_queue.tc_txq[j][i].nb_queue =
8916 dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
8918 vsi = pf->vmdq[j].vsi;
8920 } while (j < RTE_MIN(pf->nb_cfg_vmdq_vsi, ETH_MAX_VMDQ_POOL));
8925 i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
8927 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
8928 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8930 i40e_calc_itr_interval(RTE_LIBRTE_I40E_ITR_INTERVAL);
8933 msix_intr = intr_handle->intr_vec[queue_id];
8934 if (msix_intr == I40E_MISC_VEC_ID)
8935 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
8936 I40E_PFINT_DYN_CTLN_INTENA_MASK |
8937 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
8938 (0 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT) |
8940 I40E_PFINT_DYN_CTLN_INTERVAL_SHIFT));
8943 I40E_PFINT_DYN_CTLN(msix_intr -
8945 I40E_PFINT_DYN_CTLN_INTENA_MASK |
8946 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
8947 (0 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT) |
8949 I40E_PFINT_DYN_CTLN_INTERVAL_SHIFT));
8951 I40E_WRITE_FLUSH(hw);
8952 rte_intr_enable(&dev->pci_dev->intr_handle);
8958 i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
8960 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
8961 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8964 msix_intr = intr_handle->intr_vec[queue_id];
8965 if (msix_intr == I40E_MISC_VEC_ID)
8966 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0, 0);
8969 I40E_PFINT_DYN_CTLN(msix_intr -
8972 I40E_WRITE_FLUSH(hw);
8977 static int i40e_get_reg_length(__rte_unused struct rte_eth_dev *dev)
8979 /* Highest base addr + 32-bit word */
8980 return I40E_GLGEN_STAT_CLEAR + 4;
8983 static int i40e_get_regs(struct rte_eth_dev *dev,
8984 struct rte_dev_reg_info *regs)
8986 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8987 uint32_t *ptr_data = regs->data;
8988 uint32_t reg_idx, arr_idx, arr_idx2, reg_offset;
8989 const struct i40e_reg_info *reg_info;
8991 /* The first few registers have to be read using AQ operations */
8993 while (i40e_regs_adminq[reg_idx].name) {
8994 reg_info = &i40e_regs_adminq[reg_idx++];
8995 for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
8997 arr_idx2 <= reg_info->count2;
8999 reg_offset = arr_idx * reg_info->stride1 +
9000 arr_idx2 * reg_info->stride2;
9001 ptr_data[reg_offset >> 2] =
9002 i40e_read_rx_ctl(hw, reg_offset);
9006 /* The remaining registers can be read using primitives */
9008 while (i40e_regs_others[reg_idx].name) {
9009 reg_info = &i40e_regs_others[reg_idx++];
9010 for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
9012 arr_idx2 <= reg_info->count2;
9014 reg_offset = arr_idx * reg_info->stride1 +
9015 arr_idx2 * reg_info->stride2;
9016 ptr_data[reg_offset >> 2] =
9017 I40E_READ_REG(hw, reg_offset);
9024 static int i40e_get_eeprom_length(struct rte_eth_dev *dev)
9026 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
9028 /* Convert word count to byte count */
9029 return hw->nvm.sr_size << 1;
9032 static int i40e_get_eeprom(struct rte_eth_dev *dev,
9033 struct rte_dev_eeprom_info *eeprom)
9035 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
9036 uint16_t *data = eeprom->data;
9037 uint16_t offset, length, cnt_words;
9040 offset = eeprom->offset >> 1;
9041 length = eeprom->length >> 1;
9044 if (offset > hw->nvm.sr_size ||
9045 offset + length > hw->nvm.sr_size) {
9046 PMD_DRV_LOG(ERR, "Requested EEPROM bytes out of range.");
9050 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
9052 ret_code = i40e_read_nvm_buffer(hw, offset, &cnt_words, data);
9053 if (ret_code != I40E_SUCCESS || cnt_words != length) {
9054 PMD_DRV_LOG(ERR, "EEPROM read failed.");
9061 static void i40e_set_default_mac_addr(struct rte_eth_dev *dev,
9062 struct ether_addr *mac_addr)
9064 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
9066 if (!is_valid_assigned_ether_addr(mac_addr)) {
9067 PMD_DRV_LOG(ERR, "Tried to set invalid MAC address.");
9071 /* Flags: 0x3 updates port address */
9072 i40e_aq_mac_address_write(hw, 0x3, mac_addr->addr_bytes, NULL);