Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2017 Intel Corporation
3 : : */
4 : :
5 : : #include <ctype.h>
6 : : #include <stdio.h>
7 : : #include <errno.h>
8 : : #include <stdint.h>
9 : : #include <stdlib.h>
10 : : #include <string.h>
11 : : #include <unistd.h>
12 : : #include <stdarg.h>
13 : : #include <inttypes.h>
14 : : #include <assert.h>
15 : :
16 : : #include <rte_common.h>
17 : : #include <rte_eal.h>
18 : : #include <rte_string_fns.h>
19 : : #include <rte_pci.h>
20 : : #include <bus_pci_driver.h>
21 : : #include <rte_ether.h>
22 : : #include <ethdev_driver.h>
23 : : #include <ethdev_pci.h>
24 : : #include <rte_memzone.h>
25 : : #include <rte_malloc.h>
26 : : #include <rte_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, struct eth_queue_stats *qstats);
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 : : static int i40e_fec_get_capability(struct rte_eth_dev *dev,
410 : : struct rte_eth_fec_capa *speed_fec_capa, unsigned int num);
411 : : static int i40e_fec_get(struct rte_eth_dev *dev, uint32_t *fec_capa);
412 : : static int i40e_fec_set(struct rte_eth_dev *dev, uint32_t fec_capa);
413 : :
414 : : static const char *const valid_keys[] = {
415 : : ETH_I40E_FLOATING_VEB_ARG,
416 : : ETH_I40E_FLOATING_VEB_LIST_ARG,
417 : : ETH_I40E_SUPPORT_MULTI_DRIVER,
418 : : ETH_I40E_QUEUE_NUM_PER_VF_ARG,
419 : : ETH_I40E_VF_MSG_CFG,
420 : : ETH_I40E_MBUF_CHECK_ARG,
421 : : NULL};
422 : :
423 : : static const struct rte_pci_id pci_id_i40e_map[] = {
424 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_XL710) },
425 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QEMU) },
426 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_B) },
427 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_C) },
428 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_A) },
429 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_B) },
430 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_C) },
431 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T) },
432 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_20G_KR2) },
433 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_20G_KR2_A) },
434 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T4) },
435 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_B) },
436 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_25G_SFP28) },
437 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_KX_X722) },
438 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_QSFP_X722) },
439 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_X722) },
440 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_1G_BASE_T_X722) },
441 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_X722) },
442 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_I_X722) },
443 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_X710_N3000) },
444 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_XXV710_N3000) },
445 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_BASE_T_BC) },
446 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_5G_BASE_T_BC) },
447 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_1G_BASE_T_BC) },
448 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_B) },
449 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_10G_SFP) },
450 : : { RTE_PCI_DEVICE(I40E_INTEL_VENDOR_ID, I40E_DEV_ID_SFP_X722_A) },
451 : : { .vendor_id = 0, /* sentinel */ },
452 : : };
453 : :
454 : : static const struct eth_dev_ops i40e_eth_dev_ops = {
455 : : .dev_configure = i40e_dev_configure,
456 : : .dev_start = i40e_dev_start,
457 : : .dev_stop = i40e_dev_stop,
458 : : .dev_close = i40e_dev_close,
459 : : .dev_reset = i40e_dev_reset,
460 : : .promiscuous_enable = i40e_dev_promiscuous_enable,
461 : : .promiscuous_disable = i40e_dev_promiscuous_disable,
462 : : .allmulticast_enable = i40e_dev_allmulticast_enable,
463 : : .allmulticast_disable = i40e_dev_allmulticast_disable,
464 : : .dev_set_link_up = i40e_dev_set_link_up,
465 : : .dev_set_link_down = i40e_dev_set_link_down,
466 : : .link_update = i40e_dev_link_update,
467 : : .stats_get = i40e_dev_stats_get,
468 : : .xstats_get = i40e_dev_xstats_get,
469 : : .xstats_get_names = i40e_dev_xstats_get_names,
470 : : .stats_reset = i40e_dev_stats_reset,
471 : : .xstats_reset = i40e_dev_stats_reset,
472 : : .fw_version_get = i40e_fw_version_get,
473 : : .dev_infos_get = i40e_dev_info_get,
474 : : .dev_supported_ptypes_get = i40e_dev_supported_ptypes_get,
475 : : .vlan_filter_set = i40e_vlan_filter_set,
476 : : .vlan_tpid_set = i40e_vlan_tpid_set,
477 : : .vlan_offload_set = i40e_vlan_offload_set,
478 : : .vlan_strip_queue_set = i40e_vlan_strip_queue_set,
479 : : .vlan_pvid_set = i40e_vlan_pvid_set,
480 : : .rx_queue_start = i40e_dev_rx_queue_start,
481 : : .rx_queue_stop = i40e_dev_rx_queue_stop,
482 : : .tx_queue_start = i40e_dev_tx_queue_start,
483 : : .tx_queue_stop = i40e_dev_tx_queue_stop,
484 : : .rx_queue_setup = i40e_dev_rx_queue_setup,
485 : : .rx_queue_intr_enable = i40e_dev_rx_queue_intr_enable,
486 : : .rx_queue_intr_disable = i40e_dev_rx_queue_intr_disable,
487 : : .rx_queue_release = i40e_dev_rx_queue_release,
488 : : .tx_queue_setup = i40e_dev_tx_queue_setup,
489 : : .tx_queue_release = i40e_dev_tx_queue_release,
490 : : .dev_led_on = i40e_dev_led_on,
491 : : .dev_led_off = i40e_dev_led_off,
492 : : .flow_ctrl_get = i40e_flow_ctrl_get,
493 : : .flow_ctrl_set = i40e_flow_ctrl_set,
494 : : .priority_flow_ctrl_set = i40e_priority_flow_ctrl_set,
495 : : .mac_addr_add = i40e_macaddr_add,
496 : : .mac_addr_remove = i40e_macaddr_remove,
497 : : .reta_update = i40e_dev_rss_reta_update,
498 : : .reta_query = i40e_dev_rss_reta_query,
499 : : .rss_hash_update = i40e_dev_rss_hash_update,
500 : : .rss_hash_conf_get = i40e_dev_rss_hash_conf_get,
501 : : .udp_tunnel_port_add = i40e_dev_udp_tunnel_port_add,
502 : : .udp_tunnel_port_del = i40e_dev_udp_tunnel_port_del,
503 : : .flow_ops_get = i40e_dev_flow_ops_get,
504 : : .rxq_info_get = i40e_rxq_info_get,
505 : : .txq_info_get = i40e_txq_info_get,
506 : : .recycle_rxq_info_get = i40e_recycle_rxq_info_get,
507 : : .rx_burst_mode_get = i40e_rx_burst_mode_get,
508 : : .tx_burst_mode_get = i40e_tx_burst_mode_get,
509 : : .timesync_enable = i40e_timesync_enable,
510 : : .timesync_disable = i40e_timesync_disable,
511 : : .timesync_read_rx_timestamp = i40e_timesync_read_rx_timestamp,
512 : : .timesync_read_tx_timestamp = i40e_timesync_read_tx_timestamp,
513 : : .get_dcb_info = i40e_dev_get_dcb_info,
514 : : .timesync_adjust_time = i40e_timesync_adjust_time,
515 : : .timesync_read_time = i40e_timesync_read_time,
516 : : .timesync_write_time = i40e_timesync_write_time,
517 : : .get_reg = i40e_get_regs,
518 : : .get_eeprom_length = i40e_get_eeprom_length,
519 : : .get_eeprom = i40e_get_eeprom,
520 : : .get_module_info = i40e_get_module_info,
521 : : .get_module_eeprom = i40e_get_module_eeprom,
522 : : .mac_addr_set = i40e_set_default_mac_addr,
523 : : .mtu_set = i40e_dev_mtu_set,
524 : : .tm_ops_get = i40e_tm_ops_get,
525 : : .tx_done_cleanup = i40e_tx_done_cleanup,
526 : : .get_monitor_addr = i40e_get_monitor_addr,
527 : : .fec_get_capability = i40e_fec_get_capability,
528 : : .fec_get = i40e_fec_get,
529 : : .fec_set = i40e_fec_set,
530 : : };
531 : :
532 : : /* store statistics names and its offset in stats structure */
533 : : struct rte_i40e_xstats_name_off {
534 : : char name[RTE_ETH_XSTATS_NAME_SIZE];
535 : : int offset;
536 : : };
537 : :
538 : : static const struct rte_i40e_xstats_name_off rte_i40e_stats_strings[] = {
539 : : {"rx_unicast_packets", offsetof(struct i40e_eth_stats, rx_unicast)},
540 : : {"rx_multicast_packets", offsetof(struct i40e_eth_stats, rx_multicast)},
541 : : {"rx_broadcast_packets", offsetof(struct i40e_eth_stats, rx_broadcast)},
542 : : {"rx_dropped_packets", offsetof(struct i40e_eth_stats, rx_discards)},
543 : : {"rx_unknown_protocol_packets", offsetof(struct i40e_eth_stats,
544 : : rx_unknown_protocol)},
545 : : /*
546 : : * all other offsets are against i40e_eth_stats which is first member
547 : : * in i40e_hw_port_stats, so these offsets are interchangeable
548 : : */
549 : : {"rx_size_error_packets", offsetof(struct i40e_hw_port_stats, rx_err1)},
550 : : {"tx_unicast_packets", offsetof(struct i40e_eth_stats, tx_unicast)},
551 : : {"tx_multicast_packets", offsetof(struct i40e_eth_stats, tx_multicast)},
552 : : {"tx_broadcast_packets", offsetof(struct i40e_eth_stats, tx_broadcast)},
553 : : {"tx_dropped_packets", offsetof(struct i40e_eth_stats, tx_discards)},
554 : : };
555 : :
556 : : #define I40E_NB_ETH_XSTATS (sizeof(rte_i40e_stats_strings) / \
557 : : sizeof(rte_i40e_stats_strings[0]))
558 : :
559 : : static const struct rte_i40e_xstats_name_off i40e_mbuf_strings[] = {
560 : : {"tx_mbuf_error_packets", offsetof(struct i40e_mbuf_stats, tx_pkt_errors)},
561 : : };
562 : :
563 : : #define I40E_NB_MBUF_XSTATS (sizeof(i40e_mbuf_strings) / sizeof(i40e_mbuf_strings[0]))
564 : :
565 : : static const struct rte_i40e_xstats_name_off rte_i40e_hw_port_strings[] = {
566 : : {"tx_link_down_dropped", offsetof(struct i40e_hw_port_stats,
567 : : tx_dropped_link_down)},
568 : : {"rx_crc_errors", offsetof(struct i40e_hw_port_stats, crc_errors)},
569 : : {"rx_illegal_byte_errors", offsetof(struct i40e_hw_port_stats,
570 : : illegal_bytes)},
571 : : {"rx_error_bytes", offsetof(struct i40e_hw_port_stats, error_bytes)},
572 : : {"mac_local_errors", offsetof(struct i40e_hw_port_stats,
573 : : mac_local_faults)},
574 : : {"mac_remote_errors", offsetof(struct i40e_hw_port_stats,
575 : : mac_remote_faults)},
576 : : {"rx_length_errors", offsetof(struct i40e_hw_port_stats,
577 : : rx_length_errors)},
578 : : {"tx_xon_packets", offsetof(struct i40e_hw_port_stats, link_xon_tx)},
579 : : {"rx_xon_packets", offsetof(struct i40e_hw_port_stats, link_xon_rx)},
580 : : {"tx_xoff_packets", offsetof(struct i40e_hw_port_stats, link_xoff_tx)},
581 : : {"rx_xoff_packets", offsetof(struct i40e_hw_port_stats, link_xoff_rx)},
582 : : {"rx_size_64_packets", offsetof(struct i40e_hw_port_stats, rx_size_64)},
583 : : {"rx_size_65_to_127_packets", offsetof(struct i40e_hw_port_stats,
584 : : rx_size_127)},
585 : : {"rx_size_128_to_255_packets", offsetof(struct i40e_hw_port_stats,
586 : : rx_size_255)},
587 : : {"rx_size_256_to_511_packets", offsetof(struct i40e_hw_port_stats,
588 : : rx_size_511)},
589 : : {"rx_size_512_to_1023_packets", offsetof(struct i40e_hw_port_stats,
590 : : rx_size_1023)},
591 : : {"rx_size_1024_to_1522_packets", offsetof(struct i40e_hw_port_stats,
592 : : rx_size_1522)},
593 : : {"rx_size_1523_to_max_packets", offsetof(struct i40e_hw_port_stats,
594 : : rx_size_big)},
595 : : {"rx_undersized_errors", offsetof(struct i40e_hw_port_stats,
596 : : rx_undersize)},
597 : : {"rx_oversize_errors", offsetof(struct i40e_hw_port_stats,
598 : : rx_oversize)},
599 : : {"rx_mac_short_dropped", offsetof(struct i40e_hw_port_stats,
600 : : mac_short_packet_dropped)},
601 : : {"rx_fragmented_errors", offsetof(struct i40e_hw_port_stats,
602 : : rx_fragments)},
603 : : {"rx_jabber_errors", offsetof(struct i40e_hw_port_stats, rx_jabber)},
604 : : {"tx_size_64_packets", offsetof(struct i40e_hw_port_stats, tx_size_64)},
605 : : {"tx_size_65_to_127_packets", offsetof(struct i40e_hw_port_stats,
606 : : tx_size_127)},
607 : : {"tx_size_128_to_255_packets", offsetof(struct i40e_hw_port_stats,
608 : : tx_size_255)},
609 : : {"tx_size_256_to_511_packets", offsetof(struct i40e_hw_port_stats,
610 : : tx_size_511)},
611 : : {"tx_size_512_to_1023_packets", offsetof(struct i40e_hw_port_stats,
612 : : tx_size_1023)},
613 : : {"tx_size_1024_to_1522_packets", offsetof(struct i40e_hw_port_stats,
614 : : tx_size_1522)},
615 : : {"tx_size_1523_to_max_packets", offsetof(struct i40e_hw_port_stats,
616 : : tx_size_big)},
617 : : {"rx_flow_director_atr_match_packets",
618 : : offsetof(struct i40e_hw_port_stats, fd_atr_match)},
619 : : {"rx_flow_director_sb_match_packets",
620 : : offsetof(struct i40e_hw_port_stats, fd_sb_match)},
621 : : {"tx_low_power_idle_status", offsetof(struct i40e_hw_port_stats,
622 : : tx_lpi_status)},
623 : : {"rx_low_power_idle_status", offsetof(struct i40e_hw_port_stats,
624 : : rx_lpi_status)},
625 : : {"tx_low_power_idle_count", offsetof(struct i40e_hw_port_stats,
626 : : tx_lpi_count)},
627 : : {"rx_low_power_idle_count", offsetof(struct i40e_hw_port_stats,
628 : : rx_lpi_count)},
629 : : };
630 : :
631 : : #define I40E_NB_HW_PORT_XSTATS (sizeof(rte_i40e_hw_port_strings) / \
632 : : sizeof(rte_i40e_hw_port_strings[0]))
633 : :
634 : : static const struct rte_i40e_xstats_name_off rte_i40e_rxq_prio_strings[] = {
635 : : {"xon_packets", offsetof(struct i40e_hw_port_stats,
636 : : priority_xon_rx)},
637 : : {"xoff_packets", offsetof(struct i40e_hw_port_stats,
638 : : priority_xoff_rx)},
639 : : };
640 : :
641 : : #define I40E_NB_RXQ_PRIO_XSTATS (sizeof(rte_i40e_rxq_prio_strings) / \
642 : : sizeof(rte_i40e_rxq_prio_strings[0]))
643 : :
644 : : static const struct rte_i40e_xstats_name_off rte_i40e_txq_prio_strings[] = {
645 : : {"xon_packets", offsetof(struct i40e_hw_port_stats,
646 : : priority_xon_tx)},
647 : : {"xoff_packets", offsetof(struct i40e_hw_port_stats,
648 : : priority_xoff_tx)},
649 : : {"xon_to_xoff_packets", offsetof(struct i40e_hw_port_stats,
650 : : priority_xon_2_xoff)},
651 : : };
652 : :
653 : : #define I40E_NB_TXQ_PRIO_XSTATS (sizeof(rte_i40e_txq_prio_strings) / \
654 : : sizeof(rte_i40e_txq_prio_strings[0]))
655 : :
656 : : static int
657 : 0 : eth_i40e_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
658 : : struct rte_pci_device *pci_dev)
659 : : {
660 : : char name[RTE_ETH_NAME_MAX_LEN];
661 : 0 : struct rte_eth_devargs eth_da = { .nb_representor_ports = 0 };
662 : : int i, retval;
663 : :
664 [ # # ]: 0 : if (pci_dev->device.devargs) {
665 : 0 : retval = rte_eth_devargs_parse(pci_dev->device.devargs->args,
666 : : ð_da, 1);
667 [ # # ]: 0 : if (retval < 0)
668 : : return retval;
669 : : }
670 : :
671 [ # # ]: 0 : if (eth_da.nb_representor_ports > 0 &&
672 [ # # ]: 0 : eth_da.type != RTE_ETH_REPRESENTOR_VF) {
673 : 0 : PMD_DRV_LOG(ERR, "unsupported representor type: %s",
674 : : pci_dev->device.devargs->args);
675 : 0 : return -ENOTSUP;
676 : : }
677 : :
678 : 0 : retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
679 : : sizeof(struct i40e_adapter),
680 : : eth_dev_pci_specific_init, pci_dev,
681 : : eth_i40e_dev_init, NULL);
682 : :
683 [ # # # # ]: 0 : if (retval || eth_da.nb_representor_ports < 1)
684 : : return retval;
685 : :
686 : : /* probe VF representor ports */
687 : 0 : struct rte_eth_dev *pf_ethdev = rte_eth_dev_allocated(
688 : : pci_dev->device.name);
689 : :
690 [ # # ]: 0 : if (pf_ethdev == NULL)
691 : : return -ENODEV;
692 : :
693 [ # # ]: 0 : for (i = 0; i < eth_da.nb_representor_ports; i++) {
694 : 0 : struct i40e_vf_representor representor = {
695 : 0 : .vf_id = eth_da.representor_ports[i],
696 : 0 : .switch_domain_id = I40E_DEV_PRIVATE_TO_PF(
697 : 0 : pf_ethdev->data->dev_private)->switch_domain_id,
698 : : .adapter = I40E_DEV_PRIVATE_TO_ADAPTER(
699 : : pf_ethdev->data->dev_private)
700 : : };
701 : :
702 : : /* representor port net_bdf_port */
703 : 0 : snprintf(name, sizeof(name), "net_%s_representor_%d",
704 : : pci_dev->device.name, eth_da.representor_ports[i]);
705 : :
706 : 0 : retval = rte_eth_dev_create(&pci_dev->device, name,
707 : : sizeof(struct i40e_vf_representor), NULL, NULL,
708 : : i40e_vf_representor_init, &representor);
709 : :
710 [ # # ]: 0 : if (retval)
711 : 0 : PMD_DRV_LOG(ERR, "failed to create i40e vf "
712 : : "representor %s.", name);
713 : : }
714 : :
715 : : return 0;
716 : : }
717 : :
718 : 0 : static int eth_i40e_pci_remove(struct rte_pci_device *pci_dev)
719 : : {
720 : : struct rte_eth_dev *ethdev;
721 : :
722 : 0 : ethdev = rte_eth_dev_allocated(pci_dev->device.name);
723 [ # # ]: 0 : if (!ethdev)
724 : : return 0;
725 : :
726 [ # # ]: 0 : if (rte_eth_dev_is_repr(ethdev))
727 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev,
728 : : i40e_vf_representor_uninit);
729 : : else
730 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev,
731 : : eth_i40e_dev_uninit);
732 : : }
733 : :
734 : : static struct rte_pci_driver rte_i40e_pmd = {
735 : : .id_table = pci_id_i40e_map,
736 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
737 : : .probe = eth_i40e_pci_probe,
738 : : .remove = eth_i40e_pci_remove,
739 : : };
740 : :
741 : : static inline void
742 : 0 : i40e_write_global_rx_ctl(struct i40e_hw *hw, uint32_t reg_addr,
743 : : uint32_t reg_val)
744 : : {
745 : : uint32_t ori_reg_val;
746 : 0 : struct rte_eth_dev_data *dev_data =
747 : 0 : ((struct i40e_adapter *)hw->back)->pf.dev_data;
748 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[dev_data->port_id];
749 : :
750 : 0 : ori_reg_val = i40e_read_rx_ctl(hw, reg_addr);
751 : 0 : i40e_write_rx_ctl(hw, reg_addr, reg_val);
752 [ # # ]: 0 : if (ori_reg_val != reg_val)
753 : 0 : PMD_DRV_LOG(INFO,
754 : : "i40e device %s changed global register [0x%08x]."
755 : : " original: 0x%08x, new: 0x%08x",
756 : : dev->device->name, reg_addr, ori_reg_val, reg_val);
757 : 0 : }
758 : :
759 : 301 : RTE_PMD_REGISTER_PCI(net_i40e, rte_i40e_pmd);
760 : : RTE_PMD_REGISTER_PCI_TABLE(net_i40e, pci_id_i40e_map);
761 : : RTE_PMD_REGISTER_KMOD_DEP(net_i40e, "* igb_uio | uio_pci_generic | vfio-pci");
762 : :
763 : : #ifndef I40E_GLQF_ORT
764 : : #define I40E_GLQF_ORT(_i) (0x00268900 + ((_i) * 4))
765 : : #endif
766 : : #ifndef I40E_GLQF_PIT
767 : : #define I40E_GLQF_PIT(_i) (0x00268C80 + ((_i) * 4))
768 : : #endif
769 : : #ifndef I40E_GLQF_L3_MAP
770 : : #define I40E_GLQF_L3_MAP(_i) (0x0026C700 + ((_i) * 4))
771 : : #endif
772 : :
773 : 0 : static inline void i40e_GLQF_reg_init(struct i40e_hw *hw)
774 : : {
775 : : /*
776 : : * Initialize registers for parsing packet type of QinQ
777 : : * This should be removed from code once proper
778 : : * configuration API is added to avoid configuration conflicts
779 : : * between ports of the same device.
780 : : */
781 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(40), 0x00000029);
782 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_PIT(9), 0x00009420);
783 : 0 : }
784 : :
785 : : static inline void i40e_config_automask(struct i40e_pf *pf)
786 : : {
787 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
788 : : uint32_t val;
789 : :
790 : : /* INTENA flag is not auto-cleared for interrupt */
791 : 0 : val = I40E_READ_REG(hw, I40E_GLINT_CTL);
792 : 0 : val |= I40E_GLINT_CTL_DIS_AUTOMASK_PF0_MASK |
793 : : I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK;
794 : :
795 : : /* If support multi-driver, PF will use INT0. */
796 [ # # ]: 0 : if (!pf->support_multi_driver)
797 : 0 : val |= I40E_GLINT_CTL_DIS_AUTOMASK_N_MASK;
798 : :
799 : 0 : I40E_WRITE_REG(hw, I40E_GLINT_CTL, val);
800 : : }
801 : :
802 : : static inline void i40e_clear_automask(struct i40e_pf *pf)
803 : : {
804 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
805 : : uint32_t val;
806 : :
807 : 0 : val = I40E_READ_REG(hw, I40E_GLINT_CTL);
808 : 0 : val &= ~(I40E_GLINT_CTL_DIS_AUTOMASK_PF0_MASK |
809 : : I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK);
810 : :
811 [ # # ]: 0 : if (!pf->support_multi_driver)
812 : 0 : val &= ~I40E_GLINT_CTL_DIS_AUTOMASK_N_MASK;
813 : :
814 : 0 : I40E_WRITE_REG(hw, I40E_GLINT_CTL, val);
815 : : }
816 : :
817 : : #define I40E_FLOW_CONTROL_ETHERTYPE 0x8808
818 : :
819 : : /*
820 : : * Add a ethertype filter to drop all flow control frames transmitted
821 : : * from VSIs.
822 : : */
823 : : static void
824 : 0 : i40e_add_tx_flow_control_drop_filter(struct i40e_pf *pf)
825 : : {
826 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
827 : : uint16_t flags = I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC |
828 : : I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP |
829 : : I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TX;
830 : : int ret;
831 : :
832 : 0 : ret = i40e_aq_add_rem_control_packet_filter(hw, NULL,
833 : : I40E_FLOW_CONTROL_ETHERTYPE, flags,
834 : 0 : pf->main_vsi_seid, 0,
835 : : TRUE, NULL, NULL);
836 [ # # ]: 0 : if (ret)
837 : 0 : PMD_INIT_LOG(ERR,
838 : : "Failed to add filter to drop flow control frames from VSIs.");
839 : 0 : }
840 : :
841 : : static int
842 : 0 : floating_veb_list_handler(__rte_unused const char *key,
843 : : const char *floating_veb_value,
844 : : void *opaque)
845 : : {
846 : : int idx = 0;
847 : : unsigned int count = 0;
848 : 0 : char *end = NULL;
849 : : int min, max;
850 : : bool *vf_floating_veb = opaque;
851 : :
852 [ # # ]: 0 : while (isblank(*floating_veb_value))
853 : 0 : floating_veb_value++;
854 : :
855 : : /* Reset floating VEB configuration for VFs */
856 [ # # ]: 0 : for (idx = 0; idx < I40E_MAX_VF; idx++)
857 : 0 : vf_floating_veb[idx] = false;
858 : :
859 : : min = I40E_MAX_VF;
860 : : do {
861 [ # # ]: 0 : while (isblank(*floating_veb_value))
862 : 0 : floating_veb_value++;
863 [ # # ]: 0 : if (*floating_veb_value == '\0')
864 : : return -1;
865 : 0 : errno = 0;
866 : 0 : idx = strtoul(floating_veb_value, &end, 10);
867 [ # # # # ]: 0 : if (errno || end == NULL)
868 : : return -1;
869 [ # # ]: 0 : if (idx < 0)
870 : : return -1;
871 [ # # ]: 0 : while (isblank(*end))
872 : 0 : end++;
873 [ # # ]: 0 : if (*end == '-') {
874 : : min = idx;
875 [ # # ]: 0 : } else if ((*end == ';') || (*end == '\0')) {
876 : : max = idx;
877 [ # # ]: 0 : if (min == I40E_MAX_VF)
878 : : min = idx;
879 : : if (max >= I40E_MAX_VF)
880 : : max = I40E_MAX_VF - 1;
881 [ # # ]: 0 : for (idx = min; idx <= max; idx++) {
882 : 0 : vf_floating_veb[idx] = true;
883 : 0 : count++;
884 : : }
885 : : min = I40E_MAX_VF;
886 : : } else {
887 : : return -1;
888 : : }
889 : 0 : floating_veb_value = end + 1;
890 [ # # ]: 0 : } while (*end != '\0');
891 : :
892 [ # # ]: 0 : if (count == 0)
893 : 0 : return -1;
894 : :
895 : : return 0;
896 : : }
897 : :
898 : : static void
899 : 0 : config_vf_floating_veb(struct rte_devargs *devargs,
900 : : uint16_t floating_veb,
901 : : bool *vf_floating_veb)
902 : : {
903 : : struct rte_kvargs *kvlist;
904 : : int i;
905 : : const char *floating_veb_list = ETH_I40E_FLOATING_VEB_LIST_ARG;
906 : :
907 [ # # ]: 0 : if (!floating_veb)
908 : : return;
909 : : /* All the VFs attach to the floating VEB by default
910 : : * when the floating VEB is enabled.
911 : : */
912 [ # # ]: 0 : for (i = 0; i < I40E_MAX_VF; i++)
913 : 0 : vf_floating_veb[i] = true;
914 : :
915 [ # # ]: 0 : if (devargs == NULL)
916 : : return;
917 : :
918 : 0 : kvlist = rte_kvargs_parse(devargs->args, valid_keys);
919 [ # # ]: 0 : if (kvlist == NULL)
920 : : return;
921 : :
922 [ # # ]: 0 : if (!rte_kvargs_count(kvlist, floating_veb_list)) {
923 : 0 : rte_kvargs_free(kvlist);
924 : 0 : return;
925 : : }
926 : : /* When the floating_veb_list parameter exists, all the VFs
927 : : * will attach to the legacy VEB firstly, then configure VFs
928 : : * to the floating VEB according to the floating_veb_list.
929 : : */
930 [ # # ]: 0 : if (rte_kvargs_process(kvlist, floating_veb_list,
931 : : floating_veb_list_handler,
932 : : vf_floating_veb) < 0) {
933 : 0 : rte_kvargs_free(kvlist);
934 : 0 : return;
935 : : }
936 : 0 : rte_kvargs_free(kvlist);
937 : : }
938 : :
939 : : static int
940 : 0 : i40e_check_floating_handler(__rte_unused const char *key,
941 : : const char *value,
942 : : __rte_unused void *opaque)
943 : : {
944 [ # # ]: 0 : if (strcmp(value, "1"))
945 : 0 : return -1;
946 : :
947 : : return 0;
948 : : }
949 : :
950 : : static int
951 : 0 : is_floating_veb_supported(struct rte_devargs *devargs)
952 : : {
953 : : struct rte_kvargs *kvlist;
954 : : const char *floating_veb_key = ETH_I40E_FLOATING_VEB_ARG;
955 : :
956 [ # # ]: 0 : if (devargs == NULL)
957 : : return 0;
958 : :
959 : 0 : kvlist = rte_kvargs_parse(devargs->args, valid_keys);
960 [ # # ]: 0 : if (kvlist == NULL)
961 : : return 0;
962 : :
963 [ # # ]: 0 : if (!rte_kvargs_count(kvlist, floating_veb_key)) {
964 : 0 : rte_kvargs_free(kvlist);
965 : 0 : return 0;
966 : : }
967 : : /* Floating VEB is enabled when there's key-value:
968 : : * enable_floating_veb=1
969 : : */
970 [ # # ]: 0 : if (rte_kvargs_process(kvlist, floating_veb_key,
971 : : i40e_check_floating_handler, NULL) < 0) {
972 : 0 : rte_kvargs_free(kvlist);
973 : 0 : return 0;
974 : : }
975 : 0 : rte_kvargs_free(kvlist);
976 : :
977 : 0 : return 1;
978 : : }
979 : :
980 : : static void
981 : 0 : config_floating_veb(struct rte_eth_dev *dev)
982 : : {
983 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
984 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
985 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
986 : :
987 [ # # ]: 0 : memset(pf->floating_veb_list, 0, sizeof(pf->floating_veb_list));
988 : :
989 [ # # ]: 0 : if (hw->aq.fw_maj_ver >= FLOATING_VEB_SUPPORTED_FW_MAJ) {
990 : 0 : pf->floating_veb =
991 : 0 : is_floating_veb_supported(pci_dev->device.devargs);
992 : 0 : config_vf_floating_veb(pci_dev->device.devargs,
993 : : pf->floating_veb,
994 : : pf->floating_veb_list);
995 : : } else {
996 : 0 : pf->floating_veb = false;
997 : : }
998 : 0 : }
999 : :
1000 : : #define I40E_L2_TAGS_S_TAG_SHIFT 1
1001 : : #define I40E_L2_TAGS_S_TAG_MASK I40E_MASK(0x1, I40E_L2_TAGS_S_TAG_SHIFT)
1002 : :
1003 : : static int
1004 : 0 : i40e_init_ethtype_filter_list(struct rte_eth_dev *dev)
1005 : : {
1006 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1007 : : struct i40e_ethertype_rule *ethertype_rule = &pf->ethertype;
1008 : : char ethertype_hash_name[RTE_HASH_NAMESIZE];
1009 : : int ret;
1010 : :
1011 : 0 : struct rte_hash_parameters ethertype_hash_params = {
1012 : : .name = ethertype_hash_name,
1013 : : .entries = I40E_MAX_ETHERTYPE_FILTER_NUM,
1014 : : .key_len = sizeof(struct i40e_ethertype_filter_input),
1015 : : .hash_func = rte_hash_crc,
1016 : : .hash_func_init_val = 0,
1017 : 0 : .socket_id = rte_socket_id(),
1018 : : };
1019 : :
1020 : : /* Initialize ethertype filter rule list and hash */
1021 : 0 : TAILQ_INIT(ðertype_rule->ethertype_list);
1022 : 0 : snprintf(ethertype_hash_name, RTE_HASH_NAMESIZE,
1023 : 0 : "ethertype_%s", dev->device->name);
1024 : 0 : ethertype_rule->hash_table = rte_hash_create(ðertype_hash_params);
1025 [ # # ]: 0 : if (!ethertype_rule->hash_table) {
1026 : 0 : PMD_INIT_LOG(ERR, "Failed to create ethertype hash table!");
1027 : 0 : return -EINVAL;
1028 : : }
1029 : 0 : ethertype_rule->hash_map = rte_zmalloc("i40e_ethertype_hash_map",
1030 : : sizeof(struct i40e_ethertype_filter *) *
1031 : : I40E_MAX_ETHERTYPE_FILTER_NUM,
1032 : : 0);
1033 [ # # ]: 0 : if (!ethertype_rule->hash_map) {
1034 : 0 : PMD_INIT_LOG(ERR,
1035 : : "Failed to allocate memory for ethertype hash map!");
1036 : : ret = -ENOMEM;
1037 : 0 : goto err_ethertype_hash_map_alloc;
1038 : : }
1039 : :
1040 : : return 0;
1041 : :
1042 : : err_ethertype_hash_map_alloc:
1043 : 0 : rte_hash_free(ethertype_rule->hash_table);
1044 : :
1045 : 0 : return ret;
1046 : : }
1047 : :
1048 : : static int
1049 : 0 : i40e_init_tunnel_filter_list(struct rte_eth_dev *dev)
1050 : : {
1051 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1052 : : struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
1053 : : char tunnel_hash_name[RTE_HASH_NAMESIZE];
1054 : : int ret;
1055 : :
1056 : 0 : struct rte_hash_parameters tunnel_hash_params = {
1057 : : .name = tunnel_hash_name,
1058 : : .entries = I40E_MAX_TUNNEL_FILTER_NUM,
1059 : : .key_len = sizeof(struct i40e_tunnel_filter_input),
1060 : : .hash_func = rte_hash_crc,
1061 : : .hash_func_init_val = 0,
1062 : 0 : .socket_id = rte_socket_id(),
1063 : : };
1064 : :
1065 : : /* Initialize tunnel filter rule list and hash */
1066 : 0 : TAILQ_INIT(&tunnel_rule->tunnel_list);
1067 : 0 : snprintf(tunnel_hash_name, RTE_HASH_NAMESIZE,
1068 : 0 : "tunnel_%s", dev->device->name);
1069 : 0 : tunnel_rule->hash_table = rte_hash_create(&tunnel_hash_params);
1070 [ # # ]: 0 : if (!tunnel_rule->hash_table) {
1071 : 0 : PMD_INIT_LOG(ERR, "Failed to create tunnel hash table!");
1072 : 0 : return -EINVAL;
1073 : : }
1074 : 0 : tunnel_rule->hash_map = rte_zmalloc("i40e_tunnel_hash_map",
1075 : : sizeof(struct i40e_tunnel_filter *) *
1076 : : I40E_MAX_TUNNEL_FILTER_NUM,
1077 : : 0);
1078 [ # # ]: 0 : if (!tunnel_rule->hash_map) {
1079 : 0 : PMD_INIT_LOG(ERR,
1080 : : "Failed to allocate memory for tunnel hash map!");
1081 : : ret = -ENOMEM;
1082 : 0 : goto err_tunnel_hash_map_alloc;
1083 : : }
1084 : :
1085 : : return 0;
1086 : :
1087 : : err_tunnel_hash_map_alloc:
1088 : 0 : rte_hash_free(tunnel_rule->hash_table);
1089 : :
1090 : 0 : return ret;
1091 : : }
1092 : :
1093 : : static int
1094 : 0 : i40e_init_fdir_filter_list(struct rte_eth_dev *dev)
1095 : : {
1096 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1097 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1098 : : struct i40e_fdir_info *fdir_info = &pf->fdir;
1099 : : char fdir_hash_name[RTE_HASH_NAMESIZE];
1100 : 0 : uint32_t alloc = hw->func_caps.fd_filters_guaranteed;
1101 : 0 : uint32_t best = hw->func_caps.fd_filters_best_effort;
1102 : : enum i40e_filter_pctype pctype;
1103 : : struct rte_bitmap *bmp = NULL;
1104 : : uint32_t bmp_size;
1105 : : void *mem = NULL;
1106 : : uint32_t i = 0;
1107 : : int ret;
1108 : :
1109 : 0 : struct rte_hash_parameters fdir_hash_params = {
1110 : : .name = fdir_hash_name,
1111 : : .entries = I40E_MAX_FDIR_FILTER_NUM,
1112 : : .key_len = sizeof(struct i40e_fdir_input),
1113 : : .hash_func = rte_hash_crc,
1114 : : .hash_func_init_val = 0,
1115 : 0 : .socket_id = rte_socket_id(),
1116 : : };
1117 : :
1118 : : /* Initialize flow director filter rule list and hash */
1119 : 0 : TAILQ_INIT(&fdir_info->fdir_list);
1120 : 0 : snprintf(fdir_hash_name, RTE_HASH_NAMESIZE,
1121 : 0 : "fdir_%s", dev->device->name);
1122 : 0 : fdir_info->hash_table = rte_hash_create(&fdir_hash_params);
1123 [ # # ]: 0 : if (!fdir_info->hash_table) {
1124 : 0 : PMD_INIT_LOG(ERR, "Failed to create fdir hash table!");
1125 : 0 : return -EINVAL;
1126 : : }
1127 : :
1128 : 0 : fdir_info->hash_map = rte_zmalloc("i40e_fdir_hash_map",
1129 : : sizeof(struct i40e_fdir_filter *) *
1130 : : I40E_MAX_FDIR_FILTER_NUM,
1131 : : 0);
1132 [ # # ]: 0 : if (!fdir_info->hash_map) {
1133 : 0 : PMD_INIT_LOG(ERR,
1134 : : "Failed to allocate memory for fdir hash map!");
1135 : : ret = -ENOMEM;
1136 : 0 : goto err_fdir_hash_map_alloc;
1137 : : }
1138 : :
1139 : 0 : fdir_info->fdir_filter_array = rte_zmalloc("fdir_filter",
1140 : : sizeof(struct i40e_fdir_filter) *
1141 : : I40E_MAX_FDIR_FILTER_NUM,
1142 : : 0);
1143 : :
1144 [ # # ]: 0 : if (!fdir_info->fdir_filter_array) {
1145 : 0 : PMD_INIT_LOG(ERR,
1146 : : "Failed to allocate memory for fdir filter array!");
1147 : : ret = -ENOMEM;
1148 : 0 : goto err_fdir_filter_array_alloc;
1149 : : }
1150 : :
1151 : : for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
1152 [ # # ]: 0 : pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++)
1153 : 0 : pf->fdir.flow_count[pctype] = 0;
1154 : :
1155 : 0 : fdir_info->fdir_space_size = alloc + best;
1156 : 0 : fdir_info->fdir_actual_cnt = 0;
1157 : 0 : fdir_info->fdir_guarantee_total_space = alloc;
1158 : 0 : fdir_info->fdir_guarantee_free_space =
1159 : : fdir_info->fdir_guarantee_total_space;
1160 : :
1161 : 0 : PMD_DRV_LOG(INFO, "FDIR guarantee space: %u, best_effort space %u.", alloc, best);
1162 : :
1163 : 0 : fdir_info->fdir_flow_pool.pool =
1164 : 0 : rte_zmalloc("i40e_fdir_entry",
1165 : : sizeof(struct i40e_fdir_entry) *
1166 : 0 : fdir_info->fdir_space_size,
1167 : : 0);
1168 : :
1169 [ # # ]: 0 : if (!fdir_info->fdir_flow_pool.pool) {
1170 : 0 : PMD_INIT_LOG(ERR,
1171 : : "Failed to allocate memory for bitmap flow!");
1172 : : ret = -ENOMEM;
1173 : 0 : goto err_fdir_bitmap_flow_alloc;
1174 : : }
1175 : :
1176 [ # # ]: 0 : for (i = 0; i < fdir_info->fdir_space_size; i++)
1177 : 0 : fdir_info->fdir_flow_pool.pool[i].idx = i;
1178 : :
1179 : : bmp_size =
1180 : 0 : rte_bitmap_get_memory_footprint(fdir_info->fdir_space_size);
1181 : 0 : mem = rte_zmalloc("fdir_bmap", bmp_size, RTE_CACHE_LINE_SIZE);
1182 [ # # ]: 0 : if (mem == NULL) {
1183 : 0 : PMD_INIT_LOG(ERR,
1184 : : "Failed to allocate memory for fdir bitmap!");
1185 : : ret = -ENOMEM;
1186 : 0 : goto err_fdir_mem_alloc;
1187 : : }
1188 : 0 : bmp = rte_bitmap_init(fdir_info->fdir_space_size, mem, bmp_size);
1189 [ # # ]: 0 : if (bmp == NULL) {
1190 : 0 : PMD_INIT_LOG(ERR,
1191 : : "Failed to initialization fdir bitmap!");
1192 : : ret = -ENOMEM;
1193 : 0 : goto err_fdir_bmp_alloc;
1194 : : }
1195 [ # # ]: 0 : for (i = 0; i < fdir_info->fdir_space_size; i++)
1196 : 0 : rte_bitmap_set(bmp, i);
1197 : :
1198 : 0 : fdir_info->fdir_flow_pool.bitmap = bmp;
1199 : :
1200 : 0 : return 0;
1201 : :
1202 : : err_fdir_bmp_alloc:
1203 : 0 : rte_free(mem);
1204 : 0 : err_fdir_mem_alloc:
1205 : 0 : rte_free(fdir_info->fdir_flow_pool.pool);
1206 : 0 : err_fdir_bitmap_flow_alloc:
1207 : 0 : rte_free(fdir_info->fdir_filter_array);
1208 : 0 : err_fdir_filter_array_alloc:
1209 : 0 : rte_free(fdir_info->hash_map);
1210 : 0 : err_fdir_hash_map_alloc:
1211 : 0 : rte_hash_free(fdir_info->hash_table);
1212 : :
1213 : 0 : return ret;
1214 : : }
1215 : :
1216 : : static void
1217 : : i40e_init_customized_info(struct i40e_pf *pf)
1218 : : {
1219 : : int i;
1220 : :
1221 : : /* Initialize customized pctype */
1222 [ # # ]: 0 : for (i = I40E_CUSTOMIZED_GTPC; i < I40E_CUSTOMIZED_MAX; i++) {
1223 : 0 : pf->customized_pctype[i].index = i;
1224 : 0 : pf->customized_pctype[i].pctype = I40E_FILTER_PCTYPE_INVALID;
1225 : 0 : pf->customized_pctype[i].valid = false;
1226 : : }
1227 : :
1228 : 0 : pf->gtp_support = false;
1229 : 0 : pf->esp_support = false;
1230 : : }
1231 : :
1232 : : static void
1233 : 0 : i40e_init_filter_invalidation(struct i40e_pf *pf)
1234 : : {
1235 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
1236 : : struct i40e_fdir_info *fdir_info = &pf->fdir;
1237 : : uint32_t glqf_ctl_reg = 0;
1238 : :
1239 : 0 : glqf_ctl_reg = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
1240 [ # # ]: 0 : if (!pf->support_multi_driver) {
1241 : 0 : fdir_info->fdir_invalprio = 1;
1242 : 0 : glqf_ctl_reg |= I40E_GLQF_CTL_INVALPRIO_MASK;
1243 : 0 : PMD_DRV_LOG(INFO, "FDIR INVALPRIO set to guaranteed first");
1244 : 0 : i40e_write_rx_ctl(hw, I40E_GLQF_CTL, glqf_ctl_reg);
1245 : : } else {
1246 [ # # ]: 0 : if (glqf_ctl_reg & I40E_GLQF_CTL_INVALPRIO_MASK) {
1247 : 0 : fdir_info->fdir_invalprio = 1;
1248 : 0 : PMD_DRV_LOG(INFO, "FDIR INVALPRIO is: guaranteed first");
1249 : : } else {
1250 : 0 : fdir_info->fdir_invalprio = 0;
1251 : 0 : PMD_DRV_LOG(INFO, "FDIR INVALPRIO is: shared first");
1252 : : }
1253 : : }
1254 : 0 : }
1255 : :
1256 : : void
1257 : 0 : i40e_init_queue_region_conf(struct rte_eth_dev *dev)
1258 : : {
1259 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1260 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1261 : 0 : struct i40e_queue_regions *info = &pf->queue_region;
1262 : : uint16_t i;
1263 : :
1264 [ # # ]: 0 : for (i = 0; i < I40E_PFQF_HREGION_MAX_INDEX; i++)
1265 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HREGION(i), 0);
1266 : :
1267 : : memset(info, 0, sizeof(struct i40e_queue_regions));
1268 : 0 : }
1269 : :
1270 : : static int
1271 : 0 : i40e_parse_multi_drv_handler(__rte_unused const char *key,
1272 : : const char *value,
1273 : : void *opaque)
1274 : : {
1275 : : struct i40e_pf *pf;
1276 : : unsigned long support_multi_driver;
1277 : : char *end;
1278 : :
1279 : : pf = (struct i40e_pf *)opaque;
1280 : :
1281 : 0 : errno = 0;
1282 : 0 : support_multi_driver = strtoul(value, &end, 10);
1283 [ # # # # : 0 : if (errno != 0 || end == value || *end != 0) {
# # ]
1284 : 0 : PMD_DRV_LOG(WARNING, "Wrong global configuration");
1285 : 0 : return -(EINVAL);
1286 : : }
1287 : :
1288 [ # # ]: 0 : if (support_multi_driver == 1 || support_multi_driver == 0)
1289 : 0 : pf->support_multi_driver = (bool)support_multi_driver;
1290 : : else
1291 : 0 : PMD_DRV_LOG(WARNING, "%s must be 1 or 0,",
1292 : : "enable global configuration by default."
1293 : : ETH_I40E_SUPPORT_MULTI_DRIVER);
1294 : : return 0;
1295 : : }
1296 : :
1297 : : static int
1298 : 0 : i40e_support_multi_driver(struct rte_eth_dev *dev)
1299 : : {
1300 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1301 : : struct rte_kvargs *kvlist;
1302 : : int kvargs_count;
1303 : :
1304 : : /* Enable global configuration by default */
1305 : 0 : pf->support_multi_driver = false;
1306 : :
1307 [ # # ]: 0 : if (!dev->device->devargs)
1308 : : return 0;
1309 : :
1310 : 0 : kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
1311 [ # # ]: 0 : if (!kvlist)
1312 : : return -EINVAL;
1313 : :
1314 : 0 : kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_SUPPORT_MULTI_DRIVER);
1315 [ # # ]: 0 : if (!kvargs_count) {
1316 : 0 : rte_kvargs_free(kvlist);
1317 : 0 : return 0;
1318 : : }
1319 : :
1320 [ # # ]: 0 : if (kvargs_count > 1)
1321 : 0 : PMD_DRV_LOG(WARNING, "More than one argument \"%s\" and only "
1322 : : "the first invalid or last valid one is used !",
1323 : : ETH_I40E_SUPPORT_MULTI_DRIVER);
1324 : :
1325 [ # # ]: 0 : if (rte_kvargs_process(kvlist, ETH_I40E_SUPPORT_MULTI_DRIVER,
1326 : : i40e_parse_multi_drv_handler, pf) < 0) {
1327 : 0 : rte_kvargs_free(kvlist);
1328 : 0 : return -EINVAL;
1329 : : }
1330 : :
1331 : 0 : rte_kvargs_free(kvlist);
1332 : 0 : return 0;
1333 : : }
1334 : :
1335 : : static int
1336 : 0 : i40e_aq_debug_write_global_register(struct i40e_hw *hw,
1337 : : uint32_t reg_addr, uint64_t reg_val,
1338 : : struct i40e_asq_cmd_details *cmd_details)
1339 : : {
1340 : : uint64_t ori_reg_val;
1341 : 0 : struct rte_eth_dev_data *dev_data =
1342 : 0 : ((struct i40e_adapter *)hw->back)->pf.dev_data;
1343 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[dev_data->port_id];
1344 : : int ret;
1345 : :
1346 : 0 : ret = i40e_aq_debug_read_register(hw, reg_addr, &ori_reg_val, NULL);
1347 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1348 : 0 : PMD_DRV_LOG(ERR,
1349 : : "Fail to debug read from 0x%08x",
1350 : : reg_addr);
1351 : 0 : return -EIO;
1352 : : }
1353 : :
1354 [ # # ]: 0 : if (ori_reg_val != reg_val)
1355 : 0 : PMD_DRV_LOG(INFO,
1356 : : "i40e device %s changed global register [0x%08x]."
1357 : : " original: 0x%"PRIx64", after: 0x%"PRIx64,
1358 : : dev->device->name, reg_addr, ori_reg_val, reg_val);
1359 : :
1360 : 0 : return i40e_aq_debug_write_register(hw, reg_addr, reg_val, cmd_details);
1361 : : }
1362 : :
1363 : : static int
1364 : 0 : read_vf_msg_config(__rte_unused const char *key,
1365 : : const char *value,
1366 : : void *opaque)
1367 : : {
1368 : : struct i40e_vf_msg_cfg *cfg = opaque;
1369 : :
1370 [ # # ]: 0 : if (sscanf(value, "%u@%u:%u", &cfg->max_msg, &cfg->period,
1371 : : &cfg->ignore_second) != 3) {
1372 : : memset(cfg, 0, sizeof(*cfg));
1373 : 0 : PMD_DRV_LOG(ERR, "format error! example: "
1374 : : "%s=60@120:180", ETH_I40E_VF_MSG_CFG);
1375 : 0 : return -EINVAL;
1376 : : }
1377 : :
1378 : : /*
1379 : : * If the message validation function been enabled, the 'period'
1380 : : * and 'ignore_second' must greater than 0.
1381 : : */
1382 [ # # # # : 0 : if (cfg->max_msg && (!cfg->period || !cfg->ignore_second)) {
# # ]
1383 : : memset(cfg, 0, sizeof(*cfg));
1384 : 0 : PMD_DRV_LOG(ERR, "%s error! the second and third"
1385 : : " number must be greater than 0!",
1386 : : ETH_I40E_VF_MSG_CFG);
1387 : 0 : return -EINVAL;
1388 : : }
1389 : :
1390 : : return 0;
1391 : : }
1392 : :
1393 : : static int
1394 : 0 : read_mbuf_check_config(__rte_unused const char *key, const char *value, void *args)
1395 : : {
1396 : : char *cur;
1397 : : char *tmp;
1398 : : int str_len;
1399 : : int valid_len;
1400 : :
1401 : : int ret = 0;
1402 : : uint64_t *mc_flags = args;
1403 : 0 : char *str2 = strdup(value);
1404 [ # # ]: 0 : if (str2 == NULL)
1405 : : return -1;
1406 : :
1407 : 0 : str_len = strlen(str2);
1408 [ # # ]: 0 : if (str_len == 0) {
1409 : : ret = -1;
1410 : 0 : goto err_end;
1411 : : }
1412 : :
1413 : : /* Try stripping the outer square brackets of the parameter string. */
1414 : : str_len = strlen(str2);
1415 [ # # # # ]: 0 : if (str2[0] == '[' && str2[str_len - 1] == ']') {
1416 [ # # ]: 0 : if (str_len < 3) {
1417 : : ret = -1;
1418 : 0 : goto err_end;
1419 : : }
1420 : 0 : valid_len = str_len - 2;
1421 : 0 : memmove(str2, str2 + 1, valid_len);
1422 : 0 : memset(str2 + valid_len, '\0', 2);
1423 : : }
1424 : :
1425 : 0 : cur = strtok_r(str2, ",", &tmp);
1426 [ # # ]: 0 : while (cur != NULL) {
1427 [ # # ]: 0 : if (!strcmp(cur, "mbuf"))
1428 : 0 : *mc_flags |= I40E_MBUF_CHECK_F_TX_MBUF;
1429 [ # # ]: 0 : else if (!strcmp(cur, "size"))
1430 : 0 : *mc_flags |= I40E_MBUF_CHECK_F_TX_SIZE;
1431 [ # # ]: 0 : else if (!strcmp(cur, "segment"))
1432 : 0 : *mc_flags |= I40E_MBUF_CHECK_F_TX_SEGMENT;
1433 [ # # ]: 0 : else if (!strcmp(cur, "offload"))
1434 : 0 : *mc_flags |= I40E_MBUF_CHECK_F_TX_OFFLOAD;
1435 : : else
1436 : 0 : PMD_DRV_LOG(ERR, "Unsupported diagnostic type: %s", cur);
1437 : 0 : cur = strtok_r(NULL, ",", &tmp);
1438 : : }
1439 : :
1440 : 0 : err_end:
1441 : 0 : free(str2);
1442 : 0 : return ret;
1443 : : }
1444 : :
1445 : : static int
1446 : 0 : i40e_parse_mbuf_check(struct rte_eth_dev *dev)
1447 : : {
1448 : 0 : struct i40e_adapter *ad =
1449 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1450 : : struct rte_kvargs *kvlist;
1451 : : int kvargs_count;
1452 : : int ret = 0;
1453 : :
1454 [ # # ]: 0 : if (!dev->device->devargs)
1455 : : return ret;
1456 : :
1457 : 0 : kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
1458 [ # # ]: 0 : if (!kvlist)
1459 : : return -EINVAL;
1460 : :
1461 : 0 : kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_MBUF_CHECK_ARG);
1462 [ # # ]: 0 : if (!kvargs_count)
1463 : 0 : goto free_end;
1464 : :
1465 [ # # ]: 0 : if (kvargs_count > 1) {
1466 : 0 : PMD_DRV_LOG(ERR, "More than one argument \"%s\"!",
1467 : : ETH_I40E_MBUF_CHECK_ARG);
1468 : : ret = -EINVAL;
1469 : 0 : goto free_end;
1470 : : }
1471 : :
1472 [ # # ]: 0 : if (rte_kvargs_process(kvlist, ETH_I40E_MBUF_CHECK_ARG,
1473 : 0 : read_mbuf_check_config, &ad->mbuf_check) < 0)
1474 : : ret = -EINVAL;
1475 : :
1476 : 0 : free_end:
1477 : 0 : rte_kvargs_free(kvlist);
1478 : 0 : return ret;
1479 : : }
1480 : :
1481 : : static int
1482 [ # # ]: 0 : i40e_parse_vf_msg_config(struct rte_eth_dev *dev,
1483 : : struct i40e_vf_msg_cfg *msg_cfg)
1484 : : {
1485 : : struct rte_kvargs *kvlist;
1486 : : int kvargs_count;
1487 : : int ret = 0;
1488 : :
1489 : : memset(msg_cfg, 0, sizeof(*msg_cfg));
1490 : :
1491 [ # # ]: 0 : if (!dev->device->devargs)
1492 : : return ret;
1493 : :
1494 : 0 : kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
1495 [ # # ]: 0 : if (!kvlist)
1496 : : return -EINVAL;
1497 : :
1498 : 0 : kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_VF_MSG_CFG);
1499 [ # # ]: 0 : if (!kvargs_count)
1500 : 0 : goto free_end;
1501 : :
1502 [ # # ]: 0 : if (kvargs_count > 1) {
1503 : 0 : PMD_DRV_LOG(ERR, "More than one argument \"%s\"!",
1504 : : ETH_I40E_VF_MSG_CFG);
1505 : : ret = -EINVAL;
1506 : 0 : goto free_end;
1507 : : }
1508 : :
1509 [ # # ]: 0 : if (rte_kvargs_process(kvlist, ETH_I40E_VF_MSG_CFG,
1510 : : read_vf_msg_config, msg_cfg) < 0)
1511 : : ret = -EINVAL;
1512 : :
1513 : 0 : free_end:
1514 : 0 : rte_kvargs_free(kvlist);
1515 : 0 : return ret;
1516 : : }
1517 : :
1518 : : #define I40E_ALARM_INTERVAL 50000 /* us */
1519 : :
1520 : : static int
1521 : 0 : eth_i40e_dev_init(struct rte_eth_dev *dev, void *init_params __rte_unused)
1522 : : {
1523 : : struct rte_pci_device *pci_dev;
1524 : : struct rte_intr_handle *intr_handle;
1525 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1526 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1527 : : struct i40e_vsi *vsi;
1528 : : int ret;
1529 : : uint32_t len, val;
1530 : 0 : uint8_t aq_fail = 0;
1531 : :
1532 : 0 : PMD_INIT_FUNC_TRACE();
1533 : :
1534 : 0 : dev->dev_ops = &i40e_eth_dev_ops;
1535 : 0 : dev->rx_queue_count = i40e_dev_rx_queue_count;
1536 : 0 : dev->rx_descriptor_status = i40e_dev_rx_descriptor_status;
1537 : 0 : dev->tx_descriptor_status = i40e_dev_tx_descriptor_status;
1538 : 0 : dev->rx_pkt_burst = i40e_recv_pkts;
1539 : 0 : dev->tx_pkt_burst = i40e_xmit_pkts;
1540 : 0 : dev->tx_pkt_prepare = i40e_prep_pkts;
1541 : :
1542 : : /* for secondary processes, we don't initialise any further as primary
1543 : : * has already done this work. Only check we don't need a different
1544 : : * RX function */
1545 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY){
1546 : 0 : i40e_set_rx_function(dev);
1547 : 0 : i40e_set_tx_function(dev);
1548 : 0 : return 0;
1549 : : }
1550 : 0 : i40e_set_default_ptype_table(dev);
1551 : 0 : pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
1552 : 0 : intr_handle = pci_dev->intr_handle;
1553 : :
1554 : 0 : rte_eth_copy_pci_info(dev, pci_dev);
1555 : :
1556 : 0 : pf->adapter = I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1557 : 0 : pf->dev_data = dev->data;
1558 : :
1559 : 0 : hw->back = I40E_PF_TO_ADAPTER(pf);
1560 : 0 : hw->hw_addr = (uint8_t *)(pci_dev->mem_resource[0].addr);
1561 [ # # ]: 0 : if (!hw->hw_addr) {
1562 : 0 : PMD_INIT_LOG(ERR,
1563 : : "Hardware is not available, as address is NULL");
1564 : 0 : return -ENODEV;
1565 : : }
1566 : :
1567 : 0 : hw->vendor_id = pci_dev->id.vendor_id;
1568 : 0 : hw->device_id = pci_dev->id.device_id;
1569 : 0 : hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
1570 : 0 : hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
1571 : 0 : hw->bus.device = pci_dev->addr.devid;
1572 : 0 : hw->bus.func = pci_dev->addr.function;
1573 : 0 : hw->adapter_stopped = 0;
1574 : 0 : hw->adapter_closed = 0;
1575 : :
1576 : : /* Init switch device pointer */
1577 : 0 : hw->switch_dev = NULL;
1578 : :
1579 : : /*
1580 : : * Switch Tag value should not be identical to either the First Tag
1581 : : * or Second Tag values. So set something other than common Ethertype
1582 : : * for internal switching.
1583 : : */
1584 : 0 : hw->switch_tag = 0xffff;
1585 : :
1586 : : val = I40E_READ_REG(hw, I40E_GL_FWSTS);
1587 [ # # ]: 0 : if (val & I40E_GL_FWSTS_FWS1B_MASK) {
1588 : 0 : PMD_INIT_LOG(ERR, "ERROR: Firmware recovery mode detected. Limiting functionality.");
1589 : 0 : return -EIO;
1590 : : }
1591 : :
1592 : 0 : i40e_parse_vf_msg_config(dev, &pf->vf_msg_cfg);
1593 : 0 : i40e_parse_mbuf_check(dev);
1594 : : /* Check if need to support multi-driver */
1595 : 0 : i40e_support_multi_driver(dev);
1596 : :
1597 : : /* Make sure all is clean before doing PF reset */
1598 : 0 : i40e_clear_hw(hw);
1599 : :
1600 : : /* Reset here to make sure all is clean for each PF */
1601 : 0 : ret = i40e_pf_reset(hw);
1602 [ # # ]: 0 : if (ret) {
1603 : 0 : PMD_INIT_LOG(ERR, "Failed to reset pf: %d", ret);
1604 : 0 : return ret;
1605 : : }
1606 : :
1607 : : /* Initialize the shared code (base driver) */
1608 : 0 : ret = i40e_init_shared_code(hw);
1609 [ # # ]: 0 : if (ret) {
1610 : 0 : PMD_INIT_LOG(ERR, "Failed to init shared code (base driver): %d", ret);
1611 : 0 : return ret;
1612 : : }
1613 : :
1614 : : /* Initialize the parameters for adminq */
1615 : : i40e_init_adminq_parameter(hw);
1616 : 0 : ret = i40e_init_adminq(hw);
1617 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1618 : 0 : PMD_INIT_LOG(ERR, "Failed to init adminq: %d", ret);
1619 : 0 : return -EIO;
1620 : : }
1621 : : /* Firmware of SFP x722 does not support 802.1ad frames ability */
1622 [ # # ]: 0 : if (hw->device_id == I40E_DEV_ID_SFP_X722 ||
1623 : : hw->device_id == I40E_DEV_ID_SFP_I_X722)
1624 : 0 : hw->flags &= ~I40E_HW_FLAG_802_1AD_CAPABLE;
1625 : :
1626 : 0 : PMD_INIT_LOG(INFO, "FW %d.%d API %d.%d NVM %02d.%02d.%02d eetrack %04x",
1627 : : hw->aq.fw_maj_ver, hw->aq.fw_min_ver,
1628 : : hw->aq.api_maj_ver, hw->aq.api_min_ver,
1629 : : ((hw->nvm.version >> 12) & 0xf),
1630 : : ((hw->nvm.version >> 4) & 0xff),
1631 : : (hw->nvm.version & 0xf), hw->nvm.eetrack);
1632 : :
1633 : : /* Initialize the hardware */
1634 : 0 : i40e_hw_init(dev);
1635 : :
1636 : : i40e_config_automask(pf);
1637 : :
1638 : 0 : i40e_set_default_pctype_table(dev);
1639 : :
1640 : : /*
1641 : : * To work around the NVM issue, initialize registers
1642 : : * for packet type of QinQ by software.
1643 : : * It should be removed once issues are fixed in NVM.
1644 : : */
1645 [ # # ]: 0 : if (!pf->support_multi_driver)
1646 : 0 : i40e_GLQF_reg_init(hw);
1647 : :
1648 : : /* Initialize the input set for filters (hash and fd) to default value */
1649 : 0 : i40e_filter_input_set_init(pf);
1650 : :
1651 : : /* initialise the L3_MAP register */
1652 [ # # ]: 0 : if (!pf->support_multi_driver) {
1653 : 0 : ret = i40e_aq_debug_write_global_register(hw,
1654 : : I40E_GLQF_L3_MAP(40),
1655 : : 0x00000028, NULL);
1656 [ # # ]: 0 : if (ret)
1657 : 0 : PMD_INIT_LOG(ERR, "Failed to write L3 MAP register %d",
1658 : : ret);
1659 : 0 : PMD_INIT_LOG(DEBUG,
1660 : : "Global register 0x%08x is changed with 0x28",
1661 : : I40E_GLQF_L3_MAP(40));
1662 : : }
1663 : :
1664 : : /* Need the special FW version to support floating VEB */
1665 : 0 : config_floating_veb(dev);
1666 : : /* Clear PXE mode */
1667 : 0 : i40e_clear_pxe_mode(hw);
1668 : 0 : i40e_dev_sync_phy_type(hw);
1669 : :
1670 : : /*
1671 : : * On X710, performance number is far from the expectation on recent
1672 : : * firmware versions. The fix for this issue may not be integrated in
1673 : : * the following firmware version. So the workaround in software driver
1674 : : * is needed. It needs to modify the initial values of 3 internal only
1675 : : * registers. Note that the workaround can be removed when it is fixed
1676 : : * in firmware in the future.
1677 : : */
1678 : 0 : i40e_configure_registers(hw);
1679 : :
1680 : : /* Get hw capabilities */
1681 : 0 : ret = i40e_get_cap(hw);
1682 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1683 : 0 : PMD_INIT_LOG(ERR, "Failed to get capabilities: %d", ret);
1684 : 0 : goto err_get_capabilities;
1685 : : }
1686 : :
1687 : : /* Initialize parameters for PF */
1688 : 0 : ret = i40e_pf_parameter_init(dev);
1689 [ # # ]: 0 : if (ret != 0) {
1690 : 0 : PMD_INIT_LOG(ERR, "Failed to do parameter init: %d", ret);
1691 : 0 : goto err_parameter_init;
1692 : : }
1693 : :
1694 : : /* Initialize the queue management */
1695 : 0 : ret = i40e_res_pool_init(&pf->qp_pool, 0, hw->func_caps.num_tx_qp);
1696 [ # # ]: 0 : if (ret < 0) {
1697 : 0 : PMD_INIT_LOG(ERR, "Failed to init queue pool");
1698 : 0 : goto err_qp_pool_init;
1699 : : }
1700 : 0 : ret = i40e_res_pool_init(&pf->msix_pool, 1,
1701 : 0 : hw->func_caps.num_msix_vectors - 1);
1702 [ # # ]: 0 : if (ret < 0) {
1703 : 0 : PMD_INIT_LOG(ERR, "Failed to init MSIX pool");
1704 : 0 : goto err_msix_pool_init;
1705 : : }
1706 : :
1707 : : /* Initialize lan hmc */
1708 : 0 : ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
1709 : : hw->func_caps.num_rx_qp, 0, 0);
1710 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1711 : 0 : PMD_INIT_LOG(ERR, "Failed to init lan hmc: %d", ret);
1712 : 0 : goto err_init_lan_hmc;
1713 : : }
1714 : :
1715 : : /* Configure lan hmc */
1716 : 0 : ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
1717 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1718 : 0 : PMD_INIT_LOG(ERR, "Failed to configure lan hmc: %d", ret);
1719 : 0 : goto err_configure_lan_hmc;
1720 : : }
1721 : :
1722 : : /* Get and check the mac address */
1723 : 0 : i40e_get_mac_addr(hw, hw->mac.addr);
1724 [ # # ]: 0 : if (i40e_validate_mac_addr(hw->mac.addr) != I40E_SUCCESS) {
1725 : 0 : PMD_INIT_LOG(ERR, "mac address is not valid");
1726 : : ret = -EIO;
1727 : 0 : goto err_get_mac_addr;
1728 : : }
1729 : : /* Copy the permanent MAC address */
1730 : : rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
1731 : : (struct rte_ether_addr *)hw->mac.perm_addr);
1732 : :
1733 : : /* Disable flow control */
1734 : 0 : hw->fc.requested_mode = I40E_FC_NONE;
1735 : 0 : i40e_set_fc(hw, &aq_fail, TRUE);
1736 : :
1737 : : /* Set the global registers with default ether type value */
1738 [ # # ]: 0 : if (!pf->support_multi_driver) {
1739 : 0 : ret = i40e_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_OUTER,
1740 : : RTE_ETHER_TYPE_VLAN);
1741 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1742 : 0 : PMD_INIT_LOG(ERR,
1743 : : "Failed to set the default outer "
1744 : : "VLAN ether type");
1745 : 0 : goto err_setup_pf_switch;
1746 : : }
1747 : : }
1748 : :
1749 : : /* PF setup, which includes VSI setup */
1750 : 0 : ret = i40e_pf_setup(pf);
1751 [ # # ]: 0 : if (ret) {
1752 : 0 : PMD_INIT_LOG(ERR, "Failed to setup pf switch: %d", ret);
1753 : 0 : goto err_setup_pf_switch;
1754 : : }
1755 : :
1756 : 0 : vsi = pf->main_vsi;
1757 : :
1758 : : /* Disable double vlan by default */
1759 : : i40e_vsi_config_double_vlan(vsi, FALSE);
1760 : :
1761 : : /* Disable S-TAG identification when floating_veb is disabled */
1762 [ # # ]: 0 : if (!pf->floating_veb) {
1763 : 0 : ret = I40E_READ_REG(hw, I40E_PRT_L2TAGSEN);
1764 [ # # ]: 0 : if (ret & I40E_L2_TAGS_S_TAG_MASK) {
1765 : 0 : ret &= ~I40E_L2_TAGS_S_TAG_MASK;
1766 : 0 : I40E_WRITE_REG(hw, I40E_PRT_L2TAGSEN, ret);
1767 : : }
1768 : : }
1769 : :
1770 [ # # ]: 0 : if (!vsi->max_macaddrs)
1771 : : len = RTE_ETHER_ADDR_LEN;
1772 : : else
1773 : 0 : len = RTE_ETHER_ADDR_LEN * vsi->max_macaddrs;
1774 : :
1775 : : /* Should be after VSI initialized */
1776 : 0 : dev->data->mac_addrs = rte_zmalloc("i40e", len, 0);
1777 [ # # ]: 0 : if (!dev->data->mac_addrs) {
1778 : 0 : PMD_INIT_LOG(ERR,
1779 : : "Failed to allocated memory for storing mac address");
1780 : 0 : goto err_mac_alloc;
1781 : : }
1782 : : rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.perm_addr,
1783 : : &dev->data->mac_addrs[0]);
1784 : :
1785 : : /* Init dcb to sw mode by default */
1786 : 0 : ret = i40e_dcb_init_configure(dev, TRUE);
1787 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
1788 : 0 : PMD_INIT_LOG(INFO, "Failed to init dcb.");
1789 : 0 : pf->flags &= ~I40E_FLAG_DCB;
1790 : : }
1791 : : /* Update HW struct after DCB configuration */
1792 : 0 : i40e_get_cap(hw);
1793 : :
1794 : : /* initialize pf host driver to setup SRIOV resource if applicable */
1795 : 0 : i40e_pf_host_init(dev);
1796 : :
1797 : : /* register callback func to eal lib */
1798 : 0 : rte_intr_callback_register(intr_handle,
1799 : : i40e_dev_interrupt_handler, dev);
1800 : :
1801 : : /* configure and enable device interrupt */
1802 : : i40e_pf_config_irq0(hw, TRUE);
1803 : 0 : i40e_pf_enable_irq0(hw);
1804 : :
1805 : : /* enable uio intr after callback register */
1806 : 0 : rte_intr_enable(intr_handle);
1807 : :
1808 : : /* By default disable flexible payload in global configuration */
1809 [ # # ]: 0 : if (!pf->support_multi_driver)
1810 : 0 : i40e_flex_payload_reg_set_default(hw);
1811 : :
1812 : : /*
1813 : : * Add an ethertype filter to drop all flow control frames transmitted
1814 : : * from VSIs. By doing so, we stop VF from sending out PAUSE or PFC
1815 : : * frames to wire.
1816 : : */
1817 : 0 : i40e_add_tx_flow_control_drop_filter(pf);
1818 : :
1819 : : /* initialize RSS rule list */
1820 : 0 : TAILQ_INIT(&pf->rss_config_list);
1821 : :
1822 : : /* initialize Traffic Manager configuration */
1823 : 0 : i40e_tm_conf_init(dev);
1824 : :
1825 : : /* Initialize customized information */
1826 : : i40e_init_customized_info(pf);
1827 : :
1828 : : /* Initialize the filter invalidation configuration */
1829 : 0 : i40e_init_filter_invalidation(pf);
1830 : :
1831 : 0 : ret = i40e_init_ethtype_filter_list(dev);
1832 [ # # ]: 0 : if (ret < 0)
1833 : 0 : goto err_init_ethtype_filter_list;
1834 : 0 : ret = i40e_init_tunnel_filter_list(dev);
1835 [ # # ]: 0 : if (ret < 0)
1836 : 0 : goto err_init_tunnel_filter_list;
1837 : 0 : ret = i40e_init_fdir_filter_list(dev);
1838 [ # # ]: 0 : if (ret < 0)
1839 : 0 : goto err_init_fdir_filter_list;
1840 : :
1841 : : /* initialize queue region configuration */
1842 : 0 : i40e_init_queue_region_conf(dev);
1843 : :
1844 : : /* reset all stats of the device, including pf and main vsi */
1845 : 0 : i40e_dev_stats_reset(dev);
1846 : :
1847 : 0 : return 0;
1848 : :
1849 : : err_init_fdir_filter_list:
1850 : 0 : rte_hash_free(pf->tunnel.hash_table);
1851 : 0 : rte_free(pf->tunnel.hash_map);
1852 : 0 : err_init_tunnel_filter_list:
1853 : 0 : rte_hash_free(pf->ethertype.hash_table);
1854 : 0 : rte_free(pf->ethertype.hash_map);
1855 : 0 : err_init_ethtype_filter_list:
1856 : 0 : rte_intr_callback_unregister(intr_handle,
1857 : : i40e_dev_interrupt_handler, dev);
1858 : 0 : rte_free(dev->data->mac_addrs);
1859 : 0 : dev->data->mac_addrs = NULL;
1860 : 0 : err_mac_alloc:
1861 : 0 : i40e_vsi_release(pf->main_vsi);
1862 : 0 : err_setup_pf_switch:
1863 : 0 : err_get_mac_addr:
1864 : 0 : err_configure_lan_hmc:
1865 : 0 : (void)i40e_shutdown_lan_hmc(hw);
1866 : 0 : err_init_lan_hmc:
1867 : 0 : i40e_res_pool_destroy(&pf->msix_pool);
1868 : 0 : err_msix_pool_init:
1869 : 0 : i40e_res_pool_destroy(&pf->qp_pool);
1870 : 0 : err_qp_pool_init:
1871 : 0 : err_parameter_init:
1872 : 0 : err_get_capabilities:
1873 : 0 : (void)i40e_shutdown_adminq(hw);
1874 : :
1875 : 0 : return ret;
1876 : : }
1877 : :
1878 : : static void
1879 : 0 : i40e_rm_ethtype_filter_list(struct i40e_pf *pf)
1880 : : {
1881 : : struct i40e_ethertype_filter *p_ethertype;
1882 : : struct i40e_ethertype_rule *ethertype_rule;
1883 : :
1884 : : ethertype_rule = &pf->ethertype;
1885 : : /* Remove all ethertype filter rules and hash */
1886 : 0 : rte_free(ethertype_rule->hash_map);
1887 : 0 : rte_hash_free(ethertype_rule->hash_table);
1888 : :
1889 [ # # ]: 0 : while ((p_ethertype = TAILQ_FIRST(ðertype_rule->ethertype_list))) {
1890 [ # # ]: 0 : TAILQ_REMOVE(ðertype_rule->ethertype_list,
1891 : : p_ethertype, rules);
1892 : 0 : rte_free(p_ethertype);
1893 : : }
1894 : 0 : }
1895 : :
1896 : : static void
1897 : 0 : i40e_rm_tunnel_filter_list(struct i40e_pf *pf)
1898 : : {
1899 : : struct i40e_tunnel_filter *p_tunnel;
1900 : : struct i40e_tunnel_rule *tunnel_rule;
1901 : :
1902 : : tunnel_rule = &pf->tunnel;
1903 : : /* Remove all tunnel director rules and hash */
1904 : 0 : rte_free(tunnel_rule->hash_map);
1905 : 0 : rte_hash_free(tunnel_rule->hash_table);
1906 : :
1907 [ # # ]: 0 : while ((p_tunnel = TAILQ_FIRST(&tunnel_rule->tunnel_list))) {
1908 [ # # ]: 0 : TAILQ_REMOVE(&tunnel_rule->tunnel_list, p_tunnel, rules);
1909 : 0 : rte_free(p_tunnel);
1910 : : }
1911 : 0 : }
1912 : :
1913 : : static void
1914 : : i40e_rm_fdir_filter_list(struct i40e_pf *pf)
1915 : : {
1916 : : struct i40e_fdir_filter *p_fdir;
1917 : : struct i40e_fdir_info *fdir_info;
1918 : :
1919 : : fdir_info = &pf->fdir;
1920 : :
1921 : : /* Remove all flow director rules */
1922 [ # # ]: 0 : while ((p_fdir = TAILQ_FIRST(&fdir_info->fdir_list)))
1923 [ # # ]: 0 : TAILQ_REMOVE(&fdir_info->fdir_list, p_fdir, rules);
1924 : : }
1925 : :
1926 : : static void
1927 : 0 : i40e_fdir_memory_cleanup(struct i40e_pf *pf)
1928 : : {
1929 : : struct i40e_fdir_info *fdir_info;
1930 : :
1931 : : fdir_info = &pf->fdir;
1932 : :
1933 : : /* flow director memory cleanup */
1934 : 0 : rte_free(fdir_info->hash_map);
1935 : 0 : rte_hash_free(fdir_info->hash_table);
1936 : 0 : rte_free(fdir_info->fdir_flow_pool.bitmap);
1937 : 0 : rte_free(fdir_info->fdir_flow_pool.pool);
1938 : 0 : rte_free(fdir_info->fdir_filter_array);
1939 : 0 : }
1940 : :
1941 : 0 : void i40e_flex_payload_reg_set_default(struct i40e_hw *hw)
1942 : : {
1943 : : /*
1944 : : * Disable by default flexible payload
1945 : : * for corresponding L2/L3/L4 layers.
1946 : : */
1947 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(33), 0x00000000);
1948 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(34), 0x00000000);
1949 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLQF_ORT(35), 0x00000000);
1950 : 0 : }
1951 : :
1952 : : static int
1953 : 0 : eth_i40e_dev_uninit(struct rte_eth_dev *dev)
1954 : : {
1955 : : struct i40e_hw *hw;
1956 : :
1957 : 0 : PMD_INIT_FUNC_TRACE();
1958 : :
1959 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1960 : : return 0;
1961 : :
1962 : 0 : hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1963 : :
1964 [ # # ]: 0 : if (hw->adapter_closed == 0)
1965 : 0 : i40e_dev_close(dev);
1966 : :
1967 : : return 0;
1968 : : }
1969 : :
1970 : : static int
1971 : 0 : i40e_dev_configure(struct rte_eth_dev *dev)
1972 : : {
1973 : 0 : struct i40e_adapter *ad =
1974 : 0 : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
1975 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
1976 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1977 : 0 : enum rte_eth_rx_mq_mode mq_mode = dev->data->dev_conf.rxmode.mq_mode;
1978 : : int i, ret;
1979 : :
1980 : 0 : ret = i40e_dev_sync_phy_type(hw);
1981 [ # # ]: 0 : if (ret)
1982 : : return ret;
1983 : :
1984 : : /* Initialize to TRUE. If any of Rx queues doesn't meet the
1985 : : * bulk allocation or vector Rx preconditions we will reset it.
1986 : : */
1987 : 0 : ad->rx_bulk_alloc_allowed = true;
1988 : 0 : ad->rx_vec_allowed = true;
1989 : 0 : ad->tx_simple_allowed = true;
1990 : 0 : ad->tx_vec_allowed = true;
1991 : :
1992 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
1993 : 0 : dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
1994 : :
1995 : 0 : ret = i40e_dev_init_vlan(dev);
1996 [ # # ]: 0 : if (ret < 0)
1997 : 0 : goto err;
1998 : :
1999 : : /* VMDQ setup.
2000 : : * General PMD call sequence are NIC init, configure,
2001 : : * rx/tx_queue_setup and dev_start. In rx/tx_queue_setup() function, it
2002 : : * will try to lookup the VSI that specific queue belongs to if VMDQ
2003 : : * applicable. So, VMDQ setting has to be done before
2004 : : * rx/tx_queue_setup(). This function is good to place vmdq_setup.
2005 : : * For RSS setting, it will try to calculate actual configured RX queue
2006 : : * number, which will be available after rx_queue_setup(). dev_start()
2007 : : * function is good to place RSS setup.
2008 : : */
2009 [ # # ]: 0 : if (mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG) {
2010 : 0 : ret = i40e_vmdq_setup(dev);
2011 [ # # ]: 0 : if (ret)
2012 : 0 : goto err;
2013 : : }
2014 : :
2015 [ # # ]: 0 : if (mq_mode & RTE_ETH_MQ_RX_DCB_FLAG) {
2016 : 0 : ret = i40e_dcb_setup(dev);
2017 [ # # ]: 0 : if (ret) {
2018 : 0 : PMD_DRV_LOG(ERR, "failed to configure DCB.");
2019 : 0 : goto err_dcb;
2020 : : }
2021 : : }
2022 : :
2023 : 0 : TAILQ_INIT(&pf->flow_list);
2024 : :
2025 : 0 : return 0;
2026 : :
2027 : : err_dcb:
2028 : : /* need to release vmdq resource if exists */
2029 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2030 : 0 : i40e_vsi_release(pf->vmdq[i].vsi);
2031 : 0 : pf->vmdq[i].vsi = NULL;
2032 : : }
2033 : 0 : rte_free(pf->vmdq);
2034 : 0 : pf->vmdq = NULL;
2035 : : err:
2036 : : return ret;
2037 : : }
2038 : :
2039 : : void
2040 : 0 : i40e_vsi_queues_unbind_intr(struct i40e_vsi *vsi)
2041 : : {
2042 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
2043 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
2044 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2045 : : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2046 : 0 : uint16_t msix_vect = vsi->msix_intr;
2047 : : uint16_t i;
2048 : :
2049 [ # # ]: 0 : for (i = 0; i < vsi->nb_qps; i++) {
2050 : 0 : I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
2051 : 0 : I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
2052 : : rte_wmb();
2053 : : }
2054 : :
2055 [ # # ]: 0 : if (vsi->type != I40E_VSI_SRIOV) {
2056 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle)) {
2057 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
2058 : : I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
2059 : 0 : I40E_WRITE_REG(hw,
2060 : : I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
2061 : : 0);
2062 : : } else {
2063 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
2064 : : I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK);
2065 : 0 : I40E_WRITE_REG(hw,
2066 : : I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
2067 : : msix_vect - 1), 0);
2068 : : }
2069 : : } else {
2070 : : uint32_t reg;
2071 : 0 : reg = (hw->func_caps.num_msix_vectors_vf - 1) *
2072 : 0 : vsi->user_param + (msix_vect - 1);
2073 : :
2074 : 0 : I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
2075 : : I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
2076 : : }
2077 : 0 : I40E_WRITE_FLUSH(hw);
2078 : 0 : }
2079 : :
2080 : : static void
2081 : 0 : __vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t msix_vect,
2082 : : int base_queue, int nb_queue,
2083 : : uint16_t itr_idx)
2084 : : {
2085 : : int i;
2086 : : uint32_t val;
2087 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2088 : : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2089 : :
2090 : : /* Bind all RX queues to allocated MSIX interrupt */
2091 [ # # ]: 0 : for (i = 0; i < nb_queue; i++) {
2092 : 0 : val = (msix_vect << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
2093 : 0 : itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT |
2094 : 0 : ((base_queue + i + 1) <<
2095 : 0 : I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
2096 : 0 : (0 << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
2097 : : I40E_QINT_RQCTL_CAUSE_ENA_MASK;
2098 : :
2099 [ # # ]: 0 : if (i == nb_queue - 1)
2100 : 0 : val |= I40E_QINT_RQCTL_NEXTQ_INDX_MASK;
2101 : 0 : I40E_WRITE_REG(hw, I40E_QINT_RQCTL(base_queue + i), val);
2102 : : }
2103 : :
2104 : : /* Write first RX queue to Link list register as the head element */
2105 [ # # ]: 0 : if (vsi->type != I40E_VSI_SRIOV) {
2106 : : uint16_t interval =
2107 : : i40e_calc_itr_interval(1, pf->support_multi_driver);
2108 : :
2109 [ # # ]: 0 : if (msix_vect == I40E_MISC_VEC_ID) {
2110 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
2111 : : (base_queue <<
2112 : : I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
2113 : : (0x0 <<
2114 : : I40E_PFINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
2115 : 0 : I40E_WRITE_REG(hw,
2116 : : I40E_PFINT_ITR0(I40E_ITR_INDEX_DEFAULT),
2117 : : interval);
2118 : : } else {
2119 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLSTN(msix_vect - 1),
2120 : : (base_queue <<
2121 : : I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
2122 : : (0x0 <<
2123 : : I40E_PFINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
2124 : 0 : I40E_WRITE_REG(hw,
2125 : : I40E_PFINT_ITRN(I40E_ITR_INDEX_DEFAULT,
2126 : : msix_vect - 1),
2127 : : interval);
2128 : : }
2129 : : } else {
2130 : : uint32_t reg;
2131 : :
2132 [ # # ]: 0 : if (msix_vect == I40E_MISC_VEC_ID) {
2133 : 0 : I40E_WRITE_REG(hw,
2134 : : I40E_VPINT_LNKLST0(vsi->user_param),
2135 : : (base_queue <<
2136 : : I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT) |
2137 : : (0x0 <<
2138 : : I40E_VPINT_LNKLST0_FIRSTQ_TYPE_SHIFT));
2139 : : } else {
2140 : : /* num_msix_vectors_vf needs to minus irq0 */
2141 : 0 : reg = (hw->func_caps.num_msix_vectors_vf - 1) *
2142 : 0 : vsi->user_param + (msix_vect - 1);
2143 : :
2144 : 0 : I40E_WRITE_REG(hw, I40E_VPINT_LNKLSTN(reg),
2145 : : (base_queue <<
2146 : : I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT) |
2147 : : (0x0 <<
2148 : : I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT));
2149 : : }
2150 : : }
2151 : :
2152 : 0 : I40E_WRITE_FLUSH(hw);
2153 : 0 : }
2154 : :
2155 : : int
2156 : 0 : i40e_vsi_queues_bind_intr(struct i40e_vsi *vsi, uint16_t itr_idx)
2157 : : {
2158 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
2159 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
2160 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2161 : : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2162 : 0 : uint16_t msix_vect = vsi->msix_intr;
2163 : 0 : uint16_t nb_msix = RTE_MIN(vsi->nb_msix,
2164 : : rte_intr_nb_efd_get(intr_handle));
2165 : : uint16_t queue_idx = 0;
2166 : : int record = 0;
2167 : : int i;
2168 : :
2169 [ # # ]: 0 : for (i = 0; i < vsi->nb_qps; i++) {
2170 : 0 : I40E_WRITE_REG(hw, I40E_QINT_TQCTL(vsi->base_queue + i), 0);
2171 : 0 : I40E_WRITE_REG(hw, I40E_QINT_RQCTL(vsi->base_queue + i), 0);
2172 : : }
2173 : :
2174 : : /* VF bind interrupt */
2175 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
2176 [ # # ]: 0 : if (vsi->nb_msix == 0) {
2177 : 0 : PMD_DRV_LOG(ERR, "No msix resource");
2178 : 0 : return -EINVAL;
2179 : : }
2180 : 0 : __vsi_queues_bind_intr(vsi, msix_vect,
2181 : 0 : vsi->base_queue, vsi->nb_qps,
2182 : : itr_idx);
2183 : 0 : return 0;
2184 : : }
2185 : :
2186 : : /* PF & VMDq bind interrupt */
2187 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
2188 [ # # ]: 0 : if (vsi->type == I40E_VSI_MAIN) {
2189 : : queue_idx = 0;
2190 : : record = 1;
2191 [ # # ]: 0 : } else if (vsi->type == I40E_VSI_VMDQ2) {
2192 : : struct i40e_vsi *main_vsi =
2193 [ # # ]: 0 : I40E_DEV_PRIVATE_TO_MAIN_VSI(vsi->adapter);
2194 : 0 : queue_idx = vsi->base_queue - main_vsi->nb_qps;
2195 : : record = 1;
2196 : : }
2197 : : }
2198 : :
2199 [ # # ]: 0 : for (i = 0; i < vsi->nb_used_qps; i++) {
2200 [ # # ]: 0 : if (vsi->nb_msix == 0) {
2201 : 0 : PMD_DRV_LOG(ERR, "No msix resource");
2202 : 0 : return -EINVAL;
2203 [ # # ]: 0 : } else if (nb_msix <= 1) {
2204 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle))
2205 : : /* allow to share MISC_VEC_ID */
2206 : : msix_vect = I40E_MISC_VEC_ID;
2207 : :
2208 : : /* no enough msix_vect, map all to one */
2209 : 0 : __vsi_queues_bind_intr(vsi, msix_vect,
2210 : 0 : vsi->base_queue + i,
2211 : 0 : vsi->nb_used_qps - i,
2212 : : itr_idx);
2213 [ # # # # ]: 0 : for (; !!record && i < vsi->nb_used_qps; i++)
2214 : 0 : rte_intr_vec_list_index_set(intr_handle,
2215 : : queue_idx + i, msix_vect);
2216 : : break;
2217 : : }
2218 : : /* 1:1 queue/msix_vect mapping */
2219 : 0 : __vsi_queues_bind_intr(vsi, msix_vect,
2220 : 0 : vsi->base_queue + i, 1,
2221 : : itr_idx);
2222 [ # # ]: 0 : if (!!record)
2223 [ # # ]: 0 : if (rte_intr_vec_list_index_set(intr_handle,
2224 : : queue_idx + i, msix_vect))
2225 : 0 : return -rte_errno;
2226 : :
2227 : 0 : msix_vect++;
2228 : 0 : nb_msix--;
2229 : : }
2230 : :
2231 : : return 0;
2232 : : }
2233 : :
2234 : : void
2235 : 0 : i40e_vsi_enable_queues_intr(struct i40e_vsi *vsi)
2236 : : {
2237 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
2238 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
2239 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2240 : : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2241 : : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2242 : : uint16_t msix_intr, i;
2243 : :
2244 [ # # # # ]: 0 : if (rte_intr_allow_others(intr_handle) && !pf->support_multi_driver)
2245 [ # # ]: 0 : for (i = 0; i < vsi->nb_msix; i++) {
2246 : 0 : msix_intr = vsi->msix_intr + i;
2247 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
2248 : : I40E_PFINT_DYN_CTLN_INTENA_MASK |
2249 : : I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
2250 : : I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
2251 : : }
2252 : : else
2253 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
2254 : : I40E_PFINT_DYN_CTL0_INTENA_MASK |
2255 : : I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
2256 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
2257 : :
2258 : 0 : I40E_WRITE_FLUSH(hw);
2259 : 0 : }
2260 : :
2261 : : void
2262 : 0 : i40e_vsi_disable_queues_intr(struct i40e_vsi *vsi)
2263 : : {
2264 : 0 : struct rte_eth_dev *dev = I40E_VSI_TO_ETH_DEV(vsi);
2265 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
2266 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2267 : : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
2268 : : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
2269 : : uint16_t msix_intr, i;
2270 : :
2271 [ # # # # ]: 0 : if (rte_intr_allow_others(intr_handle) && !pf->support_multi_driver)
2272 [ # # ]: 0 : for (i = 0; i < vsi->nb_msix; i++) {
2273 : 0 : msix_intr = vsi->msix_intr + i;
2274 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTLN(msix_intr - 1),
2275 : : I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
2276 : : }
2277 : : else
2278 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
2279 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
2280 : :
2281 : 0 : I40E_WRITE_FLUSH(hw);
2282 : 0 : }
2283 : :
2284 : : static inline uint8_t
2285 : 0 : i40e_parse_link_speeds(uint16_t link_speeds)
2286 : : {
2287 : : uint8_t link_speed = I40E_LINK_SPEED_UNKNOWN;
2288 : :
2289 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_40G)
2290 : : link_speed |= I40E_LINK_SPEED_40GB;
2291 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_25G)
2292 : 0 : link_speed |= I40E_LINK_SPEED_25GB;
2293 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_20G)
2294 : 0 : link_speed |= I40E_LINK_SPEED_20GB;
2295 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_10G)
2296 : 0 : link_speed |= I40E_LINK_SPEED_10GB;
2297 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_1G)
2298 : 0 : link_speed |= I40E_LINK_SPEED_1GB;
2299 [ # # ]: 0 : if (link_speeds & RTE_ETH_LINK_SPEED_100M)
2300 : 0 : link_speed |= I40E_LINK_SPEED_100MB;
2301 : :
2302 : 0 : return link_speed;
2303 : : }
2304 : :
2305 : : static int
2306 : 0 : i40e_phy_conf_link(struct i40e_hw *hw,
2307 : : uint8_t abilities,
2308 : : uint8_t force_speed,
2309 : : bool is_up)
2310 : : {
2311 : : enum i40e_status_code status;
2312 : : struct i40e_aq_get_phy_abilities_resp phy_ab;
2313 : : struct i40e_aq_set_phy_config phy_conf;
2314 : : enum i40e_aq_phy_type cnt;
2315 : : uint8_t avail_speed;
2316 : : uint32_t phy_type_mask = 0;
2317 : :
2318 : : const uint8_t mask = I40E_AQ_PHY_FLAG_PAUSE_TX |
2319 : : I40E_AQ_PHY_FLAG_PAUSE_RX |
2320 : : I40E_AQ_PHY_FLAG_PAUSE_RX |
2321 : : I40E_AQ_PHY_FLAG_LOW_POWER;
2322 : : int ret = -ENOTSUP;
2323 : :
2324 : : /* To get phy capabilities of available speeds. */
2325 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, true, &phy_ab,
2326 : : NULL);
2327 [ # # ]: 0 : if (status) {
2328 : 0 : PMD_DRV_LOG(ERR, "Failed to get PHY capabilities: %d",
2329 : : status);
2330 : 0 : return ret;
2331 : : }
2332 : 0 : avail_speed = phy_ab.link_speed;
2333 : :
2334 : : /* To get the current phy config. */
2335 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, false, &phy_ab,
2336 : : NULL);
2337 [ # # ]: 0 : if (status) {
2338 : 0 : PMD_DRV_LOG(ERR, "Failed to get the current PHY config: %d",
2339 : : status);
2340 : 0 : return ret;
2341 : : }
2342 : :
2343 : : /* If link needs to go up and it is in autoneg mode the speed is OK,
2344 : : * no need to set up again.
2345 : : */
2346 [ # # # # : 0 : if (is_up && phy_ab.phy_type != 0 &&
# # ]
2347 : 0 : abilities & I40E_AQ_PHY_AN_ENABLED &&
2348 [ # # ]: 0 : phy_ab.link_speed != 0)
2349 : : return I40E_SUCCESS;
2350 : :
2351 : : memset(&phy_conf, 0, sizeof(phy_conf));
2352 : :
2353 : : /* bits 0-2 use the values from get_phy_abilities_resp */
2354 : 0 : abilities &= ~mask;
2355 : 0 : abilities |= phy_ab.abilities & mask;
2356 : :
2357 : 0 : phy_conf.abilities = abilities;
2358 : :
2359 : : /* If link needs to go up, but the force speed is not supported,
2360 : : * Warn users and config the default available speeds.
2361 : : */
2362 [ # # # # ]: 0 : if (is_up && !(force_speed & avail_speed)) {
2363 : 0 : PMD_DRV_LOG(WARNING, "Invalid speed setting, set to default!");
2364 : 0 : phy_conf.link_speed = avail_speed;
2365 : : } else {
2366 [ # # ]: 0 : phy_conf.link_speed = is_up ? force_speed : avail_speed;
2367 : : }
2368 : :
2369 : : /* PHY type mask needs to include each type except PHY type extension */
2370 [ # # ]: 0 : for (cnt = I40E_PHY_TYPE_SGMII; cnt < I40E_PHY_TYPE_25GBASE_KR; cnt++)
2371 : 0 : phy_type_mask |= 1 << cnt;
2372 : :
2373 : : /* use get_phy_abilities_resp value for the rest */
2374 [ # # ]: 0 : phy_conf.phy_type = is_up ? cpu_to_le32(phy_type_mask) : 0;
2375 [ # # ]: 0 : phy_conf.phy_type_ext = is_up ? (I40E_AQ_PHY_TYPE_EXT_25G_KR |
2376 : : I40E_AQ_PHY_TYPE_EXT_25G_CR | I40E_AQ_PHY_TYPE_EXT_25G_SR |
2377 : : I40E_AQ_PHY_TYPE_EXT_25G_LR | I40E_AQ_PHY_TYPE_EXT_25G_AOC |
2378 : : I40E_AQ_PHY_TYPE_EXT_25G_ACC) : 0;
2379 : 0 : phy_conf.fec_config = phy_ab.fec_cfg_curr_mod_ext_info;
2380 : 0 : phy_conf.eee_capability = phy_ab.eee_capability;
2381 : 0 : phy_conf.eeer = phy_ab.eeer_val;
2382 : 0 : phy_conf.low_power_ctrl = phy_ab.d3_lpan;
2383 : :
2384 : 0 : PMD_DRV_LOG(DEBUG, "\tCurrent: abilities %x, link_speed %x",
2385 : : phy_ab.abilities, phy_ab.link_speed);
2386 : 0 : PMD_DRV_LOG(DEBUG, "\tConfig: abilities %x, link_speed %x",
2387 : : phy_conf.abilities, phy_conf.link_speed);
2388 : :
2389 : 0 : status = i40e_aq_set_phy_config(hw, &phy_conf, NULL);
2390 [ # # ]: 0 : if (status)
2391 : 0 : return ret;
2392 : :
2393 : : return I40E_SUCCESS;
2394 : : }
2395 : :
2396 : : static int
2397 : 0 : i40e_apply_link_speed(struct rte_eth_dev *dev)
2398 : : {
2399 : : uint8_t speed;
2400 : : uint8_t abilities = 0;
2401 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2402 : : struct rte_eth_conf *conf = &dev->data->dev_conf;
2403 : :
2404 : : abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK |
2405 : : I40E_AQ_PHY_LINK_ENABLED;
2406 : :
2407 [ # # ]: 0 : if (conf->link_speeds == RTE_ETH_LINK_SPEED_AUTONEG) {
2408 : 0 : conf->link_speeds = RTE_ETH_LINK_SPEED_40G |
2409 : : RTE_ETH_LINK_SPEED_25G |
2410 : : RTE_ETH_LINK_SPEED_20G |
2411 : : RTE_ETH_LINK_SPEED_10G |
2412 : : RTE_ETH_LINK_SPEED_1G |
2413 : : RTE_ETH_LINK_SPEED_100M;
2414 : :
2415 : : abilities |= I40E_AQ_PHY_AN_ENABLED;
2416 : : } else {
2417 : : abilities &= ~I40E_AQ_PHY_AN_ENABLED;
2418 : : }
2419 : 0 : speed = i40e_parse_link_speeds(conf->link_speeds);
2420 : :
2421 : 0 : return i40e_phy_conf_link(hw, abilities, speed, true);
2422 : : }
2423 : :
2424 : : static int
2425 : 0 : i40e_dev_start(struct rte_eth_dev *dev)
2426 : : {
2427 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2428 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2429 : 0 : struct i40e_vsi *main_vsi = pf->main_vsi;
2430 : : struct i40e_adapter *ad =
2431 : : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
2432 : : int ret, i;
2433 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
2434 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2435 : : uint32_t intr_vector = 0;
2436 : : struct i40e_vsi *vsi;
2437 : : uint16_t nb_rxq, nb_txq;
2438 : : uint16_t max_frame_size;
2439 : :
2440 : 0 : hw->adapter_stopped = 0;
2441 : :
2442 : 0 : rte_intr_disable(intr_handle);
2443 : :
2444 [ # # ]: 0 : if ((rte_intr_cap_multiple(intr_handle) ||
2445 [ # # ]: 0 : !RTE_ETH_DEV_SRIOV(dev).active) &&
2446 [ # # ]: 0 : dev->data->dev_conf.intr_conf.rxq != 0) {
2447 : 0 : intr_vector = dev->data->nb_rx_queues;
2448 : 0 : ret = rte_intr_efd_enable(intr_handle, intr_vector);
2449 [ # # ]: 0 : if (ret)
2450 : : return ret;
2451 : : }
2452 : :
2453 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
2454 [ # # ]: 0 : if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
2455 : 0 : dev->data->nb_rx_queues)) {
2456 : 0 : PMD_INIT_LOG(ERR,
2457 : : "Failed to allocate %d rx_queues intr_vec",
2458 : : dev->data->nb_rx_queues);
2459 : 0 : return -ENOMEM;
2460 : : }
2461 : : }
2462 : :
2463 : : /* Initialize VSI */
2464 : 0 : ret = i40e_dev_rxtx_init(pf);
2465 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2466 : 0 : PMD_DRV_LOG(ERR, "Failed to init rx/tx queues");
2467 : 0 : return ret;
2468 : : }
2469 : :
2470 : : /* Map queues with MSIX interrupt */
2471 : 0 : main_vsi->nb_used_qps = dev->data->nb_rx_queues -
2472 : 0 : pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
2473 : 0 : ret = i40e_vsi_queues_bind_intr(main_vsi, I40E_ITR_INDEX_DEFAULT);
2474 [ # # ]: 0 : if (ret < 0)
2475 : : return ret;
2476 : 0 : i40e_vsi_enable_queues_intr(main_vsi);
2477 : :
2478 : : /* Map VMDQ VSI queues with MSIX interrupt */
2479 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2480 : 0 : pf->vmdq[i].vsi->nb_used_qps = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
2481 : 0 : ret = i40e_vsi_queues_bind_intr(pf->vmdq[i].vsi,
2482 : : I40E_ITR_INDEX_DEFAULT);
2483 [ # # ]: 0 : if (ret < 0)
2484 : 0 : return ret;
2485 : 0 : i40e_vsi_enable_queues_intr(pf->vmdq[i].vsi);
2486 : : }
2487 : :
2488 : : /* Enable all queues which have been configured */
2489 [ # # ]: 0 : for (nb_rxq = 0; nb_rxq < dev->data->nb_rx_queues; nb_rxq++) {
2490 : 0 : ret = i40e_dev_rx_queue_start(dev, nb_rxq);
2491 [ # # ]: 0 : if (ret)
2492 : 0 : goto rx_err;
2493 : : }
2494 : :
2495 [ # # ]: 0 : for (nb_txq = 0; nb_txq < dev->data->nb_tx_queues; nb_txq++) {
2496 : 0 : ret = i40e_dev_tx_queue_start(dev, nb_txq);
2497 [ # # ]: 0 : if (ret)
2498 : 0 : goto tx_err;
2499 : : }
2500 : :
2501 : : /* Enable receiving broadcast packets */
2502 : 0 : ret = i40e_aq_set_vsi_broadcast(hw, main_vsi->seid, true, NULL);
2503 [ # # ]: 0 : if (ret != I40E_SUCCESS)
2504 : 0 : PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
2505 : :
2506 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2507 : 0 : ret = i40e_aq_set_vsi_broadcast(hw, pf->vmdq[i].vsi->seid,
2508 : : true, NULL);
2509 [ # # ]: 0 : if (ret != I40E_SUCCESS)
2510 : 0 : PMD_DRV_LOG(INFO, "fail to set vsi broadcast");
2511 : : }
2512 : :
2513 : : /* Enable the VLAN promiscuous mode. */
2514 [ # # ]: 0 : if (pf->vfs) {
2515 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++) {
2516 : 0 : vsi = pf->vfs[i].vsi;
2517 : 0 : i40e_aq_set_vsi_vlan_promisc(hw, vsi->seid,
2518 : : true, NULL);
2519 : : }
2520 : : }
2521 : :
2522 : : /* Disable mac loopback mode */
2523 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode == I40E_AQ_LB_MODE_NONE) {
2524 : 0 : ret = i40e_aq_set_lb_modes(hw, I40E_AQ_LB_MODE_NONE, NULL);
2525 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2526 : 0 : PMD_DRV_LOG(ERR, "fail to set loopback link");
2527 : 0 : goto tx_err;
2528 : : }
2529 : : }
2530 : :
2531 : : /* Enable mac loopback mode */
2532 [ # # ]: 0 : if (dev->data->dev_conf.lpbk_mode == I40E_AQ_LB_MODE_EN) {
2533 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
2534 : 0 : ret = i40e_aq_set_lb_modes(hw, I40E_AQ_LB_MAC_LOCAL_X722, NULL);
2535 : : else
2536 : 0 : ret = i40e_aq_set_lb_modes(hw, I40E_AQ_LB_MAC, NULL);
2537 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2538 : 0 : PMD_DRV_LOG(ERR, "fail to set loopback link");
2539 : 0 : goto tx_err;
2540 : : }
2541 : : }
2542 : :
2543 : : /* Apply link configure */
2544 : 0 : ret = i40e_apply_link_speed(dev);
2545 [ # # ]: 0 : if (I40E_SUCCESS != ret) {
2546 : 0 : PMD_DRV_LOG(ERR, "Fail to apply link setting");
2547 : 0 : goto tx_err;
2548 : : }
2549 : :
2550 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle)) {
2551 : 0 : rte_intr_callback_unregister(intr_handle,
2552 : : i40e_dev_interrupt_handler,
2553 : : (void *)dev);
2554 : : /* configure and enable device interrupt */
2555 : : i40e_pf_config_irq0(hw, FALSE);
2556 : 0 : i40e_pf_enable_irq0(hw);
2557 : :
2558 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.lsc != 0)
2559 : 0 : PMD_INIT_LOG(INFO,
2560 : : "lsc won't enable because of no intr multiplex");
2561 : : } else {
2562 : 0 : ret = i40e_aq_set_phy_int_mask(hw,
2563 : : ~(I40E_AQ_EVENT_LINK_UPDOWN |
2564 : : I40E_AQ_EVENT_MODULE_QUAL_FAIL |
2565 : : I40E_AQ_EVENT_MEDIA_NA), NULL);
2566 [ # # ]: 0 : if (ret != I40E_SUCCESS)
2567 : 0 : PMD_DRV_LOG(WARNING, "Fail to set phy mask");
2568 : : }
2569 : :
2570 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq == 0) {
2571 : 0 : i40e_dev_link_update(dev, 0);
2572 : 0 : pf->mac_config_on_link_up = !dev->data->dev_link.link_status;
2573 : 0 : rte_eal_alarm_set(I40E_ALARM_INTERVAL,
2574 : : i40e_dev_alarm_handler, dev);
2575 : : } else {
2576 : : /* Block if no interrupt handler can process link-up events, to help
2577 : : * ensure that MAC config is applied when the link is up.
2578 : : */
2579 : 0 : i40e_dev_link_update(dev, !rte_intr_allow_others(intr_handle));
2580 : 0 : pf->mac_config_on_link_up = !dev->data->dev_link.link_status;
2581 : : /* enable uio intr after callback register */
2582 : 0 : rte_intr_enable(intr_handle);
2583 : : }
2584 : :
2585 : 0 : i40e_filter_restore(pf);
2586 : :
2587 [ # # # # ]: 0 : if (pf->tm_conf.root && !pf->tm_conf.committed)
2588 : 0 : PMD_DRV_LOG(WARNING,
2589 : : "please call hierarchy_commit() "
2590 : : "before starting the port");
2591 : :
2592 [ # # ]: 0 : max_frame_size = dev->data->mtu ?
2593 : : dev->data->mtu + I40E_ETH_OVERHEAD :
2594 : : I40E_FRAME_SIZE_MAX;
2595 : 0 : ad->max_pkt_len = max_frame_size;
2596 : :
2597 : : /* Set the max frame size to HW*/
2598 : 0 : i40e_aq_set_mac_config(hw, max_frame_size, TRUE, false, 0, NULL);
2599 : :
2600 : 0 : return I40E_SUCCESS;
2601 : :
2602 : 0 : tx_err:
2603 [ # # ]: 0 : for (i = 0; i < nb_txq; i++)
2604 : 0 : i40e_dev_tx_queue_stop(dev, i);
2605 : 0 : rx_err:
2606 [ # # ]: 0 : for (i = 0; i < nb_rxq; i++)
2607 : 0 : i40e_dev_rx_queue_stop(dev, i);
2608 : :
2609 : : return ret;
2610 : : }
2611 : :
2612 : : static int
2613 : 0 : i40e_dev_stop(struct rte_eth_dev *dev)
2614 : : {
2615 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2616 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2617 : 0 : struct i40e_vsi *main_vsi = pf->main_vsi;
2618 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
2619 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2620 : : int i;
2621 : :
2622 [ # # ]: 0 : if (hw->adapter_stopped == 1)
2623 : : return 0;
2624 : :
2625 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq == 0) {
2626 : 0 : rte_eal_alarm_cancel(i40e_dev_alarm_handler, dev);
2627 : 0 : rte_intr_enable(intr_handle);
2628 : : }
2629 : :
2630 : : /* Disable all queues */
2631 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
2632 : 0 : i40e_dev_tx_queue_stop(dev, i);
2633 : :
2634 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
2635 : 0 : i40e_dev_rx_queue_stop(dev, i);
2636 : :
2637 : : /* un-map queues with interrupt registers */
2638 : 0 : i40e_vsi_disable_queues_intr(main_vsi);
2639 : 0 : i40e_vsi_queues_unbind_intr(main_vsi);
2640 : :
2641 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2642 : 0 : i40e_vsi_disable_queues_intr(pf->vmdq[i].vsi);
2643 : 0 : i40e_vsi_queues_unbind_intr(pf->vmdq[i].vsi);
2644 : : }
2645 : :
2646 : : /* Clear all queues and release memory */
2647 : 0 : i40e_dev_clear_queues(dev);
2648 : :
2649 : : /* Set link down */
2650 : : i40e_dev_set_link_down(dev);
2651 : :
2652 [ # # ]: 0 : if (!rte_intr_allow_others(intr_handle))
2653 : : /* resume to the default handler */
2654 : 0 : rte_intr_callback_register(intr_handle,
2655 : : i40e_dev_interrupt_handler,
2656 : : (void *)dev);
2657 : :
2658 : : /* Clean datapath event and queue/vec mapping */
2659 : 0 : rte_intr_efd_disable(intr_handle);
2660 : :
2661 : : /* Cleanup vector list */
2662 : 0 : rte_intr_vec_list_free(intr_handle);
2663 : :
2664 : : /* reset hierarchy commit */
2665 : 0 : pf->tm_conf.committed = false;
2666 : :
2667 : 0 : hw->adapter_stopped = 1;
2668 : 0 : dev->data->dev_started = 0;
2669 : :
2670 : 0 : pf->adapter->rss_reta_updated = 0;
2671 : :
2672 : 0 : return 0;
2673 : : }
2674 : :
2675 : : static int
2676 : 0 : i40e_dev_close(struct rte_eth_dev *dev)
2677 : : {
2678 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2679 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2680 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
2681 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
2682 : : struct i40e_filter_control_settings settings;
2683 : : struct rte_flow *p_flow;
2684 : : uint32_t reg;
2685 : : int i;
2686 : : int ret;
2687 : 0 : uint8_t aq_fail = 0;
2688 : : int retries = 0;
2689 : :
2690 : 0 : PMD_INIT_FUNC_TRACE();
2691 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2692 : : return 0;
2693 : :
2694 : 0 : ret = rte_eth_switch_domain_free(pf->switch_domain_id);
2695 [ # # ]: 0 : if (ret)
2696 : 0 : PMD_INIT_LOG(WARNING, "failed to free switch domain: %d", ret);
2697 : :
2698 : :
2699 : 0 : ret = i40e_dev_stop(dev);
2700 : :
2701 : 0 : i40e_dev_free_queues(dev);
2702 : :
2703 : : /* Disable interrupt */
2704 : 0 : i40e_pf_disable_irq0(hw);
2705 : 0 : rte_intr_disable(intr_handle);
2706 : :
2707 : : /* shutdown and destroy the HMC */
2708 : 0 : i40e_shutdown_lan_hmc(hw);
2709 : :
2710 [ # # ]: 0 : for (i = 0; i < pf->nb_cfg_vmdq_vsi; i++) {
2711 : 0 : i40e_vsi_release(pf->vmdq[i].vsi);
2712 : 0 : pf->vmdq[i].vsi = NULL;
2713 : : }
2714 : 0 : rte_free(pf->vmdq);
2715 : 0 : pf->vmdq = NULL;
2716 : :
2717 : : /* release all the existing VSIs and VEBs */
2718 : 0 : i40e_vsi_release(pf->main_vsi);
2719 : :
2720 : : /* shutdown the adminq */
2721 : 0 : i40e_aq_queue_shutdown(hw, true);
2722 : 0 : i40e_shutdown_adminq(hw);
2723 : :
2724 : 0 : i40e_res_pool_destroy(&pf->qp_pool);
2725 : 0 : i40e_res_pool_destroy(&pf->msix_pool);
2726 : :
2727 : : /* Disable flexible payload in global configuration */
2728 [ # # ]: 0 : if (!pf->support_multi_driver)
2729 : 0 : i40e_flex_payload_reg_set_default(hw);
2730 : :
2731 : : /* force a PF reset to clean anything leftover */
2732 : 0 : reg = I40E_READ_REG(hw, I40E_PFGEN_CTRL);
2733 : 0 : I40E_WRITE_REG(hw, I40E_PFGEN_CTRL,
2734 : : (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
2735 : 0 : I40E_WRITE_FLUSH(hw);
2736 : :
2737 : : /* Clear PXE mode */
2738 : 0 : i40e_clear_pxe_mode(hw);
2739 : :
2740 : : /* Unconfigure filter control */
2741 : : memset(&settings, 0, sizeof(settings));
2742 : 0 : ret = i40e_set_filter_control(hw, &settings);
2743 [ # # ]: 0 : if (ret)
2744 : 0 : PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
2745 : : ret);
2746 : :
2747 : : /* Disable flow control */
2748 : 0 : hw->fc.requested_mode = I40E_FC_NONE;
2749 : 0 : i40e_set_fc(hw, &aq_fail, TRUE);
2750 : :
2751 : : /* uninitialize pf host driver */
2752 : 0 : i40e_pf_host_uninit(dev);
2753 : :
2754 : : do {
2755 : 0 : ret = rte_intr_callback_unregister(intr_handle,
2756 : : i40e_dev_interrupt_handler, dev);
2757 [ # # ]: 0 : if (ret >= 0 || ret == -ENOENT) {
2758 : : break;
2759 [ # # ]: 0 : } else if (ret != -EAGAIN) {
2760 : 0 : PMD_INIT_LOG(ERR,
2761 : : "intr callback unregister failed: %d",
2762 : : ret);
2763 : : }
2764 : 0 : i40e_msec_delay(500);
2765 [ # # ]: 0 : } while (retries++ < 5);
2766 : :
2767 : 0 : i40e_rm_ethtype_filter_list(pf);
2768 : 0 : i40e_rm_tunnel_filter_list(pf);
2769 : : i40e_rm_fdir_filter_list(pf);
2770 : :
2771 : : /* Remove all flows */
2772 [ # # ]: 0 : while ((p_flow = TAILQ_FIRST(&pf->flow_list))) {
2773 [ # # ]: 0 : TAILQ_REMOVE(&pf->flow_list, p_flow, node);
2774 : : /* Do not free FDIR flows since they are static allocated */
2775 [ # # ]: 0 : if (p_flow->filter_type != RTE_ETH_FILTER_FDIR)
2776 : 0 : rte_free(p_flow);
2777 : : }
2778 : :
2779 : : /* release the fdir static allocated memory */
2780 : 0 : i40e_fdir_memory_cleanup(pf);
2781 : :
2782 : : /* Remove all Traffic Manager configuration */
2783 : 0 : i40e_tm_conf_uninit(dev);
2784 : :
2785 : : i40e_clear_automask(pf);
2786 : :
2787 : 0 : hw->adapter_closed = 1;
2788 : 0 : return ret;
2789 : : }
2790 : :
2791 : : /*
2792 : : * Reset PF device only to re-initialize resources in PMD layer
2793 : : */
2794 : : static int
2795 : 0 : i40e_dev_reset(struct rte_eth_dev *dev)
2796 : : {
2797 : : int ret;
2798 : :
2799 : : /* When a DPDK PMD PF begin to reset PF port, it should notify all
2800 : : * its VF to make them align with it. The detailed notification
2801 : : * mechanism is PMD specific. As to i40e PF, it is rather complex.
2802 : : * To avoid unexpected behavior in VF, currently reset of PF with
2803 : : * SR-IOV activation is not supported. It might be supported later.
2804 : : */
2805 [ # # ]: 0 : if (dev->data->sriov.active)
2806 : : return -ENOTSUP;
2807 : :
2808 : 0 : ret = eth_i40e_dev_uninit(dev);
2809 [ # # ]: 0 : if (ret)
2810 : : return ret;
2811 : :
2812 : 0 : ret = eth_i40e_dev_init(dev, NULL);
2813 : :
2814 : 0 : return ret;
2815 : : }
2816 : :
2817 : : static int
2818 : 0 : i40e_dev_promiscuous_enable(struct rte_eth_dev *dev)
2819 : : {
2820 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2821 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2822 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2823 : : int status;
2824 : :
2825 : 0 : status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2826 : : true, NULL, true);
2827 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2828 : 0 : PMD_DRV_LOG(ERR, "Failed to enable unicast promiscuous");
2829 : 0 : return -EAGAIN;
2830 : : }
2831 : :
2832 : 0 : status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
2833 : : TRUE, NULL);
2834 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2835 : 0 : PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
2836 : : /* Rollback unicast promiscuous mode */
2837 : 0 : i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2838 : : false, NULL, true);
2839 : 0 : return -EAGAIN;
2840 : : }
2841 : :
2842 : : return 0;
2843 : : }
2844 : :
2845 : : static int
2846 : 0 : i40e_dev_promiscuous_disable(struct rte_eth_dev *dev)
2847 : : {
2848 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2849 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2850 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2851 : : int status;
2852 : :
2853 : 0 : status = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2854 : : false, NULL, true);
2855 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2856 : 0 : PMD_DRV_LOG(ERR, "Failed to disable unicast promiscuous");
2857 : 0 : return -EAGAIN;
2858 : : }
2859 : :
2860 : : /* must remain in all_multicast mode */
2861 [ # # ]: 0 : if (dev->data->all_multicast == 1)
2862 : : return 0;
2863 : :
2864 : 0 : status = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
2865 : : false, NULL);
2866 [ # # ]: 0 : if (status != I40E_SUCCESS) {
2867 : 0 : PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
2868 : : /* Rollback unicast promiscuous mode */
2869 : 0 : i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
2870 : : true, NULL, true);
2871 : 0 : return -EAGAIN;
2872 : : }
2873 : :
2874 : : return 0;
2875 : : }
2876 : :
2877 : : static int
2878 : 0 : i40e_dev_allmulticast_enable(struct rte_eth_dev *dev)
2879 : : {
2880 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2881 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2882 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2883 : : int ret;
2884 : :
2885 : 0 : ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid, TRUE, NULL);
2886 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2887 : 0 : PMD_DRV_LOG(ERR, "Failed to enable multicast promiscuous");
2888 : 0 : return -EAGAIN;
2889 : : }
2890 : :
2891 : : return 0;
2892 : : }
2893 : :
2894 : : static int
2895 : 0 : i40e_dev_allmulticast_disable(struct rte_eth_dev *dev)
2896 : : {
2897 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
2898 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2899 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
2900 : : int ret;
2901 : :
2902 [ # # ]: 0 : if (dev->data->promiscuous == 1)
2903 : : return 0; /* must remain in all_multicast mode */
2904 : :
2905 : 0 : ret = i40e_aq_set_vsi_multicast_promiscuous(hw,
2906 : 0 : vsi->seid, FALSE, NULL);
2907 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
2908 : 0 : PMD_DRV_LOG(ERR, "Failed to disable multicast promiscuous");
2909 : 0 : return -EAGAIN;
2910 : : }
2911 : :
2912 : : return 0;
2913 : : }
2914 : :
2915 : : /*
2916 : : * Set device link up.
2917 : : */
2918 : : static int
2919 : 0 : i40e_dev_set_link_up(struct rte_eth_dev *dev)
2920 : : {
2921 : : /* re-apply link speed setting */
2922 : 0 : return i40e_apply_link_speed(dev);
2923 : : }
2924 : :
2925 : : /*
2926 : : * Set device link down.
2927 : : */
2928 : : static int
2929 : 0 : i40e_dev_set_link_down(struct rte_eth_dev *dev)
2930 : : {
2931 : : uint8_t speed = I40E_LINK_SPEED_UNKNOWN;
2932 : : uint8_t abilities = 0;
2933 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2934 : :
2935 : : abilities = I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
2936 : 0 : return i40e_phy_conf_link(hw, abilities, speed, false);
2937 : : }
2938 : :
2939 : : static __rte_always_inline void
2940 : : update_link_reg(struct i40e_hw *hw, struct rte_eth_link *link)
2941 : : {
2942 : : /* Link status registers and values*/
2943 : : #define I40E_REG_LINK_UP 0x40000080
2944 : : #define I40E_PRTMAC_MACC 0x001E24E0
2945 : : #define I40E_REG_MACC_25GB 0x00020000
2946 : : #define I40E_REG_SPEED_MASK 0x38000000
2947 : : #define I40E_REG_SPEED_0 0x00000000
2948 : : #define I40E_REG_SPEED_1 0x08000000
2949 : : #define I40E_REG_SPEED_2 0x10000000
2950 : : #define I40E_REG_SPEED_3 0x18000000
2951 : : #define I40E_REG_SPEED_4 0x20000000
2952 : : uint32_t link_speed;
2953 : : uint32_t reg_val;
2954 : :
2955 : 0 : reg_val = I40E_READ_REG(hw, I40E_PRTMAC_LINKSTA(0));
2956 : 0 : link_speed = reg_val & I40E_REG_SPEED_MASK;
2957 : 0 : reg_val &= I40E_REG_LINK_UP;
2958 : 0 : link->link_status = (reg_val == I40E_REG_LINK_UP) ? 1 : 0;
2959 : :
2960 [ # # ]: 0 : if (unlikely(link->link_status == 0))
2961 : : return;
2962 : :
2963 : : /* Parse the link status */
2964 [ # # # # : 0 : switch (link_speed) {
# # ]
2965 : 0 : case I40E_REG_SPEED_0:
2966 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_100M;
2967 : 0 : break;
2968 : 0 : case I40E_REG_SPEED_1:
2969 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_1G;
2970 : 0 : break;
2971 : 0 : case I40E_REG_SPEED_2:
2972 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
2973 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_2_5G;
2974 : : else
2975 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_10G;
2976 : : break;
2977 : 0 : case I40E_REG_SPEED_3:
2978 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
2979 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_5G;
2980 : : } else {
2981 : 0 : reg_val = I40E_READ_REG(hw, I40E_PRTMAC_MACC);
2982 : :
2983 [ # # ]: 0 : if (reg_val & I40E_REG_MACC_25GB)
2984 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_25G;
2985 : : else
2986 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_40G;
2987 : : }
2988 : : break;
2989 : 0 : case I40E_REG_SPEED_4:
2990 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
2991 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_10G;
2992 : : else
2993 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_20G;
2994 : : break;
2995 : 0 : default:
2996 : 0 : PMD_DRV_LOG(ERR, "Unknown link speed info %u", link_speed);
2997 : 0 : break;
2998 : : }
2999 : : }
3000 : :
3001 : : static __rte_always_inline void
3002 : : update_link_aq(struct i40e_hw *hw, struct rte_eth_link *link,
3003 : : bool enable_lse, int wait_to_complete)
3004 : : {
3005 : : #define CHECK_INTERVAL 100 /* 100ms */
3006 : : #define MAX_REPEAT_TIME 10 /* 1s (10 * 100ms) in total */
3007 : : uint32_t rep_cnt = MAX_REPEAT_TIME;
3008 : : struct i40e_link_status link_status;
3009 : : int status;
3010 : :
3011 : : memset(&link_status, 0, sizeof(link_status));
3012 : :
3013 : : do {
3014 : : memset(&link_status, 0, sizeof(link_status));
3015 : :
3016 : : /* Get link status information from hardware */
3017 : 0 : status = i40e_aq_get_link_info(hw, enable_lse,
3018 : : &link_status, NULL);
3019 [ # # ]: 0 : if (unlikely(status != I40E_SUCCESS)) {
3020 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_NONE;
3021 : 0 : link->link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
3022 : 0 : PMD_DRV_LOG(ERR, "Failed to get link info");
3023 : 0 : return;
3024 : : }
3025 : :
3026 : 0 : link->link_status = link_status.link_info & I40E_AQ_LINK_UP;
3027 [ # # # # ]: 0 : if (!wait_to_complete || link->link_status)
3028 : : break;
3029 : :
3030 : : rte_delay_ms(CHECK_INTERVAL);
3031 [ # # ]: 0 : } while (--rep_cnt);
3032 : :
3033 : : /* Parse the link status */
3034 [ # # # # : 0 : switch (link_status.link_speed) {
# # # ]
3035 : 0 : case I40E_LINK_SPEED_100MB:
3036 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_100M;
3037 : 0 : break;
3038 : 0 : case I40E_LINK_SPEED_1GB:
3039 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_1G;
3040 : 0 : break;
3041 : 0 : case I40E_LINK_SPEED_10GB:
3042 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_10G;
3043 : 0 : break;
3044 : 0 : case I40E_LINK_SPEED_20GB:
3045 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_20G;
3046 : 0 : break;
3047 : 0 : case I40E_LINK_SPEED_25GB:
3048 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_25G;
3049 : 0 : break;
3050 : 0 : case I40E_LINK_SPEED_40GB:
3051 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_40G;
3052 : 0 : break;
3053 : 0 : default:
3054 [ # # ]: 0 : if (link->link_status)
3055 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_UNKNOWN;
3056 : : else
3057 : 0 : link->link_speed = RTE_ETH_SPEED_NUM_NONE;
3058 : : break;
3059 : : }
3060 : : }
3061 : :
3062 : : int
3063 : 0 : i40e_dev_link_update(struct rte_eth_dev *dev,
3064 : : int wait_to_complete)
3065 : : {
3066 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3067 : : struct rte_eth_link link;
3068 [ # # ]: 0 : bool enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
3069 : : int ret;
3070 : :
3071 : : memset(&link, 0, sizeof(link));
3072 : :
3073 : : /* i40e uses full duplex only */
3074 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
3075 : 0 : link.link_autoneg = !(dev->data->dev_conf.link_speeds &
3076 : : RTE_ETH_LINK_SPEED_FIXED);
3077 : :
3078 [ # # ]: 0 : if (!wait_to_complete && !enable_lse)
3079 : : update_link_reg(hw, &link);
3080 : : else
3081 : 0 : update_link_aq(hw, &link, enable_lse, wait_to_complete);
3082 : :
3083 [ # # ]: 0 : if (hw->switch_dev)
3084 : 0 : rte_eth_linkstatus_get(hw->switch_dev, &link);
3085 : :
3086 : : ret = rte_eth_linkstatus_set(dev, &link);
3087 : 0 : i40e_notify_all_vfs_link_status(dev);
3088 : :
3089 : 0 : return ret;
3090 : : }
3091 : :
3092 : : static void
3093 : 0 : i40e_stat_update_48_in_64(struct i40e_hw *hw, uint32_t hireg,
3094 : : uint32_t loreg, bool offset_loaded, uint64_t *offset,
3095 : : uint64_t *stat, uint64_t *prev_stat)
3096 : : {
3097 : 0 : i40e_stat_update_48(hw, hireg, loreg, offset_loaded, offset, stat);
3098 : : /* enlarge the limitation when statistics counters overflowed */
3099 [ # # ]: 0 : if (offset_loaded) {
3100 [ # # ]: 0 : if (I40E_RXTX_BYTES_L_48_BIT(*prev_stat) > *stat)
3101 : 0 : *stat += RTE_BIT64(I40E_48_BIT_WIDTH);
3102 : 0 : *stat += I40E_RXTX_BYTES_H_16_BIT(*prev_stat);
3103 : : }
3104 : 0 : *prev_stat = *stat;
3105 : 0 : }
3106 : :
3107 : : /* Get all the statistics of a VSI */
3108 : : void
3109 : 0 : i40e_update_vsi_stats(struct i40e_vsi *vsi)
3110 : : {
3111 : : struct i40e_eth_stats *oes = &vsi->eth_stats_offset;
3112 : : struct i40e_eth_stats *nes = &vsi->eth_stats;
3113 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
3114 : 0 : int idx = rte_le_to_cpu_16(vsi->info.stat_counter_idx);
3115 : :
3116 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GORCH(idx), I40E_GLV_GORCL(idx),
3117 : 0 : vsi->offset_loaded, &oes->rx_bytes,
3118 : 0 : &nes->rx_bytes, &vsi->prev_rx_bytes);
3119 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPRCH(idx), I40E_GLV_UPRCL(idx),
3120 : 0 : vsi->offset_loaded, &oes->rx_unicast,
3121 : 0 : &nes->rx_unicast);
3122 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPRCH(idx), I40E_GLV_MPRCL(idx),
3123 : 0 : vsi->offset_loaded, &oes->rx_multicast,
3124 : 0 : &nes->rx_multicast);
3125 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPRCH(idx), I40E_GLV_BPRCL(idx),
3126 : 0 : vsi->offset_loaded, &oes->rx_broadcast,
3127 : 0 : &nes->rx_broadcast);
3128 : : /* exclude CRC bytes */
3129 : 0 : nes->rx_bytes -= (nes->rx_unicast + nes->rx_multicast +
3130 : 0 : nes->rx_broadcast) * RTE_ETHER_CRC_LEN;
3131 : :
3132 : 0 : i40e_stat_update_32(hw, I40E_GLV_RDPC(idx), vsi->offset_loaded,
3133 : : &oes->rx_discards, &nes->rx_discards);
3134 : : /* GLV_REPC not supported */
3135 : : /* GLV_RMPC not supported */
3136 : 0 : i40e_stat_update_32(hw, I40E_GLV_RUPP(idx), vsi->offset_loaded,
3137 : : &oes->rx_unknown_protocol,
3138 : : &nes->rx_unknown_protocol);
3139 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GOTCH(idx), I40E_GLV_GOTCL(idx),
3140 : 0 : vsi->offset_loaded, &oes->tx_bytes,
3141 : 0 : &nes->tx_bytes, &vsi->prev_tx_bytes);
3142 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPTCH(idx), I40E_GLV_UPTCL(idx),
3143 : 0 : vsi->offset_loaded, &oes->tx_unicast,
3144 : 0 : &nes->tx_unicast);
3145 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPTCH(idx), I40E_GLV_MPTCL(idx),
3146 : 0 : vsi->offset_loaded, &oes->tx_multicast,
3147 : 0 : &nes->tx_multicast);
3148 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPTCH(idx), I40E_GLV_BPTCL(idx),
3149 : 0 : vsi->offset_loaded, &oes->tx_broadcast,
3150 : 0 : &nes->tx_broadcast);
3151 : : /* GLV_TDPC not supported */
3152 : 0 : i40e_stat_update_32(hw, I40E_GLV_TEPC(idx), vsi->offset_loaded,
3153 : : &oes->tx_errors, &nes->tx_errors);
3154 : 0 : vsi->offset_loaded = true;
3155 : :
3156 : 0 : PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats start *******************",
3157 : : vsi->vsi_id);
3158 : 0 : PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", nes->rx_bytes);
3159 : 0 : PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", nes->rx_unicast);
3160 : 0 : PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", nes->rx_multicast);
3161 : 0 : PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", nes->rx_broadcast);
3162 : 0 : PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", nes->rx_discards);
3163 : 0 : PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
3164 : : nes->rx_unknown_protocol);
3165 : 0 : PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", nes->tx_bytes);
3166 : 0 : PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", nes->tx_unicast);
3167 : 0 : PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", nes->tx_multicast);
3168 : 0 : PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", nes->tx_broadcast);
3169 : 0 : PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", nes->tx_discards);
3170 : 0 : PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", nes->tx_errors);
3171 : 0 : PMD_DRV_LOG(DEBUG, "***************** VSI[%u] stats end *******************",
3172 : : vsi->vsi_id);
3173 : 0 : }
3174 : :
3175 : : static void
3176 : 0 : i40e_read_stats_registers(struct i40e_pf *pf, struct i40e_hw *hw)
3177 : : {
3178 : : unsigned int i;
3179 : : struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
3180 : : struct i40e_hw_port_stats *os = &pf->stats_offset; /* old stats */
3181 : :
3182 : : /* Get rx/tx bytes of internal transfer packets */
3183 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GORCH(hw->port),
3184 : 0 : I40E_GLV_GORCL(hw->port),
3185 : 0 : pf->offset_loaded,
3186 : 0 : &pf->internal_stats_offset.rx_bytes,
3187 : 0 : &pf->internal_stats.rx_bytes,
3188 : : &pf->internal_prev_rx_bytes);
3189 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLV_GOTCH(hw->port),
3190 : 0 : I40E_GLV_GOTCL(hw->port),
3191 : 0 : pf->offset_loaded,
3192 : 0 : &pf->internal_stats_offset.tx_bytes,
3193 : 0 : &pf->internal_stats.tx_bytes,
3194 : : &pf->internal_prev_tx_bytes);
3195 : : /* Get total internal rx packet count */
3196 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPRCH(hw->port),
3197 : 0 : I40E_GLV_UPRCL(hw->port),
3198 : 0 : pf->offset_loaded,
3199 : 0 : &pf->internal_stats_offset.rx_unicast,
3200 : 0 : &pf->internal_stats.rx_unicast);
3201 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPRCH(hw->port),
3202 : 0 : I40E_GLV_MPRCL(hw->port),
3203 : 0 : pf->offset_loaded,
3204 : 0 : &pf->internal_stats_offset.rx_multicast,
3205 : 0 : &pf->internal_stats.rx_multicast);
3206 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPRCH(hw->port),
3207 : 0 : I40E_GLV_BPRCL(hw->port),
3208 : 0 : pf->offset_loaded,
3209 : 0 : &pf->internal_stats_offset.rx_broadcast,
3210 : 0 : &pf->internal_stats.rx_broadcast);
3211 : : /* Get total internal tx packet count */
3212 : 0 : i40e_stat_update_48(hw, I40E_GLV_UPTCH(hw->port),
3213 : 0 : I40E_GLV_UPTCL(hw->port),
3214 : 0 : pf->offset_loaded,
3215 : 0 : &pf->internal_stats_offset.tx_unicast,
3216 : 0 : &pf->internal_stats.tx_unicast);
3217 : 0 : i40e_stat_update_48(hw, I40E_GLV_MPTCH(hw->port),
3218 : 0 : I40E_GLV_MPTCL(hw->port),
3219 : 0 : pf->offset_loaded,
3220 : 0 : &pf->internal_stats_offset.tx_multicast,
3221 : 0 : &pf->internal_stats.tx_multicast);
3222 : 0 : i40e_stat_update_48(hw, I40E_GLV_BPTCH(hw->port),
3223 : 0 : I40E_GLV_BPTCL(hw->port),
3224 : 0 : pf->offset_loaded,
3225 : 0 : &pf->internal_stats_offset.tx_broadcast,
3226 : 0 : &pf->internal_stats.tx_broadcast);
3227 : :
3228 : : /* exclude CRC size */
3229 : 0 : pf->internal_stats.rx_bytes -= (pf->internal_stats.rx_unicast +
3230 : 0 : pf->internal_stats.rx_multicast +
3231 : 0 : pf->internal_stats.rx_broadcast) * RTE_ETHER_CRC_LEN;
3232 : :
3233 : : /* Get statistics of struct i40e_eth_stats */
3234 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLPRT_GORCH(hw->port),
3235 : 0 : I40E_GLPRT_GORCL(hw->port),
3236 : 0 : pf->offset_loaded, &os->eth.rx_bytes,
3237 : 0 : &ns->eth.rx_bytes, &pf->prev_rx_bytes);
3238 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_UPRCH(hw->port),
3239 : 0 : I40E_GLPRT_UPRCL(hw->port),
3240 : 0 : pf->offset_loaded, &os->eth.rx_unicast,
3241 : 0 : &ns->eth.rx_unicast);
3242 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_MPRCH(hw->port),
3243 : 0 : I40E_GLPRT_MPRCL(hw->port),
3244 : 0 : pf->offset_loaded, &os->eth.rx_multicast,
3245 : 0 : &ns->eth.rx_multicast);
3246 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_BPRCH(hw->port),
3247 : 0 : I40E_GLPRT_BPRCL(hw->port),
3248 : 0 : pf->offset_loaded, &os->eth.rx_broadcast,
3249 : 0 : &ns->eth.rx_broadcast);
3250 : : /* Workaround: CRC size should not be included in byte statistics,
3251 : : * so subtract RTE_ETHER_CRC_LEN from the byte counter for each rx
3252 : : * packet.
3253 : : */
3254 : 0 : ns->eth.rx_bytes -= (ns->eth.rx_unicast + ns->eth.rx_multicast +
3255 : 0 : ns->eth.rx_broadcast) * RTE_ETHER_CRC_LEN;
3256 : :
3257 : : /* exclude internal rx bytes
3258 : : * Workaround: it is possible I40E_GLV_GORCH[H/L] is updated before
3259 : : * I40E_GLPRT_GORCH[H/L], so there is a small window that cause negative
3260 : : * value.
3261 : : * same to I40E_GLV_UPRC[H/L], I40E_GLV_MPRC[H/L], I40E_GLV_BPRC[H/L].
3262 : : */
3263 [ # # ]: 0 : if (ns->eth.rx_bytes < pf->internal_stats.rx_bytes)
3264 : 0 : ns->eth.rx_bytes = 0;
3265 : : else
3266 : 0 : ns->eth.rx_bytes -= pf->internal_stats.rx_bytes;
3267 : :
3268 [ # # ]: 0 : if (ns->eth.rx_unicast < pf->internal_stats.rx_unicast)
3269 : 0 : ns->eth.rx_unicast = 0;
3270 : : else
3271 : 0 : ns->eth.rx_unicast -= pf->internal_stats.rx_unicast;
3272 : :
3273 [ # # ]: 0 : if (ns->eth.rx_multicast < pf->internal_stats.rx_multicast)
3274 : 0 : ns->eth.rx_multicast = 0;
3275 : : else
3276 : 0 : ns->eth.rx_multicast -= pf->internal_stats.rx_multicast;
3277 : :
3278 [ # # ]: 0 : if (ns->eth.rx_broadcast < pf->internal_stats.rx_broadcast)
3279 : 0 : ns->eth.rx_broadcast = 0;
3280 : : else
3281 : 0 : ns->eth.rx_broadcast -= pf->internal_stats.rx_broadcast;
3282 : :
3283 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RDPC(hw->port),
3284 : 0 : pf->offset_loaded, &os->eth.rx_discards,
3285 : : &ns->eth.rx_discards);
3286 : : /* GLPRT_REPC not supported */
3287 : : /* GLPRT_RMPC not supported */
3288 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RUPP(hw->port),
3289 : 0 : pf->offset_loaded,
3290 : : &os->eth.rx_unknown_protocol,
3291 : : &ns->eth.rx_unknown_protocol);
3292 : 0 : i40e_stat_update_48(hw, I40E_GL_RXERR1H(hw->pf_id + I40E_MAX_VF),
3293 : 0 : I40E_GL_RXERR1L(hw->pf_id + I40E_MAX_VF),
3294 : 0 : pf->offset_loaded, &os->rx_err1,
3295 : 0 : &ns->rx_err1);
3296 : 0 : i40e_stat_update_48_in_64(hw, I40E_GLPRT_GOTCH(hw->port),
3297 : 0 : I40E_GLPRT_GOTCL(hw->port),
3298 : 0 : pf->offset_loaded, &os->eth.tx_bytes,
3299 : 0 : &ns->eth.tx_bytes, &pf->prev_tx_bytes);
3300 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_UPTCH(hw->port),
3301 : 0 : I40E_GLPRT_UPTCL(hw->port),
3302 : 0 : pf->offset_loaded, &os->eth.tx_unicast,
3303 : 0 : &ns->eth.tx_unicast);
3304 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_MPTCH(hw->port),
3305 : 0 : I40E_GLPRT_MPTCL(hw->port),
3306 : 0 : pf->offset_loaded, &os->eth.tx_multicast,
3307 : 0 : &ns->eth.tx_multicast);
3308 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_BPTCH(hw->port),
3309 : 0 : I40E_GLPRT_BPTCL(hw->port),
3310 : 0 : pf->offset_loaded, &os->eth.tx_broadcast,
3311 : 0 : &ns->eth.tx_broadcast);
3312 : 0 : ns->eth.tx_bytes -= (ns->eth.tx_unicast + ns->eth.tx_multicast +
3313 : 0 : ns->eth.tx_broadcast) * RTE_ETHER_CRC_LEN;
3314 : :
3315 : : /* exclude internal tx bytes
3316 : : * Workaround: it is possible I40E_GLV_GOTCH[H/L] is updated before
3317 : : * I40E_GLPRT_GOTCH[H/L], so there is a small window that cause negative
3318 : : * value.
3319 : : * same to I40E_GLV_UPTC[H/L], I40E_GLV_MPTC[H/L], I40E_GLV_BPTC[H/L].
3320 : : */
3321 [ # # ]: 0 : if (ns->eth.tx_bytes < pf->internal_stats.tx_bytes)
3322 : 0 : ns->eth.tx_bytes = 0;
3323 : : else
3324 : 0 : ns->eth.tx_bytes -= pf->internal_stats.tx_bytes;
3325 : :
3326 [ # # ]: 0 : if (ns->eth.tx_unicast < pf->internal_stats.tx_unicast)
3327 : 0 : ns->eth.tx_unicast = 0;
3328 : : else
3329 : 0 : ns->eth.tx_unicast -= pf->internal_stats.tx_unicast;
3330 : :
3331 [ # # ]: 0 : if (ns->eth.tx_multicast < pf->internal_stats.tx_multicast)
3332 : 0 : ns->eth.tx_multicast = 0;
3333 : : else
3334 : 0 : ns->eth.tx_multicast -= pf->internal_stats.tx_multicast;
3335 : :
3336 [ # # ]: 0 : if (ns->eth.tx_broadcast < pf->internal_stats.tx_broadcast)
3337 : 0 : ns->eth.tx_broadcast = 0;
3338 : : else
3339 : 0 : ns->eth.tx_broadcast -= pf->internal_stats.tx_broadcast;
3340 : :
3341 : : /* GLPRT_TEPC not supported */
3342 : :
3343 : : /* additional port specific stats */
3344 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_TDOLD(hw->port),
3345 : 0 : pf->offset_loaded, &os->tx_dropped_link_down,
3346 : : &ns->tx_dropped_link_down);
3347 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_CRCERRS(hw->port),
3348 : 0 : pf->offset_loaded, &os->crc_errors,
3349 : : &ns->crc_errors);
3350 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_ILLERRC(hw->port),
3351 : 0 : pf->offset_loaded, &os->illegal_bytes,
3352 : : &ns->illegal_bytes);
3353 : : /* GLPRT_ERRBC not supported */
3354 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_MLFC(hw->port),
3355 : 0 : pf->offset_loaded, &os->mac_local_faults,
3356 : : &ns->mac_local_faults);
3357 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_MRFC(hw->port),
3358 : 0 : pf->offset_loaded, &os->mac_remote_faults,
3359 : : &ns->mac_remote_faults);
3360 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RLEC(hw->port),
3361 : 0 : pf->offset_loaded, &os->rx_length_errors,
3362 : : &ns->rx_length_errors);
3363 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXONRXC(hw->port),
3364 : 0 : pf->offset_loaded, &os->link_xon_rx,
3365 : : &ns->link_xon_rx);
3366 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
3367 : 0 : pf->offset_loaded, &os->link_xoff_rx,
3368 : : &ns->link_xoff_rx);
3369 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3370 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
3371 : 0 : pf->offset_loaded,
3372 : : &os->priority_xon_rx[i],
3373 : : &ns->priority_xon_rx[i]);
3374 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
3375 : 0 : pf->offset_loaded,
3376 : : &os->priority_xoff_rx[i],
3377 : : &ns->priority_xoff_rx[i]);
3378 : : }
3379 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXONTXC(hw->port),
3380 : 0 : pf->offset_loaded, &os->link_xon_tx,
3381 : : &ns->link_xon_tx);
3382 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
3383 : 0 : pf->offset_loaded, &os->link_xoff_tx,
3384 : : &ns->link_xoff_tx);
3385 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3386 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
3387 : 0 : pf->offset_loaded,
3388 : : &os->priority_xon_tx[i],
3389 : : &ns->priority_xon_tx[i]);
3390 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
3391 : 0 : pf->offset_loaded,
3392 : : &os->priority_xoff_tx[i],
3393 : : &ns->priority_xoff_tx[i]);
3394 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RXON2OFFCNT(hw->port, i),
3395 : 0 : pf->offset_loaded,
3396 : : &os->priority_xon_2_xoff[i],
3397 : : &ns->priority_xon_2_xoff[i]);
3398 : : }
3399 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC64H(hw->port),
3400 : 0 : I40E_GLPRT_PRC64L(hw->port),
3401 : 0 : pf->offset_loaded, &os->rx_size_64,
3402 : 0 : &ns->rx_size_64);
3403 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC127H(hw->port),
3404 : 0 : I40E_GLPRT_PRC127L(hw->port),
3405 : 0 : pf->offset_loaded, &os->rx_size_127,
3406 : 0 : &ns->rx_size_127);
3407 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC255H(hw->port),
3408 : 0 : I40E_GLPRT_PRC255L(hw->port),
3409 : 0 : pf->offset_loaded, &os->rx_size_255,
3410 : 0 : &ns->rx_size_255);
3411 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC511H(hw->port),
3412 : 0 : I40E_GLPRT_PRC511L(hw->port),
3413 : 0 : pf->offset_loaded, &os->rx_size_511,
3414 : 0 : &ns->rx_size_511);
3415 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC1023H(hw->port),
3416 : 0 : I40E_GLPRT_PRC1023L(hw->port),
3417 : 0 : pf->offset_loaded, &os->rx_size_1023,
3418 : 0 : &ns->rx_size_1023);
3419 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC1522H(hw->port),
3420 : 0 : I40E_GLPRT_PRC1522L(hw->port),
3421 : 0 : pf->offset_loaded, &os->rx_size_1522,
3422 : 0 : &ns->rx_size_1522);
3423 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PRC9522H(hw->port),
3424 : 0 : I40E_GLPRT_PRC9522L(hw->port),
3425 : 0 : pf->offset_loaded, &os->rx_size_big,
3426 : 0 : &ns->rx_size_big);
3427 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RUC(hw->port),
3428 : 0 : pf->offset_loaded, &os->rx_undersize,
3429 : : &ns->rx_undersize);
3430 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RFC(hw->port),
3431 : 0 : pf->offset_loaded, &os->rx_fragments,
3432 : : &ns->rx_fragments);
3433 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_ROC(hw->port),
3434 : 0 : pf->offset_loaded, &os->rx_oversize,
3435 : : &ns->rx_oversize);
3436 : 0 : i40e_stat_update_32(hw, I40E_GLPRT_RJC(hw->port),
3437 : 0 : pf->offset_loaded, &os->rx_jabber,
3438 : : &ns->rx_jabber);
3439 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC64H(hw->port),
3440 : 0 : I40E_GLPRT_PTC64L(hw->port),
3441 : 0 : pf->offset_loaded, &os->tx_size_64,
3442 : 0 : &ns->tx_size_64);
3443 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC127H(hw->port),
3444 : 0 : I40E_GLPRT_PTC127L(hw->port),
3445 : 0 : pf->offset_loaded, &os->tx_size_127,
3446 : 0 : &ns->tx_size_127);
3447 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC255H(hw->port),
3448 : 0 : I40E_GLPRT_PTC255L(hw->port),
3449 : 0 : pf->offset_loaded, &os->tx_size_255,
3450 : 0 : &ns->tx_size_255);
3451 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC511H(hw->port),
3452 : 0 : I40E_GLPRT_PTC511L(hw->port),
3453 : 0 : pf->offset_loaded, &os->tx_size_511,
3454 : 0 : &ns->tx_size_511);
3455 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC1023H(hw->port),
3456 : 0 : I40E_GLPRT_PTC1023L(hw->port),
3457 : 0 : pf->offset_loaded, &os->tx_size_1023,
3458 : 0 : &ns->tx_size_1023);
3459 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC1522H(hw->port),
3460 : 0 : I40E_GLPRT_PTC1522L(hw->port),
3461 : 0 : pf->offset_loaded, &os->tx_size_1522,
3462 : 0 : &ns->tx_size_1522);
3463 : 0 : i40e_stat_update_48(hw, I40E_GLPRT_PTC9522H(hw->port),
3464 : 0 : I40E_GLPRT_PTC9522L(hw->port),
3465 : 0 : pf->offset_loaded, &os->tx_size_big,
3466 : 0 : &ns->tx_size_big);
3467 : 0 : i40e_stat_update_32(hw, I40E_GLQF_PCNT(pf->fdir.match_counter_index),
3468 : 0 : pf->offset_loaded,
3469 : : &os->fd_sb_match, &ns->fd_sb_match);
3470 : : /* GLPRT_MSPDC not supported */
3471 : : /* GLPRT_XEC not supported */
3472 : :
3473 : 0 : pf->offset_loaded = true;
3474 : :
3475 [ # # ]: 0 : if (pf->main_vsi)
3476 : 0 : i40e_update_vsi_stats(pf->main_vsi);
3477 : 0 : }
3478 : :
3479 : : /* Get all statistics of a port */
3480 : : static int
3481 : 0 : i40e_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
3482 : : struct eth_queue_stats *qstats __rte_unused)
3483 : : {
3484 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3485 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3486 : : struct i40e_hw_port_stats *ns = &pf->stats; /* new stats */
3487 : : struct i40e_vsi *vsi;
3488 : : unsigned i;
3489 : :
3490 : : /* call read registers - updates values, now write them to struct */
3491 : 0 : i40e_read_stats_registers(pf, hw);
3492 : :
3493 : 0 : stats->ipackets = pf->main_vsi->eth_stats.rx_unicast +
3494 : 0 : pf->main_vsi->eth_stats.rx_multicast +
3495 : 0 : pf->main_vsi->eth_stats.rx_broadcast -
3496 : 0 : pf->main_vsi->eth_stats.rx_discards -
3497 : 0 : ns->rx_err1;
3498 : 0 : stats->opackets = ns->eth.tx_unicast +
3499 : 0 : ns->eth.tx_multicast +
3500 : 0 : ns->eth.tx_broadcast;
3501 : 0 : stats->ibytes = pf->main_vsi->eth_stats.rx_bytes;
3502 : 0 : stats->obytes = ns->eth.tx_bytes;
3503 : 0 : stats->oerrors = ns->eth.tx_errors +
3504 : 0 : pf->main_vsi->eth_stats.tx_errors;
3505 : :
3506 : : /* Rx Errors */
3507 : 0 : stats->imissed = ns->eth.rx_discards +
3508 : : pf->main_vsi->eth_stats.rx_discards;
3509 : 0 : stats->ierrors = ns->crc_errors +
3510 : 0 : ns->rx_length_errors + ns->rx_undersize +
3511 : 0 : ns->rx_oversize + ns->rx_fragments + ns->rx_jabber +
3512 : : ns->rx_err1;
3513 : :
3514 [ # # ]: 0 : if (pf->vfs) {
3515 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++) {
3516 : 0 : vsi = pf->vfs[i].vsi;
3517 : 0 : i40e_update_vsi_stats(vsi);
3518 : :
3519 : 0 : stats->ipackets += (vsi->eth_stats.rx_unicast +
3520 : 0 : vsi->eth_stats.rx_multicast +
3521 : 0 : vsi->eth_stats.rx_broadcast -
3522 : 0 : vsi->eth_stats.rx_discards);
3523 : 0 : stats->ibytes += vsi->eth_stats.rx_bytes;
3524 : 0 : stats->oerrors += vsi->eth_stats.tx_errors;
3525 : 0 : stats->imissed += vsi->eth_stats.rx_discards;
3526 : : }
3527 : : }
3528 : :
3529 : 0 : PMD_DRV_LOG(DEBUG, "***************** PF stats start *******************");
3530 : 0 : PMD_DRV_LOG(DEBUG, "rx_bytes: %"PRIu64"", ns->eth.rx_bytes);
3531 : 0 : PMD_DRV_LOG(DEBUG, "rx_unicast: %"PRIu64"", ns->eth.rx_unicast);
3532 : 0 : PMD_DRV_LOG(DEBUG, "rx_multicast: %"PRIu64"", ns->eth.rx_multicast);
3533 : 0 : PMD_DRV_LOG(DEBUG, "rx_broadcast: %"PRIu64"", ns->eth.rx_broadcast);
3534 : 0 : PMD_DRV_LOG(DEBUG, "rx_discards: %"PRIu64"", ns->eth.rx_discards);
3535 : 0 : PMD_DRV_LOG(DEBUG, "rx_unknown_protocol: %"PRIu64"",
3536 : : ns->eth.rx_unknown_protocol);
3537 : 0 : PMD_DRV_LOG(DEBUG, "tx_bytes: %"PRIu64"", ns->eth.tx_bytes);
3538 : 0 : PMD_DRV_LOG(DEBUG, "tx_unicast: %"PRIu64"", ns->eth.tx_unicast);
3539 : 0 : PMD_DRV_LOG(DEBUG, "tx_multicast: %"PRIu64"", ns->eth.tx_multicast);
3540 : 0 : PMD_DRV_LOG(DEBUG, "tx_broadcast: %"PRIu64"", ns->eth.tx_broadcast);
3541 : 0 : PMD_DRV_LOG(DEBUG, "tx_discards: %"PRIu64"", ns->eth.tx_discards);
3542 : 0 : PMD_DRV_LOG(DEBUG, "tx_errors: %"PRIu64"", ns->eth.tx_errors);
3543 : :
3544 : 0 : PMD_DRV_LOG(DEBUG, "tx_dropped_link_down: %"PRIu64"",
3545 : : ns->tx_dropped_link_down);
3546 : 0 : PMD_DRV_LOG(DEBUG, "crc_errors: %"PRIu64"", ns->crc_errors);
3547 : 0 : PMD_DRV_LOG(DEBUG, "illegal_bytes: %"PRIu64"",
3548 : : ns->illegal_bytes);
3549 : 0 : PMD_DRV_LOG(DEBUG, "error_bytes: %"PRIu64"", ns->error_bytes);
3550 : 0 : PMD_DRV_LOG(DEBUG, "mac_local_faults: %"PRIu64"",
3551 : : ns->mac_local_faults);
3552 : 0 : PMD_DRV_LOG(DEBUG, "mac_remote_faults: %"PRIu64"",
3553 : : ns->mac_remote_faults);
3554 : 0 : PMD_DRV_LOG(DEBUG, "rx_length_errors: %"PRIu64"",
3555 : : ns->rx_length_errors);
3556 : 0 : PMD_DRV_LOG(DEBUG, "link_xon_rx: %"PRIu64"", ns->link_xon_rx);
3557 : 0 : PMD_DRV_LOG(DEBUG, "link_xoff_rx: %"PRIu64"", ns->link_xoff_rx);
3558 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3559 : 0 : PMD_DRV_LOG(DEBUG, "priority_xon_rx[%d]: %"PRIu64"",
3560 : : i, ns->priority_xon_rx[i]);
3561 : 0 : PMD_DRV_LOG(DEBUG, "priority_xoff_rx[%d]: %"PRIu64"",
3562 : : i, ns->priority_xoff_rx[i]);
3563 : : }
3564 : 0 : PMD_DRV_LOG(DEBUG, "link_xon_tx: %"PRIu64"", ns->link_xon_tx);
3565 : 0 : PMD_DRV_LOG(DEBUG, "link_xoff_tx: %"PRIu64"", ns->link_xoff_tx);
3566 [ # # ]: 0 : for (i = 0; i < 8; i++) {
3567 : 0 : PMD_DRV_LOG(DEBUG, "priority_xon_tx[%d]: %"PRIu64"",
3568 : : i, ns->priority_xon_tx[i]);
3569 : 0 : PMD_DRV_LOG(DEBUG, "priority_xoff_tx[%d]: %"PRIu64"",
3570 : : i, ns->priority_xoff_tx[i]);
3571 : 0 : PMD_DRV_LOG(DEBUG, "priority_xon_2_xoff[%d]: %"PRIu64"",
3572 : : i, ns->priority_xon_2_xoff[i]);
3573 : : }
3574 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_64: %"PRIu64"", ns->rx_size_64);
3575 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_127: %"PRIu64"", ns->rx_size_127);
3576 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_255: %"PRIu64"", ns->rx_size_255);
3577 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_511: %"PRIu64"", ns->rx_size_511);
3578 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_1023: %"PRIu64"", ns->rx_size_1023);
3579 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_1522: %"PRIu64"", ns->rx_size_1522);
3580 : 0 : PMD_DRV_LOG(DEBUG, "rx_size_big: %"PRIu64"", ns->rx_size_big);
3581 : 0 : PMD_DRV_LOG(DEBUG, "rx_undersize: %"PRIu64"", ns->rx_undersize);
3582 : 0 : PMD_DRV_LOG(DEBUG, "rx_fragments: %"PRIu64"", ns->rx_fragments);
3583 : 0 : PMD_DRV_LOG(DEBUG, "rx_oversize: %"PRIu64"", ns->rx_oversize);
3584 : 0 : PMD_DRV_LOG(DEBUG, "rx_jabber: %"PRIu64"", ns->rx_jabber);
3585 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_64: %"PRIu64"", ns->tx_size_64);
3586 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_127: %"PRIu64"", ns->tx_size_127);
3587 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_255: %"PRIu64"", ns->tx_size_255);
3588 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_511: %"PRIu64"", ns->tx_size_511);
3589 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_1023: %"PRIu64"", ns->tx_size_1023);
3590 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_1522: %"PRIu64"", ns->tx_size_1522);
3591 : 0 : PMD_DRV_LOG(DEBUG, "tx_size_big: %"PRIu64"", ns->tx_size_big);
3592 : 0 : PMD_DRV_LOG(DEBUG, "mac_short_packet_dropped: %"PRIu64"",
3593 : : ns->mac_short_packet_dropped);
3594 : 0 : PMD_DRV_LOG(DEBUG, "checksum_error: %"PRIu64"",
3595 : : ns->checksum_error);
3596 : 0 : PMD_DRV_LOG(DEBUG, "fdir_match: %"PRIu64"", ns->fd_sb_match);
3597 : 0 : PMD_DRV_LOG(DEBUG, "***************** PF stats end ********************");
3598 : 0 : return 0;
3599 : : }
3600 : :
3601 : : /* Reset the statistics */
3602 : : static int
3603 : 0 : i40e_dev_stats_reset(struct rte_eth_dev *dev)
3604 : : {
3605 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3606 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3607 : :
3608 : : /* Mark PF and VSI stats to update the offset, aka "reset" */
3609 : 0 : pf->offset_loaded = false;
3610 [ # # ]: 0 : if (pf->main_vsi)
3611 : 0 : pf->main_vsi->offset_loaded = false;
3612 : :
3613 : : /* read the stats, reading current register values into offset */
3614 : 0 : i40e_read_stats_registers(pf, hw);
3615 : :
3616 : 0 : memset(&pf->mbuf_stats, 0, sizeof(struct i40e_mbuf_stats));
3617 : :
3618 : 0 : return 0;
3619 : : }
3620 : :
3621 : : static uint32_t
3622 : : i40e_xstats_calc_num(void)
3623 : : {
3624 : : return I40E_NB_ETH_XSTATS + I40E_NB_MBUF_XSTATS +
3625 : : I40E_NB_HW_PORT_XSTATS +
3626 : : (I40E_NB_RXQ_PRIO_XSTATS * 8) +
3627 : : (I40E_NB_TXQ_PRIO_XSTATS * 8);
3628 : : }
3629 : :
3630 : 0 : static int i40e_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
3631 : : struct rte_eth_xstat_name *xstats_names,
3632 : : __rte_unused unsigned limit)
3633 : : {
3634 : : unsigned count = 0;
3635 : : unsigned i, prio;
3636 : :
3637 [ # # ]: 0 : if (xstats_names == NULL)
3638 : : return i40e_xstats_calc_num();
3639 : :
3640 : : /* Note: limit checked in rte_eth_xstats_names() */
3641 : :
3642 : : /* Get stats from i40e_eth_stats struct */
3643 [ # # ]: 0 : for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
3644 : 0 : strlcpy(xstats_names[count].name,
3645 : : rte_i40e_stats_strings[i].name,
3646 : : sizeof(xstats_names[count].name));
3647 : 0 : count++;
3648 : : }
3649 : :
3650 : : /* Get stats from i40e_mbuf_stats struct */
3651 [ # # ]: 0 : for (i = 0; i < I40E_NB_MBUF_XSTATS; i++) {
3652 : 0 : strlcpy(xstats_names[count].name,
3653 : : i40e_mbuf_strings[i].name,
3654 : : sizeof(xstats_names[count].name));
3655 : 0 : count++;
3656 : : }
3657 : :
3658 : : /* Get individual stats from i40e_hw_port struct */
3659 [ # # ]: 0 : for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
3660 : 0 : strlcpy(xstats_names[count].name,
3661 : : rte_i40e_hw_port_strings[i].name,
3662 : : sizeof(xstats_names[count].name));
3663 : 0 : count++;
3664 : : }
3665 : :
3666 [ # # ]: 0 : for (i = 0; i < I40E_NB_RXQ_PRIO_XSTATS; i++) {
3667 [ # # ]: 0 : for (prio = 0; prio < 8; prio++) {
3668 : 0 : snprintf(xstats_names[count].name,
3669 : : sizeof(xstats_names[count].name),
3670 : : "rx_priority%u_%s", prio,
3671 : 0 : rte_i40e_rxq_prio_strings[i].name);
3672 : 0 : count++;
3673 : : }
3674 : : }
3675 : :
3676 [ # # ]: 0 : for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
3677 [ # # ]: 0 : for (prio = 0; prio < 8; prio++) {
3678 : 0 : snprintf(xstats_names[count].name,
3679 : : sizeof(xstats_names[count].name),
3680 : : "tx_priority%u_%s", prio,
3681 : 0 : rte_i40e_txq_prio_strings[i].name);
3682 : 0 : count++;
3683 : : }
3684 : : }
3685 : 0 : return count;
3686 : : }
3687 : :
3688 : : static void
3689 : : i40e_dev_update_mbuf_stats(struct rte_eth_dev *ethdev,
3690 : : struct i40e_mbuf_stats *mbuf_stats)
3691 : : {
3692 : : uint16_t idx;
3693 : : struct ci_tx_queue *txq;
3694 : :
3695 [ # # ]: 0 : for (idx = 0; idx < ethdev->data->nb_tx_queues; idx++) {
3696 : 0 : txq = ethdev->data->tx_queues[idx];
3697 : 0 : mbuf_stats->tx_pkt_errors += txq->mbuf_errors;
3698 : : }
3699 : : }
3700 : :
3701 : : static int
3702 : 0 : i40e_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
3703 : : unsigned n)
3704 : : {
3705 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3706 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3707 : : struct i40e_adapter *adapter =
3708 : : I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
3709 : : struct i40e_mbuf_stats mbuf_stats = {0};
3710 : : unsigned i, count, prio;
3711 : 0 : struct i40e_hw_port_stats *hw_stats = &pf->stats;
3712 : :
3713 : : count = i40e_xstats_calc_num();
3714 [ # # ]: 0 : if (n < count)
3715 : : return count;
3716 : :
3717 : 0 : i40e_read_stats_registers(pf, hw);
3718 : :
3719 [ # # ]: 0 : if (xstats == NULL)
3720 : : return 0;
3721 : :
3722 : : count = 0;
3723 : :
3724 [ # # ]: 0 : if (adapter->mbuf_check)
3725 : : i40e_dev_update_mbuf_stats(dev, &mbuf_stats);
3726 : :
3727 : : /* Get stats from i40e_eth_stats struct */
3728 [ # # ]: 0 : for (i = 0; i < I40E_NB_ETH_XSTATS; i++) {
3729 : 0 : xstats[count].value = *(uint64_t *)(((char *)&hw_stats->eth) +
3730 : 0 : rte_i40e_stats_strings[i].offset);
3731 : 0 : xstats[count].id = count;
3732 : 0 : count++;
3733 : : }
3734 : :
3735 : : /* Get stats from i40e_mbuf_stats struct */
3736 [ # # ]: 0 : for (i = 0; i < I40E_NB_MBUF_XSTATS; i++) {
3737 : 0 : xstats[count].value = *(uint64_t *)((char *)&mbuf_stats +
3738 : : i40e_mbuf_strings[i].offset);
3739 : 0 : xstats[count].id = count;
3740 : 0 : count++;
3741 : : }
3742 : :
3743 : : /* Get individual stats from i40e_hw_port struct */
3744 [ # # ]: 0 : for (i = 0; i < I40E_NB_HW_PORT_XSTATS; i++) {
3745 : 0 : xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
3746 : 0 : rte_i40e_hw_port_strings[i].offset);
3747 : 0 : xstats[count].id = count;
3748 : 0 : count++;
3749 : : }
3750 : :
3751 [ # # ]: 0 : for (i = 0; i < I40E_NB_RXQ_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_rxq_prio_strings[i].offset +
3756 : 0 : (sizeof(uint64_t) * prio));
3757 : 0 : xstats[count].id = count;
3758 : 0 : count++;
3759 : : }
3760 : : }
3761 : :
3762 [ # # ]: 0 : for (i = 0; i < I40E_NB_TXQ_PRIO_XSTATS; i++) {
3763 [ # # ]: 0 : for (prio = 0; prio < 8; prio++) {
3764 : 0 : xstats[count].value =
3765 : 0 : *(uint64_t *)(((char *)hw_stats) +
3766 : 0 : rte_i40e_txq_prio_strings[i].offset +
3767 : 0 : (sizeof(uint64_t) * prio));
3768 : 0 : xstats[count].id = count;
3769 : 0 : count++;
3770 : : }
3771 : : }
3772 : :
3773 : 0 : return count;
3774 : : }
3775 : :
3776 : : static int
3777 : 0 : i40e_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
3778 : : {
3779 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3780 : : u32 full_ver;
3781 : : u8 ver, patch;
3782 : : u16 build;
3783 : : int ret;
3784 : :
3785 : 0 : full_ver = hw->nvm.oem_ver;
3786 : 0 : ver = (u8)(full_ver >> 24);
3787 : 0 : build = (u16)((full_ver >> 8) & 0xffff);
3788 : : patch = (u8)(full_ver & 0xff);
3789 : :
3790 : 0 : ret = snprintf(fw_version, fw_size,
3791 : : "%d.%d%d 0x%08x %d.%d.%d",
3792 : : ((hw->nvm.version >> 12) & 0xf),
3793 : : ((hw->nvm.version >> 4) & 0xff),
3794 [ # # ]: 0 : (hw->nvm.version & 0xf), hw->nvm.eetrack,
3795 : : ver, build, patch);
3796 [ # # ]: 0 : if (ret < 0)
3797 : : return -EINVAL;
3798 : :
3799 : 0 : ret += 1; /* add the size of '\0' */
3800 [ # # ]: 0 : if (fw_size < (size_t)ret)
3801 : : return ret;
3802 : : else
3803 : 0 : return 0;
3804 : : }
3805 : :
3806 : : /*
3807 : : * When using NVM 6.01(for X710 XL710 XXV710)/3.33(for X722) or later,
3808 : : * the Rx data path does not hang if the FW LLDP is stopped.
3809 : : * return true if lldp need to stop
3810 : : * return false if we cannot disable the LLDP to avoid Rx data path blocking.
3811 : : */
3812 : : static bool
3813 : 0 : i40e_need_stop_lldp(struct rte_eth_dev *dev)
3814 : : {
3815 : : double nvm_ver;
3816 : 0 : char ver_str[64] = {0};
3817 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3818 : :
3819 : 0 : i40e_fw_version_get(dev, ver_str, 64);
3820 : : nvm_ver = atof(ver_str);
3821 [ # # ]: 0 : if ((hw->mac.type == I40E_MAC_X722 ||
3822 : 0 : hw->mac.type == I40E_MAC_X722_VF) &&
3823 [ # # ]: 0 : ((uint32_t)(nvm_ver * 1000) >= (uint32_t)(3.33 * 1000)))
3824 : : return true;
3825 [ # # ]: 0 : else if ((uint32_t)(nvm_ver * 1000) >= (uint32_t)(6.01 * 1000))
3826 : 0 : return true;
3827 : :
3828 : : return false;
3829 : : }
3830 : :
3831 : : static int
3832 : 0 : i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
3833 : : {
3834 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3835 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3836 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
3837 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
3838 : :
3839 : 0 : dev_info->max_rx_queues = vsi->nb_qps;
3840 : 0 : dev_info->max_tx_queues = vsi->nb_qps;
3841 : 0 : dev_info->min_rx_bufsize = I40E_BUF_SIZE_MIN;
3842 : 0 : dev_info->max_rx_pktlen = I40E_FRAME_SIZE_MAX;
3843 : 0 : dev_info->max_mac_addrs = vsi->max_macaddrs;
3844 : 0 : dev_info->max_vfs = pci_dev->max_vfs;
3845 : 0 : dev_info->max_mtu = dev_info->max_rx_pktlen - I40E_ETH_OVERHEAD;
3846 : 0 : dev_info->min_mtu = RTE_ETHER_MIN_MTU;
3847 : 0 : dev_info->rx_queue_offload_capa = 0;
3848 : 0 : dev_info->rx_offload_capa =
3849 : : RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
3850 : : RTE_ETH_RX_OFFLOAD_QINQ_STRIP |
3851 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
3852 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
3853 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
3854 : : RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM |
3855 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC |
3856 : : RTE_ETH_RX_OFFLOAD_SCATTER |
3857 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND |
3858 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
3859 : : RTE_ETH_RX_OFFLOAD_RSS_HASH;
3860 : :
3861 : 0 : dev_info->tx_queue_offload_capa = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
3862 : 0 : dev_info->tx_offload_capa =
3863 : : RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
3864 : : RTE_ETH_TX_OFFLOAD_QINQ_INSERT |
3865 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
3866 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
3867 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
3868 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
3869 : : RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
3870 : : RTE_ETH_TX_OFFLOAD_TCP_TSO |
3871 : : RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
3872 : : RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO |
3873 : : RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
3874 : : RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO |
3875 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
3876 : : dev_info->tx_queue_offload_capa;
3877 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
3878 : 0 : dev_info->tx_offload_capa |=
3879 : : RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM;
3880 : : }
3881 : :
3882 : 0 : dev_info->dev_capa =
3883 : : RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
3884 : : RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
3885 : : dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
3886 : :
3887 : 0 : dev_info->hash_key_size = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
3888 : : sizeof(uint32_t);
3889 : 0 : dev_info->reta_size = pf->hash_lut_size;
3890 : 0 : dev_info->flow_type_rss_offloads = pf->adapter->flow_types_mask;
3891 : :
3892 : 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
3893 : : .rx_thresh = {
3894 : : .pthresh = I40E_DEFAULT_RX_PTHRESH,
3895 : : .hthresh = I40E_DEFAULT_RX_HTHRESH,
3896 : : .wthresh = I40E_DEFAULT_RX_WTHRESH,
3897 : : },
3898 : : .rx_free_thresh = I40E_DEFAULT_RX_FREE_THRESH,
3899 : : .rx_drop_en = 0,
3900 : : .offloads = 0,
3901 : : };
3902 : :
3903 : 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
3904 : : .tx_thresh = {
3905 : : .pthresh = I40E_DEFAULT_TX_PTHRESH,
3906 : : .hthresh = I40E_DEFAULT_TX_HTHRESH,
3907 : : .wthresh = I40E_DEFAULT_TX_WTHRESH,
3908 : : },
3909 : : .tx_free_thresh = I40E_DEFAULT_TX_FREE_THRESH,
3910 : : .tx_rs_thresh = I40E_DEFAULT_TX_RSBIT_THRESH,
3911 : : .offloads = 0,
3912 : : };
3913 : :
3914 : 0 : dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
3915 : : .nb_max = I40E_MAX_RING_DESC,
3916 : : .nb_min = I40E_MIN_RING_DESC,
3917 : : .nb_align = I40E_ALIGN_RING_DESC,
3918 : : };
3919 : :
3920 : 0 : dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
3921 : : .nb_max = I40E_MAX_RING_DESC,
3922 : : .nb_min = I40E_MIN_RING_DESC,
3923 : : .nb_align = I40E_ALIGN_RING_DESC,
3924 : : .nb_seg_max = I40E_TX_MAX_SEG,
3925 : : .nb_mtu_seg_max = I40E_TX_MAX_MTU_SEG,
3926 : : };
3927 : :
3928 [ # # ]: 0 : if (pf->flags & I40E_FLAG_VMDQ) {
3929 : 0 : dev_info->max_vmdq_pools = pf->max_nb_vmdq_vsi;
3930 : 0 : dev_info->vmdq_queue_base = dev_info->max_rx_queues;
3931 : 0 : dev_info->vmdq_queue_num = pf->vmdq_nb_qps *
3932 : : pf->max_nb_vmdq_vsi;
3933 : 0 : dev_info->vmdq_pool_base = I40E_VMDQ_POOL_BASE;
3934 : 0 : dev_info->max_rx_queues += dev_info->vmdq_queue_num;
3935 : 0 : dev_info->max_tx_queues += dev_info->vmdq_queue_num;
3936 : : }
3937 : :
3938 [ # # ]: 0 : if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
3939 : : /* For XL710 */
3940 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_40G;
3941 : 0 : dev_info->default_rxportconf.nb_queues = 2;
3942 : 0 : dev_info->default_txportconf.nb_queues = 2;
3943 [ # # ]: 0 : if (dev->data->nb_rx_queues == 1)
3944 : 0 : dev_info->default_rxportconf.ring_size = 2048;
3945 : : else
3946 : 0 : dev_info->default_rxportconf.ring_size = 1024;
3947 [ # # ]: 0 : if (dev->data->nb_tx_queues == 1)
3948 : 0 : dev_info->default_txportconf.ring_size = 1024;
3949 : : else
3950 : 0 : dev_info->default_txportconf.ring_size = 512;
3951 : :
3952 [ # # ]: 0 : } else if (I40E_PHY_TYPE_SUPPORT_25G(hw->phy.phy_types)) {
3953 : : /* For XXV710 */
3954 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_25G;
3955 : 0 : dev_info->default_rxportconf.nb_queues = 1;
3956 : 0 : dev_info->default_txportconf.nb_queues = 1;
3957 : 0 : dev_info->default_rxportconf.ring_size = 256;
3958 : 0 : dev_info->default_txportconf.ring_size = 256;
3959 : : } else {
3960 : : /* For X710 */
3961 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_10G;
3962 : 0 : dev_info->default_rxportconf.nb_queues = 1;
3963 : 0 : dev_info->default_txportconf.nb_queues = 1;
3964 [ # # ]: 0 : if (dev->data->dev_conf.link_speeds & RTE_ETH_LINK_SPEED_10G) {
3965 : 0 : dev_info->default_rxportconf.ring_size = 512;
3966 : 0 : dev_info->default_txportconf.ring_size = 256;
3967 : : } else {
3968 : 0 : dev_info->default_rxportconf.ring_size = 256;
3969 : 0 : dev_info->default_txportconf.ring_size = 256;
3970 : : }
3971 : : }
3972 : 0 : dev_info->default_rxportconf.burst_size = 32;
3973 : 0 : dev_info->default_txportconf.burst_size = 32;
3974 : :
3975 : 0 : return 0;
3976 : : }
3977 : :
3978 : : static int
3979 : 0 : i40e_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
3980 : : {
3981 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
3982 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
3983 : 0 : PMD_INIT_FUNC_TRACE();
3984 : :
3985 [ # # ]: 0 : if (on)
3986 : 0 : return i40e_vsi_add_vlan(vsi, vlan_id);
3987 : : else
3988 : 0 : return i40e_vsi_delete_vlan(vsi, vlan_id);
3989 : : }
3990 : :
3991 : : static int
3992 : 0 : i40e_vlan_tpid_set_by_registers(struct rte_eth_dev *dev,
3993 : : enum rte_vlan_type vlan_type,
3994 : : uint16_t tpid, int qinq)
3995 : : {
3996 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3997 : 0 : uint64_t reg_r = 0;
3998 : : uint64_t reg_w = 0;
3999 : : uint16_t reg_id = 3;
4000 : : int ret;
4001 : :
4002 [ # # ]: 0 : if (qinq) {
4003 [ # # ]: 0 : if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
4004 : : reg_id = 2;
4005 : : }
4006 : :
4007 : 0 : ret = i40e_aq_debug_read_register(hw, I40E_GL_SWT_L2TAGCTRL(reg_id),
4008 : : ®_r, NULL);
4009 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
4010 : 0 : PMD_DRV_LOG(ERR,
4011 : : "Fail to debug read from I40E_GL_SWT_L2TAGCTRL[%d]",
4012 : : reg_id);
4013 : 0 : return -EIO;
4014 : : }
4015 : 0 : PMD_DRV_LOG(DEBUG,
4016 : : "Debug read from I40E_GL_SWT_L2TAGCTRL[%d]: 0x%08"PRIx64,
4017 : : reg_id, reg_r);
4018 : :
4019 : 0 : reg_w = reg_r & (~(I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_MASK));
4020 : 0 : reg_w |= ((uint64_t)tpid << I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT);
4021 [ # # ]: 0 : if (reg_r == reg_w) {
4022 : 0 : PMD_DRV_LOG(DEBUG, "No need to write");
4023 : 0 : return 0;
4024 : : }
4025 : :
4026 : 0 : ret = i40e_aq_debug_write_global_register(hw,
4027 : : I40E_GL_SWT_L2TAGCTRL(reg_id),
4028 : : reg_w, NULL);
4029 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
4030 : 0 : PMD_DRV_LOG(ERR,
4031 : : "Fail to debug write to I40E_GL_SWT_L2TAGCTRL[%d]",
4032 : : reg_id);
4033 : 0 : return -EIO;
4034 : : }
4035 : 0 : PMD_DRV_LOG(DEBUG,
4036 : : "Global register 0x%08x is changed with value 0x%08x",
4037 : : I40E_GL_SWT_L2TAGCTRL(reg_id), (uint32_t)reg_w);
4038 : :
4039 : 0 : return 0;
4040 : : }
4041 : :
4042 : : static int
4043 : 0 : i40e_vlan_tpid_set(struct rte_eth_dev *dev,
4044 : : enum rte_vlan_type vlan_type,
4045 : : uint16_t tpid)
4046 : : {
4047 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4048 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4049 : 0 : int qinq = dev->data->dev_conf.rxmode.offloads &
4050 : : RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
4051 : : u16 sw_flags = 0, valid_flags = 0;
4052 : : int ret = 0;
4053 : :
4054 [ # # ]: 0 : if ((vlan_type != RTE_ETH_VLAN_TYPE_INNER &&
4055 : 0 : vlan_type != RTE_ETH_VLAN_TYPE_OUTER) ||
4056 [ # # ]: 0 : (!qinq && vlan_type == RTE_ETH_VLAN_TYPE_INNER)) {
4057 : 0 : PMD_DRV_LOG(ERR,
4058 : : "Unsupported vlan type.");
4059 : 0 : return -EINVAL;
4060 : : }
4061 : :
4062 [ # # ]: 0 : if (pf->support_multi_driver) {
4063 : 0 : PMD_DRV_LOG(ERR, "Setting TPID is not supported.");
4064 : 0 : return -ENOTSUP;
4065 : : }
4066 : :
4067 : : /* 802.1ad frames ability is added in NVM API 1.7*/
4068 [ # # ]: 0 : if (hw->flags & I40E_HW_FLAG_802_1AD_CAPABLE) {
4069 [ # # ]: 0 : if (qinq) {
4070 [ # # ]: 0 : if (pf->fw8_3gt) {
4071 : : sw_flags = I40E_AQ_SET_SWITCH_CFG_OUTER_VLAN;
4072 : : valid_flags = I40E_AQ_SET_SWITCH_CFG_OUTER_VLAN;
4073 : : }
4074 [ # # ]: 0 : if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
4075 : 0 : hw->first_tag = rte_cpu_to_le_16(tpid);
4076 : : else if (vlan_type == RTE_ETH_VLAN_TYPE_INNER)
4077 : 0 : hw->second_tag = rte_cpu_to_le_16(tpid);
4078 : : } else {
4079 [ # # ]: 0 : if (vlan_type == RTE_ETH_VLAN_TYPE_OUTER)
4080 : 0 : hw->second_tag = rte_cpu_to_le_16(tpid);
4081 : : }
4082 : 0 : ret = i40e_aq_set_switch_config(hw, sw_flags,
4083 : : valid_flags, 0, NULL);
4084 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
4085 : 0 : PMD_DRV_LOG(ERR,
4086 : : "Set switch config failed aq_err: %d",
4087 : : hw->aq.asq_last_status);
4088 : : ret = -EIO;
4089 : : }
4090 : : } else
4091 : : /* If NVM API < 1.7, keep the register setting */
4092 : 0 : ret = i40e_vlan_tpid_set_by_registers(dev, vlan_type,
4093 : : tpid, qinq);
4094 : :
4095 : : return ret;
4096 : : }
4097 : :
4098 : : /* Configure outer vlan stripping on or off in QinQ mode */
4099 : : static int
4100 : 0 : i40e_vsi_config_outer_vlan_stripping(struct i40e_vsi *vsi, bool on)
4101 : : {
4102 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4103 : : int ret = I40E_SUCCESS;
4104 : : uint32_t reg;
4105 : :
4106 [ # # ]: 0 : if (vsi->vsi_id >= I40E_MAX_NUM_VSIS) {
4107 : 0 : PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
4108 : 0 : return -EINVAL;
4109 : : }
4110 : :
4111 : : /* Configure for outer VLAN RX stripping */
4112 : 0 : reg = I40E_READ_REG(hw, I40E_VSI_TSR(vsi->vsi_id));
4113 : :
4114 [ # # ]: 0 : if (on)
4115 : 0 : reg |= I40E_VSI_TSR_QINQ_STRIP;
4116 : : else
4117 : 0 : reg &= ~I40E_VSI_TSR_QINQ_STRIP;
4118 : :
4119 : 0 : ret = i40e_aq_debug_write_register(hw,
4120 : 0 : I40E_VSI_TSR(vsi->vsi_id),
4121 : : reg, NULL);
4122 [ # # ]: 0 : if (ret < 0) {
4123 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI_TSR[%d]",
4124 : : vsi->vsi_id);
4125 : 0 : return I40E_ERR_CONFIG;
4126 : : }
4127 : :
4128 : : return ret;
4129 : : }
4130 : :
4131 : : static int
4132 : 0 : i40e_vlan_offload_set(struct rte_eth_dev *dev, int mask)
4133 : : {
4134 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4135 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
4136 : : struct rte_eth_rxmode *rxmode;
4137 : : struct i40e_mac_filter *f;
4138 : : int i, num;
4139 : : void *temp;
4140 : : int ret;
4141 : :
4142 : : rxmode = &dev->data->dev_conf.rxmode;
4143 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_FILTER_MASK) {
4144 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
4145 : 0 : i40e_vsi_config_vlan_filter(vsi, TRUE);
4146 : : else
4147 : 0 : i40e_vsi_config_vlan_filter(vsi, FALSE);
4148 : : }
4149 : :
4150 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_STRIP_MASK) {
4151 : : /* Enable or disable VLAN stripping */
4152 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
4153 : 0 : i40e_vsi_config_vlan_stripping(vsi, TRUE);
4154 : : else
4155 : 0 : i40e_vsi_config_vlan_stripping(vsi, FALSE);
4156 : :
4157 : : /* When VLAN strip is enabled/disabled
4158 : : * after enabling outer VLAN stripping,
4159 : : * outer VLAN stripping gets disabled
4160 : : * as the register gets overridden by
4161 : : * VLAN's strip vsi param update.
4162 : : * Hence, re-enable outer VLAN stripping.
4163 : : */
4164 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP)
4165 : 0 : i40e_vsi_config_outer_vlan_stripping(vsi, TRUE);
4166 : : }
4167 : :
4168 [ # # ]: 0 : if (mask & RTE_ETH_VLAN_EXTEND_MASK) {
4169 : 0 : struct i40e_mac_filter_info mac_filter[I40E_NUM_MACADDR_MAX] = {0};
4170 : : i = 0;
4171 : 0 : num = vsi->mac_num;
4172 : :
4173 [ # # ]: 0 : if (num > I40E_NUM_MACADDR_MAX) {
4174 : 0 : PMD_DRV_LOG(ERR, "Too many MAC addresses");
4175 : 0 : return I40E_ERR_NO_MEMORY;
4176 : : }
4177 : :
4178 : : /*
4179 : : * Outer VLAN processing is supported after firmware v8.4, kernel driver
4180 : : * also change the default behavior to support this feature. To align with
4181 : : * kernel driver, set switch config in 'i40e_vlan_tpie_set' to support for
4182 : : * outer VLAN processing. But it is forbidden for firmware to change the
4183 : : * Inner/Outer VLAN configuration while there are MAC/VLAN filters in the
4184 : : * switch table. Therefore, we need to clear the MAC table before setting
4185 : : * config, and then restore the MAC table after setting. This feature is
4186 : : * recommended to be used in firmware v8.6.
4187 : : */
4188 : : /* Remove all existing mac */
4189 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp) {
4190 : 0 : mac_filter[i] = f->mac_info;
4191 : 0 : ret = i40e_vsi_delete_mac(vsi, &f->mac_info.mac_addr);
4192 [ # # ]: 0 : if (ret)
4193 : 0 : PMD_DRV_LOG(ERR, "i40e vsi delete mac fail.");
4194 : 0 : i++;
4195 : : }
4196 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND) {
4197 : : i40e_vsi_config_double_vlan(vsi, TRUE);
4198 : : /* Set global registers with default ethertype. */
4199 : 0 : i40e_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_OUTER,
4200 : : RTE_ETHER_TYPE_VLAN);
4201 : 0 : i40e_vlan_tpid_set(dev, RTE_ETH_VLAN_TYPE_INNER,
4202 : : RTE_ETHER_TYPE_VLAN);
4203 : : } else {
4204 : : i40e_vsi_config_double_vlan(vsi, FALSE);
4205 : : }
4206 : : /* Restore all mac */
4207 [ # # ]: 0 : for (i = 0; i < num; i++) {
4208 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter[i]);
4209 [ # # ]: 0 : if (ret)
4210 : 0 : PMD_DRV_LOG(ERR, "i40e vsi add mac fail.");
4211 : : }
4212 : : }
4213 : :
4214 [ # # ]: 0 : if (mask & RTE_ETH_QINQ_STRIP_MASK) {
4215 : : /* Enable or disable outer VLAN stripping */
4216 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP)
4217 : 0 : i40e_vsi_config_outer_vlan_stripping(vsi, TRUE);
4218 : : else
4219 : 0 : i40e_vsi_config_outer_vlan_stripping(vsi, FALSE);
4220 : : }
4221 : :
4222 : : return 0;
4223 : : }
4224 : :
4225 : : static void
4226 : 0 : i40e_vlan_strip_queue_set(__rte_unused struct rte_eth_dev *dev,
4227 : : __rte_unused uint16_t queue,
4228 : : __rte_unused int on)
4229 : : {
4230 : 0 : PMD_INIT_FUNC_TRACE();
4231 : 0 : }
4232 : :
4233 : : static int
4234 : 0 : i40e_vlan_pvid_set(struct rte_eth_dev *dev, uint16_t pvid, int on)
4235 : : {
4236 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4237 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
4238 [ # # ]: 0 : struct rte_eth_dev_data *data = I40E_VSI_TO_DEV_DATA(vsi);
4239 : : struct i40e_vsi_vlan_pvid_info info;
4240 : :
4241 : : memset(&info, 0, sizeof(info));
4242 : 0 : info.on = on;
4243 [ # # ]: 0 : if (info.on)
4244 : 0 : info.config.pvid = pvid;
4245 : : else {
4246 : 0 : info.config.reject.tagged =
4247 : 0 : data->dev_conf.txmode.hw_vlan_reject_tagged;
4248 : 0 : info.config.reject.untagged =
4249 : 0 : data->dev_conf.txmode.hw_vlan_reject_untagged;
4250 : : }
4251 : :
4252 : 0 : return i40e_vsi_vlan_pvid_set(vsi, &info);
4253 : : }
4254 : :
4255 : : static int
4256 : 0 : i40e_dev_led_on(struct rte_eth_dev *dev)
4257 : : {
4258 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4259 : 0 : uint32_t mode = i40e_led_get(hw);
4260 : :
4261 [ # # ]: 0 : if (mode == 0)
4262 : 0 : i40e_led_set(hw, 0xf, true); /* 0xf means led always true */
4263 : :
4264 : 0 : return 0;
4265 : : }
4266 : :
4267 : : static int
4268 : 0 : i40e_dev_led_off(struct rte_eth_dev *dev)
4269 : : {
4270 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4271 : 0 : uint32_t mode = i40e_led_get(hw);
4272 : :
4273 [ # # ]: 0 : if (mode != 0)
4274 : 0 : i40e_led_set(hw, 0, false);
4275 : :
4276 : 0 : return 0;
4277 : : }
4278 : :
4279 : : static int
4280 : 0 : i40e_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
4281 : : {
4282 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4283 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4284 : :
4285 : 0 : fc_conf->pause_time = pf->fc_conf.pause_time;
4286 : :
4287 : : /* read out from register, in case they are modified by other port */
4288 : 0 : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] =
4289 : 0 : I40E_READ_REG(hw, I40E_GLRPB_GHW) >> I40E_KILOSHIFT;
4290 : 0 : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] =
4291 : 0 : I40E_READ_REG(hw, I40E_GLRPB_GLW) >> I40E_KILOSHIFT;
4292 : :
4293 : 0 : fc_conf->high_water = pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS];
4294 : 0 : fc_conf->low_water = pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS];
4295 : :
4296 : : /* Return current mode according to actual setting*/
4297 [ # # # # ]: 0 : switch (hw->fc.current_mode) {
4298 : 0 : case I40E_FC_FULL:
4299 : 0 : fc_conf->mode = RTE_ETH_FC_FULL;
4300 : 0 : break;
4301 : 0 : case I40E_FC_TX_PAUSE:
4302 : 0 : fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
4303 : 0 : break;
4304 : 0 : case I40E_FC_RX_PAUSE:
4305 : 0 : fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
4306 : 0 : break;
4307 : 0 : case I40E_FC_NONE:
4308 : : default:
4309 : 0 : fc_conf->mode = RTE_ETH_FC_NONE;
4310 : : };
4311 : :
4312 : 0 : return 0;
4313 : : }
4314 : :
4315 : : static int
4316 : 0 : i40e_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
4317 : : {
4318 : : uint32_t mflcn_reg, fctrl_reg, reg;
4319 : : uint32_t max_high_water;
4320 : : uint8_t i, aq_failure;
4321 : : int err;
4322 : : struct i40e_hw *hw;
4323 : : struct i40e_pf *pf;
4324 : 0 : enum i40e_fc_mode rte_fcmode_2_i40e_fcmode[] = {
4325 : : [RTE_ETH_FC_NONE] = I40E_FC_NONE,
4326 : : [RTE_ETH_FC_RX_PAUSE] = I40E_FC_RX_PAUSE,
4327 : : [RTE_ETH_FC_TX_PAUSE] = I40E_FC_TX_PAUSE,
4328 : : [RTE_ETH_FC_FULL] = I40E_FC_FULL
4329 : : };
4330 : :
4331 : : /* high_water field in the rte_eth_fc_conf using the kilobytes unit */
4332 : :
4333 : : max_high_water = I40E_RXPBSIZE >> I40E_KILOSHIFT;
4334 [ # # ]: 0 : if ((fc_conf->high_water > max_high_water) ||
4335 [ # # ]: 0 : (fc_conf->high_water < fc_conf->low_water)) {
4336 : 0 : PMD_INIT_LOG(ERR,
4337 : : "Invalid high/low water setup value in KB, High_water must be <= %d.",
4338 : : max_high_water);
4339 : 0 : return -EINVAL;
4340 : : }
4341 : :
4342 : 0 : hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4343 : : pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4344 : 0 : hw->fc.requested_mode = rte_fcmode_2_i40e_fcmode[fc_conf->mode];
4345 : :
4346 : 0 : pf->fc_conf.pause_time = fc_conf->pause_time;
4347 : 0 : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->high_water;
4348 : 0 : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = fc_conf->low_water;
4349 : :
4350 : 0 : PMD_INIT_FUNC_TRACE();
4351 : :
4352 : : /* All the link flow control related enable/disable register
4353 : : * configuration is handle by the F/W
4354 : : */
4355 : 0 : err = i40e_set_fc(hw, &aq_failure, true);
4356 [ # # ]: 0 : if (err < 0)
4357 : : return -ENOSYS;
4358 : :
4359 [ # # ]: 0 : if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
4360 : : /* Configure flow control refresh threshold,
4361 : : * the value for stat_tx_pause_refresh_timer[8]
4362 : : * is used for global pause operation.
4363 : : */
4364 : :
4365 : 0 : I40E_WRITE_REG(hw,
4366 : : I40E_PRTMAC_HSEC_CTL_TX_PAUSE_REFRESH_TIMER(8),
4367 : : pf->fc_conf.pause_time);
4368 : :
4369 : : /* configure the timer value included in transmitted pause
4370 : : * frame,
4371 : : * the value for stat_tx_pause_quanta[8] is used for global
4372 : : * pause operation
4373 : : */
4374 : 0 : I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_TX_PAUSE_QUANTA(8),
4375 : : pf->fc_conf.pause_time);
4376 : :
4377 : 0 : fctrl_reg = I40E_READ_REG(hw,
4378 : : I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL);
4379 : :
4380 [ # # ]: 0 : if (fc_conf->mac_ctrl_frame_fwd != 0)
4381 : 0 : fctrl_reg |= I40E_PRTMAC_FWD_CTRL;
4382 : : else
4383 : 0 : fctrl_reg &= ~I40E_PRTMAC_FWD_CTRL;
4384 : :
4385 : 0 : I40E_WRITE_REG(hw, I40E_PRTMAC_HSEC_CTL_RX_FORWARD_CONTROL,
4386 : : fctrl_reg);
4387 : : } else {
4388 : : /* Configure pause time (2 TCs per register) */
4389 : 0 : reg = (uint32_t)pf->fc_conf.pause_time * (uint32_t)0x00010001;
4390 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS / 2; i++)
4391 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_FCTTVN(i), reg);
4392 : :
4393 : : /* Configure flow control refresh threshold value */
4394 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_FCRTV,
4395 : : pf->fc_conf.pause_time / 2);
4396 : :
4397 : 0 : mflcn_reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
4398 : :
4399 : : /* set or clear MFLCN.PMCF & MFLCN.DPF bits
4400 : : *depending on configuration
4401 : : */
4402 [ # # ]: 0 : if (fc_conf->mac_ctrl_frame_fwd != 0) {
4403 : : mflcn_reg |= I40E_PRTDCB_MFLCN_PMCF_MASK;
4404 : 0 : mflcn_reg &= ~I40E_PRTDCB_MFLCN_DPF_MASK;
4405 : : } else {
4406 : 0 : mflcn_reg &= ~I40E_PRTDCB_MFLCN_PMCF_MASK;
4407 : 0 : mflcn_reg |= I40E_PRTDCB_MFLCN_DPF_MASK;
4408 : : }
4409 : :
4410 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, mflcn_reg);
4411 : : }
4412 : :
4413 [ # # ]: 0 : if (!pf->support_multi_driver) {
4414 : : /* config water marker both based on the packets and bytes */
4415 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_PHW,
4416 : : (pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
4417 : : << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
4418 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_PLW,
4419 : : (pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
4420 : : << I40E_KILOSHIFT) / I40E_PACKET_AVERAGE_SIZE);
4421 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_GHW,
4422 : : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS]
4423 : : << I40E_KILOSHIFT);
4424 [ # # ]: 0 : I40E_WRITE_GLB_REG(hw, I40E_GLRPB_GLW,
4425 : : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS]
4426 : : << I40E_KILOSHIFT);
4427 : : } else {
4428 : 0 : PMD_DRV_LOG(ERR,
4429 : : "Water marker configuration is not supported.");
4430 : : }
4431 : :
4432 : 0 : I40E_WRITE_FLUSH(hw);
4433 : :
4434 : 0 : return 0;
4435 : : }
4436 : :
4437 : : static int
4438 : 0 : i40e_priority_flow_ctrl_set(__rte_unused struct rte_eth_dev *dev,
4439 : : __rte_unused struct rte_eth_pfc_conf *pfc_conf)
4440 : : {
4441 : 0 : PMD_INIT_FUNC_TRACE();
4442 : :
4443 : 0 : return -ENOSYS;
4444 : : }
4445 : :
4446 : : /* Add a MAC address, and update filters */
4447 : : static int
4448 : 0 : i40e_macaddr_add(struct rte_eth_dev *dev,
4449 : : struct rte_ether_addr *mac_addr,
4450 : : __rte_unused uint32_t index,
4451 : : uint32_t pool)
4452 : : {
4453 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4454 : : struct i40e_mac_filter_info mac_filter;
4455 : : struct i40e_vsi *vsi;
4456 : : struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
4457 : : int ret;
4458 : :
4459 : : /* If VMDQ not enabled or configured, return */
4460 [ # # # # ]: 0 : if (pool != 0 && (!(pf->flags & I40E_FLAG_VMDQ) ||
4461 [ # # ]: 0 : !pf->nb_cfg_vmdq_vsi)) {
4462 [ # # ]: 0 : PMD_DRV_LOG(ERR, "VMDQ not %s, can't set mac to pool %u",
4463 : : pf->flags & I40E_FLAG_VMDQ ? "configured" : "enabled",
4464 : : pool);
4465 : 0 : return -ENOTSUP;
4466 : : }
4467 : :
4468 [ # # ]: 0 : if (pool > pf->nb_cfg_vmdq_vsi) {
4469 : 0 : PMD_DRV_LOG(ERR, "Pool number %u invalid. Max pool is %u",
4470 : : pool, pf->nb_cfg_vmdq_vsi);
4471 : 0 : return -EINVAL;
4472 : : }
4473 : :
4474 : : memcpy(&mac_filter.mac_addr, mac_addr, RTE_ETHER_ADDR_LEN);
4475 [ # # ]: 0 : if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
4476 : 0 : mac_filter.filter_type = I40E_MACVLAN_PERFECT_MATCH;
4477 : : else
4478 : 0 : mac_filter.filter_type = I40E_MAC_PERFECT_MATCH;
4479 : :
4480 [ # # ]: 0 : if (pool == 0)
4481 : 0 : vsi = pf->main_vsi;
4482 : : else
4483 : 0 : vsi = pf->vmdq[pool - 1].vsi;
4484 : :
4485 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter);
4486 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
4487 : 0 : PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
4488 : 0 : return -ENODEV;
4489 : : }
4490 : : return 0;
4491 : : }
4492 : :
4493 : : /* Remove a MAC address, and update filters */
4494 : : static void
4495 : 0 : i40e_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
4496 : : {
4497 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4498 : : struct i40e_vsi *vsi;
4499 : : struct rte_eth_dev_data *data = dev->data;
4500 : : struct rte_ether_addr *macaddr;
4501 : : int ret;
4502 : : uint32_t i;
4503 : : uint64_t pool_sel;
4504 : :
4505 : 0 : macaddr = &(data->mac_addrs[index]);
4506 : :
4507 : 0 : pool_sel = dev->data->mac_pool_sel[index];
4508 : :
4509 [ # # ]: 0 : for (i = 0; i < sizeof(pool_sel) * CHAR_BIT; i++) {
4510 [ # # ]: 0 : if (pool_sel & RTE_BIT64(i)) {
4511 [ # # ]: 0 : if (i == 0)
4512 : 0 : vsi = pf->main_vsi;
4513 : : else {
4514 : : /* No VMDQ pool enabled or configured */
4515 [ # # ]: 0 : if (!(pf->flags & I40E_FLAG_VMDQ) ||
4516 [ # # ]: 0 : (i > pf->nb_cfg_vmdq_vsi)) {
4517 : 0 : PMD_DRV_LOG(ERR,
4518 : : "No VMDQ pool enabled/configured");
4519 : 0 : return;
4520 : : }
4521 : 0 : vsi = pf->vmdq[i - 1].vsi;
4522 : : }
4523 : 0 : ret = i40e_vsi_delete_mac(vsi, macaddr);
4524 : :
4525 [ # # ]: 0 : if (ret) {
4526 : 0 : PMD_DRV_LOG(ERR, "Failed to remove MACVLAN filter");
4527 : 0 : return;
4528 : : }
4529 : : }
4530 : : }
4531 : : }
4532 : :
4533 : : static int
4534 : 0 : i40e_get_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4535 : : {
4536 : 0 : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
4537 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
4538 : : uint32_t reg;
4539 : : int ret;
4540 : :
4541 [ # # ]: 0 : if (!lut)
4542 : : return -EINVAL;
4543 : :
4544 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
4545 : 0 : ret = i40e_aq_get_rss_lut(hw, vsi->vsi_id,
4546 : 0 : vsi->type != I40E_VSI_SRIOV,
4547 : : lut, lut_size);
4548 [ # # ]: 0 : if (ret) {
4549 : 0 : PMD_DRV_LOG(ERR, "Failed to get RSS lookup table");
4550 : 0 : return ret;
4551 : : }
4552 : : } else {
4553 : : uint32_t *lut_dw = (uint32_t *)lut;
4554 : 0 : uint16_t i, lut_size_dw = lut_size / 4;
4555 : :
4556 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
4557 [ # # ]: 0 : for (i = 0; i <= lut_size_dw; i++) {
4558 : 0 : reg = I40E_VFQF_HLUT1(i, vsi->user_param);
4559 : 0 : lut_dw[i] = i40e_read_rx_ctl(hw, reg);
4560 : : }
4561 : : } else {
4562 [ # # ]: 0 : for (i = 0; i < lut_size_dw; i++)
4563 : 0 : lut_dw[i] = I40E_READ_REG(hw,
4564 : : I40E_PFQF_HLUT(i));
4565 : : }
4566 : : }
4567 : :
4568 : : return 0;
4569 : : }
4570 : :
4571 : : int
4572 : 0 : i40e_set_rss_lut(struct i40e_vsi *vsi, uint8_t *lut, uint16_t lut_size)
4573 : : {
4574 : : struct i40e_pf *pf;
4575 : : struct i40e_hw *hw;
4576 : :
4577 [ # # ]: 0 : if (!vsi || !lut)
4578 : : return -EINVAL;
4579 : :
4580 : 0 : pf = I40E_VSI_TO_PF(vsi);
4581 : 0 : hw = I40E_VSI_TO_HW(vsi);
4582 : :
4583 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
4584 : : enum i40e_status_code status;
4585 : :
4586 : 0 : status = i40e_aq_set_rss_lut(hw, vsi->vsi_id,
4587 : 0 : vsi->type != I40E_VSI_SRIOV,
4588 : : lut, lut_size);
4589 [ # # ]: 0 : if (status) {
4590 : 0 : PMD_DRV_LOG(ERR,
4591 : : "Failed to update RSS lookup table, error status: %d",
4592 : : status);
4593 : 0 : return -EIO;
4594 : : }
4595 : : } else {
4596 : : uint32_t *lut_dw = (uint32_t *)lut;
4597 : 0 : uint16_t i, lut_size_dw = lut_size / 4;
4598 : :
4599 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
4600 [ # # ]: 0 : for (i = 0; i < lut_size_dw; i++)
4601 : 0 : I40E_WRITE_REG(
4602 : : hw,
4603 : : I40E_VFQF_HLUT1(i, vsi->user_param),
4604 : : lut_dw[i]);
4605 : : } else {
4606 [ # # ]: 0 : for (i = 0; i < lut_size_dw; i++)
4607 : 0 : I40E_WRITE_REG(hw, I40E_PFQF_HLUT(i),
4608 : : lut_dw[i]);
4609 : : }
4610 : 0 : I40E_WRITE_FLUSH(hw);
4611 : : }
4612 : :
4613 : : return 0;
4614 : : }
4615 : :
4616 : : static int
4617 : 0 : i40e_dev_rss_reta_update(struct rte_eth_dev *dev,
4618 : : struct rte_eth_rss_reta_entry64 *reta_conf,
4619 : : uint16_t reta_size)
4620 : : {
4621 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4622 : 0 : uint16_t i, lut_size = pf->hash_lut_size;
4623 : : uint16_t idx, shift;
4624 : 0 : uint8_t lut[RTE_ETH_RSS_RETA_SIZE_512] = {0};
4625 : : int ret;
4626 : :
4627 : 0 : if (reta_size != lut_size ||
4628 [ # # ]: 0 : reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
4629 : 0 : PMD_DRV_LOG(ERR,
4630 : : "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)",
4631 : : reta_size, lut_size);
4632 : 0 : return -EINVAL;
4633 : : }
4634 : :
4635 : 0 : ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
4636 [ # # ]: 0 : if (ret)
4637 : : return ret;
4638 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
4639 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
4640 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
4641 [ # # ]: 0 : if (reta_conf[idx].mask & RTE_BIT64(shift))
4642 : 0 : lut[i] = reta_conf[idx].reta[shift];
4643 : : }
4644 : 0 : ret = i40e_set_rss_lut(pf->main_vsi, lut, reta_size);
4645 : :
4646 : 0 : pf->adapter->rss_reta_updated = 1;
4647 : :
4648 : 0 : return ret;
4649 : : }
4650 : :
4651 : : static int
4652 : 0 : i40e_dev_rss_reta_query(struct rte_eth_dev *dev,
4653 : : struct rte_eth_rss_reta_entry64 *reta_conf,
4654 : : uint16_t reta_size)
4655 : : {
4656 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4657 : 0 : uint16_t i, lut_size = pf->hash_lut_size;
4658 : : uint16_t idx, shift;
4659 : 0 : uint8_t lut[RTE_ETH_RSS_RETA_SIZE_512] = {0};
4660 : : int ret;
4661 : :
4662 : 0 : if (reta_size != lut_size ||
4663 [ # # ]: 0 : reta_size > RTE_ETH_RSS_RETA_SIZE_512) {
4664 : 0 : PMD_DRV_LOG(ERR,
4665 : : "The size of hash lookup table configured (%d) doesn't match the number hardware can supported (%d)",
4666 : : reta_size, lut_size);
4667 : 0 : return -EINVAL;
4668 : : }
4669 : :
4670 : 0 : ret = i40e_get_rss_lut(pf->main_vsi, lut, reta_size);
4671 [ # # ]: 0 : if (ret)
4672 : : return ret;
4673 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
4674 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
4675 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
4676 [ # # ]: 0 : if (reta_conf[idx].mask & RTE_BIT64(shift))
4677 : 0 : reta_conf[idx].reta[shift] = lut[i];
4678 : : }
4679 : :
4680 : : return ret;
4681 : : }
4682 : :
4683 : : /**
4684 : : * i40e_allocate_dma_mem_d - specific memory alloc for shared code (base driver)
4685 : : * @hw: pointer to the HW structure
4686 : : * @mem: pointer to mem struct to fill out
4687 : : * @size: size of memory requested
4688 : : * @alignment: what to align the allocation to
4689 : : **/
4690 : : enum i40e_status_code
4691 : 0 : i40e_allocate_dma_mem_d(__rte_unused struct i40e_hw *hw,
4692 : : struct i40e_dma_mem *mem,
4693 : : __rte_unused enum i40e_memory_type mtype,
4694 : : u64 size,
4695 : : u32 alignment)
4696 : : {
4697 : : static RTE_ATOMIC(uint64_t) i40e_dma_memzone_id;
4698 : : const struct rte_memzone *mz = NULL;
4699 : : char z_name[RTE_MEMZONE_NAMESIZE];
4700 : :
4701 [ # # ]: 0 : if (!mem)
4702 : : return I40E_ERR_PARAM;
4703 : :
4704 : 0 : snprintf(z_name, sizeof(z_name), "i40e_dma_%" PRIu64,
4705 : : rte_atomic_fetch_add_explicit(&i40e_dma_memzone_id, 1, rte_memory_order_relaxed));
4706 : 0 : mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY,
4707 : : RTE_MEMZONE_IOVA_CONTIG, alignment, RTE_PGSIZE_2M);
4708 [ # # ]: 0 : if (!mz)
4709 : : return I40E_ERR_NO_MEMORY;
4710 : :
4711 : 0 : mem->size = size;
4712 : 0 : mem->va = mz->addr;
4713 : 0 : mem->pa = mz->iova;
4714 : 0 : mem->zone = (const void *)mz;
4715 : 0 : PMD_DRV_LOG(DEBUG,
4716 : : "memzone %s allocated with physical address: %"PRIu64,
4717 : : mz->name, mem->pa);
4718 : :
4719 : 0 : return I40E_SUCCESS;
4720 : : }
4721 : :
4722 : : /**
4723 : : * i40e_free_dma_mem_d - specific memory free for shared code (base driver)
4724 : : * @hw: pointer to the HW structure
4725 : : * @mem: ptr to mem struct to free
4726 : : **/
4727 : : enum i40e_status_code
4728 : 0 : i40e_free_dma_mem_d(__rte_unused struct i40e_hw *hw,
4729 : : struct i40e_dma_mem *mem)
4730 : : {
4731 [ # # ]: 0 : if (!mem)
4732 : : return I40E_ERR_PARAM;
4733 : :
4734 : 0 : PMD_DRV_LOG(DEBUG,
4735 : : "memzone %s to be freed with physical address: %"PRIu64,
4736 : : ((const struct rte_memzone *)mem->zone)->name, mem->pa);
4737 : 0 : rte_memzone_free((const struct rte_memzone *)mem->zone);
4738 : 0 : mem->zone = NULL;
4739 : 0 : mem->va = NULL;
4740 : 0 : mem->pa = (u64)0;
4741 : :
4742 : 0 : return I40E_SUCCESS;
4743 : : }
4744 : :
4745 : : /**
4746 : : * i40e_allocate_virt_mem_d - specific memory alloc for shared code (base driver)
4747 : : * @hw: pointer to the HW structure
4748 : : * @mem: pointer to mem struct to fill out
4749 : : * @size: size of memory requested
4750 : : **/
4751 : : enum i40e_status_code
4752 : 0 : i40e_allocate_virt_mem_d(__rte_unused struct i40e_hw *hw,
4753 : : struct i40e_virt_mem *mem,
4754 : : u32 size)
4755 : : {
4756 [ # # ]: 0 : if (!mem)
4757 : : return I40E_ERR_PARAM;
4758 : :
4759 : 0 : mem->size = size;
4760 : 0 : mem->va = rte_zmalloc("i40e", size, 0);
4761 : :
4762 [ # # ]: 0 : if (mem->va)
4763 : : return I40E_SUCCESS;
4764 : : else
4765 : 0 : return I40E_ERR_NO_MEMORY;
4766 : : }
4767 : :
4768 : : /**
4769 : : * i40e_free_virt_mem_d - specific memory free for shared code (base driver)
4770 : : * @hw: pointer to the HW structure
4771 : : * @mem: pointer to mem struct to free
4772 : : **/
4773 : : enum i40e_status_code
4774 : 0 : i40e_free_virt_mem_d(__rte_unused struct i40e_hw *hw,
4775 : : struct i40e_virt_mem *mem)
4776 : : {
4777 [ # # ]: 0 : if (!mem)
4778 : : return I40E_ERR_PARAM;
4779 : :
4780 : 0 : rte_free(mem->va);
4781 : 0 : mem->va = NULL;
4782 : :
4783 : 0 : return I40E_SUCCESS;
4784 : : }
4785 : :
4786 : : /**
4787 : : * Get the hardware capabilities, which will be parsed
4788 : : * and saved into struct i40e_hw.
4789 : : */
4790 : : static int
4791 : 0 : i40e_get_cap(struct i40e_hw *hw)
4792 : : {
4793 : : struct i40e_aqc_list_capabilities_element_resp *buf;
4794 : 0 : uint16_t len, size = 0;
4795 : : int ret;
4796 : :
4797 : : /* Calculate a huge enough buff for saving response data temporarily */
4798 : : len = sizeof(struct i40e_aqc_list_capabilities_element_resp) *
4799 : : I40E_MAX_CAP_ELE_NUM;
4800 : 0 : buf = rte_zmalloc("i40e", len, 0);
4801 [ # # ]: 0 : if (!buf) {
4802 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory");
4803 : 0 : return I40E_ERR_NO_MEMORY;
4804 : : }
4805 : :
4806 : : /* Get, parse the capabilities and save it to hw */
4807 : 0 : ret = i40e_aq_discover_capabilities(hw, buf, len, &size,
4808 : : i40e_aqc_opc_list_func_capabilities, NULL);
4809 [ # # ]: 0 : if (ret != I40E_SUCCESS)
4810 : 0 : PMD_DRV_LOG(ERR, "Failed to discover capabilities");
4811 : :
4812 : : /* Free the temporary buffer after being used */
4813 : 0 : rte_free(buf);
4814 : :
4815 : 0 : return ret;
4816 : : }
4817 : :
4818 : : #define RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF 4
4819 : :
4820 : 0 : static int i40e_pf_parse_vf_queue_number_handler(const char *key,
4821 : : const char *value,
4822 : : void *opaque)
4823 : : {
4824 : : struct i40e_pf *pf;
4825 : : unsigned long num;
4826 : : char *end;
4827 : :
4828 : : pf = (struct i40e_pf *)opaque;
4829 : : RTE_SET_USED(key);
4830 : :
4831 : 0 : errno = 0;
4832 : 0 : num = strtoul(value, &end, 0);
4833 [ # # # # : 0 : if (errno != 0 || end == value || *end != 0) {
# # ]
4834 : 0 : PMD_DRV_LOG(WARNING, "Wrong VF queue number = %s, Now it is "
4835 : : "kept the value = %hu", value, pf->vf_nb_qp_max);
4836 : 0 : return -(EINVAL);
4837 : : }
4838 : :
4839 [ # # # # ]: 0 : if (num <= I40E_MAX_QP_NUM_PER_VF && rte_is_power_of_2(num))
4840 : 0 : pf->vf_nb_qp_max = (uint16_t)num;
4841 : : else
4842 : : /* here return 0 to make next valid same argument work */
4843 : 0 : PMD_DRV_LOG(WARNING, "Wrong VF queue number = %lu, it must be "
4844 : : "power of 2 and equal or less than 16 !, Now it is "
4845 : : "kept the value = %hu", num, pf->vf_nb_qp_max);
4846 : :
4847 : : return 0;
4848 : : }
4849 : :
4850 : 0 : static int i40e_pf_config_vf_rxq_number(struct rte_eth_dev *dev)
4851 : : {
4852 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4853 : : struct rte_kvargs *kvlist;
4854 : : int kvargs_count;
4855 : :
4856 : : /* set default queue number per VF as 4 */
4857 : 0 : pf->vf_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VF;
4858 : :
4859 [ # # ]: 0 : if (dev->device->devargs == NULL)
4860 : : return 0;
4861 : :
4862 : 0 : kvlist = rte_kvargs_parse(dev->device->devargs->args, valid_keys);
4863 [ # # ]: 0 : if (kvlist == NULL)
4864 : : return -(EINVAL);
4865 : :
4866 : 0 : kvargs_count = rte_kvargs_count(kvlist, ETH_I40E_QUEUE_NUM_PER_VF_ARG);
4867 [ # # ]: 0 : if (!kvargs_count) {
4868 : 0 : rte_kvargs_free(kvlist);
4869 : 0 : return 0;
4870 : : }
4871 : :
4872 [ # # ]: 0 : if (kvargs_count > 1)
4873 : 0 : PMD_DRV_LOG(WARNING, "More than one argument \"%s\" and only "
4874 : : "the first invalid or last valid one is used !",
4875 : : ETH_I40E_QUEUE_NUM_PER_VF_ARG);
4876 : :
4877 : 0 : rte_kvargs_process(kvlist, ETH_I40E_QUEUE_NUM_PER_VF_ARG,
4878 : : i40e_pf_parse_vf_queue_number_handler, pf);
4879 : :
4880 : 0 : rte_kvargs_free(kvlist);
4881 : :
4882 : 0 : return 0;
4883 : : }
4884 : :
4885 : : static int
4886 : 0 : i40e_pf_parameter_init(struct rte_eth_dev *dev)
4887 : : {
4888 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
4889 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
4890 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
4891 : : uint16_t qp_count = 0, vsi_count = 0;
4892 : :
4893 [ # # # # ]: 0 : if (pci_dev->max_vfs && !hw->func_caps.sr_iov_1_1) {
4894 : 0 : PMD_INIT_LOG(ERR, "HW configuration doesn't support SRIOV");
4895 : 0 : return -EINVAL;
4896 : : }
4897 : :
4898 : 0 : i40e_pf_config_vf_rxq_number(dev);
4899 : :
4900 : : /* Add the parameter init for LFC */
4901 : 0 : pf->fc_conf.pause_time = I40E_DEFAULT_PAUSE_TIME;
4902 : 0 : pf->fc_conf.high_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_HIGH_WATER;
4903 : 0 : pf->fc_conf.low_water[I40E_MAX_TRAFFIC_CLASS] = I40E_DEFAULT_LOW_WATER;
4904 : :
4905 : 0 : pf->flags = I40E_FLAG_HEADER_SPLIT_DISABLED;
4906 : 0 : pf->max_num_vsi = hw->func_caps.num_vsis;
4907 : 0 : pf->lan_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_PF;
4908 : 0 : pf->vmdq_nb_qp_max = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
4909 : :
4910 : : /* FDir queue/VSI allocation */
4911 : 0 : pf->fdir_qp_offset = 0;
4912 [ # # ]: 0 : if (hw->func_caps.fd) {
4913 : 0 : pf->flags |= I40E_FLAG_FDIR;
4914 : 0 : pf->fdir_nb_qps = I40E_DEFAULT_QP_NUM_FDIR;
4915 : : } else {
4916 : 0 : pf->fdir_nb_qps = 0;
4917 : : }
4918 : 0 : qp_count += pf->fdir_nb_qps;
4919 : : vsi_count += 1;
4920 : :
4921 : : /* LAN queue/VSI allocation */
4922 : 0 : pf->lan_qp_offset = pf->fdir_qp_offset + pf->fdir_nb_qps;
4923 [ # # ]: 0 : if (!hw->func_caps.rss) {
4924 : 0 : pf->lan_nb_qps = 1;
4925 : : } else {
4926 : 0 : pf->flags |= I40E_FLAG_RSS;
4927 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
4928 : 0 : pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE;
4929 : 0 : pf->lan_nb_qps = pf->lan_nb_qp_max;
4930 : : }
4931 : 0 : qp_count += pf->lan_nb_qps;
4932 : : vsi_count += 1;
4933 : :
4934 : : /* VF queue/VSI allocation */
4935 : 0 : pf->vf_qp_offset = pf->lan_qp_offset + pf->lan_nb_qps;
4936 [ # # # # ]: 0 : if (hw->func_caps.sr_iov_1_1 && pci_dev->max_vfs) {
4937 : 0 : pf->flags |= I40E_FLAG_SRIOV;
4938 : 0 : pf->vf_nb_qps = pf->vf_nb_qp_max;
4939 : 0 : pf->vf_num = pci_dev->max_vfs;
4940 : 0 : PMD_DRV_LOG(DEBUG,
4941 : : "%u VF VSIs, %u queues per VF VSI, in total %u queues",
4942 : : pf->vf_num, pf->vf_nb_qps, pf->vf_nb_qps * pf->vf_num);
4943 : : } else {
4944 : 0 : pf->vf_nb_qps = 0;
4945 : 0 : pf->vf_num = 0;
4946 : : }
4947 : 0 : qp_count += pf->vf_nb_qps * pf->vf_num;
4948 : 0 : vsi_count += pf->vf_num;
4949 : :
4950 : : /* VMDq queue/VSI allocation */
4951 : 0 : pf->vmdq_qp_offset = pf->vf_qp_offset + pf->vf_nb_qps * pf->vf_num;
4952 : 0 : pf->vmdq_nb_qps = 0;
4953 : 0 : pf->max_nb_vmdq_vsi = 0;
4954 [ # # ]: 0 : if (hw->func_caps.vmdq) {
4955 [ # # ]: 0 : if (qp_count < hw->func_caps.num_tx_qp &&
4956 [ # # ]: 0 : vsi_count < hw->func_caps.num_vsis) {
4957 : 0 : pf->max_nb_vmdq_vsi = (hw->func_caps.num_tx_qp -
4958 : 0 : qp_count) / pf->vmdq_nb_qp_max;
4959 : :
4960 : : /* Limit the maximum number of VMDq vsi to the maximum
4961 : : * ethdev can support
4962 : : */
4963 : 0 : pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
4964 : : hw->func_caps.num_vsis - vsi_count);
4965 : 0 : pf->max_nb_vmdq_vsi = RTE_MIN(pf->max_nb_vmdq_vsi,
4966 : : RTE_ETH_64_POOLS);
4967 [ # # ]: 0 : if (pf->max_nb_vmdq_vsi) {
4968 : 0 : pf->flags |= I40E_FLAG_VMDQ;
4969 : 0 : pf->vmdq_nb_qps = pf->vmdq_nb_qp_max;
4970 : 0 : PMD_DRV_LOG(DEBUG,
4971 : : "%u VMDQ VSIs, %u queues per VMDQ VSI, in total %u queues",
4972 : : pf->max_nb_vmdq_vsi, pf->vmdq_nb_qps,
4973 : : pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi);
4974 : : } else {
4975 : 0 : PMD_DRV_LOG(INFO,
4976 : : "No enough queues left for VMDq");
4977 : : }
4978 : : } else {
4979 : 0 : PMD_DRV_LOG(INFO, "No queue or VSI left for VMDq");
4980 : : }
4981 : : }
4982 : 0 : qp_count += pf->vmdq_nb_qps * pf->max_nb_vmdq_vsi;
4983 : 0 : vsi_count += pf->max_nb_vmdq_vsi;
4984 : :
4985 [ # # ]: 0 : if (hw->func_caps.dcb)
4986 : 0 : pf->flags |= I40E_FLAG_DCB;
4987 : :
4988 [ # # ]: 0 : if (qp_count > hw->func_caps.num_tx_qp) {
4989 : 0 : PMD_DRV_LOG(ERR,
4990 : : "Failed to allocate %u queues, which exceeds the hardware maximum %u",
4991 : : qp_count, hw->func_caps.num_tx_qp);
4992 : 0 : return -EINVAL;
4993 : : }
4994 [ # # ]: 0 : if (vsi_count > hw->func_caps.num_vsis) {
4995 : 0 : PMD_DRV_LOG(ERR,
4996 : : "Failed to allocate %u VSIs, which exceeds the hardware maximum %u",
4997 : : vsi_count, hw->func_caps.num_vsis);
4998 : 0 : return -EINVAL;
4999 : : }
5000 : :
5001 : : /**
5002 : : * Enable outer VLAN processing if firmware version is greater
5003 : : * than v8.3
5004 : : */
5005 [ # # # # ]: 0 : if (hw->aq.fw_maj_ver > 8 ||
5006 [ # # ]: 0 : (hw->aq.fw_maj_ver == 8 && hw->aq.fw_min_ver > 3)) {
5007 : 0 : pf->fw8_3gt = true;
5008 : : } else {
5009 : 0 : pf->fw8_3gt = false;
5010 : : }
5011 : :
5012 : : return 0;
5013 : : }
5014 : :
5015 : : static int
5016 : 0 : i40e_pf_get_switch_config(struct i40e_pf *pf)
5017 : : {
5018 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5019 : : struct i40e_aqc_get_switch_config_resp *switch_config;
5020 : : struct i40e_aqc_switch_config_element_resp *element;
5021 : 0 : uint16_t start_seid = 0, num_reported;
5022 : : int ret;
5023 : :
5024 : : switch_config = (struct i40e_aqc_get_switch_config_resp *)\
5025 : 0 : rte_zmalloc("i40e", I40E_AQ_LARGE_BUF, 0);
5026 [ # # ]: 0 : if (!switch_config) {
5027 : 0 : PMD_DRV_LOG(ERR, "Failed to allocated memory");
5028 : 0 : return -ENOMEM;
5029 : : }
5030 : :
5031 : : /* Get the switch configurations */
5032 : 0 : ret = i40e_aq_get_switch_config(hw, switch_config,
5033 : : I40E_AQ_LARGE_BUF, &start_seid, NULL);
5034 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5035 : 0 : PMD_DRV_LOG(ERR, "Failed to get switch configurations");
5036 : 0 : goto fail;
5037 : : }
5038 : 0 : num_reported = rte_le_to_cpu_16(switch_config->header.num_reported);
5039 [ # # ]: 0 : if (num_reported != 1) { /* The number should be 1 */
5040 : 0 : PMD_DRV_LOG(ERR, "Wrong number of switch config reported");
5041 : 0 : goto fail;
5042 : : }
5043 : :
5044 : : /* Parse the switch configuration elements */
5045 : : element = &(switch_config->element[0]);
5046 [ # # ]: 0 : if (element->element_type == I40E_SWITCH_ELEMENT_TYPE_VSI) {
5047 : 0 : pf->mac_seid = rte_le_to_cpu_16(element->uplink_seid);
5048 : 0 : pf->main_vsi_seid = rte_le_to_cpu_16(element->seid);
5049 : : } else
5050 : 0 : PMD_DRV_LOG(INFO, "Unknown element type");
5051 : :
5052 : 0 : fail:
5053 : 0 : rte_free(switch_config);
5054 : :
5055 : 0 : return ret;
5056 : : }
5057 : :
5058 : : static int
5059 : 0 : i40e_res_pool_init (struct i40e_res_pool_info *pool, uint32_t base,
5060 : : uint32_t num)
5061 : : {
5062 : : struct pool_entry *entry;
5063 : :
5064 [ # # ]: 0 : if (pool == NULL || num == 0)
5065 : : return -EINVAL;
5066 : :
5067 : 0 : entry = rte_zmalloc("i40e", sizeof(*entry), 0);
5068 [ # # ]: 0 : if (entry == NULL) {
5069 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for resource pool");
5070 : 0 : return -ENOMEM;
5071 : : }
5072 : :
5073 : : /* queue heap initialize */
5074 : 0 : pool->num_free = num;
5075 : 0 : pool->num_alloc = 0;
5076 : 0 : pool->base = base;
5077 : 0 : LIST_INIT(&pool->alloc_list);
5078 : : LIST_INIT(&pool->free_list);
5079 : :
5080 : : /* Initialize element */
5081 : 0 : entry->base = 0;
5082 : 0 : entry->len = num;
5083 : :
5084 : 0 : LIST_INSERT_HEAD(&pool->free_list, entry, next);
5085 : 0 : return 0;
5086 : : }
5087 : :
5088 : : static void
5089 : 0 : i40e_res_pool_destroy(struct i40e_res_pool_info *pool)
5090 : : {
5091 : : struct pool_entry *entry, *next_entry;
5092 : :
5093 [ # # ]: 0 : if (pool == NULL)
5094 : : return;
5095 : :
5096 [ # # ]: 0 : for (entry = LIST_FIRST(&pool->alloc_list); entry; entry = next_entry) {
5097 : 0 : next_entry = LIST_NEXT(entry, next);
5098 [ # # ]: 0 : LIST_REMOVE(entry, next);
5099 : 0 : rte_free(entry);
5100 : : }
5101 : :
5102 [ # # ]: 0 : for (entry = LIST_FIRST(&pool->free_list); entry; entry = next_entry) {
5103 : 0 : next_entry = LIST_NEXT(entry, next);
5104 [ # # ]: 0 : LIST_REMOVE(entry, next);
5105 : 0 : rte_free(entry);
5106 : : }
5107 : :
5108 : 0 : pool->num_free = 0;
5109 : 0 : pool->num_alloc = 0;
5110 : 0 : pool->base = 0;
5111 : 0 : LIST_INIT(&pool->alloc_list);
5112 : 0 : LIST_INIT(&pool->free_list);
5113 : : }
5114 : :
5115 : : static int
5116 : 0 : i40e_res_pool_free(struct i40e_res_pool_info *pool,
5117 : : uint32_t base)
5118 : : {
5119 : : struct pool_entry *entry, *next, *prev, *valid_entry = NULL;
5120 : : uint32_t pool_offset;
5121 : : uint16_t len;
5122 : : int insert;
5123 : :
5124 [ # # ]: 0 : if (pool == NULL) {
5125 : 0 : PMD_DRV_LOG(ERR, "Invalid parameter");
5126 : 0 : return -EINVAL;
5127 : : }
5128 : :
5129 : 0 : pool_offset = base - pool->base;
5130 : : /* Lookup in alloc list */
5131 [ # # ]: 0 : LIST_FOREACH(entry, &pool->alloc_list, next) {
5132 [ # # ]: 0 : if (entry->base == pool_offset) {
5133 : : valid_entry = entry;
5134 [ # # ]: 0 : LIST_REMOVE(entry, next);
5135 : 0 : break;
5136 : : }
5137 : : }
5138 : :
5139 : : /* Not find, return */
5140 [ # # ]: 0 : if (valid_entry == NULL) {
5141 : 0 : PMD_DRV_LOG(ERR, "Failed to find entry");
5142 : 0 : return -EINVAL;
5143 : : }
5144 : :
5145 : : /**
5146 : : * Found it, move it to free list and try to merge.
5147 : : * In order to make merge easier, always sort it by qbase.
5148 : : * Find adjacent prev and last entries.
5149 : : */
5150 : : prev = next = NULL;
5151 [ # # ]: 0 : LIST_FOREACH(entry, &pool->free_list, next) {
5152 [ # # ]: 0 : if (entry->base > valid_entry->base) {
5153 : : next = entry;
5154 : : break;
5155 : : }
5156 : : prev = entry;
5157 : : }
5158 : :
5159 : : insert = 0;
5160 : 0 : len = valid_entry->len;
5161 : : /* Try to merge with next one*/
5162 [ # # ]: 0 : if (next != NULL) {
5163 : : /* Merge with next one */
5164 [ # # ]: 0 : if (valid_entry->base + len == next->base) {
5165 : 0 : next->base = valid_entry->base;
5166 : 0 : next->len += len;
5167 : 0 : rte_free(valid_entry);
5168 : : valid_entry = next;
5169 : : insert = 1;
5170 : : }
5171 : : }
5172 : :
5173 [ # # ]: 0 : if (prev != NULL) {
5174 : : /* Merge with previous one */
5175 [ # # ]: 0 : if (prev->base + prev->len == valid_entry->base) {
5176 : 0 : prev->len += len;
5177 : : /* If it merge with next one, remove next node */
5178 [ # # ]: 0 : if (insert == 1) {
5179 [ # # ]: 0 : LIST_REMOVE(valid_entry, next);
5180 : 0 : rte_free(valid_entry);
5181 : : valid_entry = NULL;
5182 : : } else {
5183 : 0 : rte_free(valid_entry);
5184 : : valid_entry = NULL;
5185 : : insert = 1;
5186 : : }
5187 : : }
5188 : : }
5189 : :
5190 : : /* Not find any entry to merge, insert */
5191 [ # # ]: 0 : if (insert == 0) {
5192 [ # # ]: 0 : if (prev != NULL)
5193 [ # # ]: 0 : LIST_INSERT_AFTER(prev, valid_entry, next);
5194 [ # # ]: 0 : else if (next != NULL)
5195 : 0 : LIST_INSERT_BEFORE(next, valid_entry, next);
5196 : : else /* It's empty list, insert to head */
5197 [ # # ]: 0 : LIST_INSERT_HEAD(&pool->free_list, valid_entry, next);
5198 : : }
5199 : :
5200 : 0 : pool->num_free += len;
5201 : 0 : pool->num_alloc -= len;
5202 : :
5203 : 0 : return 0;
5204 : : }
5205 : :
5206 : : static int
5207 : 0 : i40e_res_pool_alloc(struct i40e_res_pool_info *pool,
5208 : : uint16_t num)
5209 : : {
5210 : : struct pool_entry *entry, *valid_entry;
5211 : :
5212 [ # # ]: 0 : if (pool == NULL || num == 0) {
5213 : 0 : PMD_DRV_LOG(ERR, "Invalid parameter");
5214 : 0 : return -EINVAL;
5215 : : }
5216 : :
5217 [ # # ]: 0 : if (pool->num_free < num) {
5218 : 0 : PMD_DRV_LOG(ERR, "No resource. ask:%u, available:%u",
5219 : : num, pool->num_free);
5220 : 0 : return -ENOMEM;
5221 : : }
5222 : :
5223 : : valid_entry = NULL;
5224 : : /* Lookup in free list and find most fit one */
5225 [ # # ]: 0 : LIST_FOREACH(entry, &pool->free_list, next) {
5226 [ # # ]: 0 : if (entry->len >= num) {
5227 : : /* Find best one */
5228 [ # # ]: 0 : if (entry->len == num) {
5229 : : valid_entry = entry;
5230 : : break;
5231 : : }
5232 [ # # # # ]: 0 : if (valid_entry == NULL || valid_entry->len > entry->len)
5233 : : valid_entry = entry;
5234 : : }
5235 : : }
5236 : :
5237 : : /* Not find one to satisfy the request, return */
5238 [ # # ]: 0 : if (valid_entry == NULL) {
5239 : 0 : PMD_DRV_LOG(ERR, "No valid entry found");
5240 : 0 : return -ENOMEM;
5241 : : }
5242 : : /**
5243 : : * The entry have equal queue number as requested,
5244 : : * remove it from alloc_list.
5245 : : */
5246 [ # # ]: 0 : if (valid_entry->len == num) {
5247 [ # # ]: 0 : LIST_REMOVE(valid_entry, next);
5248 : : } else {
5249 : : /**
5250 : : * The entry have more numbers than requested,
5251 : : * create a new entry for alloc_list and minus its
5252 : : * queue base and number in free_list.
5253 : : */
5254 : 0 : entry = rte_zmalloc("res_pool", sizeof(*entry), 0);
5255 [ # # ]: 0 : if (entry == NULL) {
5256 : 0 : PMD_DRV_LOG(ERR,
5257 : : "Failed to allocate memory for resource pool");
5258 : 0 : return -ENOMEM;
5259 : : }
5260 : 0 : entry->base = valid_entry->base;
5261 : 0 : entry->len = num;
5262 : 0 : valid_entry->base += num;
5263 : 0 : valid_entry->len -= num;
5264 : : valid_entry = entry;
5265 : : }
5266 : :
5267 : : /* Insert it into alloc list, not sorted */
5268 [ # # ]: 0 : LIST_INSERT_HEAD(&pool->alloc_list, valid_entry, next);
5269 : :
5270 : 0 : pool->num_free -= valid_entry->len;
5271 : 0 : pool->num_alloc += valid_entry->len;
5272 : :
5273 : 0 : return valid_entry->base + pool->base;
5274 : : }
5275 : :
5276 : : /**
5277 : : * bitmap_is_subset - Check whether src2 is subset of src1
5278 : : **/
5279 : : static inline int
5280 : : bitmap_is_subset(uint8_t src1, uint8_t src2)
5281 : : {
5282 : 0 : return !((src1 ^ src2) & src2);
5283 : : }
5284 : :
5285 : : static enum i40e_status_code
5286 : 0 : validate_tcmap_parameter(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
5287 : : {
5288 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5289 : :
5290 : : /* If DCB is not supported, only default TC is supported */
5291 [ # # # # ]: 0 : if (!hw->func_caps.dcb && enabled_tcmap != I40E_DEFAULT_TCMAP) {
5292 : 0 : PMD_DRV_LOG(ERR, "DCB is not enabled, only TC0 is supported");
5293 : 0 : return I40E_NOT_SUPPORTED;
5294 : : }
5295 : :
5296 [ # # ]: 0 : if (!bitmap_is_subset(hw->func_caps.enabled_tcmap, enabled_tcmap)) {
5297 : 0 : PMD_DRV_LOG(ERR,
5298 : : "Enabled TC map 0x%x not applicable to HW support 0x%x",
5299 : : hw->func_caps.enabled_tcmap, enabled_tcmap);
5300 : 0 : return I40E_NOT_SUPPORTED;
5301 : : }
5302 : : return I40E_SUCCESS;
5303 : : }
5304 : :
5305 : : int
5306 : 0 : i40e_vsi_vlan_pvid_set(struct i40e_vsi *vsi,
5307 : : struct i40e_vsi_vlan_pvid_info *info)
5308 : : {
5309 : : struct i40e_hw *hw;
5310 : : struct i40e_vsi_context ctxt;
5311 : : uint8_t vlan_flags = 0;
5312 : : int ret;
5313 : :
5314 [ # # ]: 0 : if (vsi == NULL || info == NULL) {
5315 : 0 : PMD_DRV_LOG(ERR, "invalid parameters");
5316 : 0 : return I40E_ERR_PARAM;
5317 : : }
5318 : :
5319 [ # # ]: 0 : if (info->on) {
5320 : 0 : vsi->info.pvid = info->config.pvid;
5321 : : /**
5322 : : * If insert pvid is enabled, only tagged pkts are
5323 : : * allowed to be sent out.
5324 : : */
5325 : : vlan_flags |= I40E_AQ_VSI_PVLAN_INSERT_PVID |
5326 : : I40E_AQ_VSI_PVLAN_MODE_TAGGED;
5327 : : } else {
5328 : 0 : vsi->info.pvid = 0;
5329 [ # # ]: 0 : if (info->config.reject.tagged == 0)
5330 : : vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_TAGGED;
5331 : :
5332 [ # # ]: 0 : if (info->config.reject.untagged == 0)
5333 : 0 : vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_UNTAGGED;
5334 : : }
5335 : 0 : vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_INSERT_PVID |
5336 : : I40E_AQ_VSI_PVLAN_MODE_MASK);
5337 : 0 : vsi->info.port_vlan_flags |= vlan_flags;
5338 : 0 : vsi->info.valid_sections =
5339 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
5340 : : memset(&ctxt, 0, sizeof(ctxt));
5341 : 0 : memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
5342 : 0 : ctxt.seid = vsi->seid;
5343 : :
5344 : 0 : hw = I40E_VSI_TO_HW(vsi);
5345 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5346 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5347 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI params");
5348 : :
5349 : : return ret;
5350 : : }
5351 : :
5352 : : static int
5353 : 0 : i40e_vsi_update_tc_bandwidth(struct i40e_vsi *vsi, uint8_t enabled_tcmap)
5354 : : {
5355 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5356 : : int i, ret;
5357 : : struct i40e_aqc_configure_vsi_tc_bw_data tc_bw_data;
5358 : :
5359 : 0 : ret = validate_tcmap_parameter(vsi, enabled_tcmap);
5360 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5361 : : return ret;
5362 : :
5363 [ # # ]: 0 : if (!vsi->seid) {
5364 : 0 : PMD_DRV_LOG(ERR, "seid not valid");
5365 : 0 : return -EINVAL;
5366 : : }
5367 : :
5368 : : memset(&tc_bw_data, 0, sizeof(tc_bw_data));
5369 : 0 : tc_bw_data.tc_valid_bits = enabled_tcmap;
5370 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5371 : 0 : tc_bw_data.tc_bw_credits[i] =
5372 : 0 : (enabled_tcmap & (1 << i)) ? 1 : 0;
5373 : :
5374 : 0 : ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &tc_bw_data, NULL);
5375 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5376 : 0 : PMD_DRV_LOG(ERR, "Failed to configure TC BW");
5377 : 0 : return ret;
5378 : : }
5379 : :
5380 : 0 : memcpy(vsi->info.qs_handle, tc_bw_data.qs_handles,
5381 : : sizeof(vsi->info.qs_handle));
5382 : 0 : return I40E_SUCCESS;
5383 : : }
5384 : :
5385 : : static enum i40e_status_code
5386 : 0 : i40e_vsi_config_tc_queue_mapping(struct i40e_vsi *vsi,
5387 : : struct i40e_aqc_vsi_properties_data *info,
5388 : : uint8_t enabled_tcmap)
5389 : : {
5390 : : enum i40e_status_code ret;
5391 : : int i, total_tc = 0;
5392 : : uint16_t qpnum_per_tc, bsf, qp_idx;
5393 : :
5394 : 0 : ret = validate_tcmap_parameter(vsi, enabled_tcmap);
5395 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5396 : : return ret;
5397 : :
5398 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
5399 [ # # ]: 0 : if (enabled_tcmap & (1 << i))
5400 : 0 : total_tc++;
5401 [ # # ]: 0 : if (total_tc == 0)
5402 : : total_tc = 1;
5403 : 0 : vsi->enabled_tc = enabled_tcmap;
5404 : :
5405 : : /* Number of queues per enabled TC */
5406 [ # # ]: 0 : qpnum_per_tc = i40e_align_floor(vsi->nb_qps / total_tc);
5407 : 0 : qpnum_per_tc = RTE_MIN(qpnum_per_tc, I40E_MAX_Q_PER_TC);
5408 [ # # ]: 0 : bsf = rte_bsf32(qpnum_per_tc);
5409 : :
5410 : : /* Adjust the queue number to actual queues that can be applied */
5411 [ # # # # ]: 0 : if (!(vsi->type == I40E_VSI_MAIN && total_tc == 1))
5412 : 0 : vsi->nb_qps = qpnum_per_tc * total_tc;
5413 : :
5414 : : /**
5415 : : * Configure TC and queue mapping parameters, for enabled TC,
5416 : : * allocate qpnum_per_tc queues to this traffic. For disabled TC,
5417 : : * default queue will serve it.
5418 : : */
5419 : : qp_idx = 0;
5420 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5421 [ # # ]: 0 : if (vsi->enabled_tc & (1 << i)) {
5422 : 0 : info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
5423 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
5424 : : (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
5425 : 0 : qp_idx += qpnum_per_tc;
5426 : : } else
5427 : 0 : info->tc_mapping[i] = 0;
5428 : : }
5429 : :
5430 : : /* Associate queue number with VSI */
5431 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
5432 : 0 : info->mapping_flags |=
5433 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
5434 [ # # ]: 0 : for (i = 0; i < vsi->nb_qps; i++)
5435 : 0 : info->queue_mapping[i] =
5436 : 0 : rte_cpu_to_le_16(vsi->base_queue + i);
5437 : : } else {
5438 : 0 : info->mapping_flags |=
5439 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
5440 : 0 : info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
5441 : : }
5442 : 0 : info->valid_sections |=
5443 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
5444 : :
5445 : 0 : return I40E_SUCCESS;
5446 : : }
5447 : :
5448 : : static int
5449 : 0 : i40e_veb_release(struct i40e_veb *veb)
5450 : : {
5451 : : struct i40e_vsi *vsi;
5452 : : struct i40e_hw *hw;
5453 : :
5454 [ # # ]: 0 : if (veb == NULL)
5455 : : return -EINVAL;
5456 : :
5457 [ # # ]: 0 : if (!TAILQ_EMPTY(&veb->head)) {
5458 : 0 : PMD_DRV_LOG(ERR, "VEB still has VSI attached, can't remove");
5459 : 0 : return -EACCES;
5460 : : }
5461 : : /* associate_vsi field is NULL for floating VEB */
5462 [ # # ]: 0 : if (veb->associate_vsi != NULL) {
5463 : : vsi = veb->associate_vsi;
5464 : 0 : hw = I40E_VSI_TO_HW(vsi);
5465 : :
5466 : 0 : vsi->uplink_seid = veb->uplink_seid;
5467 : 0 : vsi->veb = NULL;
5468 : : } else {
5469 : 0 : veb->associate_pf->main_vsi->floating_veb = NULL;
5470 : 0 : hw = I40E_VSI_TO_HW(veb->associate_pf->main_vsi);
5471 : : }
5472 : :
5473 : 0 : i40e_aq_delete_element(hw, veb->seid, NULL);
5474 : 0 : rte_free(veb);
5475 : 0 : return I40E_SUCCESS;
5476 : : }
5477 : :
5478 : : /* Setup a veb */
5479 : : static struct i40e_veb *
5480 : 0 : i40e_veb_setup(struct i40e_pf *pf, struct i40e_vsi *vsi)
5481 : : {
5482 : : struct i40e_veb *veb;
5483 : : int ret;
5484 : : struct i40e_hw *hw;
5485 : :
5486 [ # # ]: 0 : if (pf == NULL) {
5487 : 0 : PMD_DRV_LOG(ERR,
5488 : : "veb setup failed, associated PF shouldn't null");
5489 : 0 : return NULL;
5490 : : }
5491 : 0 : hw = I40E_PF_TO_HW(pf);
5492 : :
5493 : 0 : veb = rte_zmalloc("i40e_veb", sizeof(struct i40e_veb), 0);
5494 [ # # ]: 0 : if (!veb) {
5495 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for veb");
5496 : 0 : goto fail;
5497 : : }
5498 : :
5499 : 0 : veb->associate_vsi = vsi;
5500 : 0 : veb->associate_pf = pf;
5501 : 0 : TAILQ_INIT(&veb->head);
5502 [ # # ]: 0 : veb->uplink_seid = vsi ? vsi->uplink_seid : 0;
5503 : :
5504 : : /* create floating veb if vsi is NULL */
5505 [ # # ]: 0 : if (vsi != NULL) {
5506 : 0 : ret = i40e_aq_add_veb(hw, veb->uplink_seid, vsi->seid,
5507 : : I40E_DEFAULT_TCMAP, false,
5508 : 0 : &veb->seid, false, NULL);
5509 : : } else {
5510 : 0 : ret = i40e_aq_add_veb(hw, 0, 0, I40E_DEFAULT_TCMAP,
5511 : 0 : true, &veb->seid, false, NULL);
5512 : : }
5513 : :
5514 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5515 : 0 : PMD_DRV_LOG(ERR, "Add veb failed, aq_err: %d",
5516 : : hw->aq.asq_last_status);
5517 : 0 : goto fail;
5518 : : }
5519 : 0 : veb->enabled_tc = I40E_DEFAULT_TCMAP;
5520 : :
5521 : : /* get statistics index */
5522 : 0 : ret = i40e_aq_get_veb_parameters(hw, veb->seid, NULL, NULL,
5523 : 0 : &veb->stats_idx, NULL, NULL, NULL);
5524 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5525 : 0 : PMD_DRV_LOG(ERR, "Get veb statistics index failed, aq_err: %d",
5526 : : hw->aq.asq_last_status);
5527 : 0 : goto fail;
5528 : : }
5529 : : /* Get VEB bandwidth, to be implemented */
5530 : : /* Now associated vsi binding to the VEB, set uplink to this VEB */
5531 [ # # ]: 0 : if (vsi)
5532 : 0 : vsi->uplink_seid = veb->seid;
5533 : :
5534 : : return veb;
5535 : 0 : fail:
5536 : 0 : rte_free(veb);
5537 : 0 : return NULL;
5538 : : }
5539 : :
5540 : : int
5541 : 0 : i40e_vsi_release(struct i40e_vsi *vsi)
5542 : : {
5543 : : struct i40e_pf *pf;
5544 : : struct i40e_hw *hw;
5545 : : struct i40e_vsi_list *vsi_list;
5546 : : void *temp;
5547 : : int ret;
5548 : : struct i40e_mac_filter *f;
5549 : : uint16_t user_param;
5550 : :
5551 [ # # ]: 0 : if (!vsi)
5552 : : return I40E_SUCCESS;
5553 : :
5554 [ # # ]: 0 : if (!vsi->adapter)
5555 : : return -EFAULT;
5556 : :
5557 : 0 : user_param = vsi->user_param;
5558 : :
5559 : : pf = I40E_VSI_TO_PF(vsi);
5560 : 0 : hw = I40E_VSI_TO_HW(vsi);
5561 : :
5562 : : /* VSI has child to attach, release child first */
5563 [ # # ]: 0 : if (vsi->veb) {
5564 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(vsi_list, &vsi->veb->head, list, temp) {
5565 [ # # ]: 0 : if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
5566 : : return -1;
5567 : : }
5568 : 0 : i40e_veb_release(vsi->veb);
5569 : : }
5570 : :
5571 [ # # ]: 0 : if (vsi->floating_veb) {
5572 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(vsi_list, &vsi->floating_veb->head,
5573 : : list, temp) {
5574 [ # # ]: 0 : if (i40e_vsi_release(vsi_list->vsi) != I40E_SUCCESS)
5575 : : return -1;
5576 : : }
5577 : : }
5578 : :
5579 : : /* Remove all macvlan filters of the VSI */
5580 : 0 : i40e_vsi_remove_all_macvlan_filter(vsi);
5581 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(f, &vsi->mac_list, next, temp)
5582 : 0 : rte_free(f);
5583 : :
5584 [ # # # # ]: 0 : if (vsi->type != I40E_VSI_MAIN &&
5585 : 0 : ((vsi->type != I40E_VSI_SRIOV) ||
5586 [ # # ]: 0 : !pf->floating_veb_list[user_param])) {
5587 : : /* Remove vsi from parent's sibling list */
5588 [ # # # # ]: 0 : if (vsi->parent_vsi == NULL || vsi->parent_vsi->veb == NULL) {
5589 : 0 : PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
5590 : 0 : return I40E_ERR_PARAM;
5591 : : }
5592 [ # # ]: 0 : TAILQ_REMOVE(&vsi->parent_vsi->veb->head,
5593 : : &vsi->sib_vsi_list, list);
5594 : :
5595 : : /* Remove all switch element of the VSI */
5596 : 0 : ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
5597 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5598 : 0 : PMD_DRV_LOG(ERR, "Failed to delete element");
5599 : : }
5600 : :
5601 [ # # ]: 0 : if ((vsi->type == I40E_VSI_SRIOV) &&
5602 [ # # ]: 0 : pf->floating_veb_list[user_param]) {
5603 : : /* Remove vsi from parent's sibling list */
5604 [ # # ]: 0 : if (vsi->parent_vsi == NULL ||
5605 [ # # ]: 0 : vsi->parent_vsi->floating_veb == NULL) {
5606 : 0 : PMD_DRV_LOG(ERR, "VSI's parent VSI is NULL");
5607 : 0 : return I40E_ERR_PARAM;
5608 : : }
5609 [ # # ]: 0 : TAILQ_REMOVE(&vsi->parent_vsi->floating_veb->head,
5610 : : &vsi->sib_vsi_list, list);
5611 : :
5612 : : /* Remove all switch element of the VSI */
5613 : 0 : ret = i40e_aq_delete_element(hw, vsi->seid, NULL);
5614 [ # # ]: 0 : if (ret != I40E_SUCCESS)
5615 : 0 : PMD_DRV_LOG(ERR, "Failed to delete element");
5616 : : }
5617 : :
5618 : 0 : i40e_res_pool_free(&pf->qp_pool, vsi->base_queue);
5619 : :
5620 [ # # ]: 0 : if (vsi->type != I40E_VSI_SRIOV)
5621 : 0 : i40e_res_pool_free(&pf->msix_pool, vsi->msix_intr);
5622 : 0 : rte_free(vsi);
5623 : :
5624 : 0 : return I40E_SUCCESS;
5625 : : }
5626 : :
5627 : : static int
5628 : 0 : i40e_update_default_filter_setting(struct i40e_vsi *vsi)
5629 : : {
5630 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
5631 : : struct i40e_aqc_remove_macvlan_element_data def_filter;
5632 : : struct i40e_mac_filter_info filter;
5633 : : int ret;
5634 : :
5635 [ # # ]: 0 : if (vsi->type != I40E_VSI_MAIN)
5636 : : return I40E_ERR_CONFIG;
5637 : : memset(&def_filter, 0, sizeof(def_filter));
5638 : : memcpy(def_filter.mac_addr, hw->mac.perm_addr,
5639 : : ETH_ADDR_LEN);
5640 : : def_filter.vlan_tag = 0;
5641 : 0 : def_filter.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
5642 : : I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
5643 : 0 : ret = i40e_aq_remove_macvlan(hw, vsi->seid, &def_filter, 1, NULL);
5644 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5645 : : struct i40e_mac_filter *f;
5646 : : struct rte_ether_addr *mac;
5647 : :
5648 : 0 : PMD_DRV_LOG(DEBUG,
5649 : : "Cannot remove the default macvlan filter");
5650 : : /* It needs to add the permanent mac into mac list */
5651 : 0 : f = rte_zmalloc("macv_filter", sizeof(*f), 0);
5652 [ # # ]: 0 : if (f == NULL) {
5653 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
5654 : 0 : return I40E_ERR_NO_MEMORY;
5655 : : }
5656 : : mac = &f->mac_info.mac_addr;
5657 : 0 : memcpy(&mac->addr_bytes, hw->mac.perm_addr,
5658 : : ETH_ADDR_LEN);
5659 : 0 : f->mac_info.filter_type = I40E_MACVLAN_PERFECT_MATCH;
5660 : 0 : TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
5661 : 0 : vsi->mac_num++;
5662 : :
5663 : 0 : return ret;
5664 : : }
5665 : : memcpy(&filter.mac_addr,
5666 : 0 : (struct rte_ether_addr *)(hw->mac.perm_addr), ETH_ADDR_LEN);
5667 : 0 : filter.filter_type = I40E_MACVLAN_PERFECT_MATCH;
5668 : 0 : return i40e_vsi_add_mac(vsi, &filter);
5669 : : }
5670 : :
5671 : : /*
5672 : : * i40e_vsi_get_bw_config - Query VSI BW Information
5673 : : * @vsi: the VSI to be queried
5674 : : *
5675 : : * Returns 0 on success, negative value on failure
5676 : : */
5677 : : static enum i40e_status_code
5678 : 0 : i40e_vsi_get_bw_config(struct i40e_vsi *vsi)
5679 : : {
5680 : : struct i40e_aqc_query_vsi_bw_config_resp bw_config;
5681 : : struct i40e_aqc_query_vsi_ets_sla_config_resp ets_sla_config;
5682 : 0 : struct i40e_hw *hw = &vsi->adapter->hw;
5683 : : i40e_status ret;
5684 : : int i;
5685 : : uint32_t bw_max;
5686 : :
5687 : : memset(&bw_config, 0, sizeof(bw_config));
5688 : 0 : ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
5689 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5690 : 0 : PMD_DRV_LOG(ERR, "VSI failed to get bandwidth configuration %u",
5691 : : hw->aq.asq_last_status);
5692 : 0 : return ret;
5693 : : }
5694 : :
5695 : : memset(&ets_sla_config, 0, sizeof(ets_sla_config));
5696 : 0 : ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid,
5697 : : &ets_sla_config, NULL);
5698 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5699 : 0 : PMD_DRV_LOG(ERR,
5700 : : "VSI failed to get TC bandwidth configuration %u",
5701 : : hw->aq.asq_last_status);
5702 : 0 : return ret;
5703 : : }
5704 : :
5705 : : /* store and print out BW info */
5706 : 0 : vsi->bw_info.bw_limit = rte_le_to_cpu_16(bw_config.port_bw_limit);
5707 : 0 : vsi->bw_info.bw_max = bw_config.max_bw;
5708 : 0 : PMD_DRV_LOG(DEBUG, "VSI bw limit:%u", vsi->bw_info.bw_limit);
5709 : 0 : PMD_DRV_LOG(DEBUG, "VSI max_bw:%u", vsi->bw_info.bw_max);
5710 : 0 : bw_max = rte_le_to_cpu_16(ets_sla_config.tc_bw_max[0]) |
5711 : 0 : (rte_le_to_cpu_16(ets_sla_config.tc_bw_max[1]) <<
5712 : : I40E_16_BIT_WIDTH);
5713 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
5714 : 0 : vsi->bw_info.bw_ets_share_credits[i] =
5715 : 0 : ets_sla_config.share_credits[i];
5716 : 0 : vsi->bw_info.bw_ets_credits[i] =
5717 : 0 : rte_le_to_cpu_16(ets_sla_config.credits[i]);
5718 : : /* 4 bits per TC, 4th bit is reserved */
5719 : 0 : vsi->bw_info.bw_ets_max[i] =
5720 : 0 : (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
5721 : : RTE_LEN2MASK(3, uint8_t));
5722 : 0 : PMD_DRV_LOG(DEBUG, "\tVSI TC%u:share credits %u", i,
5723 : : vsi->bw_info.bw_ets_share_credits[i]);
5724 : 0 : PMD_DRV_LOG(DEBUG, "\tVSI TC%u:credits %u", i,
5725 : : vsi->bw_info.bw_ets_credits[i]);
5726 : 0 : PMD_DRV_LOG(DEBUG, "\tVSI TC%u: max credits: %u", i,
5727 : : vsi->bw_info.bw_ets_max[i]);
5728 : : }
5729 : :
5730 : : return I40E_SUCCESS;
5731 : : }
5732 : :
5733 : : /* i40e_enable_pf_lb
5734 : : * @pf: pointer to the pf structure
5735 : : *
5736 : : * allow loopback on pf
5737 : : */
5738 : : static inline void
5739 : 0 : i40e_enable_pf_lb(struct i40e_pf *pf)
5740 : : {
5741 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5742 : : struct i40e_vsi_context ctxt;
5743 : : int ret;
5744 : :
5745 : : /* Use the FW API if FW >= v5.0 */
5746 [ # # # # ]: 0 : if (hw->aq.fw_maj_ver < 5 && hw->mac.type != I40E_MAC_X722) {
5747 : 0 : PMD_INIT_LOG(ERR, "FW < v5.0, cannot enable loopback");
5748 : 0 : return;
5749 : : }
5750 : :
5751 : : memset(&ctxt, 0, sizeof(ctxt));
5752 : 0 : ctxt.seid = pf->main_vsi_seid;
5753 : 0 : ctxt.pf_num = hw->pf_id;
5754 : 0 : ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5755 [ # # ]: 0 : if (ret) {
5756 : 0 : PMD_DRV_LOG(ERR, "cannot get pf vsi config, err %d, aq_err %d",
5757 : : ret, hw->aq.asq_last_status);
5758 : 0 : return;
5759 : : }
5760 : 0 : ctxt.flags = I40E_AQ_VSI_TYPE_PF;
5761 : 0 : ctxt.info.valid_sections =
5762 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5763 : 0 : ctxt.info.switch_id |=
5764 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
5765 : :
5766 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5767 [ # # ]: 0 : if (ret)
5768 : 0 : PMD_DRV_LOG(ERR, "update vsi switch failed, aq_err=%d",
5769 : : hw->aq.asq_last_status);
5770 : : }
5771 : :
5772 : : /* i40e_pf_set_source_prune
5773 : : * @pf: pointer to the pf structure
5774 : : * @on: Enable/disable source prune
5775 : : *
5776 : : * set source prune on pf
5777 : : */
5778 : : int
5779 : 0 : i40e_pf_set_source_prune(struct i40e_pf *pf, int on)
5780 : : {
5781 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5782 : : struct i40e_vsi_context ctxt;
5783 : : int ret;
5784 : :
5785 : : memset(&ctxt, 0, sizeof(ctxt));
5786 : 0 : ctxt.seid = pf->main_vsi_seid;
5787 : 0 : ctxt.pf_num = hw->pf_id;
5788 : 0 : ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5789 [ # # ]: 0 : if (ret) {
5790 : 0 : PMD_DRV_LOG(ERR, "cannot get pf vsi config, err %d, aq_err %d",
5791 : : ret, hw->aq.asq_last_status);
5792 : 0 : return ret;
5793 : : }
5794 : 0 : ctxt.flags = I40E_AQ_VSI_TYPE_PF;
5795 : 0 : ctxt.info.valid_sections =
5796 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
5797 [ # # ]: 0 : if (on)
5798 : 0 : ctxt.info.switch_id &=
5799 : : ~rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
5800 : : else
5801 : 0 : ctxt.info.switch_id |=
5802 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
5803 : :
5804 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
5805 [ # # ]: 0 : if (ret)
5806 : 0 : PMD_DRV_LOG(ERR, "update vsi switch failed, aq_err=%d",
5807 : : hw->aq.asq_last_status);
5808 : :
5809 : : return ret;
5810 : : }
5811 : :
5812 : : /* Setup a VSI */
5813 : : struct i40e_vsi *
5814 : 0 : i40e_vsi_setup(struct i40e_pf *pf,
5815 : : enum i40e_vsi_type type,
5816 : : struct i40e_vsi *uplink_vsi,
5817 : : uint16_t user_param)
5818 : : {
5819 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
5820 : : struct i40e_vsi *vsi;
5821 : : struct i40e_mac_filter_info filter;
5822 : : int ret;
5823 : : struct i40e_vsi_context ctxt;
5824 : 0 : struct rte_ether_addr broadcast =
5825 : : {.addr_bytes = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}};
5826 : :
5827 [ # # # # ]: 0 : if (type != I40E_VSI_MAIN && type != I40E_VSI_SRIOV &&
5828 : : uplink_vsi == NULL) {
5829 : 0 : PMD_DRV_LOG(ERR,
5830 : : "VSI setup failed, VSI link shouldn't be NULL");
5831 : 0 : return NULL;
5832 : : }
5833 : :
5834 [ # # ]: 0 : if (type == I40E_VSI_MAIN && uplink_vsi != NULL) {
5835 : 0 : PMD_DRV_LOG(ERR,
5836 : : "VSI setup failed, MAIN VSI uplink VSI should be NULL");
5837 : 0 : return NULL;
5838 : : }
5839 : :
5840 : : /* two situations
5841 : : * 1.type is not MAIN and uplink vsi is not NULL
5842 : : * If uplink vsi didn't setup VEB, create one first under veb field
5843 : : * 2.type is SRIOV and the uplink is NULL
5844 : : * If floating VEB is NULL, create one veb under floating veb field
5845 : : */
5846 : :
5847 [ # # ]: 0 : if (type != I40E_VSI_MAIN && uplink_vsi != NULL &&
5848 [ # # ]: 0 : uplink_vsi->veb == NULL) {
5849 : 0 : uplink_vsi->veb = i40e_veb_setup(pf, uplink_vsi);
5850 : :
5851 [ # # ]: 0 : if (uplink_vsi->veb == NULL) {
5852 : 0 : PMD_DRV_LOG(ERR, "VEB setup failed");
5853 : 0 : return NULL;
5854 : : }
5855 : : /* set ALLOWLOOPBACk on pf, when veb is created */
5856 : 0 : i40e_enable_pf_lb(pf);
5857 : : }
5858 : :
5859 [ # # ]: 0 : if (type == I40E_VSI_SRIOV && uplink_vsi == NULL &&
5860 [ # # ]: 0 : pf->main_vsi->floating_veb == NULL) {
5861 : 0 : pf->main_vsi->floating_veb = i40e_veb_setup(pf, uplink_vsi);
5862 : :
5863 [ # # ]: 0 : if (pf->main_vsi->floating_veb == NULL) {
5864 : 0 : PMD_DRV_LOG(ERR, "VEB setup failed");
5865 : 0 : return NULL;
5866 : : }
5867 : : }
5868 : :
5869 : : /* source prune is disabled to support VRRP in default*/
5870 : 0 : i40e_pf_set_source_prune(pf, 0);
5871 : :
5872 : 0 : vsi = rte_zmalloc("i40e_vsi", sizeof(struct i40e_vsi), 0);
5873 [ # # ]: 0 : if (!vsi) {
5874 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory for vsi");
5875 : 0 : return NULL;
5876 : : }
5877 : 0 : TAILQ_INIT(&vsi->mac_list);
5878 : 0 : vsi->type = type;
5879 : 0 : vsi->adapter = I40E_PF_TO_ADAPTER(pf);
5880 : 0 : vsi->max_macaddrs = I40E_NUM_MACADDR_MAX;
5881 [ # # ]: 0 : vsi->parent_vsi = uplink_vsi ? uplink_vsi : pf->main_vsi;
5882 : 0 : vsi->user_param = user_param;
5883 : 0 : vsi->vlan_anti_spoof_on = 0;
5884 : 0 : vsi->vlan_filter_on = 0;
5885 : : /* Allocate queues */
5886 [ # # # # : 0 : switch (vsi->type) {
# ]
5887 : 0 : case I40E_VSI_MAIN :
5888 : 0 : vsi->nb_qps = pf->lan_nb_qps;
5889 : 0 : break;
5890 : 0 : case I40E_VSI_SRIOV :
5891 : 0 : vsi->nb_qps = pf->vf_nb_qps;
5892 : 0 : break;
5893 : 0 : case I40E_VSI_VMDQ2:
5894 : 0 : vsi->nb_qps = pf->vmdq_nb_qps;
5895 : 0 : break;
5896 : 0 : case I40E_VSI_FDIR:
5897 : 0 : vsi->nb_qps = pf->fdir_nb_qps;
5898 : 0 : break;
5899 : 0 : default:
5900 : 0 : goto fail_mem;
5901 : : }
5902 : : /*
5903 : : * The filter status descriptor is reported in rx queue 0,
5904 : : * while the tx queue for fdir filter programming has no
5905 : : * such constraints, can be non-zero queues.
5906 : : * To simplify it, choose FDIR vsi use queue 0 pair.
5907 : : * To make sure it will use queue 0 pair, queue allocation
5908 : : * need be done before this function is called
5909 : : */
5910 [ # # ]: 0 : if (type != I40E_VSI_FDIR) {
5911 : 0 : ret = i40e_res_pool_alloc(&pf->qp_pool, vsi->nb_qps);
5912 [ # # ]: 0 : if (ret < 0) {
5913 : 0 : PMD_DRV_LOG(ERR, "VSI %d allocate queue failed %d",
5914 : : vsi->seid, ret);
5915 : 0 : goto fail_mem;
5916 : : }
5917 : 0 : vsi->base_queue = ret;
5918 : : } else
5919 : 0 : vsi->base_queue = I40E_FDIR_QUEUE_ID;
5920 : :
5921 : : /* VF has MSIX interrupt in VF range, don't allocate here */
5922 [ # # ]: 0 : if (type == I40E_VSI_MAIN) {
5923 [ # # ]: 0 : if (pf->support_multi_driver) {
5924 : : /* If support multi-driver, need to use INT0 instead of
5925 : : * allocating from msix pool. The Msix pool is init from
5926 : : * INT1, so it's OK just set msix_intr to 0 and nb_msix
5927 : : * to 1 without calling i40e_res_pool_alloc.
5928 : : */
5929 : 0 : vsi->msix_intr = 0;
5930 : 0 : vsi->nb_msix = 1;
5931 : : } else {
5932 : 0 : ret = i40e_res_pool_alloc(&pf->msix_pool,
5933 : 0 : RTE_MIN(vsi->nb_qps,
5934 : : RTE_MAX_RXTX_INTR_VEC_ID));
5935 [ # # ]: 0 : if (ret < 0) {
5936 : 0 : PMD_DRV_LOG(ERR,
5937 : : "VSI MAIN %d get heap failed %d",
5938 : : vsi->seid, ret);
5939 : 0 : goto fail_queue_alloc;
5940 : : }
5941 : 0 : vsi->msix_intr = ret;
5942 : 0 : vsi->nb_msix = RTE_MIN(vsi->nb_qps,
5943 : : RTE_MAX_RXTX_INTR_VEC_ID);
5944 : : }
5945 [ # # ]: 0 : } else if (type != I40E_VSI_SRIOV) {
5946 : 0 : ret = i40e_res_pool_alloc(&pf->msix_pool, 1);
5947 [ # # ]: 0 : if (ret < 0) {
5948 : 0 : PMD_DRV_LOG(ERR, "VSI %d get heap failed %d", vsi->seid, ret);
5949 [ # # ]: 0 : if (type != I40E_VSI_FDIR)
5950 : 0 : goto fail_queue_alloc;
5951 : 0 : vsi->msix_intr = 0;
5952 : 0 : vsi->nb_msix = 0;
5953 : : } else {
5954 : 0 : vsi->msix_intr = ret;
5955 : 0 : vsi->nb_msix = 1;
5956 : : }
5957 : : } else {
5958 : 0 : vsi->msix_intr = 0;
5959 : 0 : vsi->nb_msix = 0;
5960 : : }
5961 : :
5962 : : /* Add VSI */
5963 [ # # ]: 0 : if (type == I40E_VSI_MAIN) {
5964 : : /* For main VSI, no need to add since it's default one */
5965 : 0 : vsi->uplink_seid = pf->mac_seid;
5966 : 0 : vsi->seid = pf->main_vsi_seid;
5967 : : /* Bind queues with specific MSIX interrupt */
5968 : : /**
5969 : : * Needs 2 interrupt at least, one for misc cause which will
5970 : : * enabled from OS side, Another for queues binding the
5971 : : * interrupt from device side only.
5972 : : */
5973 : :
5974 : : /* Get default VSI parameters from hardware */
5975 : : memset(&ctxt, 0, sizeof(ctxt));
5976 : 0 : ctxt.seid = vsi->seid;
5977 : 0 : ctxt.pf_num = hw->pf_id;
5978 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
5979 : : ctxt.vf_num = 0;
5980 : 0 : ret = i40e_aq_get_vsi_params(hw, &ctxt, NULL);
5981 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
5982 : 0 : PMD_DRV_LOG(ERR, "Failed to get VSI params");
5983 : 0 : goto fail_msix_alloc;
5984 : : }
5985 : 0 : vsi->info = ctxt.info;
5986 : 0 : vsi->vsi_id = ctxt.vsi_number;
5987 : 0 : vsi->info.valid_sections = 0;
5988 : :
5989 : : /* Configure tc, enabled TC0 only */
5990 [ # # ]: 0 : if (i40e_vsi_update_tc_bandwidth(vsi, I40E_DEFAULT_TCMAP) !=
5991 : : I40E_SUCCESS) {
5992 : 0 : PMD_DRV_LOG(ERR, "Failed to update TC bandwidth");
5993 : 0 : goto fail_msix_alloc;
5994 : : }
5995 : :
5996 : : /* TC, queue mapping */
5997 : : memset(&ctxt, 0, sizeof(ctxt));
5998 : 0 : vsi->info.valid_sections |=
5999 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
6000 : 0 : vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
6001 : : I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
6002 : 0 : ctxt.info = vsi->info;
6003 : 0 : ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
6004 : : I40E_DEFAULT_TCMAP);
6005 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6006 : 0 : PMD_DRV_LOG(ERR,
6007 : : "Failed to configure TC queue mapping");
6008 : 0 : goto fail_msix_alloc;
6009 : : }
6010 : 0 : ctxt.seid = vsi->seid;
6011 : 0 : ctxt.pf_num = hw->pf_id;
6012 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
6013 : 0 : ctxt.vf_num = 0;
6014 : :
6015 : : /* Update VSI parameters */
6016 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
6017 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6018 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI params");
6019 : 0 : goto fail_msix_alloc;
6020 : : }
6021 : :
6022 : 0 : memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
6023 : : sizeof(vsi->info.tc_mapping));
6024 : 0 : memcpy(&vsi->info.queue_mapping,
6025 : : &ctxt.info.queue_mapping,
6026 : : sizeof(vsi->info.queue_mapping));
6027 : 0 : vsi->info.mapping_flags = ctxt.info.mapping_flags;
6028 : 0 : vsi->info.valid_sections = 0;
6029 : :
6030 : 0 : memcpy(pf->dev_addr.addr_bytes, hw->mac.perm_addr,
6031 : : ETH_ADDR_LEN);
6032 : :
6033 : : /**
6034 : : * Updating default filter settings are necessary to prevent
6035 : : * reception of tagged packets.
6036 : : * Some old firmware configurations load a default macvlan
6037 : : * filter which accepts both tagged and untagged packets.
6038 : : * The updating is to use a normal filter instead if needed.
6039 : : * For NVM 4.2.2 or after, the updating is not needed anymore.
6040 : : * The firmware with correct configurations load the default
6041 : : * macvlan filter which is expected and cannot be removed.
6042 : : */
6043 : 0 : i40e_update_default_filter_setting(vsi);
6044 : 0 : i40e_config_qinq(hw, vsi);
6045 [ # # ]: 0 : } else if (type == I40E_VSI_SRIOV) {
6046 : : memset(&ctxt, 0, sizeof(ctxt));
6047 : : /**
6048 : : * For other VSI, the uplink_seid equals to uplink VSI's
6049 : : * uplink_seid since they share same VEB
6050 : : */
6051 [ # # ]: 0 : if (uplink_vsi == NULL)
6052 : 0 : vsi->uplink_seid = pf->main_vsi->floating_veb->seid;
6053 : : else
6054 : 0 : vsi->uplink_seid = uplink_vsi->uplink_seid;
6055 : 0 : ctxt.pf_num = hw->pf_id;
6056 : 0 : ctxt.vf_num = hw->func_caps.vf_base_id + user_param;
6057 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
6058 : 0 : ctxt.connection_type = 0x1;
6059 : : ctxt.flags = I40E_AQ_VSI_TYPE_VF;
6060 : :
6061 : : /* Use the VEB configuration if FW >= v5.0 */
6062 [ # # # # ]: 0 : if (hw->aq.fw_maj_ver >= 5 || hw->mac.type == I40E_MAC_X722) {
6063 : : /* Configure switch ID */
6064 : 0 : ctxt.info.valid_sections |=
6065 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6066 : 0 : ctxt.info.switch_id =
6067 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6068 : : }
6069 : :
6070 : : /* Configure port/vlan */
6071 : 0 : ctxt.info.valid_sections |=
6072 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
6073 : 0 : ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
6074 : 0 : ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
6075 : 0 : hw->func_caps.enabled_tcmap);
6076 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6077 : 0 : PMD_DRV_LOG(ERR,
6078 : : "Failed to configure TC queue mapping");
6079 : 0 : goto fail_msix_alloc;
6080 : : }
6081 : :
6082 : 0 : ctxt.info.up_enable_bits = hw->func_caps.enabled_tcmap;
6083 : 0 : ctxt.info.valid_sections |=
6084 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
6085 : : /**
6086 : : * Since VSI is not created yet, only configure parameter,
6087 : : * will add vsi below.
6088 : : */
6089 : :
6090 : 0 : i40e_config_qinq(hw, vsi);
6091 [ # # ]: 0 : } else if (type == I40E_VSI_VMDQ2) {
6092 : : memset(&ctxt, 0, sizeof(ctxt));
6093 : : /*
6094 : : * For other VSI, the uplink_seid equals to uplink VSI's
6095 : : * uplink_seid since they share same VEB
6096 : : */
6097 : 0 : vsi->uplink_seid = uplink_vsi->uplink_seid;
6098 : 0 : ctxt.pf_num = hw->pf_id;
6099 : : ctxt.vf_num = 0;
6100 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
6101 : 0 : ctxt.connection_type = 0x1;
6102 : 0 : ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
6103 : :
6104 : 0 : ctxt.info.valid_sections |=
6105 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID);
6106 : : /* user_param carries flag to enable loop back */
6107 [ # # ]: 0 : if (user_param) {
6108 : : ctxt.info.switch_id =
6109 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
6110 : 0 : ctxt.info.switch_id |=
6111 : : rte_cpu_to_le_16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
6112 : : }
6113 : :
6114 : : /* Configure port/vlan */
6115 : 0 : ctxt.info.valid_sections |=
6116 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
6117 : 0 : ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
6118 : 0 : ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
6119 : : I40E_DEFAULT_TCMAP);
6120 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6121 : 0 : PMD_DRV_LOG(ERR,
6122 : : "Failed to configure TC queue mapping");
6123 : 0 : goto fail_msix_alloc;
6124 : : }
6125 : 0 : ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
6126 : 0 : ctxt.info.valid_sections |=
6127 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
6128 : : } else if (type == I40E_VSI_FDIR) {
6129 : : memset(&ctxt, 0, sizeof(ctxt));
6130 : 0 : vsi->uplink_seid = uplink_vsi->uplink_seid;
6131 : 0 : ctxt.pf_num = hw->pf_id;
6132 : : ctxt.vf_num = 0;
6133 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
6134 : 0 : ctxt.connection_type = 0x1; /* regular data port */
6135 : 0 : ctxt.flags = I40E_AQ_VSI_TYPE_PF;
6136 : 0 : ret = i40e_vsi_config_tc_queue_mapping(vsi, &ctxt.info,
6137 : : I40E_DEFAULT_TCMAP);
6138 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6139 : 0 : PMD_DRV_LOG(ERR,
6140 : : "Failed to configure TC queue mapping.");
6141 : 0 : goto fail_msix_alloc;
6142 : : }
6143 : 0 : ctxt.info.up_enable_bits = I40E_DEFAULT_TCMAP;
6144 : 0 : ctxt.info.valid_sections |=
6145 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SCHED_VALID);
6146 : : } else {
6147 : : PMD_DRV_LOG(ERR, "VSI: Not support other type VSI yet");
6148 : : goto fail_msix_alloc;
6149 : : }
6150 : :
6151 [ # # ]: 0 : if (vsi->type != I40E_VSI_MAIN) {
6152 : 0 : ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
6153 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6154 : 0 : PMD_DRV_LOG(ERR, "add vsi failed, aq_err=%d",
6155 : : hw->aq.asq_last_status);
6156 : 0 : goto fail_msix_alloc;
6157 : : }
6158 [ # # ]: 0 : memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
6159 : 0 : vsi->info.valid_sections = 0;
6160 : 0 : vsi->seid = ctxt.seid;
6161 : 0 : vsi->vsi_id = ctxt.vsi_number;
6162 : 0 : vsi->sib_vsi_list.vsi = vsi;
6163 [ # # # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV && uplink_vsi == NULL) {
6164 : 0 : TAILQ_INSERT_TAIL(&pf->main_vsi->floating_veb->head,
6165 : : &vsi->sib_vsi_list, list);
6166 : : } else {
6167 : 0 : TAILQ_INSERT_TAIL(&uplink_vsi->veb->head,
6168 : : &vsi->sib_vsi_list, list);
6169 : : }
6170 : : }
6171 : :
6172 [ # # ]: 0 : if (vsi->type != I40E_VSI_FDIR) {
6173 : : /* MAC/VLAN configuration for non-FDIR VSI*/
6174 : : memcpy(&filter.mac_addr, &broadcast, RTE_ETHER_ADDR_LEN);
6175 : 0 : filter.filter_type = I40E_MACVLAN_PERFECT_MATCH;
6176 : :
6177 : 0 : ret = i40e_vsi_add_mac(vsi, &filter);
6178 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6179 : 0 : PMD_DRV_LOG(ERR, "Failed to add MACVLAN filter");
6180 : 0 : goto fail_msix_alloc;
6181 : : }
6182 : : }
6183 : :
6184 : : /* Get VSI BW information */
6185 : 0 : i40e_vsi_get_bw_config(vsi);
6186 : 0 : return vsi;
6187 : 0 : fail_msix_alloc:
6188 : 0 : i40e_res_pool_free(&pf->msix_pool,vsi->msix_intr);
6189 : 0 : fail_queue_alloc:
6190 : 0 : i40e_res_pool_free(&pf->qp_pool,vsi->base_queue);
6191 : 0 : fail_mem:
6192 : 0 : rte_free(vsi);
6193 : 0 : return NULL;
6194 : : }
6195 : :
6196 : : /* Configure vlan filter on or off */
6197 : : int
6198 : 0 : i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on)
6199 : : {
6200 : : int i, num;
6201 : : struct i40e_mac_filter *f;
6202 : : void *temp;
6203 : 0 : struct i40e_mac_filter_info mac_filter[I40E_NUM_MACADDR_MAX] = {0};
6204 : : enum i40e_mac_filter_type desired_filter;
6205 : : int ret = I40E_SUCCESS;
6206 : :
6207 [ # # ]: 0 : if (on) {
6208 : : /* Filter to match MAC and VLAN */
6209 : : desired_filter = I40E_MACVLAN_PERFECT_MATCH;
6210 : : } else {
6211 : : /* Filter to match only MAC */
6212 : : desired_filter = I40E_MAC_PERFECT_MATCH;
6213 : : }
6214 : :
6215 : 0 : num = vsi->mac_num;
6216 [ # # ]: 0 : if (num > I40E_NUM_MACADDR_MAX) {
6217 : 0 : PMD_DRV_LOG(ERR, "Too many MAC addresses");
6218 : 0 : return -1;
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 : return ret;
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 : return ret;
6243 : : }
6244 : : }
6245 : :
6246 : : return 0;
6247 : : }
6248 : :
6249 : : /* Configure vlan stripping on or off */
6250 : : int
6251 : 0 : i40e_vsi_config_vlan_stripping(struct i40e_vsi *vsi, bool on)
6252 : : {
6253 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6254 : : struct i40e_vsi_context ctxt;
6255 : : uint8_t vlan_flags;
6256 : : int ret = I40E_SUCCESS;
6257 : :
6258 : : /* Check if it has been already on or off */
6259 [ # # ]: 0 : if (vsi->info.valid_sections &
6260 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID)) {
6261 [ # # ]: 0 : if (on) {
6262 [ # # ]: 0 : if ((vsi->info.port_vlan_flags &
6263 : : I40E_AQ_VSI_PVLAN_EMOD_MASK) == 0)
6264 : : return 0; /* already on */
6265 : : } else {
6266 [ # # ]: 0 : if ((vsi->info.port_vlan_flags &
6267 : : I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
6268 : : I40E_AQ_VSI_PVLAN_EMOD_MASK)
6269 : : return 0; /* already off */
6270 : : }
6271 : : }
6272 : :
6273 [ # # ]: 0 : if (on)
6274 : : vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
6275 : : else
6276 : : vlan_flags = I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
6277 : 0 : vsi->info.valid_sections =
6278 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_VLAN_VALID);
6279 : 0 : vsi->info.port_vlan_flags &= ~(I40E_AQ_VSI_PVLAN_EMOD_MASK);
6280 : 0 : vsi->info.port_vlan_flags |= vlan_flags;
6281 : 0 : ctxt.seid = vsi->seid;
6282 : 0 : memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
6283 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
6284 [ # # ]: 0 : if (ret)
6285 [ # # ]: 0 : PMD_DRV_LOG(INFO, "Update VSI failed to %s vlan stripping",
6286 : : on ? "enable" : "disable");
6287 : :
6288 : : return ret;
6289 : : }
6290 : :
6291 : : static int
6292 : 0 : i40e_dev_init_vlan(struct rte_eth_dev *dev)
6293 : : {
6294 : 0 : struct rte_eth_dev_data *data = dev->data;
6295 : : int ret;
6296 : : int mask = 0;
6297 : :
6298 : : /* Apply vlan offload setting */
6299 : : mask = RTE_ETH_VLAN_STRIP_MASK |
6300 : : RTE_ETH_QINQ_STRIP_MASK |
6301 : : RTE_ETH_VLAN_FILTER_MASK |
6302 : : RTE_ETH_VLAN_EXTEND_MASK;
6303 : :
6304 : 0 : ret = i40e_vlan_offload_set(dev, mask);
6305 [ # # ]: 0 : if (ret) {
6306 : 0 : PMD_DRV_LOG(INFO, "Failed to update vlan offload");
6307 : 0 : return ret;
6308 : : }
6309 : :
6310 : : /* Apply pvid setting */
6311 : 0 : ret = i40e_vlan_pvid_set(dev, data->dev_conf.txmode.pvid,
6312 : 0 : data->dev_conf.txmode.hw_vlan_insert_pvid);
6313 [ # # ]: 0 : if (ret)
6314 : 0 : PMD_DRV_LOG(INFO, "Failed to update VSI params");
6315 : :
6316 : : return ret;
6317 : : }
6318 : :
6319 : : static int
6320 : : i40e_vsi_config_double_vlan(struct i40e_vsi *vsi, int on)
6321 : : {
6322 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
6323 : :
6324 : 0 : return i40e_aq_set_port_parameters(hw, vsi->seid, 0, 1, on, NULL);
6325 : : }
6326 : :
6327 : : static int
6328 : 0 : i40e_update_flow_control(struct i40e_hw *hw)
6329 : : {
6330 : : #define I40E_LINK_PAUSE_RXTX (I40E_AQ_LINK_PAUSE_RX | I40E_AQ_LINK_PAUSE_TX)
6331 : : struct i40e_link_status link_status;
6332 : : uint32_t rxfc = 0, txfc = 0, reg;
6333 : : uint8_t an_info;
6334 : : int ret;
6335 : :
6336 : : memset(&link_status, 0, sizeof(link_status));
6337 : 0 : ret = i40e_aq_get_link_info(hw, FALSE, &link_status, NULL);
6338 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6339 : 0 : PMD_DRV_LOG(ERR, "Failed to get link status information");
6340 : 0 : goto write_reg; /* Disable flow control */
6341 : : }
6342 : :
6343 : 0 : an_info = hw->phy.link_info.an_info;
6344 [ # # ]: 0 : if (!(an_info & I40E_AQ_AN_COMPLETED)) {
6345 : 0 : PMD_DRV_LOG(INFO, "Link auto negotiation not completed");
6346 : : ret = I40E_ERR_NOT_READY;
6347 : 0 : goto write_reg; /* Disable flow control */
6348 : : }
6349 : : /**
6350 : : * If link auto negotiation is enabled, flow control needs to
6351 : : * be configured according to it
6352 : : */
6353 [ # # # # ]: 0 : switch (an_info & I40E_LINK_PAUSE_RXTX) {
6354 : 0 : case I40E_LINK_PAUSE_RXTX:
6355 : : rxfc = 1;
6356 : : txfc = 1;
6357 : 0 : hw->fc.current_mode = I40E_FC_FULL;
6358 : 0 : break;
6359 : 0 : case I40E_AQ_LINK_PAUSE_RX:
6360 : : rxfc = 1;
6361 : 0 : hw->fc.current_mode = I40E_FC_RX_PAUSE;
6362 : 0 : break;
6363 : 0 : case I40E_AQ_LINK_PAUSE_TX:
6364 : : txfc = 1;
6365 : 0 : hw->fc.current_mode = I40E_FC_TX_PAUSE;
6366 : 0 : break;
6367 : 0 : default:
6368 : 0 : hw->fc.current_mode = I40E_FC_NONE;
6369 : 0 : break;
6370 : : }
6371 : :
6372 : 0 : write_reg:
6373 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_FCCFG,
6374 : : txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT);
6375 : 0 : reg = I40E_READ_REG(hw, I40E_PRTDCB_MFLCN);
6376 : 0 : reg &= ~I40E_PRTDCB_MFLCN_RFCE_MASK;
6377 : 0 : reg |= rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT;
6378 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_MFLCN, reg);
6379 : :
6380 : 0 : return ret;
6381 : : }
6382 : :
6383 : : /* PF setup */
6384 : : static int
6385 : 0 : i40e_pf_setup(struct i40e_pf *pf)
6386 : : {
6387 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6388 : : struct i40e_filter_control_settings settings;
6389 : : struct i40e_vsi *vsi;
6390 : : int ret;
6391 : :
6392 : : /* Clear all stats counters */
6393 : 0 : pf->offset_loaded = FALSE;
6394 : 0 : memset(&pf->stats, 0, sizeof(struct i40e_hw_port_stats));
6395 : 0 : memset(&pf->stats_offset, 0, sizeof(struct i40e_hw_port_stats));
6396 : 0 : memset(&pf->internal_stats, 0, sizeof(struct i40e_eth_stats));
6397 : 0 : memset(&pf->internal_stats_offset, 0, sizeof(struct i40e_eth_stats));
6398 : :
6399 : 0 : ret = i40e_pf_get_switch_config(pf);
6400 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6401 : 0 : PMD_DRV_LOG(ERR, "Could not get switch config, err %d", ret);
6402 : 0 : return ret;
6403 : : }
6404 : :
6405 : 0 : ret = rte_eth_switch_domain_alloc(&pf->switch_domain_id);
6406 [ # # ]: 0 : if (ret)
6407 : 0 : PMD_INIT_LOG(WARNING,
6408 : : "failed to allocate switch domain for device %d", ret);
6409 : :
6410 [ # # ]: 0 : if (pf->flags & I40E_FLAG_FDIR) {
6411 : : /* make queue allocated first, let FDIR use queue pair 0*/
6412 : 0 : ret = i40e_res_pool_alloc(&pf->qp_pool, I40E_DEFAULT_QP_NUM_FDIR);
6413 [ # # ]: 0 : if (ret != I40E_FDIR_QUEUE_ID) {
6414 : 0 : PMD_DRV_LOG(ERR,
6415 : : "queue allocation fails for FDIR: ret =%d",
6416 : : ret);
6417 : 0 : pf->flags &= ~I40E_FLAG_FDIR;
6418 : : }
6419 : : }
6420 : : /* main VSI setup */
6421 : 0 : vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, NULL, 0);
6422 [ # # ]: 0 : if (!vsi) {
6423 : 0 : PMD_DRV_LOG(ERR, "Setup of main vsi failed");
6424 : 0 : return I40E_ERR_NOT_READY;
6425 : : }
6426 [ # # ]: 0 : pf->main_vsi = vsi;
6427 : :
6428 : : /* Configure filter control */
6429 : : memset(&settings, 0, sizeof(settings));
6430 [ # # ]: 0 : if (hw->func_caps.rss_table_size == RTE_ETH_RSS_RETA_SIZE_128)
6431 : : settings.hash_lut_size = I40E_HASH_LUT_SIZE_128;
6432 [ # # ]: 0 : else if (hw->func_caps.rss_table_size == RTE_ETH_RSS_RETA_SIZE_512)
6433 : 0 : settings.hash_lut_size = I40E_HASH_LUT_SIZE_512;
6434 : : else {
6435 : 0 : PMD_DRV_LOG(ERR, "Hash lookup table size (%u) not supported",
6436 : : hw->func_caps.rss_table_size);
6437 : 0 : return I40E_ERR_PARAM;
6438 : : }
6439 : 0 : PMD_DRV_LOG(INFO, "Hardware capability of hash lookup table size: %u",
6440 : : hw->func_caps.rss_table_size);
6441 : 0 : pf->hash_lut_size = hw->func_caps.rss_table_size;
6442 : :
6443 : : /* Enable ethtype and macvlan filters */
6444 : 0 : settings.enable_ethtype = TRUE;
6445 : 0 : settings.enable_macvlan = TRUE;
6446 : 0 : ret = i40e_set_filter_control(hw, &settings);
6447 [ # # ]: 0 : if (ret)
6448 : 0 : PMD_INIT_LOG(WARNING, "setup_pf_filter_control failed: %d",
6449 : : ret);
6450 : :
6451 : : /* Update flow control according to the auto negotiation */
6452 : 0 : i40e_update_flow_control(hw);
6453 : :
6454 : 0 : return I40E_SUCCESS;
6455 : : }
6456 : :
6457 : : int
6458 : 0 : i40e_switch_tx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
6459 : : {
6460 : : uint32_t reg;
6461 : : uint16_t j;
6462 : :
6463 : : /**
6464 : : * Set or clear TX Queue Disable flags,
6465 : : * which is required by hardware.
6466 : : */
6467 : 0 : i40e_pre_tx_queue_cfg(hw, q_idx, on);
6468 : 0 : rte_delay_us(I40E_PRE_TX_Q_CFG_WAIT_US);
6469 : :
6470 : : /* Wait until the request is finished */
6471 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6472 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6473 : 0 : reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
6474 : 0 : if (!(((reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 0x1) ^
6475 [ # # ]: 0 : ((reg >> I40E_QTX_ENA_QENA_STAT_SHIFT)
6476 : : & 0x1))) {
6477 : : break;
6478 : : }
6479 : : }
6480 [ # # ]: 0 : if (on) {
6481 [ # # ]: 0 : if (reg & I40E_QTX_ENA_QENA_STAT_MASK)
6482 : : return I40E_SUCCESS; /* already on, skip next steps */
6483 : :
6484 : 0 : I40E_WRITE_REG(hw, I40E_QTX_HEAD(q_idx), 0);
6485 : 0 : reg |= I40E_QTX_ENA_QENA_REQ_MASK;
6486 : : } else {
6487 [ # # ]: 0 : if (!(reg & I40E_QTX_ENA_QENA_STAT_MASK))
6488 : : return I40E_SUCCESS; /* already off, skip next steps */
6489 : 0 : reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
6490 : : }
6491 : : /* Write the register */
6492 : 0 : I40E_WRITE_REG(hw, I40E_QTX_ENA(q_idx), reg);
6493 : : /* Check the result */
6494 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6495 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6496 : 0 : reg = I40E_READ_REG(hw, I40E_QTX_ENA(q_idx));
6497 [ # # ]: 0 : if (on) {
6498 [ # # ]: 0 : if ((reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
6499 : : (reg & I40E_QTX_ENA_QENA_STAT_MASK))
6500 : : break;
6501 : : } else {
6502 [ # # ]: 0 : if (!(reg & I40E_QTX_ENA_QENA_REQ_MASK) &&
6503 : : !(reg & I40E_QTX_ENA_QENA_STAT_MASK))
6504 : : break;
6505 : : }
6506 : : }
6507 : : /* Check if it is timeout */
6508 [ # # ]: 0 : if (j >= I40E_CHK_Q_ENA_COUNT) {
6509 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Failed to %s tx queue[%u]",
6510 : : (on ? "enable" : "disable"), q_idx);
6511 : 0 : return I40E_ERR_TIMEOUT;
6512 : : }
6513 : :
6514 : : return I40E_SUCCESS;
6515 : : }
6516 : :
6517 : : int
6518 : 0 : i40e_switch_rx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on)
6519 : : {
6520 : : uint32_t reg;
6521 : : uint16_t j;
6522 : :
6523 : : /* Wait until the request is finished */
6524 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6525 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6526 : 0 : reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
6527 : 0 : if (!((reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 0x1) ^
6528 [ # # ]: 0 : ((reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 0x1))
6529 : : break;
6530 : : }
6531 : :
6532 [ # # ]: 0 : if (on) {
6533 [ # # ]: 0 : if (reg & I40E_QRX_ENA_QENA_STAT_MASK)
6534 : : return I40E_SUCCESS; /* Already on, skip next steps */
6535 : 0 : reg |= I40E_QRX_ENA_QENA_REQ_MASK;
6536 : : } else {
6537 [ # # ]: 0 : if (!(reg & I40E_QRX_ENA_QENA_STAT_MASK))
6538 : : return I40E_SUCCESS; /* Already off, skip next steps */
6539 : 0 : reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
6540 : : }
6541 : :
6542 : : /* Write the register */
6543 : 0 : I40E_WRITE_REG(hw, I40E_QRX_ENA(q_idx), reg);
6544 : : /* Check the result */
6545 [ # # ]: 0 : for (j = 0; j < I40E_CHK_Q_ENA_COUNT; j++) {
6546 : 0 : rte_delay_us(I40E_CHK_Q_ENA_INTERVAL_US);
6547 : 0 : reg = I40E_READ_REG(hw, I40E_QRX_ENA(q_idx));
6548 [ # # ]: 0 : if (on) {
6549 [ # # ]: 0 : if ((reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
6550 : : (reg & I40E_QRX_ENA_QENA_STAT_MASK))
6551 : : break;
6552 : : } else {
6553 [ # # ]: 0 : if (!(reg & I40E_QRX_ENA_QENA_REQ_MASK) &&
6554 : : !(reg & I40E_QRX_ENA_QENA_STAT_MASK))
6555 : : break;
6556 : : }
6557 : : }
6558 : :
6559 : : /* Check if it is timeout */
6560 [ # # ]: 0 : if (j >= I40E_CHK_Q_ENA_COUNT) {
6561 [ # # ]: 0 : PMD_DRV_LOG(ERR, "Failed to %s rx queue[%u]",
6562 : : (on ? "enable" : "disable"), q_idx);
6563 : 0 : return I40E_ERR_TIMEOUT;
6564 : : }
6565 : :
6566 : : return I40E_SUCCESS;
6567 : : }
6568 : :
6569 : : /* Initialize VSI for TX */
6570 : : static int
6571 : 0 : i40e_dev_tx_init(struct i40e_pf *pf)
6572 : : {
6573 : 0 : struct rte_eth_dev_data *data = pf->dev_data;
6574 : : uint16_t i;
6575 : : uint32_t ret = I40E_SUCCESS;
6576 : : struct ci_tx_queue *txq;
6577 : :
6578 [ # # ]: 0 : for (i = 0; i < data->nb_tx_queues; i++) {
6579 : 0 : txq = data->tx_queues[i];
6580 [ # # # # ]: 0 : if (!txq || !txq->q_set)
6581 : 0 : continue;
6582 : 0 : ret = i40e_tx_queue_init(txq);
6583 [ # # ]: 0 : if (ret != I40E_SUCCESS)
6584 : : break;
6585 : : }
6586 [ # # ]: 0 : if (ret == I40E_SUCCESS)
6587 : 0 : i40e_set_tx_function(&rte_eth_devices[pf->dev_data->port_id]);
6588 : :
6589 : 0 : return ret;
6590 : : }
6591 : :
6592 : : /* Initialize VSI for RX */
6593 : : static int
6594 : 0 : i40e_dev_rx_init(struct i40e_pf *pf)
6595 : : {
6596 : 0 : struct rte_eth_dev_data *data = pf->dev_data;
6597 : : int ret = I40E_SUCCESS;
6598 : : uint16_t i;
6599 : : struct ci_rx_queue *rxq;
6600 : :
6601 : 0 : i40e_pf_config_rss(pf);
6602 [ # # ]: 0 : for (i = 0; i < data->nb_rx_queues; i++) {
6603 : 0 : rxq = data->rx_queues[i];
6604 [ # # # # ]: 0 : if (!rxq || !rxq->q_set)
6605 : 0 : continue;
6606 : :
6607 : 0 : ret = i40e_rx_queue_init(rxq);
6608 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6609 : 0 : PMD_DRV_LOG(ERR,
6610 : : "Failed to do RX queue initialization");
6611 : 0 : break;
6612 : : }
6613 : : }
6614 [ # # ]: 0 : if (ret == I40E_SUCCESS)
6615 : 0 : i40e_set_rx_function(&rte_eth_devices[pf->dev_data->port_id]);
6616 : :
6617 : 0 : return ret;
6618 : : }
6619 : :
6620 : : static int
6621 : 0 : i40e_dev_rxtx_init(struct i40e_pf *pf)
6622 : : {
6623 : : int err;
6624 : :
6625 : 0 : err = i40e_dev_tx_init(pf);
6626 [ # # ]: 0 : if (err) {
6627 : 0 : PMD_DRV_LOG(ERR, "Failed to do TX initialization");
6628 : 0 : return err;
6629 : : }
6630 : 0 : err = i40e_dev_rx_init(pf);
6631 [ # # ]: 0 : if (err) {
6632 : 0 : PMD_DRV_LOG(ERR, "Failed to do RX initialization");
6633 : 0 : return err;
6634 : : }
6635 : :
6636 : : return err;
6637 : : }
6638 : :
6639 : : static int
6640 : 0 : i40e_vmdq_setup(struct rte_eth_dev *dev)
6641 : : {
6642 : 0 : struct rte_eth_conf *conf = &dev->data->dev_conf;
6643 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6644 : : int i, err, conf_vsis, j, loop;
6645 : : struct i40e_vsi *vsi;
6646 : : struct i40e_vmdq_info *vmdq_info;
6647 : : struct rte_eth_vmdq_rx_conf *vmdq_conf;
6648 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
6649 : :
6650 : : /*
6651 : : * Disable interrupt to avoid message from VF. Furthermore, it will
6652 : : * avoid race condition in VSI creation/destroy.
6653 : : */
6654 : 0 : i40e_pf_disable_irq0(hw);
6655 : :
6656 [ # # ]: 0 : if ((pf->flags & I40E_FLAG_VMDQ) == 0) {
6657 : 0 : PMD_INIT_LOG(ERR, "FW doesn't support VMDQ");
6658 : 0 : return -ENOTSUP;
6659 : : }
6660 : :
6661 : 0 : conf_vsis = conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools;
6662 [ # # ]: 0 : if (conf_vsis > pf->max_nb_vmdq_vsi) {
6663 : 0 : PMD_INIT_LOG(ERR, "VMDQ config: %u, max support:%u",
6664 : : conf->rx_adv_conf.vmdq_rx_conf.nb_queue_pools,
6665 : : pf->max_nb_vmdq_vsi);
6666 : 0 : return -ENOTSUP;
6667 : : }
6668 : :
6669 [ # # ]: 0 : if (pf->vmdq != NULL) {
6670 : 0 : PMD_INIT_LOG(INFO, "VMDQ already configured");
6671 : 0 : return 0;
6672 : : }
6673 : :
6674 : 0 : pf->vmdq = rte_zmalloc("vmdq_info_struct",
6675 : : sizeof(*vmdq_info) * conf_vsis, 0);
6676 : :
6677 [ # # ]: 0 : if (pf->vmdq == NULL) {
6678 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory");
6679 : 0 : return -ENOMEM;
6680 : : }
6681 : :
6682 : : vmdq_conf = &conf->rx_adv_conf.vmdq_rx_conf;
6683 : :
6684 : : /* Create VMDQ VSI */
6685 [ # # ]: 0 : for (i = 0; i < conf_vsis; i++) {
6686 : 0 : vsi = i40e_vsi_setup(pf, I40E_VSI_VMDQ2, pf->main_vsi,
6687 : 0 : vmdq_conf->enable_loop_back);
6688 [ # # ]: 0 : if (vsi == NULL) {
6689 : 0 : PMD_INIT_LOG(ERR, "Failed to create VMDQ VSI");
6690 : : err = -1;
6691 : 0 : goto err_vsi_setup;
6692 : : }
6693 : 0 : vmdq_info = &pf->vmdq[i];
6694 : 0 : vmdq_info->pf = pf;
6695 : 0 : vmdq_info->vsi = vsi;
6696 : : }
6697 : 0 : pf->nb_cfg_vmdq_vsi = conf_vsis;
6698 : :
6699 : : /* Configure Vlan */
6700 : : loop = sizeof(vmdq_conf->pool_map[0].pools) * CHAR_BIT;
6701 [ # # ]: 0 : for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
6702 [ # # # # ]: 0 : for (j = 0; j < loop && j < pf->nb_cfg_vmdq_vsi; j++) {
6703 [ # # ]: 0 : if (vmdq_conf->pool_map[i].pools & RTE_BIT64(j)) {
6704 : 0 : PMD_INIT_LOG(INFO, "Add vlan %u to vmdq pool %u",
6705 : : vmdq_conf->pool_map[i].vlan_id, j);
6706 : :
6707 : 0 : err = i40e_vsi_add_vlan(pf->vmdq[j].vsi,
6708 : 0 : vmdq_conf->pool_map[i].vlan_id);
6709 [ # # ]: 0 : if (err) {
6710 : 0 : PMD_INIT_LOG(ERR, "Failed to add vlan");
6711 : : err = -1;
6712 : 0 : goto err_vsi_setup;
6713 : : }
6714 : : }
6715 : : }
6716 : : }
6717 : :
6718 : 0 : i40e_pf_enable_irq0(hw);
6719 : :
6720 : 0 : return 0;
6721 : :
6722 : : err_vsi_setup:
6723 [ # # ]: 0 : for (i = 0; i < conf_vsis; i++)
6724 [ # # ]: 0 : if (pf->vmdq[i].vsi == NULL)
6725 : : break;
6726 : : else
6727 : 0 : i40e_vsi_release(pf->vmdq[i].vsi);
6728 : :
6729 : 0 : rte_free(pf->vmdq);
6730 : 0 : pf->vmdq = NULL;
6731 : 0 : i40e_pf_enable_irq0(hw);
6732 : 0 : return err;
6733 : : }
6734 : :
6735 : : static void
6736 : : i40e_stat_update_32(struct i40e_hw *hw,
6737 : : uint32_t reg,
6738 : : bool offset_loaded,
6739 : : uint64_t *offset,
6740 : : uint64_t *stat)
6741 : : {
6742 : : uint64_t new_data;
6743 : :
6744 : 0 : new_data = (uint64_t)I40E_READ_REG(hw, reg);
6745 [ # # # # : 0 : if (!offset_loaded)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
6746 : 0 : *offset = new_data;
6747 : :
6748 [ # # # # : 0 : if (new_data >= *offset)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
6749 : 0 : *stat = (uint64_t)(new_data - *offset);
6750 : : else
6751 : 0 : *stat = (uint64_t)((new_data +
6752 : : RTE_BIT64(I40E_32_BIT_WIDTH)) - *offset);
6753 : : }
6754 : :
6755 : : static void
6756 : 0 : i40e_stat_update_48(struct i40e_hw *hw,
6757 : : uint32_t hireg,
6758 : : uint32_t loreg,
6759 : : bool offset_loaded,
6760 : : uint64_t *offset,
6761 : : uint64_t *stat)
6762 : : {
6763 : : uint64_t new_data;
6764 : :
6765 [ # # ]: 0 : if (hw->device_id == I40E_DEV_ID_QEMU) {
6766 : 0 : new_data = (uint64_t)I40E_READ_REG(hw, loreg);
6767 : 0 : new_data |= ((uint64_t)(I40E_READ_REG(hw, hireg) &
6768 : 0 : I40E_16_BIT_MASK)) << I40E_32_BIT_WIDTH;
6769 : : } else {
6770 : 0 : new_data = I40E_READ_REG64(hw, loreg);
6771 : : }
6772 : :
6773 [ # # ]: 0 : if (!offset_loaded)
6774 : 0 : *offset = new_data;
6775 : :
6776 [ # # ]: 0 : if (new_data >= *offset)
6777 : 0 : *stat = new_data - *offset;
6778 : : else
6779 : 0 : *stat = (uint64_t)((new_data +
6780 : : RTE_BIT64(I40E_48_BIT_WIDTH)) - *offset);
6781 : :
6782 : 0 : *stat &= I40E_48_BIT_MASK;
6783 : 0 : }
6784 : :
6785 : : /* Disable IRQ0 */
6786 : : void
6787 : 0 : i40e_pf_disable_irq0(struct i40e_hw *hw)
6788 : : {
6789 : : /* Disable all interrupt types */
6790 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
6791 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
6792 : 0 : I40E_WRITE_FLUSH(hw);
6793 : 0 : }
6794 : :
6795 : : /* Enable IRQ0 */
6796 : : void
6797 : 0 : i40e_pf_enable_irq0(struct i40e_hw *hw)
6798 : : {
6799 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
6800 : : I40E_PFINT_DYN_CTL0_INTENA_MASK |
6801 : : I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
6802 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
6803 : 0 : I40E_WRITE_FLUSH(hw);
6804 : 0 : }
6805 : :
6806 : : static void
6807 : : i40e_pf_config_irq0(struct i40e_hw *hw, bool no_queue)
6808 : : {
6809 : : /* read pending request and disable first */
6810 : 0 : i40e_pf_disable_irq0(hw);
6811 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_ICR0_ENA, I40E_PFINT_ICR0_ENA_MASK);
6812 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_STAT_CTL0,
6813 : : I40E_PFINT_STAT_CTL0_OTHER_ITR_INDX_MASK);
6814 : :
6815 : : if (no_queue)
6816 : : /* Link no queues with irq0 */
6817 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_LNKLST0,
6818 : : I40E_PFINT_LNKLST0_FIRSTQ_INDX_MASK);
6819 : : }
6820 : :
6821 : : static void
6822 : 0 : i40e_dev_handle_vfr_event(struct rte_eth_dev *dev)
6823 : : {
6824 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6825 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6826 : : int i;
6827 : : uint16_t abs_vf_id;
6828 : : uint32_t index, offset, val;
6829 : :
6830 [ # # ]: 0 : if (!pf->vfs)
6831 : : return;
6832 : : /**
6833 : : * Try to find which VF trigger a reset, use absolute VF id to access
6834 : : * since the reg is global register.
6835 : : */
6836 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++) {
6837 : 0 : abs_vf_id = hw->func_caps.vf_base_id + i;
6838 : 0 : index = abs_vf_id / I40E_UINT32_BIT_SIZE;
6839 : 0 : offset = abs_vf_id % I40E_UINT32_BIT_SIZE;
6840 : 0 : val = I40E_READ_REG(hw, I40E_GLGEN_VFLRSTAT(index));
6841 : : /* VFR event occurred */
6842 [ # # ]: 0 : if (val & (0x1 << offset)) {
6843 : : int ret;
6844 : :
6845 : : /* Clear the event first */
6846 : 0 : I40E_WRITE_REG(hw, I40E_GLGEN_VFLRSTAT(index),
6847 : : (0x1 << offset));
6848 : 0 : PMD_DRV_LOG(INFO, "VF %u reset occurred", abs_vf_id);
6849 : : /**
6850 : : * Only notify a VF reset event occurred,
6851 : : * don't trigger another SW reset
6852 : : */
6853 : 0 : ret = i40e_pf_host_vf_reset(&pf->vfs[i], 0);
6854 [ # # ]: 0 : if (ret != I40E_SUCCESS)
6855 : 0 : PMD_DRV_LOG(ERR, "Failed to do VF reset");
6856 : : }
6857 : : }
6858 : : }
6859 : :
6860 : : static void
6861 : 0 : i40e_notify_all_vfs_link_status(struct rte_eth_dev *dev)
6862 : : {
6863 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6864 : : int i;
6865 : :
6866 [ # # ]: 0 : for (i = 0; i < pf->vf_num; i++)
6867 : 0 : i40e_notify_vf_link_status(dev, &pf->vfs[i]);
6868 : 0 : }
6869 : :
6870 : : static void
6871 : 0 : i40e_dev_handle_aq_msg(struct rte_eth_dev *dev)
6872 : : {
6873 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6874 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6875 : : struct i40e_arq_event_info info;
6876 : : uint16_t pending, opcode;
6877 : 0 : uint8_t msg_buf[I40E_AQ_BUF_SZ] = {0};
6878 : : int ret;
6879 : :
6880 : 0 : info.buf_len = sizeof(msg_buf);
6881 : 0 : info.msg_buf = msg_buf;
6882 : :
6883 : 0 : pending = 1;
6884 [ # # ]: 0 : while (pending) {
6885 : 0 : ret = i40e_clean_arq_element(hw, &info, &pending);
6886 : :
6887 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
6888 : 0 : PMD_DRV_LOG(INFO,
6889 : : "Failed to read msg from AdminQ, aq_err: %u",
6890 : : hw->aq.asq_last_status);
6891 : 0 : break;
6892 : : }
6893 : 0 : opcode = rte_le_to_cpu_16(info.desc.opcode);
6894 : :
6895 [ # # # ]: 0 : switch (opcode) {
6896 : 0 : case i40e_aqc_opc_send_msg_to_pf:
6897 : : /* Refer to i40e_aq_send_msg_to_pf() for argument layout*/
6898 : 0 : i40e_pf_host_handle_vf_msg(dev,
6899 : 0 : rte_le_to_cpu_16(info.desc.retval),
6900 : : rte_le_to_cpu_32(info.desc.cookie_high),
6901 : : rte_le_to_cpu_32(info.desc.cookie_low),
6902 : 0 : info.msg_buf,
6903 : 0 : info.msg_len);
6904 : 0 : break;
6905 : 0 : case i40e_aqc_opc_get_link_status:
6906 : 0 : ret = i40e_dev_link_update(dev, 0);
6907 : : /* Some devices require MAC config to be applied when the link comes up. */
6908 [ # # ]: 0 : if (!ret) {
6909 [ # # # # ]: 0 : if (pf->mac_config_on_link_up && dev->data->dev_link.link_status) {
6910 : : uint16_t max_frame_size;
6911 : :
6912 [ # # ]: 0 : max_frame_size = dev->data->mtu ?
6913 : : dev->data->mtu + I40E_ETH_OVERHEAD :
6914 : : I40E_FRAME_SIZE_MAX;
6915 : 0 : i40e_aq_set_mac_config(hw, max_frame_size, TRUE,
6916 : : false, 0, NULL);
6917 : 0 : pf->mac_config_on_link_up = false;
6918 : : }
6919 : 0 : rte_eth_dev_callback_process(dev,
6920 : : RTE_ETH_EVENT_INTR_LSC, NULL);
6921 : : }
6922 : : break;
6923 : 0 : default:
6924 : 0 : PMD_DRV_LOG(DEBUG, "Request %u is not supported yet",
6925 : : opcode);
6926 : 0 : break;
6927 : : }
6928 : : }
6929 : 0 : }
6930 : :
6931 : : static void
6932 : 0 : i40e_handle_mdd_event(struct rte_eth_dev *dev)
6933 : : {
6934 : : #define I40E_MDD_CLEAR32 0xFFFFFFFF
6935 : : #define I40E_MDD_CLEAR16 0xFFFF
6936 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
6937 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
6938 : : bool mdd_detected = false;
6939 : : struct i40e_pf_vf *vf;
6940 : : uint32_t reg;
6941 : : int i;
6942 : :
6943 : : /* find what triggered the MDD event */
6944 : 0 : reg = I40E_READ_REG(hw, I40E_GL_MDET_TX);
6945 [ # # ]: 0 : if (reg & I40E_GL_MDET_TX_VALID_MASK) {
6946 : 0 : uint8_t pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
6947 : : I40E_GL_MDET_TX_PF_NUM_SHIFT;
6948 : 0 : uint16_t vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
6949 : : I40E_GL_MDET_TX_VF_NUM_SHIFT;
6950 : 0 : uint8_t event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
6951 : : I40E_GL_MDET_TX_EVENT_SHIFT;
6952 : 0 : uint16_t queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
6953 : 0 : I40E_GL_MDET_TX_QUEUE_SHIFT) -
6954 : 0 : hw->func_caps.base_queue;
6955 : 0 : PMD_DRV_LOG(WARNING, "Malicious Driver Detection event 0x%02x on TX "
6956 : : "queue %d PF number 0x%02x VF number 0x%02x device %s",
6957 : : event, queue, pf_num, vf_num, dev->data->name);
6958 : 0 : I40E_WRITE_REG(hw, I40E_GL_MDET_TX, I40E_MDD_CLEAR32);
6959 : : mdd_detected = true;
6960 : : }
6961 : 0 : reg = I40E_READ_REG(hw, I40E_GL_MDET_RX);
6962 [ # # ]: 0 : if (reg & I40E_GL_MDET_RX_VALID_MASK) {
6963 : : uint8_t func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
6964 : : I40E_GL_MDET_RX_FUNCTION_SHIFT;
6965 : 0 : uint8_t event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
6966 : : I40E_GL_MDET_RX_EVENT_SHIFT;
6967 : 0 : uint16_t queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
6968 : 0 : I40E_GL_MDET_RX_QUEUE_SHIFT) -
6969 : 0 : hw->func_caps.base_queue;
6970 : :
6971 : 0 : PMD_DRV_LOG(WARNING, "Malicious Driver Detection event 0x%02x on RX "
6972 : : "queue %d of function 0x%02x device %s",
6973 : : event, queue, func, dev->data->name);
6974 : 0 : I40E_WRITE_REG(hw, I40E_GL_MDET_RX, I40E_MDD_CLEAR32);
6975 : : mdd_detected = true;
6976 : : }
6977 : :
6978 [ # # ]: 0 : if (mdd_detected) {
6979 : 0 : reg = I40E_READ_REG(hw, I40E_PF_MDET_TX);
6980 [ # # ]: 0 : if (reg & I40E_PF_MDET_TX_VALID_MASK) {
6981 : 0 : I40E_WRITE_REG(hw, I40E_PF_MDET_TX, I40E_MDD_CLEAR16);
6982 : 0 : PMD_DRV_LOG(WARNING, "TX driver issue detected on PF");
6983 : : }
6984 : 0 : reg = I40E_READ_REG(hw, I40E_PF_MDET_RX);
6985 [ # # ]: 0 : if (reg & I40E_PF_MDET_RX_VALID_MASK) {
6986 : 0 : I40E_WRITE_REG(hw, I40E_PF_MDET_RX,
6987 : : I40E_MDD_CLEAR16);
6988 : 0 : PMD_DRV_LOG(WARNING, "RX driver issue detected on PF");
6989 : : }
6990 : : }
6991 : :
6992 : : /* see if one of the VFs needs its hand slapped */
6993 [ # # # # ]: 0 : for (i = 0; i < pf->vf_num && mdd_detected; i++) {
6994 : 0 : vf = &pf->vfs[i];
6995 : 0 : reg = I40E_READ_REG(hw, I40E_VP_MDET_TX(i));
6996 [ # # ]: 0 : if (reg & I40E_VP_MDET_TX_VALID_MASK) {
6997 : 0 : I40E_WRITE_REG(hw, I40E_VP_MDET_TX(i),
6998 : : I40E_MDD_CLEAR16);
6999 : 0 : vf->num_mdd_events++;
7000 : 0 : PMD_DRV_LOG(WARNING, "TX driver issue detected on VF %d %-"
7001 : : PRIu64 "times",
7002 : : i, vf->num_mdd_events);
7003 : : }
7004 : :
7005 : 0 : reg = I40E_READ_REG(hw, I40E_VP_MDET_RX(i));
7006 [ # # ]: 0 : if (reg & I40E_VP_MDET_RX_VALID_MASK) {
7007 : 0 : I40E_WRITE_REG(hw, I40E_VP_MDET_RX(i),
7008 : : I40E_MDD_CLEAR16);
7009 : 0 : vf->num_mdd_events++;
7010 : 0 : PMD_DRV_LOG(WARNING, "RX driver issue detected on VF %d %-"
7011 : : PRIu64 "times",
7012 : : i, vf->num_mdd_events);
7013 : : }
7014 : : }
7015 : 0 : }
7016 : :
7017 : : /**
7018 : : * Interrupt handler triggered by NIC for handling
7019 : : * specific interrupt.
7020 : : *
7021 : : * @param handle
7022 : : * Pointer to interrupt handle.
7023 : : * @param param
7024 : : * The address of parameter (struct rte_eth_dev *) registered before.
7025 : : *
7026 : : * @return
7027 : : * void
7028 : : */
7029 : : static void
7030 : 0 : i40e_dev_interrupt_handler(void *param)
7031 : : {
7032 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
7033 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7034 : : uint32_t icr0;
7035 : :
7036 : : /* Disable interrupt */
7037 : 0 : i40e_pf_disable_irq0(hw);
7038 : :
7039 : : /* read out interrupt causes */
7040 : 0 : icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
7041 : :
7042 : : /* No interrupt event indicated */
7043 [ # # ]: 0 : if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK)) {
7044 : 0 : PMD_DRV_LOG(INFO, "No interrupt event");
7045 : 0 : goto done;
7046 : : }
7047 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
7048 : 0 : PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
7049 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
7050 : 0 : PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
7051 : 0 : i40e_handle_mdd_event(dev);
7052 : : }
7053 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
7054 : 0 : PMD_DRV_LOG(INFO, "ICR0: global reset requested");
7055 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
7056 : 0 : PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
7057 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
7058 : 0 : PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
7059 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
7060 : 0 : PMD_DRV_LOG(ERR, "ICR0: HMC error");
7061 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
7062 : 0 : PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
7063 : :
7064 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
7065 : 0 : PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
7066 : 0 : i40e_dev_handle_vfr_event(dev);
7067 : : }
7068 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
7069 : 0 : PMD_DRV_LOG(INFO, "ICR0: adminq event");
7070 : 0 : i40e_dev_handle_aq_msg(dev);
7071 : : }
7072 : :
7073 : 0 : done:
7074 : : /* Enable interrupt */
7075 : 0 : i40e_pf_enable_irq0(hw);
7076 : 0 : }
7077 : :
7078 : : static void
7079 : 0 : i40e_dev_alarm_handler(void *param)
7080 : : {
7081 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
7082 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7083 : : uint32_t icr0;
7084 : :
7085 : : /* Disable interrupt */
7086 : 0 : i40e_pf_disable_irq0(hw);
7087 : :
7088 : : /* read out interrupt causes */
7089 : 0 : icr0 = I40E_READ_REG(hw, I40E_PFINT_ICR0);
7090 : :
7091 : : /* No interrupt event indicated */
7092 [ # # ]: 0 : if (!(icr0 & I40E_PFINT_ICR0_INTEVENT_MASK))
7093 : 0 : goto done;
7094 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ECC_ERR_MASK)
7095 : 0 : PMD_DRV_LOG(ERR, "ICR0: unrecoverable ECC error");
7096 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
7097 : 0 : PMD_DRV_LOG(ERR, "ICR0: malicious programming detected");
7098 : 0 : i40e_handle_mdd_event(dev);
7099 : : }
7100 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_GRST_MASK)
7101 : 0 : PMD_DRV_LOG(INFO, "ICR0: global reset requested");
7102 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK)
7103 : 0 : PMD_DRV_LOG(INFO, "ICR0: PCI exception activated");
7104 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_STORM_DETECT_MASK)
7105 : 0 : PMD_DRV_LOG(INFO, "ICR0: a change in the storm control state");
7106 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK)
7107 : 0 : PMD_DRV_LOG(ERR, "ICR0: HMC error");
7108 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_PE_CRITERR_MASK)
7109 : 0 : PMD_DRV_LOG(ERR, "ICR0: protocol engine critical error");
7110 : :
7111 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
7112 : 0 : PMD_DRV_LOG(INFO, "ICR0: VF reset detected");
7113 : 0 : i40e_dev_handle_vfr_event(dev);
7114 : : }
7115 [ # # ]: 0 : if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
7116 : 0 : PMD_DRV_LOG(INFO, "ICR0: adminq event");
7117 : 0 : i40e_dev_handle_aq_msg(dev);
7118 : : }
7119 : :
7120 : 0 : done:
7121 : : /* Enable interrupt */
7122 : 0 : i40e_pf_enable_irq0(hw);
7123 : 0 : rte_eal_alarm_set(I40E_ALARM_INTERVAL,
7124 : : i40e_dev_alarm_handler, dev);
7125 : 0 : }
7126 : :
7127 : : int
7128 : 0 : i40e_add_macvlan_filters(struct i40e_vsi *vsi,
7129 : : struct i40e_macvlan_filter *filter,
7130 : : int total)
7131 : : {
7132 : : int ele_num, ele_buff_size;
7133 : : int num, actual_num, i;
7134 : : uint16_t flags;
7135 : : int ret = I40E_SUCCESS;
7136 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7137 : 0 : uint8_t aq_buff[I40E_AQ_BUF_SZ] = {0};
7138 : : struct i40e_aqc_add_macvlan_element_data *req_list =
7139 : : (struct i40e_aqc_add_macvlan_element_data *)aq_buff;
7140 : :
7141 [ # # ]: 0 : if (hw->aq.asq_buf_size > I40E_AQ_BUF_SZ) {
7142 : 0 : PMD_DRV_LOG(ERR, "AdminQ size biffer than max");
7143 : 0 : return I40E_ERR_NO_MEMORY;
7144 : : }
7145 : :
7146 [ # # ]: 0 : if (filter == NULL || total == 0)
7147 : : return I40E_ERR_PARAM;
7148 : 0 : ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
7149 : : ele_buff_size = hw->aq.asq_buf_size;
7150 : :
7151 : : num = 0;
7152 : : do {
7153 [ # # ]: 0 : actual_num = (num + ele_num > total) ? (total - num) : ele_num;
7154 : 0 : memset(req_list, 0, ele_buff_size);
7155 : :
7156 [ # # ]: 0 : for (i = 0; i < actual_num; i++) {
7157 : 0 : memcpy(req_list[i].mac_addr,
7158 [ # # ]: 0 : &filter[num + i].macaddr, ETH_ADDR_LEN);
7159 : 0 : req_list[i].vlan_tag =
7160 : 0 : rte_cpu_to_le_16(filter[num + i].vlan_id);
7161 : :
7162 [ # # ]: 0 : switch (filter[num + i].filter_type) {
7163 : : case I40E_MAC_PERFECT_MATCH:
7164 : : flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH |
7165 : : I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
7166 : : break;
7167 : : case I40E_MACVLAN_PERFECT_MATCH:
7168 : : flags = I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
7169 : : break;
7170 : : case I40E_MAC_HASH_MATCH:
7171 : : flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH |
7172 : : I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
7173 : : break;
7174 : : case I40E_MACVLAN_HASH_MATCH:
7175 : : flags = I40E_AQC_MACVLAN_ADD_HASH_MATCH;
7176 : : break;
7177 : 0 : default:
7178 : 0 : PMD_DRV_LOG(ERR, "Invalid MAC match type");
7179 : 0 : return I40E_ERR_PARAM;
7180 : : }
7181 : :
7182 : 0 : req_list[i].queue_number = 0;
7183 : :
7184 : 0 : req_list[i].flags = rte_cpu_to_le_16(flags);
7185 : : }
7186 : :
7187 : 0 : ret = i40e_aq_add_macvlan(hw, vsi->seid, req_list,
7188 : : actual_num, NULL);
7189 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
7190 : 0 : PMD_DRV_LOG(ERR, "Failed to add macvlan filter");
7191 : 0 : return ret;
7192 : : }
7193 : 0 : num += actual_num;
7194 [ # # ]: 0 : } while (num < total);
7195 : : return I40E_SUCCESS;
7196 : : }
7197 : :
7198 : : int
7199 : 0 : i40e_remove_macvlan_filters(struct i40e_vsi *vsi,
7200 : : struct i40e_macvlan_filter *filter,
7201 : : int total)
7202 : : {
7203 : : int ele_num, ele_buff_size;
7204 : : int num, actual_num, i;
7205 : : uint16_t flags;
7206 : : int ret = I40E_SUCCESS;
7207 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7208 : 0 : uint8_t aq_buff[I40E_AQ_BUF_SZ] = {0};
7209 : : struct i40e_aqc_remove_macvlan_element_data *req_list =
7210 : : (struct i40e_aqc_remove_macvlan_element_data *)aq_buff;
7211 : : enum i40e_admin_queue_err aq_status;
7212 : :
7213 [ # # ]: 0 : if (filter == NULL || total == 0)
7214 : : return I40E_ERR_PARAM;
7215 : :
7216 [ # # ]: 0 : if (hw->aq.asq_buf_size > I40E_AQ_BUF_SZ) {
7217 : 0 : PMD_DRV_LOG(ERR, "AdminQ size biffer than max");
7218 : 0 : return I40E_ERR_NO_MEMORY;
7219 : : }
7220 : :
7221 : 0 : ele_num = hw->aq.asq_buf_size / sizeof(*req_list);
7222 : : ele_buff_size = hw->aq.asq_buf_size;
7223 : :
7224 : : num = 0;
7225 : : do {
7226 [ # # ]: 0 : actual_num = (num + ele_num > total) ? (total - num) : ele_num;
7227 : 0 : memset(req_list, 0, ele_buff_size);
7228 : :
7229 [ # # ]: 0 : for (i = 0; i < actual_num; i++) {
7230 : 0 : memcpy(req_list[i].mac_addr,
7231 [ # # ]: 0 : &filter[num + i].macaddr, ETH_ADDR_LEN);
7232 : 0 : req_list[i].vlan_tag =
7233 : 0 : rte_cpu_to_le_16(filter[num + i].vlan_id);
7234 : :
7235 [ # # ]: 0 : switch (filter[num + i].filter_type) {
7236 : : case I40E_MAC_PERFECT_MATCH:
7237 : : flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
7238 : : I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
7239 : : break;
7240 : : case I40E_MACVLAN_PERFECT_MATCH:
7241 : : flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
7242 : : break;
7243 : : case I40E_MAC_HASH_MATCH:
7244 : : flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH |
7245 : : I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
7246 : : break;
7247 : : case I40E_MACVLAN_HASH_MATCH:
7248 : : flags = I40E_AQC_MACVLAN_DEL_HASH_MATCH;
7249 : : break;
7250 : 0 : default:
7251 : 0 : PMD_DRV_LOG(ERR, "Invalid MAC filter type");
7252 : 0 : return I40E_ERR_PARAM;
7253 : : }
7254 : 0 : req_list[i].flags = rte_cpu_to_le_16(flags);
7255 : : }
7256 : :
7257 : 0 : ret = i40e_aq_remove_macvlan_v2(hw, vsi->seid, req_list,
7258 : : actual_num, NULL, &aq_status);
7259 : :
7260 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
7261 : : /* Do not report as an error when firmware returns ENOENT */
7262 [ # # ]: 0 : if (aq_status != I40E_AQ_RC_ENOENT) {
7263 : 0 : PMD_DRV_LOG(ERR, "Failed to remove macvlan filter");
7264 : 0 : return ret;
7265 : : }
7266 : : }
7267 : 0 : num += actual_num;
7268 [ # # ]: 0 : } while (num < total);
7269 : :
7270 : : return I40E_SUCCESS;
7271 : : }
7272 : :
7273 : : /* Find out specific MAC filter */
7274 : : static struct i40e_mac_filter *
7275 : : i40e_find_mac_filter(struct i40e_vsi *vsi,
7276 : : struct rte_ether_addr *macaddr)
7277 : : {
7278 : : struct i40e_mac_filter *f;
7279 : :
7280 [ # # # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7281 [ # # # # ]: 0 : if (rte_is_same_ether_addr(macaddr, &f->mac_info.mac_addr))
7282 : : return f;
7283 : : }
7284 : :
7285 : : return NULL;
7286 : : }
7287 : :
7288 : : static bool
7289 : : i40e_find_vlan_filter(struct i40e_vsi *vsi,
7290 : : uint16_t vlan_id)
7291 : : {
7292 : : uint32_t vid_idx, vid_bit;
7293 : :
7294 : : if (vlan_id > RTE_ETH_VLAN_ID_MAX)
7295 : : return 0;
7296 : :
7297 : 0 : vid_idx = I40E_VFTA_IDX(vlan_id);
7298 : 0 : vid_bit = I40E_VFTA_BIT(vlan_id);
7299 : :
7300 : 0 : if (vsi->vfta[vid_idx] & vid_bit)
7301 : : return 1;
7302 : : else
7303 : : return 0;
7304 : : }
7305 : :
7306 : : static void
7307 : : i40e_store_vlan_filter(struct i40e_vsi *vsi,
7308 : : uint16_t vlan_id, bool on)
7309 : : {
7310 : : uint32_t vid_idx, vid_bit;
7311 : :
7312 : 0 : vid_idx = I40E_VFTA_IDX(vlan_id);
7313 : 0 : vid_bit = I40E_VFTA_BIT(vlan_id);
7314 : :
7315 [ # # ]: 0 : if (on)
7316 : 0 : vsi->vfta[vid_idx] |= vid_bit;
7317 : : else
7318 : 0 : vsi->vfta[vid_idx] &= ~vid_bit;
7319 : : }
7320 : :
7321 : : void
7322 : 0 : i40e_set_vlan_filter(struct i40e_vsi *vsi,
7323 : : uint16_t vlan_id, bool on)
7324 : : {
7325 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7326 : 0 : struct i40e_aqc_add_remove_vlan_element_data vlan_data = {0};
7327 : : int ret;
7328 : :
7329 [ # # ]: 0 : if (vlan_id > RTE_ETH_VLAN_ID_MAX)
7330 : 0 : return;
7331 : :
7332 : : i40e_store_vlan_filter(vsi, vlan_id, on);
7333 : :
7334 [ # # # # : 0 : if ((!vsi->vlan_anti_spoof_on && !vsi->vlan_filter_on) || !vlan_id)
# # ]
7335 : : return;
7336 : :
7337 : 0 : vlan_data.vlan_tag = rte_cpu_to_le_16(vlan_id);
7338 : :
7339 [ # # ]: 0 : if (on) {
7340 : 0 : ret = i40e_aq_add_vlan(hw, vsi->seid,
7341 : : &vlan_data, 1, NULL);
7342 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7343 : 0 : PMD_DRV_LOG(ERR, "Failed to add vlan filter");
7344 : : } else {
7345 : 0 : ret = i40e_aq_remove_vlan(hw, vsi->seid,
7346 : : &vlan_data, 1, NULL);
7347 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7348 : 0 : PMD_DRV_LOG(ERR,
7349 : : "Failed to remove vlan filter");
7350 : : }
7351 : : }
7352 : :
7353 : : /**
7354 : : * Find all vlan options for specific mac addr,
7355 : : * return with actual vlan found.
7356 : : */
7357 : : int
7358 : 0 : i40e_find_all_vlan_for_mac(struct i40e_vsi *vsi,
7359 : : struct i40e_macvlan_filter *mv_f,
7360 : : int num, struct rte_ether_addr *addr)
7361 : : {
7362 : : int i;
7363 : : uint32_t j, k;
7364 : :
7365 : : /**
7366 : : * Not to use i40e_find_vlan_filter to decrease the loop time,
7367 : : * although the code looks complex.
7368 : : */
7369 [ # # ]: 0 : if (num < vsi->vlan_num)
7370 : : return I40E_ERR_PARAM;
7371 : :
7372 : : i = 0;
7373 [ # # ]: 0 : for (j = 0; j < I40E_VFTA_SIZE; j++) {
7374 [ # # ]: 0 : if (vsi->vfta[j]) {
7375 [ # # ]: 0 : for (k = 0; k < I40E_UINT32_BIT_SIZE; k++) {
7376 [ # # ]: 0 : if (vsi->vfta[j] & (1 << k)) {
7377 [ # # ]: 0 : if (i > num - 1) {
7378 : 0 : PMD_DRV_LOG(ERR,
7379 : : "vlan number doesn't match");
7380 : 0 : return I40E_ERR_PARAM;
7381 : : }
7382 : 0 : memcpy(&mv_f[i].macaddr,
7383 : : addr, ETH_ADDR_LEN);
7384 : 0 : mv_f[i].vlan_id =
7385 : 0 : j * I40E_UINT32_BIT_SIZE + k;
7386 : 0 : i++;
7387 : : }
7388 : : }
7389 : : }
7390 : : }
7391 : : return I40E_SUCCESS;
7392 : : }
7393 : :
7394 : : static inline int
7395 : 0 : i40e_find_all_mac_for_vlan(struct i40e_vsi *vsi,
7396 : : struct i40e_macvlan_filter *mv_f,
7397 : : int num,
7398 : : uint16_t vlan)
7399 : : {
7400 : : int i = 0;
7401 : : struct i40e_mac_filter *f;
7402 : :
7403 [ # # ]: 0 : if (num < vsi->mac_num)
7404 : : return I40E_ERR_PARAM;
7405 : :
7406 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7407 [ # # ]: 0 : if (i > num - 1) {
7408 : 0 : PMD_DRV_LOG(ERR, "buffer number not match");
7409 : 0 : return I40E_ERR_PARAM;
7410 : : }
7411 : 0 : memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
7412 : : ETH_ADDR_LEN);
7413 : 0 : mv_f[i].vlan_id = vlan;
7414 : 0 : mv_f[i].filter_type = f->mac_info.filter_type;
7415 : 0 : i++;
7416 : : }
7417 : :
7418 : : return I40E_SUCCESS;
7419 : : }
7420 : :
7421 : : static int
7422 : 0 : i40e_vsi_remove_all_macvlan_filter(struct i40e_vsi *vsi)
7423 : : {
7424 : : int i, j, num;
7425 : : struct i40e_mac_filter *f;
7426 : : struct i40e_macvlan_filter *mv_f;
7427 : : int ret = I40E_SUCCESS;
7428 : :
7429 [ # # # # ]: 0 : if (vsi == NULL || vsi->mac_num == 0)
7430 : : return I40E_ERR_PARAM;
7431 : :
7432 : : /* Case that no vlan is set */
7433 [ # # ]: 0 : if (vsi->vlan_num == 0)
7434 : 0 : num = vsi->mac_num;
7435 : : else
7436 : 0 : num = vsi->mac_num * vsi->vlan_num;
7437 : :
7438 : 0 : mv_f = calloc(num, sizeof(*mv_f));
7439 [ # # ]: 0 : if (mv_f == NULL) {
7440 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7441 : 0 : return I40E_ERR_NO_MEMORY;
7442 : : }
7443 : :
7444 : : i = 0;
7445 [ # # ]: 0 : if (vsi->vlan_num == 0) {
7446 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7447 : 0 : memcpy(&mv_f[i].macaddr,
7448 : 0 : &f->mac_info.mac_addr, ETH_ADDR_LEN);
7449 : 0 : mv_f[i].filter_type = f->mac_info.filter_type;
7450 : 0 : mv_f[i].vlan_id = 0;
7451 : 0 : i++;
7452 : : }
7453 : : } else {
7454 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
7455 : 0 : ret = i40e_find_all_vlan_for_mac(vsi,&mv_f[i],
7456 : 0 : vsi->vlan_num, &f->mac_info.mac_addr);
7457 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7458 : 0 : goto DONE;
7459 [ # # ]: 0 : for (j = i; j < i + vsi->vlan_num; j++)
7460 : 0 : mv_f[j].filter_type = f->mac_info.filter_type;
7461 : : i += vsi->vlan_num;
7462 : : }
7463 : : }
7464 : :
7465 : 0 : ret = i40e_remove_macvlan_filters(vsi, mv_f, num);
7466 : 0 : DONE:
7467 : 0 : free(mv_f);
7468 : :
7469 : 0 : return ret;
7470 : : }
7471 : :
7472 : : int
7473 : 0 : i40e_vsi_add_vlan(struct i40e_vsi *vsi, uint16_t vlan)
7474 : : {
7475 : 0 : struct i40e_macvlan_filter mv_f[I40E_NUM_MACADDR_MAX] = {0};
7476 : : int mac_num;
7477 : : int ret = I40E_SUCCESS;
7478 : :
7479 [ # # ]: 0 : if (!vsi || vlan > RTE_ETHER_MAX_VLAN_ID)
7480 : : return I40E_ERR_PARAM;
7481 : :
7482 : : /* If it's already set, just return */
7483 [ # # ]: 0 : if (i40e_find_vlan_filter(vsi,vlan))
7484 : : return I40E_SUCCESS;
7485 : :
7486 : 0 : mac_num = vsi->mac_num;
7487 : :
7488 [ # # ]: 0 : if (mac_num == 0) {
7489 : 0 : PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
7490 : 0 : return I40E_ERR_PARAM;
7491 : : }
7492 [ # # ]: 0 : if (mac_num > I40E_NUM_MACADDR_MAX) {
7493 : 0 : PMD_DRV_LOG(ERR, "Error! Too many MAC addresses");
7494 : 0 : return I40E_ERR_PARAM;
7495 : : }
7496 : :
7497 : 0 : ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
7498 : :
7499 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7500 : : return ret;
7501 : :
7502 : 0 : ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
7503 : :
7504 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7505 : : return ret;
7506 : :
7507 : 0 : i40e_set_vlan_filter(vsi, vlan, 1);
7508 : :
7509 : 0 : vsi->vlan_num++;
7510 : 0 : return I40E_SUCCESS;
7511 : : }
7512 : :
7513 : : int
7514 : 0 : i40e_vsi_delete_vlan(struct i40e_vsi *vsi, uint16_t vlan)
7515 : : {
7516 : 0 : struct i40e_macvlan_filter mv_f[I40E_NUM_MACADDR_MAX] = {0};
7517 : : int mac_num;
7518 : : int ret = I40E_SUCCESS;
7519 : :
7520 : : /**
7521 : : * Vlan 0 is the generic filter for untagged packets
7522 : : * and can't be removed.
7523 : : */
7524 [ # # # # ]: 0 : if (!vsi || vlan == 0 || vlan > RTE_ETHER_MAX_VLAN_ID)
7525 : : return I40E_ERR_PARAM;
7526 : :
7527 : : /* If can't find it, just return */
7528 [ # # ]: 0 : if (!i40e_find_vlan_filter(vsi, vlan))
7529 : : return I40E_ERR_PARAM;
7530 : :
7531 : 0 : mac_num = vsi->mac_num;
7532 : :
7533 [ # # ]: 0 : if (mac_num == 0) {
7534 : 0 : PMD_DRV_LOG(ERR, "Error! VSI doesn't have a mac addr");
7535 : 0 : return I40E_ERR_PARAM;
7536 : : }
7537 [ # # ]: 0 : if (mac_num > I40E_NUM_MACADDR_MAX) {
7538 : 0 : PMD_DRV_LOG(ERR, "Error! Too many MAC addresses");
7539 : 0 : return I40E_ERR_PARAM;
7540 : : }
7541 : :
7542 : 0 : ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, vlan);
7543 : :
7544 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7545 : : return ret;
7546 : :
7547 : 0 : ret = i40e_remove_macvlan_filters(vsi, mv_f, mac_num);
7548 : :
7549 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7550 : : return ret;
7551 : :
7552 : : /* This is last vlan to remove, replace all mac filter with vlan 0 */
7553 [ # # ]: 0 : if (vsi->vlan_num == 1) {
7554 : 0 : ret = i40e_find_all_mac_for_vlan(vsi, mv_f, mac_num, 0);
7555 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7556 : : return ret;
7557 : :
7558 : 0 : ret = i40e_add_macvlan_filters(vsi, mv_f, mac_num);
7559 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7560 : : return ret;
7561 : : }
7562 : :
7563 : 0 : i40e_set_vlan_filter(vsi, vlan, 0);
7564 : :
7565 : 0 : vsi->vlan_num--;
7566 : 0 : return I40E_SUCCESS;
7567 : : }
7568 : :
7569 : : int
7570 : 0 : i40e_vsi_add_mac(struct i40e_vsi *vsi, struct i40e_mac_filter_info *mac_filter)
7571 : : {
7572 : : struct i40e_mac_filter *f;
7573 : : struct i40e_macvlan_filter *mv_f;
7574 : : int i, vlan_num = 0;
7575 : : int ret = I40E_SUCCESS;
7576 : :
7577 : : /* If it's add and we've config it, return */
7578 : : f = i40e_find_mac_filter(vsi, &mac_filter->mac_addr);
7579 [ # # ]: 0 : if (f != NULL)
7580 : : return I40E_SUCCESS;
7581 [ # # ]: 0 : if (mac_filter->filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7582 : : mac_filter->filter_type == I40E_MACVLAN_HASH_MATCH) {
7583 : :
7584 : : /**
7585 : : * If vlan_num is 0, that's the first time to add mac,
7586 : : * set mask for vlan_id 0.
7587 : : */
7588 [ # # ]: 0 : if (vsi->vlan_num == 0) {
7589 : 0 : i40e_set_vlan_filter(vsi, 0, 1);
7590 : 0 : vsi->vlan_num = 1;
7591 : : }
7592 : 0 : vlan_num = vsi->vlan_num;
7593 [ # # ]: 0 : } else if (mac_filter->filter_type == I40E_MAC_PERFECT_MATCH ||
7594 : : mac_filter->filter_type == I40E_MAC_HASH_MATCH)
7595 : : vlan_num = 1;
7596 : :
7597 : 0 : mv_f = calloc(vlan_num, sizeof(*mv_f));
7598 [ # # ]: 0 : if (mv_f == NULL) {
7599 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7600 : 0 : return I40E_ERR_NO_MEMORY;
7601 : : }
7602 : :
7603 [ # # ]: 0 : for (i = 0; i < vlan_num; i++) {
7604 : 0 : mv_f[i].filter_type = mac_filter->filter_type;
7605 : 0 : memcpy(&mv_f[i].macaddr, &mac_filter->mac_addr,
7606 : : ETH_ADDR_LEN);
7607 : : }
7608 : :
7609 [ # # ]: 0 : if (mac_filter->filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7610 : : mac_filter->filter_type == I40E_MACVLAN_HASH_MATCH) {
7611 : 0 : ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
7612 : : &mac_filter->mac_addr);
7613 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7614 : 0 : goto DONE;
7615 : : }
7616 : :
7617 : 0 : ret = i40e_add_macvlan_filters(vsi, mv_f, vlan_num);
7618 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7619 : 0 : goto DONE;
7620 : :
7621 : : /* Add the mac addr into mac list */
7622 : 0 : f = rte_zmalloc("macv_filter", sizeof(*f), 0);
7623 [ # # ]: 0 : if (f == NULL) {
7624 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7625 : : ret = I40E_ERR_NO_MEMORY;
7626 : 0 : goto DONE;
7627 : : }
7628 : 0 : memcpy(&f->mac_info.mac_addr, &mac_filter->mac_addr,
7629 : : ETH_ADDR_LEN);
7630 : 0 : f->mac_info.filter_type = mac_filter->filter_type;
7631 : 0 : TAILQ_INSERT_TAIL(&vsi->mac_list, f, next);
7632 : 0 : vsi->mac_num++;
7633 : :
7634 : : ret = I40E_SUCCESS;
7635 : 0 : DONE:
7636 : 0 : free(mv_f);
7637 : :
7638 : 0 : return ret;
7639 : : }
7640 : :
7641 : : int
7642 : 0 : i40e_vsi_delete_mac(struct i40e_vsi *vsi, struct rte_ether_addr *addr)
7643 : : {
7644 : : struct i40e_mac_filter *f;
7645 : : struct i40e_macvlan_filter *mv_f;
7646 : : int i, vlan_num;
7647 : : enum i40e_mac_filter_type filter_type;
7648 : : int ret = I40E_SUCCESS;
7649 : :
7650 : : /* Can't find it, return an error */
7651 : : f = i40e_find_mac_filter(vsi, addr);
7652 [ # # ]: 0 : if (f == NULL)
7653 : : return I40E_ERR_PARAM;
7654 : :
7655 : 0 : vlan_num = vsi->vlan_num;
7656 : 0 : filter_type = f->mac_info.filter_type;
7657 : 0 : if (filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7658 [ # # ]: 0 : filter_type == I40E_MACVLAN_HASH_MATCH) {
7659 [ # # ]: 0 : if (vlan_num == 0) {
7660 : 0 : PMD_DRV_LOG(ERR, "VLAN number shouldn't be 0");
7661 : 0 : return I40E_ERR_PARAM;
7662 : : }
7663 : 0 : } else if (filter_type == I40E_MAC_PERFECT_MATCH ||
7664 [ # # ]: 0 : filter_type == I40E_MAC_HASH_MATCH)
7665 : : vlan_num = 1;
7666 : :
7667 : 0 : mv_f = calloc(vlan_num, sizeof(*mv_f));
7668 [ # # ]: 0 : if (mv_f == NULL) {
7669 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
7670 : 0 : return I40E_ERR_NO_MEMORY;
7671 : : }
7672 : :
7673 [ # # ]: 0 : for (i = 0; i < vlan_num; i++) {
7674 : 0 : mv_f[i].filter_type = filter_type;
7675 : 0 : memcpy(&mv_f[i].macaddr, &f->mac_info.mac_addr,
7676 : : ETH_ADDR_LEN);
7677 : : }
7678 [ # # ]: 0 : if (filter_type == I40E_MACVLAN_PERFECT_MATCH ||
7679 : : filter_type == I40E_MACVLAN_HASH_MATCH) {
7680 : 0 : ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num, addr);
7681 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7682 : 0 : goto DONE;
7683 : : }
7684 : :
7685 : 0 : ret = i40e_remove_macvlan_filters(vsi, mv_f, vlan_num);
7686 [ # # ]: 0 : if (ret != I40E_SUCCESS)
7687 : 0 : goto DONE;
7688 : :
7689 : : /* Remove the mac addr into mac list */
7690 [ # # ]: 0 : TAILQ_REMOVE(&vsi->mac_list, f, next);
7691 : 0 : rte_free(f);
7692 : 0 : vsi->mac_num--;
7693 : :
7694 : : ret = I40E_SUCCESS;
7695 : 0 : DONE:
7696 : 0 : free(mv_f);
7697 : 0 : return ret;
7698 : : }
7699 : :
7700 : : /* Configure hash enable flags for RSS */
7701 : : uint64_t
7702 : 0 : i40e_config_hena(const struct i40e_adapter *adapter, uint64_t flags)
7703 : : {
7704 : : uint64_t hena = 0;
7705 : : int i;
7706 : :
7707 [ # # ]: 0 : if (!flags)
7708 : : return hena;
7709 : :
7710 [ # # ]: 0 : for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < I40E_FLOW_TYPE_MAX; i++) {
7711 [ # # ]: 0 : if (flags & RTE_BIT64(i))
7712 : 0 : hena |= adapter->pctypes_tbl[i];
7713 : : }
7714 : :
7715 : : return hena;
7716 : : }
7717 : :
7718 : : /* Parse the hash enable flags */
7719 : : uint64_t
7720 : 0 : i40e_parse_hena(const struct i40e_adapter *adapter, uint64_t flags)
7721 : : {
7722 : : uint64_t rss_hf = 0;
7723 : :
7724 [ # # ]: 0 : if (!flags)
7725 : : return rss_hf;
7726 : : int i;
7727 : :
7728 [ # # ]: 0 : for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < I40E_FLOW_TYPE_MAX; i++) {
7729 [ # # ]: 0 : if (flags & adapter->pctypes_tbl[i])
7730 : 0 : rss_hf |= RTE_BIT64(i);
7731 : : }
7732 : : return rss_hf;
7733 : : }
7734 : :
7735 : : /* Disable RSS */
7736 : : void
7737 : 0 : i40e_pf_disable_rss(struct i40e_pf *pf)
7738 : : {
7739 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7740 : :
7741 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
7742 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
7743 : 0 : I40E_WRITE_FLUSH(hw);
7744 : 0 : }
7745 : :
7746 : : int
7747 : 0 : i40e_set_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t key_len)
7748 : : {
7749 : 0 : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
7750 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7751 : : uint16_t key_idx = (vsi->type == I40E_VSI_SRIOV) ?
7752 : : I40E_VFQF_HKEY_MAX_INDEX :
7753 : : I40E_PFQF_HKEY_MAX_INDEX;
7754 : :
7755 [ # # ]: 0 : if (!key || key_len == 0) {
7756 : 0 : PMD_DRV_LOG(DEBUG, "No key to be configured");
7757 : 0 : return 0;
7758 [ # # ]: 0 : } else if (key_len != (key_idx + 1) *
7759 : : sizeof(uint32_t)) {
7760 : 0 : PMD_DRV_LOG(ERR, "Invalid key length %u", key_len);
7761 : 0 : return -EINVAL;
7762 : : }
7763 : :
7764 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
7765 : : struct i40e_aqc_get_set_rss_key_data *key_dw =
7766 : : (struct i40e_aqc_get_set_rss_key_data *)key;
7767 : : enum i40e_status_code status =
7768 : 0 : i40e_aq_set_rss_key(hw, vsi->vsi_id, key_dw);
7769 : :
7770 [ # # ]: 0 : if (status) {
7771 : 0 : PMD_DRV_LOG(ERR,
7772 : : "Failed to configure RSS key via AQ, error status: %d",
7773 : : status);
7774 : 0 : return -EIO;
7775 : : }
7776 : : } else {
7777 : : uint32_t *hash_key = (uint32_t *)key;
7778 : : uint16_t i;
7779 : :
7780 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
7781 [ # # ]: 0 : for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++)
7782 : 0 : I40E_WRITE_REG(
7783 : : hw,
7784 : : I40E_VFQF_HKEY1(i, vsi->user_param),
7785 : : hash_key[i]);
7786 : :
7787 : : } else {
7788 [ # # ]: 0 : for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
7789 : 0 : I40E_WRITE_REG(hw, I40E_PFQF_HKEY(i),
7790 : : hash_key[i]);
7791 : : }
7792 : 0 : I40E_WRITE_FLUSH(hw);
7793 : : }
7794 : :
7795 : : return 0;
7796 : : }
7797 : :
7798 : : static int
7799 : 0 : i40e_get_rss_key(struct i40e_vsi *vsi, uint8_t *key, uint8_t *key_len)
7800 : : {
7801 : 0 : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
7802 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
7803 : : uint32_t reg;
7804 : : int ret;
7805 : :
7806 [ # # ]: 0 : if (!key || !key_len)
7807 : : return 0;
7808 : :
7809 [ # # ]: 0 : if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) {
7810 : 0 : ret = i40e_aq_get_rss_key(hw, vsi->vsi_id,
7811 : : (struct i40e_aqc_get_set_rss_key_data *)key);
7812 [ # # ]: 0 : if (ret) {
7813 : 0 : PMD_INIT_LOG(ERR, "Failed to get RSS key via AQ");
7814 : 0 : return ret;
7815 : : }
7816 : : } else {
7817 : : uint32_t *key_dw = (uint32_t *)key;
7818 : : uint16_t i;
7819 : :
7820 [ # # ]: 0 : if (vsi->type == I40E_VSI_SRIOV) {
7821 [ # # ]: 0 : for (i = 0; i <= I40E_VFQF_HKEY_MAX_INDEX; i++) {
7822 : 0 : reg = I40E_VFQF_HKEY1(i, vsi->user_param);
7823 : 0 : key_dw[i] = i40e_read_rx_ctl(hw, reg);
7824 : : }
7825 : 0 : *key_len = (I40E_VFQF_HKEY_MAX_INDEX + 1) *
7826 : : sizeof(uint32_t);
7827 : : } else {
7828 [ # # ]: 0 : for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
7829 : 0 : reg = I40E_PFQF_HKEY(i);
7830 : 0 : key_dw[i] = i40e_read_rx_ctl(hw, reg);
7831 : : }
7832 : 0 : *key_len = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
7833 : : sizeof(uint32_t);
7834 : : }
7835 : : }
7836 : : return 0;
7837 : : }
7838 : :
7839 : : static int
7840 : 0 : i40e_hw_rss_hash_set(struct i40e_pf *pf, struct rte_eth_rss_conf *rss_conf)
7841 : : {
7842 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
7843 : : uint64_t hena;
7844 : : int ret;
7845 : :
7846 : 0 : ret = i40e_set_rss_key(pf->main_vsi, rss_conf->rss_key,
7847 : 0 : rss_conf->rss_key_len);
7848 [ # # ]: 0 : if (ret)
7849 : : return ret;
7850 : :
7851 : 0 : hena = i40e_config_hena(pf->adapter, rss_conf->rss_hf);
7852 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
7853 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
7854 : 0 : I40E_WRITE_FLUSH(hw);
7855 : :
7856 : 0 : return 0;
7857 : : }
7858 : :
7859 : : static int
7860 : 0 : i40e_dev_rss_hash_update(struct rte_eth_dev *dev,
7861 : : struct rte_eth_rss_conf *rss_conf)
7862 : : {
7863 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7864 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7865 : 0 : uint64_t rss_hf = rss_conf->rss_hf & pf->adapter->flow_types_mask;
7866 : : uint64_t hena;
7867 : :
7868 : 0 : hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
7869 : 0 : hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
7870 : :
7871 [ # # ]: 0 : if (!(hena & pf->adapter->pctypes_mask)) { /* RSS disabled */
7872 [ # # ]: 0 : if (rss_hf != 0) /* Enable RSS */
7873 : : return -EINVAL;
7874 : 0 : return 0; /* Nothing to do */
7875 : : }
7876 : : /* RSS enabled */
7877 [ # # ]: 0 : if (rss_hf == 0) /* Disable RSS */
7878 : : return -EINVAL;
7879 : :
7880 : 0 : return i40e_hw_rss_hash_set(pf, rss_conf);
7881 : : }
7882 : :
7883 : : static int
7884 : 0 : i40e_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
7885 : : struct rte_eth_rss_conf *rss_conf)
7886 : : {
7887 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
7888 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
7889 : : uint64_t hena;
7890 : : int ret;
7891 : :
7892 [ # # ]: 0 : if (!rss_conf)
7893 : : return -EINVAL;
7894 : :
7895 : 0 : ret = i40e_get_rss_key(pf->main_vsi, rss_conf->rss_key,
7896 : : &rss_conf->rss_key_len);
7897 [ # # ]: 0 : if (ret)
7898 : : return ret;
7899 : :
7900 : 0 : hena = (uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0));
7901 : 0 : hena |= ((uint64_t)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1))) << 32;
7902 : 0 : rss_conf->rss_hf = i40e_parse_hena(pf->adapter, hena);
7903 : :
7904 : 0 : return 0;
7905 : : }
7906 : :
7907 : : static int
7908 : 0 : i40e_dev_get_filter_type(uint16_t filter_type, uint16_t *flag)
7909 : : {
7910 [ # # # # : 0 : switch (filter_type) {
# # # # ]
7911 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC_IVLAN:
7912 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
7913 : 0 : break;
7914 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC_IVLAN_TENID:
7915 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
7916 : 0 : break;
7917 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC_TENID:
7918 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC_TEN_ID;
7919 : 0 : break;
7920 : 0 : case RTE_ETH_TUNNEL_FILTER_OMAC_TENID_IMAC:
7921 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_OMAC_TEN_ID_IMAC;
7922 : 0 : break;
7923 : 0 : case RTE_ETH_TUNNEL_FILTER_IMAC:
7924 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
7925 : 0 : break;
7926 : 0 : case RTE_ETH_TUNNEL_FILTER_OIP:
7927 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_OIP;
7928 : 0 : break;
7929 : 0 : case RTE_ETH_TUNNEL_FILTER_IIP:
7930 : 0 : *flag = I40E_AQC_ADD_CLOUD_FILTER_IIP;
7931 : 0 : break;
7932 : 0 : default:
7933 : 0 : PMD_DRV_LOG(ERR, "invalid tunnel filter type");
7934 : 0 : return -EINVAL;
7935 : : }
7936 : :
7937 : : return 0;
7938 : : }
7939 : :
7940 : : /* Convert tunnel filter structure */
7941 : : static int
7942 [ # # ]: 0 : i40e_tunnel_filter_convert(
7943 : : struct i40e_aqc_cloud_filters_element_bb *cld_filter,
7944 : : struct i40e_tunnel_filter *tunnel_filter)
7945 : : {
7946 : : rte_ether_addr_copy((struct rte_ether_addr *)
7947 : : &cld_filter->element.outer_mac,
7948 : : (struct rte_ether_addr *)&tunnel_filter->input.outer_mac);
7949 : : rte_ether_addr_copy((struct rte_ether_addr *)
7950 : : &cld_filter->element.inner_mac,
7951 : : (struct rte_ether_addr *)&tunnel_filter->input.inner_mac);
7952 : 0 : tunnel_filter->input.inner_vlan = cld_filter->element.inner_vlan;
7953 [ # # ]: 0 : if ((rte_le_to_cpu_16(cld_filter->element.flags) &
7954 : : I40E_AQC_ADD_CLOUD_FLAGS_IPV6) ==
7955 : : I40E_AQC_ADD_CLOUD_FLAGS_IPV6)
7956 : 0 : tunnel_filter->input.ip_type = I40E_TUNNEL_IPTYPE_IPV6;
7957 : : else
7958 : 0 : tunnel_filter->input.ip_type = I40E_TUNNEL_IPTYPE_IPV4;
7959 : 0 : tunnel_filter->input.flags = cld_filter->element.flags;
7960 : 0 : tunnel_filter->input.tenant_id = cld_filter->element.tenant_id;
7961 : 0 : tunnel_filter->queue = cld_filter->element.queue_number;
7962 : 0 : memcpy(tunnel_filter->input.general_fields,
7963 : 0 : cld_filter->general_fields,
7964 : : sizeof(cld_filter->general_fields));
7965 : :
7966 : 0 : return 0;
7967 : : }
7968 : :
7969 : : /* Check if there exists the tunnel filter */
7970 : : struct i40e_tunnel_filter *
7971 : 0 : i40e_sw_tunnel_filter_lookup(struct i40e_tunnel_rule *tunnel_rule,
7972 : : const struct i40e_tunnel_filter_input *input)
7973 : : {
7974 : : int ret;
7975 : :
7976 : 0 : ret = rte_hash_lookup(tunnel_rule->hash_table, (const void *)input);
7977 [ # # ]: 0 : if (ret < 0)
7978 : : return NULL;
7979 : :
7980 : 0 : return tunnel_rule->hash_map[ret];
7981 : : }
7982 : :
7983 : : /* Add a tunnel filter into the SW list */
7984 : : static int
7985 : 0 : i40e_sw_tunnel_filter_insert(struct i40e_pf *pf,
7986 : : struct i40e_tunnel_filter *tunnel_filter)
7987 : : {
7988 : : struct i40e_tunnel_rule *rule = &pf->tunnel;
7989 : : int ret;
7990 : :
7991 : 0 : ret = rte_hash_add_key(rule->hash_table, &tunnel_filter->input);
7992 [ # # ]: 0 : if (ret < 0) {
7993 : 0 : PMD_DRV_LOG(ERR,
7994 : : "Failed to insert tunnel filter to hash table %d!",
7995 : : ret);
7996 : 0 : return ret;
7997 : : }
7998 : 0 : rule->hash_map[ret] = tunnel_filter;
7999 : :
8000 : 0 : TAILQ_INSERT_TAIL(&rule->tunnel_list, tunnel_filter, rules);
8001 : :
8002 : 0 : return 0;
8003 : : }
8004 : :
8005 : : /* Delete a tunnel filter from the SW list */
8006 : : int
8007 : 0 : i40e_sw_tunnel_filter_del(struct i40e_pf *pf,
8008 : : struct i40e_tunnel_filter_input *input)
8009 : : {
8010 : : struct i40e_tunnel_rule *rule = &pf->tunnel;
8011 : : struct i40e_tunnel_filter *tunnel_filter;
8012 : : int ret;
8013 : :
8014 : 0 : ret = rte_hash_del_key(rule->hash_table, input);
8015 [ # # ]: 0 : if (ret < 0) {
8016 : 0 : PMD_DRV_LOG(ERR,
8017 : : "Failed to delete tunnel filter to hash table %d!",
8018 : : ret);
8019 : 0 : return ret;
8020 : : }
8021 : 0 : tunnel_filter = rule->hash_map[ret];
8022 : 0 : rule->hash_map[ret] = NULL;
8023 : :
8024 [ # # ]: 0 : TAILQ_REMOVE(&rule->tunnel_list, tunnel_filter, rules);
8025 : 0 : rte_free(tunnel_filter);
8026 : :
8027 : 0 : return 0;
8028 : : }
8029 : :
8030 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_TR_WORD0 0x48
8031 : : #define I40E_TR_VXLAN_GRE_KEY_MASK 0x4
8032 : : #define I40E_TR_GENEVE_KEY_MASK 0x8
8033 : : #define I40E_TR_GENERIC_UDP_TUNNEL_MASK 0x40
8034 : : #define I40E_TR_GRE_KEY_MASK 0x400
8035 : : #define I40E_TR_GRE_KEY_WITH_XSUM_MASK 0x800
8036 : : #define I40E_TR_GRE_NO_KEY_MASK 0x8000
8037 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_PORT_TR_WORD0 0x49
8038 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_DIRECTION_WORD0 0x41
8039 : : #define I40E_AQC_REPLACE_CLOUD_CMD_INPUT_INGRESS_WORD0 0x80
8040 : : #define I40E_DIRECTION_INGRESS_KEY 0x8000
8041 : : #define I40E_TR_L4_TYPE_TCP 0x2
8042 : : #define I40E_TR_L4_TYPE_UDP 0x4
8043 : : #define I40E_TR_L4_TYPE_SCTP 0x8
8044 : :
8045 : : static enum
8046 : 0 : i40e_status_code i40e_replace_mpls_l1_filter(struct i40e_pf *pf)
8047 : : {
8048 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8049 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8050 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8051 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8052 : : enum i40e_status_code status = I40E_SUCCESS;
8053 : :
8054 [ # # ]: 0 : if (pf->support_multi_driver) {
8055 : 0 : PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
8056 : 0 : return I40E_NOT_SUPPORTED;
8057 : : }
8058 : :
8059 : : memset(&filter_replace, 0,
8060 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8061 : : memset(&filter_replace_buf, 0,
8062 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8063 : :
8064 : : /* create L1 filter */
8065 : 0 : filter_replace.old_filter_type =
8066 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_IMAC;
8067 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X11;
8068 : : filter_replace.tr_bit = 0;
8069 : :
8070 : : /* Prepare the buffer, 3 entries */
8071 : : filter_replace_buf.data[0] =
8072 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8073 : 0 : filter_replace_buf.data[0] |=
8074 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8075 : 0 : filter_replace_buf.data[2] = 0xFF;
8076 : 0 : filter_replace_buf.data[3] = 0xFF;
8077 : : filter_replace_buf.data[4] =
8078 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8079 : 0 : filter_replace_buf.data[4] |=
8080 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8081 : 0 : filter_replace_buf.data[7] = 0xF0;
8082 : : filter_replace_buf.data[8]
8083 : : = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_TR_WORD0;
8084 : 0 : filter_replace_buf.data[8] |=
8085 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8086 : 0 : filter_replace_buf.data[10] = I40E_TR_VXLAN_GRE_KEY_MASK |
8087 : : I40E_TR_GENEVE_KEY_MASK |
8088 : : I40E_TR_GENERIC_UDP_TUNNEL_MASK;
8089 : 0 : filter_replace_buf.data[11] = (I40E_TR_GRE_KEY_MASK |
8090 : : I40E_TR_GRE_KEY_WITH_XSUM_MASK |
8091 : : I40E_TR_GRE_NO_KEY_MASK) >> 8;
8092 : :
8093 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8094 : : &filter_replace_buf);
8095 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8096 [ # # ]: 0 : filter_replace.new_filter_type))
8097 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8098 : : " original: 0x%x, new: 0x%x",
8099 : : dev->device->name,
8100 : : filter_replace.old_filter_type,
8101 : : filter_replace.new_filter_type);
8102 : :
8103 : : return status;
8104 : : }
8105 : :
8106 : : static enum
8107 : 0 : i40e_status_code i40e_replace_mpls_cloud_filter(struct i40e_pf *pf)
8108 : : {
8109 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8110 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8111 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8112 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8113 : : enum i40e_status_code status = I40E_SUCCESS;
8114 : :
8115 [ # # ]: 0 : if (pf->support_multi_driver) {
8116 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8117 : 0 : return I40E_NOT_SUPPORTED;
8118 : : }
8119 : :
8120 : : /* For MPLSoUDP */
8121 : : memset(&filter_replace, 0,
8122 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8123 : : memset(&filter_replace_buf, 0,
8124 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8125 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER |
8126 : : I40E_AQC_MIRROR_CLOUD_FILTER;
8127 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IIP;
8128 : 0 : filter_replace.new_filter_type =
8129 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8130 : : /* Prepare the buffer, 2 entries */
8131 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8132 : 0 : filter_replace_buf.data[0] |=
8133 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8134 : : filter_replace_buf.data[4] = I40E_AQC_ADD_L1_FILTER_0X11;
8135 : 0 : filter_replace_buf.data[4] |=
8136 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8137 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8138 : : &filter_replace_buf);
8139 [ # # ]: 0 : if (status < 0)
8140 : : return status;
8141 : 0 : if (filter_replace.old_filter_type !=
8142 [ # # ]: 0 : filter_replace.new_filter_type)
8143 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8144 : : " original: 0x%x, new: 0x%x",
8145 : : dev->device->name,
8146 : : filter_replace.old_filter_type,
8147 : : filter_replace.new_filter_type);
8148 : :
8149 : : /* For MPLSoGRE */
8150 : : memset(&filter_replace, 0,
8151 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8152 : : memset(&filter_replace_buf, 0,
8153 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8154 : :
8155 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER |
8156 : : I40E_AQC_MIRROR_CLOUD_FILTER;
8157 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IMAC;
8158 : 0 : filter_replace.new_filter_type =
8159 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8160 : : /* Prepare the buffer, 2 entries */
8161 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8162 : 0 : filter_replace_buf.data[0] |=
8163 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8164 : : filter_replace_buf.data[4] = I40E_AQC_ADD_L1_FILTER_0X11;
8165 : 0 : filter_replace_buf.data[4] |=
8166 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8167 : :
8168 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8169 : : &filter_replace_buf);
8170 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8171 [ # # ]: 0 : filter_replace.new_filter_type))
8172 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8173 : : " original: 0x%x, new: 0x%x",
8174 : : dev->device->name,
8175 : : filter_replace.old_filter_type,
8176 : : filter_replace.new_filter_type);
8177 : :
8178 : : return status;
8179 : : }
8180 : :
8181 : : static enum i40e_status_code
8182 : 0 : i40e_replace_gtp_l1_filter(struct i40e_pf *pf)
8183 : : {
8184 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8185 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8186 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8187 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8188 : : enum i40e_status_code status = I40E_SUCCESS;
8189 : :
8190 [ # # ]: 0 : if (pf->support_multi_driver) {
8191 : 0 : PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
8192 : 0 : return I40E_NOT_SUPPORTED;
8193 : : }
8194 : :
8195 : : /* For GTP-C */
8196 : : memset(&filter_replace, 0,
8197 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8198 : : memset(&filter_replace_buf, 0,
8199 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8200 : : /* create L1 filter */
8201 : 0 : filter_replace.old_filter_type =
8202 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_IMAC;
8203 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X12;
8204 : 0 : filter_replace.tr_bit = I40E_AQC_NEW_TR_22 |
8205 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8206 : : /* Prepare the buffer, 2 entries */
8207 : : filter_replace_buf.data[0] =
8208 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8209 : 0 : filter_replace_buf.data[0] |=
8210 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8211 : 0 : filter_replace_buf.data[2] = 0xFF;
8212 : 0 : filter_replace_buf.data[3] = 0xFF;
8213 : : filter_replace_buf.data[4] =
8214 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8215 : 0 : filter_replace_buf.data[4] |=
8216 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8217 : 0 : filter_replace_buf.data[6] = 0xFF;
8218 : 0 : filter_replace_buf.data[7] = 0xFF;
8219 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8220 : : &filter_replace_buf);
8221 [ # # ]: 0 : if (status < 0)
8222 : : return status;
8223 : 0 : if (filter_replace.old_filter_type !=
8224 [ # # ]: 0 : filter_replace.new_filter_type)
8225 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8226 : : " original: 0x%x, new: 0x%x",
8227 : : dev->device->name,
8228 : : filter_replace.old_filter_type,
8229 : : filter_replace.new_filter_type);
8230 : :
8231 : : /* for GTP-U */
8232 : : memset(&filter_replace, 0,
8233 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8234 : : memset(&filter_replace_buf, 0,
8235 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8236 : : /* create L1 filter */
8237 : 0 : filter_replace.old_filter_type =
8238 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TUNNLE_KEY;
8239 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X13;
8240 : 0 : filter_replace.tr_bit = I40E_AQC_NEW_TR_21 |
8241 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8242 : : /* Prepare the buffer, 2 entries */
8243 : : filter_replace_buf.data[0] =
8244 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD0;
8245 : 0 : filter_replace_buf.data[0] |=
8246 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8247 : 0 : filter_replace_buf.data[2] = 0xFF;
8248 : 0 : filter_replace_buf.data[3] = 0xFF;
8249 : : filter_replace_buf.data[4] =
8250 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TEID_WORD1;
8251 : 0 : filter_replace_buf.data[4] |=
8252 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8253 : 0 : filter_replace_buf.data[6] = 0xFF;
8254 : 0 : filter_replace_buf.data[7] = 0xFF;
8255 : :
8256 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8257 : : &filter_replace_buf);
8258 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8259 [ # # ]: 0 : filter_replace.new_filter_type))
8260 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8261 : : " original: 0x%x, new: 0x%x",
8262 : : dev->device->name,
8263 : : filter_replace.old_filter_type,
8264 : : filter_replace.new_filter_type);
8265 : :
8266 : : return status;
8267 : : }
8268 : :
8269 : : static enum
8270 : 0 : i40e_status_code i40e_replace_gtp_cloud_filter(struct i40e_pf *pf)
8271 : : {
8272 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8273 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8274 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8275 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8276 : : enum i40e_status_code status = I40E_SUCCESS;
8277 : :
8278 [ # # ]: 0 : if (pf->support_multi_driver) {
8279 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8280 : 0 : return I40E_NOT_SUPPORTED;
8281 : : }
8282 : :
8283 : : /* for GTP-C */
8284 : : memset(&filter_replace, 0,
8285 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8286 : : memset(&filter_replace_buf, 0,
8287 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8288 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8289 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN;
8290 : 0 : filter_replace.new_filter_type =
8291 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8292 : : /* Prepare the buffer, 2 entries */
8293 : : filter_replace_buf.data[0] = I40E_AQC_ADD_L1_FILTER_0X12;
8294 : 0 : filter_replace_buf.data[0] |=
8295 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8296 : : filter_replace_buf.data[4] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8297 : 0 : filter_replace_buf.data[4] |=
8298 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8299 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8300 : : &filter_replace_buf);
8301 [ # # ]: 0 : if (status < 0)
8302 : : return status;
8303 : 0 : if (filter_replace.old_filter_type !=
8304 [ # # ]: 0 : filter_replace.new_filter_type)
8305 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8306 : : " original: 0x%x, new: 0x%x",
8307 : : dev->device->name,
8308 : : filter_replace.old_filter_type,
8309 : : filter_replace.new_filter_type);
8310 : :
8311 : : /* for GTP-U */
8312 : : memset(&filter_replace, 0,
8313 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8314 : : memset(&filter_replace_buf, 0,
8315 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8316 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8317 : 0 : filter_replace.old_filter_type =
8318 : : I40E_AQC_ADD_CLOUD_FILTER_IMAC_IVLAN_TEN_ID;
8319 : 0 : filter_replace.new_filter_type =
8320 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8321 : : /* Prepare the buffer, 2 entries */
8322 : : filter_replace_buf.data[0] = I40E_AQC_ADD_L1_FILTER_0X13;
8323 : 0 : filter_replace_buf.data[0] |=
8324 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8325 : : filter_replace_buf.data[4] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8326 : 0 : filter_replace_buf.data[4] |=
8327 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8328 : :
8329 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8330 : : &filter_replace_buf);
8331 [ # # ]: 0 : if (!status && (filter_replace.old_filter_type !=
8332 [ # # ]: 0 : filter_replace.new_filter_type))
8333 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8334 : : " original: 0x%x, new: 0x%x",
8335 : : dev->device->name,
8336 : : filter_replace.old_filter_type,
8337 : : filter_replace.new_filter_type);
8338 : :
8339 : : return status;
8340 : : }
8341 : :
8342 : : static enum i40e_status_code
8343 : 0 : i40e_replace_port_l1_filter(struct i40e_pf *pf,
8344 : : enum i40e_l4_port_type l4_port_type)
8345 : : {
8346 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8347 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8348 : : enum i40e_status_code status = I40E_SUCCESS;
8349 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8350 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8351 : :
8352 [ # # ]: 0 : if (pf->support_multi_driver) {
8353 : 0 : PMD_DRV_LOG(ERR, "Replace l1 filter is not supported.");
8354 : 0 : return I40E_NOT_SUPPORTED;
8355 : : }
8356 : :
8357 : : memset(&filter_replace, 0,
8358 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8359 : : memset(&filter_replace_buf, 0,
8360 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8361 : :
8362 : : /* create L1 filter */
8363 [ # # ]: 0 : if (l4_port_type == I40E_L4_PORT_TYPE_SRC) {
8364 : 0 : filter_replace.old_filter_type =
8365 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_TUNNLE_KEY;
8366 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X11;
8367 : 0 : filter_replace_buf.data[8] =
8368 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_SRC_PORT;
8369 : : } else {
8370 : 0 : filter_replace.old_filter_type =
8371 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG_IVLAN;
8372 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_L1_FILTER_0X10;
8373 : 0 : filter_replace_buf.data[8] =
8374 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_DST_PORT;
8375 : : }
8376 : :
8377 : : filter_replace.tr_bit = 0;
8378 : : /* Prepare the buffer, 3 entries */
8379 : : filter_replace_buf.data[0] =
8380 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_DIRECTION_WORD0;
8381 : 0 : filter_replace_buf.data[0] |=
8382 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8383 : : filter_replace_buf.data[2] = 0x00;
8384 : 0 : filter_replace_buf.data[3] =
8385 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_INGRESS_WORD0;
8386 : : filter_replace_buf.data[4] =
8387 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_PORT_TR_WORD0;
8388 : 0 : filter_replace_buf.data[4] |=
8389 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8390 : : filter_replace_buf.data[5] = 0x00;
8391 : 0 : filter_replace_buf.data[6] = I40E_TR_L4_TYPE_UDP |
8392 : : I40E_TR_L4_TYPE_TCP |
8393 : : I40E_TR_L4_TYPE_SCTP;
8394 : : filter_replace_buf.data[7] = 0x00;
8395 : 0 : filter_replace_buf.data[8] |=
8396 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8397 : : filter_replace_buf.data[9] = 0x00;
8398 : 0 : filter_replace_buf.data[10] = 0xFF;
8399 : 0 : filter_replace_buf.data[11] = 0xFF;
8400 : :
8401 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8402 : : &filter_replace_buf);
8403 [ # # ]: 0 : if (!status && filter_replace.old_filter_type !=
8404 [ # # ]: 0 : filter_replace.new_filter_type)
8405 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
8406 : : " original: 0x%x, new: 0x%x",
8407 : : dev->device->name,
8408 : : filter_replace.old_filter_type,
8409 : : filter_replace.new_filter_type);
8410 : :
8411 : : return status;
8412 : : }
8413 : :
8414 : : static enum i40e_status_code
8415 : 0 : i40e_replace_port_cloud_filter(struct i40e_pf *pf,
8416 : : enum i40e_l4_port_type l4_port_type)
8417 : : {
8418 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
8419 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
8420 : : enum i40e_status_code status = I40E_SUCCESS;
8421 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8422 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
8423 : :
8424 [ # # ]: 0 : if (pf->support_multi_driver) {
8425 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
8426 : 0 : return I40E_NOT_SUPPORTED;
8427 : : }
8428 : :
8429 : : memset(&filter_replace, 0,
8430 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
8431 : : memset(&filter_replace_buf, 0,
8432 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
8433 : :
8434 [ # # ]: 0 : if (l4_port_type == I40E_L4_PORT_TYPE_SRC) {
8435 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_IIP;
8436 : 0 : filter_replace.new_filter_type =
8437 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8438 : 0 : filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X11;
8439 : : } else {
8440 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_OIP;
8441 : 0 : filter_replace.new_filter_type =
8442 : : I40E_AQC_ADD_CLOUD_FILTER_0X10;
8443 : 0 : filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X10;
8444 : : }
8445 : :
8446 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
8447 : : filter_replace.tr_bit = 0;
8448 : : /* Prepare the buffer, 2 entries */
8449 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
8450 : 0 : filter_replace_buf.data[0] |=
8451 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8452 : 0 : filter_replace_buf.data[4] |=
8453 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
8454 : 0 : status = i40e_aq_replace_cloud_filters(hw, &filter_replace,
8455 : : &filter_replace_buf);
8456 : :
8457 [ # # ]: 0 : if (!status && filter_replace.old_filter_type !=
8458 [ # # ]: 0 : filter_replace.new_filter_type)
8459 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
8460 : : " original: 0x%x, new: 0x%x",
8461 : : dev->device->name,
8462 : : filter_replace.old_filter_type,
8463 : : filter_replace.new_filter_type);
8464 : :
8465 : : return status;
8466 : : }
8467 : :
8468 : : int
8469 : 0 : i40e_dev_consistent_tunnel_filter_set(struct i40e_pf *pf,
8470 : : struct i40e_tunnel_filter_conf *tunnel_filter,
8471 : : uint8_t add)
8472 : : {
8473 : : uint16_t ip_type;
8474 : : uint32_t ipv4_addr, ipv4_addr_le;
8475 : : uint8_t i, tun_type = 0;
8476 : : /* internal variable to convert ipv6 byte order */
8477 : : uint32_t convert_ipv6[4];
8478 : : int val, ret = 0;
8479 : : struct i40e_pf_vf *vf = NULL;
8480 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8481 : : struct i40e_vsi *vsi;
8482 : 0 : struct i40e_aqc_cloud_filters_element_bb cld_filter = {0};
8483 [ # # ]: 0 : struct i40e_tunnel_rule *tunnel_rule = &pf->tunnel;
8484 : : struct i40e_tunnel_filter *node;
8485 : : struct i40e_tunnel_filter check_filter; /* Check if filter exists */
8486 : : uint32_t teid_le;
8487 : : bool big_buffer = 0;
8488 : :
8489 : : rte_ether_addr_copy(&tunnel_filter->outer_mac,
8490 : : (struct rte_ether_addr *)&cld_filter.element.outer_mac);
8491 : : rte_ether_addr_copy(&tunnel_filter->inner_mac,
8492 : : (struct rte_ether_addr *)&cld_filter.element.inner_mac);
8493 : :
8494 : 0 : cld_filter.element.inner_vlan =
8495 : 0 : rte_cpu_to_le_16(tunnel_filter->inner_vlan);
8496 [ # # ]: 0 : if (tunnel_filter->ip_type == I40E_TUNNEL_IPTYPE_IPV4) {
8497 : : ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV4;
8498 [ # # ]: 0 : ipv4_addr = rte_be_to_cpu_32(tunnel_filter->ip_addr.ipv4_addr);
8499 : : ipv4_addr_le = rte_cpu_to_le_32(ipv4_addr);
8500 : : memcpy(&cld_filter.element.ipaddr.v4.data,
8501 : : &ipv4_addr_le,
8502 : : sizeof(cld_filter.element.ipaddr.v4.data));
8503 : : } else {
8504 : : ip_type = I40E_AQC_ADD_CLOUD_FLAGS_IPV6;
8505 [ # # ]: 0 : for (i = 0; i < 4; i++) {
8506 : 0 : convert_ipv6[i] =
8507 [ # # ]: 0 : rte_cpu_to_le_32(rte_be_to_cpu_32(
8508 : : tunnel_filter->ip_addr.ipv6_addr[i]));
8509 : : }
8510 : : memcpy(&cld_filter.element.ipaddr.v6.data,
8511 : : &convert_ipv6,
8512 : : sizeof(cld_filter.element.ipaddr.v6.data));
8513 : : }
8514 : :
8515 : : /* check tunneled type */
8516 [ # # # # : 0 : switch (tunnel_filter->tunnel_type) {
# # # # #
# ]
8517 : : case I40E_TUNNEL_TYPE_VXLAN:
8518 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_VXLAN;
8519 : : break;
8520 : 0 : case I40E_TUNNEL_TYPE_NVGRE:
8521 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_NVGRE_OMAC;
8522 : 0 : break;
8523 : 0 : case I40E_TUNNEL_TYPE_IP_IN_GRE:
8524 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_IP;
8525 : 0 : break;
8526 : 0 : case I40E_TUNNEL_TYPE_MPLSoUDP:
8527 [ # # ]: 0 : if (!pf->mpls_replace_flag) {
8528 : 0 : i40e_replace_mpls_l1_filter(pf);
8529 : 0 : i40e_replace_mpls_cloud_filter(pf);
8530 : 0 : pf->mpls_replace_flag = 1;
8531 : : }
8532 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8533 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8534 : 0 : teid_le >> 4;
8535 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8536 : 0 : (teid_le & 0xF) << 12;
8537 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8538 : : 0x40;
8539 : : big_buffer = 1;
8540 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_MPLSOUDP;
8541 : 0 : break;
8542 : 0 : case I40E_TUNNEL_TYPE_MPLSoGRE:
8543 [ # # ]: 0 : if (!pf->mpls_replace_flag) {
8544 : 0 : i40e_replace_mpls_l1_filter(pf);
8545 : 0 : i40e_replace_mpls_cloud_filter(pf);
8546 : 0 : pf->mpls_replace_flag = 1;
8547 : : }
8548 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8549 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8550 : 0 : teid_le >> 4;
8551 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8552 : 0 : (teid_le & 0xF) << 12;
8553 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8554 : : 0x0;
8555 : : big_buffer = 1;
8556 : : tun_type = I40E_AQC_ADD_CLOUD_TNL_TYPE_MPLSOGRE;
8557 : 0 : break;
8558 : 0 : case I40E_TUNNEL_TYPE_GTPC:
8559 [ # # ]: 0 : if (!pf->gtp_replace_flag) {
8560 : 0 : i40e_replace_gtp_l1_filter(pf);
8561 : 0 : i40e_replace_gtp_cloud_filter(pf);
8562 : 0 : pf->gtp_replace_flag = 1;
8563 : : }
8564 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8565 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD0] =
8566 : 0 : (teid_le >> 16) & 0xFFFF;
8567 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD1] =
8568 : : teid_le & 0xFFFF;
8569 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X12_WORD2] =
8570 : : 0x0;
8571 : : big_buffer = 1;
8572 : 0 : break;
8573 : 0 : case I40E_TUNNEL_TYPE_GTPU:
8574 [ # # ]: 0 : if (!pf->gtp_replace_flag) {
8575 : 0 : i40e_replace_gtp_l1_filter(pf);
8576 : 0 : i40e_replace_gtp_cloud_filter(pf);
8577 : 0 : pf->gtp_replace_flag = 1;
8578 : : }
8579 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8580 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD0] =
8581 : 0 : (teid_le >> 16) & 0xFFFF;
8582 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD1] =
8583 : : teid_le & 0xFFFF;
8584 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X13_WORD2] =
8585 : : 0x0;
8586 : : big_buffer = 1;
8587 : 0 : break;
8588 : 0 : case I40E_TUNNEL_TYPE_QINQ:
8589 [ # # ]: 0 : if (!pf->qinq_replace_flag) {
8590 : 0 : ret = i40e_cloud_filter_qinq_create(pf);
8591 [ # # ]: 0 : if (ret < 0)
8592 : 0 : PMD_DRV_LOG(DEBUG,
8593 : : "QinQ tunnel filter already created.");
8594 : 0 : pf->qinq_replace_flag = 1;
8595 : : }
8596 : : /* Add in the General fields the values of
8597 : : * the Outer and Inner VLAN
8598 : : * Big Buffer should be set, see changes in
8599 : : * i40e_aq_add_cloud_filters
8600 : : */
8601 : 0 : cld_filter.general_fields[0] = tunnel_filter->inner_vlan;
8602 : 0 : cld_filter.general_fields[1] = tunnel_filter->outer_vlan;
8603 : : big_buffer = 1;
8604 : 0 : break;
8605 : 0 : case I40E_CLOUD_TYPE_UDP:
8606 : : case I40E_CLOUD_TYPE_TCP:
8607 : : case I40E_CLOUD_TYPE_SCTP:
8608 [ # # ]: 0 : if (tunnel_filter->l4_port_type == I40E_L4_PORT_TYPE_SRC) {
8609 [ # # ]: 0 : if (!pf->sport_replace_flag) {
8610 : 0 : i40e_replace_port_l1_filter(pf,
8611 : : tunnel_filter->l4_port_type);
8612 : 0 : i40e_replace_port_cloud_filter(pf,
8613 : : tunnel_filter->l4_port_type);
8614 : 0 : pf->sport_replace_flag = 1;
8615 : : }
8616 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8617 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD0] =
8618 : : I40E_DIRECTION_INGRESS_KEY;
8619 : :
8620 [ # # ]: 0 : if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_UDP)
8621 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8622 : : I40E_TR_L4_TYPE_UDP;
8623 [ # # ]: 0 : else if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_TCP)
8624 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8625 : : I40E_TR_L4_TYPE_TCP;
8626 : : else
8627 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD1] =
8628 : : I40E_TR_L4_TYPE_SCTP;
8629 : :
8630 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X11_WORD2] =
8631 : 0 : (teid_le >> 16) & 0xFFFF;
8632 : : big_buffer = 1;
8633 : : } else {
8634 [ # # ]: 0 : if (!pf->dport_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->dport_replace_flag = 1;
8640 : : }
8641 : 0 : teid_le = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8642 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD0] =
8643 : : I40E_DIRECTION_INGRESS_KEY;
8644 : :
8645 [ # # ]: 0 : if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_UDP)
8646 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD1] =
8647 : : I40E_TR_L4_TYPE_UDP;
8648 [ # # ]: 0 : else if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_TCP)
8649 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD1] =
8650 : : I40E_TR_L4_TYPE_TCP;
8651 : : else
8652 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD1] =
8653 : : I40E_TR_L4_TYPE_SCTP;
8654 : :
8655 : 0 : cld_filter.general_fields[I40E_AQC_ADD_CLOUD_FV_FLU_0X10_WORD2] =
8656 : 0 : (teid_le >> 16) & 0xFFFF;
8657 : : big_buffer = 1;
8658 : : }
8659 : :
8660 : : break;
8661 : 0 : default:
8662 : : /* Other tunnel types is not supported. */
8663 : 0 : PMD_DRV_LOG(ERR, "tunnel type is not supported.");
8664 : 0 : return -EINVAL;
8665 : : }
8666 : :
8667 [ # # ]: 0 : if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_MPLSoUDP)
8668 : 0 : cld_filter.element.flags =
8669 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8670 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_MPLSoGRE)
8671 : 0 : cld_filter.element.flags =
8672 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8673 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_GTPC)
8674 : 0 : cld_filter.element.flags =
8675 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8676 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_GTPU)
8677 : 0 : cld_filter.element.flags =
8678 : : I40E_AQC_ADD_CLOUD_FILTER_0X12;
8679 : : else if (tunnel_filter->tunnel_type == I40E_TUNNEL_TYPE_QINQ)
8680 : 0 : cld_filter.element.flags |=
8681 : : I40E_AQC_ADD_CLOUD_FILTER_0X10;
8682 : : else if (tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_UDP ||
8683 : : tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_TCP ||
8684 : : tunnel_filter->tunnel_type == I40E_CLOUD_TYPE_SCTP) {
8685 [ # # ]: 0 : if (tunnel_filter->l4_port_type == I40E_L4_PORT_TYPE_SRC)
8686 : 0 : cld_filter.element.flags |=
8687 : : I40E_AQC_ADD_CLOUD_FILTER_0X11;
8688 : : else
8689 : 0 : cld_filter.element.flags |=
8690 : : I40E_AQC_ADD_CLOUD_FILTER_0X10;
8691 : : } else {
8692 : 0 : val = i40e_dev_get_filter_type(tunnel_filter->filter_type,
8693 : : &cld_filter.element.flags);
8694 [ # # ]: 0 : if (val < 0) {
8695 : : return -EINVAL;
8696 : : }
8697 : : }
8698 : :
8699 : 0 : cld_filter.element.flags |=
8700 : 0 : rte_cpu_to_le_16(I40E_AQC_ADD_CLOUD_FLAGS_TO_QUEUE | ip_type |
8701 : : (tun_type << I40E_AQC_ADD_CLOUD_TNL_TYPE_SHIFT));
8702 : 0 : cld_filter.element.tenant_id = rte_cpu_to_le_32(tunnel_filter->tenant_id);
8703 : 0 : cld_filter.element.queue_number =
8704 : 0 : rte_cpu_to_le_16(tunnel_filter->queue_id);
8705 : :
8706 [ # # ]: 0 : if (!tunnel_filter->is_to_vf)
8707 : 0 : vsi = pf->main_vsi;
8708 : : else {
8709 [ # # ]: 0 : if (tunnel_filter->vf_id >= pf->vf_num) {
8710 : 0 : PMD_DRV_LOG(ERR, "Invalid argument.");
8711 : 0 : return -EINVAL;
8712 : : }
8713 : 0 : vf = &pf->vfs[tunnel_filter->vf_id];
8714 : 0 : vsi = vf->vsi;
8715 : : }
8716 : :
8717 : : /* Check if there is the filter in SW list */
8718 : : memset(&check_filter, 0, sizeof(check_filter));
8719 : 0 : i40e_tunnel_filter_convert(&cld_filter, &check_filter);
8720 : 0 : check_filter.is_to_vf = tunnel_filter->is_to_vf;
8721 : 0 : check_filter.vf_id = tunnel_filter->vf_id;
8722 : 0 : node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
8723 [ # # ]: 0 : if (add && node) {
8724 : 0 : PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
8725 : 0 : return -EINVAL;
8726 : : }
8727 : :
8728 [ # # ]: 0 : if (!add && !node) {
8729 : 0 : PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
8730 : 0 : return -EINVAL;
8731 : : }
8732 : :
8733 [ # # ]: 0 : if (add) {
8734 : : struct i40e_tunnel_filter *tunnel;
8735 : :
8736 [ # # ]: 0 : if (big_buffer)
8737 : 0 : ret = i40e_aq_add_cloud_filters_bb(hw,
8738 : 0 : vsi->seid, &cld_filter, 1);
8739 : : else
8740 : 0 : ret = i40e_aq_add_cloud_filters(hw,
8741 : 0 : vsi->seid, &cld_filter.element, 1);
8742 [ # # ]: 0 : if (ret < 0) {
8743 : 0 : PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
8744 : 0 : return -ENOTSUP;
8745 : : }
8746 : 0 : tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
8747 [ # # ]: 0 : if (tunnel == NULL) {
8748 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory.");
8749 : 0 : return -ENOMEM;
8750 : : }
8751 : :
8752 : : memcpy(tunnel, &check_filter, sizeof(check_filter));
8753 : 0 : ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
8754 [ # # ]: 0 : if (ret < 0)
8755 : 0 : rte_free(tunnel);
8756 : : } else {
8757 [ # # ]: 0 : if (big_buffer)
8758 : 0 : ret = i40e_aq_rem_cloud_filters_bb(
8759 : 0 : hw, vsi->seid, &cld_filter, 1);
8760 : : else
8761 : 0 : ret = i40e_aq_rem_cloud_filters(hw, vsi->seid,
8762 : : &cld_filter.element, 1);
8763 [ # # ]: 0 : if (ret < 0) {
8764 : 0 : PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
8765 : 0 : return -ENOTSUP;
8766 : : }
8767 : 0 : ret = i40e_sw_tunnel_filter_del(pf, &node->input);
8768 : : }
8769 : :
8770 : : return ret;
8771 : : }
8772 : :
8773 : : static int
8774 : : i40e_get_vxlan_port_idx(struct i40e_pf *pf, uint16_t port)
8775 : : {
8776 : : uint8_t i;
8777 : :
8778 [ # # # # : 0 : for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
# # ]
8779 [ # # # # : 0 : if (pf->vxlan_ports[i] == port)
# # ]
8780 : : return i;
8781 : : }
8782 : :
8783 : : return -1;
8784 : : }
8785 : :
8786 : : static int
8787 : 0 : i40e_add_vxlan_port(struct i40e_pf *pf, uint16_t port, int udp_type)
8788 : : {
8789 : : int idx, ret;
8790 : 0 : uint8_t filter_idx = 0;
8791 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8792 : :
8793 : 0 : idx = i40e_get_vxlan_port_idx(pf, port);
8794 : :
8795 : : /* Check if port already exists */
8796 [ # # ]: 0 : if (idx >= 0) {
8797 : 0 : PMD_DRV_LOG(ERR, "Port %d already offloaded", port);
8798 : 0 : return -EINVAL;
8799 : : }
8800 : :
8801 : : /* Now check if there is space to add the new port */
8802 : : idx = i40e_get_vxlan_port_idx(pf, 0);
8803 [ # # ]: 0 : if (idx < 0) {
8804 : 0 : PMD_DRV_LOG(ERR,
8805 : : "Maximum number of UDP ports reached, not adding port %d",
8806 : : port);
8807 : 0 : return -ENOSPC;
8808 : : }
8809 : :
8810 : 0 : ret = i40e_aq_add_udp_tunnel(hw, port, udp_type,
8811 : : &filter_idx, NULL);
8812 [ # # ]: 0 : if (ret < 0) {
8813 : 0 : PMD_DRV_LOG(ERR, "Failed to add VXLAN UDP port %d", port);
8814 : 0 : return -1;
8815 : : }
8816 : :
8817 : 0 : PMD_DRV_LOG(INFO, "Added port %d with AQ command with index %d",
8818 : : port, filter_idx);
8819 : :
8820 : : /* New port: add it and mark its index in the bitmap */
8821 : 0 : pf->vxlan_ports[idx] = port;
8822 : 0 : pf->vxlan_bitmap |= (1 << idx);
8823 : :
8824 [ # # ]: 0 : if (!(pf->flags & I40E_FLAG_VXLAN))
8825 : 0 : pf->flags |= I40E_FLAG_VXLAN;
8826 : :
8827 : : return 0;
8828 : : }
8829 : :
8830 : : static int
8831 : 0 : i40e_del_vxlan_port(struct i40e_pf *pf, uint16_t port)
8832 : : {
8833 : : int idx;
8834 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8835 : :
8836 [ # # ]: 0 : if (!(pf->flags & I40E_FLAG_VXLAN)) {
8837 : 0 : PMD_DRV_LOG(ERR, "VXLAN UDP port was not configured.");
8838 : 0 : return -EINVAL;
8839 : : }
8840 : :
8841 : 0 : idx = i40e_get_vxlan_port_idx(pf, port);
8842 : :
8843 [ # # ]: 0 : if (idx < 0) {
8844 : 0 : PMD_DRV_LOG(ERR, "Port %d doesn't exist", port);
8845 : 0 : return -EINVAL;
8846 : : }
8847 : :
8848 [ # # ]: 0 : if (i40e_aq_del_udp_tunnel(hw, idx, NULL) < 0) {
8849 : 0 : PMD_DRV_LOG(ERR, "Failed to delete VXLAN UDP port %d", port);
8850 : 0 : return -1;
8851 : : }
8852 : :
8853 : 0 : PMD_DRV_LOG(INFO, "Deleted port %d with AQ command with index %d",
8854 : : port, idx);
8855 : :
8856 : 0 : pf->vxlan_ports[idx] = 0;
8857 : 0 : pf->vxlan_bitmap &= ~(1 << idx);
8858 : :
8859 [ # # ]: 0 : if (!pf->vxlan_bitmap)
8860 : 0 : pf->flags &= ~I40E_FLAG_VXLAN;
8861 : :
8862 : : return 0;
8863 : : }
8864 : :
8865 : : /* Add UDP tunneling port */
8866 : : static int
8867 : 0 : i40e_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
8868 : : struct rte_eth_udp_tunnel *udp_tunnel)
8869 : : {
8870 : : int ret = 0;
8871 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8872 : :
8873 [ # # ]: 0 : if (udp_tunnel == NULL)
8874 : : return -EINVAL;
8875 : :
8876 [ # # # # ]: 0 : switch (udp_tunnel->prot_type) {
8877 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN:
8878 : 0 : ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port,
8879 : : I40E_AQC_TUNNEL_TYPE_VXLAN);
8880 : 0 : break;
8881 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN_GPE:
8882 : 0 : ret = i40e_add_vxlan_port(pf, udp_tunnel->udp_port,
8883 : : I40E_AQC_TUNNEL_TYPE_VXLAN_GPE);
8884 : 0 : break;
8885 : 0 : case RTE_ETH_TUNNEL_TYPE_GENEVE:
8886 : : case RTE_ETH_TUNNEL_TYPE_TEREDO:
8887 : 0 : PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8888 : : ret = -1;
8889 : 0 : break;
8890 : :
8891 : 0 : default:
8892 : 0 : PMD_DRV_LOG(ERR, "Invalid tunnel type");
8893 : : ret = -1;
8894 : 0 : break;
8895 : : }
8896 : :
8897 : : return ret;
8898 : : }
8899 : :
8900 : : /* Remove UDP tunneling port */
8901 : : static int
8902 : 0 : i40e_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
8903 : : struct rte_eth_udp_tunnel *udp_tunnel)
8904 : : {
8905 : : int ret = 0;
8906 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
8907 : :
8908 [ # # ]: 0 : if (udp_tunnel == NULL)
8909 : : return -EINVAL;
8910 : :
8911 [ # # # ]: 0 : switch (udp_tunnel->prot_type) {
8912 : 0 : case RTE_ETH_TUNNEL_TYPE_VXLAN:
8913 : : case RTE_ETH_TUNNEL_TYPE_VXLAN_GPE:
8914 : 0 : ret = i40e_del_vxlan_port(pf, udp_tunnel->udp_port);
8915 : 0 : break;
8916 : 0 : case RTE_ETH_TUNNEL_TYPE_GENEVE:
8917 : : case RTE_ETH_TUNNEL_TYPE_TEREDO:
8918 : 0 : PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
8919 : : ret = -1;
8920 : 0 : break;
8921 : 0 : default:
8922 : 0 : PMD_DRV_LOG(ERR, "Invalid tunnel type");
8923 : : ret = -1;
8924 : 0 : break;
8925 : : }
8926 : :
8927 : : return ret;
8928 : : }
8929 : :
8930 : : /* Calculate the maximum number of contiguous PF queues that are configured */
8931 : : uint16_t
8932 : 0 : i40e_pf_calc_configured_queues_num(struct i40e_pf *pf)
8933 : : {
8934 : 0 : struct rte_eth_dev_data *data = pf->dev_data;
8935 : : int i;
8936 : : uint16_t num;
8937 : : struct ci_rx_queue *rxq;
8938 : :
8939 : : num = 0;
8940 [ # # ]: 0 : for (i = 0; i < pf->lan_nb_qps; i++) {
8941 : 0 : rxq = data->rx_queues[i];
8942 [ # # # # ]: 0 : if (rxq && rxq->q_set)
8943 : 0 : num++;
8944 : : else
8945 : : break;
8946 : : }
8947 : :
8948 : 0 : return num;
8949 : : }
8950 : :
8951 : : /* Reset the global configure of hash function and input sets */
8952 : : static void
8953 : 0 : i40e_pf_global_rss_reset(struct i40e_pf *pf)
8954 : : {
8955 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
8956 : : uint32_t reg, reg_val;
8957 : : int i;
8958 : :
8959 : : /* Reset global RSS function sets */
8960 : 0 : reg_val = i40e_read_rx_ctl(hw, I40E_GLQF_CTL);
8961 [ # # ]: 0 : if (!(reg_val & I40E_GLQF_CTL_HTOEP_MASK)) {
8962 : 0 : reg_val |= I40E_GLQF_CTL_HTOEP_MASK;
8963 : 0 : i40e_write_global_rx_ctl(hw, I40E_GLQF_CTL, reg_val);
8964 : : }
8965 : :
8966 [ # # ]: 0 : for (i = 0; i <= I40E_FILTER_PCTYPE_L2_PAYLOAD; i++) {
8967 : : uint64_t inset;
8968 : : int j, pctype;
8969 : :
8970 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
8971 : 0 : pctype = i40e_read_rx_ctl(hw, I40E_GLQF_FD_PCTYPES(i));
8972 : : else
8973 : : pctype = i;
8974 : :
8975 : : /* Reset pctype insets */
8976 : 0 : inset = i40e_get_default_input_set(i);
8977 [ # # ]: 0 : if (inset) {
8978 : 0 : pf->hash_input_set[pctype] = inset;
8979 : 0 : inset = i40e_translate_input_set_reg(hw->mac.type,
8980 : : inset);
8981 : :
8982 : 0 : reg = I40E_GLQF_HASH_INSET(0, pctype);
8983 : 0 : i40e_check_write_global_reg(hw, reg, (uint32_t)inset);
8984 : 0 : reg = I40E_GLQF_HASH_INSET(1, pctype);
8985 : 0 : i40e_check_write_global_reg(hw, reg,
8986 : 0 : (uint32_t)(inset >> 32));
8987 : :
8988 : : /* Clear unused mask registers of the pctype */
8989 [ # # ]: 0 : for (j = 0; j < I40E_INSET_MASK_NUM_REG; j++) {
8990 : 0 : reg = I40E_GLQF_HASH_MSK(j, pctype);
8991 : 0 : i40e_check_write_global_reg(hw, reg, 0);
8992 : : }
8993 : : }
8994 : :
8995 : : /* Reset pctype symmetric sets */
8996 : 0 : reg = I40E_GLQF_HSYM(pctype);
8997 : 0 : reg_val = i40e_read_rx_ctl(hw, reg);
8998 [ # # ]: 0 : if (reg_val & I40E_GLQF_HSYM_SYMH_ENA_MASK) {
8999 : 0 : reg_val &= ~I40E_GLQF_HSYM_SYMH_ENA_MASK;
9000 : 0 : i40e_write_global_rx_ctl(hw, reg, reg_val);
9001 : : }
9002 : : }
9003 : 0 : I40E_WRITE_FLUSH(hw);
9004 : 0 : }
9005 : :
9006 : : int
9007 : 0 : i40e_pf_reset_rss_reta(struct i40e_pf *pf)
9008 : : {
9009 : 0 : struct i40e_hw *hw = &pf->adapter->hw;
9010 : : uint8_t lut[RTE_ETH_RSS_RETA_SIZE_512];
9011 : : uint32_t i;
9012 : : uint16_t num;
9013 : :
9014 : : /* If both VMDQ and RSS enabled, not all of PF queues are
9015 : : * configured. It's necessary to calculate the actual PF
9016 : : * queues that are configured.
9017 : : */
9018 [ # # ]: 0 : if (pf->dev_data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG)
9019 : 0 : num = i40e_pf_calc_configured_queues_num(pf);
9020 : : else
9021 : 0 : num = pf->dev_data->nb_rx_queues;
9022 : :
9023 : 0 : num = RTE_MIN(num, I40E_MAX_Q_PER_TC);
9024 [ # # ]: 0 : if (num <= 0)
9025 : : return 0;
9026 : :
9027 [ # # ]: 0 : for (i = 0; i < hw->func_caps.rss_table_size; i++)
9028 : 0 : lut[i] = (uint8_t)(i % num);
9029 : :
9030 : 0 : return i40e_set_rss_lut(pf->main_vsi, lut, (uint16_t)i);
9031 : : }
9032 : :
9033 : : int
9034 : 0 : i40e_pf_reset_rss_key(struct i40e_pf *pf)
9035 : : {
9036 : : uint8_t key_buf[I40E_RSS_KEY_LEN];
9037 : : const uint8_t *rss_key;
9038 : :
9039 : : /* Reset key */
9040 : 0 : rss_key = pf->dev_data->dev_conf.rx_adv_conf.rss_conf.rss_key;
9041 [ # # # # ]: 0 : if (!rss_key || pf->dev_data->dev_conf.rx_adv_conf.rss_conf.rss_key_len < sizeof(key_buf))
9042 : : rss_key = i40e_rss_key_default;
9043 : :
9044 : : /*
9045 : : * adminq does not guarantee const-ness of RSS key once a command is sent down, so make a
9046 : : * local copy.
9047 : : */
9048 : : memcpy(&key_buf, rss_key, sizeof(key_buf));
9049 : :
9050 : 0 : return i40e_set_rss_key(pf->main_vsi, key_buf, sizeof(key_buf));
9051 : : }
9052 : :
9053 : : static int
9054 : 0 : i40e_pf_rss_reset(struct i40e_pf *pf)
9055 : : {
9056 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9057 : :
9058 : : int ret;
9059 : :
9060 : 0 : pf->hash_filter_enabled = 0;
9061 : 0 : i40e_pf_disable_rss(pf);
9062 : 0 : i40e_set_symmetric_hash_enable_per_port(hw, 0);
9063 : :
9064 [ # # ]: 0 : if (!pf->support_multi_driver)
9065 : 0 : i40e_pf_global_rss_reset(pf);
9066 : :
9067 : : /* Reset RETA table */
9068 [ # # ]: 0 : if (pf->adapter->rss_reta_updated == 0) {
9069 : 0 : ret = i40e_pf_reset_rss_reta(pf);
9070 [ # # ]: 0 : if (ret)
9071 : : return ret;
9072 : : }
9073 : :
9074 : 0 : return i40e_pf_reset_rss_key(pf);
9075 : : }
9076 : :
9077 : : /* Configure RSS */
9078 : : int
9079 : 0 : i40e_pf_config_rss(struct i40e_pf *pf)
9080 : : {
9081 : : struct i40e_hw *hw;
9082 : : enum rte_eth_rx_mq_mode mq_mode;
9083 : : uint64_t rss_hf, hena;
9084 : : int ret;
9085 : :
9086 : 0 : ret = i40e_pf_rss_reset(pf);
9087 [ # # ]: 0 : if (ret) {
9088 : 0 : PMD_DRV_LOG(ERR, "Reset RSS failed, RSS has been disabled");
9089 : 0 : return ret;
9090 : : }
9091 : :
9092 : 0 : rss_hf = pf->dev_data->dev_conf.rx_adv_conf.rss_conf.rss_hf;
9093 : 0 : mq_mode = pf->dev_data->dev_conf.rxmode.mq_mode;
9094 [ # # ]: 0 : if (!(rss_hf & pf->adapter->flow_types_mask) ||
9095 [ # # ]: 0 : !(mq_mode & RTE_ETH_MQ_RX_RSS_FLAG))
9096 : : return 0;
9097 : :
9098 : 0 : hw = I40E_PF_TO_HW(pf);
9099 : 0 : hena = i40e_config_hena(pf->adapter, rss_hf);
9100 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (uint32_t)hena);
9101 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (uint32_t)(hena >> 32));
9102 : 0 : I40E_WRITE_FLUSH(hw);
9103 : :
9104 : 0 : return 0;
9105 : : }
9106 : :
9107 : : #define I40E_GL_PRS_FVBM_MSK_ENA 0x80000000
9108 : : #define I40E_GL_PRS_FVBM(_i) (0x00269760 + ((_i) * 4))
9109 : : int
9110 : 0 : i40e_dev_set_gre_key_len(struct i40e_hw *hw, uint8_t len)
9111 : : {
9112 : 0 : struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
9113 : : uint32_t val, reg;
9114 : : int ret = -EINVAL;
9115 : :
9116 [ # # ]: 0 : if (pf->support_multi_driver) {
9117 : 0 : PMD_DRV_LOG(ERR, "GRE key length configuration is unsupported");
9118 : 0 : return -ENOTSUP;
9119 : : }
9120 : :
9121 : 0 : val = I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2));
9122 : 0 : PMD_DRV_LOG(DEBUG, "Read original GL_PRS_FVBM with 0x%08x", val);
9123 : :
9124 [ # # ]: 0 : if (len == 3) {
9125 : 0 : reg = val | I40E_GL_PRS_FVBM_MSK_ENA;
9126 [ # # ]: 0 : } else if (len == 4) {
9127 : 0 : reg = val & ~I40E_GL_PRS_FVBM_MSK_ENA;
9128 : : } else {
9129 : 0 : PMD_DRV_LOG(ERR, "Unsupported GRE key length of %u", len);
9130 : 0 : return ret;
9131 : : }
9132 : :
9133 [ # # ]: 0 : if (reg != val) {
9134 : 0 : ret = i40e_aq_debug_write_global_register(hw,
9135 : : I40E_GL_PRS_FVBM(2),
9136 : : reg, NULL);
9137 [ # # ]: 0 : if (ret != 0)
9138 : : return ret;
9139 : 0 : PMD_DRV_LOG(DEBUG, "Global register 0x%08x is changed "
9140 : : "with value 0x%08x",
9141 : : I40E_GL_PRS_FVBM(2), reg);
9142 : : } else {
9143 : : ret = 0;
9144 : : }
9145 : 0 : PMD_DRV_LOG(DEBUG, "Read modified GL_PRS_FVBM with 0x%08x",
9146 : : I40E_READ_REG(hw, I40E_GL_PRS_FVBM(2)));
9147 : :
9148 : 0 : return ret;
9149 : : }
9150 : :
9151 : : /* Set the symmetric hash enable configurations per port */
9152 : : void
9153 : 0 : i40e_set_symmetric_hash_enable_per_port(struct i40e_hw *hw, uint8_t enable)
9154 : : {
9155 : 0 : uint32_t reg = i40e_read_rx_ctl(hw, I40E_PRTQF_CTL_0);
9156 : :
9157 [ # # ]: 0 : if (enable > 0) {
9158 [ # # ]: 0 : if (reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK)
9159 : : return;
9160 : :
9161 : 0 : reg |= I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
9162 : : } else {
9163 [ # # ]: 0 : if (!(reg & I40E_PRTQF_CTL_0_HSYM_ENA_MASK))
9164 : : return;
9165 : :
9166 : 0 : reg &= ~I40E_PRTQF_CTL_0_HSYM_ENA_MASK;
9167 : : }
9168 : 0 : i40e_write_rx_ctl(hw, I40E_PRTQF_CTL_0, reg);
9169 : 0 : I40E_WRITE_FLUSH(hw);
9170 : : }
9171 : :
9172 : : /**
9173 : : * Valid input sets for hash and flow director filters per PCTYPE
9174 : : */
9175 : : static uint64_t
9176 : : i40e_get_valid_input_set(enum i40e_filter_pctype pctype,
9177 : : enum rte_filter_type filter)
9178 : : {
9179 : : uint64_t valid;
9180 : :
9181 : : static const uint64_t valid_hash_inset_table[] = {
9182 : : [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9183 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9184 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9185 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_SRC |
9186 : : I40E_INSET_IPV4_DST | I40E_INSET_IPV4_TOS |
9187 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9188 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9189 : : I40E_INSET_FLEX_PAYLOAD,
9190 : : [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9191 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9192 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9193 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9194 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9195 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9196 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9197 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9198 : : I40E_INSET_FLEX_PAYLOAD,
9199 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9200 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9201 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9202 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9203 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9204 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9205 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9206 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9207 : : I40E_INSET_FLEX_PAYLOAD,
9208 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9209 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9210 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9211 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9212 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9213 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9214 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9215 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9216 : : I40E_INSET_FLEX_PAYLOAD,
9217 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9218 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9219 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9220 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9221 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9222 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9223 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9224 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9225 : : I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
9226 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9227 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9228 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9229 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9230 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9231 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9232 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9233 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9234 : : I40E_INSET_TCP_FLAGS | I40E_INSET_FLEX_PAYLOAD,
9235 : : [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9236 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9237 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9238 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9239 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9240 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9241 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9242 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9243 : : I40E_INSET_SCTP_VT | I40E_INSET_FLEX_PAYLOAD,
9244 : : [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9245 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9246 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9247 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV4_TOS |
9248 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL |
9249 : : I40E_INSET_TUNNEL_DMAC | I40E_INSET_TUNNEL_ID |
9250 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9251 : : I40E_INSET_FLEX_PAYLOAD,
9252 : : [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9253 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9254 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9255 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9256 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9257 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_TUNNEL_DMAC |
9258 : : I40E_INSET_TUNNEL_ID | I40E_INSET_IPV6_SRC |
9259 : : I40E_INSET_IPV6_DST | I40E_INSET_FLEX_PAYLOAD,
9260 : : [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9261 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9262 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9263 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9264 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9265 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9266 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9267 : : I40E_INSET_DST_PORT | I40E_INSET_FLEX_PAYLOAD,
9268 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9269 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9270 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9271 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9272 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9273 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9274 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9275 : : I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9276 : : I40E_INSET_FLEX_PAYLOAD,
9277 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9278 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9279 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9280 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9281 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9282 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9283 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9284 : : I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9285 : : I40E_INSET_FLEX_PAYLOAD,
9286 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9287 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9288 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9289 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9290 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9291 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9292 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9293 : : I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9294 : : I40E_INSET_FLEX_PAYLOAD,
9295 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9296 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9297 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9298 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9299 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9300 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9301 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9302 : : I40E_INSET_DST_PORT | I40E_INSET_TCP_FLAGS |
9303 : : I40E_INSET_FLEX_PAYLOAD,
9304 : : [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9305 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9306 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9307 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9308 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9309 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9310 : : I40E_INSET_IPV6_DST | I40E_INSET_SRC_PORT |
9311 : : I40E_INSET_DST_PORT | I40E_INSET_SCTP_VT |
9312 : : I40E_INSET_FLEX_PAYLOAD,
9313 : : [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9314 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9315 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9316 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_IPV6_TC |
9317 : : I40E_INSET_IPV6_FLOW | I40E_INSET_IPV6_NEXT_HDR |
9318 : : I40E_INSET_IPV6_HOP_LIMIT | I40E_INSET_IPV6_SRC |
9319 : : I40E_INSET_IPV6_DST | I40E_INSET_TUNNEL_ID |
9320 : : I40E_INSET_FLEX_PAYLOAD,
9321 : : [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9322 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9323 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9324 : : I40E_INSET_VLAN_TUNNEL | I40E_INSET_LAST_ETHER_TYPE |
9325 : : I40E_INSET_FLEX_PAYLOAD,
9326 : : };
9327 : :
9328 : : /**
9329 : : * Flow director supports only fields defined in
9330 : : * union rte_eth_fdir_flow.
9331 : : */
9332 : : static const uint64_t valid_fdir_inset_table[] = {
9333 : : [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9334 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9335 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9336 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9337 : : I40E_INSET_IPV4_TTL,
9338 : : [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9339 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9340 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9341 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9342 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9343 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9344 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9345 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9346 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9347 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9348 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9349 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9350 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9351 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9352 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9353 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9354 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9355 : : I40E_INSET_DMAC | I40E_INSET_SMAC |
9356 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9357 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9358 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9359 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9360 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9361 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9362 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9363 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9364 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9365 : : [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9366 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9367 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9368 : : I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_TTL |
9369 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9370 : : I40E_INSET_SCTP_VT,
9371 : : [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
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_PROTO |
9376 : : I40E_INSET_IPV4_TTL,
9377 : : [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9378 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9379 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9380 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
9381 : : I40E_INSET_IPV6_HOP_LIMIT,
9382 : : [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9383 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9384 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9385 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9386 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9387 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9388 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9389 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9390 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9391 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9392 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9393 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9394 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9395 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9396 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9397 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9398 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9399 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9400 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9401 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9402 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9403 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9404 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9405 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9406 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9407 : : [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9408 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9409 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9410 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_HOP_LIMIT |
9411 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9412 : : I40E_INSET_SCTP_VT,
9413 : : [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9414 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9415 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9416 : : I40E_INSET_IPV6_TC | I40E_INSET_IPV6_NEXT_HDR |
9417 : : I40E_INSET_IPV6_HOP_LIMIT,
9418 : : [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9419 : : I40E_INSET_VLAN_OUTER | I40E_INSET_VLAN_INNER |
9420 : : I40E_INSET_LAST_ETHER_TYPE,
9421 : : };
9422 : :
9423 : 0 : if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
9424 : : return 0;
9425 [ # # ]: 0 : if (filter == RTE_ETH_FILTER_HASH)
9426 : 0 : valid = valid_hash_inset_table[pctype];
9427 : : else
9428 : 0 : valid = valid_fdir_inset_table[pctype];
9429 : :
9430 : : return valid;
9431 : : }
9432 : :
9433 : : /**
9434 : : * Validate if the input set is allowed for a specific PCTYPE
9435 : : */
9436 : : int
9437 [ # # ]: 0 : i40e_validate_input_set(enum i40e_filter_pctype pctype,
9438 : : enum rte_filter_type filter, uint64_t inset)
9439 : : {
9440 : : uint64_t valid;
9441 : :
9442 : : valid = i40e_get_valid_input_set(pctype, filter);
9443 [ # # ]: 0 : if (inset & (~valid))
9444 : 0 : return -EINVAL;
9445 : :
9446 : : return 0;
9447 : : }
9448 : :
9449 : : /* default input set fields combination per pctype */
9450 : : uint64_t
9451 : 0 : i40e_get_default_input_set(uint16_t pctype)
9452 : : {
9453 : : static const uint64_t default_inset_table[] = {
9454 : : [I40E_FILTER_PCTYPE_FRAG_IPV4] =
9455 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
9456 : : [I40E_FILTER_PCTYPE_NONF_IPV4_UDP] =
9457 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9458 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9459 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP] =
9460 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9461 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9462 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP] =
9463 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9464 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9465 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP] =
9466 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9467 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9468 : : [I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK] =
9469 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9470 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9471 : : [I40E_FILTER_PCTYPE_NONF_IPV4_SCTP] =
9472 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST |
9473 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9474 : : I40E_INSET_SCTP_VT,
9475 : : [I40E_FILTER_PCTYPE_NONF_IPV4_OTHER] =
9476 : : I40E_INSET_IPV4_SRC | I40E_INSET_IPV4_DST,
9477 : : [I40E_FILTER_PCTYPE_FRAG_IPV6] =
9478 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
9479 : : [I40E_FILTER_PCTYPE_NONF_IPV6_UDP] =
9480 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9481 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9482 : : [I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP] =
9483 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9484 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9485 : : [I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP] =
9486 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9487 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9488 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP] =
9489 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9490 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9491 : : [I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK] =
9492 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9493 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT,
9494 : : [I40E_FILTER_PCTYPE_NONF_IPV6_SCTP] =
9495 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST |
9496 : : I40E_INSET_SRC_PORT | I40E_INSET_DST_PORT |
9497 : : I40E_INSET_SCTP_VT,
9498 : : [I40E_FILTER_PCTYPE_NONF_IPV6_OTHER] =
9499 : : I40E_INSET_IPV6_SRC | I40E_INSET_IPV6_DST,
9500 : : [I40E_FILTER_PCTYPE_L2_PAYLOAD] =
9501 : : I40E_INSET_LAST_ETHER_TYPE,
9502 : : };
9503 : :
9504 [ # # ]: 0 : if (pctype > I40E_FILTER_PCTYPE_L2_PAYLOAD)
9505 : : return 0;
9506 : :
9507 : 0 : return default_inset_table[pctype];
9508 : : }
9509 : :
9510 : : /**
9511 : : * Translate the input set from bit masks to register aware bit masks
9512 : : * and vice versa
9513 : : */
9514 : : uint64_t
9515 : 0 : i40e_translate_input_set_reg(enum i40e_mac_type type, uint64_t input)
9516 : : {
9517 : : uint64_t val = 0;
9518 : : uint16_t i;
9519 : :
9520 : : struct inset_map {
9521 : : uint64_t inset;
9522 : : uint64_t inset_reg;
9523 : : };
9524 : :
9525 : : static const struct inset_map inset_map_common[] = {
9526 : : {I40E_INSET_DMAC, I40E_REG_INSET_L2_DMAC},
9527 : : {I40E_INSET_SMAC, I40E_REG_INSET_L2_SMAC},
9528 : : {I40E_INSET_VLAN_OUTER, I40E_REG_INSET_L2_OUTER_VLAN},
9529 : : {I40E_INSET_VLAN_INNER, I40E_REG_INSET_L2_INNER_VLAN},
9530 : : {I40E_INSET_LAST_ETHER_TYPE, I40E_REG_INSET_LAST_ETHER_TYPE},
9531 : : {I40E_INSET_IPV4_TOS, I40E_REG_INSET_L3_IP4_TOS},
9532 : : {I40E_INSET_IPV6_SRC, I40E_REG_INSET_L3_SRC_IP6},
9533 : : {I40E_INSET_IPV6_DST, I40E_REG_INSET_L3_DST_IP6},
9534 : : {I40E_INSET_IPV6_TC, I40E_REG_INSET_L3_IP6_TC},
9535 : : {I40E_INSET_IPV6_NEXT_HDR, I40E_REG_INSET_L3_IP6_NEXT_HDR},
9536 : : {I40E_INSET_IPV6_HOP_LIMIT, I40E_REG_INSET_L3_IP6_HOP_LIMIT},
9537 : : {I40E_INSET_SRC_PORT, I40E_REG_INSET_L4_SRC_PORT},
9538 : : {I40E_INSET_DST_PORT, I40E_REG_INSET_L4_DST_PORT},
9539 : : {I40E_INSET_SCTP_VT, I40E_REG_INSET_L4_SCTP_VERIFICATION_TAG},
9540 : : {I40E_INSET_TUNNEL_ID, I40E_REG_INSET_TUNNEL_ID},
9541 : : {I40E_INSET_TUNNEL_DMAC,
9542 : : I40E_REG_INSET_TUNNEL_L2_INNER_DST_MAC},
9543 : : {I40E_INSET_TUNNEL_IPV4_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP4},
9544 : : {I40E_INSET_TUNNEL_IPV6_DST, I40E_REG_INSET_TUNNEL_L3_DST_IP6},
9545 : : {I40E_INSET_TUNNEL_SRC_PORT,
9546 : : I40E_REG_INSET_TUNNEL_L4_UDP_SRC_PORT},
9547 : : {I40E_INSET_TUNNEL_DST_PORT,
9548 : : I40E_REG_INSET_TUNNEL_L4_UDP_DST_PORT},
9549 : : {I40E_INSET_VLAN_TUNNEL, I40E_REG_INSET_TUNNEL_VLAN},
9550 : : {I40E_INSET_FLEX_PAYLOAD_W1, I40E_REG_INSET_FLEX_PAYLOAD_WORD1},
9551 : : {I40E_INSET_FLEX_PAYLOAD_W2, I40E_REG_INSET_FLEX_PAYLOAD_WORD2},
9552 : : {I40E_INSET_FLEX_PAYLOAD_W3, I40E_REG_INSET_FLEX_PAYLOAD_WORD3},
9553 : : {I40E_INSET_FLEX_PAYLOAD_W4, I40E_REG_INSET_FLEX_PAYLOAD_WORD4},
9554 : : {I40E_INSET_FLEX_PAYLOAD_W5, I40E_REG_INSET_FLEX_PAYLOAD_WORD5},
9555 : : {I40E_INSET_FLEX_PAYLOAD_W6, I40E_REG_INSET_FLEX_PAYLOAD_WORD6},
9556 : : {I40E_INSET_FLEX_PAYLOAD_W7, I40E_REG_INSET_FLEX_PAYLOAD_WORD7},
9557 : : {I40E_INSET_FLEX_PAYLOAD_W8, I40E_REG_INSET_FLEX_PAYLOAD_WORD8},
9558 : : };
9559 : :
9560 : : /* some different registers map in x722*/
9561 : : static const struct inset_map inset_map_diff_x722[] = {
9562 : : {I40E_INSET_IPV4_SRC, I40E_X722_REG_INSET_L3_SRC_IP4},
9563 : : {I40E_INSET_IPV4_DST, I40E_X722_REG_INSET_L3_DST_IP4},
9564 : : {I40E_INSET_IPV4_PROTO, I40E_X722_REG_INSET_L3_IP4_PROTO},
9565 : : {I40E_INSET_IPV4_TTL, I40E_X722_REG_INSET_L3_IP4_TTL},
9566 : : };
9567 : :
9568 : : static const struct inset_map inset_map_diff_not_x722[] = {
9569 : : {I40E_INSET_IPV4_SRC, I40E_REG_INSET_L3_SRC_IP4},
9570 : : {I40E_INSET_IPV4_DST, I40E_REG_INSET_L3_DST_IP4},
9571 : : {I40E_INSET_IPV4_PROTO, I40E_REG_INSET_L3_IP4_PROTO},
9572 : : {I40E_INSET_IPV4_TTL, I40E_REG_INSET_L3_IP4_TTL},
9573 : : };
9574 : :
9575 [ # # ]: 0 : if (input == 0)
9576 : : return val;
9577 : :
9578 : : /* Translate input set to register aware inset */
9579 [ # # ]: 0 : if (type == I40E_MAC_X722) {
9580 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_map_diff_x722); i++) {
9581 [ # # ]: 0 : if (input & inset_map_diff_x722[i].inset)
9582 : 0 : val |= inset_map_diff_x722[i].inset_reg;
9583 : : }
9584 : : } else {
9585 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_map_diff_not_x722); i++) {
9586 [ # # ]: 0 : if (input & inset_map_diff_not_x722[i].inset)
9587 : 0 : val |= inset_map_diff_not_x722[i].inset_reg;
9588 : : }
9589 : : }
9590 : :
9591 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_map_common); i++) {
9592 [ # # ]: 0 : if (input & inset_map_common[i].inset)
9593 : 0 : val |= inset_map_common[i].inset_reg;
9594 : : }
9595 : :
9596 : : return val;
9597 : : }
9598 : :
9599 : : static int
9600 : 0 : i40e_get_inset_field_offset(struct i40e_hw *hw, uint32_t pit_reg_start,
9601 : : uint32_t pit_reg_count, uint32_t hdr_off)
9602 : : {
9603 : 0 : const uint32_t pit_reg_end = pit_reg_start + pit_reg_count;
9604 : 0 : uint32_t field_off = I40E_FDIR_FIELD_OFFSET(hdr_off);
9605 : : uint32_t i, reg_val, src_off, count;
9606 : :
9607 [ # # ]: 0 : for (i = pit_reg_start; i < pit_reg_end; i++) {
9608 : 0 : reg_val = i40e_read_rx_ctl(hw, I40E_GLQF_PIT(i));
9609 : :
9610 : 0 : src_off = I40E_GLQF_PIT_SOURCE_OFF_GET(reg_val);
9611 : 0 : count = I40E_GLQF_PIT_FSIZE_GET(reg_val);
9612 : :
9613 [ # # # # ]: 0 : if (src_off <= field_off && (src_off + count) > field_off)
9614 : : break;
9615 : : }
9616 : :
9617 [ # # ]: 0 : if (i >= pit_reg_end) {
9618 : 0 : PMD_DRV_LOG(ERR,
9619 : : "Hardware GLQF_PIT configuration does not support this field mask");
9620 : 0 : return -1;
9621 : : }
9622 : :
9623 : 0 : return I40E_GLQF_PIT_DEST_OFF_GET(reg_val) + field_off - src_off;
9624 : : }
9625 : :
9626 : : int
9627 : 0 : i40e_generate_inset_mask_reg(struct i40e_hw *hw, uint64_t inset,
9628 : : uint32_t *mask, uint8_t nb_elem)
9629 : : {
9630 : : static const uint64_t mask_inset[] = {
9631 : : I40E_INSET_IPV4_PROTO | I40E_INSET_IPV4_TTL,
9632 : : I40E_INSET_IPV6_NEXT_HDR | I40E_INSET_IPV6_HOP_LIMIT };
9633 : :
9634 : : static const struct {
9635 : : uint64_t inset;
9636 : : uint32_t mask;
9637 : : uint32_t offset;
9638 : : } inset_mask_offset_map[] = {
9639 : : { I40E_INSET_IPV4_TOS, I40E_INSET_IPV4_TOS_MASK,
9640 : : offsetof(struct rte_ipv4_hdr, type_of_service) },
9641 : :
9642 : : { I40E_INSET_IPV4_PROTO, I40E_INSET_IPV4_PROTO_MASK,
9643 : : offsetof(struct rte_ipv4_hdr, next_proto_id) },
9644 : :
9645 : : { I40E_INSET_IPV4_TTL, I40E_INSET_IPV4_TTL_MASK,
9646 : : offsetof(struct rte_ipv4_hdr, time_to_live) },
9647 : :
9648 : : { I40E_INSET_IPV6_TC, I40E_INSET_IPV6_TC_MASK,
9649 : : offsetof(struct rte_ipv6_hdr, vtc_flow) },
9650 : :
9651 : : { I40E_INSET_IPV6_NEXT_HDR, I40E_INSET_IPV6_NEXT_HDR_MASK,
9652 : : offsetof(struct rte_ipv6_hdr, proto) },
9653 : :
9654 : : { I40E_INSET_IPV6_HOP_LIMIT, I40E_INSET_IPV6_HOP_LIMIT_MASK,
9655 : : offsetof(struct rte_ipv6_hdr, hop_limits) },
9656 : : };
9657 : :
9658 : : uint32_t i;
9659 : : int idx = 0;
9660 : :
9661 [ # # ]: 0 : assert(mask);
9662 [ # # ]: 0 : if (!inset)
9663 : : return 0;
9664 : :
9665 [ # # ]: 0 : for (i = 0; i < RTE_DIM(mask_inset); i++) {
9666 : : /* Clear the inset bit, if no MASK is required,
9667 : : * for example proto + ttl
9668 : : */
9669 [ # # ]: 0 : if ((mask_inset[i] & inset) == mask_inset[i]) {
9670 : 0 : inset &= ~mask_inset[i];
9671 [ # # ]: 0 : if (!inset)
9672 : : return 0;
9673 : : }
9674 : : }
9675 : :
9676 [ # # ]: 0 : for (i = 0; i < RTE_DIM(inset_mask_offset_map); i++) {
9677 : : uint32_t pit_start, pit_count;
9678 : : int offset;
9679 : :
9680 [ # # ]: 0 : if (!(inset_mask_offset_map[i].inset & inset))
9681 : 0 : continue;
9682 : :
9683 [ # # ]: 0 : if (inset_mask_offset_map[i].inset &
9684 : : (I40E_INSET_IPV4_TOS | I40E_INSET_IPV4_PROTO |
9685 : : I40E_INSET_IPV4_TTL)) {
9686 : : pit_start = I40E_GLQF_PIT_IPV4_START;
9687 : : pit_count = I40E_GLQF_PIT_IPV4_COUNT;
9688 : : } else {
9689 : : pit_start = I40E_GLQF_PIT_IPV6_START;
9690 : : pit_count = I40E_GLQF_PIT_IPV6_COUNT;
9691 : : }
9692 : :
9693 : 0 : offset = i40e_get_inset_field_offset(hw, pit_start, pit_count,
9694 : 0 : inset_mask_offset_map[i].offset);
9695 : :
9696 [ # # ]: 0 : if (offset < 0)
9697 : : return -EINVAL;
9698 : :
9699 [ # # ]: 0 : if (idx >= nb_elem) {
9700 : 0 : PMD_DRV_LOG(ERR,
9701 : : "Configuration of inset mask out of range %u",
9702 : : nb_elem);
9703 : 0 : return -ERANGE;
9704 : : }
9705 : :
9706 : 0 : mask[idx] = I40E_GLQF_PIT_BUILD((uint32_t)offset,
9707 : : inset_mask_offset_map[i].mask);
9708 : 0 : idx++;
9709 : : }
9710 : :
9711 : : return idx;
9712 : : }
9713 : :
9714 : : void
9715 : 0 : i40e_check_write_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
9716 : : {
9717 : 0 : uint32_t reg = i40e_read_rx_ctl(hw, addr);
9718 : :
9719 : 0 : PMD_DRV_LOG(DEBUG, "[0x%08x] original: 0x%08x", addr, reg);
9720 [ # # ]: 0 : if (reg != val)
9721 : 0 : i40e_write_rx_ctl(hw, addr, val);
9722 : 0 : PMD_DRV_LOG(DEBUG, "[0x%08x] after: 0x%08x", addr,
9723 : : (uint32_t)i40e_read_rx_ctl(hw, addr));
9724 : 0 : }
9725 : :
9726 : : void
9727 : 0 : i40e_check_write_global_reg(struct i40e_hw *hw, uint32_t addr, uint32_t val)
9728 : : {
9729 : 0 : uint32_t reg = i40e_read_rx_ctl(hw, addr);
9730 : 0 : struct rte_eth_dev_data *dev_data =
9731 : 0 : ((struct i40e_adapter *)hw->back)->pf.dev_data;
9732 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[dev_data->port_id];
9733 : :
9734 [ # # ]: 0 : if (reg != val) {
9735 : 0 : i40e_write_rx_ctl(hw, addr, val);
9736 : 0 : PMD_DRV_LOG(INFO,
9737 : : "i40e device %s changed global register [0x%08x]."
9738 : : " original: 0x%08x, new: 0x%08x",
9739 : : dev->device->name, addr, reg,
9740 : : (uint32_t)i40e_read_rx_ctl(hw, addr));
9741 : : }
9742 : 0 : }
9743 : :
9744 : : static void
9745 : 0 : i40e_filter_input_set_init(struct i40e_pf *pf)
9746 : : {
9747 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9748 : : enum i40e_filter_pctype pctype;
9749 : : uint64_t input_set, inset_reg;
9750 : 0 : uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9751 : : int num, i;
9752 : : uint16_t flow_type;
9753 : :
9754 : 0 : for (pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
9755 [ # # ]: 0 : pctype <= I40E_FILTER_PCTYPE_L2_PAYLOAD; pctype++) {
9756 : 0 : flow_type = i40e_pctype_to_flowtype(pf->adapter, pctype);
9757 : :
9758 [ # # ]: 0 : if (flow_type == RTE_ETH_FLOW_UNKNOWN)
9759 : 0 : continue;
9760 : :
9761 : 0 : input_set = i40e_get_default_input_set(pctype);
9762 : :
9763 : 0 : num = i40e_generate_inset_mask_reg(hw, input_set, mask_reg,
9764 : : I40E_INSET_MASK_NUM_REG);
9765 [ # # ]: 0 : if (num < 0)
9766 : 0 : return;
9767 [ # # # # ]: 0 : if (pf->support_multi_driver && num > 0) {
9768 : 0 : PMD_DRV_LOG(ERR, "Input set setting is not supported.");
9769 : 0 : return;
9770 : : }
9771 : 0 : inset_reg = i40e_translate_input_set_reg(hw->mac.type,
9772 : : input_set);
9773 : :
9774 : 0 : i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 0),
9775 : : (uint32_t)(inset_reg & UINT32_MAX));
9776 : 0 : i40e_check_write_reg(hw, I40E_PRTQF_FD_INSET(pctype, 1),
9777 : 0 : (uint32_t)((inset_reg >>
9778 : : I40E_32_BIT_WIDTH) & UINT32_MAX));
9779 [ # # ]: 0 : if (!pf->support_multi_driver) {
9780 : 0 : i40e_check_write_global_reg(hw,
9781 : 0 : I40E_GLQF_HASH_INSET(0, pctype),
9782 : : (uint32_t)(inset_reg & UINT32_MAX));
9783 : 0 : i40e_check_write_global_reg(hw,
9784 : 0 : I40E_GLQF_HASH_INSET(1, pctype),
9785 : : (uint32_t)((inset_reg >>
9786 : : I40E_32_BIT_WIDTH) & UINT32_MAX));
9787 : :
9788 [ # # ]: 0 : for (i = 0; i < num; i++) {
9789 : 0 : i40e_check_write_global_reg(hw,
9790 : 0 : I40E_GLQF_FD_MSK(i, pctype),
9791 : : mask_reg[i]);
9792 : 0 : i40e_check_write_global_reg(hw,
9793 : : I40E_GLQF_HASH_MSK(i, pctype),
9794 : : mask_reg[i]);
9795 : : }
9796 : : /*clear unused mask registers of the pctype */
9797 [ # # ]: 0 : for (i = num; i < I40E_INSET_MASK_NUM_REG; i++) {
9798 : 0 : i40e_check_write_global_reg(hw,
9799 : 0 : I40E_GLQF_FD_MSK(i, pctype),
9800 : : 0);
9801 : 0 : i40e_check_write_global_reg(hw,
9802 : : I40E_GLQF_HASH_MSK(i, pctype),
9803 : : 0);
9804 : : }
9805 : : } else {
9806 : 0 : PMD_DRV_LOG(ERR, "Input set setting is not supported.");
9807 : : }
9808 : 0 : I40E_WRITE_FLUSH(hw);
9809 : :
9810 : : /* store the default input set */
9811 [ # # ]: 0 : if (!pf->support_multi_driver)
9812 : 0 : pf->hash_input_set[pctype] = input_set;
9813 : 0 : pf->fdir.input_set[pctype] = input_set;
9814 : : }
9815 : : }
9816 : :
9817 : : int
9818 : 0 : i40e_set_hash_inset(struct i40e_hw *hw, uint64_t input_set,
9819 : : uint32_t pctype, bool add)
9820 : : {
9821 : 0 : struct i40e_pf *pf = &((struct i40e_adapter *)hw->back)->pf;
9822 : 0 : uint32_t mask_reg[I40E_INSET_MASK_NUM_REG] = {0};
9823 : : uint64_t inset_reg = 0;
9824 : : int num, i;
9825 : :
9826 [ # # ]: 0 : if (pf->support_multi_driver) {
9827 : 0 : PMD_DRV_LOG(ERR,
9828 : : "Modify input set is not permitted when multi-driver enabled.");
9829 : 0 : return -EPERM;
9830 : : }
9831 : :
9832 : : /* For X722, get translated pctype in fd pctype register */
9833 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722)
9834 : 0 : pctype = i40e_read_rx_ctl(hw, I40E_GLQF_FD_PCTYPES(pctype));
9835 : :
9836 [ # # ]: 0 : if (add) {
9837 : : /* get inset value in register */
9838 : 0 : inset_reg = i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, pctype));
9839 : 0 : inset_reg <<= I40E_32_BIT_WIDTH;
9840 : 0 : inset_reg |= i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, pctype));
9841 : 0 : input_set |= pf->hash_input_set[pctype];
9842 : : }
9843 : 0 : num = i40e_generate_inset_mask_reg(hw, input_set, mask_reg,
9844 : : I40E_INSET_MASK_NUM_REG);
9845 [ # # ]: 0 : if (num < 0)
9846 : : return -EINVAL;
9847 : :
9848 : 0 : inset_reg |= i40e_translate_input_set_reg(hw->mac.type, input_set);
9849 : :
9850 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(0, pctype),
9851 : : (uint32_t)(inset_reg & UINT32_MAX));
9852 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_INSET(1, pctype),
9853 : 0 : (uint32_t)((inset_reg >>
9854 : : I40E_32_BIT_WIDTH) & UINT32_MAX));
9855 : :
9856 [ # # ]: 0 : for (i = 0; i < num; i++)
9857 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
9858 : : mask_reg[i]);
9859 : : /*clear unused mask registers of the pctype */
9860 [ # # ]: 0 : for (i = num; i < I40E_INSET_MASK_NUM_REG; i++)
9861 : 0 : i40e_check_write_global_reg(hw, I40E_GLQF_HASH_MSK(i, pctype),
9862 : : 0);
9863 : 0 : I40E_WRITE_FLUSH(hw);
9864 : :
9865 : 0 : pf->hash_input_set[pctype] = input_set;
9866 : 0 : return 0;
9867 : : }
9868 : :
9869 : : /* Convert ethertype filter structure */
9870 : : static int
9871 : : i40e_ethertype_filter_convert(const struct rte_eth_ethertype_filter *input,
9872 : : struct i40e_ethertype_filter *filter)
9873 : : {
9874 : 0 : memcpy(&filter->input.mac_addr, &input->mac_addr,
9875 : : RTE_ETHER_ADDR_LEN);
9876 : 0 : filter->input.ether_type = input->ether_type;
9877 : 0 : filter->flags = input->flags;
9878 : 0 : filter->queue = input->queue;
9879 : :
9880 : : return 0;
9881 : : }
9882 : :
9883 : : /* Check if there exists the ethertype filter */
9884 : : struct i40e_ethertype_filter *
9885 : 0 : i40e_sw_ethertype_filter_lookup(struct i40e_ethertype_rule *ethertype_rule,
9886 : : const struct i40e_ethertype_filter_input *input)
9887 : : {
9888 : : int ret;
9889 : :
9890 : 0 : ret = rte_hash_lookup(ethertype_rule->hash_table, (const void *)input);
9891 [ # # ]: 0 : if (ret < 0)
9892 : : return NULL;
9893 : :
9894 : 0 : return ethertype_rule->hash_map[ret];
9895 : : }
9896 : :
9897 : : /* Add ethertype filter in SW list */
9898 : : static int
9899 : 0 : i40e_sw_ethertype_filter_insert(struct i40e_pf *pf,
9900 : : struct i40e_ethertype_filter *filter)
9901 : : {
9902 : : struct i40e_ethertype_rule *rule = &pf->ethertype;
9903 : : int ret;
9904 : :
9905 : 0 : ret = rte_hash_add_key(rule->hash_table, &filter->input);
9906 [ # # ]: 0 : if (ret < 0) {
9907 : 0 : PMD_DRV_LOG(ERR,
9908 : : "Failed to insert ethertype filter"
9909 : : " to hash table %d!",
9910 : : ret);
9911 : 0 : return ret;
9912 : : }
9913 : 0 : rule->hash_map[ret] = filter;
9914 : :
9915 : 0 : TAILQ_INSERT_TAIL(&rule->ethertype_list, filter, rules);
9916 : :
9917 : 0 : return 0;
9918 : : }
9919 : :
9920 : : /* Delete ethertype filter in SW list */
9921 : : int
9922 : 0 : i40e_sw_ethertype_filter_del(struct i40e_pf *pf,
9923 : : struct i40e_ethertype_filter_input *input)
9924 : : {
9925 : : struct i40e_ethertype_rule *rule = &pf->ethertype;
9926 : : struct i40e_ethertype_filter *filter;
9927 : : int ret;
9928 : :
9929 : 0 : ret = rte_hash_del_key(rule->hash_table, input);
9930 [ # # ]: 0 : if (ret < 0) {
9931 : 0 : PMD_DRV_LOG(ERR,
9932 : : "Failed to delete ethertype filter"
9933 : : " to hash table %d!",
9934 : : ret);
9935 : 0 : return ret;
9936 : : }
9937 : 0 : filter = rule->hash_map[ret];
9938 : 0 : rule->hash_map[ret] = NULL;
9939 : :
9940 [ # # ]: 0 : TAILQ_REMOVE(&rule->ethertype_list, filter, rules);
9941 : 0 : rte_free(filter);
9942 : :
9943 : 0 : return 0;
9944 : : }
9945 : :
9946 : : /*
9947 : : * Configure ethertype filter, which can director packet by filtering
9948 : : * with mac address and ether_type or only ether_type
9949 : : */
9950 : : int
9951 : 0 : i40e_ethertype_filter_set(struct i40e_pf *pf,
9952 : : struct rte_eth_ethertype_filter *filter,
9953 : : bool add)
9954 : : {
9955 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
9956 : 0 : struct i40e_ethertype_rule *ethertype_rule = &pf->ethertype;
9957 : : struct i40e_ethertype_filter *ethertype_filter, *node;
9958 : : struct i40e_ethertype_filter check_filter;
9959 : : struct i40e_control_filter_stats stats;
9960 : : uint16_t flags = 0;
9961 : : int ret;
9962 : :
9963 [ # # ]: 0 : if (filter->queue >= pf->dev_data->nb_rx_queues) {
9964 : 0 : PMD_DRV_LOG(ERR, "Invalid queue ID");
9965 : 0 : return -EINVAL;
9966 : : }
9967 [ # # ]: 0 : if (filter->ether_type == RTE_ETHER_TYPE_IPV4 ||
9968 : : filter->ether_type == RTE_ETHER_TYPE_IPV6) {
9969 : 0 : PMD_DRV_LOG(ERR,
9970 : : "unsupported ether_type(0x%04x) in control packet filter.",
9971 : : filter->ether_type);
9972 : 0 : return -EINVAL;
9973 : : }
9974 [ # # ]: 0 : if (filter->ether_type == RTE_ETHER_TYPE_VLAN)
9975 : 0 : PMD_DRV_LOG(WARNING,
9976 : : "filter vlan ether_type in first tag is not supported.");
9977 : :
9978 : : /* Check if there is the filter in SW list */
9979 : : memset(&check_filter, 0, sizeof(check_filter));
9980 : : i40e_ethertype_filter_convert(filter, &check_filter);
9981 : 0 : node = i40e_sw_ethertype_filter_lookup(ethertype_rule,
9982 : : &check_filter.input);
9983 [ # # ]: 0 : if (add && node) {
9984 : 0 : PMD_DRV_LOG(ERR, "Conflict with existing ethertype rules!");
9985 : 0 : return -EINVAL;
9986 : : }
9987 : :
9988 [ # # ]: 0 : if (!add && !node) {
9989 : 0 : PMD_DRV_LOG(ERR, "There's no corresponding ethertype filter!");
9990 : 0 : return -EINVAL;
9991 : : }
9992 : :
9993 [ # # ]: 0 : if (!(filter->flags & RTE_ETHTYPE_FLAGS_MAC))
9994 : : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
9995 [ # # ]: 0 : if (filter->flags & RTE_ETHTYPE_FLAGS_DROP)
9996 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
9997 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
9998 : :
9999 : : memset(&stats, 0, sizeof(stats));
10000 : 0 : ret = i40e_aq_add_rem_control_packet_filter(hw,
10001 : 0 : filter->mac_addr.addr_bytes,
10002 : 0 : filter->ether_type, flags,
10003 : 0 : pf->main_vsi->seid,
10004 : 0 : filter->queue, add, &stats, NULL);
10005 : :
10006 : 0 : PMD_DRV_LOG(INFO,
10007 : : "add/rem control packet filter, return %d, mac_etype_used = %u, etype_used = %u, mac_etype_free = %u, etype_free = %u",
10008 : : ret, stats.mac_etype_used, stats.etype_used,
10009 : : stats.mac_etype_free, stats.etype_free);
10010 [ # # ]: 0 : if (ret < 0)
10011 : : return -ENOSYS;
10012 : :
10013 : : /* Add or delete a filter in SW list */
10014 [ # # ]: 0 : if (add) {
10015 : 0 : ethertype_filter = rte_zmalloc("ethertype_filter",
10016 : : sizeof(*ethertype_filter), 0);
10017 [ # # ]: 0 : if (ethertype_filter == NULL) {
10018 : 0 : PMD_DRV_LOG(ERR, "Failed to alloc memory.");
10019 : 0 : return -ENOMEM;
10020 : : }
10021 : :
10022 : : memcpy(ethertype_filter, &check_filter,
10023 : : sizeof(check_filter));
10024 : 0 : ret = i40e_sw_ethertype_filter_insert(pf, ethertype_filter);
10025 [ # # ]: 0 : if (ret < 0)
10026 : 0 : rte_free(ethertype_filter);
10027 : : } else {
10028 : 0 : ret = i40e_sw_ethertype_filter_del(pf, &node->input);
10029 : : }
10030 : :
10031 : : return ret;
10032 : : }
10033 : :
10034 : : static int
10035 : 0 : i40e_dev_flow_ops_get(struct rte_eth_dev *dev,
10036 : : const struct rte_flow_ops **ops)
10037 : : {
10038 [ # # ]: 0 : if (dev == NULL)
10039 : : return -EINVAL;
10040 : :
10041 : 0 : *ops = &i40e_flow_ops;
10042 : 0 : return 0;
10043 : : }
10044 : :
10045 : : /*
10046 : : * Check and enable Extended Tag.
10047 : : * Enabling Extended Tag is important for 40G performance.
10048 : : */
10049 : : static void
10050 : 0 : i40e_enable_extended_tag(struct rte_eth_dev *dev)
10051 : : {
10052 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
10053 : 0 : uint32_t buf = 0;
10054 : : int ret;
10055 : :
10056 : 0 : ret = rte_pci_read_config(pci_dev, &buf, sizeof(buf),
10057 : : PCI_DEV_CAP_REG);
10058 [ # # ]: 0 : if (ret < 0) {
10059 : 0 : PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
10060 : : PCI_DEV_CAP_REG);
10061 : 0 : return;
10062 : : }
10063 [ # # ]: 0 : if (!(buf & PCI_DEV_CAP_EXT_TAG_MASK)) {
10064 : 0 : PMD_DRV_LOG(ERR, "Does not support Extended Tag");
10065 : 0 : return;
10066 : : }
10067 : :
10068 : 0 : buf = 0;
10069 : 0 : ret = rte_pci_read_config(pci_dev, &buf, sizeof(buf),
10070 : : PCI_DEV_CTRL_REG);
10071 [ # # ]: 0 : if (ret < 0) {
10072 : 0 : PMD_DRV_LOG(ERR, "Failed to read PCI offset 0x%x",
10073 : : PCI_DEV_CTRL_REG);
10074 : 0 : return;
10075 : : }
10076 [ # # ]: 0 : if (buf & PCI_DEV_CTRL_EXT_TAG_MASK) {
10077 : 0 : PMD_DRV_LOG(DEBUG, "Extended Tag has already been enabled");
10078 : 0 : return;
10079 : : }
10080 : 0 : buf |= PCI_DEV_CTRL_EXT_TAG_MASK;
10081 : 0 : ret = rte_pci_write_config(pci_dev, &buf, sizeof(buf),
10082 : : PCI_DEV_CTRL_REG);
10083 [ # # ]: 0 : if (ret < 0) {
10084 : 0 : PMD_DRV_LOG(ERR, "Failed to write PCI offset 0x%x",
10085 : : PCI_DEV_CTRL_REG);
10086 : 0 : return;
10087 : : }
10088 : : }
10089 : :
10090 : : /*
10091 : : * As some registers wouldn't be reset unless a global hardware reset,
10092 : : * hardware initialization is needed to put those registers into an
10093 : : * expected initial state.
10094 : : */
10095 : : static void
10096 : 0 : i40e_hw_init(struct rte_eth_dev *dev)
10097 : : {
10098 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10099 : :
10100 : 0 : i40e_enable_extended_tag(dev);
10101 : :
10102 : : /* clear the PF Queue Filter control register */
10103 : 0 : i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, 0);
10104 : :
10105 : : /* Disable symmetric hash per port */
10106 : 0 : i40e_set_symmetric_hash_enable_per_port(hw, 0);
10107 : 0 : }
10108 : :
10109 : : /*
10110 : : * For X722 it is possible to have multiple pctypes mapped to the same flowtype
10111 : : * however this function will return only one highest pctype index,
10112 : : * which is not quite correct. This is known problem of i40e driver
10113 : : * and needs to be fixed later.
10114 : : */
10115 : : enum i40e_filter_pctype
10116 : 0 : i40e_flowtype_to_pctype(const struct i40e_adapter *adapter, uint16_t flow_type)
10117 : : {
10118 : : int i;
10119 : : uint64_t pctype_mask;
10120 : :
10121 [ # # ]: 0 : if (flow_type < I40E_FLOW_TYPE_MAX) {
10122 : 0 : pctype_mask = adapter->pctypes_tbl[flow_type];
10123 [ # # ]: 0 : for (i = I40E_FILTER_PCTYPE_MAX - 1; i > 0; i--) {
10124 [ # # ]: 0 : if (pctype_mask & RTE_BIT64(i))
10125 : 0 : return (enum i40e_filter_pctype)i;
10126 : : }
10127 : : }
10128 : : return I40E_FILTER_PCTYPE_INVALID;
10129 : : }
10130 : :
10131 : : uint16_t
10132 : 0 : i40e_pctype_to_flowtype(const struct i40e_adapter *adapter,
10133 : : enum i40e_filter_pctype pctype)
10134 : : {
10135 : : uint16_t flowtype;
10136 : 0 : uint64_t pctype_mask = RTE_BIT64(pctype);
10137 : :
10138 [ # # ]: 0 : for (flowtype = RTE_ETH_FLOW_UNKNOWN + 1; flowtype < I40E_FLOW_TYPE_MAX;
10139 : 0 : flowtype++) {
10140 [ # # ]: 0 : if (adapter->pctypes_tbl[flowtype] & pctype_mask)
10141 : 0 : return flowtype;
10142 : : }
10143 : :
10144 : : return RTE_ETH_FLOW_UNKNOWN;
10145 : : }
10146 : :
10147 : : /*
10148 : : * On X710, performance number is far from the expectation on recent firmware
10149 : : * versions; on XL710, performance number is also far from the expectation on
10150 : : * recent firmware versions, if promiscuous mode is disabled, or promiscuous
10151 : : * mode is enabled and port MAC address is equal to the packet destination MAC
10152 : : * address. The fix for this issue may not be integrated in the following
10153 : : * firmware version. So the workaround in software driver is needed. It needs
10154 : : * to modify the initial values of 3 internal only registers for both X710 and
10155 : : * XL710. Note that the values for X710 or XL710 could be different, and the
10156 : : * workaround can be removed when it is fixed in firmware in the future.
10157 : : */
10158 : :
10159 : : /* For both X710 and XL710 */
10160 : : #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1 0x10000200
10161 : : #define I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2 0x203F0200
10162 : : #define I40E_GL_SWR_PRI_JOIN_MAP_0 0x26CE00
10163 : :
10164 : : #define I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x011f0200
10165 : : #define I40E_GL_SWR_PRI_JOIN_MAP_2 0x26CE08
10166 : :
10167 : : /* For X722 */
10168 : : #define I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE 0x20000200
10169 : : #define I40E_X722_GL_SWR_PRI_JOIN_MAP_2_VALUE 0x013F0200
10170 : :
10171 : : /* For X710 */
10172 : : #define I40E_GL_SWR_PM_UP_THR_EF_VALUE 0x03030303
10173 : : /* For XL710 */
10174 : : #define I40E_GL_SWR_PM_UP_THR_SF_VALUE 0x06060606
10175 : : #define I40E_GL_SWR_PM_UP_THR 0x269FBC
10176 : :
10177 : : /*
10178 : : * GL_SWR_PM_UP_THR:
10179 : : * The value is not impacted from the link speed, its value is set according
10180 : : * to the total number of ports for a better pipe-monitor configuration.
10181 : : */
10182 : : static bool
10183 : 0 : i40e_get_swr_pm_cfg(struct i40e_hw *hw, uint32_t *value)
10184 : : {
10185 : : #define I40E_GL_SWR_PM_EF_DEVICE(dev) \
10186 : : .device_id = (dev), \
10187 : : .val = I40E_GL_SWR_PM_UP_THR_EF_VALUE
10188 : :
10189 : : #define I40E_GL_SWR_PM_SF_DEVICE(dev) \
10190 : : .device_id = (dev), \
10191 : : .val = I40E_GL_SWR_PM_UP_THR_SF_VALUE
10192 : :
10193 : : static const struct {
10194 : : uint16_t device_id;
10195 : : uint32_t val;
10196 : : } swr_pm_table[] = {
10197 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_SFP_XL710) },
10198 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_KX_C) },
10199 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_10G_BASE_T) },
10200 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_10G_BASE_T4) },
10201 : : { I40E_GL_SWR_PM_EF_DEVICE(I40E_DEV_ID_SFP_X722) },
10202 : :
10203 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_KX_B) },
10204 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_QSFP_A) },
10205 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_QSFP_B) },
10206 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_20G_KR2) },
10207 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_20G_KR2_A) },
10208 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_25G_B) },
10209 : : { I40E_GL_SWR_PM_SF_DEVICE(I40E_DEV_ID_25G_SFP28) },
10210 : : };
10211 : : uint32_t i;
10212 : :
10213 [ # # ]: 0 : if (value == NULL) {
10214 : 0 : PMD_DRV_LOG(ERR, "value is NULL");
10215 : 0 : return false;
10216 : : }
10217 : :
10218 [ # # ]: 0 : for (i = 0; i < RTE_DIM(swr_pm_table); i++) {
10219 [ # # ]: 0 : if (hw->device_id == swr_pm_table[i].device_id) {
10220 : 0 : *value = swr_pm_table[i].val;
10221 : :
10222 : 0 : PMD_DRV_LOG(DEBUG, "Device 0x%x with GL_SWR_PM_UP_THR "
10223 : : "value - 0x%08x",
10224 : : hw->device_id, *value);
10225 : 0 : return true;
10226 : : }
10227 : : }
10228 : :
10229 : : return false;
10230 : : }
10231 : :
10232 : : static int
10233 : 0 : i40e_dev_sync_phy_type(struct i40e_hw *hw)
10234 : : {
10235 : : enum i40e_status_code status;
10236 : : struct i40e_aq_get_phy_abilities_resp phy_ab;
10237 : : int ret = -ENOTSUP;
10238 : : int retries = 0;
10239 : :
10240 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, true, &phy_ab,
10241 : : NULL);
10242 : :
10243 [ # # ]: 0 : while (status) {
10244 : 0 : PMD_INIT_LOG(WARNING, "Failed to sync phy type: status=%d",
10245 : : status);
10246 : 0 : retries++;
10247 : 0 : rte_delay_us(100000);
10248 [ # # ]: 0 : if (retries < 5)
10249 : 0 : status = i40e_aq_get_phy_capabilities(hw, false,
10250 : : true, &phy_ab, NULL);
10251 : : else
10252 : : return ret;
10253 : : }
10254 : : return 0;
10255 : : }
10256 : :
10257 : : static void
10258 : 0 : i40e_configure_registers(struct i40e_hw *hw)
10259 : : {
10260 : : static struct {
10261 : : uint32_t addr;
10262 : : uint64_t val;
10263 : : } reg_table[] = {
10264 : : {I40E_GL_SWR_PRI_JOIN_MAP_0, 0},
10265 : : {I40E_GL_SWR_PRI_JOIN_MAP_2, 0},
10266 : : {I40E_GL_SWR_PM_UP_THR, 0}, /* Compute value dynamically */
10267 : : };
10268 : : uint64_t reg;
10269 : : uint32_t i;
10270 : : int ret;
10271 : :
10272 [ # # ]: 0 : for (i = 0; i < RTE_DIM(reg_table); i++) {
10273 [ # # ]: 0 : if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_0) {
10274 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) /* For X722 */
10275 : 0 : reg_table[i].val =
10276 : : I40E_X722_GL_SWR_PRI_JOIN_MAP_0_VALUE;
10277 : : else /* For X710/XL710/XXV710 */
10278 [ # # ]: 0 : if (hw->aq.fw_maj_ver < 6)
10279 : 0 : reg_table[i].val =
10280 : : I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_1;
10281 : : else
10282 : 0 : reg_table[i].val =
10283 : : I40E_GL_SWR_PRI_JOIN_MAP_0_VALUE_2;
10284 : : }
10285 : :
10286 [ # # ]: 0 : if (reg_table[i].addr == I40E_GL_SWR_PRI_JOIN_MAP_2) {
10287 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) /* For X722 */
10288 : 0 : reg_table[i].val =
10289 : : I40E_X722_GL_SWR_PRI_JOIN_MAP_2_VALUE;
10290 : : else /* For X710/XL710/XXV710 */
10291 : 0 : reg_table[i].val =
10292 : : I40E_GL_SWR_PRI_JOIN_MAP_2_VALUE;
10293 : : }
10294 : :
10295 [ # # ]: 0 : if (reg_table[i].addr == I40E_GL_SWR_PM_UP_THR) {
10296 : : uint32_t cfg_val;
10297 : :
10298 [ # # ]: 0 : if (!i40e_get_swr_pm_cfg(hw, &cfg_val)) {
10299 : 0 : PMD_DRV_LOG(DEBUG, "Device 0x%x skips "
10300 : : "GL_SWR_PM_UP_THR value fixup",
10301 : : hw->device_id);
10302 : 0 : continue;
10303 : : }
10304 : :
10305 : 0 : reg_table[i].val = cfg_val;
10306 : : }
10307 : :
10308 : 0 : ret = i40e_aq_debug_read_register(hw, reg_table[i].addr,
10309 : : ®, NULL);
10310 [ # # ]: 0 : if (ret < 0) {
10311 : 0 : PMD_DRV_LOG(ERR, "Failed to read from 0x%"PRIx32,
10312 : : reg_table[i].addr);
10313 : 0 : break;
10314 : : }
10315 : 0 : PMD_DRV_LOG(DEBUG, "Read from 0x%"PRIx32": 0x%"PRIx64,
10316 : : reg_table[i].addr, reg);
10317 [ # # ]: 0 : if (reg == reg_table[i].val)
10318 : 0 : continue;
10319 : :
10320 : 0 : ret = i40e_aq_debug_write_register(hw, reg_table[i].addr,
10321 : : reg_table[i].val, NULL);
10322 [ # # ]: 0 : if (ret < 0) {
10323 : 0 : PMD_DRV_LOG(ERR,
10324 : : "Failed to write 0x%"PRIx64" to the address of 0x%"PRIx32,
10325 : : reg_table[i].val, reg_table[i].addr);
10326 : 0 : break;
10327 : : }
10328 : 0 : PMD_DRV_LOG(DEBUG, "Write 0x%"PRIx64" to the address of "
10329 : : "0x%"PRIx32, reg_table[i].val, reg_table[i].addr);
10330 : : }
10331 : 0 : }
10332 : :
10333 : : #define I40E_VSI_TSR_QINQ_CONFIG 0xc030
10334 : : #define I40E_VSI_L2TAGSTXVALID(_i) (0x00042800 + ((_i) * 4))
10335 : : #define I40E_VSI_L2TAGSTXVALID_QINQ 0xab
10336 : : static int
10337 : 0 : i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi)
10338 : : {
10339 : : uint32_t reg;
10340 : : int ret;
10341 : :
10342 [ # # ]: 0 : if (vsi->vsi_id >= I40E_MAX_NUM_VSIS) {
10343 : 0 : PMD_DRV_LOG(ERR, "VSI ID exceeds the maximum");
10344 : 0 : return -EINVAL;
10345 : : }
10346 : :
10347 : : /* Configure for double VLAN RX stripping */
10348 : 0 : reg = I40E_READ_REG(hw, I40E_VSI_TSR(vsi->vsi_id));
10349 [ # # ]: 0 : if ((reg & I40E_VSI_TSR_QINQ_CONFIG) != I40E_VSI_TSR_QINQ_CONFIG) {
10350 : 0 : reg |= I40E_VSI_TSR_QINQ_CONFIG;
10351 : 0 : ret = i40e_aq_debug_write_register(hw,
10352 : 0 : I40E_VSI_TSR(vsi->vsi_id),
10353 : : reg, NULL);
10354 [ # # ]: 0 : if (ret < 0) {
10355 : 0 : PMD_DRV_LOG(ERR, "Failed to update VSI_TSR[%d]",
10356 : : vsi->vsi_id);
10357 : 0 : return I40E_ERR_CONFIG;
10358 : : }
10359 : : }
10360 : :
10361 : : /* Configure for double VLAN TX insertion */
10362 : 0 : reg = I40E_READ_REG(hw, I40E_VSI_L2TAGSTXVALID(vsi->vsi_id));
10363 [ # # ]: 0 : if ((reg & 0xff) != I40E_VSI_L2TAGSTXVALID_QINQ) {
10364 : : reg = I40E_VSI_L2TAGSTXVALID_QINQ;
10365 : 0 : ret = i40e_aq_debug_write_register(hw,
10366 : 0 : I40E_VSI_L2TAGSTXVALID(
10367 : : vsi->vsi_id), reg, NULL);
10368 [ # # ]: 0 : if (ret < 0) {
10369 : 0 : PMD_DRV_LOG(ERR,
10370 : : "Failed to update VSI_L2TAGSTXVALID[%d]",
10371 : : vsi->vsi_id);
10372 : 0 : return I40E_ERR_CONFIG;
10373 : : }
10374 : : }
10375 : :
10376 : : return 0;
10377 : : }
10378 : :
10379 : : static uint64_t
10380 : : i40e_read_systime_cyclecounter(struct rte_eth_dev *dev)
10381 : : {
10382 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10383 : : uint64_t systim_cycles;
10384 : :
10385 : 0 : systim_cycles = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_L);
10386 : 0 : systim_cycles |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TIME_H)
10387 [ # # ]: 0 : << 32;
10388 : :
10389 : : return systim_cycles;
10390 : : }
10391 : :
10392 : : static uint64_t
10393 : : i40e_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev, uint8_t index)
10394 : : {
10395 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10396 : : uint64_t rx_tstamp;
10397 : :
10398 : 0 : rx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_L(index));
10399 : 0 : rx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(index))
10400 [ # # ]: 0 : << 32;
10401 : :
10402 : : return rx_tstamp;
10403 : : }
10404 : :
10405 : : static uint64_t
10406 : : i40e_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
10407 : : {
10408 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10409 : : uint64_t tx_tstamp;
10410 : :
10411 : 0 : tx_tstamp = (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_L);
10412 : 0 : tx_tstamp |= (uint64_t)I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H)
10413 [ # # ]: 0 : << 32;
10414 : :
10415 : : return tx_tstamp;
10416 : : }
10417 : :
10418 : : static void
10419 : 0 : i40e_start_timecounters(struct rte_eth_dev *dev)
10420 : : {
10421 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10422 : : struct i40e_adapter *adapter = dev->data->dev_private;
10423 : : struct rte_eth_link link;
10424 : : uint32_t tsync_inc_l;
10425 : : uint32_t tsync_inc_h;
10426 : :
10427 : : /* Get current link speed. */
10428 : 0 : i40e_dev_link_update(dev, 1);
10429 : 0 : rte_eth_linkstatus_get(dev, &link);
10430 : :
10431 [ # # # # ]: 0 : switch (link.link_speed) {
10432 : : case RTE_ETH_SPEED_NUM_40G:
10433 : : case RTE_ETH_SPEED_NUM_25G:
10434 : : tsync_inc_l = I40E_PTP_40GB_INCVAL & 0xFFFFFFFF;
10435 : : tsync_inc_h = I40E_PTP_40GB_INCVAL >> 32;
10436 : : break;
10437 : 0 : case RTE_ETH_SPEED_NUM_10G:
10438 : : tsync_inc_l = I40E_PTP_10GB_INCVAL & 0xFFFFFFFF;
10439 : : tsync_inc_h = I40E_PTP_10GB_INCVAL >> 32;
10440 : 0 : break;
10441 : 0 : case RTE_ETH_SPEED_NUM_1G:
10442 : : tsync_inc_l = I40E_PTP_1GB_INCVAL & 0xFFFFFFFF;
10443 : : tsync_inc_h = I40E_PTP_1GB_INCVAL >> 32;
10444 : 0 : break;
10445 : 0 : default:
10446 : : tsync_inc_l = 0x0;
10447 : : tsync_inc_h = 0x0;
10448 : : }
10449 : :
10450 : : /* Set the timesync increment value. */
10451 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, tsync_inc_l);
10452 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, tsync_inc_h);
10453 : :
10454 : 0 : memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
10455 : 0 : memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
10456 : 0 : memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
10457 : :
10458 : 0 : adapter->systime_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10459 : : adapter->systime_tc.cc_shift = 0;
10460 : : adapter->systime_tc.nsec_mask = 0;
10461 : :
10462 : 0 : adapter->rx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10463 : : adapter->rx_tstamp_tc.cc_shift = 0;
10464 : : adapter->rx_tstamp_tc.nsec_mask = 0;
10465 : :
10466 : 0 : adapter->tx_tstamp_tc.cc_mask = I40E_CYCLECOUNTER_MASK;
10467 : : adapter->tx_tstamp_tc.cc_shift = 0;
10468 : : adapter->tx_tstamp_tc.nsec_mask = 0;
10469 : 0 : }
10470 : :
10471 : : static int
10472 : 0 : i40e_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
10473 : : {
10474 : 0 : struct i40e_adapter *adapter = dev->data->dev_private;
10475 : :
10476 : 0 : adapter->systime_tc.nsec += delta;
10477 : 0 : adapter->rx_tstamp_tc.nsec += delta;
10478 : 0 : adapter->tx_tstamp_tc.nsec += delta;
10479 : :
10480 : 0 : return 0;
10481 : : }
10482 : :
10483 : : static int
10484 : 0 : i40e_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
10485 : : {
10486 : : uint64_t ns;
10487 : 0 : struct i40e_adapter *adapter = dev->data->dev_private;
10488 : :
10489 : : ns = rte_timespec_to_ns(ts);
10490 : :
10491 : : /* Set the timecounters to a new value. */
10492 : 0 : adapter->systime_tc.nsec = ns;
10493 : 0 : adapter->rx_tstamp_tc.nsec = ns;
10494 : 0 : adapter->tx_tstamp_tc.nsec = ns;
10495 : :
10496 : 0 : return 0;
10497 : : }
10498 : :
10499 : : static int
10500 : 0 : i40e_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
10501 : : {
10502 : : uint64_t ns, systime_cycles;
10503 : 0 : struct i40e_adapter *adapter = dev->data->dev_private;
10504 : :
10505 : : systime_cycles = i40e_read_systime_cyclecounter(dev);
10506 : : ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
10507 : 0 : *ts = rte_ns_to_timespec(ns);
10508 : :
10509 : 0 : return 0;
10510 : : }
10511 : :
10512 : : static int
10513 : 0 : i40e_timesync_enable(struct rte_eth_dev *dev)
10514 : : {
10515 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10516 : : uint32_t tsync_ctl_l;
10517 : : uint32_t tsync_ctl_h;
10518 : : struct timespec ts;
10519 : :
10520 : : memset(&ts, 0, sizeof(struct timespec));
10521 : :
10522 : : /* Stop the timesync system time. */
10523 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
10524 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
10525 : : /* Reset the timesync system time value. */
10526 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_L, 0x0);
10527 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_TIME_H, 0x0);
10528 : :
10529 : 0 : i40e_start_timecounters(dev);
10530 : :
10531 : : /* Clear timesync registers. */
10532 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
10533 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_TXTIME_H);
10534 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(0));
10535 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(1));
10536 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(2));
10537 : 0 : I40E_READ_REG(hw, I40E_PRTTSYN_RXTIME_H(3));
10538 : :
10539 : : /* Enable timestamping of PTP packets. */
10540 : 0 : tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
10541 : 0 : tsync_ctl_l |= I40E_PRTTSYN_TSYNENA;
10542 : :
10543 : 0 : tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
10544 : : tsync_ctl_h |= I40E_PRTTSYN_TSYNENA;
10545 : 0 : tsync_ctl_h |= I40E_PRTTSYN_TSYNTYPE;
10546 : :
10547 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
10548 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
10549 : :
10550 : : /* i40e uses zero-based timestamping so only adjust timecounter */
10551 : : i40e_timesync_write_time(dev, &ts);
10552 : :
10553 : 0 : return 0;
10554 : : }
10555 : :
10556 : : static int
10557 : 0 : i40e_timesync_disable(struct rte_eth_dev *dev)
10558 : : {
10559 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10560 : : uint32_t tsync_ctl_l;
10561 : : uint32_t tsync_ctl_h;
10562 : :
10563 : : /* Disable timestamping of transmitted PTP packets. */
10564 : 0 : tsync_ctl_l = I40E_READ_REG(hw, I40E_PRTTSYN_CTL0);
10565 : 0 : tsync_ctl_l &= ~I40E_PRTTSYN_TSYNENA;
10566 : :
10567 : 0 : tsync_ctl_h = I40E_READ_REG(hw, I40E_PRTTSYN_CTL1);
10568 : 0 : tsync_ctl_h &= ~I40E_PRTTSYN_TSYNENA;
10569 : :
10570 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL0, tsync_ctl_l);
10571 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_CTL1, tsync_ctl_h);
10572 : :
10573 : : /* Reset the timesync increment value. */
10574 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_L, 0x0);
10575 : 0 : I40E_WRITE_REG(hw, I40E_PRTTSYN_INC_H, 0x0);
10576 : :
10577 : 0 : return 0;
10578 : : }
10579 : :
10580 : : static int
10581 : 0 : i40e_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
10582 : : struct timespec *timestamp, uint32_t flags)
10583 : : {
10584 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10585 : : struct i40e_adapter *adapter = dev->data->dev_private;
10586 : : uint32_t sync_status;
10587 : 0 : uint32_t index = flags & 0x03;
10588 : : uint64_t rx_tstamp_cycles;
10589 : : uint64_t ns;
10590 : :
10591 : 0 : sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_1);
10592 [ # # ]: 0 : if ((sync_status & (1 << index)) == 0)
10593 : : return -EINVAL;
10594 : :
10595 : 0 : rx_tstamp_cycles = i40e_read_rx_tstamp_cyclecounter(dev, index);
10596 : : ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
10597 : 0 : *timestamp = rte_ns_to_timespec(ns);
10598 : :
10599 : 0 : return 0;
10600 : : }
10601 : :
10602 : : static int
10603 : 0 : i40e_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
10604 : : struct timespec *timestamp)
10605 : : {
10606 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
10607 : : struct i40e_adapter *adapter = dev->data->dev_private;
10608 : : uint32_t sync_status;
10609 : : uint64_t tx_tstamp_cycles;
10610 : : uint64_t ns;
10611 : :
10612 : 0 : sync_status = I40E_READ_REG(hw, I40E_PRTTSYN_STAT_0);
10613 [ # # ]: 0 : if ((sync_status & I40E_PRTTSYN_STAT_0_TXTIME_MASK) == 0)
10614 : : return -EINVAL;
10615 : :
10616 : : tx_tstamp_cycles = i40e_read_tx_tstamp_cyclecounter(dev);
10617 : : ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
10618 : 0 : *timestamp = rte_ns_to_timespec(ns);
10619 : :
10620 : 0 : return 0;
10621 : : }
10622 : :
10623 : : /*
10624 : : * i40e_parse_dcb_configure - parse dcb configure from user
10625 : : * @dev: the device being configured
10626 : : * @dcb_cfg: pointer of the result of parse
10627 : : * @*tc_map: bit map of enabled traffic classes
10628 : : *
10629 : : * Returns 0 on success, negative value on failure
10630 : : */
10631 : : static int
10632 [ # # ]: 0 : i40e_parse_dcb_configure(struct rte_eth_dev *dev,
10633 : : struct i40e_dcbx_config *dcb_cfg,
10634 : : uint8_t *tc_map)
10635 : : {
10636 : : struct rte_eth_dcb_rx_conf *dcb_rx_conf;
10637 : : uint8_t i, tc_bw, bw_lf;
10638 : :
10639 : : memset(dcb_cfg, 0, sizeof(struct i40e_dcbx_config));
10640 : :
10641 : 0 : dcb_rx_conf = &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
10642 [ # # ]: 0 : if (dcb_rx_conf->nb_tcs > I40E_MAX_TRAFFIC_CLASS) {
10643 : 0 : PMD_INIT_LOG(ERR, "number of tc exceeds max.");
10644 : 0 : return -EINVAL;
10645 : : }
10646 : :
10647 : : /* assume each tc has the same bw */
10648 : 0 : tc_bw = I40E_MAX_PERCENT / dcb_rx_conf->nb_tcs;
10649 [ # # ]: 0 : for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
10650 : 0 : dcb_cfg->etscfg.tcbwtable[i] = tc_bw;
10651 : : /* to ensure the sum of tcbw is equal to 100 */
10652 : 0 : bw_lf = I40E_MAX_PERCENT % dcb_rx_conf->nb_tcs;
10653 [ # # ]: 0 : for (i = 0; i < bw_lf; i++)
10654 : 0 : dcb_cfg->etscfg.tcbwtable[i]++;
10655 : :
10656 : : /* assume each tc has the same Transmission Selection Algorithm */
10657 [ # # ]: 0 : for (i = 0; i < dcb_rx_conf->nb_tcs; i++)
10658 : 0 : dcb_cfg->etscfg.tsatable[i] = I40E_IEEE_TSA_ETS;
10659 : :
10660 [ # # ]: 0 : for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
10661 : 0 : dcb_cfg->etscfg.prioritytable[i] =
10662 : 0 : dcb_rx_conf->dcb_tc[i];
10663 : :
10664 : : /* FW needs one App to configure HW */
10665 : 0 : dcb_cfg->numapps = I40E_DEFAULT_DCB_APP_NUM;
10666 : 0 : dcb_cfg->app[0].selector = I40E_APP_SEL_ETHTYPE;
10667 : 0 : dcb_cfg->app[0].priority = I40E_DEFAULT_DCB_APP_PRIO;
10668 : 0 : dcb_cfg->app[0].protocolid = I40E_APP_PROTOID_FCOE;
10669 : :
10670 [ # # ]: 0 : if (dcb_rx_conf->nb_tcs == 0)
10671 : 0 : *tc_map = 1; /* tc0 only */
10672 : : else
10673 : 0 : *tc_map = RTE_LEN2MASK(dcb_rx_conf->nb_tcs, uint8_t);
10674 : :
10675 [ # # ]: 0 : if (dev->data->dev_conf.dcb_capability_en & RTE_ETH_DCB_PFC_SUPPORT) {
10676 : 0 : dcb_cfg->pfc.willing = 0;
10677 : 0 : dcb_cfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
10678 : 0 : dcb_cfg->pfc.pfcenable = *tc_map;
10679 : : }
10680 : : return 0;
10681 : : }
10682 : :
10683 : :
10684 : : static enum i40e_status_code
10685 : 0 : i40e_vsi_update_queue_mapping(struct i40e_vsi *vsi,
10686 : : struct i40e_aqc_vsi_properties_data *info,
10687 : : uint8_t enabled_tcmap)
10688 : : {
10689 : : enum i40e_status_code ret;
10690 : : int i, total_tc = 0;
10691 : : uint16_t qpnum_per_tc, bsf, qp_idx;
10692 : 0 : struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(vsi);
10693 : : struct i40e_pf *pf = I40E_VSI_TO_PF(vsi);
10694 : : uint16_t used_queues;
10695 : :
10696 : 0 : ret = validate_tcmap_parameter(vsi, enabled_tcmap);
10697 [ # # ]: 0 : if (ret != I40E_SUCCESS)
10698 : : return ret;
10699 : :
10700 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10701 [ # # ]: 0 : if (enabled_tcmap & (1 << i))
10702 : 0 : total_tc++;
10703 : : }
10704 [ # # ]: 0 : if (total_tc == 0)
10705 : : total_tc = 1;
10706 : 0 : vsi->enabled_tc = enabled_tcmap;
10707 : :
10708 : : /* different VSI has different queues assigned */
10709 [ # # ]: 0 : if (vsi->type == I40E_VSI_MAIN)
10710 : 0 : used_queues = dev_data->nb_rx_queues -
10711 : 0 : pf->nb_cfg_vmdq_vsi * RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
10712 [ # # ]: 0 : else if (vsi->type == I40E_VSI_VMDQ2)
10713 : : used_queues = RTE_LIBRTE_I40E_QUEUE_NUM_PER_VM;
10714 : : else {
10715 : 0 : PMD_INIT_LOG(ERR, "unsupported VSI type.");
10716 : 0 : return I40E_ERR_NO_AVAILABLE_VSI;
10717 : : }
10718 : :
10719 : 0 : qpnum_per_tc = used_queues / total_tc;
10720 : : /* Number of queues per enabled TC */
10721 [ # # ]: 0 : if (qpnum_per_tc == 0) {
10722 : 0 : PMD_INIT_LOG(ERR, " number of queues is less that tcs.");
10723 : 0 : return I40E_ERR_INVALID_QP_ID;
10724 : : }
10725 : 0 : qpnum_per_tc = RTE_MIN((uint16_t)i40e_align_floor(qpnum_per_tc),
10726 : : I40E_MAX_Q_PER_TC);
10727 : 0 : bsf = rte_bsf32(qpnum_per_tc);
10728 : :
10729 : : /**
10730 : : * Configure TC and queue mapping parameters, for enabled TC,
10731 : : * allocate qpnum_per_tc queues to this traffic. For disabled TC,
10732 : : * default queue will serve it.
10733 : : */
10734 : : qp_idx = 0;
10735 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10736 [ # # ]: 0 : if (vsi->enabled_tc & (1 << i)) {
10737 : 0 : info->tc_mapping[i] = rte_cpu_to_le_16((qp_idx <<
10738 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
10739 : : (bsf << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT));
10740 : 0 : qp_idx += qpnum_per_tc;
10741 : : } else
10742 : 0 : info->tc_mapping[i] = 0;
10743 : : }
10744 : :
10745 : : /* Associate queue number with VSI, Keep vsi->nb_qps unchanged */
10746 : : if (vsi->type == I40E_VSI_SRIOV) {
10747 : : info->mapping_flags |=
10748 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
10749 : : for (i = 0; i < vsi->nb_qps; i++)
10750 : : info->queue_mapping[i] =
10751 : : rte_cpu_to_le_16(vsi->base_queue + i);
10752 : : } else {
10753 : 0 : info->mapping_flags |=
10754 : : rte_cpu_to_le_16(I40E_AQ_VSI_QUE_MAP_CONTIG);
10755 : 0 : info->queue_mapping[0] = rte_cpu_to_le_16(vsi->base_queue);
10756 : : }
10757 : 0 : info->valid_sections |=
10758 : : rte_cpu_to_le_16(I40E_AQ_VSI_PROP_QUEUE_MAP_VALID);
10759 : :
10760 : 0 : return I40E_SUCCESS;
10761 : : }
10762 : :
10763 : : /*
10764 : : * i40e_config_switch_comp_tc - Configure VEB tc setting for given TC map
10765 : : * @veb: VEB to be configured
10766 : : * @tc_map: enabled TC bitmap
10767 : : *
10768 : : * Returns 0 on success, negative value on failure
10769 : : */
10770 : : static enum i40e_status_code
10771 : 0 : i40e_config_switch_comp_tc(struct i40e_veb *veb, uint8_t tc_map)
10772 : : {
10773 : : struct i40e_aqc_configure_switching_comp_bw_config_data veb_bw;
10774 : : struct i40e_aqc_query_switching_comp_bw_config_resp bw_query;
10775 : : struct i40e_aqc_query_switching_comp_ets_config_resp ets_query;
10776 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(veb->associate_vsi);
10777 : : enum i40e_status_code ret = I40E_SUCCESS;
10778 : : int i;
10779 : : uint32_t bw_max;
10780 : :
10781 : : /* Check if enabled_tc is same as existing or new TCs */
10782 [ # # ]: 0 : if (veb->enabled_tc == tc_map)
10783 : : return ret;
10784 : :
10785 : : /* configure tc bandwidth */
10786 : : memset(&veb_bw, 0, sizeof(veb_bw));
10787 : 0 : veb_bw.tc_valid_bits = tc_map;
10788 : : /* Enable ETS TCs with equal BW Share for now across all VSIs */
10789 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10790 [ # # ]: 0 : if (tc_map & BIT_ULL(i))
10791 : 0 : veb_bw.tc_bw_share_credits[i] = 1;
10792 : : }
10793 : 0 : ret = i40e_aq_config_switch_comp_bw_config(hw, veb->seid,
10794 : : &veb_bw, NULL);
10795 [ # # ]: 0 : if (ret) {
10796 : 0 : PMD_INIT_LOG(ERR,
10797 : : "AQ command Config switch_comp BW allocation per TC failed = %d",
10798 : : hw->aq.asq_last_status);
10799 : 0 : return ret;
10800 : : }
10801 : :
10802 : : memset(&ets_query, 0, sizeof(ets_query));
10803 : 0 : ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
10804 : : &ets_query, NULL);
10805 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
10806 : 0 : PMD_DRV_LOG(ERR,
10807 : : "Failed to get switch_comp ETS configuration %u",
10808 : : hw->aq.asq_last_status);
10809 : 0 : return ret;
10810 : : }
10811 : : memset(&bw_query, 0, sizeof(bw_query));
10812 : 0 : ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
10813 : : &bw_query, NULL);
10814 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
10815 : 0 : PMD_DRV_LOG(ERR,
10816 : : "Failed to get switch_comp bandwidth configuration %u",
10817 : : hw->aq.asq_last_status);
10818 : 0 : return ret;
10819 : : }
10820 : :
10821 : : /* store and print out BW info */
10822 : 0 : veb->bw_info.bw_limit = rte_le_to_cpu_16(ets_query.port_bw_limit);
10823 : 0 : veb->bw_info.bw_max = ets_query.tc_bw_max;
10824 : 0 : PMD_DRV_LOG(DEBUG, "switch_comp bw limit:%u", veb->bw_info.bw_limit);
10825 : 0 : PMD_DRV_LOG(DEBUG, "switch_comp max_bw:%u", veb->bw_info.bw_max);
10826 : 0 : bw_max = rte_le_to_cpu_16(bw_query.tc_bw_max[0]) |
10827 : 0 : (rte_le_to_cpu_16(bw_query.tc_bw_max[1]) <<
10828 : : I40E_16_BIT_WIDTH);
10829 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10830 : 0 : veb->bw_info.bw_ets_share_credits[i] =
10831 : 0 : bw_query.tc_bw_share_credits[i];
10832 : 0 : veb->bw_info.bw_ets_credits[i] =
10833 : 0 : rte_le_to_cpu_16(bw_query.tc_bw_limits[i]);
10834 : : /* 4 bits per TC, 4th bit is reserved */
10835 : 0 : veb->bw_info.bw_ets_max[i] =
10836 : 0 : (uint8_t)((bw_max >> (i * I40E_4_BIT_WIDTH)) &
10837 : : RTE_LEN2MASK(3, uint8_t));
10838 : 0 : PMD_DRV_LOG(DEBUG, "\tVEB TC%u:share credits %u", i,
10839 : : veb->bw_info.bw_ets_share_credits[i]);
10840 : 0 : PMD_DRV_LOG(DEBUG, "\tVEB TC%u:credits %u", i,
10841 : : veb->bw_info.bw_ets_credits[i]);
10842 : 0 : PMD_DRV_LOG(DEBUG, "\tVEB TC%u: max credits: %u", i,
10843 : : veb->bw_info.bw_ets_max[i]);
10844 : : }
10845 : :
10846 : 0 : veb->enabled_tc = tc_map;
10847 : :
10848 : 0 : return ret;
10849 : : }
10850 : :
10851 : :
10852 : : /*
10853 : : * i40e_vsi_config_tc - Configure VSI tc setting for given TC map
10854 : : * @vsi: VSI to be configured
10855 : : * @tc_map: enabled TC bitmap
10856 : : *
10857 : : * Returns 0 on success, negative value on failure
10858 : : */
10859 : : static enum i40e_status_code
10860 : 0 : i40e_vsi_config_tc(struct i40e_vsi *vsi, uint8_t tc_map)
10861 : : {
10862 : : struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
10863 : : struct i40e_vsi_context ctxt;
10864 : 0 : struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
10865 : : enum i40e_status_code ret = I40E_SUCCESS;
10866 : : int i;
10867 : :
10868 : : /* Check if enabled_tc is same as existing or new TCs */
10869 [ # # ]: 0 : if (vsi->enabled_tc == tc_map)
10870 : : return ret;
10871 : :
10872 : : /* configure tc bandwidth */
10873 : : memset(&bw_data, 0, sizeof(bw_data));
10874 : 0 : bw_data.tc_valid_bits = tc_map;
10875 : : /* Enable ETS TCs with equal BW Share for now across all VSIs */
10876 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
10877 [ # # ]: 0 : if (tc_map & BIT_ULL(i))
10878 : 0 : bw_data.tc_bw_credits[i] = 1;
10879 : : }
10880 : 0 : ret = i40e_aq_config_vsi_tc_bw(hw, vsi->seid, &bw_data, NULL);
10881 [ # # ]: 0 : if (ret) {
10882 : 0 : PMD_INIT_LOG(ERR,
10883 : : "AQ command Config VSI BW allocation per TC failed = %d",
10884 : : hw->aq.asq_last_status);
10885 : 0 : goto out;
10886 : : }
10887 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
10888 : 0 : vsi->info.qs_handle[i] = bw_data.qs_handles[i];
10889 : :
10890 : : /* Update Queue Pairs Mapping for currently enabled UPs */
10891 : 0 : ctxt.seid = vsi->seid;
10892 : 0 : ctxt.pf_num = hw->pf_id;
10893 : 0 : ctxt.vf_num = 0;
10894 : 0 : ctxt.uplink_seid = vsi->uplink_seid;
10895 : 0 : ctxt.info = vsi->info;
10896 : 0 : i40e_get_cap(hw);
10897 : 0 : ret = i40e_vsi_update_queue_mapping(vsi, &ctxt.info, tc_map);
10898 [ # # ]: 0 : if (ret)
10899 : 0 : goto out;
10900 : :
10901 : : /* Update the VSI after updating the VSI queue-mapping information */
10902 : 0 : ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
10903 [ # # ]: 0 : if (ret) {
10904 : 0 : PMD_INIT_LOG(ERR, "Failed to configure TC queue mapping = %d",
10905 : : hw->aq.asq_last_status);
10906 : 0 : goto out;
10907 : : }
10908 : : /* update the local VSI info with updated queue map */
10909 : 0 : memcpy(&vsi->info.tc_mapping, &ctxt.info.tc_mapping,
10910 : : sizeof(vsi->info.tc_mapping));
10911 : 0 : memcpy(&vsi->info.queue_mapping,
10912 : : &ctxt.info.queue_mapping,
10913 : : sizeof(vsi->info.queue_mapping));
10914 : 0 : vsi->info.mapping_flags = ctxt.info.mapping_flags;
10915 : 0 : vsi->info.valid_sections = 0;
10916 : :
10917 : : /* query and update current VSI BW information */
10918 : 0 : ret = i40e_vsi_get_bw_config(vsi);
10919 [ # # ]: 0 : if (ret) {
10920 : 0 : PMD_INIT_LOG(ERR,
10921 : : "Failed updating vsi bw info, err %s aq_err %s",
10922 : : i40e_stat_str(hw, ret),
10923 : : i40e_aq_str(hw, hw->aq.asq_last_status));
10924 : 0 : goto out;
10925 : : }
10926 : :
10927 : 0 : vsi->enabled_tc = tc_map;
10928 : :
10929 : : out:
10930 : : return ret;
10931 : : }
10932 : :
10933 : : /*
10934 : : * i40e_dcb_hw_configure - program the dcb setting to hw
10935 : : * @pf: pf the configuration is taken on
10936 : : * @new_cfg: new configuration
10937 : : * @tc_map: enabled TC bitmap
10938 : : *
10939 : : * Returns 0 on success, negative value on failure
10940 : : */
10941 : : static enum i40e_status_code
10942 : 0 : i40e_dcb_hw_configure(struct i40e_pf *pf,
10943 : : struct i40e_dcbx_config *new_cfg,
10944 : : uint8_t tc_map)
10945 : : {
10946 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
10947 : 0 : struct i40e_dcbx_config *old_cfg = &hw->local_dcbx_config;
10948 : 0 : struct i40e_vsi *main_vsi = pf->main_vsi;
10949 : : struct i40e_vsi_list *vsi_list;
10950 : : enum i40e_status_code ret;
10951 : : int i;
10952 : : uint32_t val;
10953 : :
10954 : : /* Use the FW API if FW > v4.4*/
10955 [ # # # # : 0 : if (!(((hw->aq.fw_maj_ver == 4) && (hw->aq.fw_min_ver >= 4)) ||
# # ]
10956 : : (hw->aq.fw_maj_ver >= 5))) {
10957 : 0 : PMD_INIT_LOG(ERR,
10958 : : "FW < v4.4, can not use FW LLDP API to configure DCB");
10959 : 0 : return I40E_ERR_FIRMWARE_API_VERSION;
10960 : : }
10961 : :
10962 : : /* Check if need reconfiguration */
10963 [ # # ]: 0 : if (!memcmp(new_cfg, old_cfg, sizeof(struct i40e_dcbx_config))) {
10964 : 0 : PMD_INIT_LOG(ERR, "No Change in DCB Config required.");
10965 : 0 : return I40E_SUCCESS;
10966 : : }
10967 : :
10968 : : /* Copy the new config to the current config */
10969 : 0 : *old_cfg = *new_cfg;
10970 : 0 : old_cfg->etsrec = old_cfg->etscfg;
10971 : 0 : ret = i40e_set_dcb_config(hw);
10972 [ # # ]: 0 : if (ret) {
10973 : 0 : PMD_INIT_LOG(ERR, "Set DCB Config failed, err %s aq_err %s",
10974 : : i40e_stat_str(hw, ret),
10975 : : i40e_aq_str(hw, hw->aq.asq_last_status));
10976 : 0 : return ret;
10977 : : }
10978 : : /* set receive Arbiter to RR mode and ETS scheme by default */
10979 [ # # ]: 0 : for (i = 0; i <= I40E_PRTDCB_RETSTCC_MAX_INDEX; i++) {
10980 : 0 : val = I40E_READ_REG(hw, I40E_PRTDCB_RETSTCC(i));
10981 : 0 : val &= ~(I40E_PRTDCB_RETSTCC_BWSHARE_MASK |
10982 : : I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK |
10983 : : I40E_PRTDCB_RETSTCC_ETSTC_SHIFT);
10984 : 0 : val |= ((uint32_t)old_cfg->etscfg.tcbwtable[i] <<
10985 : 0 : I40E_PRTDCB_RETSTCC_BWSHARE_SHIFT) &
10986 : : I40E_PRTDCB_RETSTCC_BWSHARE_MASK;
10987 : : val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_UPINTC_MODE_SHIFT) &
10988 : : I40E_PRTDCB_RETSTCC_UPINTC_MODE_MASK;
10989 : 0 : val |= ((uint32_t)1 << I40E_PRTDCB_RETSTCC_ETSTC_SHIFT) &
10990 : : I40E_PRTDCB_RETSTCC_ETSTC_MASK;
10991 : 0 : I40E_WRITE_REG(hw, I40E_PRTDCB_RETSTCC(i), val);
10992 : : }
10993 : : /* get local mib to check whether it is configured correctly */
10994 : : /* IEEE mode */
10995 : 0 : hw->local_dcbx_config.dcbx_mode = I40E_DCBX_MODE_IEEE;
10996 : : /* Get Local DCB Config */
10997 : 0 : i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_LOCAL, 0,
10998 : : &hw->local_dcbx_config);
10999 : :
11000 : : /* if Veb is created, need to update TC of it at first */
11001 [ # # ]: 0 : if (main_vsi->veb) {
11002 : 0 : ret = i40e_config_switch_comp_tc(main_vsi->veb, tc_map);
11003 [ # # ]: 0 : if (ret)
11004 : 0 : PMD_INIT_LOG(WARNING,
11005 : : "Failed configuring TC for VEB seid=%d",
11006 : : main_vsi->veb->seid);
11007 : : }
11008 : : /* Update each VSI */
11009 : 0 : i40e_vsi_config_tc(main_vsi, tc_map);
11010 [ # # ]: 0 : if (main_vsi->veb) {
11011 [ # # ]: 0 : TAILQ_FOREACH(vsi_list, &main_vsi->veb->head, list) {
11012 : : /* Beside main VSI and VMDQ VSIs, only enable default
11013 : : * TC for other VSIs
11014 : : */
11015 [ # # ]: 0 : if (vsi_list->vsi->type == I40E_VSI_VMDQ2)
11016 : 0 : ret = i40e_vsi_config_tc(vsi_list->vsi,
11017 : : tc_map);
11018 : : else
11019 : 0 : ret = i40e_vsi_config_tc(vsi_list->vsi,
11020 : : I40E_DEFAULT_TCMAP);
11021 [ # # ]: 0 : if (ret)
11022 : 0 : PMD_INIT_LOG(WARNING,
11023 : : "Failed configuring TC for VSI seid=%d",
11024 : : vsi_list->vsi->seid);
11025 : : /* continue */
11026 : : }
11027 : : }
11028 : : return I40E_SUCCESS;
11029 : : }
11030 : :
11031 : : /*
11032 : : * i40e_dcb_init_configure - initial dcb config
11033 : : * @dev: device being configured
11034 : : * @sw_dcb: indicate whether dcb is sw configured or hw offload
11035 : : *
11036 : : * Returns 0 on success, negative value on failure
11037 : : */
11038 : : int
11039 : 0 : i40e_dcb_init_configure(struct rte_eth_dev *dev, bool sw_dcb)
11040 : : {
11041 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11042 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11043 : : int i, ret = 0;
11044 : :
11045 [ # # ]: 0 : if ((pf->flags & I40E_FLAG_DCB) == 0) {
11046 : 0 : PMD_INIT_LOG(ERR, "HW doesn't support DCB");
11047 : 0 : return -ENOTSUP;
11048 : : }
11049 : :
11050 : : /* DCB initialization:
11051 : : * Update DCB configuration from the Firmware and configure
11052 : : * LLDP MIB change event.
11053 : : */
11054 [ # # ]: 0 : if (sw_dcb == TRUE) {
11055 : : /* Stopping lldp is necessary for DPDK, but it will cause
11056 : : * DCB init failed. For i40e_init_dcb(), the prerequisite
11057 : : * for successful initialization of DCB is that LLDP is
11058 : : * enabled. So it is needed to start lldp before DCB init
11059 : : * and stop it after initialization.
11060 : : */
11061 : 0 : ret = i40e_aq_start_lldp(hw, true, NULL);
11062 [ # # ]: 0 : if (ret != I40E_SUCCESS)
11063 : 0 : PMD_INIT_LOG(DEBUG, "Failed to start lldp");
11064 : :
11065 : 0 : ret = i40e_init_dcb(hw, true);
11066 : : /* If lldp agent is stopped, the return value from
11067 : : * i40e_init_dcb we expect is failure with I40E_AQ_RC_EPERM
11068 : : * adminq status. Otherwise, it should return success.
11069 : : */
11070 [ # # ]: 0 : if ((ret == I40E_SUCCESS) || (ret != I40E_SUCCESS &&
11071 [ # # ]: 0 : hw->aq.asq_last_status == I40E_AQ_RC_EPERM)) {
11072 : 0 : memset(&hw->local_dcbx_config, 0,
11073 : : sizeof(struct i40e_dcbx_config));
11074 : : /* set dcb default configuration */
11075 : : hw->local_dcbx_config.etscfg.willing = 0;
11076 : : hw->local_dcbx_config.etscfg.maxtcs = 0;
11077 : 0 : hw->local_dcbx_config.etscfg.tcbwtable[0] = 100;
11078 : 0 : hw->local_dcbx_config.etscfg.tsatable[0] =
11079 : : I40E_IEEE_TSA_ETS;
11080 : : /* all UPs mapping to TC0 */
11081 [ # # ]: 0 : for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
11082 : 0 : hw->local_dcbx_config.etscfg.prioritytable[i] = 0;
11083 : 0 : hw->local_dcbx_config.etsrec =
11084 : : hw->local_dcbx_config.etscfg;
11085 : : hw->local_dcbx_config.pfc.willing = 0;
11086 : 0 : hw->local_dcbx_config.pfc.pfccap =
11087 : : I40E_MAX_TRAFFIC_CLASS;
11088 : : /* FW needs one App to configure HW */
11089 : 0 : hw->local_dcbx_config.numapps = 1;
11090 : 0 : hw->local_dcbx_config.app[0].selector =
11091 : : I40E_APP_SEL_ETHTYPE;
11092 : 0 : hw->local_dcbx_config.app[0].priority = 3;
11093 : 0 : hw->local_dcbx_config.app[0].protocolid =
11094 : : I40E_APP_PROTOID_FCOE;
11095 : 0 : ret = i40e_set_dcb_config(hw);
11096 [ # # ]: 0 : if (ret) {
11097 : 0 : PMD_INIT_LOG(ERR,
11098 : : "default dcb config fails. err = %d, aq_err = %d.",
11099 : : ret, hw->aq.asq_last_status);
11100 : 0 : return -ENOSYS;
11101 : : }
11102 : : } else {
11103 : 0 : PMD_INIT_LOG(ERR,
11104 : : "DCB initialization in FW fails, err = %d, aq_err = %d.",
11105 : : ret, hw->aq.asq_last_status);
11106 : 0 : return -ENOTSUP;
11107 : : }
11108 : :
11109 [ # # ]: 0 : if (i40e_need_stop_lldp(dev)) {
11110 : 0 : ret = i40e_aq_stop_lldp(hw, true, true, NULL);
11111 [ # # ]: 0 : if (ret != I40E_SUCCESS)
11112 : 0 : PMD_INIT_LOG(DEBUG, "Failed to stop lldp");
11113 : : }
11114 : : } else {
11115 : 0 : ret = i40e_aq_start_lldp(hw, true, NULL);
11116 [ # # ]: 0 : if (ret != I40E_SUCCESS)
11117 : 0 : PMD_INIT_LOG(DEBUG, "Failed to start lldp");
11118 : :
11119 : 0 : ret = i40e_init_dcb(hw, true);
11120 [ # # ]: 0 : if (!ret) {
11121 [ # # ]: 0 : if (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED) {
11122 : 0 : PMD_INIT_LOG(ERR,
11123 : : "HW doesn't support DCBX offload.");
11124 : 0 : return -ENOTSUP;
11125 : : }
11126 : : } else {
11127 : 0 : PMD_INIT_LOG(ERR,
11128 : : "DCBX configuration failed, err = %d, aq_err = %d.",
11129 : : ret, hw->aq.asq_last_status);
11130 : 0 : return -ENOTSUP;
11131 : : }
11132 : : }
11133 : : return 0;
11134 : : }
11135 : :
11136 : : /*
11137 : : * i40e_dcb_setup - setup dcb related config
11138 : : * @dev: device being configured
11139 : : *
11140 : : * Returns 0 on success, negative value on failure
11141 : : */
11142 : : static int
11143 : 0 : i40e_dcb_setup(struct rte_eth_dev *dev)
11144 : : {
11145 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11146 : : struct i40e_dcbx_config dcb_cfg;
11147 : 0 : uint8_t tc_map = 0;
11148 : : int ret = 0;
11149 : :
11150 [ # # ]: 0 : if ((pf->flags & I40E_FLAG_DCB) == 0) {
11151 : 0 : PMD_INIT_LOG(ERR, "HW doesn't support DCB");
11152 : 0 : return -ENOTSUP;
11153 : : }
11154 : :
11155 [ # # ]: 0 : if (pf->vf_num != 0)
11156 : 0 : PMD_INIT_LOG(DEBUG, " DCB only works on pf and vmdq vsis.");
11157 : :
11158 : 0 : ret = i40e_parse_dcb_configure(dev, &dcb_cfg, &tc_map);
11159 [ # # ]: 0 : if (ret) {
11160 : 0 : PMD_INIT_LOG(ERR, "invalid dcb config");
11161 : 0 : return -EINVAL;
11162 : : }
11163 : 0 : ret = i40e_dcb_hw_configure(pf, &dcb_cfg, tc_map);
11164 [ # # ]: 0 : if (ret) {
11165 : 0 : PMD_INIT_LOG(ERR, "dcb sw configure fails");
11166 : 0 : return -ENOSYS;
11167 : : }
11168 : :
11169 : : return 0;
11170 : : }
11171 : :
11172 : : static int
11173 : 0 : i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
11174 : : struct rte_eth_dcb_info *dcb_info)
11175 : : {
11176 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11177 : : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11178 : 0 : struct i40e_vsi *vsi = pf->main_vsi;
11179 : : struct i40e_dcbx_config *dcb_cfg = &hw->local_dcbx_config;
11180 : : uint16_t bsf, tc_mapping;
11181 : : int i, j = 0;
11182 : :
11183 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_DCB_FLAG)
11184 : 0 : dcb_info->nb_tcs = rte_bsf32(vsi->enabled_tc + 1);
11185 : : else
11186 : 0 : dcb_info->nb_tcs = 1;
11187 [ # # ]: 0 : for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
11188 : 0 : dcb_info->prio_tc[i] = dcb_cfg->etscfg.prioritytable[i];
11189 [ # # ]: 0 : for (i = 0; i < dcb_info->nb_tcs; i++)
11190 : 0 : dcb_info->tc_bws[i] = dcb_cfg->etscfg.tcbwtable[i];
11191 : :
11192 : : /* get queue mapping if vmdq is disabled */
11193 [ # # ]: 0 : if (!pf->nb_cfg_vmdq_vsi) {
11194 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11195 [ # # ]: 0 : if (!(vsi->enabled_tc & (1 << i)))
11196 : 0 : continue;
11197 : 0 : tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
11198 : 0 : dcb_info->tc_queue.tc_rxq[j][i].base =
11199 : 0 : (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
11200 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
11201 : 0 : dcb_info->tc_queue.tc_txq[j][i].base =
11202 : : dcb_info->tc_queue.tc_rxq[j][i].base;
11203 : 0 : bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
11204 : : I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
11205 : 0 : dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
11206 : 0 : dcb_info->tc_queue.tc_txq[j][i].nb_queue =
11207 : : dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
11208 : : }
11209 : : return 0;
11210 : : }
11211 : :
11212 : : /* get queue mapping if vmdq is enabled */
11213 : : do {
11214 : 0 : vsi = pf->vmdq[j].vsi;
11215 [ # # ]: 0 : for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
11216 [ # # ]: 0 : if (!(vsi->enabled_tc & (1 << i)))
11217 : 0 : continue;
11218 : 0 : tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
11219 : 0 : dcb_info->tc_queue.tc_rxq[j][i].base =
11220 : 0 : (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
11221 : : I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
11222 : 0 : dcb_info->tc_queue.tc_txq[j][i].base =
11223 : : dcb_info->tc_queue.tc_rxq[j][i].base;
11224 : 0 : bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
11225 : : I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
11226 : 0 : dcb_info->tc_queue.tc_rxq[j][i].nb_queue = 1 << bsf;
11227 : 0 : dcb_info->tc_queue.tc_txq[j][i].nb_queue =
11228 : : dcb_info->tc_queue.tc_rxq[j][i].nb_queue;
11229 : : }
11230 : 0 : j++;
11231 [ # # ]: 0 : } while (j < RTE_MIN(pf->nb_cfg_vmdq_vsi, RTE_ETH_MAX_VMDQ_POOL));
11232 : : return 0;
11233 : : }
11234 : :
11235 : : static int
11236 : 0 : i40e_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
11237 : : {
11238 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
11239 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
11240 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11241 : : uint16_t msix_intr;
11242 : :
11243 : 0 : msix_intr = rte_intr_vec_list_index_get(intr_handle, queue_id);
11244 [ # # ]: 0 : if (msix_intr == I40E_MISC_VEC_ID)
11245 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
11246 : : I40E_PFINT_DYN_CTL0_INTENA_MASK |
11247 : : I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
11248 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
11249 : : else
11250 : 0 : I40E_WRITE_REG(hw,
11251 : : I40E_PFINT_DYN_CTLN(msix_intr -
11252 : : I40E_RX_VEC_START),
11253 : : I40E_PFINT_DYN_CTLN_INTENA_MASK |
11254 : : I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
11255 : : I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
11256 : :
11257 : 0 : I40E_WRITE_FLUSH(hw);
11258 : 0 : rte_intr_ack(pci_dev->intr_handle);
11259 : :
11260 : 0 : return 0;
11261 : : }
11262 : :
11263 : : static int
11264 : 0 : i40e_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
11265 : : {
11266 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
11267 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
11268 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11269 : : uint16_t msix_intr;
11270 : :
11271 : 0 : msix_intr = rte_intr_vec_list_index_get(intr_handle, queue_id);
11272 [ # # ]: 0 : if (msix_intr == I40E_MISC_VEC_ID)
11273 : 0 : I40E_WRITE_REG(hw, I40E_PFINT_DYN_CTL0,
11274 : : I40E_PFINT_DYN_CTL0_ITR_INDX_MASK);
11275 : : else
11276 : 0 : I40E_WRITE_REG(hw,
11277 : : I40E_PFINT_DYN_CTLN(msix_intr -
11278 : : I40E_RX_VEC_START),
11279 : : I40E_PFINT_DYN_CTLN_ITR_INDX_MASK);
11280 : 0 : I40E_WRITE_FLUSH(hw);
11281 : :
11282 : 0 : return 0;
11283 : : }
11284 : :
11285 : : /**
11286 : : * This function is used to check if the register is valid.
11287 : : * Below is the valid registers list for X722 only:
11288 : : * 0x2b800--0x2bb00
11289 : : * 0x38700--0x38a00
11290 : : * 0x3d800--0x3db00
11291 : : * 0x208e00--0x209000
11292 : : * 0x20be00--0x20c000
11293 : : * 0x263c00--0x264000
11294 : : * 0x265c00--0x266000
11295 : : */
11296 : 0 : static inline int i40e_valid_regs(enum i40e_mac_type type, uint32_t reg_offset)
11297 : : {
11298 [ # # ]: 0 : if ((type != I40E_MAC_X722) &&
11299 : 0 : ((reg_offset >= 0x2b800 && reg_offset <= 0x2bb00) ||
11300 [ # # ]: 0 : (reg_offset >= 0x38700 && reg_offset <= 0x38a00) ||
11301 [ # # ]: 0 : (reg_offset >= 0x3d800 && reg_offset <= 0x3db00) ||
11302 [ # # ]: 0 : (reg_offset >= 0x208e00 && reg_offset <= 0x209000) ||
11303 [ # # ]: 0 : (reg_offset >= 0x20be00 && reg_offset <= 0x20c000) ||
11304 [ # # ]: 0 : (reg_offset >= 0x263c00 && reg_offset <= 0x264000) ||
11305 [ # # ]: 0 : (reg_offset >= 0x265c00 && reg_offset <= 0x266000)))
11306 : : return 0;
11307 : : else
11308 : 0 : return 1;
11309 : : }
11310 : :
11311 : 0 : static int i40e_get_regs(struct rte_eth_dev *dev,
11312 : : struct rte_dev_reg_info *regs)
11313 : : {
11314 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11315 : 0 : uint32_t *ptr_data = regs->data;
11316 : : uint32_t reg_idx, arr_idx, arr_idx2, reg_offset;
11317 : : const struct i40e_reg_info *reg_info;
11318 : :
11319 [ # # ]: 0 : if (ptr_data == NULL) {
11320 : 0 : regs->length = I40E_GLGEN_STAT_CLEAR + 4;
11321 : 0 : regs->width = sizeof(uint32_t);
11322 : 0 : return 0;
11323 : : }
11324 : :
11325 : : /* The first few registers have to be read using AQ operations */
11326 : : reg_idx = 0;
11327 [ # # ]: 0 : while (i40e_regs_adminq[reg_idx].name) {
11328 : 0 : reg_info = &i40e_regs_adminq[reg_idx++];
11329 [ # # ]: 0 : for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
11330 : : for (arr_idx2 = 0;
11331 [ # # ]: 0 : arr_idx2 <= reg_info->count2;
11332 : 0 : arr_idx2++) {
11333 : 0 : reg_offset = arr_idx * reg_info->stride1 +
11334 : 0 : arr_idx2 * reg_info->stride2;
11335 : 0 : reg_offset += reg_info->base_addr;
11336 : 0 : ptr_data[reg_offset >> 2] =
11337 : 0 : i40e_read_rx_ctl(hw, reg_offset);
11338 : : }
11339 : : }
11340 : :
11341 : : /* The remaining registers can be read using primitives */
11342 : : reg_idx = 0;
11343 [ # # ]: 0 : while (i40e_regs_others[reg_idx].name) {
11344 : 0 : reg_info = &i40e_regs_others[reg_idx++];
11345 [ # # ]: 0 : for (arr_idx = 0; arr_idx <= reg_info->count1; arr_idx++)
11346 : : for (arr_idx2 = 0;
11347 [ # # ]: 0 : arr_idx2 <= reg_info->count2;
11348 : 0 : arr_idx2++) {
11349 : 0 : reg_offset = arr_idx * reg_info->stride1 +
11350 : 0 : arr_idx2 * reg_info->stride2;
11351 : 0 : reg_offset += reg_info->base_addr;
11352 [ # # ]: 0 : if (!i40e_valid_regs(hw->mac.type, reg_offset))
11353 : 0 : ptr_data[reg_offset >> 2] = 0;
11354 : : else
11355 : 0 : ptr_data[reg_offset >> 2] =
11356 : 0 : I40E_READ_REG(hw, reg_offset);
11357 : : }
11358 : : }
11359 : :
11360 : : return 0;
11361 : : }
11362 : :
11363 : 0 : static int i40e_get_eeprom_length(struct rte_eth_dev *dev)
11364 : : {
11365 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11366 : :
11367 : : /* Convert word count to byte count */
11368 : 0 : return hw->nvm.sr_size << 1;
11369 : : }
11370 : :
11371 : 0 : static int i40e_get_eeprom(struct rte_eth_dev *dev,
11372 : : struct rte_dev_eeprom_info *eeprom)
11373 : : {
11374 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11375 : 0 : uint16_t *data = eeprom->data;
11376 : : uint32_t offset, length;
11377 : : uint16_t cnt_words;
11378 : : int ret_code;
11379 : :
11380 : 0 : offset = eeprom->offset >> 1;
11381 : 0 : length = eeprom->length >> 1;
11382 : 0 : cnt_words = length;
11383 : :
11384 [ # # ]: 0 : if (offset > hw->nvm.sr_size ||
11385 [ # # ]: 0 : offset + length > hw->nvm.sr_size) {
11386 : 0 : PMD_DRV_LOG(ERR, "Requested EEPROM bytes out of range.");
11387 : 0 : return -EINVAL;
11388 : : }
11389 : :
11390 : 0 : eeprom->magic = hw->vendor_id | (hw->device_id << 16);
11391 : :
11392 : 0 : ret_code = i40e_read_nvm_buffer(hw, offset, &cnt_words, data);
11393 [ # # # # ]: 0 : if (ret_code != I40E_SUCCESS || cnt_words != length) {
11394 : 0 : PMD_DRV_LOG(ERR, "EEPROM read failed.");
11395 : 0 : return -EIO;
11396 : : }
11397 : :
11398 : : return 0;
11399 : : }
11400 : :
11401 : 0 : static int i40e_get_module_info(struct rte_eth_dev *dev,
11402 : : struct rte_eth_dev_module_info *modinfo)
11403 : : {
11404 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11405 : 0 : uint32_t sff8472_comp = 0;
11406 : 0 : uint32_t sff8472_swap = 0;
11407 : 0 : uint32_t sff8636_rev = 0;
11408 : : i40e_status status;
11409 : : uint32_t type = 0;
11410 : :
11411 : : /* Check if firmware supports reading module EEPROM. */
11412 [ # # ]: 0 : if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
11413 : 0 : PMD_DRV_LOG(ERR,
11414 : : "Module EEPROM memory read not supported. "
11415 : : "Please update the NVM image.");
11416 : 0 : return -EINVAL;
11417 : : }
11418 : :
11419 : 0 : status = i40e_update_link_info(hw);
11420 [ # # ]: 0 : if (status)
11421 : : return -EIO;
11422 : :
11423 [ # # ]: 0 : if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
11424 : 0 : PMD_DRV_LOG(ERR,
11425 : : "Cannot read module EEPROM memory. "
11426 : : "No module connected.");
11427 : 0 : return -EINVAL;
11428 : : }
11429 : :
11430 : 0 : type = hw->phy.link_info.module_type[0];
11431 : :
11432 [ # # # # ]: 0 : switch (type) {
11433 : 0 : case I40E_MODULE_TYPE_SFP:
11434 : 0 : status = i40e_aq_get_phy_register(hw,
11435 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11436 : : I40E_I2C_EEPROM_DEV_ADDR, 1,
11437 : : I40E_MODULE_SFF_8472_COMP,
11438 : : &sff8472_comp, NULL);
11439 [ # # ]: 0 : if (status)
11440 : : return -EIO;
11441 : :
11442 : 0 : status = i40e_aq_get_phy_register(hw,
11443 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11444 : : I40E_I2C_EEPROM_DEV_ADDR, 1,
11445 : : I40E_MODULE_SFF_8472_SWAP,
11446 : : &sff8472_swap, NULL);
11447 [ # # ]: 0 : if (status)
11448 : : return -EIO;
11449 : :
11450 : : /* Check if the module requires address swap to access
11451 : : * the other EEPROM memory page.
11452 : : */
11453 [ # # ]: 0 : if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
11454 : 0 : PMD_DRV_LOG(WARNING,
11455 : : "Module address swap to access "
11456 : : "page 0xA2 is not supported.");
11457 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8079;
11458 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
11459 [ # # ]: 0 : } else if (sff8472_comp == 0x00) {
11460 : : /* Module is not SFF-8472 compliant */
11461 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8079;
11462 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
11463 : : } else {
11464 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8472;
11465 : 0 : modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8472_LEN;
11466 : : }
11467 : : break;
11468 : 0 : case I40E_MODULE_TYPE_QSFP_PLUS:
11469 : : /* Read from memory page 0. */
11470 : 0 : status = i40e_aq_get_phy_register(hw,
11471 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11472 : : 0, 1,
11473 : : I40E_MODULE_REVISION_ADDR,
11474 : : &sff8636_rev, NULL);
11475 [ # # ]: 0 : if (status)
11476 : : return -EIO;
11477 : : /* Determine revision compliance byte */
11478 [ # # ]: 0 : if (sff8636_rev > 0x02) {
11479 : : /* Module is SFF-8636 compliant */
11480 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8636;
11481 : 0 : modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
11482 : : } else {
11483 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8436;
11484 : 0 : modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
11485 : : }
11486 : : break;
11487 : 0 : case I40E_MODULE_TYPE_QSFP28:
11488 : 0 : modinfo->type = RTE_ETH_MODULE_SFF_8636;
11489 : 0 : modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
11490 : 0 : break;
11491 : 0 : default:
11492 : 0 : PMD_DRV_LOG(ERR, "Module type unrecognized");
11493 : 0 : return -EINVAL;
11494 : : }
11495 : : return 0;
11496 : : }
11497 : :
11498 : 0 : static int i40e_get_module_eeprom(struct rte_eth_dev *dev,
11499 : : struct rte_dev_eeprom_info *info)
11500 : : {
11501 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11502 : : bool is_sfp = false;
11503 : : i40e_status status;
11504 : : uint8_t *data;
11505 : 0 : uint32_t value = 0;
11506 : : uint32_t i;
11507 : :
11508 [ # # ]: 0 : if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
11509 : : is_sfp = true;
11510 : :
11511 : 0 : data = info->data;
11512 [ # # ]: 0 : for (i = 0; i < info->length; i++) {
11513 : 0 : u32 offset = i + info->offset;
11514 [ # # ]: 0 : u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
11515 : :
11516 : : /* Check if we need to access the other memory page */
11517 [ # # ]: 0 : if (is_sfp) {
11518 [ # # ]: 0 : if (offset >= RTE_ETH_MODULE_SFF_8079_LEN) {
11519 : 0 : offset -= RTE_ETH_MODULE_SFF_8079_LEN;
11520 : : addr = I40E_I2C_EEPROM_DEV_ADDR2;
11521 : : }
11522 : : } else {
11523 [ # # ]: 0 : while (offset >= RTE_ETH_MODULE_SFF_8436_LEN) {
11524 : : /* Compute memory page number and offset. */
11525 : 0 : offset -= RTE_ETH_MODULE_SFF_8436_LEN / 2;
11526 : 0 : addr++;
11527 : : }
11528 : : }
11529 : 0 : status = i40e_aq_get_phy_register(hw,
11530 : : I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
11531 : : addr, 1, offset, &value, NULL);
11532 [ # # ]: 0 : if (status)
11533 : : return -EIO;
11534 : 0 : data[i] = (uint8_t)value;
11535 : : }
11536 : : return 0;
11537 : : }
11538 : :
11539 : 0 : static int i40e_set_default_mac_addr(struct rte_eth_dev *dev,
11540 : : struct rte_ether_addr *mac_addr)
11541 : : {
11542 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
11543 : : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11544 [ # # ]: 0 : struct i40e_vsi *vsi = pf->main_vsi;
11545 : : struct i40e_mac_filter_info mac_filter;
11546 : : struct i40e_mac_filter *f;
11547 : : int ret;
11548 : :
11549 : : if (!rte_is_valid_assigned_ether_addr(mac_addr)) {
11550 : 0 : PMD_DRV_LOG(ERR, "Tried to set invalid MAC address.");
11551 : 0 : return -EINVAL;
11552 : : }
11553 : :
11554 [ # # ]: 0 : TAILQ_FOREACH(f, &vsi->mac_list, next) {
11555 [ # # ]: 0 : if (rte_is_same_ether_addr(&pf->dev_addr,
11556 : : &f->mac_info.mac_addr))
11557 : : break;
11558 : : }
11559 : :
11560 [ # # ]: 0 : if (f == NULL) {
11561 : 0 : PMD_DRV_LOG(ERR, "Failed to find filter for default mac");
11562 : 0 : return -EIO;
11563 : : }
11564 : :
11565 : 0 : mac_filter = f->mac_info;
11566 : 0 : ret = i40e_vsi_delete_mac(vsi, &mac_filter.mac_addr);
11567 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
11568 : 0 : PMD_DRV_LOG(ERR, "Failed to delete mac filter");
11569 : 0 : return -EIO;
11570 : : }
11571 : : memcpy(&mac_filter.mac_addr, mac_addr, ETH_ADDR_LEN);
11572 : 0 : ret = i40e_vsi_add_mac(vsi, &mac_filter);
11573 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
11574 : 0 : PMD_DRV_LOG(ERR, "Failed to add mac filter");
11575 : 0 : return -EIO;
11576 : : }
11577 : 0 : memcpy(&pf->dev_addr, mac_addr, ETH_ADDR_LEN);
11578 : :
11579 : 0 : ret = i40e_aq_mac_address_write(hw, I40E_AQC_WRITE_TYPE_LAA_WOL,
11580 : 0 : mac_addr->addr_bytes, NULL);
11581 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
11582 : 0 : PMD_DRV_LOG(ERR, "Failed to change mac");
11583 : 0 : return -EIO;
11584 : : }
11585 : :
11586 : : return 0;
11587 : : }
11588 : :
11589 : : static int
11590 : 0 : i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu __rte_unused)
11591 : : {
11592 : : /* mtu setting is forbidden if port is start */
11593 [ # # ]: 0 : if (dev->data->dev_started != 0) {
11594 : 0 : PMD_DRV_LOG(ERR, "port %d must be stopped before configuration",
11595 : : dev->data->port_id);
11596 : 0 : return -EBUSY;
11597 : : }
11598 : :
11599 : : return 0;
11600 : : }
11601 : :
11602 : : /* Restore ethertype filter */
11603 : : static void
11604 : 0 : i40e_ethertype_filter_restore(struct i40e_pf *pf)
11605 : : {
11606 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11607 : : struct i40e_ethertype_filter_list
11608 : : *ethertype_list = &pf->ethertype.ethertype_list;
11609 : : struct i40e_ethertype_filter *f;
11610 : : struct i40e_control_filter_stats stats;
11611 : : uint16_t flags;
11612 : :
11613 [ # # ]: 0 : TAILQ_FOREACH(f, ethertype_list, rules) {
11614 : : flags = 0;
11615 [ # # ]: 0 : if (!(f->flags & RTE_ETHTYPE_FLAGS_MAC))
11616 : : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_IGNORE_MAC;
11617 [ # # ]: 0 : if (f->flags & RTE_ETHTYPE_FLAGS_DROP)
11618 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_DROP;
11619 : 0 : flags |= I40E_AQC_ADD_CONTROL_PACKET_FLAGS_TO_QUEUE;
11620 : :
11621 : : memset(&stats, 0, sizeof(stats));
11622 : 0 : i40e_aq_add_rem_control_packet_filter(hw,
11623 : 0 : f->input.mac_addr.addr_bytes,
11624 : 0 : f->input.ether_type,
11625 : 0 : flags, pf->main_vsi->seid,
11626 : 0 : f->queue, 1, &stats, NULL);
11627 : : }
11628 : 0 : PMD_DRV_LOG(INFO, "Ethertype filter:"
11629 : : " mac_etype_used = %u, etype_used = %u,"
11630 : : " mac_etype_free = %u, etype_free = %u",
11631 : : stats.mac_etype_used, stats.etype_used,
11632 : : stats.mac_etype_free, stats.etype_free);
11633 : 0 : }
11634 : :
11635 : : /* Restore tunnel filter */
11636 : : static void
11637 : 0 : i40e_tunnel_filter_restore(struct i40e_pf *pf)
11638 : : {
11639 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
11640 : : struct i40e_vsi *vsi;
11641 : : struct i40e_pf_vf *vf;
11642 : : struct i40e_tunnel_filter_list
11643 : : *tunnel_list = &pf->tunnel.tunnel_list;
11644 : : struct i40e_tunnel_filter *f;
11645 : : struct i40e_aqc_cloud_filters_element_bb cld_filter;
11646 : : bool big_buffer = 0;
11647 : :
11648 [ # # ]: 0 : TAILQ_FOREACH(f, tunnel_list, rules) {
11649 [ # # ]: 0 : if (!f->is_to_vf)
11650 : 0 : vsi = pf->main_vsi;
11651 : : else {
11652 : 0 : vf = &pf->vfs[f->vf_id];
11653 : 0 : vsi = vf->vsi;
11654 : : }
11655 : : memset(&cld_filter, 0, sizeof(cld_filter));
11656 : : rte_ether_addr_copy((struct rte_ether_addr *)
11657 : : &f->input.outer_mac,
11658 : : (struct rte_ether_addr *)&cld_filter.element.outer_mac);
11659 : : rte_ether_addr_copy((struct rte_ether_addr *)
11660 : : &f->input.inner_mac,
11661 : : (struct rte_ether_addr *)&cld_filter.element.inner_mac);
11662 : 0 : cld_filter.element.inner_vlan = f->input.inner_vlan;
11663 : 0 : cld_filter.element.flags = f->input.flags;
11664 : 0 : cld_filter.element.tenant_id = f->input.tenant_id;
11665 : 0 : cld_filter.element.queue_number = f->queue;
11666 : : memcpy(cld_filter.general_fields,
11667 [ # # ]: 0 : f->input.general_fields,
11668 : : sizeof(f->input.general_fields));
11669 : :
11670 [ # # ]: 0 : if (((f->input.flags &
11671 : : I40E_AQC_ADD_CLOUD_FILTER_0X11) ==
11672 [ # # ]: 0 : I40E_AQC_ADD_CLOUD_FILTER_0X11) ||
11673 : : ((f->input.flags &
11674 : : I40E_AQC_ADD_CLOUD_FILTER_0X12) ==
11675 [ # # ]: 0 : I40E_AQC_ADD_CLOUD_FILTER_0X12) ||
11676 : : ((f->input.flags &
11677 : : I40E_AQC_ADD_CLOUD_FILTER_0X10) ==
11678 : : I40E_AQC_ADD_CLOUD_FILTER_0X10))
11679 : : big_buffer = 1;
11680 : :
11681 [ # # ]: 0 : if (big_buffer)
11682 : 0 : i40e_aq_add_cloud_filters_bb(hw,
11683 : 0 : vsi->seid, &cld_filter, 1);
11684 : : else
11685 : 0 : i40e_aq_add_cloud_filters(hw, vsi->seid,
11686 : : &cld_filter.element, 1);
11687 : : }
11688 : 0 : }
11689 : :
11690 : : static void
11691 : 0 : i40e_filter_restore(struct i40e_pf *pf)
11692 : : {
11693 : 0 : i40e_ethertype_filter_restore(pf);
11694 : 0 : i40e_tunnel_filter_restore(pf);
11695 : 0 : i40e_fdir_filter_restore(pf);
11696 : 0 : (void)i40e_hash_filter_restore(pf);
11697 : 0 : }
11698 : :
11699 : : bool
11700 : 0 : is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
11701 : : {
11702 [ # # ]: 0 : if (strcmp(dev->device->driver->name, drv->driver.name))
11703 : 0 : return false;
11704 : :
11705 : : return true;
11706 : : }
11707 : :
11708 : : bool
11709 : 0 : is_i40e_supported(struct rte_eth_dev *dev)
11710 : : {
11711 : 0 : return is_device_supported(dev, &rte_i40e_pmd);
11712 : : }
11713 : :
11714 : : struct i40e_customized_pctype*
11715 : 0 : i40e_find_customized_pctype(struct i40e_pf *pf, uint8_t index)
11716 : : {
11717 : : int i;
11718 : :
11719 [ # # ]: 0 : for (i = 0; i < I40E_CUSTOMIZED_MAX; i++) {
11720 [ # # ]: 0 : if (pf->customized_pctype[i].index == index)
11721 : 0 : return &pf->customized_pctype[i];
11722 : : }
11723 : : return NULL;
11724 : : }
11725 : :
11726 : : static int
11727 : 0 : i40e_update_customized_pctype(struct rte_eth_dev *dev, uint8_t *pkg,
11728 : : uint32_t pkg_size, uint32_t proto_num,
11729 : : struct rte_pmd_i40e_proto_info *proto,
11730 : : enum rte_pmd_i40e_package_op op)
11731 : : {
11732 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
11733 : : uint32_t pctype_num;
11734 : 0 : struct rte_pmd_i40e_ptype_info pctype[I40E_CUSTOMIZED_MAX] = {0};
11735 : : struct i40e_customized_pctype *new_pctype = NULL;
11736 : : uint8_t proto_id;
11737 : : uint8_t pctype_value;
11738 : : char name[64];
11739 : : uint32_t i, j, n;
11740 : : int ret;
11741 : :
11742 [ # # ]: 0 : if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
11743 : : op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
11744 : 0 : PMD_DRV_LOG(ERR, "Unsupported operation.");
11745 : 0 : return -1;
11746 : : }
11747 : :
11748 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11749 : : (uint8_t *)&pctype_num, sizeof(pctype_num),
11750 : : RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM);
11751 [ # # ]: 0 : if (ret) {
11752 : 0 : PMD_DRV_LOG(ERR, "Failed to get pctype number");
11753 : 0 : return -1;
11754 : : }
11755 [ # # ]: 0 : if (!pctype_num) {
11756 : 0 : PMD_DRV_LOG(INFO, "No new pctype added");
11757 : 0 : return -1;
11758 : : }
11759 : :
11760 [ # # ]: 0 : if (pctype_num > RTE_DIM(pctype)) {
11761 : 0 : PMD_DRV_LOG(ERR, "Pctype number exceeds maximum supported");
11762 : 0 : return -1;
11763 : : }
11764 : : /* get information about new pctype list */
11765 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11766 : : (uint8_t *)pctype, sizeof(pctype),
11767 : : RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST);
11768 [ # # ]: 0 : if (ret) {
11769 : 0 : PMD_DRV_LOG(ERR, "Failed to get pctype list");
11770 : 0 : return -1;
11771 : : }
11772 : :
11773 : : /* Update customized pctype. */
11774 [ # # ]: 0 : for (i = 0; i < pctype_num; i++) {
11775 : 0 : pctype_value = pctype[i].ptype_id;
11776 : : memset(name, 0, sizeof(name));
11777 [ # # ]: 0 : for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
11778 : 0 : proto_id = pctype[i].protocols[j];
11779 [ # # ]: 0 : if (proto_id == RTE_PMD_I40E_PROTO_UNUSED)
11780 : 0 : continue;
11781 [ # # ]: 0 : for (n = 0; n < proto_num; n++) {
11782 [ # # ]: 0 : if (proto[n].proto_id != proto_id)
11783 : : continue;
11784 : 0 : strlcat(name, proto[n].name, sizeof(name));
11785 : 0 : strlcat(name, "_", sizeof(name));
11786 : 0 : break;
11787 : : }
11788 : : }
11789 : 0 : name[strlen(name) - 1] = '\0';
11790 : 0 : PMD_DRV_LOG(INFO, "name = %s", name);
11791 [ # # ]: 0 : if (!strcmp(name, "GTPC"))
11792 : : new_pctype =
11793 : 0 : i40e_find_customized_pctype(pf,
11794 : : I40E_CUSTOMIZED_GTPC);
11795 [ # # ]: 0 : else if (!strcmp(name, "GTPU_IPV4"))
11796 : : new_pctype =
11797 : 0 : i40e_find_customized_pctype(pf,
11798 : : I40E_CUSTOMIZED_GTPU_IPV4);
11799 [ # # ]: 0 : else if (!strcmp(name, "GTPU_IPV6"))
11800 : : new_pctype =
11801 : 0 : i40e_find_customized_pctype(pf,
11802 : : I40E_CUSTOMIZED_GTPU_IPV6);
11803 [ # # ]: 0 : else if (!strcmp(name, "GTPU"))
11804 : : new_pctype =
11805 : 0 : i40e_find_customized_pctype(pf,
11806 : : I40E_CUSTOMIZED_GTPU);
11807 [ # # ]: 0 : else if (!strcmp(name, "IPV4_L2TPV3"))
11808 : : new_pctype =
11809 : 0 : i40e_find_customized_pctype(pf,
11810 : : I40E_CUSTOMIZED_IPV4_L2TPV3);
11811 [ # # ]: 0 : else if (!strcmp(name, "IPV6_L2TPV3"))
11812 : : new_pctype =
11813 : 0 : i40e_find_customized_pctype(pf,
11814 : : I40E_CUSTOMIZED_IPV6_L2TPV3);
11815 [ # # ]: 0 : else if (!strcmp(name, "IPV4_ESP"))
11816 : : new_pctype =
11817 : 0 : i40e_find_customized_pctype(pf,
11818 : : I40E_CUSTOMIZED_ESP_IPV4);
11819 [ # # ]: 0 : else if (!strcmp(name, "IPV6_ESP"))
11820 : : new_pctype =
11821 : 0 : i40e_find_customized_pctype(pf,
11822 : : I40E_CUSTOMIZED_ESP_IPV6);
11823 [ # # ]: 0 : else if (!strcmp(name, "IPV4_UDP_ESP"))
11824 : : new_pctype =
11825 : 0 : i40e_find_customized_pctype(pf,
11826 : : I40E_CUSTOMIZED_ESP_IPV4_UDP);
11827 [ # # ]: 0 : else if (!strcmp(name, "IPV6_UDP_ESP"))
11828 : : new_pctype =
11829 : 0 : i40e_find_customized_pctype(pf,
11830 : : I40E_CUSTOMIZED_ESP_IPV6_UDP);
11831 [ # # ]: 0 : else if (!strcmp(name, "IPV4_AH"))
11832 : : new_pctype =
11833 : 0 : i40e_find_customized_pctype(pf,
11834 : : I40E_CUSTOMIZED_AH_IPV4);
11835 [ # # ]: 0 : else if (!strcmp(name, "IPV6_AH"))
11836 : : new_pctype =
11837 : 0 : i40e_find_customized_pctype(pf,
11838 : : I40E_CUSTOMIZED_AH_IPV6);
11839 [ # # ]: 0 : if (new_pctype) {
11840 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_ADD) {
11841 : 0 : new_pctype->pctype = pctype_value;
11842 : 0 : new_pctype->valid = true;
11843 : : } else {
11844 : 0 : new_pctype->pctype = I40E_FILTER_PCTYPE_INVALID;
11845 : 0 : new_pctype->valid = false;
11846 : : }
11847 : : }
11848 : : }
11849 : :
11850 : : return 0;
11851 : : }
11852 : :
11853 : : static int
11854 : 0 : i40e_update_customized_ptype(struct rte_eth_dev *dev, uint8_t *pkg,
11855 : : uint32_t pkg_size, uint32_t proto_num,
11856 : : struct rte_pmd_i40e_proto_info *proto,
11857 : : enum rte_pmd_i40e_package_op op)
11858 : : {
11859 : 0 : struct rte_pmd_i40e_ptype_mapping ptype_mapping[I40E_MAX_PKT_TYPE] = {0};
11860 : 0 : uint16_t port_id = dev->data->port_id;
11861 : : uint32_t ptype_num;
11862 : 0 : struct rte_pmd_i40e_ptype_info ptype[I40E_MAX_PKT_TYPE] = {0};
11863 : : uint8_t proto_id;
11864 : : char name[RTE_PMD_I40E_DDP_NAME_SIZE];
11865 : : uint32_t i, j, n;
11866 : : bool in_tunnel;
11867 : : int ret;
11868 : :
11869 [ # # ]: 0 : if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
11870 : : op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
11871 : 0 : PMD_DRV_LOG(ERR, "Unsupported operation.");
11872 : 0 : return -1;
11873 : : }
11874 : :
11875 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_DEL) {
11876 : 0 : rte_pmd_i40e_ptype_mapping_reset(port_id);
11877 : 0 : return 0;
11878 : : }
11879 : :
11880 : : /* get information about new ptype num */
11881 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11882 : : (uint8_t *)&ptype_num, sizeof(ptype_num),
11883 : : RTE_PMD_I40E_PKG_INFO_PTYPE_NUM);
11884 [ # # ]: 0 : if (ret) {
11885 : 0 : PMD_DRV_LOG(ERR, "Failed to get ptype number");
11886 : 0 : return ret;
11887 : : }
11888 [ # # ]: 0 : if (!ptype_num) {
11889 : 0 : PMD_DRV_LOG(INFO, "No new ptype added");
11890 : 0 : return -1;
11891 : : }
11892 : :
11893 [ # # ]: 0 : if (ptype_num > RTE_DIM(ptype)) {
11894 : 0 : PMD_DRV_LOG(ERR, "Too many ptypes");
11895 : 0 : return -1;
11896 : : }
11897 : :
11898 : : /* get information about new ptype list */
11899 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
11900 : : (uint8_t *)ptype, sizeof(ptype),
11901 : : RTE_PMD_I40E_PKG_INFO_PTYPE_LIST);
11902 [ # # ]: 0 : if (ret) {
11903 : 0 : PMD_DRV_LOG(ERR, "Failed to get ptype list");
11904 : 0 : return ret;
11905 : : }
11906 : :
11907 : : /* Update ptype mapping table. */
11908 [ # # ]: 0 : for (i = 0; i < ptype_num; i++) {
11909 : 0 : ptype_mapping[i].hw_ptype = ptype[i].ptype_id;
11910 : 0 : ptype_mapping[i].sw_ptype = 0;
11911 : : in_tunnel = false;
11912 [ # # ]: 0 : for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) {
11913 : 0 : proto_id = ptype[i].protocols[j];
11914 [ # # ]: 0 : if (proto_id == RTE_PMD_I40E_PROTO_UNUSED)
11915 : 0 : continue;
11916 [ # # ]: 0 : for (n = 0; n < proto_num; n++) {
11917 [ # # ]: 0 : if (proto[n].proto_id != proto_id)
11918 : : continue;
11919 : : memset(name, 0, sizeof(name));
11920 : 0 : strcpy(name, proto[n].name);
11921 : 0 : PMD_DRV_LOG(INFO, "name = %s", name);
11922 [ # # ]: 0 : if (!strncasecmp(name, "PPPOE", 5))
11923 : 0 : ptype_mapping[i].sw_ptype |=
11924 : : RTE_PTYPE_L2_ETHER_PPPOE;
11925 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV4FRAG", 8) &&
11926 : : !in_tunnel) {
11927 : 0 : ptype_mapping[i].sw_ptype |=
11928 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11929 : 0 : ptype_mapping[i].sw_ptype |=
11930 : : RTE_PTYPE_L4_FRAG;
11931 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV4FRAG", 8) &&
11932 : : in_tunnel) {
11933 : 0 : ptype_mapping[i].sw_ptype |=
11934 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
11935 : 0 : ptype_mapping[i].sw_ptype |=
11936 : : RTE_PTYPE_INNER_L4_FRAG;
11937 [ # # ]: 0 : } else if (!strncasecmp(name, "OIPV4", 5)) {
11938 : 0 : ptype_mapping[i].sw_ptype |=
11939 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11940 : : in_tunnel = true;
11941 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV4", 4) &&
11942 : : !in_tunnel)
11943 : 0 : ptype_mapping[i].sw_ptype |=
11944 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
11945 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV4", 4) &&
11946 : : in_tunnel)
11947 : 0 : ptype_mapping[i].sw_ptype |=
11948 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
11949 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV6FRAG", 8) &&
11950 : : !in_tunnel) {
11951 : 0 : ptype_mapping[i].sw_ptype |=
11952 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11953 : 0 : ptype_mapping[i].sw_ptype |=
11954 : : RTE_PTYPE_L4_FRAG;
11955 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV6FRAG", 8) &&
11956 : : in_tunnel) {
11957 : 0 : ptype_mapping[i].sw_ptype |=
11958 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
11959 : 0 : ptype_mapping[i].sw_ptype |=
11960 : : RTE_PTYPE_INNER_L4_FRAG;
11961 [ # # ]: 0 : } else if (!strncasecmp(name, "OIPV6", 5)) {
11962 : 0 : ptype_mapping[i].sw_ptype |=
11963 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11964 : : in_tunnel = true;
11965 [ # # # # ]: 0 : } else if (!strncasecmp(name, "IPV6", 4) &&
11966 : : !in_tunnel)
11967 : 0 : ptype_mapping[i].sw_ptype |=
11968 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
11969 [ # # # # ]: 0 : else if (!strncasecmp(name, "IPV6", 4) &&
11970 : : in_tunnel)
11971 : 0 : ptype_mapping[i].sw_ptype |=
11972 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
11973 [ # # # # ]: 0 : else if (!strncasecmp(name, "UDP", 3) &&
11974 : : !in_tunnel)
11975 : 0 : ptype_mapping[i].sw_ptype |=
11976 : : RTE_PTYPE_L4_UDP;
11977 [ # # # # ]: 0 : else if (!strncasecmp(name, "UDP", 3) &&
11978 : : in_tunnel)
11979 : 0 : ptype_mapping[i].sw_ptype |=
11980 : : RTE_PTYPE_INNER_L4_UDP;
11981 [ # # # # ]: 0 : else if (!strncasecmp(name, "TCP", 3) &&
11982 : : !in_tunnel)
11983 : 0 : ptype_mapping[i].sw_ptype |=
11984 : : RTE_PTYPE_L4_TCP;
11985 [ # # # # ]: 0 : else if (!strncasecmp(name, "TCP", 3) &&
11986 : : in_tunnel)
11987 : 0 : ptype_mapping[i].sw_ptype |=
11988 : : RTE_PTYPE_INNER_L4_TCP;
11989 [ # # # # ]: 0 : else if (!strncasecmp(name, "SCTP", 4) &&
11990 : : !in_tunnel)
11991 : 0 : ptype_mapping[i].sw_ptype |=
11992 : : RTE_PTYPE_L4_SCTP;
11993 [ # # # # ]: 0 : else if (!strncasecmp(name, "SCTP", 4) &&
11994 : : in_tunnel)
11995 : 0 : ptype_mapping[i].sw_ptype |=
11996 : : RTE_PTYPE_INNER_L4_SCTP;
11997 [ # # ]: 0 : else if ((!strncasecmp(name, "ICMP", 4) ||
11998 [ # # # # ]: 0 : !strncasecmp(name, "ICMPV6", 6)) &&
11999 : : !in_tunnel)
12000 : 0 : ptype_mapping[i].sw_ptype |=
12001 : : RTE_PTYPE_L4_ICMP;
12002 [ # # ]: 0 : else if ((!strncasecmp(name, "ICMP", 4) ||
12003 [ # # # # ]: 0 : !strncasecmp(name, "ICMPV6", 6)) &&
12004 : : in_tunnel)
12005 : 0 : ptype_mapping[i].sw_ptype |=
12006 : : RTE_PTYPE_INNER_L4_ICMP;
12007 [ # # ]: 0 : else if (!strncasecmp(name, "GTPC", 4)) {
12008 : 0 : ptype_mapping[i].sw_ptype |=
12009 : : RTE_PTYPE_TUNNEL_GTPC;
12010 : : in_tunnel = true;
12011 [ # # ]: 0 : } else if (!strncasecmp(name, "GTPU", 4)) {
12012 : 0 : ptype_mapping[i].sw_ptype |=
12013 : : RTE_PTYPE_TUNNEL_GTPU;
12014 : : in_tunnel = true;
12015 [ # # ]: 0 : } else if (!strncasecmp(name, "ESP", 3)) {
12016 : 0 : ptype_mapping[i].sw_ptype |=
12017 : : RTE_PTYPE_TUNNEL_ESP;
12018 : : in_tunnel = true;
12019 [ # # ]: 0 : } else if (!strncasecmp(name, "GRENAT", 6)) {
12020 : 0 : ptype_mapping[i].sw_ptype |=
12021 : : RTE_PTYPE_TUNNEL_GRENAT;
12022 : : in_tunnel = true;
12023 [ # # ]: 0 : } else if (!strncasecmp(name, "L2TPV2CTL", 9) ||
12024 [ # # ]: 0 : !strncasecmp(name, "L2TPV2", 6) ||
12025 [ # # ]: 0 : !strncasecmp(name, "L2TPV3", 6)) {
12026 : 0 : ptype_mapping[i].sw_ptype |=
12027 : : RTE_PTYPE_TUNNEL_L2TP;
12028 : : in_tunnel = true;
12029 : : }
12030 : :
12031 : : break;
12032 : : }
12033 : : }
12034 : : }
12035 : :
12036 : 0 : ret = rte_pmd_i40e_ptype_mapping_update(port_id, ptype_mapping,
12037 : : ptype_num, 0);
12038 [ # # ]: 0 : if (ret)
12039 : 0 : PMD_DRV_LOG(ERR, "Failed to update ptype mapping table.");
12040 : :
12041 : : return ret;
12042 : : }
12043 : :
12044 : : void
12045 : 0 : i40e_update_customized_info(struct rte_eth_dev *dev, uint8_t *pkg,
12046 : : uint32_t pkg_size, enum rte_pmd_i40e_package_op op)
12047 : : {
12048 : 0 : struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
12049 : : uint32_t proto_num;
12050 : : struct rte_pmd_i40e_proto_info *proto;
12051 : : uint32_t buff_size;
12052 : : uint32_t i;
12053 : : int ret;
12054 : :
12055 [ # # ]: 0 : if (op != RTE_PMD_I40E_PKG_OP_WR_ADD &&
12056 : : op != RTE_PMD_I40E_PKG_OP_WR_DEL) {
12057 : 0 : PMD_DRV_LOG(ERR, "Unsupported operation.");
12058 : 0 : return;
12059 : : }
12060 : :
12061 : : /* get information about protocol number */
12062 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12063 : : (uint8_t *)&proto_num, sizeof(proto_num),
12064 : : RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM);
12065 [ # # ]: 0 : if (ret) {
12066 : 0 : PMD_DRV_LOG(ERR, "Failed to get protocol number");
12067 : 0 : return;
12068 : : }
12069 [ # # ]: 0 : if (!proto_num) {
12070 : 0 : PMD_DRV_LOG(INFO, "No new protocol added");
12071 : 0 : return;
12072 : : }
12073 : :
12074 : 0 : buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info);
12075 : 0 : proto = calloc(proto_num, sizeof(struct rte_pmd_i40e_proto_info));
12076 [ # # ]: 0 : if (!proto) {
12077 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate memory");
12078 : 0 : return;
12079 : : }
12080 : :
12081 : : /* get information about protocol list */
12082 : 0 : ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size,
12083 : : (uint8_t *)proto, buff_size,
12084 : : RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST);
12085 [ # # ]: 0 : if (ret) {
12086 : 0 : PMD_DRV_LOG(ERR, "Failed to get protocol list");
12087 : 0 : free(proto);
12088 : 0 : return;
12089 : : }
12090 : :
12091 : : /* Check if GTP is supported. */
12092 [ # # ]: 0 : for (i = 0; i < proto_num; i++) {
12093 [ # # ]: 0 : if (!strncmp(proto[i].name, "GTP", 3)) {
12094 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
12095 : 0 : pf->gtp_support = true;
12096 : : else
12097 : 0 : pf->gtp_support = false;
12098 : : break;
12099 : : }
12100 : : }
12101 : :
12102 : : /* Check if ESP is supported. */
12103 [ # # ]: 0 : for (i = 0; i < proto_num; i++) {
12104 [ # # ]: 0 : if (!strncmp(proto[i].name, "ESP", 3)) {
12105 [ # # ]: 0 : if (op == RTE_PMD_I40E_PKG_OP_WR_ADD)
12106 : 0 : pf->esp_support = true;
12107 : : else
12108 : 0 : pf->esp_support = false;
12109 : : break;
12110 : : }
12111 : : }
12112 : :
12113 : : /* Update customized pctype info */
12114 : 0 : ret = i40e_update_customized_pctype(dev, pkg, pkg_size,
12115 : : proto_num, proto, op);
12116 [ # # ]: 0 : if (ret)
12117 : 0 : PMD_DRV_LOG(INFO, "No pctype is updated.");
12118 : :
12119 : : /* Update customized ptype info */
12120 : 0 : ret = i40e_update_customized_ptype(dev, pkg, pkg_size,
12121 : : proto_num, proto, op);
12122 [ # # ]: 0 : if (ret)
12123 : 0 : PMD_DRV_LOG(INFO, "No ptype is updated.");
12124 : :
12125 : 0 : free(proto);
12126 : : }
12127 : :
12128 : : /* Create a QinQ cloud filter
12129 : : *
12130 : : * The Fortville NIC has limited resources for tunnel filters,
12131 : : * so we can only reuse existing filters.
12132 : : *
12133 : : * In step 1 we define which Field Vector fields can be used for
12134 : : * filter types.
12135 : : * As we do not have the inner tag defined as a field,
12136 : : * we have to define it first, by reusing one of L1 entries.
12137 : : *
12138 : : * In step 2 we are replacing one of existing filter types with
12139 : : * a new one for QinQ.
12140 : : * As we reusing L1 and replacing L2, some of the default filter
12141 : : * types will disappear,which depends on L1 and L2 entries we reuse.
12142 : : *
12143 : : * Step 1: Create L1 filter of outer vlan (12b) + inner vlan (12b)
12144 : : *
12145 : : * 1. Create L1 filter of outer vlan (12b) which will be in use
12146 : : * later when we define the cloud filter.
12147 : : * a. Valid_flags.replace_cloud = 0
12148 : : * b. Old_filter = 10 (Stag_Inner_Vlan)
12149 : : * c. New_filter = 0x10
12150 : : * d. TR bit = 0xff (optional, not used here)
12151 : : * e. Buffer – 2 entries:
12152 : : * i. Byte 0 = 8 (outer vlan FV index).
12153 : : * Byte 1 = 0 (rsv)
12154 : : * Byte 2-3 = 0x0fff
12155 : : * ii. Byte 0 = 37 (inner vlan FV index).
12156 : : * Byte 1 =0 (rsv)
12157 : : * Byte 2-3 = 0x0fff
12158 : : *
12159 : : * Step 2:
12160 : : * 2. Create cloud filter using two L1 filters entries: stag and
12161 : : * new filter(outer vlan+ inner vlan)
12162 : : * a. Valid_flags.replace_cloud = 1
12163 : : * b. Old_filter = 1 (instead of outer IP)
12164 : : * c. New_filter = 0x10
12165 : : * d. Buffer – 2 entries:
12166 : : * i. Byte 0 = 0x80 | 7 (valid | Stag).
12167 : : * Byte 1-3 = 0 (rsv)
12168 : : * ii. Byte 8 = 0x80 | 0x10 (valid | new l1 filter step1)
12169 : : * Byte 9-11 = 0 (rsv)
12170 : : */
12171 : : static int
12172 : 0 : i40e_cloud_filter_qinq_create(struct i40e_pf *pf)
12173 : : {
12174 : : int ret = -ENOTSUP;
12175 : : struct i40e_aqc_replace_cloud_filters_cmd filter_replace;
12176 : : struct i40e_aqc_replace_cloud_filters_cmd_buf filter_replace_buf;
12177 : 0 : struct i40e_hw *hw = I40E_PF_TO_HW(pf);
12178 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[pf->dev_data->port_id];
12179 : :
12180 [ # # ]: 0 : if (pf->support_multi_driver) {
12181 : 0 : PMD_DRV_LOG(ERR, "Replace cloud filter is not supported.");
12182 : 0 : return ret;
12183 : : }
12184 : :
12185 : : /* Init */
12186 : : memset(&filter_replace, 0,
12187 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
12188 : : memset(&filter_replace_buf, 0,
12189 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
12190 : :
12191 : : /* create L1 filter */
12192 : 0 : filter_replace.old_filter_type =
12193 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG_IVLAN;
12194 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12195 : : filter_replace.tr_bit = 0;
12196 : :
12197 : : /* Prepare the buffer, 2 entries */
12198 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_VLAN;
12199 : 0 : filter_replace_buf.data[0] |=
12200 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12201 : : /* Field Vector 12b mask */
12202 : 0 : filter_replace_buf.data[2] = 0xff;
12203 : 0 : filter_replace_buf.data[3] = 0x0f;
12204 : : filter_replace_buf.data[4] =
12205 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_INNER_VLAN;
12206 : 0 : filter_replace_buf.data[4] |=
12207 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12208 : : /* Field Vector 12b mask */
12209 : 0 : filter_replace_buf.data[6] = 0xff;
12210 : 0 : filter_replace_buf.data[7] = 0x0f;
12211 : 0 : ret = i40e_aq_replace_cloud_filters(hw, &filter_replace,
12212 : : &filter_replace_buf);
12213 [ # # ]: 0 : if (ret != I40E_SUCCESS)
12214 : : return ret;
12215 : :
12216 : 0 : if (filter_replace.old_filter_type !=
12217 [ # # ]: 0 : filter_replace.new_filter_type)
12218 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud l1 type."
12219 : : " original: 0x%x, new: 0x%x",
12220 : : dev->device->name,
12221 : : filter_replace.old_filter_type,
12222 : : filter_replace.new_filter_type);
12223 : :
12224 : : /* Apply the second L2 cloud filter */
12225 : : memset(&filter_replace, 0,
12226 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd));
12227 : : memset(&filter_replace_buf, 0,
12228 : : sizeof(struct i40e_aqc_replace_cloud_filters_cmd_buf));
12229 : :
12230 : : /* create L2 filter, input for L2 filter will be L1 filter */
12231 : 0 : filter_replace.valid_flags = I40E_AQC_REPLACE_CLOUD_FILTER;
12232 : 0 : filter_replace.old_filter_type = I40E_AQC_ADD_CLOUD_FILTER_OIP;
12233 : 0 : filter_replace.new_filter_type = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12234 : :
12235 : : /* Prepare the buffer, 2 entries */
12236 : : filter_replace_buf.data[0] = I40E_AQC_REPLACE_CLOUD_CMD_INPUT_FV_STAG;
12237 : 0 : filter_replace_buf.data[0] |=
12238 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12239 : : filter_replace_buf.data[4] = I40E_AQC_ADD_CLOUD_FILTER_0X10;
12240 : 0 : filter_replace_buf.data[4] |=
12241 : : I40E_AQC_REPLACE_CLOUD_CMD_INPUT_VALIDATED;
12242 : 0 : ret = i40e_aq_replace_cloud_filters(hw, &filter_replace,
12243 : : &filter_replace_buf);
12244 [ # # ]: 0 : if (!ret && (filter_replace.old_filter_type !=
12245 [ # # ]: 0 : filter_replace.new_filter_type))
12246 : 0 : PMD_DRV_LOG(WARNING, "i40e device %s changed cloud filter type."
12247 : : " original: 0x%x, new: 0x%x",
12248 : : dev->device->name,
12249 : : filter_replace.old_filter_type,
12250 : : filter_replace.new_filter_type);
12251 : :
12252 : : return ret;
12253 : : }
12254 : :
12255 : : static int
12256 : 0 : i40e_fec_get_capability(struct rte_eth_dev *dev,
12257 : : struct rte_eth_fec_capa *speed_fec_capa, __rte_unused unsigned int num)
12258 : : {
12259 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
12260 : :
12261 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722 &&
12262 [ # # ]: 0 : !(hw->flags & I40E_HW_FLAG_X722_FEC_REQUEST_CAPABLE)) {
12263 : 0 : PMD_DRV_LOG(ERR, "Setting FEC encoding not supported by"
12264 : : " firmware. Please update the NVM image.");
12265 : 0 : return -ENOTSUP;
12266 : : }
12267 : :
12268 [ # # ]: 0 : if (hw->device_id == I40E_DEV_ID_25G_SFP28 ||
12269 : : hw->device_id == I40E_DEV_ID_25G_B) {
12270 [ # # ]: 0 : if (speed_fec_capa) {
12271 : 0 : speed_fec_capa->speed = RTE_ETH_SPEED_NUM_25G;
12272 : 0 : speed_fec_capa->capa = RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC) |
12273 : : RTE_ETH_FEC_MODE_CAPA_MASK(BASER) |
12274 : : RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
12275 : : RTE_ETH_FEC_MODE_CAPA_MASK(RS);
12276 : : }
12277 : :
12278 : : /* since HW only supports 25G */
12279 : 0 : return 1;
12280 [ # # ]: 0 : } else if (hw->device_id == I40E_DEV_ID_KX_X722) {
12281 [ # # ]: 0 : if (speed_fec_capa) {
12282 : 0 : speed_fec_capa->speed = RTE_ETH_SPEED_NUM_25G;
12283 : 0 : speed_fec_capa->capa = RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
12284 : : RTE_ETH_FEC_MODE_CAPA_MASK(RS);
12285 : : }
12286 : 0 : return 1;
12287 : : }
12288 : :
12289 : : return -ENOTSUP;
12290 : : }
12291 : :
12292 : : static int
12293 : 0 : i40e_fec_get(struct rte_eth_dev *dev, uint32_t *fec_capa)
12294 : : {
12295 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
12296 : 0 : struct i40e_aq_get_phy_abilities_resp abilities = {0};
12297 : 0 : struct i40e_link_status link_status = {0};
12298 : : uint8_t current_fec_mode = 0, fec_config = 0;
12299 : : bool link_up, enable_lse;
12300 : : int ret = 0;
12301 : :
12302 : 0 : enable_lse = dev->data->dev_conf.intr_conf.lsc ? true : false;
12303 : : /* Get link info */
12304 : 0 : ret = i40e_aq_get_link_info(hw, enable_lse, &link_status, NULL);
12305 [ # # ]: 0 : if (ret != I40E_SUCCESS) {
12306 : 0 : PMD_DRV_LOG(ERR, "Failed to get link information: %d",
12307 : : ret);
12308 : 0 : return -ENOTSUP;
12309 : : }
12310 : :
12311 : 0 : link_up = link_status.link_info & I40E_AQ_LINK_UP;
12312 : :
12313 : 0 : ret = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
12314 : : NULL);
12315 [ # # ]: 0 : if (ret) {
12316 : 0 : PMD_DRV_LOG(ERR, "Failed to get PHY capabilities: %d",
12317 : : ret);
12318 : 0 : return -ENOTSUP;
12319 : : }
12320 : :
12321 : : /**
12322 : : * If link is down and AUTO is enabled, AUTO is returned,
12323 : : * otherwise, configured FEC mode is returned.
12324 : : * If link is up, current FEC mode is returned.
12325 : : */
12326 : 0 : fec_config = abilities.fec_cfg_curr_mod_ext_info
12327 : : & I40E_AQ_PHY_FEC_CONFIG_MASK;
12328 : 0 : current_fec_mode = link_status.fec_info;
12329 : :
12330 [ # # ]: 0 : if (link_up) {
12331 [ # # # # ]: 0 : switch (current_fec_mode) {
12332 : 0 : case I40E_AQ_CONFIG_FEC_KR_ENA:
12333 : 0 : *fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_BASER);
12334 : 0 : break;
12335 : 0 : case I40E_AQ_CONFIG_FEC_RS_ENA:
12336 : 0 : *fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_RS);
12337 : 0 : break;
12338 : 0 : case 0:
12339 : 0 : *fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_NOFEC);
12340 : 0 : break;
12341 : : default:
12342 : : return -EINVAL;
12343 : : }
12344 : 0 : return 0;
12345 : : }
12346 : :
12347 [ # # ]: 0 : if (fec_config & I40E_AQ_ENABLE_FEC_AUTO) {
12348 : 0 : *fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_AUTO);
12349 : 0 : return 0;
12350 : : }
12351 : :
12352 : : uint32_t temp_fec_capa = 0;
12353 [ # # ]: 0 : if (fec_config & I40E_AQ_ENABLE_FEC_KR)
12354 : : temp_fec_capa |= RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_BASER);
12355 [ # # ]: 0 : if (fec_config & I40E_AQ_ENABLE_FEC_RS)
12356 : 0 : temp_fec_capa |= RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_RS);
12357 : : if (temp_fec_capa == 0)
12358 : : temp_fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_NOFEC);
12359 : :
12360 : 0 : *fec_capa = temp_fec_capa;
12361 : 0 : return 0;
12362 : : }
12363 : :
12364 : : static int
12365 : 0 : i40e_fec_set(struct rte_eth_dev *dev, uint32_t fec_capa)
12366 : : {
12367 : 0 : struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
12368 : 0 : struct i40e_aq_get_phy_abilities_resp abilities = {0};
12369 : 0 : struct i40e_aq_set_phy_config config = {0};
12370 : : enum i40e_status_code status;
12371 : : uint8_t req_fec = 0, fec_auto = 0, fec_kr = 0, fec_rs = 0;
12372 : :
12373 : 0 : if (hw->device_id != I40E_DEV_ID_25G_SFP28 &&
12374 [ # # ]: 0 : hw->device_id != I40E_DEV_ID_25G_B &&
12375 : : hw->device_id != I40E_DEV_ID_KX_X722) {
12376 : : return -ENOTSUP;
12377 : : }
12378 : :
12379 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722 &&
12380 [ # # ]: 0 : !(hw->flags & I40E_HW_FLAG_X722_FEC_REQUEST_CAPABLE)) {
12381 : 0 : PMD_DRV_LOG(ERR, "Setting FEC encoding not supported by"
12382 : : " firmware. Please update the NVM image.");
12383 : 0 : return -ENOTSUP;
12384 : : }
12385 : :
12386 : : /**
12387 : : * Copy the current user PHY configuration. The current user PHY
12388 : : * configuration is initialized during probe from PHY capabilities
12389 : : * software mode, and updated on set PHY configuration.
12390 : : */
12391 [ # # ]: 0 : if (fec_capa & ~(RTE_ETH_FEC_MODE_CAPA_MASK(AUTO) |
12392 : : RTE_ETH_FEC_MODE_CAPA_MASK(BASER) | RTE_ETH_FEC_MODE_CAPA_MASK(RS)))
12393 : : return -EINVAL;
12394 : :
12395 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_CAPA_MASK(AUTO))
12396 : : fec_auto = 1;
12397 : :
12398 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_CAPA_MASK(BASER))
12399 : : fec_kr = 1;
12400 : :
12401 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_CAPA_MASK(RS))
12402 : : fec_rs = 1;
12403 : :
12404 [ # # ]: 0 : if (fec_auto) {
12405 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
12406 : 0 : PMD_DRV_LOG(ERR, "X722 Unsupported FEC mode: AUTO");
12407 : 0 : return -EINVAL;
12408 : : }
12409 [ # # ]: 0 : if (fec_kr || fec_rs) {
12410 [ # # ]: 0 : if (fec_kr)
12411 : : req_fec = I40E_AQ_SET_FEC_ABILITY_KR |
12412 : : I40E_AQ_SET_FEC_REQUEST_KR;
12413 [ # # ]: 0 : if (fec_rs) {
12414 : : if (hw->mac.type == I40E_MAC_X722) {
12415 : : PMD_DRV_LOG(ERR, "X722 Unsupported FEC mode: RS");
12416 : : return -EINVAL;
12417 : : }
12418 : 0 : req_fec |= I40E_AQ_SET_FEC_ABILITY_RS |
12419 : : I40E_AQ_SET_FEC_REQUEST_RS;
12420 : : }
12421 : : } else {
12422 : : if (hw->mac.type == I40E_MAC_X722) {
12423 : : req_fec = I40E_AQ_SET_FEC_ABILITY_KR |
12424 : : I40E_AQ_SET_FEC_REQUEST_KR;
12425 : : } else {
12426 : : req_fec = I40E_AQ_SET_FEC_ABILITY_KR |
12427 : : I40E_AQ_SET_FEC_REQUEST_KR |
12428 : : I40E_AQ_SET_FEC_ABILITY_RS |
12429 : : I40E_AQ_SET_FEC_REQUEST_RS;
12430 : : }
12431 : : }
12432 : : } else {
12433 [ # # ]: 0 : if (fec_kr ^ fec_rs) {
12434 [ # # ]: 0 : if (fec_kr) {
12435 : : req_fec = I40E_AQ_SET_FEC_ABILITY_KR |
12436 : : I40E_AQ_SET_FEC_REQUEST_KR;
12437 : : } else {
12438 [ # # ]: 0 : if (hw->mac.type == I40E_MAC_X722) {
12439 : 0 : PMD_DRV_LOG(ERR, "X722 Unsupported FEC mode: RS");
12440 : 0 : return -EINVAL;
12441 : : }
12442 : : req_fec = I40E_AQ_SET_FEC_ABILITY_RS |
12443 : : I40E_AQ_SET_FEC_REQUEST_RS;
12444 : : }
12445 : : } else {
12446 : : return -EINVAL;
12447 : : }
12448 : : }
12449 : :
12450 : : /* Get the current phy config */
12451 : 0 : status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
12452 : : NULL);
12453 [ # # ]: 0 : if (status) {
12454 : 0 : PMD_DRV_LOG(ERR, "Failed to get PHY capabilities: %d",
12455 : : status);
12456 : 0 : return -ENOTSUP;
12457 : : }
12458 : :
12459 [ # # ]: 0 : if (abilities.fec_cfg_curr_mod_ext_info != req_fec) {
12460 : 0 : config.phy_type = abilities.phy_type;
12461 : 0 : config.abilities = abilities.abilities |
12462 : : I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
12463 : 0 : config.phy_type_ext = abilities.phy_type_ext;
12464 : 0 : config.link_speed = abilities.link_speed;
12465 : 0 : config.eee_capability = abilities.eee_capability;
12466 : 0 : config.eeer = abilities.eeer_val;
12467 : 0 : config.low_power_ctrl = abilities.d3_lpan;
12468 : 0 : config.fec_config = req_fec & I40E_AQ_PHY_FEC_CONFIG_MASK;
12469 : 0 : status = i40e_aq_set_phy_config(hw, &config, NULL);
12470 [ # # ]: 0 : if (status) {
12471 : 0 : PMD_DRV_LOG(ERR, "Failed to set PHY capabilities: %d",
12472 : : status);
12473 : 0 : return -ENOTSUP;
12474 : : }
12475 : : }
12476 : :
12477 : 0 : status = i40e_update_link_info(hw);
12478 [ # # ]: 0 : if (status) {
12479 : 0 : PMD_DRV_LOG(ERR, "Failed to set PHY capabilities: %d",
12480 : : status);
12481 : 0 : return -ENOTSUP;
12482 : : }
12483 : :
12484 : : return 0;
12485 : : }
12486 : :
12487 [ - + ]: 301 : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_init, init, NOTICE);
12488 [ - + ]: 301 : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_driver, driver, NOTICE);
12489 : : #ifdef RTE_ETHDEV_DEBUG_RX
12490 : : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_rx, rx, DEBUG);
12491 : : #endif
12492 : : #ifdef RTE_ETHDEV_DEBUG_TX
12493 : : RTE_LOG_REGISTER_SUFFIX(i40e_logtype_tx, tx, DEBUG);
12494 : : #endif
12495 : :
12496 : : RTE_PMD_REGISTER_PARAM_STRING(net_i40e,
12497 : : ETH_I40E_FLOATING_VEB_ARG "=1"
12498 : : ETH_I40E_FLOATING_VEB_LIST_ARG "=<string>"
12499 : : ETH_I40E_QUEUE_NUM_PER_VF_ARG "=1|2|4|8|16"
12500 : : ETH_I40E_SUPPORT_MULTI_DRIVER "=1");
|