Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2017 Intel Corporation
3 : : */
4 : :
5 : : #include <ctype.h>
6 : : #include <stdio.h>
7 : : #include <errno.h>
8 : : #include <stdint.h>
9 : : #include <stdlib.h>
10 : : #include <string.h>
11 : : #include <unistd.h>
12 : : #include <stdarg.h>
13 : : #include <inttypes.h>
14 : : #include <assert.h>
15 : :
16 : : #include <rte_common.h>
17 : : #include <rte_eal.h>
18 : : #include <rte_string_fns.h>
19 : : #include <rte_pci.h>
20 : : #include <bus_pci_driver.h>
21 : : #include <rte_ether.h>
22 : : #include <ethdev_driver.h>
23 : : #include <ethdev_pci.h>
24 : : #include <rte_memzone.h>
25 : : #include <rte_malloc.h>
26 : : #include <rte_memcpy.h>
27 : : #include <rte_alarm.h>
28 : : #include <dev_driver.h>
29 : : #include <rte_tailq.h>
30 : : #include <rte_hash_crc.h>
31 : : #include <rte_bitmap.h>
32 : : #include <rte_os_shim.h>
33 : :
34 : : #include "i40e_logs.h"
35 : : #include "base/i40e_prototype.h"
36 : : #include "base/i40e_adminq_cmd.h"
37 : : #include "base/i40e_type.h"
38 : : #include "base/i40e_register.h"
39 : : #include "base/i40e_dcb.h"
40 : : #include "i40e_ethdev.h"
41 : : #include "i40e_rxtx.h"
42 : : #include "i40e_pf.h"
43 : : #include "i40e_regs.h"
44 : : #include "rte_pmd_i40e.h"
45 : : #include "i40e_hash.h"
46 : :
47 : : #define ETH_I40E_FLOATING_VEB_ARG "enable_floating_veb"
48 : : #define ETH_I40E_FLOATING_VEB_LIST_ARG "floating_veb_list"
49 : : #define ETH_I40E_SUPPORT_MULTI_DRIVER "support-multi-driver"
50 : : #define ETH_I40E_QUEUE_NUM_PER_VF_ARG "queue-num-per-vf"
51 : : #define ETH_I40E_VF_MSG_CFG "vf_msg_cfg"
52 : : #define ETH_I40E_MBUF_CHECK_ARG "mbuf_check"
53 : :
54 : : #define I40E_CLEAR_PXE_WAIT_MS 200
55 : : #define I40E_VSI_TSR_QINQ_STRIP 0x4010
56 : : #define I40E_VSI_TSR(_i) (0x00050800 + ((_i) * 4))
57 : :
58 : : /* Maximun number of capability elements */
59 : : #define I40E_MAX_CAP_ELE_NUM 128
60 : :
61 : : /* Wait count and interval */
62 : : #define I40E_CHK_Q_ENA_COUNT 1000
63 : : #define I40E_CHK_Q_ENA_INTERVAL_US 1000
64 : :
65 : : /* Maximun number of VSI */
66 : : #define I40E_MAX_NUM_VSIS (384UL)
67 : :
68 : : #define I40E_PRE_TX_Q_CFG_WAIT_US 10 /* 10 us */
69 : :
70 : : /* Flow control default timer */
71 : : #define I40E_DEFAULT_PAUSE_TIME 0xFFFFU
72 : :
73 : : /* Flow control enable fwd bit */
74 : : #define I40E_PRTMAC_FWD_CTRL 0x00000001
75 : :
76 : : /* Receive Packet Buffer size */
77 : : #define I40E_RXPBSIZE (968 * 1024)
78 : :
79 : : /* Kilobytes shift */
80 : : #define I40E_KILOSHIFT 10
81 : :
82 : : /* Flow control default high water */
83 : : #define I40E_DEFAULT_HIGH_WATER (0xF2000 >> I40E_KILOSHIFT)
84 : :
85 : : /* Flow control default low water */
86 : : #define I40E_DEFAULT_LOW_WATER (0xF2000 >> I40E_KILOSHIFT)
87 : :
88 : : /* Receive Average Packet Size in Byte*/
89 : : #define I40E_PACKET_AVERAGE_SIZE 128
90 : :
91 : : /* Mask of PF interrupt causes */
92 : : #define I40E_PFINT_ICR0_ENA_MASK ( \
93 : : I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | \
94 : : I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | \
95 : : I40E_PFINT_ICR0_ENA_GRST_MASK | \
96 : : I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | \
97 : : I40E_PFINT_ICR0_ENA_STORM_DETECT_MASK | \
98 : : I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | \
99 : : I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK | \
100 : : I40E_PFINT_ICR0_ENA_VFLR_MASK | \
101 : : I40E_PFINT_ICR0_ENA_ADMINQ_MASK)
102 : :
103 : : #define I40E_FLOW_TYPES ( \
104 : : (1UL << RTE_ETH_FLOW_FRAG_IPV4) | \
105 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_TCP) | \
106 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_UDP) | \
107 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_SCTP) | \
108 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_OTHER) | \
109 : : (1UL << RTE_ETH_FLOW_FRAG_IPV6) | \
110 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_TCP) | \
111 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_UDP) | \
112 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_SCTP) | \
113 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_OTHER) | \
114 : : (1UL << RTE_ETH_FLOW_L2_PAYLOAD))
115 : :
116 : : /* Additional timesync values. */
117 : : #define I40E_PTP_40GB_INCVAL 0x0199999999ULL
118 : : #define I40E_PTP_10GB_INCVAL 0x0333333333ULL
119 : : #define I40E_PTP_1GB_INCVAL 0x2000000000ULL
120 : : #define I40E_PRTTSYN_TSYNENA 0x80000000
121 : : #define I40E_PRTTSYN_TSYNTYPE 0x0e000000
122 : : #define I40E_CYCLECOUNTER_MASK 0xffffffffffffffffULL
123 : :
124 : : /**
125 : : * Below are values for writing un-exposed registers suggested
126 : : * by silicon experts
127 : : */
128 : : /* Destination MAC address */
129 : : #define I40E_REG_INSET_L2_DMAC 0xE000000000000000ULL
130 : : /* Source MAC address */
131 : : #define I40E_REG_INSET_L2_SMAC 0x1C00000000000000ULL
132 : : /* Outer (S-Tag) VLAN tag in the outer L2 header */
133 : : #define I40E_REG_INSET_L2_OUTER_VLAN 0x0000000004000000ULL
134 : : /* Inner (C-Tag) or single VLAN tag in the outer L2 header */
135 : : #define I40E_REG_INSET_L2_INNER_VLAN 0x0080000000000000ULL
136 : : /* Single VLAN tag in the inner L2 header */
137 : : #define I40E_REG_INSET_TUNNEL_VLAN 0x0100000000000000ULL
138 : : /* Source IPv4 address */
139 : : #define I40E_REG_INSET_L3_SRC_IP4 0x0001800000000000ULL
140 : : /* Destination IPv4 address */
141 : : #define I40E_REG_INSET_L3_DST_IP4 0x0000001800000000ULL
142 : : /* Source IPv4 address for X722 */
143 : : #define I40E_X722_REG_INSET_L3_SRC_IP4 0x0006000000000000ULL
144 : : /* Destination IPv4 address for X722 */
145 : : #define I40E_X722_REG_INSET_L3_DST_IP4 0x0000060000000000ULL
146 : : /* IPv4 Protocol for X722 */
147 : : #define I40E_X722_REG_INSET_L3_IP4_PROTO 0x0010000000000000ULL
148 : : /* IPv4 Time to Live for X722 */
149 : : #define I40E_X722_REG_INSET_L3_IP4_TTL 0x0010000000000000ULL
150 : : /* IPv4 Type of Service (TOS) */
151 : : #define I40E_REG_INSET_L3_IP4_TOS 0x0040000000000000ULL
152 : : /* IPv4 Protocol */
153 : : #define I40E_REG_INSET_L3_IP4_PROTO 0x0004000000000000ULL
154 : : /* IPv4 Time to Live */
155 : : #define I40E_REG_INSET_L3_IP4_TTL 0x0004000000000000ULL
156 : : /* Source IPv6 address */
157 : : #define I40E_REG_INSET_L3_SRC_IP6 0x0007F80000000000ULL
158 : : /* Destination IPv6 address */
159 : : #define I40E_REG_INSET_L3_DST_IP6 0x000007F800000000ULL
160 : : /* IPv6 Traffic Class (TC) */
161 : : #define I40E_REG_INSET_L3_IP6_TC 0x0040000000000000ULL
162 : : /* IPv6 Next Header */
163 : : #define I40E_REG_INSET_L3_IP6_NEXT_HDR 0x0008000000000000ULL
164 : : /* IPv6 Hop Limit */
165 : : #define I40E_REG_INSET_L3_IP6_HOP_LIMIT 0x0008000000000000ULL
166 : : /* Source L4 port */
167 : : #define I40E_REG_INSET_L4_SRC_PORT 0x0000000400000000ULL
168 : : /* Destination L4 port */
169 : : #define I40E_REG_INSET_L4_DST_PORT 0x0000000200000000ULL
170 : : /* SCTP verification tag */
171 : : #define I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG 0x0000000180000000ULL
172 : : /* Inner destination MAC address (MAC-in-UDP/MAC-in-GRE)*/
173 : : #define I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC 0x0000000001C00000ULL
174 : : /* Source port of tunneling UDP */
175 : : #define I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT 0x0000000000200000ULL
176 : : /* Destination port of tunneling UDP */
177 : : #define I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT 0x0000000000100000ULL
178 : : /* UDP Tunneling ID, NVGRE/GRE key */
179 : : #define I40E_REG_INSET_TUNNEL_ID 0x00000000000C0000ULL
180 : : /* Last ether type */
181 : : #define I40E_REG_INSET_LAST_ETHER_TYPE 0x0000000000004000ULL
182 : : /* Tunneling outer destination IPv4 address */
183 : : #define I40E_REG_INSET_TUNNEL_L3_DST_IP4 0x00000000000000C0ULL
184 : : /* Tunneling outer destination IPv6 address */
185 : : #define I40E_REG_INSET_TUNNEL_L3_DST_IP6 0x0000000000003FC0ULL
186 : : /* 1st word of flex payload */
187 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD1 0x0000000000002000ULL
188 : : /* 2nd word of flex payload */
189 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD2 0x0000000000001000ULL
190 : : /* 3rd word of flex payload */
191 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD3 0x0000000000000800ULL
192 : : /* 4th word of flex payload */
193 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD4 0x0000000000000400ULL
194 : : /* 5th word of flex payload */
195 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD5 0x0000000000000200ULL
196 : : /* 6th word of flex payload */
197 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD6 0x0000000000000100ULL
198 : : /* 7th word of flex payload */
199 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD7 0x0000000000000080ULL
200 : : /* 8th word of flex payload */
201 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD8 0x0000000000000040ULL
202 : : /* all 8 words flex payload */
203 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORDS 0x0000000000003FC0ULL
204 : : #define I40E_REG_INSET_MASK_DEFAULT 0x0000000000000000ULL
205 : :
206 : : #define I40E_TRANSLATE_INSET 0
207 : : #define I40E_TRANSLATE_REG 1
208 : :
209 : : #define I40E_INSET_IPV4_TOS_MASK 0x0000FF00UL
210 : : #define I40E_INSET_IPV4_TTL_MASK 0x000000FFUL
211 : : #define I40E_INSET_IPV4_PROTO_MASK 0x0000FF00UL
212 : : #define I40E_INSET_IPV6_TC_MASK 0x0000F00FUL
213 : : #define I40E_INSET_IPV6_HOP_LIMIT_MASK 0x0000FF00UL
214 : : #define I40E_INSET_IPV6_NEXT_HDR_MASK 0x000000FFUL
215 : :
216 : : /* PCI offset for querying capability */
217 : : #define PCI_DEV_CAP_REG 0xA4
218 : : /* PCI offset for enabling/disabling Extended Tag */
219 : : #define PCI_DEV_CTRL_REG 0xA8
220 : : /* Bit mask of Extended Tag capability */
221 : : #define PCI_DEV_CAP_EXT_TAG_MASK 0x20
222 : : /* Bit shift of Extended Tag enable/disable */
223 : : #define PCI_DEV_CTRL_EXT_TAG_SHIFT 8
224 : : /* Bit mask of Extended Tag enable/disable */
225 : : #define PCI_DEV_CTRL_EXT_TAG_MASK (1 << PCI_DEV_CTRL_EXT_TAG_SHIFT)
226 : :
227 : : #define I40E_GLQF_PIT_IPV4_START 2
228 : : #define I40E_GLQF_PIT_IPV4_COUNT 2
229 : : #define I40E_GLQF_PIT_IPV6_START 4
230 : : #define I40E_GLQF_PIT_IPV6_COUNT 2
231 : :
232 : : #define I40E_GLQF_PIT_SOURCE_OFF_GET(a) \
233 : : (((a) & I40E_GLQF_PIT_SOURCE_OFF_MASK) >> \
234 : : I40E_GLQF_PIT_SOURCE_OFF_SHIFT)
235 : :
236 : : #define I40E_GLQF_PIT_DEST_OFF_GET(a) \
237 : : (((a) & I40E_GLQF_PIT_DEST_OFF_MASK) >> \
238 : : I40E_GLQF_PIT_DEST_OFF_SHIFT)
239 : :
240 : : #define I40E_GLQF_PIT_FSIZE_GET(a) (((a) & I40E_GLQF_PIT_FSIZE_MASK) >> \
241 : : I40E_GLQF_PIT_FSIZE_SHIFT)
242 : :
243 : : #define I40E_GLQF_PIT_BUILD(off, mask) (((off) << 16) | (mask))
244 : : #define I40E_FDIR_FIELD_OFFSET(a) ((a) >> 1)
245 : :
246 : : static int eth_i40e_dev_init(struct rte_eth_dev *eth_dev, void *init_params);
247 : : static int eth_i40e_dev_uninit(struct rte_eth_dev *eth_dev);
248 : : static int i40e_dev_configure(struct rte_eth_dev *dev);
249 : : static int i40e_dev_start(struct rte_eth_dev *dev);
250 : : static int i40e_dev_stop(struct rte_eth_dev *dev);
251 : : static int i40e_dev_close(struct rte_eth_dev *dev);
252 : : static int i40e_dev_reset(struct rte_eth_dev *dev);
253 : : static int i40e_dev_promiscuous_enable(struct rte_eth_dev *dev);
254 : : static int i40e_dev_promiscuous_disable(struct rte_eth_dev *dev);
255 : : static int i40e_dev_allmulticast_enable(struct rte_eth_dev *dev);
256 : : static int i40e_dev_allmulticast_disable(struct rte_eth_dev *dev);
257 : : static int i40e_dev_set_link_up(struct rte_eth_dev *dev);
258 : : static int i40e_dev_set_link_down(struct rte_eth_dev *dev);
259 : : static int i40e_dev_stats_get(struct rte_eth_dev *dev,
260 : : struct rte_eth_stats *stats, struct eth_queue_stats *qstats);
261 : : static int i40e_dev_xstats_get(struct rte_eth_dev *dev,
262 : : struct rte_eth_xstat *xstats, unsigned n);
263 : : static int i40e_dev_xstats_get_names(struct rte_eth_dev *dev,
264 : : struct rte_eth_xstat_name *xstats_names,
265 : : unsigned limit);
266 : : static int i40e_dev_stats_reset(struct rte_eth_dev *dev);
267 : : static int i40e_fw_version_get(struct rte_eth_dev *dev,
268 : : char *fw_version, size_t fw_size);
269 : : static int i40e_dev_info_get(struct rte_eth_dev *dev,
270 : : struct rte_eth_dev_info *dev_info);
271 : : static int i40e_vlan_filter_set(struct rte_eth_dev *dev,
272 : : uint16_t vlan_id,
273 : : int on);
274 : : static int i40e_vlan_tpid_set(struct rte_eth_dev *dev,
275 : : enum rte_vlan_type vlan_type,
276 : : uint16_t tpid);
277 : : static int i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask);
278 : : static void i40e_vlan_strip_queue_set(struct rte_eth_dev *dev,
279 : : uint16_t queue,
280 : : int on);
281 : : static int i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on);
282 : : static int i40e_dev_led_on(struct rte_eth_dev *dev);
283 : : static int i40e_dev_led_off(struct rte_eth_dev *dev);
284 : : static int i40e_flow_ctrl_get(struct rte_eth_dev *dev,
285 : : struct rte_eth_fc_conf *fc_conf);
286 : : static int i40e_flow_ctrl_set(struct rte_eth_dev *dev,
287 : : struct rte_eth_fc_conf *fc_conf);
288 : : static int i40e_priority_flow_ctrl_set(struct rte_eth_dev *dev,
289 : : struct rte_eth_pfc_conf *pfc_conf);
290 : : static int i40e_macaddr_add(struct rte_eth_dev *dev,
291 : : struct rte_ether_addr *mac_addr,
292 : : uint32_t index,
293 : : uint32_t pool);
294 : : static void i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index);
295 : : static int i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
296 : : struct rte_eth_rss_reta_entry64 *reta_conf,
297 : : uint16_t reta_size);
298 : : static int i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
299 : : struct rte_eth_rss_reta_entry64 *reta_conf,
300 : : uint16_t reta_size);
301 : :
302 : : static int i40e_get_cap(struct i40e_hw *hw);
303 : : static int i40e_pf_parameter_init(struct rte_eth_dev *dev);
304 : : static int i40e_pf_setup(struct i40e_pf *pf);
305 : : static int i40e_dev_rxtx_init(struct i40e_pf *pf);
306 : : static int i40e_vmdq_setup(struct rte_eth_dev *dev);
307 : : static int i40e_dcb_setup(struct rte_eth_dev *dev);
308 : : static void i40e_stat_update_32(struct i40e_hw *hw, uint32_t reg,
309 : : bool offset_loaded, uint64_t *offset, uint64_t *stat);
310 : : static void i40e_stat_update_48(struct i40e_hw *hw,
311 : : uint32_t hireg,
312 : : uint32_t loreg,
313 : : bool offset_loaded,
314 : : uint64_t *offset,
315 : : uint64_t *stat);
316 : : static void i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue);
317 : : static void i40e_dev_interrupt_handler(void *param);
318 : : static void i40e_dev_alarm_handler(void *param);
319 : : static int i40e_res_pool_init(struct i40e_res_pool_info *pool,
320 : : uint32_t base, uint32_t num);
321 : : static void i40e_res_pool_destroy(struct i40e_res_pool_info *pool);
322 : : static int i40e_res_pool_free(struct i40e_res_pool_info *pool,
323 : : uint32_t base);
324 : : static int i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
325 : : uint16_t num);
326 : : static int i40e_dev_init_vlan(struct rte_eth_dev *dev);
327 : : static int i40e_veb_release(struct i40e_veb *veb);
328 : : static struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf,
329 : : struct i40e_vsi *vsi);
330 : : static int i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on);
331 : : static inline int i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
332 : : struct i40e_macvlan_filter *mv_f,
333 : : int num,
334 : : uint16_t vlan);
335 : : static int i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi);
336 : : static int i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
337 : : struct rte_eth_rss_conf *rss_conf);
338 : : static int i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
339 : : struct rte_eth_rss_conf *rss_conf);
340 : : static int i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
341 : : struct rte_eth_udp_tunnel *udp_tunnel);
342 : : static int i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
343 : : struct rte_eth_udp_tunnel *udp_tunnel);
344 : : static void i40e_filter_input_set_init(struct i40e_pf *pf);
345 : : static int i40e_dev_flow_ops_get(struct rte_eth_dev *dev,
346 : : const struct rte_flow_ops **ops);
347 : : static int i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
348 : : struct rte_eth_dcb_info *dcb_info);
349 : : static int i40e_dev_sync_phy_type(struct i40e_hw *hw);
350 : : static void i40e_configure_registers(struct i40e_hw *hw);
351 : : static void i40e_hw_init(struct rte_eth_dev *dev);
352 : : static int i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi);
353 : :
354 : : static int i40e_timesync_enable(struct rte_eth_dev *dev);
355 : : static int i40e_timesync_disable(struct rte_eth_dev *dev);
356 : : static int i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
357 : : struct timespec *timestamp,
358 : : uint32_t flags);
359 : : static int i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
360 : : struct timespec *timestamp);
361 : : static void i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw);
362 : :
363 : : static int i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
364 : :
365 : : static int i40e_timesync_read_time(struct rte_eth_dev *dev,
366 : : struct timespec *timestamp);
367 : : static int i40e_timesync_write_time(struct rte_eth_dev *dev,
368 : : const struct timespec *timestamp);
369 : :
370 : : static int i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
371 : : uint16_t queue_id);
372 : : static int i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
373 : : uint16_t queue_id);
374 : :
375 : : static int i40e_get_regs(struct rte_eth_dev *dev,
376 : : struct rte_dev_reg_info *regs);
377 : :
378 : : static int i40e_get_eeprom_length(struct rte_eth_dev *dev);
379 : :
380 : : static int i40e_get_eeprom(struct rte_eth_dev *dev,
381 : : struct rte_dev_eeprom_info *eeprom);
382 : :
383 : : static int i40e_get_module_info(struct rte_eth_dev *dev,
384 : : struct rte_eth_dev_module_info *modinfo);
385 : : static int i40e_get_module_eeprom(struct rte_eth_dev *dev,
386 : : struct rte_dev_eeprom_info *info);
387 : :
388 : : static int i40e_set_default_mac_addr(struct rte_eth_dev *dev,
389 : : struct rte_ether_addr *mac_addr);
390 : :
391 : : static int i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
392 : :
393 : : static int i40e_ethertype_filter_convert(
394 : : const struct rte_eth_ethertype_filter *input,
395 : : struct i40e_ethertype_filter *filter);
396 : : static int i40e_sw_ethertype_filter_insert(struct i40e_pf *pf,
397 : : struct i40e_ethertype_filter *filter);
398 : :
399 : : static int i40e_tunnel_filter_convert(
400 : : struct i40e_aqc_cloud_filters_element_bb *cld_filter,
401 : : struct i40e_tunnel_filter *tunnel_filter);
402 : : static int i40e_sw_tunnel_filter_insert(struct i40e_pf *pf,
403 : : struct i40e_tunnel_filter *tunnel_filter);
404 : : static int i40e_cloud_filter_qinq_create(struct i40e_pf *pf);
405 : :
406 : : static void i40e_ethertype_filter_restore(struct i40e_pf *pf);
407 : : static void i40e_tunnel_filter_restore(struct i40e_pf *pf);
408 : : static void i40e_filter_restore(struct i40e_pf *pf);
409 : : static void i40e_notify_all_vfs_link_status(struct rte_eth_dev *dev);
410 : : static int i40e_fec_get_capability(struct rte_eth_dev *dev,
411 : : struct rte_eth_fec_capa *speed_fec_capa, unsigned int num);
412 : : static int i40e_fec_get(struct rte_eth_dev *dev, uint32_t *fec_capa);
413 : : static int i40e_fec_set(struct rte_eth_dev *dev, uint32_t fec_capa);
414 : :
415 : : static const char *const valid_keys[] = {
416 : : ETH_I40E_FLOATING_VEB_ARG,
417 : : ETH_I40E_FLOATING_VEB_LIST_ARG,
418 : : ETH_I40E_SUPPORT_MULTI_DRIVER,
419 : : ETH_I40E_QUEUE_NUM_PER_VF_ARG,
420 : : ETH_I40E_VF_MSG_CFG,
421 : : ETH_I40E_MBUF_CHECK_ARG,
422 : : NULL};
423 : :
424 : : static const struct rte_pci_id pci_id_i40e_map[] = {
425 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_XL710) },
426 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QEMU) },
427 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_B) },
428 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_C) },
429 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_A) },
430 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_B) },
431 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_C) },
432 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T) },
433 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_20G_KR2) },
434 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_20G_KR2_A) },
435 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T4) },
436 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_B) },
437 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_SFP28) },
438 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_X722) },
439 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_X722) },
440 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_X722) },
441 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_1G_BASE_T_X722) },
442 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_X722) },
443 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_I_X722) },
444 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_X710_N3000) },
445 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_XXV710_N3000) },
446 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_BC) },
447 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_5G_BASE_T_BC) },
448 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_1G_BASE_T_BC) },
449 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_B) },
450 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_SFP) },
451 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_X722_A) },
452 : : { .vendor_id = 0, /* sentinel */ },
453 : : };
454 : :
455 : : static const struct eth_dev_ops i40e_eth_dev_ops = {
456 : : .dev_configure = i40e_dev_configure,
457 : : .dev_start = i40e_dev_start,
458 : : .dev_stop = i40e_dev_stop,
459 : : .dev_close = i40e_dev_close,
460 : : .dev_reset = i40e_dev_reset,
461 : : .promiscuous_enable = i40e_dev_promiscuous_enable,
462 : : .promiscuous_disable = i40e_dev_promiscuous_disable,
463 : : .allmulticast_enable = i40e_dev_allmulticast_enable,
464 : : .allmulticast_disable = i40e_dev_allmulticast_disable,
465 : : .dev_set_link_up = i40e_dev_set_link_up,
466 : : .dev_set_link_down = i40e_dev_set_link_down,
467 : : .link_update = i40e_dev_link_update,
468 : : .stats_get = i40e_dev_stats_get,
469 : : .xstats_get = i40e_dev_xstats_get,
470 : : .xstats_get_names = i40e_dev_xstats_get_names,
471 : : .stats_reset = i40e_dev_stats_reset,
472 : : .xstats_reset = i40e_dev_stats_reset,
473 : : .fw_version_get = i40e_fw_version_get,
474 : : .dev_infos_get = i40e_dev_info_get,
475 : : .dev_supported_ptypes_get = i40e_dev_supported_ptypes_get,
476 : : .vlan_filter_set = i40e_vlan_filter_set,
477 : : .vlan_tpid_set = i40e_vlan_tpid_set,
478 : : .vlan_offload_set = i40e_vlan_offload_set,
479 : : .vlan_strip_queue_set = i40e_vlan_strip_queue_set,
480 : : .vlan_pvid_set = i40e_vlan_pvid_set,
481 : : .rx_queue_start = i40e_dev_rx_queue_start,
482 : : .rx_queue_stop = i40e_dev_rx_queue_stop,
483 : : .tx_queue_start = i40e_dev_tx_queue_start,
484 : : .tx_queue_stop = i40e_dev_tx_queue_stop,
485 : : .rx_queue_setup = i40e_dev_rx_queue_setup,
486 : : .rx_queue_intr_enable = i40e_dev_rx_queue_intr_enable,
487 : : .rx_queue_intr_disable = i40e_dev_rx_queue_intr_disable,
488 : : .rx_queue_release = i40e_dev_rx_queue_release,
489 : : .tx_queue_setup = i40e_dev_tx_queue_setup,
490 : : .tx_queue_release = i40e_dev_tx_queue_release,
491 : : .dev_led_on = i40e_dev_led_on,
492 : : .dev_led_off = i40e_dev_led_off,
493 : : .flow_ctrl_get = i40e_flow_ctrl_get,
494 : : .flow_ctrl_set = i40e_flow_ctrl_set,
495 : : .priority_flow_ctrl_set = i40e_priority_flow_ctrl_set,
496 : : .mac_addr_add = i40e_macaddr_add,
497 : : .mac_addr_remove = i40e_macaddr_remove,
498 : : .reta_update = i40e_dev_rss_reta_update,
499 : : .reta_query = i40e_dev_rss_reta_query,
500 : : .rss_hash_update = i40e_dev_rss_hash_update,
501 : : .rss_hash_conf_get = i40e_dev_rss_hash_conf_get,
502 : : .udp_tunnel_port_add = i40e_dev_udp_tunnel_port_add,
503 : : .udp_tunnel_port_del = i40e_dev_udp_tunnel_port_del,
504 : : .flow_ops_get = i40e_dev_flow_ops_get,
505 : : .rxq_info_get = i40e_rxq_info_get,
506 : : .txq_info_get = i40e_txq_info_get,
507 : : .recycle_rxq_info_get = i40e_recycle_rxq_info_get,
508 : : .rx_burst_mode_get = i40e_rx_burst_mode_get,
509 : : .tx_burst_mode_get = i40e_tx_burst_mode_get,
510 : : .timesync_enable = i40e_timesync_enable,
511 : : .timesync_disable = i40e_timesync_disable,
512 : : .timesync_read_rx_timestamp = i40e_timesync_read_rx_timestamp,
513 : : .timesync_read_tx_timestamp = i40e_timesync_read_tx_timestamp,
514 : : .get_dcb_info = i40e_dev_get_dcb_info,
515 : : .timesync_adjust_time = i40e_timesync_adjust_time,
516 : : .timesync_read_time = i40e_timesync_read_time,
517 : : .timesync_write_time = i40e_timesync_write_time,
518 : : .get_reg = i40e_get_regs,
519 : : .get_eeprom_length = i40e_get_eeprom_length,
520 : : .get_eeprom = i40e_get_eeprom,
521 : : .get_module_info = i40e_get_module_info,
522 : : .get_module_eeprom = i40e_get_module_eeprom,
523 : : .mac_addr_set = i40e_set_default_mac_addr,
524 : : .mtu_set = i40e_dev_mtu_set,
525 : : .tm_ops_get = i40e_tm_ops_get,
526 : : .tx_done_cleanup = i40e_tx_done_cleanup,
527 : : .get_monitor_addr = i40e_get_monitor_addr,
528 : : .fec_get_capability = i40e_fec_get_capability,
529 : : .fec_get = i40e_fec_get,
530 : : .fec_set = i40e_fec_set,
531 : : };
532 : :
533 : : /* store statistics names and its offset in stats structure */
534 : : struct rte_i40e_xstats_name_off {
535 : : char name[RTE_ETH_XSTATS_NAME_SIZE];
536 : : int offset;
537 : : };
538 : :
539 : : static const struct rte_i40e_xstats_name_off rte_i40e_stats_strings[] = {
540 : : {"rx_unicast_packets", offsetof(struct i40e_eth_stats, rx_unicast)},
541 : : {"rx_multicast_packets", offsetof(struct i40e_eth_stats, rx_multicast)},
542 : : {"rx_broadcast_packets", offsetof(struct i40e_eth_stats, rx_broadcast)},
543 : : {"rx_dropped_packets", offsetof(struct i40e_eth_stats, rx_discards)},
544 : : {"rx_unknown_protocol_packets", offsetof(struct i40e_eth_stats,
545 : : rx_unknown_protocol)},
546 : : /*
547 : : * all other offsets are against i40e_eth_stats which is first member
548 : : * in i40e_hw_port_stats, so these offsets are interchangeable
549 : : */
550 : : {"rx_size_error_packets", offsetof(struct i40e_hw_port_stats, rx_err1)},
551 : : {"tx_unicast_packets", offsetof(struct i40e_eth_stats, tx_unicast)},
552 : : {"tx_multicast_packets", offsetof(struct i40e_eth_stats, tx_multicast)},
553 : : {"tx_broadcast_packets", offsetof(struct i40e_eth_stats, tx_broadcast)},
554 : : {"tx_dropped_packets", offsetof(struct i40e_eth_stats, tx_discards)},
555 : : };
556 : :
557 : : #define I40E_NB_ETH_XSTATS (sizeof(rte_i40e_stats_strings) / \
558 : : sizeof(rte_i40e_stats_strings[0]))
559 : :
560 : : static const struct rte_i40e_xstats_name_off i40e_mbuf_strings[] = {
561 : : {"tx_mbuf_error_packets", offsetof(struct i40e_mbuf_stats, tx_pkt_errors)},
562 : : };
563 : :
564 : : #define I40E_NB_MBUF_XSTATS (sizeof(i40e_mbuf_strings) / sizeof(i40e_mbuf_strings[0]))
565 : :
566 : : static const struct rte_i40e_xstats_name_off rte_i40e_hw_port_strings[] = {
567 : : {"tx_link_down_dropped", offsetof(struct i40e_hw_port_stats,
568 : : tx_dropped_link_down)},
569 : : {"rx_crc_errors", offsetof(struct i40e_hw_port_stats, crc_errors)},
570 : : {"rx_illegal_byte_errors", offsetof(struct i40e_hw_port_stats,
571 : : illegal_bytes)},
572 : : {"rx_error_bytes", offsetof(struct i40e_hw_port_stats, error_bytes)},
573 : : {"mac_local_errors", offsetof(struct i40e_hw_port_stats,
574 : : mac_local_faults)},
575 : : {"mac_remote_errors", offsetof(struct i40e_hw_port_stats,
576 : : mac_remote_faults)},
577 : : {"rx_length_errors", offsetof(struct i40e_hw_port_stats,
578 : : rx_length_errors)},
579 : : {"tx_xon_packets", offsetof(struct i40e_hw_port_stats, link_xon_tx)},
580 : : {"rx_xon_packets", offsetof(struct i40e_hw_port_stats, link_xon_rx)},
581 : : {"tx_xoff_packets", offsetof(struct i40e_hw_port_stats, link_xoff_tx)},
582 : : {"rx_xoff_packets", offsetof(struct i40e_hw_port_stats, link_xoff_rx)},
583 : : {"rx_size_64_packets", offsetof(struct i40e_hw_port_stats, rx_size_64)},
584 : : {"rx_size_65_to_127_packets", offsetof(struct i40e_hw_port_stats,
585 : : rx_size_127)},
586 : : {"rx_size_128_to_255_packets", offsetof(struct i40e_hw_port_stats,
587 : : rx_size_255)},
588 : : {"rx_size_256_to_511_packets", offsetof(struct i40e_hw_port_stats,
589 : : rx_size_511)},
590 : : {"rx_size_512_to_1023_packets", offsetof(struct i40e_hw_port_stats,
591 : : rx_size_1023)},
592 : : {"rx_size_1024_to_1522_packets", offsetof(struct i40e_hw_port_stats,
593 : : rx_size_1522)},
594 : : {"rx_size_1523_to_max_packets", offsetof(struct i40e_hw_port_stats,
595 : : rx_size_big)},
596 : : {"rx_undersized_errors", offsetof(struct i40e_hw_port_stats,
597 : : rx_undersize)},
598 : : {"rx_oversize_errors", offsetof(struct i40e_hw_port_stats,
599 : : rx_oversize)},
600 : : {"rx_mac_short_dropped", offsetof(struct i40e_hw_port_stats,
601 : : mac_short_packet_dropped)},
602 : : {"rx_fragmented_errors", offsetof(struct i40e_hw_port_stats,
603 : : rx_fragments)},
604 : : {"rx_jabber_errors", offsetof(struct i40e_hw_port_stats, rx_jabber)},
605 : : {"tx_size_64_packets", offsetof(struct i40e_hw_port_stats, tx_size_64)},
606 : : {"tx_size_65_to_127_packets", offsetof(struct i40e_hw_port_stats,
607 : : tx_size_127)},
608 : : {"tx_size_128_to_255_packets", offsetof(struct i40e_hw_port_stats,
609 : : tx_size_255)},
610 : : {"tx_size_256_to_511_packets", offsetof(struct i40e_hw_port_stats,
611 : : tx_size_511)},
612 : : {"tx_size_512_to_1023_packets", offsetof(struct i40e_hw_port_stats,
613 : : tx_size_1023)},
614 : : {"tx_size_1024_to_1522_packets", offsetof(struct i40e_hw_port_stats,
615 : : tx_size_1522)},
616 : : {"tx_size_1523_to_max_packets", offsetof(struct i40e_hw_port_stats,
617 : : tx_size_big)},
618 : : {"rx_flow_director_atr_match_packets",
619 : : offsetof(struct i40e_hw_port_stats, fd_atr_match)},
620 : : {"rx_flow_director_sb_match_packets",
621 : : offsetof(struct i40e_hw_port_stats, fd_sb_match)},
622 : : {"tx_low_power_idle_status", offsetof(struct i40e_hw_port_stats,
623 : : tx_lpi_status)},
624 : : {"rx_low_power_idle_status", offsetof(struct i40e_hw_port_stats,
625 : : rx_lpi_status)},
626 : : {"tx_low_power_idle_count", offsetof(struct i40e_hw_port_stats,
627 : : tx_lpi_count)},
628 : : {"rx_low_power_idle_count", offsetof(struct i40e_hw_port_stats,
629 : : rx_lpi_count)},
630 : : };
631 : :
632 : : #define I40E_NB_HW_PORT_XSTATS (sizeof(rte_i40e_hw_port_strings) / \
633 : : sizeof(rte_i40e_hw_port_strings[0]))
634 : :
635 : : static const struct rte_i40e_xstats_name_off rte_i40e_rxq_prio_strings[] = {
636 : : {"xon_packets", offsetof(struct i40e_hw_port_stats,
637 : : priority_xon_rx)},
638 : : {"xoff_packets", offsetof(struct i40e_hw_port_stats,
639 : : priority_xoff_rx)},
640 : : };
641 : :
642 : : #define I40E_NB_RXQ_PRIO_XSTATS (sizeof(rte_i40e_rxq_prio_strings) / \
643 : : sizeof(rte_i40e_rxq_prio_strings[0]))
644 : :
645 : : static const struct rte_i40e_xstats_name_off rte_i40e_txq_prio_strings[] = {
646 : : {"xon_packets", offsetof(struct i40e_hw_port_stats,
647 : : priority_xon_tx)},
648 : : {"xoff_packets", offsetof(struct i40e_hw_port_stats,
649 : : priority_xoff_tx)},
650 : : {"xon_to_xoff_packets", offsetof(struct i40e_hw_port_stats,
651 : : priority_xon_2_xoff)},
652 : : };
653 : :
654 : : #define I40E_NB_TXQ_PRIO_XSTATS (sizeof(rte_i40e_txq_prio_strings) / \
655 : : sizeof(rte_i40e_txq_prio_strings[0]))
656 : :
657 : : static int
658 : 0 : eth_i40e_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
659 : : struct rte_pci_device *pci_dev)
660 : : {
661 : : char name[RTE_ETH_NAME_MAX_LEN];
662 : 0 : struct rte_eth_devargs eth_da = { .nb_representor_ports = 0 };
663 : : int i, retval;
664 : :
665 [ # # ]: 0 : if (pci_dev->device.devargs) {
666 : 0 : retval = rte_eth_devargs_parse(pci_dev->device.devargs->args,
667 : : ð_da, 1);
668 [ # # ]: 0 : if (retval < 0)
669 : : return retval;
670 : : }
671 : :
672 [ # # ]: 0 : if (eth_da.nb_representor_ports > 0 &&
673 [ # # ]: 0 : eth_da.type != RTE_ETH_REPRESENTOR_VF) {
674 : 0 : PMD_DRV_LOG(ERR, "unsupported representor type: %s",
675 : : pci_dev->device.devargs->args);
676 : 0 : return -ENOTSUP;
677 : : }
678 : :
679 : 0 : retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
680 : : sizeof(struct i40e_adapter),
681 : : eth_dev_pci_specific_init, pci_dev,
682 : : eth_i40e_dev_init, NULL);
683 : :
684 [ # # # # ]: 0 : if (retval || eth_da.nb_representor_ports < 1)
685 : : return retval;
686 : :
687 : : /* probe VF representor ports */
688 : 0 : struct rte_eth_dev *pf_ethdev = rte_eth_dev_allocated(
689 : : pci_dev->device.name);
690 : :
691 [ # # ]: 0 : if (pf_ethdev == NULL)
692 : : return -ENODEV;
693 : :
694 [ # # ]: 0 : for (i = 0; i < eth_da.nb_representor_ports; i++) {
695 : 0 : struct i40e_vf_representor representor = {
696 : 0 : .vf_id = eth_da.representor_ports[i],
697 : 0 : .switch_domain_id = I40E_DEV_PRIVATE_TO_PF(
698 : 0 : pf_ethdev->data->dev_private)->switch_domain_id,
699 : : .adapter = I40E_DEV_PRIVATE_TO_ADAPTER(
700 : : pf_ethdev->data->dev_private)
701 : : };
702 : :
703 : : /* representor port net_bdf_port */
704 : 0 : snprintf(name, sizeof(name), "net_%s_representor_%d",
705 : : pci_dev->device.name, eth_da.representor_ports[i]);
706 : :
707 : 0 : retval = rte_eth_dev_create(&pci_dev->device, name,
708 : : sizeof(struct i40e_vf_representor), NULL, NULL,
709 : : i40e_vf_representor_init, &representor);
710 : :
711 [ # # ]: 0 : if (retval)
712 : 0 : PMD_DRV_LOG(ERR, "failed to create i40e vf "
713 : : "representor %s.", name);
714 : : }
715 : :
716 : : return 0;
717 : : }
718 : :
719 : 0 : static int eth_i40e_pci_remove(struct rte_pci_device *pci_dev)
720 : : {
721 : : struct rte_eth_dev *ethdev;
722 : :
723 : 0 : ethdev = rte_eth_dev_allocated(pci_dev->device.name);
724 [ # # ]: 0 : if (!ethdev)
725 : : return 0;
726 : :
727 [ # # ]: 0 : if (rte_eth_dev_is_repr(ethdev))
728 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev,
729 : : i40e_vf_representor_uninit);
730 : : else
731 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev,
732 : : eth_i40e_dev_uninit);
733 : : }
734 : :
735 : : static struct rte_pci_driver rte_i40e_pmd = {
736 : : .id_table = pci_id_i40e_map,
737 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
738 : : .probe = eth_i40e_pci_probe,
739 : : .remove = eth_i40e_pci_remove,
740 : : };
741 : :
742 : : static inline void
743 : 0 : i40e_write_global_rx_ctl(struct i40e_hw *hw, uint32_t reg_addr,
744 : : uint32_t reg_val)
745 : : {
746 : : uint32_t ori_reg_val;
747 : 0 : struct rte_eth_dev_data *dev_data =
748 : 0 : ((struct i40e_adapter *)hw->back)->pf.dev_data;
749 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[dev_data->port_id];
750 : :
751 : 0 : ori_reg_val = i40e_read_rx_ctl(hw, reg_addr);
752 : 0 : i40e_write_rx_ctl(hw, reg_addr, reg_val);
753 [ # # ]: 0 : if (ori_reg_val != reg_val)
754 : 0 : PMD_DRV_LOG(INFO,
755 : : "i40e device %s changed global register [0x%08x]."
756 : : " original: 0x%08x, new: 0x%08x",
757 : : dev->device->name, reg_addr, ori_reg_val, reg_val);
758 : 0 : }
759 : :
760 : 276 : RTE_PMD_REGISTER_PCI(net_i40e, rte_i40e_pmd);
761 : : RTE_PMD_REGISTER_PCI_TABLE(net_i40e, pci_id_i40e_map);
762 : : RTE_PMD_REGISTER_KMOD_DEP(net_i40e, "* igb_uio | uio_pci_generic | vfio-pci");
763 : :
764 : : #ifndef I40E_GLQF_ORT
765 : : #define I40E_GLQF_ORT(_i) (0x00268900 + ((_i) * 4))
766 : : #endif
767 : : #ifndef I40E_GLQF_PIT
768 : : #define I40E_GLQF_PIT(_i) (0x00268C80 + ((_i) * 4))
769 : : #endif
770 : : #ifndef I40E_GLQF_L3_MAP
771 : : #define I40E_GLQF_L3_MAP(_i) (0x0026C700 + ((_i) * 4))
772 : : #endif
773 : :
774 : 0 : static inline void i40e_GLQF_reg_init(struct i40e_hw *hw)
775 : : {
776 : : /*
777 : : * Initialize registers for parsing packet type of QinQ
778 : : * This should be removed from code once proper
779 : : * configuration API is added to avoid configuration conflicts
780 : : * between ports of the same device.
781 : : */
782 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(40), 0x00000029);
783 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_PIT(9), 0x00009420);
784 : 0 : }
785 : :
786 : : static inline void i40e_config_automask(struct i40e_pf *pf)
787 : : {
788 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
789 : : uint32_t val;
790 : :
791 : : /* INTENA flag is not auto-cleared for interrupt */
792 : 0 : val = I40E_READ_REG(hw, I40E_GLINT_CTL);
793 : 0 : val |= I40E_GLINT_CTL_DIS_AUTOMASK_PF0_MASK |
794 : : I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK;
795 : :
796 : : /* If support multi-driver, PF will use INT0. */
797 [ # # ]: 0 : if (!pf->support_multi_driver)
798 : 0 : val |= I40E_GLINT_CTL_DIS_AUTOMASK_N_MASK;
799 : :
800 : 0 : I40E_WRITE_REG(hw, I40E_GLINT_CTL, val);
801 : : }
802 : :
803 : : static inline void i40e_clear_automask(struct i40e_pf *pf)
804 : : {
805 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
806 : : uint32_t val;
807 : :
808 : 0 : val = I40E_READ_REG(hw, I40E_GLINT_CTL);
809 : 0 : val &= ~(I40E_GLINT_CTL_DIS_AUTOMASK_PF0_MASK |
810 : : I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK);
811 : :
812 [ # # ]: 0 : if (!pf->support_multi_driver)
813 : 0 : val &= ~I40E_GLINT_CTL_DIS_AUTOMASK_N_MASK;
814 : :
815 : 0 : I40E_WRITE_REG(hw, I40E_GLINT_CTL, val);
816 : : }
817 : :
818 : : #define I40E_FLOW_CONTROL_ETHERTYPE 0x8808
819 : :
820 : : /*
821 : : * Add a ethertype filter to drop all flow control frames transmitted
822 : : * from VSIs.
823 : : */
824 : : static void
825 : 0 : i40e_add_tx_flow_control_drop_filter(struct i40e_pf *pf)
826 : : {
827 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
828 : : uint16_t flags = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
829 : : I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
830 : : I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
831 : : int ret;
832 : :
833 : 0 : ret = i40e_aq_add_rem_control_packet_filter(hw, NULL,
834 : : I40E_FLOW_CONTROL_ETHERTYPE, flags,
835 : 0 : pf->main_vsi_seid, 0,
836 : : TRUE, NULL, NULL);
837 [ # # ]: 0 : if (ret)
838 : 0 : PMD_INIT_LOG(ERR,
839 : : "Failed to add filter to drop flow control frames from VSIs.");
840 : 0 : }
841 : :
842 : : static int
843 : 0 : floating_veb_list_handler(__rte_unused const char *key,
844 : : const char *floating_veb_value,
845 : : void *opaque)
846 : : {
847 : : int idx = 0;
848 : : unsigned int count = 0;
849 : 0 : char *end = NULL;
850 : : int min, max;
851 : : bool *vf_floating_veb = opaque;
852 : :
853 [ # # ]: 0 : while (isblank(*floating_veb_value))
854 : 0 : floating_veb_value++;
855 : :
856 : : /* Reset floating VEB configuration for VFs */
857 [ # # ]: 0 : for (idx = 0; idx < I40E_MAX_VF; idx++)
858 : 0 : vf_floating_veb[idx] = false;
859 : :
860 : : min = I40E_MAX_VF;
861 : : do {
862 [ # # ]: 0 : while (isblank(*floating_veb_value))
863 : 0 : floating_veb_value++;
864 [ # # ]: 0 : if (*floating_veb_value == '\0')
865 : : return -1;
866 : 0 : errno = 0;
867 : 0 : idx = strtoul(floating_veb_value, &end, 10);
868 [ # # # # ]: 0 : if (errno || end == NULL)
869 : : return -1;
870 [ # # ]: 0 : if (idx < 0)
871 : : return -1;
872 [ # # ]: 0 : while (isblank(*end))
873 : 0 : end++;
874 [ # # ]: 0 : if (*end == '-') {
875 : : min = idx;
876 [ # # ]: 0 : } else if ((*end == ';') || (*end == '\0')) {
877 : : max = idx;
878 [ # # ]: 0 : if (min == I40E_MAX_VF)
879 : : min = idx;
880 : : if (max >= I40E_MAX_VF)
881 : : max = I40E_MAX_VF - 1;
882 [ # # ]: 0 : for (idx = min; idx <= max; idx++) {
883 : 0 : vf_floating_veb[idx] = true;
884 : 0 : count++;
885 : : }
886 : : min = I40E_MAX_VF;
887 : : } else {
888 : : return -1;
889 : : }
890 : 0 : floating_veb_value = end + 1;
891 [ # # ]: 0 : } while (*end != '\0');
892 : :
893 [ # # ]: 0 : if (count == 0)
894 : 0 : return -1;
895 : :
896 : : return 0;
897 : : }
898 : :
899 : : static void
900 : 0 : config_vf_floating_veb(struct rte_devargs *devargs,
901 : : uint16_t floating_veb,
902 : : bool *vf_floating_veb)
903 : : {
904 : : struct rte_kvargs *kvlist;
905 : : int i;
906 : : const char *floating_veb_list = ETH_I40E_FLOATING_VEB_LIST_ARG;
907 : :
908 [ # # ]: 0 : if (!floating_veb)
909 : : return;
910 : : /* All the VFs attach to the floating VEB by default
911 : : * when the floating VEB is enabled.
912 : : */
913 [ # # ]: 0 : for (i = 0; i < I40E_MAX_VF; i++)
914 : 0 : vf_floating_veb[i] = true;
915 : :
916 [ # # ]: 0 : if (devargs == NULL)
917 : : return;
918 : :
919 : 0 : kvlist = rte_kvargs_parse(devargs->args, valid_keys);
920 [ # # ]: 0 : if (kvlist == NULL)
921 : : return;
922 : :
923 [ # # ]: 0 : if (!rte_kvargs_count(kvlist, floating_veb_list)) {
924 : 0 : rte_kvargs_free(kvlist);
925 : 0 : return;
926 : : }
927 : : /* When the floating_veb_list parameter exists, all the VFs
928 : : * will attach to the legacy VEB firstly, then configure VFs
929 : : * to the floating VEB according to the floating_veb_list.
930 : : */
931 [ # # ]: 0 : if (rte_kvargs_process(kvlist, floating_veb_list,
932 : : floating_veb_list_handler,
933 : : vf_floating_veb) < 0) {
934 : 0 : rte_kvargs_free(kvlist);
935 : 0 : return;
936 : : }
937 : 0 : rte_kvargs_free(kvlist);
938 : : }
939 : :
940 : : static int
941 : 0 : i40e_check_floating_handler(__rte_unused const char *key,
942 : : const char *value,
943 : : __rte_unused void *opaque)
944 : : {
945 [ # # ]: 0 : if (strcmp(value, "1"))
946 : 0 : return -1;
947 : :
948 : : return 0;
949 : : }
950 : :
951 : : static int
952 : 0 : is_floating_veb_supported(struct rte_devargs *devargs)
953 : : {
954 : : struct rte_kvargs *kvlist;
955 : : const char *floating_veb_key = ETH_I40E_FLOATING_VEB_ARG;
956 : :
957 [ # # ]: 0 : if (devargs == NULL)
958 : : return 0;
959 : :
960 : 0 : kvlist = rte_kvargs_parse(devargs->args, valid_keys);
961 [ # # ]: 0 : if (kvlist == NULL)
962 : : return 0;
963 : :
964 [ # # ]: 0 : if (!rte_kvargs_count(kvlist, floating_veb_key)) {
965 : 0 : rte_kvargs_free(kvlist);
966 : 0 : return 0;
967 : : }
968 : : /* Floating VEB is enabled when there's key-value:
969 : : * enable_floating_veb=1
970 : : */
971 [ # # ]: 0 : if (rte_kvargs_process(kvlist, floating_veb_key,
972 : : i40e_check_floating_handler, NULL) < 0) {
973 : 0 : rte_kvargs_free(kvlist);
974 : 0 : return 0;
975 : : }
976 : 0 : rte_kvargs_free(kvlist);
977 : :
978 : 0 : return 1;
979 : : }
980 : :
981 : : static void
982 : 0 : config_floating_veb(struct rte_eth_dev *dev)
983 : : {
984 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
985 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
986 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
987 : :
988 [ # # ]: 0 : memset(pf->floating_veb_list, 0, sizeof(pf->floating_veb_list));
989 : :
990 [ # # ]: 0 : if (hw->aq.fw_maj_ver >= FLOATING_VEB_SUPPORTED_FW_MAJ) {
991 : 0 : pf->floating_veb =
992 : 0 : is_floating_veb_supported(pci_dev->device.devargs);
993 : 0 : config_vf_floating_veb(pci_dev->device.devargs,
994 : : pf->floating_veb,
995 : : pf->floating_veb_list);
996 : : } else {
997 : 0 : pf->floating_veb = false;
998 : : }
999 : 0 : }
1000 : :
1001 : : #define I40E_L2_TAGS_S_TAG_SHIFT 1
1002 : : #define I40E_L2_TAGS_S_TAG_MASK I40E_MASK(0x1, I40E_L2_TAGS_S_TAG_SHIFT)
1003 : :
1004 : : static int
1005 : 0 : i40e_init_ethtype_filter_list(struct rte_eth_dev *dev)
1006 : : {
1007 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1008 : : struct i40e_ethertype_rule *ethertype_rule = &pf->ethertype;
1009 : : char ethertype_hash_name[RTE_HASH_NAMESIZE];
1010 : : int ret;
1011 : :
1012 : 0 : struct rte_hash_parameters ethertype_hash_params = {
1013 : : .name = ethertype_hash_name,
1014 : : .entries = I40E_MAX_ETHERTYPE_FILTER_NUM,
1015 : : .key_len = sizeof(struct i40e_ethertype_filter_input),
1016 : : .hash_func = rte_hash_crc,
1017 : : .hash_func_init_val = 0,
1018 : 0 : .socket_id = rte_socket_id(),
1019 : : };
1020 : :
1021 : : /* Initialize ethertype filter rule list and hash */
1022 : 0 : TAILQ_INIT(ðertype_rule->ethertype_list);
1023 : 0 : snprintf(ethertype_hash_name, RTE_HASH_NAMESIZE,
1024 : 0 : "ethertype_%s", dev->device->name);
1025 : 0 : ethertype_rule->hash_table = rte_hash_create(ðertype_hash_params);
1026 [ # # ]: 0 : if (!ethertype_rule->hash_table) {
1027 : 0 : PMD_INIT_LOG(ERR, "Failed to create ethertype hash table!");
1028 : 0 : return -EINVAL;
1029 : : }
1030 : 0 : ethertype_rule->hash_map = rte_zmalloc("i40e_ethertype_hash_map",
1031 : : sizeof(struct i40e_ethertype_filter *) *
1032 : : I40E_MAX_ETHERTYPE_FILTER_NUM,
1033 : : 0);
1034 [ # # ]: 0 : if (!ethertype_rule->hash_map) {
1035 : 0 : PMD_INIT_LOG(ERR,
1036 : : "Failed to allocate memory for ethertype hash map!");
1037 : : ret = -ENOMEM;
1038 : 0 : goto err_ethertype_hash_map_alloc;
1039 : : }
1040 : :
1041 : : return 0;
1042 : :
1043 : : err_ethertype_hash_map_alloc:
1044 : 0 : rte_hash_free(ethertype_rule->hash_table);
1045 : :
1046 : 0 : return ret;
1047 : : }
1048 : :
1049 : : static int
1050 : 0 : i40e_init_tunnel_filter_list(struct rte_eth_dev *dev)
1051 : : {
1052 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1053 : : struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
1054 : : char tunnel_hash_name[RTE_HASH_NAMESIZE];
1055 : : int ret;
1056 : :
1057 : 0 : struct rte_hash_parameters tunnel_hash_params = {
1058 : : .name = tunnel_hash_name,
1059 : : .entries = I40E_MAX_TUNNEL_FILTER_NUM,
1060 : : .key_len = sizeof(struct i40e_tunnel_filter_input),
1061 : : .hash_func = rte_hash_crc,
1062 : : .hash_func_init_val = 0,
1063 : 0 : .socket_id = rte_socket_id(),
1064 : : };
1065 : :
1066 : : /* Initialize tunnel filter rule list and hash */
1067 : 0 : TAILQ_INIT(&tunnel_rule->tunnel_list);
1068 : 0 : snprintf(tunnel_hash_name, RTE_HASH_NAMESIZE,
1069 : 0 : "tunnel_%s", dev->device->name);
1070 : 0 : tunnel_rule->hash_table = rte_hash_create(&tunnel_hash_params);
1071 [ # # ]: 0 : if (!tunnel_rule->hash_table) {
1072 : 0 : PMD_INIT_LOG(ERR, "Failed to create tunnel hash table!");
1073 : 0 : return -EINVAL;
1074 : : }
1075 : 0 : tunnel_rule->hash_map = rte_zmalloc("i40e_tunnel_hash_map",
1076 : : sizeof(struct i40e_tunnel_filter *) *
1077 : : I40E_MAX_TUNNEL_FILTER_NUM,
1078 : : 0);
1079 [ # # ]: 0 : if (!tunnel_rule->hash_map) {
1080 : 0 : PMD_INIT_LOG(ERR,
1081 : : "Failed to allocate memory for tunnel hash map!");
1082 : : ret = -ENOMEM;
1083 : 0 : goto err_tunnel_hash_map_alloc;
1084 : : }
1085 : :
1086 : : return 0;
1087 : :
1088 : : err_tunnel_hash_map_alloc:
1089 : 0 : rte_hash_free(tunnel_rule->hash_table);
1090 : :
1091 : 0 : return ret;
1092 : : }
1093 : :
1094 : : static int
1095 : 0 : i40e_init_fdir_filter_list(struct rte_eth_dev *dev)
1096 : : {
1097 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1098 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1099 : : struct i40e_fdir_info *fdir_info = &pf->fdir;
1100 : : char fdir_hash_name[RTE_HASH_NAMESIZE];
1101 : 0 : uint32_t alloc = hw->func_caps.fd_filters_guaranteed;
1102 : 0 : uint32_t best = hw->func_caps.fd_filters_best_effort;
1103 : : enum i40e_filter_pctype pctype;
1104 : : struct rte_bitmap *bmp = NULL;
1105 : : uint32_t bmp_size;
1106 : : void *mem = NULL;
1107 : : uint32_t i = 0;
1108 : : int ret;
1109 : :
1110 : 0 : struct rte_hash_parameters fdir_hash_params = {
1111 : : .name = fdir_hash_name,
1112 : : .entries = I40E_MAX_FDIR_FILTER_NUM,
1113 : : .key_len = sizeof(struct i40e_fdir_input),
1114 : : .hash_func = rte_hash_crc,
1115 : : .hash_func_init_val = 0,
1116 : 0 : .socket_id = rte_socket_id(),
1117 : : };
1118 : :
1119 : : /* Initialize flow director filter rule list and hash */
1120 : 0 : TAILQ_INIT(&fdir_info->fdir_list);
1121 : 0 : snprintf(fdir_hash_name, RTE_HASH_NAMESIZE,
1122 : 0 : "fdir_%s", dev->device->name);
1123 : 0 : fdir_info->hash_table = rte_hash_create(&fdir_hash_params);
1124 [ # # ]: 0 : if (!fdir_info->hash_table) {
1125 : 0 : PMD_INIT_LOG(ERR, "Failed to create fdir hash table!");
1126 : 0 : return -EINVAL;
1127 : : }
1128 : :
1129 : 0 : fdir_info->hash_map = rte_zmalloc("i40e_fdir_hash_map",
1130 : : sizeof(struct i40e_fdir_filter *) *
1131 : : I40E_MAX_FDIR_FILTER_NUM,
1132 : : 0);
1133 [ # # ]: 0 : if (!fdir_info->hash_map) {
1134 : 0 : PMD_INIT_LOG(ERR,
1135 : : "Failed to allocate memory for fdir hash map!");
1136 : : ret = -ENOMEM;
1137 : 0 : goto err_fdir_hash_map_alloc;
1138 : : }
1139 : :
1140 : 0 : fdir_info->fdir_filter_array = rte_zmalloc("fdir_filter",
1141 : : sizeof(struct i40e_fdir_filter) *
1142 : : I40E_MAX_FDIR_FILTER_NUM,
1143 : : 0);
1144 : :
1145 [ # # ]: 0 : if (!fdir_info->fdir_filter_array) {
1146 : 0 : PMD_INIT_LOG(ERR,
1147 : : "Failed to allocate memory for fdir filter array!");
1148 : : ret = -ENOMEM;
1149 : 0 : goto err_fdir_filter_array_alloc;
1150 : : }
1151 : :
1152 : : for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
1153 [ # # ]: 0 : pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++)
1154 : 0 : pf->fdir.flow_count[pctype] = 0;
1155 : :
1156 : 0 : fdir_info->fdir_space_size = alloc + best;
1157 : 0 : fdir_info->fdir_actual_cnt = 0;
1158 : 0 : fdir_info->fdir_guarantee_total_space = alloc;
1159 : 0 : fdir_info->fdir_guarantee_free_space =
1160 : : fdir_info->fdir_guarantee_total_space;
1161 : :
1162 : 0 : PMD_DRV_LOG(INFO, "FDIR guarantee space: %u, best_effort space %u.", alloc, best);
1163 : :
1164 : 0 : fdir_info->fdir_flow_pool.pool =
1165 : 0 : rte_zmalloc("i40e_fdir_entry",
1166 : : sizeof(struct i40e_fdir_entry) *
1167 : 0 : fdir_info->fdir_space_size,
1168 : : 0);
1169 : :
1170 [ # # ]: 0 : if (!fdir_info->fdir_flow_pool.pool) {
1171 : 0 : PMD_INIT_LOG(ERR,
1172 : : "Failed to allocate memory for bitmap flow!");
1173 : : ret = -ENOMEM;
1174 : 0 : goto err_fdir_bitmap_flow_alloc;
1175 : : }
1176 : :
1177 [ # # ]: 0 : for (i = 0; i < fdir_info->fdir_space_size; i++)
1178 : 0 : fdir_info->fdir_flow_pool.pool[i].idx = i;
1179 : :
1180 : : bmp_size =
1181 : 0 : rte_bitmap_get_memory_footprint(fdir_info->fdir_space_size);
1182 : 0 : mem = rte_zmalloc("fdir_bmap", bmp_size, RTE_CACHE_LINE_SIZE);
1183 [ # # ]: 0 : if (mem == NULL) {
1184 : 0 : PMD_INIT_LOG(ERR,
1185 : : "Failed to allocate memory for fdir bitmap!");
1186 : : ret = -ENOMEM;
1187 : 0 : goto err_fdir_mem_alloc;
1188 : : }
1189 : 0 : bmp = rte_bitmap_init(fdir_info->fdir_space_size, mem, bmp_size);
1190 [ # # ]: 0 : if (bmp == NULL) {
1191 : 0 : PMD_INIT_LOG(ERR,
1192 : : "Failed to initialization fdir bitmap!");
1193 : : ret = -ENOMEM;
1194 : 0 : goto err_fdir_bmp_alloc;
1195 : : }
1196 [ # # ]: 0 : for (i = 0; i < fdir_info->fdir_space_size; i++)
1197 : 0 : rte_bitmap_set(bmp, i);
1198 : :
1199 : 0 : fdir_info->fdir_flow_pool.bitmap = bmp;
1200 : :
1201 : 0 : return 0;
1202 : :
1203 : : err_fdir_bmp_alloc:
1204 : 0 : rte_free(mem);
1205 : 0 : err_fdir_mem_alloc:
1206 : 0 : rte_free(fdir_info->fdir_flow_pool.pool);
1207 : 0 : err_fdir_bitmap_flow_alloc:
1208 : 0 : rte_free(fdir_info->fdir_filter_array);
1209 : 0 : err_fdir_filter_array_alloc:
1210 : 0 : rte_free(fdir_info->hash_map);
1211 : 0 : err_fdir_hash_map_alloc:
1212 : 0 : rte_hash_free(fdir_info->hash_table);
1213 : :
1214 : 0 : return ret;
1215 : : }
1216 : :
1217 : : static void
1218 : : i40e_init_customized_info(struct i40e_pf *pf)
1219 : : {
1220 : : int i;
1221 : :
1222 : : /* Initialize customized pctype */
1223 [ # # ]: 0 : for (i = I40E_CUSTOMIZED_GTPC; i < I40E_CUSTOMIZED_MAX; i++) {
1224 : 0 : pf->customized_pctype[i].index = i;
1225 : 0 : pf->customized_pctype[i].pctype = I40E_FILTER_PCTYPE_INVALID;
1226 : 0 : pf->customized_pctype[i].valid = false;
1227 : : }
1228 : :
1229 : 0 : pf->gtp_support = false;
1230 : 0 : pf->esp_support = false;
1231 : : }
1232 : :
1233 : : static void
1234 : 0 : i40e_init_filter_invalidation(struct i40e_pf *pf)
1235 : : {
1236 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1237 : : struct i40e_fdir_info *fdir_info = &pf->fdir;
1238 : : uint32_t glqf_ctl_reg = 0;
1239 : :
1240 : 0 : glqf_ctl_reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
1241 [ # # ]: 0 : if (!pf->support_multi_driver) {
1242 : 0 : fdir_info->fdir_invalprio = 1;
1243 : 0 : glqf_ctl_reg |= I40E_GLQF_CTL_INVALPRIO_MASK;
1244 : 0 : PMD_DRV_LOG(INFO, "FDIR INVALPRIO set to guaranteed first");
1245 : 0 : i40e_write_rx_ctl(hw, I40E_GLQF_CTL, glqf_ctl_reg);
1246 : : } else {
1247 [ # # ]: 0 : if (glqf_ctl_reg & I40E_GLQF_CTL_INVALPRIO_MASK) {
1248 : 0 : fdir_info->fdir_invalprio = 1;
1249 : 0 : PMD_DRV_LOG(INFO, "FDIR INVALPRIO is: guaranteed first");
1250 : : } else {
1251 : 0 : fdir_info->fdir_invalprio = 0;
1252 : 0 : PMD_DRV_LOG(INFO, "FDIR INVALPRIO is: shared first");
1253 : : }
1254 : : }
1255 : 0 : }
1256 : :
1257 : : void
1258 : 0 : i40e_init_queue_region_conf(struct rte_eth_dev *dev)
1259 : : {
1260 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1261 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1262 : 0 : struct i40e_queue_regions *info = &pf->queue_region;
1263 : : uint16_t i;
1264 : :
1265 [ # # ]: 0 : for (i = 0; i < I40E_PFQF_HREGION_MAX_INDEX; i++)
1266 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HREGION(i), 0);
1267 : :
1268 : : memset(info, 0, sizeof(struct i40e_queue_regions));
1269 : 0 : }
1270 : :
1271 : : static int
1272 : 0 : i40e_parse_multi_drv_handler(__rte_unused const char *key,
1273 : : const char *value,
1274 : : void *opaque)
1275 : : {
1276 : : struct i40e_pf *pf;
1277 : : unsigned long support_multi_driver;
1278 : : char *end;
1279 : :
1280 : : pf = (struct i40e_pf *)opaque;
1281 : :
1282 : 0 : errno = 0;
1283 : 0 : support_multi_driver = strtoul(value, &end, 10);
1284 [ # # # # : 0 : if (errno != 0 || end == value || *end != 0) {
# # ]
1285 : 0 : PMD_DRV_LOG(WARNING, "Wrong global configuration");
1286 : 0 : return -(EINVAL);
1287 : : }
1288 : :
1289 [ # # ]: 0 : if (support_multi_driver == 1 || support_multi_driver == 0)
1290 : 0 : pf->support_multi_driver = (bool)support_multi_driver;
1291 : : else
1292 : 0 : PMD_DRV_LOG(WARNING, "%s must be 1 or 0,",
1293 : : "enable global configuration by default."
1294 : : ETH_I40E_SUPPORT_MULTI_DRIVER);
1295 : : return 0;
1296 : : }
1297 : :
1298 : : static int
1299 : 0 : i40e_support_multi_driver(struct rte_eth_dev *dev)
1300 : : {
1301 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1302 : : struct rte_kvargs *kvlist;
1303 : : int kvargs_count;
1304 : :
1305 : : /* Enable global configuration by default */
1306 : 0 : pf->support_multi_driver = false;
1307 : :
1308 [ # # ]: 0 : if (!dev->device->devargs)
1309 : : return 0;
1310 : :
1311 : 0 : kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
1312 [ # # ]: 0 : if (!kvlist)
1313 : : return -EINVAL;
1314 : :
1315 : 0 : kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_SUPPORT_MULTI_DRIVER);
1316 [ # # ]: 0 : if (!kvargs_count) {
1317 : 0 : rte_kvargs_free(kvlist);
1318 : 0 : return 0;
1319 : : }
1320 : :
1321 [ # # ]: 0 : if (kvargs_count > 1)
1322 : 0 : PMD_DRV_LOG(WARNING, "More than one argument \"%s\" and only "
1323 : : "the first invalid or last valid one is used !",
1324 : : ETH_I40E_SUPPORT_MULTI_DRIVER);
1325 : :
1326 [ # # ]: 0 : if (rte_kvargs_process(kvlist, ETH_I40E_SUPPORT_MULTI_DRIVER,
1327 : : i40e_parse_multi_drv_handler, pf) < 0) {
1328 : 0 : rte_kvargs_free(kvlist);
1329 : 0 : return -EINVAL;
1330 : : }
1331 : :
1332 : 0 : rte_kvargs_free(kvlist);
1333 : 0 : return 0;
1334 : : }
1335 : :
1336 : : static int
1337 : 0 : i40e_aq_debug_write_global_register(struct i40e_hw *hw,
1338 : : uint32_t reg_addr, uint64_t reg_val,
1339 : : struct i40e_asq_cmd_details *cmd_details)
1340 : : {
1341 : : uint64_t ori_reg_val;
1342 : 0 : struct rte_eth_dev_data *dev_data =
1343 : 0 : ((struct i40e_adapter *)hw->back)->pf.dev_data;
1344 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[dev_data->port_id];
1345 : : int ret;
1346 : :
1347 : 0 : ret = i40e_aq_debug_read_register(hw, reg_addr, &ori_reg_val, NULL);
1348 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1349 : 0 : PMD_DRV_LOG(ERR,
1350 : : "Fail to debug read from 0x%08x",
1351 : : reg_addr);
1352 : 0 : return -EIO;
1353 : : }
1354 : :
1355 [ # # ]: 0 : if (ori_reg_val != reg_val)
1356 : 0 : PMD_DRV_LOG(INFO,
1357 : : "i40e device %s changed global register [0x%08x]."
1358 : : " original: 0x%"PRIx64", after: 0x%"PRIx64,
1359 : : dev->device->name, reg_addr, ori_reg_val, reg_val);
1360 : :
1361 : 0 : return i40e_aq_debug_write_register(hw, reg_addr, reg_val, cmd_details);
1362 : : }
1363 : :
1364 : : static int
1365 : 0 : read_vf_msg_config(__rte_unused const char *key,
1366 : : const char *value,
1367 : : void *opaque)
1368 : : {
1369 : : struct i40e_vf_msg_cfg *cfg = opaque;
1370 : :
1371 [ # # ]: 0 : if (sscanf(value, "%u@%u:%u", &cfg->max_msg, &cfg->period,
1372 : : &cfg->ignore_second) != 3) {
1373 : : memset(cfg, 0, sizeof(*cfg));
1374 : 0 : PMD_DRV_LOG(ERR, "format error! example: "
1375 : : "%s=60@120:180", ETH_I40E_VF_MSG_CFG);
1376 : 0 : return -EINVAL;
1377 : : }
1378 : :
1379 : : /*
1380 : : * If the message validation function been enabled, the 'period'
1381 : : * and 'ignore_second' must greater than 0.
1382 : : */
1383 [ # # # # : 0 : if (cfg->max_msg && (!cfg->period || !cfg->ignore_second)) {
# # ]
1384 : : memset(cfg, 0, sizeof(*cfg));
1385 : 0 : PMD_DRV_LOG(ERR, "%s error! the second and third"
1386 : : " number must be greater than 0!",
1387 : : ETH_I40E_VF_MSG_CFG);
1388 : 0 : return -EINVAL;
1389 : : }
1390 : :
1391 : : return 0;
1392 : : }
1393 : :
1394 : : static int
1395 : 0 : read_mbuf_check_config(__rte_unused const char *key, const char *value, void *args)
1396 : : {
1397 : : char *cur;
1398 : : char *tmp;
1399 : : int str_len;
1400 : : int valid_len;
1401 : :
1402 : : int ret = 0;
1403 : : uint64_t *mc_flags = args;
1404 : 0 : char *str2 = strdup(value);
1405 [ # # ]: 0 : if (str2 == NULL)
1406 : : return -1;
1407 : :
1408 : 0 : str_len = strlen(str2);
1409 [ # # ]: 0 : if (str_len == 0) {
1410 : : ret = -1;
1411 : 0 : goto err_end;
1412 : : }
1413 : :
1414 : : /* Try stripping the outer square brackets of the parameter string. */
1415 : : str_len = strlen(str2);
1416 [ # # # # ]: 0 : if (str2[0] == '[' && str2[str_len - 1] == ']') {
1417 [ # # ]: 0 : if (str_len < 3) {
1418 : : ret = -1;
1419 : 0 : goto err_end;
1420 : : }
1421 : 0 : valid_len = str_len - 2;
1422 : 0 : memmove(str2, str2 + 1, valid_len);
1423 : 0 : memset(str2 + valid_len, '\0', 2);
1424 : : }
1425 : :
1426 : 0 : cur = strtok_r(str2, ",", &tmp);
1427 [ # # ]: 0 : while (cur != NULL) {
1428 [ # # ]: 0 : if (!strcmp(cur, "mbuf"))
1429 : 0 : *mc_flags |= I40E_MBUF_CHECK_F_TX_MBUF;
1430 [ # # ]: 0 : else if (!strcmp(cur, "size"))
1431 : 0 : *mc_flags |= I40E_MBUF_CHECK_F_TX_SIZE;
1432 [ # # ]: 0 : else if (!strcmp(cur, "segment"))
1433 : 0 : *mc_flags |= I40E_MBUF_CHECK_F_TX_SEGMENT;
1434 [ # # ]: 0 : else if (!strcmp(cur, "offload"))
1435 : 0 : *mc_flags |= I40E_MBUF_CHECK_F_TX_OFFLOAD;
1436 : : else
1437 : 0 : PMD_DRV_LOG(ERR, "Unsupported diagnostic type: %s", cur);
1438 : 0 : cur = strtok_r(NULL, ",", &tmp);
1439 : : }
1440 : :
1441 : 0 : err_end:
1442 : 0 : free(str2);
1443 : 0 : return ret;
1444 : : }
1445 : :
1446 : : static int
1447 : 0 : i40e_parse_mbuf_check(struct rte_eth_dev *dev)
1448 : : {
1449 : 0 : struct i40e_adapter *ad =
1450 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1451 : : struct rte_kvargs *kvlist;
1452 : : int kvargs_count;
1453 : : int ret = 0;
1454 : :
1455 [ # # ]: 0 : if (!dev->device->devargs)
1456 : : return ret;
1457 : :
1458 : 0 : kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
1459 [ # # ]: 0 : if (!kvlist)
1460 : : return -EINVAL;
1461 : :
1462 : 0 : kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_MBUF_CHECK_ARG);
1463 [ # # ]: 0 : if (!kvargs_count)
1464 : 0 : goto free_end;
1465 : :
1466 [ # # ]: 0 : if (kvargs_count > 1) {
1467 : 0 : PMD_DRV_LOG(ERR, "More than one argument \"%s\"!",
1468 : : ETH_I40E_MBUF_CHECK_ARG);
1469 : : ret = -EINVAL;
1470 : 0 : goto free_end;
1471 : : }
1472 : :
1473 [ # # ]: 0 : if (rte_kvargs_process(kvlist, ETH_I40E_MBUF_CHECK_ARG,
1474 : 0 : read_mbuf_check_config, &ad->mbuf_check) < 0)
1475 : : ret = -EINVAL;
1476 : :
1477 : 0 : free_end:
1478 : 0 : rte_kvargs_free(kvlist);
1479 : 0 : return ret;
1480 : : }
1481 : :
1482 : : static int
1483 [ # # ]: 0 : i40e_parse_vf_msg_config(struct rte_eth_dev *dev,
1484 : : struct i40e_vf_msg_cfg *msg_cfg)
1485 : : {
1486 : : struct rte_kvargs *kvlist;
1487 : : int kvargs_count;
1488 : : int ret = 0;
1489 : :
1490 : : memset(msg_cfg, 0, sizeof(*msg_cfg));
1491 : :
1492 [ # # ]: 0 : if (!dev->device->devargs)
1493 : : return ret;
1494 : :
1495 : 0 : kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
1496 [ # # ]: 0 : if (!kvlist)
1497 : : return -EINVAL;
1498 : :
1499 : 0 : kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_VF_MSG_CFG);
1500 [ # # ]: 0 : if (!kvargs_count)
1501 : 0 : goto free_end;
1502 : :
1503 [ # # ]: 0 : if (kvargs_count > 1) {
1504 : 0 : PMD_DRV_LOG(ERR, "More than one argument \"%s\"!",
1505 : : ETH_I40E_VF_MSG_CFG);
1506 : : ret = -EINVAL;
1507 : 0 : goto free_end;
1508 : : }
1509 : :
1510 [ # # ]: 0 : if (rte_kvargs_process(kvlist, ETH_I40E_VF_MSG_CFG,
1511 : : read_vf_msg_config, msg_cfg) < 0)
1512 : : ret = -EINVAL;
1513 : :
1514 : 0 : free_end:
1515 : 0 : rte_kvargs_free(kvlist);
1516 : 0 : return ret;
1517 : : }
1518 : :
1519 : : #define I40E_ALARM_INTERVAL 50000 /* us */
1520 : :
1521 : : static int
1522 : 0 : eth_i40e_dev_init(struct rte_eth_dev *dev, void *init_params __rte_unused)
1523 : : {
1524 : : struct rte_pci_device *pci_dev;
1525 : : struct rte_intr_handle *intr_handle;
1526 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1527 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1528 : : struct i40e_vsi *vsi;
1529 : : int ret;
1530 : : uint32_t len, val;
1531 : 0 : uint8_t aq_fail = 0;
1532 : :
1533 : 0 : PMD_INIT_FUNC_TRACE();
1534 : :
1535 : 0 : dev->dev_ops = &i40e_eth_dev_ops;
1536 : 0 : dev->rx_queue_count = i40e_dev_rx_queue_count;
1537 : 0 : dev->rx_descriptor_status = i40e_dev_rx_descriptor_status;
1538 : 0 : dev->tx_descriptor_status = i40e_dev_tx_descriptor_status;
1539 : 0 : dev->rx_pkt_burst = i40e_recv_pkts;
1540 : 0 : dev->tx_pkt_burst = i40e_xmit_pkts;
1541 : 0 : dev->tx_pkt_prepare = i40e_prep_pkts;
1542 : :
1543 : : /* for secondary processes, we don't initialise any further as primary
1544 : : * has already done this work. Only check we don't need a different
1545 : : * RX function */
1546 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY){
1547 : 0 : i40e_set_rx_function(dev);
1548 : 0 : i40e_set_tx_function(dev);
1549 : 0 : return 0;
1550 : : }
1551 : 0 : i40e_set_default_ptype_table(dev);
1552 : 0 : pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1553 : 0 : intr_handle = pci_dev->intr_handle;
1554 : :
1555 : 0 : rte_eth_copy_pci_info(dev, pci_dev);
1556 : :
1557 : 0 : pf->adapter = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1558 : 0 : pf->dev_data = dev->data;
1559 : :
1560 : 0 : hw->back = I40E_PF_TO_ADAPTER(pf);
1561 : 0 : hw->hw_addr = (uint8_t *)(pci_dev->mem_resource[0].addr);
1562 [ # # ]: 0 : if (!hw->hw_addr) {
1563 : 0 : PMD_INIT_LOG(ERR,
1564 : : "Hardware is not available, as address is NULL");
1565 : 0 : return -ENODEV;
1566 : : }
1567 : :
1568 : 0 : hw->vendor_id = pci_dev->id.vendor_id;
1569 : 0 : hw->device_id = pci_dev->id.device_id;
1570 : 0 : hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
1571 : 0 : hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
1572 : 0 : hw->bus.device = pci_dev->addr.devid;
1573 : 0 : hw->bus.func = pci_dev->addr.function;
1574 : 0 : hw->adapter_stopped = 0;
1575 : 0 : hw->adapter_closed = 0;
1576 : :
1577 : : /* Init switch device pointer */
1578 : 0 : hw->switch_dev = NULL;
1579 : :
1580 : : /*
1581 : : * Switch Tag value should not be identical to either the First Tag
1582 : : * or Second Tag values. So set something other than common Ethertype
1583 : : * for internal switching.
1584 : : */
1585 : 0 : hw->switch_tag = 0xffff;
1586 : :
1587 : : val = I40E_READ_REG(hw, I40E_GL_FWSTS);
1588 [ # # ]: 0 : if (val & I40E_GL_FWSTS_FWS1B_MASK) {
1589 : 0 : PMD_INIT_LOG(ERR, "ERROR: Firmware recovery mode detected. Limiting functionality.");
1590 : 0 : return -EIO;
1591 : : }
1592 : :
1593 : 0 : i40e_parse_vf_msg_config(dev, &pf->vf_msg_cfg);
1594 : 0 : i40e_parse_mbuf_check(dev);
1595 : : /* Check if need to support multi-driver */
1596 : 0 : i40e_support_multi_driver(dev);
1597 : :
1598 : : /* Make sure all is clean before doing PF reset */
1599 : 0 : i40e_clear_hw(hw);
1600 : :
1601 : : /* Reset here to make sure all is clean for each PF */
1602 : 0 : ret = i40e_pf_reset(hw);
1603 [ # # ]: 0 : if (ret) {
1604 : 0 : PMD_INIT_LOG(ERR, "Failed to reset pf: %d", ret);
1605 : 0 : return ret;
1606 : : }
1607 : :
1608 : : /* Initialize the shared code (base driver) */
1609 : 0 : ret = i40e_init_shared_code(hw);
1610 [ # # ]: 0 : if (ret) {
1611 : 0 : PMD_INIT_LOG(ERR, "Failed to init shared code (base driver): %d", ret);
1612 : 0 : return ret;
1613 : : }
1614 : :
1615 : : /* Initialize the parameters for adminq */
1616 : : i40e_init_adminq_parameter(hw);
1617 : 0 : ret = i40e_init_adminq(hw);
1618 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1619 : 0 : PMD_INIT_LOG(ERR, "Failed to init adminq: %d", ret);
1620 : 0 : return -EIO;
1621 : : }
1622 : : /* Firmware of SFP x722 does not support 802.1ad frames ability */
1623 [ # # ]: 0 : if (hw->device_id == I40E_DEV_ID_SFP_X722 ||
1624 : : hw->device_id == I40E_DEV_ID_SFP_I_X722)
1625 : 0 : hw->flags &= ~I40E_HW_FLAG_802_1AD_CAPABLE;
1626 : :
1627 : 0 : PMD_INIT_LOG(INFO, "FW %d.%d API %d.%d NVM %02d.%02d.%02d eetrack %04x",
1628 : : hw->aq.fw_maj_ver, hw->aq.fw_min_ver,
1629 : : hw->aq.api_maj_ver, hw->aq.api_min_ver,
1630 : : ((hw->nvm.version >> 12) & 0xf),
1631 : : ((hw->nvm.version >> 4) & 0xff),
1632 : : (hw->nvm.version & 0xf), hw->nvm.eetrack);
1633 : :
1634 : : /* Initialize the hardware */
1635 : 0 : i40e_hw_init(dev);
1636 : :
1637 : : i40e_config_automask(pf);
1638 : :
1639 : 0 : i40e_set_default_pctype_table(dev);
1640 : :
1641 : : /*
1642 : : * To work around the NVM issue, initialize registers
1643 : : * for packet type of QinQ by software.
1644 : : * It should be removed once issues are fixed in NVM.
1645 : : */
1646 [ # # ]: 0 : if (!pf->support_multi_driver)
1647 : 0 : i40e_GLQF_reg_init(hw);
1648 : :
1649 : : /* Initialize the input set for filters (hash and fd) to default value */
1650 : 0 : i40e_filter_input_set_init(pf);
1651 : :
1652 : : /* initialise the L3_MAP register */
1653 [ # # ]: 0 : if (!pf->support_multi_driver) {
1654 : 0 : ret = i40e_aq_debug_write_global_register(hw,
1655 : : I40E_GLQF_L3_MAP(40),
1656 : : 0x00000028, NULL);
1657 [ # # ]: 0 : if (ret)
1658 : 0 : PMD_INIT_LOG(ERR, "Failed to write L3 MAP register %d",
1659 : : ret);
1660 : 0 : PMD_INIT_LOG(DEBUG,
1661 : : "Global register 0x%08x is changed with 0x28",
1662 : : I40E_GLQF_L3_MAP(40));
1663 : : }
1664 : :
1665 : : /* Need the special FW version to support floating VEB */
1666 : 0 : config_floating_veb(dev);
1667 : : /* Clear PXE mode */
1668 : 0 : i40e_clear_pxe_mode(hw);
1669 : 0 : i40e_dev_sync_phy_type(hw);
1670 : :
1671 : : /*
1672 : : * On X710, performance number is far from the expectation on recent
1673 : : * firmware versions. The fix for this issue may not be integrated in
1674 : : * the following firmware version. So the workaround in software driver
1675 : : * is needed. It needs to modify the initial values of 3 internal only
1676 : : * registers. Note that the workaround can be removed when it is fixed
1677 : : * in firmware in the future.
1678 : : */
1679 : 0 : i40e_configure_registers(hw);
1680 : :
1681 : : /* Get hw capabilities */
1682 : 0 : ret = i40e_get_cap(hw);
1683 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1684 : 0 : PMD_INIT_LOG(ERR, "Failed to get capabilities: %d", ret);
1685 : 0 : goto err_get_capabilities;
1686 : : }
1687 : :
1688 : : /* Initialize parameters for PF */
1689 : 0 : ret = i40e_pf_parameter_init(dev);
1690 [ # # ]: 0 : if (ret != 0) {
1691 : 0 : PMD_INIT_LOG(ERR, "Failed to do parameter init: %d", ret);
1692 : 0 : goto err_parameter_init;
1693 : : }
1694 : :
1695 : : /* Initialize the queue management */
1696 : 0 : ret = i40e_res_pool_init(&pf->qp_pool, 0, hw->func_caps.num_tx_qp);
1697 [ # # ]: 0 : if (ret < 0) {
1698 : 0 : PMD_INIT_LOG(ERR, "Failed to init queue pool");
1699 : 0 : goto err_qp_pool_init;
1700 : : }
1701 : 0 : ret = i40e_res_pool_init(&pf->msix_pool, 1,
1702 : 0 : hw->func_caps.num_msix_vectors - 1);
1703 [ # # ]: 0 : if (ret < 0) {
1704 : 0 : PMD_INIT_LOG(ERR, "Failed to init MSIX pool");
1705 : 0 : goto err_msix_pool_init;
1706 : : }
1707 : :
1708 : : /* Initialize lan hmc */
1709 : 0 : ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
1710 : : hw->func_caps.num_rx_qp, 0, 0);
1711 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1712 : 0 : PMD_INIT_LOG(ERR, "Failed to init lan hmc: %d", ret);
1713 : 0 : goto err_init_lan_hmc;
1714 : : }
1715 : :
1716 : : /* Configure lan hmc */
1717 : 0 : ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
1718 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1719 : 0 : PMD_INIT_LOG(ERR, "Failed to configure lan hmc: %d", ret);
1720 : 0 : goto err_configure_lan_hmc;
1721 : : }
1722 : :
1723 : : /* Get and check the mac address */
1724 : 0 : i40e_get_mac_addr(hw, hw->mac.addr);
1725 [ # # ]: 0 : if (i40e_validate_mac_addr(hw->mac.addr) != I40E_SUCCESS) {
1726 : 0 : PMD_INIT_LOG(ERR, "mac address is not valid");
1727 : : ret = -EIO;
1728 : 0 : goto err_get_mac_addr;
1729 : : }
1730 : : /* Copy the permanent MAC address */
1731 : : rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
1732 : : (struct rte_ether_addr *)hw->mac.perm_addr);
1733 : :
1734 : : /* Disable flow control */
1735 : 0 : hw->fc.requested_mode = I40E_FC_NONE;
1736 : 0 : i40e_set_fc(hw, &aq_fail, TRUE);
1737 : :
1738 : : /* Set the global registers with default ether type value */
1739 [ # # ]: 0 : if (!pf->support_multi_driver) {
1740 : 0 : ret = i40e_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_OUTER,
1741 : : RTE_ETHER_TYPE_VLAN);
1742 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1743 : 0 : PMD_INIT_LOG(ERR,
1744 : : "Failed to set the default outer "
1745 : : "VLAN ether type");
1746 : 0 : goto err_setup_pf_switch;
1747 : : }
1748 : : }
1749 : :
1750 : : /* PF setup, which includes VSI setup */
1751 : 0 : ret = i40e_pf_setup(pf);
1752 [ # # ]: 0 : if (ret) {
1753 : 0 : PMD_INIT_LOG(ERR, "Failed to setup pf switch: %d", ret);
1754 : 0 : goto err_setup_pf_switch;
1755 : : }
1756 : :
1757 : 0 : vsi = pf->main_vsi;
1758 : :
1759 : : /* Disable double vlan by default */
1760 : : i40e_vsi_config_double_vlan(vsi, FALSE);
1761 : :
1762 : : /* Disable S-TAG identification when floating_veb is disabled */
1763 [ # # ]: 0 : if (!pf->floating_veb) {
1764 : 0 : ret = I40E_READ_REG(hw, I40E_PRT_L2TAGSEN);
1765 [ # # ]: 0 : if (ret & I40E_L2_TAGS_S_TAG_MASK) {
1766 : 0 : ret &= ~I40E_L2_TAGS_S_TAG_MASK;
1767 : 0 : I40E_WRITE_REG(hw, I40E_PRT_L2TAGSEN, ret);
1768 : : }
1769 : : }
1770 : :
1771 [ # # ]: 0 : if (!vsi->max_macaddrs)
1772 : : len = RTE_ETHER_ADDR_LEN;
1773 : : else
1774 : 0 : len = RTE_ETHER_ADDR_LEN * vsi->max_macaddrs;
1775 : :
1776 : : /* Should be after VSI initialized */
1777 : 0 : dev->data->mac_addrs = rte_zmalloc("i40e", len, 0);
1778 [ # # ]: 0 : if (!dev->data->mac_addrs) {
1779 : 0 : PMD_INIT_LOG(ERR,
1780 : : "Failed to allocated memory for storing mac address");
1781 : 0 : goto err_mac_alloc;
1782 : : }
1783 : : rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.perm_addr,
1784 : : &dev->data->mac_addrs[0]);
1785 : :
1786 : : /* Init dcb to sw mode by default */
1787 : 0 : ret = i40e_dcb_init_configure(dev, TRUE);
1788 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1789 : 0 : PMD_INIT_LOG(INFO, "Failed to init dcb.");
1790 : 0 : pf->flags &= ~I40E_FLAG_DCB;
1791 : : }
1792 : : /* Update HW struct after DCB configuration */
1793 : 0 : i40e_get_cap(hw);
1794 : :
1795 : : /* initialize pf host driver to setup SRIOV resource if applicable */
1796 : 0 : i40e_pf_host_init(dev);
1797 : :
1798 : : /* register callback func to eal lib */
1799 : 0 : rte_intr_callback_register(intr_handle,
1800 : : i40e_dev_interrupt_handler, dev);
1801 : :
1802 : : /* configure and enable device interrupt */
1803 : : i40e_pf_config_irq0(hw, TRUE);
1804 : 0 : i40e_pf_enable_irq0(hw);
1805 : :
1806 : : /* enable uio intr after callback register */
1807 : 0 : rte_intr_enable(intr_handle);
1808 : :
1809 : : /* By default disable flexible payload in global configuration */
1810 [ # # ]: 0 : if (!pf->support_multi_driver)
1811 : 0 : i40e_flex_payload_reg_set_default(hw);
1812 : :
1813 : : /*
1814 : : * Add an ethertype filter to drop all flow control frames transmitted
1815 : : * from VSIs. By doing so, we stop VF from sending out PAUSE or PFC
1816 : : * frames to wire.
1817 : : */
1818 : 0 : i40e_add_tx_flow_control_drop_filter(pf);
1819 : :
1820 : : /* initialize RSS rule list */
1821 : 0 : TAILQ_INIT(&pf->rss_config_list);
1822 : :
1823 : : /* initialize Traffic Manager configuration */
1824 : 0 : i40e_tm_conf_init(dev);
1825 : :
1826 : : /* Initialize customized information */
1827 : : i40e_init_customized_info(pf);
1828 : :
1829 : : /* Initialize the filter invalidation configuration */
1830 : 0 : i40e_init_filter_invalidation(pf);
1831 : :
1832 : 0 : ret = i40e_init_ethtype_filter_list(dev);
1833 [ # # ]: 0 : if (ret < 0)
1834 : 0 : goto err_init_ethtype_filter_list;
1835 : 0 : ret = i40e_init_tunnel_filter_list(dev);
1836 [ # # ]: 0 : if (ret < 0)
1837 : 0 : goto err_init_tunnel_filter_list;
1838 : 0 : ret = i40e_init_fdir_filter_list(dev);
1839 [ # # ]: 0 : if (ret < 0)
1840 : 0 : goto err_init_fdir_filter_list;
1841 : :
1842 : : /* initialize queue region configuration */
1843 : 0 : i40e_init_queue_region_conf(dev);
1844 : :
1845 : : /* reset all stats of the device, including pf and main vsi */
1846 : 0 : i40e_dev_stats_reset(dev);
1847 : :
1848 : 0 : return 0;
1849 : :
1850 : : err_init_fdir_filter_list:
1851 : 0 : rte_hash_free(pf->tunnel.hash_table);
1852 : 0 : rte_free(pf->tunnel.hash_map);
1853 : 0 : err_init_tunnel_filter_list:
1854 : 0 : rte_hash_free(pf->ethertype.hash_table);
1855 : 0 : rte_free(pf->ethertype.hash_map);
1856 : 0 : err_init_ethtype_filter_list:
1857 : 0 : rte_intr_callback_unregister(intr_handle,
1858 : : i40e_dev_interrupt_handler, dev);
1859 : 0 : rte_free(dev->data->mac_addrs);
1860 : 0 : dev->data->mac_addrs = NULL;
1861 : 0 : err_mac_alloc:
1862 : 0 : i40e_vsi_release(pf->main_vsi);
1863 : 0 : err_setup_pf_switch:
1864 : 0 : err_get_mac_addr:
1865 : 0 : err_configure_lan_hmc:
1866 : 0 : (void)i40e_shutdown_lan_hmc(hw);
1867 : 0 : err_init_lan_hmc:
1868 : 0 : i40e_res_pool_destroy(&pf->msix_pool);
1869 : 0 : err_msix_pool_init:
1870 : 0 : i40e_res_pool_destroy(&pf->qp_pool);
1871 : 0 : err_qp_pool_init:
1872 : 0 : err_parameter_init:
1873 : 0 : err_get_capabilities:
1874 : 0 : (void)i40e_shutdown_adminq(hw);
1875 : :
1876 : 0 : return ret;
1877 : : }
1878 : :
1879 : : static void
1880 : 0 : i40e_rm_ethtype_filter_list(struct i40e_pf *pf)
1881 : : {
1882 : : struct i40e_ethertype_filter *p_ethertype;
1883 : : struct i40e_ethertype_rule *ethertype_rule;
1884 : :
1885 : : ethertype_rule = &pf->ethertype;
1886 : : /* Remove all ethertype filter rules and hash */
1887 : 0 : rte_free(ethertype_rule->hash_map);
1888 : 0 : rte_hash_free(ethertype_rule->hash_table);
1889 : :
1890 [ # # ]: 0 : while ((p_ethertype = TAILQ_FIRST(ðertype_rule->ethertype_list))) {
1891 [ # # ]: 0 : TAILQ_REMOVE(ðertype_rule->ethertype_list,
1892 : : p_ethertype, rules);
1893 : 0 : rte_free(p_ethertype);
1894 : : }
1895 : 0 : }
1896 : :
1897 : : static void
1898 : 0 : i40e_rm_tunnel_filter_list(struct i40e_pf *pf)
1899 : : {
1900 : : struct i40e_tunnel_filter *p_tunnel;
1901 : : struct i40e_tunnel_rule *tunnel_rule;
1902 : :
1903 : : tunnel_rule = &pf->tunnel;
1904 : : /* Remove all tunnel director rules and hash */
1905 : 0 : rte_free(tunnel_rule->hash_map);
1906 : 0 : rte_hash_free(tunnel_rule->hash_table);
1907 : :
1908 [ # # ]: 0 : while ((p_tunnel = TAILQ_FIRST(&tunnel_rule->tunnel_list))) {
1909 [ # # ]: 0 : TAILQ_REMOVE(&tunnel_rule->tunnel_list, p_tunnel, rules);
1910 : 0 : rte_free(p_tunnel);
1911 : : }
1912 : 0 : }
1913 : :
1914 : : static void
1915 : : i40e_rm_fdir_filter_list(struct i40e_pf *pf)
1916 : : {
1917 : : struct i40e_fdir_filter *p_fdir;
1918 : : struct i40e_fdir_info *fdir_info;
1919 : :
1920 : : fdir_info = &pf->fdir;
1921 : :
1922 : : /* Remove all flow director rules */
1923 [ # # ]: 0 : while ((p_fdir = TAILQ_FIRST(&fdir_info->fdir_list)))
1924 [ # # ]: 0 : TAILQ_REMOVE(&fdir_info->fdir_list, p_fdir, rules);
1925 : : }
1926 : :
1927 : : static void
1928 : 0 : i40e_fdir_memory_cleanup(struct i40e_pf *pf)
1929 : : {
1930 : : struct i40e_fdir_info *fdir_info;
1931 : :
1932 : : fdir_info = &pf->fdir;
1933 : :
1934 : : /* flow director memory cleanup */
1935 : 0 : rte_free(fdir_info->hash_map);
1936 : 0 : rte_hash_free(fdir_info->hash_table);
1937 : 0 : rte_free(fdir_info->fdir_flow_pool.bitmap);
1938 : 0 : rte_free(fdir_info->fdir_flow_pool.pool);
1939 : 0 : rte_free(fdir_info->fdir_filter_array);
1940 : 0 : }
1941 : :
1942 : 0 : void i40e_flex_payload_reg_set_default(struct i40e_hw *hw)
1943 : : {
1944 : : /*
1945 : : * Disable by default flexible payload
1946 : : * for corresponding L2/L3/L4 layers.
1947 : : */
1948 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(33), 0x00000000);
1949 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(34), 0x00000000);
1950 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(35), 0x00000000);
1951 : 0 : }
1952 : :
1953 : : static int
1954 : 0 : eth_i40e_dev_uninit(struct rte_eth_dev *dev)
1955 : : {
1956 : : struct i40e_hw *hw;
1957 : :
1958 : 0 : PMD_INIT_FUNC_TRACE();
1959 : :
1960 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1961 : : return 0;
1962 : :
1963 : 0 : hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1964 : :
1965 [ # # ]: 0 : if (hw->adapter_closed == 0)
1966 : 0 : i40e_dev_close(dev);
1967 : :
1968 : : return 0;
1969 : : }
1970 : :
1971 : : static int
1972 : 0 : i40e_dev_configure(struct rte_eth_dev *dev)
1973 : : {
1974 : 0 : struct i40e_adapter *ad =
1975 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1976 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1977 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1978 : 0 : enum rte_eth_rx_mq_mode mq_mode = dev->data->dev_conf.rxmode.mq_mode;
1979 : : int i, ret;
1980 : :
1981 : 0 : ret = i40e_dev_sync_phy_type(hw);
1982 [ # # ]: 0 : if (ret)
1983 : : return ret;
1984 : :
1985 : : /* Initialize to TRUE. If any of Rx queues doesn't meet the
1986 : : * bulk allocation or vector Rx preconditions we will reset it.
1987 : : */
1988 : 0 : ad->rx_bulk_alloc_allowed = true;
1989 : 0 : ad->rx_vec_allowed = true;
1990 : 0 : ad->tx_simple_allowed = true;
1991 : 0 : ad->tx_vec_allowed = true;
1992 : :
1993 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
1994 : 0 : dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
1995 : :
1996 : 0 : ret = i40e_dev_init_vlan(dev);
1997 [ # # ]: 0 : if (ret < 0)
1998 : 0 : goto err;
1999 : :
2000 : : /* VMDQ setup.
2001 : : * General PMD call sequence are NIC init, configure,
2002 : : * rx/tx_queue_setup and dev_start. In rx/tx_queue_setup() function, it
2003 : : * will try to lookup the VSI that specific queue belongs to if VMDQ
2004 : : * applicable. So, VMDQ setting has to be done before
2005 : : * rx/tx_queue_setup(). This function is good to place vmdq_setup.
2006 : : * For RSS setting, it will try to calculate actual configured RX queue
2007 : : * number, which will be available after rx_queue_setup(). dev_start()
2008 : : * function is good to place RSS setup.
2009 : : */
2010 [ # # ]: 0 : if (mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG) {
2011 : 0 : ret = i40e_vmdq_setup(dev);
2012 [ # # ]: 0 : if (ret)
2013 : 0 : goto err;
2014 : : }
2015 : :
2016 [ # # ]: 0 : if (mq_mode & RTE_ETH_MQ_RX_DCB_FLAG) {
2017 : 0 : ret = i40e_dcb_setup(dev);
2018 [ # # ]: 0 : if (ret) {
2019 : 0 : PMD_DRV_LOG(ERR, "failed to configure DCB.");
2020 : 0 : goto err_dcb;
2021 : : }
2022 : : }
2023 : :
2024 : 0 : TAILQ_INIT(&pf->flow_list);
2025 : :
2026 : 0 : return 0;
2027 : :
2028 : : err_dcb:
2029 : : /* need to release vmdq resource if exists */
2030 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2031 : 0 : i40e_vsi_release(pf->vmdq[i].vsi);
2032 : 0 : pf->vmdq[i].vsi = NULL;
2033 : : }
2034 : 0 : rte_free(pf->vmdq);
2035 : 0 : pf->vmdq = NULL;
2036 : : err:
2037 : : return ret;
2038 : : }
2039 : :
2040 : : void
2041 : 0 : i40e_vsi_queues_unbind_intr(struct i40e_vsi *vsi)
2042 : : {
2043 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
2044 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2045 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2046 : : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2047 : 0 : uint16_t msix_vect = vsi->msix_intr;
2048 : : uint16_t i;
2049 : :
2050 [ # # ]: 0 : for (i = 0; i < vsi->nb_qps; i++) {
2051 : 0 : I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
2052 : 0 : I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
2053 : : rte_wmb();
2054 : : }
2055 : :
2056 [ # # ]: 0 : if (vsi->type != I40E_VSI_SRIOV) {
2057 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle)) {
2058 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
2059 : : I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
2060 : 0 : I40E_WRITE_REG(hw,
2061 : : I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
2062 : : 0);
2063 : : } else {
2064 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
2065 : : I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
2066 : 0 : I40E_WRITE_REG(hw,
2067 : : I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
2068 : : msix_vect - 1), 0);
2069 : : }
2070 : : } else {
2071 : : uint32_t reg;
2072 : 0 : reg = (hw->func_caps.num_msix_vectors_vf - 1) *
2073 : 0 : vsi->user_param + (msix_vect - 1);
2074 : :
2075 : 0 : I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
2076 : : I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
2077 : : }
2078 : 0 : I40E_WRITE_FLUSH(hw);
2079 : 0 : }
2080 : :
2081 : : static void
2082 : 0 : __vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t msix_vect,
2083 : : int base_queue, int nb_queue,
2084 : : uint16_t itr_idx)
2085 : : {
2086 : : int i;
2087 : : uint32_t val;
2088 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2089 : : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2090 : :
2091 : : /* Bind all RX queues to allocated MSIX interrupt */
2092 [ # # ]: 0 : for (i = 0; i < nb_queue; i++) {
2093 : 0 : val = (msix_vect << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
2094 : 0 : itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT |
2095 : 0 : ((base_queue + i + 1) <<
2096 : 0 : I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
2097 : 0 : (0 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
2098 : : I40E_QINT_RQCTL_CAUSE_ENA_MASK;
2099 : :
2100 [ # # ]: 0 : if (i == nb_queue - 1)
2101 : 0 : val |= I40E_QINT_RQCTL_NEXTQ_INDX_MASK;
2102 : 0 : I40E_WRITE_REG(hw, I40E_QINT_RQCTL(base_queue + i), val);
2103 : : }
2104 : :
2105 : : /* Write first RX queue to Link list register as the head element */
2106 [ # # ]: 0 : if (vsi->type != I40E_VSI_SRIOV) {
2107 : : uint16_t interval =
2108 : : i40e_calc_itr_interval(1, pf->support_multi_driver);
2109 : :
2110 [ # # ]: 0 : if (msix_vect == I40E_MISC_VEC_ID) {
2111 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
2112 : : (base_queue <<
2113 : : I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
2114 : : (0x0 <<
2115 : : I40E_PFINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
2116 : 0 : I40E_WRITE_REG(hw,
2117 : : I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
2118 : : interval);
2119 : : } else {
2120 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
2121 : : (base_queue <<
2122 : : I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
2123 : : (0x0 <<
2124 : : I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
2125 : 0 : I40E_WRITE_REG(hw,
2126 : : I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
2127 : : msix_vect - 1),
2128 : : interval);
2129 : : }
2130 : : } else {
2131 : : uint32_t reg;
2132 : :
2133 [ # # ]: 0 : if (msix_vect == I40E_MISC_VEC_ID) {
2134 : 0 : I40E_WRITE_REG(hw,
2135 : : I40E_VPINT_LNKLST0(vsi->user_param),
2136 : : (base_queue <<
2137 : : I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
2138 : : (0x0 <<
2139 : : I40E_VPINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
2140 : : } else {
2141 : : /* num_msix_vectors_vf needs to minus irq0 */
2142 : 0 : reg = (hw->func_caps.num_msix_vectors_vf - 1) *
2143 : 0 : vsi->user_param + (msix_vect - 1);
2144 : :
2145 : 0 : I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
2146 : : (base_queue <<
2147 : : I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
2148 : : (0x0 <<
2149 : : I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
2150 : : }
2151 : : }
2152 : :
2153 : 0 : I40E_WRITE_FLUSH(hw);
2154 : 0 : }
2155 : :
2156 : : int
2157 : 0 : i40e_vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t itr_idx)
2158 : : {
2159 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
2160 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2161 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2162 : : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2163 : 0 : uint16_t msix_vect = vsi->msix_intr;
2164 : 0 : uint16_t nb_msix = RTE_MIN(vsi->nb_msix,
2165 : : rte_intr_nb_efd_get(intr_handle));
2166 : : uint16_t queue_idx = 0;
2167 : : int record = 0;
2168 : : int i;
2169 : :
2170 [ # # ]: 0 : for (i = 0; i < vsi->nb_qps; i++) {
2171 : 0 : I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
2172 : 0 : I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
2173 : : }
2174 : :
2175 : : /* VF bind interrupt */
2176 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
2177 [ # # ]: 0 : if (vsi->nb_msix == 0) {
2178 : 0 : PMD_DRV_LOG(ERR, "No msix resource");
2179 : 0 : return -EINVAL;
2180 : : }
2181 : 0 : __vsi_queues_bind_intr(vsi, msix_vect,
2182 : 0 : vsi->base_queue, vsi->nb_qps,
2183 : : itr_idx);
2184 : 0 : return 0;
2185 : : }
2186 : :
2187 : : /* PF & VMDq bind interrupt */
2188 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
2189 [ # # ]: 0 : if (vsi->type == I40E_VSI_MAIN) {
2190 : : queue_idx = 0;
2191 : : record = 1;
2192 [ # # ]: 0 : } else if (vsi->type == I40E_VSI_VMDQ2) {
2193 : : struct i40e_vsi *main_vsi =
2194 [ # # ]: 0 : I40E_DEV_PRIVATE_TO_MAIN_VSI(vsi->adapter);
2195 : 0 : queue_idx = vsi->base_queue - main_vsi->nb_qps;
2196 : : record = 1;
2197 : : }
2198 : : }
2199 : :
2200 [ # # ]: 0 : for (i = 0; i < vsi->nb_used_qps; i++) {
2201 [ # # ]: 0 : if (vsi->nb_msix == 0) {
2202 : 0 : PMD_DRV_LOG(ERR, "No msix resource");
2203 : 0 : return -EINVAL;
2204 [ # # ]: 0 : } else if (nb_msix <= 1) {
2205 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle))
2206 : : /* allow to share MISC_VEC_ID */
2207 : : msix_vect = I40E_MISC_VEC_ID;
2208 : :
2209 : : /* no enough msix_vect, map all to one */
2210 : 0 : __vsi_queues_bind_intr(vsi, msix_vect,
2211 : 0 : vsi->base_queue + i,
2212 : 0 : vsi->nb_used_qps - i,
2213 : : itr_idx);
2214 [ # # # # ]: 0 : for (; !!record && i < vsi->nb_used_qps; i++)
2215 : 0 : rte_intr_vec_list_index_set(intr_handle,
2216 : : queue_idx + i, msix_vect);
2217 : : break;
2218 : : }
2219 : : /* 1:1 queue/msix_vect mapping */
2220 : 0 : __vsi_queues_bind_intr(vsi, msix_vect,
2221 : 0 : vsi->base_queue + i, 1,
2222 : : itr_idx);
2223 [ # # ]: 0 : if (!!record)
2224 [ # # ]: 0 : if (rte_intr_vec_list_index_set(intr_handle,
2225 : : queue_idx + i, msix_vect))
2226 : 0 : return -rte_errno;
2227 : :
2228 : 0 : msix_vect++;
2229 : 0 : nb_msix--;
2230 : : }
2231 : :
2232 : : return 0;
2233 : : }
2234 : :
2235 : : void
2236 : 0 : i40e_vsi_enable_queues_intr(struct i40e_vsi *vsi)
2237 : : {
2238 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
2239 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2240 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2241 : : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2242 : : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2243 : : uint16_t msix_intr, i;
2244 : :
2245 [ # # # # ]: 0 : if (rte_intr_allow_others(intr_handle) && !pf->support_multi_driver)
2246 [ # # ]: 0 : for (i = 0; i < vsi->nb_msix; i++) {
2247 : 0 : msix_intr = vsi->msix_intr + i;
2248 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
2249 : : I40E_PFINT_DYN_CTLN_INTENA_MASK |
2250 : : I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
2251 : : I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
2252 : : }
2253 : : else
2254 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
2255 : : I40E_PFINT_DYN_CTL0_INTENA_MASK |
2256 : : I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
2257 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
2258 : :
2259 : 0 : I40E_WRITE_FLUSH(hw);
2260 : 0 : }
2261 : :
2262 : : void
2263 : 0 : i40e_vsi_disable_queues_intr(struct i40e_vsi *vsi)
2264 : : {
2265 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
2266 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2267 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2268 : : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2269 : : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2270 : : uint16_t msix_intr, i;
2271 : :
2272 [ # # # # ]: 0 : if (rte_intr_allow_others(intr_handle) && !pf->support_multi_driver)
2273 [ # # ]: 0 : for (i = 0; i < vsi->nb_msix; i++) {
2274 : 0 : msix_intr = vsi->msix_intr + i;
2275 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
2276 : : I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
2277 : : }
2278 : : else
2279 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
2280 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
2281 : :
2282 : 0 : I40E_WRITE_FLUSH(hw);
2283 : 0 : }
2284 : :
2285 : : static inline uint8_t
2286 : 0 : i40e_parse_link_speeds(uint16_t link_speeds)
2287 : : {
2288 : : uint8_t link_speed = I40E_LINK_SPEED_UNKNOWN;
2289 : :
2290 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_40G)
2291 : : link_speed |= I40E_LINK_SPEED_40GB;
2292 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_25G)
2293 : 0 : link_speed |= I40E_LINK_SPEED_25GB;
2294 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_20G)
2295 : 0 : link_speed |= I40E_LINK_SPEED_20GB;
2296 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_10G)
2297 : 0 : link_speed |= I40E_LINK_SPEED_10GB;
2298 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_1G)
2299 : 0 : link_speed |= I40E_LINK_SPEED_1GB;
2300 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_100M)
2301 : 0 : link_speed |= I40E_LINK_SPEED_100MB;
2302 : :
2303 : 0 : return link_speed;
2304 : : }
2305 : :
2306 : : static int
2307 : 0 : i40e_phy_conf_link(struct i40e_hw *hw,
2308 : : uint8_t abilities,
2309 : : uint8_t force_speed,
2310 : : bool is_up)
2311 : : {
2312 : : enum i40e_status_code status;
2313 : : struct i40e_aq_get_phy_abilities_resp phy_ab;
2314 : : struct i40e_aq_set_phy_config phy_conf;
2315 : : enum i40e_aq_phy_type cnt;
2316 : : uint8_t avail_speed;
2317 : : uint32_t phy_type_mask = 0;
2318 : :
2319 : : const uint8_t mask = I40E_AQ_PHY_FLAG_PAUSE_TX |
2320 : : I40E_AQ_PHY_FLAG_PAUSE_RX |
2321 : : I40E_AQ_PHY_FLAG_PAUSE_RX |
2322 : : I40E_AQ_PHY_FLAG_LOW_POWER;
2323 : : int ret = -ENOTSUP;
2324 : :
2325 : : /* To get phy capabilities of available speeds. */
2326 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, true, &phy_ab,
2327 : : NULL);
2328 [ # # ]: 0 : if (status) {
2329 : 0 : PMD_DRV_LOG(ERR, "Failed to get PHY capabilities: %d",
2330 : : status);
2331 : 0 : return ret;
2332 : : }
2333 : 0 : avail_speed = phy_ab.link_speed;
2334 : :
2335 : : /* To get the current phy config. */
2336 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, false, &phy_ab,
2337 : : NULL);
2338 [ # # ]: 0 : if (status) {
2339 : 0 : PMD_DRV_LOG(ERR, "Failed to get the current PHY config: %d",
2340 : : status);
2341 : 0 : return ret;
2342 : : }
2343 : :
2344 : : /* If link needs to go up and it is in autoneg mode the speed is OK,
2345 : : * no need to set up again.
2346 : : */
2347 [ # # # # : 0 : if (is_up && phy_ab.phy_type != 0 &&
# # ]
2348 : 0 : abilities & I40E_AQ_PHY_AN_ENABLED &&
2349 [ # # ]: 0 : phy_ab.link_speed != 0)
2350 : : return I40E_SUCCESS;
2351 : :
2352 : : memset(&phy_conf, 0, sizeof(phy_conf));
2353 : :
2354 : : /* bits 0-2 use the values from get_phy_abilities_resp */
2355 : 0 : abilities &= ~mask;
2356 : 0 : abilities |= phy_ab.abilities & mask;
2357 : :
2358 : 0 : phy_conf.abilities = abilities;
2359 : :
2360 : : /* If link needs to go up, but the force speed is not supported,
2361 : : * Warn users and config the default available speeds.
2362 : : */
2363 [ # # # # ]: 0 : if (is_up && !(force_speed & avail_speed)) {
2364 : 0 : PMD_DRV_LOG(WARNING, "Invalid speed setting, set to default!");
2365 : 0 : phy_conf.link_speed = avail_speed;
2366 : : } else {
2367 [ # # ]: 0 : phy_conf.link_speed = is_up ? force_speed : avail_speed;
2368 : : }
2369 : :
2370 : : /* PHY type mask needs to include each type except PHY type extension */
2371 [ # # ]: 0 : for (cnt = I40E_PHY_TYPE_SGMII; cnt < I40E_PHY_TYPE_25GBASE_KR; cnt++)
2372 : 0 : phy_type_mask |= 1 << cnt;
2373 : :
2374 : : /* use get_phy_abilities_resp value for the rest */
2375 [ # # ]: 0 : phy_conf.phy_type = is_up ? cpu_to_le32(phy_type_mask) : 0;
2376 [ # # ]: 0 : phy_conf.phy_type_ext = is_up ? (I40E_AQ_PHY_TYPE_EXT_25G_KR |
2377 : : I40E_AQ_PHY_TYPE_EXT_25G_CR | I40E_AQ_PHY_TYPE_EXT_25G_SR |
2378 : : I40E_AQ_PHY_TYPE_EXT_25G_LR | I40E_AQ_PHY_TYPE_EXT_25G_AOC |
2379 : : I40E_AQ_PHY_TYPE_EXT_25G_ACC) : 0;
2380 : 0 : phy_conf.fec_config = phy_ab.fec_cfg_curr_mod_ext_info;
2381 : 0 : phy_conf.eee_capability = phy_ab.eee_capability;
2382 : 0 : phy_conf.eeer = phy_ab.eeer_val;
2383 : 0 : phy_conf.low_power_ctrl = phy_ab.d3_lpan;
2384 : :
2385 : 0 : PMD_DRV_LOG(DEBUG, "\tCurrent: abilities %x, link_speed %x",
2386 : : phy_ab.abilities, phy_ab.link_speed);
2387 : 0 : PMD_DRV_LOG(DEBUG, "\tConfig: abilities %x, link_speed %x",
2388 : : phy_conf.abilities, phy_conf.link_speed);
2389 : :
2390 : 0 : status = i40e_aq_set_phy_config(hw, &phy_conf, NULL);
2391 [ # # ]: 0 : if (status)
2392 : 0 : return ret;
2393 : :
2394 : : return I40E_SUCCESS;
2395 : : }
2396 : :
2397 : : static int
2398 : 0 : i40e_apply_link_speed(struct rte_eth_dev *dev)
2399 : : {
2400 : : uint8_t speed;
2401 : : uint8_t abilities = 0;
2402 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2403 : : struct rte_eth_conf *conf = &dev->data->dev_conf;
2404 : :
2405 : : abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK |
2406 : : I40E_AQ_PHY_LINK_ENABLED;
2407 : :
2408 [ # # ]: 0 : if (conf->link_speeds == RTE_ETH_LINK_SPEED_AUTONEG) {
2409 : 0 : conf->link_speeds = RTE_ETH_LINK_SPEED_40G |
2410 : : RTE_ETH_LINK_SPEED_25G |
2411 : : RTE_ETH_LINK_SPEED_20G |
2412 : : RTE_ETH_LINK_SPEED_10G |
2413 : : RTE_ETH_LINK_SPEED_1G |
2414 : : RTE_ETH_LINK_SPEED_100M;
2415 : :
2416 : : abilities |= I40E_AQ_PHY_AN_ENABLED;
2417 : : } else {
2418 : : abilities &= ~I40E_AQ_PHY_AN_ENABLED;
2419 : : }
2420 : 0 : speed = i40e_parse_link_speeds(conf->link_speeds);
2421 : :
2422 : 0 : return i40e_phy_conf_link(hw, abilities, speed, true);
2423 : : }
2424 : :
2425 : : static int
2426 : 0 : i40e_dev_start(struct rte_eth_dev *dev)
2427 : : {
2428 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2429 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2430 : 0 : struct i40e_vsi *main_vsi = pf->main_vsi;
2431 : : struct i40e_adapter *ad =
2432 : : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2433 : : int ret, i;
2434 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2435 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2436 : : uint32_t intr_vector = 0;
2437 : : struct i40e_vsi *vsi;
2438 : : uint16_t nb_rxq, nb_txq;
2439 : : uint16_t max_frame_size;
2440 : :
2441 : 0 : hw->adapter_stopped = 0;
2442 : :
2443 : 0 : rte_intr_disable(intr_handle);
2444 : :
2445 [ # # ]: 0 : if ((rte_intr_cap_multiple(intr_handle) ||
2446 [ # # ]: 0 : !RTE_ETH_DEV_SRIOV(dev).active) &&
2447 [ # # ]: 0 : dev->data->dev_conf.intr_conf.rxq != 0) {
2448 : 0 : intr_vector = dev->data->nb_rx_queues;
2449 : 0 : ret = rte_intr_efd_enable(intr_handle, intr_vector);
2450 [ # # ]: 0 : if (ret)
2451 : : return ret;
2452 : : }
2453 : :
2454 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
2455 [ # # ]: 0 : if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
2456 : 0 : dev->data->nb_rx_queues)) {
2457 : 0 : PMD_INIT_LOG(ERR,
2458 : : "Failed to allocate %d rx_queues intr_vec",
2459 : : dev->data->nb_rx_queues);
2460 : 0 : return -ENOMEM;
2461 : : }
2462 : : }
2463 : :
2464 : : /* Initialize VSI */
2465 : 0 : ret = i40e_dev_rxtx_init(pf);
2466 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2467 : 0 : PMD_DRV_LOG(ERR, "Failed to init rx/tx queues");
2468 : 0 : return ret;
2469 : : }
2470 : :
2471 : : /* Map queues with MSIX interrupt */
2472 : 0 : main_vsi->nb_used_qps = dev->data->nb_rx_queues -
2473 : 0 : pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
2474 : 0 : ret = i40e_vsi_queues_bind_intr(main_vsi, I40E_ITR_INDEX_DEFAULT);
2475 [ # # ]: 0 : if (ret < 0)
2476 : : return ret;
2477 : 0 : i40e_vsi_enable_queues_intr(main_vsi);
2478 : :
2479 : : /* Map VMDQ VSI queues with MSIX interrupt */
2480 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2481 : 0 : pf->vmdq[i].vsi->nb_used_qps = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
2482 : 0 : ret = i40e_vsi_queues_bind_intr(pf->vmdq[i].vsi,
2483 : : I40E_ITR_INDEX_DEFAULT);
2484 [ # # ]: 0 : if (ret < 0)
2485 : 0 : return ret;
2486 : 0 : i40e_vsi_enable_queues_intr(pf->vmdq[i].vsi);
2487 : : }
2488 : :
2489 : : /* Enable all queues which have been configured */
2490 [ # # ]: 0 : for (nb_rxq = 0; nb_rxq < dev->data->nb_rx_queues; nb_rxq++) {
2491 : 0 : ret = i40e_dev_rx_queue_start(dev, nb_rxq);
2492 [ # # ]: 0 : if (ret)
2493 : 0 : goto rx_err;
2494 : : }
2495 : :
2496 [ # # ]: 0 : for (nb_txq = 0; nb_txq < dev->data->nb_tx_queues; nb_txq++) {
2497 : 0 : ret = i40e_dev_tx_queue_start(dev, nb_txq);
2498 [ # # ]: 0 : if (ret)
2499 : 0 : goto tx_err;
2500 : : }
2501 : :
2502 : : /* Enable receiving broadcast packets */
2503 : 0 : ret = i40e_aq_set_vsi_broadcast(hw, main_vsi->seid, true, NULL);
2504 [ # # ]: 0 : if (ret != I40E_SUCCESS)
2505 : 0 : PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
2506 : :
2507 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2508 : 0 : ret = i40e_aq_set_vsi_broadcast(hw, pf->vmdq[i].vsi->seid,
2509 : : true, NULL);
2510 [ # # ]: 0 : if (ret != I40E_SUCCESS)
2511 : 0 : PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
2512 : : }
2513 : :
2514 : : /* Enable the VLAN promiscuous mode. */
2515 [ # # ]: 0 : if (pf->vfs) {
2516 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++) {
2517 : 0 : vsi = pf->vfs[i].vsi;
2518 : 0 : i40e_aq_set_vsi_vlan_promisc(hw, vsi->seid,
2519 : : true, NULL);
2520 : : }
2521 : : }
2522 : :
2523 : : /* Disable mac loopback mode */
2524 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode == I40E_AQ_LB_MODE_NONE) {
2525 : 0 : ret = i40e_aq_set_lb_modes(hw, I40E_AQ_LB_MODE_NONE, NULL);
2526 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2527 : 0 : PMD_DRV_LOG(ERR, "fail to set loopback link");
2528 : 0 : goto tx_err;
2529 : : }
2530 : : }
2531 : :
2532 : : /* Enable mac loopback mode */
2533 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode == I40E_AQ_LB_MODE_EN) {
2534 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
2535 : 0 : ret = i40e_aq_set_lb_modes(hw, I40E_AQ_LB_MAC_LOCAL_X722, NULL);
2536 : : else
2537 : 0 : ret = i40e_aq_set_lb_modes(hw, I40E_AQ_LB_MAC, NULL);
2538 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2539 : 0 : PMD_DRV_LOG(ERR, "fail to set loopback link");
2540 : 0 : goto tx_err;
2541 : : }
2542 : : }
2543 : :
2544 : : /* Apply link configure */
2545 : 0 : ret = i40e_apply_link_speed(dev);
2546 [ # # ]: 0 : if (I40E_SUCCESS != ret) {
2547 : 0 : PMD_DRV_LOG(ERR, "Fail to apply link setting");
2548 : 0 : goto tx_err;
2549 : : }
2550 : :
2551 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle)) {
2552 : 0 : rte_intr_callback_unregister(intr_handle,
2553 : : i40e_dev_interrupt_handler,
2554 : : (void *)dev);
2555 : : /* configure and enable device interrupt */
2556 : : i40e_pf_config_irq0(hw, FALSE);
2557 : 0 : i40e_pf_enable_irq0(hw);
2558 : :
2559 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc != 0)
2560 : 0 : PMD_INIT_LOG(INFO,
2561 : : "lsc won't enable because of no intr multiplex");
2562 : : } else {
2563 : 0 : ret = i40e_aq_set_phy_int_mask(hw,
2564 : : ~(I40E_AQ_EVENT_LINK_UPDOWN |
2565 : : I40E_AQ_EVENT_MODULE_QUAL_FAIL |
2566 : : I40E_AQ_EVENT_MEDIA_NA), NULL);
2567 [ # # ]: 0 : if (ret != I40E_SUCCESS)
2568 : 0 : PMD_DRV_LOG(WARNING, "Fail to set phy mask");
2569 : :
2570 : : /* Call get_link_info aq command to enable/disable LSE */
2571 : 0 : i40e_dev_link_update(dev, 1);
2572 : : }
2573 : :
2574 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq == 0) {
2575 : 0 : rte_eal_alarm_set(I40E_ALARM_INTERVAL,
2576 : : i40e_dev_alarm_handler, dev);
2577 : : } else {
2578 : : /* enable uio intr after callback register */
2579 : 0 : rte_intr_enable(intr_handle);
2580 : : }
2581 : :
2582 : 0 : i40e_filter_restore(pf);
2583 : :
2584 [ # # # # ]: 0 : if (pf->tm_conf.root && !pf->tm_conf.committed)
2585 : 0 : PMD_DRV_LOG(WARNING,
2586 : : "please call hierarchy_commit() "
2587 : : "before starting the port");
2588 : :
2589 [ # # ]: 0 : max_frame_size = dev->data->mtu ?
2590 : : dev->data->mtu + I40E_ETH_OVERHEAD :
2591 : : I40E_FRAME_SIZE_MAX;
2592 : 0 : ad->max_pkt_len = max_frame_size;
2593 : :
2594 : : /* Set the max frame size to HW*/
2595 : 0 : i40e_aq_set_mac_config(hw, max_frame_size, TRUE, false, 0, NULL);
2596 : :
2597 : 0 : return I40E_SUCCESS;
2598 : :
2599 : 0 : tx_err:
2600 [ # # ]: 0 : for (i = 0; i < nb_txq; i++)
2601 : 0 : i40e_dev_tx_queue_stop(dev, i);
2602 : 0 : rx_err:
2603 [ # # ]: 0 : for (i = 0; i < nb_rxq; i++)
2604 : 0 : i40e_dev_rx_queue_stop(dev, i);
2605 : :
2606 : : return ret;
2607 : : }
2608 : :
2609 : : static int
2610 : 0 : i40e_dev_stop(struct rte_eth_dev *dev)
2611 : : {
2612 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2613 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2614 : 0 : struct i40e_vsi *main_vsi = pf->main_vsi;
2615 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2616 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2617 : : int i;
2618 : :
2619 [ # # ]: 0 : if (hw->adapter_stopped == 1)
2620 : : return 0;
2621 : :
2622 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq == 0) {
2623 : 0 : rte_eal_alarm_cancel(i40e_dev_alarm_handler, dev);
2624 : 0 : rte_intr_enable(intr_handle);
2625 : : }
2626 : :
2627 : : /* Disable all queues */
2628 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
2629 : 0 : i40e_dev_tx_queue_stop(dev, i);
2630 : :
2631 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
2632 : 0 : i40e_dev_rx_queue_stop(dev, i);
2633 : :
2634 : : /* un-map queues with interrupt registers */
2635 : 0 : i40e_vsi_disable_queues_intr(main_vsi);
2636 : 0 : i40e_vsi_queues_unbind_intr(main_vsi);
2637 : :
2638 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2639 : 0 : i40e_vsi_disable_queues_intr(pf->vmdq[i].vsi);
2640 : 0 : i40e_vsi_queues_unbind_intr(pf->vmdq[i].vsi);
2641 : : }
2642 : :
2643 : : /* Clear all queues and release memory */
2644 : 0 : i40e_dev_clear_queues(dev);
2645 : :
2646 : : /* Set link down */
2647 : : i40e_dev_set_link_down(dev);
2648 : :
2649 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle))
2650 : : /* resume to the default handler */
2651 : 0 : rte_intr_callback_register(intr_handle,
2652 : : i40e_dev_interrupt_handler,
2653 : : (void *)dev);
2654 : :
2655 : : /* Clean datapath event and queue/vec mapping */
2656 : 0 : rte_intr_efd_disable(intr_handle);
2657 : :
2658 : : /* Cleanup vector list */
2659 : 0 : rte_intr_vec_list_free(intr_handle);
2660 : :
2661 : : /* reset hierarchy commit */
2662 : 0 : pf->tm_conf.committed = false;
2663 : :
2664 : 0 : hw->adapter_stopped = 1;
2665 : 0 : dev->data->dev_started = 0;
2666 : :
2667 : 0 : pf->adapter->rss_reta_updated = 0;
2668 : :
2669 : 0 : return 0;
2670 : : }
2671 : :
2672 : : static int
2673 : 0 : i40e_dev_close(struct rte_eth_dev *dev)
2674 : : {
2675 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2676 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2677 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2678 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2679 : : struct i40e_filter_control_settings settings;
2680 : : struct rte_flow *p_flow;
2681 : : uint32_t reg;
2682 : : int i;
2683 : : int ret;
2684 : 0 : uint8_t aq_fail = 0;
2685 : : int retries = 0;
2686 : :
2687 : 0 : PMD_INIT_FUNC_TRACE();
2688 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2689 : : return 0;
2690 : :
2691 : 0 : ret = rte_eth_switch_domain_free(pf->switch_domain_id);
2692 [ # # ]: 0 : if (ret)
2693 : 0 : PMD_INIT_LOG(WARNING, "failed to free switch domain: %d", ret);
2694 : :
2695 : :
2696 : 0 : ret = i40e_dev_stop(dev);
2697 : :
2698 : 0 : i40e_dev_free_queues(dev);
2699 : :
2700 : : /* Disable interrupt */
2701 : 0 : i40e_pf_disable_irq0(hw);
2702 : 0 : rte_intr_disable(intr_handle);
2703 : :
2704 : : /* shutdown and destroy the HMC */
2705 : 0 : i40e_shutdown_lan_hmc(hw);
2706 : :
2707 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2708 : 0 : i40e_vsi_release(pf->vmdq[i].vsi);
2709 : 0 : pf->vmdq[i].vsi = NULL;
2710 : : }
2711 : 0 : rte_free(pf->vmdq);
2712 : 0 : pf->vmdq = NULL;
2713 : :
2714 : : /* release all the existing VSIs and VEBs */
2715 : 0 : i40e_vsi_release(pf->main_vsi);
2716 : :
2717 : : /* shutdown the adminq */
2718 : 0 : i40e_aq_queue_shutdown(hw, true);
2719 : 0 : i40e_shutdown_adminq(hw);
2720 : :
2721 : 0 : i40e_res_pool_destroy(&pf->qp_pool);
2722 : 0 : i40e_res_pool_destroy(&pf->msix_pool);
2723 : :
2724 : : /* Disable flexible payload in global configuration */
2725 [ # # ]: 0 : if (!pf->support_multi_driver)
2726 : 0 : i40e_flex_payload_reg_set_default(hw);
2727 : :
2728 : : /* force a PF reset to clean anything leftover */
2729 : 0 : reg = I40E_READ_REG(hw, I40E_PFGEN_CTRL);
2730 : 0 : I40E_WRITE_REG(hw, I40E_PFGEN_CTRL,
2731 : : (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
2732 : 0 : I40E_WRITE_FLUSH(hw);
2733 : :
2734 : : /* Clear PXE mode */
2735 : 0 : i40e_clear_pxe_mode(hw);
2736 : :
2737 : : /* Unconfigure filter control */
2738 : : memset(&settings, 0, sizeof(settings));
2739 : 0 : ret = i40e_set_filter_control(hw, &settings);
2740 [ # # ]: 0 : if (ret)
2741 : 0 : PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
2742 : : ret);
2743 : :
2744 : : /* Disable flow control */
2745 : 0 : hw->fc.requested_mode = I40E_FC_NONE;
2746 : 0 : i40e_set_fc(hw, &aq_fail, TRUE);
2747 : :
2748 : : /* uninitialize pf host driver */
2749 : 0 : i40e_pf_host_uninit(dev);
2750 : :
2751 : : do {
2752 : 0 : ret = rte_intr_callback_unregister(intr_handle,
2753 : : i40e_dev_interrupt_handler, dev);
2754 [ # # ]: 0 : if (ret >= 0 || ret == -ENOENT) {
2755 : : break;
2756 [ # # ]: 0 : } else if (ret != -EAGAIN) {
2757 : 0 : PMD_INIT_LOG(ERR,
2758 : : "intr callback unregister failed: %d",
2759 : : ret);
2760 : : }
2761 : 0 : i40e_msec_delay(500);
2762 [ # # ]: 0 : } while (retries++ < 5);
2763 : :
2764 : 0 : i40e_rm_ethtype_filter_list(pf);
2765 : 0 : i40e_rm_tunnel_filter_list(pf);
2766 : : i40e_rm_fdir_filter_list(pf);
2767 : :
2768 : : /* Remove all flows */
2769 [ # # ]: 0 : while ((p_flow = TAILQ_FIRST(&pf->flow_list))) {
2770 [ # # ]: 0 : TAILQ_REMOVE(&pf->flow_list, p_flow, node);
2771 : : /* Do not free FDIR flows since they are static allocated */
2772 [ # # ]: 0 : if (p_flow->filter_type != RTE_ETH_FILTER_FDIR)
2773 : 0 : rte_free(p_flow);
2774 : : }
2775 : :
2776 : : /* release the fdir static allocated memory */
2777 : 0 : i40e_fdir_memory_cleanup(pf);
2778 : :
2779 : : /* Remove all Traffic Manager configuration */
2780 : 0 : i40e_tm_conf_uninit(dev);
2781 : :
2782 : : i40e_clear_automask(pf);
2783 : :
2784 : 0 : hw->adapter_closed = 1;
2785 : 0 : return ret;
2786 : : }
2787 : :
2788 : : /*
2789 : : * Reset PF device only to re-initialize resources in PMD layer
2790 : : */
2791 : : static int
2792 : 0 : i40e_dev_reset(struct rte_eth_dev *dev)
2793 : : {
2794 : : int ret;
2795 : :
2796 : : /* When a DPDK PMD PF begin to reset PF port, it should notify all
2797 : : * its VF to make them align with it. The detailed notification
2798 : : * mechanism is PMD specific. As to i40e PF, it is rather complex.
2799 : : * To avoid unexpected behavior in VF, currently reset of PF with
2800 : : * SR-IOV activation is not supported. It might be supported later.
2801 : : */
2802 [ # # ]: 0 : if (dev->data->sriov.active)
2803 : : return -ENOTSUP;
2804 : :
2805 : 0 : ret = eth_i40e_dev_uninit(dev);
2806 [ # # ]: 0 : if (ret)
2807 : : return ret;
2808 : :
2809 : 0 : ret = eth_i40e_dev_init(dev, NULL);
2810 : :
2811 : 0 : return ret;
2812 : : }
2813 : :
2814 : : static int
2815 : 0 : i40e_dev_promiscuous_enable(struct rte_eth_dev *dev)
2816 : : {
2817 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2818 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2819 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2820 : : int status;
2821 : :
2822 : 0 : status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2823 : : true, NULL, true);
2824 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2825 : 0 : PMD_DRV_LOG(ERR, "Failed to enable unicast promiscuous");
2826 : 0 : return -EAGAIN;
2827 : : }
2828 : :
2829 : 0 : status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
2830 : : TRUE, NULL);
2831 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2832 : 0 : PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
2833 : : /* Rollback unicast promiscuous mode */
2834 : 0 : i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2835 : : false, NULL, true);
2836 : 0 : return -EAGAIN;
2837 : : }
2838 : :
2839 : : return 0;
2840 : : }
2841 : :
2842 : : static int
2843 : 0 : i40e_dev_promiscuous_disable(struct rte_eth_dev *dev)
2844 : : {
2845 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2846 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2847 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2848 : : int status;
2849 : :
2850 : 0 : status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2851 : : false, NULL, true);
2852 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2853 : 0 : PMD_DRV_LOG(ERR, "Failed to disable unicast promiscuous");
2854 : 0 : return -EAGAIN;
2855 : : }
2856 : :
2857 : : /* must remain in all_multicast mode */
2858 [ # # ]: 0 : if (dev->data->all_multicast == 1)
2859 : : return 0;
2860 : :
2861 : 0 : status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
2862 : : false, NULL);
2863 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2864 : 0 : PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
2865 : : /* Rollback unicast promiscuous mode */
2866 : 0 : i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2867 : : true, NULL, true);
2868 : 0 : return -EAGAIN;
2869 : : }
2870 : :
2871 : : return 0;
2872 : : }
2873 : :
2874 : : static int
2875 : 0 : i40e_dev_allmulticast_enable(struct rte_eth_dev *dev)
2876 : : {
2877 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2878 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2879 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2880 : : int ret;
2881 : :
2882 : 0 : ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid, TRUE, NULL);
2883 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2884 : 0 : PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
2885 : 0 : return -EAGAIN;
2886 : : }
2887 : :
2888 : : return 0;
2889 : : }
2890 : :
2891 : : static int
2892 : 0 : i40e_dev_allmulticast_disable(struct rte_eth_dev *dev)
2893 : : {
2894 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2895 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2896 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2897 : : int ret;
2898 : :
2899 [ # # ]: 0 : if (dev->data->promiscuous == 1)
2900 : : return 0; /* must remain in all_multicast mode */
2901 : :
2902 : 0 : ret = i40e_aq_set_vsi_multicast_promiscuous(hw,
2903 : 0 : vsi->seid, FALSE, NULL);
2904 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2905 : 0 : PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
2906 : 0 : return -EAGAIN;
2907 : : }
2908 : :
2909 : : return 0;
2910 : : }
2911 : :
2912 : : /*
2913 : : * Set device link up.
2914 : : */
2915 : : static int
2916 : 0 : i40e_dev_set_link_up(struct rte_eth_dev *dev)
2917 : : {
2918 : : /* re-apply link speed setting */
2919 : 0 : return i40e_apply_link_speed(dev);
2920 : : }
2921 : :
2922 : : /*
2923 : : * Set device link down.
2924 : : */
2925 : : static int
2926 : 0 : i40e_dev_set_link_down(struct rte_eth_dev *dev)
2927 : : {
2928 : : uint8_t speed = I40E_LINK_SPEED_UNKNOWN;
2929 : : uint8_t abilities = 0;
2930 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2931 : :
2932 : : abilities = I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
2933 : 0 : return i40e_phy_conf_link(hw, abilities, speed, false);
2934 : : }
2935 : :
2936 : : static __rte_always_inline void
2937 : : update_link_reg(struct i40e_hw *hw, struct rte_eth_link *link)
2938 : : {
2939 : : /* Link status registers and values*/
2940 : : #define I40E_REG_LINK_UP 0x40000080
2941 : : #define I40E_PRTMAC_MACC 0x001E24E0
2942 : : #define I40E_REG_MACC_25GB 0x00020000
2943 : : #define I40E_REG_SPEED_MASK 0x38000000
2944 : : #define I40E_REG_SPEED_0 0x00000000
2945 : : #define I40E_REG_SPEED_1 0x08000000
2946 : : #define I40E_REG_SPEED_2 0x10000000
2947 : : #define I40E_REG_SPEED_3 0x18000000
2948 : : #define I40E_REG_SPEED_4 0x20000000
2949 : : uint32_t link_speed;
2950 : : uint32_t reg_val;
2951 : :
2952 : 0 : reg_val = I40E_READ_REG(hw, I40E_PRTMAC_LINKSTA(0));
2953 : 0 : link_speed = reg_val & I40E_REG_SPEED_MASK;
2954 : 0 : reg_val &= I40E_REG_LINK_UP;
2955 : 0 : link->link_status = (reg_val == I40E_REG_LINK_UP) ? 1 : 0;
2956 : :
2957 [ # # ]: 0 : if (unlikely(link->link_status == 0))
2958 : : return;
2959 : :
2960 : : /* Parse the link status */
2961 [ # # # # : 0 : switch (link_speed) {
# # ]
2962 : 0 : case I40E_REG_SPEED_0:
2963 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_100M;
2964 : 0 : break;
2965 : 0 : case I40E_REG_SPEED_1:
2966 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_1G;
2967 : 0 : break;
2968 : 0 : case I40E_REG_SPEED_2:
2969 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
2970 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_2_5G;
2971 : : else
2972 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_10G;
2973 : : break;
2974 : 0 : case I40E_REG_SPEED_3:
2975 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
2976 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_5G;
2977 : : } else {
2978 : 0 : reg_val = I40E_READ_REG(hw, I40E_PRTMAC_MACC);
2979 : :
2980 [ # # ]: 0 : if (reg_val & I40E_REG_MACC_25GB)
2981 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_25G;
2982 : : else
2983 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_40G;
2984 : : }
2985 : : break;
2986 : 0 : case I40E_REG_SPEED_4:
2987 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
2988 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_10G;
2989 : : else
2990 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_20G;
2991 : : break;
2992 : 0 : default:
2993 : 0 : PMD_DRV_LOG(ERR, "Unknown link speed info %u", link_speed);
2994 : 0 : break;
2995 : : }
2996 : : }
2997 : :
2998 : : static __rte_always_inline void
2999 : : update_link_aq(struct i40e_hw *hw, struct rte_eth_link *link,
3000 : : bool enable_lse, int wait_to_complete)
3001 : : {
3002 : : #define CHECK_INTERVAL 100 /* 100ms */
3003 : : #define MAX_REPEAT_TIME 10 /* 1s (10 * 100ms) in total */
3004 : : uint32_t rep_cnt = MAX_REPEAT_TIME;
3005 : : struct i40e_link_status link_status;
3006 : : int status;
3007 : :
3008 : : memset(&link_status, 0, sizeof(link_status));
3009 : :
3010 : : do {
3011 : : memset(&link_status, 0, sizeof(link_status));
3012 : :
3013 : : /* Get link status information from hardware */
3014 : 0 : status = i40e_aq_get_link_info(hw, enable_lse,
3015 : : &link_status, NULL);
3016 [ # # ]: 0 : if (unlikely(status != I40E_SUCCESS)) {
3017 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_NONE;
3018 : 0 : link->link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
3019 : 0 : PMD_DRV_LOG(ERR, "Failed to get link info");
3020 : 0 : return;
3021 : : }
3022 : :
3023 : 0 : link->link_status = link_status.link_info & I40E_AQ_LINK_UP;
3024 [ # # # # ]: 0 : if (!wait_to_complete || link->link_status)
3025 : : break;
3026 : :
3027 : : rte_delay_ms(CHECK_INTERVAL);
3028 [ # # ]: 0 : } while (--rep_cnt);
3029 : :
3030 : : /* Parse the link status */
3031 [ # # # # : 0 : switch (link_status.link_speed) {
# # # ]
3032 : 0 : case I40E_LINK_SPEED_100MB:
3033 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_100M;
3034 : 0 : break;
3035 : 0 : case I40E_LINK_SPEED_1GB:
3036 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_1G;
3037 : 0 : break;
3038 : 0 : case I40E_LINK_SPEED_10GB:
3039 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_10G;
3040 : 0 : break;
3041 : 0 : case I40E_LINK_SPEED_20GB:
3042 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_20G;
3043 : 0 : break;
3044 : 0 : case I40E_LINK_SPEED_25GB:
3045 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_25G;
3046 : 0 : break;
3047 : 0 : case I40E_LINK_SPEED_40GB:
3048 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_40G;
3049 : 0 : break;
3050 : 0 : default:
3051 [ # # ]: 0 : if (link->link_status)
3052 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_UNKNOWN;
3053 : : else
3054 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_NONE;
3055 : : break;
3056 : : }
3057 : : }
3058 : :
3059 : : int
3060 : 0 : i40e_dev_link_update(struct rte_eth_dev *dev,
3061 : : int wait_to_complete)
3062 : : {
3063 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3064 : : struct rte_eth_link link;
3065 [ # # ]: 0 : bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
3066 : : int ret;
3067 : :
3068 : : memset(&link, 0, sizeof(link));
3069 : :
3070 : : /* i40e uses full duplex only */
3071 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
3072 : 0 : link.link_autoneg = !(dev->data->dev_conf.link_speeds &
3073 : : RTE_ETH_LINK_SPEED_FIXED);
3074 : :
3075 [ # # ]: 0 : if (!wait_to_complete && !enable_lse)
3076 : : update_link_reg(hw, &link);
3077 : : else
3078 : 0 : update_link_aq(hw, &link, enable_lse, wait_to_complete);
3079 : :
3080 [ # # ]: 0 : if (hw->switch_dev)
3081 : 0 : rte_eth_linkstatus_get(hw->switch_dev, &link);
3082 : :
3083 : : ret = rte_eth_linkstatus_set(dev, &link);
3084 : 0 : i40e_notify_all_vfs_link_status(dev);
3085 : :
3086 : 0 : return ret;
3087 : : }
3088 : :
3089 : : static void
3090 : 0 : i40e_stat_update_48_in_64(struct i40e_hw *hw, uint32_t hireg,
3091 : : uint32_t loreg, bool offset_loaded, uint64_t *offset,
3092 : : uint64_t *stat, uint64_t *prev_stat)
3093 : : {
3094 : 0 : i40e_stat_update_48(hw, hireg, loreg, offset_loaded, offset, stat);
3095 : : /* enlarge the limitation when statistics counters overflowed */
3096 [ # # ]: 0 : if (offset_loaded) {
3097 [ # # ]: 0 : if (I40E_RXTX_BYTES_L_48_BIT(*prev_stat) > *stat)
3098 : 0 : *stat += RTE_BIT64(I40E_48_BIT_WIDTH);
3099 : 0 : *stat += I40E_RXTX_BYTES_H_16_BIT(*prev_stat);
3100 : : }
3101 : 0 : *prev_stat = *stat;
3102 : 0 : }
3103 : :
3104 : : /* Get all the statistics of a VSI */
3105 : : void
3106 : 0 : i40e_update_vsi_stats(struct i40e_vsi *vsi)
3107 : : {
3108 : : struct i40e_eth_stats *oes = &vsi->eth_stats_offset;
3109 : : struct i40e_eth_stats *nes = &vsi->eth_stats;
3110 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3111 : 0 : int idx = rte_le_to_cpu_16(vsi->info.stat_counter_idx);
3112 : :
3113 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GORCH(idx), I40E_GLV_GORCL(idx),
3114 : 0 : vsi->offset_loaded, &oes->rx_bytes,
3115 : 0 : &nes->rx_bytes, &vsi->prev_rx_bytes);
3116 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPRCH(idx), I40E_GLV_UPRCL(idx),
3117 : 0 : vsi->offset_loaded, &oes->rx_unicast,
3118 : 0 : &nes->rx_unicast);
3119 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPRCH(idx), I40E_GLV_MPRCL(idx),
3120 : 0 : vsi->offset_loaded, &oes->rx_multicast,
3121 : 0 : &nes->rx_multicast);
3122 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPRCH(idx), I40E_GLV_BPRCL(idx),
3123 : 0 : vsi->offset_loaded, &oes->rx_broadcast,
3124 : 0 : &nes->rx_broadcast);
3125 : : /* exclude CRC bytes */
3126 : 0 : nes->rx_bytes -= (nes->rx_unicast + nes->rx_multicast +
3127 : 0 : nes->rx_broadcast) * RTE_ETHER_CRC_LEN;
3128 : :
3129 : 0 : i40e_stat_update_32(hw, I40E_GLV_RDPC(idx), vsi->offset_loaded,
3130 : : &oes->rx_discards, &nes->rx_discards);
3131 : : /* GLV_REPC not supported */
3132 : : /* GLV_RMPC not supported */
3133 : 0 : i40e_stat_update_32(hw, I40E_GLV_RUPP(idx), vsi->offset_loaded,
3134 : : &oes->rx_unknown_protocol,
3135 : : &nes->rx_unknown_protocol);
3136 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GOTCH(idx), I40E_GLV_GOTCL(idx),
3137 : 0 : vsi->offset_loaded, &oes->tx_bytes,
3138 : 0 : &nes->tx_bytes, &vsi->prev_tx_bytes);
3139 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPTCH(idx), I40E_GLV_UPTCL(idx),
3140 : 0 : vsi->offset_loaded, &oes->tx_unicast,
3141 : 0 : &nes->tx_unicast);
3142 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPTCH(idx), I40E_GLV_MPTCL(idx),
3143 : 0 : vsi->offset_loaded, &oes->tx_multicast,
3144 : 0 : &nes->tx_multicast);
3145 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPTCH(idx), I40E_GLV_BPTCL(idx),
3146 : 0 : vsi->offset_loaded, &oes->tx_broadcast,
3147 : 0 : &nes->tx_broadcast);
3148 : : /* GLV_TDPC not supported */
3149 : 0 : i40e_stat_update_32(hw, I40E_GLV_TEPC(idx), vsi->offset_loaded,
3150 : : &oes->tx_errors, &nes->tx_errors);
3151 : 0 : vsi->offset_loaded = true;
3152 : :
3153 : 0 : PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats start *******************",
3154 : : vsi->vsi_id);
3155 : 0 : PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", nes->rx_bytes);
3156 : 0 : PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", nes->rx_unicast);
3157 : 0 : PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", nes->rx_multicast);
3158 : 0 : PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", nes->rx_broadcast);
3159 : 0 : PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", nes->rx_discards);
3160 : 0 : PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
3161 : : nes->rx_unknown_protocol);
3162 : 0 : PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", nes->tx_bytes);
3163 : 0 : PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", nes->tx_unicast);
3164 : 0 : PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", nes->tx_multicast);
3165 : 0 : PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", nes->tx_broadcast);
3166 : 0 : PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", nes->tx_discards);
3167 : 0 : PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", nes->tx_errors);
3168 : 0 : PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats end *******************",
3169 : : vsi->vsi_id);
3170 : 0 : }
3171 : :
3172 : : static void
3173 : 0 : i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw)
3174 : : {
3175 : : unsigned int i;
3176 : : struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
3177 : : struct i40e_hw_port_stats *os = &pf->stats_offset; /* old stats */
3178 : :
3179 : : /* Get rx/tx bytes of internal transfer packets */
3180 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GORCH(hw->port),
3181 : 0 : I40E_GLV_GORCL(hw->port),
3182 : 0 : pf->offset_loaded,
3183 : 0 : &pf->internal_stats_offset.rx_bytes,
3184 : 0 : &pf->internal_stats.rx_bytes,
3185 : : &pf->internal_prev_rx_bytes);
3186 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GOTCH(hw->port),
3187 : 0 : I40E_GLV_GOTCL(hw->port),
3188 : 0 : pf->offset_loaded,
3189 : 0 : &pf->internal_stats_offset.tx_bytes,
3190 : 0 : &pf->internal_stats.tx_bytes,
3191 : : &pf->internal_prev_tx_bytes);
3192 : : /* Get total internal rx packet count */
3193 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPRCH(hw->port),
3194 : 0 : I40E_GLV_UPRCL(hw->port),
3195 : 0 : pf->offset_loaded,
3196 : 0 : &pf->internal_stats_offset.rx_unicast,
3197 : 0 : &pf->internal_stats.rx_unicast);
3198 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPRCH(hw->port),
3199 : 0 : I40E_GLV_MPRCL(hw->port),
3200 : 0 : pf->offset_loaded,
3201 : 0 : &pf->internal_stats_offset.rx_multicast,
3202 : 0 : &pf->internal_stats.rx_multicast);
3203 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPRCH(hw->port),
3204 : 0 : I40E_GLV_BPRCL(hw->port),
3205 : 0 : pf->offset_loaded,
3206 : 0 : &pf->internal_stats_offset.rx_broadcast,
3207 : 0 : &pf->internal_stats.rx_broadcast);
3208 : : /* Get total internal tx packet count */
3209 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPTCH(hw->port),
3210 : 0 : I40E_GLV_UPTCL(hw->port),
3211 : 0 : pf->offset_loaded,
3212 : 0 : &pf->internal_stats_offset.tx_unicast,
3213 : 0 : &pf->internal_stats.tx_unicast);
3214 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPTCH(hw->port),
3215 : 0 : I40E_GLV_MPTCL(hw->port),
3216 : 0 : pf->offset_loaded,
3217 : 0 : &pf->internal_stats_offset.tx_multicast,
3218 : 0 : &pf->internal_stats.tx_multicast);
3219 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPTCH(hw->port),
3220 : 0 : I40E_GLV_BPTCL(hw->port),
3221 : 0 : pf->offset_loaded,
3222 : 0 : &pf->internal_stats_offset.tx_broadcast,
3223 : 0 : &pf->internal_stats.tx_broadcast);
3224 : :
3225 : : /* exclude CRC size */
3226 : 0 : pf->internal_stats.rx_bytes -= (pf->internal_stats.rx_unicast +
3227 : 0 : pf->internal_stats.rx_multicast +
3228 : 0 : pf->internal_stats.rx_broadcast) * RTE_ETHER_CRC_LEN;
3229 : :
3230 : : /* Get statistics of struct i40e_eth_stats */
3231 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLPRT_GORCH(hw->port),
3232 : 0 : I40E_GLPRT_GORCL(hw->port),
3233 : 0 : pf->offset_loaded, &os->eth.rx_bytes,
3234 : 0 : &ns->eth.rx_bytes, &pf->prev_rx_bytes);
3235 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_UPRCH(hw->port),
3236 : 0 : I40E_GLPRT_UPRCL(hw->port),
3237 : 0 : pf->offset_loaded, &os->eth.rx_unicast,
3238 : 0 : &ns->eth.rx_unicast);
3239 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_MPRCH(hw->port),
3240 : 0 : I40E_GLPRT_MPRCL(hw->port),
3241 : 0 : pf->offset_loaded, &os->eth.rx_multicast,
3242 : 0 : &ns->eth.rx_multicast);
3243 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_BPRCH(hw->port),
3244 : 0 : I40E_GLPRT_BPRCL(hw->port),
3245 : 0 : pf->offset_loaded, &os->eth.rx_broadcast,
3246 : 0 : &ns->eth.rx_broadcast);
3247 : : /* Workaround: CRC size should not be included in byte statistics,
3248 : : * so subtract RTE_ETHER_CRC_LEN from the byte counter for each rx
3249 : : * packet.
3250 : : */
3251 : 0 : ns->eth.rx_bytes -= (ns->eth.rx_unicast + ns->eth.rx_multicast +
3252 : 0 : ns->eth.rx_broadcast) * RTE_ETHER_CRC_LEN;
3253 : :
3254 : : /* exclude internal rx bytes
3255 : : * Workaround: it is possible I40E_GLV_GORCH[H/L] is updated before
3256 : : * I40E_GLPRT_GORCH[H/L], so there is a small window that cause negative
3257 : : * value.
3258 : : * same to I40E_GLV_UPRC[H/L], I40E_GLV_MPRC[H/L], I40E_GLV_BPRC[H/L].
3259 : : */
3260 [ # # ]: 0 : if (ns->eth.rx_bytes < pf->internal_stats.rx_bytes)
3261 : 0 : ns->eth.rx_bytes = 0;
3262 : : else
3263 : 0 : ns->eth.rx_bytes -= pf->internal_stats.rx_bytes;
3264 : :
3265 [ # # ]: 0 : if (ns->eth.rx_unicast < pf->internal_stats.rx_unicast)
3266 : 0 : ns->eth.rx_unicast = 0;
3267 : : else
3268 : 0 : ns->eth.rx_unicast -= pf->internal_stats.rx_unicast;
3269 : :
3270 [ # # ]: 0 : if (ns->eth.rx_multicast < pf->internal_stats.rx_multicast)
3271 : 0 : ns->eth.rx_multicast = 0;
3272 : : else
3273 : 0 : ns->eth.rx_multicast -= pf->internal_stats.rx_multicast;
3274 : :
3275 [ # # ]: 0 : if (ns->eth.rx_broadcast < pf->internal_stats.rx_broadcast)
3276 : 0 : ns->eth.rx_broadcast = 0;
3277 : : else
3278 : 0 : ns->eth.rx_broadcast -= pf->internal_stats.rx_broadcast;
3279 : :
3280 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RDPC(hw->port),
3281 : 0 : pf->offset_loaded, &os->eth.rx_discards,
3282 : : &ns->eth.rx_discards);
3283 : : /* GLPRT_REPC not supported */
3284 : : /* GLPRT_RMPC not supported */
3285 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RUPP(hw->port),
3286 : 0 : pf->offset_loaded,
3287 : : &os->eth.rx_unknown_protocol,
3288 : : &ns->eth.rx_unknown_protocol);
3289 : 0 : i40e_stat_update_48(hw, I40E_GL_RXERR1H(hw->pf_id + I40E_MAX_VF),
3290 : 0 : I40E_GL_RXERR1L(hw->pf_id + I40E_MAX_VF),
3291 : 0 : pf->offset_loaded, &os->rx_err1,
3292 : 0 : &ns->rx_err1);
3293 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLPRT_GOTCH(hw->port),
3294 : 0 : I40E_GLPRT_GOTCL(hw->port),
3295 : 0 : pf->offset_loaded, &os->eth.tx_bytes,
3296 : 0 : &ns->eth.tx_bytes, &pf->prev_tx_bytes);
3297 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_UPTCH(hw->port),
3298 : 0 : I40E_GLPRT_UPTCL(hw->port),
3299 : 0 : pf->offset_loaded, &os->eth.tx_unicast,
3300 : 0 : &ns->eth.tx_unicast);
3301 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_MPTCH(hw->port),
3302 : 0 : I40E_GLPRT_MPTCL(hw->port),
3303 : 0 : pf->offset_loaded, &os->eth.tx_multicast,
3304 : 0 : &ns->eth.tx_multicast);
3305 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_BPTCH(hw->port),
3306 : 0 : I40E_GLPRT_BPTCL(hw->port),
3307 : 0 : pf->offset_loaded, &os->eth.tx_broadcast,
3308 : 0 : &ns->eth.tx_broadcast);
3309 : 0 : ns->eth.tx_bytes -= (ns->eth.tx_unicast + ns->eth.tx_multicast +
3310 : 0 : ns->eth.tx_broadcast) * RTE_ETHER_CRC_LEN;
3311 : :
3312 : : /* exclude internal tx bytes
3313 : : * Workaround: it is possible I40E_GLV_GOTCH[H/L] is updated before
3314 : : * I40E_GLPRT_GOTCH[H/L], so there is a small window that cause negative
3315 : : * value.
3316 : : * same to I40E_GLV_UPTC[H/L], I40E_GLV_MPTC[H/L], I40E_GLV_BPTC[H/L].
3317 : : */
3318 [ # # ]: 0 : if (ns->eth.tx_bytes < pf->internal_stats.tx_bytes)
3319 : 0 : ns->eth.tx_bytes = 0;
3320 : : else
3321 : 0 : ns->eth.tx_bytes -= pf->internal_stats.tx_bytes;
3322 : :
3323 [ # # ]: 0 : if (ns->eth.tx_unicast < pf->internal_stats.tx_unicast)
3324 : 0 : ns->eth.tx_unicast = 0;
3325 : : else
3326 : 0 : ns->eth.tx_unicast -= pf->internal_stats.tx_unicast;
3327 : :
3328 [ # # ]: 0 : if (ns->eth.tx_multicast < pf->internal_stats.tx_multicast)
3329 : 0 : ns->eth.tx_multicast = 0;
3330 : : else
3331 : 0 : ns->eth.tx_multicast -= pf->internal_stats.tx_multicast;
3332 : :
3333 [ # # ]: 0 : if (ns->eth.tx_broadcast < pf->internal_stats.tx_broadcast)
3334 : 0 : ns->eth.tx_broadcast = 0;
3335 : : else
3336 : 0 : ns->eth.tx_broadcast -= pf->internal_stats.tx_broadcast;
3337 : :
3338 : : /* GLPRT_TEPC not supported */
3339 : :
3340 : : /* additional port specific stats */
3341 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_TDOLD(hw->port),
3342 : 0 : pf->offset_loaded, &os->tx_dropped_link_down,
3343 : : &ns->tx_dropped_link_down);
3344 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_CRCERRS(hw->port),
3345 : 0 : pf->offset_loaded, &os->crc_errors,
3346 : : &ns->crc_errors);
3347 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_ILLERRC(hw->port),
3348 : 0 : pf->offset_loaded, &os->illegal_bytes,
3349 : : &ns->illegal_bytes);
3350 : : /* GLPRT_ERRBC not supported */
3351 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_MLFC(hw->port),
3352 : 0 : pf->offset_loaded, &os->mac_local_faults,
3353 : : &ns->mac_local_faults);
3354 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_MRFC(hw->port),
3355 : 0 : pf->offset_loaded, &os->mac_remote_faults,
3356 : : &ns->mac_remote_faults);
3357 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RLEC(hw->port),
3358 : 0 : pf->offset_loaded, &os->rx_length_errors,
3359 : : &ns->rx_length_errors);
3360 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXONRXC(hw->port),
3361 : 0 : pf->offset_loaded, &os->link_xon_rx,
3362 : : &ns->link_xon_rx);
3363 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
3364 : 0 : pf->offset_loaded, &os->link_xoff_rx,
3365 : : &ns->link_xoff_rx);
3366 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3367 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
3368 : 0 : pf->offset_loaded,
3369 : : &os->priority_xon_rx[i],
3370 : : &ns->priority_xon_rx[i]);
3371 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
3372 : 0 : pf->offset_loaded,
3373 : : &os->priority_xoff_rx[i],
3374 : : &ns->priority_xoff_rx[i]);
3375 : : }
3376 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXONTXC(hw->port),
3377 : 0 : pf->offset_loaded, &os->link_xon_tx,
3378 : : &ns->link_xon_tx);
3379 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
3380 : 0 : pf->offset_loaded, &os->link_xoff_tx,
3381 : : &ns->link_xoff_tx);
3382 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3383 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
3384 : 0 : pf->offset_loaded,
3385 : : &os->priority_xon_tx[i],
3386 : : &ns->priority_xon_tx[i]);
3387 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
3388 : 0 : pf->offset_loaded,
3389 : : &os->priority_xoff_tx[i],
3390 : : &ns->priority_xoff_tx[i]);
3391 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RXON2OFFCNT(hw->port, i),
3392 : 0 : pf->offset_loaded,
3393 : : &os->priority_xon_2_xoff[i],
3394 : : &ns->priority_xon_2_xoff[i]);
3395 : : }
3396 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC64H(hw->port),
3397 : 0 : I40E_GLPRT_PRC64L(hw->port),
3398 : 0 : pf->offset_loaded, &os->rx_size_64,
3399 : 0 : &ns->rx_size_64);
3400 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC127H(hw->port),
3401 : 0 : I40E_GLPRT_PRC127L(hw->port),
3402 : 0 : pf->offset_loaded, &os->rx_size_127,
3403 : 0 : &ns->rx_size_127);
3404 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC255H(hw->port),
3405 : 0 : I40E_GLPRT_PRC255L(hw->port),
3406 : 0 : pf->offset_loaded, &os->rx_size_255,
3407 : 0 : &ns->rx_size_255);
3408 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC511H(hw->port),
3409 : 0 : I40E_GLPRT_PRC511L(hw->port),
3410 : 0 : pf->offset_loaded, &os->rx_size_511,
3411 : 0 : &ns->rx_size_511);
3412 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC1023H(hw->port),
3413 : 0 : I40E_GLPRT_PRC1023L(hw->port),
3414 : 0 : pf->offset_loaded, &os->rx_size_1023,
3415 : 0 : &ns->rx_size_1023);
3416 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC1522H(hw->port),
3417 : 0 : I40E_GLPRT_PRC1522L(hw->port),
3418 : 0 : pf->offset_loaded, &os->rx_size_1522,
3419 : 0 : &ns->rx_size_1522);
3420 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC9522H(hw->port),
3421 : 0 : I40E_GLPRT_PRC9522L(hw->port),
3422 : 0 : pf->offset_loaded, &os->rx_size_big,
3423 : 0 : &ns->rx_size_big);
3424 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RUC(hw->port),
3425 : 0 : pf->offset_loaded, &os->rx_undersize,
3426 : : &ns->rx_undersize);
3427 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RFC(hw->port),
3428 : 0 : pf->offset_loaded, &os->rx_fragments,
3429 : : &ns->rx_fragments);
3430 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_ROC(hw->port),
3431 : 0 : pf->offset_loaded, &os->rx_oversize,
3432 : : &ns->rx_oversize);
3433 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RJC(hw->port),
3434 : 0 : pf->offset_loaded, &os->rx_jabber,
3435 : : &ns->rx_jabber);
3436 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC64H(hw->port),
3437 : 0 : I40E_GLPRT_PTC64L(hw->port),
3438 : 0 : pf->offset_loaded, &os->tx_size_64,
3439 : 0 : &ns->tx_size_64);
3440 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC127H(hw->port),
3441 : 0 : I40E_GLPRT_PTC127L(hw->port),
3442 : 0 : pf->offset_loaded, &os->tx_size_127,
3443 : 0 : &ns->tx_size_127);
3444 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC255H(hw->port),
3445 : 0 : I40E_GLPRT_PTC255L(hw->port),
3446 : 0 : pf->offset_loaded, &os->tx_size_255,
3447 : 0 : &ns->tx_size_255);
3448 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC511H(hw->port),
3449 : 0 : I40E_GLPRT_PTC511L(hw->port),
3450 : 0 : pf->offset_loaded, &os->tx_size_511,
3451 : 0 : &ns->tx_size_511);
3452 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC1023H(hw->port),
3453 : 0 : I40E_GLPRT_PTC1023L(hw->port),
3454 : 0 : pf->offset_loaded, &os->tx_size_1023,
3455 : 0 : &ns->tx_size_1023);
3456 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC1522H(hw->port),
3457 : 0 : I40E_GLPRT_PTC1522L(hw->port),
3458 : 0 : pf->offset_loaded, &os->tx_size_1522,
3459 : 0 : &ns->tx_size_1522);
3460 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC9522H(hw->port),
3461 : 0 : I40E_GLPRT_PTC9522L(hw->port),
3462 : 0 : pf->offset_loaded, &os->tx_size_big,
3463 : 0 : &ns->tx_size_big);
3464 : 0 : i40e_stat_update_32(hw, I40E_GLQF_PCNT(pf->fdir.match_counter_index),
3465 : 0 : pf->offset_loaded,
3466 : : &os->fd_sb_match, &ns->fd_sb_match);
3467 : : /* GLPRT_MSPDC not supported */
3468 : : /* GLPRT_XEC not supported */
3469 : :
3470 : 0 : pf->offset_loaded = true;
3471 : :
3472 [ # # ]: 0 : if (pf->main_vsi)
3473 : 0 : i40e_update_vsi_stats(pf->main_vsi);
3474 : 0 : }
3475 : :
3476 : : /* Get all statistics of a port */
3477 : : static int
3478 : 0 : i40e_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
3479 : : struct eth_queue_stats *qstats __rte_unused)
3480 : : {
3481 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3482 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3483 : : struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
3484 : : struct i40e_vsi *vsi;
3485 : : unsigned i;
3486 : :
3487 : : /* call read registers - updates values, now write them to struct */
3488 : 0 : i40e_read_stats_registers(pf, hw);
3489 : :
3490 : 0 : stats->ipackets = pf->main_vsi->eth_stats.rx_unicast +
3491 : 0 : pf->main_vsi->eth_stats.rx_multicast +
3492 : 0 : pf->main_vsi->eth_stats.rx_broadcast -
3493 : 0 : pf->main_vsi->eth_stats.rx_discards -
3494 : 0 : ns->rx_err1;
3495 : 0 : stats->opackets = ns->eth.tx_unicast +
3496 : 0 : ns->eth.tx_multicast +
3497 : 0 : ns->eth.tx_broadcast;
3498 : 0 : stats->ibytes = pf->main_vsi->eth_stats.rx_bytes;
3499 : 0 : stats->obytes = ns->eth.tx_bytes;
3500 : 0 : stats->oerrors = ns->eth.tx_errors +
3501 : 0 : pf->main_vsi->eth_stats.tx_errors;
3502 : :
3503 : : /* Rx Errors */
3504 : 0 : stats->imissed = ns->eth.rx_discards +
3505 : : pf->main_vsi->eth_stats.rx_discards;
3506 : 0 : stats->ierrors = ns->crc_errors +
3507 : 0 : ns->rx_length_errors + ns->rx_undersize +
3508 : 0 : ns->rx_oversize + ns->rx_fragments + ns->rx_jabber +
3509 : : ns->rx_err1;
3510 : :
3511 [ # # ]: 0 : if (pf->vfs) {
3512 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++) {
3513 : 0 : vsi = pf->vfs[i].vsi;
3514 : 0 : i40e_update_vsi_stats(vsi);
3515 : :
3516 : 0 : stats->ipackets += (vsi->eth_stats.rx_unicast +
3517 : 0 : vsi->eth_stats.rx_multicast +
3518 : 0 : vsi->eth_stats.rx_broadcast -
3519 : 0 : vsi->eth_stats.rx_discards);
3520 : 0 : stats->ibytes += vsi->eth_stats.rx_bytes;
3521 : 0 : stats->oerrors += vsi->eth_stats.tx_errors;
3522 : 0 : stats->imissed += vsi->eth_stats.rx_discards;
3523 : : }
3524 : : }
3525 : :
3526 : 0 : PMD_DRV_LOG(DEBUG, "***************** PF stats start *******************");
3527 : 0 : PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", ns->eth.rx_bytes);
3528 : 0 : PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", ns->eth.rx_unicast);
3529 : 0 : PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", ns->eth.rx_multicast);
3530 : 0 : PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", ns->eth.rx_broadcast);
3531 : 0 : PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", ns->eth.rx_discards);
3532 : 0 : PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
3533 : : ns->eth.rx_unknown_protocol);
3534 : 0 : PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", ns->eth.tx_bytes);
3535 : 0 : PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", ns->eth.tx_unicast);
3536 : 0 : PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", ns->eth.tx_multicast);
3537 : 0 : PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", ns->eth.tx_broadcast);
3538 : 0 : PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", ns->eth.tx_discards);
3539 : 0 : PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", ns->eth.tx_errors);
3540 : :
3541 : 0 : PMD_DRV_LOG(DEBUG, "tx_dropped_link_down: %"PRIu64"",
3542 : : ns->tx_dropped_link_down);
3543 : 0 : PMD_DRV_LOG(DEBUG, "crc_errors: %"PRIu64"", ns->crc_errors);
3544 : 0 : PMD_DRV_LOG(DEBUG, "illegal_bytes: %"PRIu64"",
3545 : : ns->illegal_bytes);
3546 : 0 : PMD_DRV_LOG(DEBUG, "error_bytes: %"PRIu64"", ns->error_bytes);
3547 : 0 : PMD_DRV_LOG(DEBUG, "mac_local_faults: %"PRIu64"",
3548 : : ns->mac_local_faults);
3549 : 0 : PMD_DRV_LOG(DEBUG, "mac_remote_faults: %"PRIu64"",
3550 : : ns->mac_remote_faults);
3551 : 0 : PMD_DRV_LOG(DEBUG, "rx_length_errors: %"PRIu64"",
3552 : : ns->rx_length_errors);
3553 : 0 : PMD_DRV_LOG(DEBUG, "link_xon_rx: %"PRIu64"", ns->link_xon_rx);
3554 : 0 : PMD_DRV_LOG(DEBUG, "link_xoff_rx: %"PRIu64"", ns->link_xoff_rx);
3555 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3556 : 0 : PMD_DRV_LOG(DEBUG, "priority_xon_rx[%d]: %"PRIu64"",
3557 : : i, ns->priority_xon_rx[i]);
3558 : 0 : PMD_DRV_LOG(DEBUG, "priority_xoff_rx[%d]: %"PRIu64"",
3559 : : i, ns->priority_xoff_rx[i]);
3560 : : }
3561 : 0 : PMD_DRV_LOG(DEBUG, "link_xon_tx: %"PRIu64"", ns->link_xon_tx);
3562 : 0 : PMD_DRV_LOG(DEBUG, "link_xoff_tx: %"PRIu64"", ns->link_xoff_tx);
3563 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3564 : 0 : PMD_DRV_LOG(DEBUG, "priority_xon_tx[%d]: %"PRIu64"",
3565 : : i, ns->priority_xon_tx[i]);
3566 : 0 : PMD_DRV_LOG(DEBUG, "priority_xoff_tx[%d]: %"PRIu64"",
3567 : : i, ns->priority_xoff_tx[i]);
3568 : 0 : PMD_DRV_LOG(DEBUG, "priority_xon_2_xoff[%d]: %"PRIu64"",
3569 : : i, ns->priority_xon_2_xoff[i]);
3570 : : }
3571 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_64: %"PRIu64"", ns->rx_size_64);
3572 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_127: %"PRIu64"", ns->rx_size_127);
3573 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_255: %"PRIu64"", ns->rx_size_255);
3574 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_511: %"PRIu64"", ns->rx_size_511);
3575 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_1023: %"PRIu64"", ns->rx_size_1023);
3576 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_1522: %"PRIu64"", ns->rx_size_1522);
3577 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_big: %"PRIu64"", ns->rx_size_big);
3578 : 0 : PMD_DRV_LOG(DEBUG, "rx_undersize: %"PRIu64"", ns->rx_undersize);
3579 : 0 : PMD_DRV_LOG(DEBUG, "rx_fragments: %"PRIu64"", ns->rx_fragments);
3580 : 0 : PMD_DRV_LOG(DEBUG, "rx_oversize: %"PRIu64"", ns->rx_oversize);
3581 : 0 : PMD_DRV_LOG(DEBUG, "rx_jabber: %"PRIu64"", ns->rx_jabber);
3582 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_64: %"PRIu64"", ns->tx_size_64);
3583 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_127: %"PRIu64"", ns->tx_size_127);
3584 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_255: %"PRIu64"", ns->tx_size_255);
3585 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_511: %"PRIu64"", ns->tx_size_511);
3586 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_1023: %"PRIu64"", ns->tx_size_1023);
3587 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_1522: %"PRIu64"", ns->tx_size_1522);
3588 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_big: %"PRIu64"", ns->tx_size_big);
3589 : 0 : PMD_DRV_LOG(DEBUG, "mac_short_packet_dropped: %"PRIu64"",
3590 : : ns->mac_short_packet_dropped);
3591 : 0 : PMD_DRV_LOG(DEBUG, "checksum_error: %"PRIu64"",
3592 : : ns->checksum_error);
3593 : 0 : PMD_DRV_LOG(DEBUG, "fdir_match: %"PRIu64"", ns->fd_sb_match);
3594 : 0 : PMD_DRV_LOG(DEBUG, "***************** PF stats end ********************");
3595 : 0 : return 0;
3596 : : }
3597 : :
3598 : : /* Reset the statistics */
3599 : : static int
3600 : 0 : i40e_dev_stats_reset(struct rte_eth_dev *dev)
3601 : : {
3602 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3603 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3604 : :
3605 : : /* Mark PF and VSI stats to update the offset, aka "reset" */
3606 : 0 : pf->offset_loaded = false;
3607 [ # # ]: 0 : if (pf->main_vsi)
3608 : 0 : pf->main_vsi->offset_loaded = false;
3609 : :
3610 : : /* read the stats, reading current register values into offset */
3611 : 0 : i40e_read_stats_registers(pf, hw);
3612 : :
3613 : 0 : memset(&pf->mbuf_stats, 0, sizeof(struct i40e_mbuf_stats));
3614 : :
3615 : 0 : return 0;
3616 : : }
3617 : :
3618 : : static uint32_t
3619 : : i40e_xstats_calc_num(void)
3620 : : {
3621 : : return I40E_NB_ETH_XSTATS + I40E_NB_MBUF_XSTATS +
3622 : : I40E_NB_HW_PORT_XSTATS +
3623 : : (I40E_NB_RXQ_PRIO_XSTATS * 8) +
3624 : : (I40E_NB_TXQ_PRIO_XSTATS * 8);
3625 : : }
3626 : :
3627 : 0 : static int i40e_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
3628 : : struct rte_eth_xstat_name *xstats_names,
3629 : : __rte_unused unsigned limit)
3630 : : {
3631 : : unsigned count = 0;
3632 : : unsigned i, prio;
3633 : :
3634 [ # # ]: 0 : if (xstats_names == NULL)
3635 : : return i40e_xstats_calc_num();
3636 : :
3637 : : /* Note: limit checked in rte_eth_xstats_names() */
3638 : :
3639 : : /* Get stats from i40e_eth_stats struct */
3640 [ # # ]: 0 : for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
3641 : 0 : strlcpy(xstats_names[count].name,
3642 : : rte_i40e_stats_strings[i].name,
3643 : : sizeof(xstats_names[count].name));
3644 : 0 : count++;
3645 : : }
3646 : :
3647 : : /* Get stats from i40e_mbuf_stats struct */
3648 [ # # ]: 0 : for (i = 0; i < I40E_NB_MBUF_XSTATS; i++) {
3649 : 0 : strlcpy(xstats_names[count].name,
3650 : : i40e_mbuf_strings[i].name,
3651 : : sizeof(xstats_names[count].name));
3652 : 0 : count++;
3653 : : }
3654 : :
3655 : : /* Get individual stats from i40e_hw_port struct */
3656 [ # # ]: 0 : for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
3657 : 0 : strlcpy(xstats_names[count].name,
3658 : : rte_i40e_hw_port_strings[i].name,
3659 : : sizeof(xstats_names[count].name));
3660 : 0 : count++;
3661 : : }
3662 : :
3663 [ # # ]: 0 : for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
3664 [ # # ]: 0 : for (prio = 0; prio < 8; prio++) {
3665 : 0 : snprintf(xstats_names[count].name,
3666 : : sizeof(xstats_names[count].name),
3667 : : "rx_priority%u_%s", prio,
3668 : 0 : rte_i40e_rxq_prio_strings[i].name);
3669 : 0 : count++;
3670 : : }
3671 : : }
3672 : :
3673 [ # # ]: 0 : for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
3674 [ # # ]: 0 : for (prio = 0; prio < 8; prio++) {
3675 : 0 : snprintf(xstats_names[count].name,
3676 : : sizeof(xstats_names[count].name),
3677 : : "tx_priority%u_%s", prio,
3678 : 0 : rte_i40e_txq_prio_strings[i].name);
3679 : 0 : count++;
3680 : : }
3681 : : }
3682 : 0 : return count;
3683 : : }
3684 : :
3685 : : static void
3686 : : i40e_dev_update_mbuf_stats(struct rte_eth_dev *ethdev,
3687 : : struct i40e_mbuf_stats *mbuf_stats)
3688 : : {
3689 : : uint16_t idx;
3690 : : struct ci_tx_queue *txq;
3691 : :
3692 [ # # ]: 0 : for (idx = 0; idx < ethdev->data->nb_tx_queues; idx++) {
3693 : 0 : txq = ethdev->data->tx_queues[idx];
3694 : 0 : mbuf_stats->tx_pkt_errors += txq->mbuf_errors;
3695 : : }
3696 : : }
3697 : :
3698 : : static int
3699 : 0 : i40e_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
3700 : : unsigned n)
3701 : : {
3702 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3703 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3704 : : struct i40e_adapter *adapter =
3705 : : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3706 : : struct i40e_mbuf_stats mbuf_stats = {0};
3707 : : unsigned i, count, prio;
3708 : 0 : struct i40e_hw_port_stats *hw_stats = &pf->stats;
3709 : :
3710 : : count = i40e_xstats_calc_num();
3711 [ # # ]: 0 : if (n < count)
3712 : : return count;
3713 : :
3714 : 0 : i40e_read_stats_registers(pf, hw);
3715 : :
3716 [ # # ]: 0 : if (xstats == NULL)
3717 : : return 0;
3718 : :
3719 : : count = 0;
3720 : :
3721 [ # # ]: 0 : if (adapter->mbuf_check)
3722 : : i40e_dev_update_mbuf_stats(dev, &mbuf_stats);
3723 : :
3724 : : /* Get stats from i40e_eth_stats struct */
3725 [ # # ]: 0 : for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
3726 : 0 : xstats[count].value = *(uint64_t *)(((char *)&hw_stats->eth) +
3727 : 0 : rte_i40e_stats_strings[i].offset);
3728 : 0 : xstats[count].id = count;
3729 : 0 : count++;
3730 : : }
3731 : :
3732 : : /* Get stats from i40e_mbuf_stats struct */
3733 [ # # ]: 0 : for (i = 0; i < I40E_NB_MBUF_XSTATS; i++) {
3734 : 0 : xstats[count].value = *(uint64_t *)((char *)&mbuf_stats +
3735 : : i40e_mbuf_strings[i].offset);
3736 : 0 : xstats[count].id = count;
3737 : 0 : count++;
3738 : : }
3739 : :
3740 : : /* Get individual stats from i40e_hw_port struct */
3741 [ # # ]: 0 : for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
3742 : 0 : xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
3743 : 0 : rte_i40e_hw_port_strings[i].offset);
3744 : 0 : xstats[count].id = count;
3745 : 0 : count++;
3746 : : }
3747 : :
3748 [ # # ]: 0 : for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
3749 [ # # ]: 0 : for (prio = 0; prio < 8; prio++) {
3750 : 0 : xstats[count].value =
3751 : 0 : *(uint64_t *)(((char *)hw_stats) +
3752 : 0 : rte_i40e_rxq_prio_strings[i].offset +
3753 : 0 : (sizeof(uint64_t) * prio));
3754 : 0 : xstats[count].id = count;
3755 : 0 : count++;
3756 : : }
3757 : : }
3758 : :
3759 [ # # ]: 0 : for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
3760 [ # # ]: 0 : for (prio = 0; prio < 8; prio++) {
3761 : 0 : xstats[count].value =
3762 : 0 : *(uint64_t *)(((char *)hw_stats) +
3763 : 0 : rte_i40e_txq_prio_strings[i].offset +
3764 : 0 : (sizeof(uint64_t) * prio));
3765 : 0 : xstats[count].id = count;
3766 : 0 : count++;
3767 : : }
3768 : : }
3769 : :
3770 : 0 : return count;
3771 : : }
3772 : :
3773 : : static int
3774 : 0 : i40e_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
3775 : : {
3776 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3777 : : u32 full_ver;
3778 : : u8 ver, patch;
3779 : : u16 build;
3780 : : int ret;
3781 : :
3782 : 0 : full_ver = hw->nvm.oem_ver;
3783 : 0 : ver = (u8)(full_ver >> 24);
3784 : 0 : build = (u16)((full_ver >> 8) & 0xffff);
3785 : : patch = (u8)(full_ver & 0xff);
3786 : :
3787 : 0 : ret = snprintf(fw_version, fw_size,
3788 : : "%d.%d%d 0x%08x %d.%d.%d",
3789 : : ((hw->nvm.version >> 12) & 0xf),
3790 : : ((hw->nvm.version >> 4) & 0xff),
3791 [ # # ]: 0 : (hw->nvm.version & 0xf), hw->nvm.eetrack,
3792 : : ver, build, patch);
3793 [ # # ]: 0 : if (ret < 0)
3794 : : return -EINVAL;
3795 : :
3796 : 0 : ret += 1; /* add the size of '\0' */
3797 [ # # ]: 0 : if (fw_size < (size_t)ret)
3798 : : return ret;
3799 : : else
3800 : 0 : return 0;
3801 : : }
3802 : :
3803 : : /*
3804 : : * When using NVM 6.01(for X710 XL710 XXV710)/3.33(for X722) or later,
3805 : : * the Rx data path does not hang if the FW LLDP is stopped.
3806 : : * return true if lldp need to stop
3807 : : * return false if we cannot disable the LLDP to avoid Rx data path blocking.
3808 : : */
3809 : : static bool
3810 : 0 : i40e_need_stop_lldp(struct rte_eth_dev *dev)
3811 : : {
3812 : : double nvm_ver;
3813 : 0 : char ver_str[64] = {0};
3814 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3815 : :
3816 : 0 : i40e_fw_version_get(dev, ver_str, 64);
3817 : : nvm_ver = atof(ver_str);
3818 [ # # ]: 0 : if ((hw->mac.type == I40E_MAC_X722 ||
3819 : 0 : hw->mac.type == I40E_MAC_X722_VF) &&
3820 [ # # ]: 0 : ((uint32_t)(nvm_ver * 1000) >= (uint32_t)(3.33 * 1000)))
3821 : : return true;
3822 [ # # ]: 0 : else if ((uint32_t)(nvm_ver * 1000) >= (uint32_t)(6.01 * 1000))
3823 : 0 : return true;
3824 : :
3825 : : return false;
3826 : : }
3827 : :
3828 : : static int
3829 : 0 : i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
3830 : : {
3831 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3832 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3833 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
3834 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3835 : :
3836 : 0 : dev_info->max_rx_queues = vsi->nb_qps;
3837 : 0 : dev_info->max_tx_queues = vsi->nb_qps;
3838 : 0 : dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
3839 : 0 : dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
3840 : 0 : dev_info->max_mac_addrs = vsi->max_macaddrs;
3841 : 0 : dev_info->max_vfs = pci_dev->max_vfs;
3842 : 0 : dev_info->max_mtu = dev_info->max_rx_pktlen - I40E_ETH_OVERHEAD;
3843 : 0 : dev_info->min_mtu = RTE_ETHER_MIN_MTU;
3844 : 0 : dev_info->rx_queue_offload_capa = 0;
3845 : 0 : dev_info->rx_offload_capa =
3846 : : RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
3847 : : RTE_ETH_RX_OFFLOAD_QINQ_STRIP |
3848 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
3849 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
3850 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
3851 : : RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
3852 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC |
3853 : : RTE_ETH_RX_OFFLOAD_SCATTER |
3854 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND |
3855 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
3856 : : RTE_ETH_RX_OFFLOAD_RSS_HASH;
3857 : :
3858 : 0 : dev_info->tx_queue_offload_capa = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
3859 : 0 : dev_info->tx_offload_capa =
3860 : : RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
3861 : : RTE_ETH_TX_OFFLOAD_QINQ_INSERT |
3862 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
3863 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
3864 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
3865 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
3866 : : RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
3867 : : RTE_ETH_TX_OFFLOAD_TCP_TSO |
3868 : : RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
3869 : : RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
3870 : : RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
3871 : : RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
3872 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
3873 : : dev_info->tx_queue_offload_capa;
3874 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
3875 : 0 : dev_info->tx_offload_capa |=
3876 : : RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM;
3877 : : }
3878 : :
3879 : 0 : dev_info->dev_capa =
3880 : : RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
3881 : : RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
3882 : : dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
3883 : :
3884 : 0 : dev_info->hash_key_size = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
3885 : : sizeof(uint32_t);
3886 : 0 : dev_info->reta_size = pf->hash_lut_size;
3887 : 0 : dev_info->flow_type_rss_offloads = pf->adapter->flow_types_mask;
3888 : :
3889 : 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
3890 : : .rx_thresh = {
3891 : : .pthresh = I40E_DEFAULT_RX_PTHRESH,
3892 : : .hthresh = I40E_DEFAULT_RX_HTHRESH,
3893 : : .wthresh = I40E_DEFAULT_RX_WTHRESH,
3894 : : },
3895 : : .rx_free_thresh = I40E_DEFAULT_RX_FREE_THRESH,
3896 : : .rx_drop_en = 0,
3897 : : .offloads = 0,
3898 : : };
3899 : :
3900 : 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
3901 : : .tx_thresh = {
3902 : : .pthresh = I40E_DEFAULT_TX_PTHRESH,
3903 : : .hthresh = I40E_DEFAULT_TX_HTHRESH,
3904 : : .wthresh = I40E_DEFAULT_TX_WTHRESH,
3905 : : },
3906 : : .tx_free_thresh = I40E_DEFAULT_TX_FREE_THRESH,
3907 : : .tx_rs_thresh = I40E_DEFAULT_TX_RSBIT_THRESH,
3908 : : .offloads = 0,
3909 : : };
3910 : :
3911 : 0 : dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
3912 : : .nb_max = I40E_MAX_RING_DESC,
3913 : : .nb_min = I40E_MIN_RING_DESC,
3914 : : .nb_align = I40E_ALIGN_RING_DESC,
3915 : : };
3916 : :
3917 : 0 : dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
3918 : : .nb_max = I40E_MAX_RING_DESC,
3919 : : .nb_min = I40E_MIN_RING_DESC,
3920 : : .nb_align = I40E_ALIGN_RING_DESC,
3921 : : .nb_seg_max = I40E_TX_MAX_SEG,
3922 : : .nb_mtu_seg_max = I40E_TX_MAX_MTU_SEG,
3923 : : };
3924 : :
3925 [ # # ]: 0 : if (pf->flags & I40E_FLAG_VMDQ) {
3926 : 0 : dev_info->max_vmdq_pools = pf->max_nb_vmdq_vsi;
3927 : 0 : dev_info->vmdq_queue_base = dev_info->max_rx_queues;
3928 : 0 : dev_info->vmdq_queue_num = pf->vmdq_nb_qps *
3929 : : pf->max_nb_vmdq_vsi;
3930 : 0 : dev_info->vmdq_pool_base = I40E_VMDQ_POOL_BASE;
3931 : 0 : dev_info->max_rx_queues += dev_info->vmdq_queue_num;
3932 : 0 : dev_info->max_tx_queues += dev_info->vmdq_queue_num;
3933 : : }
3934 : :
3935 [ # # ]: 0 : if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
3936 : : /* For XL710 */
3937 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_40G;
3938 : 0 : dev_info->default_rxportconf.nb_queues = 2;
3939 : 0 : dev_info->default_txportconf.nb_queues = 2;
3940 [ # # ]: 0 : if (dev->data->nb_rx_queues == 1)
3941 : 0 : dev_info->default_rxportconf.ring_size = 2048;
3942 : : else
3943 : 0 : dev_info->default_rxportconf.ring_size = 1024;
3944 [ # # ]: 0 : if (dev->data->nb_tx_queues == 1)
3945 : 0 : dev_info->default_txportconf.ring_size = 1024;
3946 : : else
3947 : 0 : dev_info->default_txportconf.ring_size = 512;
3948 : :
3949 [ # # ]: 0 : } else if (I40E_PHY_TYPE_SUPPORT_25G(hw->phy.phy_types)) {
3950 : : /* For XXV710 */
3951 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_25G;
3952 : 0 : dev_info->default_rxportconf.nb_queues = 1;
3953 : 0 : dev_info->default_txportconf.nb_queues = 1;
3954 : 0 : dev_info->default_rxportconf.ring_size = 256;
3955 : 0 : dev_info->default_txportconf.ring_size = 256;
3956 : : } else {
3957 : : /* For X710 */
3958 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_10G;
3959 : 0 : dev_info->default_rxportconf.nb_queues = 1;
3960 : 0 : dev_info->default_txportconf.nb_queues = 1;
3961 [ # # ]: 0 : if (dev->data->dev_conf.link_speeds & RTE_ETH_LINK_SPEED_10G) {
3962 : 0 : dev_info->default_rxportconf.ring_size = 512;
3963 : 0 : dev_info->default_txportconf.ring_size = 256;
3964 : : } else {
3965 : 0 : dev_info->default_rxportconf.ring_size = 256;
3966 : 0 : dev_info->default_txportconf.ring_size = 256;
3967 : : }
3968 : : }
3969 : 0 : dev_info->default_rxportconf.burst_size = 32;
3970 : 0 : dev_info->default_txportconf.burst_size = 32;
3971 : :
3972 : 0 : return 0;
3973 : : }
3974 : :
3975 : : static int
3976 : 0 : i40e_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
3977 : : {
3978 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3979 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
3980 : 0 : PMD_INIT_FUNC_TRACE();
3981 : :
3982 [ # # ]: 0 : if (on)
3983 : 0 : return i40e_vsi_add_vlan(vsi, vlan_id);
3984 : : else
3985 : 0 : return i40e_vsi_delete_vlan(vsi, vlan_id);
3986 : : }
3987 : :
3988 : : static int
3989 : 0 : i40e_vlan_tpid_set_by_registers(struct rte_eth_dev *dev,
3990 : : enum rte_vlan_type vlan_type,
3991 : : uint16_t tpid, int qinq)
3992 : : {
3993 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3994 : 0 : uint64_t reg_r = 0;
3995 : : uint64_t reg_w = 0;
3996 : : uint16_t reg_id = 3;
3997 : : int ret;
3998 : :
3999 [ # # ]: 0 : if (qinq) {
4000 [ # # ]: 0 : if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
4001 : : reg_id = 2;
4002 : : }
4003 : :
4004 : 0 : ret = i40e_aq_debug_read_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
4005 : : ®_r, NULL);
4006 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
4007 : 0 : PMD_DRV_LOG(ERR,
4008 : : "Fail to debug read from I40E_GL_SWT_L2TAGCTRL[%d]",
4009 : : reg_id);
4010 : 0 : return -EIO;
4011 : : }
4012 : 0 : PMD_DRV_LOG(DEBUG,
4013 : : "Debug read from I40E_GL_SWT_L2TAGCTRL[%d]: 0x%08"PRIx64,
4014 : : reg_id, reg_r);
4015 : :
4016 : 0 : reg_w = reg_r & (~(I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_MASK));
4017 : 0 : reg_w |= ((uint64_t)tpid << I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT);
4018 [ # # ]: 0 : if (reg_r == reg_w) {
4019 : 0 : PMD_DRV_LOG(DEBUG, "No need to write");
4020 : 0 : return 0;
4021 : : }
4022 : :
4023 : 0 : ret = i40e_aq_debug_write_global_register(hw,
4024 : : I40E_GL_SWT_L2TAGCTRL(reg_id),
4025 : : reg_w, NULL);
4026 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
4027 : 0 : PMD_DRV_LOG(ERR,
4028 : : "Fail to debug write to I40E_GL_SWT_L2TAGCTRL[%d]",
4029 : : reg_id);
4030 : 0 : return -EIO;
4031 : : }
4032 : 0 : PMD_DRV_LOG(DEBUG,
4033 : : "Global register 0x%08x is changed with value 0x%08x",
4034 : : I40E_GL_SWT_L2TAGCTRL(reg_id), (uint32_t)reg_w);
4035 : :
4036 : 0 : return 0;
4037 : : }
4038 : :
4039 : : static int
4040 : 0 : i40e_vlan_tpid_set(struct rte_eth_dev *dev,
4041 : : enum rte_vlan_type vlan_type,
4042 : : uint16_t tpid)
4043 : : {
4044 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4045 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4046 : 0 : int qinq = dev->data->dev_conf.rxmode.offloads &
4047 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
4048 : : u16 sw_flags = 0, valid_flags = 0;
4049 : : int ret = 0;
4050 : :
4051 [ # # ]: 0 : if ((vlan_type != RTE_ETH_VLAN_TYPE_INNER &&
4052 : 0 : vlan_type != RTE_ETH_VLAN_TYPE_OUTER) ||
4053 [ # # ]: 0 : (!qinq && vlan_type == RTE_ETH_VLAN_TYPE_INNER)) {
4054 : 0 : PMD_DRV_LOG(ERR,
4055 : : "Unsupported vlan type.");
4056 : 0 : return -EINVAL;
4057 : : }
4058 : :
4059 [ # # ]: 0 : if (pf->support_multi_driver) {
4060 : 0 : PMD_DRV_LOG(ERR, "Setting TPID is not supported.");
4061 : 0 : return -ENOTSUP;
4062 : : }
4063 : :
4064 : : /* 802.1ad frames ability is added in NVM API 1.7*/
4065 [ # # ]: 0 : if (hw->flags & I40E_HW_FLAG_802_1AD_CAPABLE) {
4066 [ # # ]: 0 : if (qinq) {
4067 [ # # ]: 0 : if (pf->fw8_3gt) {
4068 : : sw_flags = I40E_AQ_SET_SWITCH_CFG_OUTER_VLAN;
4069 : : valid_flags = I40E_AQ_SET_SWITCH_CFG_OUTER_VLAN;
4070 : : }
4071 [ # # ]: 0 : if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
4072 : 0 : hw->first_tag = rte_cpu_to_le_16(tpid);
4073 : : else if (vlan_type == RTE_ETH_VLAN_TYPE_INNER)
4074 : 0 : hw->second_tag = rte_cpu_to_le_16(tpid);
4075 : : } else {
4076 [ # # ]: 0 : if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
4077 : 0 : hw->second_tag = rte_cpu_to_le_16(tpid);
4078 : : }
4079 : 0 : ret = i40e_aq_set_switch_config(hw, sw_flags,
4080 : : valid_flags, 0, NULL);
4081 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
4082 : 0 : PMD_DRV_LOG(ERR,
4083 : : "Set switch config failed aq_err: %d",
4084 : : hw->aq.asq_last_status);
4085 : : ret = -EIO;
4086 : : }
4087 : : } else
4088 : : /* If NVM API < 1.7, keep the register setting */
4089 : 0 : ret = i40e_vlan_tpid_set_by_registers(dev, vlan_type,
4090 : : tpid, qinq);
4091 : :
4092 : : return ret;
4093 : : }
4094 : :
4095 : : /* Configure outer vlan stripping on or off in QinQ mode */
4096 : : static int
4097 : 0 : i40e_vsi_config_outer_vlan_stripping(struct i40e_vsi *vsi, bool on)
4098 : : {
4099 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4100 : : int ret = I40E_SUCCESS;
4101 : : uint32_t reg;
4102 : :
4103 [ # # ]: 0 : if (vsi->vsi_id >= I40E_MAX_NUM_VSIS) {
4104 : 0 : PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
4105 : 0 : return -EINVAL;
4106 : : }
4107 : :
4108 : : /* Configure for outer VLAN RX stripping */
4109 : 0 : reg = I40E_READ_REG(hw, I40E_VSI_TSR(vsi->vsi_id));
4110 : :
4111 [ # # ]: 0 : if (on)
4112 : 0 : reg |= I40E_VSI_TSR_QINQ_STRIP;
4113 : : else
4114 : 0 : reg &= ~I40E_VSI_TSR_QINQ_STRIP;
4115 : :
4116 : 0 : ret = i40e_aq_debug_write_register(hw,
4117 : 0 : I40E_VSI_TSR(vsi->vsi_id),
4118 : : reg, NULL);
4119 [ # # ]: 0 : if (ret < 0) {
4120 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI_TSR[%d]",
4121 : : vsi->vsi_id);
4122 : 0 : return I40E_ERR_CONFIG;
4123 : : }
4124 : :
4125 : : return ret;
4126 : : }
4127 : :
4128 : : static int
4129 : 0 : i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask)
4130 : : {
4131 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4132 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
4133 : : struct rte_eth_rxmode *rxmode;
4134 : : struct i40e_mac_filter *f;
4135 : : int i, num;
4136 : : void *temp;
4137 : : int ret;
4138 : :
4139 : : rxmode = &dev->data->dev_conf.rxmode;
4140 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_FILTER_MASK) {
4141 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
4142 : 0 : i40e_vsi_config_vlan_filter(vsi, TRUE);
4143 : : else
4144 : 0 : i40e_vsi_config_vlan_filter(vsi, FALSE);
4145 : : }
4146 : :
4147 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
4148 : : /* Enable or disable VLAN stripping */
4149 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
4150 : 0 : i40e_vsi_config_vlan_stripping(vsi, TRUE);
4151 : : else
4152 : 0 : i40e_vsi_config_vlan_stripping(vsi, FALSE);
4153 : :
4154 : : /* When VLAN strip is enabled/disabled
4155 : : * after enabling outer VLAN stripping,
4156 : : * outer VLAN stripping gets disabled
4157 : : * as the register gets overridden by
4158 : : * VLAN's strip vsi param update.
4159 : : * Hence, re-enable outer VLAN stripping.
4160 : : */
4161 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP)
4162 : 0 : i40e_vsi_config_outer_vlan_stripping(vsi, TRUE);
4163 : : }
4164 : :
4165 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_EXTEND_MASK) {
4166 : 0 : struct i40e_mac_filter_info mac_filter[I40E_NUM_MACADDR_MAX] = {0};
4167 : : i = 0;
4168 : 0 : num = vsi->mac_num;
4169 : :
4170 [ # # ]: 0 : if (num > I40E_NUM_MACADDR_MAX) {
4171 : 0 : PMD_DRV_LOG(ERR, "Too many MAC addresses");
4172 : 0 : return I40E_ERR_NO_MEMORY;
4173 : : }
4174 : :
4175 : : /*
4176 : : * Outer VLAN processing is supported after firmware v8.4, kernel driver
4177 : : * also change the default behavior to support this feature. To align with
4178 : : * kernel driver, set switch config in 'i40e_vlan_tpie_set' to support for
4179 : : * outer VLAN processing. But it is forbidden for firmware to change the
4180 : : * Inner/Outer VLAN configuration while there are MAC/VLAN filters in the
4181 : : * switch table. Therefore, we need to clear the MAC table before setting
4182 : : * config, and then restore the MAC table after setting. This feature is
4183 : : * recommended to be used in firmware v8.6.
4184 : : */
4185 : : /* Remove all existing mac */
4186 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
4187 : 0 : mac_filter[i] = f->mac_info;
4188 : 0 : ret = i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
4189 [ # # ]: 0 : if (ret)
4190 : 0 : PMD_DRV_LOG(ERR, "i40e vsi delete mac fail.");
4191 : 0 : i++;
4192 : : }
4193 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND) {
4194 : : i40e_vsi_config_double_vlan(vsi, TRUE);
4195 : : /* Set global registers with default ethertype. */
4196 : 0 : i40e_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_OUTER,
4197 : : RTE_ETHER_TYPE_VLAN);
4198 : 0 : i40e_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_INNER,
4199 : : RTE_ETHER_TYPE_VLAN);
4200 : : } else {
4201 : : i40e_vsi_config_double_vlan(vsi, FALSE);
4202 : : }
4203 : : /* Restore all mac */
4204 [ # # ]: 0 : for (i = 0; i < num; i++) {
4205 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter[i]);
4206 [ # # ]: 0 : if (ret)
4207 : 0 : PMD_DRV_LOG(ERR, "i40e vsi add mac fail.");
4208 : : }
4209 : : }
4210 : :
4211 [ # # ]: 0 : if (mask & RTE_ETH_QINQ_STRIP_MASK) {
4212 : : /* Enable or disable outer VLAN stripping */
4213 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP)
4214 : 0 : i40e_vsi_config_outer_vlan_stripping(vsi, TRUE);
4215 : : else
4216 : 0 : i40e_vsi_config_outer_vlan_stripping(vsi, FALSE);
4217 : : }
4218 : :
4219 : : return 0;
4220 : : }
4221 : :
4222 : : static void
4223 : 0 : i40e_vlan_strip_queue_set(__rte_unused struct rte_eth_dev *dev,
4224 : : __rte_unused uint16_t queue,
4225 : : __rte_unused int on)
4226 : : {
4227 : 0 : PMD_INIT_FUNC_TRACE();
4228 : 0 : }
4229 : :
4230 : : static int
4231 : 0 : i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
4232 : : {
4233 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4234 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
4235 [ # # ]: 0 : struct rte_eth_dev_data *data = I40E_VSI_TO_DEV_DATA(vsi);
4236 : : struct i40e_vsi_vlan_pvid_info info;
4237 : :
4238 : : memset(&info, 0, sizeof(info));
4239 : 0 : info.on = on;
4240 [ # # ]: 0 : if (info.on)
4241 : 0 : info.config.pvid = pvid;
4242 : : else {
4243 : 0 : info.config.reject.tagged =
4244 : 0 : data->dev_conf.txmode.hw_vlan_reject_tagged;
4245 : 0 : info.config.reject.untagged =
4246 : 0 : data->dev_conf.txmode.hw_vlan_reject_untagged;
4247 : : }
4248 : :
4249 : 0 : return i40e_vsi_vlan_pvid_set(vsi, &info);
4250 : : }
4251 : :
4252 : : static int
4253 : 0 : i40e_dev_led_on(struct rte_eth_dev *dev)
4254 : : {
4255 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4256 : 0 : uint32_t mode = i40e_led_get(hw);
4257 : :
4258 [ # # ]: 0 : if (mode == 0)
4259 : 0 : i40e_led_set(hw, 0xf, true); /* 0xf means led always true */
4260 : :
4261 : 0 : return 0;
4262 : : }
4263 : :
4264 : : static int
4265 : 0 : i40e_dev_led_off(struct rte_eth_dev *dev)
4266 : : {
4267 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4268 : 0 : uint32_t mode = i40e_led_get(hw);
4269 : :
4270 [ # # ]: 0 : if (mode != 0)
4271 : 0 : i40e_led_set(hw, 0, false);
4272 : :
4273 : 0 : return 0;
4274 : : }
4275 : :
4276 : : static int
4277 : 0 : i40e_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
4278 : : {
4279 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4280 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4281 : :
4282 : 0 : fc_conf->pause_time = pf->fc_conf.pause_time;
4283 : :
4284 : : /* read out from register, in case they are modified by other port */
4285 : 0 : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] =
4286 : 0 : I40E_READ_REG(hw, I40E_GLRPB_GHW) >> I40E_KILOSHIFT;
4287 : 0 : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] =
4288 : 0 : I40E_READ_REG(hw, I40E_GLRPB_GLW) >> I40E_KILOSHIFT;
4289 : :
4290 : 0 : fc_conf->high_water = pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS];
4291 : 0 : fc_conf->low_water = pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS];
4292 : :
4293 : : /* Return current mode according to actual setting*/
4294 [ # # # # ]: 0 : switch (hw->fc.current_mode) {
4295 : 0 : case I40E_FC_FULL:
4296 : 0 : fc_conf->mode = RTE_ETH_FC_FULL;
4297 : 0 : break;
4298 : 0 : case I40E_FC_TX_PAUSE:
4299 : 0 : fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
4300 : 0 : break;
4301 : 0 : case I40E_FC_RX_PAUSE:
4302 : 0 : fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
4303 : 0 : break;
4304 : 0 : case I40E_FC_NONE:
4305 : : default:
4306 : 0 : fc_conf->mode = RTE_ETH_FC_NONE;
4307 : : };
4308 : :
4309 : 0 : return 0;
4310 : : }
4311 : :
4312 : : static int
4313 : 0 : i40e_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
4314 : : {
4315 : : uint32_t mflcn_reg, fctrl_reg, reg;
4316 : : uint32_t max_high_water;
4317 : : uint8_t i, aq_failure;
4318 : : int err;
4319 : : struct i40e_hw *hw;
4320 : : struct i40e_pf *pf;
4321 : 0 : enum i40e_fc_mode rte_fcmode_2_i40e_fcmode[] = {
4322 : : [RTE_ETH_FC_NONE] = I40E_FC_NONE,
4323 : : [RTE_ETH_FC_RX_PAUSE] = I40E_FC_RX_PAUSE,
4324 : : [RTE_ETH_FC_TX_PAUSE] = I40E_FC_TX_PAUSE,
4325 : : [RTE_ETH_FC_FULL] = I40E_FC_FULL
4326 : : };
4327 : :
4328 : : /* high_water field in the rte_eth_fc_conf using the kilobytes unit */
4329 : :
4330 : : max_high_water = I40E_RXPBSIZE >> I40E_KILOSHIFT;
4331 [ # # ]: 0 : if ((fc_conf->high_water > max_high_water) ||
4332 [ # # ]: 0 : (fc_conf->high_water < fc_conf->low_water)) {
4333 : 0 : PMD_INIT_LOG(ERR,
4334 : : "Invalid high/low water setup value in KB, High_water must be <= %d.",
4335 : : max_high_water);
4336 : 0 : return -EINVAL;
4337 : : }
4338 : :
4339 : 0 : hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4340 : : pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4341 : 0 : hw->fc.requested_mode = rte_fcmode_2_i40e_fcmode[fc_conf->mode];
4342 : :
4343 : 0 : pf->fc_conf.pause_time = fc_conf->pause_time;
4344 : 0 : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->high_water;
4345 : 0 : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->low_water;
4346 : :
4347 : 0 : PMD_INIT_FUNC_TRACE();
4348 : :
4349 : : /* All the link flow control related enable/disable register
4350 : : * configuration is handle by the F/W
4351 : : */
4352 : 0 : err = i40e_set_fc(hw, &aq_failure, true);
4353 [ # # ]: 0 : if (err < 0)
4354 : : return -ENOSYS;
4355 : :
4356 [ # # ]: 0 : if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
4357 : : /* Configure flow control refresh threshold,
4358 : : * the value for stat_tx_pause_refresh_timer[8]
4359 : : * is used for global pause operation.
4360 : : */
4361 : :
4362 : 0 : I40E_WRITE_REG(hw,
4363 : : I40E_PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER(8),
4364 : : pf->fc_conf.pause_time);
4365 : :
4366 : : /* configure the timer value included in transmitted pause
4367 : : * frame,
4368 : : * the value for stat_tx_pause_quanta[8] is used for global
4369 : : * pause operation
4370 : : */
4371 : 0 : I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA(8),
4372 : : pf->fc_conf.pause_time);
4373 : :
4374 : 0 : fctrl_reg = I40E_READ_REG(hw,
4375 : : I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL);
4376 : :
4377 [ # # ]: 0 : if (fc_conf->mac_ctrl_frame_fwd != 0)
4378 : 0 : fctrl_reg |= I40E_PRTMAC_FWD_CTRL;
4379 : : else
4380 : 0 : fctrl_reg &= ~I40E_PRTMAC_FWD_CTRL;
4381 : :
4382 : 0 : I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL,
4383 : : fctrl_reg);
4384 : : } else {
4385 : : /* Configure pause time (2 TCs per register) */
4386 : 0 : reg = (uint32_t)pf->fc_conf.pause_time * (uint32_t)0x00010001;
4387 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS / 2; i++)
4388 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_FCTTVN(i), reg);
4389 : :
4390 : : /* Configure flow control refresh threshold value */
4391 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_FCRTV,
4392 : : pf->fc_conf.pause_time / 2);
4393 : :
4394 : 0 : mflcn_reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
4395 : :
4396 : : /* set or clear MFLCN.PMCF & MFLCN.DPF bits
4397 : : *depending on configuration
4398 : : */
4399 [ # # ]: 0 : if (fc_conf->mac_ctrl_frame_fwd != 0) {
4400 : : mflcn_reg |= I40E_PRTDCB_MFLCN_PMCF_MASK;
4401 : 0 : mflcn_reg &= ~I40E_PRTDCB_MFLCN_DPF_MASK;
4402 : : } else {
4403 : 0 : mflcn_reg &= ~I40E_PRTDCB_MFLCN_PMCF_MASK;
4404 : 0 : mflcn_reg |= I40E_PRTDCB_MFLCN_DPF_MASK;
4405 : : }
4406 : :
4407 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, mflcn_reg);
4408 : : }
4409 : :
4410 [ # # ]: 0 : if (!pf->support_multi_driver) {
4411 : : /* config water marker both based on the packets and bytes */
4412 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_PHW,
4413 : : (pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
4414 : : << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
4415 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_PLW,
4416 : : (pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
4417 : : << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
4418 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_GHW,
4419 : : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
4420 : : << I40E_KILOSHIFT);
4421 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_GLW,
4422 : : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
4423 : : << I40E_KILOSHIFT);
4424 : : } else {
4425 : 0 : PMD_DRV_LOG(ERR,
4426 : : "Water marker configuration is not supported.");
4427 : : }
4428 : :
4429 : 0 : I40E_WRITE_FLUSH(hw);
4430 : :
4431 : 0 : return 0;
4432 : : }
4433 : :
4434 : : static int
4435 : 0 : i40e_priority_flow_ctrl_set(__rte_unused struct rte_eth_dev *dev,
4436 : : __rte_unused struct rte_eth_pfc_conf *pfc_conf)
4437 : : {
4438 : 0 : PMD_INIT_FUNC_TRACE();
4439 : :
4440 : 0 : return -ENOSYS;
4441 : : }
4442 : :
4443 : : /* Add a MAC address, and update filters */
4444 : : static int
4445 : 0 : i40e_macaddr_add(struct rte_eth_dev *dev,
4446 : : struct rte_ether_addr *mac_addr,
4447 : : __rte_unused uint32_t index,
4448 : : uint32_t pool)
4449 : : {
4450 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4451 : : struct i40e_mac_filter_info mac_filter;
4452 : : struct i40e_vsi *vsi;
4453 : : struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
4454 : : int ret;
4455 : :
4456 : : /* If VMDQ not enabled or configured, return */
4457 [ # # # # ]: 0 : if (pool != 0 && (!(pf->flags & I40E_FLAG_VMDQ) ||
4458 [ # # ]: 0 : !pf->nb_cfg_vmdq_vsi)) {
4459 [ # # ]: 0 : PMD_DRV_LOG(ERR, "VMDQ not %s, can't set mac to pool %u",
4460 : : pf->flags & I40E_FLAG_VMDQ ? "configured" : "enabled",
4461 : : pool);
4462 : 0 : return -ENOTSUP;
4463 : : }
4464 : :
4465 [ # # ]: 0 : if (pool > pf->nb_cfg_vmdq_vsi) {
4466 : 0 : PMD_DRV_LOG(ERR, "Pool number %u invalid. Max pool is %u",
4467 : : pool, pf->nb_cfg_vmdq_vsi);
4468 : 0 : return -EINVAL;
4469 : : }
4470 : :
4471 : : rte_memcpy(&mac_filter.mac_addr, mac_addr, RTE_ETHER_ADDR_LEN);
4472 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
4473 : 0 : mac_filter.filter_type = I40E_MACVLAN_PERFECT_MATCH;
4474 : : else
4475 : 0 : mac_filter.filter_type = I40E_MAC_PERFECT_MATCH;
4476 : :
4477 [ # # ]: 0 : if (pool == 0)
4478 : 0 : vsi = pf->main_vsi;
4479 : : else
4480 : 0 : vsi = pf->vmdq[pool - 1].vsi;
4481 : :
4482 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter);
4483 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
4484 : 0 : PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
4485 : 0 : return -ENODEV;
4486 : : }
4487 : : return 0;
4488 : : }
4489 : :
4490 : : /* Remove a MAC address, and update filters */
4491 : : static void
4492 : 0 : i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
4493 : : {
4494 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4495 : : struct i40e_vsi *vsi;
4496 : : struct rte_eth_dev_data *data = dev->data;
4497 : : struct rte_ether_addr *macaddr;
4498 : : int ret;
4499 : : uint32_t i;
4500 : : uint64_t pool_sel;
4501 : :
4502 : 0 : macaddr = &(data->mac_addrs[index]);
4503 : :
4504 : 0 : pool_sel = dev->data->mac_pool_sel[index];
4505 : :
4506 [ # # ]: 0 : for (i = 0; i < sizeof(pool_sel) * CHAR_BIT; i++) {
4507 [ # # ]: 0 : if (pool_sel & RTE_BIT64(i)) {
4508 [ # # ]: 0 : if (i == 0)
4509 : 0 : vsi = pf->main_vsi;
4510 : : else {
4511 : : /* No VMDQ pool enabled or configured */
4512 [ # # ]: 0 : if (!(pf->flags & I40E_FLAG_VMDQ) ||
4513 [ # # ]: 0 : (i > pf->nb_cfg_vmdq_vsi)) {
4514 : 0 : PMD_DRV_LOG(ERR,
4515 : : "No VMDQ pool enabled/configured");
4516 : 0 : return;
4517 : : }
4518 : 0 : vsi = pf->vmdq[i - 1].vsi;
4519 : : }
4520 : 0 : ret = i40e_vsi_delete_mac(vsi, macaddr);
4521 : :
4522 [ # # ]: 0 : if (ret) {
4523 : 0 : PMD_DRV_LOG(ERR, "Failed to remove MACVLAN filter");
4524 : 0 : return;
4525 : : }
4526 : : }
4527 : : }
4528 : : }
4529 : :
4530 : : static int
4531 : 0 : i40e_get_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4532 : : {
4533 : 0 : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
4534 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4535 : : uint32_t reg;
4536 : : int ret;
4537 : :
4538 [ # # ]: 0 : if (!lut)
4539 : : return -EINVAL;
4540 : :
4541 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
4542 : 0 : ret = i40e_aq_get_rss_lut(hw, vsi->vsi_id,
4543 : 0 : vsi->type != I40E_VSI_SRIOV,
4544 : : lut, lut_size);
4545 [ # # ]: 0 : if (ret) {
4546 : 0 : PMD_DRV_LOG(ERR, "Failed to get RSS lookup table");
4547 : 0 : return ret;
4548 : : }
4549 : : } else {
4550 : : uint32_t *lut_dw = (uint32_t *)lut;
4551 : 0 : uint16_t i, lut_size_dw = lut_size / 4;
4552 : :
4553 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
4554 [ # # ]: 0 : for (i = 0; i <= lut_size_dw; i++) {
4555 : 0 : reg = I40E_VFQF_HLUT1(i, vsi->user_param);
4556 : 0 : lut_dw[i] = i40e_read_rx_ctl(hw, reg);
4557 : : }
4558 : : } else {
4559 [ # # ]: 0 : for (i = 0; i < lut_size_dw; i++)
4560 : 0 : lut_dw[i] = I40E_READ_REG(hw,
4561 : : I40E_PFQF_HLUT(i));
4562 : : }
4563 : : }
4564 : :
4565 : : return 0;
4566 : : }
4567 : :
4568 : : int
4569 : 0 : i40e_set_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4570 : : {
4571 : : struct i40e_pf *pf;
4572 : : struct i40e_hw *hw;
4573 : :
4574 [ # # ]: 0 : if (!vsi || !lut)
4575 : : return -EINVAL;
4576 : :
4577 : 0 : pf = I40E_VSI_TO_PF(vsi);
4578 : 0 : hw = I40E_VSI_TO_HW(vsi);
4579 : :
4580 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
4581 : : enum i40e_status_code status;
4582 : :
4583 : 0 : status = i40e_aq_set_rss_lut(hw, vsi->vsi_id,
4584 : 0 : vsi->type != I40E_VSI_SRIOV,
4585 : : lut, lut_size);
4586 [ # # ]: 0 : if (status) {
4587 : 0 : PMD_DRV_LOG(ERR,
4588 : : "Failed to update RSS lookup table, error status: %d",
4589 : : status);
4590 : 0 : return -EIO;
4591 : : }
4592 : : } else {
4593 : : uint32_t *lut_dw = (uint32_t *)lut;
4594 : 0 : uint16_t i, lut_size_dw = lut_size / 4;
4595 : :
4596 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
4597 [ # # ]: 0 : for (i = 0; i < lut_size_dw; i++)
4598 : 0 : I40E_WRITE_REG(
4599 : : hw,
4600 : : I40E_VFQF_HLUT1(i, vsi->user_param),
4601 : : lut_dw[i]);
4602 : : } else {
4603 [ # # ]: 0 : for (i = 0; i < lut_size_dw; i++)
4604 : 0 : I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i),
4605 : : lut_dw[i]);
4606 : : }
4607 : 0 : I40E_WRITE_FLUSH(hw);
4608 : : }
4609 : :
4610 : : return 0;
4611 : : }
4612 : :
4613 : : static int
4614 : 0 : i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
4615 : : struct rte_eth_rss_reta_entry64 *reta_conf,
4616 : : uint16_t reta_size)
4617 : : {
4618 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4619 : 0 : uint16_t i, lut_size = pf->hash_lut_size;
4620 : : uint16_t idx, shift;
4621 : 0 : uint8_t lut[RTE_ETH_RSS_RETA_SIZE_512] = {0};
4622 : : int ret;
4623 : :
4624 : 0 : if (reta_size != lut_size ||
4625 [ # # ]: 0 : reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
4626 : 0 : PMD_DRV_LOG(ERR,
4627 : : "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)",
4628 : : reta_size, lut_size);
4629 : 0 : return -EINVAL;
4630 : : }
4631 : :
4632 : 0 : ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
4633 [ # # ]: 0 : if (ret)
4634 : : return ret;
4635 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
4636 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
4637 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
4638 [ # # ]: 0 : if (reta_conf[idx].mask & RTE_BIT64(shift))
4639 : 0 : lut[i] = reta_conf[idx].reta[shift];
4640 : : }
4641 : 0 : ret = i40e_set_rss_lut(pf->main_vsi, lut, reta_size);
4642 : :
4643 : 0 : pf->adapter->rss_reta_updated = 1;
4644 : :
4645 : 0 : return ret;
4646 : : }
4647 : :
4648 : : static int
4649 : 0 : i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
4650 : : struct rte_eth_rss_reta_entry64 *reta_conf,
4651 : : uint16_t reta_size)
4652 : : {
4653 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4654 : 0 : uint16_t i, lut_size = pf->hash_lut_size;
4655 : : uint16_t idx, shift;
4656 : 0 : uint8_t lut[RTE_ETH_RSS_RETA_SIZE_512] = {0};
4657 : : int ret;
4658 : :
4659 : 0 : if (reta_size != lut_size ||
4660 [ # # ]: 0 : reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
4661 : 0 : PMD_DRV_LOG(ERR,
4662 : : "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)",
4663 : : reta_size, lut_size);
4664 : 0 : return -EINVAL;
4665 : : }
4666 : :
4667 : 0 : ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
4668 [ # # ]: 0 : if (ret)
4669 : : return ret;
4670 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
4671 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
4672 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
4673 [ # # ]: 0 : if (reta_conf[idx].mask & RTE_BIT64(shift))
4674 : 0 : reta_conf[idx].reta[shift] = lut[i];
4675 : : }
4676 : :
4677 : : return ret;
4678 : : }
4679 : :
4680 : : /**
4681 : : * i40e_allocate_dma_mem_d - specific memory alloc for shared code (base driver)
4682 : : * @hw: pointer to the HW structure
4683 : : * @mem: pointer to mem struct to fill out
4684 : : * @size: size of memory requested
4685 : : * @alignment: what to align the allocation to
4686 : : **/
4687 : : enum i40e_status_code
4688 : 0 : i40e_allocate_dma_mem_d(__rte_unused struct i40e_hw *hw,
4689 : : struct i40e_dma_mem *mem,
4690 : : __rte_unused enum i40e_memory_type mtype,
4691 : : u64 size,
4692 : : u32 alignment)
4693 : : {
4694 : : static RTE_ATOMIC(uint64_t) i40e_dma_memzone_id;
4695 : : const struct rte_memzone *mz = NULL;
4696 : : char z_name[RTE_MEMZONE_NAMESIZE];
4697 : :
4698 [ # # ]: 0 : if (!mem)
4699 : : return I40E_ERR_PARAM;
4700 : :
4701 : 0 : snprintf(z_name, sizeof(z_name), "i40e_dma_%" PRIu64,
4702 : : rte_atomic_fetch_add_explicit(&i40e_dma_memzone_id, 1, rte_memory_order_relaxed));
4703 : 0 : mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY,
4704 : : RTE_MEMZONE_IOVA_CONTIG, alignment, RTE_PGSIZE_2M);
4705 [ # # ]: 0 : if (!mz)
4706 : : return I40E_ERR_NO_MEMORY;
4707 : :
4708 : 0 : mem->size = size;
4709 : 0 : mem->va = mz->addr;
4710 : 0 : mem->pa = mz->iova;
4711 : 0 : mem->zone = (const void *)mz;
4712 : 0 : PMD_DRV_LOG(DEBUG,
4713 : : "memzone %s allocated with physical address: %"PRIu64,
4714 : : mz->name, mem->pa);
4715 : :
4716 : 0 : return I40E_SUCCESS;
4717 : : }
4718 : :
4719 : : /**
4720 : : * i40e_free_dma_mem_d - specific memory free for shared code (base driver)
4721 : : * @hw: pointer to the HW structure
4722 : : * @mem: ptr to mem struct to free
4723 : : **/
4724 : : enum i40e_status_code
4725 : 0 : i40e_free_dma_mem_d(__rte_unused struct i40e_hw *hw,
4726 : : struct i40e_dma_mem *mem)
4727 : : {
4728 [ # # ]: 0 : if (!mem)
4729 : : return I40E_ERR_PARAM;
4730 : :
4731 : 0 : PMD_DRV_LOG(DEBUG,
4732 : : "memzone %s to be freed with physical address: %"PRIu64,
4733 : : ((const struct rte_memzone *)mem->zone)->name, mem->pa);
4734 : 0 : rte_memzone_free((const struct rte_memzone *)mem->zone);
4735 : 0 : mem->zone = NULL;
4736 : 0 : mem->va = NULL;
4737 : 0 : mem->pa = (u64)0;
4738 : :
4739 : 0 : return I40E_SUCCESS;
4740 : : }
4741 : :
4742 : : /**
4743 : : * i40e_allocate_virt_mem_d - specific memory alloc for shared code (base driver)
4744 : : * @hw: pointer to the HW structure
4745 : : * @mem: pointer to mem struct to fill out
4746 : : * @size: size of memory requested
4747 : : **/
4748 : : enum i40e_status_code
4749 : 0 : i40e_allocate_virt_mem_d(__rte_unused struct i40e_hw *hw,
4750 : : struct i40e_virt_mem *mem,
4751 : : u32 size)
4752 : : {
4753 [ # # ]: 0 : if (!mem)
4754 : : return I40E_ERR_PARAM;
4755 : :
4756 : 0 : mem->size = size;
4757 : 0 : mem->va = rte_zmalloc("i40e", size, 0);
4758 : :
4759 [ # # ]: 0 : if (mem->va)
4760 : : return I40E_SUCCESS;
4761 : : else
4762 : 0 : return I40E_ERR_NO_MEMORY;
4763 : : }
4764 : :
4765 : : /**
4766 : : * i40e_free_virt_mem_d - specific memory free for shared code (base driver)
4767 : : * @hw: pointer to the HW structure
4768 : : * @mem: pointer to mem struct to free
4769 : : **/
4770 : : enum i40e_status_code
4771 : 0 : i40e_free_virt_mem_d(__rte_unused struct i40e_hw *hw,
4772 : : struct i40e_virt_mem *mem)
4773 : : {
4774 [ # # ]: 0 : if (!mem)
4775 : : return I40E_ERR_PARAM;
4776 : :
4777 : 0 : rte_free(mem->va);
4778 : 0 : mem->va = NULL;
4779 : :
4780 : 0 : return I40E_SUCCESS;
4781 : : }
4782 : :
4783 : : /**
4784 : : * Get the hardware capabilities, which will be parsed
4785 : : * and saved into struct i40e_hw.
4786 : : */
4787 : : static int
4788 : 0 : i40e_get_cap(struct i40e_hw *hw)
4789 : : {
4790 : : struct i40e_aqc_list_capabilities_element_resp *buf;
4791 : 0 : uint16_t len, size = 0;
4792 : : int ret;
4793 : :
4794 : : /* Calculate a huge enough buff for saving response data temporarily */
4795 : : len = sizeof(struct i40e_aqc_list_capabilities_element_resp) *
4796 : : I40E_MAX_CAP_ELE_NUM;
4797 : 0 : buf = rte_zmalloc("i40e", len, 0);
4798 [ # # ]: 0 : if (!buf) {
4799 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory");
4800 : 0 : return I40E_ERR_NO_MEMORY;
4801 : : }
4802 : :
4803 : : /* Get, parse the capabilities and save it to hw */
4804 : 0 : ret = i40e_aq_discover_capabilities(hw, buf, len, &size,
4805 : : i40e_aqc_opc_list_func_capabilities, NULL);
4806 [ # # ]: 0 : if (ret != I40E_SUCCESS)
4807 : 0 : PMD_DRV_LOG(ERR, "Failed to discover capabilities");
4808 : :
4809 : : /* Free the temporary buffer after being used */
4810 : 0 : rte_free(buf);
4811 : :
4812 : 0 : return ret;
4813 : : }
4814 : :
4815 : : #define RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF 4
4816 : :
4817 : 0 : static int i40e_pf_parse_vf_queue_number_handler(const char *key,
4818 : : const char *value,
4819 : : void *opaque)
4820 : : {
4821 : : struct i40e_pf *pf;
4822 : : unsigned long num;
4823 : : char *end;
4824 : :
4825 : : pf = (struct i40e_pf *)opaque;
4826 : : RTE_SET_USED(key);
4827 : :
4828 : 0 : errno = 0;
4829 : 0 : num = strtoul(value, &end, 0);
4830 [ # # # # : 0 : if (errno != 0 || end == value || *end != 0) {
# # ]
4831 : 0 : PMD_DRV_LOG(WARNING, "Wrong VF queue number = %s, Now it is "
4832 : : "kept the value = %hu", value, pf->vf_nb_qp_max);
4833 : 0 : return -(EINVAL);
4834 : : }
4835 : :
4836 [ # # # # ]: 0 : if (num <= I40E_MAX_QP_NUM_PER_VF && rte_is_power_of_2(num))
4837 : 0 : pf->vf_nb_qp_max = (uint16_t)num;
4838 : : else
4839 : : /* here return 0 to make next valid same argument work */
4840 : 0 : PMD_DRV_LOG(WARNING, "Wrong VF queue number = %lu, it must be "
4841 : : "power of 2 and equal or less than 16 !, Now it is "
4842 : : "kept the value = %hu", num, pf->vf_nb_qp_max);
4843 : :
4844 : : return 0;
4845 : : }
4846 : :
4847 : 0 : static int i40e_pf_config_vf_rxq_number(struct rte_eth_dev *dev)
4848 : : {
4849 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4850 : : struct rte_kvargs *kvlist;
4851 : : int kvargs_count;
4852 : :
4853 : : /* set default queue number per VF as 4 */
4854 : 0 : pf->vf_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF;
4855 : :
4856 [ # # ]: 0 : if (dev->device->devargs == NULL)
4857 : : return 0;
4858 : :
4859 : 0 : kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
4860 [ # # ]: 0 : if (kvlist == NULL)
4861 : : return -(EINVAL);
4862 : :
4863 : 0 : kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_QUEUE_NUM_PER_VF_ARG);
4864 [ # # ]: 0 : if (!kvargs_count) {
4865 : 0 : rte_kvargs_free(kvlist);
4866 : 0 : return 0;
4867 : : }
4868 : :
4869 [ # # ]: 0 : if (kvargs_count > 1)
4870 : 0 : PMD_DRV_LOG(WARNING, "More than one argument \"%s\" and only "
4871 : : "the first invalid or last valid one is used !",
4872 : : ETH_I40E_QUEUE_NUM_PER_VF_ARG);
4873 : :
4874 : 0 : rte_kvargs_process(kvlist, ETH_I40E_QUEUE_NUM_PER_VF_ARG,
4875 : : i40e_pf_parse_vf_queue_number_handler, pf);
4876 : :
4877 : 0 : rte_kvargs_free(kvlist);
4878 : :
4879 : 0 : return 0;
4880 : : }
4881 : :
4882 : : static int
4883 : 0 : i40e_pf_parameter_init(struct rte_eth_dev *dev)
4884 : : {
4885 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4886 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4887 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
4888 : : uint16_t qp_count = 0, vsi_count = 0;
4889 : :
4890 [ # # # # ]: 0 : if (pci_dev->max_vfs && !hw->func_caps.sr_iov_1_1) {
4891 : 0 : PMD_INIT_LOG(ERR, "HW configuration doesn't support SRIOV");
4892 : 0 : return -EINVAL;
4893 : : }
4894 : :
4895 : 0 : i40e_pf_config_vf_rxq_number(dev);
4896 : :
4897 : : /* Add the parameter init for LFC */
4898 : 0 : pf->fc_conf.pause_time = I40E_DEFAULT_PAUSE_TIME;
4899 : 0 : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_HIGH_WATER;
4900 : 0 : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_LOW_WATER;
4901 : :
4902 : 0 : pf->flags = I40E_FLAG_HEADER_SPLIT_DISABLED;
4903 : 0 : pf->max_num_vsi = hw->func_caps.num_vsis;
4904 : 0 : pf->lan_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_PF;
4905 : 0 : pf->vmdq_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
4906 : :
4907 : : /* FDir queue/VSI allocation */
4908 : 0 : pf->fdir_qp_offset = 0;
4909 [ # # ]: 0 : if (hw->func_caps.fd) {
4910 : 0 : pf->flags |= I40E_FLAG_FDIR;
4911 : 0 : pf->fdir_nb_qps = I40E_DEFAULT_QP_NUM_FDIR;
4912 : : } else {
4913 : 0 : pf->fdir_nb_qps = 0;
4914 : : }
4915 : 0 : qp_count += pf->fdir_nb_qps;
4916 : : vsi_count += 1;
4917 : :
4918 : : /* LAN queue/VSI allocation */
4919 : 0 : pf->lan_qp_offset = pf->fdir_qp_offset + pf->fdir_nb_qps;
4920 [ # # ]: 0 : if (!hw->func_caps.rss) {
4921 : 0 : pf->lan_nb_qps = 1;
4922 : : } else {
4923 : 0 : pf->flags |= I40E_FLAG_RSS;
4924 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
4925 : 0 : pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE;
4926 : 0 : pf->lan_nb_qps = pf->lan_nb_qp_max;
4927 : : }
4928 : 0 : qp_count += pf->lan_nb_qps;
4929 : : vsi_count += 1;
4930 : :
4931 : : /* VF queue/VSI allocation */
4932 : 0 : pf->vf_qp_offset = pf->lan_qp_offset + pf->lan_nb_qps;
4933 [ # # # # ]: 0 : if (hw->func_caps.sr_iov_1_1 && pci_dev->max_vfs) {
4934 : 0 : pf->flags |= I40E_FLAG_SRIOV;
4935 : 0 : pf->vf_nb_qps = pf->vf_nb_qp_max;
4936 : 0 : pf->vf_num = pci_dev->max_vfs;
4937 : 0 : PMD_DRV_LOG(DEBUG,
4938 : : "%u VF VSIs, %u queues per VF VSI, in total %u queues",
4939 : : pf->vf_num, pf->vf_nb_qps, pf->vf_nb_qps * pf->vf_num);
4940 : : } else {
4941 : 0 : pf->vf_nb_qps = 0;
4942 : 0 : pf->vf_num = 0;
4943 : : }
4944 : 0 : qp_count += pf->vf_nb_qps * pf->vf_num;
4945 : 0 : vsi_count += pf->vf_num;
4946 : :
4947 : : /* VMDq queue/VSI allocation */
4948 : 0 : pf->vmdq_qp_offset = pf->vf_qp_offset + pf->vf_nb_qps * pf->vf_num;
4949 : 0 : pf->vmdq_nb_qps = 0;
4950 : 0 : pf->max_nb_vmdq_vsi = 0;
4951 [ # # ]: 0 : if (hw->func_caps.vmdq) {
4952 [ # # ]: 0 : if (qp_count < hw->func_caps.num_tx_qp &&
4953 [ # # ]: 0 : vsi_count < hw->func_caps.num_vsis) {
4954 : 0 : pf->max_nb_vmdq_vsi = (hw->func_caps.num_tx_qp -
4955 : 0 : qp_count) / pf->vmdq_nb_qp_max;
4956 : :
4957 : : /* Limit the maximum number of VMDq vsi to the maximum
4958 : : * ethdev can support
4959 : : */
4960 : 0 : pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
4961 : : hw->func_caps.num_vsis - vsi_count);
4962 : 0 : pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
4963 : : RTE_ETH_64_POOLS);
4964 [ # # ]: 0 : if (pf->max_nb_vmdq_vsi) {
4965 : 0 : pf->flags |= I40E_FLAG_VMDQ;
4966 : 0 : pf->vmdq_nb_qps = pf->vmdq_nb_qp_max;
4967 : 0 : PMD_DRV_LOG(DEBUG,
4968 : : "%u VMDQ VSIs, %u queues per VMDQ VSI, in total %u queues",
4969 : : pf->max_nb_vmdq_vsi, pf->vmdq_nb_qps,
4970 : : pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi);
4971 : : } else {
4972 : 0 : PMD_DRV_LOG(INFO,
4973 : : "No enough queues left for VMDq");
4974 : : }
4975 : : } else {
4976 : 0 : PMD_DRV_LOG(INFO, "No queue or VSI left for VMDq");
4977 : : }
4978 : : }
4979 : 0 : qp_count += pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi;
4980 : 0 : vsi_count += pf->max_nb_vmdq_vsi;
4981 : :
4982 [ # # ]: 0 : if (hw->func_caps.dcb)
4983 : 0 : pf->flags |= I40E_FLAG_DCB;
4984 : :
4985 [ # # ]: 0 : if (qp_count > hw->func_caps.num_tx_qp) {
4986 : 0 : PMD_DRV_LOG(ERR,
4987 : : "Failed to allocate %u queues, which exceeds the hardware maximum %u",
4988 : : qp_count, hw->func_caps.num_tx_qp);
4989 : 0 : return -EINVAL;
4990 : : }
4991 [ # # ]: 0 : if (vsi_count > hw->func_caps.num_vsis) {
4992 : 0 : PMD_DRV_LOG(ERR,
4993 : : "Failed to allocate %u VSIs, which exceeds the hardware maximum %u",
4994 : : vsi_count, hw->func_caps.num_vsis);
4995 : 0 : return -EINVAL;
4996 : : }
4997 : :
4998 : : /**
4999 : : * Enable outer VLAN processing if firmware version is greater
5000 : : * than v8.3
5001 : : */
5002 [ # # # # ]: 0 : if (hw->aq.fw_maj_ver > 8 ||
5003 [ # # ]: 0 : (hw->aq.fw_maj_ver == 8 && hw->aq.fw_min_ver > 3)) {
5004 : 0 : pf->fw8_3gt = true;
5005 : : } else {
5006 : 0 : pf->fw8_3gt = false;
5007 : : }
5008 : :
5009 : : return 0;
5010 : : }
5011 : :
5012 : : static int
5013 : 0 : i40e_pf_get_switch_config(struct i40e_pf *pf)
5014 : : {
5015 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5016 : : struct i40e_aqc_get_switch_config_resp *switch_config;
5017 : : struct i40e_aqc_switch_config_element_resp *element;
5018 : 0 : uint16_t start_seid = 0, num_reported;
5019 : : int ret;
5020 : :
5021 : : switch_config = (struct i40e_aqc_get_switch_config_resp *)\
5022 : 0 : rte_zmalloc("i40e", I40E_AQ_LARGE_BUF, 0);
5023 [ # # ]: 0 : if (!switch_config) {
5024 : 0 : PMD_DRV_LOG(ERR, "Failed to allocated memory");
5025 : 0 : return -ENOMEM;
5026 : : }
5027 : :
5028 : : /* Get the switch configurations */
5029 : 0 : ret = i40e_aq_get_switch_config(hw, switch_config,
5030 : : I40E_AQ_LARGE_BUF, &start_seid, NULL);
5031 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5032 : 0 : PMD_DRV_LOG(ERR, "Failed to get switch configurations");
5033 : 0 : goto fail;
5034 : : }
5035 : 0 : num_reported = rte_le_to_cpu_16(switch_config->header.num_reported);
5036 [ # # ]: 0 : if (num_reported != 1) { /* The number should be 1 */
5037 : 0 : PMD_DRV_LOG(ERR, "Wrong number of switch config reported");
5038 : 0 : goto fail;
5039 : : }
5040 : :
5041 : : /* Parse the switch configuration elements */
5042 : : element = &(switch_config->element[0]);
5043 [ # # ]: 0 : if (element->element_type == I40E_SWITCH_ELEMENT_TYPE_VSI) {
5044 : 0 : pf->mac_seid = rte_le_to_cpu_16(element->uplink_seid);
5045 : 0 : pf->main_vsi_seid = rte_le_to_cpu_16(element->seid);
5046 : : } else
5047 : 0 : PMD_DRV_LOG(INFO, "Unknown element type");
5048 : :
5049 : 0 : fail:
5050 : 0 : rte_free(switch_config);
5051 : :
5052 : 0 : return ret;
5053 : : }
5054 : :
5055 : : static int
5056 : 0 : i40e_res_pool_init (struct i40e_res_pool_info *pool, uint32_t base,
5057 : : uint32_t num)
5058 : : {
5059 : : struct pool_entry *entry;
5060 : :
5061 [ # # ]: 0 : if (pool == NULL || num == 0)
5062 : : return -EINVAL;
5063 : :
5064 : 0 : entry = rte_zmalloc("i40e", sizeof(*entry), 0);
5065 [ # # ]: 0 : if (entry == NULL) {
5066 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for resource pool");
5067 : 0 : return -ENOMEM;
5068 : : }
5069 : :
5070 : : /* queue heap initialize */
5071 : 0 : pool->num_free = num;
5072 : 0 : pool->num_alloc = 0;
5073 : 0 : pool->base = base;
5074 : 0 : LIST_INIT(&pool->alloc_list);
5075 : : LIST_INIT(&pool->free_list);
5076 : :
5077 : : /* Initialize element */
5078 : 0 : entry->base = 0;
5079 : 0 : entry->len = num;
5080 : :
5081 : 0 : LIST_INSERT_HEAD(&pool->free_list, entry, next);
5082 : 0 : return 0;
5083 : : }
5084 : :
5085 : : static void
5086 : 0 : i40e_res_pool_destroy(struct i40e_res_pool_info *pool)
5087 : : {
5088 : : struct pool_entry *entry, *next_entry;
5089 : :
5090 [ # # ]: 0 : if (pool == NULL)
5091 : : return;
5092 : :
5093 [ # # ]: 0 : for (entry = LIST_FIRST(&pool->alloc_list); entry; entry = next_entry) {
5094 : 0 : next_entry = LIST_NEXT(entry, next);
5095 [ # # ]: 0 : LIST_REMOVE(entry, next);
5096 : 0 : rte_free(entry);
5097 : : }
5098 : :
5099 [ # # ]: 0 : for (entry = LIST_FIRST(&pool->free_list); entry; entry = next_entry) {
5100 : 0 : next_entry = LIST_NEXT(entry, next);
5101 [ # # ]: 0 : LIST_REMOVE(entry, next);
5102 : 0 : rte_free(entry);
5103 : : }
5104 : :
5105 : 0 : pool->num_free = 0;
5106 : 0 : pool->num_alloc = 0;
5107 : 0 : pool->base = 0;
5108 : 0 : LIST_INIT(&pool->alloc_list);
5109 : 0 : LIST_INIT(&pool->free_list);
5110 : : }
5111 : :
5112 : : static int
5113 : 0 : i40e_res_pool_free(struct i40e_res_pool_info *pool,
5114 : : uint32_t base)
5115 : : {
5116 : : struct pool_entry *entry, *next, *prev, *valid_entry = NULL;
5117 : : uint32_t pool_offset;
5118 : : uint16_t len;
5119 : : int insert;
5120 : :
5121 [ # # ]: 0 : if (pool == NULL) {
5122 : 0 : PMD_DRV_LOG(ERR, "Invalid parameter");
5123 : 0 : return -EINVAL;
5124 : : }
5125 : :
5126 : 0 : pool_offset = base - pool->base;
5127 : : /* Lookup in alloc list */
5128 [ # # ]: 0 : LIST_FOREACH(entry, &pool->alloc_list, next) {
5129 [ # # ]: 0 : if (entry->base == pool_offset) {
5130 : : valid_entry = entry;
5131 [ # # ]: 0 : LIST_REMOVE(entry, next);
5132 : 0 : break;
5133 : : }
5134 : : }
5135 : :
5136 : : /* Not find, return */
5137 [ # # ]: 0 : if (valid_entry == NULL) {
5138 : 0 : PMD_DRV_LOG(ERR, "Failed to find entry");
5139 : 0 : return -EINVAL;
5140 : : }
5141 : :
5142 : : /**
5143 : : * Found it, move it to free list and try to merge.
5144 : : * In order to make merge easier, always sort it by qbase.
5145 : : * Find adjacent prev and last entries.
5146 : : */
5147 : : prev = next = NULL;
5148 [ # # ]: 0 : LIST_FOREACH(entry, &pool->free_list, next) {
5149 [ # # ]: 0 : if (entry->base > valid_entry->base) {
5150 : : next = entry;
5151 : : break;
5152 : : }
5153 : : prev = entry;
5154 : : }
5155 : :
5156 : : insert = 0;
5157 : 0 : len = valid_entry->len;
5158 : : /* Try to merge with next one*/
5159 [ # # ]: 0 : if (next != NULL) {
5160 : : /* Merge with next one */
5161 [ # # ]: 0 : if (valid_entry->base + len == next->base) {
5162 : 0 : next->base = valid_entry->base;
5163 : 0 : next->len += len;
5164 : 0 : rte_free(valid_entry);
5165 : : valid_entry = next;
5166 : : insert = 1;
5167 : : }
5168 : : }
5169 : :
5170 [ # # ]: 0 : if (prev != NULL) {
5171 : : /* Merge with previous one */
5172 [ # # ]: 0 : if (prev->base + prev->len == valid_entry->base) {
5173 : 0 : prev->len += len;
5174 : : /* If it merge with next one, remove next node */
5175 [ # # ]: 0 : if (insert == 1) {
5176 [ # # ]: 0 : LIST_REMOVE(valid_entry, next);
5177 : 0 : rte_free(valid_entry);
5178 : : valid_entry = NULL;
5179 : : } else {
5180 : 0 : rte_free(valid_entry);
5181 : : valid_entry = NULL;
5182 : : insert = 1;
5183 : : }
5184 : : }
5185 : : }
5186 : :
5187 : : /* Not find any entry to merge, insert */
5188 [ # # ]: 0 : if (insert == 0) {
5189 [ # # ]: 0 : if (prev != NULL)
5190 [ # # ]: 0 : LIST_INSERT_AFTER(prev, valid_entry, next);
5191 [ # # ]: 0 : else if (next != NULL)
5192 : 0 : LIST_INSERT_BEFORE(next, valid_entry, next);
5193 : : else /* It's empty list, insert to head */
5194 [ # # ]: 0 : LIST_INSERT_HEAD(&pool->free_list, valid_entry, next);
5195 : : }
5196 : :
5197 : 0 : pool->num_free += len;
5198 : 0 : pool->num_alloc -= len;
5199 : :
5200 : 0 : return 0;
5201 : : }
5202 : :
5203 : : static int
5204 : 0 : i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
5205 : : uint16_t num)
5206 : : {
5207 : : struct pool_entry *entry, *valid_entry;
5208 : :
5209 [ # # ]: 0 : if (pool == NULL || num == 0) {
5210 : 0 : PMD_DRV_LOG(ERR, "Invalid parameter");
5211 : 0 : return -EINVAL;
5212 : : }
5213 : :
5214 [ # # ]: 0 : if (pool->num_free < num) {
5215 : 0 : PMD_DRV_LOG(ERR, "No resource. ask:%u, available:%u",
5216 : : num, pool->num_free);
5217 : 0 : return -ENOMEM;
5218 : : }
5219 : :
5220 : : valid_entry = NULL;
5221 : : /* Lookup in free list and find most fit one */
5222 [ # # ]: 0 : LIST_FOREACH(entry, &pool->free_list, next) {
5223 [ # # ]: 0 : if (entry->len >= num) {
5224 : : /* Find best one */
5225 [ # # ]: 0 : if (entry->len == num) {
5226 : : valid_entry = entry;
5227 : : break;
5228 : : }
5229 [ # # # # ]: 0 : if (valid_entry == NULL || valid_entry->len > entry->len)
5230 : : valid_entry = entry;
5231 : : }
5232 : : }
5233 : :
5234 : : /* Not find one to satisfy the request, return */
5235 [ # # ]: 0 : if (valid_entry == NULL) {
5236 : 0 : PMD_DRV_LOG(ERR, "No valid entry found");
5237 : 0 : return -ENOMEM;
5238 : : }
5239 : : /**
5240 : : * The entry have equal queue number as requested,
5241 : : * remove it from alloc_list.
5242 : : */
5243 [ # # ]: 0 : if (valid_entry->len == num) {
5244 [ # # ]: 0 : LIST_REMOVE(valid_entry, next);
5245 : : } else {
5246 : : /**
5247 : : * The entry have more numbers than requested,
5248 : : * create a new entry for alloc_list and minus its
5249 : : * queue base and number in free_list.
5250 : : */
5251 : 0 : entry = rte_zmalloc("res_pool", sizeof(*entry), 0);
5252 [ # # ]: 0 : if (entry == NULL) {
5253 : 0 : PMD_DRV_LOG(ERR,
5254 : : "Failed to allocate memory for resource pool");
5255 : 0 : return -ENOMEM;
5256 : : }
5257 : 0 : entry->base = valid_entry->base;
5258 : 0 : entry->len = num;
5259 : 0 : valid_entry->base += num;
5260 : 0 : valid_entry->len -= num;
5261 : : valid_entry = entry;
5262 : : }
5263 : :
5264 : : /* Insert it into alloc list, not sorted */
5265 [ # # ]: 0 : LIST_INSERT_HEAD(&pool->alloc_list, valid_entry, next);
5266 : :
5267 : 0 : pool->num_free -= valid_entry->len;
5268 : 0 : pool->num_alloc += valid_entry->len;
5269 : :
5270 : 0 : return valid_entry->base + pool->base;
5271 : : }
5272 : :
5273 : : /**
5274 : : * bitmap_is_subset - Check whether src2 is subset of src1
5275 : : **/
5276 : : static inline int
5277 : : bitmap_is_subset(uint8_t src1, uint8_t src2)
5278 : : {
5279 : 0 : return !((src1 ^ src2) & src2);
5280 : : }
5281 : :
5282 : : static enum i40e_status_code
5283 : 0 : validate_tcmap_parameter(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
5284 : : {
5285 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5286 : :
5287 : : /* If DCB is not supported, only default TC is supported */
5288 [ # # # # ]: 0 : if (!hw->func_caps.dcb && enabled_tcmap != I40E_DEFAULT_TCMAP) {
5289 : 0 : PMD_DRV_LOG(ERR, "DCB is not enabled, only TC0 is supported");
5290 : 0 : return I40E_NOT_SUPPORTED;
5291 : : }
5292 : :
5293 [ # # ]: 0 : if (!bitmap_is_subset(hw->func_caps.enabled_tcmap, enabled_tcmap)) {
5294 : 0 : PMD_DRV_LOG(ERR,
5295 : : "Enabled TC map 0x%x not applicable to HW support 0x%x",
5296 : : hw->func_caps.enabled_tcmap, enabled_tcmap);
5297 : 0 : return I40E_NOT_SUPPORTED;
5298 : : }
5299 : : return I40E_SUCCESS;
5300 : : }
5301 : :
5302 : : int
5303 : 0 : i40e_vsi_vlan_pvid_set(struct i40e_vsi *vsi,
5304 : : struct i40e_vsi_vlan_pvid_info *info)
5305 : : {
5306 : : struct i40e_hw *hw;
5307 : : struct i40e_vsi_context ctxt;
5308 : : uint8_t vlan_flags = 0;
5309 : : int ret;
5310 : :
5311 [ # # ]: 0 : if (vsi == NULL || info == NULL) {
5312 : 0 : PMD_DRV_LOG(ERR, "invalid parameters");
5313 : 0 : return I40E_ERR_PARAM;
5314 : : }
5315 : :
5316 [ # # ]: 0 : if (info->on) {
5317 : 0 : vsi->info.pvid = info->config.pvid;
5318 : : /**
5319 : : * If insert pvid is enabled, only tagged pkts are
5320 : : * allowed to be sent out.
5321 : : */
5322 : : vlan_flags |= I40E_AQ_VSI_PVLAN_INSERT_PVID |
5323 : : I40E_AQ_VSI_PVLAN_MODE_TAGGED;
5324 : : } else {
5325 : 0 : vsi->info.pvid = 0;
5326 [ # # ]: 0 : if (info->config.reject.tagged == 0)
5327 : : vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_TAGGED;
5328 : :
5329 [ # # ]: 0 : if (info->config.reject.untagged == 0)
5330 : 0 : vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_UNTAGGED;
5331 : : }
5332 : 0 : vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_INSERT_PVID |
5333 : : I40E_AQ_VSI_PVLAN_MODE_MASK);
5334 : 0 : vsi->info.port_vlan_flags |= vlan_flags;
5335 [ # # ]: 0 : vsi->info.valid_sections =
5336 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5337 : : memset(&ctxt, 0, sizeof(ctxt));
5338 [ # # ]: 0 : rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
5339 : 0 : ctxt.seid = vsi->seid;
5340 : :
5341 : 0 : hw = I40E_VSI_TO_HW(vsi);
5342 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5343 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5344 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI params");
5345 : :
5346 : : return ret;
5347 : : }
5348 : :
5349 : : static int
5350 : 0 : i40e_vsi_update_tc_bandwidth(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
5351 : : {
5352 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5353 : : int i, ret;
5354 : : struct i40e_aqc_configure_vsi_tc_bw_data tc_bw_data;
5355 : :
5356 : 0 : ret = validate_tcmap_parameter(vsi, enabled_tcmap);
5357 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5358 : : return ret;
5359 : :
5360 [ # # ]: 0 : if (!vsi->seid) {
5361 : 0 : PMD_DRV_LOG(ERR, "seid not valid");
5362 : 0 : return -EINVAL;
5363 : : }
5364 : :
5365 : : memset(&tc_bw_data, 0, sizeof(tc_bw_data));
5366 : 0 : tc_bw_data.tc_valid_bits = enabled_tcmap;
5367 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5368 : 0 : tc_bw_data.tc_bw_credits[i] =
5369 : 0 : (enabled_tcmap & (1 << i)) ? 1 : 0;
5370 : :
5371 : 0 : ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &tc_bw_data, NULL);
5372 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5373 : 0 : PMD_DRV_LOG(ERR, "Failed to configure TC BW");
5374 : 0 : return ret;
5375 : : }
5376 : :
5377 [ # # ]: 0 : rte_memcpy(vsi->info.qs_handle, tc_bw_data.qs_handles,
5378 : : sizeof(vsi->info.qs_handle));
5379 : : return I40E_SUCCESS;
5380 : : }
5381 : :
5382 : : static enum i40e_status_code
5383 : 0 : i40e_vsi_config_tc_queue_mapping(struct i40e_vsi *vsi,
5384 : : struct i40e_aqc_vsi_properties_data *info,
5385 : : uint8_t enabled_tcmap)
5386 : : {
5387 : : enum i40e_status_code ret;
5388 : : int i, total_tc = 0;
5389 : : uint16_t qpnum_per_tc, bsf, qp_idx;
5390 : :
5391 : 0 : ret = validate_tcmap_parameter(vsi, enabled_tcmap);
5392 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5393 : : return ret;
5394 : :
5395 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5396 [ # # ]: 0 : if (enabled_tcmap & (1 << i))
5397 : 0 : total_tc++;
5398 [ # # ]: 0 : if (total_tc == 0)
5399 : : total_tc = 1;
5400 : 0 : vsi->enabled_tc = enabled_tcmap;
5401 : :
5402 : : /* Number of queues per enabled TC */
5403 [ # # ]: 0 : qpnum_per_tc = i40e_align_floor(vsi->nb_qps / total_tc);
5404 : 0 : qpnum_per_tc = RTE_MIN(qpnum_per_tc, I40E_MAX_Q_PER_TC);
5405 [ # # ]: 0 : bsf = rte_bsf32(qpnum_per_tc);
5406 : :
5407 : : /* Adjust the queue number to actual queues that can be applied */
5408 [ # # # # ]: 0 : if (!(vsi->type == I40E_VSI_MAIN && total_tc == 1))
5409 : 0 : vsi->nb_qps = qpnum_per_tc * total_tc;
5410 : :
5411 : : /**
5412 : : * Configure TC and queue mapping parameters, for enabled TC,
5413 : : * allocate qpnum_per_tc queues to this traffic. For disabled TC,
5414 : : * default queue will serve it.
5415 : : */
5416 : : qp_idx = 0;
5417 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5418 [ # # ]: 0 : if (vsi->enabled_tc & (1 << i)) {
5419 : 0 : info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
5420 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
5421 : : (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
5422 : 0 : qp_idx += qpnum_per_tc;
5423 : : } else
5424 : 0 : info->tc_mapping[i] = 0;
5425 : : }
5426 : :
5427 : : /* Associate queue number with VSI */
5428 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
5429 : 0 : info->mapping_flags |=
5430 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
5431 [ # # ]: 0 : for (i = 0; i < vsi->nb_qps; i++)
5432 : 0 : info->queue_mapping[i] =
5433 : 0 : rte_cpu_to_le_16(vsi->base_queue + i);
5434 : : } else {
5435 : 0 : info->mapping_flags |=
5436 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
5437 : 0 : info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
5438 : : }
5439 : 0 : info->valid_sections |=
5440 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
5441 : :
5442 : 0 : return I40E_SUCCESS;
5443 : : }
5444 : :
5445 : : static int
5446 : 0 : i40e_veb_release(struct i40e_veb *veb)
5447 : : {
5448 : : struct i40e_vsi *vsi;
5449 : : struct i40e_hw *hw;
5450 : :
5451 [ # # ]: 0 : if (veb == NULL)
5452 : : return -EINVAL;
5453 : :
5454 [ # # ]: 0 : if (!TAILQ_EMPTY(&veb->head)) {
5455 : 0 : PMD_DRV_LOG(ERR, "VEB still has VSI attached, can't remove");
5456 : 0 : return -EACCES;
5457 : : }
5458 : : /* associate_vsi field is NULL for floating VEB */
5459 [ # # ]: 0 : if (veb->associate_vsi != NULL) {
5460 : : vsi = veb->associate_vsi;
5461 : 0 : hw = I40E_VSI_TO_HW(vsi);
5462 : :
5463 : 0 : vsi->uplink_seid = veb->uplink_seid;
5464 : 0 : vsi->veb = NULL;
5465 : : } else {
5466 : 0 : veb->associate_pf->main_vsi->floating_veb = NULL;
5467 : 0 : hw = I40E_VSI_TO_HW(veb->associate_pf->main_vsi);
5468 : : }
5469 : :
5470 : 0 : i40e_aq_delete_element(hw, veb->seid, NULL);
5471 : 0 : rte_free(veb);
5472 : 0 : return I40E_SUCCESS;
5473 : : }
5474 : :
5475 : : /* Setup a veb */
5476 : : static struct i40e_veb *
5477 : 0 : i40e_veb_setup(struct i40e_pf *pf, struct i40e_vsi *vsi)
5478 : : {
5479 : : struct i40e_veb *veb;
5480 : : int ret;
5481 : : struct i40e_hw *hw;
5482 : :
5483 [ # # ]: 0 : if (pf == NULL) {
5484 : 0 : PMD_DRV_LOG(ERR,
5485 : : "veb setup failed, associated PF shouldn't null");
5486 : 0 : return NULL;
5487 : : }
5488 : 0 : hw = I40E_PF_TO_HW(pf);
5489 : :
5490 : 0 : veb = rte_zmalloc("i40e_veb", sizeof(struct i40e_veb), 0);
5491 [ # # ]: 0 : if (!veb) {
5492 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for veb");
5493 : 0 : goto fail;
5494 : : }
5495 : :
5496 : 0 : veb->associate_vsi = vsi;
5497 : 0 : veb->associate_pf = pf;
5498 : 0 : TAILQ_INIT(&veb->head);
5499 [ # # ]: 0 : veb->uplink_seid = vsi ? vsi->uplink_seid : 0;
5500 : :
5501 : : /* create floating veb if vsi is NULL */
5502 [ # # ]: 0 : if (vsi != NULL) {
5503 : 0 : ret = i40e_aq_add_veb(hw, veb->uplink_seid, vsi->seid,
5504 : : I40E_DEFAULT_TCMAP, false,
5505 : 0 : &veb->seid, false, NULL);
5506 : : } else {
5507 : 0 : ret = i40e_aq_add_veb(hw, 0, 0, I40E_DEFAULT_TCMAP,
5508 : 0 : true, &veb->seid, false, NULL);
5509 : : }
5510 : :
5511 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5512 : 0 : PMD_DRV_LOG(ERR, "Add veb failed, aq_err: %d",
5513 : : hw->aq.asq_last_status);
5514 : 0 : goto fail;
5515 : : }
5516 : 0 : veb->enabled_tc = I40E_DEFAULT_TCMAP;
5517 : :
5518 : : /* get statistics index */
5519 : 0 : ret = i40e_aq_get_veb_parameters(hw, veb->seid, NULL, NULL,
5520 : 0 : &veb->stats_idx, NULL, NULL, NULL);
5521 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5522 : 0 : PMD_DRV_LOG(ERR, "Get veb statistics index failed, aq_err: %d",
5523 : : hw->aq.asq_last_status);
5524 : 0 : goto fail;
5525 : : }
5526 : : /* Get VEB bandwidth, to be implemented */
5527 : : /* Now associated vsi binding to the VEB, set uplink to this VEB */
5528 [ # # ]: 0 : if (vsi)
5529 : 0 : vsi->uplink_seid = veb->seid;
5530 : :
5531 : : return veb;
5532 : 0 : fail:
5533 : 0 : rte_free(veb);
5534 : 0 : return NULL;
5535 : : }
5536 : :
5537 : : int
5538 : 0 : i40e_vsi_release(struct i40e_vsi *vsi)
5539 : : {
5540 : : struct i40e_pf *pf;
5541 : : struct i40e_hw *hw;
5542 : : struct i40e_vsi_list *vsi_list;
5543 : : void *temp;
5544 : : int ret;
5545 : : struct i40e_mac_filter *f;
5546 : : uint16_t user_param;
5547 : :
5548 [ # # ]: 0 : if (!vsi)
5549 : : return I40E_SUCCESS;
5550 : :
5551 [ # # ]: 0 : if (!vsi->adapter)
5552 : : return -EFAULT;
5553 : :
5554 : 0 : user_param = vsi->user_param;
5555 : :
5556 : : pf = I40E_VSI_TO_PF(vsi);
5557 : 0 : hw = I40E_VSI_TO_HW(vsi);
5558 : :
5559 : : /* VSI has child to attach, release child first */
5560 [ # # ]: 0 : if (vsi->veb) {
5561 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(vsi_list, &vsi->veb->head, list, temp) {
5562 [ # # ]: 0 : if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
5563 : : return -1;
5564 : : }
5565 : 0 : i40e_veb_release(vsi->veb);
5566 : : }
5567 : :
5568 [ # # ]: 0 : if (vsi->floating_veb) {
5569 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(vsi_list, &vsi->floating_veb->head,
5570 : : list, temp) {
5571 [ # # ]: 0 : if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
5572 : : return -1;
5573 : : }
5574 : : }
5575 : :
5576 : : /* Remove all macvlan filters of the VSI */
5577 : 0 : i40e_vsi_remove_all_macvlan_filter(vsi);
5578 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp)
5579 : 0 : rte_free(f);
5580 : :
5581 [ # # # # ]: 0 : if (vsi->type != I40E_VSI_MAIN &&
5582 : 0 : ((vsi->type != I40E_VSI_SRIOV) ||
5583 [ # # ]: 0 : !pf->floating_veb_list[user_param])) {
5584 : : /* Remove vsi from parent's sibling list */
5585 [ # # # # ]: 0 : if (vsi->parent_vsi == NULL || vsi->parent_vsi->veb == NULL) {
5586 : 0 : PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
5587 : 0 : return I40E_ERR_PARAM;
5588 : : }
5589 [ # # ]: 0 : TAILQ_REMOVE(&vsi->parent_vsi->veb->head,
5590 : : &vsi->sib_vsi_list, list);
5591 : :
5592 : : /* Remove all switch element of the VSI */
5593 : 0 : ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
5594 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5595 : 0 : PMD_DRV_LOG(ERR, "Failed to delete element");
5596 : : }
5597 : :
5598 [ # # ]: 0 : if ((vsi->type == I40E_VSI_SRIOV) &&
5599 [ # # ]: 0 : pf->floating_veb_list[user_param]) {
5600 : : /* Remove vsi from parent's sibling list */
5601 [ # # ]: 0 : if (vsi->parent_vsi == NULL ||
5602 [ # # ]: 0 : vsi->parent_vsi->floating_veb == NULL) {
5603 : 0 : PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
5604 : 0 : return I40E_ERR_PARAM;
5605 : : }
5606 [ # # ]: 0 : TAILQ_REMOVE(&vsi->parent_vsi->floating_veb->head,
5607 : : &vsi->sib_vsi_list, list);
5608 : :
5609 : : /* Remove all switch element of the VSI */
5610 : 0 : ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
5611 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5612 : 0 : PMD_DRV_LOG(ERR, "Failed to delete element");
5613 : : }
5614 : :
5615 : 0 : i40e_res_pool_free(&pf->qp_pool, vsi->base_queue);
5616 : :
5617 [ # # ]: 0 : if (vsi->type != I40E_VSI_SRIOV)
5618 : 0 : i40e_res_pool_free(&pf->msix_pool, vsi->msix_intr);
5619 : 0 : rte_free(vsi);
5620 : :
5621 : 0 : return I40E_SUCCESS;
5622 : : }
5623 : :
5624 : : static int
5625 : 0 : i40e_update_default_filter_setting(struct i40e_vsi *vsi)
5626 : : {
5627 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5628 : : struct i40e_aqc_remove_macvlan_element_data def_filter;
5629 : : struct i40e_mac_filter_info filter;
5630 : : int ret;
5631 : :
5632 [ # # ]: 0 : if (vsi->type != I40E_VSI_MAIN)
5633 : : return I40E_ERR_CONFIG;
5634 : : memset(&def_filter, 0, sizeof(def_filter));
5635 [ # # ]: 0 : rte_memcpy(def_filter.mac_addr, hw->mac.perm_addr,
5636 : : ETH_ADDR_LEN);
5637 : : def_filter.vlan_tag = 0;
5638 : 0 : def_filter.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
5639 : : I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
5640 : 0 : ret = i40e_aq_remove_macvlan(hw, vsi->seid, &def_filter, 1, NULL);
5641 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5642 : : struct i40e_mac_filter *f;
5643 : : struct rte_ether_addr *mac;
5644 : :
5645 : 0 : PMD_DRV_LOG(DEBUG,
5646 : : "Cannot remove the default macvlan filter");
5647 : : /* It needs to add the permanent mac into mac list */
5648 : 0 : f = rte_zmalloc("macv_filter", sizeof(*f), 0);
5649 [ # # ]: 0 : if (f == NULL) {
5650 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
5651 : 0 : return I40E_ERR_NO_MEMORY;
5652 : : }
5653 : : mac = &f->mac_info.mac_addr;
5654 [ # # ]: 0 : rte_memcpy(&mac->addr_bytes, hw->mac.perm_addr,
5655 : : ETH_ADDR_LEN);
5656 : 0 : f->mac_info.filter_type = I40E_MACVLAN_PERFECT_MATCH;
5657 : 0 : TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
5658 : 0 : vsi->mac_num++;
5659 : :
5660 : 0 : return ret;
5661 : : }
5662 : : rte_memcpy(&filter.mac_addr,
5663 : : (struct rte_ether_addr *)(hw->mac.perm_addr), ETH_ADDR_LEN);
5664 : 0 : filter.filter_type = I40E_MACVLAN_PERFECT_MATCH;
5665 : 0 : return i40e_vsi_add_mac(vsi, &filter);
5666 : : }
5667 : :
5668 : : /*
5669 : : * i40e_vsi_get_bw_config - Query VSI BW Information
5670 : : * @vsi: the VSI to be queried
5671 : : *
5672 : : * Returns 0 on success, negative value on failure
5673 : : */
5674 : : static enum i40e_status_code
5675 : 0 : i40e_vsi_get_bw_config(struct i40e_vsi *vsi)
5676 : : {
5677 : : struct i40e_aqc_query_vsi_bw_config_resp bw_config;
5678 : : struct i40e_aqc_query_vsi_ets_sla_config_resp ets_sla_config;
5679 : 0 : struct i40e_hw *hw = &vsi->adapter->hw;
5680 : : i40e_status ret;
5681 : : int i;
5682 : : uint32_t bw_max;
5683 : :
5684 : : memset(&bw_config, 0, sizeof(bw_config));
5685 : 0 : ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
5686 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5687 : 0 : PMD_DRV_LOG(ERR, "VSI failed to get bandwidth configuration %u",
5688 : : hw->aq.asq_last_status);
5689 : 0 : return ret;
5690 : : }
5691 : :
5692 : : memset(&ets_sla_config, 0, sizeof(ets_sla_config));
5693 : 0 : ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid,
5694 : : &ets_sla_config, NULL);
5695 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5696 : 0 : PMD_DRV_LOG(ERR,
5697 : : "VSI failed to get TC bandwidth configuration %u",
5698 : : hw->aq.asq_last_status);
5699 : 0 : return ret;
5700 : : }
5701 : :
5702 : : /* store and print out BW info */
5703 : 0 : vsi->bw_info.bw_limit = rte_le_to_cpu_16(bw_config.port_bw_limit);
5704 : 0 : vsi->bw_info.bw_max = bw_config.max_bw;
5705 : 0 : PMD_DRV_LOG(DEBUG, "VSI bw limit:%u", vsi->bw_info.bw_limit);
5706 : 0 : PMD_DRV_LOG(DEBUG, "VSI max_bw:%u", vsi->bw_info.bw_max);
5707 : 0 : bw_max = rte_le_to_cpu_16(ets_sla_config.tc_bw_max[0]) |
5708 : 0 : (rte_le_to_cpu_16(ets_sla_config.tc_bw_max[1]) <<
5709 : : I40E_16_BIT_WIDTH);
5710 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5711 : 0 : vsi->bw_info.bw_ets_share_credits[i] =
5712 : 0 : ets_sla_config.share_credits[i];
5713 : 0 : vsi->bw_info.bw_ets_credits[i] =
5714 : 0 : rte_le_to_cpu_16(ets_sla_config.credits[i]);
5715 : : /* 4 bits per TC, 4th bit is reserved */
5716 : 0 : vsi->bw_info.bw_ets_max[i] =
5717 : 0 : (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
5718 : : RTE_LEN2MASK(3, uint8_t));
5719 : 0 : PMD_DRV_LOG(DEBUG, "\tVSI TC%u:share credits %u", i,
5720 : : vsi->bw_info.bw_ets_share_credits[i]);
5721 : 0 : PMD_DRV_LOG(DEBUG, "\tVSI TC%u:credits %u", i,
5722 : : vsi->bw_info.bw_ets_credits[i]);
5723 : 0 : PMD_DRV_LOG(DEBUG, "\tVSI TC%u: max credits: %u", i,
5724 : : vsi->bw_info.bw_ets_max[i]);
5725 : : }
5726 : :
5727 : : return I40E_SUCCESS;
5728 : : }
5729 : :
5730 : : /* i40e_enable_pf_lb
5731 : : * @pf: pointer to the pf structure
5732 : : *
5733 : : * allow loopback on pf
5734 : : */
5735 : : static inline void
5736 : 0 : i40e_enable_pf_lb(struct i40e_pf *pf)
5737 : : {
5738 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5739 : : struct i40e_vsi_context ctxt;
5740 : : int ret;
5741 : :
5742 : : /* Use the FW API if FW >= v5.0 */
5743 [ # # # # ]: 0 : if (hw->aq.fw_maj_ver < 5 && hw->mac.type != I40E_MAC_X722) {
5744 : 0 : PMD_INIT_LOG(ERR, "FW < v5.0, cannot enable loopback");
5745 : 0 : return;
5746 : : }
5747 : :
5748 : : memset(&ctxt, 0, sizeof(ctxt));
5749 : 0 : ctxt.seid = pf->main_vsi_seid;
5750 : 0 : ctxt.pf_num = hw->pf_id;
5751 : 0 : ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5752 [ # # ]: 0 : if (ret) {
5753 : 0 : PMD_DRV_LOG(ERR, "cannot get pf vsi config, err %d, aq_err %d",
5754 : : ret, hw->aq.asq_last_status);
5755 : 0 : return;
5756 : : }
5757 : 0 : ctxt.flags = I40E_AQ_VSI_TYPE_PF;
5758 : 0 : ctxt.info.valid_sections =
5759 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5760 : 0 : ctxt.info.switch_id |=
5761 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5762 : :
5763 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5764 [ # # ]: 0 : if (ret)
5765 : 0 : PMD_DRV_LOG(ERR, "update vsi switch failed, aq_err=%d",
5766 : : hw->aq.asq_last_status);
5767 : : }
5768 : :
5769 : : /* i40e_pf_set_source_prune
5770 : : * @pf: pointer to the pf structure
5771 : : * @on: Enable/disable source prune
5772 : : *
5773 : : * set source prune on pf
5774 : : */
5775 : : int
5776 : 0 : i40e_pf_set_source_prune(struct i40e_pf *pf, int on)
5777 : : {
5778 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5779 : : struct i40e_vsi_context ctxt;
5780 : : int ret;
5781 : :
5782 : : memset(&ctxt, 0, sizeof(ctxt));
5783 : 0 : ctxt.seid = pf->main_vsi_seid;
5784 : 0 : ctxt.pf_num = hw->pf_id;
5785 : 0 : ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5786 [ # # ]: 0 : if (ret) {
5787 : 0 : PMD_DRV_LOG(ERR, "cannot get pf vsi config, err %d, aq_err %d",
5788 : : ret, hw->aq.asq_last_status);
5789 : 0 : return ret;
5790 : : }
5791 : 0 : ctxt.flags = I40E_AQ_VSI_TYPE_PF;
5792 : 0 : ctxt.info.valid_sections =
5793 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5794 [ # # ]: 0 : if (on)
5795 : 0 : ctxt.info.switch_id &=
5796 : : ~rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
5797 : : else
5798 : 0 : ctxt.info.switch_id |=
5799 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
5800 : :
5801 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5802 [ # # ]: 0 : if (ret)
5803 : 0 : PMD_DRV_LOG(ERR, "update vsi switch failed, aq_err=%d",
5804 : : hw->aq.asq_last_status);
5805 : :
5806 : : return ret;
5807 : : }
5808 : :
5809 : : /* Setup a VSI */
5810 : : struct i40e_vsi *
5811 : 0 : i40e_vsi_setup(struct i40e_pf *pf,
5812 : : enum i40e_vsi_type type,
5813 : : struct i40e_vsi *uplink_vsi,
5814 : : uint16_t user_param)
5815 : : {
5816 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5817 : : struct i40e_vsi *vsi;
5818 : : struct i40e_mac_filter_info filter;
5819 : : int ret;
5820 : : struct i40e_vsi_context ctxt;
5821 : 0 : struct rte_ether_addr broadcast =
5822 : : {.addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
5823 : :
5824 [ # # # # ]: 0 : if (type != I40E_VSI_MAIN && type != I40E_VSI_SRIOV &&
5825 : : uplink_vsi == NULL) {
5826 : 0 : PMD_DRV_LOG(ERR,
5827 : : "VSI setup failed, VSI link shouldn't be NULL");
5828 : 0 : return NULL;
5829 : : }
5830 : :
5831 [ # # ]: 0 : if (type == I40E_VSI_MAIN && uplink_vsi != NULL) {
5832 : 0 : PMD_DRV_LOG(ERR,
5833 : : "VSI setup failed, MAIN VSI uplink VSI should be NULL");
5834 : 0 : return NULL;
5835 : : }
5836 : :
5837 : : /* two situations
5838 : : * 1.type is not MAIN and uplink vsi is not NULL
5839 : : * If uplink vsi didn't setup VEB, create one first under veb field
5840 : : * 2.type is SRIOV and the uplink is NULL
5841 : : * If floating VEB is NULL, create one veb under floating veb field
5842 : : */
5843 : :
5844 [ # # ]: 0 : if (type != I40E_VSI_MAIN && uplink_vsi != NULL &&
5845 [ # # ]: 0 : uplink_vsi->veb == NULL) {
5846 : 0 : uplink_vsi->veb = i40e_veb_setup(pf, uplink_vsi);
5847 : :
5848 [ # # ]: 0 : if (uplink_vsi->veb == NULL) {
5849 : 0 : PMD_DRV_LOG(ERR, "VEB setup failed");
5850 : 0 : return NULL;
5851 : : }
5852 : : /* set ALLOWLOOPBACk on pf, when veb is created */
5853 : 0 : i40e_enable_pf_lb(pf);
5854 : : }
5855 : :
5856 [ # # ]: 0 : if (type == I40E_VSI_SRIOV && uplink_vsi == NULL &&
5857 [ # # ]: 0 : pf->main_vsi->floating_veb == NULL) {
5858 : 0 : pf->main_vsi->floating_veb = i40e_veb_setup(pf, uplink_vsi);
5859 : :
5860 [ # # ]: 0 : if (pf->main_vsi->floating_veb == NULL) {
5861 : 0 : PMD_DRV_LOG(ERR, "VEB setup failed");
5862 : 0 : return NULL;
5863 : : }
5864 : : }
5865 : :
5866 : : /* source prune is disabled to support VRRP in default*/
5867 : 0 : i40e_pf_set_source_prune(pf, 0);
5868 : :
5869 : 0 : vsi = rte_zmalloc("i40e_vsi", sizeof(struct i40e_vsi), 0);
5870 [ # # ]: 0 : if (!vsi) {
5871 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for vsi");
5872 : 0 : return NULL;
5873 : : }
5874 : 0 : TAILQ_INIT(&vsi->mac_list);
5875 : 0 : vsi->type = type;
5876 : 0 : vsi->adapter = I40E_PF_TO_ADAPTER(pf);
5877 : 0 : vsi->max_macaddrs = I40E_NUM_MACADDR_MAX;
5878 [ # # ]: 0 : vsi->parent_vsi = uplink_vsi ? uplink_vsi : pf->main_vsi;
5879 : 0 : vsi->user_param = user_param;
5880 : 0 : vsi->vlan_anti_spoof_on = 0;
5881 : 0 : vsi->vlan_filter_on = 0;
5882 : : /* Allocate queues */
5883 [ # # # # : 0 : switch (vsi->type) {
# ]
5884 : 0 : case I40E_VSI_MAIN :
5885 : 0 : vsi->nb_qps = pf->lan_nb_qps;
5886 : 0 : break;
5887 : 0 : case I40E_VSI_SRIOV :
5888 : 0 : vsi->nb_qps = pf->vf_nb_qps;
5889 : 0 : break;
5890 : 0 : case I40E_VSI_VMDQ2:
5891 : 0 : vsi->nb_qps = pf->vmdq_nb_qps;
5892 : 0 : break;
5893 : 0 : case I40E_VSI_FDIR:
5894 : 0 : vsi->nb_qps = pf->fdir_nb_qps;
5895 : 0 : break;
5896 : 0 : default:
5897 : 0 : goto fail_mem;
5898 : : }
5899 : : /*
5900 : : * The filter status descriptor is reported in rx queue 0,
5901 : : * while the tx queue for fdir filter programming has no
5902 : : * such constraints, can be non-zero queues.
5903 : : * To simplify it, choose FDIR vsi use queue 0 pair.
5904 : : * To make sure it will use queue 0 pair, queue allocation
5905 : : * need be done before this function is called
5906 : : */
5907 [ # # ]: 0 : if (type != I40E_VSI_FDIR) {
5908 : 0 : ret = i40e_res_pool_alloc(&pf->qp_pool, vsi->nb_qps);
5909 [ # # ]: 0 : if (ret < 0) {
5910 : 0 : PMD_DRV_LOG(ERR, "VSI %d allocate queue failed %d",
5911 : : vsi->seid, ret);
5912 : 0 : goto fail_mem;
5913 : : }
5914 : 0 : vsi->base_queue = ret;
5915 : : } else
5916 : 0 : vsi->base_queue = I40E_FDIR_QUEUE_ID;
5917 : :
5918 : : /* VF has MSIX interrupt in VF range, don't allocate here */
5919 [ # # ]: 0 : if (type == I40E_VSI_MAIN) {
5920 [ # # ]: 0 : if (pf->support_multi_driver) {
5921 : : /* If support multi-driver, need to use INT0 instead of
5922 : : * allocating from msix pool. The Msix pool is init from
5923 : : * INT1, so it's OK just set msix_intr to 0 and nb_msix
5924 : : * to 1 without calling i40e_res_pool_alloc.
5925 : : */
5926 : 0 : vsi->msix_intr = 0;
5927 : 0 : vsi->nb_msix = 1;
5928 : : } else {
5929 : 0 : ret = i40e_res_pool_alloc(&pf->msix_pool,
5930 : 0 : RTE_MIN(vsi->nb_qps,
5931 : : RTE_MAX_RXTX_INTR_VEC_ID));
5932 [ # # ]: 0 : if (ret < 0) {
5933 : 0 : PMD_DRV_LOG(ERR,
5934 : : "VSI MAIN %d get heap failed %d",
5935 : : vsi->seid, ret);
5936 : 0 : goto fail_queue_alloc;
5937 : : }
5938 : 0 : vsi->msix_intr = ret;
5939 : 0 : vsi->nb_msix = RTE_MIN(vsi->nb_qps,
5940 : : RTE_MAX_RXTX_INTR_VEC_ID);
5941 : : }
5942 [ # # ]: 0 : } else if (type != I40E_VSI_SRIOV) {
5943 : 0 : ret = i40e_res_pool_alloc(&pf->msix_pool, 1);
5944 [ # # ]: 0 : if (ret < 0) {
5945 : 0 : PMD_DRV_LOG(ERR, "VSI %d get heap failed %d", vsi->seid, ret);
5946 [ # # ]: 0 : if (type != I40E_VSI_FDIR)
5947 : 0 : goto fail_queue_alloc;
5948 : 0 : vsi->msix_intr = 0;
5949 : 0 : vsi->nb_msix = 0;
5950 : : } else {
5951 : 0 : vsi->msix_intr = ret;
5952 : 0 : vsi->nb_msix = 1;
5953 : : }
5954 : : } else {
5955 : 0 : vsi->msix_intr = 0;
5956 : 0 : vsi->nb_msix = 0;
5957 : : }
5958 : :
5959 : : /* Add VSI */
5960 [ # # ]: 0 : if (type == I40E_VSI_MAIN) {
5961 : : /* For main VSI, no need to add since it's default one */
5962 : 0 : vsi->uplink_seid = pf->mac_seid;
5963 : 0 : vsi->seid = pf->main_vsi_seid;
5964 : : /* Bind queues with specific MSIX interrupt */
5965 : : /**
5966 : : * Needs 2 interrupt at least, one for misc cause which will
5967 : : * enabled from OS side, Another for queues binding the
5968 : : * interrupt from device side only.
5969 : : */
5970 : :
5971 : : /* Get default VSI parameters from hardware */
5972 : : memset(&ctxt, 0, sizeof(ctxt));
5973 : 0 : ctxt.seid = vsi->seid;
5974 : 0 : ctxt.pf_num = hw->pf_id;
5975 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
5976 : : ctxt.vf_num = 0;
5977 : 0 : ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5978 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5979 : 0 : PMD_DRV_LOG(ERR, "Failed to get VSI params");
5980 : 0 : goto fail_msix_alloc;
5981 : : }
5982 : 0 : vsi->info = ctxt.info;
5983 : 0 : vsi->vsi_id = ctxt.vsi_number;
5984 : 0 : vsi->info.valid_sections = 0;
5985 : :
5986 : : /* Configure tc, enabled TC0 only */
5987 [ # # ]: 0 : if (i40e_vsi_update_tc_bandwidth(vsi, I40E_DEFAULT_TCMAP) !=
5988 : : I40E_SUCCESS) {
5989 : 0 : PMD_DRV_LOG(ERR, "Failed to update TC bandwidth");
5990 : 0 : goto fail_msix_alloc;
5991 : : }
5992 : :
5993 : : /* TC, queue mapping */
5994 : : memset(&ctxt, 0, sizeof(ctxt));
5995 : 0 : vsi->info.valid_sections |=
5996 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5997 : 0 : vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
5998 : : I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
5999 : 0 : ctxt.info = vsi->info;
6000 : 0 : ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
6001 : : I40E_DEFAULT_TCMAP);
6002 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6003 : 0 : PMD_DRV_LOG(ERR,
6004 : : "Failed to configure TC queue mapping");
6005 : 0 : goto fail_msix_alloc;
6006 : : }
6007 : 0 : ctxt.seid = vsi->seid;
6008 : 0 : ctxt.pf_num = hw->pf_id;
6009 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
6010 : 0 : ctxt.vf_num = 0;
6011 : :
6012 : : /* Update VSI parameters */
6013 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
6014 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6015 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI params");
6016 : 0 : goto fail_msix_alloc;
6017 : : }
6018 : :
6019 : : rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
6020 : : sizeof(vsi->info.tc_mapping));
6021 : : rte_memcpy(&vsi->info.queue_mapping,
6022 : : &ctxt.info.queue_mapping,
6023 : : sizeof(vsi->info.queue_mapping));
6024 : 0 : vsi->info.mapping_flags = ctxt.info.mapping_flags;
6025 : 0 : vsi->info.valid_sections = 0;
6026 : :
6027 [ # # ]: 0 : rte_memcpy(pf->dev_addr.addr_bytes, hw->mac.perm_addr,
6028 : : ETH_ADDR_LEN);
6029 : :
6030 : : /**
6031 : : * Updating default filter settings are necessary to prevent
6032 : : * reception of tagged packets.
6033 : : * Some old firmware configurations load a default macvlan
6034 : : * filter which accepts both tagged and untagged packets.
6035 : : * The updating is to use a normal filter instead if needed.
6036 : : * For NVM 4.2.2 or after, the updating is not needed anymore.
6037 : : * The firmware with correct configurations load the default
6038 : : * macvlan filter which is expected and cannot be removed.
6039 : : */
6040 : 0 : i40e_update_default_filter_setting(vsi);
6041 : 0 : i40e_config_qinq(hw, vsi);
6042 [ # # ]: 0 : } else if (type == I40E_VSI_SRIOV) {
6043 : : memset(&ctxt, 0, sizeof(ctxt));
6044 : : /**
6045 : : * For other VSI, the uplink_seid equals to uplink VSI's
6046 : : * uplink_seid since they share same VEB
6047 : : */
6048 [ # # ]: 0 : if (uplink_vsi == NULL)
6049 : 0 : vsi->uplink_seid = pf->main_vsi->floating_veb->seid;
6050 : : else
6051 : 0 : vsi->uplink_seid = uplink_vsi->uplink_seid;
6052 : 0 : ctxt.pf_num = hw->pf_id;
6053 : 0 : ctxt.vf_num = hw->func_caps.vf_base_id + user_param;
6054 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
6055 : 0 : ctxt.connection_type = 0x1;
6056 : : ctxt.flags = I40E_AQ_VSI_TYPE_VF;
6057 : :
6058 : : /* Use the VEB configuration if FW >= v5.0 */
6059 [ # # # # ]: 0 : if (hw->aq.fw_maj_ver >= 5 || hw->mac.type == I40E_MAC_X722) {
6060 : : /* Configure switch ID */
6061 : 0 : ctxt.info.valid_sections |=
6062 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6063 : 0 : ctxt.info.switch_id =
6064 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6065 : : }
6066 : :
6067 : : /* Configure port/vlan */
6068 : 0 : ctxt.info.valid_sections |=
6069 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
6070 : 0 : ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
6071 : 0 : ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
6072 : 0 : hw->func_caps.enabled_tcmap);
6073 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6074 : 0 : PMD_DRV_LOG(ERR,
6075 : : "Failed to configure TC queue mapping");
6076 : 0 : goto fail_msix_alloc;
6077 : : }
6078 : :
6079 : 0 : ctxt.info.up_enable_bits = hw->func_caps.enabled_tcmap;
6080 : 0 : ctxt.info.valid_sections |=
6081 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
6082 : : /**
6083 : : * Since VSI is not created yet, only configure parameter,
6084 : : * will add vsi below.
6085 : : */
6086 : :
6087 : 0 : i40e_config_qinq(hw, vsi);
6088 [ # # ]: 0 : } else if (type == I40E_VSI_VMDQ2) {
6089 : : memset(&ctxt, 0, sizeof(ctxt));
6090 : : /*
6091 : : * For other VSI, the uplink_seid equals to uplink VSI's
6092 : : * uplink_seid since they share same VEB
6093 : : */
6094 : 0 : vsi->uplink_seid = uplink_vsi->uplink_seid;
6095 : 0 : ctxt.pf_num = hw->pf_id;
6096 : : ctxt.vf_num = 0;
6097 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
6098 : 0 : ctxt.connection_type = 0x1;
6099 : 0 : ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
6100 : :
6101 : 0 : ctxt.info.valid_sections |=
6102 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6103 : : /* user_param carries flag to enable loop back */
6104 [ # # ]: 0 : if (user_param) {
6105 : : ctxt.info.switch_id =
6106 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
6107 : 0 : ctxt.info.switch_id |=
6108 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6109 : : }
6110 : :
6111 : : /* Configure port/vlan */
6112 : 0 : ctxt.info.valid_sections |=
6113 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
6114 : 0 : ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
6115 : 0 : ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
6116 : : I40E_DEFAULT_TCMAP);
6117 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6118 : 0 : PMD_DRV_LOG(ERR,
6119 : : "Failed to configure TC queue mapping");
6120 : 0 : goto fail_msix_alloc;
6121 : : }
6122 : 0 : ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
6123 : 0 : ctxt.info.valid_sections |=
6124 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
6125 : : } else if (type == I40E_VSI_FDIR) {
6126 : : memset(&ctxt, 0, sizeof(ctxt));
6127 : 0 : vsi->uplink_seid = uplink_vsi->uplink_seid;
6128 : 0 : ctxt.pf_num = hw->pf_id;
6129 : : ctxt.vf_num = 0;
6130 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
6131 : 0 : ctxt.connection_type = 0x1; /* regular data port */
6132 : 0 : ctxt.flags = I40E_AQ_VSI_TYPE_PF;
6133 : 0 : ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
6134 : : I40E_DEFAULT_TCMAP);
6135 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6136 : 0 : PMD_DRV_LOG(ERR,
6137 : : "Failed to configure TC queue mapping.");
6138 : 0 : goto fail_msix_alloc;
6139 : : }
6140 : 0 : ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
6141 : 0 : ctxt.info.valid_sections |=
6142 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
6143 : : } else {
6144 : : PMD_DRV_LOG(ERR, "VSI: Not support other type VSI yet");
6145 : : goto fail_msix_alloc;
6146 : : }
6147 : :
6148 [ # # ]: 0 : if (vsi->type != I40E_VSI_MAIN) {
6149 : 0 : ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
6150 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6151 : 0 : PMD_DRV_LOG(ERR, "add vsi failed, aq_err=%d",
6152 : : hw->aq.asq_last_status);
6153 : 0 : goto fail_msix_alloc;
6154 : : }
6155 [ # # ]: 0 : memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
6156 : 0 : vsi->info.valid_sections = 0;
6157 : 0 : vsi->seid = ctxt.seid;
6158 : 0 : vsi->vsi_id = ctxt.vsi_number;
6159 : 0 : vsi->sib_vsi_list.vsi = vsi;
6160 [ # # # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV && uplink_vsi == NULL) {
6161 : 0 : TAILQ_INSERT_TAIL(&pf->main_vsi->floating_veb->head,
6162 : : &vsi->sib_vsi_list, list);
6163 : : } else {
6164 : 0 : TAILQ_INSERT_TAIL(&uplink_vsi->veb->head,
6165 : : &vsi->sib_vsi_list, list);
6166 : : }
6167 : : }
6168 : :
6169 [ # # ]: 0 : if (vsi->type != I40E_VSI_FDIR) {
6170 : : /* MAC/VLAN configuration for non-FDIR VSI*/
6171 : : rte_memcpy(&filter.mac_addr, &broadcast, RTE_ETHER_ADDR_LEN);
6172 : 0 : filter.filter_type = I40E_MACVLAN_PERFECT_MATCH;
6173 : :
6174 : 0 : ret = i40e_vsi_add_mac(vsi, &filter);
6175 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6176 : 0 : PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
6177 : 0 : goto fail_msix_alloc;
6178 : : }
6179 : : }
6180 : :
6181 : : /* Get VSI BW information */
6182 : 0 : i40e_vsi_get_bw_config(vsi);
6183 : 0 : return vsi;
6184 : 0 : fail_msix_alloc:
6185 : 0 : i40e_res_pool_free(&pf->msix_pool,vsi->msix_intr);
6186 : 0 : fail_queue_alloc:
6187 : 0 : i40e_res_pool_free(&pf->qp_pool,vsi->base_queue);
6188 : 0 : fail_mem:
6189 : 0 : rte_free(vsi);
6190 : 0 : return NULL;
6191 : : }
6192 : :
6193 : : /* Configure vlan filter on or off */
6194 : : int
6195 : 0 : i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on)
6196 : : {
6197 : : int i, num;
6198 : : struct i40e_mac_filter *f;
6199 : : void *temp;
6200 : 0 : struct i40e_mac_filter_info mac_filter[I40E_NUM_MACADDR_MAX] = {0};
6201 : : enum i40e_mac_filter_type desired_filter;
6202 : : int ret = I40E_SUCCESS;
6203 : :
6204 [ # # ]: 0 : if (on) {
6205 : : /* Filter to match MAC and VLAN */
6206 : : desired_filter = I40E_MACVLAN_PERFECT_MATCH;
6207 : : } else {
6208 : : /* Filter to match only MAC */
6209 : : desired_filter = I40E_MAC_PERFECT_MATCH;
6210 : : }
6211 : :
6212 : 0 : num = vsi->mac_num;
6213 [ # # ]: 0 : if (num > I40E_NUM_MACADDR_MAX) {
6214 : 0 : PMD_DRV_LOG(ERR, "Too many MAC addresses");
6215 : 0 : return -1;
6216 : : }
6217 : :
6218 : : i = 0;
6219 : :
6220 : : /* Remove all existing mac */
6221 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
6222 : 0 : mac_filter[i] = f->mac_info;
6223 : 0 : ret = i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
6224 [ # # ]: 0 : if (ret) {
6225 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
6226 : : on ? "enable" : "disable");
6227 : 0 : return ret;
6228 : : }
6229 : 0 : i++;
6230 : : }
6231 : :
6232 : : /* Override with new filter */
6233 [ # # ]: 0 : for (i = 0; i < num; i++) {
6234 : 0 : mac_filter[i].filter_type = desired_filter;
6235 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter[i]);
6236 [ # # ]: 0 : if (ret) {
6237 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
6238 : : on ? "enable" : "disable");
6239 : 0 : return ret;
6240 : : }
6241 : : }
6242 : :
6243 : : return 0;
6244 : : }
6245 : :
6246 : : /* Configure vlan stripping on or off */
6247 : : int
6248 : 0 : i40e_vsi_config_vlan_stripping(struct i40e_vsi *vsi, bool on)
6249 : : {
6250 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6251 : : struct i40e_vsi_context ctxt;
6252 : : uint8_t vlan_flags;
6253 : : int ret = I40E_SUCCESS;
6254 : :
6255 : : /* Check if it has been already on or off */
6256 [ # # ]: 0 : if (vsi->info.valid_sections &
6257 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID)) {
6258 [ # # ]: 0 : if (on) {
6259 [ # # ]: 0 : if ((vsi->info.port_vlan_flags &
6260 : : I40E_AQ_VSI_PVLAN_EMOD_MASK) == 0)
6261 : : return 0; /* already on */
6262 : : } else {
6263 [ # # ]: 0 : if ((vsi->info.port_vlan_flags &
6264 : : I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
6265 : : I40E_AQ_VSI_PVLAN_EMOD_MASK)
6266 : : return 0; /* already off */
6267 : : }
6268 : : }
6269 : :
6270 [ # # ]: 0 : if (on)
6271 : : vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
6272 : : else
6273 : : vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
6274 : 0 : vsi->info.valid_sections =
6275 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
6276 : 0 : vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_EMOD_MASK);
6277 : 0 : vsi->info.port_vlan_flags |= vlan_flags;
6278 : 0 : ctxt.seid = vsi->seid;
6279 [ # # ]: 0 : rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
6280 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
6281 [ # # ]: 0 : if (ret)
6282 [ # # ]: 0 : PMD_DRV_LOG(INFO, "Update VSI failed to %s vlan stripping",
6283 : : on ? "enable" : "disable");
6284 : :
6285 : : return ret;
6286 : : }
6287 : :
6288 : : static int
6289 : 0 : i40e_dev_init_vlan(struct rte_eth_dev *dev)
6290 : : {
6291 : 0 : struct rte_eth_dev_data *data = dev->data;
6292 : : int ret;
6293 : : int mask = 0;
6294 : :
6295 : : /* Apply vlan offload setting */
6296 : : mask = RTE_ETH_VLAN_STRIP_MASK |
6297 : : RTE_ETH_QINQ_STRIP_MASK |
6298 : : RTE_ETH_VLAN_FILTER_MASK |
6299 : : RTE_ETH_VLAN_EXTEND_MASK;
6300 : :
6301 : 0 : ret = i40e_vlan_offload_set(dev, mask);
6302 [ # # ]: 0 : if (ret) {
6303 : 0 : PMD_DRV_LOG(INFO, "Failed to update vlan offload");
6304 : 0 : return ret;
6305 : : }
6306 : :
6307 : : /* Apply pvid setting */
6308 : 0 : ret = i40e_vlan_pvid_set(dev, data->dev_conf.txmode.pvid,
6309 : 0 : data->dev_conf.txmode.hw_vlan_insert_pvid);
6310 [ # # ]: 0 : if (ret)
6311 : 0 : PMD_DRV_LOG(INFO, "Failed to update VSI params");
6312 : :
6313 : : return ret;
6314 : : }
6315 : :
6316 : : static int
6317 : : i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on)
6318 : : {
6319 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6320 : :
6321 : 0 : return i40e_aq_set_port_parameters(hw, vsi->seid, 0, 1, on, NULL);
6322 : : }
6323 : :
6324 : : static int
6325 : 0 : i40e_update_flow_control(struct i40e_hw *hw)
6326 : : {
6327 : : #define I40E_LINK_PAUSE_RXTX (I40E_AQ_LINK_PAUSE_RX | I40E_AQ_LINK_PAUSE_TX)
6328 : : struct i40e_link_status link_status;
6329 : : uint32_t rxfc = 0, txfc = 0, reg;
6330 : : uint8_t an_info;
6331 : : int ret;
6332 : :
6333 : : memset(&link_status, 0, sizeof(link_status));
6334 : 0 : ret = i40e_aq_get_link_info(hw, FALSE, &link_status, NULL);
6335 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6336 : 0 : PMD_DRV_LOG(ERR, "Failed to get link status information");
6337 : 0 : goto write_reg; /* Disable flow control */
6338 : : }
6339 : :
6340 : 0 : an_info = hw->phy.link_info.an_info;
6341 [ # # ]: 0 : if (!(an_info & I40E_AQ_AN_COMPLETED)) {
6342 : 0 : PMD_DRV_LOG(INFO, "Link auto negotiation not completed");
6343 : : ret = I40E_ERR_NOT_READY;
6344 : 0 : goto write_reg; /* Disable flow control */
6345 : : }
6346 : : /**
6347 : : * If link auto negotiation is enabled, flow control needs to
6348 : : * be configured according to it
6349 : : */
6350 [ # # # # ]: 0 : switch (an_info & I40E_LINK_PAUSE_RXTX) {
6351 : 0 : case I40E_LINK_PAUSE_RXTX:
6352 : : rxfc = 1;
6353 : : txfc = 1;
6354 : 0 : hw->fc.current_mode = I40E_FC_FULL;
6355 : 0 : break;
6356 : 0 : case I40E_AQ_LINK_PAUSE_RX:
6357 : : rxfc = 1;
6358 : 0 : hw->fc.current_mode = I40E_FC_RX_PAUSE;
6359 : 0 : break;
6360 : 0 : case I40E_AQ_LINK_PAUSE_TX:
6361 : : txfc = 1;
6362 : 0 : hw->fc.current_mode = I40E_FC_TX_PAUSE;
6363 : 0 : break;
6364 : 0 : default:
6365 : 0 : hw->fc.current_mode = I40E_FC_NONE;
6366 : 0 : break;
6367 : : }
6368 : :
6369 : 0 : write_reg:
6370 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_FCCFG,
6371 : : txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT);
6372 : 0 : reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
6373 : 0 : reg &= ~I40E_PRTDCB_MFLCN_RFCE_MASK;
6374 : 0 : reg |= rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT;
6375 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, reg);
6376 : :
6377 : 0 : return ret;
6378 : : }
6379 : :
6380 : : /* PF setup */
6381 : : static int
6382 : 0 : i40e_pf_setup(struct i40e_pf *pf)
6383 : : {
6384 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6385 : : struct i40e_filter_control_settings settings;
6386 : : struct i40e_vsi *vsi;
6387 : : int ret;
6388 : :
6389 : : /* Clear all stats counters */
6390 : 0 : pf->offset_loaded = FALSE;
6391 : 0 : memset(&pf->stats, 0, sizeof(struct i40e_hw_port_stats));
6392 : 0 : memset(&pf->stats_offset, 0, sizeof(struct i40e_hw_port_stats));
6393 : 0 : memset(&pf->internal_stats, 0, sizeof(struct i40e_eth_stats));
6394 : 0 : memset(&pf->internal_stats_offset, 0, sizeof(struct i40e_eth_stats));
6395 : :
6396 : 0 : ret = i40e_pf_get_switch_config(pf);
6397 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6398 : 0 : PMD_DRV_LOG(ERR, "Could not get switch config, err %d", ret);
6399 : 0 : return ret;
6400 : : }
6401 : :
6402 : 0 : ret = rte_eth_switch_domain_alloc(&pf->switch_domain_id);
6403 [ # # ]: 0 : if (ret)
6404 : 0 : PMD_INIT_LOG(WARNING,
6405 : : "failed to allocate switch domain for device %d", ret);
6406 : :
6407 [ # # ]: 0 : if (pf->flags & I40E_FLAG_FDIR) {
6408 : : /* make queue allocated first, let FDIR use queue pair 0*/
6409 : 0 : ret = i40e_res_pool_alloc(&pf->qp_pool, I40E_DEFAULT_QP_NUM_FDIR);
6410 [ # # ]: 0 : if (ret != I40E_FDIR_QUEUE_ID) {
6411 : 0 : PMD_DRV_LOG(ERR,
6412 : : "queue allocation fails for FDIR: ret =%d",
6413 : : ret);
6414 : 0 : pf->flags &= ~I40E_FLAG_FDIR;
6415 : : }
6416 : : }
6417 : : /* main VSI setup */
6418 : 0 : vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, NULL, 0);
6419 [ # # ]: 0 : if (!vsi) {
6420 : 0 : PMD_DRV_LOG(ERR, "Setup of main vsi failed");
6421 : 0 : return I40E_ERR_NOT_READY;
6422 : : }
6423 [ # # ]: 0 : pf->main_vsi = vsi;
6424 : :
6425 : : /* Configure filter control */
6426 : : memset(&settings, 0, sizeof(settings));
6427 [ # # ]: 0 : if (hw->func_caps.rss_table_size == RTE_ETH_RSS_RETA_SIZE_128)
6428 : : settings.hash_lut_size = I40E_HASH_LUT_SIZE_128;
6429 [ # # ]: 0 : else if (hw->func_caps.rss_table_size == RTE_ETH_RSS_RETA_SIZE_512)
6430 : 0 : settings.hash_lut_size = I40E_HASH_LUT_SIZE_512;
6431 : : else {
6432 : 0 : PMD_DRV_LOG(ERR, "Hash lookup table size (%u) not supported",
6433 : : hw->func_caps.rss_table_size);
6434 : 0 : return I40E_ERR_PARAM;
6435 : : }
6436 : 0 : PMD_DRV_LOG(INFO, "Hardware capability of hash lookup table size: %u",
6437 : : hw->func_caps.rss_table_size);
6438 : 0 : pf->hash_lut_size = hw->func_caps.rss_table_size;
6439 : :
6440 : : /* Enable ethtype and macvlan filters */
6441 : 0 : settings.enable_ethtype = TRUE;
6442 : 0 : settings.enable_macvlan = TRUE;
6443 : 0 : ret = i40e_set_filter_control(hw, &settings);
6444 [ # # ]: 0 : if (ret)
6445 : 0 : PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
6446 : : ret);
6447 : :
6448 : : /* Update flow control according to the auto negotiation */
6449 : 0 : i40e_update_flow_control(hw);
6450 : :
6451 : 0 : return I40E_SUCCESS;
6452 : : }
6453 : :
6454 : : int
6455 : 0 : i40e_switch_tx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
6456 : : {
6457 : : uint32_t reg;
6458 : : uint16_t j;
6459 : :
6460 : : /**
6461 : : * Set or clear TX Queue Disable flags,
6462 : : * which is required by hardware.
6463 : : */
6464 : 0 : i40e_pre_tx_queue_cfg(hw, q_idx, on);
6465 : 0 : rte_delay_us(I40E_PRE_TX_Q_CFG_WAIT_US);
6466 : :
6467 : : /* Wait until the request is finished */
6468 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6469 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6470 : 0 : reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
6471 : 0 : if (!(((reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 0x1) ^
6472 [ # # ]: 0 : ((reg >> I40E_QTX_ENA_QENA_STAT_SHIFT)
6473 : : & 0x1))) {
6474 : : break;
6475 : : }
6476 : : }
6477 [ # # ]: 0 : if (on) {
6478 [ # # ]: 0 : if (reg & I40E_QTX_ENA_QENA_STAT_MASK)
6479 : : return I40E_SUCCESS; /* already on, skip next steps */
6480 : :
6481 : 0 : I40E_WRITE_REG(hw, I40E_QTX_HEAD(q_idx), 0);
6482 : 0 : reg |= I40E_QTX_ENA_QENA_REQ_MASK;
6483 : : } else {
6484 [ # # ]: 0 : if (!(reg & I40E_QTX_ENA_QENA_STAT_MASK))
6485 : : return I40E_SUCCESS; /* already off, skip next steps */
6486 : 0 : reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
6487 : : }
6488 : : /* Write the register */
6489 : 0 : I40E_WRITE_REG(hw, I40E_QTX_ENA(q_idx), reg);
6490 : : /* Check the result */
6491 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6492 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6493 : 0 : reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
6494 [ # # ]: 0 : if (on) {
6495 [ # # ]: 0 : if ((reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
6496 : : (reg & I40E_QTX_ENA_QENA_STAT_MASK))
6497 : : break;
6498 : : } else {
6499 [ # # ]: 0 : if (!(reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
6500 : : !(reg & I40E_QTX_ENA_QENA_STAT_MASK))
6501 : : break;
6502 : : }
6503 : : }
6504 : : /* Check if it is timeout */
6505 [ # # ]: 0 : if (j >= I40E_CHK_Q_ENA_COUNT) {
6506 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Failed to %s tx queue[%u]",
6507 : : (on ? "enable" : "disable"), q_idx);
6508 : 0 : return I40E_ERR_TIMEOUT;
6509 : : }
6510 : :
6511 : : return I40E_SUCCESS;
6512 : : }
6513 : :
6514 : : int
6515 : 0 : i40e_switch_rx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
6516 : : {
6517 : : uint32_t reg;
6518 : : uint16_t j;
6519 : :
6520 : : /* Wait until the request is finished */
6521 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6522 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6523 : 0 : reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
6524 : 0 : if (!((reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 0x1) ^
6525 [ # # ]: 0 : ((reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 0x1))
6526 : : break;
6527 : : }
6528 : :
6529 [ # # ]: 0 : if (on) {
6530 [ # # ]: 0 : if (reg & I40E_QRX_ENA_QENA_STAT_MASK)
6531 : : return I40E_SUCCESS; /* Already on, skip next steps */
6532 : 0 : reg |= I40E_QRX_ENA_QENA_REQ_MASK;
6533 : : } else {
6534 [ # # ]: 0 : if (!(reg & I40E_QRX_ENA_QENA_STAT_MASK))
6535 : : return I40E_SUCCESS; /* Already off, skip next steps */
6536 : 0 : reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
6537 : : }
6538 : :
6539 : : /* Write the register */
6540 : 0 : I40E_WRITE_REG(hw, I40E_QRX_ENA(q_idx), reg);
6541 : : /* Check the result */
6542 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6543 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6544 : 0 : reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
6545 [ # # ]: 0 : if (on) {
6546 [ # # ]: 0 : if ((reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
6547 : : (reg & I40E_QRX_ENA_QENA_STAT_MASK))
6548 : : break;
6549 : : } else {
6550 [ # # ]: 0 : if (!(reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
6551 : : !(reg & I40E_QRX_ENA_QENA_STAT_MASK))
6552 : : break;
6553 : : }
6554 : : }
6555 : :
6556 : : /* Check if it is timeout */
6557 [ # # ]: 0 : if (j >= I40E_CHK_Q_ENA_COUNT) {
6558 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Failed to %s rx queue[%u]",
6559 : : (on ? "enable" : "disable"), q_idx);
6560 : 0 : return I40E_ERR_TIMEOUT;
6561 : : }
6562 : :
6563 : : return I40E_SUCCESS;
6564 : : }
6565 : :
6566 : : /* Initialize VSI for TX */
6567 : : static int
6568 : 0 : i40e_dev_tx_init(struct i40e_pf *pf)
6569 : : {
6570 : 0 : struct rte_eth_dev_data *data = pf->dev_data;
6571 : : uint16_t i;
6572 : : uint32_t ret = I40E_SUCCESS;
6573 : : struct ci_tx_queue *txq;
6574 : :
6575 [ # # ]: 0 : for (i = 0; i < data->nb_tx_queues; i++) {
6576 : 0 : txq = data->tx_queues[i];
6577 [ # # # # ]: 0 : if (!txq || !txq->q_set)
6578 : 0 : continue;
6579 : 0 : ret = i40e_tx_queue_init(txq);
6580 [ # # ]: 0 : if (ret != I40E_SUCCESS)
6581 : : break;
6582 : : }
6583 [ # # ]: 0 : if (ret == I40E_SUCCESS)
6584 : 0 : i40e_set_tx_function(&rte_eth_devices[pf->dev_data->port_id]);
6585 : :
6586 : 0 : return ret;
6587 : : }
6588 : :
6589 : : /* Initialize VSI for RX */
6590 : : static int
6591 : 0 : i40e_dev_rx_init(struct i40e_pf *pf)
6592 : : {
6593 : 0 : struct rte_eth_dev_data *data = pf->dev_data;
6594 : : int ret = I40E_SUCCESS;
6595 : : uint16_t i;
6596 : : struct ci_rx_queue *rxq;
6597 : :
6598 : 0 : i40e_pf_config_rss(pf);
6599 [ # # ]: 0 : for (i = 0; i < data->nb_rx_queues; i++) {
6600 : 0 : rxq = data->rx_queues[i];
6601 [ # # # # ]: 0 : if (!rxq || !rxq->q_set)
6602 : 0 : continue;
6603 : :
6604 : 0 : ret = i40e_rx_queue_init(rxq);
6605 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6606 : 0 : PMD_DRV_LOG(ERR,
6607 : : "Failed to do RX queue initialization");
6608 : 0 : break;
6609 : : }
6610 : : }
6611 [ # # ]: 0 : if (ret == I40E_SUCCESS)
6612 : 0 : i40e_set_rx_function(&rte_eth_devices[pf->dev_data->port_id]);
6613 : :
6614 : 0 : return ret;
6615 : : }
6616 : :
6617 : : static int
6618 : 0 : i40e_dev_rxtx_init(struct i40e_pf *pf)
6619 : : {
6620 : : int err;
6621 : :
6622 : 0 : err = i40e_dev_tx_init(pf);
6623 [ # # ]: 0 : if (err) {
6624 : 0 : PMD_DRV_LOG(ERR, "Failed to do TX initialization");
6625 : 0 : return err;
6626 : : }
6627 : 0 : err = i40e_dev_rx_init(pf);
6628 [ # # ]: 0 : if (err) {
6629 : 0 : PMD_DRV_LOG(ERR, "Failed to do RX initialization");
6630 : 0 : return err;
6631 : : }
6632 : :
6633 : : return err;
6634 : : }
6635 : :
6636 : : static int
6637 : 0 : i40e_vmdq_setup(struct rte_eth_dev *dev)
6638 : : {
6639 : 0 : struct rte_eth_conf *conf = &dev->data->dev_conf;
6640 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6641 : : int i, err, conf_vsis, j, loop;
6642 : : struct i40e_vsi *vsi;
6643 : : struct i40e_vmdq_info *vmdq_info;
6644 : : struct rte_eth_vmdq_rx_conf *vmdq_conf;
6645 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6646 : :
6647 : : /*
6648 : : * Disable interrupt to avoid message from VF. Furthermore, it will
6649 : : * avoid race condition in VSI creation/destroy.
6650 : : */
6651 : 0 : i40e_pf_disable_irq0(hw);
6652 : :
6653 [ # # ]: 0 : if ((pf->flags & I40E_FLAG_VMDQ) == 0) {
6654 : 0 : PMD_INIT_LOG(ERR, "FW doesn't support VMDQ");
6655 : 0 : return -ENOTSUP;
6656 : : }
6657 : :
6658 : 0 : conf_vsis = conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools;
6659 [ # # ]: 0 : if (conf_vsis > pf->max_nb_vmdq_vsi) {
6660 : 0 : PMD_INIT_LOG(ERR, "VMDQ config: %u, max support:%u",
6661 : : conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools,
6662 : : pf->max_nb_vmdq_vsi);
6663 : 0 : return -ENOTSUP;
6664 : : }
6665 : :
6666 [ # # ]: 0 : if (pf->vmdq != NULL) {
6667 : 0 : PMD_INIT_LOG(INFO, "VMDQ already configured");
6668 : 0 : return 0;
6669 : : }
6670 : :
6671 : 0 : pf->vmdq = rte_zmalloc("vmdq_info_struct",
6672 : : sizeof(*vmdq_info) * conf_vsis, 0);
6673 : :
6674 [ # # ]: 0 : if (pf->vmdq == NULL) {
6675 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory");
6676 : 0 : return -ENOMEM;
6677 : : }
6678 : :
6679 : : vmdq_conf = &conf->rx_adv_conf.vmdq_rx_conf;
6680 : :
6681 : : /* Create VMDQ VSI */
6682 [ # # ]: 0 : for (i = 0; i < conf_vsis; i++) {
6683 : 0 : vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, pf->main_vsi,
6684 : 0 : vmdq_conf->enable_loop_back);
6685 [ # # ]: 0 : if (vsi == NULL) {
6686 : 0 : PMD_INIT_LOG(ERR, "Failed to create VMDQ VSI");
6687 : : err = -1;
6688 : 0 : goto err_vsi_setup;
6689 : : }
6690 : 0 : vmdq_info = &pf->vmdq[i];
6691 : 0 : vmdq_info->pf = pf;
6692 : 0 : vmdq_info->vsi = vsi;
6693 : : }
6694 : 0 : pf->nb_cfg_vmdq_vsi = conf_vsis;
6695 : :
6696 : : /* Configure Vlan */
6697 : : loop = sizeof(vmdq_conf->pool_map[0].pools) * CHAR_BIT;
6698 [ # # ]: 0 : for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
6699 [ # # # # ]: 0 : for (j = 0; j < loop && j < pf->nb_cfg_vmdq_vsi; j++) {
6700 [ # # ]: 0 : if (vmdq_conf->pool_map[i].pools & RTE_BIT64(j)) {
6701 : 0 : PMD_INIT_LOG(INFO, "Add vlan %u to vmdq pool %u",
6702 : : vmdq_conf->pool_map[i].vlan_id, j);
6703 : :
6704 : 0 : err = i40e_vsi_add_vlan(pf->vmdq[j].vsi,
6705 : 0 : vmdq_conf->pool_map[i].vlan_id);
6706 [ # # ]: 0 : if (err) {
6707 : 0 : PMD_INIT_LOG(ERR, "Failed to add vlan");
6708 : : err = -1;
6709 : 0 : goto err_vsi_setup;
6710 : : }
6711 : : }
6712 : : }
6713 : : }
6714 : :
6715 : 0 : i40e_pf_enable_irq0(hw);
6716 : :
6717 : 0 : return 0;
6718 : :
6719 : : err_vsi_setup:
6720 [ # # ]: 0 : for (i = 0; i < conf_vsis; i++)
6721 [ # # ]: 0 : if (pf->vmdq[i].vsi == NULL)
6722 : : break;
6723 : : else
6724 : 0 : i40e_vsi_release(pf->vmdq[i].vsi);
6725 : :
6726 : 0 : rte_free(pf->vmdq);
6727 : 0 : pf->vmdq = NULL;
6728 : 0 : i40e_pf_enable_irq0(hw);
6729 : 0 : return err;
6730 : : }
6731 : :
6732 : : static void
6733 : : i40e_stat_update_32(struct i40e_hw *hw,
6734 : : uint32_t reg,
6735 : : bool offset_loaded,
6736 : : uint64_t *offset,
6737 : : uint64_t *stat)
6738 : : {
6739 : : uint64_t new_data;
6740 : :
6741 : 0 : new_data = (uint64_t)I40E_READ_REG(hw, reg);
6742 [ # # # # : 0 : if (!offset_loaded)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
6743 : 0 : *offset = new_data;
6744 : :
6745 [ # # # # : 0 : if (new_data >= *offset)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
6746 : 0 : *stat = (uint64_t)(new_data - *offset);
6747 : : else
6748 : 0 : *stat = (uint64_t)((new_data +
6749 : : RTE_BIT64(I40E_32_BIT_WIDTH)) - *offset);
6750 : : }
6751 : :
6752 : : static void
6753 : 0 : i40e_stat_update_48(struct i40e_hw *hw,
6754 : : uint32_t hireg,
6755 : : uint32_t loreg,
6756 : : bool offset_loaded,
6757 : : uint64_t *offset,
6758 : : uint64_t *stat)
6759 : : {
6760 : : uint64_t new_data;
6761 : :
6762 [ # # ]: 0 : if (hw->device_id == I40E_DEV_ID_QEMU) {
6763 : 0 : new_data = (uint64_t)I40E_READ_REG(hw, loreg);
6764 : 0 : new_data |= ((uint64_t)(I40E_READ_REG(hw, hireg) &
6765 : 0 : I40E_16_BIT_MASK)) << I40E_32_BIT_WIDTH;
6766 : : } else {
6767 : 0 : new_data = I40E_READ_REG64(hw, loreg);
6768 : : }
6769 : :
6770 [ # # ]: 0 : if (!offset_loaded)
6771 : 0 : *offset = new_data;
6772 : :
6773 [ # # ]: 0 : if (new_data >= *offset)
6774 : 0 : *stat = new_data - *offset;
6775 : : else
6776 : 0 : *stat = (uint64_t)((new_data +
6777 : : RTE_BIT64(I40E_48_BIT_WIDTH)) - *offset);
6778 : :
6779 : 0 : *stat &= I40E_48_BIT_MASK;
6780 : 0 : }
6781 : :
6782 : : /* Disable IRQ0 */
6783 : : void
6784 : 0 : i40e_pf_disable_irq0(struct i40e_hw *hw)
6785 : : {
6786 : : /* Disable all interrupt types */
6787 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
6788 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
6789 : 0 : I40E_WRITE_FLUSH(hw);
6790 : 0 : }
6791 : :
6792 : : /* Enable IRQ0 */
6793 : : void
6794 : 0 : i40e_pf_enable_irq0(struct i40e_hw *hw)
6795 : : {
6796 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
6797 : : I40E_PFINT_DYN_CTL0_INTENA_MASK |
6798 : : I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
6799 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
6800 : 0 : I40E_WRITE_FLUSH(hw);
6801 : 0 : }
6802 : :
6803 : : static void
6804 : : i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue)
6805 : : {
6806 : : /* read pending request and disable first */
6807 : 0 : i40e_pf_disable_irq0(hw);
6808 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_ICR0_ENA, I40E_PFINT_ICR0_ENA_MASK);
6809 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_STAT_CTL0,
6810 : : I40E_PFINT_STAT_CTL0_OTHER_ITR_INDX_MASK);
6811 : :
6812 : : if (no_queue)
6813 : : /* Link no queues with irq0 */
6814 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
6815 : : I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
6816 : : }
6817 : :
6818 : : static void
6819 : 0 : i40e_dev_handle_vfr_event(struct rte_eth_dev *dev)
6820 : : {
6821 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6822 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6823 : : int i;
6824 : : uint16_t abs_vf_id;
6825 : : uint32_t index, offset, val;
6826 : :
6827 [ # # ]: 0 : if (!pf->vfs)
6828 : : return;
6829 : : /**
6830 : : * Try to find which VF trigger a reset, use absolute VF id to access
6831 : : * since the reg is global register.
6832 : : */
6833 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++) {
6834 : 0 : abs_vf_id = hw->func_caps.vf_base_id + i;
6835 : 0 : index = abs_vf_id / I40E_UINT32_BIT_SIZE;
6836 : 0 : offset = abs_vf_id % I40E_UINT32_BIT_SIZE;
6837 : 0 : val = I40E_READ_REG(hw, I40E_GLGEN_VFLRSTAT(index));
6838 : : /* VFR event occurred */
6839 [ # # ]: 0 : if (val & (0x1 << offset)) {
6840 : : int ret;
6841 : :
6842 : : /* Clear the event first */
6843 : 0 : I40E_WRITE_REG(hw, I40E_GLGEN_VFLRSTAT(index),
6844 : : (0x1 << offset));
6845 : 0 : PMD_DRV_LOG(INFO, "VF %u reset occurred", abs_vf_id);
6846 : : /**
6847 : : * Only notify a VF reset event occurred,
6848 : : * don't trigger another SW reset
6849 : : */
6850 : 0 : ret = i40e_pf_host_vf_reset(&pf->vfs[i], 0);
6851 [ # # ]: 0 : if (ret != I40E_SUCCESS)
6852 : 0 : PMD_DRV_LOG(ERR, "Failed to do VF reset");
6853 : : }
6854 : : }
6855 : : }
6856 : :
6857 : : static void
6858 : 0 : i40e_notify_all_vfs_link_status(struct rte_eth_dev *dev)
6859 : : {
6860 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6861 : : int i;
6862 : :
6863 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++)
6864 : 0 : i40e_notify_vf_link_status(dev, &pf->vfs[i]);
6865 : 0 : }
6866 : :
6867 : : static void
6868 : 0 : i40e_dev_handle_aq_msg(struct rte_eth_dev *dev)
6869 : : {
6870 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6871 : : struct i40e_arq_event_info info;
6872 : : uint16_t pending, opcode;
6873 : 0 : uint8_t msg_buf[I40E_AQ_BUF_SZ] = {0};
6874 : : int ret;
6875 : :
6876 : 0 : info.buf_len = sizeof(msg_buf);
6877 : 0 : info.msg_buf = msg_buf;
6878 : :
6879 : 0 : pending = 1;
6880 [ # # ]: 0 : while (pending) {
6881 : 0 : ret = i40e_clean_arq_element(hw, &info, &pending);
6882 : :
6883 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6884 : 0 : PMD_DRV_LOG(INFO,
6885 : : "Failed to read msg from AdminQ, aq_err: %u",
6886 : : hw->aq.asq_last_status);
6887 : 0 : break;
6888 : : }
6889 : 0 : opcode = rte_le_to_cpu_16(info.desc.opcode);
6890 : :
6891 [ # # # ]: 0 : switch (opcode) {
6892 : 0 : case i40e_aqc_opc_send_msg_to_pf:
6893 : : /* Refer to i40e_aq_send_msg_to_pf() for argument layout*/
6894 : 0 : i40e_pf_host_handle_vf_msg(dev,
6895 : 0 : rte_le_to_cpu_16(info.desc.retval),
6896 : : rte_le_to_cpu_32(info.desc.cookie_high),
6897 : : rte_le_to_cpu_32(info.desc.cookie_low),
6898 : 0 : info.msg_buf,
6899 : 0 : info.msg_len);
6900 : 0 : break;
6901 : 0 : case i40e_aqc_opc_get_link_status:
6902 : 0 : ret = i40e_dev_link_update(dev, 0);
6903 [ # # ]: 0 : if (!ret)
6904 : 0 : rte_eth_dev_callback_process(dev,
6905 : : RTE_ETH_EVENT_INTR_LSC, NULL);
6906 : : break;
6907 : 0 : default:
6908 : 0 : PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
6909 : : opcode);
6910 : 0 : break;
6911 : : }
6912 : : }
6913 : 0 : }
6914 : :
6915 : : static void
6916 : 0 : i40e_handle_mdd_event(struct rte_eth_dev *dev)
6917 : : {
6918 : : #define I40E_MDD_CLEAR32 0xFFFFFFFF
6919 : : #define I40E_MDD_CLEAR16 0xFFFF
6920 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6921 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6922 : : bool mdd_detected = false;
6923 : : struct i40e_pf_vf *vf;
6924 : : uint32_t reg;
6925 : : int i;
6926 : :
6927 : : /* find what triggered the MDD event */
6928 : 0 : reg = I40E_READ_REG(hw, I40E_GL_MDET_TX);
6929 [ # # ]: 0 : if (reg & I40E_GL_MDET_TX_VALID_MASK) {
6930 : 0 : uint8_t pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
6931 : : I40E_GL_MDET_TX_PF_NUM_SHIFT;
6932 : 0 : uint16_t vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
6933 : : I40E_GL_MDET_TX_VF_NUM_SHIFT;
6934 : 0 : uint8_t event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
6935 : : I40E_GL_MDET_TX_EVENT_SHIFT;
6936 : 0 : uint16_t queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
6937 : 0 : I40E_GL_MDET_TX_QUEUE_SHIFT) -
6938 : 0 : hw->func_caps.base_queue;
6939 : 0 : PMD_DRV_LOG(WARNING, "Malicious Driver Detection event 0x%02x on TX "
6940 : : "queue %d PF number 0x%02x VF number 0x%02x device %s",
6941 : : event, queue, pf_num, vf_num, dev->data->name);
6942 : 0 : I40E_WRITE_REG(hw, I40E_GL_MDET_TX, I40E_MDD_CLEAR32);
6943 : : mdd_detected = true;
6944 : : }
6945 : 0 : reg = I40E_READ_REG(hw, I40E_GL_MDET_RX);
6946 [ # # ]: 0 : if (reg & I40E_GL_MDET_RX_VALID_MASK) {
6947 : : uint8_t func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
6948 : : I40E_GL_MDET_RX_FUNCTION_SHIFT;
6949 : 0 : uint8_t event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
6950 : : I40E_GL_MDET_RX_EVENT_SHIFT;
6951 : 0 : uint16_t queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
6952 : 0 : I40E_GL_MDET_RX_QUEUE_SHIFT) -
6953 : 0 : hw->func_caps.base_queue;
6954 : :
6955 : 0 : PMD_DRV_LOG(WARNING, "Malicious Driver Detection event 0x%02x on RX "
6956 : : "queue %d of function 0x%02x device %s",
6957 : : event, queue, func, dev->data->name);
6958 : 0 : I40E_WRITE_REG(hw, I40E_GL_MDET_RX, I40E_MDD_CLEAR32);
6959 : : mdd_detected = true;
6960 : : }
6961 : :
6962 [ # # ]: 0 : if (mdd_detected) {
6963 : 0 : reg = I40E_READ_REG(hw, I40E_PF_MDET_TX);
6964 [ # # ]: 0 : if (reg & I40E_PF_MDET_TX_VALID_MASK) {
6965 : 0 : I40E_WRITE_REG(hw, I40E_PF_MDET_TX, I40E_MDD_CLEAR16);
6966 : 0 : PMD_DRV_LOG(WARNING, "TX driver issue detected on PF");
6967 : : }
6968 : 0 : reg = I40E_READ_REG(hw, I40E_PF_MDET_RX);
6969 [ # # ]: 0 : if (reg & I40E_PF_MDET_RX_VALID_MASK) {
6970 : 0 : I40E_WRITE_REG(hw, I40E_PF_MDET_RX,
6971 : : I40E_MDD_CLEAR16);
6972 : 0 : PMD_DRV_LOG(WARNING, "RX driver issue detected on PF");
6973 : : }
6974 : : }
6975 : :
6976 : : /* see if one of the VFs needs its hand slapped */
6977 [ # # # # ]: 0 : for (i = 0; i < pf->vf_num && mdd_detected; i++) {
6978 : 0 : vf = &pf->vfs[i];
6979 : 0 : reg = I40E_READ_REG(hw, I40E_VP_MDET_TX(i));
6980 [ # # ]: 0 : if (reg & I40E_VP_MDET_TX_VALID_MASK) {
6981 : 0 : I40E_WRITE_REG(hw, I40E_VP_MDET_TX(i),
6982 : : I40E_MDD_CLEAR16);
6983 : 0 : vf->num_mdd_events++;
6984 : 0 : PMD_DRV_LOG(WARNING, "TX driver issue detected on VF %d %-"
6985 : : PRIu64 "times",
6986 : : i, vf->num_mdd_events);
6987 : : }
6988 : :
6989 : 0 : reg = I40E_READ_REG(hw, I40E_VP_MDET_RX(i));
6990 [ # # ]: 0 : if (reg & I40E_VP_MDET_RX_VALID_MASK) {
6991 : 0 : I40E_WRITE_REG(hw, I40E_VP_MDET_RX(i),
6992 : : I40E_MDD_CLEAR16);
6993 : 0 : vf->num_mdd_events++;
6994 : 0 : PMD_DRV_LOG(WARNING, "RX driver issue detected on VF %d %-"
6995 : : PRIu64 "times",
6996 : : i, vf->num_mdd_events);
6997 : : }
6998 : : }
6999 : 0 : }
7000 : :
7001 : : /**
7002 : : * Interrupt handler triggered by NIC for handling
7003 : : * specific interrupt.
7004 : : *
7005 : : * @param handle
7006 : : * Pointer to interrupt handle.
7007 : : * @param param
7008 : : * The address of parameter (struct rte_eth_dev *) registered before.
7009 : : *
7010 : : * @return
7011 : : * void
7012 : : */
7013 : : static void
7014 : 0 : i40e_dev_interrupt_handler(void *param)
7015 : : {
7016 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
7017 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7018 : : uint32_t icr0;
7019 : :
7020 : : /* Disable interrupt */
7021 : 0 : i40e_pf_disable_irq0(hw);
7022 : :
7023 : : /* read out interrupt causes */
7024 : 0 : icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
7025 : :
7026 : : /* No interrupt event indicated */
7027 [ # # ]: 0 : if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK)) {
7028 : 0 : PMD_DRV_LOG(INFO, "No interrupt event");
7029 : 0 : goto done;
7030 : : }
7031 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
7032 : 0 : PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
7033 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
7034 : 0 : PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
7035 : 0 : i40e_handle_mdd_event(dev);
7036 : : }
7037 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
7038 : 0 : PMD_DRV_LOG(INFO, "ICR0: global reset requested");
7039 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
7040 : 0 : PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
7041 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
7042 : 0 : PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
7043 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
7044 : 0 : PMD_DRV_LOG(ERR, "ICR0: HMC error");
7045 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
7046 : 0 : PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
7047 : :
7048 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
7049 : 0 : PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
7050 : 0 : i40e_dev_handle_vfr_event(dev);
7051 : : }
7052 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
7053 : 0 : PMD_DRV_LOG(INFO, "ICR0: adminq event");
7054 : 0 : i40e_dev_handle_aq_msg(dev);
7055 : : }
7056 : :
7057 : 0 : done:
7058 : : /* Enable interrupt */
7059 : 0 : i40e_pf_enable_irq0(hw);
7060 : 0 : }
7061 : :
7062 : : static void
7063 : 0 : i40e_dev_alarm_handler(void *param)
7064 : : {
7065 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
7066 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7067 : : uint32_t icr0;
7068 : :
7069 : : /* Disable interrupt */
7070 : 0 : i40e_pf_disable_irq0(hw);
7071 : :
7072 : : /* read out interrupt causes */
7073 : 0 : icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
7074 : :
7075 : : /* No interrupt event indicated */
7076 [ # # ]: 0 : if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK))
7077 : 0 : goto done;
7078 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
7079 : 0 : PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
7080 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
7081 : 0 : PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
7082 : 0 : i40e_handle_mdd_event(dev);
7083 : : }
7084 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
7085 : 0 : PMD_DRV_LOG(INFO, "ICR0: global reset requested");
7086 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
7087 : 0 : PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
7088 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
7089 : 0 : PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
7090 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
7091 : 0 : PMD_DRV_LOG(ERR, "ICR0: HMC error");
7092 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
7093 : 0 : PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
7094 : :
7095 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
7096 : 0 : PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
7097 : 0 : i40e_dev_handle_vfr_event(dev);
7098 : : }
7099 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
7100 : 0 : PMD_DRV_LOG(INFO, "ICR0: adminq event");
7101 : 0 : i40e_dev_handle_aq_msg(dev);
7102 : : }
7103 : :
7104 : 0 : done:
7105 : : /* Enable interrupt */
7106 : 0 : i40e_pf_enable_irq0(hw);
7107 : 0 : rte_eal_alarm_set(I40E_ALARM_INTERVAL,
7108 : : i40e_dev_alarm_handler, dev);
7109 : 0 : }
7110 : :
7111 : : int
7112 : 0 : i40e_add_macvlan_filters(struct i40e_vsi *vsi,
7113 : : struct i40e_macvlan_filter *filter,
7114 : : int total)
7115 : : {
7116 : : int ele_num, ele_buff_size;
7117 : : int num, actual_num, i;
7118 : : uint16_t flags;
7119 : : int ret = I40E_SUCCESS;
7120 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7121 : 0 : uint8_t aq_buff[I40E_AQ_BUF_SZ] = {0};
7122 : : struct i40e_aqc_add_macvlan_element_data *req_list =
7123 : : (struct i40e_aqc_add_macvlan_element_data *)aq_buff;
7124 : :
7125 [ # # ]: 0 : if (hw->aq.asq_buf_size > I40E_AQ_BUF_SZ) {
7126 : 0 : PMD_DRV_LOG(ERR, "AdminQ size biffer than max");
7127 : 0 : return I40E_ERR_NO_MEMORY;
7128 : : }
7129 : :
7130 [ # # ]: 0 : if (filter == NULL || total == 0)
7131 : : return I40E_ERR_PARAM;
7132 : 0 : ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
7133 : : ele_buff_size = hw->aq.asq_buf_size;
7134 : :
7135 : : num = 0;
7136 : : do {
7137 [ # # ]: 0 : actual_num = (num + ele_num > total) ? (total - num) : ele_num;
7138 : 0 : memset(req_list, 0, ele_buff_size);
7139 : :
7140 [ # # ]: 0 : for (i = 0; i < actual_num; i++) {
7141 : 0 : rte_memcpy(req_list[i].mac_addr,
7142 [ # # ]: 0 : &filter[num + i].macaddr, ETH_ADDR_LEN);
7143 : 0 : req_list[i].vlan_tag =
7144 : 0 : rte_cpu_to_le_16(filter[num + i].vlan_id);
7145 : :
7146 [ # # ]: 0 : switch (filter[num + i].filter_type) {
7147 : : case I40E_MAC_PERFECT_MATCH:
7148 : : flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH |
7149 : : I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
7150 : : break;
7151 : : case I40E_MACVLAN_PERFECT_MATCH:
7152 : : flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
7153 : : break;
7154 : : case I40E_MAC_HASH_MATCH:
7155 : : flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH |
7156 : : I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
7157 : : break;
7158 : : case I40E_MACVLAN_HASH_MATCH:
7159 : : flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH;
7160 : : break;
7161 : 0 : default:
7162 : 0 : PMD_DRV_LOG(ERR, "Invalid MAC match type");
7163 : 0 : return I40E_ERR_PARAM;
7164 : : }
7165 : :
7166 : 0 : req_list[i].queue_number = 0;
7167 : :
7168 : 0 : req_list[i].flags = rte_cpu_to_le_16(flags);
7169 : : }
7170 : :
7171 : 0 : ret = i40e_aq_add_macvlan(hw, vsi->seid, req_list,
7172 : : actual_num, NULL);
7173 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
7174 : 0 : PMD_DRV_LOG(ERR, "Failed to add macvlan filter");
7175 : 0 : return ret;
7176 : : }
7177 : 0 : num += actual_num;
7178 [ # # ]: 0 : } while (num < total);
7179 : : return I40E_SUCCESS;
7180 : : }
7181 : :
7182 : : int
7183 : 0 : i40e_remove_macvlan_filters(struct i40e_vsi *vsi,
7184 : : struct i40e_macvlan_filter *filter,
7185 : : int total)
7186 : : {
7187 : : int ele_num, ele_buff_size;
7188 : : int num, actual_num, i;
7189 : : uint16_t flags;
7190 : : int ret = I40E_SUCCESS;
7191 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7192 : 0 : uint8_t aq_buff[I40E_AQ_BUF_SZ] = {0};
7193 : : struct i40e_aqc_remove_macvlan_element_data *req_list =
7194 : : (struct i40e_aqc_remove_macvlan_element_data *)aq_buff;
7195 : : enum i40e_admin_queue_err aq_status;
7196 : :
7197 [ # # ]: 0 : if (filter == NULL || total == 0)
7198 : : return I40E_ERR_PARAM;
7199 : :
7200 [ # # ]: 0 : if (hw->aq.asq_buf_size > I40E_AQ_BUF_SZ) {
7201 : 0 : PMD_DRV_LOG(ERR, "AdminQ size biffer than max");
7202 : 0 : return I40E_ERR_NO_MEMORY;
7203 : : }
7204 : :
7205 : 0 : ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
7206 : : ele_buff_size = hw->aq.asq_buf_size;
7207 : :
7208 : : num = 0;
7209 : : do {
7210 [ # # ]: 0 : actual_num = (num + ele_num > total) ? (total - num) : ele_num;
7211 : 0 : memset(req_list, 0, ele_buff_size);
7212 : :
7213 [ # # ]: 0 : for (i = 0; i < actual_num; i++) {
7214 : 0 : rte_memcpy(req_list[i].mac_addr,
7215 [ # # ]: 0 : &filter[num + i].macaddr, ETH_ADDR_LEN);
7216 : 0 : req_list[i].vlan_tag =
7217 : 0 : rte_cpu_to_le_16(filter[num + i].vlan_id);
7218 : :
7219 [ # # ]: 0 : switch (filter[num + i].filter_type) {
7220 : : case I40E_MAC_PERFECT_MATCH:
7221 : : flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
7222 : : I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
7223 : : break;
7224 : : case I40E_MACVLAN_PERFECT_MATCH:
7225 : : flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
7226 : : break;
7227 : : case I40E_MAC_HASH_MATCH:
7228 : : flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH |
7229 : : I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
7230 : : break;
7231 : : case I40E_MACVLAN_HASH_MATCH:
7232 : : flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH;
7233 : : break;
7234 : 0 : default:
7235 : 0 : PMD_DRV_LOG(ERR, "Invalid MAC filter type");
7236 : 0 : return I40E_ERR_PARAM;
7237 : : }
7238 : 0 : req_list[i].flags = rte_cpu_to_le_16(flags);
7239 : : }
7240 : :
7241 : 0 : ret = i40e_aq_remove_macvlan_v2(hw, vsi->seid, req_list,
7242 : : actual_num, NULL, &aq_status);
7243 : :
7244 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
7245 : : /* Do not report as an error when firmware returns ENOENT */
7246 [ # # ]: 0 : if (aq_status != I40E_AQ_RC_ENOENT) {
7247 : 0 : PMD_DRV_LOG(ERR, "Failed to remove macvlan filter");
7248 : 0 : return ret;
7249 : : }
7250 : : }
7251 : 0 : num += actual_num;
7252 [ # # ]: 0 : } while (num < total);
7253 : :
7254 : : return I40E_SUCCESS;
7255 : : }
7256 : :
7257 : : /* Find out specific MAC filter */
7258 : : static struct i40e_mac_filter *
7259 : : i40e_find_mac_filter(struct i40e_vsi *vsi,
7260 : : struct rte_ether_addr *macaddr)
7261 : : {
7262 : : struct i40e_mac_filter *f;
7263 : :
7264 [ # # # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7265 [ # # # # ]: 0 : if (rte_is_same_ether_addr(macaddr, &f->mac_info.mac_addr))
7266 : : return f;
7267 : : }
7268 : :
7269 : : return NULL;
7270 : : }
7271 : :
7272 : : static bool
7273 : : i40e_find_vlan_filter(struct i40e_vsi *vsi,
7274 : : uint16_t vlan_id)
7275 : : {
7276 : : uint32_t vid_idx, vid_bit;
7277 : :
7278 : : if (vlan_id > RTE_ETH_VLAN_ID_MAX)
7279 : : return 0;
7280 : :
7281 : 0 : vid_idx = I40E_VFTA_IDX(vlan_id);
7282 : 0 : vid_bit = I40E_VFTA_BIT(vlan_id);
7283 : :
7284 : 0 : if (vsi->vfta[vid_idx] & vid_bit)
7285 : : return 1;
7286 : : else
7287 : : return 0;
7288 : : }
7289 : :
7290 : : static void
7291 : : i40e_store_vlan_filter(struct i40e_vsi *vsi,
7292 : : uint16_t vlan_id, bool on)
7293 : : {
7294 : : uint32_t vid_idx, vid_bit;
7295 : :
7296 : 0 : vid_idx = I40E_VFTA_IDX(vlan_id);
7297 : 0 : vid_bit = I40E_VFTA_BIT(vlan_id);
7298 : :
7299 [ # # ]: 0 : if (on)
7300 : 0 : vsi->vfta[vid_idx] |= vid_bit;
7301 : : else
7302 : 0 : vsi->vfta[vid_idx] &= ~vid_bit;
7303 : : }
7304 : :
7305 : : void
7306 : 0 : i40e_set_vlan_filter(struct i40e_vsi *vsi,
7307 : : uint16_t vlan_id, bool on)
7308 : : {
7309 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7310 : 0 : struct i40e_aqc_add_remove_vlan_element_data vlan_data = {0};
7311 : : int ret;
7312 : :
7313 [ # # ]: 0 : if (vlan_id > RTE_ETH_VLAN_ID_MAX)
7314 : 0 : return;
7315 : :
7316 : : i40e_store_vlan_filter(vsi, vlan_id, on);
7317 : :
7318 [ # # # # : 0 : if ((!vsi->vlan_anti_spoof_on && !vsi->vlan_filter_on) || !vlan_id)
# # ]
7319 : : return;
7320 : :
7321 : 0 : vlan_data.vlan_tag = rte_cpu_to_le_16(vlan_id);
7322 : :
7323 [ # # ]: 0 : if (on) {
7324 : 0 : ret = i40e_aq_add_vlan(hw, vsi->seid,
7325 : : &vlan_data, 1, NULL);
7326 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7327 : 0 : PMD_DRV_LOG(ERR, "Failed to add vlan filter");
7328 : : } else {
7329 : 0 : ret = i40e_aq_remove_vlan(hw, vsi->seid,
7330 : : &vlan_data, 1, NULL);
7331 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7332 : 0 : PMD_DRV_LOG(ERR,
7333 : : "Failed to remove vlan filter");
7334 : : }
7335 : : }
7336 : :
7337 : : /**
7338 : : * Find all vlan options for specific mac addr,
7339 : : * return with actual vlan found.
7340 : : */
7341 : : int
7342 : 0 : i40e_find_all_vlan_for_mac(struct i40e_vsi *vsi,
7343 : : struct i40e_macvlan_filter *mv_f,
7344 : : int num, struct rte_ether_addr *addr)
7345 : : {
7346 : : int i;
7347 : : uint32_t j, k;
7348 : :
7349 : : /**
7350 : : * Not to use i40e_find_vlan_filter to decrease the loop time,
7351 : : * although the code looks complex.
7352 : : */
7353 [ # # ]: 0 : if (num < vsi->vlan_num)
7354 : : return I40E_ERR_PARAM;
7355 : :
7356 : : i = 0;
7357 [ # # ]: 0 : for (j = 0; j < I40E_VFTA_SIZE; j++) {
7358 [ # # ]: 0 : if (vsi->vfta[j]) {
7359 [ # # ]: 0 : for (k = 0; k < I40E_UINT32_BIT_SIZE; k++) {
7360 [ # # ]: 0 : if (vsi->vfta[j] & (1 << k)) {
7361 [ # # ]: 0 : if (i > num - 1) {
7362 : 0 : PMD_DRV_LOG(ERR,
7363 : : "vlan number doesn't match");
7364 : 0 : return I40E_ERR_PARAM;
7365 : : }
7366 [ # # ]: 0 : rte_memcpy(&mv_f[i].macaddr,
7367 : : addr, ETH_ADDR_LEN);
7368 : 0 : mv_f[i].vlan_id =
7369 : 0 : j * I40E_UINT32_BIT_SIZE + k;
7370 : 0 : i++;
7371 : : }
7372 : : }
7373 : : }
7374 : : }
7375 : : return I40E_SUCCESS;
7376 : : }
7377 : :
7378 : : static inline int
7379 : 0 : i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
7380 : : struct i40e_macvlan_filter *mv_f,
7381 : : int num,
7382 : : uint16_t vlan)
7383 : : {
7384 : : int i = 0;
7385 : : struct i40e_mac_filter *f;
7386 : :
7387 [ # # ]: 0 : if (num < vsi->mac_num)
7388 : : return I40E_ERR_PARAM;
7389 : :
7390 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7391 [ # # ]: 0 : if (i > num - 1) {
7392 : 0 : PMD_DRV_LOG(ERR, "buffer number not match");
7393 : 0 : return I40E_ERR_PARAM;
7394 : : }
7395 [ # # ]: 0 : rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
7396 : : ETH_ADDR_LEN);
7397 : 0 : mv_f[i].vlan_id = vlan;
7398 : 0 : mv_f[i].filter_type = f->mac_info.filter_type;
7399 : 0 : i++;
7400 : : }
7401 : :
7402 : : return I40E_SUCCESS;
7403 : : }
7404 : :
7405 : : static int
7406 : 0 : i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi)
7407 : : {
7408 : : int i, j, num;
7409 : : struct i40e_mac_filter *f;
7410 : : struct i40e_macvlan_filter *mv_f;
7411 : : int ret = I40E_SUCCESS;
7412 : :
7413 [ # # # # ]: 0 : if (vsi == NULL || vsi->mac_num == 0)
7414 : : return I40E_ERR_PARAM;
7415 : :
7416 : : /* Case that no vlan is set */
7417 [ # # ]: 0 : if (vsi->vlan_num == 0)
7418 : 0 : num = vsi->mac_num;
7419 : : else
7420 : 0 : num = vsi->mac_num * vsi->vlan_num;
7421 : :
7422 : 0 : mv_f = calloc(num, sizeof(*mv_f));
7423 [ # # ]: 0 : if (mv_f == NULL) {
7424 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7425 : 0 : return I40E_ERR_NO_MEMORY;
7426 : : }
7427 : :
7428 : : i = 0;
7429 [ # # ]: 0 : if (vsi->vlan_num == 0) {
7430 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7431 : 0 : rte_memcpy(&mv_f[i].macaddr,
7432 [ # # ]: 0 : &f->mac_info.mac_addr, ETH_ADDR_LEN);
7433 : 0 : mv_f[i].filter_type = f->mac_info.filter_type;
7434 : 0 : mv_f[i].vlan_id = 0;
7435 : 0 : i++;
7436 : : }
7437 : : } else {
7438 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7439 : 0 : ret = i40e_find_all_vlan_for_mac(vsi,&mv_f[i],
7440 : 0 : vsi->vlan_num, &f->mac_info.mac_addr);
7441 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7442 : 0 : goto DONE;
7443 [ # # ]: 0 : for (j = i; j < i + vsi->vlan_num; j++)
7444 : 0 : mv_f[j].filter_type = f->mac_info.filter_type;
7445 : : i += vsi->vlan_num;
7446 : : }
7447 : : }
7448 : :
7449 : 0 : ret = i40e_remove_macvlan_filters(vsi, mv_f, num);
7450 : 0 : DONE:
7451 : 0 : free(mv_f);
7452 : :
7453 : 0 : return ret;
7454 : : }
7455 : :
7456 : : int
7457 : 0 : i40e_vsi_add_vlan(struct i40e_vsi *vsi, uint16_t vlan)
7458 : : {
7459 : 0 : struct i40e_macvlan_filter mv_f[I40E_NUM_MACADDR_MAX] = {0};
7460 : : int mac_num;
7461 : : int ret = I40E_SUCCESS;
7462 : :
7463 [ # # ]: 0 : if (!vsi || vlan > RTE_ETHER_MAX_VLAN_ID)
7464 : : return I40E_ERR_PARAM;
7465 : :
7466 : : /* If it's already set, just return */
7467 [ # # ]: 0 : if (i40e_find_vlan_filter(vsi,vlan))
7468 : : return I40E_SUCCESS;
7469 : :
7470 : 0 : mac_num = vsi->mac_num;
7471 : :
7472 [ # # ]: 0 : if (mac_num == 0) {
7473 : 0 : PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
7474 : 0 : return I40E_ERR_PARAM;
7475 : : }
7476 [ # # ]: 0 : if (mac_num > I40E_NUM_MACADDR_MAX) {
7477 : 0 : PMD_DRV_LOG(ERR, "Error! Too many MAC addresses");
7478 : 0 : return I40E_ERR_PARAM;
7479 : : }
7480 : :
7481 : 0 : ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
7482 : :
7483 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7484 : : return ret;
7485 : :
7486 : 0 : ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
7487 : :
7488 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7489 : : return ret;
7490 : :
7491 : 0 : i40e_set_vlan_filter(vsi, vlan, 1);
7492 : :
7493 : 0 : vsi->vlan_num++;
7494 : 0 : return I40E_SUCCESS;
7495 : : }
7496 : :
7497 : : int
7498 : 0 : i40e_vsi_delete_vlan(struct i40e_vsi *vsi, uint16_t vlan)
7499 : : {
7500 : 0 : struct i40e_macvlan_filter mv_f[I40E_NUM_MACADDR_MAX] = {0};
7501 : : int mac_num;
7502 : : int ret = I40E_SUCCESS;
7503 : :
7504 : : /**
7505 : : * Vlan 0 is the generic filter for untagged packets
7506 : : * and can't be removed.
7507 : : */
7508 [ # # # # ]: 0 : if (!vsi || vlan == 0 || vlan > RTE_ETHER_MAX_VLAN_ID)
7509 : : return I40E_ERR_PARAM;
7510 : :
7511 : : /* If can't find it, just return */
7512 [ # # ]: 0 : if (!i40e_find_vlan_filter(vsi, vlan))
7513 : : return I40E_ERR_PARAM;
7514 : :
7515 : 0 : mac_num = vsi->mac_num;
7516 : :
7517 [ # # ]: 0 : if (mac_num == 0) {
7518 : 0 : PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
7519 : 0 : return I40E_ERR_PARAM;
7520 : : }
7521 [ # # ]: 0 : if (mac_num > I40E_NUM_MACADDR_MAX) {
7522 : 0 : PMD_DRV_LOG(ERR, "Error! Too many MAC addresses");
7523 : 0 : return I40E_ERR_PARAM;
7524 : : }
7525 : :
7526 : 0 : ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
7527 : :
7528 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7529 : : return ret;
7530 : :
7531 : 0 : ret = i40e_remove_macvlan_filters(vsi, mv_f, mac_num);
7532 : :
7533 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7534 : : return ret;
7535 : :
7536 : : /* This is last vlan to remove, replace all mac filter with vlan 0 */
7537 [ # # ]: 0 : if (vsi->vlan_num == 1) {
7538 : 0 : ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, 0);
7539 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7540 : : return ret;
7541 : :
7542 : 0 : ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
7543 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7544 : : return ret;
7545 : : }
7546 : :
7547 : 0 : i40e_set_vlan_filter(vsi, vlan, 0);
7548 : :
7549 : 0 : vsi->vlan_num--;
7550 : 0 : return I40E_SUCCESS;
7551 : : }
7552 : :
7553 : : int
7554 : 0 : i40e_vsi_add_mac(struct i40e_vsi *vsi, struct i40e_mac_filter_info *mac_filter)
7555 : : {
7556 : : struct i40e_mac_filter *f;
7557 : : struct i40e_macvlan_filter *mv_f;
7558 : : int i, vlan_num = 0;
7559 : : int ret = I40E_SUCCESS;
7560 : :
7561 : : /* If it's add and we've config it, return */
7562 : : f = i40e_find_mac_filter(vsi, &mac_filter->mac_addr);
7563 [ # # ]: 0 : if (f != NULL)
7564 : : return I40E_SUCCESS;
7565 [ # # ]: 0 : if (mac_filter->filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7566 : : mac_filter->filter_type == I40E_MACVLAN_HASH_MATCH) {
7567 : :
7568 : : /**
7569 : : * If vlan_num is 0, that's the first time to add mac,
7570 : : * set mask for vlan_id 0.
7571 : : */
7572 [ # # ]: 0 : if (vsi->vlan_num == 0) {
7573 : 0 : i40e_set_vlan_filter(vsi, 0, 1);
7574 : 0 : vsi->vlan_num = 1;
7575 : : }
7576 : 0 : vlan_num = vsi->vlan_num;
7577 [ # # ]: 0 : } else if (mac_filter->filter_type == I40E_MAC_PERFECT_MATCH ||
7578 : : mac_filter->filter_type == I40E_MAC_HASH_MATCH)
7579 : : vlan_num = 1;
7580 : :
7581 : 0 : mv_f = calloc(vlan_num, sizeof(*mv_f));
7582 [ # # ]: 0 : if (mv_f == NULL) {
7583 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7584 : 0 : return I40E_ERR_NO_MEMORY;
7585 : : }
7586 : :
7587 [ # # ]: 0 : for (i = 0; i < vlan_num; i++) {
7588 : 0 : mv_f[i].filter_type = mac_filter->filter_type;
7589 [ # # ]: 0 : rte_memcpy(&mv_f[i].macaddr, &mac_filter->mac_addr,
7590 : : ETH_ADDR_LEN);
7591 : : }
7592 : :
7593 [ # # ]: 0 : if (mac_filter->filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7594 : : mac_filter->filter_type == I40E_MACVLAN_HASH_MATCH) {
7595 : 0 : ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
7596 : : &mac_filter->mac_addr);
7597 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7598 : 0 : goto DONE;
7599 : : }
7600 : :
7601 : 0 : ret = i40e_add_macvlan_filters(vsi, mv_f, vlan_num);
7602 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7603 : 0 : goto DONE;
7604 : :
7605 : : /* Add the mac addr into mac list */
7606 : 0 : f = rte_zmalloc("macv_filter", sizeof(*f), 0);
7607 [ # # ]: 0 : if (f == NULL) {
7608 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7609 : : ret = I40E_ERR_NO_MEMORY;
7610 : 0 : goto DONE;
7611 : : }
7612 [ # # ]: 0 : rte_memcpy(&f->mac_info.mac_addr, &mac_filter->mac_addr,
7613 : : ETH_ADDR_LEN);
7614 : 0 : f->mac_info.filter_type = mac_filter->filter_type;
7615 : 0 : TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
7616 : 0 : vsi->mac_num++;
7617 : :
7618 : : ret = I40E_SUCCESS;
7619 : 0 : DONE:
7620 : 0 : free(mv_f);
7621 : :
7622 : 0 : return ret;
7623 : : }
7624 : :
7625 : : int
7626 : 0 : i40e_vsi_delete_mac(struct i40e_vsi *vsi, struct rte_ether_addr *addr)
7627 : : {
7628 : : struct i40e_mac_filter *f;
7629 : : struct i40e_macvlan_filter *mv_f;
7630 : : int i, vlan_num;
7631 : : enum i40e_mac_filter_type filter_type;
7632 : : int ret = I40E_SUCCESS;
7633 : :
7634 : : /* Can't find it, return an error */
7635 : : f = i40e_find_mac_filter(vsi, addr);
7636 [ # # ]: 0 : if (f == NULL)
7637 : : return I40E_ERR_PARAM;
7638 : :
7639 : 0 : vlan_num = vsi->vlan_num;
7640 : 0 : filter_type = f->mac_info.filter_type;
7641 : 0 : if (filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7642 [ # # ]: 0 : filter_type == I40E_MACVLAN_HASH_MATCH) {
7643 [ # # ]: 0 : if (vlan_num == 0) {
7644 : 0 : PMD_DRV_LOG(ERR, "VLAN number shouldn't be 0");
7645 : 0 : return I40E_ERR_PARAM;
7646 : : }
7647 : 0 : } else if (filter_type == I40E_MAC_PERFECT_MATCH ||
7648 [ # # ]: 0 : filter_type == I40E_MAC_HASH_MATCH)
7649 : : vlan_num = 1;
7650 : :
7651 : 0 : mv_f = calloc(vlan_num, sizeof(*mv_f));
7652 [ # # ]: 0 : if (mv_f == NULL) {
7653 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7654 : 0 : return I40E_ERR_NO_MEMORY;
7655 : : }
7656 : :
7657 [ # # ]: 0 : for (i = 0; i < vlan_num; i++) {
7658 : 0 : mv_f[i].filter_type = filter_type;
7659 [ # # ]: 0 : rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
7660 : : ETH_ADDR_LEN);
7661 : : }
7662 [ # # ]: 0 : if (filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7663 : : filter_type == I40E_MACVLAN_HASH_MATCH) {
7664 : 0 : ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num, addr);
7665 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7666 : 0 : goto DONE;
7667 : : }
7668 : :
7669 : 0 : ret = i40e_remove_macvlan_filters(vsi, mv_f, vlan_num);
7670 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7671 : 0 : goto DONE;
7672 : :
7673 : : /* Remove the mac addr into mac list */
7674 [ # # ]: 0 : TAILQ_REMOVE(&vsi->mac_list, f, next);
7675 : 0 : rte_free(f);
7676 : 0 : vsi->mac_num--;
7677 : :
7678 : : ret = I40E_SUCCESS;
7679 : 0 : DONE:
7680 : 0 : free(mv_f);
7681 : 0 : return ret;
7682 : : }
7683 : :
7684 : : /* Configure hash enable flags for RSS */
7685 : : uint64_t
7686 : 0 : i40e_config_hena(const struct i40e_adapter *adapter, uint64_t flags)
7687 : : {
7688 : : uint64_t hena = 0;
7689 : : int i;
7690 : :
7691 [ # # ]: 0 : if (!flags)
7692 : : return hena;
7693 : :
7694 [ # # ]: 0 : for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < I40E_FLOW_TYPE_MAX; i++) {
7695 [ # # ]: 0 : if (flags & RTE_BIT64(i))
7696 : 0 : hena |= adapter->pctypes_tbl[i];
7697 : : }
7698 : :
7699 : : return hena;
7700 : : }
7701 : :
7702 : : /* Parse the hash enable flags */
7703 : : uint64_t
7704 : 0 : i40e_parse_hena(const struct i40e_adapter *adapter, uint64_t flags)
7705 : : {
7706 : : uint64_t rss_hf = 0;
7707 : :
7708 [ # # ]: 0 : if (!flags)
7709 : : return rss_hf;
7710 : : int i;
7711 : :
7712 [ # # ]: 0 : for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < I40E_FLOW_TYPE_MAX; i++) {
7713 [ # # ]: 0 : if (flags & adapter->pctypes_tbl[i])
7714 : 0 : rss_hf |= RTE_BIT64(i);
7715 : : }
7716 : : return rss_hf;
7717 : : }
7718 : :
7719 : : /* Disable RSS */
7720 : : void
7721 : 0 : i40e_pf_disable_rss(struct i40e_pf *pf)
7722 : : {
7723 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7724 : :
7725 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
7726 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
7727 : 0 : I40E_WRITE_FLUSH(hw);
7728 : 0 : }
7729 : :
7730 : : int
7731 : 0 : i40e_set_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t key_len)
7732 : : {
7733 : 0 : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
7734 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7735 : : uint16_t key_idx = (vsi->type == I40E_VSI_SRIOV) ?
7736 : : I40E_VFQF_HKEY_MAX_INDEX :
7737 : : I40E_PFQF_HKEY_MAX_INDEX;
7738 : :
7739 [ # # ]: 0 : if (!key || key_len == 0) {
7740 : 0 : PMD_DRV_LOG(DEBUG, "No key to be configured");
7741 : 0 : return 0;
7742 [ # # ]: 0 : } else if (key_len != (key_idx + 1) *
7743 : : sizeof(uint32_t)) {
7744 : 0 : PMD_DRV_LOG(ERR, "Invalid key length %u", key_len);
7745 : 0 : return -EINVAL;
7746 : : }
7747 : :
7748 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
7749 : : struct i40e_aqc_get_set_rss_key_data *key_dw =
7750 : : (struct i40e_aqc_get_set_rss_key_data *)key;
7751 : : enum i40e_status_code status =
7752 : 0 : i40e_aq_set_rss_key(hw, vsi->vsi_id, key_dw);
7753 : :
7754 [ # # ]: 0 : if (status) {
7755 : 0 : PMD_DRV_LOG(ERR,
7756 : : "Failed to configure RSS key via AQ, error status: %d",
7757 : : status);
7758 : 0 : return -EIO;
7759 : : }
7760 : : } else {
7761 : : uint32_t *hash_key = (uint32_t *)key;
7762 : : uint16_t i;
7763 : :
7764 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
7765 [ # # ]: 0 : for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
7766 : 0 : I40E_WRITE_REG(
7767 : : hw,
7768 : : I40E_VFQF_HKEY1(i, vsi->user_param),
7769 : : hash_key[i]);
7770 : :
7771 : : } else {
7772 [ # # ]: 0 : for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
7773 : 0 : I40E_WRITE_REG(hw, I40E_PFQF_HKEY(i),
7774 : : hash_key[i]);
7775 : : }
7776 : 0 : I40E_WRITE_FLUSH(hw);
7777 : : }
7778 : :
7779 : : return 0;
7780 : : }
7781 : :
7782 : : static int
7783 : 0 : i40e_get_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t *key_len)
7784 : : {
7785 : 0 : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
7786 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7787 : : uint32_t reg;
7788 : : int ret;
7789 : :
7790 [ # # ]: 0 : if (!key || !key_len)
7791 : : return 0;
7792 : :
7793 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
7794 : 0 : ret = i40e_aq_get_rss_key(hw, vsi->vsi_id,
7795 : : (struct i40e_aqc_get_set_rss_key_data *)key);
7796 [ # # ]: 0 : if (ret) {
7797 : 0 : PMD_INIT_LOG(ERR, "Failed to get RSS key via AQ");
7798 : 0 : return ret;
7799 : : }
7800 : : } else {
7801 : : uint32_t *key_dw = (uint32_t *)key;
7802 : : uint16_t i;
7803 : :
7804 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
7805 [ # # ]: 0 : for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++) {
7806 : 0 : reg = I40E_VFQF_HKEY1(i, vsi->user_param);
7807 : 0 : key_dw[i] = i40e_read_rx_ctl(hw, reg);
7808 : : }
7809 : 0 : *key_len = (I40E_VFQF_HKEY_MAX_INDEX + 1) *
7810 : : sizeof(uint32_t);
7811 : : } else {
7812 [ # # ]: 0 : for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
7813 : 0 : reg = I40E_PFQF_HKEY(i);
7814 : 0 : key_dw[i] = i40e_read_rx_ctl(hw, reg);
7815 : : }
7816 : 0 : *key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
7817 : : sizeof(uint32_t);
7818 : : }
7819 : : }
7820 : : return 0;
7821 : : }
7822 : :
7823 : : static int
7824 : 0 : i40e_hw_rss_hash_set(struct i40e_pf *pf, struct rte_eth_rss_conf *rss_conf)
7825 : : {
7826 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7827 : : uint64_t hena;
7828 : : int ret;
7829 : :
7830 : 0 : ret = i40e_set_rss_key(pf->main_vsi, rss_conf->rss_key,
7831 : 0 : rss_conf->rss_key_len);
7832 [ # # ]: 0 : if (ret)
7833 : : return ret;
7834 : :
7835 : 0 : hena = i40e_config_hena(pf->adapter, rss_conf->rss_hf);
7836 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
7837 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
7838 : 0 : I40E_WRITE_FLUSH(hw);
7839 : :
7840 : 0 : return 0;
7841 : : }
7842 : :
7843 : : static int
7844 : 0 : i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
7845 : : struct rte_eth_rss_conf *rss_conf)
7846 : : {
7847 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7848 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7849 : 0 : uint64_t rss_hf = rss_conf->rss_hf & pf->adapter->flow_types_mask;
7850 : : uint64_t hena;
7851 : :
7852 : 0 : hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
7853 : 0 : hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
7854 : :
7855 [ # # ]: 0 : if (!(hena & pf->adapter->pctypes_mask)) { /* RSS disabled */
7856 [ # # ]: 0 : if (rss_hf != 0) /* Enable RSS */
7857 : : return -EINVAL;
7858 : 0 : return 0; /* Nothing to do */
7859 : : }
7860 : : /* RSS enabled */
7861 [ # # ]: 0 : if (rss_hf == 0) /* Disable RSS */
7862 : : return -EINVAL;
7863 : :
7864 : 0 : return i40e_hw_rss_hash_set(pf, rss_conf);
7865 : : }
7866 : :
7867 : : static int
7868 : 0 : i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
7869 : : struct rte_eth_rss_conf *rss_conf)
7870 : : {
7871 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7872 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7873 : : uint64_t hena;
7874 : : int ret;
7875 : :
7876 [ # # ]: 0 : if (!rss_conf)
7877 : : return -EINVAL;
7878 : :
7879 : 0 : ret = i40e_get_rss_key(pf->main_vsi, rss_conf->rss_key,
7880 : : &rss_conf->rss_key_len);
7881 [ # # ]: 0 : if (ret)
7882 : : return ret;
7883 : :
7884 : 0 : hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
7885 : 0 : hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
7886 : 0 : rss_conf->rss_hf = i40e_parse_hena(pf->adapter, hena);
7887 : :
7888 : 0 : return 0;
7889 : : }
7890 : :
7891 : : static int
7892 : 0 : i40e_dev_get_filter_type(uint16_t filter_type, uint16_t *flag)
7893 : : {
7894 [ # # # # : 0 : switch (filter_type) {
# # # # ]
7895 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC_IVLAN:
7896 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
7897 : 0 : break;
7898 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC_IVLAN_TENID:
7899 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
7900 : 0 : break;
7901 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC_TENID:
7902 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID;
7903 : 0 : break;
7904 : 0 : case RTE_ETH_TUNNEL_FILTER_OMAC_TENID_IMAC:
7905 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC;
7906 : 0 : break;
7907 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC:
7908 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
7909 : 0 : break;
7910 : 0 : case RTE_ETH_TUNNEL_FILTER_OIP:
7911 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_OIP;
7912 : 0 : break;
7913 : 0 : case RTE_ETH_TUNNEL_FILTER_IIP:
7914 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IIP;
7915 : 0 : break;
7916 : 0 : default:
7917 : 0 : PMD_DRV_LOG(ERR, "invalid tunnel filter type");
7918 : 0 : return -EINVAL;
7919 : : }
7920 : :
7921 : : return 0;
7922 : : }
7923 : :
7924 : : /* Convert tunnel filter structure */
7925 : : static int
7926 : : i40e_tunnel_filter_convert(
7927 : : struct i40e_aqc_cloud_filters_element_bb *cld_filter,
7928 : : struct i40e_tunnel_filter *tunnel_filter)
7929 : : {
7930 : : rte_ether_addr_copy((struct rte_ether_addr *)
7931 : : &cld_filter->element.outer_mac,
7932 : : (struct rte_ether_addr *)&tunnel_filter->input.outer_mac);
7933 : : rte_ether_addr_copy((struct rte_ether_addr *)
7934 : : &cld_filter->element.inner_mac,
7935 : : (struct rte_ether_addr *)&tunnel_filter->input.inner_mac);
7936 : 0 : tunnel_filter->input.inner_vlan = cld_filter->element.inner_vlan;
7937 [ # # ]: 0 : if ((rte_le_to_cpu_16(cld_filter->element.flags) &
7938 : : I40E_AQC_ADD_CLOUD_FLAGS_IPV6) ==
7939 : : I40E_AQC_ADD_CLOUD_FLAGS_IPV6)
7940 : 0 : tunnel_filter->input.ip_type = I40E_TUNNEL_IPTYPE_IPV6;
7941 : : else
7942 : : tunnel_filter->input.ip_type = I40E_TUNNEL_IPTYPE_IPV4;
7943 : 0 : tunnel_filter->input.flags = cld_filter->element.flags;
7944 : 0 : tunnel_filter->input.tenant_id = cld_filter->element.tenant_id;
7945 : 0 : tunnel_filter->queue = cld_filter->element.queue_number;
7946 : : rte_memcpy(tunnel_filter->input.general_fields,
7947 : : cld_filter->general_fields,
7948 : : sizeof(cld_filter->general_fields));
7949 : :
7950 : : return 0;
7951 : : }
7952 : :
7953 : : /* Check if there exists the tunnel filter */
7954 : : struct i40e_tunnel_filter *
7955 : 0 : i40e_sw_tunnel_filter_lookup(struct i40e_tunnel_rule *tunnel_rule,
7956 : : const struct i40e_tunnel_filter_input *input)
7957 : : {
7958 : : int ret;
7959 : :
7960 : 0 : ret = rte_hash_lookup(tunnel_rule->hash_table, (const void *)input);
7961 [ # # ]: 0 : if (ret < 0)
7962 : : return NULL;
7963 : :
7964 : 0 : return tunnel_rule->hash_map[ret];
7965 : : }
7966 : :
7967 : : /* Add a tunnel filter into the SW list */
7968 : : static int
7969 : 0 : i40e_sw_tunnel_filter_insert(struct i40e_pf *pf,
7970 : : struct i40e_tunnel_filter *tunnel_filter)
7971 : : {
7972 : : struct i40e_tunnel_rule *rule = &pf->tunnel;
7973 : : int ret;
7974 : :
7975 : 0 : ret = rte_hash_add_key(rule->hash_table, &tunnel_filter->input);
7976 [ # # ]: 0 : if (ret < 0) {
7977 : 0 : PMD_DRV_LOG(ERR,
7978 : : "Failed to insert tunnel filter to hash table %d!",
7979 : : ret);
7980 : 0 : return ret;
7981 : : }
7982 : 0 : rule->hash_map[ret] = tunnel_filter;
7983 : :
7984 : 0 : TAILQ_INSERT_TAIL(&rule->tunnel_list, tunnel_filter, rules);
7985 : :
7986 : 0 : return 0;
7987 : : }
7988 : :
7989 : : /* Delete a tunnel filter from the SW list */
7990 : : int
7991 : 0 : i40e_sw_tunnel_filter_del(struct i40e_pf *pf,
7992 : : struct i40e_tunnel_filter_input *input)
7993 : : {
7994 : : struct i40e_tunnel_rule *rule = &pf->tunnel;
7995 : : struct i40e_tunnel_filter *tunnel_filter;
7996 : : int ret;
7997 : :
7998 : 0 : ret = rte_hash_del_key(rule->hash_table, input);
7999 [ # # ]: 0 : if (ret < 0) {
8000 : 0 : PMD_DRV_LOG(ERR,
8001 : : "Failed to delete tunnel filter to hash table %d!",
8002 : : ret);
8003 : 0 : return ret;
8004 : : }
8005 : 0 : tunnel_filter = rule->hash_map[ret];
8006 : 0 : rule->hash_map[ret] = NULL;
8007 : :
8008 [ # # ]: 0 : TAILQ_REMOVE(&rule->tunnel_list, tunnel_filter, rules);
8009 : 0 : rte_free(tunnel_filter);
8010 : :
8011 : 0 : return 0;
8012 : : }
8013 : :
8014 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_TR_WORD0 0x48
8015 : : #define I40E_TR_VXLAN_GRE_KEY_MASK 0x4
8016 : : #define I40E_TR_GENEVE_KEY_MASK 0x8
8017 : : #define I40E_TR_GENERIC_UDP_TUNNEL_MASK 0x40
8018 : : #define I40E_TR_GRE_KEY_MASK 0x400
8019 : : #define I40E_TR_GRE_KEY_WITH_XSUM_MASK 0x800
8020 : : #define I40E_TR_GRE_NO_KEY_MASK 0x8000
8021 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_PORT_TR_WORD0 0x49
8022 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_DIRECTION_WORD0 0x41
8023 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_INGRESS_WORD0 0x80
8024 : : #define I40E_DIRECTION_INGRESS_KEY 0x8000
8025 : : #define I40E_TR_L4_TYPE_TCP 0x2
8026 : : #define I40E_TR_L4_TYPE_UDP 0x4
8027 : : #define I40E_TR_L4_TYPE_SCTP 0x8
8028 : :
8029 : : static enum
8030 : 0 : i40e_status_code i40e_replace_mpls_l1_filter(struct i40e_pf *pf)
8031 : : {
8032 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8033 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8034 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8035 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8036 : : enum i40e_status_code status = I40E_SUCCESS;
8037 : :
8038 [ # # ]: 0 : if (pf->support_multi_driver) {
8039 : 0 : PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
8040 : 0 : return I40E_NOT_SUPPORTED;
8041 : : }
8042 : :
8043 : : memset(&filter_replace, 0,
8044 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8045 : : memset(&filter_replace_buf, 0,
8046 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8047 : :
8048 : : /* create L1 filter */
8049 : 0 : filter_replace.old_filter_type =
8050 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_IMAC;
8051 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X11;
8052 : : filter_replace.tr_bit = 0;
8053 : :
8054 : : /* Prepare the buffer, 3 entries */
8055 : : filter_replace_buf.data[0] =
8056 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8057 : 0 : filter_replace_buf.data[0] |=
8058 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8059 : 0 : filter_replace_buf.data[2] = 0xFF;
8060 : 0 : filter_replace_buf.data[3] = 0xFF;
8061 : : filter_replace_buf.data[4] =
8062 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8063 : 0 : filter_replace_buf.data[4] |=
8064 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8065 : 0 : filter_replace_buf.data[7] = 0xF0;
8066 : : filter_replace_buf.data[8]
8067 : : = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_TR_WORD0;
8068 : 0 : filter_replace_buf.data[8] |=
8069 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8070 : 0 : filter_replace_buf.data[10] = I40E_TR_VXLAN_GRE_KEY_MASK |
8071 : : I40E_TR_GENEVE_KEY_MASK |
8072 : : I40E_TR_GENERIC_UDP_TUNNEL_MASK;
8073 : 0 : filter_replace_buf.data[11] = (I40E_TR_GRE_KEY_MASK |
8074 : : I40E_TR_GRE_KEY_WITH_XSUM_MASK |
8075 : : I40E_TR_GRE_NO_KEY_MASK) >> 8;
8076 : :
8077 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8078 : : &filter_replace_buf);
8079 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8080 [ # # ]: 0 : filter_replace.new_filter_type))
8081 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8082 : : " original: 0x%x, new: 0x%x",
8083 : : dev->device->name,
8084 : : filter_replace.old_filter_type,
8085 : : filter_replace.new_filter_type);
8086 : :
8087 : : return status;
8088 : : }
8089 : :
8090 : : static enum
8091 : 0 : i40e_status_code i40e_replace_mpls_cloud_filter(struct i40e_pf *pf)
8092 : : {
8093 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8094 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8095 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8096 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8097 : : enum i40e_status_code status = I40E_SUCCESS;
8098 : :
8099 [ # # ]: 0 : if (pf->support_multi_driver) {
8100 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8101 : 0 : return I40E_NOT_SUPPORTED;
8102 : : }
8103 : :
8104 : : /* For MPLSoUDP */
8105 : : memset(&filter_replace, 0,
8106 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8107 : : memset(&filter_replace_buf, 0,
8108 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8109 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER |
8110 : : I40E_AQC_MIRROR_CLOUD_FILTER;
8111 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IIP;
8112 : 0 : filter_replace.new_filter_type =
8113 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8114 : : /* Prepare the buffer, 2 entries */
8115 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8116 : 0 : filter_replace_buf.data[0] |=
8117 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8118 : : filter_replace_buf.data[4] = I40E_AQC_ADD_L1_FILTER_0X11;
8119 : 0 : filter_replace_buf.data[4] |=
8120 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8121 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8122 : : &filter_replace_buf);
8123 [ # # ]: 0 : if (status < 0)
8124 : : return status;
8125 : 0 : if (filter_replace.old_filter_type !=
8126 [ # # ]: 0 : filter_replace.new_filter_type)
8127 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8128 : : " original: 0x%x, new: 0x%x",
8129 : : dev->device->name,
8130 : : filter_replace.old_filter_type,
8131 : : filter_replace.new_filter_type);
8132 : :
8133 : : /* For MPLSoGRE */
8134 : : memset(&filter_replace, 0,
8135 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8136 : : memset(&filter_replace_buf, 0,
8137 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8138 : :
8139 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER |
8140 : : I40E_AQC_MIRROR_CLOUD_FILTER;
8141 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
8142 : 0 : filter_replace.new_filter_type =
8143 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8144 : : /* Prepare the buffer, 2 entries */
8145 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8146 : 0 : filter_replace_buf.data[0] |=
8147 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8148 : : filter_replace_buf.data[4] = I40E_AQC_ADD_L1_FILTER_0X11;
8149 : 0 : filter_replace_buf.data[4] |=
8150 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8151 : :
8152 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8153 : : &filter_replace_buf);
8154 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8155 [ # # ]: 0 : filter_replace.new_filter_type))
8156 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8157 : : " original: 0x%x, new: 0x%x",
8158 : : dev->device->name,
8159 : : filter_replace.old_filter_type,
8160 : : filter_replace.new_filter_type);
8161 : :
8162 : : return status;
8163 : : }
8164 : :
8165 : : static enum i40e_status_code
8166 : 0 : i40e_replace_gtp_l1_filter(struct i40e_pf *pf)
8167 : : {
8168 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8169 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8170 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8171 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8172 : : enum i40e_status_code status = I40E_SUCCESS;
8173 : :
8174 [ # # ]: 0 : if (pf->support_multi_driver) {
8175 : 0 : PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
8176 : 0 : return I40E_NOT_SUPPORTED;
8177 : : }
8178 : :
8179 : : /* For GTP-C */
8180 : : memset(&filter_replace, 0,
8181 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8182 : : memset(&filter_replace_buf, 0,
8183 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8184 : : /* create L1 filter */
8185 : 0 : filter_replace.old_filter_type =
8186 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_IMAC;
8187 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X12;
8188 : 0 : filter_replace.tr_bit = I40E_AQC_NEW_TR_22 |
8189 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8190 : : /* Prepare the buffer, 2 entries */
8191 : : filter_replace_buf.data[0] =
8192 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8193 : 0 : filter_replace_buf.data[0] |=
8194 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8195 : 0 : filter_replace_buf.data[2] = 0xFF;
8196 : 0 : filter_replace_buf.data[3] = 0xFF;
8197 : : filter_replace_buf.data[4] =
8198 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8199 : 0 : filter_replace_buf.data[4] |=
8200 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8201 : 0 : filter_replace_buf.data[6] = 0xFF;
8202 : 0 : filter_replace_buf.data[7] = 0xFF;
8203 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8204 : : &filter_replace_buf);
8205 [ # # ]: 0 : if (status < 0)
8206 : : return status;
8207 : 0 : if (filter_replace.old_filter_type !=
8208 [ # # ]: 0 : filter_replace.new_filter_type)
8209 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8210 : : " original: 0x%x, new: 0x%x",
8211 : : dev->device->name,
8212 : : filter_replace.old_filter_type,
8213 : : filter_replace.new_filter_type);
8214 : :
8215 : : /* for GTP-U */
8216 : : memset(&filter_replace, 0,
8217 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8218 : : memset(&filter_replace_buf, 0,
8219 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8220 : : /* create L1 filter */
8221 : 0 : filter_replace.old_filter_type =
8222 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TUNNLE_KEY;
8223 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X13;
8224 : 0 : filter_replace.tr_bit = I40E_AQC_NEW_TR_21 |
8225 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8226 : : /* Prepare the buffer, 2 entries */
8227 : : filter_replace_buf.data[0] =
8228 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8229 : 0 : filter_replace_buf.data[0] |=
8230 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8231 : 0 : filter_replace_buf.data[2] = 0xFF;
8232 : 0 : filter_replace_buf.data[3] = 0xFF;
8233 : : filter_replace_buf.data[4] =
8234 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8235 : 0 : filter_replace_buf.data[4] |=
8236 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8237 : 0 : filter_replace_buf.data[6] = 0xFF;
8238 : 0 : filter_replace_buf.data[7] = 0xFF;
8239 : :
8240 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8241 : : &filter_replace_buf);
8242 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8243 [ # # ]: 0 : filter_replace.new_filter_type))
8244 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8245 : : " original: 0x%x, new: 0x%x",
8246 : : dev->device->name,
8247 : : filter_replace.old_filter_type,
8248 : : filter_replace.new_filter_type);
8249 : :
8250 : : return status;
8251 : : }
8252 : :
8253 : : static enum
8254 : 0 : i40e_status_code i40e_replace_gtp_cloud_filter(struct i40e_pf *pf)
8255 : : {
8256 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8257 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8258 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8259 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8260 : : enum i40e_status_code status = I40E_SUCCESS;
8261 : :
8262 [ # # ]: 0 : if (pf->support_multi_driver) {
8263 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8264 : 0 : return I40E_NOT_SUPPORTED;
8265 : : }
8266 : :
8267 : : /* for GTP-C */
8268 : : memset(&filter_replace, 0,
8269 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8270 : : memset(&filter_replace_buf, 0,
8271 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8272 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8273 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
8274 : 0 : filter_replace.new_filter_type =
8275 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8276 : : /* Prepare the buffer, 2 entries */
8277 : : filter_replace_buf.data[0] = I40E_AQC_ADD_L1_FILTER_0X12;
8278 : 0 : filter_replace_buf.data[0] |=
8279 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8280 : : filter_replace_buf.data[4] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8281 : 0 : filter_replace_buf.data[4] |=
8282 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8283 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8284 : : &filter_replace_buf);
8285 [ # # ]: 0 : if (status < 0)
8286 : : return status;
8287 : 0 : if (filter_replace.old_filter_type !=
8288 [ # # ]: 0 : filter_replace.new_filter_type)
8289 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8290 : : " original: 0x%x, new: 0x%x",
8291 : : dev->device->name,
8292 : : filter_replace.old_filter_type,
8293 : : filter_replace.new_filter_type);
8294 : :
8295 : : /* for GTP-U */
8296 : : memset(&filter_replace, 0,
8297 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8298 : : memset(&filter_replace_buf, 0,
8299 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8300 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8301 : 0 : filter_replace.old_filter_type =
8302 : : I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
8303 : 0 : filter_replace.new_filter_type =
8304 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8305 : : /* Prepare the buffer, 2 entries */
8306 : : filter_replace_buf.data[0] = I40E_AQC_ADD_L1_FILTER_0X13;
8307 : 0 : filter_replace_buf.data[0] |=
8308 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8309 : : filter_replace_buf.data[4] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8310 : 0 : filter_replace_buf.data[4] |=
8311 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8312 : :
8313 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8314 : : &filter_replace_buf);
8315 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8316 [ # # ]: 0 : filter_replace.new_filter_type))
8317 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8318 : : " original: 0x%x, new: 0x%x",
8319 : : dev->device->name,
8320 : : filter_replace.old_filter_type,
8321 : : filter_replace.new_filter_type);
8322 : :
8323 : : return status;
8324 : : }
8325 : :
8326 : : static enum i40e_status_code
8327 : 0 : i40e_replace_port_l1_filter(struct i40e_pf *pf,
8328 : : enum i40e_l4_port_type l4_port_type)
8329 : : {
8330 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8331 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8332 : : enum i40e_status_code status = I40E_SUCCESS;
8333 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8334 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8335 : :
8336 [ # # ]: 0 : if (pf->support_multi_driver) {
8337 : 0 : PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
8338 : 0 : return I40E_NOT_SUPPORTED;
8339 : : }
8340 : :
8341 : : memset(&filter_replace, 0,
8342 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8343 : : memset(&filter_replace_buf, 0,
8344 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8345 : :
8346 : : /* create L1 filter */
8347 [ # # ]: 0 : if (l4_port_type == I40E_L4_PORT_TYPE_SRC) {
8348 : 0 : filter_replace.old_filter_type =
8349 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TUNNLE_KEY;
8350 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X11;
8351 : 0 : filter_replace_buf.data[8] =
8352 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_SRC_PORT;
8353 : : } else {
8354 : 0 : filter_replace.old_filter_type =
8355 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG_IVLAN;
8356 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X10;
8357 : 0 : filter_replace_buf.data[8] =
8358 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_DST_PORT;
8359 : : }
8360 : :
8361 : : filter_replace.tr_bit = 0;
8362 : : /* Prepare the buffer, 3 entries */
8363 : : filter_replace_buf.data[0] =
8364 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_DIRECTION_WORD0;
8365 : 0 : filter_replace_buf.data[0] |=
8366 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8367 : : filter_replace_buf.data[2] = 0x00;
8368 : 0 : filter_replace_buf.data[3] =
8369 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_INGRESS_WORD0;
8370 : : filter_replace_buf.data[4] =
8371 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_PORT_TR_WORD0;
8372 : 0 : filter_replace_buf.data[4] |=
8373 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8374 : : filter_replace_buf.data[5] = 0x00;
8375 : 0 : filter_replace_buf.data[6] = I40E_TR_L4_TYPE_UDP |
8376 : : I40E_TR_L4_TYPE_TCP |
8377 : : I40E_TR_L4_TYPE_SCTP;
8378 : : filter_replace_buf.data[7] = 0x00;
8379 : 0 : filter_replace_buf.data[8] |=
8380 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8381 : : filter_replace_buf.data[9] = 0x00;
8382 : 0 : filter_replace_buf.data[10] = 0xFF;
8383 : 0 : filter_replace_buf.data[11] = 0xFF;
8384 : :
8385 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8386 : : &filter_replace_buf);
8387 [ # # ]: 0 : if (!status && filter_replace.old_filter_type !=
8388 [ # # ]: 0 : filter_replace.new_filter_type)
8389 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8390 : : " original: 0x%x, new: 0x%x",
8391 : : dev->device->name,
8392 : : filter_replace.old_filter_type,
8393 : : filter_replace.new_filter_type);
8394 : :
8395 : : return status;
8396 : : }
8397 : :
8398 : : static enum i40e_status_code
8399 : 0 : i40e_replace_port_cloud_filter(struct i40e_pf *pf,
8400 : : enum i40e_l4_port_type l4_port_type)
8401 : : {
8402 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8403 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8404 : : enum i40e_status_code status = I40E_SUCCESS;
8405 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8406 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8407 : :
8408 [ # # ]: 0 : if (pf->support_multi_driver) {
8409 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8410 : 0 : return I40E_NOT_SUPPORTED;
8411 : : }
8412 : :
8413 : : memset(&filter_replace, 0,
8414 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8415 : : memset(&filter_replace_buf, 0,
8416 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8417 : :
8418 [ # # ]: 0 : if (l4_port_type == I40E_L4_PORT_TYPE_SRC) {
8419 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IIP;
8420 : 0 : filter_replace.new_filter_type =
8421 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8422 : 0 : filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X11;
8423 : : } else {
8424 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_OIP;
8425 : 0 : filter_replace.new_filter_type =
8426 : : I40E_AQC_ADD_CLOUD_FILTER_0X10;
8427 : 0 : filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X10;
8428 : : }
8429 : :
8430 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8431 : : filter_replace.tr_bit = 0;
8432 : : /* Prepare the buffer, 2 entries */
8433 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8434 : 0 : filter_replace_buf.data[0] |=
8435 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8436 : 0 : filter_replace_buf.data[4] |=
8437 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8438 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8439 : : &filter_replace_buf);
8440 : :
8441 [ # # ]: 0 : if (!status && filter_replace.old_filter_type !=
8442 [ # # ]: 0 : filter_replace.new_filter_type)
8443 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8444 : : " original: 0x%x, new: 0x%x",
8445 : : dev->device->name,
8446 : : filter_replace.old_filter_type,
8447 : : filter_replace.new_filter_type);
8448 : :
8449 : : return status;
8450 : : }
8451 : :
8452 : : int
8453 : 0 : i40e_dev_consistent_tunnel_filter_set(struct i40e_pf *pf,
8454 : : struct i40e_tunnel_filter_conf *tunnel_filter,
8455 : : uint8_t add)
8456 : : {
8457 : : uint16_t ip_type;
8458 : : uint32_t ipv4_addr, ipv4_addr_le;
8459 : : uint8_t i, tun_type = 0;
8460 : : /* internal variable to convert ipv6 byte order */
8461 : : uint32_t convert_ipv6[4];
8462 : : int val, ret = 0;
8463 : : struct i40e_pf_vf *vf = NULL;
8464 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8465 : : struct i40e_vsi *vsi;
8466 : 0 : struct i40e_aqc_cloud_filters_element_bb cld_filter = {0};
8467 [ # # ]: 0 : struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
8468 : : struct i40e_tunnel_filter *node;
8469 : : struct i40e_tunnel_filter check_filter; /* Check if filter exists */
8470 : : uint32_t teid_le;
8471 : : bool big_buffer = 0;
8472 : :
8473 : : rte_ether_addr_copy(&tunnel_filter->outer_mac,
8474 : : (struct rte_ether_addr *)&cld_filter.element.outer_mac);
8475 : : rte_ether_addr_copy(&tunnel_filter->inner_mac,
8476 : : (struct rte_ether_addr *)&cld_filter.element.inner_mac);
8477 : :
8478 : 0 : cld_filter.element.inner_vlan =
8479 : 0 : rte_cpu_to_le_16(tunnel_filter->inner_vlan);
8480 [ # # ]: 0 : if (tunnel_filter->ip_type == I40E_TUNNEL_IPTYPE_IPV4) {
8481 : : ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV4;
8482 [ # # ]: 0 : ipv4_addr = rte_be_to_cpu_32(tunnel_filter->ip_addr.ipv4_addr);
8483 : 0 : ipv4_addr_le = rte_cpu_to_le_32(ipv4_addr);
8484 : : rte_memcpy(&cld_filter.element.ipaddr.v4.data,
8485 : : &ipv4_addr_le,
8486 : : sizeof(cld_filter.element.ipaddr.v4.data));
8487 : : } else {
8488 : : ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV6;
8489 [ # # ]: 0 : for (i = 0; i < 4; i++) {
8490 : 0 : convert_ipv6[i] =
8491 [ # # ]: 0 : rte_cpu_to_le_32(rte_be_to_cpu_32(
8492 : : tunnel_filter->ip_addr.ipv6_addr[i]));
8493 : : }
8494 : : rte_memcpy(&cld_filter.element.ipaddr.v6.data,
8495 : : &convert_ipv6,
8496 : : sizeof(cld_filter.element.ipaddr.v6.data));
8497 : : }
8498 : :
8499 : : /* check tunneled type */
8500 [ # # # # : 0 : switch (tunnel_filter->tunnel_type) {
# # # # #
# ]
8501 : : case I40E_TUNNEL_TYPE_VXLAN:
8502 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_VXLAN;
8503 : : break;
8504 : 0 : case I40E_TUNNEL_TYPE_NVGRE:
8505 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_NVGRE_OMAC;
8506 : 0 : break;
8507 : 0 : case I40E_TUNNEL_TYPE_IP_IN_GRE:
8508 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_IP;
8509 : 0 : break;
8510 : 0 : case I40E_TUNNEL_TYPE_MPLSoUDP:
8511 [ # # ]: 0 : if (!pf->mpls_replace_flag) {
8512 : 0 : i40e_replace_mpls_l1_filter(pf);
8513 : 0 : i40e_replace_mpls_cloud_filter(pf);
8514 : 0 : pf->mpls_replace_flag = 1;
8515 : : }
8516 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8517 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8518 : 0 : teid_le >> 4;
8519 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8520 : 0 : (teid_le & 0xF) << 12;
8521 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8522 : : 0x40;
8523 : : big_buffer = 1;
8524 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_MPLSOUDP;
8525 : 0 : break;
8526 : 0 : case I40E_TUNNEL_TYPE_MPLSoGRE:
8527 [ # # ]: 0 : if (!pf->mpls_replace_flag) {
8528 : 0 : i40e_replace_mpls_l1_filter(pf);
8529 : 0 : i40e_replace_mpls_cloud_filter(pf);
8530 : 0 : pf->mpls_replace_flag = 1;
8531 : : }
8532 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8533 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8534 : 0 : teid_le >> 4;
8535 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8536 : 0 : (teid_le & 0xF) << 12;
8537 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8538 : : 0x0;
8539 : : big_buffer = 1;
8540 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_MPLSOGRE;
8541 : 0 : break;
8542 : 0 : case I40E_TUNNEL_TYPE_GTPC:
8543 [ # # ]: 0 : if (!pf->gtp_replace_flag) {
8544 : 0 : i40e_replace_gtp_l1_filter(pf);
8545 : 0 : i40e_replace_gtp_cloud_filter(pf);
8546 : 0 : pf->gtp_replace_flag = 1;
8547 : : }
8548 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8549 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD0] =
8550 : 0 : (teid_le >> 16) & 0xFFFF;
8551 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD1] =
8552 : : teid_le & 0xFFFF;
8553 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD2] =
8554 : : 0x0;
8555 : : big_buffer = 1;
8556 : 0 : break;
8557 : 0 : case I40E_TUNNEL_TYPE_GTPU:
8558 [ # # ]: 0 : if (!pf->gtp_replace_flag) {
8559 : 0 : i40e_replace_gtp_l1_filter(pf);
8560 : 0 : i40e_replace_gtp_cloud_filter(pf);
8561 : 0 : pf->gtp_replace_flag = 1;
8562 : : }
8563 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8564 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD0] =
8565 : 0 : (teid_le >> 16) & 0xFFFF;
8566 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD1] =
8567 : : teid_le & 0xFFFF;
8568 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD2] =
8569 : : 0x0;
8570 : : big_buffer = 1;
8571 : 0 : break;
8572 : 0 : case I40E_TUNNEL_TYPE_QINQ:
8573 [ # # ]: 0 : if (!pf->qinq_replace_flag) {
8574 : 0 : ret = i40e_cloud_filter_qinq_create(pf);
8575 [ # # ]: 0 : if (ret < 0)
8576 : 0 : PMD_DRV_LOG(DEBUG,
8577 : : "QinQ tunnel filter already created.");
8578 : 0 : pf->qinq_replace_flag = 1;
8579 : : }
8580 : : /* Add in the General fields the values of
8581 : : * the Outer and Inner VLAN
8582 : : * Big Buffer should be set, see changes in
8583 : : * i40e_aq_add_cloud_filters
8584 : : */
8585 : 0 : cld_filter.general_fields[0] = tunnel_filter->inner_vlan;
8586 : 0 : cld_filter.general_fields[1] = tunnel_filter->outer_vlan;
8587 : : big_buffer = 1;
8588 : 0 : break;
8589 : 0 : case I40E_CLOUD_TYPE_UDP:
8590 : : case I40E_CLOUD_TYPE_TCP:
8591 : : case I40E_CLOUD_TYPE_SCTP:
8592 [ # # ]: 0 : if (tunnel_filter->l4_port_type == I40E_L4_PORT_TYPE_SRC) {
8593 [ # # ]: 0 : if (!pf->sport_replace_flag) {
8594 : 0 : i40e_replace_port_l1_filter(pf,
8595 : : tunnel_filter->l4_port_type);
8596 : 0 : i40e_replace_port_cloud_filter(pf,
8597 : : tunnel_filter->l4_port_type);
8598 : 0 : pf->sport_replace_flag = 1;
8599 : : }
8600 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8601 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8602 : : I40E_DIRECTION_INGRESS_KEY;
8603 : :
8604 [ # # ]: 0 : if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_UDP)
8605 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8606 : : I40E_TR_L4_TYPE_UDP;
8607 [ # # ]: 0 : else if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_TCP)
8608 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8609 : : I40E_TR_L4_TYPE_TCP;
8610 : : else
8611 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8612 : : I40E_TR_L4_TYPE_SCTP;
8613 : :
8614 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8615 : 0 : (teid_le >> 16) & 0xFFFF;
8616 : : big_buffer = 1;
8617 : : } else {
8618 [ # # ]: 0 : if (!pf->dport_replace_flag) {
8619 : 0 : i40e_replace_port_l1_filter(pf,
8620 : : tunnel_filter->l4_port_type);
8621 : 0 : i40e_replace_port_cloud_filter(pf,
8622 : : tunnel_filter->l4_port_type);
8623 : 0 : pf->dport_replace_flag = 1;
8624 : : }
8625 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8626 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD0] =
8627 : : I40E_DIRECTION_INGRESS_KEY;
8628 : :
8629 [ # # ]: 0 : if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_UDP)
8630 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD1] =
8631 : : I40E_TR_L4_TYPE_UDP;
8632 [ # # ]: 0 : else if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_TCP)
8633 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD1] =
8634 : : I40E_TR_L4_TYPE_TCP;
8635 : : else
8636 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD1] =
8637 : : I40E_TR_L4_TYPE_SCTP;
8638 : :
8639 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD2] =
8640 : 0 : (teid_le >> 16) & 0xFFFF;
8641 : : big_buffer = 1;
8642 : : }
8643 : :
8644 : : break;
8645 : 0 : default:
8646 : : /* Other tunnel types is not supported. */
8647 : 0 : PMD_DRV_LOG(ERR, "tunnel type is not supported.");
8648 : 0 : return -EINVAL;
8649 : : }
8650 : :
8651 [ # # ]: 0 : if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_MPLSoUDP)
8652 : 0 : cld_filter.element.flags =
8653 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8654 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_MPLSoGRE)
8655 : 0 : cld_filter.element.flags =
8656 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8657 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_GTPC)
8658 : 0 : cld_filter.element.flags =
8659 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8660 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_GTPU)
8661 : 0 : cld_filter.element.flags =
8662 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8663 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_QINQ)
8664 : 0 : cld_filter.element.flags |=
8665 : : I40E_AQC_ADD_CLOUD_FILTER_0X10;
8666 : : else if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_UDP ||
8667 : : tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_TCP ||
8668 : : tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_SCTP) {
8669 [ # # ]: 0 : if (tunnel_filter->l4_port_type == I40E_L4_PORT_TYPE_SRC)
8670 : 0 : cld_filter.element.flags |=
8671 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8672 : : else
8673 : 0 : cld_filter.element.flags |=
8674 : : I40E_AQC_ADD_CLOUD_FILTER_0X10;
8675 : : } else {
8676 : 0 : val = i40e_dev_get_filter_type(tunnel_filter->filter_type,
8677 : : &cld_filter.element.flags);
8678 [ # # ]: 0 : if (val < 0) {
8679 : : return -EINVAL;
8680 : : }
8681 : : }
8682 : :
8683 : 0 : cld_filter.element.flags |=
8684 : 0 : rte_cpu_to_le_16(I40E_AQC_ADD_CLOUD_FLAGS_TO_QUEUE | ip_type |
8685 : : (tun_type << I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT));
8686 : 0 : cld_filter.element.tenant_id = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8687 : 0 : cld_filter.element.queue_number =
8688 : 0 : rte_cpu_to_le_16(tunnel_filter->queue_id);
8689 : :
8690 [ # # ]: 0 : if (!tunnel_filter->is_to_vf)
8691 : 0 : vsi = pf->main_vsi;
8692 : : else {
8693 [ # # ]: 0 : if (tunnel_filter->vf_id >= pf->vf_num) {
8694 : 0 : PMD_DRV_LOG(ERR, "Invalid argument.");
8695 : 0 : return -EINVAL;
8696 : : }
8697 : 0 : vf = &pf->vfs[tunnel_filter->vf_id];
8698 : 0 : vsi = vf->vsi;
8699 : : }
8700 : :
8701 : : /* Check if there is the filter in SW list */
8702 : : memset(&check_filter, 0, sizeof(check_filter));
8703 : : i40e_tunnel_filter_convert(&cld_filter, &check_filter);
8704 : 0 : check_filter.is_to_vf = tunnel_filter->is_to_vf;
8705 : 0 : check_filter.vf_id = tunnel_filter->vf_id;
8706 : 0 : node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
8707 [ # # ]: 0 : if (add && node) {
8708 : 0 : PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
8709 : 0 : return -EINVAL;
8710 : : }
8711 : :
8712 [ # # ]: 0 : if (!add && !node) {
8713 : 0 : PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
8714 : 0 : return -EINVAL;
8715 : : }
8716 : :
8717 [ # # ]: 0 : if (add) {
8718 : : struct i40e_tunnel_filter *tunnel;
8719 : :
8720 [ # # ]: 0 : if (big_buffer)
8721 : 0 : ret = i40e_aq_add_cloud_filters_bb(hw,
8722 : 0 : vsi->seid, &cld_filter, 1);
8723 : : else
8724 : 0 : ret = i40e_aq_add_cloud_filters(hw,
8725 : 0 : vsi->seid, &cld_filter.element, 1);
8726 [ # # ]: 0 : if (ret < 0) {
8727 : 0 : PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
8728 : 0 : return -ENOTSUP;
8729 : : }
8730 : 0 : tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
8731 [ # # ]: 0 : if (tunnel == NULL) {
8732 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory.");
8733 : 0 : return -ENOMEM;
8734 : : }
8735 : :
8736 : : rte_memcpy(tunnel, &check_filter, sizeof(check_filter));
8737 : 0 : ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
8738 [ # # ]: 0 : if (ret < 0)
8739 : 0 : rte_free(tunnel);
8740 : : } else {
8741 [ # # ]: 0 : if (big_buffer)
8742 : 0 : ret = i40e_aq_rem_cloud_filters_bb(
8743 : 0 : hw, vsi->seid, &cld_filter, 1);
8744 : : else
8745 : 0 : ret = i40e_aq_rem_cloud_filters(hw, vsi->seid,
8746 : : &cld_filter.element, 1);
8747 [ # # ]: 0 : if (ret < 0) {
8748 : 0 : PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
8749 : 0 : return -ENOTSUP;
8750 : : }
8751 : 0 : ret = i40e_sw_tunnel_filter_del(pf, &node->input);
8752 : : }
8753 : :
8754 : : return ret;
8755 : : }
8756 : :
8757 : : static int
8758 : : i40e_get_vxlan_port_idx(struct i40e_pf *pf, uint16_t port)
8759 : : {
8760 : : uint8_t i;
8761 : :
8762 [ # # # # : 0 : for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
# # ]
8763 [ # # # # : 0 : if (pf->vxlan_ports[i] == port)
# # ]
8764 : : return i;
8765 : : }
8766 : :
8767 : : return -1;
8768 : : }
8769 : :
8770 : : static int
8771 : 0 : i40e_add_vxlan_port(struct i40e_pf *pf, uint16_t port, int udp_type)
8772 : : {
8773 : : int idx, ret;
8774 : 0 : uint8_t filter_idx = 0;
8775 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8776 : :
8777 : 0 : idx = i40e_get_vxlan_port_idx(pf, port);
8778 : :
8779 : : /* Check if port already exists */
8780 [ # # ]: 0 : if (idx >= 0) {
8781 : 0 : PMD_DRV_LOG(ERR, "Port %d already offloaded", port);
8782 : 0 : return -EINVAL;
8783 : : }
8784 : :
8785 : : /* Now check if there is space to add the new port */
8786 : : idx = i40e_get_vxlan_port_idx(pf, 0);
8787 [ # # ]: 0 : if (idx < 0) {
8788 : 0 : PMD_DRV_LOG(ERR,
8789 : : "Maximum number of UDP ports reached, not adding port %d",
8790 : : port);
8791 : 0 : return -ENOSPC;
8792 : : }
8793 : :
8794 : 0 : ret = i40e_aq_add_udp_tunnel(hw, port, udp_type,
8795 : : &filter_idx, NULL);
8796 [ # # ]: 0 : if (ret < 0) {
8797 : 0 : PMD_DRV_LOG(ERR, "Failed to add VXLAN UDP port %d", port);
8798 : 0 : return -1;
8799 : : }
8800 : :
8801 : 0 : PMD_DRV_LOG(INFO, "Added port %d with AQ command with index %d",
8802 : : port, filter_idx);
8803 : :
8804 : : /* New port: add it and mark its index in the bitmap */
8805 : 0 : pf->vxlan_ports[idx] = port;
8806 : 0 : pf->vxlan_bitmap |= (1 << idx);
8807 : :
8808 [ # # ]: 0 : if (!(pf->flags & I40E_FLAG_VXLAN))
8809 : 0 : pf->flags |= I40E_FLAG_VXLAN;
8810 : :
8811 : : return 0;
8812 : : }
8813 : :
8814 : : static int
8815 : 0 : i40e_del_vxlan_port(struct i40e_pf *pf, uint16_t port)
8816 : : {
8817 : : int idx;
8818 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8819 : :
8820 [ # # ]: 0 : if (!(pf->flags & I40E_FLAG_VXLAN)) {
8821 : 0 : PMD_DRV_LOG(ERR, "VXLAN UDP port was not configured.");
8822 : 0 : return -EINVAL;
8823 : : }
8824 : :
8825 : 0 : idx = i40e_get_vxlan_port_idx(pf, port);
8826 : :
8827 [ # # ]: 0 : if (idx < 0) {
8828 : 0 : PMD_DRV_LOG(ERR, "Port %d doesn't exist", port);
8829 : 0 : return -EINVAL;
8830 : : }
8831 : :
8832 [ # # ]: 0 : if (i40e_aq_del_udp_tunnel(hw, idx, NULL) < 0) {
8833 : 0 : PMD_DRV_LOG(ERR, "Failed to delete VXLAN UDP port %d", port);
8834 : 0 : return -1;
8835 : : }
8836 : :
8837 : 0 : PMD_DRV_LOG(INFO, "Deleted port %d with AQ command with index %d",
8838 : : port, idx);
8839 : :
8840 : 0 : pf->vxlan_ports[idx] = 0;
8841 : 0 : pf->vxlan_bitmap &= ~(1 << idx);
8842 : :
8843 [ # # ]: 0 : if (!pf->vxlan_bitmap)
8844 : 0 : pf->flags &= ~I40E_FLAG_VXLAN;
8845 : :
8846 : : return 0;
8847 : : }
8848 : :
8849 : : /* Add UDP tunneling port */
8850 : : static int
8851 : 0 : i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
8852 : : struct rte_eth_udp_tunnel *udp_tunnel)
8853 : : {
8854 : : int ret = 0;
8855 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8856 : :
8857 [ # # ]: 0 : if (udp_tunnel == NULL)
8858 : : return -EINVAL;
8859 : :
8860 [ # # # # ]: 0 : switch (udp_tunnel->prot_type) {
8861 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN:
8862 : 0 : ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port,
8863 : : I40E_AQC_TUNNEL_TYPE_VXLAN);
8864 : 0 : break;
8865 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN_GPE:
8866 : 0 : ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port,
8867 : : I40E_AQC_TUNNEL_TYPE_VXLAN_GPE);
8868 : 0 : break;
8869 : 0 : case RTE_ETH_TUNNEL_TYPE_GENEVE:
8870 : : case RTE_ETH_TUNNEL_TYPE_TEREDO:
8871 : 0 : PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8872 : : ret = -1;
8873 : 0 : break;
8874 : :
8875 : 0 : default:
8876 : 0 : PMD_DRV_LOG(ERR, "Invalid tunnel type");
8877 : : ret = -1;
8878 : 0 : break;
8879 : : }
8880 : :
8881 : : return ret;
8882 : : }
8883 : :
8884 : : /* Remove UDP tunneling port */
8885 : : static int
8886 : 0 : i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
8887 : : struct rte_eth_udp_tunnel *udp_tunnel)
8888 : : {
8889 : : int ret = 0;
8890 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8891 : :
8892 [ # # ]: 0 : if (udp_tunnel == NULL)
8893 : : return -EINVAL;
8894 : :
8895 [ # # # ]: 0 : switch (udp_tunnel->prot_type) {
8896 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN:
8897 : : case RTE_ETH_TUNNEL_TYPE_VXLAN_GPE:
8898 : 0 : ret = i40e_del_vxlan_port(pf, udp_tunnel->udp_port);
8899 : 0 : break;
8900 : 0 : case RTE_ETH_TUNNEL_TYPE_GENEVE:
8901 : : case RTE_ETH_TUNNEL_TYPE_TEREDO:
8902 : 0 : PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8903 : : ret = -1;
8904 : 0 : break;
8905 : 0 : default:
8906 : 0 : PMD_DRV_LOG(ERR, "Invalid tunnel type");
8907 : : ret = -1;
8908 : 0 : break;
8909 : : }
8910 : :
8911 : : return ret;
8912 : : }
8913 : :
8914 : : /* Calculate the maximum number of contiguous PF queues that are configured */
8915 : : uint16_t
8916 : 0 : i40e_pf_calc_configured_queues_num(struct i40e_pf *pf)
8917 : : {
8918 : 0 : struct rte_eth_dev_data *data = pf->dev_data;
8919 : : int i;
8920 : : uint16_t num;
8921 : : struct ci_rx_queue *rxq;
8922 : :
8923 : : num = 0;
8924 [ # # ]: 0 : for (i = 0; i < pf->lan_nb_qps; i++) {
8925 : 0 : rxq = data->rx_queues[i];
8926 [ # # # # ]: 0 : if (rxq && rxq->q_set)
8927 : 0 : num++;
8928 : : else
8929 : : break;
8930 : : }
8931 : :
8932 : 0 : return num;
8933 : : }
8934 : :
8935 : : /* Reset the global configure of hash function and input sets */
8936 : : static void
8937 : 0 : i40e_pf_global_rss_reset(struct i40e_pf *pf)
8938 : : {
8939 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8940 : : uint32_t reg, reg_val;
8941 : : int i;
8942 : :
8943 : : /* Reset global RSS function sets */
8944 : 0 : reg_val = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
8945 [ # # ]: 0 : if (!(reg_val & I40E_GLQF_CTL_HTOEP_MASK)) {
8946 : 0 : reg_val |= I40E_GLQF_CTL_HTOEP_MASK;
8947 : 0 : i40e_write_global_rx_ctl(hw, I40E_GLQF_CTL, reg_val);
8948 : : }
8949 : :
8950 [ # # ]: 0 : for (i = 0; i <= I40E_FILTER_PCTYPE_L2_PAYLOAD; i++) {
8951 : : uint64_t inset;
8952 : : int j, pctype;
8953 : :
8954 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
8955 : 0 : pctype = i40e_read_rx_ctl(hw, I40E_GLQF_FD_PCTYPES(i));
8956 : : else
8957 : : pctype = i;
8958 : :
8959 : : /* Reset pctype insets */
8960 : 0 : inset = i40e_get_default_input_set(i);
8961 [ # # ]: 0 : if (inset) {
8962 : 0 : pf->hash_input_set[pctype] = inset;
8963 : 0 : inset = i40e_translate_input_set_reg(hw->mac.type,
8964 : : inset);
8965 : :
8966 : 0 : reg = I40E_GLQF_HASH_INSET(0, pctype);
8967 : 0 : i40e_check_write_global_reg(hw, reg, (uint32_t)inset);
8968 : 0 : reg = I40E_GLQF_HASH_INSET(1, pctype);
8969 : 0 : i40e_check_write_global_reg(hw, reg,
8970 : 0 : (uint32_t)(inset >> 32));
8971 : :
8972 : : /* Clear unused mask registers of the pctype */
8973 [ # # ]: 0 : for (j = 0; j < I40E_INSET_MASK_NUM_REG; j++) {
8974 : 0 : reg = I40E_GLQF_HASH_MSK(j, pctype);
8975 : 0 : i40e_check_write_global_reg(hw, reg, 0);
8976 : : }
8977 : : }
8978 : :
8979 : : /* Reset pctype symmetric sets */
8980 : 0 : reg = I40E_GLQF_HSYM(pctype);
8981 : 0 : reg_val = i40e_read_rx_ctl(hw, reg);
8982 [ # # ]: 0 : if (reg_val & I40E_GLQF_HSYM_SYMH_ENA_MASK) {
8983 : 0 : reg_val &= ~I40E_GLQF_HSYM_SYMH_ENA_MASK;
8984 : 0 : i40e_write_global_rx_ctl(hw, reg, reg_val);
8985 : : }
8986 : : }
8987 : 0 : I40E_WRITE_FLUSH(hw);
8988 : 0 : }
8989 : :
8990 : : int
8991 : 0 : i40e_pf_reset_rss_reta(struct i40e_pf *pf)
8992 : : {
8993 : 0 : struct i40e_hw *hw = &pf->adapter->hw;
8994 : : uint8_t lut[RTE_ETH_RSS_RETA_SIZE_512];
8995 : : uint32_t i;
8996 : : uint16_t num;
8997 : :
8998 : : /* If both VMDQ and RSS enabled, not all of PF queues are
8999 : : * configured. It's necessary to calculate the actual PF
9000 : : * queues that are configured.
9001 : : */
9002 [ # # ]: 0 : if (pf->dev_data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG)
9003 : 0 : num = i40e_pf_calc_configured_queues_num(pf);
9004 : : else
9005 : 0 : num = pf->dev_data->nb_rx_queues;
9006 : :
9007 : 0 : num = RTE_MIN(num, I40E_MAX_Q_PER_TC);
9008 [ # # ]: 0 : if (num <= 0)
9009 : : return 0;
9010 : :
9011 [ # # ]: 0 : for (i = 0; i < hw->func_caps.rss_table_size; i++)
9012 : 0 : lut[i] = (uint8_t)(i % num);
9013 : :
9014 : 0 : return i40e_set_rss_lut(pf->main_vsi, lut, (uint16_t)i);
9015 : : }
9016 : :
9017 : : int
9018 : 0 : i40e_pf_reset_rss_key(struct i40e_pf *pf)
9019 : : {
9020 : : uint8_t key_buf[I40E_RSS_KEY_LEN];
9021 : : const uint8_t *rss_key;
9022 : :
9023 : : /* Reset key */
9024 : 0 : rss_key = pf->dev_data->dev_conf.rx_adv_conf.rss_conf.rss_key;
9025 [ # # # # ]: 0 : if (!rss_key || pf->dev_data->dev_conf.rx_adv_conf.rss_conf.rss_key_len < sizeof(key_buf))
9026 : : rss_key = i40e_rss_key_default;
9027 : :
9028 : : /*
9029 : : * adminq does not guarantee const-ness of RSS key once a command is sent down, so make a
9030 : : * local copy.
9031 : : */
9032 : : memcpy(&key_buf, rss_key, sizeof(key_buf));
9033 : :
9034 : 0 : return i40e_set_rss_key(pf->main_vsi, key_buf, sizeof(key_buf));
9035 : : }
9036 : :
9037 : : static int
9038 : 0 : i40e_pf_rss_reset(struct i40e_pf *pf)
9039 : : {
9040 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9041 : :
9042 : : int ret;
9043 : :
9044 : 0 : pf->hash_filter_enabled = 0;
9045 : 0 : i40e_pf_disable_rss(pf);
9046 : 0 : i40e_set_symmetric_hash_enable_per_port(hw, 0);
9047 : :
9048 [ # # ]: 0 : if (!pf->support_multi_driver)
9049 : 0 : i40e_pf_global_rss_reset(pf);
9050 : :
9051 : : /* Reset RETA table */
9052 [ # # ]: 0 : if (pf->adapter->rss_reta_updated == 0) {
9053 : 0 : ret = i40e_pf_reset_rss_reta(pf);
9054 [ # # ]: 0 : if (ret)
9055 : : return ret;
9056 : : }
9057 : :
9058 : 0 : return i40e_pf_reset_rss_key(pf);
9059 : : }
9060 : :
9061 : : /* Configure RSS */
9062 : : int
9063 : 0 : i40e_pf_config_rss(struct i40e_pf *pf)
9064 : : {
9065 : : struct i40e_hw *hw;
9066 : : enum rte_eth_rx_mq_mode mq_mode;
9067 : : uint64_t rss_hf, hena;
9068 : : int ret;
9069 : :
9070 : 0 : ret = i40e_pf_rss_reset(pf);
9071 [ # # ]: 0 : if (ret) {
9072 : 0 : PMD_DRV_LOG(ERR, "Reset RSS failed, RSS has been disabled");
9073 : 0 : return ret;
9074 : : }
9075 : :
9076 : 0 : rss_hf = pf->dev_data->dev_conf.rx_adv_conf.rss_conf.rss_hf;
9077 : 0 : mq_mode = pf->dev_data->dev_conf.rxmode.mq_mode;
9078 [ # # ]: 0 : if (!(rss_hf & pf->adapter->flow_types_mask) ||
9079 [ # # ]: 0 : !(mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
9080 : : return 0;
9081 : :
9082 : 0 : hw = I40E_PF_TO_HW(pf);
9083 : 0 : hena = i40e_config_hena(pf->adapter, rss_hf);
9084 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
9085 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
9086 : 0 : I40E_WRITE_FLUSH(hw);
9087 : :
9088 : 0 : return 0;
9089 : : }
9090 : :
9091 : : #define I40E_GL_PRS_FVBM_MSK_ENA 0x80000000
9092 : : #define I40E_GL_PRS_FVBM(_i) (0x00269760 + ((_i) * 4))
9093 : : int
9094 : 0 : i40e_dev_set_gre_key_len(struct i40e_hw *hw, uint8_t len)
9095 : : {
9096 : 0 : struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
9097 : : uint32_t val, reg;
9098 : : int ret = -EINVAL;
9099 : :
9100 [ # # ]: 0 : if (pf->support_multi_driver) {
9101 : 0 : PMD_DRV_LOG(ERR, "GRE key length configuration is unsupported");
9102 : 0 : return -ENOTSUP;
9103 : : }
9104 : :
9105 : 0 : val = I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2));
9106 : 0 : PMD_DRV_LOG(DEBUG, "Read original GL_PRS_FVBM with 0x%08x", val);
9107 : :
9108 [ # # ]: 0 : if (len == 3) {
9109 : 0 : reg = val | I40E_GL_PRS_FVBM_MSK_ENA;
9110 [ # # ]: 0 : } else if (len == 4) {
9111 : 0 : reg = val & ~I40E_GL_PRS_FVBM_MSK_ENA;
9112 : : } else {
9113 : 0 : PMD_DRV_LOG(ERR, "Unsupported GRE key length of %u", len);
9114 : 0 : return ret;
9115 : : }
9116 : :
9117 [ # # ]: 0 : if (reg != val) {
9118 : 0 : ret = i40e_aq_debug_write_global_register(hw,
9119 : : I40E_GL_PRS_FVBM(2),
9120 : : reg, NULL);
9121 [ # # ]: 0 : if (ret != 0)
9122 : : return ret;
9123 : 0 : PMD_DRV_LOG(DEBUG, "Global register 0x%08x is changed "
9124 : : "with value 0x%08x",
9125 : : I40E_GL_PRS_FVBM(2), reg);
9126 : : } else {
9127 : : ret = 0;
9128 : : }
9129 : 0 : PMD_DRV_LOG(DEBUG, "Read modified GL_PRS_FVBM with 0x%08x",
9130 : : I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2)));
9131 : :
9132 : 0 : return ret;
9133 : : }
9134 : :
9135 : : /* Set the symmetric hash enable configurations per port */
9136 : : void
9137 : 0 : i40e_set_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t enable)
9138 : : {
9139 : 0 : uint32_t reg = i40e_read_rx_ctl(hw, I40E_PRTQF_CTL_0);
9140 : :
9141 [ # # ]: 0 : if (enable > 0) {
9142 [ # # ]: 0 : if (reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK)
9143 : : return;
9144 : :
9145 : 0 : reg |= I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
9146 : : } else {
9147 [ # # ]: 0 : if (!(reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK))
9148 : : return;
9149 : :
9150 : 0 : reg &= ~I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
9151 : : }
9152 : 0 : i40e_write_rx_ctl(hw, I40E_PRTQF_CTL_0, reg);
9153 : 0 : I40E_WRITE_FLUSH(hw);
9154 : : }
9155 : :
9156 : : /**
9157 : : * Valid input sets for hash and flow director filters per PCTYPE
9158 : : */
9159 : : static uint64_t
9160 : : i40e_get_valid_input_set(enum i40e_filter_pctype pctype,
9161 : : enum rte_filter_type filter)
9162 : : {
9163 : : uint64_t valid;
9164 : :
9165 : : static const uint64_t valid_hash_inset_table[] = {
9166 : : [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9167 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9168 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9169 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_SRC |
9170 : : I40E_INSET_IPV4_DST | I40E_INSET_IPV4_TOS |
9171 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9172 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9173 : : I40E_INSET_FLEX_PAYLOAD,
9174 : : [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9175 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9176 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9177 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9178 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9179 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9180 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9181 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9182 : : I40E_INSET_FLEX_PAYLOAD,
9183 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9184 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9185 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9186 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9187 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9188 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9189 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9190 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9191 : : I40E_INSET_FLEX_PAYLOAD,
9192 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9193 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9194 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9195 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9196 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9197 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9198 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9199 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9200 : : I40E_INSET_FLEX_PAYLOAD,
9201 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9202 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9203 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9204 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9205 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9206 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9207 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9208 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9209 : : I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
9210 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9211 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9212 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9213 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9214 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9215 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9216 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9217 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9218 : : I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
9219 : : [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9220 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9221 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9222 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9223 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9224 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9225 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9226 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9227 : : I40E_INSET_SCTP_VT | I40E_INSET_FLEX_PAYLOAD,
9228 : : [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9229 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9230 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9231 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9232 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9233 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9234 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9235 : : I40E_INSET_FLEX_PAYLOAD,
9236 : : [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9237 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9238 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9239 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9240 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9241 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_TUNNEL_DMAC |
9242 : : I40E_INSET_TUNNEL_ID | I40E_INSET_IPV6_SRC |
9243 : : I40E_INSET_IPV6_DST | I40E_INSET_FLEX_PAYLOAD,
9244 : : [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9245 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9246 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9247 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9248 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9249 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9250 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9251 : : I40E_INSET_DST_PORT | I40E_INSET_FLEX_PAYLOAD,
9252 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9253 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9254 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9255 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9256 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9257 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9258 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9259 : : I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9260 : : I40E_INSET_FLEX_PAYLOAD,
9261 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9262 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9263 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9264 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9265 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9266 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9267 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9268 : : I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9269 : : I40E_INSET_FLEX_PAYLOAD,
9270 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9271 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9272 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9273 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9274 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9275 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9276 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9277 : : I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9278 : : I40E_INSET_FLEX_PAYLOAD,
9279 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9280 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9281 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9282 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9283 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9284 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9285 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9286 : : I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9287 : : I40E_INSET_FLEX_PAYLOAD,
9288 : : [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9289 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9290 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9291 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9292 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9293 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9294 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9295 : : I40E_INSET_DST_PORT | I40E_INSET_SCTP_VT |
9296 : : I40E_INSET_FLEX_PAYLOAD,
9297 : : [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9298 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9299 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9300 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9301 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9302 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9303 : : I40E_INSET_IPV6_DST | I40E_INSET_TUNNEL_ID |
9304 : : I40E_INSET_FLEX_PAYLOAD,
9305 : : [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9306 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9307 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9308 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_LAST_ETHER_TYPE |
9309 : : I40E_INSET_FLEX_PAYLOAD,
9310 : : };
9311 : :
9312 : : /**
9313 : : * Flow director supports only fields defined in
9314 : : * union rte_eth_fdir_flow.
9315 : : */
9316 : : static const uint64_t valid_fdir_inset_table[] = {
9317 : : [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9318 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9319 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9320 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9321 : : I40E_INSET_IPV4_TTL,
9322 : : [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9323 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9324 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9325 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9326 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9327 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9328 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9329 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9330 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9331 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9332 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9333 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9334 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9335 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9336 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9337 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9338 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9339 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9340 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9341 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9342 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9343 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9344 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9345 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9346 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9347 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9348 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9349 : : [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9350 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9351 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9352 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9353 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9354 : : I40E_INSET_SCTP_VT,
9355 : : [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9356 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9357 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9358 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9359 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9360 : : I40E_INSET_IPV4_TTL,
9361 : : [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9362 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9363 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9364 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
9365 : : I40E_INSET_IPV6_HOP_LIMIT,
9366 : : [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9367 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9368 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9369 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9370 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9371 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9372 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9373 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9374 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9375 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9376 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9377 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9378 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9379 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9380 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9381 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9382 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9383 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9384 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9385 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9386 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9387 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9388 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9389 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9390 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9391 : : [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9392 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9393 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9394 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9395 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9396 : : I40E_INSET_SCTP_VT,
9397 : : [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9398 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9399 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9400 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
9401 : : I40E_INSET_IPV6_HOP_LIMIT,
9402 : : [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9403 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9404 : : I40E_INSET_LAST_ETHER_TYPE,
9405 : : };
9406 : :
9407 : 0 : if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
9408 : : return 0;
9409 [ # # ]: 0 : if (filter == RTE_ETH_FILTER_HASH)
9410 : 0 : valid = valid_hash_inset_table[pctype];
9411 : : else
9412 : 0 : valid = valid_fdir_inset_table[pctype];
9413 : :
9414 : : return valid;
9415 : : }
9416 : :
9417 : : /**
9418 : : * Validate if the input set is allowed for a specific PCTYPE
9419 : : */
9420 : : int
9421 [ # # ]: 0 : i40e_validate_input_set(enum i40e_filter_pctype pctype,
9422 : : enum rte_filter_type filter, uint64_t inset)
9423 : : {
9424 : : uint64_t valid;
9425 : :
9426 : : valid = i40e_get_valid_input_set(pctype, filter);
9427 [ # # ]: 0 : if (inset & (~valid))
9428 : 0 : return -EINVAL;
9429 : :
9430 : : return 0;
9431 : : }
9432 : :
9433 : : /* default input set fields combination per pctype */
9434 : : uint64_t
9435 : 0 : i40e_get_default_input_set(uint16_t pctype)
9436 : : {
9437 : : static const uint64_t default_inset_table[] = {
9438 : : [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9439 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
9440 : : [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9441 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9442 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9443 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9444 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9445 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9446 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9447 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9448 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9449 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9450 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9451 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9452 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9453 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9454 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9455 : : [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9456 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9457 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9458 : : I40E_INSET_SCTP_VT,
9459 : : [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9460 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
9461 : : [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9462 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
9463 : : [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9464 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9465 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9466 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9467 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9468 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9469 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9470 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9471 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9472 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9473 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9474 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9475 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9476 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9477 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9478 : : [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9479 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9480 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9481 : : I40E_INSET_SCTP_VT,
9482 : : [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9483 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
9484 : : [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9485 : : I40E_INSET_LAST_ETHER_TYPE,
9486 : : };
9487 : :
9488 [ # # ]: 0 : if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
9489 : : return 0;
9490 : :
9491 : 0 : return default_inset_table[pctype];
9492 : : }
9493 : :
9494 : : /**
9495 : : * Translate the input set from bit masks to register aware bit masks
9496 : : * and vice versa
9497 : : */
9498 : : uint64_t
9499 : 0 : i40e_translate_input_set_reg(enum i40e_mac_type type, uint64_t input)
9500 : : {
9501 : : uint64_t val = 0;
9502 : : uint16_t i;
9503 : :
9504 : : struct inset_map {
9505 : : uint64_t inset;
9506 : : uint64_t inset_reg;
9507 : : };
9508 : :
9509 : : static const struct inset_map inset_map_common[] = {
9510 : : {I40E_INSET_DMAC, I40E_REG_INSET_L2_DMAC},
9511 : : {I40E_INSET_SMAC, I40E_REG_INSET_L2_SMAC},
9512 : : {I40E_INSET_VLAN_OUTER, I40E_REG_INSET_L2_OUTER_VLAN},
9513 : : {I40E_INSET_VLAN_INNER, I40E_REG_INSET_L2_INNER_VLAN},
9514 : : {I40E_INSET_LAST_ETHER_TYPE, I40E_REG_INSET_LAST_ETHER_TYPE},
9515 : : {I40E_INSET_IPV4_TOS, I40E_REG_INSET_L3_IP4_TOS},
9516 : : {I40E_INSET_IPV6_SRC, I40E_REG_INSET_L3_SRC_IP6},
9517 : : {I40E_INSET_IPV6_DST, I40E_REG_INSET_L3_DST_IP6},
9518 : : {I40E_INSET_IPV6_TC, I40E_REG_INSET_L3_IP6_TC},
9519 : : {I40E_INSET_IPV6_NEXT_HDR, I40E_REG_INSET_L3_IP6_NEXT_HDR},
9520 : : {I40E_INSET_IPV6_HOP_LIMIT, I40E_REG_INSET_L3_IP6_HOP_LIMIT},
9521 : : {I40E_INSET_SRC_PORT, I40E_REG_INSET_L4_SRC_PORT},
9522 : : {I40E_INSET_DST_PORT, I40E_REG_INSET_L4_DST_PORT},
9523 : : {I40E_INSET_SCTP_VT, I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG},
9524 : : {I40E_INSET_TUNNEL_ID, I40E_REG_INSET_TUNNEL_ID},
9525 : : {I40E_INSET_TUNNEL_DMAC,
9526 : : I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC},
9527 : : {I40E_INSET_TUNNEL_IPV4_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP4},
9528 : : {I40E_INSET_TUNNEL_IPV6_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP6},
9529 : : {I40E_INSET_TUNNEL_SRC_PORT,
9530 : : I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT},
9531 : : {I40E_INSET_TUNNEL_DST_PORT,
9532 : : I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT},
9533 : : {I40E_INSET_VLAN_TUNNEL, I40E_REG_INSET_TUNNEL_VLAN},
9534 : : {I40E_INSET_FLEX_PAYLOAD_W1, I40E_REG_INSET_FLEX_PAYLOAD_WORD1},
9535 : : {I40E_INSET_FLEX_PAYLOAD_W2, I40E_REG_INSET_FLEX_PAYLOAD_WORD2},
9536 : : {I40E_INSET_FLEX_PAYLOAD_W3, I40E_REG_INSET_FLEX_PAYLOAD_WORD3},
9537 : : {I40E_INSET_FLEX_PAYLOAD_W4, I40E_REG_INSET_FLEX_PAYLOAD_WORD4},
9538 : : {I40E_INSET_FLEX_PAYLOAD_W5, I40E_REG_INSET_FLEX_PAYLOAD_WORD5},
9539 : : {I40E_INSET_FLEX_PAYLOAD_W6, I40E_REG_INSET_FLEX_PAYLOAD_WORD6},
9540 : : {I40E_INSET_FLEX_PAYLOAD_W7, I40E_REG_INSET_FLEX_PAYLOAD_WORD7},
9541 : : {I40E_INSET_FLEX_PAYLOAD_W8, I40E_REG_INSET_FLEX_PAYLOAD_WORD8},
9542 : : };
9543 : :
9544 : : /* some different registers map in x722*/
9545 : : static const struct inset_map inset_map_diff_x722[] = {
9546 : : {I40E_INSET_IPV4_SRC, I40E_X722_REG_INSET_L3_SRC_IP4},
9547 : : {I40E_INSET_IPV4_DST, I40E_X722_REG_INSET_L3_DST_IP4},
9548 : : {I40E_INSET_IPV4_PROTO, I40E_X722_REG_INSET_L3_IP4_PROTO},
9549 : : {I40E_INSET_IPV4_TTL, I40E_X722_REG_INSET_L3_IP4_TTL},
9550 : : };
9551 : :
9552 : : static const struct inset_map inset_map_diff_not_x722[] = {
9553 : : {I40E_INSET_IPV4_SRC, I40E_REG_INSET_L3_SRC_IP4},
9554 : : {I40E_INSET_IPV4_DST, I40E_REG_INSET_L3_DST_IP4},
9555 : : {I40E_INSET_IPV4_PROTO, I40E_REG_INSET_L3_IP4_PROTO},
9556 : : {I40E_INSET_IPV4_TTL, I40E_REG_INSET_L3_IP4_TTL},
9557 : : };
9558 : :
9559 [ # # ]: 0 : if (input == 0)
9560 : : return val;
9561 : :
9562 : : /* Translate input set to register aware inset */
9563 [ # # ]: 0 : if (type == I40E_MAC_X722) {
9564 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_map_diff_x722); i++) {
9565 [ # # ]: 0 : if (input & inset_map_diff_x722[i].inset)
9566 : 0 : val |= inset_map_diff_x722[i].inset_reg;
9567 : : }
9568 : : } else {
9569 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_map_diff_not_x722); i++) {
9570 [ # # ]: 0 : if (input & inset_map_diff_not_x722[i].inset)
9571 : 0 : val |= inset_map_diff_not_x722[i].inset_reg;
9572 : : }
9573 : : }
9574 : :
9575 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_map_common); i++) {
9576 [ # # ]: 0 : if (input & inset_map_common[i].inset)
9577 : 0 : val |= inset_map_common[i].inset_reg;
9578 : : }
9579 : :
9580 : : return val;
9581 : : }
9582 : :
9583 : : static int
9584 : 0 : i40e_get_inset_field_offset(struct i40e_hw *hw, uint32_t pit_reg_start,
9585 : : uint32_t pit_reg_count, uint32_t hdr_off)
9586 : : {
9587 : 0 : const uint32_t pit_reg_end = pit_reg_start + pit_reg_count;
9588 : 0 : uint32_t field_off = I40E_FDIR_FIELD_OFFSET(hdr_off);
9589 : : uint32_t i, reg_val, src_off, count;
9590 : :
9591 [ # # ]: 0 : for (i = pit_reg_start; i < pit_reg_end; i++) {
9592 : 0 : reg_val = i40e_read_rx_ctl(hw, I40E_GLQF_PIT(i));
9593 : :
9594 : 0 : src_off = I40E_GLQF_PIT_SOURCE_OFF_GET(reg_val);
9595 : 0 : count = I40E_GLQF_PIT_FSIZE_GET(reg_val);
9596 : :
9597 [ # # # # ]: 0 : if (src_off <= field_off && (src_off + count) > field_off)
9598 : : break;
9599 : : }
9600 : :
9601 [ # # ]: 0 : if (i >= pit_reg_end) {
9602 : 0 : PMD_DRV_LOG(ERR,
9603 : : "Hardware GLQF_PIT configuration does not support this field mask");
9604 : 0 : return -1;
9605 : : }
9606 : :
9607 : 0 : return I40E_GLQF_PIT_DEST_OFF_GET(reg_val) + field_off - src_off;
9608 : : }
9609 : :
9610 : : int
9611 : 0 : i40e_generate_inset_mask_reg(struct i40e_hw *hw, uint64_t inset,
9612 : : uint32_t *mask, uint8_t nb_elem)
9613 : : {
9614 : : static const uint64_t mask_inset[] = {
9615 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL,
9616 : : I40E_INSET_IPV6_NEXT_HDR | I40E_INSET_IPV6_HOP_LIMIT };
9617 : :
9618 : : static const struct {
9619 : : uint64_t inset;
9620 : : uint32_t mask;
9621 : : uint32_t offset;
9622 : : } inset_mask_offset_map[] = {
9623 : : { I40E_INSET_IPV4_TOS, I40E_INSET_IPV4_TOS_MASK,
9624 : : offsetof(struct rte_ipv4_hdr, type_of_service) },
9625 : :
9626 : : { I40E_INSET_IPV4_PROTO, I40E_INSET_IPV4_PROTO_MASK,
9627 : : offsetof(struct rte_ipv4_hdr, next_proto_id) },
9628 : :
9629 : : { I40E_INSET_IPV4_TTL, I40E_INSET_IPV4_TTL_MASK,
9630 : : offsetof(struct rte_ipv4_hdr, time_to_live) },
9631 : :
9632 : : { I40E_INSET_IPV6_TC, I40E_INSET_IPV6_TC_MASK,
9633 : : offsetof(struct rte_ipv6_hdr, vtc_flow) },
9634 : :
9635 : : { I40E_INSET_IPV6_NEXT_HDR, I40E_INSET_IPV6_NEXT_HDR_MASK,
9636 : : offsetof(struct rte_ipv6_hdr, proto) },
9637 : :
9638 : : { I40E_INSET_IPV6_HOP_LIMIT, I40E_INSET_IPV6_HOP_LIMIT_MASK,
9639 : : offsetof(struct rte_ipv6_hdr, hop_limits) },
9640 : : };
9641 : :
9642 : : uint32_t i;
9643 : : int idx = 0;
9644 : :
9645 [ # # ]: 0 : assert(mask);
9646 [ # # ]: 0 : if (!inset)
9647 : : return 0;
9648 : :
9649 [ # # ]: 0 : for (i = 0; i < RTE_DIM(mask_inset); i++) {
9650 : : /* Clear the inset bit, if no MASK is required,
9651 : : * for example proto + ttl
9652 : : */
9653 [ # # ]: 0 : if ((mask_inset[i] & inset) == mask_inset[i]) {
9654 : 0 : inset &= ~mask_inset[i];
9655 [ # # ]: 0 : if (!inset)
9656 : : return 0;
9657 : : }
9658 : : }
9659 : :
9660 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_mask_offset_map); i++) {
9661 : : uint32_t pit_start, pit_count;
9662 : : int offset;
9663 : :
9664 [ # # ]: 0 : if (!(inset_mask_offset_map[i].inset & inset))
9665 : 0 : continue;
9666 : :
9667 [ # # ]: 0 : if (inset_mask_offset_map[i].inset &
9668 : : (I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9669 : : I40E_INSET_IPV4_TTL)) {
9670 : : pit_start = I40E_GLQF_PIT_IPV4_START;
9671 : : pit_count = I40E_GLQF_PIT_IPV4_COUNT;
9672 : : } else {
9673 : : pit_start = I40E_GLQF_PIT_IPV6_START;
9674 : : pit_count = I40E_GLQF_PIT_IPV6_COUNT;
9675 : : }
9676 : :
9677 : 0 : offset = i40e_get_inset_field_offset(hw, pit_start, pit_count,
9678 : 0 : inset_mask_offset_map[i].offset);
9679 : :
9680 [ # # ]: 0 : if (offset < 0)
9681 : : return -EINVAL;
9682 : :
9683 [ # # ]: 0 : if (idx >= nb_elem) {
9684 : 0 : PMD_DRV_LOG(ERR,
9685 : : "Configuration of inset mask out of range %u",
9686 : : nb_elem);
9687 : 0 : return -ERANGE;
9688 : : }
9689 : :
9690 : 0 : mask[idx] = I40E_GLQF_PIT_BUILD((uint32_t)offset,
9691 : : inset_mask_offset_map[i].mask);
9692 : 0 : idx++;
9693 : : }
9694 : :
9695 : : return idx;
9696 : : }
9697 : :
9698 : : void
9699 : 0 : i40e_check_write_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
9700 : : {
9701 : 0 : uint32_t reg = i40e_read_rx_ctl(hw, addr);
9702 : :
9703 : 0 : PMD_DRV_LOG(DEBUG, "[0x%08x] original: 0x%08x", addr, reg);
9704 [ # # ]: 0 : if (reg != val)
9705 : 0 : i40e_write_rx_ctl(hw, addr, val);
9706 : 0 : PMD_DRV_LOG(DEBUG, "[0x%08x] after: 0x%08x", addr,
9707 : : (uint32_t)i40e_read_rx_ctl(hw, addr));
9708 : 0 : }
9709 : :
9710 : : void
9711 : 0 : i40e_check_write_global_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
9712 : : {
9713 : 0 : uint32_t reg = i40e_read_rx_ctl(hw, addr);
9714 : 0 : struct rte_eth_dev_data *dev_data =
9715 : 0 : ((struct i40e_adapter *)hw->back)->pf.dev_data;
9716 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[dev_data->port_id];
9717 : :
9718 [ # # ]: 0 : if (reg != val) {
9719 : 0 : i40e_write_rx_ctl(hw, addr, val);
9720 : 0 : PMD_DRV_LOG(INFO,
9721 : : "i40e device %s changed global register [0x%08x]."
9722 : : " original: 0x%08x, new: 0x%08x",
9723 : : dev->device->name, addr, reg,
9724 : : (uint32_t)i40e_read_rx_ctl(hw, addr));
9725 : : }
9726 : 0 : }
9727 : :
9728 : : static void
9729 : 0 : i40e_filter_input_set_init(struct i40e_pf *pf)
9730 : : {
9731 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9732 : : enum i40e_filter_pctype pctype;
9733 : : uint64_t input_set, inset_reg;
9734 : 0 : uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9735 : : int num, i;
9736 : : uint16_t flow_type;
9737 : :
9738 : 0 : for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
9739 [ # # ]: 0 : pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++) {
9740 : 0 : flow_type = i40e_pctype_to_flowtype(pf->adapter, pctype);
9741 : :
9742 [ # # ]: 0 : if (flow_type == RTE_ETH_FLOW_UNKNOWN)
9743 : 0 : continue;
9744 : :
9745 : 0 : input_set = i40e_get_default_input_set(pctype);
9746 : :
9747 : 0 : num = i40e_generate_inset_mask_reg(hw, input_set, mask_reg,
9748 : : I40E_INSET_MASK_NUM_REG);
9749 [ # # ]: 0 : if (num < 0)
9750 : 0 : return;
9751 [ # # # # ]: 0 : if (pf->support_multi_driver && num > 0) {
9752 : 0 : PMD_DRV_LOG(ERR, "Input set setting is not supported.");
9753 : 0 : return;
9754 : : }
9755 : 0 : inset_reg = i40e_translate_input_set_reg(hw->mac.type,
9756 : : input_set);
9757 : :
9758 : 0 : i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
9759 : : (uint32_t)(inset_reg & UINT32_MAX));
9760 : 0 : i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
9761 : 0 : (uint32_t)((inset_reg >>
9762 : : I40E_32_BIT_WIDTH) & UINT32_MAX));
9763 [ # # ]: 0 : if (!pf->support_multi_driver) {
9764 : 0 : i40e_check_write_global_reg(hw,
9765 : 0 : I40E_GLQF_HASH_INSET(0, pctype),
9766 : : (uint32_t)(inset_reg & UINT32_MAX));
9767 : 0 : i40e_check_write_global_reg(hw,
9768 : 0 : I40E_GLQF_HASH_INSET(1, pctype),
9769 : : (uint32_t)((inset_reg >>
9770 : : I40E_32_BIT_WIDTH) & UINT32_MAX));
9771 : :
9772 [ # # ]: 0 : for (i = 0; i < num; i++) {
9773 : 0 : i40e_check_write_global_reg(hw,
9774 : 0 : I40E_GLQF_FD_MSK(i, pctype),
9775 : : mask_reg[i]);
9776 : 0 : i40e_check_write_global_reg(hw,
9777 : : I40E_GLQF_HASH_MSK(i, pctype),
9778 : : mask_reg[i]);
9779 : : }
9780 : : /*clear unused mask registers of the pctype */
9781 [ # # ]: 0 : for (i = num; i < I40E_INSET_MASK_NUM_REG; i++) {
9782 : 0 : i40e_check_write_global_reg(hw,
9783 : 0 : I40E_GLQF_FD_MSK(i, pctype),
9784 : : 0);
9785 : 0 : i40e_check_write_global_reg(hw,
9786 : : I40E_GLQF_HASH_MSK(i, pctype),
9787 : : 0);
9788 : : }
9789 : : } else {
9790 : 0 : PMD_DRV_LOG(ERR, "Input set setting is not supported.");
9791 : : }
9792 : 0 : I40E_WRITE_FLUSH(hw);
9793 : :
9794 : : /* store the default input set */
9795 [ # # ]: 0 : if (!pf->support_multi_driver)
9796 : 0 : pf->hash_input_set[pctype] = input_set;
9797 : 0 : pf->fdir.input_set[pctype] = input_set;
9798 : : }
9799 : : }
9800 : :
9801 : : int
9802 : 0 : i40e_set_hash_inset(struct i40e_hw *hw, uint64_t input_set,
9803 : : uint32_t pctype, bool add)
9804 : : {
9805 : 0 : struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
9806 : 0 : uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9807 : : uint64_t inset_reg = 0;
9808 : : int num, i;
9809 : :
9810 [ # # ]: 0 : if (pf->support_multi_driver) {
9811 : 0 : PMD_DRV_LOG(ERR,
9812 : : "Modify input set is not permitted when multi-driver enabled.");
9813 : 0 : return -EPERM;
9814 : : }
9815 : :
9816 : : /* For X722, get translated pctype in fd pctype register */
9817 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
9818 : 0 : pctype = i40e_read_rx_ctl(hw, I40E_GLQF_FD_PCTYPES(pctype));
9819 : :
9820 [ # # ]: 0 : if (add) {
9821 : : /* get inset value in register */
9822 : 0 : inset_reg = i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, pctype));
9823 : 0 : inset_reg <<= I40E_32_BIT_WIDTH;
9824 : 0 : inset_reg |= i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, pctype));
9825 : 0 : input_set |= pf->hash_input_set[pctype];
9826 : : }
9827 : 0 : num = i40e_generate_inset_mask_reg(hw, input_set, mask_reg,
9828 : : I40E_INSET_MASK_NUM_REG);
9829 [ # # ]: 0 : if (num < 0)
9830 : : return -EINVAL;
9831 : :
9832 : 0 : inset_reg |= i40e_translate_input_set_reg(hw->mac.type, input_set);
9833 : :
9834 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(0, pctype),
9835 : : (uint32_t)(inset_reg & UINT32_MAX));
9836 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(1, pctype),
9837 : 0 : (uint32_t)((inset_reg >>
9838 : : I40E_32_BIT_WIDTH) & UINT32_MAX));
9839 : :
9840 [ # # ]: 0 : for (i = 0; i < num; i++)
9841 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
9842 : : mask_reg[i]);
9843 : : /*clear unused mask registers of the pctype */
9844 [ # # ]: 0 : for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
9845 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
9846 : : 0);
9847 : 0 : I40E_WRITE_FLUSH(hw);
9848 : :
9849 : 0 : pf->hash_input_set[pctype] = input_set;
9850 : 0 : return 0;
9851 : : }
9852 : :
9853 : : /* Convert ethertype filter structure */
9854 : : static int
9855 : : i40e_ethertype_filter_convert(const struct rte_eth_ethertype_filter *input,
9856 : : struct i40e_ethertype_filter *filter)
9857 : : {
9858 [ # # ]: 0 : rte_memcpy(&filter->input.mac_addr, &input->mac_addr,
9859 : : RTE_ETHER_ADDR_LEN);
9860 : 0 : filter->input.ether_type = input->ether_type;
9861 : 0 : filter->flags = input->flags;
9862 : 0 : filter->queue = input->queue;
9863 : :
9864 : : return 0;
9865 : : }
9866 : :
9867 : : /* Check if there exists the ethertype filter */
9868 : : struct i40e_ethertype_filter *
9869 : 0 : i40e_sw_ethertype_filter_lookup(struct i40e_ethertype_rule *ethertype_rule,
9870 : : const struct i40e_ethertype_filter_input *input)
9871 : : {
9872 : : int ret;
9873 : :
9874 : 0 : ret = rte_hash_lookup(ethertype_rule->hash_table, (const void *)input);
9875 [ # # ]: 0 : if (ret < 0)
9876 : : return NULL;
9877 : :
9878 : 0 : return ethertype_rule->hash_map[ret];
9879 : : }
9880 : :
9881 : : /* Add ethertype filter in SW list */
9882 : : static int
9883 : 0 : i40e_sw_ethertype_filter_insert(struct i40e_pf *pf,
9884 : : struct i40e_ethertype_filter *filter)
9885 : : {
9886 : : struct i40e_ethertype_rule *rule = &pf->ethertype;
9887 : : int ret;
9888 : :
9889 : 0 : ret = rte_hash_add_key(rule->hash_table, &filter->input);
9890 [ # # ]: 0 : if (ret < 0) {
9891 : 0 : PMD_DRV_LOG(ERR,
9892 : : "Failed to insert ethertype filter"
9893 : : " to hash table %d!",
9894 : : ret);
9895 : 0 : return ret;
9896 : : }
9897 : 0 : rule->hash_map[ret] = filter;
9898 : :
9899 : 0 : TAILQ_INSERT_TAIL(&rule->ethertype_list, filter, rules);
9900 : :
9901 : 0 : return 0;
9902 : : }
9903 : :
9904 : : /* Delete ethertype filter in SW list */
9905 : : int
9906 : 0 : i40e_sw_ethertype_filter_del(struct i40e_pf *pf,
9907 : : struct i40e_ethertype_filter_input *input)
9908 : : {
9909 : : struct i40e_ethertype_rule *rule = &pf->ethertype;
9910 : : struct i40e_ethertype_filter *filter;
9911 : : int ret;
9912 : :
9913 : 0 : ret = rte_hash_del_key(rule->hash_table, input);
9914 [ # # ]: 0 : if (ret < 0) {
9915 : 0 : PMD_DRV_LOG(ERR,
9916 : : "Failed to delete ethertype filter"
9917 : : " to hash table %d!",
9918 : : ret);
9919 : 0 : return ret;
9920 : : }
9921 : 0 : filter = rule->hash_map[ret];
9922 : 0 : rule->hash_map[ret] = NULL;
9923 : :
9924 [ # # ]: 0 : TAILQ_REMOVE(&rule->ethertype_list, filter, rules);
9925 : 0 : rte_free(filter);
9926 : :
9927 : 0 : return 0;
9928 : : }
9929 : :
9930 : : /*
9931 : : * Configure ethertype filter, which can director packet by filtering
9932 : : * with mac address and ether_type or only ether_type
9933 : : */
9934 : : int
9935 : 0 : i40e_ethertype_filter_set(struct i40e_pf *pf,
9936 : : struct rte_eth_ethertype_filter *filter,
9937 : : bool add)
9938 : : {
9939 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9940 : 0 : struct i40e_ethertype_rule *ethertype_rule = &pf->ethertype;
9941 : : struct i40e_ethertype_filter *ethertype_filter, *node;
9942 : : struct i40e_ethertype_filter check_filter;
9943 : : struct i40e_control_filter_stats stats;
9944 : : uint16_t flags = 0;
9945 : : int ret;
9946 : :
9947 [ # # ]: 0 : if (filter->queue >= pf->dev_data->nb_rx_queues) {
9948 : 0 : PMD_DRV_LOG(ERR, "Invalid queue ID");
9949 : 0 : return -EINVAL;
9950 : : }
9951 [ # # ]: 0 : if (filter->ether_type == RTE_ETHER_TYPE_IPV4 ||
9952 : : filter->ether_type == RTE_ETHER_TYPE_IPV6) {
9953 : 0 : PMD_DRV_LOG(ERR,
9954 : : "unsupported ether_type(0x%04x) in control packet filter.",
9955 : : filter->ether_type);
9956 : 0 : return -EINVAL;
9957 : : }
9958 [ # # ]: 0 : if (filter->ether_type == RTE_ETHER_TYPE_VLAN)
9959 : 0 : PMD_DRV_LOG(WARNING,
9960 : : "filter vlan ether_type in first tag is not supported.");
9961 : :
9962 : : /* Check if there is the filter in SW list */
9963 : : memset(&check_filter, 0, sizeof(check_filter));
9964 : : i40e_ethertype_filter_convert(filter, &check_filter);
9965 : 0 : node = i40e_sw_ethertype_filter_lookup(ethertype_rule,
9966 : : &check_filter.input);
9967 [ # # ]: 0 : if (add && node) {
9968 : 0 : PMD_DRV_LOG(ERR, "Conflict with existing ethertype rules!");
9969 : 0 : return -EINVAL;
9970 : : }
9971 : :
9972 [ # # ]: 0 : if (!add && !node) {
9973 : 0 : PMD_DRV_LOG(ERR, "There's no corresponding ethertype filter!");
9974 : 0 : return -EINVAL;
9975 : : }
9976 : :
9977 [ # # ]: 0 : if (!(filter->flags & RTE_ETHTYPE_FLAGS_MAC))
9978 : : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
9979 [ # # ]: 0 : if (filter->flags & RTE_ETHTYPE_FLAGS_DROP)
9980 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
9981 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
9982 : :
9983 : : memset(&stats, 0, sizeof(stats));
9984 : 0 : ret = i40e_aq_add_rem_control_packet_filter(hw,
9985 : 0 : filter->mac_addr.addr_bytes,
9986 : 0 : filter->ether_type, flags,
9987 : 0 : pf->main_vsi->seid,
9988 : 0 : filter->queue, add, &stats, NULL);
9989 : :
9990 : 0 : PMD_DRV_LOG(INFO,
9991 : : "add/rem control packet filter, return %d, mac_etype_used = %u, etype_used = %u, mac_etype_free = %u, etype_free = %u",
9992 : : ret, stats.mac_etype_used, stats.etype_used,
9993 : : stats.mac_etype_free, stats.etype_free);
9994 [ # # ]: 0 : if (ret < 0)
9995 : : return -ENOSYS;
9996 : :
9997 : : /* Add or delete a filter in SW list */
9998 [ # # ]: 0 : if (add) {
9999 : 0 : ethertype_filter = rte_zmalloc("ethertype_filter",
10000 : : sizeof(*ethertype_filter), 0);
10001 [ # # ]: 0 : if (ethertype_filter == NULL) {
10002 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory.");
10003 : 0 : return -ENOMEM;
10004 : : }
10005 : :
10006 : : rte_memcpy(ethertype_filter, &check_filter,
10007 : : sizeof(check_filter));
10008 : 0 : ret = i40e_sw_ethertype_filter_insert(pf, ethertype_filter);
10009 [ # # ]: 0 : if (ret < 0)
10010 : 0 : rte_free(ethertype_filter);
10011 : : } else {
10012 : 0 : ret = i40e_sw_ethertype_filter_del(pf, &node->input);
10013 : : }
10014 : :
10015 : : return ret;
10016 : : }
10017 : :
10018 : : static int
10019 : 0 : i40e_dev_flow_ops_get(struct rte_eth_dev *dev,
10020 : : const struct rte_flow_ops **ops)
10021 : : {
10022 [ # # ]: 0 : if (dev == NULL)
10023 : : return -EINVAL;
10024 : :
10025 : 0 : *ops = &i40e_flow_ops;
10026 : 0 : return 0;
10027 : : }
10028 : :
10029 : : /*
10030 : : * Check and enable Extended Tag.
10031 : : * Enabling Extended Tag is important for 40G performance.
10032 : : */
10033 : : static void
10034 : 0 : i40e_enable_extended_tag(struct rte_eth_dev *dev)
10035 : : {
10036 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
10037 : 0 : uint32_t buf = 0;
10038 : : int ret;
10039 : :
10040 : 0 : ret = rte_pci_read_config(pci_dev, &buf, sizeof(buf),
10041 : : PCI_DEV_CAP_REG);
10042 [ # # ]: 0 : if (ret < 0) {
10043 : 0 : PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
10044 : : PCI_DEV_CAP_REG);
10045 : 0 : return;
10046 : : }
10047 [ # # ]: 0 : if (!(buf & PCI_DEV_CAP_EXT_TAG_MASK)) {
10048 : 0 : PMD_DRV_LOG(ERR, "Does not support Extended Tag");
10049 : 0 : return;
10050 : : }
10051 : :
10052 : 0 : buf = 0;
10053 : 0 : ret = rte_pci_read_config(pci_dev, &buf, sizeof(buf),
10054 : : PCI_DEV_CTRL_REG);
10055 [ # # ]: 0 : if (ret < 0) {
10056 : 0 : PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
10057 : : PCI_DEV_CTRL_REG);
10058 : 0 : return;
10059 : : }
10060 [ # # ]: 0 : if (buf & PCI_DEV_CTRL_EXT_TAG_MASK) {
10061 : 0 : PMD_DRV_LOG(DEBUG, "Extended Tag has already been enabled");
10062 : 0 : return;
10063 : : }
10064 : 0 : buf |= PCI_DEV_CTRL_EXT_TAG_MASK;
10065 : 0 : ret = rte_pci_write_config(pci_dev, &buf, sizeof(buf),
10066 : : PCI_DEV_CTRL_REG);
10067 [ # # ]: 0 : if (ret < 0) {
10068 : 0 : PMD_DRV_LOG(ERR, "Failed to write PCI offset 0x%x",
10069 : : PCI_DEV_CTRL_REG);
10070 : 0 : return;
10071 : : }
10072 : : }
10073 : :
10074 : : /*
10075 : : * As some registers wouldn't be reset unless a global hardware reset,
10076 : : * hardware initialization is needed to put those registers into an
10077 : : * expected initial state.
10078 : : */
10079 : : static void
10080 : 0 : i40e_hw_init(struct rte_eth_dev *dev)
10081 : : {
10082 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10083 : :
10084 : 0 : i40e_enable_extended_tag(dev);
10085 : :
10086 : : /* clear the PF Queue Filter control register */
10087 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, 0);
10088 : :
10089 : : /* Disable symmetric hash per port */
10090 : 0 : i40e_set_symmetric_hash_enable_per_port(hw, 0);
10091 : 0 : }
10092 : :
10093 : : /*
10094 : : * For X722 it is possible to have multiple pctypes mapped to the same flowtype
10095 : : * however this function will return only one highest pctype index,
10096 : : * which is not quite correct. This is known problem of i40e driver
10097 : : * and needs to be fixed later.
10098 : : */
10099 : : enum i40e_filter_pctype
10100 : 0 : i40e_flowtype_to_pctype(const struct i40e_adapter *adapter, uint16_t flow_type)
10101 : : {
10102 : : int i;
10103 : : uint64_t pctype_mask;
10104 : :
10105 [ # # ]: 0 : if (flow_type < I40E_FLOW_TYPE_MAX) {
10106 : 0 : pctype_mask = adapter->pctypes_tbl[flow_type];
10107 [ # # ]: 0 : for (i = I40E_FILTER_PCTYPE_MAX - 1; i > 0; i--) {
10108 [ # # ]: 0 : if (pctype_mask & RTE_BIT64(i))
10109 : 0 : return (enum i40e_filter_pctype)i;
10110 : : }
10111 : : }
10112 : : return I40E_FILTER_PCTYPE_INVALID;
10113 : : }
10114 : :
10115 : : uint16_t
10116 : 0 : i40e_pctype_to_flowtype(const struct i40e_adapter *adapter,
10117 : : enum i40e_filter_pctype pctype)
10118 : : {
10119 : : uint16_t flowtype;
10120 : 0 : uint64_t pctype_mask = RTE_BIT64(pctype);
10121 : :
10122 [ # # ]: 0 : for (flowtype = RTE_ETH_FLOW_UNKNOWN + 1; flowtype < I40E_FLOW_TYPE_MAX;
10123 : 0 : flowtype++) {
10124 [ # # ]: 0 : if (adapter->pctypes_tbl[flowtype] & pctype_mask)
10125 : 0 : return flowtype;
10126 : : }
10127 : :
10128 : : return RTE_ETH_FLOW_UNKNOWN;
10129 : : }
10130 : :
10131 : : /*
10132 : : * On X710, performance number is far from the expectation on recent firmware
10133 : : * versions; on XL710, performance number is also far from the expectation on
10134 : : * recent firmware versions, if promiscuous mode is disabled, or promiscuous
10135 : : * mode is enabled and port MAC address is equal to the packet destination MAC
10136 : : * address. The fix for this issue may not be integrated in the following
10137 : : * firmware version. So the workaround in software driver is needed. It needs
10138 : : * to modify the initial values of 3 internal only registers for both X710 and
10139 : : * XL710. Note that the values for X710 or XL710 could be different, and the
10140 : : * workaround can be removed when it is fixed in firmware in the future.
10141 : : */
10142 : :
10143 : : /* For both X710 and XL710 */
10144 : : #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1 0x10000200
10145 : : #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2 0x203F0200
10146 : : #define I40E_GL_SWR_PRI_JOIN_MAP_0 0x26CE00
10147 : :
10148 : : #define I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x011f0200
10149 : : #define I40E_GL_SWR_PRI_JOIN_MAP_2 0x26CE08
10150 : :
10151 : : /* For X722 */
10152 : : #define I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE 0x20000200
10153 : : #define I40E_X722_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x013F0200
10154 : :
10155 : : /* For X710 */
10156 : : #define I40E_GL_SWR_PM_UP_THR_EF_VALUE 0x03030303
10157 : : /* For XL710 */
10158 : : #define I40E_GL_SWR_PM_UP_THR_SF_VALUE 0x06060606
10159 : : #define I40E_GL_SWR_PM_UP_THR 0x269FBC
10160 : :
10161 : : /*
10162 : : * GL_SWR_PM_UP_THR:
10163 : : * The value is not impacted from the link speed, its value is set according
10164 : : * to the total number of ports for a better pipe-monitor configuration.
10165 : : */
10166 : : static bool
10167 : 0 : i40e_get_swr_pm_cfg(struct i40e_hw *hw, uint32_t *value)
10168 : : {
10169 : : #define I40E_GL_SWR_PM_EF_DEVICE(dev) \
10170 : : .device_id = (dev), \
10171 : : .val = I40E_GL_SWR_PM_UP_THR_EF_VALUE
10172 : :
10173 : : #define I40E_GL_SWR_PM_SF_DEVICE(dev) \
10174 : : .device_id = (dev), \
10175 : : .val = I40E_GL_SWR_PM_UP_THR_SF_VALUE
10176 : :
10177 : : static const struct {
10178 : : uint16_t device_id;
10179 : : uint32_t val;
10180 : : } swr_pm_table[] = {
10181 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_SFP_XL710) },
10182 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_KX_C) },
10183 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_10G_BASE_T) },
10184 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_10G_BASE_T4) },
10185 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_SFP_X722) },
10186 : :
10187 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_KX_B) },
10188 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_QSFP_A) },
10189 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_QSFP_B) },
10190 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_20G_KR2) },
10191 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_20G_KR2_A) },
10192 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_25G_B) },
10193 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_25G_SFP28) },
10194 : : };
10195 : : uint32_t i;
10196 : :
10197 [ # # ]: 0 : if (value == NULL) {
10198 : 0 : PMD_DRV_LOG(ERR, "value is NULL");
10199 : 0 : return false;
10200 : : }
10201 : :
10202 [ # # ]: 0 : for (i = 0; i < RTE_DIM(swr_pm_table); i++) {
10203 [ # # ]: 0 : if (hw->device_id == swr_pm_table[i].device_id) {
10204 : 0 : *value = swr_pm_table[i].val;
10205 : :
10206 : 0 : PMD_DRV_LOG(DEBUG, "Device 0x%x with GL_SWR_PM_UP_THR "
10207 : : "value - 0x%08x",
10208 : : hw->device_id, *value);
10209 : 0 : return true;
10210 : : }
10211 : : }
10212 : :
10213 : : return false;
10214 : : }
10215 : :
10216 : : static int
10217 : 0 : i40e_dev_sync_phy_type(struct i40e_hw *hw)
10218 : : {
10219 : : enum i40e_status_code status;
10220 : : struct i40e_aq_get_phy_abilities_resp phy_ab;
10221 : : int ret = -ENOTSUP;
10222 : : int retries = 0;
10223 : :
10224 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, true, &phy_ab,
10225 : : NULL);
10226 : :
10227 [ # # ]: 0 : while (status) {
10228 : 0 : PMD_INIT_LOG(WARNING, "Failed to sync phy type: status=%d",
10229 : : status);
10230 : 0 : retries++;
10231 : 0 : rte_delay_us(100000);
10232 [ # # ]: 0 : if (retries < 5)
10233 : 0 : status = i40e_aq_get_phy_capabilities(hw, false,
10234 : : true, &phy_ab, NULL);
10235 : : else
10236 : : return ret;
10237 : : }
10238 : : return 0;
10239 : : }
10240 : :
10241 : : static void
10242 : 0 : i40e_configure_registers(struct i40e_hw *hw)
10243 : : {
10244 : : static struct {
10245 : : uint32_t addr;
10246 : : uint64_t val;
10247 : : } reg_table[] = {
10248 : : {I40E_GL_SWR_PRI_JOIN_MAP_0, 0},
10249 : : {I40E_GL_SWR_PRI_JOIN_MAP_2, 0},
10250 : : {I40E_GL_SWR_PM_UP_THR, 0}, /* Compute value dynamically */
10251 : : };
10252 : : uint64_t reg;
10253 : : uint32_t i;
10254 : : int ret;
10255 : :
10256 [ # # ]: 0 : for (i = 0; i < RTE_DIM(reg_table); i++) {
10257 [ # # ]: 0 : if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_0) {
10258 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) /* For X722 */
10259 : 0 : reg_table[i].val =
10260 : : I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE;
10261 : : else /* For X710/XL710/XXV710 */
10262 [ # # ]: 0 : if (hw->aq.fw_maj_ver < 6)
10263 : 0 : reg_table[i].val =
10264 : : I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1;
10265 : : else
10266 : 0 : reg_table[i].val =
10267 : : I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2;
10268 : : }
10269 : :
10270 [ # # ]: 0 : if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_2) {
10271 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) /* For X722 */
10272 : 0 : reg_table[i].val =
10273 : : I40E_X722_GL_SWR_PRI_JOIN_MAP_2_VALUE;
10274 : : else /* For X710/XL710/XXV710 */
10275 : 0 : reg_table[i].val =
10276 : : I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE;
10277 : : }
10278 : :
10279 [ # # ]: 0 : if (reg_table[i].addr == I40E_GL_SWR_PM_UP_THR) {
10280 : : uint32_t cfg_val;
10281 : :
10282 [ # # ]: 0 : if (!i40e_get_swr_pm_cfg(hw, &cfg_val)) {
10283 : 0 : PMD_DRV_LOG(DEBUG, "Device 0x%x skips "
10284 : : "GL_SWR_PM_UP_THR value fixup",
10285 : : hw->device_id);
10286 : 0 : continue;
10287 : : }
10288 : :
10289 : 0 : reg_table[i].val = cfg_val;
10290 : : }
10291 : :
10292 : 0 : ret = i40e_aq_debug_read_register(hw, reg_table[i].addr,
10293 : : ®, NULL);
10294 [ # # ]: 0 : if (ret < 0) {
10295 : 0 : PMD_DRV_LOG(ERR, "Failed to read from 0x%"PRIx32,
10296 : : reg_table[i].addr);
10297 : 0 : break;
10298 : : }
10299 : 0 : PMD_DRV_LOG(DEBUG, "Read from 0x%"PRIx32": 0x%"PRIx64,
10300 : : reg_table[i].addr, reg);
10301 [ # # ]: 0 : if (reg == reg_table[i].val)
10302 : 0 : continue;
10303 : :
10304 : 0 : ret = i40e_aq_debug_write_register(hw, reg_table[i].addr,
10305 : : reg_table[i].val, NULL);
10306 [ # # ]: 0 : if (ret < 0) {
10307 : 0 : PMD_DRV_LOG(ERR,
10308 : : "Failed to write 0x%"PRIx64" to the address of 0x%"PRIx32,
10309 : : reg_table[i].val, reg_table[i].addr);
10310 : 0 : break;
10311 : : }
10312 : 0 : PMD_DRV_LOG(DEBUG, "Write 0x%"PRIx64" to the address of "
10313 : : "0x%"PRIx32, reg_table[i].val, reg_table[i].addr);
10314 : : }
10315 : 0 : }
10316 : :
10317 : : #define I40E_VSI_TSR_QINQ_CONFIG 0xc030
10318 : : #define I40E_VSI_L2TAGSTXVALID(_i) (0x00042800 + ((_i) * 4))
10319 : : #define I40E_VSI_L2TAGSTXVALID_QINQ 0xab
10320 : : static int
10321 : 0 : i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi)
10322 : : {
10323 : : uint32_t reg;
10324 : : int ret;
10325 : :
10326 [ # # ]: 0 : if (vsi->vsi_id >= I40E_MAX_NUM_VSIS) {
10327 : 0 : PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
10328 : 0 : return -EINVAL;
10329 : : }
10330 : :
10331 : : /* Configure for double VLAN RX stripping */
10332 : 0 : reg = I40E_READ_REG(hw, I40E_VSI_TSR(vsi->vsi_id));
10333 [ # # ]: 0 : if ((reg & I40E_VSI_TSR_QINQ_CONFIG) != I40E_VSI_TSR_QINQ_CONFIG) {
10334 : 0 : reg |= I40E_VSI_TSR_QINQ_CONFIG;
10335 : 0 : ret = i40e_aq_debug_write_register(hw,
10336 : 0 : I40E_VSI_TSR(vsi->vsi_id),
10337 : : reg, NULL);
10338 [ # # ]: 0 : if (ret < 0) {
10339 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI_TSR[%d]",
10340 : : vsi->vsi_id);
10341 : 0 : return I40E_ERR_CONFIG;
10342 : : }
10343 : : }
10344 : :
10345 : : /* Configure for double VLAN TX insertion */
10346 : 0 : reg = I40E_READ_REG(hw, I40E_VSI_L2TAGSTXVALID(vsi->vsi_id));
10347 [ # # ]: 0 : if ((reg & 0xff) != I40E_VSI_L2TAGSTXVALID_QINQ) {
10348 : : reg = I40E_VSI_L2TAGSTXVALID_QINQ;
10349 : 0 : ret = i40e_aq_debug_write_register(hw,
10350 : 0 : I40E_VSI_L2TAGSTXVALID(
10351 : : vsi->vsi_id), reg, NULL);
10352 [ # # ]: 0 : if (ret < 0) {
10353 : 0 : PMD_DRV_LOG(ERR,
10354 : : "Failed to update VSI_L2TAGSTXVALID[%d]",
10355 : : vsi->vsi_id);
10356 : 0 : return I40E_ERR_CONFIG;
10357 : : }
10358 : : }
10359 : :
10360 : : return 0;
10361 : : }
10362 : :
10363 : : static uint64_t
10364 : : i40e_read_systime_cyclecounter(struct rte_eth_dev *dev)
10365 : : {
10366 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10367 : : uint64_t systim_cycles;
10368 : :
10369 : 0 : systim_cycles = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_L);
10370 : 0 : systim_cycles |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_H)
10371 [ # # ]: 0 : << 32;
10372 : :
10373 : : return systim_cycles;
10374 : : }
10375 : :
10376 : : static uint64_t
10377 : : i40e_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev, uint8_t index)
10378 : : {
10379 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10380 : : uint64_t rx_tstamp;
10381 : :
10382 : 0 : rx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_L(index));
10383 : 0 : rx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(index))
10384 [ # # ]: 0 : << 32;
10385 : :
10386 : : return rx_tstamp;
10387 : : }
10388 : :
10389 : : static uint64_t
10390 : : i40e_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
10391 : : {
10392 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10393 : : uint64_t tx_tstamp;
10394 : :
10395 : 0 : tx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_L);
10396 : 0 : tx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H)
10397 [ # # ]: 0 : << 32;
10398 : :
10399 : : return tx_tstamp;
10400 : : }
10401 : :
10402 : : static void
10403 : 0 : i40e_start_timecounters(struct rte_eth_dev *dev)
10404 : : {
10405 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10406 : : struct i40e_adapter *adapter = dev->data->dev_private;
10407 : : struct rte_eth_link link;
10408 : : uint32_t tsync_inc_l;
10409 : : uint32_t tsync_inc_h;
10410 : :
10411 : : /* Get current link speed. */
10412 : 0 : i40e_dev_link_update(dev, 1);
10413 : 0 : rte_eth_linkstatus_get(dev, &link);
10414 : :
10415 [ # # # # ]: 0 : switch (link.link_speed) {
10416 : : case RTE_ETH_SPEED_NUM_40G:
10417 : : case RTE_ETH_SPEED_NUM_25G:
10418 : : tsync_inc_l = I40E_PTP_40GB_INCVAL & 0xFFFFFFFF;
10419 : : tsync_inc_h = I40E_PTP_40GB_INCVAL >> 32;
10420 : : break;
10421 : 0 : case RTE_ETH_SPEED_NUM_10G:
10422 : : tsync_inc_l = I40E_PTP_10GB_INCVAL & 0xFFFFFFFF;
10423 : : tsync_inc_h = I40E_PTP_10GB_INCVAL >> 32;
10424 : 0 : break;
10425 : 0 : case RTE_ETH_SPEED_NUM_1G:
10426 : : tsync_inc_l = I40E_PTP_1GB_INCVAL & 0xFFFFFFFF;
10427 : : tsync_inc_h = I40E_PTP_1GB_INCVAL >> 32;
10428 : 0 : break;
10429 : 0 : default:
10430 : : tsync_inc_l = 0x0;
10431 : : tsync_inc_h = 0x0;
10432 : : }
10433 : :
10434 : : /* Set the timesync increment value. */
10435 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, tsync_inc_l);
10436 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, tsync_inc_h);
10437 : :
10438 : 0 : memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
10439 : 0 : memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
10440 : 0 : memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
10441 : :
10442 : 0 : adapter->systime_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10443 : : adapter->systime_tc.cc_shift = 0;
10444 : : adapter->systime_tc.nsec_mask = 0;
10445 : :
10446 : 0 : adapter->rx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10447 : : adapter->rx_tstamp_tc.cc_shift = 0;
10448 : : adapter->rx_tstamp_tc.nsec_mask = 0;
10449 : :
10450 : 0 : adapter->tx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10451 : : adapter->tx_tstamp_tc.cc_shift = 0;
10452 : : adapter->tx_tstamp_tc.nsec_mask = 0;
10453 : 0 : }
10454 : :
10455 : : static int
10456 : 0 : i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
10457 : : {
10458 : 0 : struct i40e_adapter *adapter = dev->data->dev_private;
10459 : :
10460 : 0 : adapter->systime_tc.nsec += delta;
10461 : 0 : adapter->rx_tstamp_tc.nsec += delta;
10462 : 0 : adapter->tx_tstamp_tc.nsec += delta;
10463 : :
10464 : 0 : return 0;
10465 : : }
10466 : :
10467 : : static int
10468 : 0 : i40e_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
10469 : : {
10470 : : uint64_t ns;
10471 : 0 : struct i40e_adapter *adapter = dev->data->dev_private;
10472 : :
10473 : : ns = rte_timespec_to_ns(ts);
10474 : :
10475 : : /* Set the timecounters to a new value. */
10476 : 0 : adapter->systime_tc.nsec = ns;
10477 : 0 : adapter->rx_tstamp_tc.nsec = ns;
10478 : 0 : adapter->tx_tstamp_tc.nsec = ns;
10479 : :
10480 : 0 : return 0;
10481 : : }
10482 : :
10483 : : static int
10484 : 0 : i40e_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
10485 : : {
10486 : : uint64_t ns, systime_cycles;
10487 : 0 : struct i40e_adapter *adapter = dev->data->dev_private;
10488 : :
10489 : : systime_cycles = i40e_read_systime_cyclecounter(dev);
10490 : : ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
10491 : 0 : *ts = rte_ns_to_timespec(ns);
10492 : :
10493 : 0 : return 0;
10494 : : }
10495 : :
10496 : : static int
10497 : 0 : i40e_timesync_enable(struct rte_eth_dev *dev)
10498 : : {
10499 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10500 : : uint32_t tsync_ctl_l;
10501 : : uint32_t tsync_ctl_h;
10502 : : struct timespec ts;
10503 : :
10504 : : memset(&ts, 0, sizeof(struct timespec));
10505 : :
10506 : : /* Stop the timesync system time. */
10507 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
10508 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
10509 : : /* Reset the timesync system time value. */
10510 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_L, 0x0);
10511 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_H, 0x0);
10512 : :
10513 : 0 : i40e_start_timecounters(dev);
10514 : :
10515 : : /* Clear timesync registers. */
10516 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
10517 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H);
10518 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(0));
10519 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(1));
10520 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(2));
10521 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(3));
10522 : :
10523 : : /* Enable timestamping of PTP packets. */
10524 : 0 : tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
10525 : 0 : tsync_ctl_l |= I40E_PRTTSYN_TSYNENA;
10526 : :
10527 : 0 : tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
10528 : : tsync_ctl_h |= I40E_PRTTSYN_TSYNENA;
10529 : 0 : tsync_ctl_h |= I40E_PRTTSYN_TSYNTYPE;
10530 : :
10531 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
10532 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
10533 : :
10534 : : /* i40e uses zero-based timestamping so only adjust timecounter */
10535 : : i40e_timesync_write_time(dev, &ts);
10536 : :
10537 : 0 : return 0;
10538 : : }
10539 : :
10540 : : static int
10541 : 0 : i40e_timesync_disable(struct rte_eth_dev *dev)
10542 : : {
10543 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10544 : : uint32_t tsync_ctl_l;
10545 : : uint32_t tsync_ctl_h;
10546 : :
10547 : : /* Disable timestamping of transmitted PTP packets. */
10548 : 0 : tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
10549 : 0 : tsync_ctl_l &= ~I40E_PRTTSYN_TSYNENA;
10550 : :
10551 : 0 : tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
10552 : 0 : tsync_ctl_h &= ~I40E_PRTTSYN_TSYNENA;
10553 : :
10554 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
10555 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
10556 : :
10557 : : /* Reset the timesync increment value. */
10558 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
10559 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
10560 : :
10561 : 0 : return 0;
10562 : : }
10563 : :
10564 : : static int
10565 : 0 : i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
10566 : : struct timespec *timestamp, uint32_t flags)
10567 : : {
10568 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10569 : : struct i40e_adapter *adapter = dev->data->dev_private;
10570 : : uint32_t sync_status;
10571 : 0 : uint32_t index = flags & 0x03;
10572 : : uint64_t rx_tstamp_cycles;
10573 : : uint64_t ns;
10574 : :
10575 : 0 : sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_1);
10576 [ # # ]: 0 : if ((sync_status & (1 << index)) == 0)
10577 : : return -EINVAL;
10578 : :
10579 : 0 : rx_tstamp_cycles = i40e_read_rx_tstamp_cyclecounter(dev, index);
10580 : : ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
10581 : 0 : *timestamp = rte_ns_to_timespec(ns);
10582 : :
10583 : 0 : return 0;
10584 : : }
10585 : :
10586 : : static int
10587 : 0 : i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
10588 : : struct timespec *timestamp)
10589 : : {
10590 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10591 : : struct i40e_adapter *adapter = dev->data->dev_private;
10592 : : uint32_t sync_status;
10593 : : uint64_t tx_tstamp_cycles;
10594 : : uint64_t ns;
10595 : :
10596 : 0 : sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
10597 [ # # ]: 0 : if ((sync_status & I40E_PRTTSYN_STAT_0_TXTIME_MASK) == 0)
10598 : : return -EINVAL;
10599 : :
10600 : : tx_tstamp_cycles = i40e_read_tx_tstamp_cyclecounter(dev);
10601 : : ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
10602 : 0 : *timestamp = rte_ns_to_timespec(ns);
10603 : :
10604 : 0 : return 0;
10605 : : }
10606 : :
10607 : : /*
10608 : : * i40e_parse_dcb_configure - parse dcb configure from user
10609 : : * @dev: the device being configured
10610 : : * @dcb_cfg: pointer of the result of parse
10611 : : * @*tc_map: bit map of enabled traffic classes
10612 : : *
10613 : : * Returns 0 on success, negative value on failure
10614 : : */
10615 : : static int
10616 [ # # ]: 0 : i40e_parse_dcb_configure(struct rte_eth_dev *dev,
10617 : : struct i40e_dcbx_config *dcb_cfg,
10618 : : uint8_t *tc_map)
10619 : : {
10620 : : struct rte_eth_dcb_rx_conf *dcb_rx_conf;
10621 : : uint8_t i, tc_bw, bw_lf;
10622 : :
10623 : : memset(dcb_cfg, 0, sizeof(struct i40e_dcbx_config));
10624 : :
10625 : 0 : dcb_rx_conf = &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
10626 [ # # ]: 0 : if (dcb_rx_conf->nb_tcs > I40E_MAX_TRAFFIC_CLASS) {
10627 : 0 : PMD_INIT_LOG(ERR, "number of tc exceeds max.");
10628 : 0 : return -EINVAL;
10629 : : }
10630 : :
10631 : : /* assume each tc has the same bw */
10632 : 0 : tc_bw = I40E_MAX_PERCENT / dcb_rx_conf->nb_tcs;
10633 [ # # ]: 0 : for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
10634 : 0 : dcb_cfg->etscfg.tcbwtable[i] = tc_bw;
10635 : : /* to ensure the sum of tcbw is equal to 100 */
10636 : 0 : bw_lf = I40E_MAX_PERCENT % dcb_rx_conf->nb_tcs;
10637 [ # # ]: 0 : for (i = 0; i < bw_lf; i++)
10638 : 0 : dcb_cfg->etscfg.tcbwtable[i]++;
10639 : :
10640 : : /* assume each tc has the same Transmission Selection Algorithm */
10641 [ # # ]: 0 : for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
10642 : 0 : dcb_cfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
10643 : :
10644 [ # # ]: 0 : for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
10645 : 0 : dcb_cfg->etscfg.prioritytable[i] =
10646 : 0 : dcb_rx_conf->dcb_tc[i];
10647 : :
10648 : : /* FW needs one App to configure HW */
10649 : 0 : dcb_cfg->numapps = I40E_DEFAULT_DCB_APP_NUM;
10650 : 0 : dcb_cfg->app[0].selector = I40E_APP_SEL_ETHTYPE;
10651 : 0 : dcb_cfg->app[0].priority = I40E_DEFAULT_DCB_APP_PRIO;
10652 : 0 : dcb_cfg->app[0].protocolid = I40E_APP_PROTOID_FCOE;
10653 : :
10654 [ # # ]: 0 : if (dcb_rx_conf->nb_tcs == 0)
10655 : 0 : *tc_map = 1; /* tc0 only */
10656 : : else
10657 : 0 : *tc_map = RTE_LEN2MASK(dcb_rx_conf->nb_tcs, uint8_t);
10658 : :
10659 [ # # ]: 0 : if (dev->data->dev_conf.dcb_capability_en & RTE_ETH_DCB_PFC_SUPPORT) {
10660 : 0 : dcb_cfg->pfc.willing = 0;
10661 : 0 : dcb_cfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
10662 : 0 : dcb_cfg->pfc.pfcenable = *tc_map;
10663 : : }
10664 : : return 0;
10665 : : }
10666 : :
10667 : :
10668 : : static enum i40e_status_code
10669 : 0 : i40e_vsi_update_queue_mapping(struct i40e_vsi *vsi,
10670 : : struct i40e_aqc_vsi_properties_data *info,
10671 : : uint8_t enabled_tcmap)
10672 : : {
10673 : : enum i40e_status_code ret;
10674 : : int i, total_tc = 0;
10675 : : uint16_t qpnum_per_tc, bsf, qp_idx;
10676 : 0 : struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(vsi);
10677 : : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
10678 : : uint16_t used_queues;
10679 : :
10680 : 0 : ret = validate_tcmap_parameter(vsi, enabled_tcmap);
10681 [ # # ]: 0 : if (ret != I40E_SUCCESS)
10682 : : return ret;
10683 : :
10684 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10685 [ # # ]: 0 : if (enabled_tcmap & (1 << i))
10686 : 0 : total_tc++;
10687 : : }
10688 [ # # ]: 0 : if (total_tc == 0)
10689 : : total_tc = 1;
10690 : 0 : vsi->enabled_tc = enabled_tcmap;
10691 : :
10692 : : /* different VSI has different queues assigned */
10693 [ # # ]: 0 : if (vsi->type == I40E_VSI_MAIN)
10694 : 0 : used_queues = dev_data->nb_rx_queues -
10695 : 0 : pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
10696 [ # # ]: 0 : else if (vsi->type == I40E_VSI_VMDQ2)
10697 : : used_queues = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
10698 : : else {
10699 : 0 : PMD_INIT_LOG(ERR, "unsupported VSI type.");
10700 : 0 : return I40E_ERR_NO_AVAILABLE_VSI;
10701 : : }
10702 : :
10703 : 0 : qpnum_per_tc = used_queues / total_tc;
10704 : : /* Number of queues per enabled TC */
10705 [ # # ]: 0 : if (qpnum_per_tc == 0) {
10706 : 0 : PMD_INIT_LOG(ERR, " number of queues is less that tcs.");
10707 : 0 : return I40E_ERR_INVALID_QP_ID;
10708 : : }
10709 : 0 : qpnum_per_tc = RTE_MIN((uint16_t)i40e_align_floor(qpnum_per_tc),
10710 : : I40E_MAX_Q_PER_TC);
10711 : 0 : bsf = rte_bsf32(qpnum_per_tc);
10712 : :
10713 : : /**
10714 : : * Configure TC and queue mapping parameters, for enabled TC,
10715 : : * allocate qpnum_per_tc queues to this traffic. For disabled TC,
10716 : : * default queue will serve it.
10717 : : */
10718 : : qp_idx = 0;
10719 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10720 [ # # ]: 0 : if (vsi->enabled_tc & (1 << i)) {
10721 : 0 : info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
10722 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
10723 : : (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
10724 : 0 : qp_idx += qpnum_per_tc;
10725 : : } else
10726 : 0 : info->tc_mapping[i] = 0;
10727 : : }
10728 : :
10729 : : /* Associate queue number with VSI, Keep vsi->nb_qps unchanged */
10730 : : if (vsi->type == I40E_VSI_SRIOV) {
10731 : : info->mapping_flags |=
10732 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
10733 : : for (i = 0; i < vsi->nb_qps; i++)
10734 : : info->queue_mapping[i] =
10735 : : rte_cpu_to_le_16(vsi->base_queue + i);
10736 : : } else {
10737 : 0 : info->mapping_flags |=
10738 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
10739 : 0 : info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
10740 : : }
10741 : 0 : info->valid_sections |=
10742 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
10743 : :
10744 : 0 : return I40E_SUCCESS;
10745 : : }
10746 : :
10747 : : /*
10748 : : * i40e_config_switch_comp_tc - Configure VEB tc setting for given TC map
10749 : : * @veb: VEB to be configured
10750 : : * @tc_map: enabled TC bitmap
10751 : : *
10752 : : * Returns 0 on success, negative value on failure
10753 : : */
10754 : : static enum i40e_status_code
10755 : 0 : i40e_config_switch_comp_tc(struct i40e_veb *veb, uint8_t tc_map)
10756 : : {
10757 : : struct i40e_aqc_configure_switching_comp_bw_config_data veb_bw;
10758 : : struct i40e_aqc_query_switching_comp_bw_config_resp bw_query;
10759 : : struct i40e_aqc_query_switching_comp_ets_config_resp ets_query;
10760 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(veb->associate_vsi);
10761 : : enum i40e_status_code ret = I40E_SUCCESS;
10762 : : int i;
10763 : : uint32_t bw_max;
10764 : :
10765 : : /* Check if enabled_tc is same as existing or new TCs */
10766 [ # # ]: 0 : if (veb->enabled_tc == tc_map)
10767 : : return ret;
10768 : :
10769 : : /* configure tc bandwidth */
10770 : : memset(&veb_bw, 0, sizeof(veb_bw));
10771 : 0 : veb_bw.tc_valid_bits = tc_map;
10772 : : /* Enable ETS TCs with equal BW Share for now across all VSIs */
10773 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10774 [ # # ]: 0 : if (tc_map & BIT_ULL(i))
10775 : 0 : veb_bw.tc_bw_share_credits[i] = 1;
10776 : : }
10777 : 0 : ret = i40e_aq_config_switch_comp_bw_config(hw, veb->seid,
10778 : : &veb_bw, NULL);
10779 [ # # ]: 0 : if (ret) {
10780 : 0 : PMD_INIT_LOG(ERR,
10781 : : "AQ command Config switch_comp BW allocation per TC failed = %d",
10782 : : hw->aq.asq_last_status);
10783 : 0 : return ret;
10784 : : }
10785 : :
10786 : : memset(&ets_query, 0, sizeof(ets_query));
10787 : 0 : ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
10788 : : &ets_query, NULL);
10789 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
10790 : 0 : PMD_DRV_LOG(ERR,
10791 : : "Failed to get switch_comp ETS configuration %u",
10792 : : hw->aq.asq_last_status);
10793 : 0 : return ret;
10794 : : }
10795 : : memset(&bw_query, 0, sizeof(bw_query));
10796 : 0 : ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
10797 : : &bw_query, NULL);
10798 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
10799 : 0 : PMD_DRV_LOG(ERR,
10800 : : "Failed to get switch_comp bandwidth configuration %u",
10801 : : hw->aq.asq_last_status);
10802 : 0 : return ret;
10803 : : }
10804 : :
10805 : : /* store and print out BW info */
10806 : 0 : veb->bw_info.bw_limit = rte_le_to_cpu_16(ets_query.port_bw_limit);
10807 : 0 : veb->bw_info.bw_max = ets_query.tc_bw_max;
10808 : 0 : PMD_DRV_LOG(DEBUG, "switch_comp bw limit:%u", veb->bw_info.bw_limit);
10809 : 0 : PMD_DRV_LOG(DEBUG, "switch_comp max_bw:%u", veb->bw_info.bw_max);
10810 : 0 : bw_max = rte_le_to_cpu_16(bw_query.tc_bw_max[0]) |
10811 : 0 : (rte_le_to_cpu_16(bw_query.tc_bw_max[1]) <<
10812 : : I40E_16_BIT_WIDTH);
10813 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10814 : 0 : veb->bw_info.bw_ets_share_credits[i] =
10815 : 0 : bw_query.tc_bw_share_credits[i];
10816 : 0 : veb->bw_info.bw_ets_credits[i] =
10817 : 0 : rte_le_to_cpu_16(bw_query.tc_bw_limits[i]);
10818 : : /* 4 bits per TC, 4th bit is reserved */
10819 : 0 : veb->bw_info.bw_ets_max[i] =
10820 : 0 : (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
10821 : : RTE_LEN2MASK(3, uint8_t));
10822 : 0 : PMD_DRV_LOG(DEBUG, "\tVEB TC%u:share credits %u", i,
10823 : : veb->bw_info.bw_ets_share_credits[i]);
10824 : 0 : PMD_DRV_LOG(DEBUG, "\tVEB TC%u:credits %u", i,
10825 : : veb->bw_info.bw_ets_credits[i]);
10826 : 0 : PMD_DRV_LOG(DEBUG, "\tVEB TC%u: max credits: %u", i,
10827 : : veb->bw_info.bw_ets_max[i]);
10828 : : }
10829 : :
10830 : 0 : veb->enabled_tc = tc_map;
10831 : :
10832 : 0 : return ret;
10833 : : }
10834 : :
10835 : :
10836 : : /*
10837 : : * i40e_vsi_config_tc - Configure VSI tc setting for given TC map
10838 : : * @vsi: VSI to be configured
10839 : : * @tc_map: enabled TC bitmap
10840 : : *
10841 : : * Returns 0 on success, negative value on failure
10842 : : */
10843 : : static enum i40e_status_code
10844 : 0 : i40e_vsi_config_tc(struct i40e_vsi *vsi, uint8_t tc_map)
10845 : : {
10846 : : struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
10847 : : struct i40e_vsi_context ctxt;
10848 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
10849 : : enum i40e_status_code ret = I40E_SUCCESS;
10850 : : int i;
10851 : :
10852 : : /* Check if enabled_tc is same as existing or new TCs */
10853 [ # # ]: 0 : if (vsi->enabled_tc == tc_map)
10854 : : return ret;
10855 : :
10856 : : /* configure tc bandwidth */
10857 : : memset(&bw_data, 0, sizeof(bw_data));
10858 : 0 : bw_data.tc_valid_bits = tc_map;
10859 : : /* Enable ETS TCs with equal BW Share for now across all VSIs */
10860 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10861 [ # # ]: 0 : if (tc_map & BIT_ULL(i))
10862 : 0 : bw_data.tc_bw_credits[i] = 1;
10863 : : }
10864 : 0 : ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &bw_data, NULL);
10865 [ # # ]: 0 : if (ret) {
10866 : 0 : PMD_INIT_LOG(ERR,
10867 : : "AQ command Config VSI BW allocation per TC failed = %d",
10868 : : hw->aq.asq_last_status);
10869 : 0 : goto out;
10870 : : }
10871 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
10872 : 0 : vsi->info.qs_handle[i] = bw_data.qs_handles[i];
10873 : :
10874 : : /* Update Queue Pairs Mapping for currently enabled UPs */
10875 : 0 : ctxt.seid = vsi->seid;
10876 : 0 : ctxt.pf_num = hw->pf_id;
10877 : 0 : ctxt.vf_num = 0;
10878 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
10879 : 0 : ctxt.info = vsi->info;
10880 : 0 : i40e_get_cap(hw);
10881 : 0 : ret = i40e_vsi_update_queue_mapping(vsi, &ctxt.info, tc_map);
10882 [ # # ]: 0 : if (ret)
10883 : 0 : goto out;
10884 : :
10885 : : /* Update the VSI after updating the VSI queue-mapping information */
10886 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
10887 [ # # ]: 0 : if (ret) {
10888 : 0 : PMD_INIT_LOG(ERR, "Failed to configure TC queue mapping = %d",
10889 : : hw->aq.asq_last_status);
10890 : 0 : goto out;
10891 : : }
10892 : : /* update the local VSI info with updated queue map */
10893 : : rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
10894 : : sizeof(vsi->info.tc_mapping));
10895 : : rte_memcpy(&vsi->info.queue_mapping,
10896 : : &ctxt.info.queue_mapping,
10897 : : sizeof(vsi->info.queue_mapping));
10898 : 0 : vsi->info.mapping_flags = ctxt.info.mapping_flags;
10899 : 0 : vsi->info.valid_sections = 0;
10900 : :
10901 : : /* query and update current VSI BW information */
10902 : 0 : ret = i40e_vsi_get_bw_config(vsi);
10903 [ # # ]: 0 : if (ret) {
10904 : 0 : PMD_INIT_LOG(ERR,
10905 : : "Failed updating vsi bw info, err %s aq_err %s",
10906 : : i40e_stat_str(hw, ret),
10907 : : i40e_aq_str(hw, hw->aq.asq_last_status));
10908 : 0 : goto out;
10909 : : }
10910 : :
10911 : 0 : vsi->enabled_tc = tc_map;
10912 : :
10913 : : out:
10914 : : return ret;
10915 : : }
10916 : :
10917 : : /*
10918 : : * i40e_dcb_hw_configure - program the dcb setting to hw
10919 : : * @pf: pf the configuration is taken on
10920 : : * @new_cfg: new configuration
10921 : : * @tc_map: enabled TC bitmap
10922 : : *
10923 : : * Returns 0 on success, negative value on failure
10924 : : */
10925 : : static enum i40e_status_code
10926 : 0 : i40e_dcb_hw_configure(struct i40e_pf *pf,
10927 : : struct i40e_dcbx_config *new_cfg,
10928 : : uint8_t tc_map)
10929 : : {
10930 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
10931 : 0 : struct i40e_dcbx_config *old_cfg = &hw->local_dcbx_config;
10932 : 0 : struct i40e_vsi *main_vsi = pf->main_vsi;
10933 : : struct i40e_vsi_list *vsi_list;
10934 : : enum i40e_status_code ret;
10935 : : int i;
10936 : : uint32_t val;
10937 : :
10938 : : /* Use the FW API if FW > v4.4*/
10939 [ # # # # : 0 : if (!(((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver >= 4)) ||
# # ]
10940 : : (hw->aq.fw_maj_ver >= 5))) {
10941 : 0 : PMD_INIT_LOG(ERR,
10942 : : "FW < v4.4, can not use FW LLDP API to configure DCB");
10943 : 0 : return I40E_ERR_FIRMWARE_API_VERSION;
10944 : : }
10945 : :
10946 : : /* Check if need reconfiguration */
10947 [ # # ]: 0 : if (!memcmp(new_cfg, old_cfg, sizeof(struct i40e_dcbx_config))) {
10948 : 0 : PMD_INIT_LOG(ERR, "No Change in DCB Config required.");
10949 : 0 : return I40E_SUCCESS;
10950 : : }
10951 : :
10952 : : /* Copy the new config to the current config */
10953 : 0 : *old_cfg = *new_cfg;
10954 : 0 : old_cfg->etsrec = old_cfg->etscfg;
10955 : 0 : ret = i40e_set_dcb_config(hw);
10956 [ # # ]: 0 : if (ret) {
10957 : 0 : PMD_INIT_LOG(ERR, "Set DCB Config failed, err %s aq_err %s",
10958 : : i40e_stat_str(hw, ret),
10959 : : i40e_aq_str(hw, hw->aq.asq_last_status));
10960 : 0 : return ret;
10961 : : }
10962 : : /* set receive Arbiter to RR mode and ETS scheme by default */
10963 [ # # ]: 0 : for (i = 0; i <= I40E_PRTDCB_RETSTCC_MAX_INDEX; i++) {
10964 : 0 : val = I40E_READ_REG(hw, I40E_PRTDCB_RETSTCC(i));
10965 : 0 : val &= ~(I40E_PRTDCB_RETSTCC_BWSHARE_MASK |
10966 : : I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK |
10967 : : I40E_PRTDCB_RETSTCC_ETSTC_SHIFT);
10968 : 0 : val |= ((uint32_t)old_cfg->etscfg.tcbwtable[i] <<
10969 : 0 : I40E_PRTDCB_RETSTCC_BWSHARE_SHIFT) &
10970 : : I40E_PRTDCB_RETSTCC_BWSHARE_MASK;
10971 : : val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_UPINTC_MODE_SHIFT) &
10972 : : I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK;
10973 : 0 : val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_ETSTC_SHIFT) &
10974 : : I40E_PRTDCB_RETSTCC_ETSTC_MASK;
10975 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_RETSTCC(i), val);
10976 : : }
10977 : : /* get local mib to check whether it is configured correctly */
10978 : : /* IEEE mode */
10979 : 0 : hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_IEEE;
10980 : : /* Get Local DCB Config */
10981 : 0 : i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
10982 : : &hw->local_dcbx_config);
10983 : :
10984 : : /* if Veb is created, need to update TC of it at first */
10985 [ # # ]: 0 : if (main_vsi->veb) {
10986 : 0 : ret = i40e_config_switch_comp_tc(main_vsi->veb, tc_map);
10987 [ # # ]: 0 : if (ret)
10988 : 0 : PMD_INIT_LOG(WARNING,
10989 : : "Failed configuring TC for VEB seid=%d",
10990 : : main_vsi->veb->seid);
10991 : : }
10992 : : /* Update each VSI */
10993 : 0 : i40e_vsi_config_tc(main_vsi, tc_map);
10994 [ # # ]: 0 : if (main_vsi->veb) {
10995 [ # # ]: 0 : TAILQ_FOREACH(vsi_list, &main_vsi->veb->head, list) {
10996 : : /* Beside main VSI and VMDQ VSIs, only enable default
10997 : : * TC for other VSIs
10998 : : */
10999 [ # # ]: 0 : if (vsi_list->vsi->type == I40E_VSI_VMDQ2)
11000 : 0 : ret = i40e_vsi_config_tc(vsi_list->vsi,
11001 : : tc_map);
11002 : : else
11003 : 0 : ret = i40e_vsi_config_tc(vsi_list->vsi,
11004 : : I40E_DEFAULT_TCMAP);
11005 [ # # ]: 0 : if (ret)
11006 : 0 : PMD_INIT_LOG(WARNING,
11007 : : "Failed configuring TC for VSI seid=%d",
11008 : : vsi_list->vsi->seid);
11009 : : /* continue */
11010 : : }
11011 : : }
11012 : : return I40E_SUCCESS;
11013 : : }
11014 : :
11015 : : /*
11016 : : * i40e_dcb_init_configure - initial dcb config
11017 : : * @dev: device being configured
11018 : : * @sw_dcb: indicate whether dcb is sw configured or hw offload
11019 : : *
11020 : : * Returns 0 on success, negative value on failure
11021 : : */
11022 : : int
11023 : 0 : i40e_dcb_init_configure(struct rte_eth_dev *dev, bool sw_dcb)
11024 : : {
11025 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11026 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11027 : : int i, ret = 0;
11028 : :
11029 [ # # ]: 0 : if ((pf->flags & I40E_FLAG_DCB) == 0) {
11030 : 0 : PMD_INIT_LOG(ERR, "HW doesn't support DCB");
11031 : 0 : return -ENOTSUP;
11032 : : }
11033 : :
11034 : : /* DCB initialization:
11035 : : * Update DCB configuration from the Firmware and configure
11036 : : * LLDP MIB change event.
11037 : : */
11038 [ # # ]: 0 : if (sw_dcb == TRUE) {
11039 : : /* Stopping lldp is necessary for DPDK, but it will cause
11040 : : * DCB init failed. For i40e_init_dcb(), the prerequisite
11041 : : * for successful initialization of DCB is that LLDP is
11042 : : * enabled. So it is needed to start lldp before DCB init
11043 : : * and stop it after initialization.
11044 : : */
11045 : 0 : ret = i40e_aq_start_lldp(hw, true, NULL);
11046 [ # # ]: 0 : if (ret != I40E_SUCCESS)
11047 : 0 : PMD_INIT_LOG(DEBUG, "Failed to start lldp");
11048 : :
11049 : 0 : ret = i40e_init_dcb(hw, true);
11050 : : /* If lldp agent is stopped, the return value from
11051 : : * i40e_init_dcb we expect is failure with I40E_AQ_RC_EPERM
11052 : : * adminq status. Otherwise, it should return success.
11053 : : */
11054 [ # # ]: 0 : if ((ret == I40E_SUCCESS) || (ret != I40E_SUCCESS &&
11055 [ # # ]: 0 : hw->aq.asq_last_status == I40E_AQ_RC_EPERM)) {
11056 : 0 : memset(&hw->local_dcbx_config, 0,
11057 : : sizeof(struct i40e_dcbx_config));
11058 : : /* set dcb default configuration */
11059 : : hw->local_dcbx_config.etscfg.willing = 0;
11060 : : hw->local_dcbx_config.etscfg.maxtcs = 0;
11061 : 0 : hw->local_dcbx_config.etscfg.tcbwtable[0] = 100;
11062 : 0 : hw->local_dcbx_config.etscfg.tsatable[0] =
11063 : : I40E_IEEE_TSA_ETS;
11064 : : /* all UPs mapping to TC0 */
11065 [ # # ]: 0 : for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
11066 : 0 : hw->local_dcbx_config.etscfg.prioritytable[i] = 0;
11067 : 0 : hw->local_dcbx_config.etsrec =
11068 : : hw->local_dcbx_config.etscfg;
11069 : : hw->local_dcbx_config.pfc.willing = 0;
11070 : 0 : hw->local_dcbx_config.pfc.pfccap =
11071 : : I40E_MAX_TRAFFIC_CLASS;
11072 : : /* FW needs one App to configure HW */
11073 : 0 : hw->local_dcbx_config.numapps = 1;
11074 : 0 : hw->local_dcbx_config.app[0].selector =
11075 : : I40E_APP_SEL_ETHTYPE;
11076 : 0 : hw->local_dcbx_config.app[0].priority = 3;
11077 : 0 : hw->local_dcbx_config.app[0].protocolid =
11078 : : I40E_APP_PROTOID_FCOE;
11079 : 0 : ret = i40e_set_dcb_config(hw);
11080 [ # # ]: 0 : if (ret) {
11081 : 0 : PMD_INIT_LOG(ERR,
11082 : : "default dcb config fails. err = %d, aq_err = %d.",
11083 : : ret, hw->aq.asq_last_status);
11084 : 0 : return -ENOSYS;
11085 : : }
11086 : : } else {
11087 : 0 : PMD_INIT_LOG(ERR,
11088 : : "DCB initialization in FW fails, err = %d, aq_err = %d.",
11089 : : ret, hw->aq.asq_last_status);
11090 : 0 : return -ENOTSUP;
11091 : : }
11092 : :
11093 [ # # ]: 0 : if (i40e_need_stop_lldp(dev)) {
11094 : 0 : ret = i40e_aq_stop_lldp(hw, true, true, NULL);
11095 [ # # ]: 0 : if (ret != I40E_SUCCESS)
11096 : 0 : PMD_INIT_LOG(DEBUG, "Failed to stop lldp");
11097 : : }
11098 : : } else {
11099 : 0 : ret = i40e_aq_start_lldp(hw, true, NULL);
11100 [ # # ]: 0 : if (ret != I40E_SUCCESS)
11101 : 0 : PMD_INIT_LOG(DEBUG, "Failed to start lldp");
11102 : :
11103 : 0 : ret = i40e_init_dcb(hw, true);
11104 [ # # ]: 0 : if (!ret) {
11105 [ # # ]: 0 : if (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED) {
11106 : 0 : PMD_INIT_LOG(ERR,
11107 : : "HW doesn't support DCBX offload.");
11108 : 0 : return -ENOTSUP;
11109 : : }
11110 : : } else {
11111 : 0 : PMD_INIT_LOG(ERR,
11112 : : "DCBX configuration failed, err = %d, aq_err = %d.",
11113 : : ret, hw->aq.asq_last_status);
11114 : 0 : return -ENOTSUP;
11115 : : }
11116 : : }
11117 : : return 0;
11118 : : }
11119 : :
11120 : : /*
11121 : : * i40e_dcb_setup - setup dcb related config
11122 : : * @dev: device being configured
11123 : : *
11124 : : * Returns 0 on success, negative value on failure
11125 : : */
11126 : : static int
11127 : 0 : i40e_dcb_setup(struct rte_eth_dev *dev)
11128 : : {
11129 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11130 : : struct i40e_dcbx_config dcb_cfg;
11131 : 0 : uint8_t tc_map = 0;
11132 : : int ret = 0;
11133 : :
11134 [ # # ]: 0 : if ((pf->flags & I40E_FLAG_DCB) == 0) {
11135 : 0 : PMD_INIT_LOG(ERR, "HW doesn't support DCB");
11136 : 0 : return -ENOTSUP;
11137 : : }
11138 : :
11139 [ # # ]: 0 : if (pf->vf_num != 0)
11140 : 0 : PMD_INIT_LOG(DEBUG, " DCB only works on pf and vmdq vsis.");
11141 : :
11142 : 0 : ret = i40e_parse_dcb_configure(dev, &dcb_cfg, &tc_map);
11143 [ # # ]: 0 : if (ret) {
11144 : 0 : PMD_INIT_LOG(ERR, "invalid dcb config");
11145 : 0 : return -EINVAL;
11146 : : }
11147 : 0 : ret = i40e_dcb_hw_configure(pf, &dcb_cfg, tc_map);
11148 [ # # ]: 0 : if (ret) {
11149 : 0 : PMD_INIT_LOG(ERR, "dcb sw configure fails");
11150 : 0 : return -ENOSYS;
11151 : : }
11152 : :
11153 : : return 0;
11154 : : }
11155 : :
11156 : : static int
11157 : 0 : i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
11158 : : struct rte_eth_dcb_info *dcb_info)
11159 : : {
11160 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11161 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11162 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
11163 : : struct i40e_dcbx_config *dcb_cfg = &hw->local_dcbx_config;
11164 : : uint16_t bsf, tc_mapping;
11165 : : int i, j = 0;
11166 : :
11167 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_DCB_FLAG)
11168 : 0 : dcb_info->nb_tcs = rte_bsf32(vsi->enabled_tc + 1);
11169 : : else
11170 : 0 : dcb_info->nb_tcs = 1;
11171 [ # # ]: 0 : for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
11172 : 0 : dcb_info->prio_tc[i] = dcb_cfg->etscfg.prioritytable[i];
11173 [ # # ]: 0 : for (i = 0; i < dcb_info->nb_tcs; i++)
11174 : 0 : dcb_info->tc_bws[i] = dcb_cfg->etscfg.tcbwtable[i];
11175 : :
11176 : : /* get queue mapping if vmdq is disabled */
11177 [ # # ]: 0 : if (!pf->nb_cfg_vmdq_vsi) {
11178 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11179 [ # # ]: 0 : if (!(vsi->enabled_tc & (1 << i)))
11180 : 0 : continue;
11181 : 0 : tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
11182 : 0 : dcb_info->tc_queue.tc_rxq[j][i].base =
11183 : 0 : (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
11184 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
11185 : 0 : dcb_info->tc_queue.tc_txq[j][i].base =
11186 : : dcb_info->tc_queue.tc_rxq[j][i].base;
11187 : 0 : bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
11188 : : I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
11189 : 0 : dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
11190 : 0 : dcb_info->tc_queue.tc_txq[j][i].nb_queue =
11191 : : dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
11192 : : }
11193 : : return 0;
11194 : : }
11195 : :
11196 : : /* get queue mapping if vmdq is enabled */
11197 : : do {
11198 : 0 : vsi = pf->vmdq[j].vsi;
11199 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11200 [ # # ]: 0 : if (!(vsi->enabled_tc & (1 << i)))
11201 : 0 : continue;
11202 : 0 : tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
11203 : 0 : dcb_info->tc_queue.tc_rxq[j][i].base =
11204 : 0 : (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
11205 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
11206 : 0 : dcb_info->tc_queue.tc_txq[j][i].base =
11207 : : dcb_info->tc_queue.tc_rxq[j][i].base;
11208 : 0 : bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
11209 : : I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
11210 : 0 : dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
11211 : 0 : dcb_info->tc_queue.tc_txq[j][i].nb_queue =
11212 : : dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
11213 : : }
11214 : 0 : j++;
11215 [ # # ]: 0 : } while (j < RTE_MIN(pf->nb_cfg_vmdq_vsi, RTE_ETH_MAX_VMDQ_POOL));
11216 : : return 0;
11217 : : }
11218 : :
11219 : : static int
11220 : 0 : i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
11221 : : {
11222 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
11223 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
11224 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11225 : : uint16_t msix_intr;
11226 : :
11227 : 0 : msix_intr = rte_intr_vec_list_index_get(intr_handle, queue_id);
11228 [ # # ]: 0 : if (msix_intr == I40E_MISC_VEC_ID)
11229 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
11230 : : I40E_PFINT_DYN_CTL0_INTENA_MASK |
11231 : : I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
11232 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
11233 : : else
11234 : 0 : I40E_WRITE_REG(hw,
11235 : : I40E_PFINT_DYN_CTLN(msix_intr -
11236 : : I40E_RX_VEC_START),
11237 : : I40E_PFINT_DYN_CTLN_INTENA_MASK |
11238 : : I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
11239 : : I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
11240 : :
11241 : 0 : I40E_WRITE_FLUSH(hw);
11242 : 0 : rte_intr_ack(pci_dev->intr_handle);
11243 : :
11244 : 0 : return 0;
11245 : : }
11246 : :
11247 : : static int
11248 : 0 : i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
11249 : : {
11250 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
11251 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
11252 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11253 : : uint16_t msix_intr;
11254 : :
11255 : 0 : msix_intr = rte_intr_vec_list_index_get(intr_handle, queue_id);
11256 [ # # ]: 0 : if (msix_intr == I40E_MISC_VEC_ID)
11257 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
11258 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
11259 : : else
11260 : 0 : I40E_WRITE_REG(hw,
11261 : : I40E_PFINT_DYN_CTLN(msix_intr -
11262 : : I40E_RX_VEC_START),
11263 : : I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
11264 : 0 : I40E_WRITE_FLUSH(hw);
11265 : :
11266 : 0 : return 0;
11267 : : }
11268 : :
11269 : : /**
11270 : : * This function is used to check if the register is valid.
11271 : : * Below is the valid registers list for X722 only:
11272 : : * 0x2b800--0x2bb00
11273 : : * 0x38700--0x38a00
11274 : : * 0x3d800--0x3db00
11275 : : * 0x208e00--0x209000
11276 : : * 0x20be00--0x20c000
11277 : : * 0x263c00--0x264000
11278 : : * 0x265c00--0x266000
11279 : : */
11280 : 0 : static inline int i40e_valid_regs(enum i40e_mac_type type, uint32_t reg_offset)
11281 : : {
11282 [ # # ]: 0 : if ((type != I40E_MAC_X722) &&
11283 : 0 : ((reg_offset >= 0x2b800 && reg_offset <= 0x2bb00) ||
11284 [ # # ]: 0 : (reg_offset >= 0x38700 && reg_offset <= 0x38a00) ||
11285 [ # # ]: 0 : (reg_offset >= 0x3d800 && reg_offset <= 0x3db00) ||
11286 [ # # ]: 0 : (reg_offset >= 0x208e00 && reg_offset <= 0x209000) ||
11287 [ # # ]: 0 : (reg_offset >= 0x20be00 && reg_offset <= 0x20c000) ||
11288 [ # # ]: 0 : (reg_offset >= 0x263c00 && reg_offset <= 0x264000) ||
11289 [ # # ]: 0 : (reg_offset >= 0x265c00 && reg_offset <= 0x266000)))
11290 : : return 0;
11291 : : else
11292 : 0 : return 1;
11293 : : }
11294 : :
11295 : 0 : static int i40e_get_regs(struct rte_eth_dev *dev,
11296 : : struct rte_dev_reg_info *regs)
11297 : : {
11298 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11299 : 0 : uint32_t *ptr_data = regs->data;
11300 : : uint32_t reg_idx, arr_idx, arr_idx2, reg_offset;
11301 : : const struct i40e_reg_info *reg_info;
11302 : :
11303 [ # # ]: 0 : if (ptr_data == NULL) {
11304 : 0 : regs->length = I40E_GLGEN_STAT_CLEAR + 4;
11305 : 0 : regs->width = sizeof(uint32_t);
11306 : 0 : return 0;
11307 : : }
11308 : :
11309 : : /* The first few registers have to be read using AQ operations */
11310 : : reg_idx = 0;
11311 [ # # ]: 0 : while (i40e_regs_adminq[reg_idx].name) {
11312 : 0 : reg_info = &i40e_regs_adminq[reg_idx++];
11313 [ # # ]: 0 : for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
11314 : : for (arr_idx2 = 0;
11315 [ # # ]: 0 : arr_idx2 <= reg_info->count2;
11316 : 0 : arr_idx2++) {
11317 : 0 : reg_offset = arr_idx * reg_info->stride1 +
11318 : 0 : arr_idx2 * reg_info->stride2;
11319 : 0 : reg_offset += reg_info->base_addr;
11320 : 0 : ptr_data[reg_offset >> 2] =
11321 : 0 : i40e_read_rx_ctl(hw, reg_offset);
11322 : : }
11323 : : }
11324 : :
11325 : : /* The remaining registers can be read using primitives */
11326 : : reg_idx = 0;
11327 [ # # ]: 0 : while (i40e_regs_others[reg_idx].name) {
11328 : 0 : reg_info = &i40e_regs_others[reg_idx++];
11329 [ # # ]: 0 : for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
11330 : : for (arr_idx2 = 0;
11331 [ # # ]: 0 : arr_idx2 <= reg_info->count2;
11332 : 0 : arr_idx2++) {
11333 : 0 : reg_offset = arr_idx * reg_info->stride1 +
11334 : 0 : arr_idx2 * reg_info->stride2;
11335 : 0 : reg_offset += reg_info->base_addr;
11336 [ # # ]: 0 : if (!i40e_valid_regs(hw->mac.type, reg_offset))
11337 : 0 : ptr_data[reg_offset >> 2] = 0;
11338 : : else
11339 : 0 : ptr_data[reg_offset >> 2] =
11340 : 0 : I40E_READ_REG(hw, reg_offset);
11341 : : }
11342 : : }
11343 : :
11344 : : return 0;
11345 : : }
11346 : :
11347 : 0 : static int i40e_get_eeprom_length(struct rte_eth_dev *dev)
11348 : : {
11349 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11350 : :
11351 : : /* Convert word count to byte count */
11352 : 0 : return hw->nvm.sr_size << 1;
11353 : : }
11354 : :
11355 : 0 : static int i40e_get_eeprom(struct rte_eth_dev *dev,
11356 : : struct rte_dev_eeprom_info *eeprom)
11357 : : {
11358 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11359 : 0 : uint16_t *data = eeprom->data;
11360 : : uint16_t offset, length, cnt_words;
11361 : : int ret_code;
11362 : :
11363 : 0 : offset = eeprom->offset >> 1;
11364 : 0 : length = eeprom->length >> 1;
11365 : 0 : cnt_words = length;
11366 : :
11367 [ # # ]: 0 : if (offset > hw->nvm.sr_size ||
11368 [ # # ]: 0 : offset + length > hw->nvm.sr_size) {
11369 : 0 : PMD_DRV_LOG(ERR, "Requested EEPROM bytes out of range.");
11370 : 0 : return -EINVAL;
11371 : : }
11372 : :
11373 : 0 : eeprom->magic = hw->vendor_id | (hw->device_id << 16);
11374 : :
11375 : 0 : ret_code = i40e_read_nvm_buffer(hw, offset, &cnt_words, data);
11376 [ # # # # ]: 0 : if (ret_code != I40E_SUCCESS || cnt_words != length) {
11377 : 0 : PMD_DRV_LOG(ERR, "EEPROM read failed.");
11378 : 0 : return -EIO;
11379 : : }
11380 : :
11381 : : return 0;
11382 : : }
11383 : :
11384 : 0 : static int i40e_get_module_info(struct rte_eth_dev *dev,
11385 : : struct rte_eth_dev_module_info *modinfo)
11386 : : {
11387 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11388 : 0 : uint32_t sff8472_comp = 0;
11389 : 0 : uint32_t sff8472_swap = 0;
11390 : 0 : uint32_t sff8636_rev = 0;
11391 : : i40e_status status;
11392 : : uint32_t type = 0;
11393 : :
11394 : : /* Check if firmware supports reading module EEPROM. */
11395 [ # # ]: 0 : if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
11396 : 0 : PMD_DRV_LOG(ERR,
11397 : : "Module EEPROM memory read not supported. "
11398 : : "Please update the NVM image.");
11399 : 0 : return -EINVAL;
11400 : : }
11401 : :
11402 : 0 : status = i40e_update_link_info(hw);
11403 [ # # ]: 0 : if (status)
11404 : : return -EIO;
11405 : :
11406 [ # # ]: 0 : if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
11407 : 0 : PMD_DRV_LOG(ERR,
11408 : : "Cannot read module EEPROM memory. "
11409 : : "No module connected.");
11410 : 0 : return -EINVAL;
11411 : : }
11412 : :
11413 : 0 : type = hw->phy.link_info.module_type[0];
11414 : :
11415 [ # # # # ]: 0 : switch (type) {
11416 : 0 : case I40E_MODULE_TYPE_SFP:
11417 : 0 : status = i40e_aq_get_phy_register(hw,
11418 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11419 : : I40E_I2C_EEPROM_DEV_ADDR, 1,
11420 : : I40E_MODULE_SFF_8472_COMP,
11421 : : &sff8472_comp, NULL);
11422 [ # # ]: 0 : if (status)
11423 : : return -EIO;
11424 : :
11425 : 0 : status = i40e_aq_get_phy_register(hw,
11426 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11427 : : I40E_I2C_EEPROM_DEV_ADDR, 1,
11428 : : I40E_MODULE_SFF_8472_SWAP,
11429 : : &sff8472_swap, NULL);
11430 [ # # ]: 0 : if (status)
11431 : : return -EIO;
11432 : :
11433 : : /* Check if the module requires address swap to access
11434 : : * the other EEPROM memory page.
11435 : : */
11436 [ # # ]: 0 : if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
11437 : 0 : PMD_DRV_LOG(WARNING,
11438 : : "Module address swap to access "
11439 : : "page 0xA2 is not supported.");
11440 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8079;
11441 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
11442 [ # # ]: 0 : } else if (sff8472_comp == 0x00) {
11443 : : /* Module is not SFF-8472 compliant */
11444 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8079;
11445 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
11446 : : } else {
11447 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8472;
11448 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8472_LEN;
11449 : : }
11450 : : break;
11451 : 0 : case I40E_MODULE_TYPE_QSFP_PLUS:
11452 : : /* Read from memory page 0. */
11453 : 0 : status = i40e_aq_get_phy_register(hw,
11454 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11455 : : 0, 1,
11456 : : I40E_MODULE_REVISION_ADDR,
11457 : : &sff8636_rev, NULL);
11458 [ # # ]: 0 : if (status)
11459 : : return -EIO;
11460 : : /* Determine revision compliance byte */
11461 [ # # ]: 0 : if (sff8636_rev > 0x02) {
11462 : : /* Module is SFF-8636 compliant */
11463 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8636;
11464 : 0 : modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
11465 : : } else {
11466 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8436;
11467 : 0 : modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
11468 : : }
11469 : : break;
11470 : 0 : case I40E_MODULE_TYPE_QSFP28:
11471 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8636;
11472 : 0 : modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
11473 : 0 : break;
11474 : 0 : default:
11475 : 0 : PMD_DRV_LOG(ERR, "Module type unrecognized");
11476 : 0 : return -EINVAL;
11477 : : }
11478 : : return 0;
11479 : : }
11480 : :
11481 : 0 : static int i40e_get_module_eeprom(struct rte_eth_dev *dev,
11482 : : struct rte_dev_eeprom_info *info)
11483 : : {
11484 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11485 : : bool is_sfp = false;
11486 : : i40e_status status;
11487 : : uint8_t *data;
11488 : 0 : uint32_t value = 0;
11489 : : uint32_t i;
11490 : :
11491 [ # # ]: 0 : if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
11492 : : is_sfp = true;
11493 : :
11494 : 0 : data = info->data;
11495 [ # # ]: 0 : for (i = 0; i < info->length; i++) {
11496 : 0 : u32 offset = i + info->offset;
11497 [ # # ]: 0 : u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
11498 : :
11499 : : /* Check if we need to access the other memory page */
11500 [ # # ]: 0 : if (is_sfp) {
11501 [ # # ]: 0 : if (offset >= RTE_ETH_MODULE_SFF_8079_LEN) {
11502 : 0 : offset -= RTE_ETH_MODULE_SFF_8079_LEN;
11503 : : addr = I40E_I2C_EEPROM_DEV_ADDR2;
11504 : : }
11505 : : } else {
11506 [ # # ]: 0 : while (offset >= RTE_ETH_MODULE_SFF_8436_LEN) {
11507 : : /* Compute memory page number and offset. */
11508 : 0 : offset -= RTE_ETH_MODULE_SFF_8436_LEN / 2;
11509 : 0 : addr++;
11510 : : }
11511 : : }
11512 : 0 : status = i40e_aq_get_phy_register(hw,
11513 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11514 : : addr, 1, offset, &value, NULL);
11515 [ # # ]: 0 : if (status)
11516 : : return -EIO;
11517 : 0 : data[i] = (uint8_t)value;
11518 : : }
11519 : : return 0;
11520 : : }
11521 : :
11522 : 0 : static int i40e_set_default_mac_addr(struct rte_eth_dev *dev,
11523 : : struct rte_ether_addr *mac_addr)
11524 : : {
11525 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11526 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11527 [ # # ]: 0 : struct i40e_vsi *vsi = pf->main_vsi;
11528 : : struct i40e_mac_filter_info mac_filter;
11529 : : struct i40e_mac_filter *f;
11530 : : int ret;
11531 : :
11532 : : if (!rte_is_valid_assigned_ether_addr(mac_addr)) {
11533 : 0 : PMD_DRV_LOG(ERR, "Tried to set invalid MAC address.");
11534 : 0 : return -EINVAL;
11535 : : }
11536 : :
11537 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
11538 [ # # ]: 0 : if (rte_is_same_ether_addr(&pf->dev_addr,
11539 : : &f->mac_info.mac_addr))
11540 : : break;
11541 : : }
11542 : :
11543 [ # # ]: 0 : if (f == NULL) {
11544 : 0 : PMD_DRV_LOG(ERR, "Failed to find filter for default mac");
11545 : 0 : return -EIO;
11546 : : }
11547 : :
11548 : 0 : mac_filter = f->mac_info;
11549 : 0 : ret = i40e_vsi_delete_mac(vsi, &mac_filter.mac_addr);
11550 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
11551 : 0 : PMD_DRV_LOG(ERR, "Failed to delete mac filter");
11552 : 0 : return -EIO;
11553 : : }
11554 : : memcpy(&mac_filter.mac_addr, mac_addr, ETH_ADDR_LEN);
11555 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter);
11556 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
11557 : 0 : PMD_DRV_LOG(ERR, "Failed to add mac filter");
11558 : 0 : return -EIO;
11559 : : }
11560 : 0 : memcpy(&pf->dev_addr, mac_addr, ETH_ADDR_LEN);
11561 : :
11562 : 0 : ret = i40e_aq_mac_address_write(hw, I40E_AQC_WRITE_TYPE_LAA_WOL,
11563 : 0 : mac_addr->addr_bytes, NULL);
11564 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
11565 : 0 : PMD_DRV_LOG(ERR, "Failed to change mac");
11566 : 0 : return -EIO;
11567 : : }
11568 : :
11569 : : return 0;
11570 : : }
11571 : :
11572 : : static int
11573 : 0 : i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu __rte_unused)
11574 : : {
11575 : : /* mtu setting is forbidden if port is start */
11576 [ # # ]: 0 : if (dev->data->dev_started != 0) {
11577 : 0 : PMD_DRV_LOG(ERR, "port %d must be stopped before configuration",
11578 : : dev->data->port_id);
11579 : 0 : return -EBUSY;
11580 : : }
11581 : :
11582 : : return 0;
11583 : : }
11584 : :
11585 : : /* Restore ethertype filter */
11586 : : static void
11587 : 0 : i40e_ethertype_filter_restore(struct i40e_pf *pf)
11588 : : {
11589 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11590 : : struct i40e_ethertype_filter_list
11591 : : *ethertype_list = &pf->ethertype.ethertype_list;
11592 : : struct i40e_ethertype_filter *f;
11593 : : struct i40e_control_filter_stats stats;
11594 : : uint16_t flags;
11595 : :
11596 [ # # ]: 0 : TAILQ_FOREACH(f, ethertype_list, rules) {
11597 : : flags = 0;
11598 [ # # ]: 0 : if (!(f->flags & RTE_ETHTYPE_FLAGS_MAC))
11599 : : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
11600 [ # # ]: 0 : if (f->flags & RTE_ETHTYPE_FLAGS_DROP)
11601 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
11602 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
11603 : :
11604 : : memset(&stats, 0, sizeof(stats));
11605 : 0 : i40e_aq_add_rem_control_packet_filter(hw,
11606 : 0 : f->input.mac_addr.addr_bytes,
11607 : 0 : f->input.ether_type,
11608 : 0 : flags, pf->main_vsi->seid,
11609 : 0 : f->queue, 1, &stats, NULL);
11610 : : }
11611 : 0 : PMD_DRV_LOG(INFO, "Ethertype filter:"
11612 : : " mac_etype_used = %u, etype_used = %u,"
11613 : : " mac_etype_free = %u, etype_free = %u",
11614 : : stats.mac_etype_used, stats.etype_used,
11615 : : stats.mac_etype_free, stats.etype_free);
11616 : 0 : }
11617 : :
11618 : : /* Restore tunnel filter */
11619 : : static void
11620 : 0 : i40e_tunnel_filter_restore(struct i40e_pf *pf)
11621 : : {
11622 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11623 : : struct i40e_vsi *vsi;
11624 : : struct i40e_pf_vf *vf;
11625 : : struct i40e_tunnel_filter_list
11626 : : *tunnel_list = &pf->tunnel.tunnel_list;
11627 : : struct i40e_tunnel_filter *f;
11628 : : struct i40e_aqc_cloud_filters_element_bb cld_filter;
11629 : : bool big_buffer = 0;
11630 : :
11631 [ # # ]: 0 : TAILQ_FOREACH(f, tunnel_list, rules) {
11632 [ # # ]: 0 : if (!f->is_to_vf)
11633 : 0 : vsi = pf->main_vsi;
11634 : : else {
11635 : 0 : vf = &pf->vfs[f->vf_id];
11636 : 0 : vsi = vf->vsi;
11637 : : }
11638 : : memset(&cld_filter, 0, sizeof(cld_filter));
11639 : : rte_ether_addr_copy((struct rte_ether_addr *)
11640 : : &f->input.outer_mac,
11641 : : (struct rte_ether_addr *)&cld_filter.element.outer_mac);
11642 : : rte_ether_addr_copy((struct rte_ether_addr *)
11643 : : &f->input.inner_mac,
11644 : : (struct rte_ether_addr *)&cld_filter.element.inner_mac);
11645 : 0 : cld_filter.element.inner_vlan = f->input.inner_vlan;
11646 : 0 : cld_filter.element.flags = f->input.flags;
11647 : 0 : cld_filter.element.tenant_id = f->input.tenant_id;
11648 : 0 : cld_filter.element.queue_number = f->queue;
11649 : : rte_memcpy(cld_filter.general_fields,
11650 [ # # ]: 0 : f->input.general_fields,
11651 : : sizeof(f->input.general_fields));
11652 : :
11653 [ # # ]: 0 : if (((f->input.flags &
11654 : : I40E_AQC_ADD_CLOUD_FILTER_0X11) ==
11655 [ # # ]: 0 : I40E_AQC_ADD_CLOUD_FILTER_0X11) ||
11656 : : ((f->input.flags &
11657 : : I40E_AQC_ADD_CLOUD_FILTER_0X12) ==
11658 [ # # ]: 0 : I40E_AQC_ADD_CLOUD_FILTER_0X12) ||
11659 : : ((f->input.flags &
11660 : : I40E_AQC_ADD_CLOUD_FILTER_0X10) ==
11661 : : I40E_AQC_ADD_CLOUD_FILTER_0X10))
11662 : : big_buffer = 1;
11663 : :
11664 [ # # ]: 0 : if (big_buffer)
11665 : 0 : i40e_aq_add_cloud_filters_bb(hw,
11666 : 0 : vsi->seid, &cld_filter, 1);
11667 : : else
11668 : 0 : i40e_aq_add_cloud_filters(hw, vsi->seid,
11669 : : &cld_filter.element, 1);
11670 : : }
11671 : 0 : }
11672 : :
11673 : : static void
11674 : 0 : i40e_filter_restore(struct i40e_pf *pf)
11675 : : {
11676 : 0 : i40e_ethertype_filter_restore(pf);
11677 : 0 : i40e_tunnel_filter_restore(pf);
11678 : 0 : i40e_fdir_filter_restore(pf);
11679 : 0 : (void)i40e_hash_filter_restore(pf);
11680 : 0 : }
11681 : :
11682 : : bool
11683 : 0 : is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
11684 : : {
11685 [ # # ]: 0 : if (strcmp(dev->device->driver->name, drv->driver.name))
11686 : 0 : return false;
11687 : :
11688 : : return true;
11689 : : }
11690 : :
11691 : : bool
11692 : 0 : is_i40e_supported(struct rte_eth_dev *dev)
11693 : : {
11694 : 0 : return is_device_supported(dev, &rte_i40e_pmd);
11695 : : }
11696 : :
11697 : : struct i40e_customized_pctype*
11698 : 0 : i40e_find_customized_pctype(struct i40e_pf *pf, uint8_t index)
11699 : : {
11700 : : int i;
11701 : :
11702 [ # # ]: 0 : for (i = 0; i < I40E_CUSTOMIZED_MAX; i++) {
11703 [ # # ]: 0 : if (pf->customized_pctype[i].index == index)
11704 : 0 : return &pf->customized_pctype[i];
11705 : : }
11706 : : return NULL;
11707 : : }
11708 : :
11709 : : static int
11710 : 0 : i40e_update_customized_pctype(struct rte_eth_dev *dev, uint8_t *pkg,
11711 : : uint32_t pkg_size, uint32_t proto_num,
11712 : : struct rte_pmd_i40e_proto_info *proto,
11713 : : enum rte_pmd_i40e_package_op op)
11714 : : {
11715 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11716 : : uint32_t pctype_num;
11717 : 0 : struct rte_pmd_i40e_ptype_info pctype[I40E_CUSTOMIZED_MAX] = {0};
11718 : : struct i40e_customized_pctype *new_pctype = NULL;
11719 : : uint8_t proto_id;
11720 : : uint8_t pctype_value;
11721 : : char name[64];
11722 : : uint32_t i, j, n;
11723 : : int ret;
11724 : :
11725 [ # # ]: 0 : if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
11726 : : op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
11727 : 0 : PMD_DRV_LOG(ERR, "Unsupported operation.");
11728 : 0 : return -1;
11729 : : }
11730 : :
11731 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11732 : : (uint8_t *)&pctype_num, sizeof(pctype_num),
11733 : : RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
11734 [ # # ]: 0 : if (ret) {
11735 : 0 : PMD_DRV_LOG(ERR, "Failed to get pctype number");
11736 : 0 : return -1;
11737 : : }
11738 [ # # ]: 0 : if (!pctype_num) {
11739 : 0 : PMD_DRV_LOG(INFO, "No new pctype added");
11740 : 0 : return -1;
11741 : : }
11742 : :
11743 [ # # ]: 0 : if (pctype_num > RTE_DIM(pctype)) {
11744 : 0 : PMD_DRV_LOG(ERR, "Pctype number exceeds maximum supported");
11745 : 0 : return -1;
11746 : : }
11747 : : /* get information about new pctype list */
11748 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11749 : : (uint8_t *)pctype, sizeof(pctype),
11750 : : RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
11751 [ # # ]: 0 : if (ret) {
11752 : 0 : PMD_DRV_LOG(ERR, "Failed to get pctype list");
11753 : 0 : return -1;
11754 : : }
11755 : :
11756 : : /* Update customized pctype. */
11757 [ # # ]: 0 : for (i = 0; i < pctype_num; i++) {
11758 : 0 : pctype_value = pctype[i].ptype_id;
11759 : : memset(name, 0, sizeof(name));
11760 [ # # ]: 0 : for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
11761 : 0 : proto_id = pctype[i].protocols[j];
11762 [ # # ]: 0 : if (proto_id == RTE_PMD_I40E_PROTO_UNUSED)
11763 : 0 : continue;
11764 [ # # ]: 0 : for (n = 0; n < proto_num; n++) {
11765 [ # # ]: 0 : if (proto[n].proto_id != proto_id)
11766 : : continue;
11767 : 0 : strlcat(name, proto[n].name, sizeof(name));
11768 : 0 : strlcat(name, "_", sizeof(name));
11769 : 0 : break;
11770 : : }
11771 : : }
11772 : 0 : name[strlen(name) - 1] = '\0';
11773 : 0 : PMD_DRV_LOG(INFO, "name = %s", name);
11774 [ # # ]: 0 : if (!strcmp(name, "GTPC"))
11775 : : new_pctype =
11776 : 0 : i40e_find_customized_pctype(pf,
11777 : : I40E_CUSTOMIZED_GTPC);
11778 [ # # ]: 0 : else if (!strcmp(name, "GTPU_IPV4"))
11779 : : new_pctype =
11780 : 0 : i40e_find_customized_pctype(pf,
11781 : : I40E_CUSTOMIZED_GTPU_IPV4);
11782 [ # # ]: 0 : else if (!strcmp(name, "GTPU_IPV6"))
11783 : : new_pctype =
11784 : 0 : i40e_find_customized_pctype(pf,
11785 : : I40E_CUSTOMIZED_GTPU_IPV6);
11786 [ # # ]: 0 : else if (!strcmp(name, "GTPU"))
11787 : : new_pctype =
11788 : 0 : i40e_find_customized_pctype(pf,
11789 : : I40E_CUSTOMIZED_GTPU);
11790 [ # # ]: 0 : else if (!strcmp(name, "IPV4_L2TPV3"))
11791 : : new_pctype =
11792 : 0 : i40e_find_customized_pctype(pf,
11793 : : I40E_CUSTOMIZED_IPV4_L2TPV3);
11794 [ # # ]: 0 : else if (!strcmp(name, "IPV6_L2TPV3"))
11795 : : new_pctype =
11796 : 0 : i40e_find_customized_pctype(pf,
11797 : : I40E_CUSTOMIZED_IPV6_L2TPV3);
11798 [ # # ]: 0 : else if (!strcmp(name, "IPV4_ESP"))
11799 : : new_pctype =
11800 : 0 : i40e_find_customized_pctype(pf,
11801 : : I40E_CUSTOMIZED_ESP_IPV4);
11802 [ # # ]: 0 : else if (!strcmp(name, "IPV6_ESP"))
11803 : : new_pctype =
11804 : 0 : i40e_find_customized_pctype(pf,
11805 : : I40E_CUSTOMIZED_ESP_IPV6);
11806 [ # # ]: 0 : else if (!strcmp(name, "IPV4_UDP_ESP"))
11807 : : new_pctype =
11808 : 0 : i40e_find_customized_pctype(pf,
11809 : : I40E_CUSTOMIZED_ESP_IPV4_UDP);
11810 [ # # ]: 0 : else if (!strcmp(name, "IPV6_UDP_ESP"))
11811 : : new_pctype =
11812 : 0 : i40e_find_customized_pctype(pf,
11813 : : I40E_CUSTOMIZED_ESP_IPV6_UDP);
11814 [ # # ]: 0 : else if (!strcmp(name, "IPV4_AH"))
11815 : : new_pctype =
11816 : 0 : i40e_find_customized_pctype(pf,
11817 : : I40E_CUSTOMIZED_AH_IPV4);
11818 [ # # ]: 0 : else if (!strcmp(name, "IPV6_AH"))
11819 : : new_pctype =
11820 : 0 : i40e_find_customized_pctype(pf,
11821 : : I40E_CUSTOMIZED_AH_IPV6);
11822 [ # # ]: 0 : if (new_pctype) {
11823 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_ADD) {
11824 : 0 : new_pctype->pctype = pctype_value;
11825 : 0 : new_pctype->valid = true;
11826 : : } else {
11827 : 0 : new_pctype->pctype = I40E_FILTER_PCTYPE_INVALID;
11828 : 0 : new_pctype->valid = false;
11829 : : }
11830 : : }
11831 : : }
11832 : :
11833 : : return 0;
11834 : : }
11835 : :
11836 : : static int
11837 : 0 : i40e_update_customized_ptype(struct rte_eth_dev *dev, uint8_t *pkg,
11838 : : uint32_t pkg_size, uint32_t proto_num,
11839 : : struct rte_pmd_i40e_proto_info *proto,
11840 : : enum rte_pmd_i40e_package_op op)
11841 : : {
11842 : 0 : struct rte_pmd_i40e_ptype_mapping ptype_mapping[I40E_MAX_PKT_TYPE] = {0};
11843 : 0 : uint16_t port_id = dev->data->port_id;
11844 : : uint32_t ptype_num;
11845 : 0 : struct rte_pmd_i40e_ptype_info ptype[I40E_MAX_PKT_TYPE] = {0};
11846 : : uint8_t proto_id;
11847 : : char name[RTE_PMD_I40E_DDP_NAME_SIZE];
11848 : : uint32_t i, j, n;
11849 : : bool in_tunnel;
11850 : : int ret;
11851 : :
11852 [ # # ]: 0 : if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
11853 : : op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
11854 : 0 : PMD_DRV_LOG(ERR, "Unsupported operation.");
11855 : 0 : return -1;
11856 : : }
11857 : :
11858 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_DEL) {
11859 : 0 : rte_pmd_i40e_ptype_mapping_reset(port_id);
11860 : 0 : return 0;
11861 : : }
11862 : :
11863 : : /* get information about new ptype num */
11864 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11865 : : (uint8_t *)&ptype_num, sizeof(ptype_num),
11866 : : RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
11867 [ # # ]: 0 : if (ret) {
11868 : 0 : PMD_DRV_LOG(ERR, "Failed to get ptype number");
11869 : 0 : return ret;
11870 : : }
11871 [ # # ]: 0 : if (!ptype_num) {
11872 : 0 : PMD_DRV_LOG(INFO, "No new ptype added");
11873 : 0 : return -1;
11874 : : }
11875 : :
11876 [ # # ]: 0 : if (ptype_num > RTE_DIM(ptype)) {
11877 : 0 : PMD_DRV_LOG(ERR, "Too many ptypes");
11878 : 0 : return -1;
11879 : : }
11880 : :
11881 : : /* get information about new ptype list */
11882 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11883 : : (uint8_t *)ptype, sizeof(ptype),
11884 : : RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
11885 [ # # ]: 0 : if (ret) {
11886 : 0 : PMD_DRV_LOG(ERR, "Failed to get ptype list");
11887 : 0 : return ret;
11888 : : }
11889 : :
11890 : : /* Update ptype mapping table. */
11891 [ # # ]: 0 : for (i = 0; i < ptype_num; i++) {
11892 : 0 : ptype_mapping[i].hw_ptype = ptype[i].ptype_id;
11893 : 0 : ptype_mapping[i].sw_ptype = 0;
11894 : : in_tunnel = false;
11895 [ # # ]: 0 : for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
11896 : 0 : proto_id = ptype[i].protocols[j];
11897 [ # # ]: 0 : if (proto_id == RTE_PMD_I40E_PROTO_UNUSED)
11898 : 0 : continue;
11899 [ # # ]: 0 : for (n = 0; n < proto_num; n++) {
11900 [ # # ]: 0 : if (proto[n].proto_id != proto_id)
11901 : : continue;
11902 : : memset(name, 0, sizeof(name));
11903 : 0 : strcpy(name, proto[n].name);
11904 : 0 : PMD_DRV_LOG(INFO, "name = %s", name);
11905 [ # # ]: 0 : if (!strncasecmp(name, "PPPOE", 5))
11906 : 0 : ptype_mapping[i].sw_ptype |=
11907 : : RTE_PTYPE_L2_ETHER_PPPOE;
11908 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV4FRAG", 8) &&
11909 : : !in_tunnel) {
11910 : 0 : ptype_mapping[i].sw_ptype |=
11911 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11912 : 0 : ptype_mapping[i].sw_ptype |=
11913 : : RTE_PTYPE_L4_FRAG;
11914 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV4FRAG", 8) &&
11915 : : in_tunnel) {
11916 : 0 : ptype_mapping[i].sw_ptype |=
11917 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
11918 : 0 : ptype_mapping[i].sw_ptype |=
11919 : : RTE_PTYPE_INNER_L4_FRAG;
11920 [ # # ]: 0 : } else if (!strncasecmp(name, "OIPV4", 5)) {
11921 : 0 : ptype_mapping[i].sw_ptype |=
11922 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11923 : : in_tunnel = true;
11924 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV4", 4) &&
11925 : : !in_tunnel)
11926 : 0 : ptype_mapping[i].sw_ptype |=
11927 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11928 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV4", 4) &&
11929 : : in_tunnel)
11930 : 0 : ptype_mapping[i].sw_ptype |=
11931 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
11932 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV6FRAG", 8) &&
11933 : : !in_tunnel) {
11934 : 0 : ptype_mapping[i].sw_ptype |=
11935 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11936 : 0 : ptype_mapping[i].sw_ptype |=
11937 : : RTE_PTYPE_L4_FRAG;
11938 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV6FRAG", 8) &&
11939 : : in_tunnel) {
11940 : 0 : ptype_mapping[i].sw_ptype |=
11941 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
11942 : 0 : ptype_mapping[i].sw_ptype |=
11943 : : RTE_PTYPE_INNER_L4_FRAG;
11944 [ # # ]: 0 : } else if (!strncasecmp(name, "OIPV6", 5)) {
11945 : 0 : ptype_mapping[i].sw_ptype |=
11946 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11947 : : in_tunnel = true;
11948 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV6", 4) &&
11949 : : !in_tunnel)
11950 : 0 : ptype_mapping[i].sw_ptype |=
11951 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11952 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV6", 4) &&
11953 : : in_tunnel)
11954 : 0 : ptype_mapping[i].sw_ptype |=
11955 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
11956 [ # # # # ]: 0 : else if (!strncasecmp(name, "UDP", 3) &&
11957 : : !in_tunnel)
11958 : 0 : ptype_mapping[i].sw_ptype |=
11959 : : RTE_PTYPE_L4_UDP;
11960 [ # # # # ]: 0 : else if (!strncasecmp(name, "UDP", 3) &&
11961 : : in_tunnel)
11962 : 0 : ptype_mapping[i].sw_ptype |=
11963 : : RTE_PTYPE_INNER_L4_UDP;
11964 [ # # # # ]: 0 : else if (!strncasecmp(name, "TCP", 3) &&
11965 : : !in_tunnel)
11966 : 0 : ptype_mapping[i].sw_ptype |=
11967 : : RTE_PTYPE_L4_TCP;
11968 [ # # # # ]: 0 : else if (!strncasecmp(name, "TCP", 3) &&
11969 : : in_tunnel)
11970 : 0 : ptype_mapping[i].sw_ptype |=
11971 : : RTE_PTYPE_INNER_L4_TCP;
11972 [ # # # # ]: 0 : else if (!strncasecmp(name, "SCTP", 4) &&
11973 : : !in_tunnel)
11974 : 0 : ptype_mapping[i].sw_ptype |=
11975 : : RTE_PTYPE_L4_SCTP;
11976 [ # # # # ]: 0 : else if (!strncasecmp(name, "SCTP", 4) &&
11977 : : in_tunnel)
11978 : 0 : ptype_mapping[i].sw_ptype |=
11979 : : RTE_PTYPE_INNER_L4_SCTP;
11980 [ # # ]: 0 : else if ((!strncasecmp(name, "ICMP", 4) ||
11981 [ # # # # ]: 0 : !strncasecmp(name, "ICMPV6", 6)) &&
11982 : : !in_tunnel)
11983 : 0 : ptype_mapping[i].sw_ptype |=
11984 : : RTE_PTYPE_L4_ICMP;
11985 [ # # ]: 0 : else if ((!strncasecmp(name, "ICMP", 4) ||
11986 [ # # # # ]: 0 : !strncasecmp(name, "ICMPV6", 6)) &&
11987 : : in_tunnel)
11988 : 0 : ptype_mapping[i].sw_ptype |=
11989 : : RTE_PTYPE_INNER_L4_ICMP;
11990 [ # # ]: 0 : else if (!strncasecmp(name, "GTPC", 4)) {
11991 : 0 : ptype_mapping[i].sw_ptype |=
11992 : : RTE_PTYPE_TUNNEL_GTPC;
11993 : : in_tunnel = true;
11994 [ # # ]: 0 : } else if (!strncasecmp(name, "GTPU", 4)) {
11995 : 0 : ptype_mapping[i].sw_ptype |=
11996 : : RTE_PTYPE_TUNNEL_GTPU;
11997 : : in_tunnel = true;
11998 [ # # ]: 0 : } else if (!strncasecmp(name, "ESP", 3)) {
11999 : 0 : ptype_mapping[i].sw_ptype |=
12000 : : RTE_PTYPE_TUNNEL_ESP;
12001 : : in_tunnel = true;
12002 [ # # ]: 0 : } else if (!strncasecmp(name, "GRENAT", 6)) {
12003 : 0 : ptype_mapping[i].sw_ptype |=
12004 : : RTE_PTYPE_TUNNEL_GRENAT;
12005 : : in_tunnel = true;
12006 [ # # ]: 0 : } else if (!strncasecmp(name, "L2TPV2CTL", 9) ||
12007 [ # # ]: 0 : !strncasecmp(name, "L2TPV2", 6) ||
12008 [ # # ]: 0 : !strncasecmp(name, "L2TPV3", 6)) {
12009 : 0 : ptype_mapping[i].sw_ptype |=
12010 : : RTE_PTYPE_TUNNEL_L2TP;
12011 : : in_tunnel = true;
12012 : : }
12013 : :
12014 : : break;
12015 : : }
12016 : : }
12017 : : }
12018 : :
12019 : 0 : ret = rte_pmd_i40e_ptype_mapping_update(port_id, ptype_mapping,
12020 : : ptype_num, 0);
12021 [ # # ]: 0 : if (ret)
12022 : 0 : PMD_DRV_LOG(ERR, "Failed to update ptype mapping table.");
12023 : :
12024 : : return ret;
12025 : : }
12026 : :
12027 : : void
12028 : 0 : i40e_update_customized_info(struct rte_eth_dev *dev, uint8_t *pkg,
12029 : : uint32_t pkg_size, enum rte_pmd_i40e_package_op op)
12030 : : {
12031 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
12032 : : uint32_t proto_num;
12033 : : struct rte_pmd_i40e_proto_info *proto;
12034 : : uint32_t buff_size;
12035 : : uint32_t i;
12036 : : int ret;
12037 : :
12038 [ # # ]: 0 : if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
12039 : : op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
12040 : 0 : PMD_DRV_LOG(ERR, "Unsupported operation.");
12041 : 0 : return;
12042 : : }
12043 : :
12044 : : /* get information about protocol number */
12045 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12046 : : (uint8_t *)&proto_num, sizeof(proto_num),
12047 : : RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
12048 [ # # ]: 0 : if (ret) {
12049 : 0 : PMD_DRV_LOG(ERR, "Failed to get protocol number");
12050 : 0 : return;
12051 : : }
12052 [ # # ]: 0 : if (!proto_num) {
12053 : 0 : PMD_DRV_LOG(INFO, "No new protocol added");
12054 : 0 : return;
12055 : : }
12056 : :
12057 : 0 : buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
12058 : 0 : proto = calloc(proto_num, sizeof(struct rte_pmd_i40e_proto_info));
12059 [ # # ]: 0 : if (!proto) {
12060 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory");
12061 : 0 : return;
12062 : : }
12063 : :
12064 : : /* get information about protocol list */
12065 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12066 : : (uint8_t *)proto, buff_size,
12067 : : RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
12068 [ # # ]: 0 : if (ret) {
12069 : 0 : PMD_DRV_LOG(ERR, "Failed to get protocol list");
12070 : 0 : free(proto);
12071 : 0 : return;
12072 : : }
12073 : :
12074 : : /* Check if GTP is supported. */
12075 [ # # ]: 0 : for (i = 0; i < proto_num; i++) {
12076 [ # # ]: 0 : if (!strncmp(proto[i].name, "GTP", 3)) {
12077 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
12078 : 0 : pf->gtp_support = true;
12079 : : else
12080 : 0 : pf->gtp_support = false;
12081 : : break;
12082 : : }
12083 : : }
12084 : :
12085 : : /* Check if ESP is supported. */
12086 [ # # ]: 0 : for (i = 0; i < proto_num; i++) {
12087 [ # # ]: 0 : if (!strncmp(proto[i].name, "ESP", 3)) {
12088 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
12089 : 0 : pf->esp_support = true;
12090 : : else
12091 : 0 : pf->esp_support = false;
12092 : : break;
12093 : : }
12094 : : }
12095 : :
12096 : : /* Update customized pctype info */
12097 : 0 : ret = i40e_update_customized_pctype(dev, pkg, pkg_size,
12098 : : proto_num, proto, op);
12099 [ # # ]: 0 : if (ret)
12100 : 0 : PMD_DRV_LOG(INFO, "No pctype is updated.");
12101 : :
12102 : : /* Update customized ptype info */
12103 : 0 : ret = i40e_update_customized_ptype(dev, pkg, pkg_size,
12104 : : proto_num, proto, op);
12105 [ # # ]: 0 : if (ret)
12106 : 0 : PMD_DRV_LOG(INFO, "No ptype is updated.");
12107 : :
12108 : 0 : free(proto);
12109 : : }
12110 : :
12111 : : /* Create a QinQ cloud filter
12112 : : *
12113 : : * The Fortville NIC has limited resources for tunnel filters,
12114 : : * so we can only reuse existing filters.
12115 : : *
12116 : : * In step 1 we define which Field Vector fields can be used for
12117 : : * filter types.
12118 : : * As we do not have the inner tag defined as a field,
12119 : : * we have to define it first, by reusing one of L1 entries.
12120 : : *
12121 : : * In step 2 we are replacing one of existing filter types with
12122 : : * a new one for QinQ.
12123 : : * As we reusing L1 and replacing L2, some of the default filter
12124 : : * types will disappear,which depends on L1 and L2 entries we reuse.
12125 : : *
12126 : : * Step 1: Create L1 filter of outer vlan (12b) + inner vlan (12b)
12127 : : *
12128 : : * 1. Create L1 filter of outer vlan (12b) which will be in use
12129 : : * later when we define the cloud filter.
12130 : : * a. Valid_flags.replace_cloud = 0
12131 : : * b. Old_filter = 10 (Stag_Inner_Vlan)
12132 : : * c. New_filter = 0x10
12133 : : * d. TR bit = 0xff (optional, not used here)
12134 : : * e. Buffer – 2 entries:
12135 : : * i. Byte 0 = 8 (outer vlan FV index).
12136 : : * Byte 1 = 0 (rsv)
12137 : : * Byte 2-3 = 0x0fff
12138 : : * ii. Byte 0 = 37 (inner vlan FV index).
12139 : : * Byte 1 =0 (rsv)
12140 : : * Byte 2-3 = 0x0fff
12141 : : *
12142 : : * Step 2:
12143 : : * 2. Create cloud filter using two L1 filters entries: stag and
12144 : : * new filter(outer vlan+ inner vlan)
12145 : : * a. Valid_flags.replace_cloud = 1
12146 : : * b. Old_filter = 1 (instead of outer IP)
12147 : : * c. New_filter = 0x10
12148 : : * d. Buffer – 2 entries:
12149 : : * i. Byte 0 = 0x80 | 7 (valid | Stag).
12150 : : * Byte 1-3 = 0 (rsv)
12151 : : * ii. Byte 8 = 0x80 | 0x10 (valid | new l1 filter step1)
12152 : : * Byte 9-11 = 0 (rsv)
12153 : : */
12154 : : static int
12155 : 0 : i40e_cloud_filter_qinq_create(struct i40e_pf *pf)
12156 : : {
12157 : : int ret = -ENOTSUP;
12158 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
12159 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
12160 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
12161 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
12162 : :
12163 [ # # ]: 0 : if (pf->support_multi_driver) {
12164 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
12165 : 0 : return ret;
12166 : : }
12167 : :
12168 : : /* Init */
12169 : : memset(&filter_replace, 0,
12170 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
12171 : : memset(&filter_replace_buf, 0,
12172 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
12173 : :
12174 : : /* create L1 filter */
12175 : 0 : filter_replace.old_filter_type =
12176 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG_IVLAN;
12177 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12178 : : filter_replace.tr_bit = 0;
12179 : :
12180 : : /* Prepare the buffer, 2 entries */
12181 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_VLAN;
12182 : 0 : filter_replace_buf.data[0] |=
12183 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12184 : : /* Field Vector 12b mask */
12185 : 0 : filter_replace_buf.data[2] = 0xff;
12186 : 0 : filter_replace_buf.data[3] = 0x0f;
12187 : : filter_replace_buf.data[4] =
12188 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_INNER_VLAN;
12189 : 0 : filter_replace_buf.data[4] |=
12190 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12191 : : /* Field Vector 12b mask */
12192 : 0 : filter_replace_buf.data[6] = 0xff;
12193 : 0 : filter_replace_buf.data[7] = 0x0f;
12194 : 0 : ret = i40e_aq_replace_cloud_filters(hw, &filter_replace,
12195 : : &filter_replace_buf);
12196 [ # # ]: 0 : if (ret != I40E_SUCCESS)
12197 : : return ret;
12198 : :
12199 : 0 : if (filter_replace.old_filter_type !=
12200 [ # # ]: 0 : filter_replace.new_filter_type)
12201 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
12202 : : " original: 0x%x, new: 0x%x",
12203 : : dev->device->name,
12204 : : filter_replace.old_filter_type,
12205 : : filter_replace.new_filter_type);
12206 : :
12207 : : /* Apply the second L2 cloud filter */
12208 : : memset(&filter_replace, 0,
12209 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
12210 : : memset(&filter_replace_buf, 0,
12211 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
12212 : :
12213 : : /* create L2 filter, input for L2 filter will be L1 filter */
12214 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
12215 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_OIP;
12216 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12217 : :
12218 : : /* Prepare the buffer, 2 entries */
12219 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
12220 : 0 : filter_replace_buf.data[0] |=
12221 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12222 : : filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12223 : 0 : filter_replace_buf.data[4] |=
12224 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12225 : 0 : ret = i40e_aq_replace_cloud_filters(hw, &filter_replace,
12226 : : &filter_replace_buf);
12227 [ # # ]: 0 : if (!ret && (filter_replace.old_filter_type !=
12228 [ # # ]: 0 : filter_replace.new_filter_type))
12229 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
12230 : : " original: 0x%x, new: 0x%x",
12231 : : dev->device->name,
12232 : : filter_replace.old_filter_type,
12233 : : filter_replace.new_filter_type);
12234 : :
12235 : : return ret;
12236 : : }
12237 : :
12238 : : static int
12239 : 0 : i40e_fec_get_capability(struct rte_eth_dev *dev,
12240 : : struct rte_eth_fec_capa *speed_fec_capa, __rte_unused unsigned int num)
12241 : : {
12242 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
12243 : :
12244 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722 &&
12245 [ # # ]: 0 : !(hw->flags & I40E_HW_FLAG_X722_FEC_REQUEST_CAPABLE)) {
12246 : 0 : PMD_DRV_LOG(ERR, "Setting FEC encoding not supported by"
12247 : : " firmware. Please update the NVM image.");
12248 : 0 : return -ENOTSUP;
12249 : : }
12250 : :
12251 [ # # ]: 0 : if (hw->device_id == I40E_DEV_ID_25G_SFP28 ||
12252 : : hw->device_id == I40E_DEV_ID_25G_B) {
12253 [ # # ]: 0 : if (speed_fec_capa) {
12254 : 0 : speed_fec_capa->speed = RTE_ETH_SPEED_NUM_25G;
12255 : 0 : speed_fec_capa->capa = RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC) |
12256 : : RTE_ETH_FEC_MODE_CAPA_MASK(BASER) |
12257 : : RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
12258 : : RTE_ETH_FEC_MODE_CAPA_MASK(RS);
12259 : : }
12260 : :
12261 : : /* since HW only supports 25G */
12262 : 0 : return 1;
12263 [ # # ]: 0 : } else if (hw->device_id == I40E_DEV_ID_KX_X722) {
12264 [ # # ]: 0 : if (speed_fec_capa) {
12265 : 0 : speed_fec_capa->speed = RTE_ETH_SPEED_NUM_25G;
12266 : 0 : speed_fec_capa->capa = RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
12267 : : RTE_ETH_FEC_MODE_CAPA_MASK(RS);
12268 : : }
12269 : 0 : return 1;
12270 : : }
12271 : :
12272 : : return -ENOTSUP;
12273 : : }
12274 : :
12275 : : static int
12276 : 0 : i40e_fec_get(struct rte_eth_dev *dev, uint32_t *fec_capa)
12277 : : {
12278 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
12279 : 0 : struct i40e_aq_get_phy_abilities_resp abilities = {0};
12280 : 0 : struct i40e_link_status link_status = {0};
12281 : : uint8_t current_fec_mode = 0, fec_config = 0;
12282 : : bool link_up, enable_lse;
12283 : : int ret = 0;
12284 : :
12285 : 0 : enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
12286 : : /* Get link info */
12287 : 0 : ret = i40e_aq_get_link_info(hw, enable_lse, &link_status, NULL);
12288 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
12289 : 0 : PMD_DRV_LOG(ERR, "Failed to get link information: %d",
12290 : : ret);
12291 : 0 : return -ENOTSUP;
12292 : : }
12293 : :
12294 : 0 : link_up = link_status.link_info & I40E_AQ_LINK_UP;
12295 : :
12296 : 0 : ret = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
12297 : : NULL);
12298 [ # # ]: 0 : if (ret) {
12299 : 0 : PMD_DRV_LOG(ERR, "Failed to get PHY capabilities: %d",
12300 : : ret);
12301 : 0 : return -ENOTSUP;
12302 : : }
12303 : :
12304 : : /**
12305 : : * If link is down and AUTO is enabled, AUTO is returned,
12306 : : * otherwise, configured FEC mode is returned.
12307 : : * If link is up, current FEC mode is returned.
12308 : : */
12309 : 0 : fec_config = abilities.fec_cfg_curr_mod_ext_info
12310 : : & I40E_AQ_PHY_FEC_CONFIG_MASK;
12311 : 0 : current_fec_mode = link_status.fec_info;
12312 : :
12313 [ # # ]: 0 : if (link_up) {
12314 [ # # # # ]: 0 : switch (current_fec_mode) {
12315 : 0 : case I40E_AQ_CONFIG_FEC_KR_ENA:
12316 : 0 : *fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_BASER);
12317 : 0 : break;
12318 : 0 : case I40E_AQ_CONFIG_FEC_RS_ENA:
12319 : 0 : *fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_RS);
12320 : 0 : break;
12321 : 0 : case 0:
12322 : 0 : *fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_NOFEC);
12323 : 0 : break;
12324 : : default:
12325 : : return -EINVAL;
12326 : : }
12327 : 0 : return 0;
12328 : : }
12329 : :
12330 [ # # ]: 0 : if (fec_config & I40E_AQ_ENABLE_FEC_AUTO) {
12331 : 0 : *fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_AUTO);
12332 : 0 : return 0;
12333 : : }
12334 : :
12335 : : uint32_t temp_fec_capa = 0;
12336 [ # # ]: 0 : if (fec_config & I40E_AQ_ENABLE_FEC_KR)
12337 : : temp_fec_capa |= RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_BASER);
12338 [ # # ]: 0 : if (fec_config & I40E_AQ_ENABLE_FEC_RS)
12339 : 0 : temp_fec_capa |= RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_RS);
12340 : : if (temp_fec_capa == 0)
12341 : : temp_fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_NOFEC);
12342 : :
12343 : 0 : *fec_capa = temp_fec_capa;
12344 : 0 : return 0;
12345 : : }
12346 : :
12347 : : static int
12348 : 0 : i40e_fec_set(struct rte_eth_dev *dev, uint32_t fec_capa)
12349 : : {
12350 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
12351 : 0 : struct i40e_aq_get_phy_abilities_resp abilities = {0};
12352 : 0 : struct i40e_aq_set_phy_config config = {0};
12353 : : enum i40e_status_code status;
12354 : : uint8_t req_fec = 0, fec_auto = 0, fec_kr = 0, fec_rs = 0;
12355 : :
12356 : 0 : if (hw->device_id != I40E_DEV_ID_25G_SFP28 &&
12357 [ # # ]: 0 : hw->device_id != I40E_DEV_ID_25G_B &&
12358 : : hw->device_id != I40E_DEV_ID_KX_X722) {
12359 : : return -ENOTSUP;
12360 : : }
12361 : :
12362 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722 &&
12363 [ # # ]: 0 : !(hw->flags & I40E_HW_FLAG_X722_FEC_REQUEST_CAPABLE)) {
12364 : 0 : PMD_DRV_LOG(ERR, "Setting FEC encoding not supported by"
12365 : : " firmware. Please update the NVM image.");
12366 : 0 : return -ENOTSUP;
12367 : : }
12368 : :
12369 : : /**
12370 : : * Copy the current user PHY configuration. The current user PHY
12371 : : * configuration is initialized during probe from PHY capabilities
12372 : : * software mode, and updated on set PHY configuration.
12373 : : */
12374 [ # # ]: 0 : if (fec_capa & ~(RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
12375 : : RTE_ETH_FEC_MODE_CAPA_MASK(BASER) | RTE_ETH_FEC_MODE_CAPA_MASK(RS)))
12376 : : return -EINVAL;
12377 : :
12378 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_CAPA_MASK(AUTO))
12379 : : fec_auto = 1;
12380 : :
12381 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_CAPA_MASK(BASER))
12382 : : fec_kr = 1;
12383 : :
12384 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_CAPA_MASK(RS))
12385 : : fec_rs = 1;
12386 : :
12387 [ # # ]: 0 : if (fec_auto) {
12388 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
12389 : 0 : PMD_DRV_LOG(ERR, "X722 Unsupported FEC mode: AUTO");
12390 : 0 : return -EINVAL;
12391 : : }
12392 [ # # ]: 0 : if (fec_kr || fec_rs) {
12393 [ # # ]: 0 : if (fec_kr)
12394 : : req_fec = I40E_AQ_SET_FEC_ABILITY_KR |
12395 : : I40E_AQ_SET_FEC_REQUEST_KR;
12396 [ # # ]: 0 : if (fec_rs) {
12397 : : if (hw->mac.type == I40E_MAC_X722) {
12398 : : PMD_DRV_LOG(ERR, "X722 Unsupported FEC mode: RS");
12399 : : return -EINVAL;
12400 : : }
12401 : 0 : req_fec |= I40E_AQ_SET_FEC_ABILITY_RS |
12402 : : I40E_AQ_SET_FEC_REQUEST_RS;
12403 : : }
12404 : : } else {
12405 : : if (hw->mac.type == I40E_MAC_X722) {
12406 : : req_fec = I40E_AQ_SET_FEC_ABILITY_KR |
12407 : : I40E_AQ_SET_FEC_REQUEST_KR;
12408 : : } else {
12409 : : req_fec = I40E_AQ_SET_FEC_ABILITY_KR |
12410 : : I40E_AQ_SET_FEC_REQUEST_KR |
12411 : : I40E_AQ_SET_FEC_ABILITY_RS |
12412 : : I40E_AQ_SET_FEC_REQUEST_RS;
12413 : : }
12414 : : }
12415 : : } else {
12416 [ # # ]: 0 : if (fec_kr ^ fec_rs) {
12417 [ # # ]: 0 : if (fec_kr) {
12418 : : req_fec = I40E_AQ_SET_FEC_ABILITY_KR |
12419 : : I40E_AQ_SET_FEC_REQUEST_KR;
12420 : : } else {
12421 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
12422 : 0 : PMD_DRV_LOG(ERR, "X722 Unsupported FEC mode: RS");
12423 : 0 : return -EINVAL;
12424 : : }
12425 : : req_fec = I40E_AQ_SET_FEC_ABILITY_RS |
12426 : : I40E_AQ_SET_FEC_REQUEST_RS;
12427 : : }
12428 : : } else {
12429 : : return -EINVAL;
12430 : : }
12431 : : }
12432 : :
12433 : : /* Get the current phy config */
12434 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
12435 : : NULL);
12436 [ # # ]: 0 : if (status) {
12437 : 0 : PMD_DRV_LOG(ERR, "Failed to get PHY capabilities: %d",
12438 : : status);
12439 : 0 : return -ENOTSUP;
12440 : : }
12441 : :
12442 [ # # ]: 0 : if (abilities.fec_cfg_curr_mod_ext_info != req_fec) {
12443 : 0 : config.phy_type = abilities.phy_type;
12444 : 0 : config.abilities = abilities.abilities |
12445 : : I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
12446 : 0 : config.phy_type_ext = abilities.phy_type_ext;
12447 : 0 : config.link_speed = abilities.link_speed;
12448 : 0 : config.eee_capability = abilities.eee_capability;
12449 : 0 : config.eeer = abilities.eeer_val;
12450 : 0 : config.low_power_ctrl = abilities.d3_lpan;
12451 : 0 : config.fec_config = req_fec & I40E_AQ_PHY_FEC_CONFIG_MASK;
12452 : 0 : status = i40e_aq_set_phy_config(hw, &config, NULL);
12453 [ # # ]: 0 : if (status) {
12454 : 0 : PMD_DRV_LOG(ERR, "Failed to set PHY capabilities: %d",
12455 : : status);
12456 : 0 : return -ENOTSUP;
12457 : : }
12458 : : }
12459 : :
12460 : 0 : status = i40e_update_link_info(hw);
12461 [ # # ]: 0 : if (status) {
12462 : 0 : PMD_DRV_LOG(ERR, "Failed to set PHY capabilities: %d",
12463 : : status);
12464 : 0 : return -ENOTSUP;
12465 : : }
12466 : :
12467 : : return 0;
12468 : : }
12469 : :
12470 [ - + ]: 276 : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_init, init, NOTICE);
12471 [ - + ]: 276 : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_driver, driver, NOTICE);
12472 : : #ifdef RTE_ETHDEV_DEBUG_RX
12473 : : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_rx, rx, DEBUG);
12474 : : #endif
12475 : : #ifdef RTE_ETHDEV_DEBUG_TX
12476 : : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_tx, tx, DEBUG);
12477 : : #endif
12478 : :
12479 : : RTE_PMD_REGISTER_PARAM_STRING(net_i40e,
12480 : : ETH_I40E_FLOATING_VEB_ARG "=1"
12481 : : ETH_I40E_FLOATING_VEB_LIST_ARG "=<string>"
12482 : : ETH_I40E_QUEUE_NUM_PER_VF_ARG "=1|2|4|8|16"
12483 : : ETH_I40E_SUPPORT_MULTI_DRIVER "=1");
|