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 0xffffffffffffffffULL
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_INSET_NONE 0x00000000000000000ULL
143 #define I40E_INSET_DMAC 0x0000000000000001ULL
144 #define I40E_INSET_SMAC 0x0000000000000002ULL
145 #define I40E_INSET_VLAN_OUTER 0x0000000000000004ULL
146 #define I40E_INSET_VLAN_INNER 0x0000000000000008ULL
147 #define I40E_INSET_VLAN_TUNNEL 0x0000000000000010ULL
150 #define I40E_INSET_IPV4_SRC 0x0000000000000100ULL
151 #define I40E_INSET_IPV4_DST 0x0000000000000200ULL
152 #define I40E_INSET_IPV6_SRC 0x0000000000000400ULL
153 #define I40E_INSET_IPV6_DST 0x0000000000000800ULL
154 #define I40E_INSET_SRC_PORT 0x0000000000001000ULL
155 #define I40E_INSET_DST_PORT 0x0000000000002000ULL
156 #define I40E_INSET_SCTP_VT 0x0000000000004000ULL
158 /* bit 16 ~ bit 31 */
159 #define I40E_INSET_IPV4_TOS 0x0000000000010000ULL
160 #define I40E_INSET_IPV4_PROTO 0x0000000000020000ULL
161 #define I40E_INSET_IPV4_TTL 0x0000000000040000ULL
162 #define I40E_INSET_IPV6_TC 0x0000000000080000ULL
163 #define I40E_INSET_IPV6_FLOW 0x0000000000100000ULL
164 #define I40E_INSET_IPV6_NEXT_HDR 0x0000000000200000ULL
165 #define I40E_INSET_IPV6_HOP_LIMIT 0x0000000000400000ULL
166 #define I40E_INSET_TCP_FLAGS 0x0000000000800000ULL
168 /* bit 32 ~ bit 47, tunnel fields */
169 #define I40E_INSET_TUNNEL_IPV4_DST 0x0000000100000000ULL
170 #define I40E_INSET_TUNNEL_IPV6_DST 0x0000000200000000ULL
171 #define I40E_INSET_TUNNEL_DMAC 0x0000000400000000ULL
172 #define I40E_INSET_TUNNEL_SRC_PORT 0x0000000800000000ULL
173 #define I40E_INSET_TUNNEL_DST_PORT 0x0000001000000000ULL
174 #define I40E_INSET_TUNNEL_ID 0x0000002000000000ULL
176 /* bit 48 ~ bit 55 */
177 #define I40E_INSET_LAST_ETHER_TYPE 0x0001000000000000ULL
179 /* bit 56 ~ bit 63, Flex Payload */
180 #define I40E_INSET_FLEX_PAYLOAD_W1 0x0100000000000000ULL
181 #define I40E_INSET_FLEX_PAYLOAD_W2 0x0200000000000000ULL
182 #define I40E_INSET_FLEX_PAYLOAD_W3 0x0400000000000000ULL
183 #define I40E_INSET_FLEX_PAYLOAD_W4 0x0800000000000000ULL
184 #define I40E_INSET_FLEX_PAYLOAD_W5 0x1000000000000000ULL
185 #define I40E_INSET_FLEX_PAYLOAD_W6 0x2000000000000000ULL
186 #define I40E_INSET_FLEX_PAYLOAD_W7 0x4000000000000000ULL
187 #define I40E_INSET_FLEX_PAYLOAD_W8 0x8000000000000000ULL
188 #define I40E_INSET_FLEX_PAYLOAD \
189 (I40E_INSET_FLEX_PAYLOAD_W1 | I40E_INSET_FLEX_PAYLOAD_W2 | \
190 I40E_INSET_FLEX_PAYLOAD_W3 | I40E_INSET_FLEX_PAYLOAD_W4 | \
191 I40E_INSET_FLEX_PAYLOAD_W5 | I40E_INSET_FLEX_PAYLOAD_W6 | \
192 I40E_INSET_FLEX_PAYLOAD_W7 | I40E_INSET_FLEX_PAYLOAD_W8)
195 * Below are values for writing un-exposed registers suggested
198 /* Destination MAC address */
199 #define I40E_REG_INSET_L2_DMAC 0xE000000000000000ULL
200 /* Source MAC address */
201 #define I40E_REG_INSET_L2_SMAC 0x1C00000000000000ULL
202 /* VLAN tag in the outer L2 header */
203 #define I40E_REG_INSET_L2_OUTER_VLAN 0x0080000000000000ULL
204 /* VLAN tag in the inner L2 header */
205 #define I40E_REG_INSET_L2_INNER_VLAN 0x0100000000000000ULL
206 /* Source IPv4 address */
207 #define I40E_REG_INSET_L3_SRC_IP4 0x0001800000000000ULL
208 /* Destination IPv4 address */
209 #define I40E_REG_INSET_L3_DST_IP4 0x0000001800000000ULL
210 /* IPv4 Type of Service (TOS) */
211 #define I40E_REG_INSET_L3_IP4_TOS 0x0040000000000000ULL
213 #define I40E_REG_INSET_L3_IP4_PROTO 0x0004000000000000ULL
214 /* Source IPv6 address */
215 #define I40E_REG_INSET_L3_SRC_IP6 0x0007F80000000000ULL
216 /* Destination IPv6 address */
217 #define I40E_REG_INSET_L3_DST_IP6 0x000007F800000000ULL
218 /* IPv6 Traffic Class (TC) */
219 #define I40E_REG_INSET_L3_IP6_TC 0x0040000000000000ULL
220 /* IPv6 Next Header */
221 #define I40E_REG_INSET_L3_IP6_NEXT_HDR 0x0008000000000000ULL
223 #define I40E_REG_INSET_L4_SRC_PORT 0x0000000400000000ULL
224 /* Destination L4 port */
225 #define I40E_REG_INSET_L4_DST_PORT 0x0000000200000000ULL
226 /* SCTP verification tag */
227 #define I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG 0x0000000180000000ULL
228 /* Inner destination MAC address (MAC-in-UDP/MAC-in-GRE)*/
229 #define I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC 0x0000000001C00000ULL
230 /* Source port of tunneling UDP */
231 #define I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT 0x0000000000200000ULL
232 /* Destination port of tunneling UDP */
233 #define I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT 0x0000000000100000ULL
234 /* UDP Tunneling ID, NVGRE/GRE key */
235 #define I40E_REG_INSET_TUNNEL_ID 0x00000000000C0000ULL
236 /* Last ether type */
237 #define I40E_REG_INSET_LAST_ETHER_TYPE 0x0000000000004000ULL
238 /* Tunneling outer destination IPv4 address */
239 #define I40E_REG_INSET_TUNNEL_L3_DST_IP4 0x00000000000000C0ULL
240 /* Tunneling outer destination IPv6 address */
241 #define I40E_REG_INSET_TUNNEL_L3_DST_IP6 0x0000000000003FC0ULL
242 /* 1st word of flex payload */
243 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD1 0x0000000000002000ULL
244 /* 2nd word of flex payload */
245 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD2 0x0000000000001000ULL
246 /* 3rd word of flex payload */
247 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD3 0x0000000000000800ULL
248 /* 4th word of flex payload */
249 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD4 0x0000000000000400ULL
250 /* 5th word of flex payload */
251 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD5 0x0000000000000200ULL
252 /* 6th word of flex payload */
253 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD6 0x0000000000000100ULL
254 /* 7th word of flex payload */
255 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD7 0x0000000000000080ULL
256 /* 8th word of flex payload */
257 #define I40E_REG_INSET_FLEX_PAYLOAD_WORD8 0x0000000000000040ULL
259 #define I40E_REG_INSET_MASK_DEFAULT 0x0000000000000000ULL
261 #define I40E_TRANSLATE_INSET 0
262 #define I40E_TRANSLATE_REG 1
264 #define I40E_INSET_IPV4_TOS_MASK 0x0009FF00UL
265 #define I40E_INSET_IPV4_PROTO_MASK 0x000DFF00UL
266 #define I40E_INSET_IPV6_TC_MASK 0x0009F00FUL
267 #define I40E_INSET_IPV6_NEXT_HDR_MASK 0x000C00FFUL
269 #define I40E_GL_SWT_L2TAGCTRL(_i) (0x001C0A70 + ((_i) * 4))
270 #define I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT 16
271 #define I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_MASK \
272 I40E_MASK(0xFFFF, I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT)
274 /* PCI offset for querying capability */
275 #define PCI_DEV_CAP_REG 0xA4
276 /* PCI offset for enabling/disabling Extended Tag */
277 #define PCI_DEV_CTRL_REG 0xA8
278 /* Bit mask of Extended Tag capability */
279 #define PCI_DEV_CAP_EXT_TAG_MASK 0x20
280 /* Bit shift of Extended Tag enable/disable */
281 #define PCI_DEV_CTRL_EXT_TAG_SHIFT 8
282 /* Bit mask of Extended Tag enable/disable */
283 #define PCI_DEV_CTRL_EXT_TAG_MASK (1 << PCI_DEV_CTRL_EXT_TAG_SHIFT)
285 static int eth_i40e_dev_init(struct rte_eth_dev *eth_dev);
286 static int eth_i40e_dev_uninit(struct rte_eth_dev *eth_dev);
287 static int i40e_dev_configure(struct rte_eth_dev *dev);
288 static int i40e_dev_start(struct rte_eth_dev *dev);
289 static void i40e_dev_stop(struct rte_eth_dev *dev);
290 static void i40e_dev_close(struct rte_eth_dev *dev);
291 static void i40e_dev_promiscuous_enable(struct rte_eth_dev *dev);
292 static void i40e_dev_promiscuous_disable(struct rte_eth_dev *dev);
293 static void i40e_dev_allmulticast_enable(struct rte_eth_dev *dev);
294 static void i40e_dev_allmulticast_disable(struct rte_eth_dev *dev);
295 static int i40e_dev_set_link_up(struct rte_eth_dev *dev);
296 static int i40e_dev_set_link_down(struct rte_eth_dev *dev);
297 static void i40e_dev_stats_get(struct rte_eth_dev *dev,
298 struct rte_eth_stats *stats);
299 static int i40e_dev_xstats_get(struct rte_eth_dev *dev,
300 struct rte_eth_xstats *xstats, unsigned n);
301 static void i40e_dev_stats_reset(struct rte_eth_dev *dev);
302 static int i40e_dev_queue_stats_mapping_set(struct rte_eth_dev *dev,
306 static void i40e_dev_info_get(struct rte_eth_dev *dev,
307 struct rte_eth_dev_info *dev_info);
308 static int i40e_vlan_filter_set(struct rte_eth_dev *dev,
311 static int i40e_vlan_tpid_set(struct rte_eth_dev *dev,
312 enum rte_vlan_type vlan_type,
314 static void i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask);
315 static void i40e_vlan_strip_queue_set(struct rte_eth_dev *dev,
318 static int i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on);
319 static int i40e_dev_led_on(struct rte_eth_dev *dev);
320 static int i40e_dev_led_off(struct rte_eth_dev *dev);
321 static int i40e_flow_ctrl_get(struct rte_eth_dev *dev,
322 struct rte_eth_fc_conf *fc_conf);
323 static int i40e_flow_ctrl_set(struct rte_eth_dev *dev,
324 struct rte_eth_fc_conf *fc_conf);
325 static int i40e_priority_flow_ctrl_set(struct rte_eth_dev *dev,
326 struct rte_eth_pfc_conf *pfc_conf);
327 static void i40e_macaddr_add(struct rte_eth_dev *dev,
328 struct ether_addr *mac_addr,
331 static void i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index);
332 static int i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
333 struct rte_eth_rss_reta_entry64 *reta_conf,
335 static int i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
336 struct rte_eth_rss_reta_entry64 *reta_conf,
339 static int i40e_get_cap(struct i40e_hw *hw);
340 static int i40e_pf_parameter_init(struct rte_eth_dev *dev);
341 static int i40e_pf_setup(struct i40e_pf *pf);
342 static int i40e_dev_rxtx_init(struct i40e_pf *pf);
343 static int i40e_vmdq_setup(struct rte_eth_dev *dev);
344 static int i40e_dcb_init_configure(struct rte_eth_dev *dev, bool sw_dcb);
345 static int i40e_dcb_setup(struct rte_eth_dev *dev);
346 static void i40e_stat_update_32(struct i40e_hw *hw, uint32_t reg,
347 bool offset_loaded, uint64_t *offset, uint64_t *stat);
348 static void i40e_stat_update_48(struct i40e_hw *hw,
354 static void i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue);
355 static void i40e_dev_interrupt_handler(
356 __rte_unused struct rte_intr_handle *handle, void *param);
357 static int i40e_res_pool_init(struct i40e_res_pool_info *pool,
358 uint32_t base, uint32_t num);
359 static void i40e_res_pool_destroy(struct i40e_res_pool_info *pool);
360 static int i40e_res_pool_free(struct i40e_res_pool_info *pool,
362 static int i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
364 static int i40e_dev_init_vlan(struct rte_eth_dev *dev);
365 static int i40e_veb_release(struct i40e_veb *veb);
366 static struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf,
367 struct i40e_vsi *vsi);
368 static int i40e_pf_config_mq_rx(struct i40e_pf *pf);
369 static int i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on);
370 static inline int i40e_find_all_vlan_for_mac(struct i40e_vsi *vsi,
371 struct i40e_macvlan_filter *mv_f,
373 struct ether_addr *addr);
374 static inline int i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
375 struct i40e_macvlan_filter *mv_f,
378 static int i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi);
379 static int i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
380 struct rte_eth_rss_conf *rss_conf);
381 static int i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
382 struct rte_eth_rss_conf *rss_conf);
383 static int i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
384 struct rte_eth_udp_tunnel *udp_tunnel);
385 static int i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
386 struct rte_eth_udp_tunnel *udp_tunnel);
387 static int i40e_ethertype_filter_set(struct i40e_pf *pf,
388 struct rte_eth_ethertype_filter *filter,
390 static int i40e_ethertype_filter_handle(struct rte_eth_dev *dev,
391 enum rte_filter_op filter_op,
393 static int i40e_dev_filter_ctrl(struct rte_eth_dev *dev,
394 enum rte_filter_type filter_type,
395 enum rte_filter_op filter_op,
397 static int i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
398 struct rte_eth_dcb_info *dcb_info);
399 static void i40e_configure_registers(struct i40e_hw *hw);
400 static void i40e_hw_init(struct rte_eth_dev *dev);
401 static int i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi);
402 static int i40e_mirror_rule_set(struct rte_eth_dev *dev,
403 struct rte_eth_mirror_conf *mirror_conf,
404 uint8_t sw_id, uint8_t on);
405 static int i40e_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t sw_id);
407 static int i40e_timesync_enable(struct rte_eth_dev *dev);
408 static int i40e_timesync_disable(struct rte_eth_dev *dev);
409 static int i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
410 struct timespec *timestamp,
412 static int i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
413 struct timespec *timestamp);
414 static void i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw);
416 static int i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
418 static int i40e_timesync_read_time(struct rte_eth_dev *dev,
419 struct timespec *timestamp);
420 static int i40e_timesync_write_time(struct rte_eth_dev *dev,
421 const struct timespec *timestamp);
423 static int i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
425 static int i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
429 static const struct rte_pci_id pci_id_i40e_map[] = {
430 #define RTE_PCI_DEV_ID_DECL_I40E(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
431 #include "rte_pci_dev_ids.h"
432 { .vendor_id = 0, /* sentinel */ },
435 static const struct eth_dev_ops i40e_eth_dev_ops = {
436 .dev_configure = i40e_dev_configure,
437 .dev_start = i40e_dev_start,
438 .dev_stop = i40e_dev_stop,
439 .dev_close = i40e_dev_close,
440 .promiscuous_enable = i40e_dev_promiscuous_enable,
441 .promiscuous_disable = i40e_dev_promiscuous_disable,
442 .allmulticast_enable = i40e_dev_allmulticast_enable,
443 .allmulticast_disable = i40e_dev_allmulticast_disable,
444 .dev_set_link_up = i40e_dev_set_link_up,
445 .dev_set_link_down = i40e_dev_set_link_down,
446 .link_update = i40e_dev_link_update,
447 .stats_get = i40e_dev_stats_get,
448 .xstats_get = i40e_dev_xstats_get,
449 .stats_reset = i40e_dev_stats_reset,
450 .xstats_reset = i40e_dev_stats_reset,
451 .queue_stats_mapping_set = i40e_dev_queue_stats_mapping_set,
452 .dev_infos_get = i40e_dev_info_get,
453 .vlan_filter_set = i40e_vlan_filter_set,
454 .vlan_tpid_set = i40e_vlan_tpid_set,
455 .vlan_offload_set = i40e_vlan_offload_set,
456 .vlan_strip_queue_set = i40e_vlan_strip_queue_set,
457 .vlan_pvid_set = i40e_vlan_pvid_set,
458 .rx_queue_start = i40e_dev_rx_queue_start,
459 .rx_queue_stop = i40e_dev_rx_queue_stop,
460 .tx_queue_start = i40e_dev_tx_queue_start,
461 .tx_queue_stop = i40e_dev_tx_queue_stop,
462 .rx_queue_setup = i40e_dev_rx_queue_setup,
463 .rx_queue_intr_enable = i40e_dev_rx_queue_intr_enable,
464 .rx_queue_intr_disable = i40e_dev_rx_queue_intr_disable,
465 .rx_queue_release = i40e_dev_rx_queue_release,
466 .rx_queue_count = i40e_dev_rx_queue_count,
467 .rx_descriptor_done = i40e_dev_rx_descriptor_done,
468 .tx_queue_setup = i40e_dev_tx_queue_setup,
469 .tx_queue_release = i40e_dev_tx_queue_release,
470 .dev_led_on = i40e_dev_led_on,
471 .dev_led_off = i40e_dev_led_off,
472 .flow_ctrl_get = i40e_flow_ctrl_get,
473 .flow_ctrl_set = i40e_flow_ctrl_set,
474 .priority_flow_ctrl_set = i40e_priority_flow_ctrl_set,
475 .mac_addr_add = i40e_macaddr_add,
476 .mac_addr_remove = i40e_macaddr_remove,
477 .reta_update = i40e_dev_rss_reta_update,
478 .reta_query = i40e_dev_rss_reta_query,
479 .rss_hash_update = i40e_dev_rss_hash_update,
480 .rss_hash_conf_get = i40e_dev_rss_hash_conf_get,
481 .udp_tunnel_port_add = i40e_dev_udp_tunnel_port_add,
482 .udp_tunnel_port_del = i40e_dev_udp_tunnel_port_del,
483 .filter_ctrl = i40e_dev_filter_ctrl,
484 .rxq_info_get = i40e_rxq_info_get,
485 .txq_info_get = i40e_txq_info_get,
486 .mirror_rule_set = i40e_mirror_rule_set,
487 .mirror_rule_reset = i40e_mirror_rule_reset,
488 .timesync_enable = i40e_timesync_enable,
489 .timesync_disable = i40e_timesync_disable,
490 .timesync_read_rx_timestamp = i40e_timesync_read_rx_timestamp,
491 .timesync_read_tx_timestamp = i40e_timesync_read_tx_timestamp,
492 .get_dcb_info = i40e_dev_get_dcb_info,
493 .timesync_adjust_time = i40e_timesync_adjust_time,
494 .timesync_read_time = i40e_timesync_read_time,
495 .timesync_write_time = i40e_timesync_write_time,
498 /* store statistics names and its offset in stats structure */
499 struct rte_i40e_xstats_name_off {
500 char name[RTE_ETH_XSTATS_NAME_SIZE];
504 static const struct rte_i40e_xstats_name_off rte_i40e_stats_strings[] = {
505 {"rx_unicast_packets", offsetof(struct i40e_eth_stats, rx_unicast)},
506 {"rx_multicast_packets", offsetof(struct i40e_eth_stats, rx_multicast)},
507 {"rx_broadcast_packets", offsetof(struct i40e_eth_stats, rx_broadcast)},
508 {"rx_dropped", offsetof(struct i40e_eth_stats, rx_discards)},
509 {"rx_unknown_protocol_packets", offsetof(struct i40e_eth_stats,
510 rx_unknown_protocol)},
511 {"tx_unicast_packets", offsetof(struct i40e_eth_stats, tx_unicast)},
512 {"tx_multicast_packets", offsetof(struct i40e_eth_stats, tx_multicast)},
513 {"tx_broadcast_packets", offsetof(struct i40e_eth_stats, tx_broadcast)},
514 {"tx_dropped", offsetof(struct i40e_eth_stats, tx_discards)},
517 #define I40E_NB_ETH_XSTATS (sizeof(rte_i40e_stats_strings) / \
518 sizeof(rte_i40e_stats_strings[0]))
520 static const struct rte_i40e_xstats_name_off rte_i40e_hw_port_strings[] = {
521 {"tx_link_down_dropped", offsetof(struct i40e_hw_port_stats,
522 tx_dropped_link_down)},
523 {"rx_crc_errors", offsetof(struct i40e_hw_port_stats, crc_errors)},
524 {"rx_illegal_byte_errors", offsetof(struct i40e_hw_port_stats,
526 {"rx_error_bytes", offsetof(struct i40e_hw_port_stats, error_bytes)},
527 {"mac_local_errors", offsetof(struct i40e_hw_port_stats,
529 {"mac_remote_errors", offsetof(struct i40e_hw_port_stats,
531 {"rx_length_errors", offsetof(struct i40e_hw_port_stats,
533 {"tx_xon_packets", offsetof(struct i40e_hw_port_stats, link_xon_tx)},
534 {"rx_xon_packets", offsetof(struct i40e_hw_port_stats, link_xon_rx)},
535 {"tx_xoff_packets", offsetof(struct i40e_hw_port_stats, link_xoff_tx)},
536 {"rx_xoff_packets", offsetof(struct i40e_hw_port_stats, link_xoff_rx)},
537 {"rx_size_64_packets", offsetof(struct i40e_hw_port_stats, rx_size_64)},
538 {"rx_size_65_to_127_packets", offsetof(struct i40e_hw_port_stats,
540 {"rx_size_128_to_255_packets", offsetof(struct i40e_hw_port_stats,
542 {"rx_size_256_to_511_packets", offsetof(struct i40e_hw_port_stats,
544 {"rx_size_512_to_1023_packets", offsetof(struct i40e_hw_port_stats,
546 {"rx_size_1024_to_1522_packets", offsetof(struct i40e_hw_port_stats,
548 {"rx_size_1523_to_max_packets", offsetof(struct i40e_hw_port_stats,
550 {"rx_undersized_errors", offsetof(struct i40e_hw_port_stats,
552 {"rx_oversize_errors", offsetof(struct i40e_hw_port_stats,
554 {"rx_mac_short_dropped", offsetof(struct i40e_hw_port_stats,
555 mac_short_packet_dropped)},
556 {"rx_fragmented_errors", offsetof(struct i40e_hw_port_stats,
558 {"rx_jabber_errors", offsetof(struct i40e_hw_port_stats, rx_jabber)},
559 {"tx_size_64_packets", offsetof(struct i40e_hw_port_stats, tx_size_64)},
560 {"tx_size_65_to_127_packets", offsetof(struct i40e_hw_port_stats,
562 {"tx_size_128_to_255_packets", offsetof(struct i40e_hw_port_stats,
564 {"tx_size_256_to_511_packets", offsetof(struct i40e_hw_port_stats,
566 {"tx_size_512_to_1023_packets", offsetof(struct i40e_hw_port_stats,
568 {"tx_size_1024_to_1522_packets", offsetof(struct i40e_hw_port_stats,
570 {"tx_size_1523_to_max_packets", offsetof(struct i40e_hw_port_stats,
572 {"rx_flow_director_atr_match_packets",
573 offsetof(struct i40e_hw_port_stats, fd_atr_match)},
574 {"rx_flow_director_sb_match_packets",
575 offsetof(struct i40e_hw_port_stats, fd_sb_match)},
576 {"tx_low_power_idle_status", offsetof(struct i40e_hw_port_stats,
578 {"rx_low_power_idle_status", offsetof(struct i40e_hw_port_stats,
580 {"tx_low_power_idle_count", offsetof(struct i40e_hw_port_stats,
582 {"rx_low_power_idle_count", offsetof(struct i40e_hw_port_stats,
586 #define I40E_NB_HW_PORT_XSTATS (sizeof(rte_i40e_hw_port_strings) / \
587 sizeof(rte_i40e_hw_port_strings[0]))
589 static const struct rte_i40e_xstats_name_off rte_i40e_rxq_prio_strings[] = {
590 {"xon_packets", offsetof(struct i40e_hw_port_stats,
592 {"xoff_packets", offsetof(struct i40e_hw_port_stats,
596 #define I40E_NB_RXQ_PRIO_XSTATS (sizeof(rte_i40e_rxq_prio_strings) / \
597 sizeof(rte_i40e_rxq_prio_strings[0]))
599 static const struct rte_i40e_xstats_name_off rte_i40e_txq_prio_strings[] = {
600 {"xon_packets", offsetof(struct i40e_hw_port_stats,
602 {"xoff_packets", offsetof(struct i40e_hw_port_stats,
604 {"xon_to_xoff_packets", offsetof(struct i40e_hw_port_stats,
605 priority_xon_2_xoff)},
608 #define I40E_NB_TXQ_PRIO_XSTATS (sizeof(rte_i40e_txq_prio_strings) / \
609 sizeof(rte_i40e_txq_prio_strings[0]))
611 static struct eth_driver rte_i40e_pmd = {
613 .name = "rte_i40e_pmd",
614 .id_table = pci_id_i40e_map,
615 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
616 RTE_PCI_DRV_DETACHABLE,
618 .eth_dev_init = eth_i40e_dev_init,
619 .eth_dev_uninit = eth_i40e_dev_uninit,
620 .dev_private_size = sizeof(struct i40e_adapter),
624 rte_i40e_dev_atomic_read_link_status(struct rte_eth_dev *dev,
625 struct rte_eth_link *link)
627 struct rte_eth_link *dst = link;
628 struct rte_eth_link *src = &(dev->data->dev_link);
630 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
631 *(uint64_t *)src) == 0)
638 rte_i40e_dev_atomic_write_link_status(struct rte_eth_dev *dev,
639 struct rte_eth_link *link)
641 struct rte_eth_link *dst = &(dev->data->dev_link);
642 struct rte_eth_link *src = link;
644 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
645 *(uint64_t *)src) == 0)
652 * Driver initialization routine.
653 * Invoked once at EAL init time.
654 * Register itself as the [Poll Mode] Driver of PCI IXGBE devices.
657 rte_i40e_pmd_init(const char *name __rte_unused,
658 const char *params __rte_unused)
660 PMD_INIT_FUNC_TRACE();
661 rte_eth_driver_register(&rte_i40e_pmd);
666 static struct rte_driver rte_i40e_driver = {
668 .init = rte_i40e_pmd_init,
671 PMD_REGISTER_DRIVER(rte_i40e_driver);
674 * Initialize registers for flexible payload, which should be set by NVM.
675 * This should be removed from code once it is fixed in NVM.
677 #ifndef I40E_GLQF_ORT
678 #define I40E_GLQF_ORT(_i) (0x00268900 + ((_i) * 4))
680 #ifndef I40E_GLQF_PIT
681 #define I40E_GLQF_PIT(_i) (0x00268C80 + ((_i) * 4))
684 static inline void i40e_flex_payload_reg_init(struct i40e_hw *hw)
686 I40E_WRITE_REG(hw, I40E_GLQF_ORT(18), 0x00000030);
687 I40E_WRITE_REG(hw, I40E_GLQF_ORT(19), 0x00000030);
688 I40E_WRITE_REG(hw, I40E_GLQF_ORT(26), 0x0000002B);
689 I40E_WRITE_REG(hw, I40E_GLQF_ORT(30), 0x0000002B);
690 I40E_WRITE_REG(hw, I40E_GLQF_ORT(33), 0x000000E0);
691 I40E_WRITE_REG(hw, I40E_GLQF_ORT(34), 0x000000E3);
692 I40E_WRITE_REG(hw, I40E_GLQF_ORT(35), 0x000000E6);
693 I40E_WRITE_REG(hw, I40E_GLQF_ORT(20), 0x00000031);
694 I40E_WRITE_REG(hw, I40E_GLQF_ORT(23), 0x00000031);
695 I40E_WRITE_REG(hw, I40E_GLQF_ORT(63), 0x0000002D);
697 /* GLQF_PIT Registers */
698 I40E_WRITE_REG(hw, I40E_GLQF_PIT(16), 0x00007480);
699 I40E_WRITE_REG(hw, I40E_GLQF_PIT(17), 0x00007440);
702 #define I40E_FLOW_CONTROL_ETHERTYPE 0x8808
705 * Add a ethertype filter to drop all flow control frames transmitted
709 i40e_add_tx_flow_control_drop_filter(struct i40e_pf *pf)
711 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
712 uint16_t flags = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
713 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
714 I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
717 ret = i40e_aq_add_rem_control_packet_filter(hw, NULL,
718 I40E_FLOW_CONTROL_ETHERTYPE, flags,
719 pf->main_vsi_seid, 0,
722 PMD_INIT_LOG(ERR, "Failed to add filter to drop flow control "
723 " frames from VSIs.");
727 eth_i40e_dev_init(struct rte_eth_dev *dev)
729 struct rte_pci_device *pci_dev;
730 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
731 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
732 struct i40e_vsi *vsi;
737 PMD_INIT_FUNC_TRACE();
739 dev->dev_ops = &i40e_eth_dev_ops;
740 dev->rx_pkt_burst = i40e_recv_pkts;
741 dev->tx_pkt_burst = i40e_xmit_pkts;
743 /* for secondary processes, we don't initialise any further as primary
744 * has already done this work. Only check we don't need a different
746 if (rte_eal_process_type() != RTE_PROC_PRIMARY){
747 i40e_set_rx_function(dev);
748 i40e_set_tx_function(dev);
751 pci_dev = dev->pci_dev;
753 rte_eth_copy_pci_info(dev, pci_dev);
755 pf->adapter = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
756 pf->adapter->eth_dev = dev;
757 pf->dev_data = dev->data;
759 hw->back = I40E_PF_TO_ADAPTER(pf);
760 hw->hw_addr = (uint8_t *)(pci_dev->mem_resource[0].addr);
762 PMD_INIT_LOG(ERR, "Hardware is not available, "
763 "as address is NULL");
767 hw->vendor_id = pci_dev->id.vendor_id;
768 hw->device_id = pci_dev->id.device_id;
769 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
770 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
771 hw->bus.device = pci_dev->addr.devid;
772 hw->bus.func = pci_dev->addr.function;
773 hw->adapter_stopped = 0;
775 /* Make sure all is clean before doing PF reset */
778 /* Initialize the hardware */
781 /* Reset here to make sure all is clean for each PF */
782 ret = i40e_pf_reset(hw);
784 PMD_INIT_LOG(ERR, "Failed to reset pf: %d", ret);
788 /* Initialize the shared code (base driver) */
789 ret = i40e_init_shared_code(hw);
791 PMD_INIT_LOG(ERR, "Failed to init shared code (base driver): %d", ret);
796 * To work around the NVM issue,initialize registers
797 * for flexible payload by software.
798 * It should be removed once issues are fixed in NVM.
800 i40e_flex_payload_reg_init(hw);
802 /* Initialize the parameters for adminq */
803 i40e_init_adminq_parameter(hw);
804 ret = i40e_init_adminq(hw);
805 if (ret != I40E_SUCCESS) {
806 PMD_INIT_LOG(ERR, "Failed to init adminq: %d", ret);
809 PMD_INIT_LOG(INFO, "FW %d.%d API %d.%d NVM %02d.%02d.%02d eetrack %04x",
810 hw->aq.fw_maj_ver, hw->aq.fw_min_ver,
811 hw->aq.api_maj_ver, hw->aq.api_min_ver,
812 ((hw->nvm.version >> 12) & 0xf),
813 ((hw->nvm.version >> 4) & 0xff),
814 (hw->nvm.version & 0xf), hw->nvm.eetrack);
817 i40e_clear_pxe_mode(hw);
820 * On X710, performance number is far from the expectation on recent
821 * firmware versions. The fix for this issue may not be integrated in
822 * the following firmware version. So the workaround in software driver
823 * is needed. It needs to modify the initial values of 3 internal only
824 * registers. Note that the workaround can be removed when it is fixed
825 * in firmware in the future.
827 i40e_configure_registers(hw);
829 /* Get hw capabilities */
830 ret = i40e_get_cap(hw);
831 if (ret != I40E_SUCCESS) {
832 PMD_INIT_LOG(ERR, "Failed to get capabilities: %d", ret);
833 goto err_get_capabilities;
836 /* Initialize parameters for PF */
837 ret = i40e_pf_parameter_init(dev);
839 PMD_INIT_LOG(ERR, "Failed to do parameter init: %d", ret);
840 goto err_parameter_init;
843 /* Initialize the queue management */
844 ret = i40e_res_pool_init(&pf->qp_pool, 0, hw->func_caps.num_tx_qp);
846 PMD_INIT_LOG(ERR, "Failed to init queue pool");
847 goto err_qp_pool_init;
849 ret = i40e_res_pool_init(&pf->msix_pool, 1,
850 hw->func_caps.num_msix_vectors - 1);
852 PMD_INIT_LOG(ERR, "Failed to init MSIX pool");
853 goto err_msix_pool_init;
856 /* Initialize lan hmc */
857 ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
858 hw->func_caps.num_rx_qp, 0, 0);
859 if (ret != I40E_SUCCESS) {
860 PMD_INIT_LOG(ERR, "Failed to init lan hmc: %d", ret);
861 goto err_init_lan_hmc;
864 /* Configure lan hmc */
865 ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
866 if (ret != I40E_SUCCESS) {
867 PMD_INIT_LOG(ERR, "Failed to configure lan hmc: %d", ret);
868 goto err_configure_lan_hmc;
871 /* Get and check the mac address */
872 i40e_get_mac_addr(hw, hw->mac.addr);
873 if (i40e_validate_mac_addr(hw->mac.addr) != I40E_SUCCESS) {
874 PMD_INIT_LOG(ERR, "mac address is not valid");
876 goto err_get_mac_addr;
878 /* Copy the permanent MAC address */
879 ether_addr_copy((struct ether_addr *) hw->mac.addr,
880 (struct ether_addr *) hw->mac.perm_addr);
882 /* Disable flow control */
883 hw->fc.requested_mode = I40E_FC_NONE;
884 i40e_set_fc(hw, &aq_fail, TRUE);
886 /* Set the global registers with default ether type value */
887 ret = i40e_vlan_tpid_set(dev, ETH_VLAN_TYPE_OUTER, ETHER_TYPE_VLAN);
888 if (ret != I40E_SUCCESS) {
889 PMD_INIT_LOG(ERR, "Failed to set the default outer "
891 goto err_setup_pf_switch;
893 ret = i40e_vlan_tpid_set(dev, ETH_VLAN_TYPE_INNER, ETHER_TYPE_VLAN);
894 if (ret != I40E_SUCCESS) {
895 PMD_INIT_LOG(ERR, "Failed to set the default outer "
897 goto err_setup_pf_switch;
900 /* PF setup, which includes VSI setup */
901 ret = i40e_pf_setup(pf);
903 PMD_INIT_LOG(ERR, "Failed to setup pf switch: %d", ret);
904 goto err_setup_pf_switch;
909 /* Disable double vlan by default */
910 i40e_vsi_config_double_vlan(vsi, FALSE);
912 if (!vsi->max_macaddrs)
913 len = ETHER_ADDR_LEN;
915 len = ETHER_ADDR_LEN * vsi->max_macaddrs;
917 /* Should be after VSI initialized */
918 dev->data->mac_addrs = rte_zmalloc("i40e", len, 0);
919 if (!dev->data->mac_addrs) {
920 PMD_INIT_LOG(ERR, "Failed to allocated memory "
921 "for storing mac address");
924 ether_addr_copy((struct ether_addr *)hw->mac.perm_addr,
925 &dev->data->mac_addrs[0]);
927 /* initialize pf host driver to setup SRIOV resource if applicable */
928 i40e_pf_host_init(dev);
930 /* register callback func to eal lib */
931 rte_intr_callback_register(&(pci_dev->intr_handle),
932 i40e_dev_interrupt_handler, (void *)dev);
934 /* configure and enable device interrupt */
935 i40e_pf_config_irq0(hw, TRUE);
936 i40e_pf_enable_irq0(hw);
938 /* enable uio intr after callback register */
939 rte_intr_enable(&(pci_dev->intr_handle));
941 * Add an ethertype filter to drop all flow control frames transmitted
942 * from VSIs. By doing so, we stop VF from sending out PAUSE or PFC
945 i40e_add_tx_flow_control_drop_filter(pf);
947 /* Set the max frame size to 0x2600 by default,
948 * in case other drivers changed the default value.
950 i40e_aq_set_mac_config(hw, I40E_FRAME_SIZE_MAX, TRUE, 0, NULL);
952 /* initialize mirror rule list */
953 TAILQ_INIT(&pf->mirror_list);
955 /* Init dcb to sw mode by default */
956 ret = i40e_dcb_init_configure(dev, TRUE);
957 if (ret != I40E_SUCCESS) {
958 PMD_INIT_LOG(INFO, "Failed to init dcb.");
959 pf->flags &= ~I40E_FLAG_DCB;
965 i40e_vsi_release(pf->main_vsi);
968 err_configure_lan_hmc:
969 (void)i40e_shutdown_lan_hmc(hw);
971 i40e_res_pool_destroy(&pf->msix_pool);
973 i40e_res_pool_destroy(&pf->qp_pool);
976 err_get_capabilities:
977 (void)i40e_shutdown_adminq(hw);
983 eth_i40e_dev_uninit(struct rte_eth_dev *dev)
985 struct rte_pci_device *pci_dev;
987 struct i40e_filter_control_settings settings;
991 PMD_INIT_FUNC_TRACE();
993 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
996 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
997 pci_dev = dev->pci_dev;
999 if (hw->adapter_stopped == 0)
1000 i40e_dev_close(dev);
1002 dev->dev_ops = NULL;
1003 dev->rx_pkt_burst = NULL;
1004 dev->tx_pkt_burst = NULL;
1007 ret = i40e_aq_stop_lldp(hw, true, NULL);
1008 if (ret != I40E_SUCCESS) /* Its failure can be ignored */
1009 PMD_INIT_LOG(INFO, "Failed to stop lldp");
1011 /* Clear PXE mode */
1012 i40e_clear_pxe_mode(hw);
1014 /* Unconfigure filter control */
1015 memset(&settings, 0, sizeof(settings));
1016 ret = i40e_set_filter_control(hw, &settings);
1018 PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
1021 /* Disable flow control */
1022 hw->fc.requested_mode = I40E_FC_NONE;
1023 i40e_set_fc(hw, &aq_fail, TRUE);
1025 /* uninitialize pf host driver */
1026 i40e_pf_host_uninit(dev);
1028 rte_free(dev->data->mac_addrs);
1029 dev->data->mac_addrs = NULL;
1031 /* disable uio intr before callback unregister */
1032 rte_intr_disable(&(pci_dev->intr_handle));
1034 /* register callback func to eal lib */
1035 rte_intr_callback_unregister(&(pci_dev->intr_handle),
1036 i40e_dev_interrupt_handler, (void *)dev);
1042 i40e_dev_configure(struct rte_eth_dev *dev)
1044 struct i40e_adapter *ad =
1045 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1046 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1047 enum rte_eth_rx_mq_mode mq_mode = dev->data->dev_conf.rxmode.mq_mode;
1050 /* Initialize to TRUE. If any of Rx queues doesn't meet the
1051 * bulk allocation or vector Rx preconditions we will reset it.
1053 ad->rx_bulk_alloc_allowed = true;
1054 ad->rx_vec_allowed = true;
1055 ad->tx_simple_allowed = true;
1056 ad->tx_vec_allowed = true;
1058 if (dev->data->dev_conf.fdir_conf.mode == RTE_FDIR_MODE_PERFECT) {
1059 ret = i40e_fdir_setup(pf);
1060 if (ret != I40E_SUCCESS) {
1061 PMD_DRV_LOG(ERR, "Failed to setup flow director.");
1064 ret = i40e_fdir_configure(dev);
1066 PMD_DRV_LOG(ERR, "failed to configure fdir.");
1070 i40e_fdir_teardown(pf);
1072 ret = i40e_dev_init_vlan(dev);
1077 * Needs to move VMDQ setting out of i40e_pf_config_mq_rx() as VMDQ and
1078 * RSS setting have different requirements.
1079 * General PMD driver call sequence are NIC init, configure,
1080 * rx/tx_queue_setup and dev_start. In rx/tx_queue_setup() function, it
1081 * will try to lookup the VSI that specific queue belongs to if VMDQ
1082 * applicable. So, VMDQ setting has to be done before
1083 * rx/tx_queue_setup(). This function is good to place vmdq_setup.
1084 * For RSS setting, it will try to calculate actual configured RX queue
1085 * number, which will be available after rx_queue_setup(). dev_start()
1086 * function is good to place RSS setup.
1088 if (mq_mode & ETH_MQ_RX_VMDQ_FLAG) {
1089 ret = i40e_vmdq_setup(dev);
1094 if (mq_mode & ETH_MQ_RX_DCB_FLAG) {
1095 ret = i40e_dcb_setup(dev);
1097 PMD_DRV_LOG(ERR, "failed to configure DCB.");
1105 /* need to release vmdq resource if exists */
1106 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1107 i40e_vsi_release(pf->vmdq[i].vsi);
1108 pf->vmdq[i].vsi = NULL;
1113 /* need to release fdir resource if exists */
1114 i40e_fdir_teardown(pf);
1119 i40e_vsi_queues_unbind_intr(struct i40e_vsi *vsi)
1121 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1122 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1123 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1124 uint16_t msix_vect = vsi->msix_intr;
1127 for (i = 0; i < vsi->nb_qps; i++) {
1128 I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
1129 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
1133 if (vsi->type != I40E_VSI_SRIOV) {
1134 if (!rte_intr_allow_others(intr_handle)) {
1135 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
1136 I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
1138 I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
1141 I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
1142 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
1144 I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
1149 reg = (hw->func_caps.num_msix_vectors_vf - 1) *
1150 vsi->user_param + (msix_vect - 1);
1152 I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
1153 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
1155 I40E_WRITE_FLUSH(hw);
1159 __vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t msix_vect,
1160 int base_queue, int nb_queue)
1164 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1166 /* Bind all RX queues to allocated MSIX interrupt */
1167 for (i = 0; i < nb_queue; i++) {
1168 val = (msix_vect << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
1169 I40E_QINT_RQCTL_ITR_INDX_MASK |
1170 ((base_queue + i + 1) <<
1171 I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
1172 (0 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
1173 I40E_QINT_RQCTL_CAUSE_ENA_MASK;
1175 if (i == nb_queue - 1)
1176 val |= I40E_QINT_RQCTL_NEXTQ_INDX_MASK;
1177 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(base_queue + i), val);
1180 /* Write first RX queue to Link list register as the head element */
1181 if (vsi->type != I40E_VSI_SRIOV) {
1183 i40e_calc_itr_interval(RTE_LIBRTE_I40E_ITR_INTERVAL);
1185 if (msix_vect == I40E_MISC_VEC_ID) {
1186 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
1188 I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
1190 I40E_PFINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
1192 I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
1195 I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
1197 I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
1199 I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
1201 I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
1208 if (msix_vect == I40E_MISC_VEC_ID) {
1210 I40E_VPINT_LNKLST0(vsi->user_param),
1212 I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
1214 I40E_VPINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
1216 /* num_msix_vectors_vf needs to minus irq0 */
1217 reg = (hw->func_caps.num_msix_vectors_vf - 1) *
1218 vsi->user_param + (msix_vect - 1);
1220 I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
1222 I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
1224 I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
1228 I40E_WRITE_FLUSH(hw);
1232 i40e_vsi_queues_bind_intr(struct i40e_vsi *vsi)
1234 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1235 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1236 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1237 uint16_t msix_vect = vsi->msix_intr;
1238 uint16_t nb_msix = RTE_MIN(vsi->nb_msix, intr_handle->nb_efd);
1239 uint16_t queue_idx = 0;
1244 for (i = 0; i < vsi->nb_qps; i++) {
1245 I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
1246 I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
1249 /* INTENA flag is not auto-cleared for interrupt */
1250 val = I40E_READ_REG(hw, I40E_GLINT_CTL);
1251 val |= I40E_GLINT_CTL_DIS_AUTOMASK_PF0_MASK |
1252 I40E_GLINT_CTL_DIS_AUTOMASK_N_MASK |
1253 I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK;
1254 I40E_WRITE_REG(hw, I40E_GLINT_CTL, val);
1256 /* VF bind interrupt */
1257 if (vsi->type == I40E_VSI_SRIOV) {
1258 __vsi_queues_bind_intr(vsi, msix_vect,
1259 vsi->base_queue, vsi->nb_qps);
1263 /* PF & VMDq bind interrupt */
1264 if (rte_intr_dp_is_en(intr_handle)) {
1265 if (vsi->type == I40E_VSI_MAIN) {
1268 } else if (vsi->type == I40E_VSI_VMDQ2) {
1269 struct i40e_vsi *main_vsi =
1270 I40E_DEV_PRIVATE_TO_MAIN_VSI(vsi->adapter);
1271 queue_idx = vsi->base_queue - main_vsi->nb_qps;
1276 for (i = 0; i < vsi->nb_used_qps; i++) {
1278 if (!rte_intr_allow_others(intr_handle))
1279 /* allow to share MISC_VEC_ID */
1280 msix_vect = I40E_MISC_VEC_ID;
1282 /* no enough msix_vect, map all to one */
1283 __vsi_queues_bind_intr(vsi, msix_vect,
1284 vsi->base_queue + i,
1285 vsi->nb_used_qps - i);
1286 for (; !!record && i < vsi->nb_used_qps; i++)
1287 intr_handle->intr_vec[queue_idx + i] =
1291 /* 1:1 queue/msix_vect mapping */
1292 __vsi_queues_bind_intr(vsi, msix_vect,
1293 vsi->base_queue + i, 1);
1295 intr_handle->intr_vec[queue_idx + i] = msix_vect;
1303 i40e_vsi_enable_queues_intr(struct i40e_vsi *vsi)
1305 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1306 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1307 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1308 uint16_t interval = i40e_calc_itr_interval(\
1309 RTE_LIBRTE_I40E_ITR_INTERVAL);
1310 uint16_t msix_intr, i;
1312 if (rte_intr_allow_others(intr_handle))
1313 for (i = 0; i < vsi->nb_msix; i++) {
1314 msix_intr = vsi->msix_intr + i;
1315 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
1316 I40E_PFINT_DYN_CTLN_INTENA_MASK |
1317 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
1318 (0 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT) |
1320 I40E_PFINT_DYN_CTLN_INTERVAL_SHIFT));
1323 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
1324 I40E_PFINT_DYN_CTL0_INTENA_MASK |
1325 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
1326 (0 << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT) |
1328 I40E_PFINT_DYN_CTL0_INTERVAL_SHIFT));
1330 I40E_WRITE_FLUSH(hw);
1334 i40e_vsi_disable_queues_intr(struct i40e_vsi *vsi)
1336 struct rte_eth_dev *dev = vsi->adapter->eth_dev;
1337 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1338 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1339 uint16_t msix_intr, i;
1341 if (rte_intr_allow_others(intr_handle))
1342 for (i = 0; i < vsi->nb_msix; i++) {
1343 msix_intr = vsi->msix_intr + i;
1344 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
1348 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0, 0);
1350 I40E_WRITE_FLUSH(hw);
1353 static inline uint8_t
1354 i40e_parse_link_speed(uint16_t eth_link_speed)
1356 uint8_t link_speed = I40E_LINK_SPEED_UNKNOWN;
1358 switch (eth_link_speed) {
1359 case ETH_LINK_SPEED_40G:
1360 link_speed = I40E_LINK_SPEED_40GB;
1362 case ETH_LINK_SPEED_20G:
1363 link_speed = I40E_LINK_SPEED_20GB;
1365 case ETH_LINK_SPEED_10G:
1366 link_speed = I40E_LINK_SPEED_10GB;
1368 case ETH_LINK_SPEED_1000:
1369 link_speed = I40E_LINK_SPEED_1GB;
1371 case ETH_LINK_SPEED_100:
1372 link_speed = I40E_LINK_SPEED_100MB;
1380 i40e_phy_conf_link(__rte_unused struct i40e_hw *hw,
1381 __rte_unused uint8_t abilities,
1382 __rte_unused uint8_t force_speed)
1384 /* Skip any phy config on both 10G and 40G interfaces, as a workaround
1385 * for the link control limitation of that all link control should be
1386 * handled by firmware. It should follow up if link control will be
1387 * opened to software driver in future firmware versions.
1389 return I40E_SUCCESS;
1393 i40e_apply_link_speed(struct rte_eth_dev *dev)
1396 uint8_t abilities = 0;
1397 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1398 struct rte_eth_conf *conf = &dev->data->dev_conf;
1400 speed = i40e_parse_link_speed(conf->link_speed);
1401 abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1402 if (conf->link_speed == ETH_LINK_SPEED_AUTONEG)
1403 abilities |= I40E_AQ_PHY_AN_ENABLED;
1405 abilities |= I40E_AQ_PHY_LINK_ENABLED;
1407 return i40e_phy_conf_link(hw, abilities, speed);
1411 i40e_dev_start(struct rte_eth_dev *dev)
1413 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1414 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1415 struct i40e_vsi *main_vsi = pf->main_vsi;
1417 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1418 uint32_t intr_vector = 0;
1420 hw->adapter_stopped = 0;
1422 if ((dev->data->dev_conf.link_duplex != ETH_LINK_AUTONEG_DUPLEX) &&
1423 (dev->data->dev_conf.link_duplex != ETH_LINK_FULL_DUPLEX)) {
1424 PMD_INIT_LOG(ERR, "Invalid link_duplex (%hu) for port %hhu",
1425 dev->data->dev_conf.link_duplex,
1426 dev->data->port_id);
1430 rte_intr_disable(intr_handle);
1432 if ((rte_intr_cap_multiple(intr_handle) ||
1433 !RTE_ETH_DEV_SRIOV(dev).active) &&
1434 dev->data->dev_conf.intr_conf.rxq != 0) {
1435 intr_vector = dev->data->nb_rx_queues;
1436 if (rte_intr_efd_enable(intr_handle, intr_vector))
1440 if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
1441 intr_handle->intr_vec =
1442 rte_zmalloc("intr_vec",
1443 dev->data->nb_rx_queues * sizeof(int),
1445 if (!intr_handle->intr_vec) {
1446 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
1447 " intr_vec\n", dev->data->nb_rx_queues);
1452 /* Initialize VSI */
1453 ret = i40e_dev_rxtx_init(pf);
1454 if (ret != I40E_SUCCESS) {
1455 PMD_DRV_LOG(ERR, "Failed to init rx/tx queues");
1459 /* Map queues with MSIX interrupt */
1460 main_vsi->nb_used_qps = dev->data->nb_rx_queues -
1461 pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
1462 i40e_vsi_queues_bind_intr(main_vsi);
1463 i40e_vsi_enable_queues_intr(main_vsi);
1465 /* Map VMDQ VSI queues with MSIX interrupt */
1466 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1467 pf->vmdq[i].vsi->nb_used_qps = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
1468 i40e_vsi_queues_bind_intr(pf->vmdq[i].vsi);
1469 i40e_vsi_enable_queues_intr(pf->vmdq[i].vsi);
1472 /* enable FDIR MSIX interrupt */
1473 if (pf->fdir.fdir_vsi) {
1474 i40e_vsi_queues_bind_intr(pf->fdir.fdir_vsi);
1475 i40e_vsi_enable_queues_intr(pf->fdir.fdir_vsi);
1478 /* Enable all queues which have been configured */
1479 ret = i40e_dev_switch_queues(pf, TRUE);
1480 if (ret != I40E_SUCCESS) {
1481 PMD_DRV_LOG(ERR, "Failed to enable VSI");
1485 /* Enable receiving broadcast packets */
1486 ret = i40e_aq_set_vsi_broadcast(hw, main_vsi->seid, true, NULL);
1487 if (ret != I40E_SUCCESS)
1488 PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
1490 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1491 ret = i40e_aq_set_vsi_broadcast(hw, pf->vmdq[i].vsi->seid,
1493 if (ret != I40E_SUCCESS)
1494 PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
1497 /* Apply link configure */
1498 ret = i40e_apply_link_speed(dev);
1499 if (I40E_SUCCESS != ret) {
1500 PMD_DRV_LOG(ERR, "Fail to apply link setting");
1504 if (!rte_intr_allow_others(intr_handle)) {
1505 rte_intr_callback_unregister(intr_handle,
1506 i40e_dev_interrupt_handler,
1508 /* configure and enable device interrupt */
1509 i40e_pf_config_irq0(hw, FALSE);
1510 i40e_pf_enable_irq0(hw);
1512 if (dev->data->dev_conf.intr_conf.lsc != 0)
1513 PMD_INIT_LOG(INFO, "lsc won't enable because of"
1514 " no intr multiplex\n");
1517 /* enable uio intr after callback register */
1518 rte_intr_enable(intr_handle);
1520 return I40E_SUCCESS;
1523 i40e_dev_switch_queues(pf, FALSE);
1524 i40e_dev_clear_queues(dev);
1530 i40e_dev_stop(struct rte_eth_dev *dev)
1532 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1533 struct i40e_vsi *main_vsi = pf->main_vsi;
1534 struct i40e_mirror_rule *p_mirror;
1535 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
1538 /* Disable all queues */
1539 i40e_dev_switch_queues(pf, FALSE);
1541 /* un-map queues with interrupt registers */
1542 i40e_vsi_disable_queues_intr(main_vsi);
1543 i40e_vsi_queues_unbind_intr(main_vsi);
1545 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1546 i40e_vsi_disable_queues_intr(pf->vmdq[i].vsi);
1547 i40e_vsi_queues_unbind_intr(pf->vmdq[i].vsi);
1550 if (pf->fdir.fdir_vsi) {
1551 i40e_vsi_queues_unbind_intr(pf->fdir.fdir_vsi);
1552 i40e_vsi_disable_queues_intr(pf->fdir.fdir_vsi);
1554 /* Clear all queues and release memory */
1555 i40e_dev_clear_queues(dev);
1558 i40e_dev_set_link_down(dev);
1560 /* Remove all mirror rules */
1561 while ((p_mirror = TAILQ_FIRST(&pf->mirror_list))) {
1562 TAILQ_REMOVE(&pf->mirror_list, p_mirror, rules);
1565 pf->nb_mirror_rule = 0;
1567 if (!rte_intr_allow_others(intr_handle))
1568 /* resume to the default handler */
1569 rte_intr_callback_register(intr_handle,
1570 i40e_dev_interrupt_handler,
1573 /* Clean datapath event and queue/vec mapping */
1574 rte_intr_efd_disable(intr_handle);
1575 if (intr_handle->intr_vec) {
1576 rte_free(intr_handle->intr_vec);
1577 intr_handle->intr_vec = NULL;
1582 i40e_dev_close(struct rte_eth_dev *dev)
1584 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1585 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1589 PMD_INIT_FUNC_TRACE();
1592 hw->adapter_stopped = 1;
1593 i40e_dev_free_queues(dev);
1595 /* Disable interrupt */
1596 i40e_pf_disable_irq0(hw);
1597 rte_intr_disable(&(dev->pci_dev->intr_handle));
1599 /* shutdown and destroy the HMC */
1600 i40e_shutdown_lan_hmc(hw);
1602 /* release all the existing VSIs and VEBs */
1603 i40e_fdir_teardown(pf);
1604 i40e_vsi_release(pf->main_vsi);
1606 for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
1607 i40e_vsi_release(pf->vmdq[i].vsi);
1608 pf->vmdq[i].vsi = NULL;
1614 /* shutdown the adminq */
1615 i40e_aq_queue_shutdown(hw, true);
1616 i40e_shutdown_adminq(hw);
1618 i40e_res_pool_destroy(&pf->qp_pool);
1619 i40e_res_pool_destroy(&pf->msix_pool);
1621 /* force a PF reset to clean anything leftover */
1622 reg = I40E_READ_REG(hw, I40E_PFGEN_CTRL);
1623 I40E_WRITE_REG(hw, I40E_PFGEN_CTRL,
1624 (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
1625 I40E_WRITE_FLUSH(hw);
1629 i40e_dev_promiscuous_enable(struct rte_eth_dev *dev)
1631 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1632 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1633 struct i40e_vsi *vsi = pf->main_vsi;
1636 status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
1638 if (status != I40E_SUCCESS)
1639 PMD_DRV_LOG(ERR, "Failed to enable unicast promiscuous");
1641 status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
1643 if (status != I40E_SUCCESS)
1644 PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
1649 i40e_dev_promiscuous_disable(struct rte_eth_dev *dev)
1651 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1652 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1653 struct i40e_vsi *vsi = pf->main_vsi;
1656 status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
1658 if (status != I40E_SUCCESS)
1659 PMD_DRV_LOG(ERR, "Failed to disable unicast promiscuous");
1661 status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
1663 if (status != I40E_SUCCESS)
1664 PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
1668 i40e_dev_allmulticast_enable(struct rte_eth_dev *dev)
1670 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1671 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1672 struct i40e_vsi *vsi = pf->main_vsi;
1675 ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid, TRUE, NULL);
1676 if (ret != I40E_SUCCESS)
1677 PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
1681 i40e_dev_allmulticast_disable(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 if (dev->data->promiscuous == 1)
1689 return; /* must remain in all_multicast mode */
1691 ret = i40e_aq_set_vsi_multicast_promiscuous(hw,
1692 vsi->seid, FALSE, NULL);
1693 if (ret != I40E_SUCCESS)
1694 PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
1698 * Set device link up.
1701 i40e_dev_set_link_up(struct rte_eth_dev *dev)
1703 /* re-apply link speed setting */
1704 return i40e_apply_link_speed(dev);
1708 * Set device link down.
1711 i40e_dev_set_link_down(__rte_unused struct rte_eth_dev *dev)
1713 uint8_t speed = I40E_LINK_SPEED_UNKNOWN;
1714 uint8_t abilities = I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1715 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1717 return i40e_phy_conf_link(hw, abilities, speed);
1721 i40e_dev_link_update(struct rte_eth_dev *dev,
1722 int wait_to_complete)
1724 #define CHECK_INTERVAL 100 /* 100ms */
1725 #define MAX_REPEAT_TIME 10 /* 1s (10 * 100ms) in total */
1726 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1727 struct i40e_link_status link_status;
1728 struct rte_eth_link link, old;
1730 unsigned rep_cnt = MAX_REPEAT_TIME;
1732 memset(&link, 0, sizeof(link));
1733 memset(&old, 0, sizeof(old));
1734 memset(&link_status, 0, sizeof(link_status));
1735 rte_i40e_dev_atomic_read_link_status(dev, &old);
1738 /* Get link status information from hardware */
1739 status = i40e_aq_get_link_info(hw, false, &link_status, NULL);
1740 if (status != I40E_SUCCESS) {
1741 link.link_speed = ETH_LINK_SPEED_100;
1742 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1743 PMD_DRV_LOG(ERR, "Failed to get link info");
1747 link.link_status = link_status.link_info & I40E_AQ_LINK_UP;
1748 if (!wait_to_complete)
1751 rte_delay_ms(CHECK_INTERVAL);
1752 } while (!link.link_status && rep_cnt--);
1754 if (!link.link_status)
1757 /* i40e uses full duplex only */
1758 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1760 /* Parse the link status */
1761 switch (link_status.link_speed) {
1762 case I40E_LINK_SPEED_100MB:
1763 link.link_speed = ETH_LINK_SPEED_100;
1765 case I40E_LINK_SPEED_1GB:
1766 link.link_speed = ETH_LINK_SPEED_1000;
1768 case I40E_LINK_SPEED_10GB:
1769 link.link_speed = ETH_LINK_SPEED_10G;
1771 case I40E_LINK_SPEED_20GB:
1772 link.link_speed = ETH_LINK_SPEED_20G;
1774 case I40E_LINK_SPEED_40GB:
1775 link.link_speed = ETH_LINK_SPEED_40G;
1778 link.link_speed = ETH_LINK_SPEED_100;
1783 rte_i40e_dev_atomic_write_link_status(dev, &link);
1784 if (link.link_status == old.link_status)
1790 /* Get all the statistics of a VSI */
1792 i40e_update_vsi_stats(struct i40e_vsi *vsi)
1794 struct i40e_eth_stats *oes = &vsi->eth_stats_offset;
1795 struct i40e_eth_stats *nes = &vsi->eth_stats;
1796 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
1797 int idx = rte_le_to_cpu_16(vsi->info.stat_counter_idx);
1799 i40e_stat_update_48(hw, I40E_GLV_GORCH(idx), I40E_GLV_GORCL(idx),
1800 vsi->offset_loaded, &oes->rx_bytes,
1802 i40e_stat_update_48(hw, I40E_GLV_UPRCH(idx), I40E_GLV_UPRCL(idx),
1803 vsi->offset_loaded, &oes->rx_unicast,
1805 i40e_stat_update_48(hw, I40E_GLV_MPRCH(idx), I40E_GLV_MPRCL(idx),
1806 vsi->offset_loaded, &oes->rx_multicast,
1807 &nes->rx_multicast);
1808 i40e_stat_update_48(hw, I40E_GLV_BPRCH(idx), I40E_GLV_BPRCL(idx),
1809 vsi->offset_loaded, &oes->rx_broadcast,
1810 &nes->rx_broadcast);
1811 i40e_stat_update_32(hw, I40E_GLV_RDPC(idx), vsi->offset_loaded,
1812 &oes->rx_discards, &nes->rx_discards);
1813 /* GLV_REPC not supported */
1814 /* GLV_RMPC not supported */
1815 i40e_stat_update_32(hw, I40E_GLV_RUPP(idx), vsi->offset_loaded,
1816 &oes->rx_unknown_protocol,
1817 &nes->rx_unknown_protocol);
1818 i40e_stat_update_48(hw, I40E_GLV_GOTCH(idx), I40E_GLV_GOTCL(idx),
1819 vsi->offset_loaded, &oes->tx_bytes,
1821 i40e_stat_update_48(hw, I40E_GLV_UPTCH(idx), I40E_GLV_UPTCL(idx),
1822 vsi->offset_loaded, &oes->tx_unicast,
1824 i40e_stat_update_48(hw, I40E_GLV_MPTCH(idx), I40E_GLV_MPTCL(idx),
1825 vsi->offset_loaded, &oes->tx_multicast,
1826 &nes->tx_multicast);
1827 i40e_stat_update_48(hw, I40E_GLV_BPTCH(idx), I40E_GLV_BPTCL(idx),
1828 vsi->offset_loaded, &oes->tx_broadcast,
1829 &nes->tx_broadcast);
1830 /* GLV_TDPC not supported */
1831 i40e_stat_update_32(hw, I40E_GLV_TEPC(idx), vsi->offset_loaded,
1832 &oes->tx_errors, &nes->tx_errors);
1833 vsi->offset_loaded = true;
1835 PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats start *******************",
1837 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", nes->rx_bytes);
1838 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", nes->rx_unicast);
1839 PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", nes->rx_multicast);
1840 PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", nes->rx_broadcast);
1841 PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", nes->rx_discards);
1842 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
1843 nes->rx_unknown_protocol);
1844 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", nes->tx_bytes);
1845 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", nes->tx_unicast);
1846 PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", nes->tx_multicast);
1847 PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", nes->tx_broadcast);
1848 PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", nes->tx_discards);
1849 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", nes->tx_errors);
1850 PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats end *******************",
1855 i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw)
1858 struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
1859 struct i40e_hw_port_stats *os = &pf->stats_offset; /* old stats */
1861 /* Get statistics of struct i40e_eth_stats */
1862 i40e_stat_update_48(hw, I40E_GLPRT_GORCH(hw->port),
1863 I40E_GLPRT_GORCL(hw->port),
1864 pf->offset_loaded, &os->eth.rx_bytes,
1866 i40e_stat_update_48(hw, I40E_GLPRT_UPRCH(hw->port),
1867 I40E_GLPRT_UPRCL(hw->port),
1868 pf->offset_loaded, &os->eth.rx_unicast,
1869 &ns->eth.rx_unicast);
1870 i40e_stat_update_48(hw, I40E_GLPRT_MPRCH(hw->port),
1871 I40E_GLPRT_MPRCL(hw->port),
1872 pf->offset_loaded, &os->eth.rx_multicast,
1873 &ns->eth.rx_multicast);
1874 i40e_stat_update_48(hw, I40E_GLPRT_BPRCH(hw->port),
1875 I40E_GLPRT_BPRCL(hw->port),
1876 pf->offset_loaded, &os->eth.rx_broadcast,
1877 &ns->eth.rx_broadcast);
1878 /* Workaround: CRC size should not be included in byte statistics,
1879 * so subtract ETHER_CRC_LEN from the byte counter for each rx packet.
1881 ns->eth.rx_bytes -= (ns->eth.rx_unicast + ns->eth.rx_multicast +
1882 ns->eth.rx_broadcast) * ETHER_CRC_LEN;
1884 i40e_stat_update_32(hw, I40E_GLPRT_RDPC(hw->port),
1885 pf->offset_loaded, &os->eth.rx_discards,
1886 &ns->eth.rx_discards);
1887 /* GLPRT_REPC not supported */
1888 /* GLPRT_RMPC not supported */
1889 i40e_stat_update_32(hw, I40E_GLPRT_RUPP(hw->port),
1891 &os->eth.rx_unknown_protocol,
1892 &ns->eth.rx_unknown_protocol);
1893 i40e_stat_update_48(hw, I40E_GLPRT_GOTCH(hw->port),
1894 I40E_GLPRT_GOTCL(hw->port),
1895 pf->offset_loaded, &os->eth.tx_bytes,
1897 i40e_stat_update_48(hw, I40E_GLPRT_UPTCH(hw->port),
1898 I40E_GLPRT_UPTCL(hw->port),
1899 pf->offset_loaded, &os->eth.tx_unicast,
1900 &ns->eth.tx_unicast);
1901 i40e_stat_update_48(hw, I40E_GLPRT_MPTCH(hw->port),
1902 I40E_GLPRT_MPTCL(hw->port),
1903 pf->offset_loaded, &os->eth.tx_multicast,
1904 &ns->eth.tx_multicast);
1905 i40e_stat_update_48(hw, I40E_GLPRT_BPTCH(hw->port),
1906 I40E_GLPRT_BPTCL(hw->port),
1907 pf->offset_loaded, &os->eth.tx_broadcast,
1908 &ns->eth.tx_broadcast);
1909 ns->eth.tx_bytes -= (ns->eth.tx_unicast + ns->eth.tx_multicast +
1910 ns->eth.tx_broadcast) * ETHER_CRC_LEN;
1911 /* GLPRT_TEPC not supported */
1913 /* additional port specific stats */
1914 i40e_stat_update_32(hw, I40E_GLPRT_TDOLD(hw->port),
1915 pf->offset_loaded, &os->tx_dropped_link_down,
1916 &ns->tx_dropped_link_down);
1917 i40e_stat_update_32(hw, I40E_GLPRT_CRCERRS(hw->port),
1918 pf->offset_loaded, &os->crc_errors,
1920 i40e_stat_update_32(hw, I40E_GLPRT_ILLERRC(hw->port),
1921 pf->offset_loaded, &os->illegal_bytes,
1922 &ns->illegal_bytes);
1923 /* GLPRT_ERRBC not supported */
1924 i40e_stat_update_32(hw, I40E_GLPRT_MLFC(hw->port),
1925 pf->offset_loaded, &os->mac_local_faults,
1926 &ns->mac_local_faults);
1927 i40e_stat_update_32(hw, I40E_GLPRT_MRFC(hw->port),
1928 pf->offset_loaded, &os->mac_remote_faults,
1929 &ns->mac_remote_faults);
1930 i40e_stat_update_32(hw, I40E_GLPRT_RLEC(hw->port),
1931 pf->offset_loaded, &os->rx_length_errors,
1932 &ns->rx_length_errors);
1933 i40e_stat_update_32(hw, I40E_GLPRT_LXONRXC(hw->port),
1934 pf->offset_loaded, &os->link_xon_rx,
1936 i40e_stat_update_32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
1937 pf->offset_loaded, &os->link_xoff_rx,
1939 for (i = 0; i < 8; i++) {
1940 i40e_stat_update_32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
1942 &os->priority_xon_rx[i],
1943 &ns->priority_xon_rx[i]);
1944 i40e_stat_update_32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
1946 &os->priority_xoff_rx[i],
1947 &ns->priority_xoff_rx[i]);
1949 i40e_stat_update_32(hw, I40E_GLPRT_LXONTXC(hw->port),
1950 pf->offset_loaded, &os->link_xon_tx,
1952 i40e_stat_update_32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
1953 pf->offset_loaded, &os->link_xoff_tx,
1955 for (i = 0; i < 8; i++) {
1956 i40e_stat_update_32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
1958 &os->priority_xon_tx[i],
1959 &ns->priority_xon_tx[i]);
1960 i40e_stat_update_32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
1962 &os->priority_xoff_tx[i],
1963 &ns->priority_xoff_tx[i]);
1964 i40e_stat_update_32(hw, I40E_GLPRT_RXON2OFFCNT(hw->port, i),
1966 &os->priority_xon_2_xoff[i],
1967 &ns->priority_xon_2_xoff[i]);
1969 i40e_stat_update_48(hw, I40E_GLPRT_PRC64H(hw->port),
1970 I40E_GLPRT_PRC64L(hw->port),
1971 pf->offset_loaded, &os->rx_size_64,
1973 i40e_stat_update_48(hw, I40E_GLPRT_PRC127H(hw->port),
1974 I40E_GLPRT_PRC127L(hw->port),
1975 pf->offset_loaded, &os->rx_size_127,
1977 i40e_stat_update_48(hw, I40E_GLPRT_PRC255H(hw->port),
1978 I40E_GLPRT_PRC255L(hw->port),
1979 pf->offset_loaded, &os->rx_size_255,
1981 i40e_stat_update_48(hw, I40E_GLPRT_PRC511H(hw->port),
1982 I40E_GLPRT_PRC511L(hw->port),
1983 pf->offset_loaded, &os->rx_size_511,
1985 i40e_stat_update_48(hw, I40E_GLPRT_PRC1023H(hw->port),
1986 I40E_GLPRT_PRC1023L(hw->port),
1987 pf->offset_loaded, &os->rx_size_1023,
1989 i40e_stat_update_48(hw, I40E_GLPRT_PRC1522H(hw->port),
1990 I40E_GLPRT_PRC1522L(hw->port),
1991 pf->offset_loaded, &os->rx_size_1522,
1993 i40e_stat_update_48(hw, I40E_GLPRT_PRC9522H(hw->port),
1994 I40E_GLPRT_PRC9522L(hw->port),
1995 pf->offset_loaded, &os->rx_size_big,
1997 i40e_stat_update_32(hw, I40E_GLPRT_RUC(hw->port),
1998 pf->offset_loaded, &os->rx_undersize,
2000 i40e_stat_update_32(hw, I40E_GLPRT_RFC(hw->port),
2001 pf->offset_loaded, &os->rx_fragments,
2003 i40e_stat_update_32(hw, I40E_GLPRT_ROC(hw->port),
2004 pf->offset_loaded, &os->rx_oversize,
2006 i40e_stat_update_32(hw, I40E_GLPRT_RJC(hw->port),
2007 pf->offset_loaded, &os->rx_jabber,
2009 i40e_stat_update_48(hw, I40E_GLPRT_PTC64H(hw->port),
2010 I40E_GLPRT_PTC64L(hw->port),
2011 pf->offset_loaded, &os->tx_size_64,
2013 i40e_stat_update_48(hw, I40E_GLPRT_PTC127H(hw->port),
2014 I40E_GLPRT_PTC127L(hw->port),
2015 pf->offset_loaded, &os->tx_size_127,
2017 i40e_stat_update_48(hw, I40E_GLPRT_PTC255H(hw->port),
2018 I40E_GLPRT_PTC255L(hw->port),
2019 pf->offset_loaded, &os->tx_size_255,
2021 i40e_stat_update_48(hw, I40E_GLPRT_PTC511H(hw->port),
2022 I40E_GLPRT_PTC511L(hw->port),
2023 pf->offset_loaded, &os->tx_size_511,
2025 i40e_stat_update_48(hw, I40E_GLPRT_PTC1023H(hw->port),
2026 I40E_GLPRT_PTC1023L(hw->port),
2027 pf->offset_loaded, &os->tx_size_1023,
2029 i40e_stat_update_48(hw, I40E_GLPRT_PTC1522H(hw->port),
2030 I40E_GLPRT_PTC1522L(hw->port),
2031 pf->offset_loaded, &os->tx_size_1522,
2033 i40e_stat_update_48(hw, I40E_GLPRT_PTC9522H(hw->port),
2034 I40E_GLPRT_PTC9522L(hw->port),
2035 pf->offset_loaded, &os->tx_size_big,
2037 i40e_stat_update_32(hw, I40E_GLQF_PCNT(pf->fdir.match_counter_index),
2039 &os->fd_sb_match, &ns->fd_sb_match);
2040 /* GLPRT_MSPDC not supported */
2041 /* GLPRT_XEC not supported */
2043 pf->offset_loaded = true;
2046 i40e_update_vsi_stats(pf->main_vsi);
2049 /* Get all statistics of a port */
2051 i40e_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
2053 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2054 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2055 struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
2058 /* call read registers - updates values, now write them to struct */
2059 i40e_read_stats_registers(pf, hw);
2061 stats->ipackets = pf->main_vsi->eth_stats.rx_unicast +
2062 pf->main_vsi->eth_stats.rx_multicast +
2063 pf->main_vsi->eth_stats.rx_broadcast -
2064 pf->main_vsi->eth_stats.rx_discards;
2065 stats->opackets = pf->main_vsi->eth_stats.tx_unicast +
2066 pf->main_vsi->eth_stats.tx_multicast +
2067 pf->main_vsi->eth_stats.tx_broadcast;
2068 stats->ibytes = ns->eth.rx_bytes;
2069 stats->obytes = ns->eth.tx_bytes;
2070 stats->oerrors = ns->eth.tx_errors +
2071 pf->main_vsi->eth_stats.tx_errors;
2072 stats->imcasts = pf->main_vsi->eth_stats.rx_multicast;
2075 stats->imissed = ns->eth.rx_discards +
2076 pf->main_vsi->eth_stats.rx_discards;
2077 stats->ierrors = ns->crc_errors +
2078 ns->rx_length_errors + ns->rx_undersize +
2079 ns->rx_oversize + ns->rx_fragments + ns->rx_jabber +
2082 PMD_DRV_LOG(DEBUG, "***************** PF stats start *******************");
2083 PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", ns->eth.rx_bytes);
2084 PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", ns->eth.rx_unicast);
2085 PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", ns->eth.rx_multicast);
2086 PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", ns->eth.rx_broadcast);
2087 PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", ns->eth.rx_discards);
2088 PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
2089 ns->eth.rx_unknown_protocol);
2090 PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", ns->eth.tx_bytes);
2091 PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", ns->eth.tx_unicast);
2092 PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", ns->eth.tx_multicast);
2093 PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", ns->eth.tx_broadcast);
2094 PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", ns->eth.tx_discards);
2095 PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", ns->eth.tx_errors);
2097 PMD_DRV_LOG(DEBUG, "tx_dropped_link_down: %"PRIu64"",
2098 ns->tx_dropped_link_down);
2099 PMD_DRV_LOG(DEBUG, "crc_errors: %"PRIu64"", ns->crc_errors);
2100 PMD_DRV_LOG(DEBUG, "illegal_bytes: %"PRIu64"",
2102 PMD_DRV_LOG(DEBUG, "error_bytes: %"PRIu64"", ns->error_bytes);
2103 PMD_DRV_LOG(DEBUG, "mac_local_faults: %"PRIu64"",
2104 ns->mac_local_faults);
2105 PMD_DRV_LOG(DEBUG, "mac_remote_faults: %"PRIu64"",
2106 ns->mac_remote_faults);
2107 PMD_DRV_LOG(DEBUG, "rx_length_errors: %"PRIu64"",
2108 ns->rx_length_errors);
2109 PMD_DRV_LOG(DEBUG, "link_xon_rx: %"PRIu64"", ns->link_xon_rx);
2110 PMD_DRV_LOG(DEBUG, "link_xoff_rx: %"PRIu64"", ns->link_xoff_rx);
2111 for (i = 0; i < 8; i++) {
2112 PMD_DRV_LOG(DEBUG, "priority_xon_rx[%d]: %"PRIu64"",
2113 i, ns->priority_xon_rx[i]);
2114 PMD_DRV_LOG(DEBUG, "priority_xoff_rx[%d]: %"PRIu64"",
2115 i, ns->priority_xoff_rx[i]);
2117 PMD_DRV_LOG(DEBUG, "link_xon_tx: %"PRIu64"", ns->link_xon_tx);
2118 PMD_DRV_LOG(DEBUG, "link_xoff_tx: %"PRIu64"", ns->link_xoff_tx);
2119 for (i = 0; i < 8; i++) {
2120 PMD_DRV_LOG(DEBUG, "priority_xon_tx[%d]: %"PRIu64"",
2121 i, ns->priority_xon_tx[i]);
2122 PMD_DRV_LOG(DEBUG, "priority_xoff_tx[%d]: %"PRIu64"",
2123 i, ns->priority_xoff_tx[i]);
2124 PMD_DRV_LOG(DEBUG, "priority_xon_2_xoff[%d]: %"PRIu64"",
2125 i, ns->priority_xon_2_xoff[i]);
2127 PMD_DRV_LOG(DEBUG, "rx_size_64: %"PRIu64"", ns->rx_size_64);
2128 PMD_DRV_LOG(DEBUG, "rx_size_127: %"PRIu64"", ns->rx_size_127);
2129 PMD_DRV_LOG(DEBUG, "rx_size_255: %"PRIu64"", ns->rx_size_255);
2130 PMD_DRV_LOG(DEBUG, "rx_size_511: %"PRIu64"", ns->rx_size_511);
2131 PMD_DRV_LOG(DEBUG, "rx_size_1023: %"PRIu64"", ns->rx_size_1023);
2132 PMD_DRV_LOG(DEBUG, "rx_size_1522: %"PRIu64"", ns->rx_size_1522);
2133 PMD_DRV_LOG(DEBUG, "rx_size_big: %"PRIu64"", ns->rx_size_big);
2134 PMD_DRV_LOG(DEBUG, "rx_undersize: %"PRIu64"", ns->rx_undersize);
2135 PMD_DRV_LOG(DEBUG, "rx_fragments: %"PRIu64"", ns->rx_fragments);
2136 PMD_DRV_LOG(DEBUG, "rx_oversize: %"PRIu64"", ns->rx_oversize);
2137 PMD_DRV_LOG(DEBUG, "rx_jabber: %"PRIu64"", ns->rx_jabber);
2138 PMD_DRV_LOG(DEBUG, "tx_size_64: %"PRIu64"", ns->tx_size_64);
2139 PMD_DRV_LOG(DEBUG, "tx_size_127: %"PRIu64"", ns->tx_size_127);
2140 PMD_DRV_LOG(DEBUG, "tx_size_255: %"PRIu64"", ns->tx_size_255);
2141 PMD_DRV_LOG(DEBUG, "tx_size_511: %"PRIu64"", ns->tx_size_511);
2142 PMD_DRV_LOG(DEBUG, "tx_size_1023: %"PRIu64"", ns->tx_size_1023);
2143 PMD_DRV_LOG(DEBUG, "tx_size_1522: %"PRIu64"", ns->tx_size_1522);
2144 PMD_DRV_LOG(DEBUG, "tx_size_big: %"PRIu64"", ns->tx_size_big);
2145 PMD_DRV_LOG(DEBUG, "mac_short_packet_dropped: %"PRIu64"",
2146 ns->mac_short_packet_dropped);
2147 PMD_DRV_LOG(DEBUG, "checksum_error: %"PRIu64"",
2148 ns->checksum_error);
2149 PMD_DRV_LOG(DEBUG, "fdir_match: %"PRIu64"", ns->fd_sb_match);
2150 PMD_DRV_LOG(DEBUG, "***************** PF stats end ********************");
2153 /* Reset the statistics */
2155 i40e_dev_stats_reset(struct rte_eth_dev *dev)
2157 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2158 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2160 /* Mark PF and VSI stats to update the offset, aka "reset" */
2161 pf->offset_loaded = false;
2163 pf->main_vsi->offset_loaded = false;
2165 /* read the stats, reading current register values into offset */
2166 i40e_read_stats_registers(pf, hw);
2170 i40e_xstats_calc_num(void)
2172 return I40E_NB_ETH_XSTATS + I40E_NB_HW_PORT_XSTATS +
2173 (I40E_NB_RXQ_PRIO_XSTATS * 8) +
2174 (I40E_NB_TXQ_PRIO_XSTATS * 8);
2178 i40e_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstats *xstats,
2181 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2182 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2183 unsigned i, count, prio;
2184 struct i40e_hw_port_stats *hw_stats = &pf->stats;
2186 count = i40e_xstats_calc_num();
2190 i40e_read_stats_registers(pf, hw);
2197 /* Get stats from i40e_eth_stats struct */
2198 for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
2199 snprintf(xstats[count].name, sizeof(xstats[count].name),
2200 "%s", rte_i40e_stats_strings[i].name);
2201 xstats[count].value = *(uint64_t *)(((char *)&hw_stats->eth) +
2202 rte_i40e_stats_strings[i].offset);
2206 /* Get individiual stats from i40e_hw_port struct */
2207 for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
2208 snprintf(xstats[count].name, sizeof(xstats[count].name),
2209 "%s", rte_i40e_hw_port_strings[i].name);
2210 xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
2211 rte_i40e_hw_port_strings[i].offset);
2215 for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
2216 for (prio = 0; prio < 8; prio++) {
2217 snprintf(xstats[count].name,
2218 sizeof(xstats[count].name),
2219 "rx_priority%u_%s", prio,
2220 rte_i40e_rxq_prio_strings[i].name);
2221 xstats[count].value =
2222 *(uint64_t *)(((char *)hw_stats) +
2223 rte_i40e_rxq_prio_strings[i].offset +
2224 (sizeof(uint64_t) * prio));
2229 for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
2230 for (prio = 0; prio < 8; prio++) {
2231 snprintf(xstats[count].name,
2232 sizeof(xstats[count].name),
2233 "tx_priority%u_%s", prio,
2234 rte_i40e_txq_prio_strings[i].name);
2235 xstats[count].value =
2236 *(uint64_t *)(((char *)hw_stats) +
2237 rte_i40e_txq_prio_strings[i].offset +
2238 (sizeof(uint64_t) * prio));
2247 i40e_dev_queue_stats_mapping_set(__rte_unused struct rte_eth_dev *dev,
2248 __rte_unused uint16_t queue_id,
2249 __rte_unused uint8_t stat_idx,
2250 __rte_unused uint8_t is_rx)
2252 PMD_INIT_FUNC_TRACE();
2258 i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2260 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2261 struct i40e_vsi *vsi = pf->main_vsi;
2263 dev_info->max_rx_queues = vsi->nb_qps;
2264 dev_info->max_tx_queues = vsi->nb_qps;
2265 dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
2266 dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
2267 dev_info->max_mac_addrs = vsi->max_macaddrs;
2268 dev_info->max_vfs = dev->pci_dev->max_vfs;
2269 dev_info->rx_offload_capa =
2270 DEV_RX_OFFLOAD_VLAN_STRIP |
2271 DEV_RX_OFFLOAD_QINQ_STRIP |
2272 DEV_RX_OFFLOAD_IPV4_CKSUM |
2273 DEV_RX_OFFLOAD_UDP_CKSUM |
2274 DEV_RX_OFFLOAD_TCP_CKSUM;
2275 dev_info->tx_offload_capa =
2276 DEV_TX_OFFLOAD_VLAN_INSERT |
2277 DEV_TX_OFFLOAD_QINQ_INSERT |
2278 DEV_TX_OFFLOAD_IPV4_CKSUM |
2279 DEV_TX_OFFLOAD_UDP_CKSUM |
2280 DEV_TX_OFFLOAD_TCP_CKSUM |
2281 DEV_TX_OFFLOAD_SCTP_CKSUM |
2282 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
2283 DEV_TX_OFFLOAD_TCP_TSO;
2284 dev_info->hash_key_size = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
2286 dev_info->reta_size = pf->hash_lut_size;
2287 dev_info->flow_type_rss_offloads = I40E_RSS_OFFLOAD_ALL;
2289 dev_info->default_rxconf = (struct rte_eth_rxconf) {
2291 .pthresh = I40E_DEFAULT_RX_PTHRESH,
2292 .hthresh = I40E_DEFAULT_RX_HTHRESH,
2293 .wthresh = I40E_DEFAULT_RX_WTHRESH,
2295 .rx_free_thresh = I40E_DEFAULT_RX_FREE_THRESH,
2299 dev_info->default_txconf = (struct rte_eth_txconf) {
2301 .pthresh = I40E_DEFAULT_TX_PTHRESH,
2302 .hthresh = I40E_DEFAULT_TX_HTHRESH,
2303 .wthresh = I40E_DEFAULT_TX_WTHRESH,
2305 .tx_free_thresh = I40E_DEFAULT_TX_FREE_THRESH,
2306 .tx_rs_thresh = I40E_DEFAULT_TX_RSBIT_THRESH,
2307 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
2308 ETH_TXQ_FLAGS_NOOFFLOADS,
2311 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
2312 .nb_max = I40E_MAX_RING_DESC,
2313 .nb_min = I40E_MIN_RING_DESC,
2314 .nb_align = I40E_ALIGN_RING_DESC,
2317 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
2318 .nb_max = I40E_MAX_RING_DESC,
2319 .nb_min = I40E_MIN_RING_DESC,
2320 .nb_align = I40E_ALIGN_RING_DESC,
2323 if (pf->flags & I40E_FLAG_VMDQ) {
2324 dev_info->max_vmdq_pools = pf->max_nb_vmdq_vsi;
2325 dev_info->vmdq_queue_base = dev_info->max_rx_queues;
2326 dev_info->vmdq_queue_num = pf->vmdq_nb_qps *
2327 pf->max_nb_vmdq_vsi;
2328 dev_info->vmdq_pool_base = I40E_VMDQ_POOL_BASE;
2329 dev_info->max_rx_queues += dev_info->vmdq_queue_num;
2330 dev_info->max_tx_queues += dev_info->vmdq_queue_num;
2335 i40e_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
2337 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2338 struct i40e_vsi *vsi = pf->main_vsi;
2339 PMD_INIT_FUNC_TRACE();
2342 return i40e_vsi_add_vlan(vsi, vlan_id);
2344 return i40e_vsi_delete_vlan(vsi, vlan_id);
2348 i40e_vlan_tpid_set(struct rte_eth_dev *dev,
2349 enum rte_vlan_type vlan_type,
2352 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2353 uint64_t reg_r = 0, reg_w = 0;
2354 uint16_t reg_id = 0;
2357 switch (vlan_type) {
2358 case ETH_VLAN_TYPE_OUTER:
2361 case ETH_VLAN_TYPE_INNER:
2366 PMD_DRV_LOG(ERR, "Unsupported vlan type %d", vlan_type);
2369 ret = i40e_aq_debug_read_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
2371 if (ret != I40E_SUCCESS) {
2372 PMD_DRV_LOG(ERR, "Fail to debug read from "
2373 "I40E_GL_SWT_L2TAGCTRL[%d]", reg_id);
2377 PMD_DRV_LOG(DEBUG, "Debug read from I40E_GL_SWT_L2TAGCTRL[%d]: "
2378 "0x%08"PRIx64"", reg_id, reg_r);
2380 reg_w = reg_r & (~(I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_MASK));
2381 reg_w |= ((uint64_t)tpid << I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT);
2382 if (reg_r == reg_w) {
2384 PMD_DRV_LOG(DEBUG, "No need to write");
2388 ret = i40e_aq_debug_write_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
2390 if (ret != I40E_SUCCESS) {
2392 PMD_DRV_LOG(ERR, "Fail to debug write to "
2393 "I40E_GL_SWT_L2TAGCTRL[%d]", reg_id);
2396 PMD_DRV_LOG(DEBUG, "Debug write 0x%08"PRIx64" to "
2397 "I40E_GL_SWT_L2TAGCTRL[%d]", reg_w, reg_id);
2403 i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask)
2405 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2406 struct i40e_vsi *vsi = pf->main_vsi;
2408 if (mask & ETH_VLAN_FILTER_MASK) {
2409 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
2410 i40e_vsi_config_vlan_filter(vsi, TRUE);
2412 i40e_vsi_config_vlan_filter(vsi, FALSE);
2415 if (mask & ETH_VLAN_STRIP_MASK) {
2416 /* Enable or disable VLAN stripping */
2417 if (dev->data->dev_conf.rxmode.hw_vlan_strip)
2418 i40e_vsi_config_vlan_stripping(vsi, TRUE);
2420 i40e_vsi_config_vlan_stripping(vsi, FALSE);
2423 if (mask & ETH_VLAN_EXTEND_MASK) {
2424 if (dev->data->dev_conf.rxmode.hw_vlan_extend)
2425 i40e_vsi_config_double_vlan(vsi, TRUE);
2427 i40e_vsi_config_double_vlan(vsi, FALSE);
2432 i40e_vlan_strip_queue_set(__rte_unused struct rte_eth_dev *dev,
2433 __rte_unused uint16_t queue,
2434 __rte_unused int on)
2436 PMD_INIT_FUNC_TRACE();
2440 i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
2442 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2443 struct i40e_vsi *vsi = pf->main_vsi;
2444 struct rte_eth_dev_data *data = I40E_VSI_TO_DEV_DATA(vsi);
2445 struct i40e_vsi_vlan_pvid_info info;
2447 memset(&info, 0, sizeof(info));
2450 info.config.pvid = pvid;
2452 info.config.reject.tagged =
2453 data->dev_conf.txmode.hw_vlan_reject_tagged;
2454 info.config.reject.untagged =
2455 data->dev_conf.txmode.hw_vlan_reject_untagged;
2458 return i40e_vsi_vlan_pvid_set(vsi, &info);
2462 i40e_dev_led_on(struct rte_eth_dev *dev)
2464 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2465 uint32_t mode = i40e_led_get(hw);
2468 i40e_led_set(hw, 0xf, true); /* 0xf means led always true */
2474 i40e_dev_led_off(struct rte_eth_dev *dev)
2476 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2477 uint32_t mode = i40e_led_get(hw);
2480 i40e_led_set(hw, 0, false);
2486 i40e_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2488 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2489 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2491 fc_conf->pause_time = pf->fc_conf.pause_time;
2492 fc_conf->high_water = pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS];
2493 fc_conf->low_water = pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS];
2495 /* Return current mode according to actual setting*/
2496 switch (hw->fc.current_mode) {
2498 fc_conf->mode = RTE_FC_FULL;
2500 case I40E_FC_TX_PAUSE:
2501 fc_conf->mode = RTE_FC_TX_PAUSE;
2503 case I40E_FC_RX_PAUSE:
2504 fc_conf->mode = RTE_FC_RX_PAUSE;
2508 fc_conf->mode = RTE_FC_NONE;
2515 i40e_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
2517 uint32_t mflcn_reg, fctrl_reg, reg;
2518 uint32_t max_high_water;
2519 uint8_t i, aq_failure;
2523 enum i40e_fc_mode rte_fcmode_2_i40e_fcmode[] = {
2524 [RTE_FC_NONE] = I40E_FC_NONE,
2525 [RTE_FC_RX_PAUSE] = I40E_FC_RX_PAUSE,
2526 [RTE_FC_TX_PAUSE] = I40E_FC_TX_PAUSE,
2527 [RTE_FC_FULL] = I40E_FC_FULL
2530 /* high_water field in the rte_eth_fc_conf using the kilobytes unit */
2532 max_high_water = I40E_RXPBSIZE >> I40E_KILOSHIFT;
2533 if ((fc_conf->high_water > max_high_water) ||
2534 (fc_conf->high_water < fc_conf->low_water)) {
2535 PMD_INIT_LOG(ERR, "Invalid high/low water setup value in KB, "
2536 "High_water must <= %d.", max_high_water);
2540 hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2541 pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2542 hw->fc.requested_mode = rte_fcmode_2_i40e_fcmode[fc_conf->mode];
2544 pf->fc_conf.pause_time = fc_conf->pause_time;
2545 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->high_water;
2546 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->low_water;
2548 PMD_INIT_FUNC_TRACE();
2550 /* All the link flow control related enable/disable register
2551 * configuration is handle by the F/W
2553 err = i40e_set_fc(hw, &aq_failure, true);
2557 if (i40e_is_40G_device(hw->device_id)) {
2558 /* Configure flow control refresh threshold,
2559 * the value for stat_tx_pause_refresh_timer[8]
2560 * is used for global pause operation.
2564 I40E_PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER(8),
2565 pf->fc_conf.pause_time);
2567 /* configure the timer value included in transmitted pause
2569 * the value for stat_tx_pause_quanta[8] is used for global
2572 I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA(8),
2573 pf->fc_conf.pause_time);
2575 fctrl_reg = I40E_READ_REG(hw,
2576 I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL);
2578 if (fc_conf->mac_ctrl_frame_fwd != 0)
2579 fctrl_reg |= I40E_PRTMAC_FWD_CTRL;
2581 fctrl_reg &= ~I40E_PRTMAC_FWD_CTRL;
2583 I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL,
2586 /* Configure pause time (2 TCs per register) */
2587 reg = (uint32_t)pf->fc_conf.pause_time * (uint32_t)0x00010001;
2588 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS / 2; i++)
2589 I40E_WRITE_REG(hw, I40E_PRTDCB_FCTTVN(i), reg);
2591 /* Configure flow control refresh threshold value */
2592 I40E_WRITE_REG(hw, I40E_PRTDCB_FCRTV,
2593 pf->fc_conf.pause_time / 2);
2595 mflcn_reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
2597 /* set or clear MFLCN.PMCF & MFLCN.DPF bits
2598 *depending on configuration
2600 if (fc_conf->mac_ctrl_frame_fwd != 0) {
2601 mflcn_reg |= I40E_PRTDCB_MFLCN_PMCF_MASK;
2602 mflcn_reg &= ~I40E_PRTDCB_MFLCN_DPF_MASK;
2604 mflcn_reg &= ~I40E_PRTDCB_MFLCN_PMCF_MASK;
2605 mflcn_reg |= I40E_PRTDCB_MFLCN_DPF_MASK;
2608 I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, mflcn_reg);
2611 /* config the water marker both based on the packets and bytes */
2612 I40E_WRITE_REG(hw, I40E_GLRPB_PHW,
2613 (pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
2614 << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
2615 I40E_WRITE_REG(hw, I40E_GLRPB_PLW,
2616 (pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
2617 << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
2618 I40E_WRITE_REG(hw, I40E_GLRPB_GHW,
2619 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
2621 I40E_WRITE_REG(hw, I40E_GLRPB_GLW,
2622 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
2625 I40E_WRITE_FLUSH(hw);
2631 i40e_priority_flow_ctrl_set(__rte_unused struct rte_eth_dev *dev,
2632 __rte_unused struct rte_eth_pfc_conf *pfc_conf)
2634 PMD_INIT_FUNC_TRACE();
2639 /* Add a MAC address, and update filters */
2641 i40e_macaddr_add(struct rte_eth_dev *dev,
2642 struct ether_addr *mac_addr,
2643 __rte_unused uint32_t index,
2646 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2647 struct i40e_mac_filter_info mac_filter;
2648 struct i40e_vsi *vsi;
2651 /* If VMDQ not enabled or configured, return */
2652 if (pool != 0 && (!(pf->flags | I40E_FLAG_VMDQ) || !pf->nb_cfg_vmdq_vsi)) {
2653 PMD_DRV_LOG(ERR, "VMDQ not %s, can't set mac to pool %u",
2654 pf->flags | I40E_FLAG_VMDQ ? "configured" : "enabled",
2659 if (pool > pf->nb_cfg_vmdq_vsi) {
2660 PMD_DRV_LOG(ERR, "Pool number %u invalid. Max pool is %u",
2661 pool, pf->nb_cfg_vmdq_vsi);
2665 (void)rte_memcpy(&mac_filter.mac_addr, mac_addr, ETHER_ADDR_LEN);
2666 if (dev->data->dev_conf.rxmode.hw_vlan_filter)
2667 mac_filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
2669 mac_filter.filter_type = RTE_MAC_PERFECT_MATCH;
2674 vsi = pf->vmdq[pool - 1].vsi;
2676 ret = i40e_vsi_add_mac(vsi, &mac_filter);
2677 if (ret != I40E_SUCCESS) {
2678 PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
2683 /* Remove a MAC address, and update filters */
2685 i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
2687 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2688 struct i40e_vsi *vsi;
2689 struct rte_eth_dev_data *data = dev->data;
2690 struct ether_addr *macaddr;
2695 macaddr = &(data->mac_addrs[index]);
2697 pool_sel = dev->data->mac_pool_sel[index];
2699 for (i = 0; i < sizeof(pool_sel) * CHAR_BIT; i++) {
2700 if (pool_sel & (1ULL << i)) {
2704 /* No VMDQ pool enabled or configured */
2705 if (!(pf->flags | I40E_FLAG_VMDQ) ||
2706 (i > pf->nb_cfg_vmdq_vsi)) {
2707 PMD_DRV_LOG(ERR, "No VMDQ pool enabled"
2711 vsi = pf->vmdq[i - 1].vsi;
2713 ret = i40e_vsi_delete_mac(vsi, macaddr);
2716 PMD_DRV_LOG(ERR, "Failed to remove MACVLAN filter");
2723 /* Set perfect match or hash match of MAC and VLAN for a VF */
2725 i40e_vf_mac_filter_set(struct i40e_pf *pf,
2726 struct rte_eth_mac_filter *filter,
2730 struct i40e_mac_filter_info mac_filter;
2731 struct ether_addr old_mac;
2732 struct ether_addr *new_mac;
2733 struct i40e_pf_vf *vf = NULL;
2738 PMD_DRV_LOG(ERR, "Invalid PF argument.");
2741 hw = I40E_PF_TO_HW(pf);
2743 if (filter == NULL) {
2744 PMD_DRV_LOG(ERR, "Invalid mac filter argument.");
2748 new_mac = &filter->mac_addr;
2750 if (is_zero_ether_addr(new_mac)) {
2751 PMD_DRV_LOG(ERR, "Invalid ethernet address.");
2755 vf_id = filter->dst_id;
2757 if (vf_id > pf->vf_num - 1 || !pf->vfs) {
2758 PMD_DRV_LOG(ERR, "Invalid argument.");
2761 vf = &pf->vfs[vf_id];
2763 if (add && is_same_ether_addr(new_mac, &(pf->dev_addr))) {
2764 PMD_DRV_LOG(INFO, "Ignore adding permanent MAC address.");
2769 (void)rte_memcpy(&old_mac, hw->mac.addr, ETHER_ADDR_LEN);
2770 (void)rte_memcpy(hw->mac.addr, new_mac->addr_bytes,
2772 (void)rte_memcpy(&mac_filter.mac_addr, &filter->mac_addr,
2775 mac_filter.filter_type = filter->filter_type;
2776 ret = i40e_vsi_add_mac(vf->vsi, &mac_filter);
2777 if (ret != I40E_SUCCESS) {
2778 PMD_DRV_LOG(ERR, "Failed to add MAC filter.");
2781 ether_addr_copy(new_mac, &pf->dev_addr);
2783 (void)rte_memcpy(hw->mac.addr, hw->mac.perm_addr,
2785 ret = i40e_vsi_delete_mac(vf->vsi, &filter->mac_addr);
2786 if (ret != I40E_SUCCESS) {
2787 PMD_DRV_LOG(ERR, "Failed to delete MAC filter.");
2791 /* Clear device address as it has been removed */
2792 if (is_same_ether_addr(&(pf->dev_addr), new_mac))
2793 memset(&pf->dev_addr, 0, sizeof(struct ether_addr));
2799 /* MAC filter handle */
2801 i40e_mac_filter_handle(struct rte_eth_dev *dev, enum rte_filter_op filter_op,
2804 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2805 struct rte_eth_mac_filter *filter;
2806 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
2807 int ret = I40E_NOT_SUPPORTED;
2809 filter = (struct rte_eth_mac_filter *)(arg);
2811 switch (filter_op) {
2812 case RTE_ETH_FILTER_NOP:
2815 case RTE_ETH_FILTER_ADD:
2816 i40e_pf_disable_irq0(hw);
2818 ret = i40e_vf_mac_filter_set(pf, filter, 1);
2819 i40e_pf_enable_irq0(hw);
2821 case RTE_ETH_FILTER_DELETE:
2822 i40e_pf_disable_irq0(hw);
2824 ret = i40e_vf_mac_filter_set(pf, filter, 0);
2825 i40e_pf_enable_irq0(hw);
2828 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
2829 ret = I40E_ERR_PARAM;
2837 i40e_get_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
2839 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2840 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2846 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
2847 ret = i40e_aq_get_rss_lut(hw, vsi->vsi_id, TRUE,
2850 PMD_DRV_LOG(ERR, "Failed to get RSS lookup table");
2854 uint32_t *lut_dw = (uint32_t *)lut;
2855 uint16_t i, lut_size_dw = lut_size / 4;
2857 for (i = 0; i < lut_size_dw; i++)
2858 lut_dw[i] = I40E_READ_REG(hw, I40E_PFQF_HLUT(i));
2865 i40e_set_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
2867 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2868 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2874 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
2875 ret = i40e_aq_set_rss_lut(hw, vsi->vsi_id, TRUE,
2878 PMD_DRV_LOG(ERR, "Failed to set RSS lookup table");
2882 uint32_t *lut_dw = (uint32_t *)lut;
2883 uint16_t i, lut_size_dw = lut_size / 4;
2885 for (i = 0; i < lut_size_dw; i++)
2886 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
2887 I40E_WRITE_FLUSH(hw);
2894 i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
2895 struct rte_eth_rss_reta_entry64 *reta_conf,
2898 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2899 uint16_t i, lut_size = pf->hash_lut_size;
2900 uint16_t idx, shift;
2904 if (reta_size != lut_size ||
2905 reta_size > ETH_RSS_RETA_SIZE_512) {
2906 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2907 "(%d) doesn't match the number hardware can supported "
2908 "(%d)\n", reta_size, lut_size);
2912 lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
2914 PMD_DRV_LOG(ERR, "No memory can be allocated");
2917 ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
2920 for (i = 0; i < reta_size; i++) {
2921 idx = i / RTE_RETA_GROUP_SIZE;
2922 shift = i % RTE_RETA_GROUP_SIZE;
2923 if (reta_conf[idx].mask & (1ULL << shift))
2924 lut[i] = reta_conf[idx].reta[shift];
2926 ret = i40e_set_rss_lut(pf->main_vsi, lut, reta_size);
2935 i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
2936 struct rte_eth_rss_reta_entry64 *reta_conf,
2939 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2940 uint16_t i, lut_size = pf->hash_lut_size;
2941 uint16_t idx, shift;
2945 if (reta_size != lut_size ||
2946 reta_size > ETH_RSS_RETA_SIZE_512) {
2947 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2948 "(%d) doesn't match the number hardware can supported "
2949 "(%d)\n", reta_size, lut_size);
2953 lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
2955 PMD_DRV_LOG(ERR, "No memory can be allocated");
2959 ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
2962 for (i = 0; i < reta_size; i++) {
2963 idx = i / RTE_RETA_GROUP_SIZE;
2964 shift = i % RTE_RETA_GROUP_SIZE;
2965 if (reta_conf[idx].mask & (1ULL << shift))
2966 reta_conf[idx].reta[shift] = lut[i];
2976 * i40e_allocate_dma_mem_d - specific memory alloc for shared code (base driver)
2977 * @hw: pointer to the HW structure
2978 * @mem: pointer to mem struct to fill out
2979 * @size: size of memory requested
2980 * @alignment: what to align the allocation to
2982 enum i40e_status_code
2983 i40e_allocate_dma_mem_d(__attribute__((unused)) struct i40e_hw *hw,
2984 struct i40e_dma_mem *mem,
2988 const struct rte_memzone *mz = NULL;
2989 char z_name[RTE_MEMZONE_NAMESIZE];
2992 return I40E_ERR_PARAM;
2994 snprintf(z_name, sizeof(z_name), "i40e_dma_%"PRIu64, rte_rand());
2995 mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY, 0,
2996 alignment, RTE_PGSIZE_2M);
2998 return I40E_ERR_NO_MEMORY;
3002 mem->pa = rte_mem_phy2mch(mz->memseg_id, mz->phys_addr);
3003 mem->zone = (const void *)mz;
3004 PMD_DRV_LOG(DEBUG, "memzone %s allocated with physical address: "
3005 "%"PRIu64, mz->name, mem->pa);
3007 return I40E_SUCCESS;
3011 * i40e_free_dma_mem_d - specific memory free for shared code (base driver)
3012 * @hw: pointer to the HW structure
3013 * @mem: ptr to mem struct to free
3015 enum i40e_status_code
3016 i40e_free_dma_mem_d(__attribute__((unused)) struct i40e_hw *hw,
3017 struct i40e_dma_mem *mem)
3020 return I40E_ERR_PARAM;
3022 PMD_DRV_LOG(DEBUG, "memzone %s to be freed with physical address: "
3023 "%"PRIu64, ((const struct rte_memzone *)mem->zone)->name,
3025 rte_memzone_free((const struct rte_memzone *)mem->zone);
3030 return I40E_SUCCESS;
3034 * i40e_allocate_virt_mem_d - specific memory alloc for shared code (base driver)
3035 * @hw: pointer to the HW structure
3036 * @mem: pointer to mem struct to fill out
3037 * @size: size of memory requested
3039 enum i40e_status_code
3040 i40e_allocate_virt_mem_d(__attribute__((unused)) struct i40e_hw *hw,
3041 struct i40e_virt_mem *mem,
3045 return I40E_ERR_PARAM;
3048 mem->va = rte_zmalloc("i40e", size, 0);
3051 return I40E_SUCCESS;
3053 return I40E_ERR_NO_MEMORY;
3057 * i40e_free_virt_mem_d - specific memory free for shared code (base driver)
3058 * @hw: pointer to the HW structure
3059 * @mem: pointer to mem struct to free
3061 enum i40e_status_code
3062 i40e_free_virt_mem_d(__attribute__((unused)) struct i40e_hw *hw,
3063 struct i40e_virt_mem *mem)
3066 return I40E_ERR_PARAM;
3071 return I40E_SUCCESS;
3075 i40e_init_spinlock_d(struct i40e_spinlock *sp)
3077 rte_spinlock_init(&sp->spinlock);
3081 i40e_acquire_spinlock_d(struct i40e_spinlock *sp)
3083 rte_spinlock_lock(&sp->spinlock);
3087 i40e_release_spinlock_d(struct i40e_spinlock *sp)
3089 rte_spinlock_unlock(&sp->spinlock);
3093 i40e_destroy_spinlock_d(__attribute__((unused)) struct i40e_spinlock *sp)
3099 * Get the hardware capabilities, which will be parsed
3100 * and saved into struct i40e_hw.
3103 i40e_get_cap(struct i40e_hw *hw)
3105 struct i40e_aqc_list_capabilities_element_resp *buf;
3106 uint16_t len, size = 0;
3109 /* Calculate a huge enough buff for saving response data temporarily */
3110 len = sizeof(struct i40e_aqc_list_capabilities_element_resp) *
3111 I40E_MAX_CAP_ELE_NUM;
3112 buf = rte_zmalloc("i40e", len, 0);
3114 PMD_DRV_LOG(ERR, "Failed to allocate memory");
3115 return I40E_ERR_NO_MEMORY;
3118 /* Get, parse the capabilities and save it to hw */
3119 ret = i40e_aq_discover_capabilities(hw, buf, len, &size,
3120 i40e_aqc_opc_list_func_capabilities, NULL);
3121 if (ret != I40E_SUCCESS)
3122 PMD_DRV_LOG(ERR, "Failed to discover capabilities");
3124 /* Free the temporary buffer after being used */
3131 i40e_pf_parameter_init(struct rte_eth_dev *dev)
3133 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3134 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
3135 uint16_t qp_count = 0, vsi_count = 0;
3137 if (dev->pci_dev->max_vfs && !hw->func_caps.sr_iov_1_1) {
3138 PMD_INIT_LOG(ERR, "HW configuration doesn't support SRIOV");
3141 /* Add the parameter init for LFC */
3142 pf->fc_conf.pause_time = I40E_DEFAULT_PAUSE_TIME;
3143 pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_HIGH_WATER;
3144 pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_LOW_WATER;
3146 pf->flags = I40E_FLAG_HEADER_SPLIT_DISABLED;
3147 pf->max_num_vsi = hw->func_caps.num_vsis;
3148 pf->lan_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_PF;
3149 pf->vmdq_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
3150 pf->vf_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF;
3152 /* FDir queue/VSI allocation */
3153 pf->fdir_qp_offset = 0;
3154 if (hw->func_caps.fd) {
3155 pf->flags |= I40E_FLAG_FDIR;
3156 pf->fdir_nb_qps = I40E_DEFAULT_QP_NUM_FDIR;
3158 pf->fdir_nb_qps = 0;
3160 qp_count += pf->fdir_nb_qps;
3163 /* LAN queue/VSI allocation */
3164 pf->lan_qp_offset = pf->fdir_qp_offset + pf->fdir_nb_qps;
3165 if (!hw->func_caps.rss) {
3168 pf->flags |= I40E_FLAG_RSS;
3169 if (hw->mac.type == I40E_MAC_X722)
3170 pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE;
3171 pf->lan_nb_qps = pf->lan_nb_qp_max;
3173 qp_count += pf->lan_nb_qps;
3176 /* VF queue/VSI allocation */
3177 pf->vf_qp_offset = pf->lan_qp_offset + pf->lan_nb_qps;
3178 if (hw->func_caps.sr_iov_1_1 && dev->pci_dev->max_vfs) {
3179 pf->flags |= I40E_FLAG_SRIOV;
3180 pf->vf_nb_qps = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF;
3181 pf->vf_num = dev->pci_dev->max_vfs;
3182 PMD_DRV_LOG(DEBUG, "%u VF VSIs, %u queues per VF VSI, "
3183 "in total %u queues", pf->vf_num, pf->vf_nb_qps,
3184 pf->vf_nb_qps * pf->vf_num);
3189 qp_count += pf->vf_nb_qps * pf->vf_num;
3190 vsi_count += pf->vf_num;
3192 /* VMDq queue/VSI allocation */
3193 pf->vmdq_qp_offset = pf->vf_qp_offset + pf->vf_nb_qps * pf->vf_num;
3194 pf->vmdq_nb_qps = 0;
3195 pf->max_nb_vmdq_vsi = 0;
3196 if (hw->func_caps.vmdq) {
3197 if (qp_count < hw->func_caps.num_tx_qp &&
3198 vsi_count < hw->func_caps.num_vsis) {
3199 pf->max_nb_vmdq_vsi = (hw->func_caps.num_tx_qp -
3200 qp_count) / pf->vmdq_nb_qp_max;
3202 /* Limit the maximum number of VMDq vsi to the maximum
3203 * ethdev can support
3205 pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
3206 hw->func_caps.num_vsis - vsi_count);
3207 pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
3209 if (pf->max_nb_vmdq_vsi) {
3210 pf->flags |= I40E_FLAG_VMDQ;
3211 pf->vmdq_nb_qps = pf->vmdq_nb_qp_max;
3212 PMD_DRV_LOG(DEBUG, "%u VMDQ VSIs, %u queues "
3213 "per VMDQ VSI, in total %u queues",
3214 pf->max_nb_vmdq_vsi,
3215 pf->vmdq_nb_qps, pf->vmdq_nb_qps *
3216 pf->max_nb_vmdq_vsi);
3218 PMD_DRV_LOG(INFO, "No enough queues left for "
3222 PMD_DRV_LOG(INFO, "No queue or VSI left for VMDq");
3225 qp_count += pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi;
3226 vsi_count += pf->max_nb_vmdq_vsi;
3228 if (hw->func_caps.dcb)
3229 pf->flags |= I40E_FLAG_DCB;
3231 if (qp_count > hw->func_caps.num_tx_qp) {
3232 PMD_DRV_LOG(ERR, "Failed to allocate %u queues, which exceeds "
3233 "the hardware maximum %u", qp_count,
3234 hw->func_caps.num_tx_qp);
3237 if (vsi_count > hw->func_caps.num_vsis) {
3238 PMD_DRV_LOG(ERR, "Failed to allocate %u VSIs, which exceeds "
3239 "the hardware maximum %u", vsi_count,
3240 hw->func_caps.num_vsis);
3248 i40e_pf_get_switch_config(struct i40e_pf *pf)
3250 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
3251 struct i40e_aqc_get_switch_config_resp *switch_config;
3252 struct i40e_aqc_switch_config_element_resp *element;
3253 uint16_t start_seid = 0, num_reported;
3256 switch_config = (struct i40e_aqc_get_switch_config_resp *)\
3257 rte_zmalloc("i40e", I40E_AQ_LARGE_BUF, 0);
3258 if (!switch_config) {
3259 PMD_DRV_LOG(ERR, "Failed to allocated memory");
3263 /* Get the switch configurations */
3264 ret = i40e_aq_get_switch_config(hw, switch_config,
3265 I40E_AQ_LARGE_BUF, &start_seid, NULL);
3266 if (ret != I40E_SUCCESS) {
3267 PMD_DRV_LOG(ERR, "Failed to get switch configurations");
3270 num_reported = rte_le_to_cpu_16(switch_config->header.num_reported);
3271 if (num_reported != 1) { /* The number should be 1 */
3272 PMD_DRV_LOG(ERR, "Wrong number of switch config reported");
3276 /* Parse the switch configuration elements */
3277 element = &(switch_config->element[0]);
3278 if (element->element_type == I40E_SWITCH_ELEMENT_TYPE_VSI) {
3279 pf->mac_seid = rte_le_to_cpu_16(element->uplink_seid);
3280 pf->main_vsi_seid = rte_le_to_cpu_16(element->seid);
3282 PMD_DRV_LOG(INFO, "Unknown element type");
3285 rte_free(switch_config);
3291 i40e_res_pool_init (struct i40e_res_pool_info *pool, uint32_t base,
3294 struct pool_entry *entry;
3296 if (pool == NULL || num == 0)
3299 entry = rte_zmalloc("i40e", sizeof(*entry), 0);
3300 if (entry == NULL) {
3301 PMD_DRV_LOG(ERR, "Failed to allocate memory for resource pool");
3305 /* queue heap initialize */
3306 pool->num_free = num;
3307 pool->num_alloc = 0;
3309 LIST_INIT(&pool->alloc_list);
3310 LIST_INIT(&pool->free_list);
3312 /* Initialize element */
3316 LIST_INSERT_HEAD(&pool->free_list, entry, next);
3321 i40e_res_pool_destroy(struct i40e_res_pool_info *pool)
3323 struct pool_entry *entry;
3328 LIST_FOREACH(entry, &pool->alloc_list, next) {
3329 LIST_REMOVE(entry, next);
3333 LIST_FOREACH(entry, &pool->free_list, next) {
3334 LIST_REMOVE(entry, next);
3339 pool->num_alloc = 0;
3341 LIST_INIT(&pool->alloc_list);
3342 LIST_INIT(&pool->free_list);
3346 i40e_res_pool_free(struct i40e_res_pool_info *pool,
3349 struct pool_entry *entry, *next, *prev, *valid_entry = NULL;
3350 uint32_t pool_offset;
3354 PMD_DRV_LOG(ERR, "Invalid parameter");
3358 pool_offset = base - pool->base;
3359 /* Lookup in alloc list */
3360 LIST_FOREACH(entry, &pool->alloc_list, next) {
3361 if (entry->base == pool_offset) {
3362 valid_entry = entry;
3363 LIST_REMOVE(entry, next);
3368 /* Not find, return */
3369 if (valid_entry == NULL) {
3370 PMD_DRV_LOG(ERR, "Failed to find entry");
3375 * Found it, move it to free list and try to merge.
3376 * In order to make merge easier, always sort it by qbase.
3377 * Find adjacent prev and last entries.
3380 LIST_FOREACH(entry, &pool->free_list, next) {
3381 if (entry->base > valid_entry->base) {
3389 /* Try to merge with next one*/
3391 /* Merge with next one */
3392 if (valid_entry->base + valid_entry->len == next->base) {
3393 next->base = valid_entry->base;
3394 next->len += valid_entry->len;
3395 rte_free(valid_entry);
3402 /* Merge with previous one */
3403 if (prev->base + prev->len == valid_entry->base) {
3404 prev->len += valid_entry->len;
3405 /* If it merge with next one, remove next node */
3407 LIST_REMOVE(valid_entry, next);
3408 rte_free(valid_entry);
3410 rte_free(valid_entry);
3416 /* Not find any entry to merge, insert */
3419 LIST_INSERT_AFTER(prev, valid_entry, next);
3420 else if (next != NULL)
3421 LIST_INSERT_BEFORE(next, valid_entry, next);
3422 else /* It's empty list, insert to head */
3423 LIST_INSERT_HEAD(&pool->free_list, valid_entry, next);
3426 pool->num_free += valid_entry->len;
3427 pool->num_alloc -= valid_entry->len;
3433 i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
3436 struct pool_entry *entry, *valid_entry;
3438 if (pool == NULL || num == 0) {
3439 PMD_DRV_LOG(ERR, "Invalid parameter");
3443 if (pool->num_free < num) {
3444 PMD_DRV_LOG(ERR, "No resource. ask:%u, available:%u",
3445 num, pool->num_free);
3450 /* Lookup in free list and find most fit one */
3451 LIST_FOREACH(entry, &pool->free_list, next) {
3452 if (entry->len >= num) {
3454 if (entry->len == num) {
3455 valid_entry = entry;
3458 if (valid_entry == NULL || valid_entry->len > entry->len)
3459 valid_entry = entry;
3463 /* Not find one to satisfy the request, return */
3464 if (valid_entry == NULL) {
3465 PMD_DRV_LOG(ERR, "No valid entry found");
3469 * The entry have equal queue number as requested,
3470 * remove it from alloc_list.
3472 if (valid_entry->len == num) {
3473 LIST_REMOVE(valid_entry, next);
3476 * The entry have more numbers than requested,
3477 * create a new entry for alloc_list and minus its
3478 * queue base and number in free_list.
3480 entry = rte_zmalloc("res_pool", sizeof(*entry), 0);
3481 if (entry == NULL) {
3482 PMD_DRV_LOG(ERR, "Failed to allocate memory for "
3486 entry->base = valid_entry->base;
3488 valid_entry->base += num;
3489 valid_entry->len -= num;
3490 valid_entry = entry;
3493 /* Insert it into alloc list, not sorted */
3494 LIST_INSERT_HEAD(&pool->alloc_list, valid_entry, next);
3496 pool->num_free -= valid_entry->len;
3497 pool->num_alloc += valid_entry->len;
3499 return valid_entry->base + pool->base;
3503 * bitmap_is_subset - Check whether src2 is subset of src1
3506 bitmap_is_subset(uint8_t src1, uint8_t src2)
3508 return !((src1 ^ src2) & src2);
3511 static enum i40e_status_code
3512 validate_tcmap_parameter(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
3514 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3516 /* If DCB is not supported, only default TC is supported */
3517 if (!hw->func_caps.dcb && enabled_tcmap != I40E_DEFAULT_TCMAP) {
3518 PMD_DRV_LOG(ERR, "DCB is not enabled, only TC0 is supported");
3519 return I40E_NOT_SUPPORTED;
3522 if (!bitmap_is_subset(hw->func_caps.enabled_tcmap, enabled_tcmap)) {
3523 PMD_DRV_LOG(ERR, "Enabled TC map 0x%x not applicable to "
3524 "HW support 0x%x", hw->func_caps.enabled_tcmap,
3526 return I40E_NOT_SUPPORTED;
3528 return I40E_SUCCESS;
3532 i40e_vsi_vlan_pvid_set(struct i40e_vsi *vsi,
3533 struct i40e_vsi_vlan_pvid_info *info)
3536 struct i40e_vsi_context ctxt;
3537 uint8_t vlan_flags = 0;
3540 if (vsi == NULL || info == NULL) {
3541 PMD_DRV_LOG(ERR, "invalid parameters");
3542 return I40E_ERR_PARAM;
3546 vsi->info.pvid = info->config.pvid;
3548 * If insert pvid is enabled, only tagged pkts are
3549 * allowed to be sent out.
3551 vlan_flags |= I40E_AQ_VSI_PVLAN_INSERT_PVID |
3552 I40E_AQ_VSI_PVLAN_MODE_TAGGED;
3555 if (info->config.reject.tagged == 0)
3556 vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_TAGGED;
3558 if (info->config.reject.untagged == 0)
3559 vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_UNTAGGED;
3561 vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_INSERT_PVID |
3562 I40E_AQ_VSI_PVLAN_MODE_MASK);
3563 vsi->info.port_vlan_flags |= vlan_flags;
3564 vsi->info.valid_sections =
3565 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
3566 memset(&ctxt, 0, sizeof(ctxt));
3567 (void)rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
3568 ctxt.seid = vsi->seid;
3570 hw = I40E_VSI_TO_HW(vsi);
3571 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
3572 if (ret != I40E_SUCCESS)
3573 PMD_DRV_LOG(ERR, "Failed to update VSI params");
3579 i40e_vsi_update_tc_bandwidth(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
3581 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3583 struct i40e_aqc_configure_vsi_tc_bw_data tc_bw_data;
3585 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
3586 if (ret != I40E_SUCCESS)
3590 PMD_DRV_LOG(ERR, "seid not valid");
3594 memset(&tc_bw_data, 0, sizeof(tc_bw_data));
3595 tc_bw_data.tc_valid_bits = enabled_tcmap;
3596 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
3597 tc_bw_data.tc_bw_credits[i] =
3598 (enabled_tcmap & (1 << i)) ? 1 : 0;
3600 ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &tc_bw_data, NULL);
3601 if (ret != I40E_SUCCESS) {
3602 PMD_DRV_LOG(ERR, "Failed to configure TC BW");
3606 (void)rte_memcpy(vsi->info.qs_handle, tc_bw_data.qs_handles,
3607 sizeof(vsi->info.qs_handle));
3608 return I40E_SUCCESS;
3611 static enum i40e_status_code
3612 i40e_vsi_config_tc_queue_mapping(struct i40e_vsi *vsi,
3613 struct i40e_aqc_vsi_properties_data *info,
3614 uint8_t enabled_tcmap)
3616 enum i40e_status_code ret;
3617 int i, total_tc = 0;
3618 uint16_t qpnum_per_tc, bsf, qp_idx;
3620 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
3621 if (ret != I40E_SUCCESS)
3624 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
3625 if (enabled_tcmap & (1 << i))
3627 vsi->enabled_tc = enabled_tcmap;
3629 /* Number of queues per enabled TC */
3630 qpnum_per_tc = i40e_align_floor(vsi->nb_qps / total_tc);
3631 qpnum_per_tc = RTE_MIN(qpnum_per_tc, I40E_MAX_Q_PER_TC);
3632 bsf = rte_bsf32(qpnum_per_tc);
3634 /* Adjust the queue number to actual queues that can be applied */
3635 if (!(vsi->type == I40E_VSI_MAIN && total_tc == 1))
3636 vsi->nb_qps = qpnum_per_tc * total_tc;
3639 * Configure TC and queue mapping parameters, for enabled TC,
3640 * allocate qpnum_per_tc queues to this traffic. For disabled TC,
3641 * default queue will serve it.
3644 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
3645 if (vsi->enabled_tc & (1 << i)) {
3646 info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
3647 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
3648 (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
3649 qp_idx += qpnum_per_tc;
3651 info->tc_mapping[i] = 0;
3654 /* Associate queue number with VSI */
3655 if (vsi->type == I40E_VSI_SRIOV) {
3656 info->mapping_flags |=
3657 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
3658 for (i = 0; i < vsi->nb_qps; i++)
3659 info->queue_mapping[i] =
3660 rte_cpu_to_le_16(vsi->base_queue + i);
3662 info->mapping_flags |=
3663 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
3664 info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
3666 info->valid_sections |=
3667 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
3669 return I40E_SUCCESS;
3673 i40e_veb_release(struct i40e_veb *veb)
3675 struct i40e_vsi *vsi;
3678 if (veb == NULL || veb->associate_vsi == NULL)
3681 if (!TAILQ_EMPTY(&veb->head)) {
3682 PMD_DRV_LOG(ERR, "VEB still has VSI attached, can't remove");
3686 vsi = veb->associate_vsi;
3687 hw = I40E_VSI_TO_HW(vsi);
3689 vsi->uplink_seid = veb->uplink_seid;
3690 i40e_aq_delete_element(hw, veb->seid, NULL);
3693 return I40E_SUCCESS;
3697 static struct i40e_veb *
3698 i40e_veb_setup(struct i40e_pf *pf, struct i40e_vsi *vsi)
3700 struct i40e_veb *veb;
3704 if (NULL == pf || vsi == NULL) {
3705 PMD_DRV_LOG(ERR, "veb setup failed, "
3706 "associated VSI shouldn't null");
3709 hw = I40E_PF_TO_HW(pf);
3711 veb = rte_zmalloc("i40e_veb", sizeof(struct i40e_veb), 0);
3713 PMD_DRV_LOG(ERR, "Failed to allocate memory for veb");
3717 veb->associate_vsi = vsi;
3718 TAILQ_INIT(&veb->head);
3719 veb->uplink_seid = vsi->uplink_seid;
3721 ret = i40e_aq_add_veb(hw, veb->uplink_seid, vsi->seid,
3722 I40E_DEFAULT_TCMAP, false, &veb->seid, false, NULL);
3724 if (ret != I40E_SUCCESS) {
3725 PMD_DRV_LOG(ERR, "Add veb failed, aq_err: %d",
3726 hw->aq.asq_last_status);
3730 /* get statistics index */
3731 ret = i40e_aq_get_veb_parameters(hw, veb->seid, NULL, NULL,
3732 &veb->stats_idx, NULL, NULL, NULL);
3733 if (ret != I40E_SUCCESS) {
3734 PMD_DRV_LOG(ERR, "Get veb statics index failed, aq_err: %d",
3735 hw->aq.asq_last_status);
3739 /* Get VEB bandwidth, to be implemented */
3740 /* Now associated vsi binding to the VEB, set uplink to this VEB */
3741 vsi->uplink_seid = veb->seid;
3750 i40e_vsi_release(struct i40e_vsi *vsi)
3754 struct i40e_vsi_list *vsi_list;
3756 struct i40e_mac_filter *f;
3759 return I40E_SUCCESS;
3761 pf = I40E_VSI_TO_PF(vsi);
3762 hw = I40E_VSI_TO_HW(vsi);
3764 /* VSI has child to attach, release child first */
3766 TAILQ_FOREACH(vsi_list, &vsi->veb->head, list) {
3767 if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
3769 TAILQ_REMOVE(&vsi->veb->head, vsi_list, list);
3771 i40e_veb_release(vsi->veb);
3774 /* Remove all macvlan filters of the VSI */
3775 i40e_vsi_remove_all_macvlan_filter(vsi);
3776 TAILQ_FOREACH(f, &vsi->mac_list, next)
3779 if (vsi->type != I40E_VSI_MAIN) {
3780 /* Remove vsi from parent's sibling list */
3781 if (vsi->parent_vsi == NULL || vsi->parent_vsi->veb == NULL) {
3782 PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
3783 return I40E_ERR_PARAM;
3785 TAILQ_REMOVE(&vsi->parent_vsi->veb->head,
3786 &vsi->sib_vsi_list, list);
3788 /* Remove all switch element of the VSI */
3789 ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
3790 if (ret != I40E_SUCCESS)
3791 PMD_DRV_LOG(ERR, "Failed to delete element");
3793 i40e_res_pool_free(&pf->qp_pool, vsi->base_queue);
3795 if (vsi->type != I40E_VSI_SRIOV)
3796 i40e_res_pool_free(&pf->msix_pool, vsi->msix_intr);
3799 return I40E_SUCCESS;
3803 i40e_update_default_filter_setting(struct i40e_vsi *vsi)
3805 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3806 struct i40e_aqc_remove_macvlan_element_data def_filter;
3807 struct i40e_mac_filter_info filter;
3810 if (vsi->type != I40E_VSI_MAIN)
3811 return I40E_ERR_CONFIG;
3812 memset(&def_filter, 0, sizeof(def_filter));
3813 (void)rte_memcpy(def_filter.mac_addr, hw->mac.perm_addr,
3815 def_filter.vlan_tag = 0;
3816 def_filter.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
3817 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
3818 ret = i40e_aq_remove_macvlan(hw, vsi->seid, &def_filter, 1, NULL);
3819 if (ret != I40E_SUCCESS) {
3820 struct i40e_mac_filter *f;
3821 struct ether_addr *mac;
3823 PMD_DRV_LOG(WARNING, "Cannot remove the default "
3825 /* It needs to add the permanent mac into mac list */
3826 f = rte_zmalloc("macv_filter", sizeof(*f), 0);
3828 PMD_DRV_LOG(ERR, "failed to allocate memory");
3829 return I40E_ERR_NO_MEMORY;
3831 mac = &f->mac_info.mac_addr;
3832 (void)rte_memcpy(&mac->addr_bytes, hw->mac.perm_addr,
3834 f->mac_info.filter_type = RTE_MACVLAN_PERFECT_MATCH;
3835 TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
3840 (void)rte_memcpy(&filter.mac_addr,
3841 (struct ether_addr *)(hw->mac.perm_addr), ETH_ADDR_LEN);
3842 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
3843 return i40e_vsi_add_mac(vsi, &filter);
3846 #define I40E_3_BIT_MASK 0x7
3848 * i40e_vsi_get_bw_config - Query VSI BW Information
3849 * @vsi: the VSI to be queried
3851 * Returns 0 on success, negative value on failure
3853 static enum i40e_status_code
3854 i40e_vsi_get_bw_config(struct i40e_vsi *vsi)
3856 struct i40e_aqc_query_vsi_bw_config_resp bw_config;
3857 struct i40e_aqc_query_vsi_ets_sla_config_resp ets_sla_config;
3858 struct i40e_hw *hw = &vsi->adapter->hw;
3863 memset(&bw_config, 0, sizeof(bw_config));
3864 ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
3865 if (ret != I40E_SUCCESS) {
3866 PMD_DRV_LOG(ERR, "VSI failed to get bandwidth configuration %u",
3867 hw->aq.asq_last_status);
3871 memset(&ets_sla_config, 0, sizeof(ets_sla_config));
3872 ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid,
3873 &ets_sla_config, NULL);
3874 if (ret != I40E_SUCCESS) {
3875 PMD_DRV_LOG(ERR, "VSI failed to get TC bandwdith "
3876 "configuration %u", hw->aq.asq_last_status);
3880 /* store and print out BW info */
3881 vsi->bw_info.bw_limit = rte_le_to_cpu_16(bw_config.port_bw_limit);
3882 vsi->bw_info.bw_max = bw_config.max_bw;
3883 PMD_DRV_LOG(DEBUG, "VSI bw limit:%u", vsi->bw_info.bw_limit);
3884 PMD_DRV_LOG(DEBUG, "VSI max_bw:%u", vsi->bw_info.bw_max);
3885 bw_max = rte_le_to_cpu_16(ets_sla_config.tc_bw_max[0]) |
3886 (rte_le_to_cpu_16(ets_sla_config.tc_bw_max[1]) <<
3888 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
3889 vsi->bw_info.bw_ets_share_credits[i] =
3890 ets_sla_config.share_credits[i];
3891 vsi->bw_info.bw_ets_credits[i] =
3892 rte_le_to_cpu_16(ets_sla_config.credits[i]);
3893 /* 4 bits per TC, 4th bit is reserved */
3894 vsi->bw_info.bw_ets_max[i] =
3895 (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
3897 PMD_DRV_LOG(DEBUG, "\tVSI TC%u:share credits %u", i,
3898 vsi->bw_info.bw_ets_share_credits[i]);
3899 PMD_DRV_LOG(DEBUG, "\tVSI TC%u:credits %u", i,
3900 vsi->bw_info.bw_ets_credits[i]);
3901 PMD_DRV_LOG(DEBUG, "\tVSI TC%u: max credits: %u", i,
3902 vsi->bw_info.bw_ets_max[i]);
3905 return I40E_SUCCESS;
3910 i40e_vsi_setup(struct i40e_pf *pf,
3911 enum i40e_vsi_type type,
3912 struct i40e_vsi *uplink_vsi,
3913 uint16_t user_param)
3915 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
3916 struct i40e_vsi *vsi;
3917 struct i40e_mac_filter_info filter;
3919 struct i40e_vsi_context ctxt;
3920 struct ether_addr broadcast =
3921 {.addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
3923 if (type != I40E_VSI_MAIN && uplink_vsi == NULL) {
3924 PMD_DRV_LOG(ERR, "VSI setup failed, "
3925 "VSI link shouldn't be NULL");
3929 if (type == I40E_VSI_MAIN && uplink_vsi != NULL) {
3930 PMD_DRV_LOG(ERR, "VSI setup failed, MAIN VSI "
3931 "uplink VSI should be NULL");
3935 /* If uplink vsi didn't setup VEB, create one first */
3936 if (type != I40E_VSI_MAIN && uplink_vsi->veb == NULL) {
3937 uplink_vsi->veb = i40e_veb_setup(pf, uplink_vsi);
3939 if (NULL == uplink_vsi->veb) {
3940 PMD_DRV_LOG(ERR, "VEB setup failed");
3945 vsi = rte_zmalloc("i40e_vsi", sizeof(struct i40e_vsi), 0);
3947 PMD_DRV_LOG(ERR, "Failed to allocate memory for vsi");
3950 TAILQ_INIT(&vsi->mac_list);
3952 vsi->adapter = I40E_PF_TO_ADAPTER(pf);
3953 vsi->max_macaddrs = I40E_NUM_MACADDR_MAX;
3954 vsi->parent_vsi = uplink_vsi;
3955 vsi->user_param = user_param;
3956 /* Allocate queues */
3957 switch (vsi->type) {
3958 case I40E_VSI_MAIN :
3959 vsi->nb_qps = pf->lan_nb_qps;
3961 case I40E_VSI_SRIOV :
3962 vsi->nb_qps = pf->vf_nb_qps;
3964 case I40E_VSI_VMDQ2:
3965 vsi->nb_qps = pf->vmdq_nb_qps;
3968 vsi->nb_qps = pf->fdir_nb_qps;
3974 * The filter status descriptor is reported in rx queue 0,
3975 * while the tx queue for fdir filter programming has no
3976 * such constraints, can be non-zero queues.
3977 * To simplify it, choose FDIR vsi use queue 0 pair.
3978 * To make sure it will use queue 0 pair, queue allocation
3979 * need be done before this function is called
3981 if (type != I40E_VSI_FDIR) {
3982 ret = i40e_res_pool_alloc(&pf->qp_pool, vsi->nb_qps);
3984 PMD_DRV_LOG(ERR, "VSI %d allocate queue failed %d",
3988 vsi->base_queue = ret;
3990 vsi->base_queue = I40E_FDIR_QUEUE_ID;
3992 /* VF has MSIX interrupt in VF range, don't allocate here */
3993 if (type == I40E_VSI_MAIN) {
3994 ret = i40e_res_pool_alloc(&pf->msix_pool,
3995 RTE_MIN(vsi->nb_qps,
3996 RTE_MAX_RXTX_INTR_VEC_ID));
3998 PMD_DRV_LOG(ERR, "VSI MAIN %d get heap failed %d",
4000 goto fail_queue_alloc;
4002 vsi->msix_intr = ret;
4003 vsi->nb_msix = RTE_MIN(vsi->nb_qps, RTE_MAX_RXTX_INTR_VEC_ID);
4004 } else if (type != I40E_VSI_SRIOV) {
4005 ret = i40e_res_pool_alloc(&pf->msix_pool, 1);
4007 PMD_DRV_LOG(ERR, "VSI %d get heap failed %d", vsi->seid, ret);
4008 goto fail_queue_alloc;
4010 vsi->msix_intr = ret;
4018 if (type == I40E_VSI_MAIN) {
4019 /* For main VSI, no need to add since it's default one */
4020 vsi->uplink_seid = pf->mac_seid;
4021 vsi->seid = pf->main_vsi_seid;
4022 /* Bind queues with specific MSIX interrupt */
4024 * Needs 2 interrupt at least, one for misc cause which will
4025 * enabled from OS side, Another for queues binding the
4026 * interrupt from device side only.
4029 /* Get default VSI parameters from hardware */
4030 memset(&ctxt, 0, sizeof(ctxt));
4031 ctxt.seid = vsi->seid;
4032 ctxt.pf_num = hw->pf_id;
4033 ctxt.uplink_seid = vsi->uplink_seid;
4035 ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
4036 if (ret != I40E_SUCCESS) {
4037 PMD_DRV_LOG(ERR, "Failed to get VSI params");
4038 goto fail_msix_alloc;
4040 (void)rte_memcpy(&vsi->info, &ctxt.info,
4041 sizeof(struct i40e_aqc_vsi_properties_data));
4042 vsi->vsi_id = ctxt.vsi_number;
4043 vsi->info.valid_sections = 0;
4045 /* Configure tc, enabled TC0 only */
4046 if (i40e_vsi_update_tc_bandwidth(vsi, I40E_DEFAULT_TCMAP) !=
4048 PMD_DRV_LOG(ERR, "Failed to update TC bandwidth");
4049 goto fail_msix_alloc;
4052 /* TC, queue mapping */
4053 memset(&ctxt, 0, sizeof(ctxt));
4054 vsi->info.valid_sections |=
4055 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
4056 vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
4057 I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
4058 (void)rte_memcpy(&ctxt.info, &vsi->info,
4059 sizeof(struct i40e_aqc_vsi_properties_data));
4060 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
4061 I40E_DEFAULT_TCMAP);
4062 if (ret != I40E_SUCCESS) {
4063 PMD_DRV_LOG(ERR, "Failed to configure "
4064 "TC queue mapping");
4065 goto fail_msix_alloc;
4067 ctxt.seid = vsi->seid;
4068 ctxt.pf_num = hw->pf_id;
4069 ctxt.uplink_seid = vsi->uplink_seid;
4072 /* Update VSI parameters */
4073 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
4074 if (ret != I40E_SUCCESS) {
4075 PMD_DRV_LOG(ERR, "Failed to update VSI params");
4076 goto fail_msix_alloc;
4079 (void)rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
4080 sizeof(vsi->info.tc_mapping));
4081 (void)rte_memcpy(&vsi->info.queue_mapping,
4082 &ctxt.info.queue_mapping,
4083 sizeof(vsi->info.queue_mapping));
4084 vsi->info.mapping_flags = ctxt.info.mapping_flags;
4085 vsi->info.valid_sections = 0;
4087 (void)rte_memcpy(pf->dev_addr.addr_bytes, hw->mac.perm_addr,
4091 * Updating default filter settings are necessary to prevent
4092 * reception of tagged packets.
4093 * Some old firmware configurations load a default macvlan
4094 * filter which accepts both tagged and untagged packets.
4095 * The updating is to use a normal filter instead if needed.
4096 * For NVM 4.2.2 or after, the updating is not needed anymore.
4097 * The firmware with correct configurations load the default
4098 * macvlan filter which is expected and cannot be removed.
4100 i40e_update_default_filter_setting(vsi);
4101 i40e_config_qinq(hw, vsi);
4102 } else if (type == I40E_VSI_SRIOV) {
4103 memset(&ctxt, 0, sizeof(ctxt));
4105 * For other VSI, the uplink_seid equals to uplink VSI's
4106 * uplink_seid since they share same VEB
4108 vsi->uplink_seid = uplink_vsi->uplink_seid;
4109 ctxt.pf_num = hw->pf_id;
4110 ctxt.vf_num = hw->func_caps.vf_base_id + user_param;
4111 ctxt.uplink_seid = vsi->uplink_seid;
4112 ctxt.connection_type = 0x1;
4113 ctxt.flags = I40E_AQ_VSI_TYPE_VF;
4116 * Do not configure switch ID to enable VEB switch by
4117 * I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB. Because in Fortville,
4118 * if the source mac address of packet sent from VF is not
4119 * listed in the VEB's mac table, the VEB will switch the
4120 * packet back to the VF. Need to enable it when HW issue
4124 /* Configure port/vlan */
4125 ctxt.info.valid_sections |=
4126 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
4127 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
4128 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
4129 I40E_DEFAULT_TCMAP);
4130 if (ret != I40E_SUCCESS) {
4131 PMD_DRV_LOG(ERR, "Failed to configure "
4132 "TC queue mapping");
4133 goto fail_msix_alloc;
4135 ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
4136 ctxt.info.valid_sections |=
4137 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
4139 * Since VSI is not created yet, only configure parameter,
4140 * will add vsi below.
4143 i40e_config_qinq(hw, vsi);
4144 } else if (type == I40E_VSI_VMDQ2) {
4145 memset(&ctxt, 0, sizeof(ctxt));
4147 * For other VSI, the uplink_seid equals to uplink VSI's
4148 * uplink_seid since they share same VEB
4150 vsi->uplink_seid = uplink_vsi->uplink_seid;
4151 ctxt.pf_num = hw->pf_id;
4153 ctxt.uplink_seid = vsi->uplink_seid;
4154 ctxt.connection_type = 0x1;
4155 ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
4157 ctxt.info.valid_sections |=
4158 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
4159 /* user_param carries flag to enable loop back */
4161 ctxt.info.switch_id =
4162 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
4163 ctxt.info.switch_id |=
4164 rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
4167 /* Configure port/vlan */
4168 ctxt.info.valid_sections |=
4169 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
4170 ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
4171 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
4172 I40E_DEFAULT_TCMAP);
4173 if (ret != I40E_SUCCESS) {
4174 PMD_DRV_LOG(ERR, "Failed to configure "
4175 "TC queue mapping");
4176 goto fail_msix_alloc;
4178 ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
4179 ctxt.info.valid_sections |=
4180 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
4181 } else if (type == I40E_VSI_FDIR) {
4182 memset(&ctxt, 0, sizeof(ctxt));
4183 vsi->uplink_seid = uplink_vsi->uplink_seid;
4184 ctxt.pf_num = hw->pf_id;
4186 ctxt.uplink_seid = vsi->uplink_seid;
4187 ctxt.connection_type = 0x1; /* regular data port */
4188 ctxt.flags = I40E_AQ_VSI_TYPE_PF;
4189 ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
4190 I40E_DEFAULT_TCMAP);
4191 if (ret != I40E_SUCCESS) {
4192 PMD_DRV_LOG(ERR, "Failed to configure "
4193 "TC queue mapping.");
4194 goto fail_msix_alloc;
4196 ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
4197 ctxt.info.valid_sections |=
4198 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
4200 PMD_DRV_LOG(ERR, "VSI: Not support other type VSI yet");
4201 goto fail_msix_alloc;
4204 if (vsi->type != I40E_VSI_MAIN) {
4205 ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
4206 if (ret != I40E_SUCCESS) {
4207 PMD_DRV_LOG(ERR, "add vsi failed, aq_err=%d",
4208 hw->aq.asq_last_status);
4209 goto fail_msix_alloc;
4211 memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
4212 vsi->info.valid_sections = 0;
4213 vsi->seid = ctxt.seid;
4214 vsi->vsi_id = ctxt.vsi_number;
4215 vsi->sib_vsi_list.vsi = vsi;
4216 TAILQ_INSERT_TAIL(&uplink_vsi->veb->head,
4217 &vsi->sib_vsi_list, list);
4220 /* MAC/VLAN configuration */
4221 (void)rte_memcpy(&filter.mac_addr, &broadcast, ETHER_ADDR_LEN);
4222 filter.filter_type = RTE_MACVLAN_PERFECT_MATCH;
4224 ret = i40e_vsi_add_mac(vsi, &filter);
4225 if (ret != I40E_SUCCESS) {
4226 PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
4227 goto fail_msix_alloc;
4230 /* Get VSI BW information */
4231 i40e_vsi_get_bw_config(vsi);
4234 i40e_res_pool_free(&pf->msix_pool,vsi->msix_intr);
4236 i40e_res_pool_free(&pf->qp_pool,vsi->base_queue);
4242 /* Configure vlan filter on or off */
4244 i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on)
4247 struct i40e_mac_filter *f;
4248 struct i40e_mac_filter_info *mac_filter;
4249 enum rte_mac_filter_type desired_filter;
4250 int ret = I40E_SUCCESS;
4253 /* Filter to match MAC and VLAN */
4254 desired_filter = RTE_MACVLAN_PERFECT_MATCH;
4256 /* Filter to match only MAC */
4257 desired_filter = RTE_MAC_PERFECT_MATCH;
4262 mac_filter = rte_zmalloc("mac_filter_info_data",
4263 num * sizeof(*mac_filter), 0);
4264 if (mac_filter == NULL) {
4265 PMD_DRV_LOG(ERR, "failed to allocate memory");
4266 return I40E_ERR_NO_MEMORY;
4271 /* Remove all existing mac */
4272 TAILQ_FOREACH(f, &vsi->mac_list, next) {
4273 mac_filter[i] = f->mac_info;
4274 ret = i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
4276 PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
4277 on ? "enable" : "disable");
4283 /* Override with new filter */
4284 for (i = 0; i < num; i++) {
4285 mac_filter[i].filter_type = desired_filter;
4286 ret = i40e_vsi_add_mac(vsi, &mac_filter[i]);
4288 PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
4289 on ? "enable" : "disable");
4295 rte_free(mac_filter);
4299 /* Configure vlan stripping on or off */
4301 i40e_vsi_config_vlan_stripping(struct i40e_vsi *vsi, bool on)
4303 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4304 struct i40e_vsi_context ctxt;
4306 int ret = I40E_SUCCESS;
4308 /* Check if it has been already on or off */
4309 if (vsi->info.valid_sections &
4310 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID)) {
4312 if ((vsi->info.port_vlan_flags &
4313 I40E_AQ_VSI_PVLAN_EMOD_MASK) == 0)
4314 return 0; /* already on */
4316 if ((vsi->info.port_vlan_flags &
4317 I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
4318 I40E_AQ_VSI_PVLAN_EMOD_MASK)
4319 return 0; /* already off */
4324 vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
4326 vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
4327 vsi->info.valid_sections =
4328 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
4329 vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_EMOD_MASK);
4330 vsi->info.port_vlan_flags |= vlan_flags;
4331 ctxt.seid = vsi->seid;
4332 (void)rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
4333 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
4335 PMD_DRV_LOG(INFO, "Update VSI failed to %s vlan stripping",
4336 on ? "enable" : "disable");
4342 i40e_dev_init_vlan(struct rte_eth_dev *dev)
4344 struct rte_eth_dev_data *data = dev->data;
4348 /* Apply vlan offload setting */
4349 mask = ETH_VLAN_STRIP_MASK | ETH_VLAN_FILTER_MASK;
4350 i40e_vlan_offload_set(dev, mask);
4352 /* Apply double-vlan setting, not implemented yet */
4354 /* Apply pvid setting */
4355 ret = i40e_vlan_pvid_set(dev, data->dev_conf.txmode.pvid,
4356 data->dev_conf.txmode.hw_vlan_insert_pvid);
4358 PMD_DRV_LOG(INFO, "Failed to update VSI params");
4364 i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on)
4366 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4368 return i40e_aq_set_port_parameters(hw, vsi->seid, 0, 1, on, NULL);
4372 i40e_update_flow_control(struct i40e_hw *hw)
4374 #define I40E_LINK_PAUSE_RXTX (I40E_AQ_LINK_PAUSE_RX | I40E_AQ_LINK_PAUSE_TX)
4375 struct i40e_link_status link_status;
4376 uint32_t rxfc = 0, txfc = 0, reg;
4380 memset(&link_status, 0, sizeof(link_status));
4381 ret = i40e_aq_get_link_info(hw, FALSE, &link_status, NULL);
4382 if (ret != I40E_SUCCESS) {
4383 PMD_DRV_LOG(ERR, "Failed to get link status information");
4384 goto write_reg; /* Disable flow control */
4387 an_info = hw->phy.link_info.an_info;
4388 if (!(an_info & I40E_AQ_AN_COMPLETED)) {
4389 PMD_DRV_LOG(INFO, "Link auto negotiation not completed");
4390 ret = I40E_ERR_NOT_READY;
4391 goto write_reg; /* Disable flow control */
4394 * If link auto negotiation is enabled, flow control needs to
4395 * be configured according to it
4397 switch (an_info & I40E_LINK_PAUSE_RXTX) {
4398 case I40E_LINK_PAUSE_RXTX:
4401 hw->fc.current_mode = I40E_FC_FULL;
4403 case I40E_AQ_LINK_PAUSE_RX:
4405 hw->fc.current_mode = I40E_FC_RX_PAUSE;
4407 case I40E_AQ_LINK_PAUSE_TX:
4409 hw->fc.current_mode = I40E_FC_TX_PAUSE;
4412 hw->fc.current_mode = I40E_FC_NONE;
4417 I40E_WRITE_REG(hw, I40E_PRTDCB_FCCFG,
4418 txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT);
4419 reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
4420 reg &= ~I40E_PRTDCB_MFLCN_RFCE_MASK;
4421 reg |= rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT;
4422 I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, reg);
4429 i40e_pf_setup(struct i40e_pf *pf)
4431 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4432 struct i40e_filter_control_settings settings;
4433 struct i40e_vsi *vsi;
4436 /* Clear all stats counters */
4437 pf->offset_loaded = FALSE;
4438 memset(&pf->stats, 0, sizeof(struct i40e_hw_port_stats));
4439 memset(&pf->stats_offset, 0, sizeof(struct i40e_hw_port_stats));
4441 ret = i40e_pf_get_switch_config(pf);
4442 if (ret != I40E_SUCCESS) {
4443 PMD_DRV_LOG(ERR, "Could not get switch config, err %d", ret);
4446 if (pf->flags & I40E_FLAG_FDIR) {
4447 /* make queue allocated first, let FDIR use queue pair 0*/
4448 ret = i40e_res_pool_alloc(&pf->qp_pool, I40E_DEFAULT_QP_NUM_FDIR);
4449 if (ret != I40E_FDIR_QUEUE_ID) {
4450 PMD_DRV_LOG(ERR, "queue allocation fails for FDIR :"
4452 pf->flags &= ~I40E_FLAG_FDIR;
4455 /* main VSI setup */
4456 vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, NULL, 0);
4458 PMD_DRV_LOG(ERR, "Setup of main vsi failed");
4459 return I40E_ERR_NOT_READY;
4463 /* Configure filter control */
4464 memset(&settings, 0, sizeof(settings));
4465 if (hw->func_caps.rss_table_size == ETH_RSS_RETA_SIZE_128)
4466 settings.hash_lut_size = I40E_HASH_LUT_SIZE_128;
4467 else if (hw->func_caps.rss_table_size == ETH_RSS_RETA_SIZE_512)
4468 settings.hash_lut_size = I40E_HASH_LUT_SIZE_512;
4470 PMD_DRV_LOG(ERR, "Hash lookup table size (%u) not supported\n",
4471 hw->func_caps.rss_table_size);
4472 return I40E_ERR_PARAM;
4474 PMD_DRV_LOG(INFO, "Hardware capability of hash lookup table "
4475 "size: %u\n", hw->func_caps.rss_table_size);
4476 pf->hash_lut_size = hw->func_caps.rss_table_size;
4478 /* Enable ethtype and macvlan filters */
4479 settings.enable_ethtype = TRUE;
4480 settings.enable_macvlan = TRUE;
4481 ret = i40e_set_filter_control(hw, &settings);
4483 PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
4486 /* Update flow control according to the auto negotiation */
4487 i40e_update_flow_control(hw);
4489 return I40E_SUCCESS;
4493 i40e_switch_tx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
4499 * Set or clear TX Queue Disable flags,
4500 * which is required by hardware.
4502 i40e_pre_tx_queue_cfg(hw, q_idx, on);
4503 rte_delay_us(I40E_PRE_TX_Q_CFG_WAIT_US);
4505 /* Wait until the request is finished */
4506 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
4507 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
4508 reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
4509 if (!(((reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 0x1) ^
4510 ((reg >> I40E_QTX_ENA_QENA_STAT_SHIFT)
4516 if (reg & I40E_QTX_ENA_QENA_STAT_MASK)
4517 return I40E_SUCCESS; /* already on, skip next steps */
4519 I40E_WRITE_REG(hw, I40E_QTX_HEAD(q_idx), 0);
4520 reg |= I40E_QTX_ENA_QENA_REQ_MASK;
4522 if (!(reg & I40E_QTX_ENA_QENA_STAT_MASK))
4523 return I40E_SUCCESS; /* already off, skip next steps */
4524 reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
4526 /* Write the register */
4527 I40E_WRITE_REG(hw, I40E_QTX_ENA(q_idx), reg);
4528 /* Check the result */
4529 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
4530 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
4531 reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
4533 if ((reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
4534 (reg & I40E_QTX_ENA_QENA_STAT_MASK))
4537 if (!(reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
4538 !(reg & I40E_QTX_ENA_QENA_STAT_MASK))
4542 /* Check if it is timeout */
4543 if (j >= I40E_CHK_Q_ENA_COUNT) {
4544 PMD_DRV_LOG(ERR, "Failed to %s tx queue[%u]",
4545 (on ? "enable" : "disable"), q_idx);
4546 return I40E_ERR_TIMEOUT;
4549 return I40E_SUCCESS;
4552 /* Swith on or off the tx queues */
4554 i40e_dev_switch_tx_queues(struct i40e_pf *pf, bool on)
4556 struct rte_eth_dev_data *dev_data = pf->dev_data;
4557 struct i40e_tx_queue *txq;
4558 struct rte_eth_dev *dev = pf->adapter->eth_dev;
4562 for (i = 0; i < dev_data->nb_tx_queues; i++) {
4563 txq = dev_data->tx_queues[i];
4564 /* Don't operate the queue if not configured or
4565 * if starting only per queue */
4566 if (!txq || !txq->q_set || (on && txq->tx_deferred_start))
4569 ret = i40e_dev_tx_queue_start(dev, i);
4571 ret = i40e_dev_tx_queue_stop(dev, i);
4572 if ( ret != I40E_SUCCESS)
4576 return I40E_SUCCESS;
4580 i40e_switch_rx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
4585 /* Wait until the request is finished */
4586 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
4587 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
4588 reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
4589 if (!((reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 0x1) ^
4590 ((reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 0x1))
4595 if (reg & I40E_QRX_ENA_QENA_STAT_MASK)
4596 return I40E_SUCCESS; /* Already on, skip next steps */
4597 reg |= I40E_QRX_ENA_QENA_REQ_MASK;
4599 if (!(reg & I40E_QRX_ENA_QENA_STAT_MASK))
4600 return I40E_SUCCESS; /* Already off, skip next steps */
4601 reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
4604 /* Write the register */
4605 I40E_WRITE_REG(hw, I40E_QRX_ENA(q_idx), reg);
4606 /* Check the result */
4607 for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
4608 rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
4609 reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
4611 if ((reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
4612 (reg & I40E_QRX_ENA_QENA_STAT_MASK))
4615 if (!(reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
4616 !(reg & I40E_QRX_ENA_QENA_STAT_MASK))
4621 /* Check if it is timeout */
4622 if (j >= I40E_CHK_Q_ENA_COUNT) {
4623 PMD_DRV_LOG(ERR, "Failed to %s rx queue[%u]",
4624 (on ? "enable" : "disable"), q_idx);
4625 return I40E_ERR_TIMEOUT;
4628 return I40E_SUCCESS;
4630 /* Switch on or off the rx queues */
4632 i40e_dev_switch_rx_queues(struct i40e_pf *pf, bool on)
4634 struct rte_eth_dev_data *dev_data = pf->dev_data;
4635 struct i40e_rx_queue *rxq;
4636 struct rte_eth_dev *dev = pf->adapter->eth_dev;
4640 for (i = 0; i < dev_data->nb_rx_queues; i++) {
4641 rxq = dev_data->rx_queues[i];
4642 /* Don't operate the queue if not configured or
4643 * if starting only per queue */
4644 if (!rxq || !rxq->q_set || (on && rxq->rx_deferred_start))
4647 ret = i40e_dev_rx_queue_start(dev, i);
4649 ret = i40e_dev_rx_queue_stop(dev, i);
4650 if (ret != I40E_SUCCESS)
4654 return I40E_SUCCESS;
4657 /* Switch on or off all the rx/tx queues */
4659 i40e_dev_switch_queues(struct i40e_pf *pf, bool on)
4664 /* enable rx queues before enabling tx queues */
4665 ret = i40e_dev_switch_rx_queues(pf, on);
4667 PMD_DRV_LOG(ERR, "Failed to switch rx queues");
4670 ret = i40e_dev_switch_tx_queues(pf, on);
4672 /* Stop tx queues before stopping rx queues */
4673 ret = i40e_dev_switch_tx_queues(pf, on);
4675 PMD_DRV_LOG(ERR, "Failed to switch tx queues");
4678 ret = i40e_dev_switch_rx_queues(pf, on);
4684 /* Initialize VSI for TX */
4686 i40e_dev_tx_init(struct i40e_pf *pf)
4688 struct rte_eth_dev_data *data = pf->dev_data;
4690 uint32_t ret = I40E_SUCCESS;
4691 struct i40e_tx_queue *txq;
4693 for (i = 0; i < data->nb_tx_queues; i++) {
4694 txq = data->tx_queues[i];
4695 if (!txq || !txq->q_set)
4697 ret = i40e_tx_queue_init(txq);
4698 if (ret != I40E_SUCCESS)
4701 if (ret == I40E_SUCCESS)
4702 i40e_set_tx_function(container_of(pf, struct i40e_adapter, pf)
4708 /* Initialize VSI for RX */
4710 i40e_dev_rx_init(struct i40e_pf *pf)
4712 struct rte_eth_dev_data *data = pf->dev_data;
4713 int ret = I40E_SUCCESS;
4715 struct i40e_rx_queue *rxq;
4717 i40e_pf_config_mq_rx(pf);
4718 for (i = 0; i < data->nb_rx_queues; i++) {
4719 rxq = data->rx_queues[i];
4720 if (!rxq || !rxq->q_set)
4723 ret = i40e_rx_queue_init(rxq);
4724 if (ret != I40E_SUCCESS) {
4725 PMD_DRV_LOG(ERR, "Failed to do RX queue "
4730 if (ret == I40E_SUCCESS)
4731 i40e_set_rx_function(container_of(pf, struct i40e_adapter, pf)
4738 i40e_dev_rxtx_init(struct i40e_pf *pf)
4742 err = i40e_dev_tx_init(pf);
4744 PMD_DRV_LOG(ERR, "Failed to do TX initialization");
4747 err = i40e_dev_rx_init(pf);
4749 PMD_DRV_LOG(ERR, "Failed to do RX initialization");
4757 i40e_vmdq_setup(struct rte_eth_dev *dev)
4759 struct rte_eth_conf *conf = &dev->data->dev_conf;
4760 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4761 int i, err, conf_vsis, j, loop;
4762 struct i40e_vsi *vsi;
4763 struct i40e_vmdq_info *vmdq_info;
4764 struct rte_eth_vmdq_rx_conf *vmdq_conf;
4765 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4768 * Disable interrupt to avoid message from VF. Furthermore, it will
4769 * avoid race condition in VSI creation/destroy.
4771 i40e_pf_disable_irq0(hw);
4773 if ((pf->flags & I40E_FLAG_VMDQ) == 0) {
4774 PMD_INIT_LOG(ERR, "FW doesn't support VMDQ");
4778 conf_vsis = conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools;
4779 if (conf_vsis > pf->max_nb_vmdq_vsi) {
4780 PMD_INIT_LOG(ERR, "VMDQ config: %u, max support:%u",
4781 conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools,
4782 pf->max_nb_vmdq_vsi);
4786 if (pf->vmdq != NULL) {
4787 PMD_INIT_LOG(INFO, "VMDQ already configured");
4791 pf->vmdq = rte_zmalloc("vmdq_info_struct",
4792 sizeof(*vmdq_info) * conf_vsis, 0);
4794 if (pf->vmdq == NULL) {
4795 PMD_INIT_LOG(ERR, "Failed to allocate memory");
4799 vmdq_conf = &conf->rx_adv_conf.vmdq_rx_conf;
4801 /* Create VMDQ VSI */
4802 for (i = 0; i < conf_vsis; i++) {
4803 vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, pf->main_vsi,
4804 vmdq_conf->enable_loop_back);
4806 PMD_INIT_LOG(ERR, "Failed to create VMDQ VSI");
4810 vmdq_info = &pf->vmdq[i];
4812 vmdq_info->vsi = vsi;
4814 pf->nb_cfg_vmdq_vsi = conf_vsis;
4816 /* Configure Vlan */
4817 loop = sizeof(vmdq_conf->pool_map[0].pools) * CHAR_BIT;
4818 for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
4819 for (j = 0; j < loop && j < pf->nb_cfg_vmdq_vsi; j++) {
4820 if (vmdq_conf->pool_map[i].pools & (1UL << j)) {
4821 PMD_INIT_LOG(INFO, "Add vlan %u to vmdq pool %u",
4822 vmdq_conf->pool_map[i].vlan_id, j);
4824 err = i40e_vsi_add_vlan(pf->vmdq[j].vsi,
4825 vmdq_conf->pool_map[i].vlan_id);
4827 PMD_INIT_LOG(ERR, "Failed to add vlan");
4835 i40e_pf_enable_irq0(hw);
4840 for (i = 0; i < conf_vsis; i++)
4841 if (pf->vmdq[i].vsi == NULL)
4844 i40e_vsi_release(pf->vmdq[i].vsi);
4848 i40e_pf_enable_irq0(hw);
4853 i40e_stat_update_32(struct i40e_hw *hw,
4861 new_data = (uint64_t)I40E_READ_REG(hw, reg);
4865 if (new_data >= *offset)
4866 *stat = (uint64_t)(new_data - *offset);
4868 *stat = (uint64_t)((new_data +
4869 ((uint64_t)1 << I40E_32_BIT_WIDTH)) - *offset);
4873 i40e_stat_update_48(struct i40e_hw *hw,
4882 new_data = (uint64_t)I40E_READ_REG(hw, loreg);
4883 new_data |= ((uint64_t)(I40E_READ_REG(hw, hireg) &
4884 I40E_16_BIT_MASK)) << I40E_32_BIT_WIDTH;
4889 if (new_data >= *offset)
4890 *stat = new_data - *offset;
4892 *stat = (uint64_t)((new_data +
4893 ((uint64_t)1 << I40E_48_BIT_WIDTH)) - *offset);
4895 *stat &= I40E_48_BIT_MASK;
4900 i40e_pf_disable_irq0(struct i40e_hw *hw)
4902 /* Disable all interrupt types */
4903 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0, 0);
4904 I40E_WRITE_FLUSH(hw);
4909 i40e_pf_enable_irq0(struct i40e_hw *hw)
4911 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
4912 I40E_PFINT_DYN_CTL0_INTENA_MASK |
4913 I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
4914 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
4915 I40E_WRITE_FLUSH(hw);
4919 i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue)
4921 /* read pending request and disable first */
4922 i40e_pf_disable_irq0(hw);
4923 I40E_WRITE_REG(hw, I40E_PFINT_ICR0_ENA, I40E_PFINT_ICR0_ENA_MASK);
4924 I40E_WRITE_REG(hw, I40E_PFINT_STAT_CTL0,
4925 I40E_PFINT_STAT_CTL0_OTHER_ITR_INDX_MASK);
4928 /* Link no queues with irq0 */
4929 I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
4930 I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
4934 i40e_dev_handle_vfr_event(struct rte_eth_dev *dev)
4936 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4937 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4940 uint32_t index, offset, val;
4945 * Try to find which VF trigger a reset, use absolute VF id to access
4946 * since the reg is global register.
4948 for (i = 0; i < pf->vf_num; i++) {
4949 abs_vf_id = hw->func_caps.vf_base_id + i;
4950 index = abs_vf_id / I40E_UINT32_BIT_SIZE;
4951 offset = abs_vf_id % I40E_UINT32_BIT_SIZE;
4952 val = I40E_READ_REG(hw, I40E_GLGEN_VFLRSTAT(index));
4953 /* VFR event occured */
4954 if (val & (0x1 << offset)) {
4957 /* Clear the event first */
4958 I40E_WRITE_REG(hw, I40E_GLGEN_VFLRSTAT(index),
4960 PMD_DRV_LOG(INFO, "VF %u reset occured", abs_vf_id);
4962 * Only notify a VF reset event occured,
4963 * don't trigger another SW reset
4965 ret = i40e_pf_host_vf_reset(&pf->vfs[i], 0);
4966 if (ret != I40E_SUCCESS)
4967 PMD_DRV_LOG(ERR, "Failed to do VF reset");
4973 i40e_dev_handle_aq_msg(struct rte_eth_dev *dev)
4975 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4976 struct i40e_arq_event_info info;
4977 uint16_t pending, opcode;
4980 info.buf_len = I40E_AQ_BUF_SZ;
4981 info.msg_buf = rte_zmalloc("msg_buffer", info.buf_len, 0);
4982 if (!info.msg_buf) {
4983 PMD_DRV_LOG(ERR, "Failed to allocate mem");
4989 ret = i40e_clean_arq_element(hw, &info, &pending);
4991 if (ret != I40E_SUCCESS) {
4992 PMD_DRV_LOG(INFO, "Failed to read msg from AdminQ, "
4993 "aq_err: %u", hw->aq.asq_last_status);
4996 opcode = rte_le_to_cpu_16(info.desc.opcode);
4999 case i40e_aqc_opc_send_msg_to_pf:
5000 /* Refer to i40e_aq_send_msg_to_pf() for argument layout*/
5001 i40e_pf_host_handle_vf_msg(dev,
5002 rte_le_to_cpu_16(info.desc.retval),
5003 rte_le_to_cpu_32(info.desc.cookie_high),
5004 rte_le_to_cpu_32(info.desc.cookie_low),
5009 PMD_DRV_LOG(ERR, "Request %u is not supported yet",
5014 rte_free(info.msg_buf);
5018 * Interrupt handler is registered as the alarm callback for handling LSC
5019 * interrupt in a definite of time, in order to wait the NIC into a stable
5020 * state. Currently it waits 1 sec in i40e for the link up interrupt, and
5021 * no need for link down interrupt.
5024 i40e_dev_interrupt_delayed_handler(void *param)
5026 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
5027 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5030 /* read interrupt causes again */
5031 icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
5033 #ifdef RTE_LIBRTE_I40E_DEBUG_DRIVER
5034 if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
5035 PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error\n");
5036 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK)
5037 PMD_DRV_LOG(ERR, "ICR0: malicious programming detected\n");
5038 if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
5039 PMD_DRV_LOG(INFO, "ICR0: global reset requested\n");
5040 if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
5041 PMD_DRV_LOG(INFO, "ICR0: PCI exception\n activated\n");
5042 if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
5043 PMD_DRV_LOG(INFO, "ICR0: a change in the storm control "
5045 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
5046 PMD_DRV_LOG(ERR, "ICR0: HMC error\n");
5047 if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
5048 PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error\n");
5049 #endif /* RTE_LIBRTE_I40E_DEBUG_DRIVER */
5051 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
5052 PMD_DRV_LOG(INFO, "INT:VF reset detected\n");
5053 i40e_dev_handle_vfr_event(dev);
5055 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
5056 PMD_DRV_LOG(INFO, "INT:ADMINQ event\n");
5057 i40e_dev_handle_aq_msg(dev);
5060 /* handle the link up interrupt in an alarm callback */
5061 i40e_dev_link_update(dev, 0);
5062 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC);
5064 i40e_pf_enable_irq0(hw);
5065 rte_intr_enable(&(dev->pci_dev->intr_handle));
5069 * Interrupt handler triggered by NIC for handling
5070 * specific interrupt.
5073 * Pointer to interrupt handle.
5075 * The address of parameter (struct rte_eth_dev *) regsitered before.
5081 i40e_dev_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
5084 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
5085 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5088 /* Disable interrupt */
5089 i40e_pf_disable_irq0(hw);
5091 /* read out interrupt causes */
5092 icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
5094 /* No interrupt event indicated */
5095 if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK)) {
5096 PMD_DRV_LOG(INFO, "No interrupt event");
5099 #ifdef RTE_LIBRTE_I40E_DEBUG_DRIVER
5100 if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
5101 PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
5102 if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK)
5103 PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
5104 if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
5105 PMD_DRV_LOG(INFO, "ICR0: global reset requested");
5106 if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
5107 PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
5108 if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
5109 PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
5110 if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
5111 PMD_DRV_LOG(ERR, "ICR0: HMC error");
5112 if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
5113 PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
5114 #endif /* RTE_LIBRTE_I40E_DEBUG_DRIVER */
5116 if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
5117 PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
5118 i40e_dev_handle_vfr_event(dev);
5120 if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
5121 PMD_DRV_LOG(INFO, "ICR0: adminq event");
5122 i40e_dev_handle_aq_msg(dev);
5125 /* Link Status Change interrupt */
5126 if (icr0 & I40E_PFINT_ICR0_LINK_STAT_CHANGE_MASK) {
5127 #define I40E_US_PER_SECOND 1000000
5128 struct rte_eth_link link;
5130 PMD_DRV_LOG(INFO, "ICR0: link status changed\n");
5131 memset(&link, 0, sizeof(link));
5132 rte_i40e_dev_atomic_read_link_status(dev, &link);
5133 i40e_dev_link_update(dev, 0);
5136 * For link up interrupt, it needs to wait 1 second to let the
5137 * hardware be a stable state. Otherwise several consecutive
5138 * interrupts can be observed.
5139 * For link down interrupt, no need to wait.
5141 if (!link.link_status && rte_eal_alarm_set(I40E_US_PER_SECOND,
5142 i40e_dev_interrupt_delayed_handler, (void *)dev) >= 0)
5145 _rte_eth_dev_callback_process(dev,
5146 RTE_ETH_EVENT_INTR_LSC);
5150 /* Enable interrupt */
5151 i40e_pf_enable_irq0(hw);
5152 rte_intr_enable(&(dev->pci_dev->intr_handle));
5156 i40e_add_macvlan_filters(struct i40e_vsi *vsi,
5157 struct i40e_macvlan_filter *filter,
5160 int ele_num, ele_buff_size;
5161 int num, actual_num, i;
5163 int ret = I40E_SUCCESS;
5164 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5165 struct i40e_aqc_add_macvlan_element_data *req_list;
5167 if (filter == NULL || total == 0)
5168 return I40E_ERR_PARAM;
5169 ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
5170 ele_buff_size = hw->aq.asq_buf_size;
5172 req_list = rte_zmalloc("macvlan_add", ele_buff_size, 0);
5173 if (req_list == NULL) {
5174 PMD_DRV_LOG(ERR, "Fail to allocate memory");
5175 return I40E_ERR_NO_MEMORY;
5180 actual_num = (num + ele_num > total) ? (total - num) : ele_num;
5181 memset(req_list, 0, ele_buff_size);
5183 for (i = 0; i < actual_num; i++) {
5184 (void)rte_memcpy(req_list[i].mac_addr,
5185 &filter[num + i].macaddr, ETH_ADDR_LEN);
5186 req_list[i].vlan_tag =
5187 rte_cpu_to_le_16(filter[num + i].vlan_id);
5189 switch (filter[num + i].filter_type) {
5190 case RTE_MAC_PERFECT_MATCH:
5191 flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH |
5192 I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
5194 case RTE_MACVLAN_PERFECT_MATCH:
5195 flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
5197 case RTE_MAC_HASH_MATCH:
5198 flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH |
5199 I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
5201 case RTE_MACVLAN_HASH_MATCH:
5202 flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH;
5205 PMD_DRV_LOG(ERR, "Invalid MAC match type\n");
5206 ret = I40E_ERR_PARAM;
5210 req_list[i].queue_number = 0;
5212 req_list[i].flags = rte_cpu_to_le_16(flags);
5215 ret = i40e_aq_add_macvlan(hw, vsi->seid, req_list,
5217 if (ret != I40E_SUCCESS) {
5218 PMD_DRV_LOG(ERR, "Failed to add macvlan filter");
5222 } while (num < total);
5230 i40e_remove_macvlan_filters(struct i40e_vsi *vsi,
5231 struct i40e_macvlan_filter *filter,
5234 int ele_num, ele_buff_size;
5235 int num, actual_num, i;
5237 int ret = I40E_SUCCESS;
5238 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5239 struct i40e_aqc_remove_macvlan_element_data *req_list;
5241 if (filter == NULL || total == 0)
5242 return I40E_ERR_PARAM;
5244 ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
5245 ele_buff_size = hw->aq.asq_buf_size;
5247 req_list = rte_zmalloc("macvlan_remove", ele_buff_size, 0);
5248 if (req_list == NULL) {
5249 PMD_DRV_LOG(ERR, "Fail to allocate memory");
5250 return I40E_ERR_NO_MEMORY;
5255 actual_num = (num + ele_num > total) ? (total - num) : ele_num;
5256 memset(req_list, 0, ele_buff_size);
5258 for (i = 0; i < actual_num; i++) {
5259 (void)rte_memcpy(req_list[i].mac_addr,
5260 &filter[num + i].macaddr, ETH_ADDR_LEN);
5261 req_list[i].vlan_tag =
5262 rte_cpu_to_le_16(filter[num + i].vlan_id);
5264 switch (filter[num + i].filter_type) {
5265 case RTE_MAC_PERFECT_MATCH:
5266 flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
5267 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
5269 case RTE_MACVLAN_PERFECT_MATCH:
5270 flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
5272 case RTE_MAC_HASH_MATCH:
5273 flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH |
5274 I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
5276 case RTE_MACVLAN_HASH_MATCH:
5277 flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH;
5280 PMD_DRV_LOG(ERR, "Invalid MAC filter type\n");
5281 ret = I40E_ERR_PARAM;
5284 req_list[i].flags = rte_cpu_to_le_16(flags);
5287 ret = i40e_aq_remove_macvlan(hw, vsi->seid, req_list,
5289 if (ret != I40E_SUCCESS) {
5290 PMD_DRV_LOG(ERR, "Failed to remove macvlan filter");
5294 } while (num < total);
5301 /* Find out specific MAC filter */
5302 static struct i40e_mac_filter *
5303 i40e_find_mac_filter(struct i40e_vsi *vsi,
5304 struct ether_addr *macaddr)
5306 struct i40e_mac_filter *f;
5308 TAILQ_FOREACH(f, &vsi->mac_list, next) {
5309 if (is_same_ether_addr(macaddr, &f->mac_info.mac_addr))
5317 i40e_find_vlan_filter(struct i40e_vsi *vsi,
5320 uint32_t vid_idx, vid_bit;
5322 if (vlan_id > ETH_VLAN_ID_MAX)
5325 vid_idx = I40E_VFTA_IDX(vlan_id);
5326 vid_bit = I40E_VFTA_BIT(vlan_id);
5328 if (vsi->vfta[vid_idx] & vid_bit)
5335 i40e_set_vlan_filter(struct i40e_vsi *vsi,
5336 uint16_t vlan_id, bool on)
5338 uint32_t vid_idx, vid_bit;
5340 if (vlan_id > ETH_VLAN_ID_MAX)
5343 vid_idx = I40E_VFTA_IDX(vlan_id);
5344 vid_bit = I40E_VFTA_BIT(vlan_id);
5347 vsi->vfta[vid_idx] |= vid_bit;
5349 vsi->vfta[vid_idx] &= ~vid_bit;
5353 * Find all vlan options for specific mac addr,
5354 * return with actual vlan found.
5357 i40e_find_all_vlan_for_mac(struct i40e_vsi *vsi,
5358 struct i40e_macvlan_filter *mv_f,
5359 int num, struct ether_addr *addr)
5365 * Not to use i40e_find_vlan_filter to decrease the loop time,
5366 * although the code looks complex.
5368 if (num < vsi->vlan_num)
5369 return I40E_ERR_PARAM;
5372 for (j = 0; j < I40E_VFTA_SIZE; j++) {
5374 for (k = 0; k < I40E_UINT32_BIT_SIZE; k++) {
5375 if (vsi->vfta[j] & (1 << k)) {
5377 PMD_DRV_LOG(ERR, "vlan number "
5379 return I40E_ERR_PARAM;
5381 (void)rte_memcpy(&mv_f[i].macaddr,
5382 addr, ETH_ADDR_LEN);
5384 j * I40E_UINT32_BIT_SIZE + k;
5390 return I40E_SUCCESS;
5394 i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
5395 struct i40e_macvlan_filter *mv_f,
5400 struct i40e_mac_filter *f;
5402 if (num < vsi->mac_num)
5403 return I40E_ERR_PARAM;
5405 TAILQ_FOREACH(f, &vsi->mac_list, next) {
5407 PMD_DRV_LOG(ERR, "buffer number not match");
5408 return I40E_ERR_PARAM;
5410 (void)rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
5412 mv_f[i].vlan_id = vlan;
5413 mv_f[i].filter_type = f->mac_info.filter_type;
5417 return I40E_SUCCESS;
5421 i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi)
5424 struct i40e_mac_filter *f;
5425 struct i40e_macvlan_filter *mv_f;
5426 int ret = I40E_SUCCESS;
5428 if (vsi == NULL || vsi->mac_num == 0)
5429 return I40E_ERR_PARAM;
5431 /* Case that no vlan is set */
5432 if (vsi->vlan_num == 0)
5435 num = vsi->mac_num * vsi->vlan_num;
5437 mv_f = rte_zmalloc("macvlan_data", num * sizeof(*mv_f), 0);
5439 PMD_DRV_LOG(ERR, "failed to allocate memory");
5440 return I40E_ERR_NO_MEMORY;
5444 if (vsi->vlan_num == 0) {
5445 TAILQ_FOREACH(f, &vsi->mac_list, next) {
5446 (void)rte_memcpy(&mv_f[i].macaddr,
5447 &f->mac_info.mac_addr, ETH_ADDR_LEN);
5448 mv_f[i].vlan_id = 0;
5452 TAILQ_FOREACH(f, &vsi->mac_list, next) {
5453 ret = i40e_find_all_vlan_for_mac(vsi,&mv_f[i],
5454 vsi->vlan_num, &f->mac_info.mac_addr);
5455 if (ret != I40E_SUCCESS)
5461 ret = i40e_remove_macvlan_filters(vsi, mv_f, num);
5469 i40e_vsi_add_vlan(struct i40e_vsi *vsi, uint16_t vlan)
5471 struct i40e_macvlan_filter *mv_f;
5473 int ret = I40E_SUCCESS;
5475 if (!vsi || vlan > ETHER_MAX_VLAN_ID)
5476 return I40E_ERR_PARAM;
5478 /* If it's already set, just return */
5479 if (i40e_find_vlan_filter(vsi,vlan))
5480 return I40E_SUCCESS;
5482 mac_num = vsi->mac_num;
5485 PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
5486 return I40E_ERR_PARAM;
5489 mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
5492 PMD_DRV_LOG(ERR, "failed to allocate memory");
5493 return I40E_ERR_NO_MEMORY;
5496 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
5498 if (ret != I40E_SUCCESS)
5501 ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
5503 if (ret != I40E_SUCCESS)
5506 i40e_set_vlan_filter(vsi, vlan, 1);
5516 i40e_vsi_delete_vlan(struct i40e_vsi *vsi, uint16_t vlan)
5518 struct i40e_macvlan_filter *mv_f;
5520 int ret = I40E_SUCCESS;
5523 * Vlan 0 is the generic filter for untagged packets
5524 * and can't be removed.
5526 if (!vsi || vlan == 0 || vlan > ETHER_MAX_VLAN_ID)
5527 return I40E_ERR_PARAM;
5529 /* If can't find it, just return */
5530 if (!i40e_find_vlan_filter(vsi, vlan))
5531 return I40E_ERR_PARAM;
5533 mac_num = vsi->mac_num;
5536 PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
5537 return I40E_ERR_PARAM;
5540 mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
5543 PMD_DRV_LOG(ERR, "failed to allocate memory");
5544 return I40E_ERR_NO_MEMORY;
5547 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
5549 if (ret != I40E_SUCCESS)
5552 ret = i40e_remove_macvlan_filters(vsi, mv_f, mac_num);
5554 if (ret != I40E_SUCCESS)
5557 /* This is last vlan to remove, replace all mac filter with vlan 0 */
5558 if (vsi->vlan_num == 1) {
5559 ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, 0);
5560 if (ret != I40E_SUCCESS)
5563 ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
5564 if (ret != I40E_SUCCESS)
5568 i40e_set_vlan_filter(vsi, vlan, 0);
5578 i40e_vsi_add_mac(struct i40e_vsi *vsi, struct i40e_mac_filter_info *mac_filter)
5580 struct i40e_mac_filter *f;
5581 struct i40e_macvlan_filter *mv_f;
5582 int i, vlan_num = 0;
5583 int ret = I40E_SUCCESS;
5585 /* If it's add and we've config it, return */
5586 f = i40e_find_mac_filter(vsi, &mac_filter->mac_addr);
5588 return I40E_SUCCESS;
5589 if ((mac_filter->filter_type == RTE_MACVLAN_PERFECT_MATCH) ||
5590 (mac_filter->filter_type == RTE_MACVLAN_HASH_MATCH)) {
5593 * If vlan_num is 0, that's the first time to add mac,
5594 * set mask for vlan_id 0.
5596 if (vsi->vlan_num == 0) {
5597 i40e_set_vlan_filter(vsi, 0, 1);
5600 vlan_num = vsi->vlan_num;
5601 } else if ((mac_filter->filter_type == RTE_MAC_PERFECT_MATCH) ||
5602 (mac_filter->filter_type == RTE_MAC_HASH_MATCH))
5605 mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
5607 PMD_DRV_LOG(ERR, "failed to allocate memory");
5608 return I40E_ERR_NO_MEMORY;
5611 for (i = 0; i < vlan_num; i++) {
5612 mv_f[i].filter_type = mac_filter->filter_type;
5613 (void)rte_memcpy(&mv_f[i].macaddr, &mac_filter->mac_addr,
5617 if (mac_filter->filter_type == RTE_MACVLAN_PERFECT_MATCH ||
5618 mac_filter->filter_type == RTE_MACVLAN_HASH_MATCH) {
5619 ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
5620 &mac_filter->mac_addr);
5621 if (ret != I40E_SUCCESS)
5625 ret = i40e_add_macvlan_filters(vsi, mv_f, vlan_num);
5626 if (ret != I40E_SUCCESS)
5629 /* Add the mac addr into mac list */
5630 f = rte_zmalloc("macv_filter", sizeof(*f), 0);
5632 PMD_DRV_LOG(ERR, "failed to allocate memory");
5633 ret = I40E_ERR_NO_MEMORY;
5636 (void)rte_memcpy(&f->mac_info.mac_addr, &mac_filter->mac_addr,
5638 f->mac_info.filter_type = mac_filter->filter_type;
5639 TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
5650 i40e_vsi_delete_mac(struct i40e_vsi *vsi, struct ether_addr *addr)
5652 struct i40e_mac_filter *f;
5653 struct i40e_macvlan_filter *mv_f;
5655 enum rte_mac_filter_type filter_type;
5656 int ret = I40E_SUCCESS;
5658 /* Can't find it, return an error */
5659 f = i40e_find_mac_filter(vsi, addr);
5661 return I40E_ERR_PARAM;
5663 vlan_num = vsi->vlan_num;
5664 filter_type = f->mac_info.filter_type;
5665 if (filter_type == RTE_MACVLAN_PERFECT_MATCH ||
5666 filter_type == RTE_MACVLAN_HASH_MATCH) {
5667 if (vlan_num == 0) {
5668 PMD_DRV_LOG(ERR, "VLAN number shouldn't be 0\n");
5669 return I40E_ERR_PARAM;
5671 } else if (filter_type == RTE_MAC_PERFECT_MATCH ||
5672 filter_type == RTE_MAC_HASH_MATCH)
5675 mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
5677 PMD_DRV_LOG(ERR, "failed to allocate memory");
5678 return I40E_ERR_NO_MEMORY;
5681 for (i = 0; i < vlan_num; i++) {
5682 mv_f[i].filter_type = filter_type;
5683 (void)rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
5686 if (filter_type == RTE_MACVLAN_PERFECT_MATCH ||
5687 filter_type == RTE_MACVLAN_HASH_MATCH) {
5688 ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num, addr);
5689 if (ret != I40E_SUCCESS)
5693 ret = i40e_remove_macvlan_filters(vsi, mv_f, vlan_num);
5694 if (ret != I40E_SUCCESS)
5697 /* Remove the mac addr into mac list */
5698 TAILQ_REMOVE(&vsi->mac_list, f, next);
5708 /* Configure hash enable flags for RSS */
5710 i40e_config_hena(uint64_t flags)
5717 if (flags & ETH_RSS_FRAG_IPV4)
5718 hena |= 1ULL << I40E_FILTER_PCTYPE_FRAG_IPV4;
5719 if (flags & ETH_RSS_NONFRAG_IPV4_TCP)
5720 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
5721 if (flags & ETH_RSS_NONFRAG_IPV4_UDP)
5722 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
5723 if (flags & ETH_RSS_NONFRAG_IPV4_SCTP)
5724 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
5725 if (flags & ETH_RSS_NONFRAG_IPV4_OTHER)
5726 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
5727 if (flags & ETH_RSS_FRAG_IPV6)
5728 hena |= 1ULL << I40E_FILTER_PCTYPE_FRAG_IPV6;
5729 if (flags & ETH_RSS_NONFRAG_IPV6_TCP)
5730 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
5731 if (flags & ETH_RSS_NONFRAG_IPV6_UDP)
5732 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
5733 if (flags & ETH_RSS_NONFRAG_IPV6_SCTP)
5734 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_SCTP;
5735 if (flags & ETH_RSS_NONFRAG_IPV6_OTHER)
5736 hena |= 1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER;
5737 if (flags & ETH_RSS_L2_PAYLOAD)
5738 hena |= 1ULL << I40E_FILTER_PCTYPE_L2_PAYLOAD;
5743 /* Parse the hash enable flags */
5745 i40e_parse_hena(uint64_t flags)
5747 uint64_t rss_hf = 0;
5751 if (flags & (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV4))
5752 rss_hf |= ETH_RSS_FRAG_IPV4;
5753 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP))
5754 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
5755 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_UDP))
5756 rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
5757 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_SCTP))
5758 rss_hf |= ETH_RSS_NONFRAG_IPV4_SCTP;
5759 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER))
5760 rss_hf |= ETH_RSS_NONFRAG_IPV4_OTHER;
5761 if (flags & (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV6))
5762 rss_hf |= ETH_RSS_FRAG_IPV6;
5763 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP))
5764 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
5765 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_UDP))
5766 rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP;
5767 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_SCTP))
5768 rss_hf |= ETH_RSS_NONFRAG_IPV6_SCTP;
5769 if (flags & (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER))
5770 rss_hf |= ETH_RSS_NONFRAG_IPV6_OTHER;
5771 if (flags & (1ULL << I40E_FILTER_PCTYPE_L2_PAYLOAD))
5772 rss_hf |= ETH_RSS_L2_PAYLOAD;
5779 i40e_pf_disable_rss(struct i40e_pf *pf)
5781 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5784 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
5785 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
5786 hena &= ~I40E_RSS_HENA_ALL;
5787 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
5788 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
5789 I40E_WRITE_FLUSH(hw);
5793 i40e_set_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t key_len)
5795 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
5796 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5799 if (!key || key_len == 0) {
5800 PMD_DRV_LOG(DEBUG, "No key to be configured");
5802 } else if (key_len != (I40E_PFQF_HKEY_MAX_INDEX + 1) *
5804 PMD_DRV_LOG(ERR, "Invalid key length %u", key_len);
5808 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
5809 struct i40e_aqc_get_set_rss_key_data *key_dw =
5810 (struct i40e_aqc_get_set_rss_key_data *)key;
5812 ret = i40e_aq_set_rss_key(hw, vsi->vsi_id, key_dw);
5814 PMD_INIT_LOG(ERR, "Failed to configure RSS key "
5817 uint32_t *hash_key = (uint32_t *)key;
5820 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
5821 i40e_write_rx_ctl(hw, I40E_PFQF_HKEY(i), hash_key[i]);
5822 I40E_WRITE_FLUSH(hw);
5829 i40e_get_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t *key_len)
5831 struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
5832 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5835 if (!key || !key_len)
5838 if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
5839 ret = i40e_aq_get_rss_key(hw, vsi->vsi_id,
5840 (struct i40e_aqc_get_set_rss_key_data *)key);
5842 PMD_INIT_LOG(ERR, "Failed to get RSS key via AQ");
5846 uint32_t *key_dw = (uint32_t *)key;
5849 for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
5850 key_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i));
5852 *key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t);
5858 i40e_hw_rss_hash_set(struct i40e_pf *pf, struct rte_eth_rss_conf *rss_conf)
5860 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5865 ret = i40e_set_rss_key(pf->main_vsi, rss_conf->rss_key,
5866 rss_conf->rss_key_len);
5870 rss_hf = rss_conf->rss_hf;
5871 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
5872 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
5873 hena &= ~I40E_RSS_HENA_ALL;
5874 hena |= i40e_config_hena(rss_hf);
5875 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
5876 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
5877 I40E_WRITE_FLUSH(hw);
5883 i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
5884 struct rte_eth_rss_conf *rss_conf)
5886 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5887 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5888 uint64_t rss_hf = rss_conf->rss_hf & I40E_RSS_OFFLOAD_ALL;
5891 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
5892 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
5893 if (!(hena & I40E_RSS_HENA_ALL)) { /* RSS disabled */
5894 if (rss_hf != 0) /* Enable RSS */
5896 return 0; /* Nothing to do */
5899 if (rss_hf == 0) /* Disable RSS */
5902 return i40e_hw_rss_hash_set(pf, rss_conf);
5906 i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
5907 struct rte_eth_rss_conf *rss_conf)
5909 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
5910 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
5913 i40e_get_rss_key(pf->main_vsi, rss_conf->rss_key,
5914 &rss_conf->rss_key_len);
5916 hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
5917 hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
5918 rss_conf->rss_hf = i40e_parse_hena(hena);
5924 i40e_dev_get_filter_type(uint16_t filter_type, uint16_t *flag)
5926 switch (filter_type) {
5927 case RTE_TUNNEL_FILTER_IMAC_IVLAN:
5928 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
5930 case RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID:
5931 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
5933 case RTE_TUNNEL_FILTER_IMAC_TENID:
5934 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID;
5936 case RTE_TUNNEL_FILTER_OMAC_TENID_IMAC:
5937 *flag = I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC;
5939 case ETH_TUNNEL_FILTER_IMAC:
5940 *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
5942 case ETH_TUNNEL_FILTER_OIP:
5943 *flag = I40E_AQC_ADD_CLOUD_FILTER_OIP;
5945 case ETH_TUNNEL_FILTER_IIP:
5946 *flag = I40E_AQC_ADD_CLOUD_FILTER_IIP;
5949 PMD_DRV_LOG(ERR, "invalid tunnel filter type");
5957 i40e_dev_tunnel_filter_set(struct i40e_pf *pf,
5958 struct rte_eth_tunnel_filter_conf *tunnel_filter,
5962 uint8_t i, tun_type = 0;
5963 /* internal varialbe to convert ipv6 byte order */
5964 uint32_t convert_ipv6[4];
5966 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5967 struct i40e_vsi *vsi = pf->main_vsi;
5968 struct i40e_aqc_add_remove_cloud_filters_element_data *cld_filter;
5969 struct i40e_aqc_add_remove_cloud_filters_element_data *pfilter;
5971 cld_filter = rte_zmalloc("tunnel_filter",
5972 sizeof(struct i40e_aqc_add_remove_cloud_filters_element_data),
5975 if (NULL == cld_filter) {
5976 PMD_DRV_LOG(ERR, "Failed to alloc memory.");
5979 pfilter = cld_filter;
5981 ether_addr_copy(&tunnel_filter->outer_mac, (struct ether_addr*)&pfilter->outer_mac);
5982 ether_addr_copy(&tunnel_filter->inner_mac, (struct ether_addr*)&pfilter->inner_mac);
5984 pfilter->inner_vlan = rte_cpu_to_le_16(tunnel_filter->inner_vlan);
5985 if (tunnel_filter->ip_type == RTE_TUNNEL_IPTYPE_IPV4) {
5986 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV4;
5987 rte_memcpy(&pfilter->ipaddr.v4.data,
5988 &rte_cpu_to_le_32(tunnel_filter->ip_addr.ipv4_addr),
5989 sizeof(pfilter->ipaddr.v4.data));
5991 ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV6;
5992 for (i = 0; i < 4; i++) {
5994 rte_cpu_to_le_32(tunnel_filter->ip_addr.ipv6_addr[i]);
5996 rte_memcpy(&pfilter->ipaddr.v6.data, &convert_ipv6,
5997 sizeof(pfilter->ipaddr.v6.data));
6000 /* check tunneled type */
6001 switch (tunnel_filter->tunnel_type) {
6002 case RTE_TUNNEL_TYPE_VXLAN:
6003 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_VXLAN;
6005 case RTE_TUNNEL_TYPE_NVGRE:
6006 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_NVGRE_OMAC;
6008 case RTE_TUNNEL_TYPE_IP_IN_GRE:
6009 tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_IP;
6012 /* Other tunnel types is not supported. */
6013 PMD_DRV_LOG(ERR, "tunnel type is not supported.");
6014 rte_free(cld_filter);
6018 val = i40e_dev_get_filter_type(tunnel_filter->filter_type,
6021 rte_free(cld_filter);
6025 pfilter->flags |= rte_cpu_to_le_16(
6026 I40E_AQC_ADD_CLOUD_FLAGS_TO_QUEUE |
6027 ip_type | (tun_type << I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT));
6028 pfilter->tenant_id = rte_cpu_to_le_32(tunnel_filter->tenant_id);
6029 pfilter->queue_number = rte_cpu_to_le_16(tunnel_filter->queue_id);
6032 ret = i40e_aq_add_cloud_filters(hw, vsi->seid, cld_filter, 1);
6034 ret = i40e_aq_remove_cloud_filters(hw, vsi->seid,
6037 rte_free(cld_filter);
6042 i40e_get_vxlan_port_idx(struct i40e_pf *pf, uint16_t port)
6046 for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
6047 if (pf->vxlan_ports[i] == port)
6055 i40e_add_vxlan_port(struct i40e_pf *pf, uint16_t port)
6059 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6061 idx = i40e_get_vxlan_port_idx(pf, port);
6063 /* Check if port already exists */
6065 PMD_DRV_LOG(ERR, "Port %d already offloaded", port);
6069 /* Now check if there is space to add the new port */
6070 idx = i40e_get_vxlan_port_idx(pf, 0);
6072 PMD_DRV_LOG(ERR, "Maximum number of UDP ports reached,"
6073 "not adding port %d", port);
6077 ret = i40e_aq_add_udp_tunnel(hw, port, I40E_AQC_TUNNEL_TYPE_VXLAN,
6080 PMD_DRV_LOG(ERR, "Failed to add VXLAN UDP port %d", port);
6084 PMD_DRV_LOG(INFO, "Added port %d with AQ command with index %d",
6087 /* New port: add it and mark its index in the bitmap */
6088 pf->vxlan_ports[idx] = port;
6089 pf->vxlan_bitmap |= (1 << idx);
6091 if (!(pf->flags & I40E_FLAG_VXLAN))
6092 pf->flags |= I40E_FLAG_VXLAN;
6098 i40e_del_vxlan_port(struct i40e_pf *pf, uint16_t port)
6101 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6103 if (!(pf->flags & I40E_FLAG_VXLAN)) {
6104 PMD_DRV_LOG(ERR, "VXLAN UDP port was not configured.");
6108 idx = i40e_get_vxlan_port_idx(pf, port);
6111 PMD_DRV_LOG(ERR, "Port %d doesn't exist", port);
6115 if (i40e_aq_del_udp_tunnel(hw, idx, NULL) < 0) {
6116 PMD_DRV_LOG(ERR, "Failed to delete VXLAN UDP port %d", port);
6120 PMD_DRV_LOG(INFO, "Deleted port %d with AQ command with index %d",
6123 pf->vxlan_ports[idx] = 0;
6124 pf->vxlan_bitmap &= ~(1 << idx);
6126 if (!pf->vxlan_bitmap)
6127 pf->flags &= ~I40E_FLAG_VXLAN;
6132 /* Add UDP tunneling port */
6134 i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
6135 struct rte_eth_udp_tunnel *udp_tunnel)
6138 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6140 if (udp_tunnel == NULL)
6143 switch (udp_tunnel->prot_type) {
6144 case RTE_TUNNEL_TYPE_VXLAN:
6145 ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port);
6148 case RTE_TUNNEL_TYPE_GENEVE:
6149 case RTE_TUNNEL_TYPE_TEREDO:
6150 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
6155 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6163 /* Remove UDP tunneling port */
6165 i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
6166 struct rte_eth_udp_tunnel *udp_tunnel)
6169 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6171 if (udp_tunnel == NULL)
6174 switch (udp_tunnel->prot_type) {
6175 case RTE_TUNNEL_TYPE_VXLAN:
6176 ret = i40e_del_vxlan_port(pf, udp_tunnel->udp_port);
6178 case RTE_TUNNEL_TYPE_GENEVE:
6179 case RTE_TUNNEL_TYPE_TEREDO:
6180 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
6184 PMD_DRV_LOG(ERR, "Invalid tunnel type");
6192 /* Calculate the maximum number of contiguous PF queues that are configured */
6194 i40e_pf_calc_configured_queues_num(struct i40e_pf *pf)
6196 struct rte_eth_dev_data *data = pf->dev_data;
6198 struct i40e_rx_queue *rxq;
6201 for (i = 0; i < pf->lan_nb_qps; i++) {
6202 rxq = data->rx_queues[i];
6203 if (rxq && rxq->q_set)
6214 i40e_pf_config_rss(struct i40e_pf *pf)
6216 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6217 struct rte_eth_rss_conf rss_conf;
6218 uint32_t i, lut = 0;
6222 * If both VMDQ and RSS enabled, not all of PF queues are configured.
6223 * It's necessary to calulate the actual PF queues that are configured.
6225 if (pf->dev_data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG)
6226 num = i40e_pf_calc_configured_queues_num(pf);
6228 num = pf->dev_data->nb_rx_queues;
6230 num = RTE_MIN(num, I40E_MAX_Q_PER_TC);
6231 PMD_INIT_LOG(INFO, "Max of contiguous %u PF queues are configured",
6235 PMD_INIT_LOG(ERR, "No PF queues are configured to enable RSS");
6239 for (i = 0, j = 0; i < hw->func_caps.rss_table_size; i++, j++) {
6242 lut = (lut << 8) | (j & ((0x1 <<
6243 hw->func_caps.rss_table_entry_width) - 1));
6245 I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i >> 2), lut);
6248 rss_conf = pf->dev_data->dev_conf.rx_adv_conf.rss_conf;
6249 if ((rss_conf.rss_hf & I40E_RSS_OFFLOAD_ALL) == 0) {
6250 i40e_pf_disable_rss(pf);
6253 if (rss_conf.rss_key == NULL || rss_conf.rss_key_len <
6254 (I40E_PFQF_HKEY_MAX_INDEX + 1) * sizeof(uint32_t)) {
6255 /* Random default keys */
6256 static uint32_t rss_key_default[] = {0x6b793944,
6257 0x23504cb5, 0x5bea75b6, 0x309f4f12, 0x3dc0a2b8,
6258 0x024ddcdf, 0x339b8ca0, 0x4c4af64a, 0x34fac605,
6259 0x55d85839, 0x3a58997d, 0x2ec938e1, 0x66031581};
6261 rss_conf.rss_key = (uint8_t *)rss_key_default;
6262 rss_conf.rss_key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
6266 return i40e_hw_rss_hash_set(pf, &rss_conf);
6270 i40e_tunnel_filter_param_check(struct i40e_pf *pf,
6271 struct rte_eth_tunnel_filter_conf *filter)
6273 if (pf == NULL || filter == NULL) {
6274 PMD_DRV_LOG(ERR, "Invalid parameter");
6278 if (filter->queue_id >= pf->dev_data->nb_rx_queues) {
6279 PMD_DRV_LOG(ERR, "Invalid queue ID");
6283 if (filter->inner_vlan > ETHER_MAX_VLAN_ID) {
6284 PMD_DRV_LOG(ERR, "Invalid inner VLAN ID");
6288 if ((filter->filter_type & ETH_TUNNEL_FILTER_OMAC) &&
6289 (is_zero_ether_addr(&filter->outer_mac))) {
6290 PMD_DRV_LOG(ERR, "Cannot add NULL outer MAC address");
6294 if ((filter->filter_type & ETH_TUNNEL_FILTER_IMAC) &&
6295 (is_zero_ether_addr(&filter->inner_mac))) {
6296 PMD_DRV_LOG(ERR, "Cannot add NULL inner MAC address");
6303 #define I40E_GL_PRS_FVBM_MSK_ENA 0x80000000
6304 #define I40E_GL_PRS_FVBM(_i) (0x00269760 + ((_i) * 4))
6306 i40e_dev_set_gre_key_len(struct i40e_hw *hw, uint8_t len)
6311 val = I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2));
6312 PMD_DRV_LOG(DEBUG, "Read original GL_PRS_FVBM with 0x%08x\n", val);
6315 reg = val | I40E_GL_PRS_FVBM_MSK_ENA;
6316 } else if (len == 4) {
6317 reg = val & ~I40E_GL_PRS_FVBM_MSK_ENA;
6319 PMD_DRV_LOG(ERR, "Unsupported GRE key length of %u", len);
6324 ret = i40e_aq_debug_write_register(hw, I40E_GL_PRS_FVBM(2),
6331 PMD_DRV_LOG(DEBUG, "Read modified GL_PRS_FVBM with 0x%08x\n",
6332 I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2)));
6338 i40e_dev_global_config_set(struct i40e_hw *hw, struct rte_eth_global_cfg *cfg)
6345 switch (cfg->cfg_type) {
6346 case RTE_ETH_GLOBAL_CFG_TYPE_GRE_KEY_LEN:
6347 ret = i40e_dev_set_gre_key_len(hw, cfg->cfg.gre_key_len);
6350 PMD_DRV_LOG(ERR, "Unknown config type %u", cfg->cfg_type);
6358 i40e_filter_ctrl_global_config(struct rte_eth_dev *dev,
6359 enum rte_filter_op filter_op,
6362 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6363 int ret = I40E_ERR_PARAM;
6365 switch (filter_op) {
6366 case RTE_ETH_FILTER_SET:
6367 ret = i40e_dev_global_config_set(hw,
6368 (struct rte_eth_global_cfg *)arg);
6371 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
6379 i40e_tunnel_filter_handle(struct rte_eth_dev *dev,
6380 enum rte_filter_op filter_op,
6383 struct rte_eth_tunnel_filter_conf *filter;
6384 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6385 int ret = I40E_SUCCESS;
6387 filter = (struct rte_eth_tunnel_filter_conf *)(arg);
6389 if (i40e_tunnel_filter_param_check(pf, filter) < 0)
6390 return I40E_ERR_PARAM;
6392 switch (filter_op) {
6393 case RTE_ETH_FILTER_NOP:
6394 if (!(pf->flags & I40E_FLAG_VXLAN))
6395 ret = I40E_NOT_SUPPORTED;
6397 case RTE_ETH_FILTER_ADD:
6398 ret = i40e_dev_tunnel_filter_set(pf, filter, 1);
6400 case RTE_ETH_FILTER_DELETE:
6401 ret = i40e_dev_tunnel_filter_set(pf, filter, 0);
6404 PMD_DRV_LOG(ERR, "unknown operation %u", filter_op);
6405 ret = I40E_ERR_PARAM;
6413 i40e_pf_config_mq_rx(struct i40e_pf *pf)
6416 enum rte_eth_rx_mq_mode mq_mode = pf->dev_data->dev_conf.rxmode.mq_mode;
6419 if (mq_mode & ETH_MQ_RX_RSS_FLAG)
6420 ret = i40e_pf_config_rss(pf);
6422 i40e_pf_disable_rss(pf);
6427 /* Get the symmetric hash enable configurations per port */
6429 i40e_get_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t *enable)
6431 uint32_t reg = i40e_read_rx_ctl(hw, I40E_PRTQF_CTL_0);
6433 *enable = reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK ? 1 : 0;
6436 /* Set the symmetric hash enable configurations per port */
6438 i40e_set_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t enable)
6440 uint32_t reg = i40e_read_rx_ctl(hw, I40E_PRTQF_CTL_0);
6443 if (reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK) {
6444 PMD_DRV_LOG(INFO, "Symmetric hash has already "
6448 reg |= I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
6450 if (!(reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK)) {
6451 PMD_DRV_LOG(INFO, "Symmetric hash has already "
6455 reg &= ~I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
6457 i40e_write_rx_ctl(hw, I40E_PRTQF_CTL_0, reg);
6458 I40E_WRITE_FLUSH(hw);
6462 * Get global configurations of hash function type and symmetric hash enable
6463 * per flow type (pctype). Note that global configuration means it affects all
6464 * the ports on the same NIC.
6467 i40e_get_hash_filter_global_config(struct i40e_hw *hw,
6468 struct rte_eth_hash_global_conf *g_cfg)
6470 uint32_t reg, mask = I40E_FLOW_TYPES;
6472 enum i40e_filter_pctype pctype;
6474 memset(g_cfg, 0, sizeof(*g_cfg));
6475 reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
6476 if (reg & I40E_GLQF_CTL_HTOEP_MASK)
6477 g_cfg->hash_func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
6479 g_cfg->hash_func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
6480 PMD_DRV_LOG(DEBUG, "Hash function is %s",
6481 (reg & I40E_GLQF_CTL_HTOEP_MASK) ? "Toeplitz" : "Simple XOR");
6483 for (i = 0; mask && i < RTE_ETH_FLOW_MAX; i++) {
6484 if (!(mask & (1UL << i)))
6486 mask &= ~(1UL << i);
6487 /* Bit set indicats the coresponding flow type is supported */
6488 g_cfg->valid_bit_mask[0] |= (1UL << i);
6489 pctype = i40e_flowtype_to_pctype(i);
6490 reg = i40e_read_rx_ctl(hw, I40E_GLQF_HSYM(pctype));
6491 if (reg & I40E_GLQF_HSYM_SYMH_ENA_MASK)
6492 g_cfg->sym_hash_enable_mask[0] |= (1UL << i);
6499 i40e_hash_global_config_check(struct rte_eth_hash_global_conf *g_cfg)
6502 uint32_t mask0, i40e_mask = I40E_FLOW_TYPES;
6504 if (g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_TOEPLITZ &&
6505 g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_SIMPLE_XOR &&
6506 g_cfg->hash_func != RTE_ETH_HASH_FUNCTION_DEFAULT) {
6507 PMD_DRV_LOG(ERR, "Unsupported hash function type %d",
6513 * As i40e supports less than 32 flow types, only first 32 bits need to
6516 mask0 = g_cfg->valid_bit_mask[0];
6517 for (i = 0; i < RTE_SYM_HASH_MASK_ARRAY_SIZE; i++) {
6519 /* Check if any unsupported flow type configured */
6520 if ((mask0 | i40e_mask) ^ i40e_mask)
6523 if (g_cfg->valid_bit_mask[i])
6531 PMD_DRV_LOG(ERR, "i40e unsupported flow type bit(s) configured");
6537 * Set global configurations of hash function type and symmetric hash enable
6538 * per flow type (pctype). Note any modifying global configuration will affect
6539 * all the ports on the same NIC.
6542 i40e_set_hash_filter_global_config(struct i40e_hw *hw,
6543 struct rte_eth_hash_global_conf *g_cfg)
6548 uint32_t mask0 = g_cfg->valid_bit_mask[0];
6549 enum i40e_filter_pctype pctype;
6551 /* Check the input parameters */
6552 ret = i40e_hash_global_config_check(g_cfg);
6556 for (i = 0; mask0 && i < UINT32_BIT; i++) {
6557 if (!(mask0 & (1UL << i)))
6559 mask0 &= ~(1UL << i);
6560 pctype = i40e_flowtype_to_pctype(i);
6561 reg = (g_cfg->sym_hash_enable_mask[0] & (1UL << i)) ?
6562 I40E_GLQF_HSYM_SYMH_ENA_MASK : 0;
6563 i40e_write_rx_ctl(hw, I40E_GLQF_HSYM(pctype), reg);
6566 reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
6567 if (g_cfg->hash_func == RTE_ETH_HASH_FUNCTION_TOEPLITZ) {
6569 if (reg & I40E_GLQF_CTL_HTOEP_MASK) {
6570 PMD_DRV_LOG(DEBUG, "Hash function already set to "
6574 reg |= I40E_GLQF_CTL_HTOEP_MASK;
6575 } else if (g_cfg->hash_func == RTE_ETH_HASH_FUNCTION_SIMPLE_XOR) {
6577 if (!(reg & I40E_GLQF_CTL_HTOEP_MASK)) {
6578 PMD_DRV_LOG(DEBUG, "Hash function already set to "
6582 reg &= ~I40E_GLQF_CTL_HTOEP_MASK;
6584 /* Use the default, and keep it as it is */
6587 i40e_write_rx_ctl(hw, I40E_GLQF_CTL, reg);
6590 I40E_WRITE_FLUSH(hw);
6596 * Valid input sets for hash and flow director filters per PCTYPE
6599 i40e_get_valid_input_set(enum i40e_filter_pctype pctype,
6600 enum rte_filter_type filter)
6604 static const uint64_t valid_hash_inset_table[] = {
6605 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
6606 I40E_INSET_DMAC | I40E_INSET_SMAC |
6607 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6608 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_SRC |
6609 I40E_INSET_IPV4_DST | I40E_INSET_IPV4_TOS |
6610 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
6611 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
6612 I40E_INSET_FLEX_PAYLOAD,
6613 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
6614 I40E_INSET_DMAC | I40E_INSET_SMAC |
6615 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6616 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
6617 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
6618 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
6619 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6620 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6621 I40E_INSET_FLEX_PAYLOAD,
6622 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
6623 I40E_INSET_DMAC | I40E_INSET_SMAC |
6624 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6625 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
6626 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
6627 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
6628 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6629 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6630 I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
6631 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
6632 I40E_INSET_DMAC | I40E_INSET_SMAC |
6633 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6634 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
6635 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
6636 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
6637 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6638 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6639 I40E_INSET_SCTP_VT | I40E_INSET_FLEX_PAYLOAD,
6640 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
6641 I40E_INSET_DMAC | I40E_INSET_SMAC |
6642 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6643 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
6644 I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
6645 I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
6646 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6647 I40E_INSET_FLEX_PAYLOAD,
6648 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
6649 I40E_INSET_DMAC | I40E_INSET_SMAC |
6650 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6651 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
6652 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
6653 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_TUNNEL_DMAC |
6654 I40E_INSET_TUNNEL_ID | I40E_INSET_IPV6_SRC |
6655 I40E_INSET_IPV6_DST | I40E_INSET_FLEX_PAYLOAD,
6656 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
6657 I40E_INSET_DMAC | I40E_INSET_SMAC |
6658 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6659 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
6660 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
6661 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
6662 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
6663 I40E_INSET_DST_PORT | I40E_INSET_FLEX_PAYLOAD,
6664 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
6665 I40E_INSET_DMAC | I40E_INSET_SMAC |
6666 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6667 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
6668 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
6669 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
6670 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
6671 I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
6672 I40E_INSET_FLEX_PAYLOAD,
6673 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
6674 I40E_INSET_DMAC | I40E_INSET_SMAC |
6675 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6676 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
6677 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
6678 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
6679 I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
6680 I40E_INSET_DST_PORT | I40E_INSET_SCTP_VT |
6681 I40E_INSET_FLEX_PAYLOAD,
6682 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
6683 I40E_INSET_DMAC | I40E_INSET_SMAC |
6684 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6685 I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
6686 I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
6687 I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
6688 I40E_INSET_IPV6_DST | I40E_INSET_TUNNEL_ID |
6689 I40E_INSET_FLEX_PAYLOAD,
6690 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
6691 I40E_INSET_DMAC | I40E_INSET_SMAC |
6692 I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
6693 I40E_INSET_VLAN_TUNNEL | I40E_INSET_LAST_ETHER_TYPE |
6694 I40E_INSET_FLEX_PAYLOAD,
6698 * Flow director supports only fields defined in
6699 * union rte_eth_fdir_flow.
6701 static const uint64_t valid_fdir_inset_table[] = {
6702 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
6703 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6704 I40E_INSET_FLEX_PAYLOAD,
6705 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
6706 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6707 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6708 I40E_INSET_FLEX_PAYLOAD,
6709 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
6710 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6711 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6712 I40E_INSET_FLEX_PAYLOAD,
6713 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
6714 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6715 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6716 I40E_INSET_SCTP_VT | I40E_INSET_FLEX_PAYLOAD,
6717 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
6718 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6719 I40E_INSET_FLEX_PAYLOAD,
6720 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
6721 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6722 I40E_INSET_FLEX_PAYLOAD,
6723 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
6724 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6725 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6726 I40E_INSET_FLEX_PAYLOAD,
6727 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
6728 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6729 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6730 I40E_INSET_FLEX_PAYLOAD,
6731 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
6732 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6733 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6734 I40E_INSET_SCTP_VT | I40E_INSET_FLEX_PAYLOAD,
6735 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
6736 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6737 I40E_INSET_FLEX_PAYLOAD,
6738 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
6739 I40E_INSET_LAST_ETHER_TYPE | I40E_INSET_FLEX_PAYLOAD,
6742 if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
6744 if (filter == RTE_ETH_FILTER_HASH)
6745 valid = valid_hash_inset_table[pctype];
6747 valid = valid_fdir_inset_table[pctype];
6753 * Validate if the input set is allowed for a specific PCTYPE
6756 i40e_validate_input_set(enum i40e_filter_pctype pctype,
6757 enum rte_filter_type filter, uint64_t inset)
6761 valid = i40e_get_valid_input_set(pctype, filter);
6762 if (inset & (~valid))
6768 /* default input set fields combination per pctype */
6770 i40e_get_default_input_set(uint16_t pctype)
6772 static const uint64_t default_inset_table[] = {
6773 [I40E_FILTER_PCTYPE_FRAG_IPV4] =
6774 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
6775 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
6776 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6777 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
6778 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
6779 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6780 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
6781 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
6782 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
6783 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6785 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
6786 I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
6787 [I40E_FILTER_PCTYPE_FRAG_IPV6] =
6788 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
6789 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
6790 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6791 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
6792 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
6793 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6794 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
6795 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
6796 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
6797 I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
6799 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
6800 I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
6801 [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
6802 I40E_INSET_LAST_ETHER_TYPE,
6805 if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
6808 return default_inset_table[pctype];
6812 * Parse the input set from index to logical bit masks
6815 i40e_parse_input_set(uint64_t *inset,
6816 enum i40e_filter_pctype pctype,
6817 enum rte_eth_input_set_field *field,
6823 static const struct {
6824 enum rte_eth_input_set_field field;
6826 } inset_convert_table[] = {
6827 {RTE_ETH_INPUT_SET_NONE, I40E_INSET_NONE},
6828 {RTE_ETH_INPUT_SET_L2_SRC_MAC, I40E_INSET_SMAC},
6829 {RTE_ETH_INPUT_SET_L2_DST_MAC, I40E_INSET_DMAC},
6830 {RTE_ETH_INPUT_SET_L2_OUTER_VLAN, I40E_INSET_VLAN_OUTER},
6831 {RTE_ETH_INPUT_SET_L2_INNER_VLAN, I40E_INSET_VLAN_INNER},
6832 {RTE_ETH_INPUT_SET_L2_ETHERTYPE, I40E_INSET_LAST_ETHER_TYPE},
6833 {RTE_ETH_INPUT_SET_L3_SRC_IP4, I40E_INSET_IPV4_SRC},
6834 {RTE_ETH_INPUT_SET_L3_DST_IP4, I40E_INSET_IPV4_DST},
6835 {RTE_ETH_INPUT_SET_L3_IP4_TOS, I40E_INSET_IPV4_TOS},
6836 {RTE_ETH_INPUT_SET_L3_IP4_PROTO, I40E_INSET_IPV4_PROTO},
6837 {RTE_ETH_INPUT_SET_L3_SRC_IP6, I40E_INSET_IPV6_SRC},
6838 {RTE_ETH_INPUT_SET_L3_DST_IP6, I40E_INSET_IPV6_DST},
6839 {RTE_ETH_INPUT_SET_L3_IP6_TC, I40E_INSET_IPV6_TC},
6840 {RTE_ETH_INPUT_SET_L3_IP6_NEXT_HEADER,
6841 I40E_INSET_IPV6_NEXT_HDR},
6842 {RTE_ETH_INPUT_SET_L4_UDP_SRC_PORT, I40E_INSET_SRC_PORT},
6843 {RTE_ETH_INPUT_SET_L4_TCP_SRC_PORT, I40E_INSET_SRC_PORT},
6844 {RTE_ETH_INPUT_SET_L4_SCTP_SRC_PORT, I40E_INSET_SRC_PORT},
6845 {RTE_ETH_INPUT_SET_L4_UDP_DST_PORT, I40E_INSET_DST_PORT},
6846 {RTE_ETH_INPUT_SET_L4_TCP_DST_PORT, I40E_INSET_DST_PORT},
6847 {RTE_ETH_INPUT_SET_L4_SCTP_DST_PORT, I40E_INSET_DST_PORT},
6848 {RTE_ETH_INPUT_SET_L4_SCTP_VERIFICATION_TAG,
6849 I40E_INSET_SCTP_VT},
6850 {RTE_ETH_INPUT_SET_TUNNEL_L2_INNER_DST_MAC,
6851 I40E_INSET_TUNNEL_DMAC},
6852 {RTE_ETH_INPUT_SET_TUNNEL_L2_INNER_VLAN,
6853 I40E_INSET_VLAN_TUNNEL},
6854 {RTE_ETH_INPUT_SET_TUNNEL_L4_UDP_KEY,
6855 I40E_INSET_TUNNEL_ID},
6856 {RTE_ETH_INPUT_SET_TUNNEL_GRE_KEY, I40E_INSET_TUNNEL_ID},
6857 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_1ST_WORD,
6858 I40E_INSET_FLEX_PAYLOAD_W1},
6859 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_2ND_WORD,
6860 I40E_INSET_FLEX_PAYLOAD_W2},
6861 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_3RD_WORD,
6862 I40E_INSET_FLEX_PAYLOAD_W3},
6863 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_4TH_WORD,
6864 I40E_INSET_FLEX_PAYLOAD_W4},
6865 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_5TH_WORD,
6866 I40E_INSET_FLEX_PAYLOAD_W5},
6867 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_6TH_WORD,
6868 I40E_INSET_FLEX_PAYLOAD_W6},
6869 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_7TH_WORD,
6870 I40E_INSET_FLEX_PAYLOAD_W7},
6871 {RTE_ETH_INPUT_SET_FLEX_PAYLOAD_8TH_WORD,
6872 I40E_INSET_FLEX_PAYLOAD_W8},
6875 if (!inset || !field || size > RTE_ETH_INSET_SIZE_MAX)
6878 /* Only one item allowed for default or all */
6880 if (field[0] == RTE_ETH_INPUT_SET_DEFAULT) {
6881 *inset = i40e_get_default_input_set(pctype);
6883 } else if (field[0] == RTE_ETH_INPUT_SET_NONE) {
6884 *inset = I40E_INSET_NONE;
6889 for (i = 0, *inset = 0; i < size; i++) {
6890 for (j = 0; j < RTE_DIM(inset_convert_table); j++) {
6891 if (field[i] == inset_convert_table[j].field) {
6892 *inset |= inset_convert_table[j].inset;
6897 /* It contains unsupported input set, return immediately */
6898 if (j == RTE_DIM(inset_convert_table))
6906 * Translate the input set from bit masks to register aware bit masks
6910 i40e_translate_input_set_reg(uint64_t input)
6915 static const struct {
6919 {I40E_INSET_DMAC, I40E_REG_INSET_L2_DMAC},
6920 {I40E_INSET_SMAC, I40E_REG_INSET_L2_SMAC},
6921 {I40E_INSET_VLAN_OUTER, I40E_REG_INSET_L2_OUTER_VLAN},
6922 {I40E_INSET_VLAN_INNER, I40E_REG_INSET_L2_INNER_VLAN},
6923 {I40E_INSET_LAST_ETHER_TYPE, I40E_REG_INSET_LAST_ETHER_TYPE},
6924 {I40E_INSET_IPV4_SRC, I40E_REG_INSET_L3_SRC_IP4},
6925 {I40E_INSET_IPV4_DST, I40E_REG_INSET_L3_DST_IP4},
6926 {I40E_INSET_IPV4_TOS, I40E_REG_INSET_L3_IP4_TOS},
6927 {I40E_INSET_IPV4_PROTO, I40E_REG_INSET_L3_IP4_PROTO},
6928 {I40E_INSET_IPV6_SRC, I40E_REG_INSET_L3_SRC_IP6},
6929 {I40E_INSET_IPV6_DST, I40E_REG_INSET_L3_DST_IP6},
6930 {I40E_INSET_IPV6_TC, I40E_REG_INSET_L3_IP6_TC},
6931 {I40E_INSET_IPV6_NEXT_HDR, I40E_REG_INSET_L3_IP6_NEXT_HDR},
6932 {I40E_INSET_SRC_PORT, I40E_REG_INSET_L4_SRC_PORT},
6933 {I40E_INSET_DST_PORT, I40E_REG_INSET_L4_DST_PORT},
6934 {I40E_INSET_SCTP_VT, I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG},
6935 {I40E_INSET_TUNNEL_ID, I40E_REG_INSET_TUNNEL_ID},
6936 {I40E_INSET_TUNNEL_DMAC,
6937 I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC},
6938 {I40E_INSET_TUNNEL_IPV4_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP4},
6939 {I40E_INSET_TUNNEL_IPV6_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP6},
6940 {I40E_INSET_TUNNEL_SRC_PORT,
6941 I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT},
6942 {I40E_INSET_TUNNEL_DST_PORT,
6943 I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT},
6944 {I40E_INSET_TUNNEL_ID, I40E_REG_INSET_TUNNEL_ID},
6945 {I40E_INSET_FLEX_PAYLOAD_W1, I40E_REG_INSET_FLEX_PAYLOAD_WORD1},
6946 {I40E_INSET_FLEX_PAYLOAD_W2, I40E_REG_INSET_FLEX_PAYLOAD_WORD2},
6947 {I40E_INSET_FLEX_PAYLOAD_W3, I40E_REG_INSET_FLEX_PAYLOAD_WORD3},
6948 {I40E_INSET_FLEX_PAYLOAD_W4, I40E_REG_INSET_FLEX_PAYLOAD_WORD4},
6949 {I40E_INSET_FLEX_PAYLOAD_W5, I40E_REG_INSET_FLEX_PAYLOAD_WORD5},
6950 {I40E_INSET_FLEX_PAYLOAD_W6, I40E_REG_INSET_FLEX_PAYLOAD_WORD6},
6951 {I40E_INSET_FLEX_PAYLOAD_W7, I40E_REG_INSET_FLEX_PAYLOAD_WORD7},
6952 {I40E_INSET_FLEX_PAYLOAD_W8, I40E_REG_INSET_FLEX_PAYLOAD_WORD8},
6958 /* Translate input set to register aware inset */
6959 for (i = 0; i < RTE_DIM(inset_map); i++) {
6960 if (input & inset_map[i].inset)
6961 val |= inset_map[i].inset_reg;
6968 i40e_generate_inset_mask_reg(uint64_t inset, uint32_t *mask, uint8_t nb_elem)
6972 static const struct {
6975 } inset_mask_map[] = {
6976 {I40E_INSET_IPV4_TOS, I40E_INSET_IPV4_TOS_MASK},
6977 {I40E_INSET_IPV4_PROTO, I40E_INSET_IPV4_PROTO_MASK},
6978 {I40E_INSET_IPV6_TC, I40E_INSET_IPV6_TC_MASK},
6979 {I40E_INSET_IPV6_NEXT_HDR, I40E_INSET_IPV6_NEXT_HDR_MASK},
6982 if (!inset || !mask || !nb_elem)
6985 if (!inset && nb_elem >= I40E_INSET_MASK_NUM_REG) {
6986 for (i = 0; i < I40E_INSET_MASK_NUM_REG; i++)
6988 return I40E_INSET_MASK_NUM_REG;
6991 for (i = 0, idx = 0; i < RTE_DIM(inset_mask_map); i++) {
6994 if (inset & inset_mask_map[i].inset) {
6995 mask[idx] = inset_mask_map[i].mask;
7004 i40e_get_reg_inset(struct i40e_hw *hw, enum rte_filter_type filter,
7005 enum i40e_filter_pctype pctype)
7009 if (filter == RTE_ETH_FILTER_HASH) {
7010 reg = i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, pctype));
7011 reg <<= I40E_32_BIT_WIDTH;
7012 reg |= i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, pctype));
7013 } else if (filter == RTE_ETH_FILTER_FDIR) {
7014 reg = i40e_read_rx_ctl(hw, I40E_PRTQF_FD_INSET(pctype, 1));
7015 reg <<= I40E_32_BIT_WIDTH;
7016 reg |= i40e_read_rx_ctl(hw, I40E_PRTQF_FD_INSET(pctype, 0));
7023 i40e_check_write_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
7025 uint32_t reg = i40e_read_rx_ctl(hw, addr);
7027 PMD_DRV_LOG(DEBUG, "[0x%08x] original: 0x%08x\n", addr, reg);
7029 i40e_write_rx_ctl(hw, addr, val);
7030 PMD_DRV_LOG(DEBUG, "[0x%08x] after: 0x%08x\n", addr,
7031 (uint32_t)i40e_read_rx_ctl(hw, addr));
7035 i40e_set_hash_inset_mask(struct i40e_hw *hw,
7036 enum i40e_filter_pctype pctype,
7037 enum rte_filter_input_set_op op,
7044 if (!mask_reg || num > RTE_ETH_INPUT_SET_SELECT)
7047 if (op == RTE_ETH_INPUT_SET_SELECT) {
7048 for (i = 0; i < I40E_INSET_MASK_NUM_REG; i++) {
7049 i40e_check_write_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
7053 i40e_check_write_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
7056 } else if (op == RTE_ETH_INPUT_SET_ADD) {
7057 uint8_t j, count = 0;
7059 for (i = 0; i < I40E_INSET_MASK_NUM_REG; i++) {
7060 reg = i40e_read_rx_ctl(hw,
7061 I40E_GLQF_HASH_MSK(i, pctype));
7062 if (reg & I40E_GLQF_HASH_MSK_MASK_MASK)
7065 if (count + num > I40E_INSET_MASK_NUM_REG)
7068 for (i = count, j = 0; i < I40E_INSET_MASK_NUM_REG; i++, j++)
7069 i40e_check_write_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
7077 i40e_set_fd_inset_mask(struct i40e_hw *hw,
7078 enum i40e_filter_pctype pctype,
7079 enum rte_filter_input_set_op op,
7086 if (!mask_reg || num > RTE_ETH_INPUT_SET_SELECT)
7089 if (op == RTE_ETH_INPUT_SET_SELECT) {
7090 for (i = 0; i < I40E_INSET_MASK_NUM_REG; i++) {
7091 i40e_check_write_reg(hw, I40E_GLQF_FD_MSK(i, pctype),
7095 i40e_check_write_reg(hw, I40E_GLQF_FD_MSK(i, pctype),
7098 } else if (op == RTE_ETH_INPUT_SET_ADD) {
7099 uint8_t j, count = 0;
7101 for (i = 0; i < I40E_INSET_MASK_NUM_REG; i++) {
7102 reg = i40e_read_rx_ctl(hw,
7103 I40E_GLQF_FD_MSK(i, pctype));
7104 if (reg & I40E_GLQF_FD_MSK_MASK_MASK)
7107 if (count + num > I40E_INSET_MASK_NUM_REG)
7110 for (i = count, j = 0; i < I40E_INSET_MASK_NUM_REG; i++, j++)
7111 i40e_check_write_reg(hw, I40E_GLQF_FD_MSK(i, pctype),
7119 i40e_filter_inset_select(struct i40e_hw *hw,
7120 struct rte_eth_input_set_conf *conf,
7121 enum rte_filter_type filter)
7123 enum i40e_filter_pctype pctype;
7124 uint64_t inset_reg = 0, input_set;
7125 uint32_t mask_reg[I40E_INSET_MASK_NUM_REG];
7130 PMD_DRV_LOG(ERR, "Invalid pointer");
7134 pctype = i40e_flowtype_to_pctype(conf->flow_type);
7135 if (pctype == 0 || pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD) {
7136 PMD_DRV_LOG(ERR, "Not supported flow type (%u)",
7140 if (filter != RTE_ETH_FILTER_HASH && filter != RTE_ETH_FILTER_FDIR) {
7141 PMD_DRV_LOG(ERR, "Not supported filter type (%u)", filter);
7145 ret = i40e_parse_input_set(&input_set, pctype, conf->field,
7148 PMD_DRV_LOG(ERR, "Failed to parse input set");
7151 if (i40e_validate_input_set(pctype, filter, input_set) != 0) {
7152 PMD_DRV_LOG(ERR, "Invalid input set");
7156 if (conf->op == RTE_ETH_INPUT_SET_ADD) {
7157 inset_reg |= i40e_get_reg_inset(hw, filter, pctype);
7158 } else if (conf->op != RTE_ETH_INPUT_SET_SELECT) {
7159 PMD_DRV_LOG(ERR, "Unsupported input set operation");
7162 num = i40e_generate_inset_mask_reg(input_set, mask_reg,
7163 I40E_INSET_MASK_NUM_REG);
7164 inset_reg |= i40e_translate_input_set_reg(input_set);
7166 if (filter == RTE_ETH_FILTER_HASH) {
7167 ret = i40e_set_hash_inset_mask(hw, pctype, conf->op, mask_reg,
7172 i40e_check_write_reg(hw, I40E_GLQF_HASH_INSET(0, pctype),
7173 (uint32_t)(inset_reg & UINT32_MAX));
7174 i40e_check_write_reg(hw, I40E_GLQF_HASH_INSET(1, pctype),
7175 (uint32_t)((inset_reg >>
7176 I40E_32_BIT_WIDTH) & UINT32_MAX));
7177 } else if (filter == RTE_ETH_FILTER_FDIR) {
7178 ret = i40e_set_fd_inset_mask(hw, pctype, conf->op, mask_reg,
7183 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
7184 (uint32_t)(inset_reg & UINT32_MAX));
7185 i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
7186 (uint32_t)((inset_reg >>
7187 I40E_32_BIT_WIDTH) & UINT32_MAX));
7189 PMD_DRV_LOG(ERR, "Not supported filter type (%u)", filter);
7192 I40E_WRITE_FLUSH(hw);
7198 i40e_hash_filter_get(struct i40e_hw *hw, struct rte_eth_hash_filter_info *info)
7203 PMD_DRV_LOG(ERR, "Invalid pointer");
7207 switch (info->info_type) {
7208 case RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT:
7209 i40e_get_symmetric_hash_enable_per_port(hw,
7210 &(info->info.enable));
7212 case RTE_ETH_HASH_FILTER_GLOBAL_CONFIG:
7213 ret = i40e_get_hash_filter_global_config(hw,
7214 &(info->info.global_conf));
7217 PMD_DRV_LOG(ERR, "Hash filter info type (%d) not supported",
7227 i40e_hash_filter_set(struct i40e_hw *hw, struct rte_eth_hash_filter_info *info)
7232 PMD_DRV_LOG(ERR, "Invalid pointer");
7236 switch (info->info_type) {
7237 case RTE_ETH_HASH_FILTER_SYM_HASH_ENA_PER_PORT:
7238 i40e_set_symmetric_hash_enable_per_port(hw, info->info.enable);
7240 case RTE_ETH_HASH_FILTER_GLOBAL_CONFIG:
7241 ret = i40e_set_hash_filter_global_config(hw,
7242 &(info->info.global_conf));
7244 case RTE_ETH_HASH_FILTER_INPUT_SET_SELECT:
7245 ret = i40e_filter_inset_select(hw,
7246 &(info->info.input_set_conf),
7247 RTE_ETH_FILTER_HASH);
7251 PMD_DRV_LOG(ERR, "Hash filter info type (%d) not supported",
7260 /* Operations for hash function */
7262 i40e_hash_filter_ctrl(struct rte_eth_dev *dev,
7263 enum rte_filter_op filter_op,
7266 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7269 switch (filter_op) {
7270 case RTE_ETH_FILTER_NOP:
7272 case RTE_ETH_FILTER_GET:
7273 ret = i40e_hash_filter_get(hw,
7274 (struct rte_eth_hash_filter_info *)arg);
7276 case RTE_ETH_FILTER_SET:
7277 ret = i40e_hash_filter_set(hw,
7278 (struct rte_eth_hash_filter_info *)arg);
7281 PMD_DRV_LOG(WARNING, "Filter operation (%d) not supported",
7291 * Configure ethertype filter, which can director packet by filtering
7292 * with mac address and ether_type or only ether_type
7295 i40e_ethertype_filter_set(struct i40e_pf *pf,
7296 struct rte_eth_ethertype_filter *filter,
7299 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7300 struct i40e_control_filter_stats stats;
7304 if (filter->queue >= pf->dev_data->nb_rx_queues) {
7305 PMD_DRV_LOG(ERR, "Invalid queue ID");
7308 if (filter->ether_type == ETHER_TYPE_IPv4 ||
7309 filter->ether_type == ETHER_TYPE_IPv6) {
7310 PMD_DRV_LOG(ERR, "unsupported ether_type(0x%04x) in"
7311 " control packet filter.", filter->ether_type);
7314 if (filter->ether_type == ETHER_TYPE_VLAN)
7315 PMD_DRV_LOG(WARNING, "filter vlan ether_type in first tag is"
7318 if (!(filter->flags & RTE_ETHTYPE_FLAGS_MAC))
7319 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
7320 if (filter->flags & RTE_ETHTYPE_FLAGS_DROP)
7321 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
7322 flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
7324 memset(&stats, 0, sizeof(stats));
7325 ret = i40e_aq_add_rem_control_packet_filter(hw,
7326 filter->mac_addr.addr_bytes,
7327 filter->ether_type, flags,
7329 filter->queue, add, &stats, NULL);
7331 PMD_DRV_LOG(INFO, "add/rem control packet filter, return %d,"
7332 " mac_etype_used = %u, etype_used = %u,"
7333 " mac_etype_free = %u, etype_free = %u\n",
7334 ret, stats.mac_etype_used, stats.etype_used,
7335 stats.mac_etype_free, stats.etype_free);
7342 * Handle operations for ethertype filter.
7345 i40e_ethertype_filter_handle(struct rte_eth_dev *dev,
7346 enum rte_filter_op filter_op,
7349 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7352 if (filter_op == RTE_ETH_FILTER_NOP)
7356 PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u",
7361 switch (filter_op) {
7362 case RTE_ETH_FILTER_ADD:
7363 ret = i40e_ethertype_filter_set(pf,
7364 (struct rte_eth_ethertype_filter *)arg,
7367 case RTE_ETH_FILTER_DELETE:
7368 ret = i40e_ethertype_filter_set(pf,
7369 (struct rte_eth_ethertype_filter *)arg,
7373 PMD_DRV_LOG(ERR, "unsupported operation %u\n", filter_op);
7381 i40e_dev_filter_ctrl(struct rte_eth_dev *dev,
7382 enum rte_filter_type filter_type,
7383 enum rte_filter_op filter_op,
7391 switch (filter_type) {
7392 case RTE_ETH_FILTER_NONE:
7393 /* For global configuration */
7394 ret = i40e_filter_ctrl_global_config(dev, filter_op, arg);
7396 case RTE_ETH_FILTER_HASH:
7397 ret = i40e_hash_filter_ctrl(dev, filter_op, arg);
7399 case RTE_ETH_FILTER_MACVLAN:
7400 ret = i40e_mac_filter_handle(dev, filter_op, arg);
7402 case RTE_ETH_FILTER_ETHERTYPE:
7403 ret = i40e_ethertype_filter_handle(dev, filter_op, arg);
7405 case RTE_ETH_FILTER_TUNNEL:
7406 ret = i40e_tunnel_filter_handle(dev, filter_op, arg);
7408 case RTE_ETH_FILTER_FDIR:
7409 ret = i40e_fdir_ctrl_func(dev, filter_op, arg);
7412 PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
7422 * Check and enable Extended Tag.
7423 * Enabling Extended Tag is important for 40G performance.
7426 i40e_enable_extended_tag(struct rte_eth_dev *dev)
7431 ret = rte_eal_pci_read_config(dev->pci_dev, &buf, sizeof(buf),
7434 PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
7438 if (!(buf & PCI_DEV_CAP_EXT_TAG_MASK)) {
7439 PMD_DRV_LOG(ERR, "Does not support Extended Tag");
7444 ret = rte_eal_pci_read_config(dev->pci_dev, &buf, sizeof(buf),
7447 PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
7451 if (buf & PCI_DEV_CTRL_EXT_TAG_MASK) {
7452 PMD_DRV_LOG(DEBUG, "Extended Tag has already been enabled");
7455 buf |= PCI_DEV_CTRL_EXT_TAG_MASK;
7456 ret = rte_eal_pci_write_config(dev->pci_dev, &buf, sizeof(buf),
7459 PMD_DRV_LOG(ERR, "Failed to write PCI offset 0x%x",
7466 * As some registers wouldn't be reset unless a global hardware reset,
7467 * hardware initialization is needed to put those registers into an
7468 * expected initial state.
7471 i40e_hw_init(struct rte_eth_dev *dev)
7473 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7475 i40e_enable_extended_tag(dev);
7477 /* clear the PF Queue Filter control register */
7478 i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, 0);
7480 /* Disable symmetric hash per port */
7481 i40e_set_symmetric_hash_enable_per_port(hw, 0);
7484 enum i40e_filter_pctype
7485 i40e_flowtype_to_pctype(uint16_t flow_type)
7487 static const enum i40e_filter_pctype pctype_table[] = {
7488 [RTE_ETH_FLOW_FRAG_IPV4] = I40E_FILTER_PCTYPE_FRAG_IPV4,
7489 [RTE_ETH_FLOW_NONFRAG_IPV4_UDP] =
7490 I40E_FILTER_PCTYPE_NONF_IPV4_UDP,
7491 [RTE_ETH_FLOW_NONFRAG_IPV4_TCP] =
7492 I40E_FILTER_PCTYPE_NONF_IPV4_TCP,
7493 [RTE_ETH_FLOW_NONFRAG_IPV4_SCTP] =
7494 I40E_FILTER_PCTYPE_NONF_IPV4_SCTP,
7495 [RTE_ETH_FLOW_NONFRAG_IPV4_OTHER] =
7496 I40E_FILTER_PCTYPE_NONF_IPV4_OTHER,
7497 [RTE_ETH_FLOW_FRAG_IPV6] = I40E_FILTER_PCTYPE_FRAG_IPV6,
7498 [RTE_ETH_FLOW_NONFRAG_IPV6_UDP] =
7499 I40E_FILTER_PCTYPE_NONF_IPV6_UDP,
7500 [RTE_ETH_FLOW_NONFRAG_IPV6_TCP] =
7501 I40E_FILTER_PCTYPE_NONF_IPV6_TCP,
7502 [RTE_ETH_FLOW_NONFRAG_IPV6_SCTP] =
7503 I40E_FILTER_PCTYPE_NONF_IPV6_SCTP,
7504 [RTE_ETH_FLOW_NONFRAG_IPV6_OTHER] =
7505 I40E_FILTER_PCTYPE_NONF_IPV6_OTHER,
7506 [RTE_ETH_FLOW_L2_PAYLOAD] = I40E_FILTER_PCTYPE_L2_PAYLOAD,
7509 return pctype_table[flow_type];
7513 i40e_pctype_to_flowtype(enum i40e_filter_pctype pctype)
7515 static const uint16_t flowtype_table[] = {
7516 [I40E_FILTER_PCTYPE_FRAG_IPV4] = RTE_ETH_FLOW_FRAG_IPV4,
7517 [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
7518 RTE_ETH_FLOW_NONFRAG_IPV4_UDP,
7519 [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
7520 RTE_ETH_FLOW_NONFRAG_IPV4_TCP,
7521 [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
7522 RTE_ETH_FLOW_NONFRAG_IPV4_SCTP,
7523 [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
7524 RTE_ETH_FLOW_NONFRAG_IPV4_OTHER,
7525 [I40E_FILTER_PCTYPE_FRAG_IPV6] = RTE_ETH_FLOW_FRAG_IPV6,
7526 [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
7527 RTE_ETH_FLOW_NONFRAG_IPV6_UDP,
7528 [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
7529 RTE_ETH_FLOW_NONFRAG_IPV6_TCP,
7530 [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
7531 RTE_ETH_FLOW_NONFRAG_IPV6_SCTP,
7532 [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
7533 RTE_ETH_FLOW_NONFRAG_IPV6_OTHER,
7534 [I40E_FILTER_PCTYPE_L2_PAYLOAD] = RTE_ETH_FLOW_L2_PAYLOAD,
7537 return flowtype_table[pctype];
7541 * On X710, performance number is far from the expectation on recent firmware
7542 * versions; on XL710, performance number is also far from the expectation on
7543 * recent firmware versions, if promiscuous mode is disabled, or promiscuous
7544 * mode is enabled and port MAC address is equal to the packet destination MAC
7545 * address. The fix for this issue may not be integrated in the following
7546 * firmware version. So the workaround in software driver is needed. It needs
7547 * to modify the initial values of 3 internal only registers for both X710 and
7548 * XL710. Note that the values for X710 or XL710 could be different, and the
7549 * workaround can be removed when it is fixed in firmware in the future.
7552 /* For both X710 and XL710 */
7553 #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE 0x10000200
7554 #define I40E_GL_SWR_PRI_JOIN_MAP_0 0x26CE00
7556 #define I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x011f0200
7557 #define I40E_GL_SWR_PRI_JOIN_MAP_2 0x26CE08
7560 #define I40E_GL_SWR_PM_UP_THR_EF_VALUE 0x03030303
7562 #define I40E_GL_SWR_PM_UP_THR_SF_VALUE 0x06060606
7563 #define I40E_GL_SWR_PM_UP_THR 0x269FBC
7566 i40e_configure_registers(struct i40e_hw *hw)
7572 {I40E_GL_SWR_PRI_JOIN_MAP_0, I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE},
7573 {I40E_GL_SWR_PRI_JOIN_MAP_2, I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE},
7574 {I40E_GL_SWR_PM_UP_THR, 0}, /* Compute value dynamically */
7580 for (i = 0; i < RTE_DIM(reg_table); i++) {
7581 if (reg_table[i].addr == I40E_GL_SWR_PM_UP_THR) {
7582 if (i40e_is_40G_device(hw->device_id)) /* For XL710 */
7584 I40E_GL_SWR_PM_UP_THR_SF_VALUE;
7587 I40E_GL_SWR_PM_UP_THR_EF_VALUE;
7590 ret = i40e_aq_debug_read_register(hw, reg_table[i].addr,
7593 PMD_DRV_LOG(ERR, "Failed to read from 0x%"PRIx32,
7597 PMD_DRV_LOG(DEBUG, "Read from 0x%"PRIx32": 0x%"PRIx64,
7598 reg_table[i].addr, reg);
7599 if (reg == reg_table[i].val)
7602 ret = i40e_aq_debug_write_register(hw, reg_table[i].addr,
7603 reg_table[i].val, NULL);
7605 PMD_DRV_LOG(ERR, "Failed to write 0x%"PRIx64" to the "
7606 "address of 0x%"PRIx32, reg_table[i].val,
7610 PMD_DRV_LOG(DEBUG, "Write 0x%"PRIx64" to the address of "
7611 "0x%"PRIx32, reg_table[i].val, reg_table[i].addr);
7615 #define I40E_VSI_TSR(_i) (0x00050800 + ((_i) * 4))
7616 #define I40E_VSI_TSR_QINQ_CONFIG 0xc030
7617 #define I40E_VSI_L2TAGSTXVALID(_i) (0x00042800 + ((_i) * 4))
7618 #define I40E_VSI_L2TAGSTXVALID_QINQ 0xab
7620 i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi)
7625 if (vsi->vsi_id >= I40E_MAX_NUM_VSIS) {
7626 PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
7630 /* Configure for double VLAN RX stripping */
7631 reg = I40E_READ_REG(hw, I40E_VSI_TSR(vsi->vsi_id));
7632 if ((reg & I40E_VSI_TSR_QINQ_CONFIG) != I40E_VSI_TSR_QINQ_CONFIG) {
7633 reg |= I40E_VSI_TSR_QINQ_CONFIG;
7634 ret = i40e_aq_debug_write_register(hw,
7635 I40E_VSI_TSR(vsi->vsi_id),
7638 PMD_DRV_LOG(ERR, "Failed to update VSI_TSR[%d]",
7640 return I40E_ERR_CONFIG;
7644 /* Configure for double VLAN TX insertion */
7645 reg = I40E_READ_REG(hw, I40E_VSI_L2TAGSTXVALID(vsi->vsi_id));
7646 if ((reg & 0xff) != I40E_VSI_L2TAGSTXVALID_QINQ) {
7647 reg = I40E_VSI_L2TAGSTXVALID_QINQ;
7648 ret = i40e_aq_debug_write_register(hw,
7649 I40E_VSI_L2TAGSTXVALID(
7650 vsi->vsi_id), reg, NULL);
7652 PMD_DRV_LOG(ERR, "Failed to update "
7653 "VSI_L2TAGSTXVALID[%d]", vsi->vsi_id);
7654 return I40E_ERR_CONFIG;
7662 * i40e_aq_add_mirror_rule
7663 * @hw: pointer to the hardware structure
7664 * @seid: VEB seid to add mirror rule to
7665 * @dst_id: destination vsi seid
7666 * @entries: Buffer which contains the entities to be mirrored
7667 * @count: number of entities contained in the buffer
7668 * @rule_id:the rule_id of the rule to be added
7670 * Add a mirror rule for a given veb.
7673 static enum i40e_status_code
7674 i40e_aq_add_mirror_rule(struct i40e_hw *hw,
7675 uint16_t seid, uint16_t dst_id,
7676 uint16_t rule_type, uint16_t *entries,
7677 uint16_t count, uint16_t *rule_id)
7679 struct i40e_aq_desc desc;
7680 struct i40e_aqc_add_delete_mirror_rule cmd;
7681 struct i40e_aqc_add_delete_mirror_rule_completion *resp =
7682 (struct i40e_aqc_add_delete_mirror_rule_completion *)
7685 enum i40e_status_code status;
7687 i40e_fill_default_direct_cmd_desc(&desc,
7688 i40e_aqc_opc_add_mirror_rule);
7689 memset(&cmd, 0, sizeof(cmd));
7691 buff_len = sizeof(uint16_t) * count;
7692 desc.datalen = rte_cpu_to_le_16(buff_len);
7694 desc.flags |= rte_cpu_to_le_16(
7695 (uint16_t)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
7696 cmd.rule_type = rte_cpu_to_le_16(rule_type <<
7697 I40E_AQC_MIRROR_RULE_TYPE_SHIFT);
7698 cmd.num_entries = rte_cpu_to_le_16(count);
7699 cmd.seid = rte_cpu_to_le_16(seid);
7700 cmd.destination = rte_cpu_to_le_16(dst_id);
7702 rte_memcpy(&desc.params.raw, &cmd, sizeof(cmd));
7703 status = i40e_asq_send_command(hw, &desc, entries, buff_len, NULL);
7704 PMD_DRV_LOG(INFO, "i40e_aq_add_mirror_rule, aq_status %d,"
7706 " mirror_rules_used = %u, mirror_rules_free = %u,",
7707 hw->aq.asq_last_status, resp->rule_id,
7708 resp->mirror_rules_used, resp->mirror_rules_free);
7709 *rule_id = rte_le_to_cpu_16(resp->rule_id);
7715 * i40e_aq_del_mirror_rule
7716 * @hw: pointer to the hardware structure
7717 * @seid: VEB seid to add mirror rule to
7718 * @entries: Buffer which contains the entities to be mirrored
7719 * @count: number of entities contained in the buffer
7720 * @rule_id:the rule_id of the rule to be delete
7722 * Delete a mirror rule for a given veb.
7725 static enum i40e_status_code
7726 i40e_aq_del_mirror_rule(struct i40e_hw *hw,
7727 uint16_t seid, uint16_t rule_type, uint16_t *entries,
7728 uint16_t count, uint16_t rule_id)
7730 struct i40e_aq_desc desc;
7731 struct i40e_aqc_add_delete_mirror_rule cmd;
7732 uint16_t buff_len = 0;
7733 enum i40e_status_code status;
7736 i40e_fill_default_direct_cmd_desc(&desc,
7737 i40e_aqc_opc_delete_mirror_rule);
7738 memset(&cmd, 0, sizeof(cmd));
7739 if (rule_type == I40E_AQC_MIRROR_RULE_TYPE_VLAN) {
7740 desc.flags |= rte_cpu_to_le_16((uint16_t)(I40E_AQ_FLAG_BUF |
7742 cmd.num_entries = count;
7743 buff_len = sizeof(uint16_t) * count;
7744 desc.datalen = rte_cpu_to_le_16(buff_len);
7745 buff = (void *)entries;
7747 /* rule id is filled in destination field for deleting mirror rule */
7748 cmd.destination = rte_cpu_to_le_16(rule_id);
7750 cmd.rule_type = rte_cpu_to_le_16(rule_type <<
7751 I40E_AQC_MIRROR_RULE_TYPE_SHIFT);
7752 cmd.seid = rte_cpu_to_le_16(seid);
7754 rte_memcpy(&desc.params.raw, &cmd, sizeof(cmd));
7755 status = i40e_asq_send_command(hw, &desc, buff, buff_len, NULL);
7761 * i40e_mirror_rule_set
7762 * @dev: pointer to the hardware structure
7763 * @mirror_conf: mirror rule info
7764 * @sw_id: mirror rule's sw_id
7765 * @on: enable/disable
7767 * set a mirror rule.
7771 i40e_mirror_rule_set(struct rte_eth_dev *dev,
7772 struct rte_eth_mirror_conf *mirror_conf,
7773 uint8_t sw_id, uint8_t on)
7775 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7776 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7777 struct i40e_mirror_rule *it, *mirr_rule = NULL;
7778 struct i40e_mirror_rule *parent = NULL;
7779 uint16_t seid, dst_seid, rule_id;
7783 PMD_DRV_LOG(DEBUG, "i40e_mirror_rule_set: sw_id = %d.", sw_id);
7785 if (pf->main_vsi->veb == NULL || pf->vfs == NULL) {
7786 PMD_DRV_LOG(ERR, "mirror rule can not be configured"
7787 " without veb or vfs.");
7790 if (pf->nb_mirror_rule > I40E_MAX_MIRROR_RULES) {
7791 PMD_DRV_LOG(ERR, "mirror table is full.");
7794 if (mirror_conf->dst_pool > pf->vf_num) {
7795 PMD_DRV_LOG(ERR, "invalid destination pool %u.",
7796 mirror_conf->dst_pool);
7800 seid = pf->main_vsi->veb->seid;
7802 TAILQ_FOREACH(it, &pf->mirror_list, rules) {
7803 if (sw_id <= it->index) {
7809 if (mirr_rule && sw_id == mirr_rule->index) {
7811 PMD_DRV_LOG(ERR, "mirror rule exists.");
7814 ret = i40e_aq_del_mirror_rule(hw, seid,
7815 mirr_rule->rule_type,
7817 mirr_rule->num_entries, mirr_rule->id);
7819 PMD_DRV_LOG(ERR, "failed to remove mirror rule:"
7820 " ret = %d, aq_err = %d.",
7821 ret, hw->aq.asq_last_status);
7824 TAILQ_REMOVE(&pf->mirror_list, mirr_rule, rules);
7825 rte_free(mirr_rule);
7826 pf->nb_mirror_rule--;
7830 PMD_DRV_LOG(ERR, "mirror rule doesn't exist.");
7834 mirr_rule = rte_zmalloc("i40e_mirror_rule",
7835 sizeof(struct i40e_mirror_rule) , 0);
7837 PMD_DRV_LOG(ERR, "failed to allocate memory");
7838 return I40E_ERR_NO_MEMORY;
7840 switch (mirror_conf->rule_type) {
7841 case ETH_MIRROR_VLAN:
7842 for (i = 0, j = 0; i < ETH_MIRROR_MAX_VLANS; i++) {
7843 if (mirror_conf->vlan.vlan_mask & (1ULL << i)) {
7844 mirr_rule->entries[j] =
7845 mirror_conf->vlan.vlan_id[i];
7850 PMD_DRV_LOG(ERR, "vlan is not specified.");
7851 rte_free(mirr_rule);
7854 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_VLAN;
7856 case ETH_MIRROR_VIRTUAL_POOL_UP:
7857 case ETH_MIRROR_VIRTUAL_POOL_DOWN:
7858 /* check if the specified pool bit is out of range */
7859 if (mirror_conf->pool_mask > (uint64_t)(1ULL << (pf->vf_num + 1))) {
7860 PMD_DRV_LOG(ERR, "pool mask is out of range.");
7861 rte_free(mirr_rule);
7864 for (i = 0, j = 0; i < pf->vf_num; i++) {
7865 if (mirror_conf->pool_mask & (1ULL << i)) {
7866 mirr_rule->entries[j] = pf->vfs[i].vsi->seid;
7870 if (mirror_conf->pool_mask & (1ULL << pf->vf_num)) {
7871 /* add pf vsi to entries */
7872 mirr_rule->entries[j] = pf->main_vsi_seid;
7876 PMD_DRV_LOG(ERR, "pool is not specified.");
7877 rte_free(mirr_rule);
7880 /* egress and ingress in aq commands means from switch but not port */
7881 mirr_rule->rule_type =
7882 (mirror_conf->rule_type == ETH_MIRROR_VIRTUAL_POOL_UP) ?
7883 I40E_AQC_MIRROR_RULE_TYPE_VPORT_EGRESS :
7884 I40E_AQC_MIRROR_RULE_TYPE_VPORT_INGRESS;
7886 case ETH_MIRROR_UPLINK_PORT:
7887 /* egress and ingress in aq commands means from switch but not port*/
7888 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_ALL_EGRESS;
7890 case ETH_MIRROR_DOWNLINK_PORT:
7891 mirr_rule->rule_type = I40E_AQC_MIRROR_RULE_TYPE_ALL_INGRESS;
7894 PMD_DRV_LOG(ERR, "unsupported mirror type %d.",
7895 mirror_conf->rule_type);
7896 rte_free(mirr_rule);
7900 /* If the dst_pool is equal to vf_num, consider it as PF */
7901 if (mirror_conf->dst_pool == pf->vf_num)
7902 dst_seid = pf->main_vsi_seid;
7904 dst_seid = pf->vfs[mirror_conf->dst_pool].vsi->seid;
7906 ret = i40e_aq_add_mirror_rule(hw, seid, dst_seid,
7907 mirr_rule->rule_type, mirr_rule->entries,
7910 PMD_DRV_LOG(ERR, "failed to add mirror rule:"
7911 " ret = %d, aq_err = %d.",
7912 ret, hw->aq.asq_last_status);
7913 rte_free(mirr_rule);
7917 mirr_rule->index = sw_id;
7918 mirr_rule->num_entries = j;
7919 mirr_rule->id = rule_id;
7920 mirr_rule->dst_vsi_seid = dst_seid;
7923 TAILQ_INSERT_AFTER(&pf->mirror_list, parent, mirr_rule, rules);
7925 TAILQ_INSERT_HEAD(&pf->mirror_list, mirr_rule, rules);
7927 pf->nb_mirror_rule++;
7932 * i40e_mirror_rule_reset
7933 * @dev: pointer to the device
7934 * @sw_id: mirror rule's sw_id
7936 * reset a mirror rule.
7940 i40e_mirror_rule_reset(struct rte_eth_dev *dev, uint8_t sw_id)
7942 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7943 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7944 struct i40e_mirror_rule *it, *mirr_rule = NULL;
7948 PMD_DRV_LOG(DEBUG, "i40e_mirror_rule_reset: sw_id = %d.", sw_id);
7950 seid = pf->main_vsi->veb->seid;
7952 TAILQ_FOREACH(it, &pf->mirror_list, rules) {
7953 if (sw_id == it->index) {
7959 ret = i40e_aq_del_mirror_rule(hw, seid,
7960 mirr_rule->rule_type,
7962 mirr_rule->num_entries, mirr_rule->id);
7964 PMD_DRV_LOG(ERR, "failed to remove mirror rule:"
7965 " status = %d, aq_err = %d.",
7966 ret, hw->aq.asq_last_status);
7969 TAILQ_REMOVE(&pf->mirror_list, mirr_rule, rules);
7970 rte_free(mirr_rule);
7971 pf->nb_mirror_rule--;
7973 PMD_DRV_LOG(ERR, "mirror rule doesn't exist.");
7980 i40e_read_systime_cyclecounter(struct rte_eth_dev *dev)
7982 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7983 uint64_t systim_cycles;
7985 systim_cycles = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_L);
7986 systim_cycles |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_H)
7989 return systim_cycles;
7993 i40e_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev, uint8_t index)
7995 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7998 rx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_L(index));
7999 rx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(index))
8006 i40e_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
8008 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8011 tx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_L);
8012 tx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H)
8019 i40e_start_timecounters(struct rte_eth_dev *dev)
8021 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8022 struct i40e_adapter *adapter =
8023 (struct i40e_adapter *)dev->data->dev_private;
8024 struct rte_eth_link link;
8025 uint32_t tsync_inc_l;
8026 uint32_t tsync_inc_h;
8028 /* Get current link speed. */
8029 memset(&link, 0, sizeof(link));
8030 i40e_dev_link_update(dev, 1);
8031 rte_i40e_dev_atomic_read_link_status(dev, &link);
8033 switch (link.link_speed) {
8034 case ETH_LINK_SPEED_40G:
8035 tsync_inc_l = I40E_PTP_40GB_INCVAL & 0xFFFFFFFF;
8036 tsync_inc_h = I40E_PTP_40GB_INCVAL >> 32;
8038 case ETH_LINK_SPEED_10G:
8039 tsync_inc_l = I40E_PTP_10GB_INCVAL & 0xFFFFFFFF;
8040 tsync_inc_h = I40E_PTP_10GB_INCVAL >> 32;
8042 case ETH_LINK_SPEED_1000:
8043 tsync_inc_l = I40E_PTP_1GB_INCVAL & 0xFFFFFFFF;
8044 tsync_inc_h = I40E_PTP_1GB_INCVAL >> 32;
8051 /* Set the timesync increment value. */
8052 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, tsync_inc_l);
8053 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, tsync_inc_h);
8055 memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
8056 memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
8057 memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
8059 adapter->systime_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
8060 adapter->systime_tc.cc_shift = 0;
8061 adapter->systime_tc.nsec_mask = 0;
8063 adapter->rx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
8064 adapter->rx_tstamp_tc.cc_shift = 0;
8065 adapter->rx_tstamp_tc.nsec_mask = 0;
8067 adapter->tx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
8068 adapter->tx_tstamp_tc.cc_shift = 0;
8069 adapter->tx_tstamp_tc.nsec_mask = 0;
8073 i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
8075 struct i40e_adapter *adapter =
8076 (struct i40e_adapter *)dev->data->dev_private;
8078 adapter->systime_tc.nsec += delta;
8079 adapter->rx_tstamp_tc.nsec += delta;
8080 adapter->tx_tstamp_tc.nsec += delta;
8086 i40e_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
8089 struct i40e_adapter *adapter =
8090 (struct i40e_adapter *)dev->data->dev_private;
8092 ns = rte_timespec_to_ns(ts);
8094 /* Set the timecounters to a new value. */
8095 adapter->systime_tc.nsec = ns;
8096 adapter->rx_tstamp_tc.nsec = ns;
8097 adapter->tx_tstamp_tc.nsec = ns;
8103 i40e_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
8105 uint64_t ns, systime_cycles;
8106 struct i40e_adapter *adapter =
8107 (struct i40e_adapter *)dev->data->dev_private;
8109 systime_cycles = i40e_read_systime_cyclecounter(dev);
8110 ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
8111 *ts = rte_ns_to_timespec(ns);
8117 i40e_timesync_enable(struct rte_eth_dev *dev)
8119 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8120 uint32_t tsync_ctl_l;
8121 uint32_t tsync_ctl_h;
8123 /* Stop the timesync system time. */
8124 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
8125 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
8126 /* Reset the timesync system time value. */
8127 I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_L, 0x0);
8128 I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_H, 0x0);
8130 i40e_start_timecounters(dev);
8132 /* Clear timesync registers. */
8133 I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
8134 I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H);
8135 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(0));
8136 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(1));
8137 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(2));
8138 I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(3));
8140 /* Enable timestamping of PTP packets. */
8141 tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
8142 tsync_ctl_l |= I40E_PRTTSYN_TSYNENA;
8144 tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
8145 tsync_ctl_h |= I40E_PRTTSYN_TSYNENA;
8146 tsync_ctl_h |= I40E_PRTTSYN_TSYNTYPE;
8148 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
8149 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
8155 i40e_timesync_disable(struct rte_eth_dev *dev)
8157 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8158 uint32_t tsync_ctl_l;
8159 uint32_t tsync_ctl_h;
8161 /* Disable timestamping of transmitted PTP packets. */
8162 tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
8163 tsync_ctl_l &= ~I40E_PRTTSYN_TSYNENA;
8165 tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
8166 tsync_ctl_h &= ~I40E_PRTTSYN_TSYNENA;
8168 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
8169 I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
8171 /* Reset the timesync increment value. */
8172 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
8173 I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
8179 i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
8180 struct timespec *timestamp, uint32_t flags)
8182 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8183 struct i40e_adapter *adapter =
8184 (struct i40e_adapter *)dev->data->dev_private;
8186 uint32_t sync_status;
8187 uint32_t index = flags & 0x03;
8188 uint64_t rx_tstamp_cycles;
8191 sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_1);
8192 if ((sync_status & (1 << index)) == 0)
8195 rx_tstamp_cycles = i40e_read_rx_tstamp_cyclecounter(dev, index);
8196 ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
8197 *timestamp = rte_ns_to_timespec(ns);
8203 i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
8204 struct timespec *timestamp)
8206 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8207 struct i40e_adapter *adapter =
8208 (struct i40e_adapter *)dev->data->dev_private;
8210 uint32_t sync_status;
8211 uint64_t tx_tstamp_cycles;
8214 sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
8215 if ((sync_status & I40E_PRTTSYN_STAT_0_TXTIME_MASK) == 0)
8218 tx_tstamp_cycles = i40e_read_tx_tstamp_cyclecounter(dev);
8219 ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
8220 *timestamp = rte_ns_to_timespec(ns);
8226 * i40e_parse_dcb_configure - parse dcb configure from user
8227 * @dev: the device being configured
8228 * @dcb_cfg: pointer of the result of parse
8229 * @*tc_map: bit map of enabled traffic classes
8231 * Returns 0 on success, negative value on failure
8234 i40e_parse_dcb_configure(struct rte_eth_dev *dev,
8235 struct i40e_dcbx_config *dcb_cfg,
8238 struct rte_eth_dcb_rx_conf *dcb_rx_conf;
8239 uint8_t i, tc_bw, bw_lf;
8241 memset(dcb_cfg, 0, sizeof(struct i40e_dcbx_config));
8243 dcb_rx_conf = &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
8244 if (dcb_rx_conf->nb_tcs > I40E_MAX_TRAFFIC_CLASS) {
8245 PMD_INIT_LOG(ERR, "number of tc exceeds max.");
8249 /* assume each tc has the same bw */
8250 tc_bw = I40E_MAX_PERCENT / dcb_rx_conf->nb_tcs;
8251 for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
8252 dcb_cfg->etscfg.tcbwtable[i] = tc_bw;
8253 /* to ensure the sum of tcbw is equal to 100 */
8254 bw_lf = I40E_MAX_PERCENT % dcb_rx_conf->nb_tcs;
8255 for (i = 0; i < bw_lf; i++)
8256 dcb_cfg->etscfg.tcbwtable[i]++;
8258 /* assume each tc has the same Transmission Selection Algorithm */
8259 for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
8260 dcb_cfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
8262 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
8263 dcb_cfg->etscfg.prioritytable[i] =
8264 dcb_rx_conf->dcb_tc[i];
8266 /* FW needs one App to configure HW */
8267 dcb_cfg->numapps = I40E_DEFAULT_DCB_APP_NUM;
8268 dcb_cfg->app[0].selector = I40E_APP_SEL_ETHTYPE;
8269 dcb_cfg->app[0].priority = I40E_DEFAULT_DCB_APP_PRIO;
8270 dcb_cfg->app[0].protocolid = I40E_APP_PROTOID_FCOE;
8272 if (dcb_rx_conf->nb_tcs == 0)
8273 *tc_map = 1; /* tc0 only */
8275 *tc_map = RTE_LEN2MASK(dcb_rx_conf->nb_tcs, uint8_t);
8277 if (dev->data->dev_conf.dcb_capability_en & ETH_DCB_PFC_SUPPORT) {
8278 dcb_cfg->pfc.willing = 0;
8279 dcb_cfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
8280 dcb_cfg->pfc.pfcenable = *tc_map;
8286 static enum i40e_status_code
8287 i40e_vsi_update_queue_mapping(struct i40e_vsi *vsi,
8288 struct i40e_aqc_vsi_properties_data *info,
8289 uint8_t enabled_tcmap)
8291 enum i40e_status_code ret;
8292 int i, total_tc = 0;
8293 uint16_t qpnum_per_tc, bsf, qp_idx;
8294 struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(vsi);
8296 ret = validate_tcmap_parameter(vsi, enabled_tcmap);
8297 if (ret != I40E_SUCCESS)
8300 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
8301 if (enabled_tcmap & (1 << i))
8306 vsi->enabled_tc = enabled_tcmap;
8308 qpnum_per_tc = dev_data->nb_rx_queues / total_tc;
8309 /* Number of queues per enabled TC */
8310 if (qpnum_per_tc == 0) {
8311 PMD_INIT_LOG(ERR, " number of queues is less that tcs.");
8312 return I40E_ERR_INVALID_QP_ID;
8314 qpnum_per_tc = RTE_MIN(i40e_align_floor(qpnum_per_tc),
8316 bsf = rte_bsf32(qpnum_per_tc);
8319 * Configure TC and queue mapping parameters, for enabled TC,
8320 * allocate qpnum_per_tc queues to this traffic. For disabled TC,
8321 * default queue will serve it.
8324 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
8325 if (vsi->enabled_tc & (1 << i)) {
8326 info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
8327 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
8328 (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
8329 qp_idx += qpnum_per_tc;
8331 info->tc_mapping[i] = 0;
8334 /* Associate queue number with VSI, Keep vsi->nb_qps unchanged */
8335 if (vsi->type == I40E_VSI_SRIOV) {
8336 info->mapping_flags |=
8337 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
8338 for (i = 0; i < vsi->nb_qps; i++)
8339 info->queue_mapping[i] =
8340 rte_cpu_to_le_16(vsi->base_queue + i);
8342 info->mapping_flags |=
8343 rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
8344 info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
8346 info->valid_sections |=
8347 rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
8349 return I40E_SUCCESS;
8353 * i40e_vsi_config_tc - Configure VSI tc setting for given TC map
8354 * @vsi: VSI to be configured
8355 * @tc_map: enabled TC bitmap
8357 * Returns 0 on success, negative value on failure
8359 static enum i40e_status_code
8360 i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 tc_map)
8362 struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
8363 struct i40e_vsi_context ctxt;
8364 struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
8365 enum i40e_status_code ret = I40E_SUCCESS;
8368 /* Check if enabled_tc is same as existing or new TCs */
8369 if (vsi->enabled_tc == tc_map)
8372 /* configure tc bandwidth */
8373 memset(&bw_data, 0, sizeof(bw_data));
8374 bw_data.tc_valid_bits = tc_map;
8375 /* Enable ETS TCs with equal BW Share for now across all VSIs */
8376 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
8377 if (tc_map & BIT_ULL(i))
8378 bw_data.tc_bw_credits[i] = 1;
8380 ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &bw_data, NULL);
8382 PMD_INIT_LOG(ERR, "AQ command Config VSI BW allocation"
8383 " per TC failed = %d",
8384 hw->aq.asq_last_status);
8387 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
8388 vsi->info.qs_handle[i] = bw_data.qs_handles[i];
8390 /* Update Queue Pairs Mapping for currently enabled UPs */
8391 ctxt.seid = vsi->seid;
8392 ctxt.pf_num = hw->pf_id;
8394 ctxt.uplink_seid = vsi->uplink_seid;
8395 ctxt.info = vsi->info;
8397 ret = i40e_vsi_update_queue_mapping(vsi, &ctxt.info, tc_map);
8401 /* Update the VSI after updating the VSI queue-mapping information */
8402 ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
8404 PMD_INIT_LOG(ERR, "Failed to configure "
8405 "TC queue mapping = %d",
8406 hw->aq.asq_last_status);
8409 /* update the local VSI info with updated queue map */
8410 (void)rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
8411 sizeof(vsi->info.tc_mapping));
8412 (void)rte_memcpy(&vsi->info.queue_mapping,
8413 &ctxt.info.queue_mapping,
8414 sizeof(vsi->info.queue_mapping));
8415 vsi->info.mapping_flags = ctxt.info.mapping_flags;
8416 vsi->info.valid_sections = 0;
8418 /* query and update current VSI BW information */
8419 ret = i40e_vsi_get_bw_config(vsi);
8422 "Failed updating vsi bw info, err %s aq_err %s",
8423 i40e_stat_str(hw, ret),
8424 i40e_aq_str(hw, hw->aq.asq_last_status));
8428 vsi->enabled_tc = tc_map;
8435 * i40e_dcb_hw_configure - program the dcb setting to hw
8436 * @pf: pf the configuration is taken on
8437 * @new_cfg: new configuration
8438 * @tc_map: enabled TC bitmap
8440 * Returns 0 on success, negative value on failure
8442 static enum i40e_status_code
8443 i40e_dcb_hw_configure(struct i40e_pf *pf,
8444 struct i40e_dcbx_config *new_cfg,
8447 struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8448 struct i40e_dcbx_config *old_cfg = &hw->local_dcbx_config;
8449 struct i40e_vsi *main_vsi = pf->main_vsi;
8450 struct i40e_vsi_list *vsi_list;
8451 enum i40e_status_code ret;
8455 /* Use the FW API if FW > v4.4*/
8456 if (!(((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver >= 4)) ||
8457 (hw->aq.fw_maj_ver >= 5))) {
8458 PMD_INIT_LOG(ERR, "FW < v4.4, can not use FW LLDP API"
8459 " to configure DCB");
8460 return I40E_ERR_FIRMWARE_API_VERSION;
8463 /* Check if need reconfiguration */
8464 if (!memcmp(new_cfg, old_cfg, sizeof(struct i40e_dcbx_config))) {
8465 PMD_INIT_LOG(ERR, "No Change in DCB Config required.");
8466 return I40E_SUCCESS;
8469 /* Copy the new config to the current config */
8470 *old_cfg = *new_cfg;
8471 old_cfg->etsrec = old_cfg->etscfg;
8472 ret = i40e_set_dcb_config(hw);
8475 "Set DCB Config failed, err %s aq_err %s\n",
8476 i40e_stat_str(hw, ret),
8477 i40e_aq_str(hw, hw->aq.asq_last_status));
8480 /* set receive Arbiter to RR mode and ETS scheme by default */
8481 for (i = 0; i <= I40E_PRTDCB_RETSTCC_MAX_INDEX; i++) {
8482 val = I40E_READ_REG(hw, I40E_PRTDCB_RETSTCC(i));
8483 val &= ~(I40E_PRTDCB_RETSTCC_BWSHARE_MASK |
8484 I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK |
8485 I40E_PRTDCB_RETSTCC_ETSTC_SHIFT);
8486 val |= ((uint32_t)old_cfg->etscfg.tcbwtable[i] <<
8487 I40E_PRTDCB_RETSTCC_BWSHARE_SHIFT) &
8488 I40E_PRTDCB_RETSTCC_BWSHARE_MASK;
8489 val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_UPINTC_MODE_SHIFT) &
8490 I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK;
8491 val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_ETSTC_SHIFT) &
8492 I40E_PRTDCB_RETSTCC_ETSTC_MASK;
8493 I40E_WRITE_REG(hw, I40E_PRTDCB_RETSTCC(i), val);
8495 /* get local mib to check whether it is configured correctly */
8497 hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_IEEE;
8498 /* Get Local DCB Config */
8499 i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
8500 &hw->local_dcbx_config);
8502 /* Update each VSI */
8503 i40e_vsi_config_tc(main_vsi, tc_map);
8504 if (main_vsi->veb) {
8505 TAILQ_FOREACH(vsi_list, &main_vsi->veb->head, list) {
8506 /* Beside main VSI, only enable default
8509 ret = i40e_vsi_config_tc(vsi_list->vsi,
8510 I40E_DEFAULT_TCMAP);
8512 PMD_INIT_LOG(WARNING,
8513 "Failed configuring TC for VSI seid=%d\n",
8514 vsi_list->vsi->seid);
8518 return I40E_SUCCESS;
8522 * i40e_dcb_init_configure - initial dcb config
8523 * @dev: device being configured
8524 * @sw_dcb: indicate whether dcb is sw configured or hw offload
8526 * Returns 0 on success, negative value on failure
8529 i40e_dcb_init_configure(struct rte_eth_dev *dev, bool sw_dcb)
8531 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8532 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8535 if ((pf->flags & I40E_FLAG_DCB) == 0) {
8536 PMD_INIT_LOG(ERR, "HW doesn't support DCB");
8540 /* DCB initialization:
8541 * Update DCB configuration from the Firmware and configure
8542 * LLDP MIB change event.
8544 if (sw_dcb == TRUE) {
8545 ret = i40e_aq_stop_lldp(hw, TRUE, NULL);
8546 if (ret != I40E_SUCCESS)
8547 PMD_INIT_LOG(DEBUG, "Failed to stop lldp");
8549 ret = i40e_init_dcb(hw);
8550 /* if sw_dcb, lldp agent is stopped, the return from
8551 * i40e_init_dcb we expect is failure with I40E_AQ_RC_EPERM
8554 if (ret != I40E_SUCCESS &&
8555 hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
8556 memset(&hw->local_dcbx_config, 0,
8557 sizeof(struct i40e_dcbx_config));
8558 /* set dcb default configuration */
8559 hw->local_dcbx_config.etscfg.willing = 0;
8560 hw->local_dcbx_config.etscfg.maxtcs = 0;
8561 hw->local_dcbx_config.etscfg.tcbwtable[0] = 100;
8562 hw->local_dcbx_config.etscfg.tsatable[0] =
8564 hw->local_dcbx_config.etsrec =
8565 hw->local_dcbx_config.etscfg;
8566 hw->local_dcbx_config.pfc.willing = 0;
8567 hw->local_dcbx_config.pfc.pfccap =
8568 I40E_MAX_TRAFFIC_CLASS;
8569 /* FW needs one App to configure HW */
8570 hw->local_dcbx_config.numapps = 1;
8571 hw->local_dcbx_config.app[0].selector =
8572 I40E_APP_SEL_ETHTYPE;
8573 hw->local_dcbx_config.app[0].priority = 3;
8574 hw->local_dcbx_config.app[0].protocolid =
8575 I40E_APP_PROTOID_FCOE;
8576 ret = i40e_set_dcb_config(hw);
8578 PMD_INIT_LOG(ERR, "default dcb config fails."
8579 " err = %d, aq_err = %d.", ret,
8580 hw->aq.asq_last_status);
8584 PMD_INIT_LOG(ERR, "DCBX configuration failed, err = %d,"
8585 " aq_err = %d.", ret,
8586 hw->aq.asq_last_status);
8590 ret = i40e_aq_start_lldp(hw, NULL);
8591 if (ret != I40E_SUCCESS)
8592 PMD_INIT_LOG(DEBUG, "Failed to start lldp");
8594 ret = i40e_init_dcb(hw);
8596 if (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED) {
8597 PMD_INIT_LOG(ERR, "HW doesn't support"
8602 PMD_INIT_LOG(ERR, "DCBX configuration failed, err = %d,"
8603 " aq_err = %d.", ret,
8604 hw->aq.asq_last_status);
8612 * i40e_dcb_setup - setup dcb related config
8613 * @dev: device being configured
8615 * Returns 0 on success, negative value on failure
8618 i40e_dcb_setup(struct rte_eth_dev *dev)
8620 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8621 struct i40e_dcbx_config dcb_cfg;
8625 if ((pf->flags & I40E_FLAG_DCB) == 0) {
8626 PMD_INIT_LOG(ERR, "HW doesn't support DCB");
8630 if (pf->vf_num != 0 ||
8631 (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_VMDQ_FLAG))
8632 PMD_INIT_LOG(DEBUG, " DCB only works on main vsi.");
8634 ret = i40e_parse_dcb_configure(dev, &dcb_cfg, &tc_map);
8636 PMD_INIT_LOG(ERR, "invalid dcb config");
8639 ret = i40e_dcb_hw_configure(pf, &dcb_cfg, tc_map);
8641 PMD_INIT_LOG(ERR, "dcb sw configure fails");
8649 i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
8650 struct rte_eth_dcb_info *dcb_info)
8652 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8653 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8654 struct i40e_vsi *vsi = pf->main_vsi;
8655 struct i40e_dcbx_config *dcb_cfg = &hw->local_dcbx_config;
8656 uint16_t bsf, tc_mapping;
8659 if (dev->data->dev_conf.rxmode.mq_mode & ETH_MQ_RX_DCB_FLAG)
8660 dcb_info->nb_tcs = rte_bsf32(vsi->enabled_tc + 1);
8662 dcb_info->nb_tcs = 1;
8663 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
8664 dcb_info->prio_tc[i] = dcb_cfg->etscfg.prioritytable[i];
8665 for (i = 0; i < dcb_info->nb_tcs; i++)
8666 dcb_info->tc_bws[i] = dcb_cfg->etscfg.tcbwtable[i];
8668 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
8669 if (vsi->enabled_tc & (1 << i)) {
8670 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
8671 /* only main vsi support multi TCs */
8672 dcb_info->tc_queue.tc_rxq[0][i].base =
8673 (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
8674 I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
8675 dcb_info->tc_queue.tc_txq[0][i].base =
8676 dcb_info->tc_queue.tc_rxq[0][i].base;
8677 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
8678 I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
8679 dcb_info->tc_queue.tc_rxq[0][i].nb_queue = 1 << bsf;
8680 dcb_info->tc_queue.tc_txq[0][i].nb_queue =
8681 dcb_info->tc_queue.tc_rxq[0][i].nb_queue;
8689 i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
8691 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
8692 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8694 i40e_calc_itr_interval(RTE_LIBRTE_I40E_ITR_INTERVAL);
8697 msix_intr = intr_handle->intr_vec[queue_id];
8698 if (msix_intr == I40E_MISC_VEC_ID)
8699 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
8700 I40E_PFINT_DYN_CTLN_INTENA_MASK |
8701 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
8702 (0 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT) |
8704 I40E_PFINT_DYN_CTLN_INTERVAL_SHIFT));
8707 I40E_PFINT_DYN_CTLN(msix_intr -
8709 I40E_PFINT_DYN_CTLN_INTENA_MASK |
8710 I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
8711 (0 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT) |
8713 I40E_PFINT_DYN_CTLN_INTERVAL_SHIFT));
8715 I40E_WRITE_FLUSH(hw);
8716 rte_intr_enable(&dev->pci_dev->intr_handle);
8722 i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
8724 struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle;
8725 struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
8728 msix_intr = intr_handle->intr_vec[queue_id];
8729 if (msix_intr == I40E_MISC_VEC_ID)
8730 I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0, 0);
8733 I40E_PFINT_DYN_CTLN(msix_intr -
8736 I40E_WRITE_FLUSH(hw);