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"
65 /* Maximun number of MAC addresses */
66 #define I40E_NUM_MACADDR_MAX 64
67 #define I40E_CLEAR_PXE_WAIT_MS 200
69 /* Maximun number of capability elements */
70 #define I40E_MAX_CAP_ELE_NUM 128
72 /* Wait count and inteval */
73 #define I40E_CHK_Q_ENA_COUNT 1000
74 #define I40E_CHK_Q_ENA_INTERVAL_US 1000
76 /* Maximun number of VSI */
77 #define I40E_MAX_NUM_VSIS (384UL)
79 #define I40E_PRE_TX_Q_CFG_WAIT_US 10 /* 10 us */
81 /* Flow control default timer */
82 #define I40E_DEFAULT_PAUSE_TIME 0xFFFFU
84 /* Flow control default high water */
85 #define I40E_DEFAULT_HIGH_WATER (0x1C40/1024)
87 /* Flow control default low water */
88 #define I40E_DEFAULT_LOW_WATER (0x1A40/1024)
90 /* Flow control enable fwd bit */
91 #define I40E_PRTMAC_FWD_CTRL 0x00000001
93 /* Receive Packet Buffer size */
94 #define I40E_RXPBSIZE (968 * 1024)
97 #define I40E_KILOSHIFT 10
99 /* Receive Average Packet Size in Byte*/
100 #define I40E_PACKET_AVERAGE_SIZE 128
102 /* Mask of PF interrupt causes */
103 #define I40E_PFINT_ICR0_ENA_MASK ( \
104 I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | \
105 I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | \
106 I40E_PFINT_ICR0_ENA_GRST_MASK | \
107 I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | \
108 I40E_PFINT_ICR0_ENA_STORM_DETECT_MASK | \
109 I40E_PFINT_ICR0_ENA_LINK_STAT_CHANGE_MASK | \
110 I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | \
111 I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK | \
112 I40E_PFINT_ICR0_ENA_VFLR_MASK | \
113 I40E_PFINT_ICR0_ENA_ADMINQ_MASK)
115 #define I40E_FLOW_TYPES ( \
116 (1UL << RTE_ETH_FLOW_FRAG_IPV4) | \
117 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_TCP) | \
118 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_UDP) | \
119 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_SCTP) | \
120 (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_OTHER) | \
121 (1UL << RTE_ETH_FLOW_FRAG_IPV6) | \
122 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_TCP) | \
123 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_UDP) | \
124 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_SCTP) | \
125 (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_OTHER) | \
126 (1UL << RTE_ETH_FLOW_L2_PAYLOAD))
128 /* Additional timesync values. */
129 #define I40E_PTP_40GB_INCVAL 0x0199999999ULL
130 #define I40E_PTP_10GB_INCVAL 0x0333333333ULL
131 #define I40E_PTP_1GB_INCVAL 0x2000000000ULL
132 #define I40E_PRTTSYN_TSYNENA 0x80000000
133 #define I40E_PRTTSYN_TSYNTYPE 0x0e000000
134 #define I40E_CYCLECOUNTER_MASK 0xffffffffffffffff
136 #define I40E_MAX_PERCENT 100
137 #define I40E_DEFAULT_DCB_APP_NUM 1
138 #define I40E_DEFAULT_DCB_APP_PRIO 3
140 #define I40E_PRTQF_FD_INSET(_i, _j) (0x00250000 + ((_i) * 64 + (_j) * 32))
141 #define I40E_GLQF_FD_MSK(_i, _j) (0x00267200 + ((_i) * 4 + (_j) * 8))
142 #define I40E_GLQF_FD_MSK_FIELD 0x0000FFFF
143 #define I40E_GLQF_HASH_INSET(_i, _j) (0x00267600 + ((_i) * 4 + (_j) * 8))
144 #define I40E_GLQF_HASH_MSK(_i, _j) (0x00267A00 + ((_i) * 4 + (_j) * 8))
145 #define I40E_GLQF_HASH_MSK_FIELD 0x0000FFFF
147 #define I40E_INSET_NONE 0x00000000000000000ULL
150 #define I40E_INSET_DMAC 0x0000000000000001ULL
151 #define I40E_INSET_SMAC 0x0000000000000002ULL
152 #define I40E_INSET_VLAN_OUTER 0x0000000000000004ULL
153 #define I40E_INSET_VLAN_INNER 0x0000000000000008ULL
154 #define I40E_INSET_VLAN_TUNNEL 0x0000000000000010ULL
157 #define I40E_INSET_IPV4_SRC 0x0000000000000100ULL
158 #define I40E_INSET_IPV4_DST 0x0000000000000200ULL
159 #define I40E_INSET_IPV6_SRC 0x0000000000000400ULL
160 #define I40E_INSET_IPV6_DST 0x0000000000000800ULL
161 #define I40E_INSET_SRC_PORT 0x0000000000001000ULL
162 #define I40E_INSET_DST_PORT 0x0000000000002000ULL
163 #define I40E_INSET_SCTP_VT 0x0000000000004000ULL
165 /* bit 16 ~ bit 31 */
166 #define I40E_INSET_IPV4_TOS 0x0000000000010000ULL
167 #define I40E_INSET_IPV4_PROTO 0x0000000000020000ULL
168 #define I40E_INSET_IPV4_TTL 0x0000000000040000ULL
169 #define I40E_INSET_IPV6_TC 0x0000000000080000ULL
170 #define I40E_INSET_IPV6_FLOW 0x0000000000100000ULL
171 #define I40E_INSET_IPV6_NEXT_HDR 0x0000000000200000ULL
172 #define I40E_INSET_IPV6_HOP_LIMIT 0x0000000000400000ULL
173 #define I40E_INSET_TCP_FLAGS 0x0000000000800000ULL
175 /* bit 32 ~ bit 47, tunnel fields */
176 #define I40E_INSET_TUNNEL_IPV4_DST 0x0000000100000000ULL
177 #define I40E_INSET_TUNNEL_IPV6_DST 0x0000000200000000ULL
178 #define I40E_INSET_TUNNEL_DMAC 0x0000000400000000ULL
179 #define I40E_INSET_TUNNEL_SRC_PORT 0x0000000800000000ULL
180 #define I40E_INSET_TUNNEL_DST_PORT 0x0000001000000000ULL
181 #define I40E_INSET_TUNNEL_ID 0x0000002000000000ULL
183 /* bit 48 ~ bit 55 */
184 #define I40E_INSET_LAST_ETHER_TYPE 0x0001000000000000ULL
186 /* bit 56 ~ bit 63, Flex Payload */
187 #define I40E_INSET_FLEX_PAYLOAD_W1 0x0100000000000000ULL
188 #define I40E_INSET_FLEX_PAYLOAD_W2 0x0200000000000000ULL
189 #define I40E_INSET_FLEX_PAYLOAD_W3 0x0400000000000000ULL
190 #define I40E_INSET_FLEX_PAYLOAD_W4 0x0800000000000000ULL
191 #define I40E_INSET_FLEX_PAYLOAD_W5 0x1000000000000000ULL
192 #define I40E_INSET_FLEX_PAYLOAD_W6 0x2000000000000000ULL
193 #define I40E_INSET_FLEX_PAYLOAD_W7 0x4000000000000000ULL
194 #define I40E_INSET_FLEX_PAYLOAD_W8 0x8000000000000000ULL
195 #define I40E_INSET_FLEX_PAYLOAD \
196 (I40E_INSET_FLEX_PAYLOAD_W1 | I40E_INSET_FLEX_PAYLOAD_W2 | \
197 I40E_INSET_FLEX_PAYLOAD_W3 | I40E_INSET_FLEX_PAYLOAD_W3 | \
198 I40E_INSET_FLEX_PAYLOAD_W5 | I40E_INSET_FLEX_PAYLOAD_W6 | \
199 I40E_INSET_FLEX_PAYLOAD_W7 | I40E_INSET_FLEX_PAYLOAD_W8)
202 * Below are values for writing un-exposed registers suggested
205 /* Destination MAC address */
206 #define I40E_REG_INSET_L2_DMAC 0xE000000000000000ULL
207 /* Source MAC address */
208 #define I40E_REG_INSET_L2_SMAC 0x1C00000000000000ULL
209 /* VLAN tag in the outer L2 header */
210 #define I40E_REG_INSET_L2_OUTER_VLAN 0x0000000000800000ULL
211 /* VLAN tag in the inner L2 header */
212 #define I40E_REG_INSET_L2_INNER_VLAN 0x0000000001000000ULL
213 /* Source IPv4 address */
214 #define I40E_REG_INSET_L3_SRC_IP4 0x0001800000000000ULL
215 /* Destination IPv4 address */
216 #define I40E_REG_INSET_L3_DST_IP4 0x0000001800000000ULL
217 /* IPv4 Type of Service (TOS) */
218 #define I40E_REG_INSET_L3_IP4_TOS 0x0040000000000000ULL
220 #define I40E_REG_INSET_L3_IP4_PROTO 0x0004000000000000ULL
221 /* Source IPv6 address */
222 #define I40E_REG_INSET_L3_SRC_IP6 0x0007F80000000000ULL
223 /* Destination IPv6 address */
224 #define I40E_REG_INSET_L3_DST_IP6 0x000007F800000000ULL
225 /* IPv6 Traffic Class (TC) */
226 #define I40E_REG_INSET_L3_IP6_TC 0x0040000000000000ULL
227 /* IPv6 Next Header */
228 #define I40E_REG_INSET_L3_IP6_NEXT_HDR 0x0008000000000000ULL
230 #define I40E_REG_INSET_L4_SRC_PORT 0x0000000400000000ULL
231 /* Destination L4 port */
232 #define I40E_REG_INSET_L4_DST_PORT 0x0000000200000000ULL
233 /* SCTP verification tag */
234 #define I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG 0x0000000180000000ULL
235 /* Inner destination MAC address (MAC-in-UDP/MAC-in-GRE)*/
236 #define I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC 0x0000000001C00000ULL
237 /* Source port of tunneling UDP */
238 #define I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT 0x0000000000200000ULL
239 /* Destination port of tunneling UDP */
240 #define I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT 0x0000000000100000ULL
241 /* UDP Tunneling ID, NVGRE/GRE key */
242 #define I40E_REG_INSET_TUNNEL_ID 0x00000000000C0000ULL
243 /* Last ether type */
244 #define I40E_REG_INSET_LAST_ETHER_TYPE 0x0000000000004000ULL
245 /* Tunneling outer destination IPv4 address */
246 #define I40E_REG_INSET_TUNNEL_L3_DST_IP4 0x00000000000000C0ULL
247 /* Tunneling outer destination IPv6 address */
248 #define I40E_REG_INSET_TUNNEL_L3_DST_IP6 0x0000000000003FC0ULL
249 /* 1st word of flex payload */
250 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD1 0x0000000000002000ULL
251 /* 2nd word of flex payload */
252 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD2 0x0000000000001000ULL
253 /* 3rd word of flex payload */
254 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD3 0x0000000000000800ULL
255 /* 4th word of flex payload */
256 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD4 0x0000000000000400ULL
257 /* 5th word of flex payload */
258 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD5 0x0000000000000200ULL
259 /* 6th word of flex payload */
260 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD6 0x0000000000000100ULL
261 /* 7th word of flex payload */
262 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD7 0x0000000000000080ULL
263 /* 8th word of flex payload */
264 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD8 0x0000000000000040ULL
266 #define I40E_REG_INSET_MASK_DEFAULT 0x0000000000000000ULL
268 #define I40E_TRANSLATE_INSET 0
269 #define I40E_TRANSLATE_REG 1
271 #define I40E_INSET_IPV4_TOS_MASK 0x0009FF00UL
272 #define I40E_INSET_IPV4_PROTO_MASK 0x000DFF00UL
273 #define I40E_INSET_IPV6_TC_MASK 0x0009F00FUL
274 #define I40E_INSET_IPV6_NEXT_HDR_MASK 0x000C00FFUL
276 static int eth_i40e_dev_init(struct rte_eth_dev *eth_dev);
277 static int eth_i40e_dev_uninit(struct rte_eth_dev *eth_dev);
278 static int i40e_dev_configure(struct rte_eth_dev *dev);
279 static int i40e_dev_start(struct rte_eth_dev *dev);
280 static void i40e_dev_stop(struct rte_eth_dev *dev);
281 static void i40e_dev_close(struct rte_eth_dev *dev);
282 static void i40e_dev_promiscuous_enable(struct rte_eth_dev *dev);
283 static void i40e_dev_promiscuous_disable(struct rte_eth_dev *dev);
284 static void i40e_dev_allmulticast_enable(struct rte_eth_dev *dev);
285 static void i40e_dev_allmulticast_disable(struct rte_eth_dev *dev);
286 static int i40e_dev_set_link_up(struct rte_eth_dev *dev);
287 static int i40e_dev_set_link_down(struct rte_eth_dev *dev);
288 static void i40e_dev_stats_get(struct rte_eth_dev *dev,
289 struct rte_eth_stats *stats);
290 static int i40e_dev_xstats_get(struct rte_eth_dev *dev,
291 struct rte_eth_xstats *xstats, unsigned n);
292 static void i40e_dev_stats_reset(struct rte_eth_dev *dev);
293 static int i40e_dev_queue_stats_mapping_set(struct rte_eth_dev *dev,
297 static void i40e_dev_info_get(struct rte_eth_dev *dev,
298 struct rte_eth_dev_info *dev_info);
299 static int i40e_vlan_filter_set(struct rte_eth_dev *dev,
302 static void i40e_vlan_tpid_set(struct rte_eth_dev *dev, uint16_t tpid);
303 static void i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask);
304 static void i40e_vlan_strip_queue_set(struct rte_eth_dev *dev,
307 static int i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on);
308 static int i40e_dev_led_on(struct rte_eth_dev *dev);
309 static int i40e_dev_led_off(struct rte_eth_dev *dev);
310 static int i40e_flow_ctrl_get(struct rte_eth_dev *dev,
311 struct rte_eth_fc_conf *fc_conf);
312 static int i40e_flow_ctrl_set(struct rte_eth_dev *dev,
313 struct rte_eth_fc_conf *fc_conf);
314 static int i40e_priority_flow_ctrl_set(struct rte_eth_dev *dev,
315 struct rte_eth_pfc_conf *pfc_conf);
316 static void i40e_macaddr_add(struct rte_eth_dev *dev,
317 struct ether_addr *mac_addr,
320 static void i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index);
321 static int i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
322 struct rte_eth_rss_reta_entry64 *reta_conf,
324 static int i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
325 struct rte_eth_rss_reta_entry64 *reta_conf,
328 static int i40e_get_cap(struct i40e_hw *hw);
329 static int i40e_pf_parameter_init(struct rte_eth_dev *dev);
330 static int i40e_pf_setup(struct i40e_pf *pf);
331 static int i40e_dev_rxtx_init(struct i40e_pf *pf);
332 static int i40e_vmdq_setup(struct rte_eth_dev *dev);
333 static int i40e_dcb_init_configure(struct rte_eth_dev *dev, bool sw_dcb);
334 static int i40e_dcb_setup(struct rte_eth_dev *dev);
335 static void i40e_stat_update_32(struct i40e_hw *hw, uint32_t reg,
336 bool offset_loaded, uint64_t *offset, uint64_t *stat);
337 static void i40e_stat_update_48(struct i40e_hw *hw,
343 static void i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue);
344 static void i40e_dev_interrupt_handler(
345 __rte_unused struct rte_intr_handle *handle, void *param);
346 static int i40e_res_pool_init(struct i40e_res_pool_info *pool,
347 uint32_t base, uint32_t num);
348 static void i40e_res_pool_destroy(struct i40e_res_pool_info *pool);
349 static int i40e_res_pool_free(struct i40e_res_pool_info *pool,
351 static int i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
353 static int i40e_dev_init_vlan(struct rte_eth_dev *dev);
354 static int i40e_veb_release(struct i40e_veb *veb);
355 static struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf,
356 struct i40e_vsi *vsi);
357 static int i40e_pf_config_mq_rx(struct i40e_pf *pf);
358 static int i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on);
359 static inline int i40e_find_all_vlan_for_mac(struct i40e_vsi *vsi,
360 struct i40e_macvlan_filter *mv_f,
362 struct ether_addr *addr);
363 static inline int i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
364 struct i40e_macvlan_filter *mv_f,
367 static int i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi);
368 static int i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
369 struct rte_eth_rss_conf *rss_conf);
370 static int i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
371 struct rte_eth_rss_conf *rss_conf);
372 static int i40e_dev_udp_tunnel_add(struct rte_eth_dev *dev,
373 struct rte_eth_udp_tunnel *udp_tunnel);
374 static int i40e_dev_udp_tunnel_del(struct rte_eth_dev *dev,
375 struct rte_eth_udp_tunnel *udp_tunnel);
376 static int i40e_ethertype_filter_set(struct i40e_pf *pf,
377 struct rte_eth_ethertype_filter *filter,
379 static int i40e_ethertype_filter_handle(struct rte_eth_dev *dev,
380 enum rte_filter_op filter_op,
382 static int i40e_dev_filter_ctrl(struct rte_eth_dev *dev,
383 enum rte_filter_type filter_type,
384 enum rte_filter_op filter_op,
386 static int i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
387 struct rte_eth_dcb_info *dcb_info);
388 static void i40e_configure_registers(struct i40e_hw *hw);
389 static void i40e_hw_init(struct i40e_hw *hw);
390 static int i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi);
391 static int i40e_mirror_rule_set(struct rte_eth_dev *dev,
392 struct rte_eth_mirror_conf *mirror_conf,
393 uint8_t sw_id, uint8_t on);
394 static int i40e_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t sw_id);
396 static int i40e_timesync_enable(struct rte_eth_dev *dev);
397 static int i40e_timesync_disable(struct rte_eth_dev *dev);
398 static int i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
399 struct timespec *timestamp,
401 static int i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
402 struct timespec *timestamp);
403 static void i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw);
405 static int i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
407 static int i40e_timesync_read_time(struct rte_eth_dev *dev,
408 struct timespec *timestamp);
409 static int i40e_timesync_write_time(struct rte_eth_dev *dev,
410 const struct timespec *timestamp);
412 static int i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
414 static int i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
418 static const struct rte_pci_id pci_id_i40e_map[] = {
419 #define RTE_PCI_DEV_ID_DECL_I40E(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
420 #include "rte_pci_dev_ids.h"
421 { .vendor_id = 0, /* sentinel */ },
424 static const struct eth_dev_ops i40e_eth_dev_ops = {
425 .dev_configure = i40e_dev_configure,
426 .dev_start = i40e_dev_start,
427 .dev_stop = i40e_dev_stop,
428 .dev_close = i40e_dev_close,
429 .promiscuous_enable = i40e_dev_promiscuous_enable,
430 .promiscuous_disable = i40e_dev_promiscuous_disable,
431 .allmulticast_enable = i40e_dev_allmulticast_enable,
432 .allmulticast_disable = i40e_dev_allmulticast_disable,
433 .dev_set_link_up = i40e_dev_set_link_up,
434 .dev_set_link_down = i40e_dev_set_link_down,
435 .link_update = i40e_dev_link_update,
436 .stats_get = i40e_dev_stats_get,
437 .xstats_get = i40e_dev_xstats_get,
438 .stats_reset = i40e_dev_stats_reset,
439 .xstats_reset = i40e_dev_stats_reset,
440 .queue_stats_mapping_set = i40e_dev_queue_stats_mapping_set,
441 .dev_infos_get = i40e_dev_info_get,
442 .vlan_filter_set = i40e_vlan_filter_set,
443 .vlan_tpid_set = i40e_vlan_tpid_set,
444 .vlan_offload_set = i40e_vlan_offload_set,
445 .vlan_strip_queue_set = i40e_vlan_strip_queue_set,
446 .vlan_pvid_set = i40e_vlan_pvid_set,
447 .rx_queue_start = i40e_dev_rx_queue_start,
448 .rx_queue_stop = i40e_dev_rx_queue_stop,
449 .tx_queue_start = i40e_dev_tx_queue_start,
450 .tx_queue_stop = i40e_dev_tx_queue_stop,
451 .rx_queue_setup = i40e_dev_rx_queue_setup,
452 .rx_queue_intr_enable = i40e_dev_rx_queue_intr_enable,
453 .rx_queue_intr_disable = i40e_dev_rx_queue_intr_disable,
454 .rx_queue_release = i40e_dev_rx_queue_release,
455 .rx_queue_count = i40e_dev_rx_queue_count,
456 .rx_descriptor_done = i40e_dev_rx_descriptor_done,
457 .tx_queue_setup = i40e_dev_tx_queue_setup,
458 .tx_queue_release = i40e_dev_tx_queue_release,
459 .dev_led_on = i40e_dev_led_on,
460 .dev_led_off = i40e_dev_led_off,
461 .flow_ctrl_get = i40e_flow_ctrl_get,
462 .flow_ctrl_set = i40e_flow_ctrl_set,
463 .priority_flow_ctrl_set = i40e_priority_flow_ctrl_set,
464 .mac_addr_add = i40e_macaddr_add,
465 .mac_addr_remove = i40e_macaddr_remove,
466 .reta_update = i40e_dev_rss_reta_update,
467 .reta_query = i40e_dev_rss_reta_query,
468 .rss_hash_update = i40e_dev_rss_hash_update,
469 .rss_hash_conf_get = i40e_dev_rss_hash_conf_get,
470 .udp_tunnel_add = i40e_dev_udp_tunnel_add,
471 .udp_tunnel_del = i40e_dev_udp_tunnel_del,
472 .filter_ctrl = i40e_dev_filter_ctrl,
473 .rxq_info_get = i40e_rxq_info_get,
474 .txq_info_get = i40e_txq_info_get,
475 .mirror_rule_set = i40e_mirror_rule_set,
476 .mirror_rule_reset = i40e_mirror_rule_reset,
477 .timesync_enable = i40e_timesync_enable,
478 .timesync_disable = i40e_timesync_disable,
479 .timesync_read_rx_timestamp = i40e_timesync_read_rx_timestamp,
480 .timesync_read_tx_timestamp = i40e_timesync_read_tx_timestamp,
481 .get_dcb_info = i40e_dev_get_dcb_info,
482 .timesync_adjust_time = i40e_timesync_adjust_time,
483 .timesync_read_time = i40e_timesync_read_time,
484 .timesync_write_time = i40e_timesync_write_time,
487 /* store statistics names and its offset in stats structure */
488 struct rte_i40e_xstats_name_off {
489 char name[RTE_ETH_XSTATS_NAME_SIZE];
493 static const struct rte_i40e_xstats_name_off rte_i40e_stats_strings[] = {
494 {"rx_unicast_packets", offsetof(struct i40e_eth_stats, rx_unicast)},
495 {"rx_multicast_packets", offsetof(struct i40e_eth_stats, rx_multicast)},
496 {"rx_broadcast_packets", offsetof(struct i40e_eth_stats, rx_broadcast)},
497 {"rx_dropped", offsetof(struct i40e_eth_stats, rx_discards)},
498 {"rx_unknown_protocol_packets", offsetof(struct i40e_eth_stats,
499 rx_unknown_protocol)},
500 {"tx_unicast_packets", offsetof(struct i40e_eth_stats, tx_unicast)},
501 {"tx_multicast_packets", offsetof(struct i40e_eth_stats, tx_multicast)},
502 {"tx_broadcast_packets", offsetof(struct i40e_eth_stats, tx_broadcast)},
503 {"tx_dropped", offsetof(struct i40e_eth_stats, tx_discards)},
506 #define I40E_NB_ETH_XSTATS (sizeof(rte_i40e_stats_strings) / \
507 sizeof(rte_i40e_stats_strings[0]))
509 static const struct rte_i40e_xstats_name_off rte_i40e_hw_port_strings[] = {
510 {"tx_link_down_dropped", offsetof(struct i40e_hw_port_stats,
511 tx_dropped_link_down)},
512 {"rx_crc_errors", offsetof(struct i40e_hw_port_stats, crc_errors)},
513 {"rx_illegal_byte_errors", offsetof(struct i40e_hw_port_stats,
515 {"rx_error_bytes", offsetof(struct i40e_hw_port_stats, error_bytes)},
516 {"mac_local_errors", offsetof(struct i40e_hw_port_stats,
518 {"mac_remote_errors", offsetof(struct i40e_hw_port_stats,
520 {"rx_length_errors", offsetof(struct i40e_hw_port_stats,
522 {"tx_xon_packets", offsetof(struct i40e_hw_port_stats, link_xon_tx)},
523 {"rx_xon_packets", offsetof(struct i40e_hw_port_stats, link_xon_rx)},
524 {"tx_xoff_packets", offsetof(struct i40e_hw_port_stats, link_xoff_tx)},
525 {"rx_xoff_packets", offsetof(struct i40e_hw_port_stats, link_xoff_rx)},
526 {"rx_size_64_packets", offsetof(struct i40e_hw_port_stats, rx_size_64)},
527 {"rx_size_65_to_127_packets", offsetof(struct i40e_hw_port_stats,
529 {"rx_size_128_to_255_packets", offsetof(struct i40e_hw_port_stats,
531 {"rx_size_256_to_511_packets", offsetof(struct i40e_hw_port_stats,
533 {"rx_size_512_to_1023_packets", offsetof(struct i40e_hw_port_stats,
535 {"rx_size_1024_to_1522_packets", offsetof(struct i40e_hw_port_stats,
537 {"rx_size_1523_to_max_packets", offsetof(struct i40e_hw_port_stats,
539 {"rx_undersized_errors", offsetof(struct i40e_hw_port_stats,
541 {"rx_oversize_errors", offsetof(struct i40e_hw_port_stats,
543 {"rx_mac_short_dropped", offsetof(struct i40e_hw_port_stats,
544 mac_short_packet_dropped)},
545 {"rx_fragmented_errors", offsetof(struct i40e_hw_port_stats,
547 {"rx_jabber_errors", offsetof(struct i40e_hw_port_stats, rx_jabber)},
548 {"tx_size_64_packets", offsetof(struct i40e_hw_port_stats, tx_size_64)},
549 {"tx_size_65_to_127_packets", offsetof(struct i40e_hw_port_stats,
551 {"tx_size_128_to_255_packets", offsetof(struct i40e_hw_port_stats,
553 {"tx_size_256_to_511_packets", offsetof(struct i40e_hw_port_stats,
555 {"tx_size_512_to_1023_packets", offsetof(struct i40e_hw_port_stats,
557 {"tx_size_1024_to_1522_packets", offsetof(struct i40e_hw_port_stats,
559 {"tx_size_1523_to_max_packets", offsetof(struct i40e_hw_port_stats,
561 {"rx_flow_director_atr_match_packets",
562 offsetof(struct i40e_hw_port_stats, fd_atr_match)},
563 {"rx_flow_director_sb_match_packets",
564 offsetof(struct i40e_hw_port_stats, fd_sb_match)},
565 {"tx_low_power_idle_status", offsetof(struct i40e_hw_port_stats,
567 {"rx_low_power_idle_status", offsetof(struct i40e_hw_port_stats,
569 {"tx_low_power_idle_count", offsetof(struct i40e_hw_port_stats,
571 {"rx_low_power_idle_count", offsetof(struct i40e_hw_port_stats,
575 #define I40E_NB_HW_PORT_XSTATS (sizeof(rte_i40e_hw_port_strings) / \
576 sizeof(rte_i40e_hw_port_strings[0]))
578 static const struct rte_i40e_xstats_name_off rte_i40e_rxq_prio_strings[] = {
579 {"xon_packets", offsetof(struct i40e_hw_port_stats,
581 {"xoff_packets", offsetof(struct i40e_hw_port_stats,
585 #define I40E_NB_RXQ_PRIO_XSTATS (sizeof(rte_i40e_rxq_prio_strings) / \
586 sizeof(rte_i40e_rxq_prio_strings[0]))
588 static const struct rte_i40e_xstats_name_off rte_i40e_txq_prio_strings[] = {
589 {"xon_packets", offsetof(struct i40e_hw_port_stats,
591 {"xoff_packets", offsetof(struct i40e_hw_port_stats,
593 {"xon_to_xoff_packets", offsetof(struct i40e_hw_port_stats,
594 priority_xon_2_xoff)},
597 #define I40E_NB_TXQ_PRIO_XSTATS (sizeof(rte_i40e_txq_prio_strings) / \
598 sizeof(rte_i40e_txq_prio_strings[0]))
600 static struct eth_driver rte_i40e_pmd = {
602 .name = "rte_i40e_pmd",
603 .id_table = pci_id_i40e_map,
604 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
605 RTE_PCI_DRV_DETACHABLE,
607 .eth_dev_init = eth_i40e_dev_init,
608 .eth_dev_uninit = eth_i40e_dev_uninit,
609 .dev_private_size = sizeof(struct i40e_adapter),
613 rte_i40e_dev_atomic_read_link_status(struct rte_eth_dev *dev,
614 struct rte_eth_link *link)
616 struct rte_eth_link *dst = link;
617 struct rte_eth_link *src = &(dev->data->dev_link);
619 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
620 *(uint64_t *)src) == 0)
627 rte_i40e_dev_atomic_write_link_status(struct rte_eth_dev *dev,
628 struct rte_eth_link *link)
630 struct rte_eth_link *dst = &(dev->data->dev_link);
631 struct rte_eth_link *src = link;
633 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
634 *(uint64_t *)src) == 0)
641 * Driver initialization routine.
642 * Invoked once at EAL init time.
643 * Register itself as the [Poll Mode] Driver of PCI IXGBE devices.
646 rte_i40e_pmd_init(const char *name __rte_unused,
647 const char *params __rte_unused)
649 PMD_INIT_FUNC_TRACE();
650 rte_eth_driver_register(&rte_i40e_pmd);
655 static struct rte_driver rte_i40e_driver = {
657 .init = rte_i40e_pmd_init,
660 PMD_REGISTER_DRIVER(rte_i40e_driver);
663 * Initialize registers for flexible payload, which should be set by NVM.
664 * This should be removed from code once it is fixed in NVM.
666 #ifndef I40E_GLQF_ORT
667 #define I40E_GLQF_ORT(_i) (0x00268900 + ((_i) * 4))
669 #ifndef I40E_GLQF_PIT
670 #define I40E_GLQF_PIT(_i) (0x00268C80 + ((_i) * 4))
673 static inline void i40e_flex_payload_reg_init(struct i40e_hw *hw)
675 I40E_WRITE_REG(hw, I40E_GLQF_ORT(18), 0x00000030);
676 I40E_WRITE_REG(hw, I40E_GLQF_ORT(19), 0x00000030);
677 I40E_WRITE_REG(hw, I40E_GLQF_ORT(26), 0x0000002B);
678 I40E_WRITE_REG(hw, I40E_GLQF_ORT(30), 0x0000002B);
679 I40E_WRITE_REG(hw, I40E_GLQF_ORT(33), 0x000000E0);
680 I40E_WRITE_REG(hw, I40E_GLQF_ORT(34), 0x000000E3);
681 I40E_WRITE_REG(hw, I40E_GLQF_ORT(35), 0x000000E6);
682 I40E_WRITE_REG(hw, I40E_GLQF_ORT(20), 0x00000031);
683 I40E_WRITE_REG(hw, I40E_GLQF_ORT(23), 0x00000031);
684 I40E_WRITE_REG(hw, I40E_GLQF_ORT(63), 0x0000002D);
686 /* GLQF_PIT Registers */
687 I40E_WRITE_REG(hw, I40E_GLQF_PIT(16), 0x00007480);
688 I40E_WRITE_REG(hw, I40E_GLQF_PIT(17), 0x00007440);
691 #define I40E_FLOW_CONTROL_ETHERTYPE 0x8808
694 * Add a ethertype filter to drop all flow control frames transmitted
698 i40e_add_tx_flow_control_drop_filter(struct i40e_pf *pf)
700 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
701 uint16_t flags = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
702 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
703 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
706 ret = i40e_aq_add_rem_control_packet_filter(hw, NULL,
707 I40E_FLOW_CONTROL_ETHERTYPE, flags,
708 pf->main_vsi_seid, 0,
711 PMD_INIT_LOG(ERR, "Failed to add filter to drop flow control "
712 " frames from VSIs.");
716 eth_i40e_dev_init(struct rte_eth_dev *dev)
718 struct rte_pci_device *pci_dev;
719 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
720 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
721 struct i40e_vsi *vsi;
726 PMD_INIT_FUNC_TRACE();
728 dev->dev_ops = &i40e_eth_dev_ops;
729 dev->rx_pkt_burst = i40e_recv_pkts;
730 dev->tx_pkt_burst = i40e_xmit_pkts;
732 /* for secondary processes, we don't initialise any further as primary
733 * has already done this work. Only check we don't need a different
735 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
736 i40e_set_rx_function(dev);
737 i40e_set_tx_function(dev);
740 pci_dev = dev->pci_dev;
742 rte_eth_copy_pci_info(dev, pci_dev);
744 pf->adapter = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
745 pf->adapter->eth_dev = dev;
746 pf->dev_data = dev->data;
748 hw->back = I40E_PF_TO_ADAPTER(pf);
749 hw->hw_addr = (uint8_t *)(pci_dev->mem_resource[0].addr);
751 PMD_INIT_LOG(ERR, "Hardware is not available, "
752 "as address is NULL");
756 hw->vendor_id = pci_dev->id.vendor_id;
757 hw->device_id = pci_dev->id.device_id;
758 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
759 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
760 hw->bus.device = pci_dev->addr.devid;
761 hw->bus.func = pci_dev->addr.function;
762 hw->adapter_stopped = 0;
764 /* Make sure all is clean before doing PF reset */
767 /* Initialize the hardware */
770 /* Reset here to make sure all is clean for each PF */
771 ret = i40e_pf_reset(hw);
773 PMD_INIT_LOG(ERR, "Failed to reset pf: %d", ret);
777 /* Initialize the shared code (base driver) */
778 ret = i40e_init_shared_code(hw);
780 PMD_INIT_LOG(ERR, "Failed to init shared code (base driver): %d", ret);
785 * To work around the NVM issue,initialize registers
786 * for flexible payload by software.
787 * It should be removed once issues are fixed in NVM.
789 i40e_flex_payload_reg_init(hw);
791 /* Initialize the parameters for adminq */
792 i40e_init_adminq_parameter(hw);
793 ret = i40e_init_adminq(hw);
794 if (ret != I40E_SUCCESS) {
795 PMD_INIT_LOG(ERR, "Failed to init adminq: %d", ret);
798 PMD_INIT_LOG(INFO, "FW %d.%d API %d.%d NVM %02d.%02d.%02d eetrack %04x",
799 hw->aq.fw_maj_ver, hw->aq.fw_min_ver,
800 hw->aq.api_maj_ver, hw->aq.api_min_ver,
801 ((hw->nvm.version >> 12) & 0xf),
802 ((hw->nvm.version >> 4) & 0xff),
803 (hw->nvm.version & 0xf), hw->nvm.eetrack);
806 i40e_clear_pxe_mode(hw);
809 * On X710, performance number is far from the expectation on recent
810 * firmware versions. The fix for this issue may not be integrated in
811 * the following firmware version. So the workaround in software driver
812 * is needed. It needs to modify the initial values of 3 internal only
813 * registers. Note that the workaround can be removed when it is fixed
814 * in firmware in the future.
816 i40e_configure_registers(hw);
818 /* Get hw capabilities */
819 ret = i40e_get_cap(hw);
820 if (ret != I40E_SUCCESS) {
821 PMD_INIT_LOG(ERR, "Failed to get capabilities: %d", ret);
822 goto err_get_capabilities;
825 /* Initialize parameters for PF */
826 ret = i40e_pf_parameter_init(dev);
828 PMD_INIT_LOG(ERR, "Failed to do parameter init: %d", ret);
829 goto err_parameter_init;
832 /* Initialize the queue management */
833 ret = i40e_res_pool_init(&pf->qp_pool, 0, hw->func_caps.num_tx_qp);
835 PMD_INIT_LOG(ERR, "Failed to init queue pool");
836 goto err_qp_pool_init;
838 ret = i40e_res_pool_init(&pf->msix_pool, 1,
839 hw->func_caps.num_msix_vectors - 1);
841 PMD_INIT_LOG(ERR, "Failed to init MSIX pool");
842 goto err_msix_pool_init;
845 /* Initialize lan hmc */
846 ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
847 hw->func_caps.num_rx_qp, 0, 0);
848 if (ret != I40E_SUCCESS) {
849 PMD_INIT_LOG(ERR, "Failed to init lan hmc: %d", ret);
850 goto err_init_lan_hmc;
853 /* Configure lan hmc */
854 ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
855 if (ret != I40E_SUCCESS) {
856 PMD_INIT_LOG(ERR, "Failed to configure lan hmc: %d", ret);
857 goto err_configure_lan_hmc;
860 /* Get and check the mac address */
861 i40e_get_mac_addr(hw, hw->mac.addr);
862 if (i40e_validate_mac_addr(hw->mac.addr) != I40E_SUCCESS) {
863 PMD_INIT_LOG(ERR, "mac address is not valid");
865 goto err_get_mac_addr;
867 /* Copy the permanent MAC address */
868 ether_addr_copy((struct ether_addr *) hw->mac.addr,
869 (struct ether_addr *) hw->mac.perm_addr);
871 /* Disable flow control */
872 hw->fc.requested_mode = I40E_FC_NONE;
873 i40e_set_fc(hw, &aq_fail, TRUE);
875 /* PF setup, which includes VSI setup */
876 ret = i40e_pf_setup(pf);
878 PMD_INIT_LOG(ERR, "Failed to setup pf switch: %d", ret);
879 goto err_setup_pf_switch;
884 /* Disable double vlan by default */
885 i40e_vsi_config_double_vlan(vsi, FALSE);
887 if (!vsi->max_macaddrs)
888 len = ETHER_ADDR_LEN;
890 len = ETHER_ADDR_LEN * vsi->max_macaddrs;
892 /* Should be after VSI initialized */
893 dev->data->mac_addrs = rte_zmalloc("i40e", len, 0);
894 if (!dev->data->mac_addrs) {
895 PMD_INIT_LOG(ERR, "Failed to allocated memory "
896 "for storing mac address");
899 ether_addr_copy((struct ether_addr *)hw->mac.perm_addr,
900 &dev->data->mac_addrs[0]);
902 /* initialize pf host driver to setup SRIOV resource if applicable */
903 i40e_pf_host_init(dev);
905 /* register callback func to eal lib */
906 rte_intr_callback_register(&(pci_dev->intr_handle),
907 i40e_dev_interrupt_handler, (void *)dev);
909 /* configure and enable device interrupt */
910 i40e_pf_config_irq0(hw, TRUE);
911 i40e_pf_enable_irq0(hw);
913 /* enable uio intr after callback register */
914 rte_intr_enable(&(pci_dev->intr_handle));
916 * Add an ethertype filter to drop all flow control frames transmitted
917 * from VSIs. By doing so, we stop VF from sending out PAUSE or PFC
920 i40e_add_tx_flow_control_drop_filter(pf);
922 /* initialize mirror rule list */
923 TAILQ_INIT(&pf->mirror_list);
925 /* Init dcb to sw mode by default */
926 ret = i40e_dcb_init_configure(dev, TRUE);
927 if (ret != I40E_SUCCESS) {
928 PMD_INIT_LOG(INFO, "Failed to init dcb.");
929 pf->flags &= ~I40E_FLAG_DCB;
935 i40e_vsi_release(pf->main_vsi);
938 err_configure_lan_hmc:
939 (void)i40e_shutdown_lan_hmc(hw);
941 i40e_res_pool_destroy(&pf->msix_pool);
943 i40e_res_pool_destroy(&pf->qp_pool);
946 err_get_capabilities:
947 (void)i40e_shutdown_adminq(hw);
953 eth_i40e_dev_uninit(struct rte_eth_dev *dev)
955 struct rte_pci_device *pci_dev;
957 struct i40e_filter_control_settings settings;
961 PMD_INIT_FUNC_TRACE();
963 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
966 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
967 pci_dev = dev->pci_dev;
969 if (hw->adapter_stopped == 0)
973 dev->rx_pkt_burst = NULL;
974 dev->tx_pkt_burst = NULL;
977 ret = i40e_aq_stop_lldp(hw, true, NULL);
978 if (ret != I40E_SUCCESS) /* Its failure can be ignored */
979 PMD_INIT_LOG(INFO, "Failed to stop lldp");
982 i40e_clear_pxe_mode(hw);
984 /* Unconfigure filter control */
985 memset(&settings, 0, sizeof(settings));
986 ret = i40e_set_filter_control(hw, &settings);
988 PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
991 /* Disable flow control */
992 hw->fc.requested_mode = I40E_FC_NONE;
993 i40e_set_fc(hw, &aq_fail, TRUE);
995 /* uninitialize pf host driver */
996 i40e_pf_host_uninit(dev);
998 rte_free(dev->data->mac_addrs);
999 dev->data->mac_addrs = NULL;
1001 /* disable uio intr before callback unregister */
1002 rte_intr_disable(&(pci_dev->intr_handle));
1004 /* register callback func to eal lib */
1005 rte_intr_callback_unregister(&(pci_dev->intr_handle),
1006 i40e_dev_interrupt_handler, (void *)dev);
1012 i40e_dev_configure(struct rte_eth_dev *dev)
1014 struct i40e_adapter *ad =
1015 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1016 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1017 enum rte_eth_rx_mq_mode mq_mode = dev->data->dev_conf.rxmode.mq_mode;
1020 /* Initialize to TRUE. If any of Rx queues doesn't meet the
1021 * bulk allocation or vector Rx preconditions we will reset it.
1023 ad->rx_bulk_alloc_allowed = true;
1024 ad->rx_vec_allowed = true;
1025 ad->tx_simple_allowed = true;
1026 ad->tx_vec_allowed = true;
1028 if (dev->data->dev_conf.fdir_conf.mode == RTE_FDIR_MODE_PERFECT) {
1029 ret = i40e_fdir_setup(pf);
1030 if (ret != I40E_SUCCESS) {
1031 PMD_DRV_LOG(ERR, "Failed to setup flow director.");
1034 ret = i40e_fdir_configure(dev);
1036 PMD_DRV_LOG(ERR, "failed to configure fdir.");
1040 i40e_fdir_teardown(pf);
1042 ret = i40e_dev_init_vlan(dev);
1047 * Needs to move VMDQ setting out of i40e_pf_config_mq_rx() as VMDQ and
1048 * RSS setting have different requirements.
1049 * General PMD driver call sequence are NIC init, configure,
1050 * rx/tx_queue_setup and dev_start. In rx/tx_queue_setup() function, it
1051 * will try to lookup the VSI that specific queue belongs to if VMDQ
1052 * applicable. So, VMDQ setting has to be done before
1053 * rx/tx_queue_setup(). This function is good to place vmdq_setup.
1054 * For RSS setting, it will try to calculate actual configured RX queue
1055 * number, which will be available after rx_queue_setup(). dev_start()
1056 * function is good to place RSS setup.
1058 if (mq_mode & ETH_MQ_RX_VMDQ_FLAG) {
1059 ret = i40e_vmdq_setup(dev);
1064 if (mq_mode & ETH_MQ_RX_DCB_FLAG) {
1065 ret = i40e_dcb_setup(dev);
1067 PMD_DRV_LOG(ERR, "failed to configure DCB.");
1075 /* need to release vmdq resource if exists */
1076 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1077 i40e_vsi_release(pf->vmdq[i].vsi);
1078 pf->vmdq[i].vsi = NULL;
1083 /* need to release fdir resource if exists */
1084 i40e_fdir_teardown(pf);
1089 i40e_vsi_queues_unbind_intr(struct i40e_vsi *vsi)
1091 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1092 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1093 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1094 uint16_t msix_vect = vsi->msix_intr;
1097 for (i = 0; i < vsi->nb_qps; i++) {
1098 I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
1099 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
1103 if (vsi->type != I40E_VSI_SRIOV) {
1104 if (!rte_intr_allow_others(intr_handle)) {
1105 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
1106 I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
1108 I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
1111 I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
1112 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
1114 I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
1119 reg = (hw->func_caps.num_msix_vectors_vf - 1) *
1120 vsi->user_param + (msix_vect - 1);
1122 I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
1123 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
1125 I40E_WRITE_FLUSH(hw);
1129 __vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t msix_vect,
1130 int base_queue, int nb_queue)
1134 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1136 /* Bind all RX queues to allocated MSIX interrupt */
1137 for (i = 0; i < nb_queue; i++) {
1138 val = (msix_vect << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
1139 I40E_QINT_RQCTL_ITR_INDX_MASK |
1140 ((base_queue + i + 1) <<
1141 I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
1142 (0 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
1143 I40E_QINT_RQCTL_CAUSE_ENA_MASK;
1145 if (i == nb_queue - 1)
1146 val |= I40E_QINT_RQCTL_NEXTQ_INDX_MASK;
1147 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(base_queue + i), val);
1150 /* Write first RX queue to Link list register as the head element */
1151 if (vsi->type != I40E_VSI_SRIOV) {
1153 i40e_calc_itr_interval(RTE_LIBRTE_I40E_ITR_INTERVAL);
1155 if (msix_vect == I40E_MISC_VEC_ID) {
1156 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
1158 I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
1160 I40E_PFINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
1162 I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
1165 I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
1167 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
1169 I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
1171 I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
1178 if (msix_vect == I40E_MISC_VEC_ID) {
1180 I40E_VPINT_LNKLST0(vsi->user_param),
1182 I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
1184 I40E_VPINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
1186 /* num_msix_vectors_vf needs to minus irq0 */
1187 reg = (hw->func_caps.num_msix_vectors_vf - 1) *
1188 vsi->user_param + (msix_vect - 1);
1190 I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
1192 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
1194 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
1198 I40E_WRITE_FLUSH(hw);
1202 i40e_vsi_queues_bind_intr(struct i40e_vsi *vsi)
1204 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1205 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1206 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1207 uint16_t msix_vect = vsi->msix_intr;
1208 uint16_t nb_msix = RTE_MIN(vsi->nb_msix, intr_handle->nb_efd);
1209 uint16_t queue_idx = 0;
1214 for (i = 0; i < vsi->nb_qps; i++) {
1215 I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
1216 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
1219 /* INTENA flag is not auto-cleared for interrupt */
1220 val = I40E_READ_REG(hw, I40E_GLINT_CTL);
1221 val |= I40E_GLINT_CTL_DIS_AUTOMASK_PF0_MASK |
1222 I40E_GLINT_CTL_DIS_AUTOMASK_N_MASK |
1223 I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK;
1224 I40E_WRITE_REG(hw, I40E_GLINT_CTL, val);
1226 /* VF bind interrupt */
1227 if (vsi->type == I40E_VSI_SRIOV) {
1228 __vsi_queues_bind_intr(vsi, msix_vect,
1229 vsi->base_queue, vsi->nb_qps);
1233 /* PF & VMDq bind interrupt */
1234 if (rte_intr_dp_is_en(intr_handle)) {
1235 if (vsi->type == I40E_VSI_MAIN) {
1238 } else if (vsi->type == I40E_VSI_VMDQ2) {
1239 struct i40e_vsi *main_vsi =
1240 I40E_DEV_PRIVATE_TO_MAIN_VSI(vsi->adapter);
1241 queue_idx = vsi->base_queue - main_vsi->nb_qps;
1246 for (i = 0; i < vsi->nb_used_qps; i++) {
1248 if (!rte_intr_allow_others(intr_handle))
1249 /* allow to share MISC_VEC_ID */
1250 msix_vect = I40E_MISC_VEC_ID;
1252 /* no enough msix_vect, map all to one */
1253 __vsi_queues_bind_intr(vsi, msix_vect,
1254 vsi->base_queue + i,
1255 vsi->nb_used_qps - i);
1256 for (; !!record && i < vsi->nb_used_qps; i++)
1257 intr_handle->intr_vec[queue_idx + i] =
1261 /* 1:1 queue/msix_vect mapping */
1262 __vsi_queues_bind_intr(vsi, msix_vect,
1263 vsi->base_queue + i, 1);
1265 intr_handle->intr_vec[queue_idx + i] = msix_vect;
1273 i40e_vsi_enable_queues_intr(struct i40e_vsi *vsi)
1275 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1276 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1277 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1278 uint16_t interval = i40e_calc_itr_interval(\
1279 RTE_LIBRTE_I40E_ITR_INTERVAL);
1280 uint16_t msix_intr, i;
1282 if (rte_intr_allow_others(intr_handle))
1283 for (i = 0; i < vsi->nb_msix; i++) {
1284 msix_intr = vsi->msix_intr + i;
1285 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
1286 I40E_PFINT_DYN_CTLN_INTENA_MASK |
1287 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
1288 (0 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT) |
1290 I40E_PFINT_DYN_CTLN_INTERVAL_SHIFT));
1293 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
1294 I40E_PFINT_DYN_CTL0_INTENA_MASK |
1295 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
1296 (0 << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT) |
1298 I40E_PFINT_DYN_CTL0_INTERVAL_SHIFT));
1300 I40E_WRITE_FLUSH(hw);
1304 i40e_vsi_disable_queues_intr(struct i40e_vsi *vsi)
1306 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1307 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1308 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1309 uint16_t msix_intr, i;
1311 if (rte_intr_allow_others(intr_handle))
1312 for (i = 0; i < vsi->nb_msix; i++) {
1313 msix_intr = vsi->msix_intr + i;
1314 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
1318 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0, 0);
1320 I40E_WRITE_FLUSH(hw);
1323 static inline uint8_t
1324 i40e_parse_link_speed(uint16_t eth_link_speed)
1326 uint8_t link_speed = I40E_LINK_SPEED_UNKNOWN;
1328 switch (eth_link_speed) {
1329 case ETH_LINK_SPEED_40G:
1330 link_speed = I40E_LINK_SPEED_40GB;
1332 case ETH_LINK_SPEED_20G:
1333 link_speed = I40E_LINK_SPEED_20GB;
1335 case ETH_LINK_SPEED_10G:
1336 link_speed = I40E_LINK_SPEED_10GB;
1338 case ETH_LINK_SPEED_1000:
1339 link_speed = I40E_LINK_SPEED_1GB;
1341 case ETH_LINK_SPEED_100:
1342 link_speed = I40E_LINK_SPEED_100MB;
1350 i40e_phy_conf_link(struct i40e_hw *hw, uint8_t abilities, uint8_t force_speed)
1352 enum i40e_status_code status;
1353 struct i40e_aq_get_phy_abilities_resp phy_ab;
1354 struct i40e_aq_set_phy_config phy_conf;
1355 const uint8_t mask = I40E_AQ_PHY_FLAG_PAUSE_TX |
1356 I40E_AQ_PHY_FLAG_PAUSE_RX |
1357 I40E_AQ_PHY_FLAG_LOW_POWER;
1358 const uint8_t advt = I40E_LINK_SPEED_40GB |
1359 I40E_LINK_SPEED_10GB |
1360 I40E_LINK_SPEED_1GB |
1361 I40E_LINK_SPEED_100MB;
1364 /* Skip it on 40G interfaces, as a workaround for the link issue */
1365 if (i40e_is_40G_device(hw->device_id))
1366 return I40E_SUCCESS;
1368 status = i40e_aq_get_phy_capabilities(hw, false, false, &phy_ab,
1373 memset(&phy_conf, 0, sizeof(phy_conf));
1375 /* bits 0-2 use the values from get_phy_abilities_resp */
1377 abilities |= phy_ab.abilities & mask;
1379 /* update ablities and speed */
1380 if (abilities & I40E_AQ_PHY_AN_ENABLED)
1381 phy_conf.link_speed = advt;
1383 phy_conf.link_speed = force_speed;
1385 phy_conf.abilities = abilities;
1387 /* use get_phy_abilities_resp value for the rest */
1388 phy_conf.phy_type = phy_ab.phy_type;
1389 phy_conf.eee_capability = phy_ab.eee_capability;
1390 phy_conf.eeer = phy_ab.eeer_val;
1391 phy_conf.low_power_ctrl = phy_ab.d3_lpan;
1393 PMD_DRV_LOG(DEBUG, "\tCurrent: abilities %x, link_speed %x",
1394 phy_ab.abilities, phy_ab.link_speed);
1395 PMD_DRV_LOG(DEBUG, "\tConfig: abilities %x, link_speed %x",
1396 phy_conf.abilities, phy_conf.link_speed);
1398 status = i40e_aq_set_phy_config(hw, &phy_conf, NULL);
1402 return I40E_SUCCESS;
1406 i40e_apply_link_speed(struct rte_eth_dev *dev)
1409 uint8_t abilities = 0;
1410 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1411 struct rte_eth_conf *conf = &dev->data->dev_conf;
1413 speed = i40e_parse_link_speed(conf->link_speed);
1414 abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1415 if (conf->link_speed == ETH_LINK_SPEED_AUTONEG)
1416 abilities |= I40E_AQ_PHY_AN_ENABLED;
1418 abilities |= I40E_AQ_PHY_LINK_ENABLED;
1420 return i40e_phy_conf_link(hw, abilities, speed);
1424 i40e_dev_start(struct rte_eth_dev *dev)
1426 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1427 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1428 struct i40e_vsi *main_vsi = pf->main_vsi;
1430 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1431 uint32_t intr_vector = 0;
1433 hw->adapter_stopped = 0;
1435 if ((dev->data->dev_conf.link_duplex != ETH_LINK_AUTONEG_DUPLEX) &&
1436 (dev->data->dev_conf.link_duplex != ETH_LINK_FULL_DUPLEX)) {
1437 PMD_INIT_LOG(ERR, "Invalid link_duplex (%hu) for port %hhu",
1438 dev->data->dev_conf.link_duplex,
1439 dev->data->port_id);
1443 rte_intr_disable(intr_handle);
1445 if ((rte_intr_cap_multiple(intr_handle) ||
1446 !RTE_ETH_DEV_SRIOV(dev).active) &&
1447 dev->data->dev_conf.intr_conf.rxq != 0) {
1448 intr_vector = dev->data->nb_rx_queues;
1449 if (rte_intr_efd_enable(intr_handle, intr_vector))
1453 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
1454 intr_handle->intr_vec =
1455 rte_zmalloc("intr_vec",
1456 dev->data->nb_rx_queues * sizeof(int),
1458 if (!intr_handle->intr_vec) {
1459 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
1460 " intr_vec\n", dev->data->nb_rx_queues);
1465 /* Initialize VSI */
1466 ret = i40e_dev_rxtx_init(pf);
1467 if (ret != I40E_SUCCESS) {
1468 PMD_DRV_LOG(ERR, "Failed to init rx/tx queues");
1472 /* Map queues with MSIX interrupt */
1473 main_vsi->nb_used_qps = dev->data->nb_rx_queues -
1474 pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
1475 i40e_vsi_queues_bind_intr(main_vsi);
1476 i40e_vsi_enable_queues_intr(main_vsi);
1478 /* Map VMDQ VSI queues with MSIX interrupt */
1479 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1480 pf->vmdq[i].vsi->nb_used_qps = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
1481 i40e_vsi_queues_bind_intr(pf->vmdq[i].vsi);
1482 i40e_vsi_enable_queues_intr(pf->vmdq[i].vsi);
1485 /* enable FDIR MSIX interrupt */
1486 if (pf->fdir.fdir_vsi) {
1487 i40e_vsi_queues_bind_intr(pf->fdir.fdir_vsi);
1488 i40e_vsi_enable_queues_intr(pf->fdir.fdir_vsi);
1491 /* Enable all queues which have been configured */
1492 ret = i40e_dev_switch_queues(pf, TRUE);
1493 if (ret != I40E_SUCCESS) {
1494 PMD_DRV_LOG(ERR, "Failed to enable VSI");
1498 /* Enable receiving broadcast packets */
1499 ret = i40e_aq_set_vsi_broadcast(hw, main_vsi->seid, true, NULL);
1500 if (ret != I40E_SUCCESS)
1501 PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
1503 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1504 ret = i40e_aq_set_vsi_broadcast(hw, pf->vmdq[i].vsi->seid,
1506 if (ret != I40E_SUCCESS)
1507 PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
1510 /* Apply link configure */
1511 ret = i40e_apply_link_speed(dev);
1512 if (I40E_SUCCESS != ret) {
1513 PMD_DRV_LOG(ERR, "Fail to apply link setting");
1517 if (!rte_intr_allow_others(intr_handle)) {
1518 rte_intr_callback_unregister(intr_handle,
1519 i40e_dev_interrupt_handler,
1521 /* configure and enable device interrupt */
1522 i40e_pf_config_irq0(hw, FALSE);
1523 i40e_pf_enable_irq0(hw);
1525 if (dev->data->dev_conf.intr_conf.lsc != 0)
1526 PMD_INIT_LOG(INFO, "lsc won't enable because of"
1527 " no intr multiplex\n");
1530 /* enable uio intr after callback register */
1531 rte_intr_enable(intr_handle);
1533 return I40E_SUCCESS;
1536 i40e_dev_switch_queues(pf, FALSE);
1537 i40e_dev_clear_queues(dev);
1543 i40e_dev_stop(struct rte_eth_dev *dev)
1545 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1546 struct i40e_vsi *main_vsi = pf->main_vsi;
1547 struct i40e_mirror_rule *p_mirror;
1548 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1551 /* Disable all queues */
1552 i40e_dev_switch_queues(pf, FALSE);
1554 /* un-map queues with interrupt registers */
1555 i40e_vsi_disable_queues_intr(main_vsi);
1556 i40e_vsi_queues_unbind_intr(main_vsi);
1558 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1559 i40e_vsi_disable_queues_intr(pf->vmdq[i].vsi);
1560 i40e_vsi_queues_unbind_intr(pf->vmdq[i].vsi);
1563 if (pf->fdir.fdir_vsi) {
1564 i40e_vsi_queues_unbind_intr(pf->fdir.fdir_vsi);
1565 i40e_vsi_disable_queues_intr(pf->fdir.fdir_vsi);
1567 /* Clear all queues and release memory */
1568 i40e_dev_clear_queues(dev);
1571 i40e_dev_set_link_down(dev);
1573 /* Remove all mirror rules */
1574 while ((p_mirror = TAILQ_FIRST(&pf->mirror_list))) {
1575 TAILQ_REMOVE(&pf->mirror_list, p_mirror, rules);
1578 pf->nb_mirror_rule = 0;
1580 if (!rte_intr_allow_others(intr_handle))
1581 /* resume to the default handler */
1582 rte_intr_callback_register(intr_handle,
1583 i40e_dev_interrupt_handler,
1586 /* Clean datapath event and queue/vec mapping */
1587 rte_intr_efd_disable(intr_handle);
1588 if (intr_handle->intr_vec) {
1589 rte_free(intr_handle->intr_vec);
1590 intr_handle->intr_vec = NULL;
1595 i40e_dev_close(struct rte_eth_dev *dev)
1597 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1598 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1602 PMD_INIT_FUNC_TRACE();
1605 hw->adapter_stopped = 1;
1606 i40e_dev_free_queues(dev);
1608 /* Disable interrupt */
1609 i40e_pf_disable_irq0(hw);
1610 rte_intr_disable(&(dev->pci_dev->intr_handle));
1612 /* shutdown and destroy the HMC */
1613 i40e_shutdown_lan_hmc(hw);
1615 /* release all the existing VSIs and VEBs */
1616 i40e_fdir_teardown(pf);
1617 i40e_vsi_release(pf->main_vsi);
1619 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1620 i40e_vsi_release(pf->vmdq[i].vsi);
1621 pf->vmdq[i].vsi = NULL;
1627 /* shutdown the adminq */
1628 i40e_aq_queue_shutdown(hw, true);
1629 i40e_shutdown_adminq(hw);
1631 i40e_res_pool_destroy(&pf->qp_pool);
1632 i40e_res_pool_destroy(&pf->msix_pool);
1634 /* force a PF reset to clean anything leftover */
1635 reg = I40E_READ_REG(hw, I40E_PFGEN_CTRL);
1636 I40E_WRITE_REG(hw, I40E_PFGEN_CTRL,
1637 (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
1638 I40E_WRITE_FLUSH(hw);
1642 i40e_dev_promiscuous_enable(struct rte_eth_dev *dev)
1644 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1645 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1646 struct i40e_vsi *vsi = pf->main_vsi;
1649 status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
1651 if (status != I40E_SUCCESS)
1652 PMD_DRV_LOG(ERR, "Failed to enable unicast promiscuous");
1654 status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
1656 if (status != I40E_SUCCESS)
1657 PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
1662 i40e_dev_promiscuous_disable(struct rte_eth_dev *dev)
1664 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1665 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1666 struct i40e_vsi *vsi = pf->main_vsi;
1669 status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
1671 if (status != I40E_SUCCESS)
1672 PMD_DRV_LOG(ERR, "Failed to disable unicast promiscuous");
1674 status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
1676 if (status != I40E_SUCCESS)
1677 PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
1681 i40e_dev_allmulticast_enable(struct rte_eth_dev *dev)
1683 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1684 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1685 struct i40e_vsi *vsi = pf->main_vsi;
1688 ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid, TRUE, NULL);
1689 if (ret != I40E_SUCCESS)
1690 PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
1694 i40e_dev_allmulticast_disable(struct rte_eth_dev *dev)
1696 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1697 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1698 struct i40e_vsi *vsi = pf->main_vsi;
1701 if (dev->data->promiscuous == 1)
1702 return; /* must remain in all_multicast mode */
1704 ret = i40e_aq_set_vsi_multicast_promiscuous(hw,
1705 vsi->seid, FALSE, NULL);
1706 if (ret != I40E_SUCCESS)
1707 PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
1711 * Set device link up.
1714 i40e_dev_set_link_up(struct rte_eth_dev *dev)
1716 /* re-apply link speed setting */
1717 return i40e_apply_link_speed(dev);
1721 * Set device link down.
1724 i40e_dev_set_link_down(__rte_unused struct rte_eth_dev *dev)
1726 uint8_t speed = I40E_LINK_SPEED_UNKNOWN;
1727 uint8_t abilities = I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1728 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1730 return i40e_phy_conf_link(hw, abilities, speed);
1734 i40e_dev_link_update(struct rte_eth_dev *dev,
1735 int wait_to_complete)
1737 #define CHECK_INTERVAL 100 /* 100ms */
1738 #define MAX_REPEAT_TIME 10 /* 1s (10 * 100ms) in total */
1739 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1740 struct i40e_link_status link_status;
1741 struct rte_eth_link link, old;
1743 unsigned rep_cnt = MAX_REPEAT_TIME;
1745 memset(&link, 0, sizeof(link));
1746 memset(&old, 0, sizeof(old));
1747 memset(&link_status, 0, sizeof(link_status));
1748 rte_i40e_dev_atomic_read_link_status(dev, &old);
1751 /* Get link status information from hardware */
1752 status = i40e_aq_get_link_info(hw, false, &link_status, NULL);
1753 if (status != I40E_SUCCESS) {
1754 link.link_speed = ETH_LINK_SPEED_100;
1755 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1756 PMD_DRV_LOG(ERR, "Failed to get link info");
1760 link.link_status = link_status.link_info & I40E_AQ_LINK_UP;
1761 if (!wait_to_complete)
1764 rte_delay_ms(CHECK_INTERVAL);
1765 } while (!link.link_status && rep_cnt--);
1767 if (!link.link_status)
1770 /* i40e uses full duplex only */
1771 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1773 /* Parse the link status */
1774 switch (link_status.link_speed) {
1775 case I40E_LINK_SPEED_100MB:
1776 link.link_speed = ETH_LINK_SPEED_100;
1778 case I40E_LINK_SPEED_1GB:
1779 link.link_speed = ETH_LINK_SPEED_1000;
1781 case I40E_LINK_SPEED_10GB:
1782 link.link_speed = ETH_LINK_SPEED_10G;
1784 case I40E_LINK_SPEED_20GB:
1785 link.link_speed = ETH_LINK_SPEED_20G;
1787 case I40E_LINK_SPEED_40GB:
1788 link.link_speed = ETH_LINK_SPEED_40G;
1791 link.link_speed = ETH_LINK_SPEED_100;
1796 rte_i40e_dev_atomic_write_link_status(dev, &link);
1797 if (link.link_status == old.link_status)
1803 /* Get all the statistics of a VSI */
1805 i40e_update_vsi_stats(struct i40e_vsi *vsi)
1807 struct i40e_eth_stats *oes = &vsi->eth_stats_offset;
1808 struct i40e_eth_stats *nes = &vsi->eth_stats;
1809 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1810 int idx = rte_le_to_cpu_16(vsi->info.stat_counter_idx);
1812 i40e_stat_update_48(hw, I40E_GLV_GORCH(idx), I40E_GLV_GORCL(idx),
1813 vsi->offset_loaded, &oes->rx_bytes,
1815 i40e_stat_update_48(hw, I40E_GLV_UPRCH(idx), I40E_GLV_UPRCL(idx),
1816 vsi->offset_loaded, &oes->rx_unicast,
1818 i40e_stat_update_48(hw, I40E_GLV_MPRCH(idx), I40E_GLV_MPRCL(idx),
1819 vsi->offset_loaded, &oes->rx_multicast,
1820 &nes->rx_multicast);
1821 i40e_stat_update_48(hw, I40E_GLV_BPRCH(idx), I40E_GLV_BPRCL(idx),
1822 vsi->offset_loaded, &oes->rx_broadcast,
1823 &nes->rx_broadcast);
1824 i40e_stat_update_32(hw, I40E_GLV_RDPC(idx), vsi->offset_loaded,
1825 &oes->rx_discards, &nes->rx_discards);
1826 /* GLV_REPC not supported */
1827 /* GLV_RMPC not supported */
1828 i40e_stat_update_32(hw, I40E_GLV_RUPP(idx), vsi->offset_loaded,
1829 &oes->rx_unknown_protocol,
1830 &nes->rx_unknown_protocol);
1831 i40e_stat_update_48(hw, I40E_GLV_GOTCH(idx), I40E_GLV_GOTCL(idx),
1832 vsi->offset_loaded, &oes->tx_bytes,
1834 i40e_stat_update_48(hw, I40E_GLV_UPTCH(idx), I40E_GLV_UPTCL(idx),
1835 vsi->offset_loaded, &oes->tx_unicast,
1837 i40e_stat_update_48(hw, I40E_GLV_MPTCH(idx), I40E_GLV_MPTCL(idx),
1838 vsi->offset_loaded, &oes->tx_multicast,
1839 &nes->tx_multicast);
1840 i40e_stat_update_48(hw, I40E_GLV_BPTCH(idx), I40E_GLV_BPTCL(idx),
1841 vsi->offset_loaded, &oes->tx_broadcast,
1842 &nes->tx_broadcast);
1843 /* GLV_TDPC not supported */
1844 i40e_stat_update_32(hw, I40E_GLV_TEPC(idx), vsi->offset_loaded,
1845 &oes->tx_errors, &nes->tx_errors);
1846 vsi->offset_loaded = true;
1848 PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats start *******************",
1850 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", nes->rx_bytes);
1851 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", nes->rx_unicast);
1852 PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", nes->rx_multicast);
1853 PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", nes->rx_broadcast);
1854 PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", nes->rx_discards);
1855 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
1856 nes->rx_unknown_protocol);
1857 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", nes->tx_bytes);
1858 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", nes->tx_unicast);
1859 PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", nes->tx_multicast);
1860 PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", nes->tx_broadcast);
1861 PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", nes->tx_discards);
1862 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", nes->tx_errors);
1863 PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats end *******************",
1868 i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw)
1871 struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
1872 struct i40e_hw_port_stats *os = &pf->stats_offset; /* old stats */
1874 /* Get statistics of struct i40e_eth_stats */
1875 i40e_stat_update_48(hw, I40E_GLPRT_GORCH(hw->port),
1876 I40E_GLPRT_GORCL(hw->port),
1877 pf->offset_loaded, &os->eth.rx_bytes,
1879 i40e_stat_update_48(hw, I40E_GLPRT_UPRCH(hw->port),
1880 I40E_GLPRT_UPRCL(hw->port),
1881 pf->offset_loaded, &os->eth.rx_unicast,
1882 &ns->eth.rx_unicast);
1883 i40e_stat_update_48(hw, I40E_GLPRT_MPRCH(hw->port),
1884 I40E_GLPRT_MPRCL(hw->port),
1885 pf->offset_loaded, &os->eth.rx_multicast,
1886 &ns->eth.rx_multicast);
1887 i40e_stat_update_48(hw, I40E_GLPRT_BPRCH(hw->port),
1888 I40E_GLPRT_BPRCL(hw->port),
1889 pf->offset_loaded, &os->eth.rx_broadcast,
1890 &ns->eth.rx_broadcast);
1891 /* Workaround: CRC size should not be included in byte statistics,
1892 * so subtract ETHER_CRC_LEN from the byte counter for each rx packet.
1894 ns->eth.rx_bytes -= (ns->eth.rx_unicast + ns->eth.rx_multicast +
1895 ns->eth.rx_broadcast) * ETHER_CRC_LEN;
1897 i40e_stat_update_32(hw, I40E_GLPRT_RDPC(hw->port),
1898 pf->offset_loaded, &os->eth.rx_discards,
1899 &ns->eth.rx_discards);
1900 /* GLPRT_REPC not supported */
1901 /* GLPRT_RMPC not supported */
1902 i40e_stat_update_32(hw, I40E_GLPRT_RUPP(hw->port),
1904 &os->eth.rx_unknown_protocol,
1905 &ns->eth.rx_unknown_protocol);
1906 i40e_stat_update_48(hw, I40E_GLPRT_GOTCH(hw->port),
1907 I40E_GLPRT_GOTCL(hw->port),
1908 pf->offset_loaded, &os->eth.tx_bytes,
1910 i40e_stat_update_48(hw, I40E_GLPRT_UPTCH(hw->port),
1911 I40E_GLPRT_UPTCL(hw->port),
1912 pf->offset_loaded, &os->eth.tx_unicast,
1913 &ns->eth.tx_unicast);
1914 i40e_stat_update_48(hw, I40E_GLPRT_MPTCH(hw->port),
1915 I40E_GLPRT_MPTCL(hw->port),
1916 pf->offset_loaded, &os->eth.tx_multicast,
1917 &ns->eth.tx_multicast);
1918 i40e_stat_update_48(hw, I40E_GLPRT_BPTCH(hw->port),
1919 I40E_GLPRT_BPTCL(hw->port),
1920 pf->offset_loaded, &os->eth.tx_broadcast,
1921 &ns->eth.tx_broadcast);
1922 ns->eth.tx_bytes -= (ns->eth.tx_unicast + ns->eth.tx_multicast +
1923 ns->eth.tx_broadcast) * ETHER_CRC_LEN;
1924 /* GLPRT_TEPC not supported */
1926 /* additional port specific stats */
1927 i40e_stat_update_32(hw, I40E_GLPRT_TDOLD(hw->port),
1928 pf->offset_loaded, &os->tx_dropped_link_down,
1929 &ns->tx_dropped_link_down);
1930 i40e_stat_update_32(hw, I40E_GLPRT_CRCERRS(hw->port),
1931 pf->offset_loaded, &os->crc_errors,
1933 i40e_stat_update_32(hw, I40E_GLPRT_ILLERRC(hw->port),
1934 pf->offset_loaded, &os->illegal_bytes,
1935 &ns->illegal_bytes);
1936 /* GLPRT_ERRBC not supported */
1937 i40e_stat_update_32(hw, I40E_GLPRT_MLFC(hw->port),
1938 pf->offset_loaded, &os->mac_local_faults,
1939 &ns->mac_local_faults);
1940 i40e_stat_update_32(hw, I40E_GLPRT_MRFC(hw->port),
1941 pf->offset_loaded, &os->mac_remote_faults,
1942 &ns->mac_remote_faults);
1943 i40e_stat_update_32(hw, I40E_GLPRT_RLEC(hw->port),
1944 pf->offset_loaded, &os->rx_length_errors,
1945 &ns->rx_length_errors);
1946 i40e_stat_update_32(hw, I40E_GLPRT_LXONRXC(hw->port),
1947 pf->offset_loaded, &os->link_xon_rx,
1949 i40e_stat_update_32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
1950 pf->offset_loaded, &os->link_xoff_rx,
1952 for (i = 0; i < 8; i++) {
1953 i40e_stat_update_32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
1955 &os->priority_xon_rx[i],
1956 &ns->priority_xon_rx[i]);
1957 i40e_stat_update_32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
1959 &os->priority_xoff_rx[i],
1960 &ns->priority_xoff_rx[i]);
1962 i40e_stat_update_32(hw, I40E_GLPRT_LXONTXC(hw->port),
1963 pf->offset_loaded, &os->link_xon_tx,
1965 i40e_stat_update_32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
1966 pf->offset_loaded, &os->link_xoff_tx,
1968 for (i = 0; i < 8; i++) {
1969 i40e_stat_update_32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
1971 &os->priority_xon_tx[i],
1972 &ns->priority_xon_tx[i]);
1973 i40e_stat_update_32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
1975 &os->priority_xoff_tx[i],
1976 &ns->priority_xoff_tx[i]);
1977 i40e_stat_update_32(hw, I40E_GLPRT_RXON2OFFCNT(hw->port, i),
1979 &os->priority_xon_2_xoff[i],
1980 &ns->priority_xon_2_xoff[i]);
1982 i40e_stat_update_48(hw, I40E_GLPRT_PRC64H(hw->port),
1983 I40E_GLPRT_PRC64L(hw->port),
1984 pf->offset_loaded, &os->rx_size_64,
1986 i40e_stat_update_48(hw, I40E_GLPRT_PRC127H(hw->port),
1987 I40E_GLPRT_PRC127L(hw->port),
1988 pf->offset_loaded, &os->rx_size_127,
1990 i40e_stat_update_48(hw, I40E_GLPRT_PRC255H(hw->port),
1991 I40E_GLPRT_PRC255L(hw->port),
1992 pf->offset_loaded, &os->rx_size_255,
1994 i40e_stat_update_48(hw, I40E_GLPRT_PRC511H(hw->port),
1995 I40E_GLPRT_PRC511L(hw->port),
1996 pf->offset_loaded, &os->rx_size_511,
1998 i40e_stat_update_48(hw, I40E_GLPRT_PRC1023H(hw->port),
1999 I40E_GLPRT_PRC1023L(hw->port),
2000 pf->offset_loaded, &os->rx_size_1023,
2002 i40e_stat_update_48(hw, I40E_GLPRT_PRC1522H(hw->port),
2003 I40E_GLPRT_PRC1522L(hw->port),
2004 pf->offset_loaded, &os->rx_size_1522,
2006 i40e_stat_update_48(hw, I40E_GLPRT_PRC9522H(hw->port),
2007 I40E_GLPRT_PRC9522L(hw->port),
2008 pf->offset_loaded, &os->rx_size_big,
2010 i40e_stat_update_32(hw, I40E_GLPRT_RUC(hw->port),
2011 pf->offset_loaded, &os->rx_undersize,
2013 i40e_stat_update_32(hw, I40E_GLPRT_RFC(hw->port),
2014 pf->offset_loaded, &os->rx_fragments,
2016 i40e_stat_update_32(hw, I40E_GLPRT_ROC(hw->port),
2017 pf->offset_loaded, &os->rx_oversize,
2019 i40e_stat_update_32(hw, I40E_GLPRT_RJC(hw->port),
2020 pf->offset_loaded, &os->rx_jabber,
2022 i40e_stat_update_48(hw, I40E_GLPRT_PTC64H(hw->port),
2023 I40E_GLPRT_PTC64L(hw->port),
2024 pf->offset_loaded, &os->tx_size_64,
2026 i40e_stat_update_48(hw, I40E_GLPRT_PTC127H(hw->port),
2027 I40E_GLPRT_PTC127L(hw->port),
2028 pf->offset_loaded, &os->tx_size_127,
2030 i40e_stat_update_48(hw, I40E_GLPRT_PTC255H(hw->port),
2031 I40E_GLPRT_PTC255L(hw->port),
2032 pf->offset_loaded, &os->tx_size_255,
2034 i40e_stat_update_48(hw, I40E_GLPRT_PTC511H(hw->port),
2035 I40E_GLPRT_PTC511L(hw->port),
2036 pf->offset_loaded, &os->tx_size_511,
2038 i40e_stat_update_48(hw, I40E_GLPRT_PTC1023H(hw->port),
2039 I40E_GLPRT_PTC1023L(hw->port),
2040 pf->offset_loaded, &os->tx_size_1023,
2042 i40e_stat_update_48(hw, I40E_GLPRT_PTC1522H(hw->port),
2043 I40E_GLPRT_PTC1522L(hw->port),
2044 pf->offset_loaded, &os->tx_size_1522,
2046 i40e_stat_update_48(hw, I40E_GLPRT_PTC9522H(hw->port),
2047 I40E_GLPRT_PTC9522L(hw->port),
2048 pf->offset_loaded, &os->tx_size_big,
2050 i40e_stat_update_32(hw, I40E_GLQF_PCNT(pf->fdir.match_counter_index),
2052 &os->fd_sb_match, &ns->fd_sb_match);
2053 /* GLPRT_MSPDC not supported */
2054 /* GLPRT_XEC not supported */
2056 pf->offset_loaded = true;
2059 i40e_update_vsi_stats(pf->main_vsi);
2062 /* Get all statistics of a port */
2064 i40e_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
2066 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2067 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2068 struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
2071 /* call read registers - updates values, now write them to struct */
2072 i40e_read_stats_registers(pf, hw);
2074 stats->ipackets = pf->main_vsi->eth_stats.rx_unicast +
2075 pf->main_vsi->eth_stats.rx_multicast +
2076 pf->main_vsi->eth_stats.rx_broadcast -
2077 pf->main_vsi->eth_stats.rx_discards;
2078 stats->opackets = pf->main_vsi->eth_stats.tx_unicast +
2079 pf->main_vsi->eth_stats.tx_multicast +
2080 pf->main_vsi->eth_stats.tx_broadcast;
2081 stats->ibytes = ns->eth.rx_bytes;
2082 stats->obytes = ns->eth.tx_bytes;
2083 stats->oerrors = ns->eth.tx_errors +
2084 pf->main_vsi->eth_stats.tx_errors;
2085 stats->imcasts = pf->main_vsi->eth_stats.rx_multicast;
2088 stats->imissed = ns->eth.rx_discards +
2089 pf->main_vsi->eth_stats.rx_discards;
2090 stats->ierrors = ns->crc_errors +
2091 ns->rx_length_errors + ns->rx_undersize +
2092 ns->rx_oversize + ns->rx_fragments + ns->rx_jabber +
2095 PMD_DRV_LOG(DEBUG, "***************** PF stats start *******************");
2096 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", ns->eth.rx_bytes);
2097 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", ns->eth.rx_unicast);
2098 PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", ns->eth.rx_multicast);
2099 PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", ns->eth.rx_broadcast);
2100 PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", ns->eth.rx_discards);
2101 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
2102 ns->eth.rx_unknown_protocol);
2103 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", ns->eth.tx_bytes);
2104 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", ns->eth.tx_unicast);
2105 PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", ns->eth.tx_multicast);
2106 PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", ns->eth.tx_broadcast);
2107 PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", ns->eth.tx_discards);
2108 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", ns->eth.tx_errors);
2110 PMD_DRV_LOG(DEBUG, "tx_dropped_link_down: %"PRIu64"",
2111 ns->tx_dropped_link_down);
2112 PMD_DRV_LOG(DEBUG, "crc_errors: %"PRIu64"", ns->crc_errors);
2113 PMD_DRV_LOG(DEBUG, "illegal_bytes: %"PRIu64"",
2115 PMD_DRV_LOG(DEBUG, "error_bytes: %"PRIu64"", ns->error_bytes);
2116 PMD_DRV_LOG(DEBUG, "mac_local_faults: %"PRIu64"",
2117 ns->mac_local_faults);
2118 PMD_DRV_LOG(DEBUG, "mac_remote_faults: %"PRIu64"",
2119 ns->mac_remote_faults);
2120 PMD_DRV_LOG(DEBUG, "rx_length_errors: %"PRIu64"",
2121 ns->rx_length_errors);
2122 PMD_DRV_LOG(DEBUG, "link_xon_rx: %"PRIu64"", ns->link_xon_rx);
2123 PMD_DRV_LOG(DEBUG, "link_xoff_rx: %"PRIu64"", ns->link_xoff_rx);
2124 for (i = 0; i < 8; i++) {
2125 PMD_DRV_LOG(DEBUG, "priority_xon_rx[%d]: %"PRIu64"",
2126 i, ns->priority_xon_rx[i]);
2127 PMD_DRV_LOG(DEBUG, "priority_xoff_rx[%d]: %"PRIu64"",
2128 i, ns->priority_xoff_rx[i]);
2130 PMD_DRV_LOG(DEBUG, "link_xon_tx: %"PRIu64"", ns->link_xon_tx);
2131 PMD_DRV_LOG(DEBUG, "link_xoff_tx: %"PRIu64"", ns->link_xoff_tx);
2132 for (i = 0; i < 8; i++) {
2133 PMD_DRV_LOG(DEBUG, "priority_xon_tx[%d]: %"PRIu64"",
2134 i, ns->priority_xon_tx[i]);
2135 PMD_DRV_LOG(DEBUG, "priority_xoff_tx[%d]: %"PRIu64"",
2136 i, ns->priority_xoff_tx[i]);
2137 PMD_DRV_LOG(DEBUG, "priority_xon_2_xoff[%d]: %"PRIu64"",
2138 i, ns->priority_xon_2_xoff[i]);
2140 PMD_DRV_LOG(DEBUG, "rx_size_64: %"PRIu64"", ns->rx_size_64);
2141 PMD_DRV_LOG(DEBUG, "rx_size_127: %"PRIu64"", ns->rx_size_127);
2142 PMD_DRV_LOG(DEBUG, "rx_size_255: %"PRIu64"", ns->rx_size_255);
2143 PMD_DRV_LOG(DEBUG, "rx_size_511: %"PRIu64"", ns->rx_size_511);
2144 PMD_DRV_LOG(DEBUG, "rx_size_1023: %"PRIu64"", ns->rx_size_1023);
2145 PMD_DRV_LOG(DEBUG, "rx_size_1522: %"PRIu64"", ns->rx_size_1522);
2146 PMD_DRV_LOG(DEBUG, "rx_size_big: %"PRIu64"", ns->rx_size_big);
2147 PMD_DRV_LOG(DEBUG, "rx_undersize: %"PRIu64"", ns->rx_undersize);
2148 PMD_DRV_LOG(DEBUG, "rx_fragments: %"PRIu64"", ns->rx_fragments);
2149 PMD_DRV_LOG(DEBUG, "rx_oversize: %"PRIu64"", ns->rx_oversize);
2150 PMD_DRV_LOG(DEBUG, "rx_jabber: %"PRIu64"", ns->rx_jabber);
2151 PMD_DRV_LOG(DEBUG, "tx_size_64: %"PRIu64"", ns->tx_size_64);
2152 PMD_DRV_LOG(DEBUG, "tx_size_127: %"PRIu64"", ns->tx_size_127);
2153 PMD_DRV_LOG(DEBUG, "tx_size_255: %"PRIu64"", ns->tx_size_255);
2154 PMD_DRV_LOG(DEBUG, "tx_size_511: %"PRIu64"", ns->tx_size_511);
2155 PMD_DRV_LOG(DEBUG, "tx_size_1023: %"PRIu64"", ns->tx_size_1023);
2156 PMD_DRV_LOG(DEBUG, "tx_size_1522: %"PRIu64"", ns->tx_size_1522);
2157 PMD_DRV_LOG(DEBUG, "tx_size_big: %"PRIu64"", ns->tx_size_big);
2158 PMD_DRV_LOG(DEBUG, "mac_short_packet_dropped: %"PRIu64"",
2159 ns->mac_short_packet_dropped);
2160 PMD_DRV_LOG(DEBUG, "checksum_error: %"PRIu64"",
2161 ns->checksum_error);
2162 PMD_DRV_LOG(DEBUG, "fdir_match: %"PRIu64"", ns->fd_sb_match);
2163 PMD_DRV_LOG(DEBUG, "***************** PF stats end ********************");
2166 /* Reset the statistics */
2168 i40e_dev_stats_reset(struct rte_eth_dev *dev)
2170 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2171 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2173 /* Mark PF and VSI stats to update the offset, aka "reset" */
2174 pf->offset_loaded = false;
2176 pf->main_vsi->offset_loaded = false;
2178 /* read the stats, reading current register values into offset */
2179 i40e_read_stats_registers(pf, hw);
2183 i40e_xstats_calc_num(void)
2185 return I40E_NB_ETH_XSTATS + I40E_NB_HW_PORT_XSTATS +
2186 (I40E_NB_RXQ_PRIO_XSTATS * 8) +
2187 (I40E_NB_TXQ_PRIO_XSTATS * 8);
2191 i40e_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstats *xstats,
2194 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2195 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2196 unsigned i, count, prio;
2197 struct i40e_hw_port_stats *hw_stats = &pf->stats;
2199 count = i40e_xstats_calc_num();
2203 i40e_read_stats_registers(pf, hw);
2210 /* Get stats from i40e_eth_stats struct */
2211 for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
2212 snprintf(xstats[count].name, sizeof(xstats[count].name),
2213 "%s", rte_i40e_stats_strings[i].name);
2214 xstats[count].value = *(uint64_t *)(((char *)&hw_stats->eth) +
2215 rte_i40e_stats_strings[i].offset);
2219 /* Get individiual stats from i40e_hw_port struct */
2220 for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
2221 snprintf(xstats[count].name, sizeof(xstats[count].name),
2222 "%s", rte_i40e_hw_port_strings[i].name);
2223 xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
2224 rte_i40e_hw_port_strings[i].offset);
2228 for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
2229 for (prio = 0; prio < 8; prio++) {
2230 snprintf(xstats[count].name,
2231 sizeof(xstats[count].name),
2232 "rx_priority%u_%s", prio,
2233 rte_i40e_rxq_prio_strings[i].name);
2234 xstats[count].value =
2235 *(uint64_t *)(((char *)hw_stats) +
2236 rte_i40e_rxq_prio_strings[i].offset +
2237 (sizeof(uint64_t) * prio));
2242 for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
2243 for (prio = 0; prio < 8; prio++) {
2244 snprintf(xstats[count].name,
2245 sizeof(xstats[count].name),
2246 "tx_priority%u_%s", prio,
2247 rte_i40e_txq_prio_strings[i].name);
2248 xstats[count].value =
2249 *(uint64_t *)(((char *)hw_stats) +
2250 rte_i40e_txq_prio_strings[i].offset +
2251 (sizeof(uint64_t) * prio));
2260 i40e_dev_queue_stats_mapping_set(__rte_unused struct rte_eth_dev *dev,
2261 __rte_unused uint16_t queue_id,
2262 __rte_unused uint8_t stat_idx,
2263 __rte_unused uint8_t is_rx)
2265 PMD_INIT_FUNC_TRACE();
2271 i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2273 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2274 struct i40e_vsi *vsi = pf->main_vsi;
2276 dev_info->max_rx_queues = vsi->nb_qps;
2277 dev_info->max_tx_queues = vsi->nb_qps;
2278 dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
2279 dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
2280 dev_info->max_mac_addrs = vsi->max_macaddrs;
2281 dev_info->max_vfs = dev->pci_dev->max_vfs;
2282 dev_info->rx_offload_capa =
2283 DEV_RX_OFFLOAD_VLAN_STRIP |
2284 DEV_RX_OFFLOAD_QINQ_STRIP |
2285 DEV_RX_OFFLOAD_IPV4_CKSUM |
2286 DEV_RX_OFFLOAD_UDP_CKSUM |
2287 DEV_RX_OFFLOAD_TCP_CKSUM;
2288 dev_info->tx_offload_capa =
2289 DEV_TX_OFFLOAD_VLAN_INSERT |
2290 DEV_TX_OFFLOAD_QINQ_INSERT |
2291 DEV_TX_OFFLOAD_IPV4_CKSUM |
2292 DEV_TX_OFFLOAD_UDP_CKSUM |
2293 DEV_TX_OFFLOAD_TCP_CKSUM |
2294 DEV_TX_OFFLOAD_SCTP_CKSUM |
2295 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
2296 DEV_TX_OFFLOAD_TCP_TSO;
2297 dev_info->hash_key_size = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
2299 dev_info->reta_size = pf->hash_lut_size;
2300 dev_info->flow_type_rss_offloads = I40E_RSS_OFFLOAD_ALL;
2302 dev_info->default_rxconf = (struct rte_eth_rxconf) {
2304 .pthresh = I40E_DEFAULT_RX_PTHRESH,
2305 .hthresh = I40E_DEFAULT_RX_HTHRESH,
2306 .wthresh = I40E_DEFAULT_RX_WTHRESH,
2308 .rx_free_thresh = I40E_DEFAULT_RX_FREE_THRESH,
2312 dev_info->default_txconf = (struct rte_eth_txconf) {
2314 .pthresh = I40E_DEFAULT_TX_PTHRESH,
2315 .hthresh = I40E_DEFAULT_TX_HTHRESH,
2316 .wthresh = I40E_DEFAULT_TX_WTHRESH,
2318 .tx_free_thresh = I40E_DEFAULT_TX_FREE_THRESH,
2319 .tx_rs_thresh = I40E_DEFAULT_TX_RSBIT_THRESH,
2320 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
2321 ETH_TXQ_FLAGS_NOOFFLOADS,
2324 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
2325 .nb_max = I40E_MAX_RING_DESC,
2326 .nb_min = I40E_MIN_RING_DESC,
2327 .nb_align = I40E_ALIGN_RING_DESC,
2330 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
2331 .nb_max = I40E_MAX_RING_DESC,
2332 .nb_min = I40E_MIN_RING_DESC,
2333 .nb_align = I40E_ALIGN_RING_DESC,
2336 if (pf->flags & I40E_FLAG_VMDQ) {
2337 dev_info->max_vmdq_pools = pf->max_nb_vmdq_vsi;
2338 dev_info->vmdq_queue_base = dev_info->max_rx_queues;
2339 dev_info->vmdq_queue_num = pf->vmdq_nb_qps *
2340 pf->max_nb_vmdq_vsi;
2341 dev_info->vmdq_pool_base = I40E_VMDQ_POOL_BASE;
2342 dev_info->max_rx_queues += dev_info->vmdq_queue_num;
2343 dev_info->max_tx_queues += dev_info->vmdq_queue_num;
2348 i40e_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
2350 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2351 struct i40e_vsi *vsi = pf->main_vsi;
2352 PMD_INIT_FUNC_TRACE();
2355 return i40e_vsi_add_vlan(vsi, vlan_id);
2357 return i40e_vsi_delete_vlan(vsi, vlan_id);
2361 i40e_vlan_tpid_set(__rte_unused struct rte_eth_dev *dev,
2362 __rte_unused uint16_t tpid)
2364 PMD_INIT_FUNC_TRACE();
2368 i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask)
2370 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2371 struct i40e_vsi *vsi = pf->main_vsi;
2373 if (mask & ETH_VLAN_STRIP_MASK) {
2374 /* Enable or disable VLAN stripping */
2375 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
2376 i40e_vsi_config_vlan_stripping(vsi, TRUE);
2378 i40e_vsi_config_vlan_stripping(vsi, FALSE);
2381 if (mask & ETH_VLAN_EXTEND_MASK) {
2382 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
2383 i40e_vsi_config_double_vlan(vsi, TRUE);
2385 i40e_vsi_config_double_vlan(vsi, FALSE);
2390 i40e_vlan_strip_queue_set(__rte_unused struct rte_eth_dev *dev,
2391 __rte_unused uint16_t queue,
2392 __rte_unused int on)
2394 PMD_INIT_FUNC_TRACE();
2398 i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
2400 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2401 struct i40e_vsi *vsi = pf->main_vsi;
2402 struct rte_eth_dev_data *data = I40E_VSI_TO_DEV_DATA(vsi);
2403 struct i40e_vsi_vlan_pvid_info info;
2405 memset(&info, 0, sizeof(info));
2408 info.config.pvid = pvid;
2410 info.config.reject.tagged =
2411 data->dev_conf.txmode.hw_vlan_reject_tagged;
2412 info.config.reject.untagged =
2413 data->dev_conf.txmode.hw_vlan_reject_untagged;
2416 return i40e_vsi_vlan_pvid_set(vsi, &info);
2420 i40e_dev_led_on(struct rte_eth_dev *dev)
2422 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2423 uint32_t mode = i40e_led_get(hw);
2426 i40e_led_set(hw, 0xf, true); /* 0xf means led always true */
2432 i40e_dev_led_off(struct rte_eth_dev *dev)
2434 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2435 uint32_t mode = i40e_led_get(hw);
2438 i40e_led_set(hw, 0, false);
2444 i40e_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2446 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2447 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2449 fc_conf->pause_time = pf->fc_conf.pause_time;
2450 fc_conf->high_water = pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS];
2451 fc_conf->low_water = pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS];
2453 /* Return current mode according to actual setting*/
2454 switch (hw->fc.current_mode) {
2456 fc_conf->mode = RTE_FC_FULL;
2458 case I40E_FC_TX_PAUSE:
2459 fc_conf->mode = RTE_FC_TX_PAUSE;
2461 case I40E_FC_RX_PAUSE:
2462 fc_conf->mode = RTE_FC_RX_PAUSE;
2466 fc_conf->mode = RTE_FC_NONE;
2473 i40e_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2475 uint32_t mflcn_reg, fctrl_reg, reg;
2476 uint32_t max_high_water;
2477 uint8_t i, aq_failure;
2481 enum i40e_fc_mode rte_fcmode_2_i40e_fcmode[] = {
2482 [RTE_FC_NONE] = I40E_FC_NONE,
2483 [RTE_FC_RX_PAUSE] = I40E_FC_RX_PAUSE,
2484 [RTE_FC_TX_PAUSE] = I40E_FC_TX_PAUSE,
2485 [RTE_FC_FULL] = I40E_FC_FULL
2488 /* high_water field in the rte_eth_fc_conf using the kilobytes unit */
2490 max_high_water = I40E_RXPBSIZE >> I40E_KILOSHIFT;
2491 if ((fc_conf->high_water > max_high_water) ||
2492 (fc_conf->high_water < fc_conf->low_water)) {
2493 PMD_INIT_LOG(ERR, "Invalid high/low water setup value in KB, "
2494 "High_water must <= %d.", max_high_water);
2498 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2499 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2500 hw->fc.requested_mode = rte_fcmode_2_i40e_fcmode[fc_conf->mode];
2502 pf->fc_conf.pause_time = fc_conf->pause_time;
2503 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->high_water;
2504 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->low_water;
2506 PMD_INIT_FUNC_TRACE();
2508 /* All the link flow control related enable/disable register
2509 * configuration is handle by the F/W
2511 err = i40e_set_fc(hw, &aq_failure, true);
2515 if (i40e_is_40G_device(hw->device_id)) {
2516 /* Configure flow control refresh threshold,
2517 * the value for stat_tx_pause_refresh_timer[8]
2518 * is used for global pause operation.
2522 I40E_PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER(8),
2523 pf->fc_conf.pause_time);
2525 /* configure the timer value included in transmitted pause
2527 * the value for stat_tx_pause_quanta[8] is used for global
2530 I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA(8),
2531 pf->fc_conf.pause_time);
2533 fctrl_reg = I40E_READ_REG(hw,
2534 I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL);
2536 if (fc_conf->mac_ctrl_frame_fwd != 0)
2537 fctrl_reg |= I40E_PRTMAC_FWD_CTRL;
2539 fctrl_reg &= ~I40E_PRTMAC_FWD_CTRL;
2541 I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL,
2544 /* Configure pause time (2 TCs per register) */
2545 reg = (uint32_t)pf->fc_conf.pause_time * (uint32_t)0x00010001;
2546 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS / 2; i++)
2547 I40E_WRITE_REG(hw, I40E_PRTDCB_FCTTVN(i), reg);
2549 /* Configure flow control refresh threshold value */
2550 I40E_WRITE_REG(hw, I40E_PRTDCB_FCRTV,
2551 pf->fc_conf.pause_time / 2);
2553 mflcn_reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
2555 /* set or clear MFLCN.PMCF & MFLCN.DPF bits
2556 *depending on configuration
2558 if (fc_conf->mac_ctrl_frame_fwd != 0) {
2559 mflcn_reg |= I40E_PRTDCB_MFLCN_PMCF_MASK;
2560 mflcn_reg &= ~I40E_PRTDCB_MFLCN_DPF_MASK;
2562 mflcn_reg &= ~I40E_PRTDCB_MFLCN_PMCF_MASK;
2563 mflcn_reg |= I40E_PRTDCB_MFLCN_DPF_MASK;
2566 I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, mflcn_reg);
2569 /* config the water marker both based on the packets and bytes */
2570 I40E_WRITE_REG(hw, I40E_GLRPB_PHW,
2571 (pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
2572 << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
2573 I40E_WRITE_REG(hw, I40E_GLRPB_PLW,
2574 (pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
2575 << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
2576 I40E_WRITE_REG(hw, I40E_GLRPB_GHW,
2577 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
2579 I40E_WRITE_REG(hw, I40E_GLRPB_GLW,
2580 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
2583 I40E_WRITE_FLUSH(hw);
2589 i40e_priority_flow_ctrl_set(__rte_unused struct rte_eth_dev *dev,
2590 __rte_unused struct rte_eth_pfc_conf *pfc_conf)
2592 PMD_INIT_FUNC_TRACE();
2597 /* Add a MAC address, and update filters */
2599 i40e_macaddr_add(struct rte_eth_dev *dev,
2600 struct ether_addr *mac_addr,
2601 __rte_unused uint32_t index,
2604 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2605 struct i40e_mac_filter_info mac_filter;
2606 struct i40e_vsi *vsi;
2609 /* If VMDQ not enabled or configured, return */
2610 if (pool != 0 && (!(pf->flags | I40E_FLAG_VMDQ) || !pf->nb_cfg_vmdq_vsi)) {
2611 PMD_DRV_LOG(ERR, "VMDQ not %s, can't set mac to pool %u",
2612 pf->flags | I40E_FLAG_VMDQ ? "configured" : "enabled",
2617 if (pool > pf->nb_cfg_vmdq_vsi) {
2618 PMD_DRV_LOG(ERR, "Pool number %u invalid. Max pool is %u",
2619 pool, pf->nb_cfg_vmdq_vsi);
2623 (void)rte_memcpy(&mac_filter.mac_addr, mac_addr, ETHER_ADDR_LEN);
2624 mac_filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
2629 vsi = pf->vmdq[pool - 1].vsi;
2631 ret = i40e_vsi_add_mac(vsi, &mac_filter);
2632 if (ret != I40E_SUCCESS) {
2633 PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
2638 /* Remove a MAC address, and update filters */
2640 i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
2642 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2643 struct i40e_vsi *vsi;
2644 struct rte_eth_dev_data *data = dev->data;
2645 struct ether_addr *macaddr;
2650 macaddr = &(data->mac_addrs[index]);
2652 pool_sel = dev->data->mac_pool_sel[index];
2654 for (i = 0; i < sizeof(pool_sel) * CHAR_BIT; i++) {
2655 if (pool_sel & (1ULL << i)) {
2659 /* No VMDQ pool enabled or configured */
2660 if (!(pf->flags | I40E_FLAG_VMDQ) ||
2661 (i > pf->nb_cfg_vmdq_vsi)) {
2662 PMD_DRV_LOG(ERR, "No VMDQ pool enabled"
2666 vsi = pf->vmdq[i - 1].vsi;
2668 ret = i40e_vsi_delete_mac(vsi, macaddr);
2671 PMD_DRV_LOG(ERR, "Failed to remove MACVLAN filter");
2678 /* Set perfect match or hash match of MAC and VLAN for a VF */
2680 i40e_vf_mac_filter_set(struct i40e_pf *pf,
2681 struct rte_eth_mac_filter *filter,
2685 struct i40e_mac_filter_info mac_filter;
2686 struct ether_addr old_mac;
2687 struct ether_addr *new_mac;
2688 struct i40e_pf_vf *vf = NULL;
2693 PMD_DRV_LOG(ERR, "Invalid PF argument.");
2696 hw = I40E_PF_TO_HW(pf);
2698 if (filter == NULL) {
2699 PMD_DRV_LOG(ERR, "Invalid mac filter argument.");
2703 new_mac = &filter->mac_addr;
2705 if (is_zero_ether_addr(new_mac)) {
2706 PMD_DRV_LOG(ERR, "Invalid ethernet address.");
2710 vf_id = filter->dst_id;
2712 if (vf_id > pf->vf_num - 1 || !pf->vfs) {
2713 PMD_DRV_LOG(ERR, "Invalid argument.");
2716 vf = &pf->vfs[vf_id];
2718 if (add && is_same_ether_addr(new_mac, &(pf->dev_addr))) {
2719 PMD_DRV_LOG(INFO, "Ignore adding permanent MAC address.");
2724 (void)rte_memcpy(&old_mac, hw->mac.addr, ETHER_ADDR_LEN);
2725 (void)rte_memcpy(hw->mac.addr, new_mac->addr_bytes,
2727 (void)rte_memcpy(&mac_filter.mac_addr, &filter->mac_addr,
2730 mac_filter.filter_type = filter->filter_type;
2731 ret = i40e_vsi_add_mac(vf->vsi, &mac_filter);
2732 if (ret != I40E_SUCCESS) {
2733 PMD_DRV_LOG(ERR, "Failed to add MAC filter.");
2736 ether_addr_copy(new_mac, &pf->dev_addr);
2738 (void)rte_memcpy(hw->mac.addr, hw->mac.perm_addr,
2740 ret = i40e_vsi_delete_mac(vf->vsi, &filter->mac_addr);
2741 if (ret != I40E_SUCCESS) {
2742 PMD_DRV_LOG(ERR, "Failed to delete MAC filter.");
2746 /* Clear device address as it has been removed */
2747 if (is_same_ether_addr(&(pf->dev_addr), new_mac))
2748 memset(&pf->dev_addr, 0, sizeof(struct ether_addr));
2754 /* MAC filter handle */
2756 i40e_mac_filter_handle(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
2759 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2760 struct rte_eth_mac_filter *filter;
2761 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
2762 int ret = I40E_NOT_SUPPORTED;
2764 filter = (struct rte_eth_mac_filter *)(arg);
2766 switch (filter_op) {
2767 case RTE_ETH_FILTER_NOP:
2770 case RTE_ETH_FILTER_ADD:
2771 i40e_pf_disable_irq0(hw);
2773 ret = i40e_vf_mac_filter_set(pf, filter, 1);
2774 i40e_pf_enable_irq0(hw);
2776 case RTE_ETH_FILTER_DELETE:
2777 i40e_pf_disable_irq0(hw);
2779 ret = i40e_vf_mac_filter_set(pf, filter, 0);
2780 i40e_pf_enable_irq0(hw);
2783 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
2784 ret = I40E_ERR_PARAM;
2792 i40e_get_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
2794 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2795 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2801 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
2802 ret = i40e_aq_get_rss_lut(hw, vsi->vsi_id, TRUE,
2805 PMD_DRV_LOG(ERR, "Failed to get RSS lookup table");
2809 uint32_t *lut_dw = (uint32_t *)lut;
2810 uint16_t i, lut_size_dw = lut_size / 4;
2812 for (i = 0; i < lut_size_dw; i++)
2813 lut_dw[i] = I40E_READ_REG(hw, I40E_PFQF_HLUT(i));
2820 i40e_set_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
2822 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2823 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2829 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
2830 ret = i40e_aq_set_rss_lut(hw, vsi->vsi_id, TRUE,
2833 PMD_DRV_LOG(ERR, "Failed to set RSS lookup table");
2837 uint32_t *lut_dw = (uint32_t *)lut;
2838 uint16_t i, lut_size_dw = lut_size / 4;
2840 for (i = 0; i < lut_size_dw; i++)
2841 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
2842 I40E_WRITE_FLUSH(hw);
2849 i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
2850 struct rte_eth_rss_reta_entry64 *reta_conf,
2853 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2854 uint16_t i, lut_size = pf->hash_lut_size;
2855 uint16_t idx, shift;
2859 if (reta_size != lut_size ||
2860 reta_size > ETH_RSS_RETA_SIZE_512) {
2861 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2862 "(%d) doesn't match the number hardware can supported "
2863 "(%d)\n", reta_size, lut_size);
2867 lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
2869 PMD_DRV_LOG(ERR, "No memory can be allocated");
2872 ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
2875 for (i = 0; i < reta_size; i++) {
2876 idx = i / RTE_RETA_GROUP_SIZE;
2877 shift = i % RTE_RETA_GROUP_SIZE;
2878 if (reta_conf[idx].mask & (1ULL << shift))
2879 lut[i] = reta_conf[idx].reta[shift];
2881 ret = i40e_set_rss_lut(pf->main_vsi, lut, reta_size);
2890 i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
2891 struct rte_eth_rss_reta_entry64 *reta_conf,
2894 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2895 uint16_t i, lut_size = pf->hash_lut_size;
2896 uint16_t idx, shift;
2900 if (reta_size != lut_size ||
2901 reta_size > ETH_RSS_RETA_SIZE_512) {
2902 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2903 "(%d) doesn't match the number hardware can supported "
2904 "(%d)\n", reta_size, lut_size);
2908 lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
2910 PMD_DRV_LOG(ERR, "No memory can be allocated");
2914 ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
2917 for (i = 0; i < reta_size; i++) {
2918 idx = i / RTE_RETA_GROUP_SIZE;
2919 shift = i % RTE_RETA_GROUP_SIZE;
2920 if (reta_conf[idx].mask & (1ULL << shift))
2921 reta_conf[idx].reta[shift] = lut[i];
2931 * i40e_allocate_dma_mem_d - specific memory alloc for shared code (base driver)
2932 * @hw: pointer to the HW structure
2933 * @mem: pointer to mem struct to fill out
2934 * @size: size of memory requested
2935 * @alignment: what to align the allocation to
2937 enum i40e_status_code
2938 i40e_allocate_dma_mem_d(__attribute__((unused)) struct i40e_hw *hw,
2939 struct i40e_dma_mem *mem,
2943 const struct rte_memzone *mz = NULL;
2944 char z_name[RTE_MEMZONE_NAMESIZE];
2947 return I40E_ERR_PARAM;
2949 snprintf(z_name, sizeof(z_name), "i40e_dma_%"PRIu64, rte_rand());
2950 mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY, 0,
2951 alignment, RTE_PGSIZE_2M);
2953 return I40E_ERR_NO_MEMORY;
2957 mem->pa = rte_mem_phy2mch(mz->memseg_id, mz->phys_addr);
2958 mem->zone = (const void *)mz;
2959 PMD_DRV_LOG(DEBUG, "memzone %s allocated with physical address: "
2960 "%"PRIu64, mz->name, mem->pa);
2962 return I40E_SUCCESS;
2966 * i40e_free_dma_mem_d - specific memory free for shared code (base driver)
2967 * @hw: pointer to the HW structure
2968 * @mem: ptr to mem struct to free
2970 enum i40e_status_code
2971 i40e_free_dma_mem_d(__attribute__((unused)) struct i40e_hw *hw,
2972 struct i40e_dma_mem *mem)
2975 return I40E_ERR_PARAM;
2977 PMD_DRV_LOG(DEBUG, "memzone %s to be freed with physical address: "
2978 "%"PRIu64, ((const struct rte_memzone *)mem->zone)->name,
2980 rte_memzone_free((const struct rte_memzone *)mem->zone);
2985 return I40E_SUCCESS;
2989 * i40e_allocate_virt_mem_d - specific memory alloc for shared code (base driver)
2990 * @hw: pointer to the HW structure
2991 * @mem: pointer to mem struct to fill out
2992 * @size: size of memory requested
2994 enum i40e_status_code
2995 i40e_allocate_virt_mem_d(__attribute__((unused)) struct i40e_hw *hw,
2996 struct i40e_virt_mem *mem,
3000 return I40E_ERR_PARAM;
3003 mem->va = rte_zmalloc("i40e", size, 0);
3006 return I40E_SUCCESS;
3008 return I40E_ERR_NO_MEMORY;
3012 * i40e_free_virt_mem_d - specific memory free for shared code (base driver)
3013 * @hw: pointer to the HW structure
3014 * @mem: pointer to mem struct to free
3016 enum i40e_status_code
3017 i40e_free_virt_mem_d(__attribute__((unused)) struct i40e_hw *hw,
3018 struct i40e_virt_mem *mem)
3021 return I40E_ERR_PARAM;
3026 return I40E_SUCCESS;
3030 i40e_init_spinlock_d(struct i40e_spinlock *sp)
3032 rte_spinlock_init(&sp->spinlock);
3036 i40e_acquire_spinlock_d(struct i40e_spinlock *sp)
3038 rte_spinlock_lock(&sp->spinlock);
3042 i40e_release_spinlock_d(struct i40e_spinlock *sp)
3044 rte_spinlock_unlock(&sp->spinlock);
3048 i40e_destroy_spinlock_d(__attribute__((unused)) struct i40e_spinlock *sp)
3054 * Get the hardware capabilities, which will be parsed
3055 * and saved into struct i40e_hw.
3058 i40e_get_cap(struct i40e_hw *hw)
3060 struct i40e_aqc_list_capabilities_element_resp *buf;
3061 uint16_t len, size = 0;
3064 /* Calculate a huge enough buff for saving response data temporarily */
3065 len = sizeof(struct i40e_aqc_list_capabilities_element_resp) *
3066 I40E_MAX_CAP_ELE_NUM;
3067 buf = rte_zmalloc("i40e", len, 0);
3069 PMD_DRV_LOG(ERR, "Failed to allocate memory");
3070 return I40E_ERR_NO_MEMORY;
3073 /* Get, parse the capabilities and save it to hw */
3074 ret = i40e_aq_discover_capabilities(hw, buf, len, &size,
3075 i40e_aqc_opc_list_func_capabilities, NULL);
3076 if (ret != I40E_SUCCESS)
3077 PMD_DRV_LOG(ERR, "Failed to discover capabilities");
3079 /* Free the temporary buffer after being used */
3086 i40e_pf_parameter_init(struct rte_eth_dev *dev)
3088 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3089 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
3090 uint16_t qp_count = 0, vsi_count = 0;
3092 if (dev->pci_dev->max_vfs && !hw->func_caps.sr_iov_1_1) {
3093 PMD_INIT_LOG(ERR, "HW configuration doesn't support SRIOV");
3096 /* Add the parameter init for LFC */
3097 pf->fc_conf.pause_time = I40E_DEFAULT_PAUSE_TIME;
3098 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_HIGH_WATER;
3099 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_LOW_WATER;
3101 pf->flags = I40E_FLAG_HEADER_SPLIT_DISABLED;
3102 pf->max_num_vsi = hw->func_caps.num_vsis;
3103 pf->lan_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_PF;
3104 pf->vmdq_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
3105 pf->vf_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF;
3107 /* FDir queue/VSI allocation */
3108 pf->fdir_qp_offset = 0;
3109 if (hw->func_caps.fd) {
3110 pf->flags |= I40E_FLAG_FDIR;
3111 pf->fdir_nb_qps = I40E_DEFAULT_QP_NUM_FDIR;
3113 pf->fdir_nb_qps = 0;
3115 qp_count += pf->fdir_nb_qps;
3118 /* LAN queue/VSI allocation */
3119 pf->lan_qp_offset = pf->fdir_qp_offset + pf->fdir_nb_qps;
3120 if (!hw->func_caps.rss) {
3123 pf->flags |= I40E_FLAG_RSS;
3124 if (hw->mac.type == I40E_MAC_X722)
3125 pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE;
3126 pf->lan_nb_qps = pf->lan_nb_qp_max;
3128 qp_count += pf->lan_nb_qps;
3131 /* VF queue/VSI allocation */
3132 pf->vf_qp_offset = pf->lan_qp_offset + pf->lan_nb_qps;
3133 if (hw->func_caps.sr_iov_1_1 && dev->pci_dev->max_vfs) {
3134 pf->flags |= I40E_FLAG_SRIOV;
3135 pf->vf_nb_qps = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF;
3136 pf->vf_num = dev->pci_dev->max_vfs;
3137 PMD_DRV_LOG(DEBUG, "%u VF VSIs, %u queues per VF VSI, "
3138 "in total %u queues", pf->vf_num, pf->vf_nb_qps,
3139 pf->vf_nb_qps * pf->vf_num);
3144 qp_count += pf->vf_nb_qps * pf->vf_num;
3145 vsi_count += pf->vf_num;
3147 /* VMDq queue/VSI allocation */
3148 pf->vmdq_qp_offset = pf->vf_qp_offset + pf->vf_nb_qps * pf->vf_num;
3149 pf->vmdq_nb_qps = 0;
3150 pf->max_nb_vmdq_vsi = 0;
3151 if (hw->func_caps.vmdq) {
3152 if (qp_count < hw->func_caps.num_tx_qp &&
3153 vsi_count < hw->func_caps.num_vsis) {
3154 pf->max_nb_vmdq_vsi = (hw->func_caps.num_tx_qp -
3155 qp_count) / pf->vmdq_nb_qp_max;
3157 /* Limit the maximum number of VMDq vsi to the maximum
3158 * ethdev can support
3160 pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
3161 hw->func_caps.num_vsis - vsi_count);
3162 pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
3164 if (pf->max_nb_vmdq_vsi) {
3165 pf->flags |= I40E_FLAG_VMDQ;
3166 pf->vmdq_nb_qps = pf->vmdq_nb_qp_max;
3167 PMD_DRV_LOG(DEBUG, "%u VMDQ VSIs, %u queues "
3168 "per VMDQ VSI, in total %u queues",
3169 pf->max_nb_vmdq_vsi,
3170 pf->vmdq_nb_qps, pf->vmdq_nb_qps *
3171 pf->max_nb_vmdq_vsi);
3173 PMD_DRV_LOG(INFO, "No enough queues left for "
3177 PMD_DRV_LOG(INFO, "No queue or VSI left for VMDq");
3180 qp_count += pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi;
3181 vsi_count += pf->max_nb_vmdq_vsi;
3183 if (hw->func_caps.dcb)
3184 pf->flags |= I40E_FLAG_DCB;
3186 if (qp_count > hw->func_caps.num_tx_qp) {
3187 PMD_DRV_LOG(ERR, "Failed to allocate %u queues, which exceeds "
3188 "the hardware maximum %u", qp_count,
3189 hw->func_caps.num_tx_qp);
3192 if (vsi_count > hw->func_caps.num_vsis) {
3193 PMD_DRV_LOG(ERR, "Failed to allocate %u VSIs, which exceeds "
3194 "the hardware maximum %u", vsi_count,
3195 hw->func_caps.num_vsis);
3203 i40e_pf_get_switch_config(struct i40e_pf *pf)
3205 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
3206 struct i40e_aqc_get_switch_config_resp *switch_config;
3207 struct i40e_aqc_switch_config_element_resp *element;
3208 uint16_t start_seid = 0, num_reported;
3211 switch_config = (struct i40e_aqc_get_switch_config_resp *)\
3212 rte_zmalloc("i40e", I40E_AQ_LARGE_BUF, 0);
3213 if (!switch_config) {
3214 PMD_DRV_LOG(ERR, "Failed to allocated memory");
3218 /* Get the switch configurations */
3219 ret = i40e_aq_get_switch_config(hw, switch_config,
3220 I40E_AQ_LARGE_BUF, &start_seid, NULL);
3221 if (ret != I40E_SUCCESS) {
3222 PMD_DRV_LOG(ERR, "Failed to get switch configurations");
3225 num_reported = rte_le_to_cpu_16(switch_config->header.num_reported);
3226 if (num_reported != 1) { /* The number should be 1 */
3227 PMD_DRV_LOG(ERR, "Wrong number of switch config reported");
3231 /* Parse the switch configuration elements */
3232 element = &(switch_config->element[0]);
3233 if (element->element_type == I40E_SWITCH_ELEMENT_TYPE_VSI) {
3234 pf->mac_seid = rte_le_to_cpu_16(element->uplink_seid);
3235 pf->main_vsi_seid = rte_le_to_cpu_16(element->seid);
3237 PMD_DRV_LOG(INFO, "Unknown element type");
3240 rte_free(switch_config);
3246 i40e_res_pool_init (struct i40e_res_pool_info *pool, uint32_t base,
3249 struct pool_entry *entry;
3251 if (pool == NULL || num == 0)
3254 entry = rte_zmalloc("i40e", sizeof(*entry), 0);
3255 if (entry == NULL) {
3256 PMD_DRV_LOG(ERR, "Failed to allocate memory for resource pool");
3260 /* queue heap initialize */
3261 pool->num_free = num;
3262 pool->num_alloc = 0;
3264 LIST_INIT(&pool->alloc_list);
3265 LIST_INIT(&pool->free_list);
3267 /* Initialize element */
3271 LIST_INSERT_HEAD(&pool->free_list, entry, next);
3276 i40e_res_pool_destroy(struct i40e_res_pool_info *pool)
3278 struct pool_entry *entry;
3283 LIST_FOREACH(entry, &pool->alloc_list, next) {
3284 LIST_REMOVE(entry, next);
3288 LIST_FOREACH(entry, &pool->free_list, next) {
3289 LIST_REMOVE(entry, next);
3294 pool->num_alloc = 0;
3296 LIST_INIT(&pool->alloc_list);
3297 LIST_INIT(&pool->free_list);
3301 i40e_res_pool_free(struct i40e_res_pool_info *pool,
3304 struct pool_entry *entry, *next, *prev, *valid_entry = NULL;
3305 uint32_t pool_offset;
3309 PMD_DRV_LOG(ERR, "Invalid parameter");
3313 pool_offset = base - pool->base;
3314 /* Lookup in alloc list */
3315 LIST_FOREACH(entry, &pool->alloc_list, next) {
3316 if (entry->base == pool_offset) {
3317 valid_entry = entry;
3318 LIST_REMOVE(entry, next);
3323 /* Not find, return */
3324 if (valid_entry == NULL) {
3325 PMD_DRV_LOG(ERR, "Failed to find entry");
3330 * Found it, move it to free list and try to merge.
3331 * In order to make merge easier, always sort it by qbase.
3332 * Find adjacent prev and last entries.
3335 LIST_FOREACH(entry, &pool->free_list, next) {
3336 if (entry->base > valid_entry->base) {
3344 /* Try to merge with next one*/
3346 /* Merge with next one */
3347 if (valid_entry->base + valid_entry->len == next->base) {
3348 next->base = valid_entry->base;
3349 next->len += valid_entry->len;
3350 rte_free(valid_entry);
3357 /* Merge with previous one */
3358 if (prev->base + prev->len == valid_entry->base) {
3359 prev->len += valid_entry->len;
3360 /* If it merge with next one, remove next node */
3362 LIST_REMOVE(valid_entry, next);
3363 rte_free(valid_entry);
3365 rte_free(valid_entry);
3371 /* Not find any entry to merge, insert */
3374 LIST_INSERT_AFTER(prev, valid_entry, next);
3375 else if (next != NULL)
3376 LIST_INSERT_BEFORE(next, valid_entry, next);
3377 else /* It's empty list, insert to head */
3378 LIST_INSERT_HEAD(&pool->free_list, valid_entry, next);
3381 pool->num_free += valid_entry->len;
3382 pool->num_alloc -= valid_entry->len;
3388 i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
3391 struct pool_entry *entry, *valid_entry;
3393 if (pool == NULL || num == 0) {
3394 PMD_DRV_LOG(ERR, "Invalid parameter");
3398 if (pool->num_free < num) {
3399 PMD_DRV_LOG(ERR, "No resource. ask:%u, available:%u",
3400 num, pool->num_free);
3405 /* Lookup in free list and find most fit one */
3406 LIST_FOREACH(entry, &pool->free_list, next) {
3407 if (entry->len >= num) {
3409 if (entry->len == num) {
3410 valid_entry = entry;
3413 if (valid_entry == NULL || valid_entry->len > entry->len)
3414 valid_entry = entry;
3418 /* Not find one to satisfy the request, return */
3419 if (valid_entry == NULL) {
3420 PMD_DRV_LOG(ERR, "No valid entry found");
3424 * The entry have equal queue number as requested,
3425 * remove it from alloc_list.
3427 if (valid_entry->len == num) {
3428 LIST_REMOVE(valid_entry, next);
3431 * The entry have more numbers than requested,
3432 * create a new entry for alloc_list and minus its
3433 * queue base and number in free_list.
3435 entry = rte_zmalloc("res_pool", sizeof(*entry), 0);
3436 if (entry == NULL) {
3437 PMD_DRV_LOG(ERR, "Failed to allocate memory for "
3441 entry->base = valid_entry->base;
3443 valid_entry->base += num;
3444 valid_entry->len -= num;
3445 valid_entry = entry;
3448 /* Insert it into alloc list, not sorted */
3449 LIST_INSERT_HEAD(&pool->alloc_list, valid_entry, next);
3451 pool->num_free -= valid_entry->len;
3452 pool->num_alloc += valid_entry->len;
3454 return (valid_entry->base + pool->base);
3458 * bitmap_is_subset - Check whether src2 is subset of src1
3461 bitmap_is_subset(uint8_t src1, uint8_t src2)
3463 return !((src1 ^ src2) & src2);
3466 static enum i40e_status_code
3467 validate_tcmap_parameter(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
3469 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3471 /* If DCB is not supported, only default TC is supported */
3472 if (!hw->func_caps.dcb && enabled_tcmap != I40E_DEFAULT_TCMAP) {
3473 PMD_DRV_LOG(ERR, "DCB is not enabled, only TC0 is supported");
3474 return I40E_NOT_SUPPORTED;
3477 if (!bitmap_is_subset(hw->func_caps.enabled_tcmap, enabled_tcmap)) {
3478 PMD_DRV_LOG(ERR, "Enabled TC map 0x%x not applicable to "
3479 "HW support 0x%x", hw->func_caps.enabled_tcmap,
3481 return I40E_NOT_SUPPORTED;
3483 return I40E_SUCCESS;
3487 i40e_vsi_vlan_pvid_set(struct i40e_vsi *vsi,
3488 struct i40e_vsi_vlan_pvid_info *info)
3491 struct i40e_vsi_context ctxt;
3492 uint8_t vlan_flags = 0;
3495 if (vsi == NULL || info == NULL) {
3496 PMD_DRV_LOG(ERR, "invalid parameters");
3497 return I40E_ERR_PARAM;
3501 vsi->info.pvid = info->config.pvid;
3503 * If insert pvid is enabled, only tagged pkts are
3504 * allowed to be sent out.
3506 vlan_flags |= I40E_AQ_VSI_PVLAN_INSERT_PVID |
3507 I40E_AQ_VSI_PVLAN_MODE_TAGGED;
3510 if (info->config.reject.tagged == 0)
3511 vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_TAGGED;
3513 if (info->config.reject.untagged == 0)
3514 vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_UNTAGGED;
3516 vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_INSERT_PVID |
3517 I40E_AQ_VSI_PVLAN_MODE_MASK);
3518 vsi->info.port_vlan_flags |= vlan_flags;
3519 vsi->info.valid_sections =
3520 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
3521 memset(&ctxt, 0, sizeof(ctxt));
3522 (void)rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
3523 ctxt.seid = vsi->seid;
3525 hw = I40E_VSI_TO_HW(vsi);
3526 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
3527 if (ret != I40E_SUCCESS)
3528 PMD_DRV_LOG(ERR, "Failed to update VSI params");
3534 i40e_vsi_update_tc_bandwidth(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
3536 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3538 struct i40e_aqc_configure_vsi_tc_bw_data tc_bw_data;
3540 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
3541 if (ret != I40E_SUCCESS)
3545 PMD_DRV_LOG(ERR, "seid not valid");
3549 memset(&tc_bw_data, 0, sizeof(tc_bw_data));
3550 tc_bw_data.tc_valid_bits = enabled_tcmap;
3551 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
3552 tc_bw_data.tc_bw_credits[i] =
3553 (enabled_tcmap & (1 << i)) ? 1 : 0;
3555 ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &tc_bw_data, NULL);
3556 if (ret != I40E_SUCCESS) {
3557 PMD_DRV_LOG(ERR, "Failed to configure TC BW");
3561 (void)rte_memcpy(vsi->info.qs_handle, tc_bw_data.qs_handles,
3562 sizeof(vsi->info.qs_handle));
3563 return I40E_SUCCESS;
3566 static enum i40e_status_code
3567 i40e_vsi_config_tc_queue_mapping(struct i40e_vsi *vsi,
3568 struct i40e_aqc_vsi_properties_data *info,
3569 uint8_t enabled_tcmap)
3571 enum i40e_status_code ret;
3572 int i, total_tc = 0;
3573 uint16_t qpnum_per_tc, bsf, qp_idx;
3575 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
3576 if (ret != I40E_SUCCESS)
3579 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
3580 if (enabled_tcmap & (1 << i))
3582 vsi->enabled_tc = enabled_tcmap;
3584 /* Number of queues per enabled TC */
3585 qpnum_per_tc = i40e_align_floor(vsi->nb_qps / total_tc);
3586 qpnum_per_tc = RTE_MIN(qpnum_per_tc, I40E_MAX_Q_PER_TC);
3587 bsf = rte_bsf32(qpnum_per_tc);
3589 /* Adjust the queue number to actual queues that can be applied */
3590 if (!(vsi->type == I40E_VSI_MAIN && total_tc == 1))
3591 vsi->nb_qps = qpnum_per_tc * total_tc;
3594 * Configure TC and queue mapping parameters, for enabled TC,
3595 * allocate qpnum_per_tc queues to this traffic. For disabled TC,
3596 * default queue will serve it.
3599 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
3600 if (vsi->enabled_tc & (1 << i)) {
3601 info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
3602 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
3603 (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
3604 qp_idx += qpnum_per_tc;
3606 info->tc_mapping[i] = 0;
3609 /* Associate queue number with VSI */
3610 if (vsi->type == I40E_VSI_SRIOV) {
3611 info->mapping_flags |=
3612 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
3613 for (i = 0; i < vsi->nb_qps; i++)
3614 info->queue_mapping[i] =
3615 rte_cpu_to_le_16(vsi->base_queue + i);
3617 info->mapping_flags |=
3618 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
3619 info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
3621 info->valid_sections |=
3622 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
3624 return I40E_SUCCESS;
3628 i40e_veb_release(struct i40e_veb *veb)
3630 struct i40e_vsi *vsi;
3633 if (veb == NULL || veb->associate_vsi == NULL)
3636 if (!TAILQ_EMPTY(&veb->head)) {
3637 PMD_DRV_LOG(ERR, "VEB still has VSI attached, can't remove");
3641 vsi = veb->associate_vsi;
3642 hw = I40E_VSI_TO_HW(vsi);
3644 vsi->uplink_seid = veb->uplink_seid;
3645 i40e_aq_delete_element(hw, veb->seid, NULL);
3648 return I40E_SUCCESS;
3652 static struct i40e_veb *
3653 i40e_veb_setup(struct i40e_pf *pf, struct i40e_vsi *vsi)
3655 struct i40e_veb *veb;
3659 if (NULL == pf || vsi == NULL) {
3660 PMD_DRV_LOG(ERR, "veb setup failed, "
3661 "associated VSI shouldn't null");
3664 hw = I40E_PF_TO_HW(pf);
3666 veb = rte_zmalloc("i40e_veb", sizeof(struct i40e_veb), 0);
3668 PMD_DRV_LOG(ERR, "Failed to allocate memory for veb");
3672 veb->associate_vsi = vsi;
3673 TAILQ_INIT(&veb->head);
3674 veb->uplink_seid = vsi->uplink_seid;
3676 ret = i40e_aq_add_veb(hw, veb->uplink_seid, vsi->seid,
3677 I40E_DEFAULT_TCMAP, false, false, &veb->seid, NULL);
3679 if (ret != I40E_SUCCESS) {
3680 PMD_DRV_LOG(ERR, "Add veb failed, aq_err: %d",
3681 hw->aq.asq_last_status);
3685 /* get statistics index */
3686 ret = i40e_aq_get_veb_parameters(hw, veb->seid, NULL, NULL,
3687 &veb->stats_idx, NULL, NULL, NULL);
3688 if (ret != I40E_SUCCESS) {
3689 PMD_DRV_LOG(ERR, "Get veb statics index failed, aq_err: %d",
3690 hw->aq.asq_last_status);
3694 /* Get VEB bandwidth, to be implemented */
3695 /* Now associated vsi binding to the VEB, set uplink to this VEB */
3696 vsi->uplink_seid = veb->seid;
3705 i40e_vsi_release(struct i40e_vsi *vsi)
3709 struct i40e_vsi_list *vsi_list;
3711 struct i40e_mac_filter *f;
3714 return I40E_SUCCESS;
3716 pf = I40E_VSI_TO_PF(vsi);
3717 hw = I40E_VSI_TO_HW(vsi);
3719 /* VSI has child to attach, release child first */
3721 TAILQ_FOREACH(vsi_list, &vsi->veb->head, list) {
3722 if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
3724 TAILQ_REMOVE(&vsi->veb->head, vsi_list, list);
3726 i40e_veb_release(vsi->veb);
3729 /* Remove all macvlan filters of the VSI */
3730 i40e_vsi_remove_all_macvlan_filter(vsi);
3731 TAILQ_FOREACH(f, &vsi->mac_list, next)
3734 if (vsi->type != I40E_VSI_MAIN) {
3735 /* Remove vsi from parent's sibling list */
3736 if (vsi->parent_vsi == NULL || vsi->parent_vsi->veb == NULL) {
3737 PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
3738 return I40E_ERR_PARAM;
3740 TAILQ_REMOVE(&vsi->parent_vsi->veb->head,
3741 &vsi->sib_vsi_list, list);
3743 /* Remove all switch element of the VSI */
3744 ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
3745 if (ret != I40E_SUCCESS)
3746 PMD_DRV_LOG(ERR, "Failed to delete element");
3748 i40e_res_pool_free(&pf->qp_pool, vsi->base_queue);
3750 if (vsi->type != I40E_VSI_SRIOV)
3751 i40e_res_pool_free(&pf->msix_pool, vsi->msix_intr);
3754 return I40E_SUCCESS;
3758 i40e_update_default_filter_setting(struct i40e_vsi *vsi)
3760 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3761 struct i40e_aqc_remove_macvlan_element_data def_filter;
3762 struct i40e_mac_filter_info filter;
3765 if (vsi->type != I40E_VSI_MAIN)
3766 return I40E_ERR_CONFIG;
3767 memset(&def_filter, 0, sizeof(def_filter));
3768 (void)rte_memcpy(def_filter.mac_addr, hw->mac.perm_addr,
3770 def_filter.vlan_tag = 0;
3771 def_filter.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
3772 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
3773 ret = i40e_aq_remove_macvlan(hw, vsi->seid, &def_filter, 1, NULL);
3774 if (ret != I40E_SUCCESS) {
3775 struct i40e_mac_filter *f;
3776 struct ether_addr *mac;
3778 PMD_DRV_LOG(WARNING, "Cannot remove the default "
3780 /* It needs to add the permanent mac into mac list */
3781 f = rte_zmalloc("macv_filter", sizeof(*f), 0);
3783 PMD_DRV_LOG(ERR, "failed to allocate memory");
3784 return I40E_ERR_NO_MEMORY;
3786 mac = &f->mac_info.mac_addr;
3787 (void)rte_memcpy(&mac->addr_bytes, hw->mac.perm_addr,
3789 f->mac_info.filter_type = RTE_MACVLAN_PERFECT_MATCH;
3790 TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
3795 (void)rte_memcpy(&filter.mac_addr,
3796 (struct ether_addr *)(hw->mac.perm_addr), ETH_ADDR_LEN);
3797 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
3798 return i40e_vsi_add_mac(vsi, &filter);
3802 i40e_vsi_dump_bw_config(struct i40e_vsi *vsi)
3804 struct i40e_aqc_query_vsi_bw_config_resp bw_config;
3805 struct i40e_aqc_query_vsi_ets_sla_config_resp ets_sla_config;
3806 struct i40e_hw *hw = &vsi->adapter->hw;
3810 memset(&bw_config, 0, sizeof(bw_config));
3811 ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
3812 if (ret != I40E_SUCCESS) {
3813 PMD_DRV_LOG(ERR, "VSI failed to get bandwidth configuration %u",
3814 hw->aq.asq_last_status);
3818 memset(&ets_sla_config, 0, sizeof(ets_sla_config));
3819 ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid,
3820 &ets_sla_config, NULL);
3821 if (ret != I40E_SUCCESS) {
3822 PMD_DRV_LOG(ERR, "VSI failed to get TC bandwdith "
3823 "configuration %u", hw->aq.asq_last_status);
3827 /* Not store the info yet, just print out */
3828 PMD_DRV_LOG(INFO, "VSI bw limit:%u", bw_config.port_bw_limit);
3829 PMD_DRV_LOG(INFO, "VSI max_bw:%u", bw_config.max_bw);
3830 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
3831 PMD_DRV_LOG(INFO, "\tVSI TC%u:share credits %u", i,
3832 ets_sla_config.share_credits[i]);
3833 PMD_DRV_LOG(INFO, "\tVSI TC%u:credits %u", i,
3834 rte_le_to_cpu_16(ets_sla_config.credits[i]));
3835 PMD_DRV_LOG(INFO, "\tVSI TC%u: max credits: %u", i,
3836 rte_le_to_cpu_16(ets_sla_config.credits[i / 4]) >>
3845 i40e_vsi_setup(struct i40e_pf *pf,
3846 enum i40e_vsi_type type,
3847 struct i40e_vsi *uplink_vsi,
3848 uint16_t user_param)
3850 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
3851 struct i40e_vsi *vsi;
3852 struct i40e_mac_filter_info filter;
3854 struct i40e_vsi_context ctxt;
3855 struct ether_addr broadcast =
3856 {.addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
3858 if (type != I40E_VSI_MAIN && uplink_vsi == NULL) {
3859 PMD_DRV_LOG(ERR, "VSI setup failed, "
3860 "VSI link shouldn't be NULL");
3864 if (type == I40E_VSI_MAIN && uplink_vsi != NULL) {
3865 PMD_DRV_LOG(ERR, "VSI setup failed, MAIN VSI "
3866 "uplink VSI should be NULL");
3870 /* If uplink vsi didn't setup VEB, create one first */
3871 if (type != I40E_VSI_MAIN && uplink_vsi->veb == NULL) {
3872 uplink_vsi->veb = i40e_veb_setup(pf, uplink_vsi);
3874 if (NULL == uplink_vsi->veb) {
3875 PMD_DRV_LOG(ERR, "VEB setup failed");
3880 vsi = rte_zmalloc("i40e_vsi", sizeof(struct i40e_vsi), 0);
3882 PMD_DRV_LOG(ERR, "Failed to allocate memory for vsi");
3885 TAILQ_INIT(&vsi->mac_list);
3887 vsi->adapter = I40E_PF_TO_ADAPTER(pf);
3888 vsi->max_macaddrs = I40E_NUM_MACADDR_MAX;
3889 vsi->parent_vsi = uplink_vsi;
3890 vsi->user_param = user_param;
3891 /* Allocate queues */
3892 switch (vsi->type) {
3893 case I40E_VSI_MAIN :
3894 vsi->nb_qps = pf->lan_nb_qps;
3896 case I40E_VSI_SRIOV :
3897 vsi->nb_qps = pf->vf_nb_qps;
3899 case I40E_VSI_VMDQ2:
3900 vsi->nb_qps = pf->vmdq_nb_qps;
3903 vsi->nb_qps = pf->fdir_nb_qps;
3909 * The filter status descriptor is reported in rx queue 0,
3910 * while the tx queue for fdir filter programming has no
3911 * such constraints, can be non-zero queues.
3912 * To simplify it, choose FDIR vsi use queue 0 pair.
3913 * To make sure it will use queue 0 pair, queue allocation
3914 * need be done before this function is called
3916 if (type != I40E_VSI_FDIR) {
3917 ret = i40e_res_pool_alloc(&pf->qp_pool, vsi->nb_qps);
3919 PMD_DRV_LOG(ERR, "VSI %d allocate queue failed %d",
3923 vsi->base_queue = ret;
3925 vsi->base_queue = I40E_FDIR_QUEUE_ID;
3927 /* VF has MSIX interrupt in VF range, don't allocate here */
3928 if (type == I40E_VSI_MAIN) {
3929 ret = i40e_res_pool_alloc(&pf->msix_pool,
3930 RTE_MIN(vsi->nb_qps,
3931 RTE_MAX_RXTX_INTR_VEC_ID));
3933 PMD_DRV_LOG(ERR, "VSI MAIN %d get heap failed %d",
3935 goto fail_queue_alloc;
3937 vsi->msix_intr = ret;
3938 vsi->nb_msix = RTE_MIN(vsi->nb_qps, RTE_MAX_RXTX_INTR_VEC_ID);
3939 } else if (type != I40E_VSI_SRIOV) {
3940 ret = i40e_res_pool_alloc(&pf->msix_pool, 1);
3942 PMD_DRV_LOG(ERR, "VSI %d get heap failed %d", vsi->seid, ret);
3943 goto fail_queue_alloc;
3945 vsi->msix_intr = ret;
3953 if (type == I40E_VSI_MAIN) {
3954 /* For main VSI, no need to add since it's default one */
3955 vsi->uplink_seid = pf->mac_seid;
3956 vsi->seid = pf->main_vsi_seid;
3957 /* Bind queues with specific MSIX interrupt */
3959 * Needs 2 interrupt at least, one for misc cause which will
3960 * enabled from OS side, Another for queues binding the
3961 * interrupt from device side only.
3964 /* Get default VSI parameters from hardware */
3965 memset(&ctxt, 0, sizeof(ctxt));
3966 ctxt.seid = vsi->seid;
3967 ctxt.pf_num = hw->pf_id;
3968 ctxt.uplink_seid = vsi->uplink_seid;
3970 ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
3971 if (ret != I40E_SUCCESS) {
3972 PMD_DRV_LOG(ERR, "Failed to get VSI params");
3973 goto fail_msix_alloc;
3975 (void)rte_memcpy(&vsi->info, &ctxt.info,
3976 sizeof(struct i40e_aqc_vsi_properties_data));
3977 vsi->vsi_id = ctxt.vsi_number;
3978 vsi->info.valid_sections = 0;
3980 /* Configure tc, enabled TC0 only */
3981 if (i40e_vsi_update_tc_bandwidth(vsi, I40E_DEFAULT_TCMAP) !=
3983 PMD_DRV_LOG(ERR, "Failed to update TC bandwidth");
3984 goto fail_msix_alloc;
3987 /* TC, queue mapping */
3988 memset(&ctxt, 0, sizeof(ctxt));
3989 vsi->info.valid_sections |=
3990 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
3991 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
3992 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
3993 (void)rte_memcpy(&ctxt.info, &vsi->info,
3994 sizeof(struct i40e_aqc_vsi_properties_data));
3995 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
3996 I40E_DEFAULT_TCMAP);
3997 if (ret != I40E_SUCCESS) {
3998 PMD_DRV_LOG(ERR, "Failed to configure "
3999 "TC queue mapping");
4000 goto fail_msix_alloc;
4002 ctxt.seid = vsi->seid;
4003 ctxt.pf_num = hw->pf_id;
4004 ctxt.uplink_seid = vsi->uplink_seid;
4007 /* Update VSI parameters */
4008 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
4009 if (ret != I40E_SUCCESS) {
4010 PMD_DRV_LOG(ERR, "Failed to update VSI params");
4011 goto fail_msix_alloc;
4014 (void)rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
4015 sizeof(vsi->info.tc_mapping));
4016 (void)rte_memcpy(&vsi->info.queue_mapping,
4017 &ctxt.info.queue_mapping,
4018 sizeof(vsi->info.queue_mapping));
4019 vsi->info.mapping_flags = ctxt.info.mapping_flags;
4020 vsi->info.valid_sections = 0;
4022 (void)rte_memcpy(pf->dev_addr.addr_bytes, hw->mac.perm_addr,
4026 * Updating default filter settings are necessary to prevent
4027 * reception of tagged packets.
4028 * Some old firmware configurations load a default macvlan
4029 * filter which accepts both tagged and untagged packets.
4030 * The updating is to use a normal filter instead if needed.
4031 * For NVM 4.2.2 or after, the updating is not needed anymore.
4032 * The firmware with correct configurations load the default
4033 * macvlan filter which is expected and cannot be removed.
4035 i40e_update_default_filter_setting(vsi);
4036 i40e_config_qinq(hw, vsi);
4037 } else if (type == I40E_VSI_SRIOV) {
4038 memset(&ctxt, 0, sizeof(ctxt));
4040 * For other VSI, the uplink_seid equals to uplink VSI's
4041 * uplink_seid since they share same VEB
4043 vsi->uplink_seid = uplink_vsi->uplink_seid;
4044 ctxt.pf_num = hw->pf_id;
4045 ctxt.vf_num = hw->func_caps.vf_base_id + user_param;
4046 ctxt.uplink_seid = vsi->uplink_seid;
4047 ctxt.connection_type = 0x1;
4048 ctxt.flags = I40E_AQ_VSI_TYPE_VF;
4051 * Do not configure switch ID to enable VEB switch by
4052 * I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB. Because in Fortville,
4053 * if the source mac address of packet sent from VF is not
4054 * listed in the VEB's mac table, the VEB will switch the
4055 * packet back to the VF. Need to enable it when HW issue
4059 /* Configure port/vlan */
4060 ctxt.info.valid_sections |=
4061 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
4062 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
4063 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
4064 I40E_DEFAULT_TCMAP);
4065 if (ret != I40E_SUCCESS) {
4066 PMD_DRV_LOG(ERR, "Failed to configure "
4067 "TC queue mapping");
4068 goto fail_msix_alloc;
4070 ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
4071 ctxt.info.valid_sections |=
4072 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
4074 * Since VSI is not created yet, only configure parameter,
4075 * will add vsi below.
4078 i40e_config_qinq(hw, vsi);
4079 } else if (type == I40E_VSI_VMDQ2) {
4080 memset(&ctxt, 0, sizeof(ctxt));
4082 * For other VSI, the uplink_seid equals to uplink VSI's
4083 * uplink_seid since they share same VEB
4085 vsi->uplink_seid = uplink_vsi->uplink_seid;
4086 ctxt.pf_num = hw->pf_id;
4088 ctxt.uplink_seid = vsi->uplink_seid;
4089 ctxt.connection_type = 0x1;
4090 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
4092 ctxt.info.valid_sections |=
4093 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
4094 /* user_param carries flag to enable loop back */
4096 ctxt.info.switch_id =
4097 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
4098 ctxt.info.switch_id |=
4099 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
4102 /* Configure port/vlan */
4103 ctxt.info.valid_sections |=
4104 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
4105 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
4106 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
4107 I40E_DEFAULT_TCMAP);
4108 if (ret != I40E_SUCCESS) {
4109 PMD_DRV_LOG(ERR, "Failed to configure "
4110 "TC queue mapping");
4111 goto fail_msix_alloc;
4113 ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
4114 ctxt.info.valid_sections |=
4115 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
4116 } else if (type == I40E_VSI_FDIR) {
4117 memset(&ctxt, 0, sizeof(ctxt));
4118 vsi->uplink_seid = uplink_vsi->uplink_seid;
4119 ctxt.pf_num = hw->pf_id;
4121 ctxt.uplink_seid = vsi->uplink_seid;
4122 ctxt.connection_type = 0x1; /* regular data port */
4123 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
4124 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
4125 I40E_DEFAULT_TCMAP);
4126 if (ret != I40E_SUCCESS) {
4127 PMD_DRV_LOG(ERR, "Failed to configure "
4128 "TC queue mapping.");
4129 goto fail_msix_alloc;
4131 ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
4132 ctxt.info.valid_sections |=
4133 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
4135 PMD_DRV_LOG(ERR, "VSI: Not support other type VSI yet");
4136 goto fail_msix_alloc;
4139 if (vsi->type != I40E_VSI_MAIN) {
4140 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
4141 if (ret != I40E_SUCCESS) {
4142 PMD_DRV_LOG(ERR, "add vsi failed, aq_err=%d",
4143 hw->aq.asq_last_status);
4144 goto fail_msix_alloc;
4146 memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
4147 vsi->info.valid_sections = 0;
4148 vsi->seid = ctxt.seid;
4149 vsi->vsi_id = ctxt.vsi_number;
4150 vsi->sib_vsi_list.vsi = vsi;
4151 TAILQ_INSERT_TAIL(&uplink_vsi->veb->head,
4152 &vsi->sib_vsi_list, list);
4155 /* MAC/VLAN configuration */
4156 (void)rte_memcpy(&filter.mac_addr, &broadcast, ETHER_ADDR_LEN);
4157 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
4159 ret = i40e_vsi_add_mac(vsi, &filter);
4160 if (ret != I40E_SUCCESS) {
4161 PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
4162 goto fail_msix_alloc;
4165 /* Get VSI BW information */
4166 i40e_vsi_dump_bw_config(vsi);
4169 i40e_res_pool_free(&pf->msix_pool,vsi->msix_intr);
4171 i40e_res_pool_free(&pf->qp_pool,vsi->base_queue);
4177 /* Configure vlan stripping on or off */
4179 i40e_vsi_config_vlan_stripping(struct i40e_vsi *vsi, bool on)
4181 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4182 struct i40e_vsi_context ctxt;
4184 int ret = I40E_SUCCESS;
4186 /* Check if it has been already on or off */
4187 if (vsi->info.valid_sections &
4188 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID)) {
4190 if ((vsi->info.port_vlan_flags &
4191 I40E_AQ_VSI_PVLAN_EMOD_MASK) == 0)
4192 return 0; /* already on */
4194 if ((vsi->info.port_vlan_flags &
4195 I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
4196 I40E_AQ_VSI_PVLAN_EMOD_MASK)
4197 return 0; /* already off */
4202 vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
4204 vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
4205 vsi->info.valid_sections =
4206 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
4207 vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_EMOD_MASK);
4208 vsi->info.port_vlan_flags |= vlan_flags;
4209 ctxt.seid = vsi->seid;
4210 (void)rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
4211 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
4213 PMD_DRV_LOG(INFO, "Update VSI failed to %s vlan stripping",
4214 on ? "enable" : "disable");
4220 i40e_dev_init_vlan(struct rte_eth_dev *dev)
4222 struct rte_eth_dev_data *data = dev->data;
4225 /* Apply vlan offload setting */
4226 i40e_vlan_offload_set(dev, ETH_VLAN_STRIP_MASK);
4228 /* Apply double-vlan setting, not implemented yet */
4230 /* Apply pvid setting */
4231 ret = i40e_vlan_pvid_set(dev, data->dev_conf.txmode.pvid,
4232 data->dev_conf.txmode.hw_vlan_insert_pvid);
4234 PMD_DRV_LOG(INFO, "Failed to update VSI params");
4240 i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on)
4242 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4244 return i40e_aq_set_port_parameters(hw, vsi->seid, 0, 1, on, NULL);
4248 i40e_update_flow_control(struct i40e_hw *hw)
4250 #define I40E_LINK_PAUSE_RXTX (I40E_AQ_LINK_PAUSE_RX | I40E_AQ_LINK_PAUSE_TX)
4251 struct i40e_link_status link_status;
4252 uint32_t rxfc = 0, txfc = 0, reg;
4256 memset(&link_status, 0, sizeof(link_status));
4257 ret = i40e_aq_get_link_info(hw, FALSE, &link_status, NULL);
4258 if (ret != I40E_SUCCESS) {
4259 PMD_DRV_LOG(ERR, "Failed to get link status information");
4260 goto write_reg; /* Disable flow control */
4263 an_info = hw->phy.link_info.an_info;
4264 if (!(an_info & I40E_AQ_AN_COMPLETED)) {
4265 PMD_DRV_LOG(INFO, "Link auto negotiation not completed");
4266 ret = I40E_ERR_NOT_READY;
4267 goto write_reg; /* Disable flow control */
4270 * If link auto negotiation is enabled, flow control needs to
4271 * be configured according to it
4273 switch (an_info & I40E_LINK_PAUSE_RXTX) {
4274 case I40E_LINK_PAUSE_RXTX:
4277 hw->fc.current_mode = I40E_FC_FULL;
4279 case I40E_AQ_LINK_PAUSE_RX:
4281 hw->fc.current_mode = I40E_FC_RX_PAUSE;
4283 case I40E_AQ_LINK_PAUSE_TX:
4285 hw->fc.current_mode = I40E_FC_TX_PAUSE;
4288 hw->fc.current_mode = I40E_FC_NONE;
4293 I40E_WRITE_REG(hw, I40E_PRTDCB_FCCFG,
4294 txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT);
4295 reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
4296 reg &= ~I40E_PRTDCB_MFLCN_RFCE_MASK;
4297 reg |= rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT;
4298 I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, reg);
4305 i40e_pf_setup(struct i40e_pf *pf)
4307 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4308 struct i40e_filter_control_settings settings;
4309 struct i40e_vsi *vsi;
4312 /* Clear all stats counters */
4313 pf->offset_loaded = FALSE;
4314 memset(&pf->stats, 0, sizeof(struct i40e_hw_port_stats));
4315 memset(&pf->stats_offset, 0, sizeof(struct i40e_hw_port_stats));
4317 ret = i40e_pf_get_switch_config(pf);
4318 if (ret != I40E_SUCCESS) {
4319 PMD_DRV_LOG(ERR, "Could not get switch config, err %d", ret);
4322 if (pf->flags & I40E_FLAG_FDIR) {
4323 /* make queue allocated first, let FDIR use queue pair 0*/
4324 ret = i40e_res_pool_alloc(&pf->qp_pool, I40E_DEFAULT_QP_NUM_FDIR);
4325 if (ret != I40E_FDIR_QUEUE_ID) {
4326 PMD_DRV_LOG(ERR, "queue allocation fails for FDIR :"
4328 pf->flags &= ~I40E_FLAG_FDIR;
4331 /* main VSI setup */
4332 vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, NULL, 0);
4334 PMD_DRV_LOG(ERR, "Setup of main vsi failed");
4335 return I40E_ERR_NOT_READY;
4339 /* Configure filter control */
4340 memset(&settings, 0, sizeof(settings));
4341 if (hw->func_caps.rss_table_size == ETH_RSS_RETA_SIZE_128)
4342 settings.hash_lut_size = I40E_HASH_LUT_SIZE_128;
4343 else if (hw->func_caps.rss_table_size == ETH_RSS_RETA_SIZE_512)
4344 settings.hash_lut_size = I40E_HASH_LUT_SIZE_512;
4346 PMD_DRV_LOG(ERR, "Hash lookup table size (%u) not supported\n",
4347 hw->func_caps.rss_table_size);
4348 return I40E_ERR_PARAM;
4350 PMD_DRV_LOG(INFO, "Hardware capability of hash lookup table "
4351 "size: %u\n", hw->func_caps.rss_table_size);
4352 pf->hash_lut_size = hw->func_caps.rss_table_size;
4354 /* Enable ethtype and macvlan filters */
4355 settings.enable_ethtype = TRUE;
4356 settings.enable_macvlan = TRUE;
4357 ret = i40e_set_filter_control(hw, &settings);
4359 PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
4362 /* Update flow control according to the auto negotiation */
4363 i40e_update_flow_control(hw);
4365 return I40E_SUCCESS;
4369 i40e_switch_tx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
4375 * Set or clear TX Queue Disable flags,
4376 * which is required by hardware.
4378 i40e_pre_tx_queue_cfg(hw, q_idx, on);
4379 rte_delay_us(I40E_PRE_TX_Q_CFG_WAIT_US);
4381 /* Wait until the request is finished */
4382 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
4383 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
4384 reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
4385 if (!(((reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 0x1) ^
4386 ((reg >> I40E_QTX_ENA_QENA_STAT_SHIFT)
4392 if (reg & I40E_QTX_ENA_QENA_STAT_MASK)
4393 return I40E_SUCCESS; /* already on, skip next steps */
4395 I40E_WRITE_REG(hw, I40E_QTX_HEAD(q_idx), 0);
4396 reg |= I40E_QTX_ENA_QENA_REQ_MASK;
4398 if (!(reg & I40E_QTX_ENA_QENA_STAT_MASK))
4399 return I40E_SUCCESS; /* already off, skip next steps */
4400 reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
4402 /* Write the register */
4403 I40E_WRITE_REG(hw, I40E_QTX_ENA(q_idx), reg);
4404 /* Check the result */
4405 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
4406 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
4407 reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
4409 if ((reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
4410 (reg & I40E_QTX_ENA_QENA_STAT_MASK))
4413 if (!(reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
4414 !(reg & I40E_QTX_ENA_QENA_STAT_MASK))
4418 /* Check if it is timeout */
4419 if (j >= I40E_CHK_Q_ENA_COUNT) {
4420 PMD_DRV_LOG(ERR, "Failed to %s tx queue[%u]",
4421 (on ? "enable" : "disable"), q_idx);
4422 return I40E_ERR_TIMEOUT;
4425 return I40E_SUCCESS;
4428 /* Swith on or off the tx queues */
4430 i40e_dev_switch_tx_queues(struct i40e_pf *pf, bool on)
4432 struct rte_eth_dev_data *dev_data = pf->dev_data;
4433 struct i40e_tx_queue *txq;
4434 struct rte_eth_dev *dev = pf->adapter->eth_dev;
4438 for (i = 0; i < dev_data->nb_tx_queues; i++) {
4439 txq = dev_data->tx_queues[i];
4440 /* Don't operate the queue if not configured or
4441 * if starting only per queue */
4442 if (!txq || !txq->q_set || (on && txq->tx_deferred_start))
4445 ret = i40e_dev_tx_queue_start(dev, i);
4447 ret = i40e_dev_tx_queue_stop(dev, i);
4448 if ( ret != I40E_SUCCESS)
4452 return I40E_SUCCESS;
4456 i40e_switch_rx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
4461 /* Wait until the request is finished */
4462 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
4463 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
4464 reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
4465 if (!((reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 0x1) ^
4466 ((reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 0x1))
4471 if (reg & I40E_QRX_ENA_QENA_STAT_MASK)
4472 return I40E_SUCCESS; /* Already on, skip next steps */
4473 reg |= I40E_QRX_ENA_QENA_REQ_MASK;
4475 if (!(reg & I40E_QRX_ENA_QENA_STAT_MASK))
4476 return I40E_SUCCESS; /* Already off, skip next steps */
4477 reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
4480 /* Write the register */
4481 I40E_WRITE_REG(hw, I40E_QRX_ENA(q_idx), reg);
4482 /* Check the result */
4483 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
4484 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
4485 reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
4487 if ((reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
4488 (reg & I40E_QRX_ENA_QENA_STAT_MASK))
4491 if (!(reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
4492 !(reg & I40E_QRX_ENA_QENA_STAT_MASK))
4497 /* Check if it is timeout */
4498 if (j >= I40E_CHK_Q_ENA_COUNT) {
4499 PMD_DRV_LOG(ERR, "Failed to %s rx queue[%u]",
4500 (on ? "enable" : "disable"), q_idx);
4501 return I40E_ERR_TIMEOUT;
4504 return I40E_SUCCESS;
4506 /* Switch on or off the rx queues */
4508 i40e_dev_switch_rx_queues(struct i40e_pf *pf, bool on)
4510 struct rte_eth_dev_data *dev_data = pf->dev_data;
4511 struct i40e_rx_queue *rxq;
4512 struct rte_eth_dev *dev = pf->adapter->eth_dev;
4516 for (i = 0; i < dev_data->nb_rx_queues; i++) {
4517 rxq = dev_data->rx_queues[i];
4518 /* Don't operate the queue if not configured or
4519 * if starting only per queue */
4520 if (!rxq || !rxq->q_set || (on && rxq->rx_deferred_start))
4523 ret = i40e_dev_rx_queue_start(dev, i);
4525 ret = i40e_dev_rx_queue_stop(dev, i);
4526 if (ret != I40E_SUCCESS)
4530 return I40E_SUCCESS;
4533 /* Switch on or off all the rx/tx queues */
4535 i40e_dev_switch_queues(struct i40e_pf *pf, bool on)
4540 /* enable rx queues before enabling tx queues */
4541 ret = i40e_dev_switch_rx_queues(pf, on);
4543 PMD_DRV_LOG(ERR, "Failed to switch rx queues");
4546 ret = i40e_dev_switch_tx_queues(pf, on);
4548 /* Stop tx queues before stopping rx queues */
4549 ret = i40e_dev_switch_tx_queues(pf, on);
4551 PMD_DRV_LOG(ERR, "Failed to switch tx queues");
4554 ret = i40e_dev_switch_rx_queues(pf, on);
4560 /* Initialize VSI for TX */
4562 i40e_dev_tx_init(struct i40e_pf *pf)
4564 struct rte_eth_dev_data *data = pf->dev_data;
4566 uint32_t ret = I40E_SUCCESS;
4567 struct i40e_tx_queue *txq;
4569 for (i = 0; i < data->nb_tx_queues; i++) {
4570 txq = data->tx_queues[i];
4571 if (!txq || !txq->q_set)
4573 ret = i40e_tx_queue_init(txq);
4574 if (ret != I40E_SUCCESS)
4577 if (ret == I40E_SUCCESS)
4578 i40e_set_tx_function(container_of(pf, struct i40e_adapter, pf)
4584 /* Initialize VSI for RX */
4586 i40e_dev_rx_init(struct i40e_pf *pf)
4588 struct rte_eth_dev_data *data = pf->dev_data;
4589 int ret = I40E_SUCCESS;
4591 struct i40e_rx_queue *rxq;
4593 i40e_pf_config_mq_rx(pf);
4594 for (i = 0; i < data->nb_rx_queues; i++) {
4595 rxq = data->rx_queues[i];
4596 if (!rxq || !rxq->q_set)
4599 ret = i40e_rx_queue_init(rxq);
4600 if (ret != I40E_SUCCESS) {
4601 PMD_DRV_LOG(ERR, "Failed to do RX queue "
4606 if (ret == I40E_SUCCESS)
4607 i40e_set_rx_function(container_of(pf, struct i40e_adapter, pf)
4614 i40e_dev_rxtx_init(struct i40e_pf *pf)
4618 err = i40e_dev_tx_init(pf);
4620 PMD_DRV_LOG(ERR, "Failed to do TX initialization");
4623 err = i40e_dev_rx_init(pf);
4625 PMD_DRV_LOG(ERR, "Failed to do RX initialization");
4633 i40e_vmdq_setup(struct rte_eth_dev *dev)
4635 struct rte_eth_conf *conf = &dev->data->dev_conf;
4636 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4637 int i, err, conf_vsis, j, loop;
4638 struct i40e_vsi *vsi;
4639 struct i40e_vmdq_info *vmdq_info;
4640 struct rte_eth_vmdq_rx_conf *vmdq_conf;
4641 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4644 * Disable interrupt to avoid message from VF. Furthermore, it will
4645 * avoid race condition in VSI creation/destroy.
4647 i40e_pf_disable_irq0(hw);
4649 if ((pf->flags & I40E_FLAG_VMDQ) == 0) {
4650 PMD_INIT_LOG(ERR, "FW doesn't support VMDQ");
4654 conf_vsis = conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools;
4655 if (conf_vsis > pf->max_nb_vmdq_vsi) {
4656 PMD_INIT_LOG(ERR, "VMDQ config: %u, max support:%u",
4657 conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools,
4658 pf->max_nb_vmdq_vsi);
4662 if (pf->vmdq != NULL) {
4663 PMD_INIT_LOG(INFO, "VMDQ already configured");
4667 pf->vmdq = rte_zmalloc("vmdq_info_struct",
4668 sizeof(*vmdq_info) * conf_vsis, 0);
4670 if (pf->vmdq == NULL) {
4671 PMD_INIT_LOG(ERR, "Failed to allocate memory");
4675 vmdq_conf = &conf->rx_adv_conf.vmdq_rx_conf;
4677 /* Create VMDQ VSI */
4678 for (i = 0; i < conf_vsis; i++) {
4679 vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, pf->main_vsi,
4680 vmdq_conf->enable_loop_back);
4682 PMD_INIT_LOG(ERR, "Failed to create VMDQ VSI");
4686 vmdq_info = &pf->vmdq[i];
4688 vmdq_info->vsi = vsi;
4690 pf->nb_cfg_vmdq_vsi = conf_vsis;
4692 /* Configure Vlan */
4693 loop = sizeof(vmdq_conf->pool_map[0].pools) * CHAR_BIT;
4694 for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
4695 for (j = 0; j < loop && j < pf->nb_cfg_vmdq_vsi; j++) {
4696 if (vmdq_conf->pool_map[i].pools & (1UL << j)) {
4697 PMD_INIT_LOG(INFO, "Add vlan %u to vmdq pool %u",
4698 vmdq_conf->pool_map[i].vlan_id, j);
4700 err = i40e_vsi_add_vlan(pf->vmdq[j].vsi,
4701 vmdq_conf->pool_map[i].vlan_id);
4703 PMD_INIT_LOG(ERR, "Failed to add vlan");
4711 i40e_pf_enable_irq0(hw);
4716 for (i = 0; i < conf_vsis; i++)
4717 if (pf->vmdq[i].vsi == NULL)
4720 i40e_vsi_release(pf->vmdq[i].vsi);
4724 i40e_pf_enable_irq0(hw);
4729 i40e_stat_update_32(struct i40e_hw *hw,
4737 new_data = (uint64_t)I40E_READ_REG(hw, reg);
4741 if (new_data >= *offset)
4742 *stat = (uint64_t)(new_data - *offset);
4744 *stat = (uint64_t)((new_data +
4745 ((uint64_t)1 << I40E_32_BIT_WIDTH)) - *offset);
4749 i40e_stat_update_48(struct i40e_hw *hw,
4758 new_data = (uint64_t)I40E_READ_REG(hw, loreg);
4759 new_data |= ((uint64_t)(I40E_READ_REG(hw, hireg) &
4760 I40E_16_BIT_MASK)) << I40E_32_BIT_WIDTH;
4765 if (new_data >= *offset)
4766 *stat = new_data - *offset;
4768 *stat = (uint64_t)((new_data +
4769 ((uint64_t)1 << I40E_48_BIT_WIDTH)) - *offset);
4771 *stat &= I40E_48_BIT_MASK;
4776 i40e_pf_disable_irq0(struct i40e_hw *hw)
4778 /* Disable all interrupt types */
4779 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0, 0);
4780 I40E_WRITE_FLUSH(hw);
4785 i40e_pf_enable_irq0(struct i40e_hw *hw)
4787 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
4788 I40E_PFINT_DYN_CTL0_INTENA_MASK |
4789 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
4790 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
4791 I40E_WRITE_FLUSH(hw);
4795 i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue)
4797 /* read pending request and disable first */
4798 i40e_pf_disable_irq0(hw);
4799 I40E_WRITE_REG(hw, I40E_PFINT_ICR0_ENA, I40E_PFINT_ICR0_ENA_MASK);
4800 I40E_WRITE_REG(hw, I40E_PFINT_STAT_CTL0,
4801 I40E_PFINT_STAT_CTL0_OTHER_ITR_INDX_MASK);
4804 /* Link no queues with irq0 */
4805 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
4806 I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
4810 i40e_dev_handle_vfr_event(struct rte_eth_dev *dev)
4812 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4813 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4816 uint32_t index, offset, val;
4821 * Try to find which VF trigger a reset, use absolute VF id to access
4822 * since the reg is global register.
4824 for (i = 0; i < pf->vf_num; i++) {
4825 abs_vf_id = hw->func_caps.vf_base_id + i;
4826 index = abs_vf_id / I40E_UINT32_BIT_SIZE;
4827 offset = abs_vf_id % I40E_UINT32_BIT_SIZE;
4828 val = I40E_READ_REG(hw, I40E_GLGEN_VFLRSTAT(index));
4829 /* VFR event occured */
4830 if (val & (0x1 << offset)) {
4833 /* Clear the event first */
4834 I40E_WRITE_REG(hw, I40E_GLGEN_VFLRSTAT(index),
4836 PMD_DRV_LOG(INFO, "VF %u reset occured", abs_vf_id);
4838 * Only notify a VF reset event occured,
4839 * don't trigger another SW reset
4841 ret = i40e_pf_host_vf_reset(&pf->vfs[i], 0);
4842 if (ret != I40E_SUCCESS)
4843 PMD_DRV_LOG(ERR, "Failed to do VF reset");
4849 i40e_dev_handle_aq_msg(struct rte_eth_dev *dev)
4851 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4852 struct i40e_arq_event_info info;
4853 uint16_t pending, opcode;
4856 info.buf_len = I40E_AQ_BUF_SZ;
4857 info.msg_buf = rte_zmalloc("msg_buffer", info.buf_len, 0);
4858 if (!info.msg_buf) {
4859 PMD_DRV_LOG(ERR, "Failed to allocate mem");
4865 ret = i40e_clean_arq_element(hw, &info, &pending);
4867 if (ret != I40E_SUCCESS) {
4868 PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ, "
4869 "aq_err: %u", hw->aq.asq_last_status);
4872 opcode = rte_le_to_cpu_16(info.desc.opcode);
4875 case i40e_aqc_opc_send_msg_to_pf:
4876 /* Refer to i40e_aq_send_msg_to_pf() for argument layout*/
4877 i40e_pf_host_handle_vf_msg(dev,
4878 rte_le_to_cpu_16(info.desc.retval),
4879 rte_le_to_cpu_32(info.desc.cookie_high),
4880 rte_le_to_cpu_32(info.desc.cookie_low),
4885 PMD_DRV_LOG(ERR, "Request %u is not supported yet",
4890 rte_free(info.msg_buf);
4894 * Interrupt handler is registered as the alarm callback for handling LSC
4895 * interrupt in a definite of time, in order to wait the NIC into a stable
4896 * state. Currently it waits 1 sec in i40e for the link up interrupt, and
4897 * no need for link down interrupt.
4900 i40e_dev_interrupt_delayed_handler(void *param)
4902 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
4903 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4906 /* read interrupt causes again */
4907 icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
4909 #ifdef RTE_LIBRTE_I40E_DEBUG_DRIVER
4910 if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
4911 PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error\n");
4912 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK)
4913 PMD_DRV_LOG(ERR, "ICR0: malicious programming detected\n");
4914 if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
4915 PMD_DRV_LOG(INFO, "ICR0: global reset requested\n");
4916 if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
4917 PMD_DRV_LOG(INFO, "ICR0: PCI exception\n activated\n");
4918 if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
4919 PMD_DRV_LOG(INFO, "ICR0: a change in the storm control "
4921 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
4922 PMD_DRV_LOG(ERR, "ICR0: HMC error\n");
4923 if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
4924 PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error\n");
4925 #endif /* RTE_LIBRTE_I40E_DEBUG_DRIVER */
4927 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
4928 PMD_DRV_LOG(INFO, "INT:VF reset detected\n");
4929 i40e_dev_handle_vfr_event(dev);
4931 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
4932 PMD_DRV_LOG(INFO, "INT:ADMINQ event\n");
4933 i40e_dev_handle_aq_msg(dev);
4936 /* handle the link up interrupt in an alarm callback */
4937 i40e_dev_link_update(dev, 0);
4938 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC);
4940 i40e_pf_enable_irq0(hw);
4941 rte_intr_enable(&(dev->pci_dev->intr_handle));
4945 * Interrupt handler triggered by NIC for handling
4946 * specific interrupt.
4949 * Pointer to interrupt handle.
4951 * The address of parameter (struct rte_eth_dev *) regsitered before.
4957 i40e_dev_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
4960 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
4961 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4964 /* Disable interrupt */
4965 i40e_pf_disable_irq0(hw);
4967 /* read out interrupt causes */
4968 icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
4970 /* No interrupt event indicated */
4971 if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK)) {
4972 PMD_DRV_LOG(INFO, "No interrupt event");
4975 #ifdef RTE_LIBRTE_I40E_DEBUG_DRIVER
4976 if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
4977 PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
4978 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK)
4979 PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
4980 if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
4981 PMD_DRV_LOG(INFO, "ICR0: global reset requested");
4982 if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
4983 PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
4984 if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
4985 PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
4986 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
4987 PMD_DRV_LOG(ERR, "ICR0: HMC error");
4988 if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
4989 PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
4990 #endif /* RTE_LIBRTE_I40E_DEBUG_DRIVER */
4992 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
4993 PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
4994 i40e_dev_handle_vfr_event(dev);
4996 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
4997 PMD_DRV_LOG(INFO, "ICR0: adminq event");
4998 i40e_dev_handle_aq_msg(dev);
5001 /* Link Status Change interrupt */
5002 if (icr0 & I40E_PFINT_ICR0_LINK_STAT_CHANGE_MASK) {
5003 #define I40E_US_PER_SECOND 1000000
5004 struct rte_eth_link link;
5006 PMD_DRV_LOG(INFO, "ICR0: link status changed\n");
5007 memset(&link, 0, sizeof(link));
5008 rte_i40e_dev_atomic_read_link_status(dev, &link);
5009 i40e_dev_link_update(dev, 0);
5012 * For link up interrupt, it needs to wait 1 second to let the
5013 * hardware be a stable state. Otherwise several consecutive
5014 * interrupts can be observed.
5015 * For link down interrupt, no need to wait.
5017 if (!link.link_status && rte_eal_alarm_set(I40E_US_PER_SECOND,
5018 i40e_dev_interrupt_delayed_handler, (void *)dev) >= 0)
5021 _rte_eth_dev_callback_process(dev,
5022 RTE_ETH_EVENT_INTR_LSC);
5026 /* Enable interrupt */
5027 i40e_pf_enable_irq0(hw);
5028 rte_intr_enable(&(dev->pci_dev->intr_handle));
5032 i40e_add_macvlan_filters(struct i40e_vsi *vsi,
5033 struct i40e_macvlan_filter *filter,
5036 int ele_num, ele_buff_size;
5037 int num, actual_num, i;
5039 int ret = I40E_SUCCESS;
5040 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5041 struct i40e_aqc_add_macvlan_element_data *req_list;
5043 if (filter == NULL || total == 0)
5044 return I40E_ERR_PARAM;
5045 ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
5046 ele_buff_size = hw->aq.asq_buf_size;
5048 req_list = rte_zmalloc("macvlan_add", ele_buff_size, 0);
5049 if (req_list == NULL) {
5050 PMD_DRV_LOG(ERR, "Fail to allocate memory");
5051 return I40E_ERR_NO_MEMORY;
5056 actual_num = (num + ele_num > total) ? (total - num) : ele_num;
5057 memset(req_list, 0, ele_buff_size);
5059 for (i = 0; i < actual_num; i++) {
5060 (void)rte_memcpy(req_list[i].mac_addr,
5061 &filter[num + i].macaddr, ETH_ADDR_LEN);
5062 req_list[i].vlan_tag =
5063 rte_cpu_to_le_16(filter[num + i].vlan_id);
5065 switch (filter[num + i].filter_type) {
5066 case RTE_MAC_PERFECT_MATCH:
5067 flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH |
5068 I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
5070 case RTE_MACVLAN_PERFECT_MATCH:
5071 flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
5073 case RTE_MAC_HASH_MATCH:
5074 flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH |
5075 I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
5077 case RTE_MACVLAN_HASH_MATCH:
5078 flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH;
5081 PMD_DRV_LOG(ERR, "Invalid MAC match type\n");
5082 ret = I40E_ERR_PARAM;
5086 req_list[i].queue_number = 0;
5088 req_list[i].flags = rte_cpu_to_le_16(flags);
5091 ret = i40e_aq_add_macvlan(hw, vsi->seid, req_list,
5093 if (ret != I40E_SUCCESS) {
5094 PMD_DRV_LOG(ERR, "Failed to add macvlan filter");
5098 } while (num < total);
5106 i40e_remove_macvlan_filters(struct i40e_vsi *vsi,
5107 struct i40e_macvlan_filter *filter,
5110 int ele_num, ele_buff_size;
5111 int num, actual_num, i;
5113 int ret = I40E_SUCCESS;
5114 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5115 struct i40e_aqc_remove_macvlan_element_data *req_list;
5117 if (filter == NULL || total == 0)
5118 return I40E_ERR_PARAM;
5120 ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
5121 ele_buff_size = hw->aq.asq_buf_size;
5123 req_list = rte_zmalloc("macvlan_remove", ele_buff_size, 0);
5124 if (req_list == NULL) {
5125 PMD_DRV_LOG(ERR, "Fail to allocate memory");
5126 return I40E_ERR_NO_MEMORY;
5131 actual_num = (num + ele_num > total) ? (total - num) : ele_num;
5132 memset(req_list, 0, ele_buff_size);
5134 for (i = 0; i < actual_num; i++) {
5135 (void)rte_memcpy(req_list[i].mac_addr,
5136 &filter[num + i].macaddr, ETH_ADDR_LEN);
5137 req_list[i].vlan_tag =
5138 rte_cpu_to_le_16(filter[num + i].vlan_id);
5140 switch (filter[num + i].filter_type) {
5141 case RTE_MAC_PERFECT_MATCH:
5142 flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
5143 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
5145 case RTE_MACVLAN_PERFECT_MATCH:
5146 flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
5148 case RTE_MAC_HASH_MATCH:
5149 flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH |
5150 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
5152 case RTE_MACVLAN_HASH_MATCH:
5153 flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH;
5156 PMD_DRV_LOG(ERR, "Invalid MAC filter type\n");
5157 ret = I40E_ERR_PARAM;
5160 req_list[i].flags = rte_cpu_to_le_16(flags);
5163 ret = i40e_aq_remove_macvlan(hw, vsi->seid, req_list,
5165 if (ret != I40E_SUCCESS) {
5166 PMD_DRV_LOG(ERR, "Failed to remove macvlan filter");
5170 } while (num < total);
5177 /* Find out specific MAC filter */
5178 static struct i40e_mac_filter *
5179 i40e_find_mac_filter(struct i40e_vsi *vsi,
5180 struct ether_addr *macaddr)
5182 struct i40e_mac_filter *f;
5184 TAILQ_FOREACH(f, &vsi->mac_list, next) {
5185 if (is_same_ether_addr(macaddr, &f->mac_info.mac_addr))
5193 i40e_find_vlan_filter(struct i40e_vsi *vsi,
5196 uint32_t vid_idx, vid_bit;
5198 if (vlan_id > ETH_VLAN_ID_MAX)
5201 vid_idx = I40E_VFTA_IDX(vlan_id);
5202 vid_bit = I40E_VFTA_BIT(vlan_id);
5204 if (vsi->vfta[vid_idx] & vid_bit)
5211 i40e_set_vlan_filter(struct i40e_vsi *vsi,
5212 uint16_t vlan_id, bool on)
5214 uint32_t vid_idx, vid_bit;
5216 if (vlan_id > ETH_VLAN_ID_MAX)
5219 vid_idx = I40E_VFTA_IDX(vlan_id);
5220 vid_bit = I40E_VFTA_BIT(vlan_id);
5223 vsi->vfta[vid_idx] |= vid_bit;
5225 vsi->vfta[vid_idx] &= ~vid_bit;
5229 * Find all vlan options for specific mac addr,
5230 * return with actual vlan found.
5233 i40e_find_all_vlan_for_mac(struct i40e_vsi *vsi,
5234 struct i40e_macvlan_filter *mv_f,
5235 int num, struct ether_addr *addr)
5241 * Not to use i40e_find_vlan_filter to decrease the loop time,
5242 * although the code looks complex.
5244 if (num < vsi->vlan_num)
5245 return I40E_ERR_PARAM;
5248 for (j = 0; j < I40E_VFTA_SIZE; j++) {
5250 for (k = 0; k < I40E_UINT32_BIT_SIZE; k++) {
5251 if (vsi->vfta[j] & (1 << k)) {
5253 PMD_DRV_LOG(ERR, "vlan number "
5255 return I40E_ERR_PARAM;
5257 (void)rte_memcpy(&mv_f[i].macaddr,
5258 addr, ETH_ADDR_LEN);
5260 j * I40E_UINT32_BIT_SIZE + k;
5266 return I40E_SUCCESS;
5270 i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
5271 struct i40e_macvlan_filter *mv_f,
5276 struct i40e_mac_filter *f;
5278 if (num < vsi->mac_num)
5279 return I40E_ERR_PARAM;
5281 TAILQ_FOREACH(f, &vsi->mac_list, next) {
5283 PMD_DRV_LOG(ERR, "buffer number not match");
5284 return I40E_ERR_PARAM;
5286 (void)rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
5288 mv_f[i].vlan_id = vlan;
5289 mv_f[i].filter_type = f->mac_info.filter_type;
5293 return I40E_SUCCESS;
5297 i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi)
5300 struct i40e_mac_filter *f;
5301 struct i40e_macvlan_filter *mv_f;
5302 int ret = I40E_SUCCESS;
5304 if (vsi == NULL || vsi->mac_num == 0)
5305 return I40E_ERR_PARAM;
5307 /* Case that no vlan is set */
5308 if (vsi->vlan_num == 0)
5311 num = vsi->mac_num * vsi->vlan_num;
5313 mv_f = rte_zmalloc("macvlan_data", num * sizeof(*mv_f), 0);
5315 PMD_DRV_LOG(ERR, "failed to allocate memory");
5316 return I40E_ERR_NO_MEMORY;
5320 if (vsi->vlan_num == 0) {
5321 TAILQ_FOREACH(f, &vsi->mac_list, next) {
5322 (void)rte_memcpy(&mv_f[i].macaddr,
5323 &f->mac_info.mac_addr, ETH_ADDR_LEN);
5324 mv_f[i].vlan_id = 0;
5328 TAILQ_FOREACH(f, &vsi->mac_list, next) {
5329 ret = i40e_find_all_vlan_for_mac(vsi,&mv_f[i],
5330 vsi->vlan_num, &f->mac_info.mac_addr);
5331 if (ret != I40E_SUCCESS)
5337 ret = i40e_remove_macvlan_filters(vsi, mv_f, num);
5345 i40e_vsi_add_vlan(struct i40e_vsi *vsi, uint16_t vlan)
5347 struct i40e_macvlan_filter *mv_f;
5349 int ret = I40E_SUCCESS;
5351 if (!vsi || vlan > ETHER_MAX_VLAN_ID)
5352 return I40E_ERR_PARAM;
5354 /* If it's already set, just return */
5355 if (i40e_find_vlan_filter(vsi,vlan))
5356 return I40E_SUCCESS;
5358 mac_num = vsi->mac_num;
5361 PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
5362 return I40E_ERR_PARAM;
5365 mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
5368 PMD_DRV_LOG(ERR, "failed to allocate memory");
5369 return I40E_ERR_NO_MEMORY;
5372 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
5374 if (ret != I40E_SUCCESS)
5377 ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
5379 if (ret != I40E_SUCCESS)
5382 i40e_set_vlan_filter(vsi, vlan, 1);
5392 i40e_vsi_delete_vlan(struct i40e_vsi *vsi, uint16_t vlan)
5394 struct i40e_macvlan_filter *mv_f;
5396 int ret = I40E_SUCCESS;
5399 * Vlan 0 is the generic filter for untagged packets
5400 * and can't be removed.
5402 if (!vsi || vlan == 0 || vlan > ETHER_MAX_VLAN_ID)
5403 return I40E_ERR_PARAM;
5405 /* If can't find it, just return */
5406 if (!i40e_find_vlan_filter(vsi, vlan))
5407 return I40E_ERR_PARAM;
5409 mac_num = vsi->mac_num;
5412 PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
5413 return I40E_ERR_PARAM;
5416 mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
5419 PMD_DRV_LOG(ERR, "failed to allocate memory");
5420 return I40E_ERR_NO_MEMORY;
5423 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
5425 if (ret != I40E_SUCCESS)
5428 ret = i40e_remove_macvlan_filters(vsi, mv_f, mac_num);
5430 if (ret != I40E_SUCCESS)
5433 /* This is last vlan to remove, replace all mac filter with vlan 0 */
5434 if (vsi->vlan_num == 1) {
5435 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, 0);
5436 if (ret != I40E_SUCCESS)
5439 ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
5440 if (ret != I40E_SUCCESS)
5444 i40e_set_vlan_filter(vsi, vlan, 0);
5454 i40e_vsi_add_mac(struct i40e_vsi *vsi, struct i40e_mac_filter_info *mac_filter)
5456 struct i40e_mac_filter *f;
5457 struct i40e_macvlan_filter *mv_f;
5458 int i, vlan_num = 0;
5459 int ret = I40E_SUCCESS;
5461 /* If it's add and we've config it, return */
5462 f = i40e_find_mac_filter(vsi, &mac_filter->mac_addr);
5464 return I40E_SUCCESS;
5465 if ((mac_filter->filter_type == RTE_MACVLAN_PERFECT_MATCH) ||
5466 (mac_filter->filter_type == RTE_MACVLAN_HASH_MATCH)) {
5469 * If vlan_num is 0, that's the first time to add mac,
5470 * set mask for vlan_id 0.
5472 if (vsi->vlan_num == 0) {
5473 i40e_set_vlan_filter(vsi, 0, 1);
5476 vlan_num = vsi->vlan_num;
5477 } else if ((mac_filter->filter_type == RTE_MAC_PERFECT_MATCH) ||
5478 (mac_filter->filter_type == RTE_MAC_HASH_MATCH))
5481 mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
5483 PMD_DRV_LOG(ERR, "failed to allocate memory");
5484 return I40E_ERR_NO_MEMORY;
5487 for (i = 0; i < vlan_num; i++) {
5488 mv_f[i].filter_type = mac_filter->filter_type;
5489 (void)rte_memcpy(&mv_f[i].macaddr, &mac_filter->mac_addr,
5493 if (mac_filter->filter_type == RTE_MACVLAN_PERFECT_MATCH ||
5494 mac_filter->filter_type == RTE_MACVLAN_HASH_MATCH) {
5495 ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
5496 &mac_filter->mac_addr);
5497 if (ret != I40E_SUCCESS)
5501 ret = i40e_add_macvlan_filters(vsi, mv_f, vlan_num);
5502 if (ret != I40E_SUCCESS)
5505 /* Add the mac addr into mac list */
5506 f = rte_zmalloc("macv_filter", sizeof(*f), 0);
5508 PMD_DRV_LOG(ERR, "failed to allocate memory");
5509 ret = I40E_ERR_NO_MEMORY;
5512 (void)rte_memcpy(&f->mac_info.mac_addr, &mac_filter->mac_addr,
5514 f->mac_info.filter_type = mac_filter->filter_type;
5515 TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
5526 i40e_vsi_delete_mac(struct i40e_vsi *vsi, struct ether_addr *addr)
5528 struct i40e_mac_filter *f;
5529 struct i40e_macvlan_filter *mv_f;
5531 enum rte_mac_filter_type filter_type;
5532 int ret = I40E_SUCCESS;
5534 /* Can't find it, return an error */
5535 f = i40e_find_mac_filter(vsi, addr);
5537 return I40E_ERR_PARAM;
5539 vlan_num = vsi->vlan_num;
5540 filter_type = f->mac_info.filter_type;
5541 if (filter_type == RTE_MACVLAN_PERFECT_MATCH ||
5542 filter_type == RTE_MACVLAN_HASH_MATCH) {
5543 if (vlan_num == 0) {
5544 PMD_DRV_LOG(ERR, "VLAN number shouldn't be 0\n");
5545 return I40E_ERR_PARAM;
5547 } else if (filter_type == RTE_MAC_PERFECT_MATCH ||
5548 filter_type == RTE_MAC_HASH_MATCH)
5551 mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
5553 PMD_DRV_LOG(ERR, "failed to allocate memory");
5554 return I40E_ERR_NO_MEMORY;
5557 for (i = 0; i < vlan_num; i++) {
5558 mv_f[i].filter_type = filter_type;
5559 (void)rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
5562 if (filter_type == RTE_MACVLAN_PERFECT_MATCH ||
5563 filter_type == RTE_MACVLAN_HASH_MATCH) {
5564 ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num, addr);
5565 if (ret != I40E_SUCCESS)
5569 ret = i40e_remove_macvlan_filters(vsi, mv_f, vlan_num);
5570 if (ret != I40E_SUCCESS)
5573 /* Remove the mac addr into mac list */
5574 TAILQ_REMOVE(&vsi->mac_list, f, next);
5584 /* Configure hash enable flags for RSS */
5586 i40e_config_hena(uint64_t flags)
5593 if (flags & ETH_RSS_FRAG_IPV4)
5594 hena |= 1ULL << I40E_FILTER_PCTYPE_FRAG_IPV4;
5595 if (flags & ETH_RSS_NONFRAG_IPV4_TCP)
5596 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
5597 if (flags & ETH_RSS_NONFRAG_IPV4_UDP)
5598 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
5599 if (flags & ETH_RSS_NONFRAG_IPV4_SCTP)
5600 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
5601 if (flags & ETH_RSS_NONFRAG_IPV4_OTHER)
5602 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
5603 if (flags & ETH_RSS_FRAG_IPV6)
5604 hena |= 1ULL << I40E_FILTER_PCTYPE_FRAG_IPV6;
5605 if (flags & ETH_RSS_NONFRAG_IPV6_TCP)
5606 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
5607 if (flags & ETH_RSS_NONFRAG_IPV6_UDP)
5608 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
5609 if (flags & ETH_RSS_NONFRAG_IPV6_SCTP)
5610 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_SCTP;
5611 if (flags & ETH_RSS_NONFRAG_IPV6_OTHER)
5612 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER;
5613 if (flags & ETH_RSS_L2_PAYLOAD)
5614 hena |= 1ULL << I40E_FILTER_PCTYPE_L2_PAYLOAD;
5619 /* Parse the hash enable flags */
5621 i40e_parse_hena(uint64_t flags)
5623 uint64_t rss_hf = 0;
5627 if (flags & (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV4))
5628 rss_hf |= ETH_RSS_FRAG_IPV4;
5629 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP))
5630 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
5631 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_UDP))
5632 rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
5633 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_SCTP))
5634 rss_hf |= ETH_RSS_NONFRAG_IPV4_SCTP;
5635 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER))
5636 rss_hf |= ETH_RSS_NONFRAG_IPV4_OTHER;
5637 if (flags & (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV6))
5638 rss_hf |= ETH_RSS_FRAG_IPV6;
5639 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP))
5640 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
5641 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_UDP))
5642 rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP;
5643 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_SCTP))
5644 rss_hf |= ETH_RSS_NONFRAG_IPV6_SCTP;
5645 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER))
5646 rss_hf |= ETH_RSS_NONFRAG_IPV6_OTHER;
5647 if (flags & (1ULL << I40E_FILTER_PCTYPE_L2_PAYLOAD))
5648 rss_hf |= ETH_RSS_L2_PAYLOAD;
5655 i40e_pf_disable_rss(struct i40e_pf *pf)
5657 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5660 hena = (uint64_t)I40E_READ_REG(hw, I40E_PFQF_HENA(0));
5661 hena |= ((uint64_t)I40E_READ_REG(hw, I40E_PFQF_HENA(1))) << 32;
5662 hena &= ~I40E_RSS_HENA_ALL;
5663 I40E_WRITE_REG(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
5664 I40E_WRITE_REG(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
5665 I40E_WRITE_FLUSH(hw);
5669 i40e_set_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t key_len)
5671 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
5672 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5675 if (!key || key_len != ((I40E_PFQF_HKEY_MAX_INDEX + 1) *
5679 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
5680 struct i40e_aqc_get_set_rss_key_data *key_dw =
5681 (struct i40e_aqc_get_set_rss_key_data *)key;
5683 ret = i40e_aq_set_rss_key(hw, vsi->vsi_id, key_dw);
5685 PMD_INIT_LOG(ERR, "Failed to configure RSS key "
5688 uint32_t *hash_key = (uint32_t *)key;
5691 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
5692 I40E_WRITE_REG(hw, I40E_PFQF_HKEY(i), hash_key[i]);
5693 I40E_WRITE_FLUSH(hw);
5700 i40e_get_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t *key_len)
5702 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
5703 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5706 if (!key || !key_len)
5709 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
5710 ret = i40e_aq_get_rss_key(hw, vsi->vsi_id,
5711 (struct i40e_aqc_get_set_rss_key_data *)key);
5713 PMD_INIT_LOG(ERR, "Failed to get RSS key via AQ");
5717 uint32_t *key_dw = (uint32_t *)key;
5720 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
5721 key_dw[i] = I40E_READ_REG(hw, I40E_PFQF_HKEY(i));
5723 *key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t);
5729 i40e_hw_rss_hash_set(struct i40e_pf *pf, struct rte_eth_rss_conf *rss_conf)
5731 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5736 ret = i40e_set_rss_key(pf->main_vsi, rss_conf->rss_key,
5737 rss_conf->rss_key_len);
5741 rss_hf = rss_conf->rss_hf;
5742 hena = (uint64_t)I40E_READ_REG(hw, I40E_PFQF_HENA(0));
5743 hena |= ((uint64_t)I40E_READ_REG(hw, I40E_PFQF_HENA(1))) << 32;
5744 hena &= ~I40E_RSS_HENA_ALL;
5745 hena |= i40e_config_hena(rss_hf);
5746 I40E_WRITE_REG(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
5747 I40E_WRITE_REG(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
5748 I40E_WRITE_FLUSH(hw);
5754 i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
5755 struct rte_eth_rss_conf *rss_conf)
5757 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5758 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5759 uint64_t rss_hf = rss_conf->rss_hf & I40E_RSS_OFFLOAD_ALL;
5762 hena = (uint64_t)I40E_READ_REG(hw, I40E_PFQF_HENA(0));
5763 hena |= ((uint64_t)I40E_READ_REG(hw, I40E_PFQF_HENA(1))) << 32;
5764 if (!(hena & I40E_RSS_HENA_ALL)) { /* RSS disabled */
5765 if (rss_hf != 0) /* Enable RSS */
5767 return 0; /* Nothing to do */
5770 if (rss_hf == 0) /* Disable RSS */
5773 return i40e_hw_rss_hash_set(pf, rss_conf);
5777 i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
5778 struct rte_eth_rss_conf *rss_conf)
5780 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5781 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5784 i40e_get_rss_key(pf->main_vsi, rss_conf->rss_key,
5785 &rss_conf->rss_key_len);
5787 hena = (uint64_t)I40E_READ_REG(hw, I40E_PFQF_HENA(0));
5788 hena |= ((uint64_t)I40E_READ_REG(hw, I40E_PFQF_HENA(1))) << 32;
5789 rss_conf->rss_hf = i40e_parse_hena(hena);
5795 i40e_dev_get_filter_type(uint16_t filter_type, uint16_t *flag)
5797 switch (filter_type) {
5798 case RTE_TUNNEL_FILTER_IMAC_IVLAN:
5799 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
5801 case RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID:
5802 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
5804 case RTE_TUNNEL_FILTER_IMAC_TENID:
5805 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID;
5807 case RTE_TUNNEL_FILTER_OMAC_TENID_IMAC:
5808 *flag = I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC;
5810 case ETH_TUNNEL_FILTER_IMAC:
5811 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
5814 PMD_DRV_LOG(ERR, "invalid tunnel filter type");
5822 i40e_dev_tunnel_filter_set(struct i40e_pf *pf,
5823 struct rte_eth_tunnel_filter_conf *tunnel_filter,
5827 uint8_t tun_type = 0;
5829 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5830 struct i40e_vsi *vsi = pf->main_vsi;
5831 struct i40e_aqc_add_remove_cloud_filters_element_data *cld_filter;
5832 struct i40e_aqc_add_remove_cloud_filters_element_data *pfilter;
5834 cld_filter = rte_zmalloc("tunnel_filter",
5835 sizeof(struct i40e_aqc_add_remove_cloud_filters_element_data),
5838 if (NULL == cld_filter) {
5839 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
5842 pfilter = cld_filter;
5844 (void)rte_memcpy(&pfilter->outer_mac, tunnel_filter->outer_mac,
5845 sizeof(struct ether_addr));
5846 (void)rte_memcpy(&pfilter->inner_mac, tunnel_filter->inner_mac,
5847 sizeof(struct ether_addr));
5849 pfilter->inner_vlan = tunnel_filter->inner_vlan;
5850 if (tunnel_filter->ip_type == RTE_TUNNEL_IPTYPE_IPV4) {
5851 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV4;
5852 (void)rte_memcpy(&pfilter->ipaddr.v4.data,
5853 &tunnel_filter->ip_addr,
5854 sizeof(pfilter->ipaddr.v4.data));
5856 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV6;
5857 (void)rte_memcpy(&pfilter->ipaddr.v6.data,
5858 &tunnel_filter->ip_addr,
5859 sizeof(pfilter->ipaddr.v6.data));
5862 /* check tunneled type */
5863 switch (tunnel_filter->tunnel_type) {
5864 case RTE_TUNNEL_TYPE_VXLAN:
5865 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_XVLAN;
5867 case RTE_TUNNEL_TYPE_NVGRE:
5868 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_NVGRE_OMAC;
5871 /* Other tunnel types is not supported. */
5872 PMD_DRV_LOG(ERR, "tunnel type is not supported.");
5873 rte_free(cld_filter);
5877 val = i40e_dev_get_filter_type(tunnel_filter->filter_type,
5880 rte_free(cld_filter);
5884 pfilter->flags |= I40E_AQC_ADD_CLOUD_FLAGS_TO_QUEUE | ip_type |
5885 (tun_type << I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT);
5886 pfilter->tenant_id = tunnel_filter->tenant_id;
5887 pfilter->queue_number = tunnel_filter->queue_id;
5890 ret = i40e_aq_add_cloud_filters(hw, vsi->seid, cld_filter, 1);
5892 ret = i40e_aq_remove_cloud_filters(hw, vsi->seid,
5895 rte_free(cld_filter);
5900 i40e_get_vxlan_port_idx(struct i40e_pf *pf, uint16_t port)
5904 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
5905 if (pf->vxlan_ports[i] == port)
5913 i40e_add_vxlan_port(struct i40e_pf *pf, uint16_t port)
5917 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5919 idx = i40e_get_vxlan_port_idx(pf, port);
5921 /* Check if port already exists */
5923 PMD_DRV_LOG(ERR, "Port %d already offloaded", port);
5927 /* Now check if there is space to add the new port */
5928 idx = i40e_get_vxlan_port_idx(pf, 0);
5930 PMD_DRV_LOG(ERR, "Maximum number of UDP ports reached,"
5931 "not adding port %d", port);
5935 ret = i40e_aq_add_udp_tunnel(hw, port, I40E_AQC_TUNNEL_TYPE_VXLAN,
5938 PMD_DRV_LOG(ERR, "Failed to add VXLAN UDP port %d", port);
5942 PMD_DRV_LOG(INFO, "Added port %d with AQ command with index %d",
5945 /* New port: add it and mark its index in the bitmap */
5946 pf->vxlan_ports[idx] = port;
5947 pf->vxlan_bitmap |= (1 << idx);
5949 if (!(pf->flags & I40E_FLAG_VXLAN))
5950 pf->flags |= I40E_FLAG_VXLAN;
5956 i40e_del_vxlan_port(struct i40e_pf *pf, uint16_t port)
5959 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5961 if (!(pf->flags & I40E_FLAG_VXLAN)) {
5962 PMD_DRV_LOG(ERR, "VXLAN UDP port was not configured.");
5966 idx = i40e_get_vxlan_port_idx(pf, port);
5969 PMD_DRV_LOG(ERR, "Port %d doesn't exist", port);
5973 if (i40e_aq_del_udp_tunnel(hw, idx, NULL) < 0) {
5974 PMD_DRV_LOG(ERR, "Failed to delete VXLAN UDP port %d", port);
5978 PMD_DRV_LOG(INFO, "Deleted port %d with AQ command with index %d",
5981 pf->vxlan_ports[idx] = 0;
5982 pf->vxlan_bitmap &= ~(1 << idx);
5984 if (!pf->vxlan_bitmap)
5985 pf->flags &= ~I40E_FLAG_VXLAN;
5990 /* Add UDP tunneling port */
5992 i40e_dev_udp_tunnel_add(struct rte_eth_dev *dev,
5993 struct rte_eth_udp_tunnel *udp_tunnel)
5996 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5998 if (udp_tunnel == NULL)
6001 switch (udp_tunnel->prot_type) {
6002 case RTE_TUNNEL_TYPE_VXLAN:
6003 ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port);
6006 case RTE_TUNNEL_TYPE_GENEVE:
6007 case RTE_TUNNEL_TYPE_TEREDO:
6008 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
6013 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6021 /* Remove UDP tunneling port */
6023 i40e_dev_udp_tunnel_del(struct rte_eth_dev *dev,
6024 struct rte_eth_udp_tunnel *udp_tunnel)
6027 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6029 if (udp_tunnel == NULL)
6032 switch (udp_tunnel->prot_type) {
6033 case RTE_TUNNEL_TYPE_VXLAN:
6034 ret = i40e_del_vxlan_port(pf, udp_tunnel->udp_port);
6036 case RTE_TUNNEL_TYPE_GENEVE:
6037 case RTE_TUNNEL_TYPE_TEREDO:
6038 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
6042 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6050 /* Calculate the maximum number of contiguous PF queues that are configured */
6052 i40e_pf_calc_configured_queues_num(struct i40e_pf *pf)
6054 struct rte_eth_dev_data *data = pf->dev_data;
6056 struct i40e_rx_queue *rxq;
6059 for (i = 0; i < pf->lan_nb_qps; i++) {
6060 rxq = data->rx_queues[i];
6061 if (rxq && rxq->q_set)
6072 i40e_pf_config_rss(struct i40e_pf *pf)
6074 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6075 struct rte_eth_rss_conf rss_conf;
6076 uint32_t i, lut = 0;
6080 * If both VMDQ and RSS enabled, not all of PF queues are configured.
6081 * It's necessary to calulate the actual PF queues that are configured.
6083 if (pf->dev_data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG)
6084 num = i40e_pf_calc_configured_queues_num(pf);
6086 num = pf->dev_data->nb_rx_queues;
6088 num = RTE_MIN(num, I40E_MAX_Q_PER_TC);
6089 PMD_INIT_LOG(INFO, "Max of contiguous %u PF queues are configured",
6093 PMD_INIT_LOG(ERR, "No PF queues are configured to enable RSS");
6097 for (i = 0, j = 0; i < hw->func_caps.rss_table_size; i++, j++) {
6100 lut = (lut << 8) | (j & ((0x1 <<
6101 hw->func_caps.rss_table_entry_width) - 1));
6103 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i >> 2), lut);
6106 rss_conf = pf->dev_data->dev_conf.rx_adv_conf.rss_conf;
6107 if ((rss_conf.rss_hf & I40E_RSS_OFFLOAD_ALL) == 0) {
6108 i40e_pf_disable_rss(pf);
6111 if (rss_conf.rss_key == NULL || rss_conf.rss_key_len <
6112 (I40E_PFQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t)) {
6113 /* Random default keys */
6114 static uint32_t rss_key_default[] = {0x6b793944,
6115 0x23504cb5, 0x5bea75b6, 0x309f4f12, 0x3dc0a2b8,
6116 0x024ddcdf, 0x339b8ca0, 0x4c4af64a, 0x34fac605,
6117 0x55d85839, 0x3a58997d, 0x2ec938e1, 0x66031581};
6119 rss_conf.rss_key = (uint8_t *)rss_key_default;
6120 rss_conf.rss_key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
6124 return i40e_hw_rss_hash_set(pf, &rss_conf);
6128 i40e_tunnel_filter_param_check(struct i40e_pf *pf,
6129 struct rte_eth_tunnel_filter_conf *filter)
6131 if (pf == NULL || filter == NULL) {
6132 PMD_DRV_LOG(ERR, "Invalid parameter");
6136 if (filter->queue_id >= pf->dev_data->nb_rx_queues) {
6137 PMD_DRV_LOG(ERR, "Invalid queue ID");
6141 if (filter->inner_vlan > ETHER_MAX_VLAN_ID) {
6142 PMD_DRV_LOG(ERR, "Invalid inner VLAN ID");
6146 if ((filter->filter_type & ETH_TUNNEL_FILTER_OMAC) &&
6147 (is_zero_ether_addr(filter->outer_mac))) {
6148 PMD_DRV_LOG(ERR, "Cannot add NULL outer MAC address");
6152 if ((filter->filter_type & ETH_TUNNEL_FILTER_IMAC) &&
6153 (is_zero_ether_addr(filter->inner_mac))) {
6154 PMD_DRV_LOG(ERR, "Cannot add NULL inner MAC address");
6161 #define I40E_GL_PRS_FVBM_MSK_ENA 0x80000000
6162 #define I40E_GL_PRS_FVBM(_i) (0x00269760 + ((_i) * 4))
6164 i40e_dev_set_gre_key_len(struct i40e_hw *hw, uint8_t len)
6169 val = I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2));
6170 PMD_DRV_LOG(DEBUG, "Read original GL_PRS_FVBM with 0x%08x\n", val);
6173 reg = val | I40E_GL_PRS_FVBM_MSK_ENA;
6174 } else if (len == 4) {
6175 reg = val & ~I40E_GL_PRS_FVBM_MSK_ENA;
6177 PMD_DRV_LOG(ERR, "Unsupported GRE key length of %u", len);
6182 ret = i40e_aq_debug_write_register(hw, I40E_GL_PRS_FVBM(2),
6189 PMD_DRV_LOG(DEBUG, "Read modified GL_PRS_FVBM with 0x%08x\n",
6190 I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2)));
6196 i40e_dev_global_config_set(struct i40e_hw *hw, struct rte_eth_global_cfg *cfg)
6203 switch (cfg->cfg_type) {
6204 case RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN:
6205 ret = i40e_dev_set_gre_key_len(hw, cfg->cfg.gre_key_len);
6208 PMD_DRV_LOG(ERR, "Unknown config type %u", cfg->cfg_type);
6216 i40e_filter_ctrl_global_config(struct rte_eth_dev *dev,
6217 enum rte_filter_op filter_op,
6220 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6221 int ret = I40E_ERR_PARAM;
6223 switch (filter_op) {
6224 case RTE_ETH_FILTER_SET:
6225 ret = i40e_dev_global_config_set(hw,
6226 (struct rte_eth_global_cfg *)arg);
6229 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
6237 i40e_tunnel_filter_handle(struct rte_eth_dev *dev,
6238 enum rte_filter_op filter_op,
6241 struct rte_eth_tunnel_filter_conf *filter;
6242 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6243 int ret = I40E_SUCCESS;
6245 filter = (struct rte_eth_tunnel_filter_conf *)(arg);
6247 if (i40e_tunnel_filter_param_check(pf, filter) < 0)
6248 return I40E_ERR_PARAM;
6250 switch (filter_op) {
6251 case RTE_ETH_FILTER_NOP:
6252 if (!(pf->flags & I40E_FLAG_VXLAN))
6253 ret = I40E_NOT_SUPPORTED;
6255 case RTE_ETH_FILTER_ADD:
6256 ret = i40e_dev_tunnel_filter_set(pf, filter, 1);
6258 case RTE_ETH_FILTER_DELETE:
6259 ret = i40e_dev_tunnel_filter_set(pf, filter, 0);
6262 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
6263 ret = I40E_ERR_PARAM;
6271 i40e_pf_config_mq_rx(struct i40e_pf *pf)
6274 enum rte_eth_rx_mq_mode mq_mode = pf->dev_data->dev_conf.rxmode.mq_mode;
6277 if (mq_mode & ETH_MQ_RX_RSS_FLAG)
6278 ret = i40e_pf_config_rss(pf);
6280 i40e_pf_disable_rss(pf);
6285 /* Get the symmetric hash enable configurations per port */
6287 i40e_get_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t *enable)
6289 uint32_t reg = I40E_READ_REG(hw, I40E_PRTQF_CTL_0);
6291 *enable = reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK ? 1 : 0;
6294 /* Set the symmetric hash enable configurations per port */
6296 i40e_set_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t enable)
6298 uint32_t reg = I40E_READ_REG(hw, I40E_PRTQF_CTL_0);
6301 if (reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK) {
6302 PMD_DRV_LOG(INFO, "Symmetric hash has already "
6306 reg |= I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
6308 if (!(reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK)) {
6309 PMD_DRV_LOG(INFO, "Symmetric hash has already "
6313 reg &= ~I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
6315 I40E_WRITE_REG(hw, I40E_PRTQF_CTL_0, reg);
6316 I40E_WRITE_FLUSH(hw);
6320 * Get global configurations of hash function type and symmetric hash enable
6321 * per flow type (pctype). Note that global configuration means it affects all
6322 * the ports on the same NIC.
6325 i40e_get_hash_filter_global_config(struct i40e_hw *hw,
6326 struct rte_eth_hash_global_conf *g_cfg)
6328 uint32_t reg, mask = I40E_FLOW_TYPES;
6330 enum i40e_filter_pctype pctype;
6332 memset(g_cfg, 0, sizeof(*g_cfg));
6333 reg = I40E_READ_REG(hw, I40E_GLQF_CTL);
6334 if (reg & I40E_GLQF_CTL_HTOEP_MASK)
6335 g_cfg->hash_func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
6337 g_cfg->hash_func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
6338 PMD_DRV_LOG(DEBUG, "Hash function is %s",
6339 (reg & I40E_GLQF_CTL_HTOEP_MASK) ? "Toeplitz" : "Simple XOR");
6341 for (i = 0; mask && i < RTE_ETH_FLOW_MAX; i++) {
6342 if (!(mask & (1UL << i)))
6344 mask &= ~(1UL << i);
6345 /* Bit set indicats the coresponding flow type is supported */
6346 g_cfg->valid_bit_mask[0] |= (1UL << i);
6347 pctype = i40e_flowtype_to_pctype(i);
6348 reg = I40E_READ_REG(hw, I40E_GLQF_HSYM(pctype));
6349 if (reg & I40E_GLQF_HSYM_SYMH_ENA_MASK)
6350 g_cfg->sym_hash_enable_mask[0] |= (1UL << i);
6357 i40e_hash_global_config_check(struct rte_eth_hash_global_conf *g_cfg)
6360 uint32_t mask0, i40e_mask = I40E_FLOW_TYPES;
6362 if (g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_TOEPLITZ &&
6363 g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_SIMPLE_XOR &&
6364 g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_DEFAULT) {
6365 PMD_DRV_LOG(ERR, "Unsupported hash function type %d",
6371 * As i40e supports less than 32 flow types, only first 32 bits need to
6374 mask0 = g_cfg->valid_bit_mask[0];
6375 for (i = 0; i < RTE_SYM_HASH_MASK_ARRAY_SIZE; i++) {
6377 /* Check if any unsupported flow type configured */
6378 if ((mask0 | i40e_mask) ^ i40e_mask)
6381 if (g_cfg->valid_bit_mask[i])
6389 PMD_DRV_LOG(ERR, "i40e unsupported flow type bit(s) configured");
6395 * Set global configurations of hash function type and symmetric hash enable
6396 * per flow type (pctype). Note any modifying global configuration will affect
6397 * all the ports on the same NIC.
6400 i40e_set_hash_filter_global_config(struct i40e_hw *hw,
6401 struct rte_eth_hash_global_conf *g_cfg)
6406 uint32_t mask0 = g_cfg->valid_bit_mask[0];
6407 enum i40e_filter_pctype pctype;
6409 /* Check the input parameters */
6410 ret = i40e_hash_global_config_check(g_cfg);
6414 for (i = 0; mask0 && i < UINT32_BIT; i++) {
6415 if (!(mask0 & (1UL << i)))
6417 mask0 &= ~(1UL << i);
6418 pctype = i40e_flowtype_to_pctype(i);
6419 reg = (g_cfg->sym_hash_enable_mask[0] & (1UL << i)) ?
6420 I40E_GLQF_HSYM_SYMH_ENA_MASK : 0;
6421 I40E_WRITE_REG(hw, I40E_GLQF_HSYM(pctype), reg);
6424 reg = I40E_READ_REG(hw, I40E_GLQF_CTL);
6425 if (g_cfg->hash_func == RTE_ETH_HASH_FUNCTION_TOEPLITZ) {
6427 if (reg & I40E_GLQF_CTL_HTOEP_MASK) {
6428 PMD_DRV_LOG(DEBUG, "Hash function already set to "
6432 reg |= I40E_GLQF_CTL_HTOEP_MASK;
6433 } else if (g_cfg->hash_func == RTE_ETH_HASH_FUNCTION_SIMPLE_XOR) {
6435 if (!(reg & I40E_GLQF_CTL_HTOEP_MASK)) {
6436 PMD_DRV_LOG(DEBUG, "Hash function already set to "
6440 reg &= ~I40E_GLQF_CTL_HTOEP_MASK;
6442 /* Use the default, and keep it as it is */
6445 I40E_WRITE_REG(hw, I40E_GLQF_CTL, reg);
6448 I40E_WRITE_FLUSH(hw);
6454 * Valid input sets for hash and flow director filters per PCTYPE
6457 i40e_get_valid_input_set(enum i40e_filter_pctype pctype,
6458 enum rte_filter_type filter)
6462 static const uint64_t valid_hash_inset_table[] = {
6463 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
6464 I40E_INSET_DMAC | I40E_INSET_SMAC |
6465 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6466 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_SRC |
6467 I40E_INSET_IPV4_DST | I40E_INSET_IPV4_TOS |
6468 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
6469 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
6470 I40E_INSET_FLEX_PAYLOAD,
6471 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
6472 I40E_INSET_DMAC | I40E_INSET_SMAC |
6473 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6474 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
6475 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
6476 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
6477 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6478 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6479 I40E_INSET_FLEX_PAYLOAD,
6480 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
6481 I40E_INSET_DMAC | I40E_INSET_SMAC |
6482 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6483 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
6484 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
6485 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
6486 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6487 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6488 I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
6489 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
6490 I40E_INSET_DMAC | I40E_INSET_SMAC |
6491 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6492 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
6493 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
6494 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
6495 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6496 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6497 I40E_INSET_SCTP_VT | I40E_INSET_FLEX_PAYLOAD,
6498 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
6499 I40E_INSET_DMAC | I40E_INSET_SMAC |
6500 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6501 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
6502 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
6503 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
6504 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6505 I40E_INSET_FLEX_PAYLOAD,
6506 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
6507 I40E_INSET_DMAC | I40E_INSET_SMAC |
6508 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6509 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
6510 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
6511 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_TUNNEL_DMAC |
6512 I40E_INSET_TUNNEL_ID | I40E_INSET_IPV6_SRC |
6513 I40E_INSET_IPV6_DST | I40E_INSET_FLEX_PAYLOAD,
6514 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
6515 I40E_INSET_DMAC | I40E_INSET_SMAC |
6516 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6517 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
6518 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
6519 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
6520 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
6521 I40E_INSET_DST_PORT | I40E_INSET_FLEX_PAYLOAD,
6522 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
6523 I40E_INSET_DMAC | I40E_INSET_SMAC |
6524 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6525 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
6526 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
6527 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
6528 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
6529 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
6530 I40E_INSET_FLEX_PAYLOAD,
6531 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
6532 I40E_INSET_DMAC | I40E_INSET_SMAC |
6533 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6534 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
6535 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
6536 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
6537 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
6538 I40E_INSET_DST_PORT | I40E_INSET_SCTP_VT |
6539 I40E_INSET_FLEX_PAYLOAD,
6540 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
6541 I40E_INSET_DMAC | I40E_INSET_SMAC |
6542 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6543 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
6544 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
6545 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
6546 I40E_INSET_IPV6_DST | I40E_INSET_TUNNEL_ID |
6547 I40E_INSET_FLEX_PAYLOAD,
6548 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
6549 I40E_INSET_DMAC | I40E_INSET_SMAC |
6550 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6551 I40E_INSET_VLAN_TUNNEL | I40E_INSET_LAST_ETHER_TYPE |
6552 I40E_INSET_FLEX_PAYLOAD,
6556 * Flow director supports only fields defined in
6557 * union rte_eth_fdir_flow.
6559 static const uint64_t valid_fdir_inset_table[] = {
6560 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
6561 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6562 I40E_INSET_FLEX_PAYLOAD,
6563 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
6564 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6565 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6566 I40E_INSET_FLEX_PAYLOAD,
6567 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
6568 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6569 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6570 I40E_INSET_FLEX_PAYLOAD,
6571 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
6572 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6573 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6574 I40E_INSET_SCTP_VT | I40E_INSET_FLEX_PAYLOAD,
6575 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
6576 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6577 I40E_INSET_FLEX_PAYLOAD,
6578 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
6579 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6580 I40E_INSET_FLEX_PAYLOAD,
6581 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
6582 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6583 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6584 I40E_INSET_FLEX_PAYLOAD,
6585 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
6586 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6587 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6588 I40E_INSET_FLEX_PAYLOAD,
6589 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
6590 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6591 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6592 I40E_INSET_SCTP_VT | I40E_INSET_FLEX_PAYLOAD,
6593 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
6594 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6595 I40E_INSET_FLEX_PAYLOAD,
6596 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
6597 I40E_INSET_LAST_ETHER_TYPE | I40E_INSET_FLEX_PAYLOAD,
6600 if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
6602 if (filter == RTE_ETH_FILTER_HASH)
6603 valid = valid_hash_inset_table[pctype];
6605 valid = valid_fdir_inset_table[pctype];
6611 * Validate if the input set is allowed for a specific PCTYPE
6614 i40e_validate_input_set(enum i40e_filter_pctype pctype,
6615 enum rte_filter_type filter, uint64_t inset)
6619 valid = i40e_get_valid_input_set(pctype, filter);
6620 if (inset & (~valid))
6626 /* default input set fields combination per pctype */
6628 i40e_get_default_input_set(uint16_t pctype)
6630 static const uint64_t default_inset_table[] = {
6631 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
6632 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
6633 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
6634 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6635 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
6636 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
6637 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6638 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
6639 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
6640 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6641 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6643 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
6644 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
6645 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
6646 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
6647 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
6648 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6649 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
6650 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
6651 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6652 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
6653 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
6654 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6655 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6657 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
6658 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
6659 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
6660 I40E_INSET_LAST_ETHER_TYPE,
6663 if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
6666 return default_inset_table[pctype];
6670 * Parse the input set from index to logical bit masks
6673 i40e_parse_input_set(uint64_t *inset,
6674 enum i40e_filter_pctype pctype,
6675 enum rte_eth_input_set_field *field,
6681 static const struct {
6682 enum rte_eth_input_set_field field;
6684 } inset_convert_table[] = {
6685 {RTE_ETH_INPUT_SET_NONE, I40E_INSET_NONE},
6686 {RTE_ETH_INPUT_SET_L2_SRC_MAC, I40E_INSET_SMAC},
6687 {RTE_ETH_INPUT_SET_L2_DST_MAC, I40E_INSET_DMAC},
6688 {RTE_ETH_INPUT_SET_L2_OUTER_VLAN, I40E_INSET_VLAN_OUTER},
6689 {RTE_ETH_INPUT_SET_L2_INNER_VLAN, I40E_INSET_VLAN_INNER},
6690 {RTE_ETH_INPUT_SET_L2_ETHERTYPE, I40E_INSET_LAST_ETHER_TYPE},
6691 {RTE_ETH_INPUT_SET_L3_SRC_IP4, I40E_INSET_IPV4_SRC},
6692 {RTE_ETH_INPUT_SET_L3_DST_IP4, I40E_INSET_IPV4_DST},
6693 {RTE_ETH_INPUT_SET_L3_IP4_TOS, I40E_INSET_IPV4_TOS},
6694 {RTE_ETH_INPUT_SET_L3_IP4_PROTO, I40E_INSET_IPV4_PROTO},
6695 {RTE_ETH_INPUT_SET_L3_SRC_IP6, I40E_INSET_IPV6_SRC},
6696 {RTE_ETH_INPUT_SET_L3_DST_IP6, I40E_INSET_IPV6_DST},
6697 {RTE_ETH_INPUT_SET_L3_IP6_TC, I40E_INSET_IPV6_TC},
6698 {RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER,
6699 I40E_INSET_IPV6_NEXT_HDR},
6700 {RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT, I40E_INSET_SRC_PORT},
6701 {RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT, I40E_INSET_SRC_PORT},
6702 {RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT, I40E_INSET_SRC_PORT},
6703 {RTE_ETH_INPUT_SET_L4_UDP_DST_PORT, I40E_INSET_DST_PORT},
6704 {RTE_ETH_INPUT_SET_L4_TCP_DST_PORT, I40E_INSET_DST_PORT},
6705 {RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT, I40E_INSET_DST_PORT},
6706 {RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG,
6707 I40E_INSET_SCTP_VT},
6708 {RTE_ETH_INPUT_SET_TUNNEL_L2_INNER_DST_MAC,
6709 I40E_INSET_TUNNEL_DMAC},
6710 {RTE_ETH_INPUT_SET_TUNNEL_L2_INNER_VLAN,
6711 I40E_INSET_VLAN_TUNNEL},
6712 {RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY,
6713 I40E_INSET_TUNNEL_ID},
6714 {RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY, I40E_INSET_TUNNEL_ID},
6715 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD,
6716 I40E_INSET_FLEX_PAYLOAD_W1},
6717 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD,
6718 I40E_INSET_FLEX_PAYLOAD_W2},
6719 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD,
6720 I40E_INSET_FLEX_PAYLOAD_W3},
6721 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD,
6722 I40E_INSET_FLEX_PAYLOAD_W4},
6723 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD,
6724 I40E_INSET_FLEX_PAYLOAD_W5},
6725 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD,
6726 I40E_INSET_FLEX_PAYLOAD_W6},
6727 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD,
6728 I40E_INSET_FLEX_PAYLOAD_W7},
6729 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD,
6730 I40E_INSET_FLEX_PAYLOAD_W8},
6733 if (!inset || !field || size > RTE_ETH_INSET_SIZE_MAX)
6736 /* Only one item allowed for default or all */
6738 if (field[0] == RTE_ETH_INPUT_SET_DEFAULT) {
6739 *inset = i40e_get_default_input_set(pctype);
6741 } else if (field[0] == RTE_ETH_INPUT_SET_NONE) {
6742 *inset = I40E_INSET_NONE;
6747 for (i = 0, *inset = 0; i < size; i++) {
6748 for (j = 0; j < RTE_DIM(inset_convert_table); j++) {
6749 if (field[i] == inset_convert_table[j].field) {
6750 *inset |= inset_convert_table[j].inset;
6755 /* It contains unsupported input set, return immediately */
6756 if (j == RTE_DIM(inset_convert_table))
6764 * Translate the input set from bit masks to register aware bit masks
6768 i40e_translate_input_set_reg(uint64_t input)
6773 static const struct {
6777 {I40E_INSET_DMAC, I40E_REG_INSET_L2_DMAC},
6778 {I40E_INSET_SMAC, I40E_REG_INSET_L2_SMAC},
6779 {I40E_INSET_VLAN_OUTER, I40E_REG_INSET_L2_OUTER_VLAN},
6780 {I40E_INSET_VLAN_INNER, I40E_REG_INSET_L2_INNER_VLAN},
6781 {I40E_INSET_LAST_ETHER_TYPE, I40E_REG_INSET_LAST_ETHER_TYPE},
6782 {I40E_INSET_IPV4_SRC, I40E_REG_INSET_L3_SRC_IP4},
6783 {I40E_INSET_IPV4_DST, I40E_REG_INSET_L3_DST_IP4},
6784 {I40E_INSET_IPV4_TOS, I40E_REG_INSET_L3_IP4_TOS},
6785 {I40E_INSET_IPV4_PROTO, I40E_REG_INSET_L3_IP4_PROTO},
6786 {I40E_INSET_IPV6_SRC, I40E_REG_INSET_L3_SRC_IP6},
6787 {I40E_INSET_IPV6_DST, I40E_REG_INSET_L3_DST_IP6},
6788 {I40E_INSET_IPV6_TC, I40E_REG_INSET_L3_IP6_TC},
6789 {I40E_INSET_IPV6_NEXT_HDR, I40E_REG_INSET_L3_IP6_NEXT_HDR},
6790 {I40E_INSET_SRC_PORT, I40E_REG_INSET_L4_SRC_PORT},
6791 {I40E_INSET_DST_PORT, I40E_REG_INSET_L4_DST_PORT},
6792 {I40E_INSET_SCTP_VT, I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG},
6793 {I40E_INSET_TUNNEL_ID, I40E_REG_INSET_TUNNEL_ID},
6794 {I40E_INSET_TUNNEL_DMAC,
6795 I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC},
6796 {I40E_INSET_TUNNEL_IPV4_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP4},
6797 {I40E_INSET_TUNNEL_IPV6_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP6},
6798 {I40E_INSET_TUNNEL_SRC_PORT,
6799 I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT},
6800 {I40E_INSET_TUNNEL_DST_PORT,
6801 I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT},
6802 {I40E_INSET_TUNNEL_ID, I40E_REG_INSET_TUNNEL_ID},
6803 {I40E_INSET_FLEX_PAYLOAD_W1, I40E_REG_INSET_FLEX_PAYLOAD_WORD1},
6804 {I40E_INSET_FLEX_PAYLOAD_W2, I40E_REG_INSET_FLEX_PAYLOAD_WORD2},
6805 {I40E_INSET_FLEX_PAYLOAD_W3, I40E_REG_INSET_FLEX_PAYLOAD_WORD3},
6806 {I40E_INSET_FLEX_PAYLOAD_W4, I40E_REG_INSET_FLEX_PAYLOAD_WORD4},
6807 {I40E_INSET_FLEX_PAYLOAD_W5, I40E_REG_INSET_FLEX_PAYLOAD_WORD5},
6808 {I40E_INSET_FLEX_PAYLOAD_W6, I40E_REG_INSET_FLEX_PAYLOAD_WORD6},
6809 {I40E_INSET_FLEX_PAYLOAD_W7, I40E_REG_INSET_FLEX_PAYLOAD_WORD7},
6810 {I40E_INSET_FLEX_PAYLOAD_W8, I40E_REG_INSET_FLEX_PAYLOAD_WORD8},
6816 /* Translate input set to register aware inset */
6817 for (i = 0; i < RTE_DIM(inset_map); i++) {
6818 if (input & inset_map[i].inset)
6819 val |= inset_map[i].inset_reg;
6826 i40e_generate_inset_mask_reg(uint64_t inset, uint32_t *mask, uint8_t nb_elem)
6830 static const struct {
6833 } inset_mask_map[] = {
6834 {I40E_INSET_IPV4_TOS, I40E_INSET_IPV4_TOS_MASK},
6835 {I40E_INSET_IPV4_PROTO, I40E_INSET_IPV4_PROTO_MASK},
6836 {I40E_INSET_IPV6_TC, I40E_INSET_IPV6_TC_MASK},
6837 {I40E_INSET_IPV6_NEXT_HDR, I40E_INSET_IPV6_NEXT_HDR_MASK},
6840 if (!inset || !mask || !nb_elem)
6843 if (!inset && nb_elem >= I40E_INSET_MASK_NUM_REG) {
6844 for (i = 0; i < I40E_INSET_MASK_NUM_REG; i++)
6846 return I40E_INSET_MASK_NUM_REG;
6849 for (i = 0, idx = 0; i < RTE_DIM(inset_mask_map); i++) {
6852 if (inset & inset_mask_map[i].inset) {
6853 mask[idx] = inset_mask_map[i].mask;
6862 i40e_get_reg_inset(struct i40e_hw *hw, enum rte_filter_type filter,
6863 enum i40e_filter_pctype pctype)
6867 if (filter == RTE_ETH_FILTER_HASH) {
6868 reg = I40E_READ_REG(hw, I40E_GLQF_HASH_INSET(1, pctype));
6869 reg <<= I40E_32_BIT_WIDTH;
6870 reg |= I40E_READ_REG(hw, I40E_GLQF_HASH_INSET(0, pctype));
6871 } else if (filter == RTE_ETH_FILTER_FDIR) {
6872 reg = I40E_READ_REG(hw, I40E_PRTQF_FD_INSET(pctype, 1));
6873 reg <<= I40E_32_BIT_WIDTH;
6874 reg |= I40E_READ_REG(hw, I40E_PRTQF_FD_INSET(pctype, 0));
6881 i40e_check_write_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
6883 uint32_t reg = I40E_READ_REG(hw, addr);
6885 PMD_DRV_LOG(DEBUG, "[0x%08x] original: 0x%08x\n", addr, reg);
6887 I40E_WRITE_REG(hw, addr, val);
6888 PMD_DRV_LOG(DEBUG, "[0x%08x] after: 0x%08x\n", addr,
6889 (uint32_t)I40E_READ_REG(hw, addr));
6893 i40e_set_hash_inset_mask(struct i40e_hw *hw,
6894 enum i40e_filter_pctype pctype,
6895 enum rte_filter_input_set_op op,
6902 if (!mask_reg || num > RTE_ETH_INPUT_SET_SELECT)
6905 if (op == RTE_ETH_INPUT_SET_SELECT) {
6906 for (i = 0; i < I40E_INSET_MASK_NUM_REG; i++) {
6907 i40e_check_write_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
6911 i40e_check_write_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
6914 } else if (op == RTE_ETH_INPUT_SET_ADD) {
6915 uint8_t j, count = 0;
6917 for (i = 0; i < I40E_INSET_MASK_NUM_REG; i++) {
6918 reg = I40E_READ_REG(hw, I40E_GLQF_HASH_MSK(i, pctype));
6919 if (reg & I40E_GLQF_HASH_MSK_FIELD)
6922 if (count + num > I40E_INSET_MASK_NUM_REG)
6925 for (i = count, j = 0; i < I40E_INSET_MASK_NUM_REG; i++, j++)
6926 i40e_check_write_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
6934 i40e_set_fd_inset_mask(struct i40e_hw *hw,
6935 enum i40e_filter_pctype pctype,
6936 enum rte_filter_input_set_op op,
6943 if (!mask_reg || num > RTE_ETH_INPUT_SET_SELECT)
6946 if (op == RTE_ETH_INPUT_SET_SELECT) {
6947 for (i = 0; i < I40E_INSET_MASK_NUM_REG; i++) {
6948 i40e_check_write_reg(hw, I40E_GLQF_FD_MSK(i, pctype),
6952 i40e_check_write_reg(hw, I40E_GLQF_FD_MSK(i, pctype),
6955 } else if (op == RTE_ETH_INPUT_SET_ADD) {
6956 uint8_t j, count = 0;
6958 for (i = 0; i < I40E_INSET_MASK_NUM_REG; i++) {
6959 reg = I40E_READ_REG(hw, I40E_GLQF_FD_MSK(i, pctype));
6960 if (reg & I40E_GLQF_FD_MSK_FIELD)
6963 if (count + num > I40E_INSET_MASK_NUM_REG)
6966 for (i = count, j = 0; i < I40E_INSET_MASK_NUM_REG; i++, j++)
6967 i40e_check_write_reg(hw, I40E_GLQF_FD_MSK(i, pctype),
6975 i40e_filter_inset_select(struct i40e_hw *hw,
6976 struct rte_eth_input_set_conf *conf,
6977 enum rte_filter_type filter)
6979 enum i40e_filter_pctype pctype;
6980 uint64_t inset_reg = 0, input_set;
6981 uint32_t mask_reg[I40E_INSET_MASK_NUM_REG];
6986 PMD_DRV_LOG(ERR, "Invalid pointer");
6990 pctype = i40e_flowtype_to_pctype(conf->flow_type);
6991 if (pctype == 0 || pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD) {
6992 PMD_DRV_LOG(ERR, "Not supported flow type (%u)",
6996 if (filter != RTE_ETH_FILTER_HASH && filter != RTE_ETH_FILTER_FDIR) {
6997 PMD_DRV_LOG(ERR, "Not supported filter type (%u)", filter);
7001 ret = i40e_parse_input_set(&input_set, pctype, conf->field,
7004 PMD_DRV_LOG(ERR, "Failed to parse input set");
7007 if (i40e_validate_input_set(pctype, filter, input_set) != 0) {
7008 PMD_DRV_LOG(ERR, "Invalid input set");
7012 if (conf->op == RTE_ETH_INPUT_SET_ADD) {
7013 inset_reg |= i40e_get_reg_inset(hw, filter, pctype);
7014 } else if (conf->op != RTE_ETH_INPUT_SET_SELECT) {
7015 PMD_DRV_LOG(ERR, "Unsupported input set operation");
7018 num = i40e_generate_inset_mask_reg(input_set, mask_reg,
7019 I40E_INSET_MASK_NUM_REG);
7020 inset_reg |= i40e_translate_input_set_reg(input_set);
7022 if (filter == RTE_ETH_FILTER_HASH) {
7023 ret = i40e_set_hash_inset_mask(hw, pctype, conf->op, mask_reg,
7028 i40e_check_write_reg(hw, I40E_GLQF_HASH_INSET(0, pctype),
7029 (uint32_t)(inset_reg & UINT32_MAX));
7030 i40e_check_write_reg(hw, I40E_GLQF_HASH_INSET(1, pctype),
7031 (uint32_t)((inset_reg >>
7032 I40E_32_BIT_WIDTH) & UINT32_MAX));
7033 } else if (filter == RTE_ETH_FILTER_FDIR) {
7034 ret = i40e_set_fd_inset_mask(hw, pctype, conf->op, mask_reg,
7039 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
7040 (uint32_t)(inset_reg & UINT32_MAX));
7041 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
7042 (uint32_t)((inset_reg >>
7043 I40E_32_BIT_WIDTH) & UINT32_MAX));
7045 PMD_DRV_LOG(ERR, "Not supported filter type (%u)", filter);
7048 I40E_WRITE_FLUSH(hw);
7054 i40e_hash_filter_get(struct i40e_hw *hw, struct rte_eth_hash_filter_info *info)
7059 PMD_DRV_LOG(ERR, "Invalid pointer");
7063 switch (info->info_type) {
7064 case RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT:
7065 i40e_get_symmetric_hash_enable_per_port(hw,
7066 &(info->info.enable));
7068 case RTE_ETH_HASH_FILTER_GLOBAL_CONFIG:
7069 ret = i40e_get_hash_filter_global_config(hw,
7070 &(info->info.global_conf));
7073 PMD_DRV_LOG(ERR, "Hash filter info type (%d) not supported",
7083 i40e_hash_filter_set(struct i40e_hw *hw, struct rte_eth_hash_filter_info *info)
7088 PMD_DRV_LOG(ERR, "Invalid pointer");
7092 switch (info->info_type) {
7093 case RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT:
7094 i40e_set_symmetric_hash_enable_per_port(hw, info->info.enable);
7096 case RTE_ETH_HASH_FILTER_GLOBAL_CONFIG:
7097 ret = i40e_set_hash_filter_global_config(hw,
7098 &(info->info.global_conf));
7100 case RTE_ETH_HASH_FILTER_INPUT_SET_SELECT:
7101 ret = i40e_filter_inset_select(hw,
7102 &(info->info.input_set_conf),
7103 RTE_ETH_FILTER_HASH);
7107 PMD_DRV_LOG(ERR, "Hash filter info type (%d) not supported",
7116 /* Operations for hash function */
7118 i40e_hash_filter_ctrl(struct rte_eth_dev *dev,
7119 enum rte_filter_op filter_op,
7122 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7125 switch (filter_op) {
7126 case RTE_ETH_FILTER_NOP:
7128 case RTE_ETH_FILTER_GET:
7129 ret = i40e_hash_filter_get(hw,
7130 (struct rte_eth_hash_filter_info *)arg);
7132 case RTE_ETH_FILTER_SET:
7133 ret = i40e_hash_filter_set(hw,
7134 (struct rte_eth_hash_filter_info *)arg);
7137 PMD_DRV_LOG(WARNING, "Filter operation (%d) not supported",
7147 * Configure ethertype filter, which can director packet by filtering
7148 * with mac address and ether_type or only ether_type
7151 i40e_ethertype_filter_set(struct i40e_pf *pf,
7152 struct rte_eth_ethertype_filter *filter,
7155 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7156 struct i40e_control_filter_stats stats;
7160 if (filter->queue >= pf->dev_data->nb_rx_queues) {
7161 PMD_DRV_LOG(ERR, "Invalid queue ID");
7164 if (filter->ether_type == ETHER_TYPE_IPv4 ||
7165 filter->ether_type == ETHER_TYPE_IPv6) {
7166 PMD_DRV_LOG(ERR, "unsupported ether_type(0x%04x) in"
7167 " control packet filter.", filter->ether_type);
7170 if (filter->ether_type == ETHER_TYPE_VLAN)
7171 PMD_DRV_LOG(WARNING, "filter vlan ether_type in first tag is"
7174 if (!(filter->flags & RTE_ETHTYPE_FLAGS_MAC))
7175 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
7176 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP)
7177 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
7178 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
7180 memset(&stats, 0, sizeof(stats));
7181 ret = i40e_aq_add_rem_control_packet_filter(hw,
7182 filter->mac_addr.addr_bytes,
7183 filter->ether_type, flags,
7185 filter->queue, add, &stats, NULL);
7187 PMD_DRV_LOG(INFO, "add/rem control packet filter, return %d,"
7188 " mac_etype_used = %u, etype_used = %u,"
7189 " mac_etype_free = %u, etype_free = %u\n",
7190 ret, stats.mac_etype_used, stats.etype_used,
7191 stats.mac_etype_free, stats.etype_free);
7198 * Handle operations for ethertype filter.
7201 i40e_ethertype_filter_handle(struct rte_eth_dev *dev,
7202 enum rte_filter_op filter_op,
7205 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7208 if (filter_op == RTE_ETH_FILTER_NOP)
7212 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
7217 switch (filter_op) {
7218 case RTE_ETH_FILTER_ADD:
7219 ret = i40e_ethertype_filter_set(pf,
7220 (struct rte_eth_ethertype_filter *)arg,
7223 case RTE_ETH_FILTER_DELETE:
7224 ret = i40e_ethertype_filter_set(pf,
7225 (struct rte_eth_ethertype_filter *)arg,
7229 PMD_DRV_LOG(ERR, "unsupported operation %u\n", filter_op);
7237 i40e_dev_filter_ctrl(struct rte_eth_dev *dev,
7238 enum rte_filter_type filter_type,
7239 enum rte_filter_op filter_op,
7247 switch (filter_type) {
7248 case RTE_ETH_FILTER_NONE:
7249 /* For global configuration */
7250 ret = i40e_filter_ctrl_global_config(dev, filter_op, arg);
7252 case RTE_ETH_FILTER_HASH:
7253 ret = i40e_hash_filter_ctrl(dev, filter_op, arg);
7255 case RTE_ETH_FILTER_MACVLAN:
7256 ret = i40e_mac_filter_handle(dev, filter_op, arg);
7258 case RTE_ETH_FILTER_ETHERTYPE:
7259 ret = i40e_ethertype_filter_handle(dev, filter_op, arg);
7261 case RTE_ETH_FILTER_TUNNEL:
7262 ret = i40e_tunnel_filter_handle(dev, filter_op, arg);
7264 case RTE_ETH_FILTER_FDIR:
7265 ret = i40e_fdir_ctrl_func(dev, filter_op, arg);
7268 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
7278 * As some registers wouldn't be reset unless a global hardware reset,
7279 * hardware initialization is needed to put those registers into an
7280 * expected initial state.
7283 i40e_hw_init(struct i40e_hw *hw)
7285 /* clear the PF Queue Filter control register */
7286 I40E_WRITE_REG(hw, I40E_PFQF_CTL_0, 0);
7288 /* Disable symmetric hash per port */
7289 i40e_set_symmetric_hash_enable_per_port(hw, 0);
7292 enum i40e_filter_pctype
7293 i40e_flowtype_to_pctype(uint16_t flow_type)
7295 static const enum i40e_filter_pctype pctype_table[] = {
7296 [RTE_ETH_FLOW_FRAG_IPV4] = I40E_FILTER_PCTYPE_FRAG_IPV4,
7297 [RTE_ETH_FLOW_NONFRAG_IPV4_UDP] =
7298 I40E_FILTER_PCTYPE_NONF_IPV4_UDP,
7299 [RTE_ETH_FLOW_NONFRAG_IPV4_TCP] =
7300 I40E_FILTER_PCTYPE_NONF_IPV4_TCP,
7301 [RTE_ETH_FLOW_NONFRAG_IPV4_SCTP] =
7302 I40E_FILTER_PCTYPE_NONF_IPV4_SCTP,
7303 [RTE_ETH_FLOW_NONFRAG_IPV4_OTHER] =
7304 I40E_FILTER_PCTYPE_NONF_IPV4_OTHER,
7305 [RTE_ETH_FLOW_FRAG_IPV6] = I40E_FILTER_PCTYPE_FRAG_IPV6,
7306 [RTE_ETH_FLOW_NONFRAG_IPV6_UDP] =
7307 I40E_FILTER_PCTYPE_NONF_IPV6_UDP,
7308 [RTE_ETH_FLOW_NONFRAG_IPV6_TCP] =
7309 I40E_FILTER_PCTYPE_NONF_IPV6_TCP,
7310 [RTE_ETH_FLOW_NONFRAG_IPV6_SCTP] =
7311 I40E_FILTER_PCTYPE_NONF_IPV6_SCTP,
7312 [RTE_ETH_FLOW_NONFRAG_IPV6_OTHER] =
7313 I40E_FILTER_PCTYPE_NONF_IPV6_OTHER,
7314 [RTE_ETH_FLOW_L2_PAYLOAD] = I40E_FILTER_PCTYPE_L2_PAYLOAD,
7317 return pctype_table[flow_type];
7321 i40e_pctype_to_flowtype(enum i40e_filter_pctype pctype)
7323 static const uint16_t flowtype_table[] = {
7324 [I40E_FILTER_PCTYPE_FRAG_IPV4] = RTE_ETH_FLOW_FRAG_IPV4,
7325 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
7326 RTE_ETH_FLOW_NONFRAG_IPV4_UDP,
7327 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
7328 RTE_ETH_FLOW_NONFRAG_IPV4_TCP,
7329 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
7330 RTE_ETH_FLOW_NONFRAG_IPV4_SCTP,
7331 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
7332 RTE_ETH_FLOW_NONFRAG_IPV4_OTHER,
7333 [I40E_FILTER_PCTYPE_FRAG_IPV6] = RTE_ETH_FLOW_FRAG_IPV6,
7334 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
7335 RTE_ETH_FLOW_NONFRAG_IPV6_UDP,
7336 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
7337 RTE_ETH_FLOW_NONFRAG_IPV6_TCP,
7338 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
7339 RTE_ETH_FLOW_NONFRAG_IPV6_SCTP,
7340 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
7341 RTE_ETH_FLOW_NONFRAG_IPV6_OTHER,
7342 [I40E_FILTER_PCTYPE_L2_PAYLOAD] = RTE_ETH_FLOW_L2_PAYLOAD,
7345 return flowtype_table[pctype];
7349 * On X710, performance number is far from the expectation on recent firmware
7350 * versions; on XL710, performance number is also far from the expectation on
7351 * recent firmware versions, if promiscuous mode is disabled, or promiscuous
7352 * mode is enabled and port MAC address is equal to the packet destination MAC
7353 * address. The fix for this issue may not be integrated in the following
7354 * firmware version. So the workaround in software driver is needed. It needs
7355 * to modify the initial values of 3 internal only registers for both X710 and
7356 * XL710. Note that the values for X710 or XL710 could be different, and the
7357 * workaround can be removed when it is fixed in firmware in the future.
7360 /* For both X710 and XL710 */
7361 #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE 0x10000200
7362 #define I40E_GL_SWR_PRI_JOIN_MAP_0 0x26CE00
7364 #define I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x011f0200
7365 #define I40E_GL_SWR_PRI_JOIN_MAP_2 0x26CE08
7368 #define I40E_GL_SWR_PM_UP_THR_EF_VALUE 0x03030303
7370 #define I40E_GL_SWR_PM_UP_THR_SF_VALUE 0x06060606
7371 #define I40E_GL_SWR_PM_UP_THR 0x269FBC
7374 i40e_configure_registers(struct i40e_hw *hw)
7380 {I40E_GL_SWR_PRI_JOIN_MAP_0, I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE},
7381 {I40E_GL_SWR_PRI_JOIN_MAP_2, I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE},
7382 {I40E_GL_SWR_PM_UP_THR, 0}, /* Compute value dynamically */
7388 for (i = 0; i < RTE_DIM(reg_table); i++) {
7389 if (reg_table[i].addr == I40E_GL_SWR_PM_UP_THR) {
7390 if (i40e_is_40G_device(hw->device_id)) /* For XL710 */
7392 I40E_GL_SWR_PM_UP_THR_SF_VALUE;
7395 I40E_GL_SWR_PM_UP_THR_EF_VALUE;
7398 ret = i40e_aq_debug_read_register(hw, reg_table[i].addr,
7401 PMD_DRV_LOG(ERR, "Failed to read from 0x%"PRIx32,
7405 PMD_DRV_LOG(DEBUG, "Read from 0x%"PRIx32": 0x%"PRIx64,
7406 reg_table[i].addr, reg);
7407 if (reg == reg_table[i].val)
7410 ret = i40e_aq_debug_write_register(hw, reg_table[i].addr,
7411 reg_table[i].val, NULL);
7413 PMD_DRV_LOG(ERR, "Failed to write 0x%"PRIx64" to the "
7414 "address of 0x%"PRIx32, reg_table[i].val,
7418 PMD_DRV_LOG(DEBUG, "Write 0x%"PRIx64" to the address of "
7419 "0x%"PRIx32, reg_table[i].val, reg_table[i].addr);
7423 #define I40E_VSI_TSR(_i) (0x00050800 + ((_i) * 4))
7424 #define I40E_VSI_TSR_QINQ_CONFIG 0xc030
7425 #define I40E_VSI_L2TAGSTXVALID(_i) (0x00042800 + ((_i) * 4))
7426 #define I40E_VSI_L2TAGSTXVALID_QINQ 0xab
7428 i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi)
7433 if (vsi->vsi_id >= I40E_MAX_NUM_VSIS) {
7434 PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
7438 /* Configure for double VLAN RX stripping */
7439 reg = I40E_READ_REG(hw, I40E_VSI_TSR(vsi->vsi_id));
7440 if ((reg & I40E_VSI_TSR_QINQ_CONFIG) != I40E_VSI_TSR_QINQ_CONFIG) {
7441 reg |= I40E_VSI_TSR_QINQ_CONFIG;
7442 ret = i40e_aq_debug_write_register(hw,
7443 I40E_VSI_TSR(vsi->vsi_id),
7446 PMD_DRV_LOG(ERR, "Failed to update VSI_TSR[%d]",
7448 return I40E_ERR_CONFIG;
7452 /* Configure for double VLAN TX insertion */
7453 reg = I40E_READ_REG(hw, I40E_VSI_L2TAGSTXVALID(vsi->vsi_id));
7454 if ((reg & 0xff) != I40E_VSI_L2TAGSTXVALID_QINQ) {
7455 reg = I40E_VSI_L2TAGSTXVALID_QINQ;
7456 ret = i40e_aq_debug_write_register(hw,
7457 I40E_VSI_L2TAGSTXVALID(
7458 vsi->vsi_id), reg, NULL);
7460 PMD_DRV_LOG(ERR, "Failed to update "
7461 "VSI_L2TAGSTXVALID[%d]", vsi->vsi_id);
7462 return I40E_ERR_CONFIG;
7470 * i40e_aq_add_mirror_rule
7471 * @hw: pointer to the hardware structure
7472 * @seid: VEB seid to add mirror rule to
7473 * @dst_id: destination vsi seid
7474 * @entries: Buffer which contains the entities to be mirrored
7475 * @count: number of entities contained in the buffer
7476 * @rule_id:the rule_id of the rule to be added
7478 * Add a mirror rule for a given veb.
7481 static enum i40e_status_code
7482 i40e_aq_add_mirror_rule(struct i40e_hw *hw,
7483 uint16_t seid, uint16_t dst_id,
7484 uint16_t rule_type, uint16_t *entries,
7485 uint16_t count, uint16_t *rule_id)
7487 struct i40e_aq_desc desc;
7488 struct i40e_aqc_add_delete_mirror_rule cmd;
7489 struct i40e_aqc_add_delete_mirror_rule_completion *resp =
7490 (struct i40e_aqc_add_delete_mirror_rule_completion *)
7493 enum i40e_status_code status;
7495 i40e_fill_default_direct_cmd_desc(&desc,
7496 i40e_aqc_opc_add_mirror_rule);
7497 memset(&cmd, 0, sizeof(cmd));
7499 buff_len = sizeof(uint16_t) * count;
7500 desc.datalen = rte_cpu_to_le_16(buff_len);
7502 desc.flags |= rte_cpu_to_le_16(
7503 (uint16_t)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
7504 cmd.rule_type = rte_cpu_to_le_16(rule_type <<
7505 I40E_AQC_MIRROR_RULE_TYPE_SHIFT);
7506 cmd.num_entries = rte_cpu_to_le_16(count);
7507 cmd.seid = rte_cpu_to_le_16(seid);
7508 cmd.destination = rte_cpu_to_le_16(dst_id);
7510 rte_memcpy(&desc.params.raw, &cmd, sizeof(cmd));
7511 status = i40e_asq_send_command(hw, &desc, entries, buff_len, NULL);
7512 PMD_DRV_LOG(INFO, "i40e_aq_add_mirror_rule, aq_status %d,"
7514 " mirror_rules_used = %u, mirror_rules_free = %u,",
7515 hw->aq.asq_last_status, resp->rule_id,
7516 resp->mirror_rules_used, resp->mirror_rules_free);
7517 *rule_id = rte_le_to_cpu_16(resp->rule_id);
7523 * i40e_aq_del_mirror_rule
7524 * @hw: pointer to the hardware structure
7525 * @seid: VEB seid to add mirror rule to
7526 * @entries: Buffer which contains the entities to be mirrored
7527 * @count: number of entities contained in the buffer
7528 * @rule_id:the rule_id of the rule to be delete
7530 * Delete a mirror rule for a given veb.
7533 static enum i40e_status_code
7534 i40e_aq_del_mirror_rule(struct i40e_hw *hw,
7535 uint16_t seid, uint16_t rule_type, uint16_t *entries,
7536 uint16_t count, uint16_t rule_id)
7538 struct i40e_aq_desc desc;
7539 struct i40e_aqc_add_delete_mirror_rule cmd;
7540 uint16_t buff_len = 0;
7541 enum i40e_status_code status;
7544 i40e_fill_default_direct_cmd_desc(&desc,
7545 i40e_aqc_opc_delete_mirror_rule);
7546 memset(&cmd, 0, sizeof(cmd));
7547 if (rule_type == I40E_AQC_MIRROR_RULE_TYPE_VLAN) {
7548 desc.flags |= rte_cpu_to_le_16((uint16_t)(I40E_AQ_FLAG_BUF |
7550 cmd.num_entries = count;
7551 buff_len = sizeof(uint16_t) * count;
7552 desc.datalen = rte_cpu_to_le_16(buff_len);
7553 buff = (void *)entries;
7555 /* rule id is filled in destination field for deleting mirror rule */
7556 cmd.destination = rte_cpu_to_le_16(rule_id);
7558 cmd.rule_type = rte_cpu_to_le_16(rule_type <<
7559 I40E_AQC_MIRROR_RULE_TYPE_SHIFT);
7560 cmd.seid = rte_cpu_to_le_16(seid);
7562 rte_memcpy(&desc.params.raw, &cmd, sizeof(cmd));
7563 status = i40e_asq_send_command(hw, &desc, buff, buff_len, NULL);
7569 * i40e_mirror_rule_set
7570 * @dev: pointer to the hardware structure
7571 * @mirror_conf: mirror rule info
7572 * @sw_id: mirror rule's sw_id
7573 * @on: enable/disable
7575 * set a mirror rule.
7579 i40e_mirror_rule_set(struct rte_eth_dev *dev,
7580 struct rte_eth_mirror_conf *mirror_conf,
7581 uint8_t sw_id, uint8_t on)
7583 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7584 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7585 struct i40e_mirror_rule *it, *mirr_rule = NULL;
7586 struct i40e_mirror_rule *parent = NULL;
7587 uint16_t seid, dst_seid, rule_id;
7591 PMD_DRV_LOG(DEBUG, "i40e_mirror_rule_set: sw_id = %d.", sw_id);
7593 if (pf->main_vsi->veb == NULL || pf->vfs == NULL) {
7594 PMD_DRV_LOG(ERR, "mirror rule can not be configured"
7595 " without veb or vfs.");
7598 if (pf->nb_mirror_rule > I40E_MAX_MIRROR_RULES) {
7599 PMD_DRV_LOG(ERR, "mirror table is full.");
7602 if (mirror_conf->dst_pool > pf->vf_num) {
7603 PMD_DRV_LOG(ERR, "invalid destination pool %u.",
7604 mirror_conf->dst_pool);
7608 seid = pf->main_vsi->veb->seid;
7610 TAILQ_FOREACH(it, &pf->mirror_list, rules) {
7611 if (sw_id <= it->index) {
7617 if (mirr_rule && sw_id == mirr_rule->index) {
7619 PMD_DRV_LOG(ERR, "mirror rule exists.");
7622 ret = i40e_aq_del_mirror_rule(hw, seid,
7623 mirr_rule->rule_type,
7625 mirr_rule->num_entries, mirr_rule->id);
7627 PMD_DRV_LOG(ERR, "failed to remove mirror rule:"
7628 " ret = %d, aq_err = %d.",
7629 ret, hw->aq.asq_last_status);
7632 TAILQ_REMOVE(&pf->mirror_list, mirr_rule, rules);
7633 rte_free(mirr_rule);
7634 pf->nb_mirror_rule--;
7638 PMD_DRV_LOG(ERR, "mirror rule doesn't exist.");
7642 mirr_rule = rte_zmalloc("i40e_mirror_rule",
7643 sizeof(struct i40e_mirror_rule) , 0);
7645 PMD_DRV_LOG(ERR, "failed to allocate memory");
7646 return I40E_ERR_NO_MEMORY;
7648 switch (mirror_conf->rule_type) {
7649 case ETH_MIRROR_VLAN:
7650 for (i = 0, j = 0; i < ETH_MIRROR_MAX_VLANS; i++) {
7651 if (mirror_conf->vlan.vlan_mask & (1ULL << i)) {
7652 mirr_rule->entries[j] =
7653 mirror_conf->vlan.vlan_id[i];
7658 PMD_DRV_LOG(ERR, "vlan is not specified.");
7659 rte_free(mirr_rule);
7662 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_VLAN;
7664 case ETH_MIRROR_VIRTUAL_POOL_UP:
7665 case ETH_MIRROR_VIRTUAL_POOL_DOWN:
7666 /* check if the specified pool bit is out of range */
7667 if (mirror_conf->pool_mask > (uint64_t)(1ULL << (pf->vf_num + 1))) {
7668 PMD_DRV_LOG(ERR, "pool mask is out of range.");
7669 rte_free(mirr_rule);
7672 for (i = 0, j = 0; i < pf->vf_num; i++) {
7673 if (mirror_conf->pool_mask & (1ULL << i)) {
7674 mirr_rule->entries[j] = pf->vfs[i].vsi->seid;
7678 if (mirror_conf->pool_mask & (1ULL << pf->vf_num)) {
7679 /* add pf vsi to entries */
7680 mirr_rule->entries[j] = pf->main_vsi_seid;
7684 PMD_DRV_LOG(ERR, "pool is not specified.");
7685 rte_free(mirr_rule);
7688 /* egress and ingress in aq commands means from switch but not port */
7689 mirr_rule->rule_type =
7690 (mirror_conf->rule_type == ETH_MIRROR_VIRTUAL_POOL_UP) ?
7691 I40E_AQC_MIRROR_RULE_TYPE_VPORT_EGRESS :
7692 I40E_AQC_MIRROR_RULE_TYPE_VPORT_INGRESS;
7694 case ETH_MIRROR_UPLINK_PORT:
7695 /* egress and ingress in aq commands means from switch but not port*/
7696 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_ALL_EGRESS;
7698 case ETH_MIRROR_DOWNLINK_PORT:
7699 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_ALL_INGRESS;
7702 PMD_DRV_LOG(ERR, "unsupported mirror type %d.",
7703 mirror_conf->rule_type);
7704 rte_free(mirr_rule);
7708 /* If the dst_pool is equal to vf_num, consider it as PF */
7709 if (mirror_conf->dst_pool == pf->vf_num)
7710 dst_seid = pf->main_vsi_seid;
7712 dst_seid = pf->vfs[mirror_conf->dst_pool].vsi->seid;
7714 ret = i40e_aq_add_mirror_rule(hw, seid, dst_seid,
7715 mirr_rule->rule_type, mirr_rule->entries,
7718 PMD_DRV_LOG(ERR, "failed to add mirror rule:"
7719 " ret = %d, aq_err = %d.",
7720 ret, hw->aq.asq_last_status);
7721 rte_free(mirr_rule);
7725 mirr_rule->index = sw_id;
7726 mirr_rule->num_entries = j;
7727 mirr_rule->id = rule_id;
7728 mirr_rule->dst_vsi_seid = dst_seid;
7731 TAILQ_INSERT_AFTER(&pf->mirror_list, parent, mirr_rule, rules);
7733 TAILQ_INSERT_HEAD(&pf->mirror_list, mirr_rule, rules);
7735 pf->nb_mirror_rule++;
7740 * i40e_mirror_rule_reset
7741 * @dev: pointer to the device
7742 * @sw_id: mirror rule's sw_id
7744 * reset a mirror rule.
7748 i40e_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t sw_id)
7750 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7751 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7752 struct i40e_mirror_rule *it, *mirr_rule = NULL;
7756 PMD_DRV_LOG(DEBUG, "i40e_mirror_rule_reset: sw_id = %d.", sw_id);
7758 seid = pf->main_vsi->veb->seid;
7760 TAILQ_FOREACH(it, &pf->mirror_list, rules) {
7761 if (sw_id == it->index) {
7767 ret = i40e_aq_del_mirror_rule(hw, seid,
7768 mirr_rule->rule_type,
7770 mirr_rule->num_entries, mirr_rule->id);
7772 PMD_DRV_LOG(ERR, "failed to remove mirror rule:"
7773 " status = %d, aq_err = %d.",
7774 ret, hw->aq.asq_last_status);
7777 TAILQ_REMOVE(&pf->mirror_list, mirr_rule, rules);
7778 rte_free(mirr_rule);
7779 pf->nb_mirror_rule--;
7781 PMD_DRV_LOG(ERR, "mirror rule doesn't exist.");
7788 i40e_read_systime_cyclecounter(struct rte_eth_dev *dev)
7790 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7791 uint64_t systim_cycles;
7793 systim_cycles = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_L);
7794 systim_cycles |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_H)
7797 return systim_cycles;
7801 i40e_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev, uint8_t index)
7803 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7806 rx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_L(index));
7807 rx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(index))
7814 i40e_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
7816 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7819 tx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_L);
7820 tx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H)
7827 i40e_start_timecounters(struct rte_eth_dev *dev)
7829 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7830 struct i40e_adapter *adapter =
7831 (struct i40e_adapter *)dev->data->dev_private;
7832 struct rte_eth_link link;
7833 uint32_t tsync_inc_l;
7834 uint32_t tsync_inc_h;
7836 /* Get current link speed. */
7837 memset(&link, 0, sizeof(link));
7838 i40e_dev_link_update(dev, 1);
7839 rte_i40e_dev_atomic_read_link_status(dev, &link);
7841 switch (link.link_speed) {
7842 case ETH_LINK_SPEED_40G:
7843 tsync_inc_l = I40E_PTP_40GB_INCVAL & 0xFFFFFFFF;
7844 tsync_inc_h = I40E_PTP_40GB_INCVAL >> 32;
7846 case ETH_LINK_SPEED_10G:
7847 tsync_inc_l = I40E_PTP_10GB_INCVAL & 0xFFFFFFFF;
7848 tsync_inc_h = I40E_PTP_10GB_INCVAL >> 32;
7850 case ETH_LINK_SPEED_1000:
7851 tsync_inc_l = I40E_PTP_1GB_INCVAL & 0xFFFFFFFF;
7852 tsync_inc_h = I40E_PTP_1GB_INCVAL >> 32;
7859 /* Set the timesync increment value. */
7860 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, tsync_inc_l);
7861 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, tsync_inc_h);
7863 memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
7864 memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
7865 memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
7867 adapter->systime_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
7868 adapter->systime_tc.cc_shift = 0;
7869 adapter->systime_tc.nsec_mask = 0;
7871 adapter->rx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
7872 adapter->rx_tstamp_tc.cc_shift = 0;
7873 adapter->rx_tstamp_tc.nsec_mask = 0;
7875 adapter->tx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
7876 adapter->tx_tstamp_tc.cc_shift = 0;
7877 adapter->tx_tstamp_tc.nsec_mask = 0;
7881 i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
7883 struct i40e_adapter *adapter =
7884 (struct i40e_adapter *)dev->data->dev_private;
7886 adapter->systime_tc.nsec += delta;
7887 adapter->rx_tstamp_tc.nsec += delta;
7888 adapter->tx_tstamp_tc.nsec += delta;
7894 i40e_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
7897 struct i40e_adapter *adapter =
7898 (struct i40e_adapter *)dev->data->dev_private;
7900 ns = rte_timespec_to_ns(ts);
7902 /* Set the timecounters to a new value. */
7903 adapter->systime_tc.nsec = ns;
7904 adapter->rx_tstamp_tc.nsec = ns;
7905 adapter->tx_tstamp_tc.nsec = ns;
7911 i40e_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
7913 uint64_t ns, systime_cycles;
7914 struct i40e_adapter *adapter =
7915 (struct i40e_adapter *)dev->data->dev_private;
7917 systime_cycles = i40e_read_systime_cyclecounter(dev);
7918 ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
7919 *ts = rte_ns_to_timespec(ns);
7925 i40e_timesync_enable(struct rte_eth_dev *dev)
7927 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7928 uint32_t tsync_ctl_l;
7929 uint32_t tsync_ctl_h;
7931 /* Stop the timesync system time. */
7932 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
7933 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
7934 /* Reset the timesync system time value. */
7935 I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_L, 0x0);
7936 I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_H, 0x0);
7938 i40e_start_timecounters(dev);
7940 /* Clear timesync registers. */
7941 I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
7942 I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H);
7943 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(0));
7944 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(1));
7945 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(2));
7946 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(3));
7948 /* Enable timestamping of PTP packets. */
7949 tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
7950 tsync_ctl_l |= I40E_PRTTSYN_TSYNENA;
7952 tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
7953 tsync_ctl_h |= I40E_PRTTSYN_TSYNENA;
7954 tsync_ctl_h |= I40E_PRTTSYN_TSYNTYPE;
7956 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
7957 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
7963 i40e_timesync_disable(struct rte_eth_dev *dev)
7965 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7966 uint32_t tsync_ctl_l;
7967 uint32_t tsync_ctl_h;
7969 /* Disable timestamping of transmitted PTP packets. */
7970 tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
7971 tsync_ctl_l &= ~I40E_PRTTSYN_TSYNENA;
7973 tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
7974 tsync_ctl_h &= ~I40E_PRTTSYN_TSYNENA;
7976 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
7977 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
7979 /* Reset the timesync increment value. */
7980 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
7981 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
7987 i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
7988 struct timespec *timestamp, uint32_t flags)
7990 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7991 struct i40e_adapter *adapter =
7992 (struct i40e_adapter *)dev->data->dev_private;
7994 uint32_t sync_status;
7995 uint32_t index = flags & 0x03;
7996 uint64_t rx_tstamp_cycles;
7999 sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_1);
8000 if ((sync_status & (1 << index)) == 0)
8003 rx_tstamp_cycles = i40e_read_rx_tstamp_cyclecounter(dev, index);
8004 ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
8005 *timestamp = rte_ns_to_timespec(ns);
8011 i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
8012 struct timespec *timestamp)
8014 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8015 struct i40e_adapter *adapter =
8016 (struct i40e_adapter *)dev->data->dev_private;
8018 uint32_t sync_status;
8019 uint64_t tx_tstamp_cycles;
8022 sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
8023 if ((sync_status & I40E_PRTTSYN_STAT_0_TXTIME_MASK) == 0)
8026 tx_tstamp_cycles = i40e_read_tx_tstamp_cyclecounter(dev);
8027 ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
8028 *timestamp = rte_ns_to_timespec(ns);
8034 * i40e_parse_dcb_configure - parse dcb configure from user
8035 * @dev: the device being configured
8036 * @dcb_cfg: pointer of the result of parse
8037 * @*tc_map: bit map of enabled traffic classes
8039 * Returns 0 on success, negative value on failure
8042 i40e_parse_dcb_configure(struct rte_eth_dev *dev,
8043 struct i40e_dcbx_config *dcb_cfg,
8046 struct rte_eth_dcb_rx_conf *dcb_rx_conf;
8047 uint8_t i, tc_bw, bw_lf;
8049 memset(dcb_cfg, 0, sizeof(struct i40e_dcbx_config));
8051 dcb_rx_conf = &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
8052 if (dcb_rx_conf->nb_tcs > I40E_MAX_TRAFFIC_CLASS) {
8053 PMD_INIT_LOG(ERR, "number of tc exceeds max.");
8057 /* assume each tc has the same bw */
8058 tc_bw = I40E_MAX_PERCENT / dcb_rx_conf->nb_tcs;
8059 for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
8060 dcb_cfg->etscfg.tcbwtable[i] = tc_bw;
8061 /* to ensure the sum of tcbw is equal to 100 */
8062 bw_lf = I40E_MAX_PERCENT % dcb_rx_conf->nb_tcs;
8063 for (i = 0; i < bw_lf; i++)
8064 dcb_cfg->etscfg.tcbwtable[i]++;
8066 /* assume each tc has the same Transmission Selection Algorithm */
8067 for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
8068 dcb_cfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
8070 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
8071 dcb_cfg->etscfg.prioritytable[i] =
8072 dcb_rx_conf->dcb_tc[i];
8074 /* FW needs one App to configure HW */
8075 dcb_cfg->numapps = I40E_DEFAULT_DCB_APP_NUM;
8076 dcb_cfg->app[0].selector = I40E_APP_SEL_ETHTYPE;
8077 dcb_cfg->app[0].priority = I40E_DEFAULT_DCB_APP_PRIO;
8078 dcb_cfg->app[0].protocolid = I40E_APP_PROTOID_FCOE;
8080 if (dcb_rx_conf->nb_tcs == 0)
8081 *tc_map = 1; /* tc0 only */
8083 *tc_map = RTE_LEN2MASK(dcb_rx_conf->nb_tcs, uint8_t);
8085 if (dev->data->dev_conf.dcb_capability_en & ETH_DCB_PFC_SUPPORT) {
8086 dcb_cfg->pfc.willing = 0;
8087 dcb_cfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
8088 dcb_cfg->pfc.pfcenable = *tc_map;
8094 * i40e_vsi_get_bw_info - Query VSI BW Information
8095 * @vsi: the VSI being queried
8097 * Returns 0 on success, negative value on failure
8099 static enum i40e_status_code
8100 i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
8102 struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
8103 struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
8104 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
8105 enum i40e_status_code ret;
8109 /* Get the VSI level BW configuration */
8110 ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
8113 "couldn't get PF vsi bw config, err %s aq_err %s\n",
8114 i40e_stat_str(hw, ret),
8115 i40e_aq_str(hw, hw->aq.asq_last_status));
8119 /* Get the VSI level BW configuration per TC */
8120 ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
8124 "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
8125 i40e_stat_str(hw, ret),
8126 i40e_aq_str(hw, hw->aq.asq_last_status));
8130 if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
8131 PMD_INIT_LOG(WARNING,
8132 "Enabled TCs mismatch from querying VSI BW info"
8133 " 0x%08x 0x%08x\n", bw_config.tc_valid_bits,
8134 bw_ets_config.tc_valid_bits);
8135 /* Still continuing */
8138 vsi->bw_info.bw_limit = rte_le_to_cpu_16(bw_config.port_bw_limit);
8139 vsi->bw_info.bw_max_quanta = bw_config.max_bw;
8140 tc_bw_max = rte_le_to_cpu_16(bw_ets_config.tc_bw_max[0]) |
8141 (rte_le_to_cpu_16(bw_ets_config.tc_bw_max[1]) << 16);
8142 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
8143 vsi->bw_info.bw_ets_share_credits[i] =
8144 bw_ets_config.share_credits[i];
8145 vsi->bw_info.bw_ets_limit_credits[i] =
8146 rte_le_to_cpu_16(bw_ets_config.credits[i]);
8147 /* 3 bits out of 4 for each TC */
8148 vsi->bw_info.bw_ets_max_quanta[i] =
8149 (uint8_t)((tc_bw_max >> (i * 4)) & 0x7);
8151 "%s: vsi seid = %d, TC = %d, qset = 0x%x\n",
8152 __func__, vsi->seid, i, bw_config.qs_handles[i]);
8158 static enum i40e_status_code
8159 i40e_vsi_update_queue_mapping(struct i40e_vsi *vsi,
8160 struct i40e_aqc_vsi_properties_data *info,
8161 uint8_t enabled_tcmap)
8163 enum i40e_status_code ret;
8164 int i, total_tc = 0;
8165 uint16_t qpnum_per_tc, bsf, qp_idx;
8166 struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(vsi);
8168 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
8169 if (ret != I40E_SUCCESS)
8172 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
8173 if (enabled_tcmap & (1 << i))
8178 vsi->enabled_tc = enabled_tcmap;
8180 qpnum_per_tc = dev_data->nb_rx_queues / total_tc;
8181 /* Number of queues per enabled TC */
8182 if (qpnum_per_tc == 0) {
8183 PMD_INIT_LOG(ERR, " number of queues is less that tcs.");
8184 return I40E_ERR_INVALID_QP_ID;
8186 qpnum_per_tc = RTE_MIN(i40e_align_floor(qpnum_per_tc),
8188 bsf = rte_bsf32(qpnum_per_tc);
8191 * Configure TC and queue mapping parameters, for enabled TC,
8192 * allocate qpnum_per_tc queues to this traffic. For disabled TC,
8193 * default queue will serve it.
8196 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
8197 if (vsi->enabled_tc & (1 << i)) {
8198 info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
8199 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
8200 (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
8201 qp_idx += qpnum_per_tc;
8203 info->tc_mapping[i] = 0;
8206 /* Associate queue number with VSI, Keep vsi->nb_qps unchanged */
8207 if (vsi->type == I40E_VSI_SRIOV) {
8208 info->mapping_flags |=
8209 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
8210 for (i = 0; i < vsi->nb_qps; i++)
8211 info->queue_mapping[i] =
8212 rte_cpu_to_le_16(vsi->base_queue + i);
8214 info->mapping_flags |=
8215 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
8216 info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
8218 info->valid_sections |=
8219 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
8221 return I40E_SUCCESS;
8225 * i40e_vsi_config_tc - Configure VSI tc setting for given TC map
8226 * @vsi: VSI to be configured
8227 * @tc_map: enabled TC bitmap
8229 * Returns 0 on success, negative value on failure
8231 static enum i40e_status_code
8232 i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 tc_map)
8234 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
8235 struct i40e_vsi_context ctxt;
8236 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
8237 enum i40e_status_code ret = I40E_SUCCESS;
8240 /* Check if enabled_tc is same as existing or new TCs */
8241 if (vsi->enabled_tc == tc_map)
8244 /* configure tc bandwidth */
8245 memset(&bw_data, 0, sizeof(bw_data));
8246 bw_data.tc_valid_bits = tc_map;
8247 /* Enable ETS TCs with equal BW Share for now across all VSIs */
8248 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
8249 if (tc_map & BIT_ULL(i))
8250 bw_data.tc_bw_credits[i] = 1;
8252 ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &bw_data, NULL);
8254 PMD_INIT_LOG(ERR, "AQ command Config VSI BW allocation"
8255 " per TC failed = %d",
8256 hw->aq.asq_last_status);
8259 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
8260 vsi->info.qs_handle[i] = bw_data.qs_handles[i];
8262 /* Update Queue Pairs Mapping for currently enabled UPs */
8263 ctxt.seid = vsi->seid;
8264 ctxt.pf_num = hw->pf_id;
8266 ctxt.uplink_seid = vsi->uplink_seid;
8267 ctxt.info = vsi->info;
8269 ret = i40e_vsi_update_queue_mapping(vsi, &ctxt.info, tc_map);
8273 /* Update the VSI after updating the VSI queue-mapping information */
8274 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
8276 PMD_INIT_LOG(ERR, "Failed to configure "
8277 "TC queue mapping = %d",
8278 hw->aq.asq_last_status);
8281 /* update the local VSI info with updated queue map */
8282 (void)rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
8283 sizeof(vsi->info.tc_mapping));
8284 (void)rte_memcpy(&vsi->info.queue_mapping,
8285 &ctxt.info.queue_mapping,
8286 sizeof(vsi->info.queue_mapping));
8287 vsi->info.mapping_flags = ctxt.info.mapping_flags;
8288 vsi->info.valid_sections = 0;
8290 /* Update current VSI BW information */
8291 ret = i40e_vsi_get_bw_info(vsi);
8294 "Failed updating vsi bw info, err %s aq_err %s",
8295 i40e_stat_str(hw, ret),
8296 i40e_aq_str(hw, hw->aq.asq_last_status));
8300 vsi->enabled_tc = tc_map;
8307 * i40e_dcb_hw_configure - program the dcb setting to hw
8308 * @pf: pf the configuration is taken on
8309 * @new_cfg: new configuration
8310 * @tc_map: enabled TC bitmap
8312 * Returns 0 on success, negative value on failure
8314 static enum i40e_status_code
8315 i40e_dcb_hw_configure(struct i40e_pf *pf,
8316 struct i40e_dcbx_config *new_cfg,
8319 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8320 struct i40e_dcbx_config *old_cfg = &hw->local_dcbx_config;
8321 struct i40e_vsi *main_vsi = pf->main_vsi;
8322 struct i40e_vsi_list *vsi_list;
8323 enum i40e_status_code ret;
8327 /* Use the FW API if FW > v4.4*/
8328 if (!((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver >= 4))) {
8329 PMD_INIT_LOG(ERR, "FW < v4.4, can not use FW LLDP API"
8330 " to configure DCB");
8331 return I40E_ERR_FIRMWARE_API_VERSION;
8334 /* Check if need reconfiguration */
8335 if (!memcmp(new_cfg, old_cfg, sizeof(struct i40e_dcbx_config))) {
8336 PMD_INIT_LOG(ERR, "No Change in DCB Config required.");
8337 return I40E_SUCCESS;
8340 /* Copy the new config to the current config */
8341 *old_cfg = *new_cfg;
8342 old_cfg->etsrec = old_cfg->etscfg;
8343 ret = i40e_set_dcb_config(hw);
8346 "Set DCB Config failed, err %s aq_err %s\n",
8347 i40e_stat_str(hw, ret),
8348 i40e_aq_str(hw, hw->aq.asq_last_status));
8351 /* set receive Arbiter to RR mode and ETS scheme by default */
8352 for (i = 0; i <= I40E_PRTDCB_RETSTCC_MAX_INDEX; i++) {
8353 val = I40E_READ_REG(hw, I40E_PRTDCB_RETSTCC(i));
8354 val &= ~(I40E_PRTDCB_RETSTCC_BWSHARE_MASK |
8355 I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK |
8356 I40E_PRTDCB_RETSTCC_ETSTC_SHIFT);
8357 val |= ((uint32_t)old_cfg->etscfg.tcbwtable[i] <<
8358 I40E_PRTDCB_RETSTCC_BWSHARE_SHIFT) &
8359 I40E_PRTDCB_RETSTCC_BWSHARE_MASK;
8360 val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_UPINTC_MODE_SHIFT) &
8361 I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK;
8362 val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_ETSTC_SHIFT) &
8363 I40E_PRTDCB_RETSTCC_ETSTC_MASK;
8364 I40E_WRITE_REG(hw, I40E_PRTDCB_RETSTCC(i), val);
8366 /* get local mib to check whether it is configured correctly */
8368 hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_IEEE;
8369 /* Get Local DCB Config */
8370 i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
8371 &hw->local_dcbx_config);
8373 /* Update each VSI */
8374 i40e_vsi_config_tc(main_vsi, tc_map);
8375 if (main_vsi->veb) {
8376 TAILQ_FOREACH(vsi_list, &main_vsi->veb->head, list) {
8377 /* Beside main VSI, only enable default
8380 ret = i40e_vsi_config_tc(vsi_list->vsi,
8381 I40E_DEFAULT_TCMAP);
8383 PMD_INIT_LOG(WARNING,
8384 "Failed configuring TC for VSI seid=%d\n",
8385 vsi_list->vsi->seid);
8389 return I40E_SUCCESS;
8393 * i40e_dcb_init_configure - initial dcb config
8394 * @dev: device being configured
8395 * @sw_dcb: indicate whether dcb is sw configured or hw offload
8397 * Returns 0 on success, negative value on failure
8400 i40e_dcb_init_configure(struct rte_eth_dev *dev, bool sw_dcb)
8402 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8403 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8406 if ((pf->flags & I40E_FLAG_DCB) == 0) {
8407 PMD_INIT_LOG(ERR, "HW doesn't support DCB");
8411 /* DCB initialization:
8412 * Update DCB configuration from the Firmware and configure
8413 * LLDP MIB change event.
8415 if (sw_dcb == TRUE) {
8416 ret = i40e_aq_stop_lldp(hw, TRUE, NULL);
8417 if (ret != I40E_SUCCESS)
8418 PMD_INIT_LOG(DEBUG, "Failed to stop lldp");
8420 ret = i40e_init_dcb(hw);
8421 /* if sw_dcb, lldp agent is stopped, the return from
8422 * i40e_init_dcb we expect is failure with I40E_AQ_RC_EPERM
8425 if (ret != I40E_SUCCESS &&
8426 hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
8427 memset(&hw->local_dcbx_config, 0,
8428 sizeof(struct i40e_dcbx_config));
8429 /* set dcb default configuration */
8430 hw->local_dcbx_config.etscfg.willing = 0;
8431 hw->local_dcbx_config.etscfg.maxtcs = 0;
8432 hw->local_dcbx_config.etscfg.tcbwtable[0] = 100;
8433 hw->local_dcbx_config.etscfg.tsatable[0] =
8435 hw->local_dcbx_config.etsrec =
8436 hw->local_dcbx_config.etscfg;
8437 hw->local_dcbx_config.pfc.willing = 0;
8438 hw->local_dcbx_config.pfc.pfccap =
8439 I40E_MAX_TRAFFIC_CLASS;
8440 /* FW needs one App to configure HW */
8441 hw->local_dcbx_config.numapps = 1;
8442 hw->local_dcbx_config.app[0].selector =
8443 I40E_APP_SEL_ETHTYPE;
8444 hw->local_dcbx_config.app[0].priority = 3;
8445 hw->local_dcbx_config.app[0].protocolid =
8446 I40E_APP_PROTOID_FCOE;
8447 ret = i40e_set_dcb_config(hw);
8449 PMD_INIT_LOG(ERR, "default dcb config fails."
8450 " err = %d, aq_err = %d.", ret,
8451 hw->aq.asq_last_status);
8455 PMD_INIT_LOG(ERR, "DCBX configuration failed, err = %d,"
8456 " aq_err = %d.", ret,
8457 hw->aq.asq_last_status);
8461 ret = i40e_aq_start_lldp(hw, NULL);
8462 if (ret != I40E_SUCCESS)
8463 PMD_INIT_LOG(DEBUG, "Failed to start lldp");
8465 ret = i40e_init_dcb(hw);
8467 if (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED) {
8468 PMD_INIT_LOG(ERR, "HW doesn't support"
8473 PMD_INIT_LOG(ERR, "DCBX configuration failed, err = %d,"
8474 " aq_err = %d.", ret,
8475 hw->aq.asq_last_status);
8483 * i40e_dcb_setup - setup dcb related config
8484 * @dev: device being configured
8486 * Returns 0 on success, negative value on failure
8489 i40e_dcb_setup(struct rte_eth_dev *dev)
8491 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8492 struct i40e_dcbx_config dcb_cfg;
8496 if ((pf->flags & I40E_FLAG_DCB) == 0) {
8497 PMD_INIT_LOG(ERR, "HW doesn't support DCB");
8501 if (pf->vf_num != 0 ||
8502 (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG))
8503 PMD_INIT_LOG(DEBUG, " DCB only works on main vsi.");
8505 ret = i40e_parse_dcb_configure(dev, &dcb_cfg, &tc_map);
8507 PMD_INIT_LOG(ERR, "invalid dcb config");
8510 ret = i40e_dcb_hw_configure(pf, &dcb_cfg, tc_map);
8512 PMD_INIT_LOG(ERR, "dcb sw configure fails");
8520 i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
8521 struct rte_eth_dcb_info *dcb_info)
8523 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8524 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8525 struct i40e_vsi *vsi = pf->main_vsi;
8526 struct i40e_dcbx_config *dcb_cfg = &hw->local_dcbx_config;
8527 uint16_t bsf, tc_mapping;
8530 if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_DCB_FLAG)
8531 dcb_info->nb_tcs = rte_bsf32(vsi->enabled_tc + 1);
8533 dcb_info->nb_tcs = 1;
8534 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
8535 dcb_info->prio_tc[i] = dcb_cfg->etscfg.prioritytable[i];
8536 for (i = 0; i < dcb_info->nb_tcs; i++)
8537 dcb_info->tc_bws[i] = dcb_cfg->etscfg.tcbwtable[i];
8539 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
8540 if (vsi->enabled_tc & (1 << i)) {
8541 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
8542 /* only main vsi support multi TCs */
8543 dcb_info->tc_queue.tc_rxq[0][i].base =
8544 (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
8545 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
8546 dcb_info->tc_queue.tc_txq[0][i].base =
8547 dcb_info->tc_queue.tc_rxq[0][i].base;
8548 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
8549 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
8550 dcb_info->tc_queue.tc_rxq[0][i].nb_queue = 1 << bsf;
8551 dcb_info->tc_queue.tc_txq[0][i].nb_queue =
8552 dcb_info->tc_queue.tc_rxq[0][i].nb_queue;
8560 i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
8562 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
8563 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8565 i40e_calc_itr_interval(RTE_LIBRTE_I40E_ITR_INTERVAL);
8568 msix_intr = intr_handle->intr_vec[queue_id];
8569 if (msix_intr == I40E_MISC_VEC_ID)
8570 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
8571 I40E_PFINT_DYN_CTLN_INTENA_MASK |
8572 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
8573 (0 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT) |
8575 I40E_PFINT_DYN_CTLN_INTERVAL_SHIFT));
8578 I40E_PFINT_DYN_CTLN(msix_intr -
8580 I40E_PFINT_DYN_CTLN_INTENA_MASK |
8581 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
8582 (0 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT) |
8584 I40E_PFINT_DYN_CTLN_INTERVAL_SHIFT));
8586 I40E_WRITE_FLUSH(hw);
8587 rte_intr_enable(&dev->pci_dev->intr_handle);
8593 i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
8595 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
8596 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8599 msix_intr = intr_handle->intr_vec[queue_id];
8600 if (msix_intr == I40E_MISC_VEC_ID)
8601 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0, 0);
8604 I40E_PFINT_DYN_CTLN(msix_intr -
8607 I40E_WRITE_FLUSH(hw);