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 <string.h>
10 : : #include <unistd.h>
11 : : #include <stdarg.h>
12 : : #include <inttypes.h>
13 : : #include <assert.h>
14 : :
15 : : #include <rte_common.h>
16 : : #include <rte_eal.h>
17 : : #include <rte_string_fns.h>
18 : : #include <rte_pci.h>
19 : : #include <bus_pci_driver.h>
20 : : #include <rte_ether.h>
21 : : #include <ethdev_driver.h>
22 : : #include <ethdev_pci.h>
23 : : #include <rte_memzone.h>
24 : : #include <rte_malloc.h>
25 : : #include <rte_memcpy.h>
26 : : #include <rte_alarm.h>
27 : : #include <dev_driver.h>
28 : : #include <rte_tailq.h>
29 : : #include <rte_hash_crc.h>
30 : : #include <rte_bitmap.h>
31 : : #include <rte_os_shim.h>
32 : :
33 : : #include "i40e_logs.h"
34 : : #include "base/i40e_prototype.h"
35 : : #include "base/i40e_adminq_cmd.h"
36 : : #include "base/i40e_type.h"
37 : : #include "base/i40e_register.h"
38 : : #include "base/i40e_dcb.h"
39 : : #include "i40e_ethdev.h"
40 : : #include "i40e_rxtx.h"
41 : : #include "i40e_pf.h"
42 : : #include "i40e_regs.h"
43 : : #include "rte_pmd_i40e.h"
44 : : #include "i40e_hash.h"
45 : :
46 : : #define ETH_I40E_FLOATING_VEB_ARG "enable_floating_veb"
47 : : #define ETH_I40E_FLOATING_VEB_LIST_ARG "floating_veb_list"
48 : : #define ETH_I40E_SUPPORT_MULTI_DRIVER "support-multi-driver"
49 : : #define ETH_I40E_QUEUE_NUM_PER_VF_ARG "queue-num-per-vf"
50 : : #define ETH_I40E_VF_MSG_CFG "vf_msg_cfg"
51 : : #define ETH_I40E_MBUF_CHECK_ARG "mbuf_check"
52 : :
53 : : #define I40E_CLEAR_PXE_WAIT_MS 200
54 : : #define I40E_VSI_TSR_QINQ_STRIP 0x4010
55 : : #define I40E_VSI_TSR(_i) (0x00050800 + ((_i) * 4))
56 : :
57 : : /* Maximun number of capability elements */
58 : : #define I40E_MAX_CAP_ELE_NUM 128
59 : :
60 : : /* Wait count and interval */
61 : : #define I40E_CHK_Q_ENA_COUNT 1000
62 : : #define I40E_CHK_Q_ENA_INTERVAL_US 1000
63 : :
64 : : /* Maximun number of VSI */
65 : : #define I40E_MAX_NUM_VSIS (384UL)
66 : :
67 : : #define I40E_PRE_TX_Q_CFG_WAIT_US 10 /* 10 us */
68 : :
69 : : /* Flow control default timer */
70 : : #define I40E_DEFAULT_PAUSE_TIME 0xFFFFU
71 : :
72 : : /* Flow control enable fwd bit */
73 : : #define I40E_PRTMAC_FWD_CTRL 0x00000001
74 : :
75 : : /* Receive Packet Buffer size */
76 : : #define I40E_RXPBSIZE (968 * 1024)
77 : :
78 : : /* Kilobytes shift */
79 : : #define I40E_KILOSHIFT 10
80 : :
81 : : /* Flow control default high water */
82 : : #define I40E_DEFAULT_HIGH_WATER (0xF2000 >> I40E_KILOSHIFT)
83 : :
84 : : /* Flow control default low water */
85 : : #define I40E_DEFAULT_LOW_WATER (0xF2000 >> I40E_KILOSHIFT)
86 : :
87 : : /* Receive Average Packet Size in Byte*/
88 : : #define I40E_PACKET_AVERAGE_SIZE 128
89 : :
90 : : /* Mask of PF interrupt causes */
91 : : #define I40E_PFINT_ICR0_ENA_MASK ( \
92 : : I40E_PFINT_ICR0_ENA_ECC_ERR_MASK | \
93 : : I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK | \
94 : : I40E_PFINT_ICR0_ENA_GRST_MASK | \
95 : : I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK | \
96 : : I40E_PFINT_ICR0_ENA_STORM_DETECT_MASK | \
97 : : I40E_PFINT_ICR0_ENA_HMC_ERR_MASK | \
98 : : I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK | \
99 : : I40E_PFINT_ICR0_ENA_VFLR_MASK | \
100 : : I40E_PFINT_ICR0_ENA_ADMINQ_MASK)
101 : :
102 : : #define I40E_FLOW_TYPES ( \
103 : : (1UL << RTE_ETH_FLOW_FRAG_IPV4) | \
104 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_TCP) | \
105 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_UDP) | \
106 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_SCTP) | \
107 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV4_OTHER) | \
108 : : (1UL << RTE_ETH_FLOW_FRAG_IPV6) | \
109 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_TCP) | \
110 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_UDP) | \
111 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_SCTP) | \
112 : : (1UL << RTE_ETH_FLOW_NONFRAG_IPV6_OTHER) | \
113 : : (1UL << RTE_ETH_FLOW_L2_PAYLOAD))
114 : :
115 : : /* Additional timesync values. */
116 : : #define I40E_PTP_40GB_INCVAL 0x0199999999ULL
117 : : #define I40E_PTP_10GB_INCVAL 0x0333333333ULL
118 : : #define I40E_PTP_1GB_INCVAL 0x2000000000ULL
119 : : #define I40E_PRTTSYN_TSYNENA 0x80000000
120 : : #define I40E_PRTTSYN_TSYNTYPE 0x0e000000
121 : : #define I40E_CYCLECOUNTER_MASK 0xffffffffffffffffULL
122 : :
123 : : /**
124 : : * Below are values for writing un-exposed registers suggested
125 : : * by silicon experts
126 : : */
127 : : /* Destination MAC address */
128 : : #define I40E_REG_INSET_L2_DMAC 0xE000000000000000ULL
129 : : /* Source MAC address */
130 : : #define I40E_REG_INSET_L2_SMAC 0x1C00000000000000ULL
131 : : /* Outer (S-Tag) VLAN tag in the outer L2 header */
132 : : #define I40E_REG_INSET_L2_OUTER_VLAN 0x0000000004000000ULL
133 : : /* Inner (C-Tag) or single VLAN tag in the outer L2 header */
134 : : #define I40E_REG_INSET_L2_INNER_VLAN 0x0080000000000000ULL
135 : : /* Single VLAN tag in the inner L2 header */
136 : : #define I40E_REG_INSET_TUNNEL_VLAN 0x0100000000000000ULL
137 : : /* Source IPv4 address */
138 : : #define I40E_REG_INSET_L3_SRC_IP4 0x0001800000000000ULL
139 : : /* Destination IPv4 address */
140 : : #define I40E_REG_INSET_L3_DST_IP4 0x0000001800000000ULL
141 : : /* Source IPv4 address for X722 */
142 : : #define I40E_X722_REG_INSET_L3_SRC_IP4 0x0006000000000000ULL
143 : : /* Destination IPv4 address for X722 */
144 : : #define I40E_X722_REG_INSET_L3_DST_IP4 0x0000060000000000ULL
145 : : /* IPv4 Protocol for X722 */
146 : : #define I40E_X722_REG_INSET_L3_IP4_PROTO 0x0010000000000000ULL
147 : : /* IPv4 Time to Live for X722 */
148 : : #define I40E_X722_REG_INSET_L3_IP4_TTL 0x0010000000000000ULL
149 : : /* IPv4 Type of Service (TOS) */
150 : : #define I40E_REG_INSET_L3_IP4_TOS 0x0040000000000000ULL
151 : : /* IPv4 Protocol */
152 : : #define I40E_REG_INSET_L3_IP4_PROTO 0x0004000000000000ULL
153 : : /* IPv4 Time to Live */
154 : : #define I40E_REG_INSET_L3_IP4_TTL 0x0004000000000000ULL
155 : : /* Source IPv6 address */
156 : : #define I40E_REG_INSET_L3_SRC_IP6 0x0007F80000000000ULL
157 : : /* Destination IPv6 address */
158 : : #define I40E_REG_INSET_L3_DST_IP6 0x000007F800000000ULL
159 : : /* IPv6 Traffic Class (TC) */
160 : : #define I40E_REG_INSET_L3_IP6_TC 0x0040000000000000ULL
161 : : /* IPv6 Next Header */
162 : : #define I40E_REG_INSET_L3_IP6_NEXT_HDR 0x0008000000000000ULL
163 : : /* IPv6 Hop Limit */
164 : : #define I40E_REG_INSET_L3_IP6_HOP_LIMIT 0x0008000000000000ULL
165 : : /* Source L4 port */
166 : : #define I40E_REG_INSET_L4_SRC_PORT 0x0000000400000000ULL
167 : : /* Destination L4 port */
168 : : #define I40E_REG_INSET_L4_DST_PORT 0x0000000200000000ULL
169 : : /* SCTP verification tag */
170 : : #define I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG 0x0000000180000000ULL
171 : : /* Inner destination MAC address (MAC-in-UDP/MAC-in-GRE)*/
172 : : #define I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC 0x0000000001C00000ULL
173 : : /* Source port of tunneling UDP */
174 : : #define I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT 0x0000000000200000ULL
175 : : /* Destination port of tunneling UDP */
176 : : #define I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT 0x0000000000100000ULL
177 : : /* UDP Tunneling ID, NVGRE/GRE key */
178 : : #define I40E_REG_INSET_TUNNEL_ID 0x00000000000C0000ULL
179 : : /* Last ether type */
180 : : #define I40E_REG_INSET_LAST_ETHER_TYPE 0x0000000000004000ULL
181 : : /* Tunneling outer destination IPv4 address */
182 : : #define I40E_REG_INSET_TUNNEL_L3_DST_IP4 0x00000000000000C0ULL
183 : : /* Tunneling outer destination IPv6 address */
184 : : #define I40E_REG_INSET_TUNNEL_L3_DST_IP6 0x0000000000003FC0ULL
185 : : /* 1st word of flex payload */
186 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD1 0x0000000000002000ULL
187 : : /* 2nd word of flex payload */
188 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD2 0x0000000000001000ULL
189 : : /* 3rd word of flex payload */
190 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD3 0x0000000000000800ULL
191 : : /* 4th word of flex payload */
192 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD4 0x0000000000000400ULL
193 : : /* 5th word of flex payload */
194 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD5 0x0000000000000200ULL
195 : : /* 6th word of flex payload */
196 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD6 0x0000000000000100ULL
197 : : /* 7th word of flex payload */
198 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD7 0x0000000000000080ULL
199 : : /* 8th word of flex payload */
200 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORD8 0x0000000000000040ULL
201 : : /* all 8 words flex payload */
202 : : #define I40E_REG_INSET_FLEX_PAYLOAD_WORDS 0x0000000000003FC0ULL
203 : : #define I40E_REG_INSET_MASK_DEFAULT 0x0000000000000000ULL
204 : :
205 : : #define I40E_TRANSLATE_INSET 0
206 : : #define I40E_TRANSLATE_REG 1
207 : :
208 : : #define I40E_INSET_IPV4_TOS_MASK 0x0000FF00UL
209 : : #define I40E_INSET_IPV4_TTL_MASK 0x000000FFUL
210 : : #define I40E_INSET_IPV4_PROTO_MASK 0x0000FF00UL
211 : : #define I40E_INSET_IPV6_TC_MASK 0x0000F00FUL
212 : : #define I40E_INSET_IPV6_HOP_LIMIT_MASK 0x0000FF00UL
213 : : #define I40E_INSET_IPV6_NEXT_HDR_MASK 0x000000FFUL
214 : :
215 : : /* PCI offset for querying capability */
216 : : #define PCI_DEV_CAP_REG 0xA4
217 : : /* PCI offset for enabling/disabling Extended Tag */
218 : : #define PCI_DEV_CTRL_REG 0xA8
219 : : /* Bit mask of Extended Tag capability */
220 : : #define PCI_DEV_CAP_EXT_TAG_MASK 0x20
221 : : /* Bit shift of Extended Tag enable/disable */
222 : : #define PCI_DEV_CTRL_EXT_TAG_SHIFT 8
223 : : /* Bit mask of Extended Tag enable/disable */
224 : : #define PCI_DEV_CTRL_EXT_TAG_MASK (1 << PCI_DEV_CTRL_EXT_TAG_SHIFT)
225 : :
226 : : #define I40E_GLQF_PIT_IPV4_START 2
227 : : #define I40E_GLQF_PIT_IPV4_COUNT 2
228 : : #define I40E_GLQF_PIT_IPV6_START 4
229 : : #define I40E_GLQF_PIT_IPV6_COUNT 2
230 : :
231 : : #define I40E_GLQF_PIT_SOURCE_OFF_GET(a) \
232 : : (((a) & I40E_GLQF_PIT_SOURCE_OFF_MASK) >> \
233 : : I40E_GLQF_PIT_SOURCE_OFF_SHIFT)
234 : :
235 : : #define I40E_GLQF_PIT_DEST_OFF_GET(a) \
236 : : (((a) & I40E_GLQF_PIT_DEST_OFF_MASK) >> \
237 : : I40E_GLQF_PIT_DEST_OFF_SHIFT)
238 : :
239 : : #define I40E_GLQF_PIT_FSIZE_GET(a) (((a) & I40E_GLQF_PIT_FSIZE_MASK) >> \
240 : : I40E_GLQF_PIT_FSIZE_SHIFT)
241 : :
242 : : #define I40E_GLQF_PIT_BUILD(off, mask) (((off) << 16) | (mask))
243 : : #define I40E_FDIR_FIELD_OFFSET(a) ((a) >> 1)
244 : :
245 : : static int eth_i40e_dev_init(struct rte_eth_dev *eth_dev, void *init_params);
246 : : static int eth_i40e_dev_uninit(struct rte_eth_dev *eth_dev);
247 : : static int i40e_dev_configure(struct rte_eth_dev *dev);
248 : : static int i40e_dev_start(struct rte_eth_dev *dev);
249 : : static int i40e_dev_stop(struct rte_eth_dev *dev);
250 : : static int i40e_dev_close(struct rte_eth_dev *dev);
251 : : static int i40e_dev_reset(struct rte_eth_dev *dev);
252 : : static int i40e_dev_promiscuous_enable(struct rte_eth_dev *dev);
253 : : static int i40e_dev_promiscuous_disable(struct rte_eth_dev *dev);
254 : : static int i40e_dev_allmulticast_enable(struct rte_eth_dev *dev);
255 : : static int i40e_dev_allmulticast_disable(struct rte_eth_dev *dev);
256 : : static int i40e_dev_set_link_up(struct rte_eth_dev *dev);
257 : : static int i40e_dev_set_link_down(struct rte_eth_dev *dev);
258 : : static int i40e_dev_stats_get(struct rte_eth_dev *dev,
259 : : struct rte_eth_stats *stats);
260 : : static int i40e_dev_xstats_get(struct rte_eth_dev *dev,
261 : : struct rte_eth_xstat *xstats, unsigned n);
262 : : static int i40e_dev_xstats_get_names(struct rte_eth_dev *dev,
263 : : struct rte_eth_xstat_name *xstats_names,
264 : : unsigned limit);
265 : : static int i40e_dev_stats_reset(struct rte_eth_dev *dev);
266 : : static int i40e_fw_version_get(struct rte_eth_dev *dev,
267 : : char *fw_version, size_t fw_size);
268 : : static int i40e_dev_info_get(struct rte_eth_dev *dev,
269 : : struct rte_eth_dev_info *dev_info);
270 : : static int i40e_vlan_filter_set(struct rte_eth_dev *dev,
271 : : uint16_t vlan_id,
272 : : int on);
273 : : static int i40e_vlan_tpid_set(struct rte_eth_dev *dev,
274 : : enum rte_vlan_type vlan_type,
275 : : uint16_t tpid);
276 : : static int i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask);
277 : : static void i40e_vlan_strip_queue_set(struct rte_eth_dev *dev,
278 : : uint16_t queue,
279 : : int on);
280 : : static int i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on);
281 : : static int i40e_dev_led_on(struct rte_eth_dev *dev);
282 : : static int i40e_dev_led_off(struct rte_eth_dev *dev);
283 : : static int i40e_flow_ctrl_get(struct rte_eth_dev *dev,
284 : : struct rte_eth_fc_conf *fc_conf);
285 : : static int i40e_flow_ctrl_set(struct rte_eth_dev *dev,
286 : : struct rte_eth_fc_conf *fc_conf);
287 : : static int i40e_priority_flow_ctrl_set(struct rte_eth_dev *dev,
288 : : struct rte_eth_pfc_conf *pfc_conf);
289 : : static int i40e_macaddr_add(struct rte_eth_dev *dev,
290 : : struct rte_ether_addr *mac_addr,
291 : : uint32_t index,
292 : : uint32_t pool);
293 : : static void i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index);
294 : : static int i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
295 : : struct rte_eth_rss_reta_entry64 *reta_conf,
296 : : uint16_t reta_size);
297 : : static int i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
298 : : struct rte_eth_rss_reta_entry64 *reta_conf,
299 : : uint16_t reta_size);
300 : :
301 : : static int i40e_get_cap(struct i40e_hw *hw);
302 : : static int i40e_pf_parameter_init(struct rte_eth_dev *dev);
303 : : static int i40e_pf_setup(struct i40e_pf *pf);
304 : : static int i40e_dev_rxtx_init(struct i40e_pf *pf);
305 : : static int i40e_vmdq_setup(struct rte_eth_dev *dev);
306 : : static int i40e_dcb_setup(struct rte_eth_dev *dev);
307 : : static void i40e_stat_update_32(struct i40e_hw *hw, uint32_t reg,
308 : : bool offset_loaded, uint64_t *offset, uint64_t *stat);
309 : : static void i40e_stat_update_48(struct i40e_hw *hw,
310 : : uint32_t hireg,
311 : : uint32_t loreg,
312 : : bool offset_loaded,
313 : : uint64_t *offset,
314 : : uint64_t *stat);
315 : : static void i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue);
316 : : static void i40e_dev_interrupt_handler(void *param);
317 : : static void i40e_dev_alarm_handler(void *param);
318 : : static int i40e_res_pool_init(struct i40e_res_pool_info *pool,
319 : : uint32_t base, uint32_t num);
320 : : static void i40e_res_pool_destroy(struct i40e_res_pool_info *pool);
321 : : static int i40e_res_pool_free(struct i40e_res_pool_info *pool,
322 : : uint32_t base);
323 : : static int i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
324 : : uint16_t num);
325 : : static int i40e_dev_init_vlan(struct rte_eth_dev *dev);
326 : : static int i40e_veb_release(struct i40e_veb *veb);
327 : : static struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf,
328 : : struct i40e_vsi *vsi);
329 : : static int i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on);
330 : : static inline int i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
331 : : struct i40e_macvlan_filter *mv_f,
332 : : int num,
333 : : uint16_t vlan);
334 : : static int i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi);
335 : : static int i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
336 : : struct rte_eth_rss_conf *rss_conf);
337 : : static int i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
338 : : struct rte_eth_rss_conf *rss_conf);
339 : : static int i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
340 : : struct rte_eth_udp_tunnel *udp_tunnel);
341 : : static int i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
342 : : struct rte_eth_udp_tunnel *udp_tunnel);
343 : : static void i40e_filter_input_set_init(struct i40e_pf *pf);
344 : : static int i40e_dev_flow_ops_get(struct rte_eth_dev *dev,
345 : : const struct rte_flow_ops **ops);
346 : : static int i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
347 : : struct rte_eth_dcb_info *dcb_info);
348 : : static int i40e_dev_sync_phy_type(struct i40e_hw *hw);
349 : : static void i40e_configure_registers(struct i40e_hw *hw);
350 : : static void i40e_hw_init(struct rte_eth_dev *dev);
351 : : static int i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi);
352 : :
353 : : static int i40e_timesync_enable(struct rte_eth_dev *dev);
354 : : static int i40e_timesync_disable(struct rte_eth_dev *dev);
355 : : static int i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
356 : : struct timespec *timestamp,
357 : : uint32_t flags);
358 : : static int i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
359 : : struct timespec *timestamp);
360 : : static void i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw);
361 : :
362 : : static int i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
363 : :
364 : : static int i40e_timesync_read_time(struct rte_eth_dev *dev,
365 : : struct timespec *timestamp);
366 : : static int i40e_timesync_write_time(struct rte_eth_dev *dev,
367 : : const struct timespec *timestamp);
368 : :
369 : : static int i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
370 : : uint16_t queue_id);
371 : : static int i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
372 : : uint16_t queue_id);
373 : :
374 : : static int i40e_get_regs(struct rte_eth_dev *dev,
375 : : struct rte_dev_reg_info *regs);
376 : :
377 : : static int i40e_get_eeprom_length(struct rte_eth_dev *dev);
378 : :
379 : : static int i40e_get_eeprom(struct rte_eth_dev *dev,
380 : : struct rte_dev_eeprom_info *eeprom);
381 : :
382 : : static int i40e_get_module_info(struct rte_eth_dev *dev,
383 : : struct rte_eth_dev_module_info *modinfo);
384 : : static int i40e_get_module_eeprom(struct rte_eth_dev *dev,
385 : : struct rte_dev_eeprom_info *info);
386 : :
387 : : static int i40e_set_default_mac_addr(struct rte_eth_dev *dev,
388 : : struct rte_ether_addr *mac_addr);
389 : :
390 : : static int i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
391 : :
392 : : static int i40e_ethertype_filter_convert(
393 : : const struct rte_eth_ethertype_filter *input,
394 : : struct i40e_ethertype_filter *filter);
395 : : static int i40e_sw_ethertype_filter_insert(struct i40e_pf *pf,
396 : : struct i40e_ethertype_filter *filter);
397 : :
398 : : static int i40e_tunnel_filter_convert(
399 : : struct i40e_aqc_cloud_filters_element_bb *cld_filter,
400 : : struct i40e_tunnel_filter *tunnel_filter);
401 : : static int i40e_sw_tunnel_filter_insert(struct i40e_pf *pf,
402 : : struct i40e_tunnel_filter *tunnel_filter);
403 : : static int i40e_cloud_filter_qinq_create(struct i40e_pf *pf);
404 : :
405 : : static void i40e_ethertype_filter_restore(struct i40e_pf *pf);
406 : : static void i40e_tunnel_filter_restore(struct i40e_pf *pf);
407 : : static void i40e_filter_restore(struct i40e_pf *pf);
408 : : static void i40e_notify_all_vfs_link_status(struct rte_eth_dev *dev);
409 : :
410 : : static const char *const valid_keys[] = {
411 : : ETH_I40E_FLOATING_VEB_ARG,
412 : : ETH_I40E_FLOATING_VEB_LIST_ARG,
413 : : ETH_I40E_SUPPORT_MULTI_DRIVER,
414 : : ETH_I40E_QUEUE_NUM_PER_VF_ARG,
415 : : ETH_I40E_VF_MSG_CFG,
416 : : ETH_I40E_MBUF_CHECK_ARG,
417 : : NULL};
418 : :
419 : : static const struct rte_pci_id pci_id_i40e_map[] = {
420 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_XL710) },
421 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QEMU) },
422 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_B) },
423 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_C) },
424 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_A) },
425 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_B) },
426 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_C) },
427 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T) },
428 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_20G_KR2) },
429 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_20G_KR2_A) },
430 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T4) },
431 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_B) },
432 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_SFP28) },
433 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_X722_A0) },
434 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_X722) },
435 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_X722) },
436 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_X722) },
437 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_1G_BASE_T_X722) },
438 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_X722) },
439 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_I_X722) },
440 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_X710_N3000) },
441 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_XXV710_N3000) },
442 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_BC) },
443 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_5G_BASE_T_BC) },
444 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_1G_BASE_T_BC) },
445 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_B) },
446 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_SFP) },
447 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_X722_A) },
448 : : { .vendor_id = 0, /* sentinel */ },
449 : : };
450 : :
451 : : static const struct eth_dev_ops i40e_eth_dev_ops = {
452 : : .dev_configure = i40e_dev_configure,
453 : : .dev_start = i40e_dev_start,
454 : : .dev_stop = i40e_dev_stop,
455 : : .dev_close = i40e_dev_close,
456 : : .dev_reset = i40e_dev_reset,
457 : : .promiscuous_enable = i40e_dev_promiscuous_enable,
458 : : .promiscuous_disable = i40e_dev_promiscuous_disable,
459 : : .allmulticast_enable = i40e_dev_allmulticast_enable,
460 : : .allmulticast_disable = i40e_dev_allmulticast_disable,
461 : : .dev_set_link_up = i40e_dev_set_link_up,
462 : : .dev_set_link_down = i40e_dev_set_link_down,
463 : : .link_update = i40e_dev_link_update,
464 : : .stats_get = i40e_dev_stats_get,
465 : : .xstats_get = i40e_dev_xstats_get,
466 : : .xstats_get_names = i40e_dev_xstats_get_names,
467 : : .stats_reset = i40e_dev_stats_reset,
468 : : .xstats_reset = i40e_dev_stats_reset,
469 : : .fw_version_get = i40e_fw_version_get,
470 : : .dev_infos_get = i40e_dev_info_get,
471 : : .dev_supported_ptypes_get = i40e_dev_supported_ptypes_get,
472 : : .vlan_filter_set = i40e_vlan_filter_set,
473 : : .vlan_tpid_set = i40e_vlan_tpid_set,
474 : : .vlan_offload_set = i40e_vlan_offload_set,
475 : : .vlan_strip_queue_set = i40e_vlan_strip_queue_set,
476 : : .vlan_pvid_set = i40e_vlan_pvid_set,
477 : : .rx_queue_start = i40e_dev_rx_queue_start,
478 : : .rx_queue_stop = i40e_dev_rx_queue_stop,
479 : : .tx_queue_start = i40e_dev_tx_queue_start,
480 : : .tx_queue_stop = i40e_dev_tx_queue_stop,
481 : : .rx_queue_setup = i40e_dev_rx_queue_setup,
482 : : .rx_queue_intr_enable = i40e_dev_rx_queue_intr_enable,
483 : : .rx_queue_intr_disable = i40e_dev_rx_queue_intr_disable,
484 : : .rx_queue_release = i40e_dev_rx_queue_release,
485 : : .tx_queue_setup = i40e_dev_tx_queue_setup,
486 : : .tx_queue_release = i40e_dev_tx_queue_release,
487 : : .dev_led_on = i40e_dev_led_on,
488 : : .dev_led_off = i40e_dev_led_off,
489 : : .flow_ctrl_get = i40e_flow_ctrl_get,
490 : : .flow_ctrl_set = i40e_flow_ctrl_set,
491 : : .priority_flow_ctrl_set = i40e_priority_flow_ctrl_set,
492 : : .mac_addr_add = i40e_macaddr_add,
493 : : .mac_addr_remove = i40e_macaddr_remove,
494 : : .reta_update = i40e_dev_rss_reta_update,
495 : : .reta_query = i40e_dev_rss_reta_query,
496 : : .rss_hash_update = i40e_dev_rss_hash_update,
497 : : .rss_hash_conf_get = i40e_dev_rss_hash_conf_get,
498 : : .udp_tunnel_port_add = i40e_dev_udp_tunnel_port_add,
499 : : .udp_tunnel_port_del = i40e_dev_udp_tunnel_port_del,
500 : : .flow_ops_get = i40e_dev_flow_ops_get,
501 : : .rxq_info_get = i40e_rxq_info_get,
502 : : .txq_info_get = i40e_txq_info_get,
503 : : .recycle_rxq_info_get = i40e_recycle_rxq_info_get,
504 : : .rx_burst_mode_get = i40e_rx_burst_mode_get,
505 : : .tx_burst_mode_get = i40e_tx_burst_mode_get,
506 : : .timesync_enable = i40e_timesync_enable,
507 : : .timesync_disable = i40e_timesync_disable,
508 : : .timesync_read_rx_timestamp = i40e_timesync_read_rx_timestamp,
509 : : .timesync_read_tx_timestamp = i40e_timesync_read_tx_timestamp,
510 : : .get_dcb_info = i40e_dev_get_dcb_info,
511 : : .timesync_adjust_time = i40e_timesync_adjust_time,
512 : : .timesync_read_time = i40e_timesync_read_time,
513 : : .timesync_write_time = i40e_timesync_write_time,
514 : : .get_reg = i40e_get_regs,
515 : : .get_eeprom_length = i40e_get_eeprom_length,
516 : : .get_eeprom = i40e_get_eeprom,
517 : : .get_module_info = i40e_get_module_info,
518 : : .get_module_eeprom = i40e_get_module_eeprom,
519 : : .mac_addr_set = i40e_set_default_mac_addr,
520 : : .mtu_set = i40e_dev_mtu_set,
521 : : .tm_ops_get = i40e_tm_ops_get,
522 : : .tx_done_cleanup = i40e_tx_done_cleanup,
523 : : .get_monitor_addr = i40e_get_monitor_addr,
524 : : };
525 : :
526 : : /* store statistics names and its offset in stats structure */
527 : : struct rte_i40e_xstats_name_off {
528 : : char name[RTE_ETH_XSTATS_NAME_SIZE];
529 : : int offset;
530 : : };
531 : :
532 : : static const struct rte_i40e_xstats_name_off rte_i40e_stats_strings[] = {
533 : : {"rx_unicast_packets", offsetof(struct i40e_eth_stats, rx_unicast)},
534 : : {"rx_multicast_packets", offsetof(struct i40e_eth_stats, rx_multicast)},
535 : : {"rx_broadcast_packets", offsetof(struct i40e_eth_stats, rx_broadcast)},
536 : : {"rx_dropped_packets", offsetof(struct i40e_eth_stats, rx_discards)},
537 : : {"rx_unknown_protocol_packets", offsetof(struct i40e_eth_stats,
538 : : rx_unknown_protocol)},
539 : : {"rx_size_error_packets", offsetof(struct i40e_pf, rx_err1) -
540 : : offsetof(struct i40e_pf, stats)},
541 : : {"tx_unicast_packets", offsetof(struct i40e_eth_stats, tx_unicast)},
542 : : {"tx_multicast_packets", offsetof(struct i40e_eth_stats, tx_multicast)},
543 : : {"tx_broadcast_packets", offsetof(struct i40e_eth_stats, tx_broadcast)},
544 : : {"tx_dropped_packets", offsetof(struct i40e_eth_stats, tx_discards)},
545 : : };
546 : :
547 : : #define I40E_NB_ETH_XSTATS (sizeof(rte_i40e_stats_strings) / \
548 : : sizeof(rte_i40e_stats_strings[0]))
549 : :
550 : : static const struct rte_i40e_xstats_name_off i40e_mbuf_strings[] = {
551 : : {"tx_mbuf_error_packets", offsetof(struct i40e_mbuf_stats, tx_pkt_errors)},
552 : : };
553 : :
554 : : #define I40E_NB_MBUF_XSTATS (sizeof(i40e_mbuf_strings) / sizeof(i40e_mbuf_strings[0]))
555 : :
556 : : static const struct rte_i40e_xstats_name_off rte_i40e_hw_port_strings[] = {
557 : : {"tx_link_down_dropped", offsetof(struct i40e_hw_port_stats,
558 : : tx_dropped_link_down)},
559 : : {"rx_crc_errors", offsetof(struct i40e_hw_port_stats, crc_errors)},
560 : : {"rx_illegal_byte_errors", offsetof(struct i40e_hw_port_stats,
561 : : illegal_bytes)},
562 : : {"rx_error_bytes", offsetof(struct i40e_hw_port_stats, error_bytes)},
563 : : {"mac_local_errors", offsetof(struct i40e_hw_port_stats,
564 : : mac_local_faults)},
565 : : {"mac_remote_errors", offsetof(struct i40e_hw_port_stats,
566 : : mac_remote_faults)},
567 : : {"rx_length_errors", offsetof(struct i40e_hw_port_stats,
568 : : rx_length_errors)},
569 : : {"tx_xon_packets", offsetof(struct i40e_hw_port_stats, link_xon_tx)},
570 : : {"rx_xon_packets", offsetof(struct i40e_hw_port_stats, link_xon_rx)},
571 : : {"tx_xoff_packets", offsetof(struct i40e_hw_port_stats, link_xoff_tx)},
572 : : {"rx_xoff_packets", offsetof(struct i40e_hw_port_stats, link_xoff_rx)},
573 : : {"rx_size_64_packets", offsetof(struct i40e_hw_port_stats, rx_size_64)},
574 : : {"rx_size_65_to_127_packets", offsetof(struct i40e_hw_port_stats,
575 : : rx_size_127)},
576 : : {"rx_size_128_to_255_packets", offsetof(struct i40e_hw_port_stats,
577 : : rx_size_255)},
578 : : {"rx_size_256_to_511_packets", offsetof(struct i40e_hw_port_stats,
579 : : rx_size_511)},
580 : : {"rx_size_512_to_1023_packets", offsetof(struct i40e_hw_port_stats,
581 : : rx_size_1023)},
582 : : {"rx_size_1024_to_1522_packets", offsetof(struct i40e_hw_port_stats,
583 : : rx_size_1522)},
584 : : {"rx_size_1523_to_max_packets", offsetof(struct i40e_hw_port_stats,
585 : : rx_size_big)},
586 : : {"rx_undersized_errors", offsetof(struct i40e_hw_port_stats,
587 : : rx_undersize)},
588 : : {"rx_oversize_errors", offsetof(struct i40e_hw_port_stats,
589 : : rx_oversize)},
590 : : {"rx_mac_short_dropped", offsetof(struct i40e_hw_port_stats,
591 : : mac_short_packet_dropped)},
592 : : {"rx_fragmented_errors", offsetof(struct i40e_hw_port_stats,
593 : : rx_fragments)},
594 : : {"rx_jabber_errors", offsetof(struct i40e_hw_port_stats, rx_jabber)},
595 : : {"tx_size_64_packets", offsetof(struct i40e_hw_port_stats, tx_size_64)},
596 : : {"tx_size_65_to_127_packets", offsetof(struct i40e_hw_port_stats,
597 : : tx_size_127)},
598 : : {"tx_size_128_to_255_packets", offsetof(struct i40e_hw_port_stats,
599 : : tx_size_255)},
600 : : {"tx_size_256_to_511_packets", offsetof(struct i40e_hw_port_stats,
601 : : tx_size_511)},
602 : : {"tx_size_512_to_1023_packets", offsetof(struct i40e_hw_port_stats,
603 : : tx_size_1023)},
604 : : {"tx_size_1024_to_1522_packets", offsetof(struct i40e_hw_port_stats,
605 : : tx_size_1522)},
606 : : {"tx_size_1523_to_max_packets", offsetof(struct i40e_hw_port_stats,
607 : : tx_size_big)},
608 : : {"rx_flow_director_atr_match_packets",
609 : : offsetof(struct i40e_hw_port_stats, fd_atr_match)},
610 : : {"rx_flow_director_sb_match_packets",
611 : : offsetof(struct i40e_hw_port_stats, fd_sb_match)},
612 : : {"tx_low_power_idle_status", offsetof(struct i40e_hw_port_stats,
613 : : tx_lpi_status)},
614 : : {"rx_low_power_idle_status", offsetof(struct i40e_hw_port_stats,
615 : : rx_lpi_status)},
616 : : {"tx_low_power_idle_count", offsetof(struct i40e_hw_port_stats,
617 : : tx_lpi_count)},
618 : : {"rx_low_power_idle_count", offsetof(struct i40e_hw_port_stats,
619 : : rx_lpi_count)},
620 : : };
621 : :
622 : : #define I40E_NB_HW_PORT_XSTATS (sizeof(rte_i40e_hw_port_strings) / \
623 : : sizeof(rte_i40e_hw_port_strings[0]))
624 : :
625 : : static const struct rte_i40e_xstats_name_off rte_i40e_rxq_prio_strings[] = {
626 : : {"xon_packets", offsetof(struct i40e_hw_port_stats,
627 : : priority_xon_rx)},
628 : : {"xoff_packets", offsetof(struct i40e_hw_port_stats,
629 : : priority_xoff_rx)},
630 : : };
631 : :
632 : : #define I40E_NB_RXQ_PRIO_XSTATS (sizeof(rte_i40e_rxq_prio_strings) / \
633 : : sizeof(rte_i40e_rxq_prio_strings[0]))
634 : :
635 : : static const struct rte_i40e_xstats_name_off rte_i40e_txq_prio_strings[] = {
636 : : {"xon_packets", offsetof(struct i40e_hw_port_stats,
637 : : priority_xon_tx)},
638 : : {"xoff_packets", offsetof(struct i40e_hw_port_stats,
639 : : priority_xoff_tx)},
640 : : {"xon_to_xoff_packets", offsetof(struct i40e_hw_port_stats,
641 : : priority_xon_2_xoff)},
642 : : };
643 : :
644 : : #define I40E_NB_TXQ_PRIO_XSTATS (sizeof(rte_i40e_txq_prio_strings) / \
645 : : sizeof(rte_i40e_txq_prio_strings[0]))
646 : :
647 : : static int
648 : 0 : eth_i40e_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
649 : : struct rte_pci_device *pci_dev)
650 : : {
651 : : char name[RTE_ETH_NAME_MAX_LEN];
652 : 0 : struct rte_eth_devargs eth_da = { .nb_representor_ports = 0 };
653 : : int i, retval;
654 : :
655 [ # # ]: 0 : if (pci_dev->device.devargs) {
656 : 0 : retval = rte_eth_devargs_parse(pci_dev->device.devargs->args,
657 : : ð_da, 1);
658 [ # # ]: 0 : if (retval < 0)
659 : : return retval;
660 : : }
661 : :
662 [ # # ]: 0 : if (eth_da.nb_representor_ports > 0 &&
663 [ # # ]: 0 : eth_da.type != RTE_ETH_REPRESENTOR_VF) {
664 : 0 : PMD_DRV_LOG(ERR, "unsupported representor type: %s\n",
665 : : pci_dev->device.devargs->args);
666 : 0 : return -ENOTSUP;
667 : : }
668 : :
669 : 0 : retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
670 : : sizeof(struct i40e_adapter),
671 : : eth_dev_pci_specific_init, pci_dev,
672 : : eth_i40e_dev_init, NULL);
673 : :
674 [ # # # # ]: 0 : if (retval || eth_da.nb_representor_ports < 1)
675 : : return retval;
676 : :
677 : : /* probe VF representor ports */
678 : 0 : struct rte_eth_dev *pf_ethdev = rte_eth_dev_allocated(
679 : : pci_dev->device.name);
680 : :
681 [ # # ]: 0 : if (pf_ethdev == NULL)
682 : : return -ENODEV;
683 : :
684 [ # # ]: 0 : for (i = 0; i < eth_da.nb_representor_ports; i++) {
685 : 0 : struct i40e_vf_representor representor = {
686 : 0 : .vf_id = eth_da.representor_ports[i],
687 : 0 : .switch_domain_id = I40E_DEV_PRIVATE_TO_PF(
688 : 0 : pf_ethdev->data->dev_private)->switch_domain_id,
689 : : .adapter = I40E_DEV_PRIVATE_TO_ADAPTER(
690 : : pf_ethdev->data->dev_private)
691 : : };
692 : :
693 : : /* representor port net_bdf_port */
694 : 0 : snprintf(name, sizeof(name), "net_%s_representor_%d",
695 : : pci_dev->device.name, eth_da.representor_ports[i]);
696 : :
697 : 0 : retval = rte_eth_dev_create(&pci_dev->device, name,
698 : : sizeof(struct i40e_vf_representor), NULL, NULL,
699 : : i40e_vf_representor_init, &representor);
700 : :
701 [ # # ]: 0 : if (retval)
702 : 0 : PMD_DRV_LOG(ERR, "failed to create i40e vf "
703 : : "representor %s.", name);
704 : : }
705 : :
706 : : return 0;
707 : : }
708 : :
709 : 0 : static int eth_i40e_pci_remove(struct rte_pci_device *pci_dev)
710 : : {
711 : : struct rte_eth_dev *ethdev;
712 : :
713 : 0 : ethdev = rte_eth_dev_allocated(pci_dev->device.name);
714 [ # # ]: 0 : if (!ethdev)
715 : : return 0;
716 : :
717 [ # # ]: 0 : if (rte_eth_dev_is_repr(ethdev))
718 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev,
719 : : i40e_vf_representor_uninit);
720 : : else
721 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev,
722 : : eth_i40e_dev_uninit);
723 : : }
724 : :
725 : : static struct rte_pci_driver rte_i40e_pmd = {
726 : : .id_table = pci_id_i40e_map,
727 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
728 : : .probe = eth_i40e_pci_probe,
729 : : .remove = eth_i40e_pci_remove,
730 : : };
731 : :
732 : : static inline void
733 : 0 : i40e_write_global_rx_ctl(struct i40e_hw *hw, uint32_t reg_addr,
734 : : uint32_t reg_val)
735 : : {
736 : : uint32_t ori_reg_val;
737 : 0 : struct rte_eth_dev_data *dev_data =
738 : 0 : ((struct i40e_adapter *)hw->back)->pf.dev_data;
739 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[dev_data->port_id];
740 : :
741 : 0 : ori_reg_val = i40e_read_rx_ctl(hw, reg_addr);
742 : 0 : i40e_write_rx_ctl(hw, reg_addr, reg_val);
743 [ # # ]: 0 : if (ori_reg_val != reg_val)
744 : 0 : PMD_DRV_LOG(WARNING,
745 : : "i40e device %s changed global register [0x%08x]."
746 : : " original: 0x%08x, new: 0x%08x",
747 : : dev->device->name, reg_addr, ori_reg_val, reg_val);
748 : 0 : }
749 : :
750 : 238 : RTE_PMD_REGISTER_PCI(net_i40e, rte_i40e_pmd);
751 : : RTE_PMD_REGISTER_PCI_TABLE(net_i40e, pci_id_i40e_map);
752 : : RTE_PMD_REGISTER_KMOD_DEP(net_i40e, "* igb_uio | uio_pci_generic | vfio-pci");
753 : :
754 : : #ifndef I40E_GLQF_ORT
755 : : #define I40E_GLQF_ORT(_i) (0x00268900 + ((_i) * 4))
756 : : #endif
757 : : #ifndef I40E_GLQF_PIT
758 : : #define I40E_GLQF_PIT(_i) (0x00268C80 + ((_i) * 4))
759 : : #endif
760 : : #ifndef I40E_GLQF_L3_MAP
761 : : #define I40E_GLQF_L3_MAP(_i) (0x0026C700 + ((_i) * 4))
762 : : #endif
763 : :
764 : 0 : static inline void i40e_GLQF_reg_init(struct i40e_hw *hw)
765 : : {
766 : : /*
767 : : * Initialize registers for parsing packet type of QinQ
768 : : * This should be removed from code once proper
769 : : * configuration API is added to avoid configuration conflicts
770 : : * between ports of the same device.
771 : : */
772 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(40), 0x00000029);
773 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_PIT(9), 0x00009420);
774 : 0 : }
775 : :
776 : : static inline void i40e_config_automask(struct i40e_pf *pf)
777 : : {
778 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
779 : : uint32_t val;
780 : :
781 : : /* INTENA flag is not auto-cleared for interrupt */
782 : 0 : val = I40E_READ_REG(hw, I40E_GLINT_CTL);
783 : 0 : val |= I40E_GLINT_CTL_DIS_AUTOMASK_PF0_MASK |
784 : : I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK;
785 : :
786 : : /* If support multi-driver, PF will use INT0. */
787 [ # # ]: 0 : if (!pf->support_multi_driver)
788 : 0 : val |= I40E_GLINT_CTL_DIS_AUTOMASK_N_MASK;
789 : :
790 : 0 : I40E_WRITE_REG(hw, I40E_GLINT_CTL, val);
791 : : }
792 : :
793 : : static inline void i40e_clear_automask(struct i40e_pf *pf)
794 : : {
795 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
796 : : uint32_t val;
797 : :
798 : 0 : val = I40E_READ_REG(hw, I40E_GLINT_CTL);
799 : 0 : val &= ~(I40E_GLINT_CTL_DIS_AUTOMASK_PF0_MASK |
800 : : I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK);
801 : :
802 [ # # ]: 0 : if (!pf->support_multi_driver)
803 : 0 : val &= ~I40E_GLINT_CTL_DIS_AUTOMASK_N_MASK;
804 : :
805 : 0 : I40E_WRITE_REG(hw, I40E_GLINT_CTL, val);
806 : : }
807 : :
808 : : #define I40E_FLOW_CONTROL_ETHERTYPE 0x8808
809 : :
810 : : /*
811 : : * Add a ethertype filter to drop all flow control frames transmitted
812 : : * from VSIs.
813 : : */
814 : : static void
815 : 0 : i40e_add_tx_flow_control_drop_filter(struct i40e_pf *pf)
816 : : {
817 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
818 : : uint16_t flags = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
819 : : I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
820 : : I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
821 : : int ret;
822 : :
823 : 0 : ret = i40e_aq_add_rem_control_packet_filter(hw, NULL,
824 : : I40E_FLOW_CONTROL_ETHERTYPE, flags,
825 : 0 : pf->main_vsi_seid, 0,
826 : : TRUE, NULL, NULL);
827 [ # # ]: 0 : if (ret)
828 : 0 : PMD_INIT_LOG(ERR,
829 : : "Failed to add filter to drop flow control frames from VSIs.");
830 : 0 : }
831 : :
832 : : static int
833 : 0 : floating_veb_list_handler(__rte_unused const char *key,
834 : : const char *floating_veb_value,
835 : : void *opaque)
836 : : {
837 : : int idx = 0;
838 : : unsigned int count = 0;
839 : 0 : char *end = NULL;
840 : : int min, max;
841 : : bool *vf_floating_veb = opaque;
842 : :
843 [ # # ]: 0 : while (isblank(*floating_veb_value))
844 : 0 : floating_veb_value++;
845 : :
846 : : /* Reset floating VEB configuration for VFs */
847 [ # # ]: 0 : for (idx = 0; idx < I40E_MAX_VF; idx++)
848 : 0 : vf_floating_veb[idx] = false;
849 : :
850 : : min = I40E_MAX_VF;
851 : : do {
852 [ # # ]: 0 : while (isblank(*floating_veb_value))
853 : 0 : floating_veb_value++;
854 [ # # ]: 0 : if (*floating_veb_value == '\0')
855 : : return -1;
856 : 0 : errno = 0;
857 : 0 : idx = strtoul(floating_veb_value, &end, 10);
858 [ # # # # ]: 0 : if (errno || end == NULL)
859 : : return -1;
860 [ # # ]: 0 : if (idx < 0)
861 : : return -1;
862 [ # # ]: 0 : while (isblank(*end))
863 : 0 : end++;
864 [ # # ]: 0 : if (*end == '-') {
865 : : min = idx;
866 [ # # ]: 0 : } else if ((*end == ';') || (*end == '\0')) {
867 : : max = idx;
868 [ # # ]: 0 : if (min == I40E_MAX_VF)
869 : : min = idx;
870 : : if (max >= I40E_MAX_VF)
871 : : max = I40E_MAX_VF - 1;
872 [ # # ]: 0 : for (idx = min; idx <= max; idx++) {
873 : 0 : vf_floating_veb[idx] = true;
874 : 0 : count++;
875 : : }
876 : : min = I40E_MAX_VF;
877 : : } else {
878 : : return -1;
879 : : }
880 : 0 : floating_veb_value = end + 1;
881 [ # # ]: 0 : } while (*end != '\0');
882 : :
883 [ # # ]: 0 : if (count == 0)
884 : 0 : return -1;
885 : :
886 : : return 0;
887 : : }
888 : :
889 : : static void
890 : 0 : config_vf_floating_veb(struct rte_devargs *devargs,
891 : : uint16_t floating_veb,
892 : : bool *vf_floating_veb)
893 : : {
894 : : struct rte_kvargs *kvlist;
895 : : int i;
896 : : const char *floating_veb_list = ETH_I40E_FLOATING_VEB_LIST_ARG;
897 : :
898 [ # # ]: 0 : if (!floating_veb)
899 : : return;
900 : : /* All the VFs attach to the floating VEB by default
901 : : * when the floating VEB is enabled.
902 : : */
903 [ # # ]: 0 : for (i = 0; i < I40E_MAX_VF; i++)
904 : 0 : vf_floating_veb[i] = true;
905 : :
906 [ # # ]: 0 : if (devargs == NULL)
907 : : return;
908 : :
909 : 0 : kvlist = rte_kvargs_parse(devargs->args, valid_keys);
910 [ # # ]: 0 : if (kvlist == NULL)
911 : : return;
912 : :
913 [ # # ]: 0 : if (!rte_kvargs_count(kvlist, floating_veb_list)) {
914 : 0 : rte_kvargs_free(kvlist);
915 : 0 : return;
916 : : }
917 : : /* When the floating_veb_list parameter exists, all the VFs
918 : : * will attach to the legacy VEB firstly, then configure VFs
919 : : * to the floating VEB according to the floating_veb_list.
920 : : */
921 [ # # ]: 0 : if (rte_kvargs_process(kvlist, floating_veb_list,
922 : : floating_veb_list_handler,
923 : : vf_floating_veb) < 0) {
924 : 0 : rte_kvargs_free(kvlist);
925 : 0 : return;
926 : : }
927 : 0 : rte_kvargs_free(kvlist);
928 : : }
929 : :
930 : : static int
931 : 0 : i40e_check_floating_handler(__rte_unused const char *key,
932 : : const char *value,
933 : : __rte_unused void *opaque)
934 : : {
935 [ # # ]: 0 : if (strcmp(value, "1"))
936 : 0 : return -1;
937 : :
938 : : return 0;
939 : : }
940 : :
941 : : static int
942 : 0 : is_floating_veb_supported(struct rte_devargs *devargs)
943 : : {
944 : : struct rte_kvargs *kvlist;
945 : : const char *floating_veb_key = ETH_I40E_FLOATING_VEB_ARG;
946 : :
947 [ # # ]: 0 : if (devargs == NULL)
948 : : return 0;
949 : :
950 : 0 : kvlist = rte_kvargs_parse(devargs->args, valid_keys);
951 [ # # ]: 0 : if (kvlist == NULL)
952 : : return 0;
953 : :
954 [ # # ]: 0 : if (!rte_kvargs_count(kvlist, floating_veb_key)) {
955 : 0 : rte_kvargs_free(kvlist);
956 : 0 : return 0;
957 : : }
958 : : /* Floating VEB is enabled when there's key-value:
959 : : * enable_floating_veb=1
960 : : */
961 [ # # ]: 0 : if (rte_kvargs_process(kvlist, floating_veb_key,
962 : : i40e_check_floating_handler, NULL) < 0) {
963 : 0 : rte_kvargs_free(kvlist);
964 : 0 : return 0;
965 : : }
966 : 0 : rte_kvargs_free(kvlist);
967 : :
968 : 0 : return 1;
969 : : }
970 : :
971 : : static void
972 : 0 : config_floating_veb(struct rte_eth_dev *dev)
973 : : {
974 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
975 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
976 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
977 : :
978 [ # # ]: 0 : memset(pf->floating_veb_list, 0, sizeof(pf->floating_veb_list));
979 : :
980 [ # # ]: 0 : if (hw->aq.fw_maj_ver >= FLOATING_VEB_SUPPORTED_FW_MAJ) {
981 : 0 : pf->floating_veb =
982 : 0 : is_floating_veb_supported(pci_dev->device.devargs);
983 : 0 : config_vf_floating_veb(pci_dev->device.devargs,
984 : : pf->floating_veb,
985 : : pf->floating_veb_list);
986 : : } else {
987 : 0 : pf->floating_veb = false;
988 : : }
989 : 0 : }
990 : :
991 : : #define I40E_L2_TAGS_S_TAG_SHIFT 1
992 : : #define I40E_L2_TAGS_S_TAG_MASK I40E_MASK(0x1, I40E_L2_TAGS_S_TAG_SHIFT)
993 : :
994 : : static int
995 : 0 : i40e_init_ethtype_filter_list(struct rte_eth_dev *dev)
996 : : {
997 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
998 : : struct i40e_ethertype_rule *ethertype_rule = &pf->ethertype;
999 : : char ethertype_hash_name[RTE_HASH_NAMESIZE];
1000 : : int ret;
1001 : :
1002 : 0 : struct rte_hash_parameters ethertype_hash_params = {
1003 : : .name = ethertype_hash_name,
1004 : : .entries = I40E_MAX_ETHERTYPE_FILTER_NUM,
1005 : : .key_len = sizeof(struct i40e_ethertype_filter_input),
1006 : : .hash_func = rte_hash_crc,
1007 : : .hash_func_init_val = 0,
1008 : 0 : .socket_id = rte_socket_id(),
1009 : : };
1010 : :
1011 : : /* Initialize ethertype filter rule list and hash */
1012 : 0 : TAILQ_INIT(ðertype_rule->ethertype_list);
1013 : 0 : snprintf(ethertype_hash_name, RTE_HASH_NAMESIZE,
1014 : 0 : "ethertype_%s", dev->device->name);
1015 : 0 : ethertype_rule->hash_table = rte_hash_create(ðertype_hash_params);
1016 [ # # ]: 0 : if (!ethertype_rule->hash_table) {
1017 : 0 : PMD_INIT_LOG(ERR, "Failed to create ethertype hash table!");
1018 : 0 : return -EINVAL;
1019 : : }
1020 : 0 : ethertype_rule->hash_map = rte_zmalloc("i40e_ethertype_hash_map",
1021 : : sizeof(struct i40e_ethertype_filter *) *
1022 : : I40E_MAX_ETHERTYPE_FILTER_NUM,
1023 : : 0);
1024 [ # # ]: 0 : if (!ethertype_rule->hash_map) {
1025 : 0 : PMD_INIT_LOG(ERR,
1026 : : "Failed to allocate memory for ethertype hash map!");
1027 : : ret = -ENOMEM;
1028 : 0 : goto err_ethertype_hash_map_alloc;
1029 : : }
1030 : :
1031 : : return 0;
1032 : :
1033 : : err_ethertype_hash_map_alloc:
1034 : 0 : rte_hash_free(ethertype_rule->hash_table);
1035 : :
1036 : 0 : return ret;
1037 : : }
1038 : :
1039 : : static int
1040 : 0 : i40e_init_tunnel_filter_list(struct rte_eth_dev *dev)
1041 : : {
1042 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1043 : : struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
1044 : : char tunnel_hash_name[RTE_HASH_NAMESIZE];
1045 : : int ret;
1046 : :
1047 : 0 : struct rte_hash_parameters tunnel_hash_params = {
1048 : : .name = tunnel_hash_name,
1049 : : .entries = I40E_MAX_TUNNEL_FILTER_NUM,
1050 : : .key_len = sizeof(struct i40e_tunnel_filter_input),
1051 : : .hash_func = rte_hash_crc,
1052 : : .hash_func_init_val = 0,
1053 : 0 : .socket_id = rte_socket_id(),
1054 : : };
1055 : :
1056 : : /* Initialize tunnel filter rule list and hash */
1057 : 0 : TAILQ_INIT(&tunnel_rule->tunnel_list);
1058 : 0 : snprintf(tunnel_hash_name, RTE_HASH_NAMESIZE,
1059 : 0 : "tunnel_%s", dev->device->name);
1060 : 0 : tunnel_rule->hash_table = rte_hash_create(&tunnel_hash_params);
1061 [ # # ]: 0 : if (!tunnel_rule->hash_table) {
1062 : 0 : PMD_INIT_LOG(ERR, "Failed to create tunnel hash table!");
1063 : 0 : return -EINVAL;
1064 : : }
1065 : 0 : tunnel_rule->hash_map = rte_zmalloc("i40e_tunnel_hash_map",
1066 : : sizeof(struct i40e_tunnel_filter *) *
1067 : : I40E_MAX_TUNNEL_FILTER_NUM,
1068 : : 0);
1069 [ # # ]: 0 : if (!tunnel_rule->hash_map) {
1070 : 0 : PMD_INIT_LOG(ERR,
1071 : : "Failed to allocate memory for tunnel hash map!");
1072 : : ret = -ENOMEM;
1073 : 0 : goto err_tunnel_hash_map_alloc;
1074 : : }
1075 : :
1076 : : return 0;
1077 : :
1078 : : err_tunnel_hash_map_alloc:
1079 : 0 : rte_hash_free(tunnel_rule->hash_table);
1080 : :
1081 : 0 : return ret;
1082 : : }
1083 : :
1084 : : static int
1085 : 0 : i40e_init_fdir_filter_list(struct rte_eth_dev *dev)
1086 : : {
1087 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1088 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1089 : : struct i40e_fdir_info *fdir_info = &pf->fdir;
1090 : : char fdir_hash_name[RTE_HASH_NAMESIZE];
1091 : 0 : uint32_t alloc = hw->func_caps.fd_filters_guaranteed;
1092 : 0 : uint32_t best = hw->func_caps.fd_filters_best_effort;
1093 : : enum i40e_filter_pctype pctype;
1094 : : struct rte_bitmap *bmp = NULL;
1095 : : uint32_t bmp_size;
1096 : : void *mem = NULL;
1097 : : uint32_t i = 0;
1098 : : int ret;
1099 : :
1100 : 0 : struct rte_hash_parameters fdir_hash_params = {
1101 : : .name = fdir_hash_name,
1102 : : .entries = I40E_MAX_FDIR_FILTER_NUM,
1103 : : .key_len = sizeof(struct i40e_fdir_input),
1104 : : .hash_func = rte_hash_crc,
1105 : : .hash_func_init_val = 0,
1106 : 0 : .socket_id = rte_socket_id(),
1107 : : };
1108 : :
1109 : : /* Initialize flow director filter rule list and hash */
1110 : 0 : TAILQ_INIT(&fdir_info->fdir_list);
1111 : 0 : snprintf(fdir_hash_name, RTE_HASH_NAMESIZE,
1112 : 0 : "fdir_%s", dev->device->name);
1113 : 0 : fdir_info->hash_table = rte_hash_create(&fdir_hash_params);
1114 [ # # ]: 0 : if (!fdir_info->hash_table) {
1115 : 0 : PMD_INIT_LOG(ERR, "Failed to create fdir hash table!");
1116 : 0 : return -EINVAL;
1117 : : }
1118 : :
1119 : 0 : fdir_info->hash_map = rte_zmalloc("i40e_fdir_hash_map",
1120 : : sizeof(struct i40e_fdir_filter *) *
1121 : : I40E_MAX_FDIR_FILTER_NUM,
1122 : : 0);
1123 [ # # ]: 0 : if (!fdir_info->hash_map) {
1124 : 0 : PMD_INIT_LOG(ERR,
1125 : : "Failed to allocate memory for fdir hash map!");
1126 : : ret = -ENOMEM;
1127 : 0 : goto err_fdir_hash_map_alloc;
1128 : : }
1129 : :
1130 : 0 : fdir_info->fdir_filter_array = rte_zmalloc("fdir_filter",
1131 : : sizeof(struct i40e_fdir_filter) *
1132 : : I40E_MAX_FDIR_FILTER_NUM,
1133 : : 0);
1134 : :
1135 [ # # ]: 0 : if (!fdir_info->fdir_filter_array) {
1136 : 0 : PMD_INIT_LOG(ERR,
1137 : : "Failed to allocate memory for fdir filter array!");
1138 : : ret = -ENOMEM;
1139 : 0 : goto err_fdir_filter_array_alloc;
1140 : : }
1141 : :
1142 : : for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
1143 [ # # ]: 0 : pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++)
1144 : 0 : pf->fdir.flow_count[pctype] = 0;
1145 : :
1146 : 0 : fdir_info->fdir_space_size = alloc + best;
1147 : 0 : fdir_info->fdir_actual_cnt = 0;
1148 : 0 : fdir_info->fdir_guarantee_total_space = alloc;
1149 : 0 : fdir_info->fdir_guarantee_free_space =
1150 : : fdir_info->fdir_guarantee_total_space;
1151 : :
1152 : 0 : PMD_DRV_LOG(INFO, "FDIR guarantee space: %u, best_effort space %u.", alloc, best);
1153 : :
1154 : 0 : fdir_info->fdir_flow_pool.pool =
1155 : 0 : rte_zmalloc("i40e_fdir_entry",
1156 : : sizeof(struct i40e_fdir_entry) *
1157 : 0 : fdir_info->fdir_space_size,
1158 : : 0);
1159 : :
1160 [ # # ]: 0 : if (!fdir_info->fdir_flow_pool.pool) {
1161 : 0 : PMD_INIT_LOG(ERR,
1162 : : "Failed to allocate memory for bitmap flow!");
1163 : : ret = -ENOMEM;
1164 : 0 : goto err_fdir_bitmap_flow_alloc;
1165 : : }
1166 : :
1167 [ # # ]: 0 : for (i = 0; i < fdir_info->fdir_space_size; i++)
1168 : 0 : fdir_info->fdir_flow_pool.pool[i].idx = i;
1169 : :
1170 : : bmp_size =
1171 : 0 : rte_bitmap_get_memory_footprint(fdir_info->fdir_space_size);
1172 : 0 : mem = rte_zmalloc("fdir_bmap", bmp_size, RTE_CACHE_LINE_SIZE);
1173 [ # # ]: 0 : if (mem == NULL) {
1174 : 0 : PMD_INIT_LOG(ERR,
1175 : : "Failed to allocate memory for fdir bitmap!");
1176 : : ret = -ENOMEM;
1177 : 0 : goto err_fdir_mem_alloc;
1178 : : }
1179 : 0 : bmp = rte_bitmap_init(fdir_info->fdir_space_size, mem, bmp_size);
1180 [ # # ]: 0 : if (bmp == NULL) {
1181 : 0 : PMD_INIT_LOG(ERR,
1182 : : "Failed to initialization fdir bitmap!");
1183 : : ret = -ENOMEM;
1184 : 0 : goto err_fdir_bmp_alloc;
1185 : : }
1186 [ # # ]: 0 : for (i = 0; i < fdir_info->fdir_space_size; i++)
1187 : 0 : rte_bitmap_set(bmp, i);
1188 : :
1189 : 0 : fdir_info->fdir_flow_pool.bitmap = bmp;
1190 : :
1191 : 0 : return 0;
1192 : :
1193 : : err_fdir_bmp_alloc:
1194 : 0 : rte_free(mem);
1195 : 0 : err_fdir_mem_alloc:
1196 : 0 : rte_free(fdir_info->fdir_flow_pool.pool);
1197 : 0 : err_fdir_bitmap_flow_alloc:
1198 : 0 : rte_free(fdir_info->fdir_filter_array);
1199 : 0 : err_fdir_filter_array_alloc:
1200 : 0 : rte_free(fdir_info->hash_map);
1201 : 0 : err_fdir_hash_map_alloc:
1202 : 0 : rte_hash_free(fdir_info->hash_table);
1203 : :
1204 : 0 : return ret;
1205 : : }
1206 : :
1207 : : static void
1208 : : i40e_init_customized_info(struct i40e_pf *pf)
1209 : : {
1210 : : int i;
1211 : :
1212 : : /* Initialize customized pctype */
1213 [ # # ]: 0 : for (i = I40E_CUSTOMIZED_GTPC; i < I40E_CUSTOMIZED_MAX; i++) {
1214 : 0 : pf->customized_pctype[i].index = i;
1215 : 0 : pf->customized_pctype[i].pctype = I40E_FILTER_PCTYPE_INVALID;
1216 : 0 : pf->customized_pctype[i].valid = false;
1217 : : }
1218 : :
1219 : 0 : pf->gtp_support = false;
1220 : 0 : pf->esp_support = false;
1221 : : }
1222 : :
1223 : : static void
1224 : 0 : i40e_init_filter_invalidation(struct i40e_pf *pf)
1225 : : {
1226 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1227 : : struct i40e_fdir_info *fdir_info = &pf->fdir;
1228 : : uint32_t glqf_ctl_reg = 0;
1229 : :
1230 : 0 : glqf_ctl_reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
1231 [ # # ]: 0 : if (!pf->support_multi_driver) {
1232 : 0 : fdir_info->fdir_invalprio = 1;
1233 : 0 : glqf_ctl_reg |= I40E_GLQF_CTL_INVALPRIO_MASK;
1234 : 0 : PMD_DRV_LOG(INFO, "FDIR INVALPRIO set to guaranteed first");
1235 : 0 : i40e_write_rx_ctl(hw, I40E_GLQF_CTL, glqf_ctl_reg);
1236 : : } else {
1237 [ # # ]: 0 : if (glqf_ctl_reg & I40E_GLQF_CTL_INVALPRIO_MASK) {
1238 : 0 : fdir_info->fdir_invalprio = 1;
1239 : 0 : PMD_DRV_LOG(INFO, "FDIR INVALPRIO is: guaranteed first");
1240 : : } else {
1241 : 0 : fdir_info->fdir_invalprio = 0;
1242 : 0 : PMD_DRV_LOG(INFO, "FDIR INVALPRIO is: shared first");
1243 : : }
1244 : : }
1245 : 0 : }
1246 : :
1247 : : void
1248 : 0 : i40e_init_queue_region_conf(struct rte_eth_dev *dev)
1249 : : {
1250 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1251 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1252 : 0 : struct i40e_queue_regions *info = &pf->queue_region;
1253 : : uint16_t i;
1254 : :
1255 [ # # ]: 0 : for (i = 0; i < I40E_PFQF_HREGION_MAX_INDEX; i++)
1256 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HREGION(i), 0);
1257 : :
1258 : : memset(info, 0, sizeof(struct i40e_queue_regions));
1259 : 0 : }
1260 : :
1261 : : static int
1262 : 0 : i40e_parse_multi_drv_handler(__rte_unused const char *key,
1263 : : const char *value,
1264 : : void *opaque)
1265 : : {
1266 : : struct i40e_pf *pf;
1267 : : unsigned long support_multi_driver;
1268 : : char *end;
1269 : :
1270 : : pf = (struct i40e_pf *)opaque;
1271 : :
1272 : 0 : errno = 0;
1273 : 0 : support_multi_driver = strtoul(value, &end, 10);
1274 [ # # # # : 0 : if (errno != 0 || end == value || *end != 0) {
# # ]
1275 : 0 : PMD_DRV_LOG(WARNING, "Wrong global configuration");
1276 : 0 : return -(EINVAL);
1277 : : }
1278 : :
1279 [ # # ]: 0 : if (support_multi_driver == 1 || support_multi_driver == 0)
1280 : 0 : pf->support_multi_driver = (bool)support_multi_driver;
1281 : : else
1282 : 0 : PMD_DRV_LOG(WARNING, "%s must be 1 or 0,",
1283 : : "enable global configuration by default."
1284 : : ETH_I40E_SUPPORT_MULTI_DRIVER);
1285 : : return 0;
1286 : : }
1287 : :
1288 : : static int
1289 : 0 : i40e_support_multi_driver(struct rte_eth_dev *dev)
1290 : : {
1291 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1292 : : struct rte_kvargs *kvlist;
1293 : : int kvargs_count;
1294 : :
1295 : : /* Enable global configuration by default */
1296 : 0 : pf->support_multi_driver = false;
1297 : :
1298 [ # # ]: 0 : if (!dev->device->devargs)
1299 : : return 0;
1300 : :
1301 : 0 : kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
1302 [ # # ]: 0 : if (!kvlist)
1303 : : return -EINVAL;
1304 : :
1305 : 0 : kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_SUPPORT_MULTI_DRIVER);
1306 [ # # ]: 0 : if (!kvargs_count) {
1307 : 0 : rte_kvargs_free(kvlist);
1308 : 0 : return 0;
1309 : : }
1310 : :
1311 [ # # ]: 0 : if (kvargs_count > 1)
1312 : 0 : PMD_DRV_LOG(WARNING, "More than one argument \"%s\" and only "
1313 : : "the first invalid or last valid one is used !",
1314 : : ETH_I40E_SUPPORT_MULTI_DRIVER);
1315 : :
1316 [ # # ]: 0 : if (rte_kvargs_process(kvlist, ETH_I40E_SUPPORT_MULTI_DRIVER,
1317 : : i40e_parse_multi_drv_handler, pf) < 0) {
1318 : 0 : rte_kvargs_free(kvlist);
1319 : 0 : return -EINVAL;
1320 : : }
1321 : :
1322 : 0 : rte_kvargs_free(kvlist);
1323 : 0 : return 0;
1324 : : }
1325 : :
1326 : : static int
1327 : 0 : i40e_aq_debug_write_global_register(struct i40e_hw *hw,
1328 : : uint32_t reg_addr, uint64_t reg_val,
1329 : : struct i40e_asq_cmd_details *cmd_details)
1330 : : {
1331 : : uint64_t ori_reg_val;
1332 : 0 : struct rte_eth_dev_data *dev_data =
1333 : 0 : ((struct i40e_adapter *)hw->back)->pf.dev_data;
1334 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[dev_data->port_id];
1335 : : int ret;
1336 : :
1337 : 0 : ret = i40e_aq_debug_read_register(hw, reg_addr, &ori_reg_val, NULL);
1338 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1339 : 0 : PMD_DRV_LOG(ERR,
1340 : : "Fail to debug read from 0x%08x",
1341 : : reg_addr);
1342 : 0 : return -EIO;
1343 : : }
1344 : :
1345 [ # # ]: 0 : if (ori_reg_val != reg_val)
1346 : 0 : PMD_DRV_LOG(WARNING,
1347 : : "i40e device %s changed global register [0x%08x]."
1348 : : " original: 0x%"PRIx64", after: 0x%"PRIx64,
1349 : : dev->device->name, reg_addr, ori_reg_val, reg_val);
1350 : :
1351 : 0 : return i40e_aq_debug_write_register(hw, reg_addr, reg_val, cmd_details);
1352 : : }
1353 : :
1354 : : static int
1355 : 0 : read_vf_msg_config(__rte_unused const char *key,
1356 : : const char *value,
1357 : : void *opaque)
1358 : : {
1359 : : struct i40e_vf_msg_cfg *cfg = opaque;
1360 : :
1361 [ # # ]: 0 : if (sscanf(value, "%u@%u:%u", &cfg->max_msg, &cfg->period,
1362 : : &cfg->ignore_second) != 3) {
1363 : : memset(cfg, 0, sizeof(*cfg));
1364 : 0 : PMD_DRV_LOG(ERR, "format error! example: "
1365 : : "%s=60@120:180", ETH_I40E_VF_MSG_CFG);
1366 : 0 : return -EINVAL;
1367 : : }
1368 : :
1369 : : /*
1370 : : * If the message validation function been enabled, the 'period'
1371 : : * and 'ignore_second' must greater than 0.
1372 : : */
1373 [ # # # # : 0 : if (cfg->max_msg && (!cfg->period || !cfg->ignore_second)) {
# # ]
1374 : : memset(cfg, 0, sizeof(*cfg));
1375 : 0 : PMD_DRV_LOG(ERR, "%s error! the second and third"
1376 : : " number must be greater than 0!",
1377 : : ETH_I40E_VF_MSG_CFG);
1378 : 0 : return -EINVAL;
1379 : : }
1380 : :
1381 : : return 0;
1382 : : }
1383 : :
1384 : : static int
1385 : 0 : read_mbuf_check_config(__rte_unused const char *key, const char *value, void *args)
1386 : : {
1387 : : char *cur;
1388 : : char *tmp;
1389 : : int str_len;
1390 : : int valid_len;
1391 : :
1392 : : int ret = 0;
1393 : : uint64_t *mc_flags = args;
1394 : 0 : char *str2 = strdup(value);
1395 [ # # ]: 0 : if (str2 == NULL)
1396 : : return -1;
1397 : :
1398 : 0 : str_len = strlen(str2);
1399 [ # # ]: 0 : if (str_len == 0) {
1400 : : ret = -1;
1401 : 0 : goto err_end;
1402 : : }
1403 : :
1404 : : /* Try stripping the outer square brackets of the parameter string. */
1405 : : str_len = strlen(str2);
1406 [ # # # # ]: 0 : if (str2[0] == '[' && str2[str_len - 1] == ']') {
1407 [ # # ]: 0 : if (str_len < 3) {
1408 : : ret = -1;
1409 : 0 : goto err_end;
1410 : : }
1411 : 0 : valid_len = str_len - 2;
1412 : 0 : memmove(str2, str2 + 1, valid_len);
1413 : 0 : memset(str2 + valid_len, '\0', 2);
1414 : : }
1415 : :
1416 : 0 : cur = strtok_r(str2, ",", &tmp);
1417 [ # # ]: 0 : while (cur != NULL) {
1418 [ # # ]: 0 : if (!strcmp(cur, "mbuf"))
1419 : 0 : *mc_flags |= I40E_MBUF_CHECK_F_TX_MBUF;
1420 [ # # ]: 0 : else if (!strcmp(cur, "size"))
1421 : 0 : *mc_flags |= I40E_MBUF_CHECK_F_TX_SIZE;
1422 [ # # ]: 0 : else if (!strcmp(cur, "segment"))
1423 : 0 : *mc_flags |= I40E_MBUF_CHECK_F_TX_SEGMENT;
1424 [ # # ]: 0 : else if (!strcmp(cur, "offload"))
1425 : 0 : *mc_flags |= I40E_MBUF_CHECK_F_TX_OFFLOAD;
1426 : : else
1427 : 0 : PMD_DRV_LOG(ERR, "Unsupported diagnostic type: %s", cur);
1428 : 0 : cur = strtok_r(NULL, ",", &tmp);
1429 : : }
1430 : :
1431 : 0 : err_end:
1432 : 0 : free(str2);
1433 : 0 : return ret;
1434 : : }
1435 : :
1436 : : static int
1437 : 0 : i40e_parse_mbuf_check(struct rte_eth_dev *dev)
1438 : : {
1439 : 0 : struct i40e_adapter *ad =
1440 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1441 : : struct rte_kvargs *kvlist;
1442 : : int kvargs_count;
1443 : : int ret = 0;
1444 : :
1445 [ # # ]: 0 : if (!dev->device->devargs)
1446 : : return ret;
1447 : :
1448 : 0 : kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
1449 [ # # ]: 0 : if (!kvlist)
1450 : : return -EINVAL;
1451 : :
1452 : 0 : kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_MBUF_CHECK_ARG);
1453 [ # # ]: 0 : if (!kvargs_count)
1454 : 0 : goto free_end;
1455 : :
1456 [ # # ]: 0 : if (kvargs_count > 1) {
1457 : 0 : PMD_DRV_LOG(ERR, "More than one argument \"%s\"!",
1458 : : ETH_I40E_MBUF_CHECK_ARG);
1459 : : ret = -EINVAL;
1460 : 0 : goto free_end;
1461 : : }
1462 : :
1463 [ # # ]: 0 : if (rte_kvargs_process(kvlist, ETH_I40E_MBUF_CHECK_ARG,
1464 : 0 : read_mbuf_check_config, &ad->mbuf_check) < 0)
1465 : : ret = -EINVAL;
1466 : :
1467 : 0 : free_end:
1468 : 0 : rte_kvargs_free(kvlist);
1469 : 0 : return ret;
1470 : : }
1471 : :
1472 : : static int
1473 [ # # ]: 0 : i40e_parse_vf_msg_config(struct rte_eth_dev *dev,
1474 : : struct i40e_vf_msg_cfg *msg_cfg)
1475 : : {
1476 : : struct rte_kvargs *kvlist;
1477 : : int kvargs_count;
1478 : : int ret = 0;
1479 : :
1480 : : memset(msg_cfg, 0, sizeof(*msg_cfg));
1481 : :
1482 [ # # ]: 0 : if (!dev->device->devargs)
1483 : : return ret;
1484 : :
1485 : 0 : kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
1486 [ # # ]: 0 : if (!kvlist)
1487 : : return -EINVAL;
1488 : :
1489 : 0 : kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_VF_MSG_CFG);
1490 [ # # ]: 0 : if (!kvargs_count)
1491 : 0 : goto free_end;
1492 : :
1493 [ # # ]: 0 : if (kvargs_count > 1) {
1494 : 0 : PMD_DRV_LOG(ERR, "More than one argument \"%s\"!",
1495 : : ETH_I40E_VF_MSG_CFG);
1496 : : ret = -EINVAL;
1497 : 0 : goto free_end;
1498 : : }
1499 : :
1500 [ # # ]: 0 : if (rte_kvargs_process(kvlist, ETH_I40E_VF_MSG_CFG,
1501 : : read_vf_msg_config, msg_cfg) < 0)
1502 : : ret = -EINVAL;
1503 : :
1504 : 0 : free_end:
1505 : 0 : rte_kvargs_free(kvlist);
1506 : 0 : return ret;
1507 : : }
1508 : :
1509 : : #define I40E_ALARM_INTERVAL 50000 /* us */
1510 : :
1511 : : static int
1512 : 0 : eth_i40e_dev_init(struct rte_eth_dev *dev, void *init_params __rte_unused)
1513 : : {
1514 : : struct rte_pci_device *pci_dev;
1515 : : struct rte_intr_handle *intr_handle;
1516 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1517 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1518 : : struct i40e_vsi *vsi;
1519 : : int ret;
1520 : : uint32_t len, val;
1521 : 0 : uint8_t aq_fail = 0;
1522 : :
1523 : 0 : PMD_INIT_FUNC_TRACE();
1524 : :
1525 : 0 : dev->dev_ops = &i40e_eth_dev_ops;
1526 : 0 : dev->rx_queue_count = i40e_dev_rx_queue_count;
1527 : 0 : dev->rx_descriptor_status = i40e_dev_rx_descriptor_status;
1528 : 0 : dev->tx_descriptor_status = i40e_dev_tx_descriptor_status;
1529 : 0 : dev->rx_pkt_burst = i40e_recv_pkts;
1530 : 0 : dev->tx_pkt_burst = i40e_xmit_pkts;
1531 : 0 : dev->tx_pkt_prepare = i40e_prep_pkts;
1532 : :
1533 : : /* for secondary processes, we don't initialise any further as primary
1534 : : * has already done this work. Only check we don't need a different
1535 : : * RX function */
1536 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY){
1537 : 0 : i40e_set_rx_function(dev);
1538 : 0 : i40e_set_tx_function(dev);
1539 : 0 : return 0;
1540 : : }
1541 : 0 : i40e_set_default_ptype_table(dev);
1542 : 0 : pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1543 : 0 : intr_handle = pci_dev->intr_handle;
1544 : :
1545 : 0 : rte_eth_copy_pci_info(dev, pci_dev);
1546 : :
1547 : 0 : pf->adapter = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1548 : 0 : pf->dev_data = dev->data;
1549 : :
1550 : 0 : hw->back = I40E_PF_TO_ADAPTER(pf);
1551 : 0 : hw->hw_addr = (uint8_t *)(pci_dev->mem_resource[0].addr);
1552 [ # # ]: 0 : if (!hw->hw_addr) {
1553 : 0 : PMD_INIT_LOG(ERR,
1554 : : "Hardware is not available, as address is NULL");
1555 : 0 : return -ENODEV;
1556 : : }
1557 : :
1558 : 0 : hw->vendor_id = pci_dev->id.vendor_id;
1559 : 0 : hw->device_id = pci_dev->id.device_id;
1560 : 0 : hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
1561 : 0 : hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
1562 : 0 : hw->bus.device = pci_dev->addr.devid;
1563 : 0 : hw->bus.func = pci_dev->addr.function;
1564 : 0 : hw->adapter_stopped = 0;
1565 : 0 : hw->adapter_closed = 0;
1566 : :
1567 : : /* Init switch device pointer */
1568 : 0 : hw->switch_dev = NULL;
1569 : :
1570 : : /*
1571 : : * Switch Tag value should not be identical to either the First Tag
1572 : : * or Second Tag values. So set something other than common Ethertype
1573 : : * for internal switching.
1574 : : */
1575 : 0 : hw->switch_tag = 0xffff;
1576 : :
1577 : : val = I40E_READ_REG(hw, I40E_GL_FWSTS);
1578 [ # # ]: 0 : if (val & I40E_GL_FWSTS_FWS1B_MASK) {
1579 : 0 : PMD_INIT_LOG(ERR, "\nERROR: "
1580 : : "Firmware recovery mode detected. Limiting functionality.\n"
1581 : : "Refer to the Intel(R) Ethernet Adapters and Devices "
1582 : : "User Guide for details on firmware recovery mode.");
1583 : 0 : return -EIO;
1584 : : }
1585 : :
1586 : 0 : i40e_parse_vf_msg_config(dev, &pf->vf_msg_cfg);
1587 : 0 : i40e_parse_mbuf_check(dev);
1588 : : /* Check if need to support multi-driver */
1589 : 0 : i40e_support_multi_driver(dev);
1590 : :
1591 : : /* Make sure all is clean before doing PF reset */
1592 : 0 : i40e_clear_hw(hw);
1593 : :
1594 : : /* Reset here to make sure all is clean for each PF */
1595 : 0 : ret = i40e_pf_reset(hw);
1596 [ # # ]: 0 : if (ret) {
1597 : 0 : PMD_INIT_LOG(ERR, "Failed to reset pf: %d", ret);
1598 : 0 : return ret;
1599 : : }
1600 : :
1601 : : /* Initialize the shared code (base driver) */
1602 : 0 : ret = i40e_init_shared_code(hw);
1603 [ # # ]: 0 : if (ret) {
1604 : 0 : PMD_INIT_LOG(ERR, "Failed to init shared code (base driver): %d", ret);
1605 : 0 : return ret;
1606 : : }
1607 : :
1608 : : /* Initialize the parameters for adminq */
1609 : : i40e_init_adminq_parameter(hw);
1610 : 0 : ret = i40e_init_adminq(hw);
1611 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1612 : 0 : PMD_INIT_LOG(ERR, "Failed to init adminq: %d", ret);
1613 : 0 : return -EIO;
1614 : : }
1615 : : /* Firmware of SFP x722 does not support 802.1ad frames ability */
1616 [ # # ]: 0 : if (hw->device_id == I40E_DEV_ID_SFP_X722 ||
1617 : : hw->device_id == I40E_DEV_ID_SFP_I_X722)
1618 : 0 : hw->flags &= ~I40E_HW_FLAG_802_1AD_CAPABLE;
1619 : :
1620 : 0 : PMD_INIT_LOG(INFO, "FW %d.%d API %d.%d NVM %02d.%02d.%02d eetrack %04x",
1621 : : hw->aq.fw_maj_ver, hw->aq.fw_min_ver,
1622 : : hw->aq.api_maj_ver, hw->aq.api_min_ver,
1623 : : ((hw->nvm.version >> 12) & 0xf),
1624 : : ((hw->nvm.version >> 4) & 0xff),
1625 : : (hw->nvm.version & 0xf), hw->nvm.eetrack);
1626 : :
1627 : : /* Initialize the hardware */
1628 : 0 : i40e_hw_init(dev);
1629 : :
1630 : : i40e_config_automask(pf);
1631 : :
1632 : 0 : i40e_set_default_pctype_table(dev);
1633 : :
1634 : : /*
1635 : : * To work around the NVM issue, initialize registers
1636 : : * for packet type of QinQ by software.
1637 : : * It should be removed once issues are fixed in NVM.
1638 : : */
1639 [ # # ]: 0 : if (!pf->support_multi_driver)
1640 : 0 : i40e_GLQF_reg_init(hw);
1641 : :
1642 : : /* Initialize the input set for filters (hash and fd) to default value */
1643 : 0 : i40e_filter_input_set_init(pf);
1644 : :
1645 : : /* initialise the L3_MAP register */
1646 [ # # ]: 0 : if (!pf->support_multi_driver) {
1647 : 0 : ret = i40e_aq_debug_write_global_register(hw,
1648 : : I40E_GLQF_L3_MAP(40),
1649 : : 0x00000028, NULL);
1650 [ # # ]: 0 : if (ret)
1651 : 0 : PMD_INIT_LOG(ERR, "Failed to write L3 MAP register %d",
1652 : : ret);
1653 : 0 : PMD_INIT_LOG(DEBUG,
1654 : : "Global register 0x%08x is changed with 0x28",
1655 : : I40E_GLQF_L3_MAP(40));
1656 : : }
1657 : :
1658 : : /* Need the special FW version to support floating VEB */
1659 : 0 : config_floating_veb(dev);
1660 : : /* Clear PXE mode */
1661 : 0 : i40e_clear_pxe_mode(hw);
1662 : 0 : i40e_dev_sync_phy_type(hw);
1663 : :
1664 : : /*
1665 : : * On X710, performance number is far from the expectation on recent
1666 : : * firmware versions. The fix for this issue may not be integrated in
1667 : : * the following firmware version. So the workaround in software driver
1668 : : * is needed. It needs to modify the initial values of 3 internal only
1669 : : * registers. Note that the workaround can be removed when it is fixed
1670 : : * in firmware in the future.
1671 : : */
1672 : 0 : i40e_configure_registers(hw);
1673 : :
1674 : : /* Get hw capabilities */
1675 : 0 : ret = i40e_get_cap(hw);
1676 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1677 : 0 : PMD_INIT_LOG(ERR, "Failed to get capabilities: %d", ret);
1678 : 0 : goto err_get_capabilities;
1679 : : }
1680 : :
1681 : : /* Initialize parameters for PF */
1682 : 0 : ret = i40e_pf_parameter_init(dev);
1683 [ # # ]: 0 : if (ret != 0) {
1684 : 0 : PMD_INIT_LOG(ERR, "Failed to do parameter init: %d", ret);
1685 : 0 : goto err_parameter_init;
1686 : : }
1687 : :
1688 : : /* Initialize the queue management */
1689 : 0 : ret = i40e_res_pool_init(&pf->qp_pool, 0, hw->func_caps.num_tx_qp);
1690 [ # # ]: 0 : if (ret < 0) {
1691 : 0 : PMD_INIT_LOG(ERR, "Failed to init queue pool");
1692 : 0 : goto err_qp_pool_init;
1693 : : }
1694 : 0 : ret = i40e_res_pool_init(&pf->msix_pool, 1,
1695 : 0 : hw->func_caps.num_msix_vectors - 1);
1696 [ # # ]: 0 : if (ret < 0) {
1697 : 0 : PMD_INIT_LOG(ERR, "Failed to init MSIX pool");
1698 : 0 : goto err_msix_pool_init;
1699 : : }
1700 : :
1701 : : /* Initialize lan hmc */
1702 : 0 : ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
1703 : : hw->func_caps.num_rx_qp, 0, 0);
1704 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1705 : 0 : PMD_INIT_LOG(ERR, "Failed to init lan hmc: %d", ret);
1706 : 0 : goto err_init_lan_hmc;
1707 : : }
1708 : :
1709 : : /* Configure lan hmc */
1710 : 0 : ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
1711 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1712 : 0 : PMD_INIT_LOG(ERR, "Failed to configure lan hmc: %d", ret);
1713 : 0 : goto err_configure_lan_hmc;
1714 : : }
1715 : :
1716 : : /* Get and check the mac address */
1717 : 0 : i40e_get_mac_addr(hw, hw->mac.addr);
1718 [ # # ]: 0 : if (i40e_validate_mac_addr(hw->mac.addr) != I40E_SUCCESS) {
1719 : 0 : PMD_INIT_LOG(ERR, "mac address is not valid");
1720 : : ret = -EIO;
1721 : 0 : goto err_get_mac_addr;
1722 : : }
1723 : : /* Copy the permanent MAC address */
1724 : : rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
1725 : : (struct rte_ether_addr *)hw->mac.perm_addr);
1726 : :
1727 : : /* Disable flow control */
1728 : 0 : hw->fc.requested_mode = I40E_FC_NONE;
1729 : 0 : i40e_set_fc(hw, &aq_fail, TRUE);
1730 : :
1731 : : /* Set the global registers with default ether type value */
1732 [ # # ]: 0 : if (!pf->support_multi_driver) {
1733 : 0 : ret = i40e_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_OUTER,
1734 : : RTE_ETHER_TYPE_VLAN);
1735 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1736 : 0 : PMD_INIT_LOG(ERR,
1737 : : "Failed to set the default outer "
1738 : : "VLAN ether type");
1739 : 0 : goto err_setup_pf_switch;
1740 : : }
1741 : : }
1742 : :
1743 : : /* PF setup, which includes VSI setup */
1744 : 0 : ret = i40e_pf_setup(pf);
1745 [ # # ]: 0 : if (ret) {
1746 : 0 : PMD_INIT_LOG(ERR, "Failed to setup pf switch: %d", ret);
1747 : 0 : goto err_setup_pf_switch;
1748 : : }
1749 : :
1750 : 0 : vsi = pf->main_vsi;
1751 : :
1752 : : /* Disable double vlan by default */
1753 : : i40e_vsi_config_double_vlan(vsi, FALSE);
1754 : :
1755 : : /* Disable S-TAG identification when floating_veb is disabled */
1756 [ # # ]: 0 : if (!pf->floating_veb) {
1757 : 0 : ret = I40E_READ_REG(hw, I40E_PRT_L2TAGSEN);
1758 [ # # ]: 0 : if (ret & I40E_L2_TAGS_S_TAG_MASK) {
1759 : 0 : ret &= ~I40E_L2_TAGS_S_TAG_MASK;
1760 : 0 : I40E_WRITE_REG(hw, I40E_PRT_L2TAGSEN, ret);
1761 : : }
1762 : : }
1763 : :
1764 [ # # ]: 0 : if (!vsi->max_macaddrs)
1765 : : len = RTE_ETHER_ADDR_LEN;
1766 : : else
1767 : 0 : len = RTE_ETHER_ADDR_LEN * vsi->max_macaddrs;
1768 : :
1769 : : /* Should be after VSI initialized */
1770 : 0 : dev->data->mac_addrs = rte_zmalloc("i40e", len, 0);
1771 [ # # ]: 0 : if (!dev->data->mac_addrs) {
1772 : 0 : PMD_INIT_LOG(ERR,
1773 : : "Failed to allocated memory for storing mac address");
1774 : 0 : goto err_mac_alloc;
1775 : : }
1776 : : rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.perm_addr,
1777 : : &dev->data->mac_addrs[0]);
1778 : :
1779 : : /* Init dcb to sw mode by default */
1780 : 0 : ret = i40e_dcb_init_configure(dev, TRUE);
1781 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1782 : 0 : PMD_INIT_LOG(INFO, "Failed to init dcb.");
1783 : 0 : pf->flags &= ~I40E_FLAG_DCB;
1784 : : }
1785 : : /* Update HW struct after DCB configuration */
1786 : 0 : i40e_get_cap(hw);
1787 : :
1788 : : /* initialize pf host driver to setup SRIOV resource if applicable */
1789 : 0 : i40e_pf_host_init(dev);
1790 : :
1791 : : /* register callback func to eal lib */
1792 : 0 : rte_intr_callback_register(intr_handle,
1793 : : i40e_dev_interrupt_handler, dev);
1794 : :
1795 : : /* configure and enable device interrupt */
1796 : : i40e_pf_config_irq0(hw, TRUE);
1797 : 0 : i40e_pf_enable_irq0(hw);
1798 : :
1799 : : /* enable uio intr after callback register */
1800 : 0 : rte_intr_enable(intr_handle);
1801 : :
1802 : : /* By default disable flexible payload in global configuration */
1803 [ # # ]: 0 : if (!pf->support_multi_driver)
1804 : 0 : i40e_flex_payload_reg_set_default(hw);
1805 : :
1806 : : /*
1807 : : * Add an ethertype filter to drop all flow control frames transmitted
1808 : : * from VSIs. By doing so, we stop VF from sending out PAUSE or PFC
1809 : : * frames to wire.
1810 : : */
1811 : 0 : i40e_add_tx_flow_control_drop_filter(pf);
1812 : :
1813 : : /* initialize RSS rule list */
1814 : 0 : TAILQ_INIT(&pf->rss_config_list);
1815 : :
1816 : : /* initialize Traffic Manager configuration */
1817 : 0 : i40e_tm_conf_init(dev);
1818 : :
1819 : : /* Initialize customized information */
1820 : : i40e_init_customized_info(pf);
1821 : :
1822 : : /* Initialize the filter invalidation configuration */
1823 : 0 : i40e_init_filter_invalidation(pf);
1824 : :
1825 : 0 : ret = i40e_init_ethtype_filter_list(dev);
1826 [ # # ]: 0 : if (ret < 0)
1827 : 0 : goto err_init_ethtype_filter_list;
1828 : 0 : ret = i40e_init_tunnel_filter_list(dev);
1829 [ # # ]: 0 : if (ret < 0)
1830 : 0 : goto err_init_tunnel_filter_list;
1831 : 0 : ret = i40e_init_fdir_filter_list(dev);
1832 [ # # ]: 0 : if (ret < 0)
1833 : 0 : goto err_init_fdir_filter_list;
1834 : :
1835 : : /* initialize queue region configuration */
1836 : 0 : i40e_init_queue_region_conf(dev);
1837 : :
1838 : : /* reset all stats of the device, including pf and main vsi */
1839 : 0 : i40e_dev_stats_reset(dev);
1840 : :
1841 : 0 : return 0;
1842 : :
1843 : : err_init_fdir_filter_list:
1844 : 0 : rte_hash_free(pf->tunnel.hash_table);
1845 : 0 : rte_free(pf->tunnel.hash_map);
1846 : 0 : err_init_tunnel_filter_list:
1847 : 0 : rte_hash_free(pf->ethertype.hash_table);
1848 : 0 : rte_free(pf->ethertype.hash_map);
1849 : 0 : err_init_ethtype_filter_list:
1850 : 0 : rte_intr_callback_unregister(intr_handle,
1851 : : i40e_dev_interrupt_handler, dev);
1852 : 0 : rte_free(dev->data->mac_addrs);
1853 : 0 : dev->data->mac_addrs = NULL;
1854 : 0 : err_mac_alloc:
1855 : 0 : i40e_vsi_release(pf->main_vsi);
1856 : 0 : err_setup_pf_switch:
1857 : 0 : err_get_mac_addr:
1858 : 0 : err_configure_lan_hmc:
1859 : 0 : (void)i40e_shutdown_lan_hmc(hw);
1860 : 0 : err_init_lan_hmc:
1861 : 0 : i40e_res_pool_destroy(&pf->msix_pool);
1862 : 0 : err_msix_pool_init:
1863 : 0 : i40e_res_pool_destroy(&pf->qp_pool);
1864 : 0 : err_qp_pool_init:
1865 : 0 : err_parameter_init:
1866 : 0 : err_get_capabilities:
1867 : 0 : (void)i40e_shutdown_adminq(hw);
1868 : :
1869 : 0 : return ret;
1870 : : }
1871 : :
1872 : : static void
1873 : 0 : i40e_rm_ethtype_filter_list(struct i40e_pf *pf)
1874 : : {
1875 : : struct i40e_ethertype_filter *p_ethertype;
1876 : : struct i40e_ethertype_rule *ethertype_rule;
1877 : :
1878 : : ethertype_rule = &pf->ethertype;
1879 : : /* Remove all ethertype filter rules and hash */
1880 : 0 : rte_free(ethertype_rule->hash_map);
1881 : 0 : rte_hash_free(ethertype_rule->hash_table);
1882 : :
1883 [ # # ]: 0 : while ((p_ethertype = TAILQ_FIRST(ðertype_rule->ethertype_list))) {
1884 [ # # ]: 0 : TAILQ_REMOVE(ðertype_rule->ethertype_list,
1885 : : p_ethertype, rules);
1886 : 0 : rte_free(p_ethertype);
1887 : : }
1888 : 0 : }
1889 : :
1890 : : static void
1891 : 0 : i40e_rm_tunnel_filter_list(struct i40e_pf *pf)
1892 : : {
1893 : : struct i40e_tunnel_filter *p_tunnel;
1894 : : struct i40e_tunnel_rule *tunnel_rule;
1895 : :
1896 : : tunnel_rule = &pf->tunnel;
1897 : : /* Remove all tunnel director rules and hash */
1898 : 0 : rte_free(tunnel_rule->hash_map);
1899 : 0 : rte_hash_free(tunnel_rule->hash_table);
1900 : :
1901 [ # # ]: 0 : while ((p_tunnel = TAILQ_FIRST(&tunnel_rule->tunnel_list))) {
1902 [ # # ]: 0 : TAILQ_REMOVE(&tunnel_rule->tunnel_list, p_tunnel, rules);
1903 : 0 : rte_free(p_tunnel);
1904 : : }
1905 : 0 : }
1906 : :
1907 : : static void
1908 : : i40e_rm_fdir_filter_list(struct i40e_pf *pf)
1909 : : {
1910 : : struct i40e_fdir_filter *p_fdir;
1911 : : struct i40e_fdir_info *fdir_info;
1912 : :
1913 : : fdir_info = &pf->fdir;
1914 : :
1915 : : /* Remove all flow director rules */
1916 [ # # ]: 0 : while ((p_fdir = TAILQ_FIRST(&fdir_info->fdir_list)))
1917 [ # # ]: 0 : TAILQ_REMOVE(&fdir_info->fdir_list, p_fdir, rules);
1918 : : }
1919 : :
1920 : : static void
1921 : 0 : i40e_fdir_memory_cleanup(struct i40e_pf *pf)
1922 : : {
1923 : : struct i40e_fdir_info *fdir_info;
1924 : :
1925 : : fdir_info = &pf->fdir;
1926 : :
1927 : : /* flow director memory cleanup */
1928 : 0 : rte_free(fdir_info->hash_map);
1929 : 0 : rte_hash_free(fdir_info->hash_table);
1930 : 0 : rte_free(fdir_info->fdir_flow_pool.bitmap);
1931 : 0 : rte_free(fdir_info->fdir_flow_pool.pool);
1932 : 0 : rte_free(fdir_info->fdir_filter_array);
1933 : 0 : }
1934 : :
1935 : 0 : void i40e_flex_payload_reg_set_default(struct i40e_hw *hw)
1936 : : {
1937 : : /*
1938 : : * Disable by default flexible payload
1939 : : * for corresponding L2/L3/L4 layers.
1940 : : */
1941 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(33), 0x00000000);
1942 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(34), 0x00000000);
1943 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(35), 0x00000000);
1944 : 0 : }
1945 : :
1946 : : static int
1947 : 0 : eth_i40e_dev_uninit(struct rte_eth_dev *dev)
1948 : : {
1949 : : struct i40e_hw *hw;
1950 : :
1951 : 0 : PMD_INIT_FUNC_TRACE();
1952 : :
1953 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1954 : : return 0;
1955 : :
1956 : 0 : hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1957 : :
1958 [ # # ]: 0 : if (hw->adapter_closed == 0)
1959 : 0 : i40e_dev_close(dev);
1960 : :
1961 : : return 0;
1962 : : }
1963 : :
1964 : : static int
1965 : 0 : i40e_dev_configure(struct rte_eth_dev *dev)
1966 : : {
1967 : 0 : struct i40e_adapter *ad =
1968 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1969 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1970 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1971 : 0 : enum rte_eth_rx_mq_mode mq_mode = dev->data->dev_conf.rxmode.mq_mode;
1972 : : int i, ret;
1973 : :
1974 : 0 : ret = i40e_dev_sync_phy_type(hw);
1975 [ # # ]: 0 : if (ret)
1976 : : return ret;
1977 : :
1978 : : /* Initialize to TRUE. If any of Rx queues doesn't meet the
1979 : : * bulk allocation or vector Rx preconditions we will reset it.
1980 : : */
1981 : 0 : ad->rx_bulk_alloc_allowed = true;
1982 : 0 : ad->rx_vec_allowed = true;
1983 : 0 : ad->tx_simple_allowed = true;
1984 : 0 : ad->tx_vec_allowed = true;
1985 : :
1986 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
1987 : 0 : dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
1988 : :
1989 : 0 : ret = i40e_dev_init_vlan(dev);
1990 [ # # ]: 0 : if (ret < 0)
1991 : 0 : goto err;
1992 : :
1993 : : /* VMDQ setup.
1994 : : * General PMD call sequence are NIC init, configure,
1995 : : * rx/tx_queue_setup and dev_start. In rx/tx_queue_setup() function, it
1996 : : * will try to lookup the VSI that specific queue belongs to if VMDQ
1997 : : * applicable. So, VMDQ setting has to be done before
1998 : : * rx/tx_queue_setup(). This function is good to place vmdq_setup.
1999 : : * For RSS setting, it will try to calculate actual configured RX queue
2000 : : * number, which will be available after rx_queue_setup(). dev_start()
2001 : : * function is good to place RSS setup.
2002 : : */
2003 [ # # ]: 0 : if (mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG) {
2004 : 0 : ret = i40e_vmdq_setup(dev);
2005 [ # # ]: 0 : if (ret)
2006 : 0 : goto err;
2007 : : }
2008 : :
2009 [ # # ]: 0 : if (mq_mode & RTE_ETH_MQ_RX_DCB_FLAG) {
2010 : 0 : ret = i40e_dcb_setup(dev);
2011 [ # # ]: 0 : if (ret) {
2012 : 0 : PMD_DRV_LOG(ERR, "failed to configure DCB.");
2013 : 0 : goto err_dcb;
2014 : : }
2015 : : }
2016 : :
2017 : 0 : TAILQ_INIT(&pf->flow_list);
2018 : :
2019 : 0 : return 0;
2020 : :
2021 : : err_dcb:
2022 : : /* need to release vmdq resource if exists */
2023 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2024 : 0 : i40e_vsi_release(pf->vmdq[i].vsi);
2025 : 0 : pf->vmdq[i].vsi = NULL;
2026 : : }
2027 : 0 : rte_free(pf->vmdq);
2028 : 0 : pf->vmdq = NULL;
2029 : : err:
2030 : : return ret;
2031 : : }
2032 : :
2033 : : void
2034 : 0 : i40e_vsi_queues_unbind_intr(struct i40e_vsi *vsi)
2035 : : {
2036 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
2037 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2038 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2039 : : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2040 : 0 : uint16_t msix_vect = vsi->msix_intr;
2041 : : uint16_t i;
2042 : :
2043 [ # # ]: 0 : for (i = 0; i < vsi->nb_qps; i++) {
2044 : 0 : I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
2045 : 0 : I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
2046 : : rte_wmb();
2047 : : }
2048 : :
2049 [ # # ]: 0 : if (vsi->type != I40E_VSI_SRIOV) {
2050 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle)) {
2051 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
2052 : : I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
2053 : 0 : I40E_WRITE_REG(hw,
2054 : : I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
2055 : : 0);
2056 : : } else {
2057 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
2058 : : I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
2059 : 0 : I40E_WRITE_REG(hw,
2060 : : I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
2061 : : msix_vect - 1), 0);
2062 : : }
2063 : : } else {
2064 : : uint32_t reg;
2065 : 0 : reg = (hw->func_caps.num_msix_vectors_vf - 1) *
2066 : 0 : vsi->user_param + (msix_vect - 1);
2067 : :
2068 : 0 : I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
2069 : : I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
2070 : : }
2071 : 0 : I40E_WRITE_FLUSH(hw);
2072 : 0 : }
2073 : :
2074 : : static void
2075 : 0 : __vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t msix_vect,
2076 : : int base_queue, int nb_queue,
2077 : : uint16_t itr_idx)
2078 : : {
2079 : : int i;
2080 : : uint32_t val;
2081 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2082 : : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2083 : :
2084 : : /* Bind all RX queues to allocated MSIX interrupt */
2085 [ # # ]: 0 : for (i = 0; i < nb_queue; i++) {
2086 : 0 : val = (msix_vect << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
2087 : 0 : itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT |
2088 : 0 : ((base_queue + i + 1) <<
2089 : 0 : I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
2090 : 0 : (0 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
2091 : : I40E_QINT_RQCTL_CAUSE_ENA_MASK;
2092 : :
2093 [ # # ]: 0 : if (i == nb_queue - 1)
2094 : 0 : val |= I40E_QINT_RQCTL_NEXTQ_INDX_MASK;
2095 : 0 : I40E_WRITE_REG(hw, I40E_QINT_RQCTL(base_queue + i), val);
2096 : : }
2097 : :
2098 : : /* Write first RX queue to Link list register as the head element */
2099 [ # # ]: 0 : if (vsi->type != I40E_VSI_SRIOV) {
2100 : : uint16_t interval =
2101 : : i40e_calc_itr_interval(1, pf->support_multi_driver);
2102 : :
2103 [ # # ]: 0 : if (msix_vect == I40E_MISC_VEC_ID) {
2104 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
2105 : : (base_queue <<
2106 : : I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
2107 : : (0x0 <<
2108 : : I40E_PFINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
2109 : 0 : I40E_WRITE_REG(hw,
2110 : : I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
2111 : : interval);
2112 : : } else {
2113 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
2114 : : (base_queue <<
2115 : : I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
2116 : : (0x0 <<
2117 : : I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
2118 : 0 : I40E_WRITE_REG(hw,
2119 : : I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
2120 : : msix_vect - 1),
2121 : : interval);
2122 : : }
2123 : : } else {
2124 : : uint32_t reg;
2125 : :
2126 [ # # ]: 0 : if (msix_vect == I40E_MISC_VEC_ID) {
2127 : 0 : I40E_WRITE_REG(hw,
2128 : : I40E_VPINT_LNKLST0(vsi->user_param),
2129 : : (base_queue <<
2130 : : I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
2131 : : (0x0 <<
2132 : : I40E_VPINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
2133 : : } else {
2134 : : /* num_msix_vectors_vf needs to minus irq0 */
2135 : 0 : reg = (hw->func_caps.num_msix_vectors_vf - 1) *
2136 : 0 : vsi->user_param + (msix_vect - 1);
2137 : :
2138 : 0 : I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
2139 : : (base_queue <<
2140 : : I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
2141 : : (0x0 <<
2142 : : I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
2143 : : }
2144 : : }
2145 : :
2146 : 0 : I40E_WRITE_FLUSH(hw);
2147 : 0 : }
2148 : :
2149 : : int
2150 : 0 : i40e_vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t itr_idx)
2151 : : {
2152 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
2153 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2154 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2155 : : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2156 : 0 : uint16_t msix_vect = vsi->msix_intr;
2157 : 0 : uint16_t nb_msix = RTE_MIN(vsi->nb_msix,
2158 : : rte_intr_nb_efd_get(intr_handle));
2159 : : uint16_t queue_idx = 0;
2160 : : int record = 0;
2161 : : int i;
2162 : :
2163 [ # # ]: 0 : for (i = 0; i < vsi->nb_qps; i++) {
2164 : 0 : I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
2165 : 0 : I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
2166 : : }
2167 : :
2168 : : /* VF bind interrupt */
2169 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
2170 [ # # ]: 0 : if (vsi->nb_msix == 0) {
2171 : 0 : PMD_DRV_LOG(ERR, "No msix resource");
2172 : 0 : return -EINVAL;
2173 : : }
2174 : 0 : __vsi_queues_bind_intr(vsi, msix_vect,
2175 : 0 : vsi->base_queue, vsi->nb_qps,
2176 : : itr_idx);
2177 : 0 : return 0;
2178 : : }
2179 : :
2180 : : /* PF & VMDq bind interrupt */
2181 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
2182 [ # # ]: 0 : if (vsi->type == I40E_VSI_MAIN) {
2183 : : queue_idx = 0;
2184 : : record = 1;
2185 [ # # ]: 0 : } else if (vsi->type == I40E_VSI_VMDQ2) {
2186 : : struct i40e_vsi *main_vsi =
2187 [ # # ]: 0 : I40E_DEV_PRIVATE_TO_MAIN_VSI(vsi->adapter);
2188 : 0 : queue_idx = vsi->base_queue - main_vsi->nb_qps;
2189 : : record = 1;
2190 : : }
2191 : : }
2192 : :
2193 [ # # ]: 0 : for (i = 0; i < vsi->nb_used_qps; i++) {
2194 [ # # ]: 0 : if (vsi->nb_msix == 0) {
2195 : 0 : PMD_DRV_LOG(ERR, "No msix resource");
2196 : 0 : return -EINVAL;
2197 [ # # ]: 0 : } else if (nb_msix <= 1) {
2198 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle))
2199 : : /* allow to share MISC_VEC_ID */
2200 : : msix_vect = I40E_MISC_VEC_ID;
2201 : :
2202 : : /* no enough msix_vect, map all to one */
2203 : 0 : __vsi_queues_bind_intr(vsi, msix_vect,
2204 : 0 : vsi->base_queue + i,
2205 : 0 : vsi->nb_used_qps - i,
2206 : : itr_idx);
2207 [ # # # # ]: 0 : for (; !!record && i < vsi->nb_used_qps; i++)
2208 : 0 : rte_intr_vec_list_index_set(intr_handle,
2209 : : queue_idx + i, msix_vect);
2210 : : break;
2211 : : }
2212 : : /* 1:1 queue/msix_vect mapping */
2213 : 0 : __vsi_queues_bind_intr(vsi, msix_vect,
2214 : 0 : vsi->base_queue + i, 1,
2215 : : itr_idx);
2216 [ # # ]: 0 : if (!!record)
2217 [ # # ]: 0 : if (rte_intr_vec_list_index_set(intr_handle,
2218 : : queue_idx + i, msix_vect))
2219 : 0 : return -rte_errno;
2220 : :
2221 : 0 : msix_vect++;
2222 : 0 : nb_msix--;
2223 : : }
2224 : :
2225 : : return 0;
2226 : : }
2227 : :
2228 : : void
2229 : 0 : i40e_vsi_enable_queues_intr(struct i40e_vsi *vsi)
2230 : : {
2231 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
2232 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2233 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2234 : : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2235 : : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2236 : : uint16_t msix_intr, i;
2237 : :
2238 [ # # # # ]: 0 : if (rte_intr_allow_others(intr_handle) && !pf->support_multi_driver)
2239 [ # # ]: 0 : for (i = 0; i < vsi->nb_msix; i++) {
2240 : 0 : msix_intr = vsi->msix_intr + i;
2241 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
2242 : : I40E_PFINT_DYN_CTLN_INTENA_MASK |
2243 : : I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
2244 : : I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
2245 : : }
2246 : : else
2247 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
2248 : : I40E_PFINT_DYN_CTL0_INTENA_MASK |
2249 : : I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
2250 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
2251 : :
2252 : 0 : I40E_WRITE_FLUSH(hw);
2253 : 0 : }
2254 : :
2255 : : void
2256 : 0 : i40e_vsi_disable_queues_intr(struct i40e_vsi *vsi)
2257 : : {
2258 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
2259 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2260 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2261 : : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2262 : : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2263 : : uint16_t msix_intr, i;
2264 : :
2265 [ # # # # ]: 0 : if (rte_intr_allow_others(intr_handle) && !pf->support_multi_driver)
2266 [ # # ]: 0 : for (i = 0; i < vsi->nb_msix; i++) {
2267 : 0 : msix_intr = vsi->msix_intr + i;
2268 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
2269 : : I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
2270 : : }
2271 : : else
2272 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
2273 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
2274 : :
2275 : 0 : I40E_WRITE_FLUSH(hw);
2276 : 0 : }
2277 : :
2278 : : static inline uint8_t
2279 : 0 : i40e_parse_link_speeds(uint16_t link_speeds)
2280 : : {
2281 : : uint8_t link_speed = I40E_LINK_SPEED_UNKNOWN;
2282 : :
2283 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_40G)
2284 : : link_speed |= I40E_LINK_SPEED_40GB;
2285 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_25G)
2286 : 0 : link_speed |= I40E_LINK_SPEED_25GB;
2287 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_20G)
2288 : 0 : link_speed |= I40E_LINK_SPEED_20GB;
2289 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_10G)
2290 : 0 : link_speed |= I40E_LINK_SPEED_10GB;
2291 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_1G)
2292 : 0 : link_speed |= I40E_LINK_SPEED_1GB;
2293 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_100M)
2294 : 0 : link_speed |= I40E_LINK_SPEED_100MB;
2295 : :
2296 : 0 : return link_speed;
2297 : : }
2298 : :
2299 : : static int
2300 : 0 : i40e_phy_conf_link(struct i40e_hw *hw,
2301 : : uint8_t abilities,
2302 : : uint8_t force_speed,
2303 : : bool is_up)
2304 : : {
2305 : : enum i40e_status_code status;
2306 : : struct i40e_aq_get_phy_abilities_resp phy_ab;
2307 : : struct i40e_aq_set_phy_config phy_conf;
2308 : : enum i40e_aq_phy_type cnt;
2309 : : uint8_t avail_speed;
2310 : : uint32_t phy_type_mask = 0;
2311 : :
2312 : : const uint8_t mask = I40E_AQ_PHY_FLAG_PAUSE_TX |
2313 : : I40E_AQ_PHY_FLAG_PAUSE_RX |
2314 : : I40E_AQ_PHY_FLAG_PAUSE_RX |
2315 : : I40E_AQ_PHY_FLAG_LOW_POWER;
2316 : : int ret = -ENOTSUP;
2317 : :
2318 : : /* To get phy capabilities of available speeds. */
2319 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, true, &phy_ab,
2320 : : NULL);
2321 [ # # ]: 0 : if (status) {
2322 : 0 : PMD_DRV_LOG(ERR, "Failed to get PHY capabilities: %d\n",
2323 : : status);
2324 : 0 : return ret;
2325 : : }
2326 : 0 : avail_speed = phy_ab.link_speed;
2327 : :
2328 : : /* To get the current phy config. */
2329 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, false, &phy_ab,
2330 : : NULL);
2331 [ # # ]: 0 : if (status) {
2332 : 0 : PMD_DRV_LOG(ERR, "Failed to get the current PHY config: %d\n",
2333 : : status);
2334 : 0 : return ret;
2335 : : }
2336 : :
2337 : : /* If link needs to go up and it is in autoneg mode the speed is OK,
2338 : : * no need to set up again.
2339 : : */
2340 [ # # # # : 0 : if (is_up && phy_ab.phy_type != 0 &&
# # ]
2341 : 0 : abilities & I40E_AQ_PHY_AN_ENABLED &&
2342 [ # # ]: 0 : phy_ab.link_speed != 0)
2343 : : return I40E_SUCCESS;
2344 : :
2345 : : memset(&phy_conf, 0, sizeof(phy_conf));
2346 : :
2347 : : /* bits 0-2 use the values from get_phy_abilities_resp */
2348 : 0 : abilities &= ~mask;
2349 : 0 : abilities |= phy_ab.abilities & mask;
2350 : :
2351 : 0 : phy_conf.abilities = abilities;
2352 : :
2353 : : /* If link needs to go up, but the force speed is not supported,
2354 : : * Warn users and config the default available speeds.
2355 : : */
2356 [ # # # # ]: 0 : if (is_up && !(force_speed & avail_speed)) {
2357 : 0 : PMD_DRV_LOG(WARNING, "Invalid speed setting, set to default!\n");
2358 : 0 : phy_conf.link_speed = avail_speed;
2359 : : } else {
2360 [ # # ]: 0 : phy_conf.link_speed = is_up ? force_speed : avail_speed;
2361 : : }
2362 : :
2363 : : /* PHY type mask needs to include each type except PHY type extension */
2364 [ # # ]: 0 : for (cnt = I40E_PHY_TYPE_SGMII; cnt < I40E_PHY_TYPE_25GBASE_KR; cnt++)
2365 : 0 : phy_type_mask |= 1 << cnt;
2366 : :
2367 : : /* use get_phy_abilities_resp value for the rest */
2368 [ # # ]: 0 : phy_conf.phy_type = is_up ? cpu_to_le32(phy_type_mask) : 0;
2369 [ # # ]: 0 : phy_conf.phy_type_ext = is_up ? (I40E_AQ_PHY_TYPE_EXT_25G_KR |
2370 : : I40E_AQ_PHY_TYPE_EXT_25G_CR | I40E_AQ_PHY_TYPE_EXT_25G_SR |
2371 : : I40E_AQ_PHY_TYPE_EXT_25G_LR | I40E_AQ_PHY_TYPE_EXT_25G_AOC |
2372 : : I40E_AQ_PHY_TYPE_EXT_25G_ACC) : 0;
2373 : 0 : phy_conf.fec_config = phy_ab.fec_cfg_curr_mod_ext_info;
2374 : 0 : phy_conf.eee_capability = phy_ab.eee_capability;
2375 : 0 : phy_conf.eeer = phy_ab.eeer_val;
2376 : 0 : phy_conf.low_power_ctrl = phy_ab.d3_lpan;
2377 : :
2378 : 0 : PMD_DRV_LOG(DEBUG, "\tCurrent: abilities %x, link_speed %x",
2379 : : phy_ab.abilities, phy_ab.link_speed);
2380 : 0 : PMD_DRV_LOG(DEBUG, "\tConfig: abilities %x, link_speed %x",
2381 : : phy_conf.abilities, phy_conf.link_speed);
2382 : :
2383 : 0 : status = i40e_aq_set_phy_config(hw, &phy_conf, NULL);
2384 [ # # ]: 0 : if (status)
2385 : 0 : return ret;
2386 : :
2387 : : return I40E_SUCCESS;
2388 : : }
2389 : :
2390 : : static int
2391 : 0 : i40e_apply_link_speed(struct rte_eth_dev *dev)
2392 : : {
2393 : : uint8_t speed;
2394 : : uint8_t abilities = 0;
2395 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2396 : : struct rte_eth_conf *conf = &dev->data->dev_conf;
2397 : :
2398 : : abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK |
2399 : : I40E_AQ_PHY_LINK_ENABLED;
2400 : :
2401 [ # # ]: 0 : if (conf->link_speeds == RTE_ETH_LINK_SPEED_AUTONEG) {
2402 : 0 : conf->link_speeds = RTE_ETH_LINK_SPEED_40G |
2403 : : RTE_ETH_LINK_SPEED_25G |
2404 : : RTE_ETH_LINK_SPEED_20G |
2405 : : RTE_ETH_LINK_SPEED_10G |
2406 : : RTE_ETH_LINK_SPEED_1G |
2407 : : RTE_ETH_LINK_SPEED_100M;
2408 : :
2409 : : abilities |= I40E_AQ_PHY_AN_ENABLED;
2410 : : } else {
2411 : : abilities &= ~I40E_AQ_PHY_AN_ENABLED;
2412 : : }
2413 : 0 : speed = i40e_parse_link_speeds(conf->link_speeds);
2414 : :
2415 : 0 : return i40e_phy_conf_link(hw, abilities, speed, true);
2416 : : }
2417 : :
2418 : : static int
2419 : 0 : i40e_dev_start(struct rte_eth_dev *dev)
2420 : : {
2421 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2422 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2423 : 0 : struct i40e_vsi *main_vsi = pf->main_vsi;
2424 : : struct i40e_adapter *ad =
2425 : : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2426 : : int ret, i;
2427 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2428 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2429 : : uint32_t intr_vector = 0;
2430 : : struct i40e_vsi *vsi;
2431 : : uint16_t nb_rxq, nb_txq;
2432 : : uint16_t max_frame_size;
2433 : :
2434 : 0 : hw->adapter_stopped = 0;
2435 : :
2436 : 0 : rte_intr_disable(intr_handle);
2437 : :
2438 [ # # ]: 0 : if ((rte_intr_cap_multiple(intr_handle) ||
2439 [ # # ]: 0 : !RTE_ETH_DEV_SRIOV(dev).active) &&
2440 [ # # ]: 0 : dev->data->dev_conf.intr_conf.rxq != 0) {
2441 : 0 : intr_vector = dev->data->nb_rx_queues;
2442 : 0 : ret = rte_intr_efd_enable(intr_handle, intr_vector);
2443 [ # # ]: 0 : if (ret)
2444 : : return ret;
2445 : : }
2446 : :
2447 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
2448 [ # # ]: 0 : if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
2449 : 0 : dev->data->nb_rx_queues)) {
2450 : 0 : PMD_INIT_LOG(ERR,
2451 : : "Failed to allocate %d rx_queues intr_vec",
2452 : : dev->data->nb_rx_queues);
2453 : 0 : return -ENOMEM;
2454 : : }
2455 : : }
2456 : :
2457 : : /* Initialize VSI */
2458 : 0 : ret = i40e_dev_rxtx_init(pf);
2459 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2460 : 0 : PMD_DRV_LOG(ERR, "Failed to init rx/tx queues");
2461 : 0 : return ret;
2462 : : }
2463 : :
2464 : : /* Map queues with MSIX interrupt */
2465 : 0 : main_vsi->nb_used_qps = dev->data->nb_rx_queues -
2466 : 0 : pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
2467 : 0 : ret = i40e_vsi_queues_bind_intr(main_vsi, I40E_ITR_INDEX_DEFAULT);
2468 [ # # ]: 0 : if (ret < 0)
2469 : : return ret;
2470 : 0 : i40e_vsi_enable_queues_intr(main_vsi);
2471 : :
2472 : : /* Map VMDQ VSI queues with MSIX interrupt */
2473 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2474 : 0 : pf->vmdq[i].vsi->nb_used_qps = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
2475 : 0 : ret = i40e_vsi_queues_bind_intr(pf->vmdq[i].vsi,
2476 : : I40E_ITR_INDEX_DEFAULT);
2477 [ # # ]: 0 : if (ret < 0)
2478 : 0 : return ret;
2479 : 0 : i40e_vsi_enable_queues_intr(pf->vmdq[i].vsi);
2480 : : }
2481 : :
2482 : : /* Enable all queues which have been configured */
2483 [ # # ]: 0 : for (nb_rxq = 0; nb_rxq < dev->data->nb_rx_queues; nb_rxq++) {
2484 : 0 : ret = i40e_dev_rx_queue_start(dev, nb_rxq);
2485 [ # # ]: 0 : if (ret)
2486 : 0 : goto rx_err;
2487 : : }
2488 : :
2489 [ # # ]: 0 : for (nb_txq = 0; nb_txq < dev->data->nb_tx_queues; nb_txq++) {
2490 : 0 : ret = i40e_dev_tx_queue_start(dev, nb_txq);
2491 [ # # ]: 0 : if (ret)
2492 : 0 : goto tx_err;
2493 : : }
2494 : :
2495 : : /* Enable receiving broadcast packets */
2496 : 0 : ret = i40e_aq_set_vsi_broadcast(hw, main_vsi->seid, true, NULL);
2497 [ # # ]: 0 : if (ret != I40E_SUCCESS)
2498 : 0 : PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
2499 : :
2500 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2501 : 0 : ret = i40e_aq_set_vsi_broadcast(hw, pf->vmdq[i].vsi->seid,
2502 : : true, NULL);
2503 [ # # ]: 0 : if (ret != I40E_SUCCESS)
2504 : 0 : PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
2505 : : }
2506 : :
2507 : : /* Enable the VLAN promiscuous mode. */
2508 [ # # ]: 0 : if (pf->vfs) {
2509 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++) {
2510 : 0 : vsi = pf->vfs[i].vsi;
2511 : 0 : i40e_aq_set_vsi_vlan_promisc(hw, vsi->seid,
2512 : : true, NULL);
2513 : : }
2514 : : }
2515 : :
2516 : : /* Disable mac loopback mode */
2517 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode == I40E_AQ_LB_MODE_NONE) {
2518 : 0 : ret = i40e_aq_set_lb_modes(hw, I40E_AQ_LB_MODE_NONE, NULL);
2519 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2520 : 0 : PMD_DRV_LOG(ERR, "fail to set loopback link");
2521 : 0 : goto tx_err;
2522 : : }
2523 : : }
2524 : :
2525 : : /* Enable mac loopback mode */
2526 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode == I40E_AQ_LB_MODE_EN) {
2527 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
2528 : 0 : ret = i40e_aq_set_lb_modes(hw, I40E_AQ_LB_MAC_LOCAL_X722, NULL);
2529 : : else
2530 : 0 : ret = i40e_aq_set_lb_modes(hw, I40E_AQ_LB_MAC, NULL);
2531 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2532 : 0 : PMD_DRV_LOG(ERR, "fail to set loopback link");
2533 : 0 : goto tx_err;
2534 : : }
2535 : : }
2536 : :
2537 : : /* Apply link configure */
2538 : 0 : ret = i40e_apply_link_speed(dev);
2539 [ # # ]: 0 : if (I40E_SUCCESS != ret) {
2540 : 0 : PMD_DRV_LOG(ERR, "Fail to apply link setting");
2541 : 0 : goto tx_err;
2542 : : }
2543 : :
2544 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle)) {
2545 : 0 : rte_intr_callback_unregister(intr_handle,
2546 : : i40e_dev_interrupt_handler,
2547 : : (void *)dev);
2548 : : /* configure and enable device interrupt */
2549 : : i40e_pf_config_irq0(hw, FALSE);
2550 : 0 : i40e_pf_enable_irq0(hw);
2551 : :
2552 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc != 0)
2553 : 0 : PMD_INIT_LOG(INFO,
2554 : : "lsc won't enable because of no intr multiplex");
2555 : : } else {
2556 : 0 : ret = i40e_aq_set_phy_int_mask(hw,
2557 : : ~(I40E_AQ_EVENT_LINK_UPDOWN |
2558 : : I40E_AQ_EVENT_MODULE_QUAL_FAIL |
2559 : : I40E_AQ_EVENT_MEDIA_NA), NULL);
2560 [ # # ]: 0 : if (ret != I40E_SUCCESS)
2561 : 0 : PMD_DRV_LOG(WARNING, "Fail to set phy mask");
2562 : :
2563 : : /* Call get_link_info aq command to enable/disable LSE */
2564 : 0 : i40e_dev_link_update(dev, 1);
2565 : : }
2566 : :
2567 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq == 0) {
2568 : 0 : rte_eal_alarm_set(I40E_ALARM_INTERVAL,
2569 : : i40e_dev_alarm_handler, dev);
2570 : : } else {
2571 : : /* enable uio intr after callback register */
2572 : 0 : rte_intr_enable(intr_handle);
2573 : : }
2574 : :
2575 : 0 : i40e_filter_restore(pf);
2576 : :
2577 [ # # # # ]: 0 : if (pf->tm_conf.root && !pf->tm_conf.committed)
2578 : 0 : PMD_DRV_LOG(WARNING,
2579 : : "please call hierarchy_commit() "
2580 : : "before starting the port");
2581 : :
2582 [ # # ]: 0 : max_frame_size = dev->data->mtu ?
2583 : : dev->data->mtu + I40E_ETH_OVERHEAD :
2584 : : I40E_FRAME_SIZE_MAX;
2585 : 0 : ad->max_pkt_len = max_frame_size;
2586 : :
2587 : : /* Set the max frame size to HW*/
2588 : 0 : i40e_aq_set_mac_config(hw, max_frame_size, TRUE, false, 0, NULL);
2589 : :
2590 : 0 : return I40E_SUCCESS;
2591 : :
2592 : 0 : tx_err:
2593 [ # # ]: 0 : for (i = 0; i < nb_txq; i++)
2594 : 0 : i40e_dev_tx_queue_stop(dev, i);
2595 : 0 : rx_err:
2596 [ # # ]: 0 : for (i = 0; i < nb_rxq; i++)
2597 : 0 : i40e_dev_rx_queue_stop(dev, i);
2598 : :
2599 : : return ret;
2600 : : }
2601 : :
2602 : : static int
2603 : 0 : i40e_dev_stop(struct rte_eth_dev *dev)
2604 : : {
2605 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2606 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2607 : 0 : struct i40e_vsi *main_vsi = pf->main_vsi;
2608 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2609 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2610 : : int i;
2611 : :
2612 [ # # ]: 0 : if (hw->adapter_stopped == 1)
2613 : : return 0;
2614 : :
2615 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq == 0) {
2616 : 0 : rte_eal_alarm_cancel(i40e_dev_alarm_handler, dev);
2617 : 0 : rte_intr_enable(intr_handle);
2618 : : }
2619 : :
2620 : : /* Disable all queues */
2621 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
2622 : 0 : i40e_dev_tx_queue_stop(dev, i);
2623 : :
2624 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
2625 : 0 : i40e_dev_rx_queue_stop(dev, i);
2626 : :
2627 : : /* un-map queues with interrupt registers */
2628 : 0 : i40e_vsi_disable_queues_intr(main_vsi);
2629 : 0 : i40e_vsi_queues_unbind_intr(main_vsi);
2630 : :
2631 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2632 : 0 : i40e_vsi_disable_queues_intr(pf->vmdq[i].vsi);
2633 : 0 : i40e_vsi_queues_unbind_intr(pf->vmdq[i].vsi);
2634 : : }
2635 : :
2636 : : /* Clear all queues and release memory */
2637 : 0 : i40e_dev_clear_queues(dev);
2638 : :
2639 : : /* Set link down */
2640 : : i40e_dev_set_link_down(dev);
2641 : :
2642 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle))
2643 : : /* resume to the default handler */
2644 : 0 : rte_intr_callback_register(intr_handle,
2645 : : i40e_dev_interrupt_handler,
2646 : : (void *)dev);
2647 : :
2648 : : /* Clean datapath event and queue/vec mapping */
2649 : 0 : rte_intr_efd_disable(intr_handle);
2650 : :
2651 : : /* Cleanup vector list */
2652 : 0 : rte_intr_vec_list_free(intr_handle);
2653 : :
2654 : : /* reset hierarchy commit */
2655 : 0 : pf->tm_conf.committed = false;
2656 : :
2657 : 0 : hw->adapter_stopped = 1;
2658 : 0 : dev->data->dev_started = 0;
2659 : :
2660 : 0 : pf->adapter->rss_reta_updated = 0;
2661 : :
2662 : 0 : return 0;
2663 : : }
2664 : :
2665 : : static int
2666 : 0 : i40e_dev_close(struct rte_eth_dev *dev)
2667 : : {
2668 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2669 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2670 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2671 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2672 : : struct i40e_filter_control_settings settings;
2673 : : struct rte_flow *p_flow;
2674 : : uint32_t reg;
2675 : : int i;
2676 : : int ret;
2677 : 0 : uint8_t aq_fail = 0;
2678 : : int retries = 0;
2679 : :
2680 : 0 : PMD_INIT_FUNC_TRACE();
2681 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2682 : : return 0;
2683 : :
2684 : 0 : ret = rte_eth_switch_domain_free(pf->switch_domain_id);
2685 [ # # ]: 0 : if (ret)
2686 : 0 : PMD_INIT_LOG(WARNING, "failed to free switch domain: %d", ret);
2687 : :
2688 : :
2689 : 0 : ret = i40e_dev_stop(dev);
2690 : :
2691 : 0 : i40e_dev_free_queues(dev);
2692 : :
2693 : : /* Disable interrupt */
2694 : 0 : i40e_pf_disable_irq0(hw);
2695 : 0 : rte_intr_disable(intr_handle);
2696 : :
2697 : : /* shutdown and destroy the HMC */
2698 : 0 : i40e_shutdown_lan_hmc(hw);
2699 : :
2700 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2701 : 0 : i40e_vsi_release(pf->vmdq[i].vsi);
2702 : 0 : pf->vmdq[i].vsi = NULL;
2703 : : }
2704 : 0 : rte_free(pf->vmdq);
2705 : 0 : pf->vmdq = NULL;
2706 : :
2707 : : /* release all the existing VSIs and VEBs */
2708 : 0 : i40e_vsi_release(pf->main_vsi);
2709 : :
2710 : : /* shutdown the adminq */
2711 : 0 : i40e_aq_queue_shutdown(hw, true);
2712 : 0 : i40e_shutdown_adminq(hw);
2713 : :
2714 : 0 : i40e_res_pool_destroy(&pf->qp_pool);
2715 : 0 : i40e_res_pool_destroy(&pf->msix_pool);
2716 : :
2717 : : /* Disable flexible payload in global configuration */
2718 [ # # ]: 0 : if (!pf->support_multi_driver)
2719 : 0 : i40e_flex_payload_reg_set_default(hw);
2720 : :
2721 : : /* force a PF reset to clean anything leftover */
2722 : 0 : reg = I40E_READ_REG(hw, I40E_PFGEN_CTRL);
2723 : 0 : I40E_WRITE_REG(hw, I40E_PFGEN_CTRL,
2724 : : (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
2725 : 0 : I40E_WRITE_FLUSH(hw);
2726 : :
2727 : : /* Clear PXE mode */
2728 : 0 : i40e_clear_pxe_mode(hw);
2729 : :
2730 : : /* Unconfigure filter control */
2731 : : memset(&settings, 0, sizeof(settings));
2732 : 0 : ret = i40e_set_filter_control(hw, &settings);
2733 [ # # ]: 0 : if (ret)
2734 : 0 : PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
2735 : : ret);
2736 : :
2737 : : /* Disable flow control */
2738 : 0 : hw->fc.requested_mode = I40E_FC_NONE;
2739 : 0 : i40e_set_fc(hw, &aq_fail, TRUE);
2740 : :
2741 : : /* uninitialize pf host driver */
2742 : 0 : i40e_pf_host_uninit(dev);
2743 : :
2744 : : do {
2745 : 0 : ret = rte_intr_callback_unregister(intr_handle,
2746 : : i40e_dev_interrupt_handler, dev);
2747 [ # # ]: 0 : if (ret >= 0 || ret == -ENOENT) {
2748 : : break;
2749 [ # # ]: 0 : } else if (ret != -EAGAIN) {
2750 : 0 : PMD_INIT_LOG(ERR,
2751 : : "intr callback unregister failed: %d",
2752 : : ret);
2753 : : }
2754 : 0 : i40e_msec_delay(500);
2755 [ # # ]: 0 : } while (retries++ < 5);
2756 : :
2757 : 0 : i40e_rm_ethtype_filter_list(pf);
2758 : 0 : i40e_rm_tunnel_filter_list(pf);
2759 : : i40e_rm_fdir_filter_list(pf);
2760 : :
2761 : : /* Remove all flows */
2762 [ # # ]: 0 : while ((p_flow = TAILQ_FIRST(&pf->flow_list))) {
2763 [ # # ]: 0 : TAILQ_REMOVE(&pf->flow_list, p_flow, node);
2764 : : /* Do not free FDIR flows since they are static allocated */
2765 [ # # ]: 0 : if (p_flow->filter_type != RTE_ETH_FILTER_FDIR)
2766 : 0 : rte_free(p_flow);
2767 : : }
2768 : :
2769 : : /* release the fdir static allocated memory */
2770 : 0 : i40e_fdir_memory_cleanup(pf);
2771 : :
2772 : : /* Remove all Traffic Manager configuration */
2773 : 0 : i40e_tm_conf_uninit(dev);
2774 : :
2775 : : i40e_clear_automask(pf);
2776 : :
2777 : 0 : hw->adapter_closed = 1;
2778 : 0 : return ret;
2779 : : }
2780 : :
2781 : : /*
2782 : : * Reset PF device only to re-initialize resources in PMD layer
2783 : : */
2784 : : static int
2785 : 0 : i40e_dev_reset(struct rte_eth_dev *dev)
2786 : : {
2787 : : int ret;
2788 : :
2789 : : /* When a DPDK PMD PF begin to reset PF port, it should notify all
2790 : : * its VF to make them align with it. The detailed notification
2791 : : * mechanism is PMD specific. As to i40e PF, it is rather complex.
2792 : : * To avoid unexpected behavior in VF, currently reset of PF with
2793 : : * SR-IOV activation is not supported. It might be supported later.
2794 : : */
2795 [ # # ]: 0 : if (dev->data->sriov.active)
2796 : : return -ENOTSUP;
2797 : :
2798 : 0 : ret = eth_i40e_dev_uninit(dev);
2799 [ # # ]: 0 : if (ret)
2800 : : return ret;
2801 : :
2802 : 0 : ret = eth_i40e_dev_init(dev, NULL);
2803 : :
2804 : 0 : return ret;
2805 : : }
2806 : :
2807 : : static int
2808 : 0 : i40e_dev_promiscuous_enable(struct rte_eth_dev *dev)
2809 : : {
2810 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2811 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2812 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2813 : : int status;
2814 : :
2815 : 0 : status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2816 : : true, NULL, true);
2817 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2818 : 0 : PMD_DRV_LOG(ERR, "Failed to enable unicast promiscuous");
2819 : 0 : return -EAGAIN;
2820 : : }
2821 : :
2822 : 0 : status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
2823 : : TRUE, NULL);
2824 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2825 : 0 : PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
2826 : : /* Rollback unicast promiscuous mode */
2827 : 0 : i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2828 : : false, NULL, true);
2829 : 0 : return -EAGAIN;
2830 : : }
2831 : :
2832 : : return 0;
2833 : : }
2834 : :
2835 : : static int
2836 : 0 : i40e_dev_promiscuous_disable(struct rte_eth_dev *dev)
2837 : : {
2838 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2839 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2840 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2841 : : int status;
2842 : :
2843 : 0 : status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2844 : : false, NULL, true);
2845 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2846 : 0 : PMD_DRV_LOG(ERR, "Failed to disable unicast promiscuous");
2847 : 0 : return -EAGAIN;
2848 : : }
2849 : :
2850 : : /* must remain in all_multicast mode */
2851 [ # # ]: 0 : if (dev->data->all_multicast == 1)
2852 : : return 0;
2853 : :
2854 : 0 : status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
2855 : : false, NULL);
2856 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2857 : 0 : PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
2858 : : /* Rollback unicast promiscuous mode */
2859 : 0 : i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2860 : : true, NULL, true);
2861 : 0 : return -EAGAIN;
2862 : : }
2863 : :
2864 : : return 0;
2865 : : }
2866 : :
2867 : : static int
2868 : 0 : i40e_dev_allmulticast_enable(struct rte_eth_dev *dev)
2869 : : {
2870 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2871 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2872 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2873 : : int ret;
2874 : :
2875 : 0 : ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid, TRUE, NULL);
2876 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2877 : 0 : PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
2878 : 0 : return -EAGAIN;
2879 : : }
2880 : :
2881 : : return 0;
2882 : : }
2883 : :
2884 : : static int
2885 : 0 : i40e_dev_allmulticast_disable(struct rte_eth_dev *dev)
2886 : : {
2887 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2888 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2889 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2890 : : int ret;
2891 : :
2892 [ # # ]: 0 : if (dev->data->promiscuous == 1)
2893 : : return 0; /* must remain in all_multicast mode */
2894 : :
2895 : 0 : ret = i40e_aq_set_vsi_multicast_promiscuous(hw,
2896 : 0 : vsi->seid, FALSE, NULL);
2897 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2898 : 0 : PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
2899 : 0 : return -EAGAIN;
2900 : : }
2901 : :
2902 : : return 0;
2903 : : }
2904 : :
2905 : : /*
2906 : : * Set device link up.
2907 : : */
2908 : : static int
2909 : 0 : i40e_dev_set_link_up(struct rte_eth_dev *dev)
2910 : : {
2911 : : /* re-apply link speed setting */
2912 : 0 : return i40e_apply_link_speed(dev);
2913 : : }
2914 : :
2915 : : /*
2916 : : * Set device link down.
2917 : : */
2918 : : static int
2919 : 0 : i40e_dev_set_link_down(struct rte_eth_dev *dev)
2920 : : {
2921 : : uint8_t speed = I40E_LINK_SPEED_UNKNOWN;
2922 : : uint8_t abilities = 0;
2923 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2924 : :
2925 : : abilities = I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
2926 : 0 : return i40e_phy_conf_link(hw, abilities, speed, false);
2927 : : }
2928 : :
2929 : : static __rte_always_inline void
2930 : : update_link_reg(struct i40e_hw *hw, struct rte_eth_link *link)
2931 : : {
2932 : : /* Link status registers and values*/
2933 : : #define I40E_REG_LINK_UP 0x40000080
2934 : : #define I40E_PRTMAC_MACC 0x001E24E0
2935 : : #define I40E_REG_MACC_25GB 0x00020000
2936 : : #define I40E_REG_SPEED_MASK 0x38000000
2937 : : #define I40E_REG_SPEED_0 0x00000000
2938 : : #define I40E_REG_SPEED_1 0x08000000
2939 : : #define I40E_REG_SPEED_2 0x10000000
2940 : : #define I40E_REG_SPEED_3 0x18000000
2941 : : #define I40E_REG_SPEED_4 0x20000000
2942 : : uint32_t link_speed;
2943 : : uint32_t reg_val;
2944 : :
2945 : 0 : reg_val = I40E_READ_REG(hw, I40E_PRTMAC_LINKSTA(0));
2946 : 0 : link_speed = reg_val & I40E_REG_SPEED_MASK;
2947 : 0 : reg_val &= I40E_REG_LINK_UP;
2948 : 0 : link->link_status = (reg_val == I40E_REG_LINK_UP) ? 1 : 0;
2949 : :
2950 [ # # ]: 0 : if (unlikely(link->link_status == 0))
2951 : : return;
2952 : :
2953 : : /* Parse the link status */
2954 [ # # # # : 0 : switch (link_speed) {
# # ]
2955 : 0 : case I40E_REG_SPEED_0:
2956 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_100M;
2957 : 0 : break;
2958 : 0 : case I40E_REG_SPEED_1:
2959 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_1G;
2960 : 0 : break;
2961 : 0 : case I40E_REG_SPEED_2:
2962 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
2963 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_2_5G;
2964 : : else
2965 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_10G;
2966 : : break;
2967 : 0 : case I40E_REG_SPEED_3:
2968 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
2969 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_5G;
2970 : : } else {
2971 : 0 : reg_val = I40E_READ_REG(hw, I40E_PRTMAC_MACC);
2972 : :
2973 [ # # ]: 0 : if (reg_val & I40E_REG_MACC_25GB)
2974 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_25G;
2975 : : else
2976 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_40G;
2977 : : }
2978 : : break;
2979 : 0 : case I40E_REG_SPEED_4:
2980 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
2981 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_10G;
2982 : : else
2983 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_20G;
2984 : : break;
2985 : 0 : default:
2986 : 0 : PMD_DRV_LOG(ERR, "Unknown link speed info %u", link_speed);
2987 : 0 : break;
2988 : : }
2989 : : }
2990 : :
2991 : : static __rte_always_inline void
2992 : : update_link_aq(struct i40e_hw *hw, struct rte_eth_link *link,
2993 : : bool enable_lse, int wait_to_complete)
2994 : : {
2995 : : #define CHECK_INTERVAL 100 /* 100ms */
2996 : : #define MAX_REPEAT_TIME 10 /* 1s (10 * 100ms) in total */
2997 : : uint32_t rep_cnt = MAX_REPEAT_TIME;
2998 : : struct i40e_link_status link_status;
2999 : : int status;
3000 : :
3001 : : memset(&link_status, 0, sizeof(link_status));
3002 : :
3003 : : do {
3004 : : memset(&link_status, 0, sizeof(link_status));
3005 : :
3006 : : /* Get link status information from hardware */
3007 : 0 : status = i40e_aq_get_link_info(hw, enable_lse,
3008 : : &link_status, NULL);
3009 [ # # ]: 0 : if (unlikely(status != I40E_SUCCESS)) {
3010 : : link->link_speed = RTE_ETH_SPEED_NUM_NONE;
3011 : : link->link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
3012 : 0 : PMD_DRV_LOG(ERR, "Failed to get link info");
3013 : 0 : return;
3014 : : }
3015 : :
3016 : 0 : link->link_status = link_status.link_info & I40E_AQ_LINK_UP;
3017 [ # # # # ]: 0 : if (!wait_to_complete || link->link_status)
3018 : : break;
3019 : :
3020 : : rte_delay_ms(CHECK_INTERVAL);
3021 [ # # ]: 0 : } while (--rep_cnt);
3022 : :
3023 : : /* Parse the link status */
3024 [ # # # # : 0 : switch (link_status.link_speed) {
# # # ]
3025 : 0 : case I40E_LINK_SPEED_100MB:
3026 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_100M;
3027 : 0 : break;
3028 : 0 : case I40E_LINK_SPEED_1GB:
3029 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_1G;
3030 : 0 : break;
3031 : 0 : case I40E_LINK_SPEED_10GB:
3032 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_10G;
3033 : 0 : break;
3034 : 0 : case I40E_LINK_SPEED_20GB:
3035 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_20G;
3036 : 0 : break;
3037 : 0 : case I40E_LINK_SPEED_25GB:
3038 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_25G;
3039 : 0 : break;
3040 : 0 : case I40E_LINK_SPEED_40GB:
3041 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_40G;
3042 : 0 : break;
3043 : 0 : default:
3044 [ # # ]: 0 : if (link->link_status)
3045 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_UNKNOWN;
3046 : : else
3047 : : link->link_speed = RTE_ETH_SPEED_NUM_NONE;
3048 : : break;
3049 : : }
3050 : : }
3051 : :
3052 : : int
3053 : 0 : i40e_dev_link_update(struct rte_eth_dev *dev,
3054 : : int wait_to_complete)
3055 : : {
3056 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3057 : : struct rte_eth_link link;
3058 [ # # ]: 0 : bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
3059 : : int ret;
3060 : :
3061 : : memset(&link, 0, sizeof(link));
3062 : :
3063 : : /* i40e uses full duplex only */
3064 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
3065 : 0 : link.link_autoneg = !(dev->data->dev_conf.link_speeds &
3066 : : RTE_ETH_LINK_SPEED_FIXED);
3067 : :
3068 [ # # ]: 0 : if (!wait_to_complete && !enable_lse)
3069 : : update_link_reg(hw, &link);
3070 : : else
3071 : 0 : update_link_aq(hw, &link, enable_lse, wait_to_complete);
3072 : :
3073 [ # # ]: 0 : if (hw->switch_dev)
3074 : : rte_eth_linkstatus_get(hw->switch_dev, &link);
3075 : :
3076 : : ret = rte_eth_linkstatus_set(dev, &link);
3077 : 0 : i40e_notify_all_vfs_link_status(dev);
3078 : :
3079 : 0 : return ret;
3080 : : }
3081 : :
3082 : : static void
3083 : 0 : i40e_stat_update_48_in_64(struct i40e_hw *hw, uint32_t hireg,
3084 : : uint32_t loreg, bool offset_loaded, uint64_t *offset,
3085 : : uint64_t *stat, uint64_t *prev_stat)
3086 : : {
3087 : 0 : i40e_stat_update_48(hw, hireg, loreg, offset_loaded, offset, stat);
3088 : : /* enlarge the limitation when statistics counters overflowed */
3089 [ # # ]: 0 : if (offset_loaded) {
3090 [ # # ]: 0 : if (I40E_RXTX_BYTES_L_48_BIT(*prev_stat) > *stat)
3091 : 0 : *stat += (uint64_t)1 << I40E_48_BIT_WIDTH;
3092 : 0 : *stat += I40E_RXTX_BYTES_H_16_BIT(*prev_stat);
3093 : : }
3094 : 0 : *prev_stat = *stat;
3095 : 0 : }
3096 : :
3097 : : /* Get all the statistics of a VSI */
3098 : : void
3099 : 0 : i40e_update_vsi_stats(struct i40e_vsi *vsi)
3100 : : {
3101 : : struct i40e_eth_stats *oes = &vsi->eth_stats_offset;
3102 : : struct i40e_eth_stats *nes = &vsi->eth_stats;
3103 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3104 : 0 : int idx = rte_le_to_cpu_16(vsi->info.stat_counter_idx);
3105 : :
3106 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GORCH(idx), I40E_GLV_GORCL(idx),
3107 : 0 : vsi->offset_loaded, &oes->rx_bytes,
3108 : 0 : &nes->rx_bytes, &vsi->prev_rx_bytes);
3109 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPRCH(idx), I40E_GLV_UPRCL(idx),
3110 : 0 : vsi->offset_loaded, &oes->rx_unicast,
3111 : 0 : &nes->rx_unicast);
3112 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPRCH(idx), I40E_GLV_MPRCL(idx),
3113 : 0 : vsi->offset_loaded, &oes->rx_multicast,
3114 : 0 : &nes->rx_multicast);
3115 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPRCH(idx), I40E_GLV_BPRCL(idx),
3116 : 0 : vsi->offset_loaded, &oes->rx_broadcast,
3117 : 0 : &nes->rx_broadcast);
3118 : : /* exclude CRC bytes */
3119 : 0 : nes->rx_bytes -= (nes->rx_unicast + nes->rx_multicast +
3120 : 0 : nes->rx_broadcast) * RTE_ETHER_CRC_LEN;
3121 : :
3122 : 0 : i40e_stat_update_32(hw, I40E_GLV_RDPC(idx), vsi->offset_loaded,
3123 : : &oes->rx_discards, &nes->rx_discards);
3124 : : /* GLV_REPC not supported */
3125 : : /* GLV_RMPC not supported */
3126 : 0 : i40e_stat_update_32(hw, I40E_GLV_RUPP(idx), vsi->offset_loaded,
3127 : : &oes->rx_unknown_protocol,
3128 : : &nes->rx_unknown_protocol);
3129 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GOTCH(idx), I40E_GLV_GOTCL(idx),
3130 : 0 : vsi->offset_loaded, &oes->tx_bytes,
3131 : 0 : &nes->tx_bytes, &vsi->prev_tx_bytes);
3132 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPTCH(idx), I40E_GLV_UPTCL(idx),
3133 : 0 : vsi->offset_loaded, &oes->tx_unicast,
3134 : 0 : &nes->tx_unicast);
3135 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPTCH(idx), I40E_GLV_MPTCL(idx),
3136 : 0 : vsi->offset_loaded, &oes->tx_multicast,
3137 : 0 : &nes->tx_multicast);
3138 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPTCH(idx), I40E_GLV_BPTCL(idx),
3139 : 0 : vsi->offset_loaded, &oes->tx_broadcast,
3140 : 0 : &nes->tx_broadcast);
3141 : : /* GLV_TDPC not supported */
3142 : 0 : i40e_stat_update_32(hw, I40E_GLV_TEPC(idx), vsi->offset_loaded,
3143 : : &oes->tx_errors, &nes->tx_errors);
3144 : 0 : vsi->offset_loaded = true;
3145 : :
3146 : 0 : PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats start *******************",
3147 : : vsi->vsi_id);
3148 : 0 : PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", nes->rx_bytes);
3149 : 0 : PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", nes->rx_unicast);
3150 : 0 : PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", nes->rx_multicast);
3151 : 0 : PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", nes->rx_broadcast);
3152 : 0 : PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", nes->rx_discards);
3153 : 0 : PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
3154 : : nes->rx_unknown_protocol);
3155 : 0 : PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", nes->tx_bytes);
3156 : 0 : PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", nes->tx_unicast);
3157 : 0 : PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", nes->tx_multicast);
3158 : 0 : PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", nes->tx_broadcast);
3159 : 0 : PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", nes->tx_discards);
3160 : 0 : PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", nes->tx_errors);
3161 : 0 : PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats end *******************",
3162 : : vsi->vsi_id);
3163 : 0 : }
3164 : :
3165 : : static void
3166 : 0 : i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw)
3167 : : {
3168 : : unsigned int i;
3169 : : struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
3170 : : struct i40e_hw_port_stats *os = &pf->stats_offset; /* old stats */
3171 : :
3172 : : /* Get rx/tx bytes of internal transfer packets */
3173 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GORCH(hw->port),
3174 : 0 : I40E_GLV_GORCL(hw->port),
3175 : 0 : pf->offset_loaded,
3176 : 0 : &pf->internal_stats_offset.rx_bytes,
3177 : 0 : &pf->internal_stats.rx_bytes,
3178 : : &pf->internal_prev_rx_bytes);
3179 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GOTCH(hw->port),
3180 : 0 : I40E_GLV_GOTCL(hw->port),
3181 : 0 : pf->offset_loaded,
3182 : 0 : &pf->internal_stats_offset.tx_bytes,
3183 : 0 : &pf->internal_stats.tx_bytes,
3184 : : &pf->internal_prev_tx_bytes);
3185 : : /* Get total internal rx packet count */
3186 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPRCH(hw->port),
3187 : 0 : I40E_GLV_UPRCL(hw->port),
3188 : 0 : pf->offset_loaded,
3189 : 0 : &pf->internal_stats_offset.rx_unicast,
3190 : 0 : &pf->internal_stats.rx_unicast);
3191 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPRCH(hw->port),
3192 : 0 : I40E_GLV_MPRCL(hw->port),
3193 : 0 : pf->offset_loaded,
3194 : 0 : &pf->internal_stats_offset.rx_multicast,
3195 : 0 : &pf->internal_stats.rx_multicast);
3196 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPRCH(hw->port),
3197 : 0 : I40E_GLV_BPRCL(hw->port),
3198 : 0 : pf->offset_loaded,
3199 : 0 : &pf->internal_stats_offset.rx_broadcast,
3200 : 0 : &pf->internal_stats.rx_broadcast);
3201 : : /* Get total internal tx packet count */
3202 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPTCH(hw->port),
3203 : 0 : I40E_GLV_UPTCL(hw->port),
3204 : 0 : pf->offset_loaded,
3205 : 0 : &pf->internal_stats_offset.tx_unicast,
3206 : 0 : &pf->internal_stats.tx_unicast);
3207 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPTCH(hw->port),
3208 : 0 : I40E_GLV_MPTCL(hw->port),
3209 : 0 : pf->offset_loaded,
3210 : 0 : &pf->internal_stats_offset.tx_multicast,
3211 : 0 : &pf->internal_stats.tx_multicast);
3212 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPTCH(hw->port),
3213 : 0 : I40E_GLV_BPTCL(hw->port),
3214 : 0 : pf->offset_loaded,
3215 : 0 : &pf->internal_stats_offset.tx_broadcast,
3216 : 0 : &pf->internal_stats.tx_broadcast);
3217 : :
3218 : : /* exclude CRC size */
3219 : 0 : pf->internal_stats.rx_bytes -= (pf->internal_stats.rx_unicast +
3220 : 0 : pf->internal_stats.rx_multicast +
3221 : 0 : pf->internal_stats.rx_broadcast) * RTE_ETHER_CRC_LEN;
3222 : :
3223 : : /* Get statistics of struct i40e_eth_stats */
3224 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLPRT_GORCH(hw->port),
3225 : 0 : I40E_GLPRT_GORCL(hw->port),
3226 : 0 : pf->offset_loaded, &os->eth.rx_bytes,
3227 : 0 : &ns->eth.rx_bytes, &pf->prev_rx_bytes);
3228 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_UPRCH(hw->port),
3229 : 0 : I40E_GLPRT_UPRCL(hw->port),
3230 : 0 : pf->offset_loaded, &os->eth.rx_unicast,
3231 : 0 : &ns->eth.rx_unicast);
3232 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_MPRCH(hw->port),
3233 : 0 : I40E_GLPRT_MPRCL(hw->port),
3234 : 0 : pf->offset_loaded, &os->eth.rx_multicast,
3235 : 0 : &ns->eth.rx_multicast);
3236 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_BPRCH(hw->port),
3237 : 0 : I40E_GLPRT_BPRCL(hw->port),
3238 : 0 : pf->offset_loaded, &os->eth.rx_broadcast,
3239 : 0 : &ns->eth.rx_broadcast);
3240 : : /* Workaround: CRC size should not be included in byte statistics,
3241 : : * so subtract RTE_ETHER_CRC_LEN from the byte counter for each rx
3242 : : * packet.
3243 : : */
3244 : 0 : ns->eth.rx_bytes -= (ns->eth.rx_unicast + ns->eth.rx_multicast +
3245 : 0 : ns->eth.rx_broadcast) * RTE_ETHER_CRC_LEN;
3246 : :
3247 : : /* exclude internal rx bytes
3248 : : * Workaround: it is possible I40E_GLV_GORCH[H/L] is updated before
3249 : : * I40E_GLPRT_GORCH[H/L], so there is a small window that cause negative
3250 : : * value.
3251 : : * same to I40E_GLV_UPRC[H/L], I40E_GLV_MPRC[H/L], I40E_GLV_BPRC[H/L].
3252 : : */
3253 [ # # ]: 0 : if (ns->eth.rx_bytes < pf->internal_stats.rx_bytes)
3254 : 0 : ns->eth.rx_bytes = 0;
3255 : : else
3256 : 0 : ns->eth.rx_bytes -= pf->internal_stats.rx_bytes;
3257 : :
3258 [ # # ]: 0 : if (ns->eth.rx_unicast < pf->internal_stats.rx_unicast)
3259 : 0 : ns->eth.rx_unicast = 0;
3260 : : else
3261 : 0 : ns->eth.rx_unicast -= pf->internal_stats.rx_unicast;
3262 : :
3263 [ # # ]: 0 : if (ns->eth.rx_multicast < pf->internal_stats.rx_multicast)
3264 : 0 : ns->eth.rx_multicast = 0;
3265 : : else
3266 : 0 : ns->eth.rx_multicast -= pf->internal_stats.rx_multicast;
3267 : :
3268 [ # # ]: 0 : if (ns->eth.rx_broadcast < pf->internal_stats.rx_broadcast)
3269 : 0 : ns->eth.rx_broadcast = 0;
3270 : : else
3271 : 0 : ns->eth.rx_broadcast -= pf->internal_stats.rx_broadcast;
3272 : :
3273 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RDPC(hw->port),
3274 : 0 : pf->offset_loaded, &os->eth.rx_discards,
3275 : : &ns->eth.rx_discards);
3276 : : /* GLPRT_REPC not supported */
3277 : : /* GLPRT_RMPC not supported */
3278 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RUPP(hw->port),
3279 : 0 : pf->offset_loaded,
3280 : : &os->eth.rx_unknown_protocol,
3281 : : &ns->eth.rx_unknown_protocol);
3282 : 0 : i40e_stat_update_48(hw, I40E_GL_RXERR1_H(hw->pf_id + I40E_MAX_VF),
3283 : 0 : I40E_GL_RXERR1_L(hw->pf_id + I40E_MAX_VF),
3284 : 0 : pf->offset_loaded, &pf->rx_err1_offset,
3285 : 0 : &pf->rx_err1);
3286 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLPRT_GOTCH(hw->port),
3287 : 0 : I40E_GLPRT_GOTCL(hw->port),
3288 : 0 : pf->offset_loaded, &os->eth.tx_bytes,
3289 : 0 : &ns->eth.tx_bytes, &pf->prev_tx_bytes);
3290 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_UPTCH(hw->port),
3291 : 0 : I40E_GLPRT_UPTCL(hw->port),
3292 : 0 : pf->offset_loaded, &os->eth.tx_unicast,
3293 : 0 : &ns->eth.tx_unicast);
3294 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_MPTCH(hw->port),
3295 : 0 : I40E_GLPRT_MPTCL(hw->port),
3296 : 0 : pf->offset_loaded, &os->eth.tx_multicast,
3297 : 0 : &ns->eth.tx_multicast);
3298 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_BPTCH(hw->port),
3299 : 0 : I40E_GLPRT_BPTCL(hw->port),
3300 : 0 : pf->offset_loaded, &os->eth.tx_broadcast,
3301 : 0 : &ns->eth.tx_broadcast);
3302 : 0 : ns->eth.tx_bytes -= (ns->eth.tx_unicast + ns->eth.tx_multicast +
3303 : 0 : ns->eth.tx_broadcast) * RTE_ETHER_CRC_LEN;
3304 : :
3305 : : /* exclude internal tx bytes
3306 : : * Workaround: it is possible I40E_GLV_GOTCH[H/L] is updated before
3307 : : * I40E_GLPRT_GOTCH[H/L], so there is a small window that cause negative
3308 : : * value.
3309 : : * same to I40E_GLV_UPTC[H/L], I40E_GLV_MPTC[H/L], I40E_GLV_BPTC[H/L].
3310 : : */
3311 [ # # ]: 0 : if (ns->eth.tx_bytes < pf->internal_stats.tx_bytes)
3312 : 0 : ns->eth.tx_bytes = 0;
3313 : : else
3314 : 0 : ns->eth.tx_bytes -= pf->internal_stats.tx_bytes;
3315 : :
3316 [ # # ]: 0 : if (ns->eth.tx_unicast < pf->internal_stats.tx_unicast)
3317 : 0 : ns->eth.tx_unicast = 0;
3318 : : else
3319 : 0 : ns->eth.tx_unicast -= pf->internal_stats.tx_unicast;
3320 : :
3321 [ # # ]: 0 : if (ns->eth.tx_multicast < pf->internal_stats.tx_multicast)
3322 : 0 : ns->eth.tx_multicast = 0;
3323 : : else
3324 : 0 : ns->eth.tx_multicast -= pf->internal_stats.tx_multicast;
3325 : :
3326 [ # # ]: 0 : if (ns->eth.tx_broadcast < pf->internal_stats.tx_broadcast)
3327 : 0 : ns->eth.tx_broadcast = 0;
3328 : : else
3329 : 0 : ns->eth.tx_broadcast -= pf->internal_stats.tx_broadcast;
3330 : :
3331 : : /* GLPRT_TEPC not supported */
3332 : :
3333 : : /* additional port specific stats */
3334 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_TDOLD(hw->port),
3335 : 0 : pf->offset_loaded, &os->tx_dropped_link_down,
3336 : : &ns->tx_dropped_link_down);
3337 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_CRCERRS(hw->port),
3338 : 0 : pf->offset_loaded, &os->crc_errors,
3339 : : &ns->crc_errors);
3340 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_ILLERRC(hw->port),
3341 : 0 : pf->offset_loaded, &os->illegal_bytes,
3342 : : &ns->illegal_bytes);
3343 : : /* GLPRT_ERRBC not supported */
3344 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_MLFC(hw->port),
3345 : 0 : pf->offset_loaded, &os->mac_local_faults,
3346 : : &ns->mac_local_faults);
3347 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_MRFC(hw->port),
3348 : 0 : pf->offset_loaded, &os->mac_remote_faults,
3349 : : &ns->mac_remote_faults);
3350 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RLEC(hw->port),
3351 : 0 : pf->offset_loaded, &os->rx_length_errors,
3352 : : &ns->rx_length_errors);
3353 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXONRXC(hw->port),
3354 : 0 : pf->offset_loaded, &os->link_xon_rx,
3355 : : &ns->link_xon_rx);
3356 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
3357 : 0 : pf->offset_loaded, &os->link_xoff_rx,
3358 : : &ns->link_xoff_rx);
3359 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3360 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
3361 : 0 : pf->offset_loaded,
3362 : : &os->priority_xon_rx[i],
3363 : : &ns->priority_xon_rx[i]);
3364 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
3365 : 0 : pf->offset_loaded,
3366 : : &os->priority_xoff_rx[i],
3367 : : &ns->priority_xoff_rx[i]);
3368 : : }
3369 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXONTXC(hw->port),
3370 : 0 : pf->offset_loaded, &os->link_xon_tx,
3371 : : &ns->link_xon_tx);
3372 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
3373 : 0 : pf->offset_loaded, &os->link_xoff_tx,
3374 : : &ns->link_xoff_tx);
3375 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3376 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
3377 : 0 : pf->offset_loaded,
3378 : : &os->priority_xon_tx[i],
3379 : : &ns->priority_xon_tx[i]);
3380 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
3381 : 0 : pf->offset_loaded,
3382 : : &os->priority_xoff_tx[i],
3383 : : &ns->priority_xoff_tx[i]);
3384 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RXON2OFFCNT(hw->port, i),
3385 : 0 : pf->offset_loaded,
3386 : : &os->priority_xon_2_xoff[i],
3387 : : &ns->priority_xon_2_xoff[i]);
3388 : : }
3389 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC64H(hw->port),
3390 : 0 : I40E_GLPRT_PRC64L(hw->port),
3391 : 0 : pf->offset_loaded, &os->rx_size_64,
3392 : 0 : &ns->rx_size_64);
3393 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC127H(hw->port),
3394 : 0 : I40E_GLPRT_PRC127L(hw->port),
3395 : 0 : pf->offset_loaded, &os->rx_size_127,
3396 : 0 : &ns->rx_size_127);
3397 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC255H(hw->port),
3398 : 0 : I40E_GLPRT_PRC255L(hw->port),
3399 : 0 : pf->offset_loaded, &os->rx_size_255,
3400 : 0 : &ns->rx_size_255);
3401 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC511H(hw->port),
3402 : 0 : I40E_GLPRT_PRC511L(hw->port),
3403 : 0 : pf->offset_loaded, &os->rx_size_511,
3404 : 0 : &ns->rx_size_511);
3405 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC1023H(hw->port),
3406 : 0 : I40E_GLPRT_PRC1023L(hw->port),
3407 : 0 : pf->offset_loaded, &os->rx_size_1023,
3408 : 0 : &ns->rx_size_1023);
3409 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC1522H(hw->port),
3410 : 0 : I40E_GLPRT_PRC1522L(hw->port),
3411 : 0 : pf->offset_loaded, &os->rx_size_1522,
3412 : 0 : &ns->rx_size_1522);
3413 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC9522H(hw->port),
3414 : 0 : I40E_GLPRT_PRC9522L(hw->port),
3415 : 0 : pf->offset_loaded, &os->rx_size_big,
3416 : 0 : &ns->rx_size_big);
3417 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RUC(hw->port),
3418 : 0 : pf->offset_loaded, &os->rx_undersize,
3419 : : &ns->rx_undersize);
3420 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RFC(hw->port),
3421 : 0 : pf->offset_loaded, &os->rx_fragments,
3422 : : &ns->rx_fragments);
3423 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_ROC(hw->port),
3424 : 0 : pf->offset_loaded, &os->rx_oversize,
3425 : : &ns->rx_oversize);
3426 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RJC(hw->port),
3427 : 0 : pf->offset_loaded, &os->rx_jabber,
3428 : : &ns->rx_jabber);
3429 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC64H(hw->port),
3430 : 0 : I40E_GLPRT_PTC64L(hw->port),
3431 : 0 : pf->offset_loaded, &os->tx_size_64,
3432 : 0 : &ns->tx_size_64);
3433 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC127H(hw->port),
3434 : 0 : I40E_GLPRT_PTC127L(hw->port),
3435 : 0 : pf->offset_loaded, &os->tx_size_127,
3436 : 0 : &ns->tx_size_127);
3437 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC255H(hw->port),
3438 : 0 : I40E_GLPRT_PTC255L(hw->port),
3439 : 0 : pf->offset_loaded, &os->tx_size_255,
3440 : 0 : &ns->tx_size_255);
3441 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC511H(hw->port),
3442 : 0 : I40E_GLPRT_PTC511L(hw->port),
3443 : 0 : pf->offset_loaded, &os->tx_size_511,
3444 : 0 : &ns->tx_size_511);
3445 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC1023H(hw->port),
3446 : 0 : I40E_GLPRT_PTC1023L(hw->port),
3447 : 0 : pf->offset_loaded, &os->tx_size_1023,
3448 : 0 : &ns->tx_size_1023);
3449 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC1522H(hw->port),
3450 : 0 : I40E_GLPRT_PTC1522L(hw->port),
3451 : 0 : pf->offset_loaded, &os->tx_size_1522,
3452 : 0 : &ns->tx_size_1522);
3453 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC9522H(hw->port),
3454 : 0 : I40E_GLPRT_PTC9522L(hw->port),
3455 : 0 : pf->offset_loaded, &os->tx_size_big,
3456 : 0 : &ns->tx_size_big);
3457 : 0 : i40e_stat_update_32(hw, I40E_GLQF_PCNT(pf->fdir.match_counter_index),
3458 : 0 : pf->offset_loaded,
3459 : : &os->fd_sb_match, &ns->fd_sb_match);
3460 : : /* GLPRT_MSPDC not supported */
3461 : : /* GLPRT_XEC not supported */
3462 : :
3463 : 0 : pf->offset_loaded = true;
3464 : :
3465 [ # # ]: 0 : if (pf->main_vsi)
3466 : 0 : i40e_update_vsi_stats(pf->main_vsi);
3467 : 0 : }
3468 : :
3469 : : /* Get all statistics of a port */
3470 : : static int
3471 : 0 : i40e_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
3472 : : {
3473 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3474 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3475 : : struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
3476 : : struct i40e_vsi *vsi;
3477 : : unsigned i;
3478 : :
3479 : : /* call read registers - updates values, now write them to struct */
3480 : 0 : i40e_read_stats_registers(pf, hw);
3481 : :
3482 : 0 : stats->ipackets = pf->main_vsi->eth_stats.rx_unicast +
3483 : 0 : pf->main_vsi->eth_stats.rx_multicast +
3484 : 0 : pf->main_vsi->eth_stats.rx_broadcast -
3485 : 0 : pf->main_vsi->eth_stats.rx_discards -
3486 : 0 : pf->rx_err1;
3487 : 0 : stats->opackets = ns->eth.tx_unicast +
3488 : 0 : ns->eth.tx_multicast +
3489 : 0 : ns->eth.tx_broadcast;
3490 : 0 : stats->ibytes = pf->main_vsi->eth_stats.rx_bytes;
3491 : 0 : stats->obytes = ns->eth.tx_bytes;
3492 : 0 : stats->oerrors = ns->eth.tx_errors +
3493 : 0 : pf->main_vsi->eth_stats.tx_errors;
3494 : :
3495 : : /* Rx Errors */
3496 : 0 : stats->imissed = ns->eth.rx_discards +
3497 : : pf->main_vsi->eth_stats.rx_discards;
3498 : 0 : stats->ierrors = ns->crc_errors +
3499 : 0 : ns->rx_length_errors + ns->rx_undersize +
3500 : 0 : ns->rx_oversize + ns->rx_fragments + ns->rx_jabber +
3501 : : pf->rx_err1;
3502 : :
3503 [ # # ]: 0 : if (pf->vfs) {
3504 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++) {
3505 : 0 : vsi = pf->vfs[i].vsi;
3506 : 0 : i40e_update_vsi_stats(vsi);
3507 : :
3508 : 0 : stats->ipackets += (vsi->eth_stats.rx_unicast +
3509 : 0 : vsi->eth_stats.rx_multicast +
3510 : 0 : vsi->eth_stats.rx_broadcast -
3511 : 0 : vsi->eth_stats.rx_discards);
3512 : 0 : stats->ibytes += vsi->eth_stats.rx_bytes;
3513 : 0 : stats->oerrors += vsi->eth_stats.tx_errors;
3514 : 0 : stats->imissed += vsi->eth_stats.rx_discards;
3515 : : }
3516 : : }
3517 : :
3518 : 0 : PMD_DRV_LOG(DEBUG, "***************** PF stats start *******************");
3519 : 0 : PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", ns->eth.rx_bytes);
3520 : 0 : PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", ns->eth.rx_unicast);
3521 : 0 : PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", ns->eth.rx_multicast);
3522 : 0 : PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", ns->eth.rx_broadcast);
3523 : 0 : PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", ns->eth.rx_discards);
3524 : 0 : PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
3525 : : ns->eth.rx_unknown_protocol);
3526 : 0 : PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", ns->eth.tx_bytes);
3527 : 0 : PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", ns->eth.tx_unicast);
3528 : 0 : PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", ns->eth.tx_multicast);
3529 : 0 : PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", ns->eth.tx_broadcast);
3530 : 0 : PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", ns->eth.tx_discards);
3531 : 0 : PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", ns->eth.tx_errors);
3532 : :
3533 : 0 : PMD_DRV_LOG(DEBUG, "tx_dropped_link_down: %"PRIu64"",
3534 : : ns->tx_dropped_link_down);
3535 : 0 : PMD_DRV_LOG(DEBUG, "crc_errors: %"PRIu64"", ns->crc_errors);
3536 : 0 : PMD_DRV_LOG(DEBUG, "illegal_bytes: %"PRIu64"",
3537 : : ns->illegal_bytes);
3538 : 0 : PMD_DRV_LOG(DEBUG, "error_bytes: %"PRIu64"", ns->error_bytes);
3539 : 0 : PMD_DRV_LOG(DEBUG, "mac_local_faults: %"PRIu64"",
3540 : : ns->mac_local_faults);
3541 : 0 : PMD_DRV_LOG(DEBUG, "mac_remote_faults: %"PRIu64"",
3542 : : ns->mac_remote_faults);
3543 : 0 : PMD_DRV_LOG(DEBUG, "rx_length_errors: %"PRIu64"",
3544 : : ns->rx_length_errors);
3545 : 0 : PMD_DRV_LOG(DEBUG, "link_xon_rx: %"PRIu64"", ns->link_xon_rx);
3546 : 0 : PMD_DRV_LOG(DEBUG, "link_xoff_rx: %"PRIu64"", ns->link_xoff_rx);
3547 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3548 : 0 : PMD_DRV_LOG(DEBUG, "priority_xon_rx[%d]: %"PRIu64"",
3549 : : i, ns->priority_xon_rx[i]);
3550 : 0 : PMD_DRV_LOG(DEBUG, "priority_xoff_rx[%d]: %"PRIu64"",
3551 : : i, ns->priority_xoff_rx[i]);
3552 : : }
3553 : 0 : PMD_DRV_LOG(DEBUG, "link_xon_tx: %"PRIu64"", ns->link_xon_tx);
3554 : 0 : PMD_DRV_LOG(DEBUG, "link_xoff_tx: %"PRIu64"", ns->link_xoff_tx);
3555 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3556 : 0 : PMD_DRV_LOG(DEBUG, "priority_xon_tx[%d]: %"PRIu64"",
3557 : : i, ns->priority_xon_tx[i]);
3558 : 0 : PMD_DRV_LOG(DEBUG, "priority_xoff_tx[%d]: %"PRIu64"",
3559 : : i, ns->priority_xoff_tx[i]);
3560 : 0 : PMD_DRV_LOG(DEBUG, "priority_xon_2_xoff[%d]: %"PRIu64"",
3561 : : i, ns->priority_xon_2_xoff[i]);
3562 : : }
3563 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_64: %"PRIu64"", ns->rx_size_64);
3564 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_127: %"PRIu64"", ns->rx_size_127);
3565 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_255: %"PRIu64"", ns->rx_size_255);
3566 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_511: %"PRIu64"", ns->rx_size_511);
3567 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_1023: %"PRIu64"", ns->rx_size_1023);
3568 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_1522: %"PRIu64"", ns->rx_size_1522);
3569 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_big: %"PRIu64"", ns->rx_size_big);
3570 : 0 : PMD_DRV_LOG(DEBUG, "rx_undersize: %"PRIu64"", ns->rx_undersize);
3571 : 0 : PMD_DRV_LOG(DEBUG, "rx_fragments: %"PRIu64"", ns->rx_fragments);
3572 : 0 : PMD_DRV_LOG(DEBUG, "rx_oversize: %"PRIu64"", ns->rx_oversize);
3573 : 0 : PMD_DRV_LOG(DEBUG, "rx_jabber: %"PRIu64"", ns->rx_jabber);
3574 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_64: %"PRIu64"", ns->tx_size_64);
3575 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_127: %"PRIu64"", ns->tx_size_127);
3576 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_255: %"PRIu64"", ns->tx_size_255);
3577 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_511: %"PRIu64"", ns->tx_size_511);
3578 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_1023: %"PRIu64"", ns->tx_size_1023);
3579 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_1522: %"PRIu64"", ns->tx_size_1522);
3580 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_big: %"PRIu64"", ns->tx_size_big);
3581 : 0 : PMD_DRV_LOG(DEBUG, "mac_short_packet_dropped: %"PRIu64"",
3582 : : ns->mac_short_packet_dropped);
3583 : 0 : PMD_DRV_LOG(DEBUG, "checksum_error: %"PRIu64"",
3584 : : ns->checksum_error);
3585 : 0 : PMD_DRV_LOG(DEBUG, "fdir_match: %"PRIu64"", ns->fd_sb_match);
3586 : 0 : PMD_DRV_LOG(DEBUG, "***************** PF stats end ********************");
3587 : 0 : return 0;
3588 : : }
3589 : :
3590 : : /* Reset the statistics */
3591 : : static int
3592 : 0 : i40e_dev_stats_reset(struct rte_eth_dev *dev)
3593 : : {
3594 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3595 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3596 : :
3597 : : /* Mark PF and VSI stats to update the offset, aka "reset" */
3598 : 0 : pf->offset_loaded = false;
3599 [ # # ]: 0 : if (pf->main_vsi)
3600 : 0 : pf->main_vsi->offset_loaded = false;
3601 : :
3602 : : /* read the stats, reading current register values into offset */
3603 : 0 : i40e_read_stats_registers(pf, hw);
3604 : :
3605 : 0 : memset(&pf->mbuf_stats, 0, sizeof(struct i40e_mbuf_stats));
3606 : :
3607 : 0 : return 0;
3608 : : }
3609 : :
3610 : : static uint32_t
3611 : : i40e_xstats_calc_num(void)
3612 : : {
3613 : : return I40E_NB_ETH_XSTATS + I40E_NB_MBUF_XSTATS +
3614 : : I40E_NB_HW_PORT_XSTATS +
3615 : : (I40E_NB_RXQ_PRIO_XSTATS * 8) +
3616 : : (I40E_NB_TXQ_PRIO_XSTATS * 8);
3617 : : }
3618 : :
3619 : 0 : static int i40e_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
3620 : : struct rte_eth_xstat_name *xstats_names,
3621 : : __rte_unused unsigned limit)
3622 : : {
3623 : : unsigned count = 0;
3624 : : unsigned i, prio;
3625 : :
3626 [ # # ]: 0 : if (xstats_names == NULL)
3627 : : return i40e_xstats_calc_num();
3628 : :
3629 : : /* Note: limit checked in rte_eth_xstats_names() */
3630 : :
3631 : : /* Get stats from i40e_eth_stats struct */
3632 [ # # ]: 0 : for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
3633 : 0 : strlcpy(xstats_names[count].name,
3634 : : rte_i40e_stats_strings[i].name,
3635 : : sizeof(xstats_names[count].name));
3636 : 0 : count++;
3637 : : }
3638 : :
3639 : : /* Get stats from i40e_mbuf_stats struct */
3640 [ # # ]: 0 : for (i = 0; i < I40E_NB_MBUF_XSTATS; i++) {
3641 : 0 : strlcpy(xstats_names[count].name,
3642 : : i40e_mbuf_strings[i].name,
3643 : : sizeof(xstats_names[count].name));
3644 : 0 : count++;
3645 : : }
3646 : :
3647 : : /* Get individual stats from i40e_hw_port struct */
3648 [ # # ]: 0 : for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
3649 : 0 : strlcpy(xstats_names[count].name,
3650 : : rte_i40e_hw_port_strings[i].name,
3651 : : sizeof(xstats_names[count].name));
3652 : 0 : count++;
3653 : : }
3654 : :
3655 [ # # ]: 0 : for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
3656 [ # # ]: 0 : for (prio = 0; prio < 8; prio++) {
3657 : 0 : snprintf(xstats_names[count].name,
3658 : : sizeof(xstats_names[count].name),
3659 : : "rx_priority%u_%s", prio,
3660 : 0 : rte_i40e_rxq_prio_strings[i].name);
3661 : 0 : count++;
3662 : : }
3663 : : }
3664 : :
3665 [ # # ]: 0 : for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
3666 [ # # ]: 0 : for (prio = 0; prio < 8; prio++) {
3667 : 0 : snprintf(xstats_names[count].name,
3668 : : sizeof(xstats_names[count].name),
3669 : : "tx_priority%u_%s", prio,
3670 : 0 : rte_i40e_txq_prio_strings[i].name);
3671 : 0 : count++;
3672 : : }
3673 : : }
3674 : 0 : return count;
3675 : : }
3676 : :
3677 : : static void
3678 : : i40e_dev_update_mbuf_stats(struct rte_eth_dev *ethdev,
3679 : : struct i40e_mbuf_stats *mbuf_stats)
3680 : : {
3681 : : uint16_t idx;
3682 : : struct i40e_tx_queue *txq;
3683 : :
3684 [ # # ]: 0 : for (idx = 0; idx < ethdev->data->nb_tx_queues; idx++) {
3685 : 0 : txq = ethdev->data->tx_queues[idx];
3686 : 0 : mbuf_stats->tx_pkt_errors += txq->mbuf_errors;
3687 : : }
3688 : : }
3689 : :
3690 : : static int
3691 : 0 : i40e_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
3692 : : unsigned n)
3693 : : {
3694 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3695 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3696 : : struct i40e_adapter *adapter =
3697 : : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3698 : : struct i40e_mbuf_stats mbuf_stats = {0};
3699 : : unsigned i, count, prio;
3700 : 0 : struct i40e_hw_port_stats *hw_stats = &pf->stats;
3701 : :
3702 : : count = i40e_xstats_calc_num();
3703 [ # # ]: 0 : if (n < count)
3704 : : return count;
3705 : :
3706 : 0 : i40e_read_stats_registers(pf, hw);
3707 : :
3708 [ # # ]: 0 : if (xstats == NULL)
3709 : : return 0;
3710 : :
3711 : : count = 0;
3712 : :
3713 [ # # ]: 0 : if (adapter->mbuf_check)
3714 : : i40e_dev_update_mbuf_stats(dev, &mbuf_stats);
3715 : :
3716 : : /* Get stats from i40e_eth_stats struct */
3717 [ # # ]: 0 : for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
3718 : 0 : xstats[count].value = *(uint64_t *)(((char *)&hw_stats->eth) +
3719 : 0 : rte_i40e_stats_strings[i].offset);
3720 : 0 : xstats[count].id = count;
3721 : 0 : count++;
3722 : : }
3723 : :
3724 : : /* Get stats from i40e_mbuf_stats struct */
3725 [ # # ]: 0 : for (i = 0; i < I40E_NB_MBUF_XSTATS; i++) {
3726 : 0 : xstats[count].value = *(uint64_t *)((char *)&mbuf_stats +
3727 : : i40e_mbuf_strings[i].offset);
3728 : 0 : xstats[count].id = count;
3729 : 0 : count++;
3730 : : }
3731 : :
3732 : : /* Get individual stats from i40e_hw_port struct */
3733 [ # # ]: 0 : for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
3734 : 0 : xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
3735 : 0 : rte_i40e_hw_port_strings[i].offset);
3736 : 0 : xstats[count].id = count;
3737 : 0 : count++;
3738 : : }
3739 : :
3740 [ # # ]: 0 : for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
3741 [ # # ]: 0 : for (prio = 0; prio < 8; prio++) {
3742 : 0 : xstats[count].value =
3743 : 0 : *(uint64_t *)(((char *)hw_stats) +
3744 : 0 : rte_i40e_rxq_prio_strings[i].offset +
3745 : 0 : (sizeof(uint64_t) * prio));
3746 : 0 : xstats[count].id = count;
3747 : 0 : count++;
3748 : : }
3749 : : }
3750 : :
3751 [ # # ]: 0 : for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
3752 [ # # ]: 0 : for (prio = 0; prio < 8; prio++) {
3753 : 0 : xstats[count].value =
3754 : 0 : *(uint64_t *)(((char *)hw_stats) +
3755 : 0 : rte_i40e_txq_prio_strings[i].offset +
3756 : 0 : (sizeof(uint64_t) * prio));
3757 : 0 : xstats[count].id = count;
3758 : 0 : count++;
3759 : : }
3760 : : }
3761 : :
3762 : 0 : return count;
3763 : : }
3764 : :
3765 : : static int
3766 : 0 : i40e_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
3767 : : {
3768 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3769 : : u32 full_ver;
3770 : : u8 ver, patch;
3771 : : u16 build;
3772 : : int ret;
3773 : :
3774 : 0 : full_ver = hw->nvm.oem_ver;
3775 : 0 : ver = (u8)(full_ver >> 24);
3776 : 0 : build = (u16)((full_ver >> 8) & 0xffff);
3777 : : patch = (u8)(full_ver & 0xff);
3778 : :
3779 : 0 : ret = snprintf(fw_version, fw_size,
3780 : : "%d.%d%d 0x%08x %d.%d.%d",
3781 : : ((hw->nvm.version >> 12) & 0xf),
3782 : : ((hw->nvm.version >> 4) & 0xff),
3783 [ # # ]: 0 : (hw->nvm.version & 0xf), hw->nvm.eetrack,
3784 : : ver, build, patch);
3785 [ # # ]: 0 : if (ret < 0)
3786 : : return -EINVAL;
3787 : :
3788 : 0 : ret += 1; /* add the size of '\0' */
3789 [ # # ]: 0 : if (fw_size < (size_t)ret)
3790 : : return ret;
3791 : : else
3792 : 0 : return 0;
3793 : : }
3794 : :
3795 : : /*
3796 : : * When using NVM 6.01(for X710 XL710 XXV710)/3.33(for X722) or later,
3797 : : * the Rx data path does not hang if the FW LLDP is stopped.
3798 : : * return true if lldp need to stop
3799 : : * return false if we cannot disable the LLDP to avoid Rx data path blocking.
3800 : : */
3801 : : static bool
3802 : 0 : i40e_need_stop_lldp(struct rte_eth_dev *dev)
3803 : : {
3804 : : double nvm_ver;
3805 : 0 : char ver_str[64] = {0};
3806 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3807 : :
3808 : 0 : i40e_fw_version_get(dev, ver_str, 64);
3809 : : nvm_ver = atof(ver_str);
3810 [ # # ]: 0 : if ((hw->mac.type == I40E_MAC_X722 ||
3811 : 0 : hw->mac.type == I40E_MAC_X722_VF) &&
3812 [ # # ]: 0 : ((uint32_t)(nvm_ver * 1000) >= (uint32_t)(3.33 * 1000)))
3813 : : return true;
3814 [ # # ]: 0 : else if ((uint32_t)(nvm_ver * 1000) >= (uint32_t)(6.01 * 1000))
3815 : 0 : return true;
3816 : :
3817 : : return false;
3818 : : }
3819 : :
3820 : : static int
3821 : 0 : i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
3822 : : {
3823 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3824 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3825 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
3826 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
3827 : :
3828 : 0 : dev_info->max_rx_queues = vsi->nb_qps;
3829 : 0 : dev_info->max_tx_queues = vsi->nb_qps;
3830 : 0 : dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
3831 : 0 : dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
3832 : 0 : dev_info->max_mac_addrs = vsi->max_macaddrs;
3833 : 0 : dev_info->max_vfs = pci_dev->max_vfs;
3834 : 0 : dev_info->max_mtu = dev_info->max_rx_pktlen - I40E_ETH_OVERHEAD;
3835 : 0 : dev_info->min_mtu = RTE_ETHER_MIN_MTU;
3836 : 0 : dev_info->rx_queue_offload_capa = 0;
3837 : 0 : dev_info->rx_offload_capa =
3838 : : RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
3839 : : RTE_ETH_RX_OFFLOAD_QINQ_STRIP |
3840 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
3841 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
3842 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
3843 : : RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
3844 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC |
3845 : : RTE_ETH_RX_OFFLOAD_SCATTER |
3846 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND |
3847 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
3848 : : RTE_ETH_RX_OFFLOAD_RSS_HASH;
3849 : :
3850 : 0 : dev_info->tx_queue_offload_capa = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
3851 : 0 : dev_info->tx_offload_capa =
3852 : : RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
3853 : : RTE_ETH_TX_OFFLOAD_QINQ_INSERT |
3854 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
3855 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
3856 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
3857 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
3858 : : RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
3859 : : RTE_ETH_TX_OFFLOAD_TCP_TSO |
3860 : : RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
3861 : : RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
3862 : : RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
3863 : : RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
3864 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
3865 : : RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM |
3866 : : dev_info->tx_queue_offload_capa;
3867 : 0 : dev_info->dev_capa =
3868 : : RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
3869 : : RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
3870 : : dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
3871 : :
3872 : 0 : dev_info->hash_key_size = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
3873 : : sizeof(uint32_t);
3874 : 0 : dev_info->reta_size = pf->hash_lut_size;
3875 : 0 : dev_info->flow_type_rss_offloads = pf->adapter->flow_types_mask;
3876 : :
3877 : 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
3878 : : .rx_thresh = {
3879 : : .pthresh = I40E_DEFAULT_RX_PTHRESH,
3880 : : .hthresh = I40E_DEFAULT_RX_HTHRESH,
3881 : : .wthresh = I40E_DEFAULT_RX_WTHRESH,
3882 : : },
3883 : : .rx_free_thresh = I40E_DEFAULT_RX_FREE_THRESH,
3884 : : .rx_drop_en = 0,
3885 : : .offloads = 0,
3886 : : };
3887 : :
3888 : 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
3889 : : .tx_thresh = {
3890 : : .pthresh = I40E_DEFAULT_TX_PTHRESH,
3891 : : .hthresh = I40E_DEFAULT_TX_HTHRESH,
3892 : : .wthresh = I40E_DEFAULT_TX_WTHRESH,
3893 : : },
3894 : : .tx_free_thresh = I40E_DEFAULT_TX_FREE_THRESH,
3895 : : .tx_rs_thresh = I40E_DEFAULT_TX_RSBIT_THRESH,
3896 : : .offloads = 0,
3897 : : };
3898 : :
3899 : 0 : dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
3900 : : .nb_max = I40E_MAX_RING_DESC,
3901 : : .nb_min = I40E_MIN_RING_DESC,
3902 : : .nb_align = I40E_ALIGN_RING_DESC,
3903 : : };
3904 : :
3905 : 0 : dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
3906 : : .nb_max = I40E_MAX_RING_DESC,
3907 : : .nb_min = I40E_MIN_RING_DESC,
3908 : : .nb_align = I40E_ALIGN_RING_DESC,
3909 : : .nb_seg_max = I40E_TX_MAX_SEG,
3910 : : .nb_mtu_seg_max = I40E_TX_MAX_MTU_SEG,
3911 : : };
3912 : :
3913 [ # # ]: 0 : if (pf->flags & I40E_FLAG_VMDQ) {
3914 : 0 : dev_info->max_vmdq_pools = pf->max_nb_vmdq_vsi;
3915 : 0 : dev_info->vmdq_queue_base = dev_info->max_rx_queues;
3916 : 0 : dev_info->vmdq_queue_num = pf->vmdq_nb_qps *
3917 : : pf->max_nb_vmdq_vsi;
3918 : 0 : dev_info->vmdq_pool_base = I40E_VMDQ_POOL_BASE;
3919 : 0 : dev_info->max_rx_queues += dev_info->vmdq_queue_num;
3920 : 0 : dev_info->max_tx_queues += dev_info->vmdq_queue_num;
3921 : : }
3922 : :
3923 [ # # ]: 0 : if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
3924 : : /* For XL710 */
3925 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_40G;
3926 : 0 : dev_info->default_rxportconf.nb_queues = 2;
3927 : 0 : dev_info->default_txportconf.nb_queues = 2;
3928 [ # # ]: 0 : if (dev->data->nb_rx_queues == 1)
3929 : 0 : dev_info->default_rxportconf.ring_size = 2048;
3930 : : else
3931 : 0 : dev_info->default_rxportconf.ring_size = 1024;
3932 [ # # ]: 0 : if (dev->data->nb_tx_queues == 1)
3933 : 0 : dev_info->default_txportconf.ring_size = 1024;
3934 : : else
3935 : 0 : dev_info->default_txportconf.ring_size = 512;
3936 : :
3937 [ # # ]: 0 : } else if (I40E_PHY_TYPE_SUPPORT_25G(hw->phy.phy_types)) {
3938 : : /* For XXV710 */
3939 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_25G;
3940 : 0 : dev_info->default_rxportconf.nb_queues = 1;
3941 : 0 : dev_info->default_txportconf.nb_queues = 1;
3942 : 0 : dev_info->default_rxportconf.ring_size = 256;
3943 : 0 : dev_info->default_txportconf.ring_size = 256;
3944 : : } else {
3945 : : /* For X710 */
3946 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_10G;
3947 : 0 : dev_info->default_rxportconf.nb_queues = 1;
3948 : 0 : dev_info->default_txportconf.nb_queues = 1;
3949 [ # # ]: 0 : if (dev->data->dev_conf.link_speeds & RTE_ETH_LINK_SPEED_10G) {
3950 : 0 : dev_info->default_rxportconf.ring_size = 512;
3951 : 0 : dev_info->default_txportconf.ring_size = 256;
3952 : : } else {
3953 : 0 : dev_info->default_rxportconf.ring_size = 256;
3954 : 0 : dev_info->default_txportconf.ring_size = 256;
3955 : : }
3956 : : }
3957 : 0 : dev_info->default_rxportconf.burst_size = 32;
3958 : 0 : dev_info->default_txportconf.burst_size = 32;
3959 : :
3960 : 0 : return 0;
3961 : : }
3962 : :
3963 : : static int
3964 : 0 : i40e_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
3965 : : {
3966 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3967 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
3968 : 0 : PMD_INIT_FUNC_TRACE();
3969 : :
3970 [ # # ]: 0 : if (on)
3971 : 0 : return i40e_vsi_add_vlan(vsi, vlan_id);
3972 : : else
3973 : 0 : return i40e_vsi_delete_vlan(vsi, vlan_id);
3974 : : }
3975 : :
3976 : : static int
3977 : 0 : i40e_vlan_tpid_set_by_registers(struct rte_eth_dev *dev,
3978 : : enum rte_vlan_type vlan_type,
3979 : : uint16_t tpid, int qinq)
3980 : : {
3981 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3982 : 0 : uint64_t reg_r = 0;
3983 : : uint64_t reg_w = 0;
3984 : : uint16_t reg_id = 3;
3985 : : int ret;
3986 : :
3987 [ # # ]: 0 : if (qinq) {
3988 [ # # ]: 0 : if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
3989 : : reg_id = 2;
3990 : : }
3991 : :
3992 : 0 : ret = i40e_aq_debug_read_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
3993 : : ®_r, NULL);
3994 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
3995 : 0 : PMD_DRV_LOG(ERR,
3996 : : "Fail to debug read from I40E_GL_SWT_L2TAGCTRL[%d]",
3997 : : reg_id);
3998 : 0 : return -EIO;
3999 : : }
4000 : 0 : PMD_DRV_LOG(DEBUG,
4001 : : "Debug read from I40E_GL_SWT_L2TAGCTRL[%d]: 0x%08"PRIx64,
4002 : : reg_id, reg_r);
4003 : :
4004 : 0 : reg_w = reg_r & (~(I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_MASK));
4005 : 0 : reg_w |= ((uint64_t)tpid << I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT);
4006 [ # # ]: 0 : if (reg_r == reg_w) {
4007 : 0 : PMD_DRV_LOG(DEBUG, "No need to write");
4008 : 0 : return 0;
4009 : : }
4010 : :
4011 : 0 : ret = i40e_aq_debug_write_global_register(hw,
4012 : : I40E_GL_SWT_L2TAGCTRL(reg_id),
4013 : : reg_w, NULL);
4014 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
4015 : 0 : PMD_DRV_LOG(ERR,
4016 : : "Fail to debug write to I40E_GL_SWT_L2TAGCTRL[%d]",
4017 : : reg_id);
4018 : 0 : return -EIO;
4019 : : }
4020 : 0 : PMD_DRV_LOG(DEBUG,
4021 : : "Global register 0x%08x is changed with value 0x%08x",
4022 : : I40E_GL_SWT_L2TAGCTRL(reg_id), (uint32_t)reg_w);
4023 : :
4024 : 0 : return 0;
4025 : : }
4026 : :
4027 : : static int
4028 : 0 : i40e_vlan_tpid_set(struct rte_eth_dev *dev,
4029 : : enum rte_vlan_type vlan_type,
4030 : : uint16_t tpid)
4031 : : {
4032 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4033 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4034 : 0 : int qinq = dev->data->dev_conf.rxmode.offloads &
4035 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
4036 : : u16 sw_flags = 0, valid_flags = 0;
4037 : : int ret = 0;
4038 : :
4039 [ # # ]: 0 : if ((vlan_type != RTE_ETH_VLAN_TYPE_INNER &&
4040 : 0 : vlan_type != RTE_ETH_VLAN_TYPE_OUTER) ||
4041 [ # # ]: 0 : (!qinq && vlan_type == RTE_ETH_VLAN_TYPE_INNER)) {
4042 : 0 : PMD_DRV_LOG(ERR,
4043 : : "Unsupported vlan type.");
4044 : 0 : return -EINVAL;
4045 : : }
4046 : :
4047 [ # # ]: 0 : if (pf->support_multi_driver) {
4048 : 0 : PMD_DRV_LOG(ERR, "Setting TPID is not supported.");
4049 : 0 : return -ENOTSUP;
4050 : : }
4051 : :
4052 : : /* 802.1ad frames ability is added in NVM API 1.7*/
4053 [ # # ]: 0 : if (hw->flags & I40E_HW_FLAG_802_1AD_CAPABLE) {
4054 [ # # ]: 0 : if (qinq) {
4055 [ # # ]: 0 : if (pf->fw8_3gt) {
4056 : : sw_flags = I40E_AQ_SET_SWITCH_CFG_OUTER_VLAN;
4057 : : valid_flags = I40E_AQ_SET_SWITCH_CFG_OUTER_VLAN;
4058 : : }
4059 [ # # ]: 0 : if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
4060 : 0 : hw->first_tag = rte_cpu_to_le_16(tpid);
4061 : : else if (vlan_type == RTE_ETH_VLAN_TYPE_INNER)
4062 : 0 : hw->second_tag = rte_cpu_to_le_16(tpid);
4063 : : } else {
4064 [ # # ]: 0 : if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
4065 : 0 : hw->second_tag = rte_cpu_to_le_16(tpid);
4066 : : }
4067 : 0 : ret = i40e_aq_set_switch_config(hw, sw_flags,
4068 : : valid_flags, 0, NULL);
4069 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
4070 : 0 : PMD_DRV_LOG(ERR,
4071 : : "Set switch config failed aq_err: %d",
4072 : : hw->aq.asq_last_status);
4073 : : ret = -EIO;
4074 : : }
4075 : : } else
4076 : : /* If NVM API < 1.7, keep the register setting */
4077 : 0 : ret = i40e_vlan_tpid_set_by_registers(dev, vlan_type,
4078 : : tpid, qinq);
4079 : :
4080 : : return ret;
4081 : : }
4082 : :
4083 : : /* Configure outer vlan stripping on or off in QinQ mode */
4084 : : static int
4085 : 0 : i40e_vsi_config_outer_vlan_stripping(struct i40e_vsi *vsi, bool on)
4086 : : {
4087 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4088 : : int ret = I40E_SUCCESS;
4089 : : uint32_t reg;
4090 : :
4091 [ # # ]: 0 : if (vsi->vsi_id >= I40E_MAX_NUM_VSIS) {
4092 : 0 : PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
4093 : 0 : return -EINVAL;
4094 : : }
4095 : :
4096 : : /* Configure for outer VLAN RX stripping */
4097 : 0 : reg = I40E_READ_REG(hw, I40E_VSI_TSR(vsi->vsi_id));
4098 : :
4099 [ # # ]: 0 : if (on)
4100 : 0 : reg |= I40E_VSI_TSR_QINQ_STRIP;
4101 : : else
4102 : 0 : reg &= ~I40E_VSI_TSR_QINQ_STRIP;
4103 : :
4104 : 0 : ret = i40e_aq_debug_write_register(hw,
4105 : 0 : I40E_VSI_TSR(vsi->vsi_id),
4106 : : reg, NULL);
4107 [ # # ]: 0 : if (ret < 0) {
4108 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI_TSR[%d]",
4109 : : vsi->vsi_id);
4110 : 0 : return I40E_ERR_CONFIG;
4111 : : }
4112 : :
4113 : : return ret;
4114 : : }
4115 : :
4116 : : static int
4117 : 0 : i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask)
4118 : : {
4119 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4120 : : struct i40e_mac_filter_info *mac_filter;
4121 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
4122 : : struct rte_eth_rxmode *rxmode;
4123 : : struct i40e_mac_filter *f;
4124 : : int i, num;
4125 : : void *temp;
4126 : : int ret;
4127 : :
4128 : : rxmode = &dev->data->dev_conf.rxmode;
4129 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_FILTER_MASK) {
4130 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
4131 : 0 : i40e_vsi_config_vlan_filter(vsi, TRUE);
4132 : : else
4133 : 0 : i40e_vsi_config_vlan_filter(vsi, FALSE);
4134 : : }
4135 : :
4136 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
4137 : : /* Enable or disable VLAN stripping */
4138 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
4139 : 0 : i40e_vsi_config_vlan_stripping(vsi, TRUE);
4140 : : else
4141 : 0 : i40e_vsi_config_vlan_stripping(vsi, FALSE);
4142 : : }
4143 : :
4144 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_EXTEND_MASK) {
4145 : : i = 0;
4146 : 0 : num = vsi->mac_num;
4147 : 0 : mac_filter = rte_zmalloc("mac_filter_info_data",
4148 : : num * sizeof(*mac_filter), 0);
4149 [ # # ]: 0 : if (mac_filter == NULL) {
4150 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
4151 : 0 : return I40E_ERR_NO_MEMORY;
4152 : : }
4153 : :
4154 : : /*
4155 : : * Outer VLAN processing is supported after firmware v8.4, kernel driver
4156 : : * also change the default behavior to support this feature. To align with
4157 : : * kernel driver, set switch config in 'i40e_vlan_tpie_set' to support for
4158 : : * outer VLAN processing. But it is forbidden for firmware to change the
4159 : : * Inner/Outer VLAN configuration while there are MAC/VLAN filters in the
4160 : : * switch table. Therefore, we need to clear the MAC table before setting
4161 : : * config, and then restore the MAC table after setting. This feature is
4162 : : * recommended to be used in firmware v8.6.
4163 : : */
4164 : : /* Remove all existing mac */
4165 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
4166 : 0 : mac_filter[i] = f->mac_info;
4167 : 0 : ret = i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
4168 [ # # ]: 0 : if (ret)
4169 : 0 : PMD_DRV_LOG(ERR, "i40e vsi delete mac fail.");
4170 : 0 : i++;
4171 : : }
4172 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND) {
4173 : : i40e_vsi_config_double_vlan(vsi, TRUE);
4174 : : /* Set global registers with default ethertype. */
4175 : 0 : i40e_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_OUTER,
4176 : : RTE_ETHER_TYPE_VLAN);
4177 : 0 : i40e_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_INNER,
4178 : : RTE_ETHER_TYPE_VLAN);
4179 : : } else {
4180 : : i40e_vsi_config_double_vlan(vsi, FALSE);
4181 : : }
4182 : : /* Restore all mac */
4183 [ # # ]: 0 : for (i = 0; i < num; i++) {
4184 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter[i]);
4185 [ # # ]: 0 : if (ret)
4186 : 0 : PMD_DRV_LOG(ERR, "i40e vsi add mac fail.");
4187 : : }
4188 : 0 : rte_free(mac_filter);
4189 : : }
4190 : :
4191 [ # # ]: 0 : if (mask & RTE_ETH_QINQ_STRIP_MASK) {
4192 : : /* Enable or disable outer VLAN stripping */
4193 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP)
4194 : 0 : i40e_vsi_config_outer_vlan_stripping(vsi, TRUE);
4195 : : else
4196 : 0 : i40e_vsi_config_outer_vlan_stripping(vsi, FALSE);
4197 : : }
4198 : :
4199 : : return 0;
4200 : : }
4201 : :
4202 : : static void
4203 : 0 : i40e_vlan_strip_queue_set(__rte_unused struct rte_eth_dev *dev,
4204 : : __rte_unused uint16_t queue,
4205 : : __rte_unused int on)
4206 : : {
4207 : 0 : PMD_INIT_FUNC_TRACE();
4208 : 0 : }
4209 : :
4210 : : static int
4211 : 0 : i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
4212 : : {
4213 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4214 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
4215 [ # # ]: 0 : struct rte_eth_dev_data *data = I40E_VSI_TO_DEV_DATA(vsi);
4216 : : struct i40e_vsi_vlan_pvid_info info;
4217 : :
4218 : : memset(&info, 0, sizeof(info));
4219 : 0 : info.on = on;
4220 [ # # ]: 0 : if (info.on)
4221 : 0 : info.config.pvid = pvid;
4222 : : else {
4223 : 0 : info.config.reject.tagged =
4224 : 0 : data->dev_conf.txmode.hw_vlan_reject_tagged;
4225 : 0 : info.config.reject.untagged =
4226 : 0 : data->dev_conf.txmode.hw_vlan_reject_untagged;
4227 : : }
4228 : :
4229 : 0 : return i40e_vsi_vlan_pvid_set(vsi, &info);
4230 : : }
4231 : :
4232 : : static int
4233 : 0 : i40e_dev_led_on(struct rte_eth_dev *dev)
4234 : : {
4235 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4236 : 0 : uint32_t mode = i40e_led_get(hw);
4237 : :
4238 [ # # ]: 0 : if (mode == 0)
4239 : 0 : i40e_led_set(hw, 0xf, true); /* 0xf means led always true */
4240 : :
4241 : 0 : return 0;
4242 : : }
4243 : :
4244 : : static int
4245 : 0 : i40e_dev_led_off(struct rte_eth_dev *dev)
4246 : : {
4247 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4248 : 0 : uint32_t mode = i40e_led_get(hw);
4249 : :
4250 [ # # ]: 0 : if (mode != 0)
4251 : 0 : i40e_led_set(hw, 0, false);
4252 : :
4253 : 0 : return 0;
4254 : : }
4255 : :
4256 : : static int
4257 : 0 : i40e_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
4258 : : {
4259 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4260 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4261 : :
4262 : 0 : fc_conf->pause_time = pf->fc_conf.pause_time;
4263 : :
4264 : : /* read out from register, in case they are modified by other port */
4265 : 0 : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] =
4266 : 0 : I40E_READ_REG(hw, I40E_GLRPB_GHW) >> I40E_KILOSHIFT;
4267 : 0 : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] =
4268 : 0 : I40E_READ_REG(hw, I40E_GLRPB_GLW) >> I40E_KILOSHIFT;
4269 : :
4270 : 0 : fc_conf->high_water = pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS];
4271 : 0 : fc_conf->low_water = pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS];
4272 : :
4273 : : /* Return current mode according to actual setting*/
4274 [ # # # # ]: 0 : switch (hw->fc.current_mode) {
4275 : 0 : case I40E_FC_FULL:
4276 : 0 : fc_conf->mode = RTE_ETH_FC_FULL;
4277 : 0 : break;
4278 : 0 : case I40E_FC_TX_PAUSE:
4279 : 0 : fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
4280 : 0 : break;
4281 : 0 : case I40E_FC_RX_PAUSE:
4282 : 0 : fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
4283 : 0 : break;
4284 : 0 : case I40E_FC_NONE:
4285 : : default:
4286 : 0 : fc_conf->mode = RTE_ETH_FC_NONE;
4287 : : };
4288 : :
4289 : 0 : return 0;
4290 : : }
4291 : :
4292 : : static int
4293 : 0 : i40e_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
4294 : : {
4295 : : uint32_t mflcn_reg, fctrl_reg, reg;
4296 : : uint32_t max_high_water;
4297 : : uint8_t i, aq_failure;
4298 : : int err;
4299 : : struct i40e_hw *hw;
4300 : : struct i40e_pf *pf;
4301 : 0 : enum i40e_fc_mode rte_fcmode_2_i40e_fcmode[] = {
4302 : : [RTE_ETH_FC_NONE] = I40E_FC_NONE,
4303 : : [RTE_ETH_FC_RX_PAUSE] = I40E_FC_RX_PAUSE,
4304 : : [RTE_ETH_FC_TX_PAUSE] = I40E_FC_TX_PAUSE,
4305 : : [RTE_ETH_FC_FULL] = I40E_FC_FULL
4306 : : };
4307 : :
4308 : : /* high_water field in the rte_eth_fc_conf using the kilobytes unit */
4309 : :
4310 : : max_high_water = I40E_RXPBSIZE >> I40E_KILOSHIFT;
4311 [ # # ]: 0 : if ((fc_conf->high_water > max_high_water) ||
4312 [ # # ]: 0 : (fc_conf->high_water < fc_conf->low_water)) {
4313 : 0 : PMD_INIT_LOG(ERR,
4314 : : "Invalid high/low water setup value in KB, High_water must be <= %d.",
4315 : : max_high_water);
4316 : 0 : return -EINVAL;
4317 : : }
4318 : :
4319 : 0 : hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4320 : : pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4321 : 0 : hw->fc.requested_mode = rte_fcmode_2_i40e_fcmode[fc_conf->mode];
4322 : :
4323 : 0 : pf->fc_conf.pause_time = fc_conf->pause_time;
4324 : 0 : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->high_water;
4325 : 0 : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->low_water;
4326 : :
4327 : 0 : PMD_INIT_FUNC_TRACE();
4328 : :
4329 : : /* All the link flow control related enable/disable register
4330 : : * configuration is handle by the F/W
4331 : : */
4332 : 0 : err = i40e_set_fc(hw, &aq_failure, true);
4333 [ # # ]: 0 : if (err < 0)
4334 : : return -ENOSYS;
4335 : :
4336 [ # # ]: 0 : if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
4337 : : /* Configure flow control refresh threshold,
4338 : : * the value for stat_tx_pause_refresh_timer[8]
4339 : : * is used for global pause operation.
4340 : : */
4341 : :
4342 : 0 : I40E_WRITE_REG(hw,
4343 : : I40E_PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER(8),
4344 : : pf->fc_conf.pause_time);
4345 : :
4346 : : /* configure the timer value included in transmitted pause
4347 : : * frame,
4348 : : * the value for stat_tx_pause_quanta[8] is used for global
4349 : : * pause operation
4350 : : */
4351 : 0 : I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA(8),
4352 : : pf->fc_conf.pause_time);
4353 : :
4354 : 0 : fctrl_reg = I40E_READ_REG(hw,
4355 : : I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL);
4356 : :
4357 [ # # ]: 0 : if (fc_conf->mac_ctrl_frame_fwd != 0)
4358 : 0 : fctrl_reg |= I40E_PRTMAC_FWD_CTRL;
4359 : : else
4360 : 0 : fctrl_reg &= ~I40E_PRTMAC_FWD_CTRL;
4361 : :
4362 : 0 : I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL,
4363 : : fctrl_reg);
4364 : : } else {
4365 : : /* Configure pause time (2 TCs per register) */
4366 : 0 : reg = (uint32_t)pf->fc_conf.pause_time * (uint32_t)0x00010001;
4367 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS / 2; i++)
4368 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_FCTTVN(i), reg);
4369 : :
4370 : : /* Configure flow control refresh threshold value */
4371 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_FCRTV,
4372 : : pf->fc_conf.pause_time / 2);
4373 : :
4374 : 0 : mflcn_reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
4375 : :
4376 : : /* set or clear MFLCN.PMCF & MFLCN.DPF bits
4377 : : *depending on configuration
4378 : : */
4379 [ # # ]: 0 : if (fc_conf->mac_ctrl_frame_fwd != 0) {
4380 : : mflcn_reg |= I40E_PRTDCB_MFLCN_PMCF_MASK;
4381 : 0 : mflcn_reg &= ~I40E_PRTDCB_MFLCN_DPF_MASK;
4382 : : } else {
4383 : 0 : mflcn_reg &= ~I40E_PRTDCB_MFLCN_PMCF_MASK;
4384 : 0 : mflcn_reg |= I40E_PRTDCB_MFLCN_DPF_MASK;
4385 : : }
4386 : :
4387 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, mflcn_reg);
4388 : : }
4389 : :
4390 [ # # ]: 0 : if (!pf->support_multi_driver) {
4391 : : /* config water marker both based on the packets and bytes */
4392 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_PHW,
4393 : : (pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
4394 : : << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
4395 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_PLW,
4396 : : (pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
4397 : : << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
4398 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_GHW,
4399 : : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
4400 : : << I40E_KILOSHIFT);
4401 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_GLW,
4402 : : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
4403 : : << I40E_KILOSHIFT);
4404 : : } else {
4405 : 0 : PMD_DRV_LOG(ERR,
4406 : : "Water marker configuration is not supported.");
4407 : : }
4408 : :
4409 : 0 : I40E_WRITE_FLUSH(hw);
4410 : :
4411 : 0 : return 0;
4412 : : }
4413 : :
4414 : : static int
4415 : 0 : i40e_priority_flow_ctrl_set(__rte_unused struct rte_eth_dev *dev,
4416 : : __rte_unused struct rte_eth_pfc_conf *pfc_conf)
4417 : : {
4418 : 0 : PMD_INIT_FUNC_TRACE();
4419 : :
4420 : 0 : return -ENOSYS;
4421 : : }
4422 : :
4423 : : /* Add a MAC address, and update filters */
4424 : : static int
4425 : 0 : i40e_macaddr_add(struct rte_eth_dev *dev,
4426 : : struct rte_ether_addr *mac_addr,
4427 : : __rte_unused uint32_t index,
4428 : : uint32_t pool)
4429 : : {
4430 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4431 : : struct i40e_mac_filter_info mac_filter;
4432 : : struct i40e_vsi *vsi;
4433 : : struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
4434 : : int ret;
4435 : :
4436 : : /* If VMDQ not enabled or configured, return */
4437 [ # # # # ]: 0 : if (pool != 0 && (!(pf->flags & I40E_FLAG_VMDQ) ||
4438 [ # # ]: 0 : !pf->nb_cfg_vmdq_vsi)) {
4439 [ # # ]: 0 : PMD_DRV_LOG(ERR, "VMDQ not %s, can't set mac to pool %u",
4440 : : pf->flags & I40E_FLAG_VMDQ ? "configured" : "enabled",
4441 : : pool);
4442 : 0 : return -ENOTSUP;
4443 : : }
4444 : :
4445 [ # # ]: 0 : if (pool > pf->nb_cfg_vmdq_vsi) {
4446 : 0 : PMD_DRV_LOG(ERR, "Pool number %u invalid. Max pool is %u",
4447 : : pool, pf->nb_cfg_vmdq_vsi);
4448 : 0 : return -EINVAL;
4449 : : }
4450 : :
4451 : : rte_memcpy(&mac_filter.mac_addr, mac_addr, RTE_ETHER_ADDR_LEN);
4452 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
4453 : 0 : mac_filter.filter_type = I40E_MACVLAN_PERFECT_MATCH;
4454 : : else
4455 : 0 : mac_filter.filter_type = I40E_MAC_PERFECT_MATCH;
4456 : :
4457 [ # # ]: 0 : if (pool == 0)
4458 : 0 : vsi = pf->main_vsi;
4459 : : else
4460 : 0 : vsi = pf->vmdq[pool - 1].vsi;
4461 : :
4462 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter);
4463 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
4464 : 0 : PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
4465 : 0 : return -ENODEV;
4466 : : }
4467 : : return 0;
4468 : : }
4469 : :
4470 : : /* Remove a MAC address, and update filters */
4471 : : static void
4472 : 0 : i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
4473 : : {
4474 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4475 : : struct i40e_vsi *vsi;
4476 : : struct rte_eth_dev_data *data = dev->data;
4477 : : struct rte_ether_addr *macaddr;
4478 : : int ret;
4479 : : uint32_t i;
4480 : : uint64_t pool_sel;
4481 : :
4482 : 0 : macaddr = &(data->mac_addrs[index]);
4483 : :
4484 : 0 : pool_sel = dev->data->mac_pool_sel[index];
4485 : :
4486 [ # # ]: 0 : for (i = 0; i < sizeof(pool_sel) * CHAR_BIT; i++) {
4487 [ # # ]: 0 : if (pool_sel & (1ULL << i)) {
4488 [ # # ]: 0 : if (i == 0)
4489 : 0 : vsi = pf->main_vsi;
4490 : : else {
4491 : : /* No VMDQ pool enabled or configured */
4492 [ # # ]: 0 : if (!(pf->flags & I40E_FLAG_VMDQ) ||
4493 [ # # ]: 0 : (i > pf->nb_cfg_vmdq_vsi)) {
4494 : 0 : PMD_DRV_LOG(ERR,
4495 : : "No VMDQ pool enabled/configured");
4496 : 0 : return;
4497 : : }
4498 : 0 : vsi = pf->vmdq[i - 1].vsi;
4499 : : }
4500 : 0 : ret = i40e_vsi_delete_mac(vsi, macaddr);
4501 : :
4502 [ # # ]: 0 : if (ret) {
4503 : 0 : PMD_DRV_LOG(ERR, "Failed to remove MACVLAN filter");
4504 : 0 : return;
4505 : : }
4506 : : }
4507 : : }
4508 : : }
4509 : :
4510 : : static int
4511 : 0 : i40e_get_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4512 : : {
4513 : 0 : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
4514 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4515 : : uint32_t reg;
4516 : : int ret;
4517 : :
4518 [ # # ]: 0 : if (!lut)
4519 : : return -EINVAL;
4520 : :
4521 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
4522 : 0 : ret = i40e_aq_get_rss_lut(hw, vsi->vsi_id,
4523 : 0 : vsi->type != I40E_VSI_SRIOV,
4524 : : lut, lut_size);
4525 [ # # ]: 0 : if (ret) {
4526 : 0 : PMD_DRV_LOG(ERR, "Failed to get RSS lookup table");
4527 : 0 : return ret;
4528 : : }
4529 : : } else {
4530 : : uint32_t *lut_dw = (uint32_t *)lut;
4531 : 0 : uint16_t i, lut_size_dw = lut_size / 4;
4532 : :
4533 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
4534 [ # # ]: 0 : for (i = 0; i <= lut_size_dw; i++) {
4535 : 0 : reg = I40E_VFQF_HLUT1(i, vsi->user_param);
4536 : 0 : lut_dw[i] = i40e_read_rx_ctl(hw, reg);
4537 : : }
4538 : : } else {
4539 [ # # ]: 0 : for (i = 0; i < lut_size_dw; i++)
4540 : 0 : lut_dw[i] = I40E_READ_REG(hw,
4541 : : I40E_PFQF_HLUT(i));
4542 : : }
4543 : : }
4544 : :
4545 : : return 0;
4546 : : }
4547 : :
4548 : : int
4549 : 0 : i40e_set_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4550 : : {
4551 : : struct i40e_pf *pf;
4552 : : struct i40e_hw *hw;
4553 : :
4554 [ # # ]: 0 : if (!vsi || !lut)
4555 : : return -EINVAL;
4556 : :
4557 : 0 : pf = I40E_VSI_TO_PF(vsi);
4558 : 0 : hw = I40E_VSI_TO_HW(vsi);
4559 : :
4560 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
4561 : : enum i40e_status_code status;
4562 : :
4563 : 0 : status = i40e_aq_set_rss_lut(hw, vsi->vsi_id,
4564 : 0 : vsi->type != I40E_VSI_SRIOV,
4565 : : lut, lut_size);
4566 [ # # ]: 0 : if (status) {
4567 : 0 : PMD_DRV_LOG(ERR,
4568 : : "Failed to update RSS lookup table, error status: %d",
4569 : : status);
4570 : 0 : return -EIO;
4571 : : }
4572 : : } else {
4573 : : uint32_t *lut_dw = (uint32_t *)lut;
4574 : 0 : uint16_t i, lut_size_dw = lut_size / 4;
4575 : :
4576 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
4577 [ # # ]: 0 : for (i = 0; i < lut_size_dw; i++)
4578 : 0 : I40E_WRITE_REG(
4579 : : hw,
4580 : : I40E_VFQF_HLUT1(i, vsi->user_param),
4581 : : lut_dw[i]);
4582 : : } else {
4583 [ # # ]: 0 : for (i = 0; i < lut_size_dw; i++)
4584 : 0 : I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i),
4585 : : lut_dw[i]);
4586 : : }
4587 : 0 : I40E_WRITE_FLUSH(hw);
4588 : : }
4589 : :
4590 : : return 0;
4591 : : }
4592 : :
4593 : : static int
4594 : 0 : i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
4595 : : struct rte_eth_rss_reta_entry64 *reta_conf,
4596 : : uint16_t reta_size)
4597 : : {
4598 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4599 : 0 : uint16_t i, lut_size = pf->hash_lut_size;
4600 : : uint16_t idx, shift;
4601 : : uint8_t *lut;
4602 : : int ret;
4603 : :
4604 : 0 : if (reta_size != lut_size ||
4605 [ # # ]: 0 : reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
4606 : 0 : PMD_DRV_LOG(ERR,
4607 : : "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)",
4608 : : reta_size, lut_size);
4609 : 0 : return -EINVAL;
4610 : : }
4611 : :
4612 : 0 : lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
4613 [ # # ]: 0 : if (!lut) {
4614 : 0 : PMD_DRV_LOG(ERR, "No memory can be allocated");
4615 : 0 : return -ENOMEM;
4616 : : }
4617 : 0 : ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
4618 [ # # ]: 0 : if (ret)
4619 : 0 : goto out;
4620 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
4621 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
4622 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
4623 [ # # ]: 0 : if (reta_conf[idx].mask & (1ULL << shift))
4624 : 0 : lut[i] = reta_conf[idx].reta[shift];
4625 : : }
4626 : 0 : ret = i40e_set_rss_lut(pf->main_vsi, lut, reta_size);
4627 : :
4628 : 0 : pf->adapter->rss_reta_updated = 1;
4629 : :
4630 : 0 : out:
4631 : 0 : rte_free(lut);
4632 : :
4633 : 0 : return ret;
4634 : : }
4635 : :
4636 : : static int
4637 : 0 : i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
4638 : : struct rte_eth_rss_reta_entry64 *reta_conf,
4639 : : uint16_t reta_size)
4640 : : {
4641 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4642 : 0 : uint16_t i, lut_size = pf->hash_lut_size;
4643 : : uint16_t idx, shift;
4644 : : uint8_t *lut;
4645 : : int ret;
4646 : :
4647 : 0 : if (reta_size != lut_size ||
4648 [ # # ]: 0 : reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
4649 : 0 : PMD_DRV_LOG(ERR,
4650 : : "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)",
4651 : : reta_size, lut_size);
4652 : 0 : return -EINVAL;
4653 : : }
4654 : :
4655 : 0 : lut = rte_zmalloc("i40e_rss_lut", reta_size, 0);
4656 [ # # ]: 0 : if (!lut) {
4657 : 0 : PMD_DRV_LOG(ERR, "No memory can be allocated");
4658 : 0 : return -ENOMEM;
4659 : : }
4660 : :
4661 : 0 : ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
4662 [ # # ]: 0 : if (ret)
4663 : 0 : goto out;
4664 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
4665 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
4666 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
4667 [ # # ]: 0 : if (reta_conf[idx].mask & (1ULL << shift))
4668 : 0 : reta_conf[idx].reta[shift] = lut[i];
4669 : : }
4670 : :
4671 : 0 : out:
4672 : 0 : rte_free(lut);
4673 : :
4674 : 0 : return ret;
4675 : : }
4676 : :
4677 : : /**
4678 : : * i40e_allocate_dma_mem_d - specific memory alloc for shared code (base driver)
4679 : : * @hw: pointer to the HW structure
4680 : : * @mem: pointer to mem struct to fill out
4681 : : * @size: size of memory requested
4682 : : * @alignment: what to align the allocation to
4683 : : **/
4684 : : enum i40e_status_code
4685 : 0 : i40e_allocate_dma_mem_d(__rte_unused struct i40e_hw *hw,
4686 : : struct i40e_dma_mem *mem,
4687 : : u64 size,
4688 : : u32 alignment)
4689 : : {
4690 : : static uint64_t i40e_dma_memzone_id;
4691 : : const struct rte_memzone *mz = NULL;
4692 : : char z_name[RTE_MEMZONE_NAMESIZE];
4693 : :
4694 [ # # ]: 0 : if (!mem)
4695 : : return I40E_ERR_PARAM;
4696 : :
4697 : 0 : snprintf(z_name, sizeof(z_name), "i40e_dma_%" PRIu64,
4698 : : __atomic_fetch_add(&i40e_dma_memzone_id, 1, __ATOMIC_RELAXED));
4699 : 0 : mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY,
4700 : : RTE_MEMZONE_IOVA_CONTIG, alignment, RTE_PGSIZE_2M);
4701 [ # # ]: 0 : if (!mz)
4702 : : return I40E_ERR_NO_MEMORY;
4703 : :
4704 : 0 : mem->size = size;
4705 : 0 : mem->va = mz->addr;
4706 : 0 : mem->pa = mz->iova;
4707 : 0 : mem->zone = (const void *)mz;
4708 : 0 : PMD_DRV_LOG(DEBUG,
4709 : : "memzone %s allocated with physical address: %"PRIu64,
4710 : : mz->name, mem->pa);
4711 : :
4712 : 0 : return I40E_SUCCESS;
4713 : : }
4714 : :
4715 : : /**
4716 : : * i40e_free_dma_mem_d - specific memory free for shared code (base driver)
4717 : : * @hw: pointer to the HW structure
4718 : : * @mem: ptr to mem struct to free
4719 : : **/
4720 : : enum i40e_status_code
4721 : 0 : i40e_free_dma_mem_d(__rte_unused struct i40e_hw *hw,
4722 : : struct i40e_dma_mem *mem)
4723 : : {
4724 [ # # ]: 0 : if (!mem)
4725 : : return I40E_ERR_PARAM;
4726 : :
4727 : 0 : PMD_DRV_LOG(DEBUG,
4728 : : "memzone %s to be freed with physical address: %"PRIu64,
4729 : : ((const struct rte_memzone *)mem->zone)->name, mem->pa);
4730 : 0 : rte_memzone_free((const struct rte_memzone *)mem->zone);
4731 : 0 : mem->zone = NULL;
4732 : 0 : mem->va = NULL;
4733 : 0 : mem->pa = (u64)0;
4734 : :
4735 : 0 : return I40E_SUCCESS;
4736 : : }
4737 : :
4738 : : /**
4739 : : * i40e_allocate_virt_mem_d - specific memory alloc for shared code (base driver)
4740 : : * @hw: pointer to the HW structure
4741 : : * @mem: pointer to mem struct to fill out
4742 : : * @size: size of memory requested
4743 : : **/
4744 : : enum i40e_status_code
4745 : 0 : i40e_allocate_virt_mem_d(__rte_unused struct i40e_hw *hw,
4746 : : struct i40e_virt_mem *mem,
4747 : : u32 size)
4748 : : {
4749 [ # # ]: 0 : if (!mem)
4750 : : return I40E_ERR_PARAM;
4751 : :
4752 : 0 : mem->size = size;
4753 : 0 : mem->va = rte_zmalloc("i40e", size, 0);
4754 : :
4755 [ # # ]: 0 : if (mem->va)
4756 : : return I40E_SUCCESS;
4757 : : else
4758 : 0 : return I40E_ERR_NO_MEMORY;
4759 : : }
4760 : :
4761 : : /**
4762 : : * i40e_free_virt_mem_d - specific memory free for shared code (base driver)
4763 : : * @hw: pointer to the HW structure
4764 : : * @mem: pointer to mem struct to free
4765 : : **/
4766 : : enum i40e_status_code
4767 : 0 : i40e_free_virt_mem_d(__rte_unused struct i40e_hw *hw,
4768 : : struct i40e_virt_mem *mem)
4769 : : {
4770 [ # # ]: 0 : if (!mem)
4771 : : return I40E_ERR_PARAM;
4772 : :
4773 : 0 : rte_free(mem->va);
4774 : 0 : mem->va = NULL;
4775 : :
4776 : 0 : return I40E_SUCCESS;
4777 : : }
4778 : :
4779 : : /**
4780 : : * Get the hardware capabilities, which will be parsed
4781 : : * and saved into struct i40e_hw.
4782 : : */
4783 : : static int
4784 : 0 : i40e_get_cap(struct i40e_hw *hw)
4785 : : {
4786 : : struct i40e_aqc_list_capabilities_element_resp *buf;
4787 : 0 : uint16_t len, size = 0;
4788 : : int ret;
4789 : :
4790 : : /* Calculate a huge enough buff for saving response data temporarily */
4791 : : len = sizeof(struct i40e_aqc_list_capabilities_element_resp) *
4792 : : I40E_MAX_CAP_ELE_NUM;
4793 : 0 : buf = rte_zmalloc("i40e", len, 0);
4794 [ # # ]: 0 : if (!buf) {
4795 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory");
4796 : 0 : return I40E_ERR_NO_MEMORY;
4797 : : }
4798 : :
4799 : : /* Get, parse the capabilities and save it to hw */
4800 : 0 : ret = i40e_aq_discover_capabilities(hw, buf, len, &size,
4801 : : i40e_aqc_opc_list_func_capabilities, NULL);
4802 [ # # ]: 0 : if (ret != I40E_SUCCESS)
4803 : 0 : PMD_DRV_LOG(ERR, "Failed to discover capabilities");
4804 : :
4805 : : /* Free the temporary buffer after being used */
4806 : 0 : rte_free(buf);
4807 : :
4808 : 0 : return ret;
4809 : : }
4810 : :
4811 : : #define RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF 4
4812 : :
4813 : 0 : static int i40e_pf_parse_vf_queue_number_handler(const char *key,
4814 : : const char *value,
4815 : : void *opaque)
4816 : : {
4817 : : struct i40e_pf *pf;
4818 : : unsigned long num;
4819 : : char *end;
4820 : :
4821 : : pf = (struct i40e_pf *)opaque;
4822 : : RTE_SET_USED(key);
4823 : :
4824 : 0 : errno = 0;
4825 : 0 : num = strtoul(value, &end, 0);
4826 [ # # # # : 0 : if (errno != 0 || end == value || *end != 0) {
# # ]
4827 : 0 : PMD_DRV_LOG(WARNING, "Wrong VF queue number = %s, Now it is "
4828 : : "kept the value = %hu", value, pf->vf_nb_qp_max);
4829 : 0 : return -(EINVAL);
4830 : : }
4831 : :
4832 [ # # # # ]: 0 : if (num <= I40E_MAX_QP_NUM_PER_VF && rte_is_power_of_2(num))
4833 : 0 : pf->vf_nb_qp_max = (uint16_t)num;
4834 : : else
4835 : : /* here return 0 to make next valid same argument work */
4836 : 0 : PMD_DRV_LOG(WARNING, "Wrong VF queue number = %lu, it must be "
4837 : : "power of 2 and equal or less than 16 !, Now it is "
4838 : : "kept the value = %hu", num, pf->vf_nb_qp_max);
4839 : :
4840 : : return 0;
4841 : : }
4842 : :
4843 : 0 : static int i40e_pf_config_vf_rxq_number(struct rte_eth_dev *dev)
4844 : : {
4845 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4846 : : struct rte_kvargs *kvlist;
4847 : : int kvargs_count;
4848 : :
4849 : : /* set default queue number per VF as 4 */
4850 : 0 : pf->vf_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF;
4851 : :
4852 [ # # ]: 0 : if (dev->device->devargs == NULL)
4853 : : return 0;
4854 : :
4855 : 0 : kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
4856 [ # # ]: 0 : if (kvlist == NULL)
4857 : : return -(EINVAL);
4858 : :
4859 : 0 : kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_QUEUE_NUM_PER_VF_ARG);
4860 [ # # ]: 0 : if (!kvargs_count) {
4861 : 0 : rte_kvargs_free(kvlist);
4862 : 0 : return 0;
4863 : : }
4864 : :
4865 [ # # ]: 0 : if (kvargs_count > 1)
4866 : 0 : PMD_DRV_LOG(WARNING, "More than one argument \"%s\" and only "
4867 : : "the first invalid or last valid one is used !",
4868 : : ETH_I40E_QUEUE_NUM_PER_VF_ARG);
4869 : :
4870 : 0 : rte_kvargs_process(kvlist, ETH_I40E_QUEUE_NUM_PER_VF_ARG,
4871 : : i40e_pf_parse_vf_queue_number_handler, pf);
4872 : :
4873 : 0 : rte_kvargs_free(kvlist);
4874 : :
4875 : 0 : return 0;
4876 : : }
4877 : :
4878 : : static int
4879 : 0 : i40e_pf_parameter_init(struct rte_eth_dev *dev)
4880 : : {
4881 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4882 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4883 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
4884 : : uint16_t qp_count = 0, vsi_count = 0;
4885 : :
4886 [ # # # # ]: 0 : if (pci_dev->max_vfs && !hw->func_caps.sr_iov_1_1) {
4887 : 0 : PMD_INIT_LOG(ERR, "HW configuration doesn't support SRIOV");
4888 : 0 : return -EINVAL;
4889 : : }
4890 : :
4891 : 0 : i40e_pf_config_vf_rxq_number(dev);
4892 : :
4893 : : /* Add the parameter init for LFC */
4894 : 0 : pf->fc_conf.pause_time = I40E_DEFAULT_PAUSE_TIME;
4895 : 0 : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_HIGH_WATER;
4896 : 0 : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_LOW_WATER;
4897 : :
4898 : 0 : pf->flags = I40E_FLAG_HEADER_SPLIT_DISABLED;
4899 : 0 : pf->max_num_vsi = hw->func_caps.num_vsis;
4900 : 0 : pf->lan_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_PF;
4901 : 0 : pf->vmdq_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
4902 : :
4903 : : /* FDir queue/VSI allocation */
4904 : 0 : pf->fdir_qp_offset = 0;
4905 [ # # ]: 0 : if (hw->func_caps.fd) {
4906 : 0 : pf->flags |= I40E_FLAG_FDIR;
4907 : 0 : pf->fdir_nb_qps = I40E_DEFAULT_QP_NUM_FDIR;
4908 : : } else {
4909 : 0 : pf->fdir_nb_qps = 0;
4910 : : }
4911 : 0 : qp_count += pf->fdir_nb_qps;
4912 : : vsi_count += 1;
4913 : :
4914 : : /* LAN queue/VSI allocation */
4915 : 0 : pf->lan_qp_offset = pf->fdir_qp_offset + pf->fdir_nb_qps;
4916 [ # # ]: 0 : if (!hw->func_caps.rss) {
4917 : 0 : pf->lan_nb_qps = 1;
4918 : : } else {
4919 : 0 : pf->flags |= I40E_FLAG_RSS;
4920 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
4921 : 0 : pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE;
4922 : 0 : pf->lan_nb_qps = pf->lan_nb_qp_max;
4923 : : }
4924 : 0 : qp_count += pf->lan_nb_qps;
4925 : : vsi_count += 1;
4926 : :
4927 : : /* VF queue/VSI allocation */
4928 : 0 : pf->vf_qp_offset = pf->lan_qp_offset + pf->lan_nb_qps;
4929 [ # # # # ]: 0 : if (hw->func_caps.sr_iov_1_1 && pci_dev->max_vfs) {
4930 : 0 : pf->flags |= I40E_FLAG_SRIOV;
4931 : 0 : pf->vf_nb_qps = pf->vf_nb_qp_max;
4932 : 0 : pf->vf_num = pci_dev->max_vfs;
4933 : 0 : PMD_DRV_LOG(DEBUG,
4934 : : "%u VF VSIs, %u queues per VF VSI, in total %u queues",
4935 : : pf->vf_num, pf->vf_nb_qps, pf->vf_nb_qps * pf->vf_num);
4936 : : } else {
4937 : 0 : pf->vf_nb_qps = 0;
4938 : 0 : pf->vf_num = 0;
4939 : : }
4940 : 0 : qp_count += pf->vf_nb_qps * pf->vf_num;
4941 : 0 : vsi_count += pf->vf_num;
4942 : :
4943 : : /* VMDq queue/VSI allocation */
4944 : 0 : pf->vmdq_qp_offset = pf->vf_qp_offset + pf->vf_nb_qps * pf->vf_num;
4945 : 0 : pf->vmdq_nb_qps = 0;
4946 : 0 : pf->max_nb_vmdq_vsi = 0;
4947 [ # # ]: 0 : if (hw->func_caps.vmdq) {
4948 [ # # ]: 0 : if (qp_count < hw->func_caps.num_tx_qp &&
4949 [ # # ]: 0 : vsi_count < hw->func_caps.num_vsis) {
4950 : 0 : pf->max_nb_vmdq_vsi = (hw->func_caps.num_tx_qp -
4951 : 0 : qp_count) / pf->vmdq_nb_qp_max;
4952 : :
4953 : : /* Limit the maximum number of VMDq vsi to the maximum
4954 : : * ethdev can support
4955 : : */
4956 : 0 : pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
4957 : : hw->func_caps.num_vsis - vsi_count);
4958 : 0 : pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
4959 : : RTE_ETH_64_POOLS);
4960 [ # # ]: 0 : if (pf->max_nb_vmdq_vsi) {
4961 : 0 : pf->flags |= I40E_FLAG_VMDQ;
4962 : 0 : pf->vmdq_nb_qps = pf->vmdq_nb_qp_max;
4963 : 0 : PMD_DRV_LOG(DEBUG,
4964 : : "%u VMDQ VSIs, %u queues per VMDQ VSI, in total %u queues",
4965 : : pf->max_nb_vmdq_vsi, pf->vmdq_nb_qps,
4966 : : pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi);
4967 : : } else {
4968 : 0 : PMD_DRV_LOG(INFO,
4969 : : "No enough queues left for VMDq");
4970 : : }
4971 : : } else {
4972 : 0 : PMD_DRV_LOG(INFO, "No queue or VSI left for VMDq");
4973 : : }
4974 : : }
4975 : 0 : qp_count += pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi;
4976 : 0 : vsi_count += pf->max_nb_vmdq_vsi;
4977 : :
4978 [ # # ]: 0 : if (hw->func_caps.dcb)
4979 : 0 : pf->flags |= I40E_FLAG_DCB;
4980 : :
4981 [ # # ]: 0 : if (qp_count > hw->func_caps.num_tx_qp) {
4982 : 0 : PMD_DRV_LOG(ERR,
4983 : : "Failed to allocate %u queues, which exceeds the hardware maximum %u",
4984 : : qp_count, hw->func_caps.num_tx_qp);
4985 : 0 : return -EINVAL;
4986 : : }
4987 [ # # ]: 0 : if (vsi_count > hw->func_caps.num_vsis) {
4988 : 0 : PMD_DRV_LOG(ERR,
4989 : : "Failed to allocate %u VSIs, which exceeds the hardware maximum %u",
4990 : : vsi_count, hw->func_caps.num_vsis);
4991 : 0 : return -EINVAL;
4992 : : }
4993 : :
4994 : : /**
4995 : : * Enable outer VLAN processing if firmware version is greater
4996 : : * than v8.3
4997 : : */
4998 [ # # # # ]: 0 : if (hw->aq.fw_maj_ver > 8 ||
4999 [ # # ]: 0 : (hw->aq.fw_maj_ver == 8 && hw->aq.fw_min_ver > 3)) {
5000 : 0 : pf->fw8_3gt = true;
5001 : : } else {
5002 : 0 : pf->fw8_3gt = false;
5003 : : }
5004 : :
5005 : : return 0;
5006 : : }
5007 : :
5008 : : static int
5009 : 0 : i40e_pf_get_switch_config(struct i40e_pf *pf)
5010 : : {
5011 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5012 : : struct i40e_aqc_get_switch_config_resp *switch_config;
5013 : : struct i40e_aqc_switch_config_element_resp *element;
5014 : 0 : uint16_t start_seid = 0, num_reported;
5015 : : int ret;
5016 : :
5017 : : switch_config = (struct i40e_aqc_get_switch_config_resp *)\
5018 : 0 : rte_zmalloc("i40e", I40E_AQ_LARGE_BUF, 0);
5019 [ # # ]: 0 : if (!switch_config) {
5020 : 0 : PMD_DRV_LOG(ERR, "Failed to allocated memory");
5021 : 0 : return -ENOMEM;
5022 : : }
5023 : :
5024 : : /* Get the switch configurations */
5025 : 0 : ret = i40e_aq_get_switch_config(hw, switch_config,
5026 : : I40E_AQ_LARGE_BUF, &start_seid, NULL);
5027 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5028 : 0 : PMD_DRV_LOG(ERR, "Failed to get switch configurations");
5029 : 0 : goto fail;
5030 : : }
5031 : 0 : num_reported = rte_le_to_cpu_16(switch_config->header.num_reported);
5032 [ # # ]: 0 : if (num_reported != 1) { /* The number should be 1 */
5033 : 0 : PMD_DRV_LOG(ERR, "Wrong number of switch config reported");
5034 : 0 : goto fail;
5035 : : }
5036 : :
5037 : : /* Parse the switch configuration elements */
5038 : : element = &(switch_config->element[0]);
5039 [ # # ]: 0 : if (element->element_type == I40E_SWITCH_ELEMENT_TYPE_VSI) {
5040 : 0 : pf->mac_seid = rte_le_to_cpu_16(element->uplink_seid);
5041 : 0 : pf->main_vsi_seid = rte_le_to_cpu_16(element->seid);
5042 : : } else
5043 : 0 : PMD_DRV_LOG(INFO, "Unknown element type");
5044 : :
5045 : 0 : fail:
5046 : 0 : rte_free(switch_config);
5047 : :
5048 : 0 : return ret;
5049 : : }
5050 : :
5051 : : static int
5052 : 0 : i40e_res_pool_init (struct i40e_res_pool_info *pool, uint32_t base,
5053 : : uint32_t num)
5054 : : {
5055 : : struct pool_entry *entry;
5056 : :
5057 [ # # ]: 0 : if (pool == NULL || num == 0)
5058 : : return -EINVAL;
5059 : :
5060 : 0 : entry = rte_zmalloc("i40e", sizeof(*entry), 0);
5061 [ # # ]: 0 : if (entry == NULL) {
5062 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for resource pool");
5063 : 0 : return -ENOMEM;
5064 : : }
5065 : :
5066 : : /* queue heap initialize */
5067 : 0 : pool->num_free = num;
5068 : 0 : pool->num_alloc = 0;
5069 : 0 : pool->base = base;
5070 : 0 : LIST_INIT(&pool->alloc_list);
5071 : : LIST_INIT(&pool->free_list);
5072 : :
5073 : : /* Initialize element */
5074 : 0 : entry->base = 0;
5075 : 0 : entry->len = num;
5076 : :
5077 : 0 : LIST_INSERT_HEAD(&pool->free_list, entry, next);
5078 : 0 : return 0;
5079 : : }
5080 : :
5081 : : static void
5082 : 0 : i40e_res_pool_destroy(struct i40e_res_pool_info *pool)
5083 : : {
5084 : : struct pool_entry *entry, *next_entry;
5085 : :
5086 [ # # ]: 0 : if (pool == NULL)
5087 : : return;
5088 : :
5089 : 0 : for (entry = LIST_FIRST(&pool->alloc_list);
5090 [ # # ]: 0 : entry && (next_entry = LIST_NEXT(entry, next), 1);
5091 : : entry = next_entry) {
5092 [ # # ]: 0 : LIST_REMOVE(entry, next);
5093 : 0 : rte_free(entry);
5094 : : }
5095 : :
5096 : 0 : for (entry = LIST_FIRST(&pool->free_list);
5097 [ # # ]: 0 : entry && (next_entry = LIST_NEXT(entry, next), 1);
5098 : : entry = next_entry) {
5099 [ # # ]: 0 : LIST_REMOVE(entry, next);
5100 : 0 : rte_free(entry);
5101 : : }
5102 : :
5103 : 0 : pool->num_free = 0;
5104 : 0 : pool->num_alloc = 0;
5105 : 0 : pool->base = 0;
5106 : 0 : LIST_INIT(&pool->alloc_list);
5107 : 0 : LIST_INIT(&pool->free_list);
5108 : : }
5109 : :
5110 : : static int
5111 : 0 : i40e_res_pool_free(struct i40e_res_pool_info *pool,
5112 : : uint32_t base)
5113 : : {
5114 : : struct pool_entry *entry, *next, *prev, *valid_entry = NULL;
5115 : : uint32_t pool_offset;
5116 : : uint16_t len;
5117 : : int insert;
5118 : :
5119 [ # # ]: 0 : if (pool == NULL) {
5120 : 0 : PMD_DRV_LOG(ERR, "Invalid parameter");
5121 : 0 : return -EINVAL;
5122 : : }
5123 : :
5124 : 0 : pool_offset = base - pool->base;
5125 : : /* Lookup in alloc list */
5126 [ # # ]: 0 : LIST_FOREACH(entry, &pool->alloc_list, next) {
5127 [ # # ]: 0 : if (entry->base == pool_offset) {
5128 : : valid_entry = entry;
5129 [ # # ]: 0 : LIST_REMOVE(entry, next);
5130 : 0 : break;
5131 : : }
5132 : : }
5133 : :
5134 : : /* Not find, return */
5135 [ # # ]: 0 : if (valid_entry == NULL) {
5136 : 0 : PMD_DRV_LOG(ERR, "Failed to find entry");
5137 : 0 : return -EINVAL;
5138 : : }
5139 : :
5140 : : /**
5141 : : * Found it, move it to free list and try to merge.
5142 : : * In order to make merge easier, always sort it by qbase.
5143 : : * Find adjacent prev and last entries.
5144 : : */
5145 : : prev = next = NULL;
5146 [ # # ]: 0 : LIST_FOREACH(entry, &pool->free_list, next) {
5147 [ # # ]: 0 : if (entry->base > valid_entry->base) {
5148 : : next = entry;
5149 : : break;
5150 : : }
5151 : : prev = entry;
5152 : : }
5153 : :
5154 : : insert = 0;
5155 : 0 : len = valid_entry->len;
5156 : : /* Try to merge with next one*/
5157 [ # # ]: 0 : if (next != NULL) {
5158 : : /* Merge with next one */
5159 [ # # ]: 0 : if (valid_entry->base + len == next->base) {
5160 : 0 : next->base = valid_entry->base;
5161 : 0 : next->len += len;
5162 : 0 : rte_free(valid_entry);
5163 : : valid_entry = next;
5164 : : insert = 1;
5165 : : }
5166 : : }
5167 : :
5168 [ # # ]: 0 : if (prev != NULL) {
5169 : : /* Merge with previous one */
5170 [ # # ]: 0 : if (prev->base + prev->len == valid_entry->base) {
5171 : 0 : prev->len += len;
5172 : : /* If it merge with next one, remove next node */
5173 [ # # ]: 0 : if (insert == 1) {
5174 [ # # ]: 0 : LIST_REMOVE(valid_entry, next);
5175 : 0 : rte_free(valid_entry);
5176 : : valid_entry = NULL;
5177 : : } else {
5178 : 0 : rte_free(valid_entry);
5179 : : valid_entry = NULL;
5180 : : insert = 1;
5181 : : }
5182 : : }
5183 : : }
5184 : :
5185 : : /* Not find any entry to merge, insert */
5186 [ # # ]: 0 : if (insert == 0) {
5187 [ # # ]: 0 : if (prev != NULL)
5188 [ # # ]: 0 : LIST_INSERT_AFTER(prev, valid_entry, next);
5189 [ # # ]: 0 : else if (next != NULL)
5190 : 0 : LIST_INSERT_BEFORE(next, valid_entry, next);
5191 : : else /* It's empty list, insert to head */
5192 [ # # ]: 0 : LIST_INSERT_HEAD(&pool->free_list, valid_entry, next);
5193 : : }
5194 : :
5195 : 0 : pool->num_free += len;
5196 : 0 : pool->num_alloc -= len;
5197 : :
5198 : 0 : return 0;
5199 : : }
5200 : :
5201 : : static int
5202 : 0 : i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
5203 : : uint16_t num)
5204 : : {
5205 : : struct pool_entry *entry, *valid_entry;
5206 : :
5207 [ # # ]: 0 : if (pool == NULL || num == 0) {
5208 : 0 : PMD_DRV_LOG(ERR, "Invalid parameter");
5209 : 0 : return -EINVAL;
5210 : : }
5211 : :
5212 [ # # ]: 0 : if (pool->num_free < num) {
5213 : 0 : PMD_DRV_LOG(ERR, "No resource. ask:%u, available:%u",
5214 : : num, pool->num_free);
5215 : 0 : return -ENOMEM;
5216 : : }
5217 : :
5218 : : valid_entry = NULL;
5219 : : /* Lookup in free list and find most fit one */
5220 [ # # ]: 0 : LIST_FOREACH(entry, &pool->free_list, next) {
5221 [ # # ]: 0 : if (entry->len >= num) {
5222 : : /* Find best one */
5223 [ # # ]: 0 : if (entry->len == num) {
5224 : : valid_entry = entry;
5225 : : break;
5226 : : }
5227 [ # # # # ]: 0 : if (valid_entry == NULL || valid_entry->len > entry->len)
5228 : : valid_entry = entry;
5229 : : }
5230 : : }
5231 : :
5232 : : /* Not find one to satisfy the request, return */
5233 [ # # ]: 0 : if (valid_entry == NULL) {
5234 : 0 : PMD_DRV_LOG(ERR, "No valid entry found");
5235 : 0 : return -ENOMEM;
5236 : : }
5237 : : /**
5238 : : * The entry have equal queue number as requested,
5239 : : * remove it from alloc_list.
5240 : : */
5241 [ # # ]: 0 : if (valid_entry->len == num) {
5242 [ # # ]: 0 : LIST_REMOVE(valid_entry, next);
5243 : : } else {
5244 : : /**
5245 : : * The entry have more numbers than requested,
5246 : : * create a new entry for alloc_list and minus its
5247 : : * queue base and number in free_list.
5248 : : */
5249 : 0 : entry = rte_zmalloc("res_pool", sizeof(*entry), 0);
5250 [ # # ]: 0 : if (entry == NULL) {
5251 : 0 : PMD_DRV_LOG(ERR,
5252 : : "Failed to allocate memory for resource pool");
5253 : 0 : return -ENOMEM;
5254 : : }
5255 : 0 : entry->base = valid_entry->base;
5256 : 0 : entry->len = num;
5257 : 0 : valid_entry->base += num;
5258 : 0 : valid_entry->len -= num;
5259 : : valid_entry = entry;
5260 : : }
5261 : :
5262 : : /* Insert it into alloc list, not sorted */
5263 [ # # ]: 0 : LIST_INSERT_HEAD(&pool->alloc_list, valid_entry, next);
5264 : :
5265 : 0 : pool->num_free -= valid_entry->len;
5266 : 0 : pool->num_alloc += valid_entry->len;
5267 : :
5268 : 0 : return valid_entry->base + pool->base;
5269 : : }
5270 : :
5271 : : /**
5272 : : * bitmap_is_subset - Check whether src2 is subset of src1
5273 : : **/
5274 : : static inline int
5275 : : bitmap_is_subset(uint8_t src1, uint8_t src2)
5276 : : {
5277 : 0 : return !((src1 ^ src2) & src2);
5278 : : }
5279 : :
5280 : : static enum i40e_status_code
5281 : 0 : validate_tcmap_parameter(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
5282 : : {
5283 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5284 : :
5285 : : /* If DCB is not supported, only default TC is supported */
5286 [ # # # # ]: 0 : if (!hw->func_caps.dcb && enabled_tcmap != I40E_DEFAULT_TCMAP) {
5287 : 0 : PMD_DRV_LOG(ERR, "DCB is not enabled, only TC0 is supported");
5288 : 0 : return I40E_NOT_SUPPORTED;
5289 : : }
5290 : :
5291 [ # # ]: 0 : if (!bitmap_is_subset(hw->func_caps.enabled_tcmap, enabled_tcmap)) {
5292 : 0 : PMD_DRV_LOG(ERR,
5293 : : "Enabled TC map 0x%x not applicable to HW support 0x%x",
5294 : : hw->func_caps.enabled_tcmap, enabled_tcmap);
5295 : 0 : return I40E_NOT_SUPPORTED;
5296 : : }
5297 : : return I40E_SUCCESS;
5298 : : }
5299 : :
5300 : : int
5301 : 0 : i40e_vsi_vlan_pvid_set(struct i40e_vsi *vsi,
5302 : : struct i40e_vsi_vlan_pvid_info *info)
5303 : : {
5304 : : struct i40e_hw *hw;
5305 : : struct i40e_vsi_context ctxt;
5306 : : uint8_t vlan_flags = 0;
5307 : : int ret;
5308 : :
5309 [ # # ]: 0 : if (vsi == NULL || info == NULL) {
5310 : 0 : PMD_DRV_LOG(ERR, "invalid parameters");
5311 : 0 : return I40E_ERR_PARAM;
5312 : : }
5313 : :
5314 [ # # ]: 0 : if (info->on) {
5315 : 0 : vsi->info.pvid = info->config.pvid;
5316 : : /**
5317 : : * If insert pvid is enabled, only tagged pkts are
5318 : : * allowed to be sent out.
5319 : : */
5320 : : vlan_flags |= I40E_AQ_VSI_PVLAN_INSERT_PVID |
5321 : : I40E_AQ_VSI_PVLAN_MODE_TAGGED;
5322 : : } else {
5323 : 0 : vsi->info.pvid = 0;
5324 [ # # ]: 0 : if (info->config.reject.tagged == 0)
5325 : : vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_TAGGED;
5326 : :
5327 [ # # ]: 0 : if (info->config.reject.untagged == 0)
5328 : 0 : vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_UNTAGGED;
5329 : : }
5330 : 0 : vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_INSERT_PVID |
5331 : : I40E_AQ_VSI_PVLAN_MODE_MASK);
5332 : 0 : vsi->info.port_vlan_flags |= vlan_flags;
5333 [ # # ]: 0 : vsi->info.valid_sections =
5334 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5335 : : memset(&ctxt, 0, sizeof(ctxt));
5336 [ # # ]: 0 : rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
5337 : 0 : ctxt.seid = vsi->seid;
5338 : :
5339 : 0 : hw = I40E_VSI_TO_HW(vsi);
5340 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5341 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5342 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI params");
5343 : :
5344 : : return ret;
5345 : : }
5346 : :
5347 : : static int
5348 : 0 : i40e_vsi_update_tc_bandwidth(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
5349 : : {
5350 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5351 : : int i, ret;
5352 : : struct i40e_aqc_configure_vsi_tc_bw_data tc_bw_data;
5353 : :
5354 : 0 : ret = validate_tcmap_parameter(vsi, enabled_tcmap);
5355 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5356 : : return ret;
5357 : :
5358 [ # # ]: 0 : if (!vsi->seid) {
5359 : 0 : PMD_DRV_LOG(ERR, "seid not valid");
5360 : 0 : return -EINVAL;
5361 : : }
5362 : :
5363 : : memset(&tc_bw_data, 0, sizeof(tc_bw_data));
5364 : 0 : tc_bw_data.tc_valid_bits = enabled_tcmap;
5365 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5366 : 0 : tc_bw_data.tc_bw_credits[i] =
5367 : 0 : (enabled_tcmap & (1 << i)) ? 1 : 0;
5368 : :
5369 : 0 : ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &tc_bw_data, NULL);
5370 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5371 : 0 : PMD_DRV_LOG(ERR, "Failed to configure TC BW");
5372 : 0 : return ret;
5373 : : }
5374 : :
5375 [ # # ]: 0 : rte_memcpy(vsi->info.qs_handle, tc_bw_data.qs_handles,
5376 : : sizeof(vsi->info.qs_handle));
5377 : : return I40E_SUCCESS;
5378 : : }
5379 : :
5380 : : static enum i40e_status_code
5381 : 0 : i40e_vsi_config_tc_queue_mapping(struct i40e_vsi *vsi,
5382 : : struct i40e_aqc_vsi_properties_data *info,
5383 : : uint8_t enabled_tcmap)
5384 : : {
5385 : : enum i40e_status_code ret;
5386 : : int i, total_tc = 0;
5387 : : uint16_t qpnum_per_tc, bsf, qp_idx;
5388 : :
5389 : 0 : ret = validate_tcmap_parameter(vsi, enabled_tcmap);
5390 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5391 : : return ret;
5392 : :
5393 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5394 [ # # ]: 0 : if (enabled_tcmap & (1 << i))
5395 : 0 : total_tc++;
5396 [ # # ]: 0 : if (total_tc == 0)
5397 : : total_tc = 1;
5398 : 0 : vsi->enabled_tc = enabled_tcmap;
5399 : :
5400 : : /* Number of queues per enabled TC */
5401 [ # # ]: 0 : qpnum_per_tc = i40e_align_floor(vsi->nb_qps / total_tc);
5402 : 0 : qpnum_per_tc = RTE_MIN(qpnum_per_tc, I40E_MAX_Q_PER_TC);
5403 [ # # ]: 0 : bsf = rte_bsf32(qpnum_per_tc);
5404 : :
5405 : : /* Adjust the queue number to actual queues that can be applied */
5406 [ # # # # ]: 0 : if (!(vsi->type == I40E_VSI_MAIN && total_tc == 1))
5407 : 0 : vsi->nb_qps = qpnum_per_tc * total_tc;
5408 : :
5409 : : /**
5410 : : * Configure TC and queue mapping parameters, for enabled TC,
5411 : : * allocate qpnum_per_tc queues to this traffic. For disabled TC,
5412 : : * default queue will serve it.
5413 : : */
5414 : : qp_idx = 0;
5415 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5416 [ # # ]: 0 : if (vsi->enabled_tc & (1 << i)) {
5417 : 0 : info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
5418 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
5419 : : (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
5420 : 0 : qp_idx += qpnum_per_tc;
5421 : : } else
5422 : 0 : info->tc_mapping[i] = 0;
5423 : : }
5424 : :
5425 : : /* Associate queue number with VSI */
5426 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
5427 : 0 : info->mapping_flags |=
5428 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
5429 [ # # ]: 0 : for (i = 0; i < vsi->nb_qps; i++)
5430 : 0 : info->queue_mapping[i] =
5431 : 0 : rte_cpu_to_le_16(vsi->base_queue + i);
5432 : : } else {
5433 : 0 : info->mapping_flags |=
5434 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
5435 : 0 : info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
5436 : : }
5437 : 0 : info->valid_sections |=
5438 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
5439 : :
5440 : 0 : return I40E_SUCCESS;
5441 : : }
5442 : :
5443 : : static int
5444 : 0 : i40e_veb_release(struct i40e_veb *veb)
5445 : : {
5446 : : struct i40e_vsi *vsi;
5447 : : struct i40e_hw *hw;
5448 : :
5449 [ # # ]: 0 : if (veb == NULL)
5450 : : return -EINVAL;
5451 : :
5452 [ # # ]: 0 : if (!TAILQ_EMPTY(&veb->head)) {
5453 : 0 : PMD_DRV_LOG(ERR, "VEB still has VSI attached, can't remove");
5454 : 0 : return -EACCES;
5455 : : }
5456 : : /* associate_vsi field is NULL for floating VEB */
5457 [ # # ]: 0 : if (veb->associate_vsi != NULL) {
5458 : : vsi = veb->associate_vsi;
5459 : 0 : hw = I40E_VSI_TO_HW(vsi);
5460 : :
5461 : 0 : vsi->uplink_seid = veb->uplink_seid;
5462 : 0 : vsi->veb = NULL;
5463 : : } else {
5464 : 0 : veb->associate_pf->main_vsi->floating_veb = NULL;
5465 : 0 : hw = I40E_VSI_TO_HW(veb->associate_pf->main_vsi);
5466 : : }
5467 : :
5468 : 0 : i40e_aq_delete_element(hw, veb->seid, NULL);
5469 : 0 : rte_free(veb);
5470 : 0 : return I40E_SUCCESS;
5471 : : }
5472 : :
5473 : : /* Setup a veb */
5474 : : static struct i40e_veb *
5475 : 0 : i40e_veb_setup(struct i40e_pf *pf, struct i40e_vsi *vsi)
5476 : : {
5477 : : struct i40e_veb *veb;
5478 : : int ret;
5479 : : struct i40e_hw *hw;
5480 : :
5481 [ # # ]: 0 : if (pf == NULL) {
5482 : 0 : PMD_DRV_LOG(ERR,
5483 : : "veb setup failed, associated PF shouldn't null");
5484 : 0 : return NULL;
5485 : : }
5486 : 0 : hw = I40E_PF_TO_HW(pf);
5487 : :
5488 : 0 : veb = rte_zmalloc("i40e_veb", sizeof(struct i40e_veb), 0);
5489 [ # # ]: 0 : if (!veb) {
5490 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for veb");
5491 : 0 : goto fail;
5492 : : }
5493 : :
5494 : 0 : veb->associate_vsi = vsi;
5495 : 0 : veb->associate_pf = pf;
5496 : 0 : TAILQ_INIT(&veb->head);
5497 [ # # ]: 0 : veb->uplink_seid = vsi ? vsi->uplink_seid : 0;
5498 : :
5499 : : /* create floating veb if vsi is NULL */
5500 [ # # ]: 0 : if (vsi != NULL) {
5501 : 0 : ret = i40e_aq_add_veb(hw, veb->uplink_seid, vsi->seid,
5502 : : I40E_DEFAULT_TCMAP, false,
5503 : 0 : &veb->seid, false, NULL);
5504 : : } else {
5505 : 0 : ret = i40e_aq_add_veb(hw, 0, 0, I40E_DEFAULT_TCMAP,
5506 : 0 : true, &veb->seid, false, NULL);
5507 : : }
5508 : :
5509 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5510 : 0 : PMD_DRV_LOG(ERR, "Add veb failed, aq_err: %d",
5511 : : hw->aq.asq_last_status);
5512 : 0 : goto fail;
5513 : : }
5514 : 0 : veb->enabled_tc = I40E_DEFAULT_TCMAP;
5515 : :
5516 : : /* get statistics index */
5517 : 0 : ret = i40e_aq_get_veb_parameters(hw, veb->seid, NULL, NULL,
5518 : 0 : &veb->stats_idx, NULL, NULL, NULL);
5519 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5520 : 0 : PMD_DRV_LOG(ERR, "Get veb statistics index failed, aq_err: %d",
5521 : : hw->aq.asq_last_status);
5522 : 0 : goto fail;
5523 : : }
5524 : : /* Get VEB bandwidth, to be implemented */
5525 : : /* Now associated vsi binding to the VEB, set uplink to this VEB */
5526 [ # # ]: 0 : if (vsi)
5527 : 0 : vsi->uplink_seid = veb->seid;
5528 : :
5529 : : return veb;
5530 : 0 : fail:
5531 : 0 : rte_free(veb);
5532 : 0 : return NULL;
5533 : : }
5534 : :
5535 : : int
5536 : 0 : i40e_vsi_release(struct i40e_vsi *vsi)
5537 : : {
5538 : : struct i40e_pf *pf;
5539 : : struct i40e_hw *hw;
5540 : : struct i40e_vsi_list *vsi_list;
5541 : : void *temp;
5542 : : int ret;
5543 : : struct i40e_mac_filter *f;
5544 : : uint16_t user_param;
5545 : :
5546 [ # # ]: 0 : if (!vsi)
5547 : : return I40E_SUCCESS;
5548 : :
5549 [ # # ]: 0 : if (!vsi->adapter)
5550 : : return -EFAULT;
5551 : :
5552 : 0 : user_param = vsi->user_param;
5553 : :
5554 : : pf = I40E_VSI_TO_PF(vsi);
5555 : 0 : hw = I40E_VSI_TO_HW(vsi);
5556 : :
5557 : : /* VSI has child to attach, release child first */
5558 [ # # ]: 0 : if (vsi->veb) {
5559 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(vsi_list, &vsi->veb->head, list, temp) {
5560 [ # # ]: 0 : if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
5561 : : return -1;
5562 : : }
5563 : 0 : i40e_veb_release(vsi->veb);
5564 : : }
5565 : :
5566 [ # # ]: 0 : if (vsi->floating_veb) {
5567 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(vsi_list, &vsi->floating_veb->head,
5568 : : list, temp) {
5569 [ # # ]: 0 : if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
5570 : : return -1;
5571 : : }
5572 : : }
5573 : :
5574 : : /* Remove all macvlan filters of the VSI */
5575 : 0 : i40e_vsi_remove_all_macvlan_filter(vsi);
5576 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp)
5577 : 0 : rte_free(f);
5578 : :
5579 [ # # # # ]: 0 : if (vsi->type != I40E_VSI_MAIN &&
5580 : 0 : ((vsi->type != I40E_VSI_SRIOV) ||
5581 [ # # ]: 0 : !pf->floating_veb_list[user_param])) {
5582 : : /* Remove vsi from parent's sibling list */
5583 [ # # # # ]: 0 : if (vsi->parent_vsi == NULL || vsi->parent_vsi->veb == NULL) {
5584 : 0 : PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
5585 : 0 : return I40E_ERR_PARAM;
5586 : : }
5587 [ # # ]: 0 : TAILQ_REMOVE(&vsi->parent_vsi->veb->head,
5588 : : &vsi->sib_vsi_list, list);
5589 : :
5590 : : /* Remove all switch element of the VSI */
5591 : 0 : ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
5592 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5593 : 0 : PMD_DRV_LOG(ERR, "Failed to delete element");
5594 : : }
5595 : :
5596 [ # # ]: 0 : if ((vsi->type == I40E_VSI_SRIOV) &&
5597 [ # # ]: 0 : pf->floating_veb_list[user_param]) {
5598 : : /* Remove vsi from parent's sibling list */
5599 [ # # ]: 0 : if (vsi->parent_vsi == NULL ||
5600 [ # # ]: 0 : vsi->parent_vsi->floating_veb == NULL) {
5601 : 0 : PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
5602 : 0 : return I40E_ERR_PARAM;
5603 : : }
5604 [ # # ]: 0 : TAILQ_REMOVE(&vsi->parent_vsi->floating_veb->head,
5605 : : &vsi->sib_vsi_list, list);
5606 : :
5607 : : /* Remove all switch element of the VSI */
5608 : 0 : ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
5609 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5610 : 0 : PMD_DRV_LOG(ERR, "Failed to delete element");
5611 : : }
5612 : :
5613 : 0 : i40e_res_pool_free(&pf->qp_pool, vsi->base_queue);
5614 : :
5615 [ # # ]: 0 : if (vsi->type != I40E_VSI_SRIOV)
5616 : 0 : i40e_res_pool_free(&pf->msix_pool, vsi->msix_intr);
5617 : 0 : rte_free(vsi);
5618 : :
5619 : 0 : return I40E_SUCCESS;
5620 : : }
5621 : :
5622 : : static int
5623 : 0 : i40e_update_default_filter_setting(struct i40e_vsi *vsi)
5624 : : {
5625 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5626 : : struct i40e_aqc_remove_macvlan_element_data def_filter;
5627 : : struct i40e_mac_filter_info filter;
5628 : : int ret;
5629 : :
5630 [ # # ]: 0 : if (vsi->type != I40E_VSI_MAIN)
5631 : : return I40E_ERR_CONFIG;
5632 : : memset(&def_filter, 0, sizeof(def_filter));
5633 [ # # ]: 0 : rte_memcpy(def_filter.mac_addr, hw->mac.perm_addr,
5634 : : ETH_ADDR_LEN);
5635 : : def_filter.vlan_tag = 0;
5636 : 0 : def_filter.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
5637 : : I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
5638 : 0 : ret = i40e_aq_remove_macvlan(hw, vsi->seid, &def_filter, 1, NULL);
5639 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5640 : : struct i40e_mac_filter *f;
5641 : : struct rte_ether_addr *mac;
5642 : :
5643 : 0 : PMD_DRV_LOG(DEBUG,
5644 : : "Cannot remove the default macvlan filter");
5645 : : /* It needs to add the permanent mac into mac list */
5646 : 0 : f = rte_zmalloc("macv_filter", sizeof(*f), 0);
5647 [ # # ]: 0 : if (f == NULL) {
5648 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
5649 : 0 : return I40E_ERR_NO_MEMORY;
5650 : : }
5651 : : mac = &f->mac_info.mac_addr;
5652 [ # # ]: 0 : rte_memcpy(&mac->addr_bytes, hw->mac.perm_addr,
5653 : : ETH_ADDR_LEN);
5654 : 0 : f->mac_info.filter_type = I40E_MACVLAN_PERFECT_MATCH;
5655 : 0 : TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
5656 : 0 : vsi->mac_num++;
5657 : :
5658 : 0 : return ret;
5659 : : }
5660 : : rte_memcpy(&filter.mac_addr,
5661 : : (struct rte_ether_addr *)(hw->mac.perm_addr), ETH_ADDR_LEN);
5662 : 0 : filter.filter_type = I40E_MACVLAN_PERFECT_MATCH;
5663 : 0 : return i40e_vsi_add_mac(vsi, &filter);
5664 : : }
5665 : :
5666 : : /*
5667 : : * i40e_vsi_get_bw_config - Query VSI BW Information
5668 : : * @vsi: the VSI to be queried
5669 : : *
5670 : : * Returns 0 on success, negative value on failure
5671 : : */
5672 : : static enum i40e_status_code
5673 : 0 : i40e_vsi_get_bw_config(struct i40e_vsi *vsi)
5674 : : {
5675 : : struct i40e_aqc_query_vsi_bw_config_resp bw_config;
5676 : : struct i40e_aqc_query_vsi_ets_sla_config_resp ets_sla_config;
5677 : 0 : struct i40e_hw *hw = &vsi->adapter->hw;
5678 : : i40e_status ret;
5679 : : int i;
5680 : : uint32_t bw_max;
5681 : :
5682 : : memset(&bw_config, 0, sizeof(bw_config));
5683 : 0 : ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
5684 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5685 : 0 : PMD_DRV_LOG(ERR, "VSI failed to get bandwidth configuration %u",
5686 : : hw->aq.asq_last_status);
5687 : 0 : return ret;
5688 : : }
5689 : :
5690 : : memset(&ets_sla_config, 0, sizeof(ets_sla_config));
5691 : 0 : ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid,
5692 : : &ets_sla_config, NULL);
5693 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5694 : 0 : PMD_DRV_LOG(ERR,
5695 : : "VSI failed to get TC bandwidth configuration %u",
5696 : : hw->aq.asq_last_status);
5697 : 0 : return ret;
5698 : : }
5699 : :
5700 : : /* store and print out BW info */
5701 : 0 : vsi->bw_info.bw_limit = rte_le_to_cpu_16(bw_config.port_bw_limit);
5702 : 0 : vsi->bw_info.bw_max = bw_config.max_bw;
5703 : 0 : PMD_DRV_LOG(DEBUG, "VSI bw limit:%u", vsi->bw_info.bw_limit);
5704 : 0 : PMD_DRV_LOG(DEBUG, "VSI max_bw:%u", vsi->bw_info.bw_max);
5705 : 0 : bw_max = rte_le_to_cpu_16(ets_sla_config.tc_bw_max[0]) |
5706 : 0 : (rte_le_to_cpu_16(ets_sla_config.tc_bw_max[1]) <<
5707 : : I40E_16_BIT_WIDTH);
5708 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5709 : 0 : vsi->bw_info.bw_ets_share_credits[i] =
5710 : 0 : ets_sla_config.share_credits[i];
5711 : 0 : vsi->bw_info.bw_ets_credits[i] =
5712 : 0 : rte_le_to_cpu_16(ets_sla_config.credits[i]);
5713 : : /* 4 bits per TC, 4th bit is reserved */
5714 : 0 : vsi->bw_info.bw_ets_max[i] =
5715 : 0 : (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
5716 : : RTE_LEN2MASK(3, uint8_t));
5717 : 0 : PMD_DRV_LOG(DEBUG, "\tVSI TC%u:share credits %u", i,
5718 : : vsi->bw_info.bw_ets_share_credits[i]);
5719 : 0 : PMD_DRV_LOG(DEBUG, "\tVSI TC%u:credits %u", i,
5720 : : vsi->bw_info.bw_ets_credits[i]);
5721 : 0 : PMD_DRV_LOG(DEBUG, "\tVSI TC%u: max credits: %u", i,
5722 : : vsi->bw_info.bw_ets_max[i]);
5723 : : }
5724 : :
5725 : : return I40E_SUCCESS;
5726 : : }
5727 : :
5728 : : /* i40e_enable_pf_lb
5729 : : * @pf: pointer to the pf structure
5730 : : *
5731 : : * allow loopback on pf
5732 : : */
5733 : : static inline void
5734 : 0 : i40e_enable_pf_lb(struct i40e_pf *pf)
5735 : : {
5736 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5737 : : struct i40e_vsi_context ctxt;
5738 : : int ret;
5739 : :
5740 : : /* Use the FW API if FW >= v5.0 */
5741 [ # # # # ]: 0 : if (hw->aq.fw_maj_ver < 5 && hw->mac.type != I40E_MAC_X722) {
5742 : 0 : PMD_INIT_LOG(ERR, "FW < v5.0, cannot enable loopback");
5743 : 0 : return;
5744 : : }
5745 : :
5746 : : memset(&ctxt, 0, sizeof(ctxt));
5747 : 0 : ctxt.seid = pf->main_vsi_seid;
5748 : 0 : ctxt.pf_num = hw->pf_id;
5749 : 0 : ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5750 [ # # ]: 0 : if (ret) {
5751 : 0 : PMD_DRV_LOG(ERR, "cannot get pf vsi config, err %d, aq_err %d",
5752 : : ret, hw->aq.asq_last_status);
5753 : 0 : return;
5754 : : }
5755 : 0 : ctxt.flags = I40E_AQ_VSI_TYPE_PF;
5756 : 0 : ctxt.info.valid_sections =
5757 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5758 : 0 : ctxt.info.switch_id |=
5759 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5760 : :
5761 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5762 [ # # ]: 0 : if (ret)
5763 : 0 : PMD_DRV_LOG(ERR, "update vsi switch failed, aq_err=%d",
5764 : : hw->aq.asq_last_status);
5765 : : }
5766 : :
5767 : : /* i40e_pf_set_source_prune
5768 : : * @pf: pointer to the pf structure
5769 : : * @on: Enable/disable source prune
5770 : : *
5771 : : * set source prune on pf
5772 : : */
5773 : : int
5774 : 0 : i40e_pf_set_source_prune(struct i40e_pf *pf, int on)
5775 : : {
5776 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5777 : : struct i40e_vsi_context ctxt;
5778 : : int ret;
5779 : :
5780 : : memset(&ctxt, 0, sizeof(ctxt));
5781 : 0 : ctxt.seid = pf->main_vsi_seid;
5782 : 0 : ctxt.pf_num = hw->pf_id;
5783 : 0 : ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5784 [ # # ]: 0 : if (ret) {
5785 : 0 : PMD_DRV_LOG(ERR, "cannot get pf vsi config, err %d, aq_err %d",
5786 : : ret, hw->aq.asq_last_status);
5787 : 0 : return ret;
5788 : : }
5789 : 0 : ctxt.flags = I40E_AQ_VSI_TYPE_PF;
5790 : 0 : ctxt.info.valid_sections =
5791 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5792 [ # # ]: 0 : if (on)
5793 : 0 : ctxt.info.switch_id &=
5794 : : ~rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
5795 : : else
5796 : 0 : ctxt.info.switch_id |=
5797 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
5798 : :
5799 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5800 [ # # ]: 0 : if (ret)
5801 : 0 : PMD_DRV_LOG(ERR, "update vsi switch failed, aq_err=%d",
5802 : : hw->aq.asq_last_status);
5803 : :
5804 : : return ret;
5805 : : }
5806 : :
5807 : : /* Setup a VSI */
5808 : : struct i40e_vsi *
5809 : 0 : i40e_vsi_setup(struct i40e_pf *pf,
5810 : : enum i40e_vsi_type type,
5811 : : struct i40e_vsi *uplink_vsi,
5812 : : uint16_t user_param)
5813 : : {
5814 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5815 : : struct i40e_vsi *vsi;
5816 : : struct i40e_mac_filter_info filter;
5817 : : int ret;
5818 : : struct i40e_vsi_context ctxt;
5819 : 0 : struct rte_ether_addr broadcast =
5820 : : {.addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
5821 : :
5822 [ # # # # ]: 0 : if (type != I40E_VSI_MAIN && type != I40E_VSI_SRIOV &&
5823 : : uplink_vsi == NULL) {
5824 : 0 : PMD_DRV_LOG(ERR,
5825 : : "VSI setup failed, VSI link shouldn't be NULL");
5826 : 0 : return NULL;
5827 : : }
5828 : :
5829 [ # # ]: 0 : if (type == I40E_VSI_MAIN && uplink_vsi != NULL) {
5830 : 0 : PMD_DRV_LOG(ERR,
5831 : : "VSI setup failed, MAIN VSI uplink VSI should be NULL");
5832 : 0 : return NULL;
5833 : : }
5834 : :
5835 : : /* two situations
5836 : : * 1.type is not MAIN and uplink vsi is not NULL
5837 : : * If uplink vsi didn't setup VEB, create one first under veb field
5838 : : * 2.type is SRIOV and the uplink is NULL
5839 : : * If floating VEB is NULL, create one veb under floating veb field
5840 : : */
5841 : :
5842 [ # # ]: 0 : if (type != I40E_VSI_MAIN && uplink_vsi != NULL &&
5843 [ # # ]: 0 : uplink_vsi->veb == NULL) {
5844 : 0 : uplink_vsi->veb = i40e_veb_setup(pf, uplink_vsi);
5845 : :
5846 [ # # ]: 0 : if (uplink_vsi->veb == NULL) {
5847 : 0 : PMD_DRV_LOG(ERR, "VEB setup failed");
5848 : 0 : return NULL;
5849 : : }
5850 : : /* set ALLOWLOOPBACk on pf, when veb is created */
5851 : 0 : i40e_enable_pf_lb(pf);
5852 : : }
5853 : :
5854 [ # # ]: 0 : if (type == I40E_VSI_SRIOV && uplink_vsi == NULL &&
5855 [ # # ]: 0 : pf->main_vsi->floating_veb == NULL) {
5856 : 0 : pf->main_vsi->floating_veb = i40e_veb_setup(pf, uplink_vsi);
5857 : :
5858 [ # # ]: 0 : if (pf->main_vsi->floating_veb == NULL) {
5859 : 0 : PMD_DRV_LOG(ERR, "VEB setup failed");
5860 : 0 : return NULL;
5861 : : }
5862 : : }
5863 : :
5864 : : /* source prune is disabled to support VRRP in default*/
5865 : 0 : i40e_pf_set_source_prune(pf, 0);
5866 : :
5867 : 0 : vsi = rte_zmalloc("i40e_vsi", sizeof(struct i40e_vsi), 0);
5868 [ # # ]: 0 : if (!vsi) {
5869 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for vsi");
5870 : 0 : return NULL;
5871 : : }
5872 : 0 : TAILQ_INIT(&vsi->mac_list);
5873 : 0 : vsi->type = type;
5874 : 0 : vsi->adapter = I40E_PF_TO_ADAPTER(pf);
5875 : 0 : vsi->max_macaddrs = I40E_NUM_MACADDR_MAX;
5876 [ # # ]: 0 : vsi->parent_vsi = uplink_vsi ? uplink_vsi : pf->main_vsi;
5877 : 0 : vsi->user_param = user_param;
5878 : 0 : vsi->vlan_anti_spoof_on = 0;
5879 : 0 : vsi->vlan_filter_on = 0;
5880 : : /* Allocate queues */
5881 [ # # # # : 0 : switch (vsi->type) {
# ]
5882 : 0 : case I40E_VSI_MAIN :
5883 : 0 : vsi->nb_qps = pf->lan_nb_qps;
5884 : 0 : break;
5885 : 0 : case I40E_VSI_SRIOV :
5886 : 0 : vsi->nb_qps = pf->vf_nb_qps;
5887 : 0 : break;
5888 : 0 : case I40E_VSI_VMDQ2:
5889 : 0 : vsi->nb_qps = pf->vmdq_nb_qps;
5890 : 0 : break;
5891 : 0 : case I40E_VSI_FDIR:
5892 : 0 : vsi->nb_qps = pf->fdir_nb_qps;
5893 : 0 : break;
5894 : 0 : default:
5895 : 0 : goto fail_mem;
5896 : : }
5897 : : /*
5898 : : * The filter status descriptor is reported in rx queue 0,
5899 : : * while the tx queue for fdir filter programming has no
5900 : : * such constraints, can be non-zero queues.
5901 : : * To simplify it, choose FDIR vsi use queue 0 pair.
5902 : : * To make sure it will use queue 0 pair, queue allocation
5903 : : * need be done before this function is called
5904 : : */
5905 [ # # ]: 0 : if (type != I40E_VSI_FDIR) {
5906 : 0 : ret = i40e_res_pool_alloc(&pf->qp_pool, vsi->nb_qps);
5907 [ # # ]: 0 : if (ret < 0) {
5908 : 0 : PMD_DRV_LOG(ERR, "VSI %d allocate queue failed %d",
5909 : : vsi->seid, ret);
5910 : 0 : goto fail_mem;
5911 : : }
5912 : 0 : vsi->base_queue = ret;
5913 : : } else
5914 : 0 : vsi->base_queue = I40E_FDIR_QUEUE_ID;
5915 : :
5916 : : /* VF has MSIX interrupt in VF range, don't allocate here */
5917 [ # # ]: 0 : if (type == I40E_VSI_MAIN) {
5918 [ # # ]: 0 : if (pf->support_multi_driver) {
5919 : : /* If support multi-driver, need to use INT0 instead of
5920 : : * allocating from msix pool. The Msix pool is init from
5921 : : * INT1, so it's OK just set msix_intr to 0 and nb_msix
5922 : : * to 1 without calling i40e_res_pool_alloc.
5923 : : */
5924 : 0 : vsi->msix_intr = 0;
5925 : 0 : vsi->nb_msix = 1;
5926 : : } else {
5927 : 0 : ret = i40e_res_pool_alloc(&pf->msix_pool,
5928 : 0 : RTE_MIN(vsi->nb_qps,
5929 : : RTE_MAX_RXTX_INTR_VEC_ID));
5930 [ # # ]: 0 : if (ret < 0) {
5931 : 0 : PMD_DRV_LOG(ERR,
5932 : : "VSI MAIN %d get heap failed %d",
5933 : : vsi->seid, ret);
5934 : 0 : goto fail_queue_alloc;
5935 : : }
5936 : 0 : vsi->msix_intr = ret;
5937 : 0 : vsi->nb_msix = RTE_MIN(vsi->nb_qps,
5938 : : RTE_MAX_RXTX_INTR_VEC_ID);
5939 : : }
5940 [ # # ]: 0 : } else if (type != I40E_VSI_SRIOV) {
5941 : 0 : ret = i40e_res_pool_alloc(&pf->msix_pool, 1);
5942 [ # # ]: 0 : if (ret < 0) {
5943 : 0 : PMD_DRV_LOG(ERR, "VSI %d get heap failed %d", vsi->seid, ret);
5944 [ # # ]: 0 : if (type != I40E_VSI_FDIR)
5945 : 0 : goto fail_queue_alloc;
5946 : 0 : vsi->msix_intr = 0;
5947 : 0 : vsi->nb_msix = 0;
5948 : : } else {
5949 : 0 : vsi->msix_intr = ret;
5950 : 0 : vsi->nb_msix = 1;
5951 : : }
5952 : : } else {
5953 : 0 : vsi->msix_intr = 0;
5954 : 0 : vsi->nb_msix = 0;
5955 : : }
5956 : :
5957 : : /* Add VSI */
5958 [ # # ]: 0 : if (type == I40E_VSI_MAIN) {
5959 : : /* For main VSI, no need to add since it's default one */
5960 : 0 : vsi->uplink_seid = pf->mac_seid;
5961 : 0 : vsi->seid = pf->main_vsi_seid;
5962 : : /* Bind queues with specific MSIX interrupt */
5963 : : /**
5964 : : * Needs 2 interrupt at least, one for misc cause which will
5965 : : * enabled from OS side, Another for queues binding the
5966 : : * interrupt from device side only.
5967 : : */
5968 : :
5969 : : /* Get default VSI parameters from hardware */
5970 : : memset(&ctxt, 0, sizeof(ctxt));
5971 : 0 : ctxt.seid = vsi->seid;
5972 : 0 : ctxt.pf_num = hw->pf_id;
5973 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
5974 : : ctxt.vf_num = 0;
5975 : 0 : ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5976 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5977 : 0 : PMD_DRV_LOG(ERR, "Failed to get VSI params");
5978 : 0 : goto fail_msix_alloc;
5979 : : }
5980 [ # # ]: 0 : rte_memcpy(&vsi->info, &ctxt.info,
5981 : : sizeof(struct i40e_aqc_vsi_properties_data));
5982 : 0 : vsi->vsi_id = ctxt.vsi_number;
5983 : 0 : vsi->info.valid_sections = 0;
5984 : :
5985 : : /* Configure tc, enabled TC0 only */
5986 [ # # ]: 0 : if (i40e_vsi_update_tc_bandwidth(vsi, I40E_DEFAULT_TCMAP) !=
5987 : : I40E_SUCCESS) {
5988 : 0 : PMD_DRV_LOG(ERR, "Failed to update TC bandwidth");
5989 : 0 : goto fail_msix_alloc;
5990 : : }
5991 : :
5992 : : /* TC, queue mapping */
5993 : : memset(&ctxt, 0, sizeof(ctxt));
5994 : 0 : vsi->info.valid_sections |=
5995 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5996 [ # # ]: 0 : vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
5997 : : I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
5998 : : rte_memcpy(&ctxt.info, &vsi->info,
5999 : : sizeof(struct i40e_aqc_vsi_properties_data));
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 : : struct i40e_mac_filter_info *mac_filter;
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 : :
6214 : 0 : mac_filter = rte_zmalloc("mac_filter_info_data",
6215 : : num * sizeof(*mac_filter), 0);
6216 [ # # ]: 0 : if (mac_filter == NULL) {
6217 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
6218 : 0 : return I40E_ERR_NO_MEMORY;
6219 : : }
6220 : :
6221 : : i = 0;
6222 : :
6223 : : /* Remove all existing mac */
6224 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
6225 : 0 : mac_filter[i] = f->mac_info;
6226 : 0 : ret = i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
6227 [ # # ]: 0 : if (ret) {
6228 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
6229 : : on ? "enable" : "disable");
6230 : 0 : goto DONE;
6231 : : }
6232 : 0 : i++;
6233 : : }
6234 : :
6235 : : /* Override with new filter */
6236 [ # # ]: 0 : for (i = 0; i < num; i++) {
6237 : 0 : mac_filter[i].filter_type = desired_filter;
6238 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter[i]);
6239 [ # # ]: 0 : if (ret) {
6240 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Update VSI failed to %s vlan filter",
6241 : : on ? "enable" : "disable");
6242 : 0 : goto DONE;
6243 : : }
6244 : : }
6245 : :
6246 : 0 : DONE:
6247 : 0 : rte_free(mac_filter);
6248 : 0 : return ret;
6249 : : }
6250 : :
6251 : : /* Configure vlan stripping on or off */
6252 : : int
6253 : 0 : i40e_vsi_config_vlan_stripping(struct i40e_vsi *vsi, bool on)
6254 : : {
6255 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6256 : : struct i40e_vsi_context ctxt;
6257 : : uint8_t vlan_flags;
6258 : : int ret = I40E_SUCCESS;
6259 : :
6260 : : /* Check if it has been already on or off */
6261 [ # # ]: 0 : if (vsi->info.valid_sections &
6262 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID)) {
6263 [ # # ]: 0 : if (on) {
6264 [ # # ]: 0 : if ((vsi->info.port_vlan_flags &
6265 : : I40E_AQ_VSI_PVLAN_EMOD_MASK) == 0)
6266 : : return 0; /* already on */
6267 : : } else {
6268 [ # # ]: 0 : if ((vsi->info.port_vlan_flags &
6269 : : I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
6270 : : I40E_AQ_VSI_PVLAN_EMOD_MASK)
6271 : : return 0; /* already off */
6272 : : }
6273 : : }
6274 : :
6275 [ # # ]: 0 : if (on)
6276 : : vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
6277 : : else
6278 : : vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
6279 : 0 : vsi->info.valid_sections =
6280 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
6281 : 0 : vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_EMOD_MASK);
6282 : 0 : vsi->info.port_vlan_flags |= vlan_flags;
6283 : 0 : ctxt.seid = vsi->seid;
6284 [ # # ]: 0 : rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
6285 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
6286 [ # # ]: 0 : if (ret)
6287 [ # # ]: 0 : PMD_DRV_LOG(INFO, "Update VSI failed to %s vlan stripping",
6288 : : on ? "enable" : "disable");
6289 : :
6290 : : return ret;
6291 : : }
6292 : :
6293 : : static int
6294 : 0 : i40e_dev_init_vlan(struct rte_eth_dev *dev)
6295 : : {
6296 : 0 : struct rte_eth_dev_data *data = dev->data;
6297 : : int ret;
6298 : : int mask = 0;
6299 : :
6300 : : /* Apply vlan offload setting */
6301 : : mask = RTE_ETH_VLAN_STRIP_MASK |
6302 : : RTE_ETH_QINQ_STRIP_MASK |
6303 : : RTE_ETH_VLAN_FILTER_MASK |
6304 : : RTE_ETH_VLAN_EXTEND_MASK;
6305 : :
6306 : 0 : ret = i40e_vlan_offload_set(dev, mask);
6307 [ # # ]: 0 : if (ret) {
6308 : 0 : PMD_DRV_LOG(INFO, "Failed to update vlan offload");
6309 : 0 : return ret;
6310 : : }
6311 : :
6312 : : /* Apply pvid setting */
6313 : 0 : ret = i40e_vlan_pvid_set(dev, data->dev_conf.txmode.pvid,
6314 : 0 : data->dev_conf.txmode.hw_vlan_insert_pvid);
6315 [ # # ]: 0 : if (ret)
6316 : 0 : PMD_DRV_LOG(INFO, "Failed to update VSI params");
6317 : :
6318 : : return ret;
6319 : : }
6320 : :
6321 : : static int
6322 : : i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on)
6323 : : {
6324 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6325 : :
6326 : 0 : return i40e_aq_set_port_parameters(hw, vsi->seid, 0, 1, on, NULL);
6327 : : }
6328 : :
6329 : : static int
6330 : 0 : i40e_update_flow_control(struct i40e_hw *hw)
6331 : : {
6332 : : #define I40E_LINK_PAUSE_RXTX (I40E_AQ_LINK_PAUSE_RX | I40E_AQ_LINK_PAUSE_TX)
6333 : : struct i40e_link_status link_status;
6334 : : uint32_t rxfc = 0, txfc = 0, reg;
6335 : : uint8_t an_info;
6336 : : int ret;
6337 : :
6338 : : memset(&link_status, 0, sizeof(link_status));
6339 : 0 : ret = i40e_aq_get_link_info(hw, FALSE, &link_status, NULL);
6340 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6341 : 0 : PMD_DRV_LOG(ERR, "Failed to get link status information");
6342 : 0 : goto write_reg; /* Disable flow control */
6343 : : }
6344 : :
6345 : 0 : an_info = hw->phy.link_info.an_info;
6346 [ # # ]: 0 : if (!(an_info & I40E_AQ_AN_COMPLETED)) {
6347 : 0 : PMD_DRV_LOG(INFO, "Link auto negotiation not completed");
6348 : : ret = I40E_ERR_NOT_READY;
6349 : 0 : goto write_reg; /* Disable flow control */
6350 : : }
6351 : : /**
6352 : : * If link auto negotiation is enabled, flow control needs to
6353 : : * be configured according to it
6354 : : */
6355 [ # # # # ]: 0 : switch (an_info & I40E_LINK_PAUSE_RXTX) {
6356 : 0 : case I40E_LINK_PAUSE_RXTX:
6357 : : rxfc = 1;
6358 : : txfc = 1;
6359 : 0 : hw->fc.current_mode = I40E_FC_FULL;
6360 : 0 : break;
6361 : 0 : case I40E_AQ_LINK_PAUSE_RX:
6362 : : rxfc = 1;
6363 : 0 : hw->fc.current_mode = I40E_FC_RX_PAUSE;
6364 : 0 : break;
6365 : 0 : case I40E_AQ_LINK_PAUSE_TX:
6366 : : txfc = 1;
6367 : 0 : hw->fc.current_mode = I40E_FC_TX_PAUSE;
6368 : 0 : break;
6369 : 0 : default:
6370 : 0 : hw->fc.current_mode = I40E_FC_NONE;
6371 : 0 : break;
6372 : : }
6373 : :
6374 : 0 : write_reg:
6375 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_FCCFG,
6376 : : txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT);
6377 : 0 : reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
6378 : 0 : reg &= ~I40E_PRTDCB_MFLCN_RFCE_MASK;
6379 : 0 : reg |= rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT;
6380 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, reg);
6381 : :
6382 : 0 : return ret;
6383 : : }
6384 : :
6385 : : /* PF setup */
6386 : : static int
6387 : 0 : i40e_pf_setup(struct i40e_pf *pf)
6388 : : {
6389 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6390 : : struct i40e_filter_control_settings settings;
6391 : : struct i40e_vsi *vsi;
6392 : : int ret;
6393 : :
6394 : : /* Clear all stats counters */
6395 : 0 : pf->offset_loaded = FALSE;
6396 : 0 : memset(&pf->stats, 0, sizeof(struct i40e_hw_port_stats));
6397 : 0 : memset(&pf->stats_offset, 0, sizeof(struct i40e_hw_port_stats));
6398 : 0 : memset(&pf->internal_stats, 0, sizeof(struct i40e_eth_stats));
6399 : 0 : memset(&pf->internal_stats_offset, 0, sizeof(struct i40e_eth_stats));
6400 : 0 : pf->rx_err1 = 0;
6401 : 0 : pf->rx_err1_offset = 0;
6402 : :
6403 : 0 : ret = i40e_pf_get_switch_config(pf);
6404 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6405 : 0 : PMD_DRV_LOG(ERR, "Could not get switch config, err %d", ret);
6406 : 0 : return ret;
6407 : : }
6408 : :
6409 : 0 : ret = rte_eth_switch_domain_alloc(&pf->switch_domain_id);
6410 [ # # ]: 0 : if (ret)
6411 : 0 : PMD_INIT_LOG(WARNING,
6412 : : "failed to allocate switch domain for device %d", ret);
6413 : :
6414 [ # # ]: 0 : if (pf->flags & I40E_FLAG_FDIR) {
6415 : : /* make queue allocated first, let FDIR use queue pair 0*/
6416 : 0 : ret = i40e_res_pool_alloc(&pf->qp_pool, I40E_DEFAULT_QP_NUM_FDIR);
6417 [ # # ]: 0 : if (ret != I40E_FDIR_QUEUE_ID) {
6418 : 0 : PMD_DRV_LOG(ERR,
6419 : : "queue allocation fails for FDIR: ret =%d",
6420 : : ret);
6421 : 0 : pf->flags &= ~I40E_FLAG_FDIR;
6422 : : }
6423 : : }
6424 : : /* main VSI setup */
6425 : 0 : vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, NULL, 0);
6426 [ # # ]: 0 : if (!vsi) {
6427 : 0 : PMD_DRV_LOG(ERR, "Setup of main vsi failed");
6428 : 0 : return I40E_ERR_NOT_READY;
6429 : : }
6430 [ # # ]: 0 : pf->main_vsi = vsi;
6431 : :
6432 : : /* Configure filter control */
6433 : : memset(&settings, 0, sizeof(settings));
6434 [ # # ]: 0 : if (hw->func_caps.rss_table_size == RTE_ETH_RSS_RETA_SIZE_128)
6435 : : settings.hash_lut_size = I40E_HASH_LUT_SIZE_128;
6436 [ # # ]: 0 : else if (hw->func_caps.rss_table_size == RTE_ETH_RSS_RETA_SIZE_512)
6437 : 0 : settings.hash_lut_size = I40E_HASH_LUT_SIZE_512;
6438 : : else {
6439 : 0 : PMD_DRV_LOG(ERR, "Hash lookup table size (%u) not supported",
6440 : : hw->func_caps.rss_table_size);
6441 : 0 : return I40E_ERR_PARAM;
6442 : : }
6443 : 0 : PMD_DRV_LOG(INFO, "Hardware capability of hash lookup table size: %u",
6444 : : hw->func_caps.rss_table_size);
6445 : 0 : pf->hash_lut_size = hw->func_caps.rss_table_size;
6446 : :
6447 : : /* Enable ethtype and macvlan filters */
6448 : 0 : settings.enable_ethtype = TRUE;
6449 : 0 : settings.enable_macvlan = TRUE;
6450 : 0 : ret = i40e_set_filter_control(hw, &settings);
6451 [ # # ]: 0 : if (ret)
6452 : 0 : PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
6453 : : ret);
6454 : :
6455 : : /* Update flow control according to the auto negotiation */
6456 : 0 : i40e_update_flow_control(hw);
6457 : :
6458 : 0 : return I40E_SUCCESS;
6459 : : }
6460 : :
6461 : : int
6462 : 0 : i40e_switch_tx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
6463 : : {
6464 : : uint32_t reg;
6465 : : uint16_t j;
6466 : :
6467 : : /**
6468 : : * Set or clear TX Queue Disable flags,
6469 : : * which is required by hardware.
6470 : : */
6471 : 0 : i40e_pre_tx_queue_cfg(hw, q_idx, on);
6472 : 0 : rte_delay_us(I40E_PRE_TX_Q_CFG_WAIT_US);
6473 : :
6474 : : /* Wait until the request is finished */
6475 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6476 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6477 : 0 : reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
6478 : 0 : if (!(((reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 0x1) ^
6479 [ # # ]: 0 : ((reg >> I40E_QTX_ENA_QENA_STAT_SHIFT)
6480 : : & 0x1))) {
6481 : : break;
6482 : : }
6483 : : }
6484 [ # # ]: 0 : if (on) {
6485 [ # # ]: 0 : if (reg & I40E_QTX_ENA_QENA_STAT_MASK)
6486 : : return I40E_SUCCESS; /* already on, skip next steps */
6487 : :
6488 : 0 : I40E_WRITE_REG(hw, I40E_QTX_HEAD(q_idx), 0);
6489 : 0 : reg |= I40E_QTX_ENA_QENA_REQ_MASK;
6490 : : } else {
6491 [ # # ]: 0 : if (!(reg & I40E_QTX_ENA_QENA_STAT_MASK))
6492 : : return I40E_SUCCESS; /* already off, skip next steps */
6493 : 0 : reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
6494 : : }
6495 : : /* Write the register */
6496 : 0 : I40E_WRITE_REG(hw, I40E_QTX_ENA(q_idx), reg);
6497 : : /* Check the result */
6498 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6499 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6500 : 0 : reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
6501 [ # # ]: 0 : if (on) {
6502 [ # # ]: 0 : if ((reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
6503 : : (reg & I40E_QTX_ENA_QENA_STAT_MASK))
6504 : : break;
6505 : : } else {
6506 [ # # ]: 0 : if (!(reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
6507 : : !(reg & I40E_QTX_ENA_QENA_STAT_MASK))
6508 : : break;
6509 : : }
6510 : : }
6511 : : /* Check if it is timeout */
6512 [ # # ]: 0 : if (j >= I40E_CHK_Q_ENA_COUNT) {
6513 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Failed to %s tx queue[%u]",
6514 : : (on ? "enable" : "disable"), q_idx);
6515 : 0 : return I40E_ERR_TIMEOUT;
6516 : : }
6517 : :
6518 : : return I40E_SUCCESS;
6519 : : }
6520 : :
6521 : : int
6522 : 0 : i40e_switch_rx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
6523 : : {
6524 : : uint32_t reg;
6525 : : uint16_t j;
6526 : :
6527 : : /* Wait until the request is finished */
6528 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6529 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6530 : 0 : reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
6531 : 0 : if (!((reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 0x1) ^
6532 [ # # ]: 0 : ((reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 0x1))
6533 : : break;
6534 : : }
6535 : :
6536 [ # # ]: 0 : if (on) {
6537 [ # # ]: 0 : if (reg & I40E_QRX_ENA_QENA_STAT_MASK)
6538 : : return I40E_SUCCESS; /* Already on, skip next steps */
6539 : 0 : reg |= I40E_QRX_ENA_QENA_REQ_MASK;
6540 : : } else {
6541 [ # # ]: 0 : if (!(reg & I40E_QRX_ENA_QENA_STAT_MASK))
6542 : : return I40E_SUCCESS; /* Already off, skip next steps */
6543 : 0 : reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
6544 : : }
6545 : :
6546 : : /* Write the register */
6547 : 0 : I40E_WRITE_REG(hw, I40E_QRX_ENA(q_idx), reg);
6548 : : /* Check the result */
6549 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6550 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6551 : 0 : reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
6552 [ # # ]: 0 : if (on) {
6553 [ # # ]: 0 : if ((reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
6554 : : (reg & I40E_QRX_ENA_QENA_STAT_MASK))
6555 : : break;
6556 : : } else {
6557 [ # # ]: 0 : if (!(reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
6558 : : !(reg & I40E_QRX_ENA_QENA_STAT_MASK))
6559 : : break;
6560 : : }
6561 : : }
6562 : :
6563 : : /* Check if it is timeout */
6564 [ # # ]: 0 : if (j >= I40E_CHK_Q_ENA_COUNT) {
6565 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Failed to %s rx queue[%u]",
6566 : : (on ? "enable" : "disable"), q_idx);
6567 : 0 : return I40E_ERR_TIMEOUT;
6568 : : }
6569 : :
6570 : : return I40E_SUCCESS;
6571 : : }
6572 : :
6573 : : /* Initialize VSI for TX */
6574 : : static int
6575 : 0 : i40e_dev_tx_init(struct i40e_pf *pf)
6576 : : {
6577 : 0 : struct rte_eth_dev_data *data = pf->dev_data;
6578 : : uint16_t i;
6579 : : uint32_t ret = I40E_SUCCESS;
6580 : : struct i40e_tx_queue *txq;
6581 : :
6582 [ # # ]: 0 : for (i = 0; i < data->nb_tx_queues; i++) {
6583 : 0 : txq = data->tx_queues[i];
6584 [ # # # # ]: 0 : if (!txq || !txq->q_set)
6585 : 0 : continue;
6586 : 0 : ret = i40e_tx_queue_init(txq);
6587 [ # # ]: 0 : if (ret != I40E_SUCCESS)
6588 : : break;
6589 : : }
6590 [ # # ]: 0 : if (ret == I40E_SUCCESS)
6591 : 0 : i40e_set_tx_function(&rte_eth_devices[pf->dev_data->port_id]);
6592 : :
6593 : 0 : return ret;
6594 : : }
6595 : :
6596 : : /* Initialize VSI for RX */
6597 : : static int
6598 : 0 : i40e_dev_rx_init(struct i40e_pf *pf)
6599 : : {
6600 : 0 : struct rte_eth_dev_data *data = pf->dev_data;
6601 : : int ret = I40E_SUCCESS;
6602 : : uint16_t i;
6603 : : struct i40e_rx_queue *rxq;
6604 : :
6605 : 0 : i40e_pf_config_rss(pf);
6606 [ # # ]: 0 : for (i = 0; i < data->nb_rx_queues; i++) {
6607 : 0 : rxq = data->rx_queues[i];
6608 [ # # # # ]: 0 : if (!rxq || !rxq->q_set)
6609 : 0 : continue;
6610 : :
6611 : 0 : ret = i40e_rx_queue_init(rxq);
6612 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6613 : 0 : PMD_DRV_LOG(ERR,
6614 : : "Failed to do RX queue initialization");
6615 : 0 : break;
6616 : : }
6617 : : }
6618 [ # # ]: 0 : if (ret == I40E_SUCCESS)
6619 : 0 : i40e_set_rx_function(&rte_eth_devices[pf->dev_data->port_id]);
6620 : :
6621 : 0 : return ret;
6622 : : }
6623 : :
6624 : : static int
6625 : 0 : i40e_dev_rxtx_init(struct i40e_pf *pf)
6626 : : {
6627 : : int err;
6628 : :
6629 : 0 : err = i40e_dev_tx_init(pf);
6630 [ # # ]: 0 : if (err) {
6631 : 0 : PMD_DRV_LOG(ERR, "Failed to do TX initialization");
6632 : 0 : return err;
6633 : : }
6634 : 0 : err = i40e_dev_rx_init(pf);
6635 [ # # ]: 0 : if (err) {
6636 : 0 : PMD_DRV_LOG(ERR, "Failed to do RX initialization");
6637 : 0 : return err;
6638 : : }
6639 : :
6640 : : return err;
6641 : : }
6642 : :
6643 : : static int
6644 : 0 : i40e_vmdq_setup(struct rte_eth_dev *dev)
6645 : : {
6646 : 0 : struct rte_eth_conf *conf = &dev->data->dev_conf;
6647 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6648 : : int i, err, conf_vsis, j, loop;
6649 : : struct i40e_vsi *vsi;
6650 : : struct i40e_vmdq_info *vmdq_info;
6651 : : struct rte_eth_vmdq_rx_conf *vmdq_conf;
6652 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6653 : :
6654 : : /*
6655 : : * Disable interrupt to avoid message from VF. Furthermore, it will
6656 : : * avoid race condition in VSI creation/destroy.
6657 : : */
6658 : 0 : i40e_pf_disable_irq0(hw);
6659 : :
6660 [ # # ]: 0 : if ((pf->flags & I40E_FLAG_VMDQ) == 0) {
6661 : 0 : PMD_INIT_LOG(ERR, "FW doesn't support VMDQ");
6662 : 0 : return -ENOTSUP;
6663 : : }
6664 : :
6665 : 0 : conf_vsis = conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools;
6666 [ # # ]: 0 : if (conf_vsis > pf->max_nb_vmdq_vsi) {
6667 : 0 : PMD_INIT_LOG(ERR, "VMDQ config: %u, max support:%u",
6668 : : conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools,
6669 : : pf->max_nb_vmdq_vsi);
6670 : 0 : return -ENOTSUP;
6671 : : }
6672 : :
6673 [ # # ]: 0 : if (pf->vmdq != NULL) {
6674 : 0 : PMD_INIT_LOG(INFO, "VMDQ already configured");
6675 : 0 : return 0;
6676 : : }
6677 : :
6678 : 0 : pf->vmdq = rte_zmalloc("vmdq_info_struct",
6679 : : sizeof(*vmdq_info) * conf_vsis, 0);
6680 : :
6681 [ # # ]: 0 : if (pf->vmdq == NULL) {
6682 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory");
6683 : 0 : return -ENOMEM;
6684 : : }
6685 : :
6686 : : vmdq_conf = &conf->rx_adv_conf.vmdq_rx_conf;
6687 : :
6688 : : /* Create VMDQ VSI */
6689 [ # # ]: 0 : for (i = 0; i < conf_vsis; i++) {
6690 : 0 : vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, pf->main_vsi,
6691 : 0 : vmdq_conf->enable_loop_back);
6692 [ # # ]: 0 : if (vsi == NULL) {
6693 : 0 : PMD_INIT_LOG(ERR, "Failed to create VMDQ VSI");
6694 : : err = -1;
6695 : 0 : goto err_vsi_setup;
6696 : : }
6697 : 0 : vmdq_info = &pf->vmdq[i];
6698 : 0 : vmdq_info->pf = pf;
6699 : 0 : vmdq_info->vsi = vsi;
6700 : : }
6701 : 0 : pf->nb_cfg_vmdq_vsi = conf_vsis;
6702 : :
6703 : : /* Configure Vlan */
6704 : : loop = sizeof(vmdq_conf->pool_map[0].pools) * CHAR_BIT;
6705 [ # # ]: 0 : for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
6706 [ # # # # ]: 0 : for (j = 0; j < loop && j < pf->nb_cfg_vmdq_vsi; j++) {
6707 [ # # ]: 0 : if (vmdq_conf->pool_map[i].pools & (1UL << j)) {
6708 : 0 : PMD_INIT_LOG(INFO, "Add vlan %u to vmdq pool %u",
6709 : : vmdq_conf->pool_map[i].vlan_id, j);
6710 : :
6711 : 0 : err = i40e_vsi_add_vlan(pf->vmdq[j].vsi,
6712 : 0 : vmdq_conf->pool_map[i].vlan_id);
6713 [ # # ]: 0 : if (err) {
6714 : 0 : PMD_INIT_LOG(ERR, "Failed to add vlan");
6715 : : err = -1;
6716 : 0 : goto err_vsi_setup;
6717 : : }
6718 : : }
6719 : : }
6720 : : }
6721 : :
6722 : 0 : i40e_pf_enable_irq0(hw);
6723 : :
6724 : 0 : return 0;
6725 : :
6726 : : err_vsi_setup:
6727 [ # # ]: 0 : for (i = 0; i < conf_vsis; i++)
6728 [ # # ]: 0 : if (pf->vmdq[i].vsi == NULL)
6729 : : break;
6730 : : else
6731 : 0 : i40e_vsi_release(pf->vmdq[i].vsi);
6732 : :
6733 : 0 : rte_free(pf->vmdq);
6734 : 0 : pf->vmdq = NULL;
6735 : 0 : i40e_pf_enable_irq0(hw);
6736 : 0 : return err;
6737 : : }
6738 : :
6739 : : static void
6740 : : i40e_stat_update_32(struct i40e_hw *hw,
6741 : : uint32_t reg,
6742 : : bool offset_loaded,
6743 : : uint64_t *offset,
6744 : : uint64_t *stat)
6745 : : {
6746 : : uint64_t new_data;
6747 : :
6748 : 0 : new_data = (uint64_t)I40E_READ_REG(hw, reg);
6749 [ # # # # : 0 : if (!offset_loaded)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
6750 : 0 : *offset = new_data;
6751 : :
6752 [ # # # # : 0 : if (new_data >= *offset)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
6753 : 0 : *stat = (uint64_t)(new_data - *offset);
6754 : : else
6755 : 0 : *stat = (uint64_t)((new_data +
6756 : : ((uint64_t)1 << I40E_32_BIT_WIDTH)) - *offset);
6757 : : }
6758 : :
6759 : : static void
6760 : 0 : i40e_stat_update_48(struct i40e_hw *hw,
6761 : : uint32_t hireg,
6762 : : uint32_t loreg,
6763 : : bool offset_loaded,
6764 : : uint64_t *offset,
6765 : : uint64_t *stat)
6766 : : {
6767 : : uint64_t new_data;
6768 : :
6769 [ # # ]: 0 : if (hw->device_id == I40E_DEV_ID_QEMU) {
6770 : 0 : new_data = (uint64_t)I40E_READ_REG(hw, loreg);
6771 : 0 : new_data |= ((uint64_t)(I40E_READ_REG(hw, hireg) &
6772 : 0 : I40E_16_BIT_MASK)) << I40E_32_BIT_WIDTH;
6773 : : } else {
6774 : 0 : new_data = I40E_READ_REG64(hw, loreg);
6775 : : }
6776 : :
6777 [ # # ]: 0 : if (!offset_loaded)
6778 : 0 : *offset = new_data;
6779 : :
6780 [ # # ]: 0 : if (new_data >= *offset)
6781 : 0 : *stat = new_data - *offset;
6782 : : else
6783 : 0 : *stat = (uint64_t)((new_data +
6784 : : ((uint64_t)1 << I40E_48_BIT_WIDTH)) - *offset);
6785 : :
6786 : 0 : *stat &= I40E_48_BIT_MASK;
6787 : 0 : }
6788 : :
6789 : : /* Disable IRQ0 */
6790 : : void
6791 : 0 : i40e_pf_disable_irq0(struct i40e_hw *hw)
6792 : : {
6793 : : /* Disable all interrupt types */
6794 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
6795 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
6796 : 0 : I40E_WRITE_FLUSH(hw);
6797 : 0 : }
6798 : :
6799 : : /* Enable IRQ0 */
6800 : : void
6801 : 0 : i40e_pf_enable_irq0(struct i40e_hw *hw)
6802 : : {
6803 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
6804 : : I40E_PFINT_DYN_CTL0_INTENA_MASK |
6805 : : I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
6806 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
6807 : 0 : I40E_WRITE_FLUSH(hw);
6808 : 0 : }
6809 : :
6810 : : static void
6811 : : i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue)
6812 : : {
6813 : : /* read pending request and disable first */
6814 : 0 : i40e_pf_disable_irq0(hw);
6815 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_ICR0_ENA, I40E_PFINT_ICR0_ENA_MASK);
6816 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_STAT_CTL0,
6817 : : I40E_PFINT_STAT_CTL0_OTHER_ITR_INDX_MASK);
6818 : :
6819 : : if (no_queue)
6820 : : /* Link no queues with irq0 */
6821 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
6822 : : I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
6823 : : }
6824 : :
6825 : : static void
6826 : 0 : i40e_dev_handle_vfr_event(struct rte_eth_dev *dev)
6827 : : {
6828 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6829 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6830 : : int i;
6831 : : uint16_t abs_vf_id;
6832 : : uint32_t index, offset, val;
6833 : :
6834 [ # # ]: 0 : if (!pf->vfs)
6835 : : return;
6836 : : /**
6837 : : * Try to find which VF trigger a reset, use absolute VF id to access
6838 : : * since the reg is global register.
6839 : : */
6840 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++) {
6841 : 0 : abs_vf_id = hw->func_caps.vf_base_id + i;
6842 : 0 : index = abs_vf_id / I40E_UINT32_BIT_SIZE;
6843 : 0 : offset = abs_vf_id % I40E_UINT32_BIT_SIZE;
6844 : 0 : val = I40E_READ_REG(hw, I40E_GLGEN_VFLRSTAT(index));
6845 : : /* VFR event occurred */
6846 [ # # ]: 0 : if (val & (0x1 << offset)) {
6847 : : int ret;
6848 : :
6849 : : /* Clear the event first */
6850 : 0 : I40E_WRITE_REG(hw, I40E_GLGEN_VFLRSTAT(index),
6851 : : (0x1 << offset));
6852 : 0 : PMD_DRV_LOG(INFO, "VF %u reset occurred", abs_vf_id);
6853 : : /**
6854 : : * Only notify a VF reset event occurred,
6855 : : * don't trigger another SW reset
6856 : : */
6857 : 0 : ret = i40e_pf_host_vf_reset(&pf->vfs[i], 0);
6858 [ # # ]: 0 : if (ret != I40E_SUCCESS)
6859 : 0 : PMD_DRV_LOG(ERR, "Failed to do VF reset");
6860 : : }
6861 : : }
6862 : : }
6863 : :
6864 : : static void
6865 : 0 : i40e_notify_all_vfs_link_status(struct rte_eth_dev *dev)
6866 : : {
6867 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6868 : : int i;
6869 : :
6870 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++)
6871 : 0 : i40e_notify_vf_link_status(dev, &pf->vfs[i]);
6872 : 0 : }
6873 : :
6874 : : static void
6875 : 0 : i40e_dev_handle_aq_msg(struct rte_eth_dev *dev)
6876 : : {
6877 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6878 : : struct i40e_arq_event_info info;
6879 : : uint16_t pending, opcode;
6880 : : int ret;
6881 : :
6882 : 0 : info.buf_len = I40E_AQ_BUF_SZ;
6883 : 0 : info.msg_buf = rte_zmalloc("msg_buffer", info.buf_len, 0);
6884 [ # # ]: 0 : if (!info.msg_buf) {
6885 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate mem");
6886 : 0 : return;
6887 : : }
6888 : :
6889 : 0 : pending = 1;
6890 [ # # ]: 0 : while (pending) {
6891 : 0 : ret = i40e_clean_arq_element(hw, &info, &pending);
6892 : :
6893 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6894 : 0 : PMD_DRV_LOG(INFO,
6895 : : "Failed to read msg from AdminQ, aq_err: %u",
6896 : : hw->aq.asq_last_status);
6897 : 0 : break;
6898 : : }
6899 : 0 : opcode = rte_le_to_cpu_16(info.desc.opcode);
6900 : :
6901 [ # # # ]: 0 : switch (opcode) {
6902 : 0 : case i40e_aqc_opc_send_msg_to_pf:
6903 : : /* Refer to i40e_aq_send_msg_to_pf() for argument layout*/
6904 : 0 : i40e_pf_host_handle_vf_msg(dev,
6905 : 0 : rte_le_to_cpu_16(info.desc.retval),
6906 : : rte_le_to_cpu_32(info.desc.cookie_high),
6907 : : rte_le_to_cpu_32(info.desc.cookie_low),
6908 : 0 : info.msg_buf,
6909 : 0 : info.msg_len);
6910 : 0 : break;
6911 : 0 : case i40e_aqc_opc_get_link_status:
6912 : 0 : ret = i40e_dev_link_update(dev, 0);
6913 [ # # ]: 0 : if (!ret)
6914 : 0 : rte_eth_dev_callback_process(dev,
6915 : : RTE_ETH_EVENT_INTR_LSC, NULL);
6916 : : break;
6917 : 0 : default:
6918 : 0 : PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
6919 : : opcode);
6920 : 0 : break;
6921 : : }
6922 : : }
6923 : 0 : rte_free(info.msg_buf);
6924 : : }
6925 : :
6926 : : static void
6927 : 0 : i40e_handle_mdd_event(struct rte_eth_dev *dev)
6928 : : {
6929 : : #define I40E_MDD_CLEAR32 0xFFFFFFFF
6930 : : #define I40E_MDD_CLEAR16 0xFFFF
6931 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6932 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6933 : : bool mdd_detected = false;
6934 : : struct i40e_pf_vf *vf;
6935 : : uint32_t reg;
6936 : : int i;
6937 : :
6938 : : /* find what triggered the MDD event */
6939 : 0 : reg = I40E_READ_REG(hw, I40E_GL_MDET_TX);
6940 [ # # ]: 0 : if (reg & I40E_GL_MDET_TX_VALID_MASK) {
6941 : 0 : uint8_t pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
6942 : : I40E_GL_MDET_TX_PF_NUM_SHIFT;
6943 : 0 : uint16_t vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
6944 : : I40E_GL_MDET_TX_VF_NUM_SHIFT;
6945 : 0 : uint8_t event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
6946 : : I40E_GL_MDET_TX_EVENT_SHIFT;
6947 : 0 : uint16_t queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
6948 : 0 : I40E_GL_MDET_TX_QUEUE_SHIFT) -
6949 : 0 : hw->func_caps.base_queue;
6950 : 0 : PMD_DRV_LOG(WARNING, "Malicious Driver Detection event 0x%02x on TX "
6951 : : "queue %d PF number 0x%02x VF number 0x%02x device %s\n",
6952 : : event, queue, pf_num, vf_num, dev->data->name);
6953 : 0 : I40E_WRITE_REG(hw, I40E_GL_MDET_TX, I40E_MDD_CLEAR32);
6954 : : mdd_detected = true;
6955 : : }
6956 : 0 : reg = I40E_READ_REG(hw, I40E_GL_MDET_RX);
6957 [ # # ]: 0 : if (reg & I40E_GL_MDET_RX_VALID_MASK) {
6958 : : uint8_t func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
6959 : : I40E_GL_MDET_RX_FUNCTION_SHIFT;
6960 : 0 : uint8_t event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
6961 : : I40E_GL_MDET_RX_EVENT_SHIFT;
6962 : 0 : uint16_t queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
6963 : 0 : I40E_GL_MDET_RX_QUEUE_SHIFT) -
6964 : 0 : hw->func_caps.base_queue;
6965 : :
6966 : 0 : PMD_DRV_LOG(WARNING, "Malicious Driver Detection event 0x%02x on RX "
6967 : : "queue %d of function 0x%02x device %s\n",
6968 : : event, queue, func, dev->data->name);
6969 : 0 : I40E_WRITE_REG(hw, I40E_GL_MDET_RX, I40E_MDD_CLEAR32);
6970 : : mdd_detected = true;
6971 : : }
6972 : :
6973 [ # # ]: 0 : if (mdd_detected) {
6974 : 0 : reg = I40E_READ_REG(hw, I40E_PF_MDET_TX);
6975 [ # # ]: 0 : if (reg & I40E_PF_MDET_TX_VALID_MASK) {
6976 : 0 : I40E_WRITE_REG(hw, I40E_PF_MDET_TX, I40E_MDD_CLEAR16);
6977 : 0 : PMD_DRV_LOG(WARNING, "TX driver issue detected on PF\n");
6978 : : }
6979 : 0 : reg = I40E_READ_REG(hw, I40E_PF_MDET_RX);
6980 [ # # ]: 0 : if (reg & I40E_PF_MDET_RX_VALID_MASK) {
6981 : 0 : I40E_WRITE_REG(hw, I40E_PF_MDET_RX,
6982 : : I40E_MDD_CLEAR16);
6983 : 0 : PMD_DRV_LOG(WARNING, "RX driver issue detected on PF\n");
6984 : : }
6985 : : }
6986 : :
6987 : : /* see if one of the VFs needs its hand slapped */
6988 [ # # # # ]: 0 : for (i = 0; i < pf->vf_num && mdd_detected; i++) {
6989 : 0 : vf = &pf->vfs[i];
6990 : 0 : reg = I40E_READ_REG(hw, I40E_VP_MDET_TX(i));
6991 [ # # ]: 0 : if (reg & I40E_VP_MDET_TX_VALID_MASK) {
6992 : 0 : I40E_WRITE_REG(hw, I40E_VP_MDET_TX(i),
6993 : : I40E_MDD_CLEAR16);
6994 : 0 : vf->num_mdd_events++;
6995 : 0 : PMD_DRV_LOG(WARNING, "TX driver issue detected on VF %d %-"
6996 : : PRIu64 "times\n",
6997 : : i, vf->num_mdd_events);
6998 : : }
6999 : :
7000 : 0 : reg = I40E_READ_REG(hw, I40E_VP_MDET_RX(i));
7001 [ # # ]: 0 : if (reg & I40E_VP_MDET_RX_VALID_MASK) {
7002 : 0 : I40E_WRITE_REG(hw, I40E_VP_MDET_RX(i),
7003 : : I40E_MDD_CLEAR16);
7004 : 0 : vf->num_mdd_events++;
7005 : 0 : PMD_DRV_LOG(WARNING, "RX driver issue detected on VF %d %-"
7006 : : PRIu64 "times\n",
7007 : : i, vf->num_mdd_events);
7008 : : }
7009 : : }
7010 : 0 : }
7011 : :
7012 : : /**
7013 : : * Interrupt handler triggered by NIC for handling
7014 : : * specific interrupt.
7015 : : *
7016 : : * @param handle
7017 : : * Pointer to interrupt handle.
7018 : : * @param param
7019 : : * The address of parameter (struct rte_eth_dev *) registered before.
7020 : : *
7021 : : * @return
7022 : : * void
7023 : : */
7024 : : static void
7025 : 0 : i40e_dev_interrupt_handler(void *param)
7026 : : {
7027 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
7028 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7029 : : uint32_t icr0;
7030 : :
7031 : : /* Disable interrupt */
7032 : 0 : i40e_pf_disable_irq0(hw);
7033 : :
7034 : : /* read out interrupt causes */
7035 : 0 : icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
7036 : :
7037 : : /* No interrupt event indicated */
7038 [ # # ]: 0 : if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK)) {
7039 : 0 : PMD_DRV_LOG(INFO, "No interrupt event");
7040 : 0 : goto done;
7041 : : }
7042 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
7043 : 0 : PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
7044 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
7045 : 0 : PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
7046 : 0 : i40e_handle_mdd_event(dev);
7047 : : }
7048 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
7049 : 0 : PMD_DRV_LOG(INFO, "ICR0: global reset requested");
7050 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
7051 : 0 : PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
7052 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
7053 : 0 : PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
7054 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
7055 : 0 : PMD_DRV_LOG(ERR, "ICR0: HMC error");
7056 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
7057 : 0 : PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
7058 : :
7059 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
7060 : 0 : PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
7061 : 0 : i40e_dev_handle_vfr_event(dev);
7062 : : }
7063 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
7064 : 0 : PMD_DRV_LOG(INFO, "ICR0: adminq event");
7065 : 0 : i40e_dev_handle_aq_msg(dev);
7066 : : }
7067 : :
7068 : 0 : done:
7069 : : /* Enable interrupt */
7070 : 0 : i40e_pf_enable_irq0(hw);
7071 : 0 : }
7072 : :
7073 : : static void
7074 : 0 : i40e_dev_alarm_handler(void *param)
7075 : : {
7076 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
7077 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7078 : : uint32_t icr0;
7079 : :
7080 : : /* Disable interrupt */
7081 : 0 : i40e_pf_disable_irq0(hw);
7082 : :
7083 : : /* read out interrupt causes */
7084 : 0 : icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
7085 : :
7086 : : /* No interrupt event indicated */
7087 [ # # ]: 0 : if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK))
7088 : 0 : goto done;
7089 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
7090 : 0 : PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
7091 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
7092 : 0 : PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
7093 : 0 : i40e_handle_mdd_event(dev);
7094 : : }
7095 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
7096 : 0 : PMD_DRV_LOG(INFO, "ICR0: global reset requested");
7097 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
7098 : 0 : PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
7099 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
7100 : 0 : PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
7101 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
7102 : 0 : PMD_DRV_LOG(ERR, "ICR0: HMC error");
7103 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
7104 : 0 : PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
7105 : :
7106 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
7107 : 0 : PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
7108 : 0 : i40e_dev_handle_vfr_event(dev);
7109 : : }
7110 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
7111 : 0 : PMD_DRV_LOG(INFO, "ICR0: adminq event");
7112 : 0 : i40e_dev_handle_aq_msg(dev);
7113 : : }
7114 : :
7115 : 0 : done:
7116 : : /* Enable interrupt */
7117 : 0 : i40e_pf_enable_irq0(hw);
7118 : 0 : rte_eal_alarm_set(I40E_ALARM_INTERVAL,
7119 : : i40e_dev_alarm_handler, dev);
7120 : 0 : }
7121 : :
7122 : : int
7123 : 0 : i40e_add_macvlan_filters(struct i40e_vsi *vsi,
7124 : : struct i40e_macvlan_filter *filter,
7125 : : int total)
7126 : : {
7127 : : int ele_num, ele_buff_size;
7128 : : int num, actual_num, i;
7129 : : uint16_t flags;
7130 : : int ret = I40E_SUCCESS;
7131 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7132 : : struct i40e_aqc_add_macvlan_element_data *req_list;
7133 : :
7134 [ # # ]: 0 : if (filter == NULL || total == 0)
7135 : : return I40E_ERR_PARAM;
7136 : 0 : ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
7137 : : ele_buff_size = hw->aq.asq_buf_size;
7138 : :
7139 : 0 : req_list = rte_zmalloc("macvlan_add", ele_buff_size, 0);
7140 [ # # ]: 0 : if (req_list == NULL) {
7141 : 0 : PMD_DRV_LOG(ERR, "Fail to allocate memory");
7142 : 0 : return I40E_ERR_NO_MEMORY;
7143 : : }
7144 : :
7145 : : num = 0;
7146 : : do {
7147 [ # # ]: 0 : actual_num = (num + ele_num > total) ? (total - num) : ele_num;
7148 : : memset(req_list, 0, ele_buff_size);
7149 : :
7150 [ # # ]: 0 : for (i = 0; i < actual_num; i++) {
7151 : 0 : rte_memcpy(req_list[i].mac_addr,
7152 [ # # ]: 0 : &filter[num + i].macaddr, ETH_ADDR_LEN);
7153 : 0 : req_list[i].vlan_tag =
7154 : 0 : rte_cpu_to_le_16(filter[num + i].vlan_id);
7155 : :
7156 [ # # ]: 0 : switch (filter[num + i].filter_type) {
7157 : : case I40E_MAC_PERFECT_MATCH:
7158 : : flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH |
7159 : : I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
7160 : : break;
7161 : : case I40E_MACVLAN_PERFECT_MATCH:
7162 : : flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
7163 : : break;
7164 : : case I40E_MAC_HASH_MATCH:
7165 : : flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH |
7166 : : I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
7167 : : break;
7168 : : case I40E_MACVLAN_HASH_MATCH:
7169 : : flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH;
7170 : : break;
7171 : 0 : default:
7172 : 0 : PMD_DRV_LOG(ERR, "Invalid MAC match type");
7173 : : ret = I40E_ERR_PARAM;
7174 : 0 : goto DONE;
7175 : : }
7176 : :
7177 : 0 : req_list[i].queue_number = 0;
7178 : :
7179 : 0 : req_list[i].flags = rte_cpu_to_le_16(flags);
7180 : : }
7181 : :
7182 : 0 : ret = i40e_aq_add_macvlan(hw, vsi->seid, req_list,
7183 : : actual_num, NULL);
7184 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
7185 : 0 : PMD_DRV_LOG(ERR, "Failed to add macvlan filter");
7186 : 0 : goto DONE;
7187 : : }
7188 : 0 : num += actual_num;
7189 [ # # ]: 0 : } while (num < total);
7190 : :
7191 : 0 : DONE:
7192 : 0 : rte_free(req_list);
7193 : 0 : return ret;
7194 : : }
7195 : :
7196 : : int
7197 : 0 : i40e_remove_macvlan_filters(struct i40e_vsi *vsi,
7198 : : struct i40e_macvlan_filter *filter,
7199 : : int total)
7200 : : {
7201 : : int ele_num, ele_buff_size;
7202 : : int num, actual_num, i;
7203 : : uint16_t flags;
7204 : : int ret = I40E_SUCCESS;
7205 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7206 : : struct i40e_aqc_remove_macvlan_element_data *req_list;
7207 : : enum i40e_admin_queue_err aq_status;
7208 : :
7209 [ # # ]: 0 : if (filter == NULL || total == 0)
7210 : : return I40E_ERR_PARAM;
7211 : :
7212 : 0 : ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
7213 : : ele_buff_size = hw->aq.asq_buf_size;
7214 : :
7215 : 0 : req_list = rte_zmalloc("macvlan_remove", ele_buff_size, 0);
7216 [ # # ]: 0 : if (req_list == NULL) {
7217 : 0 : PMD_DRV_LOG(ERR, "Fail to allocate memory");
7218 : 0 : return I40E_ERR_NO_MEMORY;
7219 : : }
7220 : :
7221 : : num = 0;
7222 : : do {
7223 [ # # ]: 0 : actual_num = (num + ele_num > total) ? (total - num) : ele_num;
7224 : : memset(req_list, 0, ele_buff_size);
7225 : :
7226 [ # # ]: 0 : for (i = 0; i < actual_num; i++) {
7227 : 0 : rte_memcpy(req_list[i].mac_addr,
7228 [ # # ]: 0 : &filter[num + i].macaddr, ETH_ADDR_LEN);
7229 : 0 : req_list[i].vlan_tag =
7230 : 0 : rte_cpu_to_le_16(filter[num + i].vlan_id);
7231 : :
7232 [ # # ]: 0 : switch (filter[num + i].filter_type) {
7233 : : case I40E_MAC_PERFECT_MATCH:
7234 : : flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
7235 : : I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
7236 : : break;
7237 : : case I40E_MACVLAN_PERFECT_MATCH:
7238 : : flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
7239 : : break;
7240 : : case I40E_MAC_HASH_MATCH:
7241 : : flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH |
7242 : : I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
7243 : : break;
7244 : : case I40E_MACVLAN_HASH_MATCH:
7245 : : flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH;
7246 : : break;
7247 : 0 : default:
7248 : 0 : PMD_DRV_LOG(ERR, "Invalid MAC filter type");
7249 : : ret = I40E_ERR_PARAM;
7250 : 0 : goto DONE;
7251 : : }
7252 : 0 : req_list[i].flags = rte_cpu_to_le_16(flags);
7253 : : }
7254 : :
7255 : 0 : ret = i40e_aq_remove_macvlan_v2(hw, vsi->seid, req_list,
7256 : : actual_num, NULL, &aq_status);
7257 : :
7258 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
7259 : : /* Do not report as an error when firmware returns ENOENT */
7260 [ # # ]: 0 : if (aq_status == I40E_AQ_RC_ENOENT) {
7261 : : ret = I40E_SUCCESS;
7262 : : } else {
7263 : 0 : PMD_DRV_LOG(ERR, "Failed to remove macvlan filter");
7264 : 0 : goto DONE;
7265 : : }
7266 : : }
7267 : 0 : num += actual_num;
7268 [ # # ]: 0 : } while (num < total);
7269 : :
7270 : 0 : DONE:
7271 : 0 : rte_free(req_list);
7272 : 0 : return ret;
7273 : : }
7274 : :
7275 : : /* Find out specific MAC filter */
7276 : : static struct i40e_mac_filter *
7277 : : i40e_find_mac_filter(struct i40e_vsi *vsi,
7278 : : struct rte_ether_addr *macaddr)
7279 : : {
7280 : : struct i40e_mac_filter *f;
7281 : :
7282 [ # # # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7283 [ # # # # ]: 0 : if (rte_is_same_ether_addr(macaddr, &f->mac_info.mac_addr))
7284 : : return f;
7285 : : }
7286 : :
7287 : : return NULL;
7288 : : }
7289 : :
7290 : : static bool
7291 : : i40e_find_vlan_filter(struct i40e_vsi *vsi,
7292 : : uint16_t vlan_id)
7293 : : {
7294 : : uint32_t vid_idx, vid_bit;
7295 : :
7296 : : if (vlan_id > RTE_ETH_VLAN_ID_MAX)
7297 : : return 0;
7298 : :
7299 : 0 : vid_idx = I40E_VFTA_IDX(vlan_id);
7300 : 0 : vid_bit = I40E_VFTA_BIT(vlan_id);
7301 : :
7302 : 0 : if (vsi->vfta[vid_idx] & vid_bit)
7303 : : return 1;
7304 : : else
7305 : : return 0;
7306 : : }
7307 : :
7308 : : static void
7309 : : i40e_store_vlan_filter(struct i40e_vsi *vsi,
7310 : : uint16_t vlan_id, bool on)
7311 : : {
7312 : : uint32_t vid_idx, vid_bit;
7313 : :
7314 : 0 : vid_idx = I40E_VFTA_IDX(vlan_id);
7315 : 0 : vid_bit = I40E_VFTA_BIT(vlan_id);
7316 : :
7317 [ # # ]: 0 : if (on)
7318 : 0 : vsi->vfta[vid_idx] |= vid_bit;
7319 : : else
7320 : 0 : vsi->vfta[vid_idx] &= ~vid_bit;
7321 : : }
7322 : :
7323 : : void
7324 : 0 : i40e_set_vlan_filter(struct i40e_vsi *vsi,
7325 : : uint16_t vlan_id, bool on)
7326 : : {
7327 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7328 : 0 : struct i40e_aqc_add_remove_vlan_element_data vlan_data = {0};
7329 : : int ret;
7330 : :
7331 [ # # ]: 0 : if (vlan_id > RTE_ETH_VLAN_ID_MAX)
7332 : 0 : return;
7333 : :
7334 : : i40e_store_vlan_filter(vsi, vlan_id, on);
7335 : :
7336 [ # # # # : 0 : if ((!vsi->vlan_anti_spoof_on && !vsi->vlan_filter_on) || !vlan_id)
# # ]
7337 : : return;
7338 : :
7339 : 0 : vlan_data.vlan_tag = rte_cpu_to_le_16(vlan_id);
7340 : :
7341 [ # # ]: 0 : if (on) {
7342 : 0 : ret = i40e_aq_add_vlan(hw, vsi->seid,
7343 : : &vlan_data, 1, NULL);
7344 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7345 : 0 : PMD_DRV_LOG(ERR, "Failed to add vlan filter");
7346 : : } else {
7347 : 0 : ret = i40e_aq_remove_vlan(hw, vsi->seid,
7348 : : &vlan_data, 1, NULL);
7349 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7350 : 0 : PMD_DRV_LOG(ERR,
7351 : : "Failed to remove vlan filter");
7352 : : }
7353 : : }
7354 : :
7355 : : /**
7356 : : * Find all vlan options for specific mac addr,
7357 : : * return with actual vlan found.
7358 : : */
7359 : : int
7360 : 0 : i40e_find_all_vlan_for_mac(struct i40e_vsi *vsi,
7361 : : struct i40e_macvlan_filter *mv_f,
7362 : : int num, struct rte_ether_addr *addr)
7363 : : {
7364 : : int i;
7365 : : uint32_t j, k;
7366 : :
7367 : : /**
7368 : : * Not to use i40e_find_vlan_filter to decrease the loop time,
7369 : : * although the code looks complex.
7370 : : */
7371 [ # # ]: 0 : if (num < vsi->vlan_num)
7372 : : return I40E_ERR_PARAM;
7373 : :
7374 : : i = 0;
7375 [ # # ]: 0 : for (j = 0; j < I40E_VFTA_SIZE; j++) {
7376 [ # # ]: 0 : if (vsi->vfta[j]) {
7377 [ # # ]: 0 : for (k = 0; k < I40E_UINT32_BIT_SIZE; k++) {
7378 [ # # ]: 0 : if (vsi->vfta[j] & (1 << k)) {
7379 [ # # ]: 0 : if (i > num - 1) {
7380 : 0 : PMD_DRV_LOG(ERR,
7381 : : "vlan number doesn't match");
7382 : 0 : return I40E_ERR_PARAM;
7383 : : }
7384 [ # # ]: 0 : rte_memcpy(&mv_f[i].macaddr,
7385 : : addr, ETH_ADDR_LEN);
7386 : 0 : mv_f[i].vlan_id =
7387 : 0 : j * I40E_UINT32_BIT_SIZE + k;
7388 : 0 : i++;
7389 : : }
7390 : : }
7391 : : }
7392 : : }
7393 : : return I40E_SUCCESS;
7394 : : }
7395 : :
7396 : : static inline int
7397 : 0 : i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
7398 : : struct i40e_macvlan_filter *mv_f,
7399 : : int num,
7400 : : uint16_t vlan)
7401 : : {
7402 : : int i = 0;
7403 : : struct i40e_mac_filter *f;
7404 : :
7405 [ # # ]: 0 : if (num < vsi->mac_num)
7406 : : return I40E_ERR_PARAM;
7407 : :
7408 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7409 [ # # ]: 0 : if (i > num - 1) {
7410 : 0 : PMD_DRV_LOG(ERR, "buffer number not match");
7411 : 0 : return I40E_ERR_PARAM;
7412 : : }
7413 [ # # ]: 0 : rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
7414 : : ETH_ADDR_LEN);
7415 : 0 : mv_f[i].vlan_id = vlan;
7416 : 0 : mv_f[i].filter_type = f->mac_info.filter_type;
7417 : 0 : i++;
7418 : : }
7419 : :
7420 : : return I40E_SUCCESS;
7421 : : }
7422 : :
7423 : : static int
7424 : 0 : i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi)
7425 : : {
7426 : : int i, j, num;
7427 : : struct i40e_mac_filter *f;
7428 : : struct i40e_macvlan_filter *mv_f;
7429 : : int ret = I40E_SUCCESS;
7430 : :
7431 [ # # # # ]: 0 : if (vsi == NULL || vsi->mac_num == 0)
7432 : : return I40E_ERR_PARAM;
7433 : :
7434 : : /* Case that no vlan is set */
7435 [ # # ]: 0 : if (vsi->vlan_num == 0)
7436 : 0 : num = vsi->mac_num;
7437 : : else
7438 : 0 : num = vsi->mac_num * vsi->vlan_num;
7439 : :
7440 : 0 : mv_f = rte_zmalloc("macvlan_data", num * sizeof(*mv_f), 0);
7441 [ # # ]: 0 : if (mv_f == NULL) {
7442 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7443 : 0 : return I40E_ERR_NO_MEMORY;
7444 : : }
7445 : :
7446 : : i = 0;
7447 [ # # ]: 0 : if (vsi->vlan_num == 0) {
7448 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7449 : 0 : rte_memcpy(&mv_f[i].macaddr,
7450 [ # # ]: 0 : &f->mac_info.mac_addr, ETH_ADDR_LEN);
7451 : 0 : mv_f[i].filter_type = f->mac_info.filter_type;
7452 : 0 : mv_f[i].vlan_id = 0;
7453 : 0 : i++;
7454 : : }
7455 : : } else {
7456 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7457 : 0 : ret = i40e_find_all_vlan_for_mac(vsi,&mv_f[i],
7458 : 0 : vsi->vlan_num, &f->mac_info.mac_addr);
7459 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7460 : 0 : goto DONE;
7461 [ # # ]: 0 : for (j = i; j < i + vsi->vlan_num; j++)
7462 : 0 : mv_f[j].filter_type = f->mac_info.filter_type;
7463 : : i += vsi->vlan_num;
7464 : : }
7465 : : }
7466 : :
7467 : 0 : ret = i40e_remove_macvlan_filters(vsi, mv_f, num);
7468 : 0 : DONE:
7469 : 0 : rte_free(mv_f);
7470 : :
7471 : 0 : return ret;
7472 : : }
7473 : :
7474 : : int
7475 : 0 : i40e_vsi_add_vlan(struct i40e_vsi *vsi, uint16_t vlan)
7476 : : {
7477 : : struct i40e_macvlan_filter *mv_f;
7478 : : int mac_num;
7479 : : int ret = I40E_SUCCESS;
7480 : :
7481 [ # # ]: 0 : if (!vsi || vlan > RTE_ETHER_MAX_VLAN_ID)
7482 : : return I40E_ERR_PARAM;
7483 : :
7484 : : /* If it's already set, just return */
7485 [ # # ]: 0 : if (i40e_find_vlan_filter(vsi,vlan))
7486 : : return I40E_SUCCESS;
7487 : :
7488 : 0 : mac_num = vsi->mac_num;
7489 : :
7490 [ # # ]: 0 : if (mac_num == 0) {
7491 : 0 : PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
7492 : 0 : return I40E_ERR_PARAM;
7493 : : }
7494 : :
7495 : 0 : mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
7496 : :
7497 [ # # ]: 0 : if (mv_f == NULL) {
7498 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7499 : 0 : return I40E_ERR_NO_MEMORY;
7500 : : }
7501 : :
7502 : 0 : ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
7503 : :
7504 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7505 : 0 : goto DONE;
7506 : :
7507 : 0 : ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
7508 : :
7509 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7510 : 0 : goto DONE;
7511 : :
7512 : 0 : i40e_set_vlan_filter(vsi, vlan, 1);
7513 : :
7514 : 0 : vsi->vlan_num++;
7515 : : ret = I40E_SUCCESS;
7516 : 0 : DONE:
7517 : 0 : rte_free(mv_f);
7518 : 0 : return ret;
7519 : : }
7520 : :
7521 : : int
7522 : 0 : i40e_vsi_delete_vlan(struct i40e_vsi *vsi, uint16_t vlan)
7523 : : {
7524 : : struct i40e_macvlan_filter *mv_f;
7525 : : int mac_num;
7526 : : int ret = I40E_SUCCESS;
7527 : :
7528 : : /**
7529 : : * Vlan 0 is the generic filter for untagged packets
7530 : : * and can't be removed.
7531 : : */
7532 [ # # # # ]: 0 : if (!vsi || vlan == 0 || vlan > RTE_ETHER_MAX_VLAN_ID)
7533 : : return I40E_ERR_PARAM;
7534 : :
7535 : : /* If can't find it, just return */
7536 [ # # ]: 0 : if (!i40e_find_vlan_filter(vsi, vlan))
7537 : : return I40E_ERR_PARAM;
7538 : :
7539 : 0 : mac_num = vsi->mac_num;
7540 : :
7541 [ # # ]: 0 : if (mac_num == 0) {
7542 : 0 : PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
7543 : 0 : return I40E_ERR_PARAM;
7544 : : }
7545 : :
7546 : 0 : mv_f = rte_zmalloc("macvlan_data", mac_num * sizeof(*mv_f), 0);
7547 : :
7548 [ # # ]: 0 : if (mv_f == NULL) {
7549 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7550 : 0 : return I40E_ERR_NO_MEMORY;
7551 : : }
7552 : :
7553 : 0 : ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
7554 : :
7555 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7556 : 0 : goto DONE;
7557 : :
7558 : 0 : ret = i40e_remove_macvlan_filters(vsi, mv_f, mac_num);
7559 : :
7560 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7561 : 0 : goto DONE;
7562 : :
7563 : : /* This is last vlan to remove, replace all mac filter with vlan 0 */
7564 [ # # ]: 0 : if (vsi->vlan_num == 1) {
7565 : 0 : ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, 0);
7566 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7567 : 0 : goto DONE;
7568 : :
7569 : 0 : ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
7570 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7571 : 0 : goto DONE;
7572 : : }
7573 : :
7574 : 0 : i40e_set_vlan_filter(vsi, vlan, 0);
7575 : :
7576 : 0 : vsi->vlan_num--;
7577 : : ret = I40E_SUCCESS;
7578 : 0 : DONE:
7579 : 0 : rte_free(mv_f);
7580 : 0 : return ret;
7581 : : }
7582 : :
7583 : : int
7584 : 0 : i40e_vsi_add_mac(struct i40e_vsi *vsi, struct i40e_mac_filter_info *mac_filter)
7585 : : {
7586 : : struct i40e_mac_filter *f;
7587 : : struct i40e_macvlan_filter *mv_f;
7588 : : int i, vlan_num = 0;
7589 : : int ret = I40E_SUCCESS;
7590 : :
7591 : : /* If it's add and we've config it, return */
7592 : : f = i40e_find_mac_filter(vsi, &mac_filter->mac_addr);
7593 [ # # ]: 0 : if (f != NULL)
7594 : : return I40E_SUCCESS;
7595 [ # # ]: 0 : if (mac_filter->filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7596 : : mac_filter->filter_type == I40E_MACVLAN_HASH_MATCH) {
7597 : :
7598 : : /**
7599 : : * If vlan_num is 0, that's the first time to add mac,
7600 : : * set mask for vlan_id 0.
7601 : : */
7602 [ # # ]: 0 : if (vsi->vlan_num == 0) {
7603 : 0 : i40e_set_vlan_filter(vsi, 0, 1);
7604 : 0 : vsi->vlan_num = 1;
7605 : : }
7606 : 0 : vlan_num = vsi->vlan_num;
7607 [ # # ]: 0 : } else if (mac_filter->filter_type == I40E_MAC_PERFECT_MATCH ||
7608 : : mac_filter->filter_type == I40E_MAC_HASH_MATCH)
7609 : : vlan_num = 1;
7610 : :
7611 : 0 : mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
7612 [ # # ]: 0 : if (mv_f == NULL) {
7613 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7614 : 0 : return I40E_ERR_NO_MEMORY;
7615 : : }
7616 : :
7617 [ # # ]: 0 : for (i = 0; i < vlan_num; i++) {
7618 : 0 : mv_f[i].filter_type = mac_filter->filter_type;
7619 [ # # ]: 0 : rte_memcpy(&mv_f[i].macaddr, &mac_filter->mac_addr,
7620 : : ETH_ADDR_LEN);
7621 : : }
7622 : :
7623 [ # # ]: 0 : if (mac_filter->filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7624 : : mac_filter->filter_type == I40E_MACVLAN_HASH_MATCH) {
7625 : 0 : ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
7626 : : &mac_filter->mac_addr);
7627 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7628 : 0 : goto DONE;
7629 : : }
7630 : :
7631 : 0 : ret = i40e_add_macvlan_filters(vsi, mv_f, vlan_num);
7632 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7633 : 0 : goto DONE;
7634 : :
7635 : : /* Add the mac addr into mac list */
7636 : 0 : f = rte_zmalloc("macv_filter", sizeof(*f), 0);
7637 [ # # ]: 0 : if (f == NULL) {
7638 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7639 : : ret = I40E_ERR_NO_MEMORY;
7640 : 0 : goto DONE;
7641 : : }
7642 [ # # ]: 0 : rte_memcpy(&f->mac_info.mac_addr, &mac_filter->mac_addr,
7643 : : ETH_ADDR_LEN);
7644 : 0 : f->mac_info.filter_type = mac_filter->filter_type;
7645 : 0 : TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
7646 : 0 : vsi->mac_num++;
7647 : :
7648 : : ret = I40E_SUCCESS;
7649 : 0 : DONE:
7650 : 0 : rte_free(mv_f);
7651 : :
7652 : 0 : return ret;
7653 : : }
7654 : :
7655 : : int
7656 : 0 : i40e_vsi_delete_mac(struct i40e_vsi *vsi, struct rte_ether_addr *addr)
7657 : : {
7658 : : struct i40e_mac_filter *f;
7659 : : struct i40e_macvlan_filter *mv_f;
7660 : : int i, vlan_num;
7661 : : enum i40e_mac_filter_type filter_type;
7662 : : int ret = I40E_SUCCESS;
7663 : :
7664 : : /* Can't find it, return an error */
7665 : : f = i40e_find_mac_filter(vsi, addr);
7666 [ # # ]: 0 : if (f == NULL)
7667 : : return I40E_ERR_PARAM;
7668 : :
7669 : 0 : vlan_num = vsi->vlan_num;
7670 : 0 : filter_type = f->mac_info.filter_type;
7671 : 0 : if (filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7672 [ # # ]: 0 : filter_type == I40E_MACVLAN_HASH_MATCH) {
7673 [ # # ]: 0 : if (vlan_num == 0) {
7674 : 0 : PMD_DRV_LOG(ERR, "VLAN number shouldn't be 0");
7675 : 0 : return I40E_ERR_PARAM;
7676 : : }
7677 : 0 : } else if (filter_type == I40E_MAC_PERFECT_MATCH ||
7678 [ # # ]: 0 : filter_type == I40E_MAC_HASH_MATCH)
7679 : : vlan_num = 1;
7680 : :
7681 : 0 : mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
7682 [ # # ]: 0 : if (mv_f == NULL) {
7683 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7684 : 0 : return I40E_ERR_NO_MEMORY;
7685 : : }
7686 : :
7687 [ # # ]: 0 : for (i = 0; i < vlan_num; i++) {
7688 : 0 : mv_f[i].filter_type = filter_type;
7689 [ # # ]: 0 : rte_memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
7690 : : ETH_ADDR_LEN);
7691 : : }
7692 [ # # ]: 0 : if (filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7693 : : filter_type == I40E_MACVLAN_HASH_MATCH) {
7694 : 0 : ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num, addr);
7695 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7696 : 0 : goto DONE;
7697 : : }
7698 : :
7699 : 0 : ret = i40e_remove_macvlan_filters(vsi, mv_f, vlan_num);
7700 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7701 : 0 : goto DONE;
7702 : :
7703 : : /* Remove the mac addr into mac list */
7704 [ # # ]: 0 : TAILQ_REMOVE(&vsi->mac_list, f, next);
7705 : 0 : rte_free(f);
7706 : 0 : vsi->mac_num--;
7707 : :
7708 : : ret = I40E_SUCCESS;
7709 : 0 : DONE:
7710 : 0 : rte_free(mv_f);
7711 : 0 : return ret;
7712 : : }
7713 : :
7714 : : /* Configure hash enable flags for RSS */
7715 : : uint64_t
7716 : 0 : i40e_config_hena(const struct i40e_adapter *adapter, uint64_t flags)
7717 : : {
7718 : : uint64_t hena = 0;
7719 : : int i;
7720 : :
7721 [ # # ]: 0 : if (!flags)
7722 : : return hena;
7723 : :
7724 [ # # ]: 0 : for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < I40E_FLOW_TYPE_MAX; i++) {
7725 [ # # ]: 0 : if (flags & (1ULL << i))
7726 : 0 : hena |= adapter->pctypes_tbl[i];
7727 : : }
7728 : :
7729 : : return hena;
7730 : : }
7731 : :
7732 : : /* Parse the hash enable flags */
7733 : : uint64_t
7734 : 0 : i40e_parse_hena(const struct i40e_adapter *adapter, uint64_t flags)
7735 : : {
7736 : : uint64_t rss_hf = 0;
7737 : :
7738 [ # # ]: 0 : if (!flags)
7739 : : return rss_hf;
7740 : : int i;
7741 : :
7742 [ # # ]: 0 : for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < I40E_FLOW_TYPE_MAX; i++) {
7743 [ # # ]: 0 : if (flags & adapter->pctypes_tbl[i])
7744 : 0 : rss_hf |= (1ULL << i);
7745 : : }
7746 : : return rss_hf;
7747 : : }
7748 : :
7749 : : /* Disable RSS */
7750 : : void
7751 : 0 : i40e_pf_disable_rss(struct i40e_pf *pf)
7752 : : {
7753 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7754 : :
7755 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
7756 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
7757 : 0 : I40E_WRITE_FLUSH(hw);
7758 : 0 : }
7759 : :
7760 : : int
7761 : 0 : i40e_set_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t key_len)
7762 : : {
7763 : 0 : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
7764 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7765 : : uint16_t key_idx = (vsi->type == I40E_VSI_SRIOV) ?
7766 : : I40E_VFQF_HKEY_MAX_INDEX :
7767 : : I40E_PFQF_HKEY_MAX_INDEX;
7768 : :
7769 [ # # ]: 0 : if (!key || key_len == 0) {
7770 : 0 : PMD_DRV_LOG(DEBUG, "No key to be configured");
7771 : 0 : return 0;
7772 [ # # ]: 0 : } else if (key_len != (key_idx + 1) *
7773 : : sizeof(uint32_t)) {
7774 : 0 : PMD_DRV_LOG(ERR, "Invalid key length %u", key_len);
7775 : 0 : return -EINVAL;
7776 : : }
7777 : :
7778 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
7779 : : struct i40e_aqc_get_set_rss_key_data *key_dw =
7780 : : (struct i40e_aqc_get_set_rss_key_data *)key;
7781 : : enum i40e_status_code status =
7782 : 0 : i40e_aq_set_rss_key(hw, vsi->vsi_id, key_dw);
7783 : :
7784 [ # # ]: 0 : if (status) {
7785 : 0 : PMD_DRV_LOG(ERR,
7786 : : "Failed to configure RSS key via AQ, error status: %d",
7787 : : status);
7788 : 0 : return -EIO;
7789 : : }
7790 : : } else {
7791 : : uint32_t *hash_key = (uint32_t *)key;
7792 : : uint16_t i;
7793 : :
7794 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
7795 [ # # ]: 0 : for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
7796 : 0 : I40E_WRITE_REG(
7797 : : hw,
7798 : : I40E_VFQF_HKEY1(i, vsi->user_param),
7799 : : hash_key[i]);
7800 : :
7801 : : } else {
7802 [ # # ]: 0 : for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
7803 : 0 : I40E_WRITE_REG(hw, I40E_PFQF_HKEY(i),
7804 : : hash_key[i]);
7805 : : }
7806 : 0 : I40E_WRITE_FLUSH(hw);
7807 : : }
7808 : :
7809 : : return 0;
7810 : : }
7811 : :
7812 : : static int
7813 : 0 : i40e_get_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t *key_len)
7814 : : {
7815 : 0 : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
7816 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7817 : : uint32_t reg;
7818 : : int ret;
7819 : :
7820 [ # # ]: 0 : if (!key || !key_len)
7821 : : return 0;
7822 : :
7823 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
7824 : 0 : ret = i40e_aq_get_rss_key(hw, vsi->vsi_id,
7825 : : (struct i40e_aqc_get_set_rss_key_data *)key);
7826 [ # # ]: 0 : if (ret) {
7827 : 0 : PMD_INIT_LOG(ERR, "Failed to get RSS key via AQ");
7828 : 0 : return ret;
7829 : : }
7830 : : } else {
7831 : : uint32_t *key_dw = (uint32_t *)key;
7832 : : uint16_t i;
7833 : :
7834 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
7835 [ # # ]: 0 : for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++) {
7836 : 0 : reg = I40E_VFQF_HKEY1(i, vsi->user_param);
7837 : 0 : key_dw[i] = i40e_read_rx_ctl(hw, reg);
7838 : : }
7839 : 0 : *key_len = (I40E_VFQF_HKEY_MAX_INDEX + 1) *
7840 : : sizeof(uint32_t);
7841 : : } else {
7842 [ # # ]: 0 : for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
7843 : 0 : reg = I40E_PFQF_HKEY(i);
7844 : 0 : key_dw[i] = i40e_read_rx_ctl(hw, reg);
7845 : : }
7846 : 0 : *key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
7847 : : sizeof(uint32_t);
7848 : : }
7849 : : }
7850 : : return 0;
7851 : : }
7852 : :
7853 : : static int
7854 : 0 : i40e_hw_rss_hash_set(struct i40e_pf *pf, struct rte_eth_rss_conf *rss_conf)
7855 : : {
7856 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7857 : : uint64_t hena;
7858 : : int ret;
7859 : :
7860 : 0 : ret = i40e_set_rss_key(pf->main_vsi, rss_conf->rss_key,
7861 : 0 : rss_conf->rss_key_len);
7862 [ # # ]: 0 : if (ret)
7863 : : return ret;
7864 : :
7865 : 0 : hena = i40e_config_hena(pf->adapter, rss_conf->rss_hf);
7866 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
7867 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
7868 : 0 : I40E_WRITE_FLUSH(hw);
7869 : :
7870 : 0 : return 0;
7871 : : }
7872 : :
7873 : : static int
7874 : 0 : i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
7875 : : struct rte_eth_rss_conf *rss_conf)
7876 : : {
7877 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7878 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7879 : 0 : uint64_t rss_hf = rss_conf->rss_hf & pf->adapter->flow_types_mask;
7880 : : uint64_t hena;
7881 : :
7882 : 0 : hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
7883 : 0 : hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
7884 : :
7885 [ # # ]: 0 : if (!(hena & pf->adapter->pctypes_mask)) { /* RSS disabled */
7886 [ # # ]: 0 : if (rss_hf != 0) /* Enable RSS */
7887 : : return -EINVAL;
7888 : 0 : return 0; /* Nothing to do */
7889 : : }
7890 : : /* RSS enabled */
7891 [ # # ]: 0 : if (rss_hf == 0) /* Disable RSS */
7892 : : return -EINVAL;
7893 : :
7894 : 0 : return i40e_hw_rss_hash_set(pf, rss_conf);
7895 : : }
7896 : :
7897 : : static int
7898 : 0 : i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
7899 : : struct rte_eth_rss_conf *rss_conf)
7900 : : {
7901 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7902 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7903 : : uint64_t hena;
7904 : : int ret;
7905 : :
7906 [ # # ]: 0 : if (!rss_conf)
7907 : : return -EINVAL;
7908 : :
7909 : 0 : ret = i40e_get_rss_key(pf->main_vsi, rss_conf->rss_key,
7910 : : &rss_conf->rss_key_len);
7911 [ # # ]: 0 : if (ret)
7912 : : return ret;
7913 : :
7914 : 0 : hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
7915 : 0 : hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
7916 : 0 : rss_conf->rss_hf = i40e_parse_hena(pf->adapter, hena);
7917 : :
7918 : 0 : return 0;
7919 : : }
7920 : :
7921 : : static int
7922 : 0 : i40e_dev_get_filter_type(uint16_t filter_type, uint16_t *flag)
7923 : : {
7924 [ # # # # : 0 : switch (filter_type) {
# # # # ]
7925 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC_IVLAN:
7926 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
7927 : 0 : break;
7928 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC_IVLAN_TENID:
7929 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
7930 : 0 : break;
7931 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC_TENID:
7932 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID;
7933 : 0 : break;
7934 : 0 : case RTE_ETH_TUNNEL_FILTER_OMAC_TENID_IMAC:
7935 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC;
7936 : 0 : break;
7937 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC:
7938 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
7939 : 0 : break;
7940 : 0 : case RTE_ETH_TUNNEL_FILTER_OIP:
7941 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_OIP;
7942 : 0 : break;
7943 : 0 : case RTE_ETH_TUNNEL_FILTER_IIP:
7944 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IIP;
7945 : 0 : break;
7946 : 0 : default:
7947 : 0 : PMD_DRV_LOG(ERR, "invalid tunnel filter type");
7948 : 0 : return -EINVAL;
7949 : : }
7950 : :
7951 : : return 0;
7952 : : }
7953 : :
7954 : : /* Convert tunnel filter structure */
7955 : : static int
7956 [ # # ]: 0 : i40e_tunnel_filter_convert(
7957 : : struct i40e_aqc_cloud_filters_element_bb *cld_filter,
7958 : : struct i40e_tunnel_filter *tunnel_filter)
7959 : : {
7960 : : rte_ether_addr_copy((struct rte_ether_addr *)
7961 : : &cld_filter->element.outer_mac,
7962 : : (struct rte_ether_addr *)&tunnel_filter->input.outer_mac);
7963 : : rte_ether_addr_copy((struct rte_ether_addr *)
7964 : : &cld_filter->element.inner_mac,
7965 : : (struct rte_ether_addr *)&tunnel_filter->input.inner_mac);
7966 : 0 : tunnel_filter->input.inner_vlan = cld_filter->element.inner_vlan;
7967 [ # # ]: 0 : if ((rte_le_to_cpu_16(cld_filter->element.flags) &
7968 : : I40E_AQC_ADD_CLOUD_FLAGS_IPV6) ==
7969 : : I40E_AQC_ADD_CLOUD_FLAGS_IPV6)
7970 : 0 : tunnel_filter->input.ip_type = I40E_TUNNEL_IPTYPE_IPV6;
7971 : : else
7972 : 0 : tunnel_filter->input.ip_type = I40E_TUNNEL_IPTYPE_IPV4;
7973 : 0 : tunnel_filter->input.flags = cld_filter->element.flags;
7974 : 0 : tunnel_filter->input.tenant_id = cld_filter->element.tenant_id;
7975 : 0 : tunnel_filter->queue = cld_filter->element.queue_number;
7976 : 0 : rte_memcpy(tunnel_filter->input.general_fields,
7977 [ # # ]: 0 : cld_filter->general_fields,
7978 : : sizeof(cld_filter->general_fields));
7979 : :
7980 : 0 : return 0;
7981 : : }
7982 : :
7983 : : /* Check if there exists the tunnel filter */
7984 : : struct i40e_tunnel_filter *
7985 : 0 : i40e_sw_tunnel_filter_lookup(struct i40e_tunnel_rule *tunnel_rule,
7986 : : const struct i40e_tunnel_filter_input *input)
7987 : : {
7988 : : int ret;
7989 : :
7990 : 0 : ret = rte_hash_lookup(tunnel_rule->hash_table, (const void *)input);
7991 [ # # ]: 0 : if (ret < 0)
7992 : : return NULL;
7993 : :
7994 : 0 : return tunnel_rule->hash_map[ret];
7995 : : }
7996 : :
7997 : : /* Add a tunnel filter into the SW list */
7998 : : static int
7999 : 0 : i40e_sw_tunnel_filter_insert(struct i40e_pf *pf,
8000 : : struct i40e_tunnel_filter *tunnel_filter)
8001 : : {
8002 : : struct i40e_tunnel_rule *rule = &pf->tunnel;
8003 : : int ret;
8004 : :
8005 : 0 : ret = rte_hash_add_key(rule->hash_table, &tunnel_filter->input);
8006 [ # # ]: 0 : if (ret < 0) {
8007 : 0 : PMD_DRV_LOG(ERR,
8008 : : "Failed to insert tunnel filter to hash table %d!",
8009 : : ret);
8010 : 0 : return ret;
8011 : : }
8012 : 0 : rule->hash_map[ret] = tunnel_filter;
8013 : :
8014 : 0 : TAILQ_INSERT_TAIL(&rule->tunnel_list, tunnel_filter, rules);
8015 : :
8016 : 0 : return 0;
8017 : : }
8018 : :
8019 : : /* Delete a tunnel filter from the SW list */
8020 : : int
8021 : 0 : i40e_sw_tunnel_filter_del(struct i40e_pf *pf,
8022 : : struct i40e_tunnel_filter_input *input)
8023 : : {
8024 : : struct i40e_tunnel_rule *rule = &pf->tunnel;
8025 : : struct i40e_tunnel_filter *tunnel_filter;
8026 : : int ret;
8027 : :
8028 : 0 : ret = rte_hash_del_key(rule->hash_table, input);
8029 [ # # ]: 0 : if (ret < 0) {
8030 : 0 : PMD_DRV_LOG(ERR,
8031 : : "Failed to delete tunnel filter to hash table %d!",
8032 : : ret);
8033 : 0 : return ret;
8034 : : }
8035 : 0 : tunnel_filter = rule->hash_map[ret];
8036 : 0 : rule->hash_map[ret] = NULL;
8037 : :
8038 [ # # ]: 0 : TAILQ_REMOVE(&rule->tunnel_list, tunnel_filter, rules);
8039 : 0 : rte_free(tunnel_filter);
8040 : :
8041 : 0 : return 0;
8042 : : }
8043 : :
8044 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_TR_WORD0 0x48
8045 : : #define I40E_TR_VXLAN_GRE_KEY_MASK 0x4
8046 : : #define I40E_TR_GENEVE_KEY_MASK 0x8
8047 : : #define I40E_TR_GENERIC_UDP_TUNNEL_MASK 0x40
8048 : : #define I40E_TR_GRE_KEY_MASK 0x400
8049 : : #define I40E_TR_GRE_KEY_WITH_XSUM_MASK 0x800
8050 : : #define I40E_TR_GRE_NO_KEY_MASK 0x8000
8051 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_PORT_TR_WORD0 0x49
8052 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_DIRECTION_WORD0 0x41
8053 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_INGRESS_WORD0 0x80
8054 : : #define I40E_DIRECTION_INGRESS_KEY 0x8000
8055 : : #define I40E_TR_L4_TYPE_TCP 0x2
8056 : : #define I40E_TR_L4_TYPE_UDP 0x4
8057 : : #define I40E_TR_L4_TYPE_SCTP 0x8
8058 : :
8059 : : static enum
8060 : 0 : i40e_status_code i40e_replace_mpls_l1_filter(struct i40e_pf *pf)
8061 : : {
8062 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8063 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8064 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8065 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8066 : : enum i40e_status_code status = I40E_SUCCESS;
8067 : :
8068 [ # # ]: 0 : if (pf->support_multi_driver) {
8069 : 0 : PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
8070 : 0 : return I40E_NOT_SUPPORTED;
8071 : : }
8072 : :
8073 : : memset(&filter_replace, 0,
8074 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8075 : : memset(&filter_replace_buf, 0,
8076 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8077 : :
8078 : : /* create L1 filter */
8079 : 0 : filter_replace.old_filter_type =
8080 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_IMAC;
8081 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X11;
8082 : : filter_replace.tr_bit = 0;
8083 : :
8084 : : /* Prepare the buffer, 3 entries */
8085 : : filter_replace_buf.data[0] =
8086 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8087 : 0 : filter_replace_buf.data[0] |=
8088 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8089 : 0 : filter_replace_buf.data[2] = 0xFF;
8090 : 0 : filter_replace_buf.data[3] = 0xFF;
8091 : : filter_replace_buf.data[4] =
8092 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8093 : 0 : filter_replace_buf.data[4] |=
8094 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8095 : 0 : filter_replace_buf.data[7] = 0xF0;
8096 : : filter_replace_buf.data[8]
8097 : : = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_TR_WORD0;
8098 : 0 : filter_replace_buf.data[8] |=
8099 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8100 : 0 : filter_replace_buf.data[10] = I40E_TR_VXLAN_GRE_KEY_MASK |
8101 : : I40E_TR_GENEVE_KEY_MASK |
8102 : : I40E_TR_GENERIC_UDP_TUNNEL_MASK;
8103 : 0 : filter_replace_buf.data[11] = (I40E_TR_GRE_KEY_MASK |
8104 : : I40E_TR_GRE_KEY_WITH_XSUM_MASK |
8105 : : I40E_TR_GRE_NO_KEY_MASK) >> 8;
8106 : :
8107 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8108 : : &filter_replace_buf);
8109 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8110 [ # # ]: 0 : filter_replace.new_filter_type))
8111 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8112 : : " original: 0x%x, new: 0x%x",
8113 : : dev->device->name,
8114 : : filter_replace.old_filter_type,
8115 : : filter_replace.new_filter_type);
8116 : :
8117 : : return status;
8118 : : }
8119 : :
8120 : : static enum
8121 : 0 : i40e_status_code i40e_replace_mpls_cloud_filter(struct i40e_pf *pf)
8122 : : {
8123 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8124 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8125 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8126 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8127 : : enum i40e_status_code status = I40E_SUCCESS;
8128 : :
8129 [ # # ]: 0 : if (pf->support_multi_driver) {
8130 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8131 : 0 : return I40E_NOT_SUPPORTED;
8132 : : }
8133 : :
8134 : : /* For MPLSoUDP */
8135 : : memset(&filter_replace, 0,
8136 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8137 : : memset(&filter_replace_buf, 0,
8138 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
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_IIP;
8142 : 0 : filter_replace.new_filter_type =
8143 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
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 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8152 : : &filter_replace_buf);
8153 [ # # ]: 0 : if (status < 0)
8154 : : return status;
8155 : 0 : if (filter_replace.old_filter_type !=
8156 [ # # ]: 0 : filter_replace.new_filter_type)
8157 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8158 : : " original: 0x%x, new: 0x%x",
8159 : : dev->device->name,
8160 : : filter_replace.old_filter_type,
8161 : : filter_replace.new_filter_type);
8162 : :
8163 : : /* For MPLSoGRE */
8164 : : memset(&filter_replace, 0,
8165 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8166 : : memset(&filter_replace_buf, 0,
8167 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8168 : :
8169 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER |
8170 : : I40E_AQC_MIRROR_CLOUD_FILTER;
8171 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
8172 : 0 : filter_replace.new_filter_type =
8173 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8174 : : /* Prepare the buffer, 2 entries */
8175 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8176 : 0 : filter_replace_buf.data[0] |=
8177 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8178 : : filter_replace_buf.data[4] = I40E_AQC_ADD_L1_FILTER_0X11;
8179 : 0 : filter_replace_buf.data[4] |=
8180 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8181 : :
8182 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8183 : : &filter_replace_buf);
8184 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8185 [ # # ]: 0 : filter_replace.new_filter_type))
8186 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8187 : : " original: 0x%x, new: 0x%x",
8188 : : dev->device->name,
8189 : : filter_replace.old_filter_type,
8190 : : filter_replace.new_filter_type);
8191 : :
8192 : : return status;
8193 : : }
8194 : :
8195 : : static enum i40e_status_code
8196 : 0 : i40e_replace_gtp_l1_filter(struct i40e_pf *pf)
8197 : : {
8198 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8199 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8200 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8201 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8202 : : enum i40e_status_code status = I40E_SUCCESS;
8203 : :
8204 [ # # ]: 0 : if (pf->support_multi_driver) {
8205 : 0 : PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
8206 : 0 : return I40E_NOT_SUPPORTED;
8207 : : }
8208 : :
8209 : : /* For GTP-C */
8210 : : memset(&filter_replace, 0,
8211 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8212 : : memset(&filter_replace_buf, 0,
8213 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8214 : : /* create L1 filter */
8215 : 0 : filter_replace.old_filter_type =
8216 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_IMAC;
8217 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X12;
8218 : 0 : filter_replace.tr_bit = I40E_AQC_NEW_TR_22 |
8219 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8220 : : /* Prepare the buffer, 2 entries */
8221 : : filter_replace_buf.data[0] =
8222 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8223 : 0 : filter_replace_buf.data[0] |=
8224 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8225 : 0 : filter_replace_buf.data[2] = 0xFF;
8226 : 0 : filter_replace_buf.data[3] = 0xFF;
8227 : : filter_replace_buf.data[4] =
8228 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8229 : 0 : filter_replace_buf.data[4] |=
8230 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8231 : 0 : filter_replace_buf.data[6] = 0xFF;
8232 : 0 : filter_replace_buf.data[7] = 0xFF;
8233 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8234 : : &filter_replace_buf);
8235 [ # # ]: 0 : if (status < 0)
8236 : : return status;
8237 : 0 : if (filter_replace.old_filter_type !=
8238 [ # # ]: 0 : filter_replace.new_filter_type)
8239 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8240 : : " original: 0x%x, new: 0x%x",
8241 : : dev->device->name,
8242 : : filter_replace.old_filter_type,
8243 : : filter_replace.new_filter_type);
8244 : :
8245 : : /* for GTP-U */
8246 : : memset(&filter_replace, 0,
8247 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8248 : : memset(&filter_replace_buf, 0,
8249 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8250 : : /* create L1 filter */
8251 : 0 : filter_replace.old_filter_type =
8252 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TUNNLE_KEY;
8253 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X13;
8254 : 0 : filter_replace.tr_bit = I40E_AQC_NEW_TR_21 |
8255 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8256 : : /* Prepare the buffer, 2 entries */
8257 : : filter_replace_buf.data[0] =
8258 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8259 : 0 : filter_replace_buf.data[0] |=
8260 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8261 : 0 : filter_replace_buf.data[2] = 0xFF;
8262 : 0 : filter_replace_buf.data[3] = 0xFF;
8263 : : filter_replace_buf.data[4] =
8264 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8265 : 0 : filter_replace_buf.data[4] |=
8266 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8267 : 0 : filter_replace_buf.data[6] = 0xFF;
8268 : 0 : filter_replace_buf.data[7] = 0xFF;
8269 : :
8270 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8271 : : &filter_replace_buf);
8272 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8273 [ # # ]: 0 : filter_replace.new_filter_type))
8274 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8275 : : " original: 0x%x, new: 0x%x",
8276 : : dev->device->name,
8277 : : filter_replace.old_filter_type,
8278 : : filter_replace.new_filter_type);
8279 : :
8280 : : return status;
8281 : : }
8282 : :
8283 : : static enum
8284 : 0 : i40e_status_code i40e_replace_gtp_cloud_filter(struct i40e_pf *pf)
8285 : : {
8286 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8287 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8288 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8289 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8290 : : enum i40e_status_code status = I40E_SUCCESS;
8291 : :
8292 [ # # ]: 0 : if (pf->support_multi_driver) {
8293 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8294 : 0 : return I40E_NOT_SUPPORTED;
8295 : : }
8296 : :
8297 : : /* for GTP-C */
8298 : : memset(&filter_replace, 0,
8299 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8300 : : memset(&filter_replace_buf, 0,
8301 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8302 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8303 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
8304 : 0 : filter_replace.new_filter_type =
8305 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8306 : : /* Prepare the buffer, 2 entries */
8307 : : filter_replace_buf.data[0] = I40E_AQC_ADD_L1_FILTER_0X12;
8308 : 0 : filter_replace_buf.data[0] |=
8309 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8310 : : filter_replace_buf.data[4] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8311 : 0 : filter_replace_buf.data[4] |=
8312 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8313 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8314 : : &filter_replace_buf);
8315 [ # # ]: 0 : if (status < 0)
8316 : : return status;
8317 : 0 : if (filter_replace.old_filter_type !=
8318 [ # # ]: 0 : filter_replace.new_filter_type)
8319 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8320 : : " original: 0x%x, new: 0x%x",
8321 : : dev->device->name,
8322 : : filter_replace.old_filter_type,
8323 : : filter_replace.new_filter_type);
8324 : :
8325 : : /* for GTP-U */
8326 : : memset(&filter_replace, 0,
8327 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8328 : : memset(&filter_replace_buf, 0,
8329 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8330 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8331 : 0 : filter_replace.old_filter_type =
8332 : : I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
8333 : 0 : filter_replace.new_filter_type =
8334 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8335 : : /* Prepare the buffer, 2 entries */
8336 : : filter_replace_buf.data[0] = I40E_AQC_ADD_L1_FILTER_0X13;
8337 : 0 : filter_replace_buf.data[0] |=
8338 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8339 : : filter_replace_buf.data[4] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8340 : 0 : filter_replace_buf.data[4] |=
8341 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8342 : :
8343 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8344 : : &filter_replace_buf);
8345 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8346 [ # # ]: 0 : filter_replace.new_filter_type))
8347 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8348 : : " original: 0x%x, new: 0x%x",
8349 : : dev->device->name,
8350 : : filter_replace.old_filter_type,
8351 : : filter_replace.new_filter_type);
8352 : :
8353 : : return status;
8354 : : }
8355 : :
8356 : : static enum i40e_status_code
8357 : 0 : i40e_replace_port_l1_filter(struct i40e_pf *pf,
8358 : : enum i40e_l4_port_type l4_port_type)
8359 : : {
8360 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8361 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8362 : : enum i40e_status_code status = I40E_SUCCESS;
8363 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8364 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8365 : :
8366 [ # # ]: 0 : if (pf->support_multi_driver) {
8367 : 0 : PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
8368 : 0 : return I40E_NOT_SUPPORTED;
8369 : : }
8370 : :
8371 : : memset(&filter_replace, 0,
8372 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8373 : : memset(&filter_replace_buf, 0,
8374 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8375 : :
8376 : : /* create L1 filter */
8377 [ # # ]: 0 : if (l4_port_type == I40E_L4_PORT_TYPE_SRC) {
8378 : 0 : filter_replace.old_filter_type =
8379 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TUNNLE_KEY;
8380 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X11;
8381 : 0 : filter_replace_buf.data[8] =
8382 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_SRC_PORT;
8383 : : } else {
8384 : 0 : filter_replace.old_filter_type =
8385 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG_IVLAN;
8386 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X10;
8387 : 0 : filter_replace_buf.data[8] =
8388 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_DST_PORT;
8389 : : }
8390 : :
8391 : : filter_replace.tr_bit = 0;
8392 : : /* Prepare the buffer, 3 entries */
8393 : : filter_replace_buf.data[0] =
8394 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_DIRECTION_WORD0;
8395 : 0 : filter_replace_buf.data[0] |=
8396 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8397 : : filter_replace_buf.data[2] = 0x00;
8398 : 0 : filter_replace_buf.data[3] =
8399 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_INGRESS_WORD0;
8400 : : filter_replace_buf.data[4] =
8401 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_PORT_TR_WORD0;
8402 : 0 : filter_replace_buf.data[4] |=
8403 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8404 : : filter_replace_buf.data[5] = 0x00;
8405 : 0 : filter_replace_buf.data[6] = I40E_TR_L4_TYPE_UDP |
8406 : : I40E_TR_L4_TYPE_TCP |
8407 : : I40E_TR_L4_TYPE_SCTP;
8408 : : filter_replace_buf.data[7] = 0x00;
8409 : 0 : filter_replace_buf.data[8] |=
8410 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8411 : : filter_replace_buf.data[9] = 0x00;
8412 : 0 : filter_replace_buf.data[10] = 0xFF;
8413 : 0 : filter_replace_buf.data[11] = 0xFF;
8414 : :
8415 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8416 : : &filter_replace_buf);
8417 [ # # ]: 0 : if (!status && filter_replace.old_filter_type !=
8418 [ # # ]: 0 : filter_replace.new_filter_type)
8419 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8420 : : " original: 0x%x, new: 0x%x",
8421 : : dev->device->name,
8422 : : filter_replace.old_filter_type,
8423 : : filter_replace.new_filter_type);
8424 : :
8425 : : return status;
8426 : : }
8427 : :
8428 : : static enum i40e_status_code
8429 : 0 : i40e_replace_port_cloud_filter(struct i40e_pf *pf,
8430 : : enum i40e_l4_port_type l4_port_type)
8431 : : {
8432 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8433 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8434 : : enum i40e_status_code status = I40E_SUCCESS;
8435 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8436 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8437 : :
8438 [ # # ]: 0 : if (pf->support_multi_driver) {
8439 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8440 : 0 : return I40E_NOT_SUPPORTED;
8441 : : }
8442 : :
8443 : : memset(&filter_replace, 0,
8444 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8445 : : memset(&filter_replace_buf, 0,
8446 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8447 : :
8448 [ # # ]: 0 : if (l4_port_type == I40E_L4_PORT_TYPE_SRC) {
8449 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IIP;
8450 : 0 : filter_replace.new_filter_type =
8451 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8452 : 0 : filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X11;
8453 : : } else {
8454 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_OIP;
8455 : 0 : filter_replace.new_filter_type =
8456 : : I40E_AQC_ADD_CLOUD_FILTER_0X10;
8457 : 0 : filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X10;
8458 : : }
8459 : :
8460 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8461 : : filter_replace.tr_bit = 0;
8462 : : /* Prepare the buffer, 2 entries */
8463 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8464 : 0 : filter_replace_buf.data[0] |=
8465 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8466 : 0 : filter_replace_buf.data[4] |=
8467 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8468 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8469 : : &filter_replace_buf);
8470 : :
8471 [ # # ]: 0 : if (!status && filter_replace.old_filter_type !=
8472 [ # # ]: 0 : filter_replace.new_filter_type)
8473 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8474 : : " original: 0x%x, new: 0x%x",
8475 : : dev->device->name,
8476 : : filter_replace.old_filter_type,
8477 : : filter_replace.new_filter_type);
8478 : :
8479 : : return status;
8480 : : }
8481 : :
8482 : : int
8483 : 0 : i40e_dev_consistent_tunnel_filter_set(struct i40e_pf *pf,
8484 : : struct i40e_tunnel_filter_conf *tunnel_filter,
8485 : : uint8_t add)
8486 : : {
8487 : : uint16_t ip_type;
8488 : : uint32_t ipv4_addr, ipv4_addr_le;
8489 : : uint8_t i, tun_type = 0;
8490 : : /* internal variable to convert ipv6 byte order */
8491 : : uint32_t convert_ipv6[4];
8492 : : int val, ret = 0;
8493 : : struct i40e_pf_vf *vf = NULL;
8494 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8495 : : struct i40e_vsi *vsi;
8496 : : struct i40e_aqc_cloud_filters_element_bb *cld_filter;
8497 : : struct i40e_aqc_cloud_filters_element_bb *pfilter;
8498 : 0 : struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
8499 : : struct i40e_tunnel_filter *tunnel, *node;
8500 : : struct i40e_tunnel_filter check_filter; /* Check if filter exists */
8501 : : uint32_t teid_le;
8502 : : bool big_buffer = 0;
8503 : :
8504 : 0 : cld_filter = rte_zmalloc("tunnel_filter",
8505 : : sizeof(struct i40e_aqc_add_rm_cloud_filt_elem_ext),
8506 : : 0);
8507 : :
8508 [ # # ]: 0 : if (cld_filter == NULL) {
8509 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory.");
8510 : 0 : return -ENOMEM;
8511 : : }
8512 : : pfilter = cld_filter;
8513 : :
8514 : : rte_ether_addr_copy(&tunnel_filter->outer_mac,
8515 : : (struct rte_ether_addr *)&pfilter->element.outer_mac);
8516 : : rte_ether_addr_copy(&tunnel_filter->inner_mac,
8517 : : (struct rte_ether_addr *)&pfilter->element.inner_mac);
8518 : :
8519 : 0 : pfilter->element.inner_vlan =
8520 : 0 : rte_cpu_to_le_16(tunnel_filter->inner_vlan);
8521 [ # # ]: 0 : if (tunnel_filter->ip_type == I40E_TUNNEL_IPTYPE_IPV4) {
8522 : : ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV4;
8523 [ # # ]: 0 : ipv4_addr = rte_be_to_cpu_32(tunnel_filter->ip_addr.ipv4_addr);
8524 : 0 : ipv4_addr_le = rte_cpu_to_le_32(ipv4_addr);
8525 [ # # ]: 0 : rte_memcpy(&pfilter->element.ipaddr.v4.data,
8526 : : &ipv4_addr_le,
8527 : : sizeof(pfilter->element.ipaddr.v4.data));
8528 : : } else {
8529 : : ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV6;
8530 [ # # ]: 0 : for (i = 0; i < 4; i++) {
8531 : 0 : convert_ipv6[i] =
8532 [ # # ]: 0 : rte_cpu_to_le_32(rte_be_to_cpu_32(
8533 : : tunnel_filter->ip_addr.ipv6_addr[i]));
8534 : : }
8535 [ # # ]: 0 : rte_memcpy(&pfilter->element.ipaddr.v6.data,
8536 : : &convert_ipv6,
8537 : : sizeof(pfilter->element.ipaddr.v6.data));
8538 : : }
8539 : :
8540 : : /* check tunneled type */
8541 [ # # # # : 0 : switch (tunnel_filter->tunnel_type) {
# # # # #
# ]
8542 : : case I40E_TUNNEL_TYPE_VXLAN:
8543 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_VXLAN;
8544 : : break;
8545 : 0 : case I40E_TUNNEL_TYPE_NVGRE:
8546 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_NVGRE_OMAC;
8547 : 0 : break;
8548 : 0 : case I40E_TUNNEL_TYPE_IP_IN_GRE:
8549 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_IP;
8550 : 0 : break;
8551 : 0 : case I40E_TUNNEL_TYPE_MPLSoUDP:
8552 [ # # ]: 0 : if (!pf->mpls_replace_flag) {
8553 : 0 : i40e_replace_mpls_l1_filter(pf);
8554 : 0 : i40e_replace_mpls_cloud_filter(pf);
8555 : 0 : pf->mpls_replace_flag = 1;
8556 : : }
8557 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8558 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8559 : 0 : teid_le >> 4;
8560 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8561 : 0 : (teid_le & 0xF) << 12;
8562 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8563 : : 0x40;
8564 : : big_buffer = 1;
8565 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_MPLSOUDP;
8566 : 0 : break;
8567 : 0 : case I40E_TUNNEL_TYPE_MPLSoGRE:
8568 [ # # ]: 0 : if (!pf->mpls_replace_flag) {
8569 : 0 : i40e_replace_mpls_l1_filter(pf);
8570 : 0 : i40e_replace_mpls_cloud_filter(pf);
8571 : 0 : pf->mpls_replace_flag = 1;
8572 : : }
8573 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8574 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8575 : 0 : teid_le >> 4;
8576 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8577 : 0 : (teid_le & 0xF) << 12;
8578 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8579 : : 0x0;
8580 : : big_buffer = 1;
8581 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_MPLSOGRE;
8582 : 0 : break;
8583 : 0 : case I40E_TUNNEL_TYPE_GTPC:
8584 [ # # ]: 0 : if (!pf->gtp_replace_flag) {
8585 : 0 : i40e_replace_gtp_l1_filter(pf);
8586 : 0 : i40e_replace_gtp_cloud_filter(pf);
8587 : 0 : pf->gtp_replace_flag = 1;
8588 : : }
8589 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8590 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD0] =
8591 : 0 : (teid_le >> 16) & 0xFFFF;
8592 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD1] =
8593 : : teid_le & 0xFFFF;
8594 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD2] =
8595 : : 0x0;
8596 : : big_buffer = 1;
8597 : 0 : break;
8598 : 0 : case I40E_TUNNEL_TYPE_GTPU:
8599 [ # # ]: 0 : if (!pf->gtp_replace_flag) {
8600 : 0 : i40e_replace_gtp_l1_filter(pf);
8601 : 0 : i40e_replace_gtp_cloud_filter(pf);
8602 : 0 : pf->gtp_replace_flag = 1;
8603 : : }
8604 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8605 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD0] =
8606 : 0 : (teid_le >> 16) & 0xFFFF;
8607 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD1] =
8608 : : teid_le & 0xFFFF;
8609 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD2] =
8610 : : 0x0;
8611 : : big_buffer = 1;
8612 : 0 : break;
8613 : 0 : case I40E_TUNNEL_TYPE_QINQ:
8614 [ # # ]: 0 : if (!pf->qinq_replace_flag) {
8615 : 0 : ret = i40e_cloud_filter_qinq_create(pf);
8616 [ # # ]: 0 : if (ret < 0)
8617 : 0 : PMD_DRV_LOG(DEBUG,
8618 : : "QinQ tunnel filter already created.");
8619 : 0 : pf->qinq_replace_flag = 1;
8620 : : }
8621 : : /* Add in the General fields the values of
8622 : : * the Outer and Inner VLAN
8623 : : * Big Buffer should be set, see changes in
8624 : : * i40e_aq_add_cloud_filters
8625 : : */
8626 : 0 : pfilter->general_fields[0] = tunnel_filter->inner_vlan;
8627 : 0 : pfilter->general_fields[1] = tunnel_filter->outer_vlan;
8628 : : big_buffer = 1;
8629 : 0 : break;
8630 : 0 : case I40E_CLOUD_TYPE_UDP:
8631 : : case I40E_CLOUD_TYPE_TCP:
8632 : : case I40E_CLOUD_TYPE_SCTP:
8633 [ # # ]: 0 : if (tunnel_filter->l4_port_type == I40E_L4_PORT_TYPE_SRC) {
8634 [ # # ]: 0 : if (!pf->sport_replace_flag) {
8635 : 0 : i40e_replace_port_l1_filter(pf,
8636 : : tunnel_filter->l4_port_type);
8637 : 0 : i40e_replace_port_cloud_filter(pf,
8638 : : tunnel_filter->l4_port_type);
8639 : 0 : pf->sport_replace_flag = 1;
8640 : : }
8641 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8642 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8643 : : I40E_DIRECTION_INGRESS_KEY;
8644 : :
8645 [ # # ]: 0 : if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_UDP)
8646 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8647 : : I40E_TR_L4_TYPE_UDP;
8648 [ # # ]: 0 : else if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_TCP)
8649 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8650 : : I40E_TR_L4_TYPE_TCP;
8651 : : else
8652 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8653 : : I40E_TR_L4_TYPE_SCTP;
8654 : :
8655 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8656 : 0 : (teid_le >> 16) & 0xFFFF;
8657 : : big_buffer = 1;
8658 : : } else {
8659 [ # # ]: 0 : if (!pf->dport_replace_flag) {
8660 : 0 : i40e_replace_port_l1_filter(pf,
8661 : : tunnel_filter->l4_port_type);
8662 : 0 : i40e_replace_port_cloud_filter(pf,
8663 : : tunnel_filter->l4_port_type);
8664 : 0 : pf->dport_replace_flag = 1;
8665 : : }
8666 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8667 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD0] =
8668 : : I40E_DIRECTION_INGRESS_KEY;
8669 : :
8670 [ # # ]: 0 : if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_UDP)
8671 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD1] =
8672 : : I40E_TR_L4_TYPE_UDP;
8673 [ # # ]: 0 : else if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_TCP)
8674 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD1] =
8675 : : I40E_TR_L4_TYPE_TCP;
8676 : : else
8677 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD1] =
8678 : : I40E_TR_L4_TYPE_SCTP;
8679 : :
8680 : 0 : pfilter->general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD2] =
8681 : 0 : (teid_le >> 16) & 0xFFFF;
8682 : : big_buffer = 1;
8683 : : }
8684 : :
8685 : : break;
8686 : 0 : default:
8687 : : /* Other tunnel types is not supported. */
8688 : 0 : PMD_DRV_LOG(ERR, "tunnel type is not supported.");
8689 : 0 : rte_free(cld_filter);
8690 : 0 : return -EINVAL;
8691 : : }
8692 : :
8693 [ # # ]: 0 : if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_MPLSoUDP)
8694 : 0 : pfilter->element.flags =
8695 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8696 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_MPLSoGRE)
8697 : 0 : pfilter->element.flags =
8698 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8699 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_GTPC)
8700 : 0 : pfilter->element.flags =
8701 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8702 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_GTPU)
8703 : 0 : pfilter->element.flags =
8704 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8705 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_QINQ)
8706 : 0 : pfilter->element.flags |=
8707 : : I40E_AQC_ADD_CLOUD_FILTER_0X10;
8708 : : else if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_UDP ||
8709 : : tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_TCP ||
8710 : : tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_SCTP) {
8711 [ # # ]: 0 : if (tunnel_filter->l4_port_type == I40E_L4_PORT_TYPE_SRC)
8712 : 0 : pfilter->element.flags |=
8713 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8714 : : else
8715 : 0 : pfilter->element.flags |=
8716 : : I40E_AQC_ADD_CLOUD_FILTER_0X10;
8717 : : } else {
8718 : 0 : val = i40e_dev_get_filter_type(tunnel_filter->filter_type,
8719 : : &pfilter->element.flags);
8720 [ # # ]: 0 : if (val < 0) {
8721 : 0 : rte_free(cld_filter);
8722 : 0 : return -EINVAL;
8723 : : }
8724 : : }
8725 : :
8726 : 0 : pfilter->element.flags |= rte_cpu_to_le_16(
8727 : : I40E_AQC_ADD_CLOUD_FLAGS_TO_QUEUE |
8728 : : ip_type | (tun_type << I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT));
8729 : 0 : pfilter->element.tenant_id = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8730 : 0 : pfilter->element.queue_number =
8731 : 0 : rte_cpu_to_le_16(tunnel_filter->queue_id);
8732 : :
8733 [ # # ]: 0 : if (!tunnel_filter->is_to_vf)
8734 : 0 : vsi = pf->main_vsi;
8735 : : else {
8736 [ # # ]: 0 : if (tunnel_filter->vf_id >= pf->vf_num) {
8737 : 0 : PMD_DRV_LOG(ERR, "Invalid argument.");
8738 : 0 : rte_free(cld_filter);
8739 : 0 : return -EINVAL;
8740 : : }
8741 : 0 : vf = &pf->vfs[tunnel_filter->vf_id];
8742 : 0 : vsi = vf->vsi;
8743 : : }
8744 : :
8745 : : /* Check if there is the filter in SW list */
8746 : : memset(&check_filter, 0, sizeof(check_filter));
8747 : 0 : i40e_tunnel_filter_convert(cld_filter, &check_filter);
8748 : 0 : check_filter.is_to_vf = tunnel_filter->is_to_vf;
8749 : 0 : check_filter.vf_id = tunnel_filter->vf_id;
8750 : 0 : node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
8751 [ # # ]: 0 : if (add && node) {
8752 : 0 : PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
8753 : 0 : rte_free(cld_filter);
8754 : 0 : return -EINVAL;
8755 : : }
8756 : :
8757 [ # # ]: 0 : if (!add && !node) {
8758 : 0 : PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
8759 : 0 : rte_free(cld_filter);
8760 : 0 : return -EINVAL;
8761 : : }
8762 : :
8763 [ # # ]: 0 : if (add) {
8764 [ # # ]: 0 : if (big_buffer)
8765 : 0 : ret = i40e_aq_add_cloud_filters_bb(hw,
8766 : 0 : vsi->seid, cld_filter, 1);
8767 : : else
8768 : 0 : ret = i40e_aq_add_cloud_filters(hw,
8769 : 0 : vsi->seid, &cld_filter->element, 1);
8770 [ # # ]: 0 : if (ret < 0) {
8771 : 0 : PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
8772 : 0 : rte_free(cld_filter);
8773 : 0 : return -ENOTSUP;
8774 : : }
8775 : 0 : tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
8776 [ # # ]: 0 : if (tunnel == NULL) {
8777 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory.");
8778 : 0 : rte_free(cld_filter);
8779 : 0 : return -ENOMEM;
8780 : : }
8781 : :
8782 : : rte_memcpy(tunnel, &check_filter, sizeof(check_filter));
8783 : 0 : ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
8784 [ # # ]: 0 : if (ret < 0)
8785 : 0 : rte_free(tunnel);
8786 : : } else {
8787 [ # # ]: 0 : if (big_buffer)
8788 : 0 : ret = i40e_aq_rem_cloud_filters_bb(
8789 : 0 : hw, vsi->seid, cld_filter, 1);
8790 : : else
8791 : 0 : ret = i40e_aq_rem_cloud_filters(hw, vsi->seid,
8792 : : &cld_filter->element, 1);
8793 [ # # ]: 0 : if (ret < 0) {
8794 : 0 : PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
8795 : 0 : rte_free(cld_filter);
8796 : 0 : return -ENOTSUP;
8797 : : }
8798 : 0 : ret = i40e_sw_tunnel_filter_del(pf, &node->input);
8799 : : }
8800 : :
8801 : 0 : rte_free(cld_filter);
8802 : 0 : return ret;
8803 : : }
8804 : :
8805 : : static int
8806 : : i40e_get_vxlan_port_idx(struct i40e_pf *pf, uint16_t port)
8807 : : {
8808 : : uint8_t i;
8809 : :
8810 [ # # # # : 0 : for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
# # ]
8811 [ # # # # : 0 : if (pf->vxlan_ports[i] == port)
# # ]
8812 : : return i;
8813 : : }
8814 : :
8815 : : return -1;
8816 : : }
8817 : :
8818 : : static int
8819 : 0 : i40e_add_vxlan_port(struct i40e_pf *pf, uint16_t port, int udp_type)
8820 : : {
8821 : : int idx, ret;
8822 : 0 : uint8_t filter_idx = 0;
8823 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8824 : :
8825 : 0 : idx = i40e_get_vxlan_port_idx(pf, port);
8826 : :
8827 : : /* Check if port already exists */
8828 [ # # ]: 0 : if (idx >= 0) {
8829 : 0 : PMD_DRV_LOG(ERR, "Port %d already offloaded", port);
8830 : 0 : return -EINVAL;
8831 : : }
8832 : :
8833 : : /* Now check if there is space to add the new port */
8834 : : idx = i40e_get_vxlan_port_idx(pf, 0);
8835 [ # # ]: 0 : if (idx < 0) {
8836 : 0 : PMD_DRV_LOG(ERR,
8837 : : "Maximum number of UDP ports reached, not adding port %d",
8838 : : port);
8839 : 0 : return -ENOSPC;
8840 : : }
8841 : :
8842 : 0 : ret = i40e_aq_add_udp_tunnel(hw, port, udp_type,
8843 : : &filter_idx, NULL);
8844 [ # # ]: 0 : if (ret < 0) {
8845 : 0 : PMD_DRV_LOG(ERR, "Failed to add VXLAN UDP port %d", port);
8846 : 0 : return -1;
8847 : : }
8848 : :
8849 : 0 : PMD_DRV_LOG(INFO, "Added port %d with AQ command with index %d",
8850 : : port, filter_idx);
8851 : :
8852 : : /* New port: add it and mark its index in the bitmap */
8853 : 0 : pf->vxlan_ports[idx] = port;
8854 : 0 : pf->vxlan_bitmap |= (1 << idx);
8855 : :
8856 [ # # ]: 0 : if (!(pf->flags & I40E_FLAG_VXLAN))
8857 : 0 : pf->flags |= I40E_FLAG_VXLAN;
8858 : :
8859 : : return 0;
8860 : : }
8861 : :
8862 : : static int
8863 : 0 : i40e_del_vxlan_port(struct i40e_pf *pf, uint16_t port)
8864 : : {
8865 : : int idx;
8866 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8867 : :
8868 [ # # ]: 0 : if (!(pf->flags & I40E_FLAG_VXLAN)) {
8869 : 0 : PMD_DRV_LOG(ERR, "VXLAN UDP port was not configured.");
8870 : 0 : return -EINVAL;
8871 : : }
8872 : :
8873 : 0 : idx = i40e_get_vxlan_port_idx(pf, port);
8874 : :
8875 [ # # ]: 0 : if (idx < 0) {
8876 : 0 : PMD_DRV_LOG(ERR, "Port %d doesn't exist", port);
8877 : 0 : return -EINVAL;
8878 : : }
8879 : :
8880 [ # # ]: 0 : if (i40e_aq_del_udp_tunnel(hw, idx, NULL) < 0) {
8881 : 0 : PMD_DRV_LOG(ERR, "Failed to delete VXLAN UDP port %d", port);
8882 : 0 : return -1;
8883 : : }
8884 : :
8885 : 0 : PMD_DRV_LOG(INFO, "Deleted port %d with AQ command with index %d",
8886 : : port, idx);
8887 : :
8888 : 0 : pf->vxlan_ports[idx] = 0;
8889 : 0 : pf->vxlan_bitmap &= ~(1 << idx);
8890 : :
8891 [ # # ]: 0 : if (!pf->vxlan_bitmap)
8892 : 0 : pf->flags &= ~I40E_FLAG_VXLAN;
8893 : :
8894 : : return 0;
8895 : : }
8896 : :
8897 : : /* Add UDP tunneling port */
8898 : : static int
8899 : 0 : i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
8900 : : struct rte_eth_udp_tunnel *udp_tunnel)
8901 : : {
8902 : : int ret = 0;
8903 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8904 : :
8905 [ # # ]: 0 : if (udp_tunnel == NULL)
8906 : : return -EINVAL;
8907 : :
8908 [ # # # # ]: 0 : switch (udp_tunnel->prot_type) {
8909 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN:
8910 : 0 : ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port,
8911 : : I40E_AQC_TUNNEL_TYPE_VXLAN);
8912 : 0 : break;
8913 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN_GPE:
8914 : 0 : ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port,
8915 : : I40E_AQC_TUNNEL_TYPE_VXLAN_GPE);
8916 : 0 : break;
8917 : 0 : case RTE_ETH_TUNNEL_TYPE_GENEVE:
8918 : : case RTE_ETH_TUNNEL_TYPE_TEREDO:
8919 : 0 : PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8920 : : ret = -1;
8921 : 0 : break;
8922 : :
8923 : 0 : default:
8924 : 0 : PMD_DRV_LOG(ERR, "Invalid tunnel type");
8925 : : ret = -1;
8926 : 0 : break;
8927 : : }
8928 : :
8929 : : return ret;
8930 : : }
8931 : :
8932 : : /* Remove UDP tunneling port */
8933 : : static int
8934 : 0 : i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
8935 : : struct rte_eth_udp_tunnel *udp_tunnel)
8936 : : {
8937 : : int ret = 0;
8938 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8939 : :
8940 [ # # ]: 0 : if (udp_tunnel == NULL)
8941 : : return -EINVAL;
8942 : :
8943 [ # # # ]: 0 : switch (udp_tunnel->prot_type) {
8944 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN:
8945 : : case RTE_ETH_TUNNEL_TYPE_VXLAN_GPE:
8946 : 0 : ret = i40e_del_vxlan_port(pf, udp_tunnel->udp_port);
8947 : 0 : break;
8948 : 0 : case RTE_ETH_TUNNEL_TYPE_GENEVE:
8949 : : case RTE_ETH_TUNNEL_TYPE_TEREDO:
8950 : 0 : PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8951 : : ret = -1;
8952 : 0 : break;
8953 : 0 : default:
8954 : 0 : PMD_DRV_LOG(ERR, "Invalid tunnel type");
8955 : : ret = -1;
8956 : 0 : break;
8957 : : }
8958 : :
8959 : : return ret;
8960 : : }
8961 : :
8962 : : /* Calculate the maximum number of contiguous PF queues that are configured */
8963 : : int
8964 : 0 : i40e_pf_calc_configured_queues_num(struct i40e_pf *pf)
8965 : : {
8966 : 0 : struct rte_eth_dev_data *data = pf->dev_data;
8967 : : int i, num;
8968 : : struct i40e_rx_queue *rxq;
8969 : :
8970 : : num = 0;
8971 [ # # ]: 0 : for (i = 0; i < pf->lan_nb_qps; i++) {
8972 : 0 : rxq = data->rx_queues[i];
8973 [ # # # # ]: 0 : if (rxq && rxq->q_set)
8974 : 0 : num++;
8975 : : else
8976 : : break;
8977 : : }
8978 : :
8979 : 0 : return num;
8980 : : }
8981 : :
8982 : : /* Reset the global configure of hash function and input sets */
8983 : : static void
8984 : 0 : i40e_pf_global_rss_reset(struct i40e_pf *pf)
8985 : : {
8986 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8987 : : uint32_t reg, reg_val;
8988 : : int i;
8989 : :
8990 : : /* Reset global RSS function sets */
8991 : 0 : reg_val = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
8992 [ # # ]: 0 : if (!(reg_val & I40E_GLQF_CTL_HTOEP_MASK)) {
8993 : 0 : reg_val |= I40E_GLQF_CTL_HTOEP_MASK;
8994 : 0 : i40e_write_global_rx_ctl(hw, I40E_GLQF_CTL, reg_val);
8995 : : }
8996 : :
8997 [ # # ]: 0 : for (i = 0; i <= I40E_FILTER_PCTYPE_L2_PAYLOAD; i++) {
8998 : : uint64_t inset;
8999 : : int j, pctype;
9000 : :
9001 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
9002 : 0 : pctype = i40e_read_rx_ctl(hw, I40E_GLQF_FD_PCTYPES(i));
9003 : : else
9004 : : pctype = i;
9005 : :
9006 : : /* Reset pctype insets */
9007 : 0 : inset = i40e_get_default_input_set(i);
9008 [ # # ]: 0 : if (inset) {
9009 : 0 : pf->hash_input_set[pctype] = inset;
9010 : 0 : inset = i40e_translate_input_set_reg(hw->mac.type,
9011 : : inset);
9012 : :
9013 : 0 : reg = I40E_GLQF_HASH_INSET(0, pctype);
9014 : 0 : i40e_check_write_global_reg(hw, reg, (uint32_t)inset);
9015 : 0 : reg = I40E_GLQF_HASH_INSET(1, pctype);
9016 : 0 : i40e_check_write_global_reg(hw, reg,
9017 : 0 : (uint32_t)(inset >> 32));
9018 : :
9019 : : /* Clear unused mask registers of the pctype */
9020 [ # # ]: 0 : for (j = 0; j < I40E_INSET_MASK_NUM_REG; j++) {
9021 : 0 : reg = I40E_GLQF_HASH_MSK(j, pctype);
9022 : 0 : i40e_check_write_global_reg(hw, reg, 0);
9023 : : }
9024 : : }
9025 : :
9026 : : /* Reset pctype symmetric sets */
9027 : 0 : reg = I40E_GLQF_HSYM(pctype);
9028 : 0 : reg_val = i40e_read_rx_ctl(hw, reg);
9029 [ # # ]: 0 : if (reg_val & I40E_GLQF_HSYM_SYMH_ENA_MASK) {
9030 : 0 : reg_val &= ~I40E_GLQF_HSYM_SYMH_ENA_MASK;
9031 : 0 : i40e_write_global_rx_ctl(hw, reg, reg_val);
9032 : : }
9033 : : }
9034 : 0 : I40E_WRITE_FLUSH(hw);
9035 : 0 : }
9036 : :
9037 : : int
9038 : 0 : i40e_pf_reset_rss_reta(struct i40e_pf *pf)
9039 : : {
9040 : 0 : struct i40e_hw *hw = &pf->adapter->hw;
9041 : : uint8_t lut[RTE_ETH_RSS_RETA_SIZE_512];
9042 : : uint32_t i;
9043 : : int num;
9044 : :
9045 : : /* If both VMDQ and RSS enabled, not all of PF queues are
9046 : : * configured. It's necessary to calculate the actual PF
9047 : : * queues that are configured.
9048 : : */
9049 [ # # ]: 0 : if (pf->dev_data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG)
9050 : 0 : num = i40e_pf_calc_configured_queues_num(pf);
9051 : : else
9052 : 0 : num = pf->dev_data->nb_rx_queues;
9053 : :
9054 : 0 : num = RTE_MIN(num, I40E_MAX_Q_PER_TC);
9055 [ # # ]: 0 : if (num <= 0)
9056 : : return 0;
9057 : :
9058 [ # # ]: 0 : for (i = 0; i < hw->func_caps.rss_table_size; i++)
9059 : 0 : lut[i] = (uint8_t)(i % (uint32_t)num);
9060 : :
9061 : 0 : return i40e_set_rss_lut(pf->main_vsi, lut, (uint16_t)i);
9062 : : }
9063 : :
9064 : : int
9065 : 0 : i40e_pf_reset_rss_key(struct i40e_pf *pf)
9066 : : {
9067 : : const uint8_t key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
9068 : : sizeof(uint32_t);
9069 : : uint8_t *rss_key;
9070 : :
9071 : : /* Reset key */
9072 : 0 : rss_key = pf->dev_data->dev_conf.rx_adv_conf.rss_conf.rss_key;
9073 [ # # ]: 0 : if (!rss_key ||
9074 [ # # ]: 0 : pf->dev_data->dev_conf.rx_adv_conf.rss_conf.rss_key_len < key_len) {
9075 : : static uint32_t rss_key_default[] = {0x6b793944,
9076 : : 0x23504cb5, 0x5bea75b6, 0x309f4f12, 0x3dc0a2b8,
9077 : : 0x024ddcdf, 0x339b8ca0, 0x4c4af64a, 0x34fac605,
9078 : : 0x55d85839, 0x3a58997d, 0x2ec938e1, 0x66031581};
9079 : :
9080 : : rss_key = (uint8_t *)rss_key_default;
9081 : : }
9082 : :
9083 : 0 : return i40e_set_rss_key(pf->main_vsi, rss_key, key_len);
9084 : : }
9085 : :
9086 : : static int
9087 : 0 : i40e_pf_rss_reset(struct i40e_pf *pf)
9088 : : {
9089 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9090 : :
9091 : : int ret;
9092 : :
9093 : 0 : pf->hash_filter_enabled = 0;
9094 : 0 : i40e_pf_disable_rss(pf);
9095 : 0 : i40e_set_symmetric_hash_enable_per_port(hw, 0);
9096 : :
9097 [ # # ]: 0 : if (!pf->support_multi_driver)
9098 : 0 : i40e_pf_global_rss_reset(pf);
9099 : :
9100 : : /* Reset RETA table */
9101 [ # # ]: 0 : if (pf->adapter->rss_reta_updated == 0) {
9102 : 0 : ret = i40e_pf_reset_rss_reta(pf);
9103 [ # # ]: 0 : if (ret)
9104 : : return ret;
9105 : : }
9106 : :
9107 : 0 : return i40e_pf_reset_rss_key(pf);
9108 : : }
9109 : :
9110 : : /* Configure RSS */
9111 : : int
9112 : 0 : i40e_pf_config_rss(struct i40e_pf *pf)
9113 : : {
9114 : : struct i40e_hw *hw;
9115 : : enum rte_eth_rx_mq_mode mq_mode;
9116 : : uint64_t rss_hf, hena;
9117 : : int ret;
9118 : :
9119 : 0 : ret = i40e_pf_rss_reset(pf);
9120 [ # # ]: 0 : if (ret) {
9121 : 0 : PMD_DRV_LOG(ERR, "Reset RSS failed, RSS has been disabled");
9122 : 0 : return ret;
9123 : : }
9124 : :
9125 : 0 : rss_hf = pf->dev_data->dev_conf.rx_adv_conf.rss_conf.rss_hf;
9126 : 0 : mq_mode = pf->dev_data->dev_conf.rxmode.mq_mode;
9127 [ # # ]: 0 : if (!(rss_hf & pf->adapter->flow_types_mask) ||
9128 [ # # ]: 0 : !(mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
9129 : : return 0;
9130 : :
9131 : 0 : hw = I40E_PF_TO_HW(pf);
9132 : 0 : hena = i40e_config_hena(pf->adapter, rss_hf);
9133 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
9134 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
9135 : 0 : I40E_WRITE_FLUSH(hw);
9136 : :
9137 : 0 : return 0;
9138 : : }
9139 : :
9140 : : #define I40E_GL_PRS_FVBM_MSK_ENA 0x80000000
9141 : : #define I40E_GL_PRS_FVBM(_i) (0x00269760 + ((_i) * 4))
9142 : : int
9143 : 0 : i40e_dev_set_gre_key_len(struct i40e_hw *hw, uint8_t len)
9144 : : {
9145 : 0 : struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
9146 : : uint32_t val, reg;
9147 : : int ret = -EINVAL;
9148 : :
9149 [ # # ]: 0 : if (pf->support_multi_driver) {
9150 : 0 : PMD_DRV_LOG(ERR, "GRE key length configuration is unsupported");
9151 : 0 : return -ENOTSUP;
9152 : : }
9153 : :
9154 : 0 : val = I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2));
9155 : 0 : PMD_DRV_LOG(DEBUG, "Read original GL_PRS_FVBM with 0x%08x", val);
9156 : :
9157 [ # # ]: 0 : if (len == 3) {
9158 : 0 : reg = val | I40E_GL_PRS_FVBM_MSK_ENA;
9159 [ # # ]: 0 : } else if (len == 4) {
9160 : 0 : reg = val & ~I40E_GL_PRS_FVBM_MSK_ENA;
9161 : : } else {
9162 : 0 : PMD_DRV_LOG(ERR, "Unsupported GRE key length of %u", len);
9163 : 0 : return ret;
9164 : : }
9165 : :
9166 [ # # ]: 0 : if (reg != val) {
9167 : 0 : ret = i40e_aq_debug_write_global_register(hw,
9168 : : I40E_GL_PRS_FVBM(2),
9169 : : reg, NULL);
9170 [ # # ]: 0 : if (ret != 0)
9171 : : return ret;
9172 : 0 : PMD_DRV_LOG(DEBUG, "Global register 0x%08x is changed "
9173 : : "with value 0x%08x",
9174 : : I40E_GL_PRS_FVBM(2), reg);
9175 : : } else {
9176 : : ret = 0;
9177 : : }
9178 : 0 : PMD_DRV_LOG(DEBUG, "Read modified GL_PRS_FVBM with 0x%08x",
9179 : : I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2)));
9180 : :
9181 : 0 : return ret;
9182 : : }
9183 : :
9184 : : /* Set the symmetric hash enable configurations per port */
9185 : : void
9186 : 0 : i40e_set_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t enable)
9187 : : {
9188 : 0 : uint32_t reg = i40e_read_rx_ctl(hw, I40E_PRTQF_CTL_0);
9189 : :
9190 [ # # ]: 0 : if (enable > 0) {
9191 [ # # ]: 0 : if (reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK)
9192 : : return;
9193 : :
9194 : 0 : reg |= I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
9195 : : } else {
9196 [ # # ]: 0 : if (!(reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK))
9197 : : return;
9198 : :
9199 : 0 : reg &= ~I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
9200 : : }
9201 : 0 : i40e_write_rx_ctl(hw, I40E_PRTQF_CTL_0, reg);
9202 : 0 : I40E_WRITE_FLUSH(hw);
9203 : : }
9204 : :
9205 : : /**
9206 : : * Valid input sets for hash and flow director filters per PCTYPE
9207 : : */
9208 : : static uint64_t
9209 : : i40e_get_valid_input_set(enum i40e_filter_pctype pctype,
9210 : : enum rte_filter_type filter)
9211 : : {
9212 : : uint64_t valid;
9213 : :
9214 : : static const uint64_t valid_hash_inset_table[] = {
9215 : : [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9216 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9217 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9218 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_SRC |
9219 : : I40E_INSET_IPV4_DST | I40E_INSET_IPV4_TOS |
9220 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9221 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9222 : : I40E_INSET_FLEX_PAYLOAD,
9223 : : [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9224 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9225 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9226 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9227 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9228 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9229 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9230 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9231 : : I40E_INSET_FLEX_PAYLOAD,
9232 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9233 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9234 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9235 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9236 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9237 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9238 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9239 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9240 : : I40E_INSET_FLEX_PAYLOAD,
9241 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9242 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9243 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9244 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9245 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9246 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9247 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9248 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9249 : : I40E_INSET_FLEX_PAYLOAD,
9250 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9251 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9252 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9253 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9254 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9255 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9256 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9257 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9258 : : I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
9259 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9260 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9261 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9262 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9263 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9264 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9265 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9266 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9267 : : I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
9268 : : [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9269 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9270 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9271 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9272 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9273 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9274 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9275 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9276 : : I40E_INSET_SCTP_VT | I40E_INSET_FLEX_PAYLOAD,
9277 : : [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9278 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9279 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9280 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9281 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9282 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9283 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9284 : : I40E_INSET_FLEX_PAYLOAD,
9285 : : [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9286 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9287 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9288 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9289 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9290 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_TUNNEL_DMAC |
9291 : : I40E_INSET_TUNNEL_ID | I40E_INSET_IPV6_SRC |
9292 : : I40E_INSET_IPV6_DST | I40E_INSET_FLEX_PAYLOAD,
9293 : : [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9294 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9295 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9296 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9297 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9298 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9299 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9300 : : I40E_INSET_DST_PORT | I40E_INSET_FLEX_PAYLOAD,
9301 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9302 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9303 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9304 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9305 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9306 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9307 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9308 : : I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9309 : : I40E_INSET_FLEX_PAYLOAD,
9310 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9311 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9312 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9313 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9314 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9315 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9316 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9317 : : I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9318 : : I40E_INSET_FLEX_PAYLOAD,
9319 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9320 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9321 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9322 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9323 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9324 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9325 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9326 : : I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9327 : : I40E_INSET_FLEX_PAYLOAD,
9328 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9329 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9330 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9331 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9332 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9333 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9334 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9335 : : I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9336 : : I40E_INSET_FLEX_PAYLOAD,
9337 : : [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9338 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9339 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9340 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9341 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9342 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9343 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9344 : : I40E_INSET_DST_PORT | I40E_INSET_SCTP_VT |
9345 : : I40E_INSET_FLEX_PAYLOAD,
9346 : : [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9347 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9348 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9349 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9350 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9351 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9352 : : I40E_INSET_IPV6_DST | I40E_INSET_TUNNEL_ID |
9353 : : I40E_INSET_FLEX_PAYLOAD,
9354 : : [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9355 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9356 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9357 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_LAST_ETHER_TYPE |
9358 : : I40E_INSET_FLEX_PAYLOAD,
9359 : : };
9360 : :
9361 : : /**
9362 : : * Flow director supports only fields defined in
9363 : : * union rte_eth_fdir_flow.
9364 : : */
9365 : : static const uint64_t valid_fdir_inset_table[] = {
9366 : : [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9367 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9368 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9369 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9370 : : I40E_INSET_IPV4_TTL,
9371 : : [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9372 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9373 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9374 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9375 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9376 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9377 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9378 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9379 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9380 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9381 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9382 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9383 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9384 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9385 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9386 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9387 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9388 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9389 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9390 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9391 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9392 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9393 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9394 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9395 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9396 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9397 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9398 : : [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9399 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9400 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9401 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9402 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9403 : : I40E_INSET_SCTP_VT,
9404 : : [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9405 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9406 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9407 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9408 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9409 : : I40E_INSET_IPV4_TTL,
9410 : : [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9411 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9412 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9413 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
9414 : : I40E_INSET_IPV6_HOP_LIMIT,
9415 : : [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9416 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9417 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9418 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9419 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9420 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9421 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9422 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9423 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9424 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9425 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9426 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9427 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9428 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9429 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9430 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9431 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9432 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9433 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9434 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9435 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9436 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9437 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9438 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9439 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9440 : : [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9441 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9442 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9443 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9444 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9445 : : I40E_INSET_SCTP_VT,
9446 : : [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9447 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9448 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9449 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
9450 : : I40E_INSET_IPV6_HOP_LIMIT,
9451 : : [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9452 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9453 : : I40E_INSET_LAST_ETHER_TYPE,
9454 : : };
9455 : :
9456 : 0 : if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
9457 : : return 0;
9458 [ # # ]: 0 : if (filter == RTE_ETH_FILTER_HASH)
9459 : 0 : valid = valid_hash_inset_table[pctype];
9460 : : else
9461 : 0 : valid = valid_fdir_inset_table[pctype];
9462 : :
9463 : : return valid;
9464 : : }
9465 : :
9466 : : /**
9467 : : * Validate if the input set is allowed for a specific PCTYPE
9468 : : */
9469 : : int
9470 [ # # ]: 0 : i40e_validate_input_set(enum i40e_filter_pctype pctype,
9471 : : enum rte_filter_type filter, uint64_t inset)
9472 : : {
9473 : : uint64_t valid;
9474 : :
9475 : : valid = i40e_get_valid_input_set(pctype, filter);
9476 [ # # ]: 0 : if (inset & (~valid))
9477 : 0 : return -EINVAL;
9478 : :
9479 : : return 0;
9480 : : }
9481 : :
9482 : : /* default input set fields combination per pctype */
9483 : : uint64_t
9484 : 0 : i40e_get_default_input_set(uint16_t pctype)
9485 : : {
9486 : : static const uint64_t default_inset_table[] = {
9487 : : [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9488 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
9489 : : [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9490 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9491 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9492 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9493 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9494 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9495 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9496 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9497 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9498 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9499 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9500 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9501 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9502 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9503 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9504 : : [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9505 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9506 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9507 : : I40E_INSET_SCTP_VT,
9508 : : [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9509 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
9510 : : [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9511 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
9512 : : [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9513 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9514 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9515 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9516 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9517 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9518 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9519 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9520 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9521 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9522 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9523 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9524 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9525 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9526 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9527 : : [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9528 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9529 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9530 : : I40E_INSET_SCTP_VT,
9531 : : [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9532 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
9533 : : [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9534 : : I40E_INSET_LAST_ETHER_TYPE,
9535 : : };
9536 : :
9537 [ # # ]: 0 : if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
9538 : : return 0;
9539 : :
9540 : 0 : return default_inset_table[pctype];
9541 : : }
9542 : :
9543 : : /**
9544 : : * Translate the input set from bit masks to register aware bit masks
9545 : : * and vice versa
9546 : : */
9547 : : uint64_t
9548 : 0 : i40e_translate_input_set_reg(enum i40e_mac_type type, uint64_t input)
9549 : : {
9550 : : uint64_t val = 0;
9551 : : uint16_t i;
9552 : :
9553 : : struct inset_map {
9554 : : uint64_t inset;
9555 : : uint64_t inset_reg;
9556 : : };
9557 : :
9558 : : static const struct inset_map inset_map_common[] = {
9559 : : {I40E_INSET_DMAC, I40E_REG_INSET_L2_DMAC},
9560 : : {I40E_INSET_SMAC, I40E_REG_INSET_L2_SMAC},
9561 : : {I40E_INSET_VLAN_OUTER, I40E_REG_INSET_L2_OUTER_VLAN},
9562 : : {I40E_INSET_VLAN_INNER, I40E_REG_INSET_L2_INNER_VLAN},
9563 : : {I40E_INSET_LAST_ETHER_TYPE, I40E_REG_INSET_LAST_ETHER_TYPE},
9564 : : {I40E_INSET_IPV4_TOS, I40E_REG_INSET_L3_IP4_TOS},
9565 : : {I40E_INSET_IPV6_SRC, I40E_REG_INSET_L3_SRC_IP6},
9566 : : {I40E_INSET_IPV6_DST, I40E_REG_INSET_L3_DST_IP6},
9567 : : {I40E_INSET_IPV6_TC, I40E_REG_INSET_L3_IP6_TC},
9568 : : {I40E_INSET_IPV6_NEXT_HDR, I40E_REG_INSET_L3_IP6_NEXT_HDR},
9569 : : {I40E_INSET_IPV6_HOP_LIMIT, I40E_REG_INSET_L3_IP6_HOP_LIMIT},
9570 : : {I40E_INSET_SRC_PORT, I40E_REG_INSET_L4_SRC_PORT},
9571 : : {I40E_INSET_DST_PORT, I40E_REG_INSET_L4_DST_PORT},
9572 : : {I40E_INSET_SCTP_VT, I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG},
9573 : : {I40E_INSET_TUNNEL_ID, I40E_REG_INSET_TUNNEL_ID},
9574 : : {I40E_INSET_TUNNEL_DMAC,
9575 : : I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC},
9576 : : {I40E_INSET_TUNNEL_IPV4_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP4},
9577 : : {I40E_INSET_TUNNEL_IPV6_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP6},
9578 : : {I40E_INSET_TUNNEL_SRC_PORT,
9579 : : I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT},
9580 : : {I40E_INSET_TUNNEL_DST_PORT,
9581 : : I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT},
9582 : : {I40E_INSET_VLAN_TUNNEL, I40E_REG_INSET_TUNNEL_VLAN},
9583 : : {I40E_INSET_FLEX_PAYLOAD_W1, I40E_REG_INSET_FLEX_PAYLOAD_WORD1},
9584 : : {I40E_INSET_FLEX_PAYLOAD_W2, I40E_REG_INSET_FLEX_PAYLOAD_WORD2},
9585 : : {I40E_INSET_FLEX_PAYLOAD_W3, I40E_REG_INSET_FLEX_PAYLOAD_WORD3},
9586 : : {I40E_INSET_FLEX_PAYLOAD_W4, I40E_REG_INSET_FLEX_PAYLOAD_WORD4},
9587 : : {I40E_INSET_FLEX_PAYLOAD_W5, I40E_REG_INSET_FLEX_PAYLOAD_WORD5},
9588 : : {I40E_INSET_FLEX_PAYLOAD_W6, I40E_REG_INSET_FLEX_PAYLOAD_WORD6},
9589 : : {I40E_INSET_FLEX_PAYLOAD_W7, I40E_REG_INSET_FLEX_PAYLOAD_WORD7},
9590 : : {I40E_INSET_FLEX_PAYLOAD_W8, I40E_REG_INSET_FLEX_PAYLOAD_WORD8},
9591 : : };
9592 : :
9593 : : /* some different registers map in x722*/
9594 : : static const struct inset_map inset_map_diff_x722[] = {
9595 : : {I40E_INSET_IPV4_SRC, I40E_X722_REG_INSET_L3_SRC_IP4},
9596 : : {I40E_INSET_IPV4_DST, I40E_X722_REG_INSET_L3_DST_IP4},
9597 : : {I40E_INSET_IPV4_PROTO, I40E_X722_REG_INSET_L3_IP4_PROTO},
9598 : : {I40E_INSET_IPV4_TTL, I40E_X722_REG_INSET_L3_IP4_TTL},
9599 : : };
9600 : :
9601 : : static const struct inset_map inset_map_diff_not_x722[] = {
9602 : : {I40E_INSET_IPV4_SRC, I40E_REG_INSET_L3_SRC_IP4},
9603 : : {I40E_INSET_IPV4_DST, I40E_REG_INSET_L3_DST_IP4},
9604 : : {I40E_INSET_IPV4_PROTO, I40E_REG_INSET_L3_IP4_PROTO},
9605 : : {I40E_INSET_IPV4_TTL, I40E_REG_INSET_L3_IP4_TTL},
9606 : : };
9607 : :
9608 [ # # ]: 0 : if (input == 0)
9609 : : return val;
9610 : :
9611 : : /* Translate input set to register aware inset */
9612 [ # # ]: 0 : if (type == I40E_MAC_X722) {
9613 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_map_diff_x722); i++) {
9614 [ # # ]: 0 : if (input & inset_map_diff_x722[i].inset)
9615 : 0 : val |= inset_map_diff_x722[i].inset_reg;
9616 : : }
9617 : : } else {
9618 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_map_diff_not_x722); i++) {
9619 [ # # ]: 0 : if (input & inset_map_diff_not_x722[i].inset)
9620 : 0 : val |= inset_map_diff_not_x722[i].inset_reg;
9621 : : }
9622 : : }
9623 : :
9624 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_map_common); i++) {
9625 [ # # ]: 0 : if (input & inset_map_common[i].inset)
9626 : 0 : val |= inset_map_common[i].inset_reg;
9627 : : }
9628 : :
9629 : : return val;
9630 : : }
9631 : :
9632 : : static int
9633 : 0 : i40e_get_inset_field_offset(struct i40e_hw *hw, uint32_t pit_reg_start,
9634 : : uint32_t pit_reg_count, uint32_t hdr_off)
9635 : : {
9636 : 0 : const uint32_t pit_reg_end = pit_reg_start + pit_reg_count;
9637 : 0 : uint32_t field_off = I40E_FDIR_FIELD_OFFSET(hdr_off);
9638 : : uint32_t i, reg_val, src_off, count;
9639 : :
9640 [ # # ]: 0 : for (i = pit_reg_start; i < pit_reg_end; i++) {
9641 : 0 : reg_val = i40e_read_rx_ctl(hw, I40E_GLQF_PIT(i));
9642 : :
9643 : 0 : src_off = I40E_GLQF_PIT_SOURCE_OFF_GET(reg_val);
9644 : 0 : count = I40E_GLQF_PIT_FSIZE_GET(reg_val);
9645 : :
9646 [ # # # # ]: 0 : if (src_off <= field_off && (src_off + count) > field_off)
9647 : : break;
9648 : : }
9649 : :
9650 [ # # ]: 0 : if (i >= pit_reg_end) {
9651 : 0 : PMD_DRV_LOG(ERR,
9652 : : "Hardware GLQF_PIT configuration does not support this field mask");
9653 : 0 : return -1;
9654 : : }
9655 : :
9656 : 0 : return I40E_GLQF_PIT_DEST_OFF_GET(reg_val) + field_off - src_off;
9657 : : }
9658 : :
9659 : : int
9660 : 0 : i40e_generate_inset_mask_reg(struct i40e_hw *hw, uint64_t inset,
9661 : : uint32_t *mask, uint8_t nb_elem)
9662 : : {
9663 : : static const uint64_t mask_inset[] = {
9664 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL,
9665 : : I40E_INSET_IPV6_NEXT_HDR | I40E_INSET_IPV6_HOP_LIMIT };
9666 : :
9667 : : static const struct {
9668 : : uint64_t inset;
9669 : : uint32_t mask;
9670 : : uint32_t offset;
9671 : : } inset_mask_offset_map[] = {
9672 : : { I40E_INSET_IPV4_TOS, I40E_INSET_IPV4_TOS_MASK,
9673 : : offsetof(struct rte_ipv4_hdr, type_of_service) },
9674 : :
9675 : : { I40E_INSET_IPV4_PROTO, I40E_INSET_IPV4_PROTO_MASK,
9676 : : offsetof(struct rte_ipv4_hdr, next_proto_id) },
9677 : :
9678 : : { I40E_INSET_IPV4_TTL, I40E_INSET_IPV4_TTL_MASK,
9679 : : offsetof(struct rte_ipv4_hdr, time_to_live) },
9680 : :
9681 : : { I40E_INSET_IPV6_TC, I40E_INSET_IPV6_TC_MASK,
9682 : : offsetof(struct rte_ipv6_hdr, vtc_flow) },
9683 : :
9684 : : { I40E_INSET_IPV6_NEXT_HDR, I40E_INSET_IPV6_NEXT_HDR_MASK,
9685 : : offsetof(struct rte_ipv6_hdr, proto) },
9686 : :
9687 : : { I40E_INSET_IPV6_HOP_LIMIT, I40E_INSET_IPV6_HOP_LIMIT_MASK,
9688 : : offsetof(struct rte_ipv6_hdr, hop_limits) },
9689 : : };
9690 : :
9691 : : uint32_t i;
9692 : : int idx = 0;
9693 : :
9694 [ # # ]: 0 : assert(mask);
9695 [ # # ]: 0 : if (!inset)
9696 : : return 0;
9697 : :
9698 [ # # ]: 0 : for (i = 0; i < RTE_DIM(mask_inset); i++) {
9699 : : /* Clear the inset bit, if no MASK is required,
9700 : : * for example proto + ttl
9701 : : */
9702 [ # # ]: 0 : if ((mask_inset[i] & inset) == mask_inset[i]) {
9703 : 0 : inset &= ~mask_inset[i];
9704 [ # # ]: 0 : if (!inset)
9705 : : return 0;
9706 : : }
9707 : : }
9708 : :
9709 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_mask_offset_map); i++) {
9710 : : uint32_t pit_start, pit_count;
9711 : : int offset;
9712 : :
9713 [ # # ]: 0 : if (!(inset_mask_offset_map[i].inset & inset))
9714 : 0 : continue;
9715 : :
9716 [ # # ]: 0 : if (inset_mask_offset_map[i].inset &
9717 : : (I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9718 : : I40E_INSET_IPV4_TTL)) {
9719 : : pit_start = I40E_GLQF_PIT_IPV4_START;
9720 : : pit_count = I40E_GLQF_PIT_IPV4_COUNT;
9721 : : } else {
9722 : : pit_start = I40E_GLQF_PIT_IPV6_START;
9723 : : pit_count = I40E_GLQF_PIT_IPV6_COUNT;
9724 : : }
9725 : :
9726 : 0 : offset = i40e_get_inset_field_offset(hw, pit_start, pit_count,
9727 : 0 : inset_mask_offset_map[i].offset);
9728 : :
9729 [ # # ]: 0 : if (offset < 0)
9730 : : return -EINVAL;
9731 : :
9732 [ # # ]: 0 : if (idx >= nb_elem) {
9733 : 0 : PMD_DRV_LOG(ERR,
9734 : : "Configuration of inset mask out of range %u",
9735 : : nb_elem);
9736 : 0 : return -ERANGE;
9737 : : }
9738 : :
9739 : 0 : mask[idx] = I40E_GLQF_PIT_BUILD((uint32_t)offset,
9740 : : inset_mask_offset_map[i].mask);
9741 : 0 : idx++;
9742 : : }
9743 : :
9744 : : return idx;
9745 : : }
9746 : :
9747 : : void
9748 : 0 : i40e_check_write_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
9749 : : {
9750 : 0 : uint32_t reg = i40e_read_rx_ctl(hw, addr);
9751 : :
9752 : 0 : PMD_DRV_LOG(DEBUG, "[0x%08x] original: 0x%08x", addr, reg);
9753 [ # # ]: 0 : if (reg != val)
9754 : 0 : i40e_write_rx_ctl(hw, addr, val);
9755 : 0 : PMD_DRV_LOG(DEBUG, "[0x%08x] after: 0x%08x", addr,
9756 : : (uint32_t)i40e_read_rx_ctl(hw, addr));
9757 : 0 : }
9758 : :
9759 : : void
9760 : 0 : i40e_check_write_global_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
9761 : : {
9762 : 0 : uint32_t reg = i40e_read_rx_ctl(hw, addr);
9763 : 0 : struct rte_eth_dev_data *dev_data =
9764 : 0 : ((struct i40e_adapter *)hw->back)->pf.dev_data;
9765 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[dev_data->port_id];
9766 : :
9767 [ # # ]: 0 : if (reg != val) {
9768 : 0 : i40e_write_rx_ctl(hw, addr, val);
9769 : 0 : PMD_DRV_LOG(WARNING,
9770 : : "i40e device %s changed global register [0x%08x]."
9771 : : " original: 0x%08x, new: 0x%08x",
9772 : : dev->device->name, addr, reg,
9773 : : (uint32_t)i40e_read_rx_ctl(hw, addr));
9774 : : }
9775 : 0 : }
9776 : :
9777 : : static void
9778 : 0 : i40e_filter_input_set_init(struct i40e_pf *pf)
9779 : : {
9780 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9781 : : enum i40e_filter_pctype pctype;
9782 : : uint64_t input_set, inset_reg;
9783 : 0 : uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9784 : : int num, i;
9785 : : uint16_t flow_type;
9786 : :
9787 : 0 : for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
9788 [ # # ]: 0 : pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++) {
9789 : 0 : flow_type = i40e_pctype_to_flowtype(pf->adapter, pctype);
9790 : :
9791 [ # # ]: 0 : if (flow_type == RTE_ETH_FLOW_UNKNOWN)
9792 : 0 : continue;
9793 : :
9794 : 0 : input_set = i40e_get_default_input_set(pctype);
9795 : :
9796 : 0 : num = i40e_generate_inset_mask_reg(hw, input_set, mask_reg,
9797 : : I40E_INSET_MASK_NUM_REG);
9798 [ # # ]: 0 : if (num < 0)
9799 : 0 : return;
9800 [ # # # # ]: 0 : if (pf->support_multi_driver && num > 0) {
9801 : 0 : PMD_DRV_LOG(ERR, "Input set setting is not supported.");
9802 : 0 : return;
9803 : : }
9804 : 0 : inset_reg = i40e_translate_input_set_reg(hw->mac.type,
9805 : : input_set);
9806 : :
9807 : 0 : i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
9808 : : (uint32_t)(inset_reg & UINT32_MAX));
9809 : 0 : i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
9810 : 0 : (uint32_t)((inset_reg >>
9811 : : I40E_32_BIT_WIDTH) & UINT32_MAX));
9812 [ # # ]: 0 : if (!pf->support_multi_driver) {
9813 : 0 : i40e_check_write_global_reg(hw,
9814 : 0 : I40E_GLQF_HASH_INSET(0, pctype),
9815 : : (uint32_t)(inset_reg & UINT32_MAX));
9816 : 0 : i40e_check_write_global_reg(hw,
9817 : 0 : I40E_GLQF_HASH_INSET(1, pctype),
9818 : : (uint32_t)((inset_reg >>
9819 : : I40E_32_BIT_WIDTH) & UINT32_MAX));
9820 : :
9821 [ # # ]: 0 : for (i = 0; i < num; i++) {
9822 : 0 : i40e_check_write_global_reg(hw,
9823 : 0 : I40E_GLQF_FD_MSK(i, pctype),
9824 : : mask_reg[i]);
9825 : 0 : i40e_check_write_global_reg(hw,
9826 : : I40E_GLQF_HASH_MSK(i, pctype),
9827 : : mask_reg[i]);
9828 : : }
9829 : : /*clear unused mask registers of the pctype */
9830 [ # # ]: 0 : for (i = num; i < I40E_INSET_MASK_NUM_REG; i++) {
9831 : 0 : i40e_check_write_global_reg(hw,
9832 : 0 : I40E_GLQF_FD_MSK(i, pctype),
9833 : : 0);
9834 : 0 : i40e_check_write_global_reg(hw,
9835 : : I40E_GLQF_HASH_MSK(i, pctype),
9836 : : 0);
9837 : : }
9838 : : } else {
9839 : 0 : PMD_DRV_LOG(ERR, "Input set setting is not supported.");
9840 : : }
9841 : 0 : I40E_WRITE_FLUSH(hw);
9842 : :
9843 : : /* store the default input set */
9844 [ # # ]: 0 : if (!pf->support_multi_driver)
9845 : 0 : pf->hash_input_set[pctype] = input_set;
9846 : 0 : pf->fdir.input_set[pctype] = input_set;
9847 : : }
9848 : : }
9849 : :
9850 : : int
9851 : 0 : i40e_set_hash_inset(struct i40e_hw *hw, uint64_t input_set,
9852 : : uint32_t pctype, bool add)
9853 : : {
9854 : 0 : struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
9855 : 0 : uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9856 : : uint64_t inset_reg = 0;
9857 : : int num, i;
9858 : :
9859 [ # # ]: 0 : if (pf->support_multi_driver) {
9860 : 0 : PMD_DRV_LOG(ERR,
9861 : : "Modify input set is not permitted when multi-driver enabled.");
9862 : 0 : return -EPERM;
9863 : : }
9864 : :
9865 : : /* For X722, get translated pctype in fd pctype register */
9866 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
9867 : 0 : pctype = i40e_read_rx_ctl(hw, I40E_GLQF_FD_PCTYPES(pctype));
9868 : :
9869 [ # # ]: 0 : if (add) {
9870 : : /* get inset value in register */
9871 : 0 : inset_reg = i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, pctype));
9872 : 0 : inset_reg <<= I40E_32_BIT_WIDTH;
9873 : 0 : inset_reg |= i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, pctype));
9874 : 0 : input_set |= pf->hash_input_set[pctype];
9875 : : }
9876 : 0 : num = i40e_generate_inset_mask_reg(hw, input_set, mask_reg,
9877 : : I40E_INSET_MASK_NUM_REG);
9878 [ # # ]: 0 : if (num < 0)
9879 : : return -EINVAL;
9880 : :
9881 : 0 : inset_reg |= i40e_translate_input_set_reg(hw->mac.type, input_set);
9882 : :
9883 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(0, pctype),
9884 : : (uint32_t)(inset_reg & UINT32_MAX));
9885 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(1, pctype),
9886 : 0 : (uint32_t)((inset_reg >>
9887 : : I40E_32_BIT_WIDTH) & UINT32_MAX));
9888 : :
9889 [ # # ]: 0 : for (i = 0; i < num; i++)
9890 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
9891 : : mask_reg[i]);
9892 : : /*clear unused mask registers of the pctype */
9893 [ # # ]: 0 : for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
9894 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
9895 : : 0);
9896 : 0 : I40E_WRITE_FLUSH(hw);
9897 : :
9898 : 0 : pf->hash_input_set[pctype] = input_set;
9899 : 0 : return 0;
9900 : : }
9901 : :
9902 : : /* Convert ethertype filter structure */
9903 : : static int
9904 : : i40e_ethertype_filter_convert(const struct rte_eth_ethertype_filter *input,
9905 : : struct i40e_ethertype_filter *filter)
9906 : : {
9907 [ # # ]: 0 : rte_memcpy(&filter->input.mac_addr, &input->mac_addr,
9908 : : RTE_ETHER_ADDR_LEN);
9909 : 0 : filter->input.ether_type = input->ether_type;
9910 : 0 : filter->flags = input->flags;
9911 : 0 : filter->queue = input->queue;
9912 : :
9913 : : return 0;
9914 : : }
9915 : :
9916 : : /* Check if there exists the ethertype filter */
9917 : : struct i40e_ethertype_filter *
9918 : 0 : i40e_sw_ethertype_filter_lookup(struct i40e_ethertype_rule *ethertype_rule,
9919 : : const struct i40e_ethertype_filter_input *input)
9920 : : {
9921 : : int ret;
9922 : :
9923 : 0 : ret = rte_hash_lookup(ethertype_rule->hash_table, (const void *)input);
9924 [ # # ]: 0 : if (ret < 0)
9925 : : return NULL;
9926 : :
9927 : 0 : return ethertype_rule->hash_map[ret];
9928 : : }
9929 : :
9930 : : /* Add ethertype filter in SW list */
9931 : : static int
9932 : 0 : i40e_sw_ethertype_filter_insert(struct i40e_pf *pf,
9933 : : struct i40e_ethertype_filter *filter)
9934 : : {
9935 : : struct i40e_ethertype_rule *rule = &pf->ethertype;
9936 : : int ret;
9937 : :
9938 : 0 : ret = rte_hash_add_key(rule->hash_table, &filter->input);
9939 [ # # ]: 0 : if (ret < 0) {
9940 : 0 : PMD_DRV_LOG(ERR,
9941 : : "Failed to insert ethertype filter"
9942 : : " to hash table %d!",
9943 : : ret);
9944 : 0 : return ret;
9945 : : }
9946 : 0 : rule->hash_map[ret] = filter;
9947 : :
9948 : 0 : TAILQ_INSERT_TAIL(&rule->ethertype_list, filter, rules);
9949 : :
9950 : 0 : return 0;
9951 : : }
9952 : :
9953 : : /* Delete ethertype filter in SW list */
9954 : : int
9955 : 0 : i40e_sw_ethertype_filter_del(struct i40e_pf *pf,
9956 : : struct i40e_ethertype_filter_input *input)
9957 : : {
9958 : : struct i40e_ethertype_rule *rule = &pf->ethertype;
9959 : : struct i40e_ethertype_filter *filter;
9960 : : int ret;
9961 : :
9962 : 0 : ret = rte_hash_del_key(rule->hash_table, input);
9963 [ # # ]: 0 : if (ret < 0) {
9964 : 0 : PMD_DRV_LOG(ERR,
9965 : : "Failed to delete ethertype filter"
9966 : : " to hash table %d!",
9967 : : ret);
9968 : 0 : return ret;
9969 : : }
9970 : 0 : filter = rule->hash_map[ret];
9971 : 0 : rule->hash_map[ret] = NULL;
9972 : :
9973 [ # # ]: 0 : TAILQ_REMOVE(&rule->ethertype_list, filter, rules);
9974 : 0 : rte_free(filter);
9975 : :
9976 : 0 : return 0;
9977 : : }
9978 : :
9979 : : /*
9980 : : * Configure ethertype filter, which can director packet by filtering
9981 : : * with mac address and ether_type or only ether_type
9982 : : */
9983 : : int
9984 : 0 : i40e_ethertype_filter_set(struct i40e_pf *pf,
9985 : : struct rte_eth_ethertype_filter *filter,
9986 : : bool add)
9987 : : {
9988 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9989 : 0 : struct i40e_ethertype_rule *ethertype_rule = &pf->ethertype;
9990 : : struct i40e_ethertype_filter *ethertype_filter, *node;
9991 : : struct i40e_ethertype_filter check_filter;
9992 : : struct i40e_control_filter_stats stats;
9993 : : uint16_t flags = 0;
9994 : : int ret;
9995 : :
9996 [ # # ]: 0 : if (filter->queue >= pf->dev_data->nb_rx_queues) {
9997 : 0 : PMD_DRV_LOG(ERR, "Invalid queue ID");
9998 : 0 : return -EINVAL;
9999 : : }
10000 [ # # ]: 0 : if (filter->ether_type == RTE_ETHER_TYPE_IPV4 ||
10001 : : filter->ether_type == RTE_ETHER_TYPE_IPV6) {
10002 : 0 : PMD_DRV_LOG(ERR,
10003 : : "unsupported ether_type(0x%04x) in control packet filter.",
10004 : : filter->ether_type);
10005 : 0 : return -EINVAL;
10006 : : }
10007 [ # # ]: 0 : if (filter->ether_type == RTE_ETHER_TYPE_VLAN)
10008 : 0 : PMD_DRV_LOG(WARNING,
10009 : : "filter vlan ether_type in first tag is not supported.");
10010 : :
10011 : : /* Check if there is the filter in SW list */
10012 : : memset(&check_filter, 0, sizeof(check_filter));
10013 : : i40e_ethertype_filter_convert(filter, &check_filter);
10014 : 0 : node = i40e_sw_ethertype_filter_lookup(ethertype_rule,
10015 : : &check_filter.input);
10016 [ # # ]: 0 : if (add && node) {
10017 : 0 : PMD_DRV_LOG(ERR, "Conflict with existing ethertype rules!");
10018 : 0 : return -EINVAL;
10019 : : }
10020 : :
10021 [ # # ]: 0 : if (!add && !node) {
10022 : 0 : PMD_DRV_LOG(ERR, "There's no corresponding ethertype filter!");
10023 : 0 : return -EINVAL;
10024 : : }
10025 : :
10026 [ # # ]: 0 : if (!(filter->flags & RTE_ETHTYPE_FLAGS_MAC))
10027 : : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
10028 [ # # ]: 0 : if (filter->flags & RTE_ETHTYPE_FLAGS_DROP)
10029 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
10030 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
10031 : :
10032 : : memset(&stats, 0, sizeof(stats));
10033 : 0 : ret = i40e_aq_add_rem_control_packet_filter(hw,
10034 : 0 : filter->mac_addr.addr_bytes,
10035 : 0 : filter->ether_type, flags,
10036 : 0 : pf->main_vsi->seid,
10037 : 0 : filter->queue, add, &stats, NULL);
10038 : :
10039 : 0 : PMD_DRV_LOG(INFO,
10040 : : "add/rem control packet filter, return %d, mac_etype_used = %u, etype_used = %u, mac_etype_free = %u, etype_free = %u",
10041 : : ret, stats.mac_etype_used, stats.etype_used,
10042 : : stats.mac_etype_free, stats.etype_free);
10043 [ # # ]: 0 : if (ret < 0)
10044 : : return -ENOSYS;
10045 : :
10046 : : /* Add or delete a filter in SW list */
10047 [ # # ]: 0 : if (add) {
10048 : 0 : ethertype_filter = rte_zmalloc("ethertype_filter",
10049 : : sizeof(*ethertype_filter), 0);
10050 [ # # ]: 0 : if (ethertype_filter == NULL) {
10051 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory.");
10052 : 0 : return -ENOMEM;
10053 : : }
10054 : :
10055 : : rte_memcpy(ethertype_filter, &check_filter,
10056 : : sizeof(check_filter));
10057 : 0 : ret = i40e_sw_ethertype_filter_insert(pf, ethertype_filter);
10058 [ # # ]: 0 : if (ret < 0)
10059 : 0 : rte_free(ethertype_filter);
10060 : : } else {
10061 : 0 : ret = i40e_sw_ethertype_filter_del(pf, &node->input);
10062 : : }
10063 : :
10064 : : return ret;
10065 : : }
10066 : :
10067 : : static int
10068 : 0 : i40e_dev_flow_ops_get(struct rte_eth_dev *dev,
10069 : : const struct rte_flow_ops **ops)
10070 : : {
10071 [ # # ]: 0 : if (dev == NULL)
10072 : : return -EINVAL;
10073 : :
10074 : 0 : *ops = &i40e_flow_ops;
10075 : 0 : return 0;
10076 : : }
10077 : :
10078 : : /*
10079 : : * Check and enable Extended Tag.
10080 : : * Enabling Extended Tag is important for 40G performance.
10081 : : */
10082 : : static void
10083 : 0 : i40e_enable_extended_tag(struct rte_eth_dev *dev)
10084 : : {
10085 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
10086 : 0 : uint32_t buf = 0;
10087 : : int ret;
10088 : :
10089 : 0 : ret = rte_pci_read_config(pci_dev, &buf, sizeof(buf),
10090 : : PCI_DEV_CAP_REG);
10091 [ # # ]: 0 : if (ret < 0) {
10092 : 0 : PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
10093 : : PCI_DEV_CAP_REG);
10094 : 0 : return;
10095 : : }
10096 [ # # ]: 0 : if (!(buf & PCI_DEV_CAP_EXT_TAG_MASK)) {
10097 : 0 : PMD_DRV_LOG(ERR, "Does not support Extended Tag");
10098 : 0 : return;
10099 : : }
10100 : :
10101 : 0 : buf = 0;
10102 : 0 : ret = rte_pci_read_config(pci_dev, &buf, sizeof(buf),
10103 : : PCI_DEV_CTRL_REG);
10104 [ # # ]: 0 : if (ret < 0) {
10105 : 0 : PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
10106 : : PCI_DEV_CTRL_REG);
10107 : 0 : return;
10108 : : }
10109 [ # # ]: 0 : if (buf & PCI_DEV_CTRL_EXT_TAG_MASK) {
10110 : 0 : PMD_DRV_LOG(DEBUG, "Extended Tag has already been enabled");
10111 : 0 : return;
10112 : : }
10113 : 0 : buf |= PCI_DEV_CTRL_EXT_TAG_MASK;
10114 : 0 : ret = rte_pci_write_config(pci_dev, &buf, sizeof(buf),
10115 : : PCI_DEV_CTRL_REG);
10116 [ # # ]: 0 : if (ret < 0) {
10117 : 0 : PMD_DRV_LOG(ERR, "Failed to write PCI offset 0x%x",
10118 : : PCI_DEV_CTRL_REG);
10119 : 0 : return;
10120 : : }
10121 : : }
10122 : :
10123 : : /*
10124 : : * As some registers wouldn't be reset unless a global hardware reset,
10125 : : * hardware initialization is needed to put those registers into an
10126 : : * expected initial state.
10127 : : */
10128 : : static void
10129 : 0 : i40e_hw_init(struct rte_eth_dev *dev)
10130 : : {
10131 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10132 : :
10133 : 0 : i40e_enable_extended_tag(dev);
10134 : :
10135 : : /* clear the PF Queue Filter control register */
10136 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, 0);
10137 : :
10138 : : /* Disable symmetric hash per port */
10139 : 0 : i40e_set_symmetric_hash_enable_per_port(hw, 0);
10140 : 0 : }
10141 : :
10142 : : /*
10143 : : * For X722 it is possible to have multiple pctypes mapped to the same flowtype
10144 : : * however this function will return only one highest pctype index,
10145 : : * which is not quite correct. This is known problem of i40e driver
10146 : : * and needs to be fixed later.
10147 : : */
10148 : : enum i40e_filter_pctype
10149 : 0 : i40e_flowtype_to_pctype(const struct i40e_adapter *adapter, uint16_t flow_type)
10150 : : {
10151 : : int i;
10152 : : uint64_t pctype_mask;
10153 : :
10154 [ # # ]: 0 : if (flow_type < I40E_FLOW_TYPE_MAX) {
10155 : 0 : pctype_mask = adapter->pctypes_tbl[flow_type];
10156 [ # # ]: 0 : for (i = I40E_FILTER_PCTYPE_MAX - 1; i > 0; i--) {
10157 [ # # ]: 0 : if (pctype_mask & (1ULL << i))
10158 : 0 : return (enum i40e_filter_pctype)i;
10159 : : }
10160 : : }
10161 : : return I40E_FILTER_PCTYPE_INVALID;
10162 : : }
10163 : :
10164 : : uint16_t
10165 : 0 : i40e_pctype_to_flowtype(const struct i40e_adapter *adapter,
10166 : : enum i40e_filter_pctype pctype)
10167 : : {
10168 : : uint16_t flowtype;
10169 : 0 : uint64_t pctype_mask = 1ULL << pctype;
10170 : :
10171 [ # # ]: 0 : for (flowtype = RTE_ETH_FLOW_UNKNOWN + 1; flowtype < I40E_FLOW_TYPE_MAX;
10172 : 0 : flowtype++) {
10173 [ # # ]: 0 : if (adapter->pctypes_tbl[flowtype] & pctype_mask)
10174 : 0 : return flowtype;
10175 : : }
10176 : :
10177 : : return RTE_ETH_FLOW_UNKNOWN;
10178 : : }
10179 : :
10180 : : /*
10181 : : * On X710, performance number is far from the expectation on recent firmware
10182 : : * versions; on XL710, performance number is also far from the expectation on
10183 : : * recent firmware versions, if promiscuous mode is disabled, or promiscuous
10184 : : * mode is enabled and port MAC address is equal to the packet destination MAC
10185 : : * address. The fix for this issue may not be integrated in the following
10186 : : * firmware version. So the workaround in software driver is needed. It needs
10187 : : * to modify the initial values of 3 internal only registers for both X710 and
10188 : : * XL710. Note that the values for X710 or XL710 could be different, and the
10189 : : * workaround can be removed when it is fixed in firmware in the future.
10190 : : */
10191 : :
10192 : : /* For both X710 and XL710 */
10193 : : #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1 0x10000200
10194 : : #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2 0x203F0200
10195 : : #define I40E_GL_SWR_PRI_JOIN_MAP_0 0x26CE00
10196 : :
10197 : : #define I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x011f0200
10198 : : #define I40E_GL_SWR_PRI_JOIN_MAP_2 0x26CE08
10199 : :
10200 : : /* For X722 */
10201 : : #define I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE 0x20000200
10202 : : #define I40E_X722_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x013F0200
10203 : :
10204 : : /* For X710 */
10205 : : #define I40E_GL_SWR_PM_UP_THR_EF_VALUE 0x03030303
10206 : : /* For XL710 */
10207 : : #define I40E_GL_SWR_PM_UP_THR_SF_VALUE 0x06060606
10208 : : #define I40E_GL_SWR_PM_UP_THR 0x269FBC
10209 : :
10210 : : /*
10211 : : * GL_SWR_PM_UP_THR:
10212 : : * The value is not impacted from the link speed, its value is set according
10213 : : * to the total number of ports for a better pipe-monitor configuration.
10214 : : */
10215 : : static bool
10216 : 0 : i40e_get_swr_pm_cfg(struct i40e_hw *hw, uint32_t *value)
10217 : : {
10218 : : #define I40E_GL_SWR_PM_EF_DEVICE(dev) \
10219 : : .device_id = (dev), \
10220 : : .val = I40E_GL_SWR_PM_UP_THR_EF_VALUE
10221 : :
10222 : : #define I40E_GL_SWR_PM_SF_DEVICE(dev) \
10223 : : .device_id = (dev), \
10224 : : .val = I40E_GL_SWR_PM_UP_THR_SF_VALUE
10225 : :
10226 : : static const struct {
10227 : : uint16_t device_id;
10228 : : uint32_t val;
10229 : : } swr_pm_table[] = {
10230 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_SFP_XL710) },
10231 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_KX_C) },
10232 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_10G_BASE_T) },
10233 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_10G_BASE_T4) },
10234 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_SFP_X722) },
10235 : :
10236 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_KX_B) },
10237 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_QSFP_A) },
10238 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_QSFP_B) },
10239 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_20G_KR2) },
10240 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_20G_KR2_A) },
10241 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_25G_B) },
10242 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_25G_SFP28) },
10243 : : };
10244 : : uint32_t i;
10245 : :
10246 [ # # ]: 0 : if (value == NULL) {
10247 : 0 : PMD_DRV_LOG(ERR, "value is NULL");
10248 : 0 : return false;
10249 : : }
10250 : :
10251 [ # # ]: 0 : for (i = 0; i < RTE_DIM(swr_pm_table); i++) {
10252 [ # # ]: 0 : if (hw->device_id == swr_pm_table[i].device_id) {
10253 : 0 : *value = swr_pm_table[i].val;
10254 : :
10255 : 0 : PMD_DRV_LOG(DEBUG, "Device 0x%x with GL_SWR_PM_UP_THR "
10256 : : "value - 0x%08x",
10257 : : hw->device_id, *value);
10258 : 0 : return true;
10259 : : }
10260 : : }
10261 : :
10262 : : return false;
10263 : : }
10264 : :
10265 : : static int
10266 : 0 : i40e_dev_sync_phy_type(struct i40e_hw *hw)
10267 : : {
10268 : : enum i40e_status_code status;
10269 : : struct i40e_aq_get_phy_abilities_resp phy_ab;
10270 : : int ret = -ENOTSUP;
10271 : : int retries = 0;
10272 : :
10273 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, true, &phy_ab,
10274 : : NULL);
10275 : :
10276 [ # # ]: 0 : while (status) {
10277 : 0 : PMD_INIT_LOG(WARNING, "Failed to sync phy type: status=%d",
10278 : : status);
10279 : 0 : retries++;
10280 : 0 : rte_delay_us(100000);
10281 [ # # ]: 0 : if (retries < 5)
10282 : 0 : status = i40e_aq_get_phy_capabilities(hw, false,
10283 : : true, &phy_ab, NULL);
10284 : : else
10285 : : return ret;
10286 : : }
10287 : : return 0;
10288 : : }
10289 : :
10290 : : static void
10291 : 0 : i40e_configure_registers(struct i40e_hw *hw)
10292 : : {
10293 : : static struct {
10294 : : uint32_t addr;
10295 : : uint64_t val;
10296 : : } reg_table[] = {
10297 : : {I40E_GL_SWR_PRI_JOIN_MAP_0, 0},
10298 : : {I40E_GL_SWR_PRI_JOIN_MAP_2, 0},
10299 : : {I40E_GL_SWR_PM_UP_THR, 0}, /* Compute value dynamically */
10300 : : };
10301 : : uint64_t reg;
10302 : : uint32_t i;
10303 : : int ret;
10304 : :
10305 [ # # ]: 0 : for (i = 0; i < RTE_DIM(reg_table); i++) {
10306 [ # # ]: 0 : if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_0) {
10307 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) /* For X722 */
10308 : 0 : reg_table[i].val =
10309 : : I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE;
10310 : : else /* For X710/XL710/XXV710 */
10311 [ # # ]: 0 : if (hw->aq.fw_maj_ver < 6)
10312 : 0 : reg_table[i].val =
10313 : : I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1;
10314 : : else
10315 : 0 : reg_table[i].val =
10316 : : I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2;
10317 : : }
10318 : :
10319 [ # # ]: 0 : if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_2) {
10320 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) /* For X722 */
10321 : 0 : reg_table[i].val =
10322 : : I40E_X722_GL_SWR_PRI_JOIN_MAP_2_VALUE;
10323 : : else /* For X710/XL710/XXV710 */
10324 : 0 : reg_table[i].val =
10325 : : I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE;
10326 : : }
10327 : :
10328 [ # # ]: 0 : if (reg_table[i].addr == I40E_GL_SWR_PM_UP_THR) {
10329 : : uint32_t cfg_val;
10330 : :
10331 [ # # ]: 0 : if (!i40e_get_swr_pm_cfg(hw, &cfg_val)) {
10332 : 0 : PMD_DRV_LOG(DEBUG, "Device 0x%x skips "
10333 : : "GL_SWR_PM_UP_THR value fixup",
10334 : : hw->device_id);
10335 : 0 : continue;
10336 : : }
10337 : :
10338 : 0 : reg_table[i].val = cfg_val;
10339 : : }
10340 : :
10341 : 0 : ret = i40e_aq_debug_read_register(hw, reg_table[i].addr,
10342 : : ®, NULL);
10343 [ # # ]: 0 : if (ret < 0) {
10344 : 0 : PMD_DRV_LOG(ERR, "Failed to read from 0x%"PRIx32,
10345 : : reg_table[i].addr);
10346 : 0 : break;
10347 : : }
10348 : 0 : PMD_DRV_LOG(DEBUG, "Read from 0x%"PRIx32": 0x%"PRIx64,
10349 : : reg_table[i].addr, reg);
10350 [ # # ]: 0 : if (reg == reg_table[i].val)
10351 : 0 : continue;
10352 : :
10353 : 0 : ret = i40e_aq_debug_write_register(hw, reg_table[i].addr,
10354 : : reg_table[i].val, NULL);
10355 [ # # ]: 0 : if (ret < 0) {
10356 : 0 : PMD_DRV_LOG(ERR,
10357 : : "Failed to write 0x%"PRIx64" to the address of 0x%"PRIx32,
10358 : : reg_table[i].val, reg_table[i].addr);
10359 : 0 : break;
10360 : : }
10361 : 0 : PMD_DRV_LOG(DEBUG, "Write 0x%"PRIx64" to the address of "
10362 : : "0x%"PRIx32, reg_table[i].val, reg_table[i].addr);
10363 : : }
10364 : 0 : }
10365 : :
10366 : : #define I40E_VSI_TSR_QINQ_CONFIG 0xc030
10367 : : #define I40E_VSI_L2TAGSTXVALID(_i) (0x00042800 + ((_i) * 4))
10368 : : #define I40E_VSI_L2TAGSTXVALID_QINQ 0xab
10369 : : static int
10370 : 0 : i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi)
10371 : : {
10372 : : uint32_t reg;
10373 : : int ret;
10374 : :
10375 [ # # ]: 0 : if (vsi->vsi_id >= I40E_MAX_NUM_VSIS) {
10376 : 0 : PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
10377 : 0 : return -EINVAL;
10378 : : }
10379 : :
10380 : : /* Configure for double VLAN RX stripping */
10381 : 0 : reg = I40E_READ_REG(hw, I40E_VSI_TSR(vsi->vsi_id));
10382 [ # # ]: 0 : if ((reg & I40E_VSI_TSR_QINQ_CONFIG) != I40E_VSI_TSR_QINQ_CONFIG) {
10383 : 0 : reg |= I40E_VSI_TSR_QINQ_CONFIG;
10384 : 0 : ret = i40e_aq_debug_write_register(hw,
10385 : 0 : I40E_VSI_TSR(vsi->vsi_id),
10386 : : reg, NULL);
10387 [ # # ]: 0 : if (ret < 0) {
10388 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI_TSR[%d]",
10389 : : vsi->vsi_id);
10390 : 0 : return I40E_ERR_CONFIG;
10391 : : }
10392 : : }
10393 : :
10394 : : /* Configure for double VLAN TX insertion */
10395 : 0 : reg = I40E_READ_REG(hw, I40E_VSI_L2TAGSTXVALID(vsi->vsi_id));
10396 [ # # ]: 0 : if ((reg & 0xff) != I40E_VSI_L2TAGSTXVALID_QINQ) {
10397 : : reg = I40E_VSI_L2TAGSTXVALID_QINQ;
10398 : 0 : ret = i40e_aq_debug_write_register(hw,
10399 : 0 : I40E_VSI_L2TAGSTXVALID(
10400 : : vsi->vsi_id), reg, NULL);
10401 [ # # ]: 0 : if (ret < 0) {
10402 : 0 : PMD_DRV_LOG(ERR,
10403 : : "Failed to update VSI_L2TAGSTXVALID[%d]",
10404 : : vsi->vsi_id);
10405 : 0 : return I40E_ERR_CONFIG;
10406 : : }
10407 : : }
10408 : :
10409 : : return 0;
10410 : : }
10411 : :
10412 : : static uint64_t
10413 : : i40e_read_systime_cyclecounter(struct rte_eth_dev *dev)
10414 : : {
10415 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10416 : : uint64_t systim_cycles;
10417 : :
10418 : 0 : systim_cycles = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_L);
10419 : 0 : systim_cycles |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_H)
10420 [ # # ]: 0 : << 32;
10421 : :
10422 : : return systim_cycles;
10423 : : }
10424 : :
10425 : : static uint64_t
10426 : : i40e_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev, uint8_t index)
10427 : : {
10428 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10429 : : uint64_t rx_tstamp;
10430 : :
10431 : 0 : rx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_L(index));
10432 : 0 : rx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(index))
10433 [ # # ]: 0 : << 32;
10434 : :
10435 : : return rx_tstamp;
10436 : : }
10437 : :
10438 : : static uint64_t
10439 : : i40e_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
10440 : : {
10441 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10442 : : uint64_t tx_tstamp;
10443 : :
10444 : 0 : tx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_L);
10445 : 0 : tx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H)
10446 [ # # ]: 0 : << 32;
10447 : :
10448 : : return tx_tstamp;
10449 : : }
10450 : :
10451 : : static void
10452 : 0 : i40e_start_timecounters(struct rte_eth_dev *dev)
10453 : : {
10454 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10455 : : struct i40e_adapter *adapter = dev->data->dev_private;
10456 : : struct rte_eth_link link;
10457 : : uint32_t tsync_inc_l;
10458 : : uint32_t tsync_inc_h;
10459 : :
10460 : : /* Get current link speed. */
10461 : 0 : i40e_dev_link_update(dev, 1);
10462 : : rte_eth_linkstatus_get(dev, &link);
10463 : :
10464 [ # # # # ]: 0 : switch (link.link_speed) {
10465 : : case RTE_ETH_SPEED_NUM_40G:
10466 : : case RTE_ETH_SPEED_NUM_25G:
10467 : : tsync_inc_l = I40E_PTP_40GB_INCVAL & 0xFFFFFFFF;
10468 : : tsync_inc_h = I40E_PTP_40GB_INCVAL >> 32;
10469 : : break;
10470 : 0 : case RTE_ETH_SPEED_NUM_10G:
10471 : : tsync_inc_l = I40E_PTP_10GB_INCVAL & 0xFFFFFFFF;
10472 : : tsync_inc_h = I40E_PTP_10GB_INCVAL >> 32;
10473 : 0 : break;
10474 : 0 : case RTE_ETH_SPEED_NUM_1G:
10475 : : tsync_inc_l = I40E_PTP_1GB_INCVAL & 0xFFFFFFFF;
10476 : : tsync_inc_h = I40E_PTP_1GB_INCVAL >> 32;
10477 : 0 : break;
10478 : 0 : default:
10479 : : tsync_inc_l = 0x0;
10480 : : tsync_inc_h = 0x0;
10481 : : }
10482 : :
10483 : : /* Set the timesync increment value. */
10484 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, tsync_inc_l);
10485 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, tsync_inc_h);
10486 : :
10487 : 0 : memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
10488 : 0 : memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
10489 : 0 : memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
10490 : :
10491 : 0 : adapter->systime_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10492 : : adapter->systime_tc.cc_shift = 0;
10493 : : adapter->systime_tc.nsec_mask = 0;
10494 : :
10495 : 0 : adapter->rx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10496 : : adapter->rx_tstamp_tc.cc_shift = 0;
10497 : : adapter->rx_tstamp_tc.nsec_mask = 0;
10498 : :
10499 : 0 : adapter->tx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10500 : : adapter->tx_tstamp_tc.cc_shift = 0;
10501 : : adapter->tx_tstamp_tc.nsec_mask = 0;
10502 : 0 : }
10503 : :
10504 : : static int
10505 : 0 : i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
10506 : : {
10507 : 0 : struct i40e_adapter *adapter = dev->data->dev_private;
10508 : :
10509 : 0 : adapter->systime_tc.nsec += delta;
10510 : 0 : adapter->rx_tstamp_tc.nsec += delta;
10511 : 0 : adapter->tx_tstamp_tc.nsec += delta;
10512 : :
10513 : 0 : return 0;
10514 : : }
10515 : :
10516 : : static int
10517 : 0 : i40e_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
10518 : : {
10519 : : uint64_t ns;
10520 : 0 : struct i40e_adapter *adapter = dev->data->dev_private;
10521 : :
10522 : : ns = rte_timespec_to_ns(ts);
10523 : :
10524 : : /* Set the timecounters to a new value. */
10525 : 0 : adapter->systime_tc.nsec = ns;
10526 : 0 : adapter->rx_tstamp_tc.nsec = ns;
10527 : 0 : adapter->tx_tstamp_tc.nsec = ns;
10528 : :
10529 : 0 : return 0;
10530 : : }
10531 : :
10532 : : static int
10533 : 0 : i40e_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
10534 : : {
10535 : : uint64_t ns, systime_cycles;
10536 : 0 : struct i40e_adapter *adapter = dev->data->dev_private;
10537 : :
10538 : : systime_cycles = i40e_read_systime_cyclecounter(dev);
10539 : : ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
10540 : 0 : *ts = rte_ns_to_timespec(ns);
10541 : :
10542 : 0 : return 0;
10543 : : }
10544 : :
10545 : : static int
10546 : 0 : i40e_timesync_enable(struct rte_eth_dev *dev)
10547 : : {
10548 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10549 : : uint32_t tsync_ctl_l;
10550 : : uint32_t tsync_ctl_h;
10551 : :
10552 : : /* Stop the timesync system time. */
10553 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
10554 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
10555 : : /* Reset the timesync system time value. */
10556 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_L, 0x0);
10557 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_H, 0x0);
10558 : :
10559 : 0 : i40e_start_timecounters(dev);
10560 : :
10561 : : /* Clear timesync registers. */
10562 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
10563 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H);
10564 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(0));
10565 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(1));
10566 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(2));
10567 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(3));
10568 : :
10569 : : /* Enable timestamping of PTP packets. */
10570 : 0 : tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
10571 : 0 : tsync_ctl_l |= I40E_PRTTSYN_TSYNENA;
10572 : :
10573 : 0 : tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
10574 : : tsync_ctl_h |= I40E_PRTTSYN_TSYNENA;
10575 : 0 : tsync_ctl_h |= I40E_PRTTSYN_TSYNTYPE;
10576 : :
10577 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
10578 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
10579 : :
10580 : 0 : return 0;
10581 : : }
10582 : :
10583 : : static int
10584 : 0 : i40e_timesync_disable(struct rte_eth_dev *dev)
10585 : : {
10586 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10587 : : uint32_t tsync_ctl_l;
10588 : : uint32_t tsync_ctl_h;
10589 : :
10590 : : /* Disable timestamping of transmitted PTP packets. */
10591 : 0 : tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
10592 : 0 : tsync_ctl_l &= ~I40E_PRTTSYN_TSYNENA;
10593 : :
10594 : 0 : tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
10595 : 0 : tsync_ctl_h &= ~I40E_PRTTSYN_TSYNENA;
10596 : :
10597 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
10598 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
10599 : :
10600 : : /* Reset the timesync increment value. */
10601 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
10602 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
10603 : :
10604 : 0 : return 0;
10605 : : }
10606 : :
10607 : : static int
10608 : 0 : i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
10609 : : struct timespec *timestamp, uint32_t flags)
10610 : : {
10611 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10612 : : struct i40e_adapter *adapter = dev->data->dev_private;
10613 : : uint32_t sync_status;
10614 : 0 : uint32_t index = flags & 0x03;
10615 : : uint64_t rx_tstamp_cycles;
10616 : : uint64_t ns;
10617 : :
10618 : 0 : sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_1);
10619 [ # # ]: 0 : if ((sync_status & (1 << index)) == 0)
10620 : : return -EINVAL;
10621 : :
10622 : 0 : rx_tstamp_cycles = i40e_read_rx_tstamp_cyclecounter(dev, index);
10623 : : ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
10624 : 0 : *timestamp = rte_ns_to_timespec(ns);
10625 : :
10626 : 0 : return 0;
10627 : : }
10628 : :
10629 : : static int
10630 : 0 : i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
10631 : : struct timespec *timestamp)
10632 : : {
10633 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10634 : : struct i40e_adapter *adapter = dev->data->dev_private;
10635 : : uint32_t sync_status;
10636 : : uint64_t tx_tstamp_cycles;
10637 : : uint64_t ns;
10638 : :
10639 : 0 : sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
10640 [ # # ]: 0 : if ((sync_status & I40E_PRTTSYN_STAT_0_TXTIME_MASK) == 0)
10641 : : return -EINVAL;
10642 : :
10643 : : tx_tstamp_cycles = i40e_read_tx_tstamp_cyclecounter(dev);
10644 : : ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
10645 : 0 : *timestamp = rte_ns_to_timespec(ns);
10646 : :
10647 : 0 : return 0;
10648 : : }
10649 : :
10650 : : /*
10651 : : * i40e_parse_dcb_configure - parse dcb configure from user
10652 : : * @dev: the device being configured
10653 : : * @dcb_cfg: pointer of the result of parse
10654 : : * @*tc_map: bit map of enabled traffic classes
10655 : : *
10656 : : * Returns 0 on success, negative value on failure
10657 : : */
10658 : : static int
10659 [ # # ]: 0 : i40e_parse_dcb_configure(struct rte_eth_dev *dev,
10660 : : struct i40e_dcbx_config *dcb_cfg,
10661 : : uint8_t *tc_map)
10662 : : {
10663 : : struct rte_eth_dcb_rx_conf *dcb_rx_conf;
10664 : : uint8_t i, tc_bw, bw_lf;
10665 : :
10666 : : memset(dcb_cfg, 0, sizeof(struct i40e_dcbx_config));
10667 : :
10668 : 0 : dcb_rx_conf = &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
10669 [ # # ]: 0 : if (dcb_rx_conf->nb_tcs > I40E_MAX_TRAFFIC_CLASS) {
10670 : 0 : PMD_INIT_LOG(ERR, "number of tc exceeds max.");
10671 : 0 : return -EINVAL;
10672 : : }
10673 : :
10674 : : /* assume each tc has the same bw */
10675 : 0 : tc_bw = I40E_MAX_PERCENT / dcb_rx_conf->nb_tcs;
10676 [ # # ]: 0 : for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
10677 : 0 : dcb_cfg->etscfg.tcbwtable[i] = tc_bw;
10678 : : /* to ensure the sum of tcbw is equal to 100 */
10679 : 0 : bw_lf = I40E_MAX_PERCENT % dcb_rx_conf->nb_tcs;
10680 [ # # ]: 0 : for (i = 0; i < bw_lf; i++)
10681 : 0 : dcb_cfg->etscfg.tcbwtable[i]++;
10682 : :
10683 : : /* assume each tc has the same Transmission Selection Algorithm */
10684 [ # # ]: 0 : for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
10685 : 0 : dcb_cfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
10686 : :
10687 [ # # ]: 0 : for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
10688 : 0 : dcb_cfg->etscfg.prioritytable[i] =
10689 : 0 : dcb_rx_conf->dcb_tc[i];
10690 : :
10691 : : /* FW needs one App to configure HW */
10692 : 0 : dcb_cfg->numapps = I40E_DEFAULT_DCB_APP_NUM;
10693 : 0 : dcb_cfg->app[0].selector = I40E_APP_SEL_ETHTYPE;
10694 : 0 : dcb_cfg->app[0].priority = I40E_DEFAULT_DCB_APP_PRIO;
10695 : 0 : dcb_cfg->app[0].protocolid = I40E_APP_PROTOID_FCOE;
10696 : :
10697 [ # # ]: 0 : if (dcb_rx_conf->nb_tcs == 0)
10698 : 0 : *tc_map = 1; /* tc0 only */
10699 : : else
10700 : 0 : *tc_map = RTE_LEN2MASK(dcb_rx_conf->nb_tcs, uint8_t);
10701 : :
10702 [ # # ]: 0 : if (dev->data->dev_conf.dcb_capability_en & RTE_ETH_DCB_PFC_SUPPORT) {
10703 : 0 : dcb_cfg->pfc.willing = 0;
10704 : 0 : dcb_cfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
10705 : 0 : dcb_cfg->pfc.pfcenable = *tc_map;
10706 : : }
10707 : : return 0;
10708 : : }
10709 : :
10710 : :
10711 : : static enum i40e_status_code
10712 : 0 : i40e_vsi_update_queue_mapping(struct i40e_vsi *vsi,
10713 : : struct i40e_aqc_vsi_properties_data *info,
10714 : : uint8_t enabled_tcmap)
10715 : : {
10716 : : enum i40e_status_code ret;
10717 : : int i, total_tc = 0;
10718 : : uint16_t qpnum_per_tc, bsf, qp_idx;
10719 : 0 : struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(vsi);
10720 : : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
10721 : : uint16_t used_queues;
10722 : :
10723 : 0 : ret = validate_tcmap_parameter(vsi, enabled_tcmap);
10724 [ # # ]: 0 : if (ret != I40E_SUCCESS)
10725 : : return ret;
10726 : :
10727 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10728 [ # # ]: 0 : if (enabled_tcmap & (1 << i))
10729 : 0 : total_tc++;
10730 : : }
10731 [ # # ]: 0 : if (total_tc == 0)
10732 : : total_tc = 1;
10733 : 0 : vsi->enabled_tc = enabled_tcmap;
10734 : :
10735 : : /* different VSI has different queues assigned */
10736 [ # # ]: 0 : if (vsi->type == I40E_VSI_MAIN)
10737 : 0 : used_queues = dev_data->nb_rx_queues -
10738 : 0 : pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
10739 [ # # ]: 0 : else if (vsi->type == I40E_VSI_VMDQ2)
10740 : : used_queues = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
10741 : : else {
10742 : 0 : PMD_INIT_LOG(ERR, "unsupported VSI type.");
10743 : 0 : return I40E_ERR_NO_AVAILABLE_VSI;
10744 : : }
10745 : :
10746 : 0 : qpnum_per_tc = used_queues / total_tc;
10747 : : /* Number of queues per enabled TC */
10748 [ # # ]: 0 : if (qpnum_per_tc == 0) {
10749 : 0 : PMD_INIT_LOG(ERR, " number of queues is less that tcs.");
10750 : 0 : return I40E_ERR_INVALID_QP_ID;
10751 : : }
10752 : 0 : qpnum_per_tc = RTE_MIN(i40e_align_floor(qpnum_per_tc),
10753 : : I40E_MAX_Q_PER_TC);
10754 : 0 : bsf = rte_bsf32(qpnum_per_tc);
10755 : :
10756 : : /**
10757 : : * Configure TC and queue mapping parameters, for enabled TC,
10758 : : * allocate qpnum_per_tc queues to this traffic. For disabled TC,
10759 : : * default queue will serve it.
10760 : : */
10761 : : qp_idx = 0;
10762 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10763 [ # # ]: 0 : if (vsi->enabled_tc & (1 << i)) {
10764 : 0 : info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
10765 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
10766 : : (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
10767 : 0 : qp_idx += qpnum_per_tc;
10768 : : } else
10769 : 0 : info->tc_mapping[i] = 0;
10770 : : }
10771 : :
10772 : : /* Associate queue number with VSI, Keep vsi->nb_qps unchanged */
10773 : : if (vsi->type == I40E_VSI_SRIOV) {
10774 : : info->mapping_flags |=
10775 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
10776 : : for (i = 0; i < vsi->nb_qps; i++)
10777 : : info->queue_mapping[i] =
10778 : : rte_cpu_to_le_16(vsi->base_queue + i);
10779 : : } else {
10780 : 0 : info->mapping_flags |=
10781 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
10782 : 0 : info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
10783 : : }
10784 : 0 : info->valid_sections |=
10785 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
10786 : :
10787 : 0 : return I40E_SUCCESS;
10788 : : }
10789 : :
10790 : : /*
10791 : : * i40e_config_switch_comp_tc - Configure VEB tc setting for given TC map
10792 : : * @veb: VEB to be configured
10793 : : * @tc_map: enabled TC bitmap
10794 : : *
10795 : : * Returns 0 on success, negative value on failure
10796 : : */
10797 : : static enum i40e_status_code
10798 : 0 : i40e_config_switch_comp_tc(struct i40e_veb *veb, uint8_t tc_map)
10799 : : {
10800 : : struct i40e_aqc_configure_switching_comp_bw_config_data veb_bw;
10801 : : struct i40e_aqc_query_switching_comp_bw_config_resp bw_query;
10802 : : struct i40e_aqc_query_switching_comp_ets_config_resp ets_query;
10803 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(veb->associate_vsi);
10804 : : enum i40e_status_code ret = I40E_SUCCESS;
10805 : : int i;
10806 : : uint32_t bw_max;
10807 : :
10808 : : /* Check if enabled_tc is same as existing or new TCs */
10809 [ # # ]: 0 : if (veb->enabled_tc == tc_map)
10810 : : return ret;
10811 : :
10812 : : /* configure tc bandwidth */
10813 : : memset(&veb_bw, 0, sizeof(veb_bw));
10814 : 0 : veb_bw.tc_valid_bits = tc_map;
10815 : : /* Enable ETS TCs with equal BW Share for now across all VSIs */
10816 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10817 [ # # ]: 0 : if (tc_map & BIT_ULL(i))
10818 : 0 : veb_bw.tc_bw_share_credits[i] = 1;
10819 : : }
10820 : 0 : ret = i40e_aq_config_switch_comp_bw_config(hw, veb->seid,
10821 : : &veb_bw, NULL);
10822 [ # # ]: 0 : if (ret) {
10823 : 0 : PMD_INIT_LOG(ERR,
10824 : : "AQ command Config switch_comp BW allocation per TC failed = %d",
10825 : : hw->aq.asq_last_status);
10826 : 0 : return ret;
10827 : : }
10828 : :
10829 : : memset(&ets_query, 0, sizeof(ets_query));
10830 : 0 : ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
10831 : : &ets_query, NULL);
10832 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
10833 : 0 : PMD_DRV_LOG(ERR,
10834 : : "Failed to get switch_comp ETS configuration %u",
10835 : : hw->aq.asq_last_status);
10836 : 0 : return ret;
10837 : : }
10838 : : memset(&bw_query, 0, sizeof(bw_query));
10839 : 0 : ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
10840 : : &bw_query, NULL);
10841 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
10842 : 0 : PMD_DRV_LOG(ERR,
10843 : : "Failed to get switch_comp bandwidth configuration %u",
10844 : : hw->aq.asq_last_status);
10845 : 0 : return ret;
10846 : : }
10847 : :
10848 : : /* store and print out BW info */
10849 : 0 : veb->bw_info.bw_limit = rte_le_to_cpu_16(ets_query.port_bw_limit);
10850 : 0 : veb->bw_info.bw_max = ets_query.tc_bw_max;
10851 : 0 : PMD_DRV_LOG(DEBUG, "switch_comp bw limit:%u", veb->bw_info.bw_limit);
10852 : 0 : PMD_DRV_LOG(DEBUG, "switch_comp max_bw:%u", veb->bw_info.bw_max);
10853 : 0 : bw_max = rte_le_to_cpu_16(bw_query.tc_bw_max[0]) |
10854 : 0 : (rte_le_to_cpu_16(bw_query.tc_bw_max[1]) <<
10855 : : I40E_16_BIT_WIDTH);
10856 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10857 : 0 : veb->bw_info.bw_ets_share_credits[i] =
10858 : 0 : bw_query.tc_bw_share_credits[i];
10859 : 0 : veb->bw_info.bw_ets_credits[i] =
10860 : 0 : rte_le_to_cpu_16(bw_query.tc_bw_limits[i]);
10861 : : /* 4 bits per TC, 4th bit is reserved */
10862 : 0 : veb->bw_info.bw_ets_max[i] =
10863 : 0 : (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
10864 : : RTE_LEN2MASK(3, uint8_t));
10865 : 0 : PMD_DRV_LOG(DEBUG, "\tVEB TC%u:share credits %u", i,
10866 : : veb->bw_info.bw_ets_share_credits[i]);
10867 : 0 : PMD_DRV_LOG(DEBUG, "\tVEB TC%u:credits %u", i,
10868 : : veb->bw_info.bw_ets_credits[i]);
10869 : 0 : PMD_DRV_LOG(DEBUG, "\tVEB TC%u: max credits: %u", i,
10870 : : veb->bw_info.bw_ets_max[i]);
10871 : : }
10872 : :
10873 : 0 : veb->enabled_tc = tc_map;
10874 : :
10875 : 0 : return ret;
10876 : : }
10877 : :
10878 : :
10879 : : /*
10880 : : * i40e_vsi_config_tc - Configure VSI tc setting for given TC map
10881 : : * @vsi: VSI to be configured
10882 : : * @tc_map: enabled TC bitmap
10883 : : *
10884 : : * Returns 0 on success, negative value on failure
10885 : : */
10886 : : static enum i40e_status_code
10887 : 0 : i40e_vsi_config_tc(struct i40e_vsi *vsi, uint8_t tc_map)
10888 : : {
10889 : : struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
10890 : : struct i40e_vsi_context ctxt;
10891 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
10892 : : enum i40e_status_code ret = I40E_SUCCESS;
10893 : : int i;
10894 : :
10895 : : /* Check if enabled_tc is same as existing or new TCs */
10896 [ # # ]: 0 : if (vsi->enabled_tc == tc_map)
10897 : : return ret;
10898 : :
10899 : : /* configure tc bandwidth */
10900 : : memset(&bw_data, 0, sizeof(bw_data));
10901 : 0 : bw_data.tc_valid_bits = tc_map;
10902 : : /* Enable ETS TCs with equal BW Share for now across all VSIs */
10903 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10904 [ # # ]: 0 : if (tc_map & BIT_ULL(i))
10905 : 0 : bw_data.tc_bw_credits[i] = 1;
10906 : : }
10907 : 0 : ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &bw_data, NULL);
10908 [ # # ]: 0 : if (ret) {
10909 : 0 : PMD_INIT_LOG(ERR,
10910 : : "AQ command Config VSI BW allocation per TC failed = %d",
10911 : : hw->aq.asq_last_status);
10912 : 0 : goto out;
10913 : : }
10914 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
10915 : 0 : vsi->info.qs_handle[i] = bw_data.qs_handles[i];
10916 : :
10917 : : /* Update Queue Pairs Mapping for currently enabled UPs */
10918 : 0 : ctxt.seid = vsi->seid;
10919 : 0 : ctxt.pf_num = hw->pf_id;
10920 : 0 : ctxt.vf_num = 0;
10921 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
10922 : 0 : ctxt.info = vsi->info;
10923 : 0 : i40e_get_cap(hw);
10924 : 0 : ret = i40e_vsi_update_queue_mapping(vsi, &ctxt.info, tc_map);
10925 [ # # ]: 0 : if (ret)
10926 : 0 : goto out;
10927 : :
10928 : : /* Update the VSI after updating the VSI queue-mapping information */
10929 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
10930 [ # # ]: 0 : if (ret) {
10931 : 0 : PMD_INIT_LOG(ERR, "Failed to configure TC queue mapping = %d",
10932 : : hw->aq.asq_last_status);
10933 : 0 : goto out;
10934 : : }
10935 : : /* update the local VSI info with updated queue map */
10936 : : rte_memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
10937 : : sizeof(vsi->info.tc_mapping));
10938 : : rte_memcpy(&vsi->info.queue_mapping,
10939 : : &ctxt.info.queue_mapping,
10940 : : sizeof(vsi->info.queue_mapping));
10941 : 0 : vsi->info.mapping_flags = ctxt.info.mapping_flags;
10942 : 0 : vsi->info.valid_sections = 0;
10943 : :
10944 : : /* query and update current VSI BW information */
10945 : 0 : ret = i40e_vsi_get_bw_config(vsi);
10946 [ # # ]: 0 : if (ret) {
10947 : 0 : PMD_INIT_LOG(ERR,
10948 : : "Failed updating vsi bw info, err %s aq_err %s",
10949 : : i40e_stat_str(hw, ret),
10950 : : i40e_aq_str(hw, hw->aq.asq_last_status));
10951 : 0 : goto out;
10952 : : }
10953 : :
10954 : 0 : vsi->enabled_tc = tc_map;
10955 : :
10956 : : out:
10957 : : return ret;
10958 : : }
10959 : :
10960 : : /*
10961 : : * i40e_dcb_hw_configure - program the dcb setting to hw
10962 : : * @pf: pf the configuration is taken on
10963 : : * @new_cfg: new configuration
10964 : : * @tc_map: enabled TC bitmap
10965 : : *
10966 : : * Returns 0 on success, negative value on failure
10967 : : */
10968 : : static enum i40e_status_code
10969 : 0 : i40e_dcb_hw_configure(struct i40e_pf *pf,
10970 : : struct i40e_dcbx_config *new_cfg,
10971 : : uint8_t tc_map)
10972 : : {
10973 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
10974 : 0 : struct i40e_dcbx_config *old_cfg = &hw->local_dcbx_config;
10975 : 0 : struct i40e_vsi *main_vsi = pf->main_vsi;
10976 : : struct i40e_vsi_list *vsi_list;
10977 : : enum i40e_status_code ret;
10978 : : int i;
10979 : : uint32_t val;
10980 : :
10981 : : /* Use the FW API if FW > v4.4*/
10982 [ # # # # : 0 : if (!(((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver >= 4)) ||
# # ]
10983 : : (hw->aq.fw_maj_ver >= 5))) {
10984 : 0 : PMD_INIT_LOG(ERR,
10985 : : "FW < v4.4, can not use FW LLDP API to configure DCB");
10986 : 0 : return I40E_ERR_FIRMWARE_API_VERSION;
10987 : : }
10988 : :
10989 : : /* Check if need reconfiguration */
10990 [ # # ]: 0 : if (!memcmp(new_cfg, old_cfg, sizeof(struct i40e_dcbx_config))) {
10991 : 0 : PMD_INIT_LOG(ERR, "No Change in DCB Config required.");
10992 : 0 : return I40E_SUCCESS;
10993 : : }
10994 : :
10995 : : /* Copy the new config to the current config */
10996 : 0 : *old_cfg = *new_cfg;
10997 : 0 : old_cfg->etsrec = old_cfg->etscfg;
10998 : 0 : ret = i40e_set_dcb_config(hw);
10999 [ # # ]: 0 : if (ret) {
11000 : 0 : PMD_INIT_LOG(ERR, "Set DCB Config failed, err %s aq_err %s",
11001 : : i40e_stat_str(hw, ret),
11002 : : i40e_aq_str(hw, hw->aq.asq_last_status));
11003 : 0 : return ret;
11004 : : }
11005 : : /* set receive Arbiter to RR mode and ETS scheme by default */
11006 [ # # ]: 0 : for (i = 0; i <= I40E_PRTDCB_RETSTCC_MAX_INDEX; i++) {
11007 : 0 : val = I40E_READ_REG(hw, I40E_PRTDCB_RETSTCC(i));
11008 : 0 : val &= ~(I40E_PRTDCB_RETSTCC_BWSHARE_MASK |
11009 : : I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK |
11010 : : I40E_PRTDCB_RETSTCC_ETSTC_SHIFT);
11011 : 0 : val |= ((uint32_t)old_cfg->etscfg.tcbwtable[i] <<
11012 : 0 : I40E_PRTDCB_RETSTCC_BWSHARE_SHIFT) &
11013 : : I40E_PRTDCB_RETSTCC_BWSHARE_MASK;
11014 : : val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_UPINTC_MODE_SHIFT) &
11015 : : I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK;
11016 : 0 : val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_ETSTC_SHIFT) &
11017 : : I40E_PRTDCB_RETSTCC_ETSTC_MASK;
11018 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_RETSTCC(i), val);
11019 : : }
11020 : : /* get local mib to check whether it is configured correctly */
11021 : : /* IEEE mode */
11022 : 0 : hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_IEEE;
11023 : : /* Get Local DCB Config */
11024 : 0 : i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
11025 : : &hw->local_dcbx_config);
11026 : :
11027 : : /* if Veb is created, need to update TC of it at first */
11028 [ # # ]: 0 : if (main_vsi->veb) {
11029 : 0 : ret = i40e_config_switch_comp_tc(main_vsi->veb, tc_map);
11030 [ # # ]: 0 : if (ret)
11031 : 0 : PMD_INIT_LOG(WARNING,
11032 : : "Failed configuring TC for VEB seid=%d",
11033 : : main_vsi->veb->seid);
11034 : : }
11035 : : /* Update each VSI */
11036 : 0 : i40e_vsi_config_tc(main_vsi, tc_map);
11037 [ # # ]: 0 : if (main_vsi->veb) {
11038 [ # # ]: 0 : TAILQ_FOREACH(vsi_list, &main_vsi->veb->head, list) {
11039 : : /* Beside main VSI and VMDQ VSIs, only enable default
11040 : : * TC for other VSIs
11041 : : */
11042 [ # # ]: 0 : if (vsi_list->vsi->type == I40E_VSI_VMDQ2)
11043 : 0 : ret = i40e_vsi_config_tc(vsi_list->vsi,
11044 : : tc_map);
11045 : : else
11046 : 0 : ret = i40e_vsi_config_tc(vsi_list->vsi,
11047 : : I40E_DEFAULT_TCMAP);
11048 [ # # ]: 0 : if (ret)
11049 : 0 : PMD_INIT_LOG(WARNING,
11050 : : "Failed configuring TC for VSI seid=%d",
11051 : : vsi_list->vsi->seid);
11052 : : /* continue */
11053 : : }
11054 : : }
11055 : : return I40E_SUCCESS;
11056 : : }
11057 : :
11058 : : /*
11059 : : * i40e_dcb_init_configure - initial dcb config
11060 : : * @dev: device being configured
11061 : : * @sw_dcb: indicate whether dcb is sw configured or hw offload
11062 : : *
11063 : : * Returns 0 on success, negative value on failure
11064 : : */
11065 : : int
11066 : 0 : i40e_dcb_init_configure(struct rte_eth_dev *dev, bool sw_dcb)
11067 : : {
11068 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11069 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11070 : : int i, ret = 0;
11071 : :
11072 [ # # ]: 0 : if ((pf->flags & I40E_FLAG_DCB) == 0) {
11073 : 0 : PMD_INIT_LOG(ERR, "HW doesn't support DCB");
11074 : 0 : return -ENOTSUP;
11075 : : }
11076 : :
11077 : : /* DCB initialization:
11078 : : * Update DCB configuration from the Firmware and configure
11079 : : * LLDP MIB change event.
11080 : : */
11081 [ # # ]: 0 : if (sw_dcb == TRUE) {
11082 : : /* Stopping lldp is necessary for DPDK, but it will cause
11083 : : * DCB init failed. For i40e_init_dcb(), the prerequisite
11084 : : * for successful initialization of DCB is that LLDP is
11085 : : * enabled. So it is needed to start lldp before DCB init
11086 : : * and stop it after initialization.
11087 : : */
11088 : 0 : ret = i40e_aq_start_lldp(hw, true, NULL);
11089 [ # # ]: 0 : if (ret != I40E_SUCCESS)
11090 : 0 : PMD_INIT_LOG(DEBUG, "Failed to start lldp");
11091 : :
11092 : 0 : ret = i40e_init_dcb(hw, true);
11093 : : /* If lldp agent is stopped, the return value from
11094 : : * i40e_init_dcb we expect is failure with I40E_AQ_RC_EPERM
11095 : : * adminq status. Otherwise, it should return success.
11096 : : */
11097 [ # # ]: 0 : if ((ret == I40E_SUCCESS) || (ret != I40E_SUCCESS &&
11098 [ # # ]: 0 : hw->aq.asq_last_status == I40E_AQ_RC_EPERM)) {
11099 : 0 : memset(&hw->local_dcbx_config, 0,
11100 : : sizeof(struct i40e_dcbx_config));
11101 : : /* set dcb default configuration */
11102 : : hw->local_dcbx_config.etscfg.willing = 0;
11103 : : hw->local_dcbx_config.etscfg.maxtcs = 0;
11104 : 0 : hw->local_dcbx_config.etscfg.tcbwtable[0] = 100;
11105 : 0 : hw->local_dcbx_config.etscfg.tsatable[0] =
11106 : : I40E_IEEE_TSA_ETS;
11107 : : /* all UPs mapping to TC0 */
11108 [ # # ]: 0 : for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
11109 : 0 : hw->local_dcbx_config.etscfg.prioritytable[i] = 0;
11110 : 0 : hw->local_dcbx_config.etsrec =
11111 : : hw->local_dcbx_config.etscfg;
11112 : : hw->local_dcbx_config.pfc.willing = 0;
11113 : 0 : hw->local_dcbx_config.pfc.pfccap =
11114 : : I40E_MAX_TRAFFIC_CLASS;
11115 : : /* FW needs one App to configure HW */
11116 : 0 : hw->local_dcbx_config.numapps = 1;
11117 : 0 : hw->local_dcbx_config.app[0].selector =
11118 : : I40E_APP_SEL_ETHTYPE;
11119 : 0 : hw->local_dcbx_config.app[0].priority = 3;
11120 : 0 : hw->local_dcbx_config.app[0].protocolid =
11121 : : I40E_APP_PROTOID_FCOE;
11122 : 0 : ret = i40e_set_dcb_config(hw);
11123 [ # # ]: 0 : if (ret) {
11124 : 0 : PMD_INIT_LOG(ERR,
11125 : : "default dcb config fails. err = %d, aq_err = %d.",
11126 : : ret, hw->aq.asq_last_status);
11127 : 0 : return -ENOSYS;
11128 : : }
11129 : : } else {
11130 : 0 : PMD_INIT_LOG(ERR,
11131 : : "DCB initialization in FW fails, err = %d, aq_err = %d.",
11132 : : ret, hw->aq.asq_last_status);
11133 : 0 : return -ENOTSUP;
11134 : : }
11135 : :
11136 [ # # ]: 0 : if (i40e_need_stop_lldp(dev)) {
11137 : 0 : ret = i40e_aq_stop_lldp(hw, true, true, NULL);
11138 [ # # ]: 0 : if (ret != I40E_SUCCESS)
11139 : 0 : PMD_INIT_LOG(DEBUG, "Failed to stop lldp");
11140 : : }
11141 : : } else {
11142 : 0 : ret = i40e_aq_start_lldp(hw, true, NULL);
11143 [ # # ]: 0 : if (ret != I40E_SUCCESS)
11144 : 0 : PMD_INIT_LOG(DEBUG, "Failed to start lldp");
11145 : :
11146 : 0 : ret = i40e_init_dcb(hw, true);
11147 [ # # ]: 0 : if (!ret) {
11148 [ # # ]: 0 : if (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED) {
11149 : 0 : PMD_INIT_LOG(ERR,
11150 : : "HW doesn't support DCBX offload.");
11151 : 0 : return -ENOTSUP;
11152 : : }
11153 : : } else {
11154 : 0 : PMD_INIT_LOG(ERR,
11155 : : "DCBX configuration failed, err = %d, aq_err = %d.",
11156 : : ret, hw->aq.asq_last_status);
11157 : 0 : return -ENOTSUP;
11158 : : }
11159 : : }
11160 : : return 0;
11161 : : }
11162 : :
11163 : : /*
11164 : : * i40e_dcb_setup - setup dcb related config
11165 : : * @dev: device being configured
11166 : : *
11167 : : * Returns 0 on success, negative value on failure
11168 : : */
11169 : : static int
11170 : 0 : i40e_dcb_setup(struct rte_eth_dev *dev)
11171 : : {
11172 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11173 : : struct i40e_dcbx_config dcb_cfg;
11174 : 0 : uint8_t tc_map = 0;
11175 : : int ret = 0;
11176 : :
11177 [ # # ]: 0 : if ((pf->flags & I40E_FLAG_DCB) == 0) {
11178 : 0 : PMD_INIT_LOG(ERR, "HW doesn't support DCB");
11179 : 0 : return -ENOTSUP;
11180 : : }
11181 : :
11182 [ # # ]: 0 : if (pf->vf_num != 0)
11183 : 0 : PMD_INIT_LOG(DEBUG, " DCB only works on pf and vmdq vsis.");
11184 : :
11185 : 0 : ret = i40e_parse_dcb_configure(dev, &dcb_cfg, &tc_map);
11186 [ # # ]: 0 : if (ret) {
11187 : 0 : PMD_INIT_LOG(ERR, "invalid dcb config");
11188 : 0 : return -EINVAL;
11189 : : }
11190 : 0 : ret = i40e_dcb_hw_configure(pf, &dcb_cfg, tc_map);
11191 [ # # ]: 0 : if (ret) {
11192 : 0 : PMD_INIT_LOG(ERR, "dcb sw configure fails");
11193 : 0 : return -ENOSYS;
11194 : : }
11195 : :
11196 : : return 0;
11197 : : }
11198 : :
11199 : : static int
11200 : 0 : i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
11201 : : struct rte_eth_dcb_info *dcb_info)
11202 : : {
11203 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11204 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11205 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
11206 : : struct i40e_dcbx_config *dcb_cfg = &hw->local_dcbx_config;
11207 : : uint16_t bsf, tc_mapping;
11208 : : int i, j = 0;
11209 : :
11210 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_DCB_FLAG)
11211 : 0 : dcb_info->nb_tcs = rte_bsf32(vsi->enabled_tc + 1);
11212 : : else
11213 : 0 : dcb_info->nb_tcs = 1;
11214 [ # # ]: 0 : for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
11215 : 0 : dcb_info->prio_tc[i] = dcb_cfg->etscfg.prioritytable[i];
11216 [ # # ]: 0 : for (i = 0; i < dcb_info->nb_tcs; i++)
11217 : 0 : dcb_info->tc_bws[i] = dcb_cfg->etscfg.tcbwtable[i];
11218 : :
11219 : : /* get queue mapping if vmdq is disabled */
11220 [ # # ]: 0 : if (!pf->nb_cfg_vmdq_vsi) {
11221 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11222 [ # # ]: 0 : if (!(vsi->enabled_tc & (1 << i)))
11223 : 0 : continue;
11224 : 0 : tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
11225 : 0 : dcb_info->tc_queue.tc_rxq[j][i].base =
11226 : 0 : (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
11227 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
11228 : 0 : dcb_info->tc_queue.tc_txq[j][i].base =
11229 : : dcb_info->tc_queue.tc_rxq[j][i].base;
11230 : 0 : bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
11231 : : I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
11232 : 0 : dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
11233 : 0 : dcb_info->tc_queue.tc_txq[j][i].nb_queue =
11234 : : dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
11235 : : }
11236 : : return 0;
11237 : : }
11238 : :
11239 : : /* get queue mapping if vmdq is enabled */
11240 : : do {
11241 : 0 : vsi = pf->vmdq[j].vsi;
11242 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11243 [ # # ]: 0 : if (!(vsi->enabled_tc & (1 << i)))
11244 : 0 : continue;
11245 : 0 : tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
11246 : 0 : dcb_info->tc_queue.tc_rxq[j][i].base =
11247 : 0 : (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
11248 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
11249 : 0 : dcb_info->tc_queue.tc_txq[j][i].base =
11250 : : dcb_info->tc_queue.tc_rxq[j][i].base;
11251 : 0 : bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
11252 : : I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
11253 : 0 : dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
11254 : 0 : dcb_info->tc_queue.tc_txq[j][i].nb_queue =
11255 : : dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
11256 : : }
11257 : 0 : j++;
11258 [ # # ]: 0 : } while (j < RTE_MIN(pf->nb_cfg_vmdq_vsi, RTE_ETH_MAX_VMDQ_POOL));
11259 : : return 0;
11260 : : }
11261 : :
11262 : : static int
11263 : 0 : i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
11264 : : {
11265 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
11266 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
11267 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11268 : : uint16_t msix_intr;
11269 : :
11270 : 0 : msix_intr = rte_intr_vec_list_index_get(intr_handle, queue_id);
11271 [ # # ]: 0 : if (msix_intr == I40E_MISC_VEC_ID)
11272 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
11273 : : I40E_PFINT_DYN_CTL0_INTENA_MASK |
11274 : : I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
11275 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
11276 : : else
11277 : 0 : I40E_WRITE_REG(hw,
11278 : : I40E_PFINT_DYN_CTLN(msix_intr -
11279 : : I40E_RX_VEC_START),
11280 : : I40E_PFINT_DYN_CTLN_INTENA_MASK |
11281 : : I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
11282 : : I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
11283 : :
11284 : 0 : I40E_WRITE_FLUSH(hw);
11285 : 0 : rte_intr_ack(pci_dev->intr_handle);
11286 : :
11287 : 0 : return 0;
11288 : : }
11289 : :
11290 : : static int
11291 : 0 : i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
11292 : : {
11293 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
11294 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
11295 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11296 : : uint16_t msix_intr;
11297 : :
11298 : 0 : msix_intr = rte_intr_vec_list_index_get(intr_handle, queue_id);
11299 [ # # ]: 0 : if (msix_intr == I40E_MISC_VEC_ID)
11300 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
11301 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
11302 : : else
11303 : 0 : I40E_WRITE_REG(hw,
11304 : : I40E_PFINT_DYN_CTLN(msix_intr -
11305 : : I40E_RX_VEC_START),
11306 : : I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
11307 : 0 : I40E_WRITE_FLUSH(hw);
11308 : :
11309 : 0 : return 0;
11310 : : }
11311 : :
11312 : : /**
11313 : : * This function is used to check if the register is valid.
11314 : : * Below is the valid registers list for X722 only:
11315 : : * 0x2b800--0x2bb00
11316 : : * 0x38700--0x38a00
11317 : : * 0x3d800--0x3db00
11318 : : * 0x208e00--0x209000
11319 : : * 0x20be00--0x20c000
11320 : : * 0x263c00--0x264000
11321 : : * 0x265c00--0x266000
11322 : : */
11323 : 0 : static inline int i40e_valid_regs(enum i40e_mac_type type, uint32_t reg_offset)
11324 : : {
11325 [ # # ]: 0 : if ((type != I40E_MAC_X722) &&
11326 : 0 : ((reg_offset >= 0x2b800 && reg_offset <= 0x2bb00) ||
11327 [ # # ]: 0 : (reg_offset >= 0x38700 && reg_offset <= 0x38a00) ||
11328 [ # # ]: 0 : (reg_offset >= 0x3d800 && reg_offset <= 0x3db00) ||
11329 [ # # ]: 0 : (reg_offset >= 0x208e00 && reg_offset <= 0x209000) ||
11330 [ # # ]: 0 : (reg_offset >= 0x20be00 && reg_offset <= 0x20c000) ||
11331 [ # # ]: 0 : (reg_offset >= 0x263c00 && reg_offset <= 0x264000) ||
11332 [ # # ]: 0 : (reg_offset >= 0x265c00 && reg_offset <= 0x266000)))
11333 : : return 0;
11334 : : else
11335 : 0 : return 1;
11336 : : }
11337 : :
11338 : 0 : static int i40e_get_regs(struct rte_eth_dev *dev,
11339 : : struct rte_dev_reg_info *regs)
11340 : : {
11341 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11342 : 0 : uint32_t *ptr_data = regs->data;
11343 : : uint32_t reg_idx, arr_idx, arr_idx2, reg_offset;
11344 : : const struct i40e_reg_info *reg_info;
11345 : :
11346 [ # # ]: 0 : if (ptr_data == NULL) {
11347 : 0 : regs->length = I40E_GLGEN_STAT_CLEAR + 4;
11348 : 0 : regs->width = sizeof(uint32_t);
11349 : 0 : return 0;
11350 : : }
11351 : :
11352 : : /* The first few registers have to be read using AQ operations */
11353 : : reg_idx = 0;
11354 [ # # ]: 0 : while (i40e_regs_adminq[reg_idx].name) {
11355 : 0 : reg_info = &i40e_regs_adminq[reg_idx++];
11356 [ # # ]: 0 : for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
11357 : : for (arr_idx2 = 0;
11358 [ # # ]: 0 : arr_idx2 <= reg_info->count2;
11359 : 0 : arr_idx2++) {
11360 : 0 : reg_offset = arr_idx * reg_info->stride1 +
11361 : 0 : arr_idx2 * reg_info->stride2;
11362 : 0 : reg_offset += reg_info->base_addr;
11363 : 0 : ptr_data[reg_offset >> 2] =
11364 : 0 : i40e_read_rx_ctl(hw, reg_offset);
11365 : : }
11366 : : }
11367 : :
11368 : : /* The remaining registers can be read using primitives */
11369 : : reg_idx = 0;
11370 [ # # ]: 0 : while (i40e_regs_others[reg_idx].name) {
11371 : 0 : reg_info = &i40e_regs_others[reg_idx++];
11372 [ # # ]: 0 : for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
11373 : : for (arr_idx2 = 0;
11374 [ # # ]: 0 : arr_idx2 <= reg_info->count2;
11375 : 0 : arr_idx2++) {
11376 : 0 : reg_offset = arr_idx * reg_info->stride1 +
11377 : 0 : arr_idx2 * reg_info->stride2;
11378 : 0 : reg_offset += reg_info->base_addr;
11379 [ # # ]: 0 : if (!i40e_valid_regs(hw->mac.type, reg_offset))
11380 : 0 : ptr_data[reg_offset >> 2] = 0;
11381 : : else
11382 : 0 : ptr_data[reg_offset >> 2] =
11383 : 0 : I40E_READ_REG(hw, reg_offset);
11384 : : }
11385 : : }
11386 : :
11387 : : return 0;
11388 : : }
11389 : :
11390 : 0 : static int i40e_get_eeprom_length(struct rte_eth_dev *dev)
11391 : : {
11392 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11393 : :
11394 : : /* Convert word count to byte count */
11395 : 0 : return hw->nvm.sr_size << 1;
11396 : : }
11397 : :
11398 : 0 : static int i40e_get_eeprom(struct rte_eth_dev *dev,
11399 : : struct rte_dev_eeprom_info *eeprom)
11400 : : {
11401 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11402 : 0 : uint16_t *data = eeprom->data;
11403 : : uint16_t offset, length, cnt_words;
11404 : : int ret_code;
11405 : :
11406 : 0 : offset = eeprom->offset >> 1;
11407 : 0 : length = eeprom->length >> 1;
11408 : 0 : cnt_words = length;
11409 : :
11410 [ # # ]: 0 : if (offset > hw->nvm.sr_size ||
11411 [ # # ]: 0 : offset + length > hw->nvm.sr_size) {
11412 : 0 : PMD_DRV_LOG(ERR, "Requested EEPROM bytes out of range.");
11413 : 0 : return -EINVAL;
11414 : : }
11415 : :
11416 : 0 : eeprom->magic = hw->vendor_id | (hw->device_id << 16);
11417 : :
11418 : 0 : ret_code = i40e_read_nvm_buffer(hw, offset, &cnt_words, data);
11419 [ # # # # ]: 0 : if (ret_code != I40E_SUCCESS || cnt_words != length) {
11420 : 0 : PMD_DRV_LOG(ERR, "EEPROM read failed.");
11421 : 0 : return -EIO;
11422 : : }
11423 : :
11424 : : return 0;
11425 : : }
11426 : :
11427 : 0 : static int i40e_get_module_info(struct rte_eth_dev *dev,
11428 : : struct rte_eth_dev_module_info *modinfo)
11429 : : {
11430 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11431 : 0 : uint32_t sff8472_comp = 0;
11432 : 0 : uint32_t sff8472_swap = 0;
11433 : 0 : uint32_t sff8636_rev = 0;
11434 : : i40e_status status;
11435 : : uint32_t type = 0;
11436 : :
11437 : : /* Check if firmware supports reading module EEPROM. */
11438 [ # # ]: 0 : if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
11439 : 0 : PMD_DRV_LOG(ERR,
11440 : : "Module EEPROM memory read not supported. "
11441 : : "Please update the NVM image.\n");
11442 : 0 : return -EINVAL;
11443 : : }
11444 : :
11445 : 0 : status = i40e_update_link_info(hw);
11446 [ # # ]: 0 : if (status)
11447 : : return -EIO;
11448 : :
11449 [ # # ]: 0 : if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
11450 : 0 : PMD_DRV_LOG(ERR,
11451 : : "Cannot read module EEPROM memory. "
11452 : : "No module connected.\n");
11453 : 0 : return -EINVAL;
11454 : : }
11455 : :
11456 : 0 : type = hw->phy.link_info.module_type[0];
11457 : :
11458 [ # # # # ]: 0 : switch (type) {
11459 : 0 : case I40E_MODULE_TYPE_SFP:
11460 : 0 : status = i40e_aq_get_phy_register(hw,
11461 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11462 : : I40E_I2C_EEPROM_DEV_ADDR, 1,
11463 : : I40E_MODULE_SFF_8472_COMP,
11464 : : &sff8472_comp, NULL);
11465 [ # # ]: 0 : if (status)
11466 : : return -EIO;
11467 : :
11468 : 0 : status = i40e_aq_get_phy_register(hw,
11469 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11470 : : I40E_I2C_EEPROM_DEV_ADDR, 1,
11471 : : I40E_MODULE_SFF_8472_SWAP,
11472 : : &sff8472_swap, NULL);
11473 [ # # ]: 0 : if (status)
11474 : : return -EIO;
11475 : :
11476 : : /* Check if the module requires address swap to access
11477 : : * the other EEPROM memory page.
11478 : : */
11479 [ # # ]: 0 : if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
11480 : 0 : PMD_DRV_LOG(WARNING,
11481 : : "Module address swap to access "
11482 : : "page 0xA2 is not supported.\n");
11483 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8079;
11484 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
11485 [ # # ]: 0 : } else if (sff8472_comp == 0x00) {
11486 : : /* Module is not SFF-8472 compliant */
11487 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8079;
11488 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
11489 : : } else {
11490 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8472;
11491 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8472_LEN;
11492 : : }
11493 : : break;
11494 : 0 : case I40E_MODULE_TYPE_QSFP_PLUS:
11495 : : /* Read from memory page 0. */
11496 : 0 : status = i40e_aq_get_phy_register(hw,
11497 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11498 : : 0, 1,
11499 : : I40E_MODULE_REVISION_ADDR,
11500 : : &sff8636_rev, NULL);
11501 [ # # ]: 0 : if (status)
11502 : : return -EIO;
11503 : : /* Determine revision compliance byte */
11504 [ # # ]: 0 : if (sff8636_rev > 0x02) {
11505 : : /* Module is SFF-8636 compliant */
11506 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8636;
11507 : 0 : modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
11508 : : } else {
11509 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8436;
11510 : 0 : modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
11511 : : }
11512 : : break;
11513 : 0 : case I40E_MODULE_TYPE_QSFP28:
11514 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8636;
11515 : 0 : modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
11516 : 0 : break;
11517 : 0 : default:
11518 : 0 : PMD_DRV_LOG(ERR, "Module type unrecognized\n");
11519 : 0 : return -EINVAL;
11520 : : }
11521 : : return 0;
11522 : : }
11523 : :
11524 : 0 : static int i40e_get_module_eeprom(struct rte_eth_dev *dev,
11525 : : struct rte_dev_eeprom_info *info)
11526 : : {
11527 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11528 : : bool is_sfp = false;
11529 : : i40e_status status;
11530 : : uint8_t *data;
11531 : 0 : uint32_t value = 0;
11532 : : uint32_t i;
11533 : :
11534 [ # # ]: 0 : if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
11535 : : is_sfp = true;
11536 : :
11537 : 0 : data = info->data;
11538 [ # # ]: 0 : for (i = 0; i < info->length; i++) {
11539 : 0 : u32 offset = i + info->offset;
11540 [ # # ]: 0 : u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
11541 : :
11542 : : /* Check if we need to access the other memory page */
11543 [ # # ]: 0 : if (is_sfp) {
11544 [ # # ]: 0 : if (offset >= RTE_ETH_MODULE_SFF_8079_LEN) {
11545 : 0 : offset -= RTE_ETH_MODULE_SFF_8079_LEN;
11546 : : addr = I40E_I2C_EEPROM_DEV_ADDR2;
11547 : : }
11548 : : } else {
11549 [ # # ]: 0 : while (offset >= RTE_ETH_MODULE_SFF_8436_LEN) {
11550 : : /* Compute memory page number and offset. */
11551 : 0 : offset -= RTE_ETH_MODULE_SFF_8436_LEN / 2;
11552 : 0 : addr++;
11553 : : }
11554 : : }
11555 : 0 : status = i40e_aq_get_phy_register(hw,
11556 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11557 : : addr, 1, offset, &value, NULL);
11558 [ # # ]: 0 : if (status)
11559 : : return -EIO;
11560 : 0 : data[i] = (uint8_t)value;
11561 : : }
11562 : : return 0;
11563 : : }
11564 : :
11565 : 0 : static int i40e_set_default_mac_addr(struct rte_eth_dev *dev,
11566 : : struct rte_ether_addr *mac_addr)
11567 : : {
11568 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11569 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11570 [ # # ]: 0 : struct i40e_vsi *vsi = pf->main_vsi;
11571 : : struct i40e_mac_filter_info mac_filter;
11572 : : struct i40e_mac_filter *f;
11573 : : int ret;
11574 : :
11575 : : if (!rte_is_valid_assigned_ether_addr(mac_addr)) {
11576 : 0 : PMD_DRV_LOG(ERR, "Tried to set invalid MAC address.");
11577 : 0 : return -EINVAL;
11578 : : }
11579 : :
11580 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
11581 [ # # ]: 0 : if (rte_is_same_ether_addr(&pf->dev_addr,
11582 : : &f->mac_info.mac_addr))
11583 : : break;
11584 : : }
11585 : :
11586 [ # # ]: 0 : if (f == NULL) {
11587 : 0 : PMD_DRV_LOG(ERR, "Failed to find filter for default mac");
11588 : 0 : return -EIO;
11589 : : }
11590 : :
11591 : 0 : mac_filter = f->mac_info;
11592 : 0 : ret = i40e_vsi_delete_mac(vsi, &mac_filter.mac_addr);
11593 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
11594 : 0 : PMD_DRV_LOG(ERR, "Failed to delete mac filter");
11595 : 0 : return -EIO;
11596 : : }
11597 : : memcpy(&mac_filter.mac_addr, mac_addr, ETH_ADDR_LEN);
11598 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter);
11599 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
11600 : 0 : PMD_DRV_LOG(ERR, "Failed to add mac filter");
11601 : 0 : return -EIO;
11602 : : }
11603 : 0 : memcpy(&pf->dev_addr, mac_addr, ETH_ADDR_LEN);
11604 : :
11605 : 0 : ret = i40e_aq_mac_address_write(hw, I40E_AQC_WRITE_TYPE_LAA_WOL,
11606 : 0 : mac_addr->addr_bytes, NULL);
11607 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
11608 : 0 : PMD_DRV_LOG(ERR, "Failed to change mac");
11609 : 0 : return -EIO;
11610 : : }
11611 : :
11612 : : return 0;
11613 : : }
11614 : :
11615 : : static int
11616 : 0 : i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu __rte_unused)
11617 : : {
11618 : : /* mtu setting is forbidden if port is start */
11619 [ # # ]: 0 : if (dev->data->dev_started != 0) {
11620 : 0 : PMD_DRV_LOG(ERR, "port %d must be stopped before configuration",
11621 : : dev->data->port_id);
11622 : 0 : return -EBUSY;
11623 : : }
11624 : :
11625 : : return 0;
11626 : : }
11627 : :
11628 : : /* Restore ethertype filter */
11629 : : static void
11630 : 0 : i40e_ethertype_filter_restore(struct i40e_pf *pf)
11631 : : {
11632 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11633 : : struct i40e_ethertype_filter_list
11634 : : *ethertype_list = &pf->ethertype.ethertype_list;
11635 : : struct i40e_ethertype_filter *f;
11636 : : struct i40e_control_filter_stats stats;
11637 : : uint16_t flags;
11638 : :
11639 [ # # ]: 0 : TAILQ_FOREACH(f, ethertype_list, rules) {
11640 : : flags = 0;
11641 [ # # ]: 0 : if (!(f->flags & RTE_ETHTYPE_FLAGS_MAC))
11642 : : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
11643 [ # # ]: 0 : if (f->flags & RTE_ETHTYPE_FLAGS_DROP)
11644 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
11645 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
11646 : :
11647 : : memset(&stats, 0, sizeof(stats));
11648 : 0 : i40e_aq_add_rem_control_packet_filter(hw,
11649 : 0 : f->input.mac_addr.addr_bytes,
11650 : 0 : f->input.ether_type,
11651 : 0 : flags, pf->main_vsi->seid,
11652 : 0 : f->queue, 1, &stats, NULL);
11653 : : }
11654 : 0 : PMD_DRV_LOG(INFO, "Ethertype filter:"
11655 : : " mac_etype_used = %u, etype_used = %u,"
11656 : : " mac_etype_free = %u, etype_free = %u",
11657 : : stats.mac_etype_used, stats.etype_used,
11658 : : stats.mac_etype_free, stats.etype_free);
11659 : 0 : }
11660 : :
11661 : : /* Restore tunnel filter */
11662 : : static void
11663 : 0 : i40e_tunnel_filter_restore(struct i40e_pf *pf)
11664 : : {
11665 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11666 : : struct i40e_vsi *vsi;
11667 : : struct i40e_pf_vf *vf;
11668 : : struct i40e_tunnel_filter_list
11669 : : *tunnel_list = &pf->tunnel.tunnel_list;
11670 : : struct i40e_tunnel_filter *f;
11671 : : struct i40e_aqc_cloud_filters_element_bb cld_filter;
11672 : : bool big_buffer = 0;
11673 : :
11674 [ # # ]: 0 : TAILQ_FOREACH(f, tunnel_list, rules) {
11675 [ # # ]: 0 : if (!f->is_to_vf)
11676 : 0 : vsi = pf->main_vsi;
11677 : : else {
11678 : 0 : vf = &pf->vfs[f->vf_id];
11679 : 0 : vsi = vf->vsi;
11680 : : }
11681 : : memset(&cld_filter, 0, sizeof(cld_filter));
11682 : : rte_ether_addr_copy((struct rte_ether_addr *)
11683 : : &f->input.outer_mac,
11684 : : (struct rte_ether_addr *)&cld_filter.element.outer_mac);
11685 : : rte_ether_addr_copy((struct rte_ether_addr *)
11686 : : &f->input.inner_mac,
11687 : : (struct rte_ether_addr *)&cld_filter.element.inner_mac);
11688 : 0 : cld_filter.element.inner_vlan = f->input.inner_vlan;
11689 : 0 : cld_filter.element.flags = f->input.flags;
11690 : 0 : cld_filter.element.tenant_id = f->input.tenant_id;
11691 : 0 : cld_filter.element.queue_number = f->queue;
11692 : : rte_memcpy(cld_filter.general_fields,
11693 [ # # ]: 0 : f->input.general_fields,
11694 : : sizeof(f->input.general_fields));
11695 : :
11696 [ # # ]: 0 : if (((f->input.flags &
11697 : : I40E_AQC_ADD_CLOUD_FILTER_0X11) ==
11698 [ # # ]: 0 : I40E_AQC_ADD_CLOUD_FILTER_0X11) ||
11699 : : ((f->input.flags &
11700 : : I40E_AQC_ADD_CLOUD_FILTER_0X12) ==
11701 [ # # ]: 0 : I40E_AQC_ADD_CLOUD_FILTER_0X12) ||
11702 : : ((f->input.flags &
11703 : : I40E_AQC_ADD_CLOUD_FILTER_0X10) ==
11704 : : I40E_AQC_ADD_CLOUD_FILTER_0X10))
11705 : : big_buffer = 1;
11706 : :
11707 [ # # ]: 0 : if (big_buffer)
11708 : 0 : i40e_aq_add_cloud_filters_bb(hw,
11709 : 0 : vsi->seid, &cld_filter, 1);
11710 : : else
11711 : 0 : i40e_aq_add_cloud_filters(hw, vsi->seid,
11712 : : &cld_filter.element, 1);
11713 : : }
11714 : 0 : }
11715 : :
11716 : : static void
11717 : 0 : i40e_filter_restore(struct i40e_pf *pf)
11718 : : {
11719 : 0 : i40e_ethertype_filter_restore(pf);
11720 : 0 : i40e_tunnel_filter_restore(pf);
11721 : 0 : i40e_fdir_filter_restore(pf);
11722 : 0 : (void)i40e_hash_filter_restore(pf);
11723 : 0 : }
11724 : :
11725 : : bool
11726 : 0 : is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
11727 : : {
11728 [ # # ]: 0 : if (strcmp(dev->device->driver->name, drv->driver.name))
11729 : 0 : return false;
11730 : :
11731 : : return true;
11732 : : }
11733 : :
11734 : : bool
11735 : 0 : is_i40e_supported(struct rte_eth_dev *dev)
11736 : : {
11737 : 0 : return is_device_supported(dev, &rte_i40e_pmd);
11738 : : }
11739 : :
11740 : : struct i40e_customized_pctype*
11741 : 0 : i40e_find_customized_pctype(struct i40e_pf *pf, uint8_t index)
11742 : : {
11743 : : int i;
11744 : :
11745 [ # # ]: 0 : for (i = 0; i < I40E_CUSTOMIZED_MAX; i++) {
11746 [ # # ]: 0 : if (pf->customized_pctype[i].index == index)
11747 : 0 : return &pf->customized_pctype[i];
11748 : : }
11749 : : return NULL;
11750 : : }
11751 : :
11752 : : static int
11753 : 0 : i40e_update_customized_pctype(struct rte_eth_dev *dev, uint8_t *pkg,
11754 : : uint32_t pkg_size, uint32_t proto_num,
11755 : : struct rte_pmd_i40e_proto_info *proto,
11756 : : enum rte_pmd_i40e_package_op op)
11757 : : {
11758 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11759 : : uint32_t pctype_num;
11760 : : struct rte_pmd_i40e_ptype_info *pctype;
11761 : : uint32_t buff_size;
11762 : : struct i40e_customized_pctype *new_pctype = NULL;
11763 : : uint8_t proto_id;
11764 : : uint8_t pctype_value;
11765 : : char name[64];
11766 : : uint32_t i, j, n;
11767 : : int ret;
11768 : :
11769 [ # # ]: 0 : if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
11770 : : op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
11771 : 0 : PMD_DRV_LOG(ERR, "Unsupported operation.");
11772 : 0 : return -1;
11773 : : }
11774 : :
11775 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11776 : : (uint8_t *)&pctype_num, sizeof(pctype_num),
11777 : : RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
11778 [ # # ]: 0 : if (ret) {
11779 : 0 : PMD_DRV_LOG(ERR, "Failed to get pctype number");
11780 : 0 : return -1;
11781 : : }
11782 [ # # ]: 0 : if (!pctype_num) {
11783 : 0 : PMD_DRV_LOG(INFO, "No new pctype added");
11784 : 0 : return -1;
11785 : : }
11786 : :
11787 : 0 : buff_size = pctype_num * sizeof(struct rte_pmd_i40e_proto_info);
11788 : 0 : pctype = rte_zmalloc("new_pctype", buff_size, 0);
11789 [ # # ]: 0 : if (!pctype) {
11790 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory");
11791 : 0 : return -1;
11792 : : }
11793 : : /* get information about new pctype list */
11794 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11795 : : (uint8_t *)pctype, buff_size,
11796 : : RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
11797 [ # # ]: 0 : if (ret) {
11798 : 0 : PMD_DRV_LOG(ERR, "Failed to get pctype list");
11799 : 0 : rte_free(pctype);
11800 : 0 : return -1;
11801 : : }
11802 : :
11803 : : /* Update customized pctype. */
11804 [ # # ]: 0 : for (i = 0; i < pctype_num; i++) {
11805 : 0 : pctype_value = pctype[i].ptype_id;
11806 : : memset(name, 0, sizeof(name));
11807 [ # # ]: 0 : for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
11808 : 0 : proto_id = pctype[i].protocols[j];
11809 [ # # ]: 0 : if (proto_id == RTE_PMD_I40E_PROTO_UNUSED)
11810 : 0 : continue;
11811 [ # # ]: 0 : for (n = 0; n < proto_num; n++) {
11812 [ # # ]: 0 : if (proto[n].proto_id != proto_id)
11813 : : continue;
11814 : 0 : strlcat(name, proto[n].name, sizeof(name));
11815 : 0 : strlcat(name, "_", sizeof(name));
11816 : 0 : break;
11817 : : }
11818 : : }
11819 : 0 : name[strlen(name) - 1] = '\0';
11820 : 0 : PMD_DRV_LOG(INFO, "name = %s\n", name);
11821 [ # # ]: 0 : if (!strcmp(name, "GTPC"))
11822 : : new_pctype =
11823 : 0 : i40e_find_customized_pctype(pf,
11824 : : I40E_CUSTOMIZED_GTPC);
11825 [ # # ]: 0 : else if (!strcmp(name, "GTPU_IPV4"))
11826 : : new_pctype =
11827 : 0 : i40e_find_customized_pctype(pf,
11828 : : I40E_CUSTOMIZED_GTPU_IPV4);
11829 [ # # ]: 0 : else if (!strcmp(name, "GTPU_IPV6"))
11830 : : new_pctype =
11831 : 0 : i40e_find_customized_pctype(pf,
11832 : : I40E_CUSTOMIZED_GTPU_IPV6);
11833 [ # # ]: 0 : else if (!strcmp(name, "GTPU"))
11834 : : new_pctype =
11835 : 0 : i40e_find_customized_pctype(pf,
11836 : : I40E_CUSTOMIZED_GTPU);
11837 [ # # ]: 0 : else if (!strcmp(name, "IPV4_L2TPV3"))
11838 : : new_pctype =
11839 : 0 : i40e_find_customized_pctype(pf,
11840 : : I40E_CUSTOMIZED_IPV4_L2TPV3);
11841 [ # # ]: 0 : else if (!strcmp(name, "IPV6_L2TPV3"))
11842 : : new_pctype =
11843 : 0 : i40e_find_customized_pctype(pf,
11844 : : I40E_CUSTOMIZED_IPV6_L2TPV3);
11845 [ # # ]: 0 : else if (!strcmp(name, "IPV4_ESP"))
11846 : : new_pctype =
11847 : 0 : i40e_find_customized_pctype(pf,
11848 : : I40E_CUSTOMIZED_ESP_IPV4);
11849 [ # # ]: 0 : else if (!strcmp(name, "IPV6_ESP"))
11850 : : new_pctype =
11851 : 0 : i40e_find_customized_pctype(pf,
11852 : : I40E_CUSTOMIZED_ESP_IPV6);
11853 [ # # ]: 0 : else if (!strcmp(name, "IPV4_UDP_ESP"))
11854 : : new_pctype =
11855 : 0 : i40e_find_customized_pctype(pf,
11856 : : I40E_CUSTOMIZED_ESP_IPV4_UDP);
11857 [ # # ]: 0 : else if (!strcmp(name, "IPV6_UDP_ESP"))
11858 : : new_pctype =
11859 : 0 : i40e_find_customized_pctype(pf,
11860 : : I40E_CUSTOMIZED_ESP_IPV6_UDP);
11861 [ # # ]: 0 : else if (!strcmp(name, "IPV4_AH"))
11862 : : new_pctype =
11863 : 0 : i40e_find_customized_pctype(pf,
11864 : : I40E_CUSTOMIZED_AH_IPV4);
11865 [ # # ]: 0 : else if (!strcmp(name, "IPV6_AH"))
11866 : : new_pctype =
11867 : 0 : i40e_find_customized_pctype(pf,
11868 : : I40E_CUSTOMIZED_AH_IPV6);
11869 [ # # ]: 0 : if (new_pctype) {
11870 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_ADD) {
11871 : 0 : new_pctype->pctype = pctype_value;
11872 : 0 : new_pctype->valid = true;
11873 : : } else {
11874 : 0 : new_pctype->pctype = I40E_FILTER_PCTYPE_INVALID;
11875 : 0 : new_pctype->valid = false;
11876 : : }
11877 : : }
11878 : : }
11879 : :
11880 : 0 : rte_free(pctype);
11881 : 0 : return 0;
11882 : : }
11883 : :
11884 : : static int
11885 : 0 : i40e_update_customized_ptype(struct rte_eth_dev *dev, uint8_t *pkg,
11886 : : uint32_t pkg_size, uint32_t proto_num,
11887 : : struct rte_pmd_i40e_proto_info *proto,
11888 : : enum rte_pmd_i40e_package_op op)
11889 : : {
11890 : : struct rte_pmd_i40e_ptype_mapping *ptype_mapping;
11891 : 0 : uint16_t port_id = dev->data->port_id;
11892 : : uint32_t ptype_num;
11893 : : struct rte_pmd_i40e_ptype_info *ptype;
11894 : : uint32_t buff_size;
11895 : : uint8_t proto_id;
11896 : : char name[RTE_PMD_I40E_DDP_NAME_SIZE];
11897 : : uint32_t i, j, n;
11898 : : bool in_tunnel;
11899 : : int ret;
11900 : :
11901 [ # # ]: 0 : if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
11902 : : op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
11903 : 0 : PMD_DRV_LOG(ERR, "Unsupported operation.");
11904 : 0 : return -1;
11905 : : }
11906 : :
11907 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_DEL) {
11908 : 0 : rte_pmd_i40e_ptype_mapping_reset(port_id);
11909 : 0 : return 0;
11910 : : }
11911 : :
11912 : : /* get information about new ptype num */
11913 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11914 : : (uint8_t *)&ptype_num, sizeof(ptype_num),
11915 : : RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
11916 [ # # ]: 0 : if (ret) {
11917 : 0 : PMD_DRV_LOG(ERR, "Failed to get ptype number");
11918 : 0 : return ret;
11919 : : }
11920 [ # # ]: 0 : if (!ptype_num) {
11921 : 0 : PMD_DRV_LOG(INFO, "No new ptype added");
11922 : 0 : return -1;
11923 : : }
11924 : :
11925 : 0 : buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info);
11926 : 0 : ptype = rte_zmalloc("new_ptype", buff_size, 0);
11927 [ # # ]: 0 : if (!ptype) {
11928 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory");
11929 : 0 : return -1;
11930 : : }
11931 : :
11932 : : /* get information about new ptype list */
11933 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11934 : : (uint8_t *)ptype, buff_size,
11935 : : RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
11936 [ # # ]: 0 : if (ret) {
11937 : 0 : PMD_DRV_LOG(ERR, "Failed to get ptype list");
11938 : 0 : rte_free(ptype);
11939 : 0 : return ret;
11940 : : }
11941 : :
11942 : 0 : buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_mapping);
11943 : 0 : ptype_mapping = rte_zmalloc("ptype_mapping", buff_size, 0);
11944 [ # # ]: 0 : if (!ptype_mapping) {
11945 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory");
11946 : 0 : rte_free(ptype);
11947 : 0 : return -1;
11948 : : }
11949 : :
11950 : : /* Update ptype mapping table. */
11951 [ # # ]: 0 : for (i = 0; i < ptype_num; i++) {
11952 : 0 : ptype_mapping[i].hw_ptype = ptype[i].ptype_id;
11953 : 0 : ptype_mapping[i].sw_ptype = 0;
11954 : : in_tunnel = false;
11955 [ # # ]: 0 : for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
11956 : 0 : proto_id = ptype[i].protocols[j];
11957 [ # # ]: 0 : if (proto_id == RTE_PMD_I40E_PROTO_UNUSED)
11958 : 0 : continue;
11959 [ # # ]: 0 : for (n = 0; n < proto_num; n++) {
11960 [ # # ]: 0 : if (proto[n].proto_id != proto_id)
11961 : : continue;
11962 : : memset(name, 0, sizeof(name));
11963 : 0 : strcpy(name, proto[n].name);
11964 : 0 : PMD_DRV_LOG(INFO, "name = %s\n", name);
11965 [ # # ]: 0 : if (!strncasecmp(name, "PPPOE", 5))
11966 : 0 : ptype_mapping[i].sw_ptype |=
11967 : : RTE_PTYPE_L2_ETHER_PPPOE;
11968 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV4FRAG", 8) &&
11969 : : !in_tunnel) {
11970 : 0 : ptype_mapping[i].sw_ptype |=
11971 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11972 : 0 : ptype_mapping[i].sw_ptype |=
11973 : : RTE_PTYPE_L4_FRAG;
11974 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV4FRAG", 8) &&
11975 : : in_tunnel) {
11976 : 0 : ptype_mapping[i].sw_ptype |=
11977 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
11978 : 0 : ptype_mapping[i].sw_ptype |=
11979 : : RTE_PTYPE_INNER_L4_FRAG;
11980 [ # # ]: 0 : } else if (!strncasecmp(name, "OIPV4", 5)) {
11981 : 0 : ptype_mapping[i].sw_ptype |=
11982 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11983 : : in_tunnel = true;
11984 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV4", 4) &&
11985 : : !in_tunnel)
11986 : 0 : ptype_mapping[i].sw_ptype |=
11987 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11988 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV4", 4) &&
11989 : : in_tunnel)
11990 : 0 : ptype_mapping[i].sw_ptype |=
11991 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
11992 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV6FRAG", 8) &&
11993 : : !in_tunnel) {
11994 : 0 : ptype_mapping[i].sw_ptype |=
11995 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11996 : 0 : ptype_mapping[i].sw_ptype |=
11997 : : RTE_PTYPE_L4_FRAG;
11998 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV6FRAG", 8) &&
11999 : : in_tunnel) {
12000 : 0 : ptype_mapping[i].sw_ptype |=
12001 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
12002 : 0 : ptype_mapping[i].sw_ptype |=
12003 : : RTE_PTYPE_INNER_L4_FRAG;
12004 [ # # ]: 0 : } else if (!strncasecmp(name, "OIPV6", 5)) {
12005 : 0 : ptype_mapping[i].sw_ptype |=
12006 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
12007 : : in_tunnel = true;
12008 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV6", 4) &&
12009 : : !in_tunnel)
12010 : 0 : ptype_mapping[i].sw_ptype |=
12011 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
12012 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV6", 4) &&
12013 : : in_tunnel)
12014 : 0 : ptype_mapping[i].sw_ptype |=
12015 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
12016 [ # # # # ]: 0 : else if (!strncasecmp(name, "UDP", 3) &&
12017 : : !in_tunnel)
12018 : 0 : ptype_mapping[i].sw_ptype |=
12019 : : RTE_PTYPE_L4_UDP;
12020 [ # # # # ]: 0 : else if (!strncasecmp(name, "UDP", 3) &&
12021 : : in_tunnel)
12022 : 0 : ptype_mapping[i].sw_ptype |=
12023 : : RTE_PTYPE_INNER_L4_UDP;
12024 [ # # # # ]: 0 : else if (!strncasecmp(name, "TCP", 3) &&
12025 : : !in_tunnel)
12026 : 0 : ptype_mapping[i].sw_ptype |=
12027 : : RTE_PTYPE_L4_TCP;
12028 [ # # # # ]: 0 : else if (!strncasecmp(name, "TCP", 3) &&
12029 : : in_tunnel)
12030 : 0 : ptype_mapping[i].sw_ptype |=
12031 : : RTE_PTYPE_INNER_L4_TCP;
12032 [ # # # # ]: 0 : else if (!strncasecmp(name, "SCTP", 4) &&
12033 : : !in_tunnel)
12034 : 0 : ptype_mapping[i].sw_ptype |=
12035 : : RTE_PTYPE_L4_SCTP;
12036 [ # # # # ]: 0 : else if (!strncasecmp(name, "SCTP", 4) &&
12037 : : in_tunnel)
12038 : 0 : ptype_mapping[i].sw_ptype |=
12039 : : RTE_PTYPE_INNER_L4_SCTP;
12040 [ # # ]: 0 : else if ((!strncasecmp(name, "ICMP", 4) ||
12041 [ # # # # ]: 0 : !strncasecmp(name, "ICMPV6", 6)) &&
12042 : : !in_tunnel)
12043 : 0 : ptype_mapping[i].sw_ptype |=
12044 : : RTE_PTYPE_L4_ICMP;
12045 [ # # ]: 0 : else if ((!strncasecmp(name, "ICMP", 4) ||
12046 [ # # # # ]: 0 : !strncasecmp(name, "ICMPV6", 6)) &&
12047 : : in_tunnel)
12048 : 0 : ptype_mapping[i].sw_ptype |=
12049 : : RTE_PTYPE_INNER_L4_ICMP;
12050 [ # # ]: 0 : else if (!strncasecmp(name, "GTPC", 4)) {
12051 : 0 : ptype_mapping[i].sw_ptype |=
12052 : : RTE_PTYPE_TUNNEL_GTPC;
12053 : : in_tunnel = true;
12054 [ # # ]: 0 : } else if (!strncasecmp(name, "GTPU", 4)) {
12055 : 0 : ptype_mapping[i].sw_ptype |=
12056 : : RTE_PTYPE_TUNNEL_GTPU;
12057 : : in_tunnel = true;
12058 [ # # ]: 0 : } else if (!strncasecmp(name, "ESP", 3)) {
12059 : 0 : ptype_mapping[i].sw_ptype |=
12060 : : RTE_PTYPE_TUNNEL_ESP;
12061 : : in_tunnel = true;
12062 [ # # ]: 0 : } else if (!strncasecmp(name, "GRENAT", 6)) {
12063 : 0 : ptype_mapping[i].sw_ptype |=
12064 : : RTE_PTYPE_TUNNEL_GRENAT;
12065 : : in_tunnel = true;
12066 [ # # ]: 0 : } else if (!strncasecmp(name, "L2TPV2CTL", 9) ||
12067 [ # # ]: 0 : !strncasecmp(name, "L2TPV2", 6) ||
12068 [ # # ]: 0 : !strncasecmp(name, "L2TPV3", 6)) {
12069 : 0 : ptype_mapping[i].sw_ptype |=
12070 : : RTE_PTYPE_TUNNEL_L2TP;
12071 : : in_tunnel = true;
12072 : : }
12073 : :
12074 : : break;
12075 : : }
12076 : : }
12077 : : }
12078 : :
12079 : 0 : ret = rte_pmd_i40e_ptype_mapping_update(port_id, ptype_mapping,
12080 : : ptype_num, 0);
12081 [ # # ]: 0 : if (ret)
12082 : 0 : PMD_DRV_LOG(ERR, "Failed to update ptype mapping table.");
12083 : :
12084 : 0 : rte_free(ptype_mapping);
12085 : 0 : rte_free(ptype);
12086 : 0 : return ret;
12087 : : }
12088 : :
12089 : : void
12090 : 0 : i40e_update_customized_info(struct rte_eth_dev *dev, uint8_t *pkg,
12091 : : uint32_t pkg_size, enum rte_pmd_i40e_package_op op)
12092 : : {
12093 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
12094 : : uint32_t proto_num;
12095 : : struct rte_pmd_i40e_proto_info *proto;
12096 : : uint32_t buff_size;
12097 : : uint32_t i;
12098 : : int ret;
12099 : :
12100 [ # # ]: 0 : if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
12101 : : op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
12102 : 0 : PMD_DRV_LOG(ERR, "Unsupported operation.");
12103 : 0 : return;
12104 : : }
12105 : :
12106 : : /* get information about protocol number */
12107 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12108 : : (uint8_t *)&proto_num, sizeof(proto_num),
12109 : : RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
12110 [ # # ]: 0 : if (ret) {
12111 : 0 : PMD_DRV_LOG(ERR, "Failed to get protocol number");
12112 : 0 : return;
12113 : : }
12114 [ # # ]: 0 : if (!proto_num) {
12115 : 0 : PMD_DRV_LOG(INFO, "No new protocol added");
12116 : 0 : return;
12117 : : }
12118 : :
12119 : 0 : buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
12120 : 0 : proto = rte_zmalloc("new_proto", buff_size, 0);
12121 [ # # ]: 0 : if (!proto) {
12122 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory");
12123 : 0 : return;
12124 : : }
12125 : :
12126 : : /* get information about protocol list */
12127 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12128 : : (uint8_t *)proto, buff_size,
12129 : : RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
12130 [ # # ]: 0 : if (ret) {
12131 : 0 : PMD_DRV_LOG(ERR, "Failed to get protocol list");
12132 : 0 : rte_free(proto);
12133 : 0 : return;
12134 : : }
12135 : :
12136 : : /* Check if GTP is supported. */
12137 [ # # ]: 0 : for (i = 0; i < proto_num; i++) {
12138 [ # # ]: 0 : if (!strncmp(proto[i].name, "GTP", 3)) {
12139 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
12140 : 0 : pf->gtp_support = true;
12141 : : else
12142 : 0 : pf->gtp_support = false;
12143 : : break;
12144 : : }
12145 : : }
12146 : :
12147 : : /* Check if ESP is supported. */
12148 [ # # ]: 0 : for (i = 0; i < proto_num; i++) {
12149 [ # # ]: 0 : if (!strncmp(proto[i].name, "ESP", 3)) {
12150 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
12151 : 0 : pf->esp_support = true;
12152 : : else
12153 : 0 : pf->esp_support = false;
12154 : : break;
12155 : : }
12156 : : }
12157 : :
12158 : : /* Update customized pctype info */
12159 : 0 : ret = i40e_update_customized_pctype(dev, pkg, pkg_size,
12160 : : proto_num, proto, op);
12161 [ # # ]: 0 : if (ret)
12162 : 0 : PMD_DRV_LOG(INFO, "No pctype is updated.");
12163 : :
12164 : : /* Update customized ptype info */
12165 : 0 : ret = i40e_update_customized_ptype(dev, pkg, pkg_size,
12166 : : proto_num, proto, op);
12167 [ # # ]: 0 : if (ret)
12168 : 0 : PMD_DRV_LOG(INFO, "No ptype is updated.");
12169 : :
12170 : 0 : rte_free(proto);
12171 : : }
12172 : :
12173 : : /* Create a QinQ cloud filter
12174 : : *
12175 : : * The Fortville NIC has limited resources for tunnel filters,
12176 : : * so we can only reuse existing filters.
12177 : : *
12178 : : * In step 1 we define which Field Vector fields can be used for
12179 : : * filter types.
12180 : : * As we do not have the inner tag defined as a field,
12181 : : * we have to define it first, by reusing one of L1 entries.
12182 : : *
12183 : : * In step 2 we are replacing one of existing filter types with
12184 : : * a new one for QinQ.
12185 : : * As we reusing L1 and replacing L2, some of the default filter
12186 : : * types will disappear,which depends on L1 and L2 entries we reuse.
12187 : : *
12188 : : * Step 1: Create L1 filter of outer vlan (12b) + inner vlan (12b)
12189 : : *
12190 : : * 1. Create L1 filter of outer vlan (12b) which will be in use
12191 : : * later when we define the cloud filter.
12192 : : * a. Valid_flags.replace_cloud = 0
12193 : : * b. Old_filter = 10 (Stag_Inner_Vlan)
12194 : : * c. New_filter = 0x10
12195 : : * d. TR bit = 0xff (optional, not used here)
12196 : : * e. Buffer – 2 entries:
12197 : : * i. Byte 0 = 8 (outer vlan FV index).
12198 : : * Byte 1 = 0 (rsv)
12199 : : * Byte 2-3 = 0x0fff
12200 : : * ii. Byte 0 = 37 (inner vlan FV index).
12201 : : * Byte 1 =0 (rsv)
12202 : : * Byte 2-3 = 0x0fff
12203 : : *
12204 : : * Step 2:
12205 : : * 2. Create cloud filter using two L1 filters entries: stag and
12206 : : * new filter(outer vlan+ inner vlan)
12207 : : * a. Valid_flags.replace_cloud = 1
12208 : : * b. Old_filter = 1 (instead of outer IP)
12209 : : * c. New_filter = 0x10
12210 : : * d. Buffer – 2 entries:
12211 : : * i. Byte 0 = 0x80 | 7 (valid | Stag).
12212 : : * Byte 1-3 = 0 (rsv)
12213 : : * ii. Byte 8 = 0x80 | 0x10 (valid | new l1 filter step1)
12214 : : * Byte 9-11 = 0 (rsv)
12215 : : */
12216 : : static int
12217 : 0 : i40e_cloud_filter_qinq_create(struct i40e_pf *pf)
12218 : : {
12219 : : int ret = -ENOTSUP;
12220 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
12221 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
12222 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
12223 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
12224 : :
12225 [ # # ]: 0 : if (pf->support_multi_driver) {
12226 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
12227 : 0 : return ret;
12228 : : }
12229 : :
12230 : : /* Init */
12231 : : memset(&filter_replace, 0,
12232 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
12233 : : memset(&filter_replace_buf, 0,
12234 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
12235 : :
12236 : : /* create L1 filter */
12237 : 0 : filter_replace.old_filter_type =
12238 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG_IVLAN;
12239 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12240 : : filter_replace.tr_bit = 0;
12241 : :
12242 : : /* Prepare the buffer, 2 entries */
12243 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_VLAN;
12244 : 0 : filter_replace_buf.data[0] |=
12245 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12246 : : /* Field Vector 12b mask */
12247 : 0 : filter_replace_buf.data[2] = 0xff;
12248 : 0 : filter_replace_buf.data[3] = 0x0f;
12249 : : filter_replace_buf.data[4] =
12250 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_INNER_VLAN;
12251 : 0 : filter_replace_buf.data[4] |=
12252 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12253 : : /* Field Vector 12b mask */
12254 : 0 : filter_replace_buf.data[6] = 0xff;
12255 : 0 : filter_replace_buf.data[7] = 0x0f;
12256 : 0 : ret = i40e_aq_replace_cloud_filters(hw, &filter_replace,
12257 : : &filter_replace_buf);
12258 [ # # ]: 0 : if (ret != I40E_SUCCESS)
12259 : : return ret;
12260 : :
12261 : 0 : if (filter_replace.old_filter_type !=
12262 [ # # ]: 0 : filter_replace.new_filter_type)
12263 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
12264 : : " original: 0x%x, new: 0x%x",
12265 : : dev->device->name,
12266 : : filter_replace.old_filter_type,
12267 : : filter_replace.new_filter_type);
12268 : :
12269 : : /* Apply the second L2 cloud filter */
12270 : : memset(&filter_replace, 0,
12271 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
12272 : : memset(&filter_replace_buf, 0,
12273 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
12274 : :
12275 : : /* create L2 filter, input for L2 filter will be L1 filter */
12276 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
12277 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_OIP;
12278 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12279 : :
12280 : : /* Prepare the buffer, 2 entries */
12281 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
12282 : 0 : filter_replace_buf.data[0] |=
12283 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12284 : : filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12285 : 0 : filter_replace_buf.data[4] |=
12286 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12287 : 0 : ret = i40e_aq_replace_cloud_filters(hw, &filter_replace,
12288 : : &filter_replace_buf);
12289 [ # # ]: 0 : if (!ret && (filter_replace.old_filter_type !=
12290 [ # # ]: 0 : filter_replace.new_filter_type))
12291 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
12292 : : " original: 0x%x, new: 0x%x",
12293 : : dev->device->name,
12294 : : filter_replace.old_filter_type,
12295 : : filter_replace.new_filter_type);
12296 : :
12297 : : return ret;
12298 : : }
12299 : :
12300 [ - + ]: 238 : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_init, init, NOTICE);
12301 [ - + ]: 238 : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_driver, driver, NOTICE);
12302 : : #ifdef RTE_ETHDEV_DEBUG_RX
12303 : : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_rx, rx, DEBUG);
12304 : : #endif
12305 : : #ifdef RTE_ETHDEV_DEBUG_TX
12306 : : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_tx, tx, DEBUG);
12307 : : #endif
12308 : :
12309 : : RTE_PMD_REGISTER_PARAM_STRING(net_i40e,
12310 : : ETH_I40E_FLOATING_VEB_ARG "=1"
12311 : : ETH_I40E_FLOATING_VEB_LIST_ARG "=<string>"
12312 : : ETH_I40E_QUEUE_NUM_PER_VF_ARG "=1|2|4|8|16"
12313 : : ETH_I40E_SUPPORT_MULTI_DRIVER "=1");
|